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