blob: 4bfa1a5da85cbe9dac5ee066c0c351fa6bbf406f [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/camellia.h"
Paul Bakker33b43f12013-08-20 11:48:36 +02003/* END_HEADER */
Paul Bakkere896fea2009-07-06 06:40:23 +00004
Paul Bakker33b43f12013-08-20 11:48:36 +02005/* BEGIN_DEPENDENCIES
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02006 * depends_on:MBEDTLS_CAMELLIA_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 Khand30ca132017-06-09 04:32:58 +010011void camellia_encrypt_ecb( HexParam_t * key_str, HexParam_t * src_str,
12 HexParam_t * hex_dst_string, int setkey_result )
Paul Bakkere896fea2009-07-06 06:40:23 +000013{
Paul Bakkere896fea2009-07-06 06:40:23 +000014 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020015 mbedtls_camellia_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +000016
Paul Bakkere896fea2009-07-06 06:40:23 +000017 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020018 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000019
Paul Bakkere896fea2009-07-06 06:40:23 +000020
Azim Khand30ca132017-06-09 04:32:58 +010021 TEST_ASSERT( mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
Paul Bakker33b43f12013-08-20 11:48:36 +020022 if( setkey_result == 0 )
Paul Bakker2b222c82009-07-27 21:03:45 +000023 {
Azim Khand30ca132017-06-09 04:32:58 +010024 TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->x, output ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +000025
Azim Khand30ca132017-06-09 04:32:58 +010026 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
Paul Bakker2b222c82009-07-27 21:03:45 +000027 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +020028
Paul Bakkerbd51b262014-07-10 15:26:12 +020029exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000031}
Paul Bakker33b43f12013-08-20 11:48:36 +020032/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +000033
Paul Bakker33b43f12013-08-20 11:48:36 +020034/* BEGIN_CASE */
Azim Khand30ca132017-06-09 04:32:58 +010035void camellia_decrypt_ecb( HexParam_t * key_str, HexParam_t * src_str,
36 HexParam_t * hex_dst_string, int setkey_result )
Paul Bakkere896fea2009-07-06 06:40:23 +000037{
Paul Bakkere896fea2009-07-06 06:40:23 +000038 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039 mbedtls_camellia_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +000040
Paul Bakkere896fea2009-07-06 06:40:23 +000041 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020042 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000043
Paul Bakkere896fea2009-07-06 06:40:23 +000044
Azim Khand30ca132017-06-09 04:32:58 +010045 TEST_ASSERT( mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
Paul Bakker33b43f12013-08-20 11:48:36 +020046 if( setkey_result == 0 )
Paul Bakker2b222c82009-07-27 21:03:45 +000047 {
Azim Khand30ca132017-06-09 04:32:58 +010048 TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->x, output ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +000049
Azim Khand30ca132017-06-09 04:32:58 +010050 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
Paul Bakker2b222c82009-07-27 21:03:45 +000051 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +020052
Paul Bakkerbd51b262014-07-10 15:26:12 +020053exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000055}
Paul Bakker33b43f12013-08-20 11:48:36 +020056/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +000057
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khand30ca132017-06-09 04:32:58 +010059void camellia_encrypt_cbc( HexParam_t * key_str, HexParam_t * iv_str,
60 HexParam_t * src_str, HexParam_t * hex_dst_string,
61 int cbc_result )
Paul Bakkere896fea2009-07-06 06:40:23 +000062{
Paul Bakkere896fea2009-07-06 06:40:23 +000063 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064 mbedtls_camellia_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +000065
Paul Bakkere896fea2009-07-06 06:40:23 +000066 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000068
Paul Bakkere896fea2009-07-06 06:40:23 +000069
Azim Khand30ca132017-06-09 04:32:58 +010070 mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
71 TEST_ASSERT( mbedtls_camellia_crypt_cbc( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->len, iv_str->x, src_str->x, output) == cbc_result );
Paul Bakker33b43f12013-08-20 11:48:36 +020072 if( cbc_result == 0 )
Paul Bakkerf3ccc682010-03-18 21:21:02 +000073 {
Paul Bakkere896fea2009-07-06 06:40:23 +000074
Azim Khand30ca132017-06-09 04:32:58 +010075 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +000076 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +020077
Paul Bakkerbd51b262014-07-10 15:26:12 +020078exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000080}
Paul Bakker33b43f12013-08-20 11:48:36 +020081/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +000082
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khand30ca132017-06-09 04:32:58 +010084void camellia_decrypt_cbc( HexParam_t * key_str, HexParam_t * iv_str,
85 HexParam_t * src_str, HexParam_t * hex_dst_string,
86 int cbc_result )
Paul Bakkere896fea2009-07-06 06:40:23 +000087{
Paul Bakkere896fea2009-07-06 06:40:23 +000088 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089 mbedtls_camellia_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +000090
Paul Bakkere896fea2009-07-06 06:40:23 +000091 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000093
Paul Bakkere896fea2009-07-06 06:40:23 +000094
Azim Khand30ca132017-06-09 04:32:58 +010095 mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 );
96 TEST_ASSERT( mbedtls_camellia_crypt_cbc( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
Paul Bakker33b43f12013-08-20 11:48:36 +020097 if( cbc_result == 0 )
Paul Bakkerf3ccc682010-03-18 21:21:02 +000098 {
Paul Bakkere896fea2009-07-06 06:40:23 +000099
Azim Khand30ca132017-06-09 04:32:58 +0100100 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000101 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200102
Paul Bakkerbd51b262014-07-10 15:26:12 +0200103exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000105}
Paul Bakker33b43f12013-08-20 11:48:36 +0200106/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000107
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
Azim Khand30ca132017-06-09 04:32:58 +0100109void camellia_encrypt_cfb128( HexParam_t * key_str, HexParam_t * iv_str,
110 HexParam_t * src_str,
111 HexParam_t * hex_dst_string )
Paul Bakkere896fea2009-07-06 06:40:23 +0000112{
Paul Bakkere896fea2009-07-06 06:40:23 +0000113 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114 mbedtls_camellia_context ctx;
Paul Bakker1ef71df2011-06-09 14:14:58 +0000115 size_t iv_offset = 0;
Paul Bakkere896fea2009-07-06 06:40:23 +0000116
Paul Bakkere896fea2009-07-06 06:40:23 +0000117 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200118 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000119
Paul Bakkere896fea2009-07-06 06:40:23 +0000120
Azim Khand30ca132017-06-09 04:32:58 +0100121 mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
122 TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000123
Azim Khand30ca132017-06-09 04:32:58 +0100124 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200125
Paul Bakkerbd51b262014-07-10 15:26:12 +0200126exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000128}
Paul Bakker33b43f12013-08-20 11:48:36 +0200129/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000130
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
Azim Khand30ca132017-06-09 04:32:58 +0100132void camellia_decrypt_cfb128( HexParam_t * key_str, HexParam_t * iv_str,
133 HexParam_t * src_str,
134 HexParam_t * hex_dst_string )
Paul Bakkere896fea2009-07-06 06:40:23 +0000135{
Paul Bakkere896fea2009-07-06 06:40:23 +0000136 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200137 mbedtls_camellia_context ctx;
Paul Bakker1ef71df2011-06-09 14:14:58 +0000138 size_t iv_offset = 0;
Paul Bakkere896fea2009-07-06 06:40:23 +0000139
Paul Bakkere896fea2009-07-06 06:40:23 +0000140 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000142
Paul Bakkere896fea2009-07-06 06:40:23 +0000143
Azim Khand30ca132017-06-09 04:32:58 +0100144 mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
145 TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_DECRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000146
Azim Khand30ca132017-06-09 04:32:58 +0100147 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200148
Paul Bakkerbd51b262014-07-10 15:26:12 +0200149exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000151}
Paul Bakker33b43f12013-08-20 11:48:36 +0200152/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000153
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200154/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +0100155void camellia_selftest( )
Paul Bakkere896fea2009-07-06 06:40:23 +0000156{
Andres AG93012e82016-09-09 09:10:28 +0100157 TEST_ASSERT( mbedtls_camellia_self_test( 1 ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000158}
Paul Bakker33b43f12013-08-20 11:48:36 +0200159/* END_CASE */