Skip to content

Commit a6c6492

Browse files
Valerii Chubarsjaeckel
authored andcommitted
ed25519: Add testcase for segfault on verify
In case when the signature is not verified the "mlen" variable is equal to ULONG_MAX. When LTC_CLEAN_STACK has been defined this results in a segmentation fault. Signed-off-by: Valerii Chubar <[email protected]> Signed-off-by: Sergiy Kibrik <[email protected]>
1 parent 8fd5dad commit a6c6492

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/ed25519_test.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
#ifdef LTC_CURVE25519
1111

12+
static void xor_shuffle(char *buf, int size, int change)
13+
{
14+
for(int i = 0; i < size; i++)
15+
buf[i] ^= change;
16+
}
17+
1218
static int s_rfc_8410_10_test(void)
1319
{
1420
const struct {
@@ -202,6 +208,13 @@ static int s_rfc_8032_7_1_test(void)
202208
DO(ed25519_verify(msg, mlen, sig, siglen, &ret, &key));
203209
DO(do_compare_testvector(&ret, sizeof(ret), &should, sizeof(should), "Ed25519 RFC8032 7.1 - verify w/ privkey", n));
204210

211+
xor_shuffle(sig, siglen, 0x8);
212+
DO( ed25519_verify(msg, mlen, sig, siglen, &ret, &key));
213+
ENSUREX(ret != 1, "ed25519_verify is expected to fail on the modified signature");
214+
xor_shuffle(msg, mlen, 0xf);
215+
DO( ed25519_verify(msg, mlen, sig, siglen, &ret, &key));
216+
ENSUREX(ret != 1, "ed25519_verify is expected to fail on the modified message");
217+
205218
plen = sizeof(pub);
206219
DO(base16_decode(rfc_8032_7_1[n].public_key, XSTRLEN(rfc_8032_7_1[n].public_key), pub, &plen));
207220
mlen = sizeof(msg);

0 commit comments

Comments
 (0)