Paul Bakker | f725a88 | 2009-07-08 06:43:10 +0000 | [diff] [blame] | 1 | BEGIN_HEADER |
| 2 | #include <polarssl/xtea.h> |
| 3 | END_HEADER |
| 4 | |
| 5 | BEGIN_CASE |
| 6 | xtea_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string |
| 7 | { |
| 8 | unsigned char key_str[100]; |
| 9 | unsigned char src_str[100]; |
| 10 | unsigned char dst_str[100]; |
| 11 | unsigned char output[100]; |
| 12 | xtea_context ctx; |
| 13 | |
| 14 | memset(key_str, 0x00, 100); |
| 15 | memset(src_str, 0x00, 100); |
| 16 | memset(dst_str, 0x00, 100); |
| 17 | memset(output, 0x00, 100); |
| 18 | |
| 19 | unhexify( key_str, {hex_key_string} ); |
| 20 | unhexify( src_str, {hex_src_string} ); |
| 21 | |
| 22 | xtea_setup( &ctx, key_str ); |
| 23 | xtea_crypt_ecb( &ctx, XTEA_ENCRYPT, src_str, output ); |
| 24 | hexify( dst_str, output, 8 ); |
| 25 | |
| 26 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 27 | } |
| 28 | END_CASE |
| 29 | |
| 30 | BEGIN_CASE |
| 31 | xtea_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string |
| 32 | { |
| 33 | unsigned char key_str[100]; |
| 34 | unsigned char src_str[100]; |
| 35 | unsigned char dst_str[100]; |
| 36 | unsigned char output[100]; |
| 37 | xtea_context ctx; |
| 38 | |
| 39 | memset(key_str, 0x00, 100); |
| 40 | memset(src_str, 0x00, 100); |
| 41 | memset(dst_str, 0x00, 100); |
| 42 | memset(output, 0x00, 100); |
| 43 | |
| 44 | unhexify( key_str, {hex_key_string} ); |
| 45 | unhexify( src_str, {hex_src_string} ); |
| 46 | |
| 47 | xtea_setup( &ctx, key_str ); |
| 48 | xtea_crypt_ecb( &ctx, XTEA_DECRYPT, src_str, output ); |
| 49 | hexify( dst_str, output, 8 ); |
| 50 | |
| 51 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 52 | } |
| 53 | END_CASE |
| 54 | |
| 55 | BEGIN_CASE |
| 56 | xtea_selftest: |
| 57 | { |
| 58 | TEST_ASSERT( xtea_self_test( 0 ) == 0 ); |
| 59 | } |
| 60 | END_CASE |