Skip to content

Commit 4894655

Browse files
committed
Fix parsing of legacy ed25519 keys with short MPIs
1 parent 32ecff8 commit 4894655

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -495,18 +495,19 @@ else if (getKeyAlgorithm() == PublicKeyAlgorithmTags.EDDSA_LEGACY)
495495
{
496496
byte[] a = BigIntegers.asUnsignedByteArray(sigValues[0].getValue());
497497
byte[] b = BigIntegers.asUnsignedByteArray(sigValues[1].getValue());
498-
if (a.length + b.length > Ed25519.SIGNATURE_SIZE)
499-
{
500-
signature = new byte[Ed448.SIGNATURE_SIZE];
501-
System.arraycopy(a, 0, signature, Ed448.PUBLIC_KEY_SIZE - a.length, a.length);
502-
System.arraycopy(b, 0, signature, Ed448.SIGNATURE_SIZE - b.length, b.length);
503-
}
504-
else
498+
499+
if (a.length + b.length <= Ed25519.SIGNATURE_SIZE)
505500
{
506501
signature = new byte[Ed25519.SIGNATURE_SIZE];
507502
System.arraycopy(a, 0, signature, Ed25519.PUBLIC_KEY_SIZE - a.length, a.length);
508503
System.arraycopy(b, 0, signature, Ed25519.SIGNATURE_SIZE - b.length, b.length);
509504
}
505+
else
506+
{
507+
signature = new byte[Ed448.SIGNATURE_SIZE];
508+
System.arraycopy(a, 0, signature, Ed448.PUBLIC_KEY_SIZE - a.length, a.length);
509+
System.arraycopy(b, 0, signature, Ed448.SIGNATURE_SIZE - b.length, b.length);
510+
}
510511
}
511512
else
512513
{

0 commit comments

Comments
 (0)