LibCrypto: Reject wrongly sized inputs in Ed25519::verify

verify() copied two 32-byte halves out of the signature and read 32
bytes of the public key without looking at the size of either span, so
a shorter buffer was read past its end. SSHServer, LibTLS and LibWeb
all pass buffers whose size is chosen by the peer.
This commit is contained in:
Chandan MK authored and Lucas Chollet committed 2026-10-01 13:38:23 +02:00
1 parent 9e83d4e12e
commit 3bb1891bea
2 files changed
+31

No files matched your search

+28
View File
@@ -154,3 +154,31 @@ TEST_CASE(TEST_SHA_ABC)
ed25519_test(public_key, private_key, message, expected_signature);
}
TEST_CASE(verify_rejects_inputs_of_the_wrong_size)
{
// https://datatracker.ietf.org/doc/html/rfc8032#section-7.1
Array<u8, 32> public_key = {
0xd7, 0x5a, 0x98, 0x01, 0x82, 0xb1, 0x0a, 0xb7,
0xd5, 0x4b, 0xfe, 0xd3, 0xc9, 0x64, 0x07, 0x3a,
0x0e, 0xe1, 0x72, 0xf3, 0xda, 0xa6, 0x23, 0x25,
0xaf, 0x02, 0x1a, 0x68, 0xf7, 0x07, 0x51, 0x1a
};
Array<u8, 0> message = {};
Array<u8, 64> signature = {
0xe5, 0x56, 0x43, 0x00, 0xc3, 0x60, 0xac, 0x72,
0x90, 0x86, 0xe2, 0xcc, 0x80, 0x6e, 0x82, 0x8a,
0x84, 0x87, 0x7f, 0x1e, 0xb8, 0xe5, 0xd9, 0x74,
0xd8, 0x73, 0xe0, 0x65, 0x22, 0x49, 0x01, 0x55,
0x5f, 0xb8, 0x82, 0x15, 0x90, 0xa3, 0x3b, 0xac,
0xc6, 0x1e, 0x39, 0x70, 0x1c, 0xf9, 0xb4, 0x6b,
0xd2, 0x5b, 0xf5, 0xf0, 0x59, 0x5b, 0xbe, 0x24,
0x65, 0x51, 0x41, 0x43, 0x8e, 0x7a, 0x10, 0x0b
};
EXPECT(Crypto::Curves::Ed25519::verify(public_key, signature, message));
EXPECT(!Crypto::Curves::Ed25519::verify(public_key, signature.span().trim(63), message));
EXPECT(!Crypto::Curves::Ed25519::verify(public_key.span().trim(31), signature, message));
}