From ac08827f91d635227d5e98cdd7d40c35072c84a1 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 11 Dec 2020 18:16:31 +0100 Subject: [PATCH] Move ECDSA and ECDH to ecc subpackage --- .../key/generation/KeyRingBuilder.java | 2 +- .../key/generation/type/KeyType.java | 13 +++++-- .../type/{ => ecc}/EllipticCurve.java | 2 +- .../generation/type/{ => ecc}/ecdh/ECDH.java | 9 ++++- .../type/{ => ecc}/ecdh/package-info.java | 2 +- .../type/{ => ecc}/ecdsa/ECDSA.java | 9 ++++- .../type/{ => ecc}/ecdsa/package-info.java | 2 +- .../key/generation/type/eddsa/EdDSA.java | 8 ++++ .../type/elgamal/ElGamal_ENCRYPT.java | 5 +++ .../type/elgamal/ElGamal_GENERAL.java | 5 +++ .../type/length/DiffieHellmanLength.java | 38 ------------------- .../generation/type/length/package-info.java | 19 ---------- .../key/generation/type/rsa/RSA.java | 5 +++ .../key/generation/type/xdh/XDH.java | 5 +++ .../key/modification/AddSubKeyTest.java | 4 +- 15 files changed, 58 insertions(+), 70 deletions(-) rename pgpainless-core/src/main/java/org/pgpainless/key/generation/type/{ => ecc}/EllipticCurve.java (94%) rename pgpainless-core/src/main/java/org/pgpainless/key/generation/type/{ => ecc}/ecdh/ECDH.java (88%) rename pgpainless-core/src/main/java/org/pgpainless/key/generation/type/{ => ecc}/ecdh/package-info.java (92%) rename pgpainless-core/src/main/java/org/pgpainless/key/generation/type/{ => ecc}/ecdsa/ECDSA.java (88%) rename pgpainless-core/src/main/java/org/pgpainless/key/generation/type/{ => ecc}/ecdsa/package-info.java (92%) delete mode 100644 pgpainless-core/src/main/java/org/pgpainless/key/generation/type/length/DiffieHellmanLength.java delete mode 100644 pgpainless-core/src/main/java/org/pgpainless/key/generation/type/length/package-info.java diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java index d3426f5f..41428e09 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java @@ -53,7 +53,7 @@ import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.SignatureType; import org.pgpainless.key.generation.type.KeyType; -import org.pgpainless.key.generation.type.EllipticCurve; +import org.pgpainless.key.generation.type.ecc.EllipticCurve; import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.key.util.UserId; import org.pgpainless.provider.ProviderFactory; diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/KeyType.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/KeyType.java index a39d2a85..c22d78ee 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/KeyType.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/KeyType.java @@ -18,8 +18,11 @@ package org.pgpainless.key.generation.type; import java.security.spec.AlgorithmParameterSpec; import org.pgpainless.algorithm.PublicKeyAlgorithm; -import org.pgpainless.key.generation.type.ecdh.ECDH; -import org.pgpainless.key.generation.type.ecdsa.ECDSA; +import org.pgpainless.key.generation.type.ecc.EllipticCurve; +import org.pgpainless.key.generation.type.ecc.ecdh.ECDH; +import org.pgpainless.key.generation.type.ecc.ecdsa.ECDSA; +import org.pgpainless.key.generation.type.eddsa.EdDSA; +import org.pgpainless.key.generation.type.eddsa.EdDSACurve; import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.key.generation.type.rsa.RSA; @@ -31,6 +34,8 @@ public interface KeyType { AlgorithmParameterSpec getAlgorithmSpec(); + boolean canCertify(); + static KeyType RSA(RsaLength length) { return RSA.withLength(length); } @@ -43,5 +48,7 @@ public interface KeyType { return ECDSA.fromCurve(curve); } - // TODO: Decide, if we want to add ElGamal here as well? + static KeyType EDDSA(EdDSACurve curve) { + return EdDSA.fromCurve(curve); + } } diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/EllipticCurve.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/EllipticCurve.java similarity index 94% rename from pgpainless-core/src/main/java/org/pgpainless/key/generation/type/EllipticCurve.java rename to pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/EllipticCurve.java index 7921c6f0..330a635f 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/EllipticCurve.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/EllipticCurve.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.pgpainless.key.generation.type; +package org.pgpainless.key.generation.type.ecc; import javax.annotation.Nonnull; diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecdh/ECDH.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/ecdh/ECDH.java similarity index 88% rename from pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecdh/ECDH.java rename to pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/ecdh/ECDH.java index a6753cfd..b3662574 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecdh/ECDH.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/ecdh/ECDH.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.pgpainless.key.generation.type.ecdh; +package org.pgpainless.key.generation.type.ecc.ecdh; import javax.annotation.Nonnull; import java.security.spec.AlgorithmParameterSpec; @@ -21,7 +21,7 @@ import java.security.spec.AlgorithmParameterSpec; import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec; import org.pgpainless.algorithm.PublicKeyAlgorithm; import org.pgpainless.key.generation.type.KeyType; -import org.pgpainless.key.generation.type.EllipticCurve; +import org.pgpainless.key.generation.type.ecc.EllipticCurve; public final class ECDH implements KeyType { @@ -49,4 +49,9 @@ public final class ECDH implements KeyType { public AlgorithmParameterSpec getAlgorithmSpec() { return new ECNamedCurveGenParameterSpec(curve.getName()); } + + @Override + public boolean canCertify() { + return false; + } } diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecdh/package-info.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/ecdh/package-info.java similarity index 92% rename from pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecdh/package-info.java rename to pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/ecdh/package-info.java index b6c623bc..64e17d22 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecdh/package-info.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/ecdh/package-info.java @@ -16,4 +16,4 @@ /** * Classes related to ECDH. */ -package org.pgpainless.key.generation.type.ecdh; +package org.pgpainless.key.generation.type.ecc.ecdh; diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecdsa/ECDSA.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/ecdsa/ECDSA.java similarity index 88% rename from pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecdsa/ECDSA.java rename to pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/ecdsa/ECDSA.java index a9022f79..beb65b9d 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecdsa/ECDSA.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/ecdsa/ECDSA.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.pgpainless.key.generation.type.ecdsa; +package org.pgpainless.key.generation.type.ecc.ecdsa; import java.security.spec.AlgorithmParameterSpec; @@ -21,7 +21,7 @@ import javax.annotation.Nonnull; import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec; import org.pgpainless.algorithm.PublicKeyAlgorithm; -import org.pgpainless.key.generation.type.EllipticCurve; +import org.pgpainless.key.generation.type.ecc.EllipticCurve; import org.pgpainless.key.generation.type.KeyType; public final class ECDSA implements KeyType { @@ -50,4 +50,9 @@ public final class ECDSA implements KeyType { public AlgorithmParameterSpec getAlgorithmSpec() { return new ECNamedCurveGenParameterSpec(curve.getName()); } + + @Override + public boolean canCertify() { + return true; + } } diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecdsa/package-info.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/ecdsa/package-info.java similarity index 92% rename from pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecdsa/package-info.java rename to pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/ecdsa/package-info.java index 0e96e3e4..9850591b 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecdsa/package-info.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/ecc/ecdsa/package-info.java @@ -16,4 +16,4 @@ /** * Classes related to ECDSA. */ -package org.pgpainless.key.generation.type.ecdsa; +package org.pgpainless.key.generation.type.ecc.ecdsa; diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/eddsa/EdDSA.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/eddsa/EdDSA.java index 2517f40e..fb746af9 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/eddsa/EdDSA.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/eddsa/EdDSA.java @@ -21,6 +21,9 @@ import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec; import org.pgpainless.algorithm.PublicKeyAlgorithm; import org.pgpainless.key.generation.type.KeyType; +/** + * Edwards-curve Digital Signature Algorithm (EdDSA). + */ public final class EdDSA implements KeyType { private final EdDSACurve curve; @@ -47,4 +50,9 @@ public final class EdDSA implements KeyType { public AlgorithmParameterSpec getAlgorithmSpec() { return new ECNamedCurveGenParameterSpec(curve.getName()); } + + @Override + public boolean canCertify() { + return true; + } } diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/elgamal/ElGamal_ENCRYPT.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/elgamal/ElGamal_ENCRYPT.java index 22603377..ff29c78f 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/elgamal/ElGamal_ENCRYPT.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/elgamal/ElGamal_ENCRYPT.java @@ -48,4 +48,9 @@ public final class ElGamal_ENCRYPT implements KeyType { public AlgorithmParameterSpec getAlgorithmSpec() { return new ElGamalParameterSpec(length.getP(), length.getG()); } + + @Override + public boolean canCertify() { + return false; + } } diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/elgamal/ElGamal_GENERAL.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/elgamal/ElGamal_GENERAL.java index 1a03a647..0ff11108 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/elgamal/ElGamal_GENERAL.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/elgamal/ElGamal_GENERAL.java @@ -49,4 +49,9 @@ public class ElGamal_GENERAL implements KeyType { public AlgorithmParameterSpec getAlgorithmSpec() { return new ElGamalParameterSpec(length.getP(), length.getG()); } + + @Override + public boolean canCertify() { + return false; + } } diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/length/DiffieHellmanLength.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/length/DiffieHellmanLength.java deleted file mode 100644 index 1579b016..00000000 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/length/DiffieHellmanLength.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2018 Paul Schaub. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.pgpainless.key.generation.type.length; - -import org.pgpainless.key.generation.type.KeyLength; - -public enum DiffieHellmanLength implements KeyLength { - - _1024(1024), - _2048(2048), - _3072(3072), - ; - - private final int length; - - DiffieHellmanLength(int length) { - this.length = length; - } - - @Override - public int getLength() { - return length; - } - -} diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/length/package-info.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/length/package-info.java deleted file mode 100644 index 4864d5e6..00000000 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/length/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2018 Paul Schaub. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * Classes describing the lengths of different public key crypto systems. - */ -package org.pgpainless.key.generation.type.length; diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/rsa/RSA.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/rsa/RSA.java index 67d6a051..13fb48ad 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/rsa/RSA.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/rsa/RSA.java @@ -51,4 +51,9 @@ public class RSA implements KeyType { public AlgorithmParameterSpec getAlgorithmSpec() { return new RSAKeyGenParameterSpec(length.getLength(), RSAKeyGenParameterSpec.F4); } + + @Override + public boolean canCertify() { + return true; + } } diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/xdh/XDH.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/xdh/XDH.java index 31e307ec..c660a8eb 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/xdh/XDH.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/type/xdh/XDH.java @@ -47,4 +47,9 @@ public final class XDH implements KeyType { public AlgorithmParameterSpec getAlgorithmSpec() { return new ECNamedCurveGenParameterSpec(curve.getName()); } + + @Override + public boolean canCertify() { + return false; + } } diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java index 1ed4dd88..472f8e10 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java @@ -34,8 +34,8 @@ import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.key.TestKeys; import org.pgpainless.key.generation.KeySpec; -import org.pgpainless.key.generation.type.ecdsa.ECDSA; -import org.pgpainless.key.generation.type.EllipticCurve; +import org.pgpainless.key.generation.type.ecc.ecdsa.ECDSA; +import org.pgpainless.key.generation.type.ecc.EllipticCurve; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.util.Passphrase;