Skip to content

Commit d07266b

Browse files
committed
Fix signing using legacy Ed448 keys
1 parent 105dbef commit d07266b

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

pg/src/main/java/org/bouncycastle/openpgp/operator/bc/BcImplProvider.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.bouncycastle.crypto.engines.RFC3394WrapEngine;
3434
import org.bouncycastle.crypto.engines.RSABlindedEngine;
3535
import org.bouncycastle.crypto.engines.TwofishEngine;
36+
import org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters;
37+
import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters;
3638
import org.bouncycastle.crypto.signers.DSADigestSigner;
3739
import org.bouncycastle.crypto.signers.DSASigner;
3840
import org.bouncycastle.crypto.signers.ECDSASigner;
@@ -96,6 +98,14 @@ static Signer createSigner(int keyAlgorithm, int hashAlgorithm, CipherParameters
9698
case PublicKeyAlgorithmTags.ECDSA:
9799
return new DSADigestSigner(new ECDSASigner(), createDigest(hashAlgorithm));
98100
case PublicKeyAlgorithmTags.EDDSA_LEGACY:
101+
if (keyParam instanceof Ed25519PrivateKeyParameters || keyParam instanceof Ed25519PublicKeyParameters)
102+
{
103+
return new EdDsaSigner(new Ed25519Signer(), createDigest(hashAlgorithm));
104+
}
105+
else
106+
{
107+
return new EdDsaSigner(new Ed448Signer(new byte[0]), createDigest(hashAlgorithm));
108+
}
99109
case PublicKeyAlgorithmTags.Ed25519:
100110
return new EdDsaSigner(new Ed25519Signer(), createDigest(hashAlgorithm));
101111
case PublicKeyAlgorithmTags.Ed448:

pg/src/main/java/org/bouncycastle/openpgp/operator/jcajce/JcaPGPContentSignerBuilder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,14 @@ public PGPContentSigner build(final int signatureType, final long keyID, final P
9595
final PGPDigestCalculator digestCalculator = digestCalculatorProviderBuilder.build().get(hashAlgorithm);
9696
final PGPDigestCalculator edDigestCalculator = digestCalculatorProviderBuilder.build().get(hashAlgorithm);
9797
final Signature signature;
98-
signature = helper.createSignature(keyAlgorithm, hashAlgorithm);
98+
if (keyAlgorithm == PublicKeyAlgorithmTags.EDDSA_LEGACY && privateKey.getAlgorithm().equals("Ed448"))
99+
{
100+
signature = helper.createSignature(PublicKeyAlgorithmTags.Ed448, hashAlgorithm);
101+
}
102+
else
103+
{
104+
signature = helper.createSignature(keyAlgorithm, hashAlgorithm);
105+
}
99106

100107
try
101108
{

pg/src/main/java/org/bouncycastle/openpgp/operator/jcajce/JcaPGPContentVerifierBuilderProvider.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import java.security.SignatureException;
99
import java.security.interfaces.RSAPublicKey;
1010

11-
import org.bouncycastle.asn1.edec.EdECObjectIdentifiers;
12-
import org.bouncycastle.bcpg.EdDSAPublicBCPGKey;
1311
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
1412
import org.bouncycastle.jcajce.io.OutputStreamFactory;
1513
import org.bouncycastle.jcajce.util.DefaultJcaJceHelper;
@@ -73,11 +71,19 @@ public JcaPGPContentVerifierBuilder(int keyAlgorithm, int hashAlgorithm)
7371
public PGPContentVerifier build(final PGPPublicKey publicKey)
7472
throws PGPException
7573
{
76-
final Signature signature = helper.createSignature(keyAlgorithm, hashAlgorithm);
77-
7874
final PGPDigestCalculator digestCalculator = digestCalculatorProviderBuilder.build().get(hashAlgorithm);
7975
final PublicKey jcaKey = keyConverter.getPublicKey(publicKey);
8076

77+
final Signature signature;
78+
if (keyAlgorithm == PublicKeyAlgorithmTags.EDDSA_LEGACY && jcaKey.getAlgorithm().equals("Ed448"))
79+
{
80+
signature = helper.createSignature(PublicKeyAlgorithmTags.Ed448, hashAlgorithm);
81+
}
82+
else
83+
{
84+
signature = helper.createSignature(keyAlgorithm, hashAlgorithm);
85+
}
86+
8187
try
8288
{
8389
signature.initVerify(jcaKey);

0 commit comments

Comments
 (0)