2013-01-20 18:25:22 -05:00
2013-01-20 18:55:10 -05:00
# define TEST_NAME "auth"
# include "cmptest.h"
2013-01-20 18:25:22 -05:00
/* "Test Case 2" from RFC 4231 */
unsigned char key [ 32 ] = " Jefe " ;
2013-04-27 00:52:21 -04:00
unsigned char c [ ] = " what do ya want for nothing? " ;
2013-01-20 18:25:22 -05:00
2014-09-16 17:59:19 -04:00
/* Hacker manifesto */
2014-09-16 18:25:38 -04:00
unsigned char key2 [ ] = " Another one got caught today, it's all over the papers. \" Teenager Arrested in Computer Crime Scandal \" , \" Hacker Arrested after Bank Tampering \" ... Damn kids. They're all alike. " ;
2014-09-16 17:59:19 -04:00
unsigned char a [ crypto_auth_BYTES ] ;
unsigned char a2 [ crypto_auth_hmacsha512_BYTES ] ;
2013-01-20 18:25:22 -05:00
2013-01-20 18:48:08 -05:00
int main ( void )
2013-01-20 18:25:22 -05:00
{
2014-09-16 17:59:19 -04:00
crypto_auth_hmacsha512_state st ;
2014-09-14 13:34:16 -04:00
int i ;
2014-09-13 17:11:12 -04:00
2014-09-14 14:32:55 -04:00
crypto_auth ( a , c , sizeof c - 1U , key ) ;
2014-09-16 17:59:19 -04:00
for ( i = 0 ; i < sizeof a ; + + i ) {
2014-09-14 14:32:55 -04:00
printf ( " ,0x%02x " , ( unsigned int ) a [ i ] ) ;
if ( i % 8 = = 7 )
printf ( " \n " ) ;
2014-09-14 13:34:16 -04:00
}
2014-09-16 17:59:19 -04:00
printf ( " \n " ) ;
crypto_auth_hmacsha512_init ( & st , key , sizeof key ) ;
crypto_auth_hmacsha512_update ( & st , c , 1U ) ;
crypto_auth_hmacsha512_update ( & st , c , sizeof c - 2U ) ;
crypto_auth_hmacsha512_final ( & st , a2 ) ;
for ( i = 0 ; i < sizeof a2 ; + + i ) {
printf ( " ,0x%02x " , ( unsigned int ) a2 [ i ] ) ;
if ( i % 8 = = 7 )
printf ( " \n " ) ;
}
printf ( " \n " ) ;
crypto_auth_hmacsha512_init ( & st , key2 , sizeof key2 ) ;
crypto_auth_hmacsha512_update ( & st , c , 1U ) ;
crypto_auth_hmacsha512_update ( & st , c , sizeof c - 2U ) ;
crypto_auth_hmacsha512_final ( & st , a2 ) ;
for ( i = 0 ; i < sizeof a2 ; + + i ) {
printf ( " ,0x%02x " , ( unsigned int ) a2 [ i ] ) ;
if ( i % 8 = = 7 )
printf ( " \n " ) ;
}
2014-09-13 17:11:12 -04:00
2014-09-14 13:34:16 -04:00
assert ( crypto_auth_bytes ( ) > 0U ) ;
assert ( crypto_auth_keybytes ( ) > 0U ) ;
assert ( strcmp ( crypto_auth_primitive ( ) , " hmacsha512256 " ) = = 0 ) ;
assert ( crypto_auth_hmacsha256_bytes ( ) > 0U ) ;
assert ( crypto_auth_hmacsha256_keybytes ( ) > 0U ) ;
assert ( crypto_auth_hmacsha512_bytes ( ) > 0U ) ;
assert ( crypto_auth_hmacsha512_keybytes ( ) > 0U ) ;
assert ( crypto_auth_hmacsha512256_bytes ( ) = = crypto_auth_bytes ( ) ) ;
assert ( crypto_auth_hmacsha512256_keybytes ( ) = = crypto_auth_keybytes ( ) ) ;
return 0 ;
2013-01-20 18:25:22 -05:00
}