Skip to content

Commit 105dbef

Browse files
committed
Fix legacy Ed448 signature field parsing
1 parent 3b66bb1 commit 105dbef

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pg/src/main/java/org/bouncycastle/openpgp/PGPSignature.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.bouncycastle.bcpg.SignatureSubpacket;
2020
import org.bouncycastle.bcpg.TrustPacket;
2121
import org.bouncycastle.math.ec.rfc8032.Ed25519;
22+
import org.bouncycastle.math.ec.rfc8032.Ed448;
2223
import org.bouncycastle.openpgp.operator.PGPContentVerifier;
2324
import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilder;
2425
import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilderProvider;
@@ -454,9 +455,19 @@ else if (getKeyAlgorithm() == PublicKeyAlgorithmTags.EDDSA_LEGACY)
454455
{
455456
byte[] a = BigIntegers.asUnsignedByteArray(sigValues[0].getValue());
456457
byte[] b = BigIntegers.asUnsignedByteArray(sigValues[1].getValue());
457-
signature = new byte[Ed25519.SIGNATURE_SIZE];
458-
System.arraycopy(a, 0, signature, Ed25519.PUBLIC_KEY_SIZE - a.length, a.length);
459-
System.arraycopy(b, 0, signature, Ed25519.SIGNATURE_SIZE - b.length, b.length);
458+
if (a.length + b.length == Ed25519.SIGNATURE_SIZE)
459+
{
460+
signature = new byte[Ed25519.SIGNATURE_SIZE];
461+
System.arraycopy(a, 0, signature, Ed25519.PUBLIC_KEY_SIZE - a.length, a.length);
462+
System.arraycopy(b, 0, signature, Ed25519.SIGNATURE_SIZE - b.length, b.length);
463+
}
464+
else
465+
{
466+
signature = new byte[Ed448.SIGNATURE_SIZE];
467+
System.arraycopy(a, 0, signature, Ed448.PUBLIC_KEY_SIZE - a.length, a.length);
468+
System.arraycopy(b, 0, signature, Ed448.SIGNATURE_SIZE - b.length, b.length);
469+
}
470+
460471
}
461472
else
462473
{

0 commit comments

Comments
 (0)