blob: 7da890acbf521a63577871fca7bec783fce485e6 [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00002#include "mbedtls/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
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02006 * depends_on:MBEDTLS_XTEA_C
Paul Bakker33b43f12013-08-20 11:48:36 +02007 * END_DEPENDENCIES
8 */
Paul Bakker5690efc2011-05-26 13:16:06 +00009
Paul Bakker33b43f12013-08-20 11:48:36 +020010/* BEGIN_CASE */
Azim Khanf1aaec92017-05-30 14:23:15 +010011void xtea_encrypt_ecb( uint8_t * key_str, uint32_t key_str_len,
12 uint8_t * src_str, uint32_t src_str_len,
13 uint8_t * hex_dst_string, uint32_t hex_dst_string_len )
Paul Bakkerf725a882009-07-08 06:43:10 +000014{
Paul Bakkerf725a882009-07-08 06:43:10 +000015 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020016 mbedtls_xtea_context ctx;
Paul Bakkerf725a882009-07-08 06:43:10 +000017
Paul Bakkerf725a882009-07-08 06:43:10 +000018 memset(output, 0x00, 100);
19
Paul Bakkerf725a882009-07-08 06:43:10 +000020
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020021 mbedtls_xtea_setup( &ctx, key_str );
22 TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str, output ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000023
Azim Khanf1aaec92017-05-30 14:23:15 +010024 TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000025}
Paul Bakker33b43f12013-08-20 11:48:36 +020026/* END_CASE */
Paul Bakkerf725a882009-07-08 06:43:10 +000027
Paul Bakker33b43f12013-08-20 11:48:36 +020028/* BEGIN_CASE */
Azim Khanf1aaec92017-05-30 14:23:15 +010029void xtea_decrypt_ecb( uint8_t * key_str, uint32_t key_str_len,
30 uint8_t * src_str, uint32_t src_str_len,
31 uint8_t * hex_dst_string, uint32_t hex_dst_string_len )
Paul Bakkerf725a882009-07-08 06:43:10 +000032{
Paul Bakkerf725a882009-07-08 06:43:10 +000033 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034 mbedtls_xtea_context ctx;
Paul Bakkerf725a882009-07-08 06:43:10 +000035
Paul Bakkerf725a882009-07-08 06:43:10 +000036 memset(output, 0x00, 100);
37
Paul Bakkerf725a882009-07-08 06:43:10 +000038
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039 mbedtls_xtea_setup( &ctx, key_str );
40 TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_DECRYPT, src_str, output ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000041
Azim Khanf1aaec92017-05-30 14:23:15 +010042 TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000043}
Paul Bakker33b43f12013-08-20 11:48:36 +020044/* END_CASE */
Paul Bakkerf725a882009-07-08 06:43:10 +000045
Simon Butcher02c4a382016-06-23 02:41:31 +010046/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khanf1aaec92017-05-30 14:23:15 +010047void xtea_encrypt_cbc( uint8_t * key_str, uint32_t key_str_len,
48 uint8_t * iv_str, uint32_t iv_str_len,
49 uint8_t * src_str, uint32_t len,
50 uint8_t * hex_dst_string, uint32_t hex_dst_string_len )
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020051{
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020052 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053 mbedtls_xtea_context ctx;
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020054
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020055 memset(output, 0x00, 100);
56
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020057
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058 mbedtls_xtea_setup( &ctx, key_str );
59 TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_ENCRYPT, len, iv_str,
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020060 src_str, output ) == 0 );
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020061
Azim Khanf1aaec92017-05-30 14:23:15 +010062 TEST_ASSERT( hexcmp( output, hex_dst_string, len, hex_dst_string_len ) == 0 );
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020063}
64/* END_CASE */
65
Simon Butcher02c4a382016-06-23 02:41:31 +010066/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khanf1aaec92017-05-30 14:23:15 +010067void xtea_decrypt_cbc( uint8_t * key_str, uint32_t key_str_len,
68 uint8_t * iv_str, uint32_t iv_str_len,
69 uint8_t * src_str, uint32_t len,
70 uint8_t * hex_dst_string, uint32_t hex_dst_string_len )
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020071{
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020072 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073 mbedtls_xtea_context ctx;
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020074
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020075 memset(output, 0x00, 100);
76
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020077
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078 mbedtls_xtea_setup( &ctx, key_str );
79 TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_DECRYPT, len, iv_str,
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020080 src_str, output ) == 0 );
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020081
Azim Khanf1aaec92017-05-30 14:23:15 +010082 TEST_ASSERT( hexcmp( output, hex_dst_string, len, hex_dst_string_len ) == 0 );
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020083}
84/* END_CASE */
85
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020086/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +010087void xtea_selftest( )
Paul Bakkerf725a882009-07-08 06:43:10 +000088{
Andres AG93012e82016-09-09 09:10:28 +010089 TEST_ASSERT( mbedtls_xtea_self_test( 1 ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000090}
Paul Bakker33b43f12013-08-20 11:48:36 +020091/* END_CASE */