1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 22:32:07 +01:00

Move ECDSA and ECDH to ecc subpackage

This commit is contained in:
Paul Schaub 2020-12-11 18:16:31 +01:00
parent 799265f332
commit ac08827f91
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
15 changed files with 58 additions and 70 deletions

View file

@ -53,7 +53,7 @@ import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.SignatureType; import org.pgpainless.algorithm.SignatureType;
import org.pgpainless.key.generation.type.KeyType; 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.generation.type.rsa.RsaLength;
import org.pgpainless.key.util.UserId; import org.pgpainless.key.util.UserId;
import org.pgpainless.provider.ProviderFactory; import org.pgpainless.provider.ProviderFactory;

View file

@ -18,8 +18,11 @@ package org.pgpainless.key.generation.type;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import org.pgpainless.algorithm.PublicKeyAlgorithm; import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.key.generation.type.ecdh.ECDH; import org.pgpainless.key.generation.type.ecc.EllipticCurve;
import org.pgpainless.key.generation.type.ecdsa.ECDSA; 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.RsaLength;
import org.pgpainless.key.generation.type.rsa.RSA; import org.pgpainless.key.generation.type.rsa.RSA;
@ -31,6 +34,8 @@ public interface KeyType {
AlgorithmParameterSpec getAlgorithmSpec(); AlgorithmParameterSpec getAlgorithmSpec();
boolean canCertify();
static KeyType RSA(RsaLength length) { static KeyType RSA(RsaLength length) {
return RSA.withLength(length); return RSA.withLength(length);
} }
@ -43,5 +48,7 @@ public interface KeyType {
return ECDSA.fromCurve(curve); return ECDSA.fromCurve(curve);
} }
// TODO: Decide, if we want to add ElGamal here as well? static KeyType EDDSA(EdDSACurve curve) {
return EdDSA.fromCurve(curve);
}
} }

View file

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.pgpainless.key.generation.type; package org.pgpainless.key.generation.type.ecc;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;

View file

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.pgpainless.key.generation.type.ecdh; package org.pgpainless.key.generation.type.ecc.ecdh;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
@ -21,7 +21,7 @@ import java.security.spec.AlgorithmParameterSpec;
import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec; import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec;
import org.pgpainless.algorithm.PublicKeyAlgorithm; import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.key.generation.type.KeyType; 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 { public final class ECDH implements KeyType {
@ -49,4 +49,9 @@ public final class ECDH implements KeyType {
public AlgorithmParameterSpec getAlgorithmSpec() { public AlgorithmParameterSpec getAlgorithmSpec() {
return new ECNamedCurveGenParameterSpec(curve.getName()); return new ECNamedCurveGenParameterSpec(curve.getName());
} }
@Override
public boolean canCertify() {
return false;
}
} }

View file

@ -16,4 +16,4 @@
/** /**
* Classes related to ECDH. * Classes related to ECDH.
*/ */
package org.pgpainless.key.generation.type.ecdh; package org.pgpainless.key.generation.type.ecc.ecdh;

View file

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.pgpainless.key.generation.type.ecdsa; package org.pgpainless.key.generation.type.ecc.ecdsa;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
@ -21,7 +21,7 @@ import javax.annotation.Nonnull;
import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec; import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec;
import org.pgpainless.algorithm.PublicKeyAlgorithm; 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; import org.pgpainless.key.generation.type.KeyType;
public final class ECDSA implements KeyType { public final class ECDSA implements KeyType {
@ -50,4 +50,9 @@ public final class ECDSA implements KeyType {
public AlgorithmParameterSpec getAlgorithmSpec() { public AlgorithmParameterSpec getAlgorithmSpec() {
return new ECNamedCurveGenParameterSpec(curve.getName()); return new ECNamedCurveGenParameterSpec(curve.getName());
} }
@Override
public boolean canCertify() {
return true;
}
} }

View file

@ -16,4 +16,4 @@
/** /**
* Classes related to ECDSA. * Classes related to ECDSA.
*/ */
package org.pgpainless.key.generation.type.ecdsa; package org.pgpainless.key.generation.type.ecc.ecdsa;

View file

@ -21,6 +21,9 @@ import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec;
import org.pgpainless.algorithm.PublicKeyAlgorithm; import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.KeyType;
/**
* Edwards-curve Digital Signature Algorithm (EdDSA).
*/
public final class EdDSA implements KeyType { public final class EdDSA implements KeyType {
private final EdDSACurve curve; private final EdDSACurve curve;
@ -47,4 +50,9 @@ public final class EdDSA implements KeyType {
public AlgorithmParameterSpec getAlgorithmSpec() { public AlgorithmParameterSpec getAlgorithmSpec() {
return new ECNamedCurveGenParameterSpec(curve.getName()); return new ECNamedCurveGenParameterSpec(curve.getName());
} }
@Override
public boolean canCertify() {
return true;
}
} }

View file

@ -48,4 +48,9 @@ public final class ElGamal_ENCRYPT implements KeyType {
public AlgorithmParameterSpec getAlgorithmSpec() { public AlgorithmParameterSpec getAlgorithmSpec() {
return new ElGamalParameterSpec(length.getP(), length.getG()); return new ElGamalParameterSpec(length.getP(), length.getG());
} }
@Override
public boolean canCertify() {
return false;
}
} }

View file

@ -49,4 +49,9 @@ public class ElGamal_GENERAL implements KeyType {
public AlgorithmParameterSpec getAlgorithmSpec() { public AlgorithmParameterSpec getAlgorithmSpec() {
return new ElGamalParameterSpec(length.getP(), length.getG()); return new ElGamalParameterSpec(length.getP(), length.getG());
} }
@Override
public boolean canCertify() {
return false;
}
} }

View file

@ -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;
}
}

View file

@ -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;

View file

@ -51,4 +51,9 @@ public class RSA implements KeyType {
public AlgorithmParameterSpec getAlgorithmSpec() { public AlgorithmParameterSpec getAlgorithmSpec() {
return new RSAKeyGenParameterSpec(length.getLength(), RSAKeyGenParameterSpec.F4); return new RSAKeyGenParameterSpec(length.getLength(), RSAKeyGenParameterSpec.F4);
} }
@Override
public boolean canCertify() {
return true;
}
} }

View file

@ -47,4 +47,9 @@ public final class XDH implements KeyType {
public AlgorithmParameterSpec getAlgorithmSpec() { public AlgorithmParameterSpec getAlgorithmSpec() {
return new ECNamedCurveGenParameterSpec(curve.getName()); return new ECNamedCurveGenParameterSpec(curve.getName());
} }
@Override
public boolean canCertify() {
return false;
}
} }

View file

@ -34,8 +34,8 @@ import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.generation.KeySpec; import org.pgpainless.key.generation.KeySpec;
import org.pgpainless.key.generation.type.ecdsa.ECDSA; import org.pgpainless.key.generation.type.ecc.ecdsa.ECDSA;
import org.pgpainless.key.generation.type.EllipticCurve; import org.pgpainless.key.generation.type.ecc.EllipticCurve;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;