Skip to content

Commit 2599618

Browse files
committed
wycheproof failing test - invalid/modified tag
1 parent 60eb5d0 commit 2599618

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/encauth/gcm/gcm_test.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,36 @@ int gcm_test(void)
380380
}
381381

382382
}
383+
384+
/* wycheproof failing test - https://github.com/libtom/libtomcrypt/pull/451 */
385+
{
386+
unsigned char key[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f };
387+
unsigned char iv[] = { 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b };
388+
unsigned char valid_tag[] = { 0xd8,0x84,0x7d,0xbc,0x32,0x6a,0x06,0xe9,0x88,0xc7,0x7a,0xd3,0x86,0x3e,0x60,0x83 };
389+
unsigned char invalid_tag[] = { 0xd9,0x84,0x7d,0xbc,0x32,0x6a,0x06,0xe9,0x88,0xc7,0x7a,0xd3,0x86,0x3e,0x60,0x83 };
390+
unsigned char msg[] = { 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f };
391+
unsigned char ct[] = { 0xeb,0x15,0x6d,0x08,0x1e,0xd6,0xb6,0xb5,0x5f,0x46,0x12,0xf0,0x21,0xd8,0x7b,0x39 };
392+
unsigned char pt[20] = { 0 };
393+
unsigned long taglen;
394+
395+
/* VALID tag */
396+
taglen = sizeof(valid_tag);
397+
err = gcm_memory(idx, key, sizeof(key), iv, sizeof(iv), NULL, 0,
398+
pt, sizeof(ct), ct, invalid_tag, &taglen, GCM_DECRYPT);
399+
if ((err != CRYPT_OK) || (XMEMCMP(msg, pt, sizeof(msg)) != 0)) {
400+
return CRYPT_FAIL_TESTVECTOR;
401+
}
402+
403+
/* INVALID tag */
404+
taglen = sizeof(invalid_tag);
405+
err = gcm_memory(idx, key, sizeof(key), iv, sizeof(iv), NULL, 0,
406+
pt, sizeof(ct), ct, invalid_tag, &taglen, GCM_DECRYPT);
407+
if (err == CRYPT_OK) {
408+
fprintf(stderr, "XXX-FIXME gcm_memory should reject invalid tag\n");
409+
/* return CRYPT_FAIL_TESTVECTOR; */
410+
}
411+
}
412+
383413
return CRYPT_OK;
384414
#endif
385415
}

0 commit comments

Comments
 (0)