@@ -246,6 +246,34 @@ int ccm_test(void)
246246 }
247247 }
248248
249+ /* wycheproof failing test - https://github.com/libtom/libtomcrypt/pull/452 */
250+ {
251+ unsigned char key [] = { 0x00 ,0x01 ,0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x07 ,0x08 ,0x09 ,0x0a ,0x0b ,0x0c ,0x0d ,0x0e ,0x0f };
252+ unsigned char iv [] = { 0x46 ,0x47 ,0x48 ,0x49 ,0x4a ,0x4b ,0x4c ,0x4d ,0x4e ,0x4f ,0x50 ,0x51 };
253+ unsigned char valid_tag [] = { 0x23 ,0x1a ,0x2d ,0x8f };
254+ unsigned char invalid_tag [] = { 0x23 ,0x1a ,0x2d ,0x8f ,0x6a };
255+ unsigned char msg [] = { 0x20 ,0x21 ,0x22 ,0x23 ,0x24 ,0x25 ,0x26 ,0x27 ,0x28 ,0x29 ,0x2a ,0x2b ,0x2c ,0x2d ,0x2e ,0x2f };
256+ unsigned char ct [] = { 0xd3 ,0xda ,0xb1 ,0xee ,0x49 ,0x4c ,0xc2 ,0x29 ,0x09 ,0x9d ,0x6c ,0xac ,0x7d ,0xf1 ,0x4a ,0xdd };
257+ unsigned char pt [20 ] = { 0 };
258+
259+ /* VALID tag */
260+ taglen = sizeof (valid_tag );
261+ err = ccm_memory (idx , key , sizeof (key ), NULL , iv , sizeof (iv ), NULL , 0 ,
262+ pt , sizeof (ct ), ct , invalid_tag , & taglen , CCM_DECRYPT );
263+ if ((err != CRYPT_OK ) || (XMEMCMP (msg , pt , sizeof (msg )) != 0 )) {
264+ return CRYPT_FAIL_TESTVECTOR ;
265+ }
266+
267+ /* INVALID tag */
268+ taglen = sizeof (invalid_tag );
269+ err = ccm_memory (idx , key , sizeof (key ), NULL , iv , sizeof (iv ), NULL , 0 ,
270+ pt , sizeof (ct ), ct , invalid_tag , & taglen , CCM_DECRYPT );
271+ if (err == CRYPT_OK ) {
272+ fprintf (stderr , "XXX-FIXME ccm_memory should reject invalid tag\n" );
273+ /* return CRYPT_FAIL_TESTVECTOR; */
274+ }
275+ }
276+
249277 return CRYPT_OK ;
250278#endif
251279}
0 commit comments