blob: a24a4206570c449def931fff4f26db3ae9760a5d [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 Khan5fcca462018-06-29 11:05:32 +010011void xtea_encrypt_ecb( data_t * key_str, data_t * src_str,
12 data_t * hex_dst_string )
Paul Bakkerf725a882009-07-08 06:43:10 +000013{
Paul Bakkerf725a882009-07-08 06:43:10 +000014 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020015 mbedtls_xtea_context ctx;
Paul Bakkerf725a882009-07-08 06:43:10 +000016
Paul Bakkerf725a882009-07-08 06:43:10 +000017 memset(output, 0x00, 100);
18
Paul Bakkerf725a882009-07-08 06:43:10 +000019
Azim Khand30ca132017-06-09 04:32:58 +010020 mbedtls_xtea_setup( &ctx, key_str->x );
21 TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str->x, output ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000022
Azim Khand30ca132017-06-09 04:32:58 +010023 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 8, hex_dst_string->len ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000024}
Paul Bakker33b43f12013-08-20 11:48:36 +020025/* END_CASE */
Paul Bakkerf725a882009-07-08 06:43:10 +000026
Paul Bakker33b43f12013-08-20 11:48:36 +020027/* BEGIN_CASE */
Azim Khan5fcca462018-06-29 11:05:32 +010028void xtea_decrypt_ecb( data_t * key_str, data_t * src_str,
29 data_t * hex_dst_string )
Paul Bakkerf725a882009-07-08 06:43:10 +000030{
Paul Bakkerf725a882009-07-08 06:43:10 +000031 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032 mbedtls_xtea_context ctx;
Paul Bakkerf725a882009-07-08 06:43:10 +000033
Paul Bakkerf725a882009-07-08 06:43:10 +000034 memset(output, 0x00, 100);
35
Paul Bakkerf725a882009-07-08 06:43:10 +000036
Azim Khand30ca132017-06-09 04:32:58 +010037 mbedtls_xtea_setup( &ctx, key_str->x );
38 TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_DECRYPT, src_str->x, output ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000039
Azim Khand30ca132017-06-09 04:32:58 +010040 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 8, hex_dst_string->len ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000041}
Paul Bakker33b43f12013-08-20 11:48:36 +020042/* END_CASE */
Paul Bakkerf725a882009-07-08 06:43:10 +000043
Simon Butcher02c4a382016-06-23 02:41:31 +010044/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khan5fcca462018-06-29 11:05:32 +010045void xtea_encrypt_cbc( data_t * key_str, data_t * iv_str,
46 data_t * src_str, data_t * hex_dst_string )
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020047{
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020048 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049 mbedtls_xtea_context ctx;
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020050
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020051 memset(output, 0x00, 100);
52
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020053
Azim Khand30ca132017-06-09 04:32:58 +010054 mbedtls_xtea_setup( &ctx, key_str->x );
55 TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str->len, iv_str->x,
56 src_str->x, output ) == 0 );
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020057
Azim Khand30ca132017-06-09 04:32:58 +010058 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020059}
60/* END_CASE */
61
Simon Butcher02c4a382016-06-23 02:41:31 +010062/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khan5fcca462018-06-29 11:05:32 +010063void xtea_decrypt_cbc( data_t * key_str, data_t * iv_str,
64 data_t * src_str, data_t * hex_dst_string )
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020065{
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020066 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067 mbedtls_xtea_context ctx;
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020068
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020069 memset(output, 0x00, 100);
70
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020071
Azim Khand30ca132017-06-09 04:32:58 +010072 mbedtls_xtea_setup( &ctx, key_str->x );
73 TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_DECRYPT, src_str->len, iv_str->x,
74 src_str->x, output ) == 0 );
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020075
Azim Khand30ca132017-06-09 04:32:58 +010076 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020077}
78/* END_CASE */
79
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +010081void xtea_selftest( )
Paul Bakkerf725a882009-07-08 06:43:10 +000082{
Andres AG93012e82016-09-09 09:10:28 +010083 TEST_ASSERT( mbedtls_xtea_self_test( 1 ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000084}
Paul Bakker33b43f12013-08-20 11:48:36 +020085/* END_CASE */