blob: f286e67354fc67269f2dc0d1b584c45ecd762ce3 [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
Ronald Cron9fde3532020-06-10 11:42:32 +020023 TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
24 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 Khan5fcca462018-06-29 11:05:32 +010029void xtea_decrypt_ecb( data_t * key_str, data_t * src_str,
30 data_t * hex_dst_string )
Paul Bakkerf725a882009-07-08 06:43:10 +000031{
Paul Bakkerf725a882009-07-08 06:43:10 +000032 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033 mbedtls_xtea_context ctx;
Paul Bakkerf725a882009-07-08 06:43:10 +000034
Paul Bakkerf725a882009-07-08 06:43:10 +000035 memset(output, 0x00, 100);
36
Paul Bakkerf725a882009-07-08 06:43:10 +000037
Azim Khand30ca132017-06-09 04:32:58 +010038 mbedtls_xtea_setup( &ctx, key_str->x );
39 TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_DECRYPT, src_str->x, output ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000040
Ronald Cron9fde3532020-06-10 11:42:32 +020041 TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
42 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 Khan5fcca462018-06-29 11:05:32 +010047void xtea_encrypt_cbc( data_t * key_str, data_t * iv_str,
48 data_t * src_str, data_t * hex_dst_string )
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020049{
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020050 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051 mbedtls_xtea_context ctx;
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020052
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020053 memset(output, 0x00, 100);
54
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020055
Azim Khand30ca132017-06-09 04:32:58 +010056 mbedtls_xtea_setup( &ctx, key_str->x );
57 TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str->len, iv_str->x,
58 src_str->x, output ) == 0 );
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020059
Ronald Cron9fde3532020-06-10 11:42:32 +020060 TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
61 src_str->len,
62 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 Khan5fcca462018-06-29 11:05:32 +010067void xtea_decrypt_cbc( data_t * key_str, data_t * iv_str,
68 data_t * src_str, data_t * hex_dst_string )
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020069{
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020070 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071 mbedtls_xtea_context ctx;
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020072
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020073 memset(output, 0x00, 100);
74
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020075
Azim Khand30ca132017-06-09 04:32:58 +010076 mbedtls_xtea_setup( &ctx, key_str->x );
77 TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_DECRYPT, src_str->len, iv_str->x,
78 src_str->x, output ) == 0 );
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020079
Ronald Cron9fde3532020-06-10 11:42:32 +020080 TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x,
81 src_str->len,
82 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 */