blob: 748b50c364f79b0a5778b7d72c2adae2f6a2da67 [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Paul Bakkerf725a882009-07-08 06:43:10 +00002#include <polarssl/xtea.h>
Paul Bakker33b43f12013-08-20 11:48:36 +02003/* END_HEADER */
Paul Bakkerf725a882009-07-08 06:43:10 +00004
Paul Bakker33b43f12013-08-20 11:48:36 +02005/* BEGIN_DEPENDENCIES
6 *depends_on:POLARSSL_XTEA_C
7 * END_DEPENDENCIES
8 */
Paul Bakker5690efc2011-05-26 13:16:06 +00009
Paul Bakker33b43f12013-08-20 11:48:36 +020010/* BEGIN_CASE */
11void xtea_encrypt_ecb( char *hex_key_string, char *hex_src_string,
12 char *hex_dst_string )
Paul Bakkerf725a882009-07-08 06:43:10 +000013{
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 Bakker33b43f12013-08-20 11:48:36 +020025 unhexify( key_str, hex_key_string );
26 unhexify( src_str, hex_src_string );
Paul Bakkerf725a882009-07-08 06:43:10 +000027
28 xtea_setup( &ctx, key_str );
Paul Bakkerf3ccc682010-03-18 21:21:02 +000029 TEST_ASSERT( xtea_crypt_ecb( &ctx, XTEA_ENCRYPT, src_str, output ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000030 hexify( dst_str, output, 8 );
31
Paul Bakker33b43f12013-08-20 11:48:36 +020032 TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000033}
Paul Bakker33b43f12013-08-20 11:48:36 +020034/* END_CASE */
Paul Bakkerf725a882009-07-08 06:43:10 +000035
Paul Bakker33b43f12013-08-20 11:48:36 +020036/* BEGIN_CASE */
37void xtea_decrypt_ecb( char *hex_key_string, char *hex_src_string,
38 char *hex_dst_string )
Paul Bakkerf725a882009-07-08 06:43:10 +000039{
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 Bakker33b43f12013-08-20 11:48:36 +020051 unhexify( key_str, hex_key_string );
52 unhexify( src_str, hex_src_string );
Paul Bakkerf725a882009-07-08 06:43:10 +000053
54 xtea_setup( &ctx, key_str );
Paul Bakkerf3ccc682010-03-18 21:21:02 +000055 TEST_ASSERT( xtea_crypt_ecb( &ctx, XTEA_DECRYPT, src_str, output ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000056 hexify( dst_str, output, 8 );
57
Paul Bakker33b43f12013-08-20 11:48:36 +020058 TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000059}
Paul Bakker33b43f12013-08-20 11:48:36 +020060/* END_CASE */
Paul Bakkerf725a882009-07-08 06:43:10 +000061
Paul Bakker33b43f12013-08-20 11:48:36 +020062/* BEGIN_CASE */
63void xtea_selftest()
Paul Bakkerf725a882009-07-08 06:43:10 +000064{
65 TEST_ASSERT( xtea_self_test( 0 ) == 0 );
66}
Paul Bakker33b43f12013-08-20 11:48:36 +020067/* END_CASE */