mbed TLS Build
tests/suites/test_suite_xtea.function@0:cdf462088d13, 2017-01-05 (annotated)
- Committer:
- markrad
- Date:
- Thu Jan 05 00:18:44 2017 +0000
- Revision:
- 0:cdf462088d13
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
markrad | 0:cdf462088d13 | 1 | /* BEGIN_HEADER */ |
markrad | 0:cdf462088d13 | 2 | #include "mbedtls/xtea.h" |
markrad | 0:cdf462088d13 | 3 | /* END_HEADER */ |
markrad | 0:cdf462088d13 | 4 | |
markrad | 0:cdf462088d13 | 5 | /* BEGIN_DEPENDENCIES |
markrad | 0:cdf462088d13 | 6 | * depends_on:MBEDTLS_XTEA_C |
markrad | 0:cdf462088d13 | 7 | * END_DEPENDENCIES |
markrad | 0:cdf462088d13 | 8 | */ |
markrad | 0:cdf462088d13 | 9 | |
markrad | 0:cdf462088d13 | 10 | /* BEGIN_CASE */ |
markrad | 0:cdf462088d13 | 11 | void xtea_encrypt_ecb( char *hex_key_string, char *hex_src_string, |
markrad | 0:cdf462088d13 | 12 | char *hex_dst_string ) |
markrad | 0:cdf462088d13 | 13 | { |
markrad | 0:cdf462088d13 | 14 | unsigned char key_str[100]; |
markrad | 0:cdf462088d13 | 15 | unsigned char src_str[100]; |
markrad | 0:cdf462088d13 | 16 | unsigned char dst_str[100]; |
markrad | 0:cdf462088d13 | 17 | unsigned char output[100]; |
markrad | 0:cdf462088d13 | 18 | mbedtls_xtea_context ctx; |
markrad | 0:cdf462088d13 | 19 | |
markrad | 0:cdf462088d13 | 20 | memset(key_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 21 | memset(src_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 22 | memset(dst_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 23 | memset(output, 0x00, 100); |
markrad | 0:cdf462088d13 | 24 | |
markrad | 0:cdf462088d13 | 25 | unhexify( key_str, hex_key_string ); |
markrad | 0:cdf462088d13 | 26 | unhexify( src_str, hex_src_string ); |
markrad | 0:cdf462088d13 | 27 | |
markrad | 0:cdf462088d13 | 28 | mbedtls_xtea_setup( &ctx, key_str ); |
markrad | 0:cdf462088d13 | 29 | TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str, output ) == 0 ); |
markrad | 0:cdf462088d13 | 30 | hexify( dst_str, output, 8 ); |
markrad | 0:cdf462088d13 | 31 | |
markrad | 0:cdf462088d13 | 32 | TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 ); |
markrad | 0:cdf462088d13 | 33 | } |
markrad | 0:cdf462088d13 | 34 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 35 | |
markrad | 0:cdf462088d13 | 36 | /* BEGIN_CASE */ |
markrad | 0:cdf462088d13 | 37 | void xtea_decrypt_ecb( char *hex_key_string, char *hex_src_string, |
markrad | 0:cdf462088d13 | 38 | char *hex_dst_string ) |
markrad | 0:cdf462088d13 | 39 | { |
markrad | 0:cdf462088d13 | 40 | unsigned char key_str[100]; |
markrad | 0:cdf462088d13 | 41 | unsigned char src_str[100]; |
markrad | 0:cdf462088d13 | 42 | unsigned char dst_str[100]; |
markrad | 0:cdf462088d13 | 43 | unsigned char output[100]; |
markrad | 0:cdf462088d13 | 44 | mbedtls_xtea_context ctx; |
markrad | 0:cdf462088d13 | 45 | |
markrad | 0:cdf462088d13 | 46 | memset(key_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 47 | memset(src_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 48 | memset(dst_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 49 | memset(output, 0x00, 100); |
markrad | 0:cdf462088d13 | 50 | |
markrad | 0:cdf462088d13 | 51 | unhexify( key_str, hex_key_string ); |
markrad | 0:cdf462088d13 | 52 | unhexify( src_str, hex_src_string ); |
markrad | 0:cdf462088d13 | 53 | |
markrad | 0:cdf462088d13 | 54 | mbedtls_xtea_setup( &ctx, key_str ); |
markrad | 0:cdf462088d13 | 55 | TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_DECRYPT, src_str, output ) == 0 ); |
markrad | 0:cdf462088d13 | 56 | hexify( dst_str, output, 8 ); |
markrad | 0:cdf462088d13 | 57 | |
markrad | 0:cdf462088d13 | 58 | TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 ); |
markrad | 0:cdf462088d13 | 59 | } |
markrad | 0:cdf462088d13 | 60 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 61 | |
markrad | 0:cdf462088d13 | 62 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
markrad | 0:cdf462088d13 | 63 | void xtea_encrypt_cbc( char *hex_key_string, char *hex_iv_string, |
markrad | 0:cdf462088d13 | 64 | char *hex_src_string, char *hex_dst_string ) |
markrad | 0:cdf462088d13 | 65 | { |
markrad | 0:cdf462088d13 | 66 | unsigned char key_str[100]; |
markrad | 0:cdf462088d13 | 67 | unsigned char src_str[100]; |
markrad | 0:cdf462088d13 | 68 | unsigned char dst_str[100]; |
markrad | 0:cdf462088d13 | 69 | unsigned char iv_str[100]; |
markrad | 0:cdf462088d13 | 70 | unsigned char output[100]; |
markrad | 0:cdf462088d13 | 71 | size_t len; |
markrad | 0:cdf462088d13 | 72 | mbedtls_xtea_context ctx; |
markrad | 0:cdf462088d13 | 73 | |
markrad | 0:cdf462088d13 | 74 | memset(key_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 75 | memset(src_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 76 | memset(dst_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 77 | memset(iv_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 78 | memset(output, 0x00, 100); |
markrad | 0:cdf462088d13 | 79 | |
markrad | 0:cdf462088d13 | 80 | unhexify( key_str, hex_key_string ); |
markrad | 0:cdf462088d13 | 81 | unhexify( iv_str, hex_iv_string ); |
markrad | 0:cdf462088d13 | 82 | len = unhexify( src_str, hex_src_string ); |
markrad | 0:cdf462088d13 | 83 | |
markrad | 0:cdf462088d13 | 84 | mbedtls_xtea_setup( &ctx, key_str ); |
markrad | 0:cdf462088d13 | 85 | TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_ENCRYPT, len, iv_str, |
markrad | 0:cdf462088d13 | 86 | src_str, output ) == 0 ); |
markrad | 0:cdf462088d13 | 87 | hexify( dst_str, output, len ); |
markrad | 0:cdf462088d13 | 88 | |
markrad | 0:cdf462088d13 | 89 | TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 ); |
markrad | 0:cdf462088d13 | 90 | } |
markrad | 0:cdf462088d13 | 91 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 92 | |
markrad | 0:cdf462088d13 | 93 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
markrad | 0:cdf462088d13 | 94 | void xtea_decrypt_cbc( char *hex_key_string, char *hex_iv_string, |
markrad | 0:cdf462088d13 | 95 | char *hex_src_string, char *hex_dst_string ) |
markrad | 0:cdf462088d13 | 96 | { |
markrad | 0:cdf462088d13 | 97 | unsigned char key_str[100]; |
markrad | 0:cdf462088d13 | 98 | unsigned char src_str[100]; |
markrad | 0:cdf462088d13 | 99 | unsigned char dst_str[100]; |
markrad | 0:cdf462088d13 | 100 | unsigned char iv_str[100]; |
markrad | 0:cdf462088d13 | 101 | unsigned char output[100]; |
markrad | 0:cdf462088d13 | 102 | size_t len; |
markrad | 0:cdf462088d13 | 103 | mbedtls_xtea_context ctx; |
markrad | 0:cdf462088d13 | 104 | |
markrad | 0:cdf462088d13 | 105 | memset(key_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 106 | memset(src_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 107 | memset(dst_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 108 | memset(iv_str, 0x00, 100); |
markrad | 0:cdf462088d13 | 109 | memset(output, 0x00, 100); |
markrad | 0:cdf462088d13 | 110 | |
markrad | 0:cdf462088d13 | 111 | unhexify( key_str, hex_key_string ); |
markrad | 0:cdf462088d13 | 112 | unhexify( iv_str, hex_iv_string ); |
markrad | 0:cdf462088d13 | 113 | len = unhexify( src_str, hex_src_string ); |
markrad | 0:cdf462088d13 | 114 | |
markrad | 0:cdf462088d13 | 115 | mbedtls_xtea_setup( &ctx, key_str ); |
markrad | 0:cdf462088d13 | 116 | TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_DECRYPT, len, iv_str, |
markrad | 0:cdf462088d13 | 117 | src_str, output ) == 0 ); |
markrad | 0:cdf462088d13 | 118 | hexify( dst_str, output, len ); |
markrad | 0:cdf462088d13 | 119 | |
markrad | 0:cdf462088d13 | 120 | TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 ); |
markrad | 0:cdf462088d13 | 121 | } |
markrad | 0:cdf462088d13 | 122 | /* END_CASE */ |
markrad | 0:cdf462088d13 | 123 | |
markrad | 0:cdf462088d13 | 124 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
markrad | 0:cdf462088d13 | 125 | void xtea_selftest() |
markrad | 0:cdf462088d13 | 126 | { |
markrad | 0:cdf462088d13 | 127 | TEST_ASSERT( mbedtls_xtea_self_test( 1 ) == 0 ); |
markrad | 0:cdf462088d13 | 128 | } |
markrad | 0:cdf462088d13 | 129 | /* END_CASE */ |