From 5f289f4fe19fa5b2eba49d88035d0af46e973899 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 11 Dec 2020 18:14:36 +0100 Subject: [PATCH] ElGamal: Deprecate GENERAL --- .../algorithm/PublicKeyAlgorithm.java | 5 ++++ .../type/elgamal/ElGamal_ENCRYPT.java | 25 ++++++++++++++++--- .../type/elgamal/ElGamal_GENERAL.java | 1 + .../EncryptDecryptTest.java | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/algorithm/PublicKeyAlgorithm.java b/pgpainless-core/src/main/java/org/pgpainless/algorithm/PublicKeyAlgorithm.java index 63d88890..f22954e5 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/algorithm/PublicKeyAlgorithm.java +++ b/pgpainless-core/src/main/java/org/pgpainless/algorithm/PublicKeyAlgorithm.java @@ -34,6 +34,11 @@ public enum PublicKeyAlgorithm { EC (PublicKeyAlgorithmTags.EC), ECDH (PublicKeyAlgorithmTags.ECDH), ECDSA (PublicKeyAlgorithmTags.ECDSA), + + /** + * @deprecated see https://tools.ietf.org/html/rfc4880#section-13.8 + */ + @Deprecated ELGAMAL_GENERAL (PublicKeyAlgorithmTags.ELGAMAL_GENERAL), DIFFIE_HELLMAN (PublicKeyAlgorithmTags.DIFFIE_HELLMAN), EDDSA (PublicKeyAlgorithmTags.EDDSA), 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 cb3008de..22603377 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 @@ -15,18 +15,37 @@ */ package org.pgpainless.key.generation.type.elgamal; +import java.security.spec.AlgorithmParameterSpec; import javax.annotation.Nonnull; +import org.bouncycastle.jce.spec.ElGamalParameterSpec; import org.pgpainless.algorithm.PublicKeyAlgorithm; +import org.pgpainless.key.generation.type.KeyType; -public class ElGamal_ENCRYPT extends ElGamal_GENERAL { +public final class ElGamal_ENCRYPT implements KeyType { - ElGamal_ENCRYPT(@Nonnull ElGamalLength length) { - super(length); + private final ElGamalLength length; + + private ElGamal_ENCRYPT(@Nonnull ElGamalLength length) { + this.length = length; + } + + public static ElGamal_ENCRYPT withLength(ElGamalLength length) { + return new ElGamal_ENCRYPT(length); + } + + @Override + public String getName() { + return "ElGamal"; } @Override public PublicKeyAlgorithm getAlgorithm() { return PublicKeyAlgorithm.ELGAMAL_ENCRYPT; } + + @Override + public AlgorithmParameterSpec getAlgorithmSpec() { + return new ElGamalParameterSpec(length.getP(), length.getG()); + } } 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 f12e0849..1a03a647 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 @@ -22,6 +22,7 @@ import org.bouncycastle.jce.spec.ElGamalParameterSpec; import org.pgpainless.algorithm.PublicKeyAlgorithm; import org.pgpainless.key.generation.type.KeyType; +@Deprecated public class ElGamal_GENERAL implements KeyType { private final ElGamalLength length; diff --git a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java index 6be7a8f3..7a167882 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java @@ -68,6 +68,7 @@ public class EncryptDecryptTest { "Unfold the imagined happiness that both\n" + "Receive in either by this dear encounter."; + @SuppressWarnings("deprecation") @Test public void freshKeysRsaToElGamalTest() throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {