blob: 1d5b29b8ab2b3dcc6fb7c9c031610087d5afc7b5 [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,
Ronald Cronaea41df2020-06-26 14:33:03 +020012 data_t * dst )
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 Cronaea41df2020-06-26 14:33:03 +020023 TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->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 */
Ronald Cronaea41df2020-06-26 14:33:03 +020028void xtea_decrypt_ecb( data_t * key_str, data_t * src_str, data_t * dst )
Paul Bakkerf725a882009-07-08 06:43:10 +000029{
Paul Bakkerf725a882009-07-08 06:43:10 +000030 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031 mbedtls_xtea_context ctx;
Paul Bakkerf725a882009-07-08 06:43:10 +000032
Paul Bakkerf725a882009-07-08 06:43:10 +000033 memset(output, 0x00, 100);
34
Paul Bakkerf725a882009-07-08 06:43:10 +000035
Azim Khand30ca132017-06-09 04:32:58 +010036 mbedtls_xtea_setup( &ctx, key_str->x );
37 TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_DECRYPT, src_str->x, output ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000038
Ronald Cronaea41df2020-06-26 14:33:03 +020039 TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000040}
Paul Bakker33b43f12013-08-20 11:48:36 +020041/* END_CASE */
Paul Bakkerf725a882009-07-08 06:43:10 +000042
Simon Butcher02c4a382016-06-23 02:41:31 +010043/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khan5fcca462018-06-29 11:05:32 +010044void xtea_encrypt_cbc( data_t * key_str, data_t * iv_str,
Ronald Cronaea41df2020-06-26 14:33:03 +020045 data_t * src_str, data_t * dst )
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020046{
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020047 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048 mbedtls_xtea_context ctx;
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020049
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020050 memset(output, 0x00, 100);
51
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020052
Azim Khand30ca132017-06-09 04:32:58 +010053 mbedtls_xtea_setup( &ctx, key_str->x );
54 TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str->len, iv_str->x,
55 src_str->x, output ) == 0 );
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020056
Ronald Cronaea41df2020-06-26 14:33:03 +020057 TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
58 src_str->len, dst->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,
Ronald Cronaea41df2020-06-26 14:33:03 +020064 data_t * src_str, data_t * dst )
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
Ronald Cronaea41df2020-06-26 14:33:03 +020076 TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
77 src_str->len, dst->len ) == 0 );
Manuel Pégourié-Gonnard7b4919c2014-05-29 18:26:53 +020078}
79/* END_CASE */
80
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +010082void xtea_selftest( )
Paul Bakkerf725a882009-07-08 06:43:10 +000083{
Andres AG93012e82016-09-09 09:10:28 +010084 TEST_ASSERT( mbedtls_xtea_self_test( 1 ) == 0 );
Paul Bakkerf725a882009-07-08 06:43:10 +000085}
Paul Bakker33b43f12013-08-20 11:48:36 +020086/* END_CASE */