Skip to content

Test PGPSignatures with LegacyEd25519 keys with short MPIs - #1706

Closed
vanitasvitae wants to merge 1 commit into
bcgit:mainfrom
pgpainless:fixEd25519SignatureParsing
Closed

Test PGPSignatures with LegacyEd25519 keys with short MPIs#1706
vanitasvitae wants to merge 1 commit into
bcgit:mainfrom
pgpainless:fixEd25519SignatureParsing

Conversation

@vanitasvitae

Copy link
Copy Markdown
Contributor

With legacy ed25519 we need to detect the curve (curve25519 / curve448) based on the length of the encoding (see #1675, most notably 105dbef).

However, I noticed, that some ed25519 signatures MPIs are shorter than the expected 2*32 octets (leading 0s), resulting in the code misinterpreting the signature as an ed448 signature. This in turn causes signature verification failures for good signatures.

This patch catches this edge case by allowing short MPIs.

{
byte[] a = BigIntegers.asUnsignedByteArray(sigValues[0].getValue());
byte[] b = BigIntegers.asUnsignedByteArray(sigValues[1].getValue());
if (a.length + b.length == Ed25519.SIGNATURE_SIZE)

@vanitasvitae vanitasvitae Jun 12, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, a.length or b.length could be 31 instead of the the expected 32.
Since Ed25519 signatures are shorter than Ed448 signatures, the new comparison should hold.

@vanitasvitae

Copy link
Copy Markdown
Contributor Author

The test vector (see as PGP packet here) demonstrates the issue by having a short 31-octet r value.

@vanitasvitae
vanitasvitae force-pushed the fixEd25519SignatureParsing branch 2 times, most recently from 4894655 to 32ecff8 Compare August 8, 2024 10:24
@vanitasvitae

Copy link
Copy Markdown
Contributor Author

Fix is already part of main, so I reduced the PR to only contain the test.

@vanitasvitae vanitasvitae changed the title Fix PGPSignatures with LegacyEd25519 keys with short MPIs Test PGPSignatures with LegacyEd25519 keys with short MPIs Aug 22, 2024
hubot pushed a commit that referenced this pull request Sep 11, 2024
#1706 Test PGPSignatures with LegacyEd25519 keys with short MPIs

See merge request root/bc-java!31
@vanitasvitae

Copy link
Copy Markdown
Contributor Author

In main as c51be49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants