test_suite_xtea.function 1.66 KB
Newer Older
1
/* BEGIN_HEADER */
Paul Bakker's avatar
Paul Bakker committed
2
#include <polarssl/xtea.h>
3
/* END_HEADER */
Paul Bakker's avatar
Paul Bakker committed
4

5
/* BEGIN_DEPENDENCIES
6
 * depends_on:POLARSSL_XTEA_C
7 8
 * END_DEPENDENCIES
 */
9

10 11 12
/* BEGIN_CASE */
void xtea_encrypt_ecb( char *hex_key_string, char *hex_src_string,
                       char *hex_dst_string )
Paul Bakker's avatar
Paul Bakker committed
13 14 15 16 17 18 19 20 21 22 23 24
{
    unsigned char key_str[100];
    unsigned char src_str[100];
    unsigned char dst_str[100];
    unsigned char output[100];
    xtea_context ctx;

    memset(key_str, 0x00, 100);
    memset(src_str, 0x00, 100);
    memset(dst_str, 0x00, 100);
    memset(output, 0x00, 100);

25 26
    unhexify( key_str, hex_key_string );
    unhexify( src_str, hex_src_string );
Paul Bakker's avatar
Paul Bakker committed
27 28

    xtea_setup( &ctx, key_str );
29
    TEST_ASSERT( xtea_crypt_ecb( &ctx, XTEA_ENCRYPT, src_str, output ) == 0 );
Paul Bakker's avatar
Paul Bakker committed
30 31
    hexify( dst_str, output, 8 );

32
    TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
Paul Bakker's avatar
Paul Bakker committed
33
}
34
/* END_CASE */
Paul Bakker's avatar
Paul Bakker committed
35

36 37 38
/* BEGIN_CASE */
void xtea_decrypt_ecb( char *hex_key_string, char *hex_src_string,
                       char *hex_dst_string )
Paul Bakker's avatar
Paul Bakker committed
39 40 41 42 43 44 45 46 47 48 49 50
{
    unsigned char key_str[100];
    unsigned char src_str[100];
    unsigned char dst_str[100];
    unsigned char output[100];
    xtea_context ctx;

    memset(key_str, 0x00, 100);
    memset(src_str, 0x00, 100);
    memset(dst_str, 0x00, 100);
    memset(output, 0x00, 100);

51 52
    unhexify( key_str, hex_key_string );
    unhexify( src_str, hex_src_string );
Paul Bakker's avatar
Paul Bakker committed
53 54

    xtea_setup( &ctx, key_str );
55
    TEST_ASSERT( xtea_crypt_ecb( &ctx, XTEA_DECRYPT, src_str, output ) == 0 );
Paul Bakker's avatar
Paul Bakker committed
56 57
    hexify( dst_str, output, 8 );

58
    TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
Paul Bakker's avatar
Paul Bakker committed
59
}
60
/* END_CASE */
Paul Bakker's avatar
Paul Bakker committed
61

62 63
/* BEGIN_CASE */
void xtea_selftest()
Paul Bakker's avatar
Paul Bakker committed
64 65 66
{
    TEST_ASSERT( xtea_self_test( 0 ) == 0 );
}
67
/* END_CASE */