blob: b4fa13eb88dd1c842aa968820c9b634dc23203cc [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
Hanno Becker75788372018-12-12 18:02:18 +000010/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
11void camellia_invalid_param( )
12{
13 mbedtls_camellia_context ctx;
14 unsigned char buf[16] = { 0 };
Hanno Beckere939de72018-12-13 15:39:24 +000015 const size_t valid_keybits = 128;
16 const size_t invalid_keybits = 42;
17 const int invalid_mode = 42;
18 const int valid_mode = MBEDTLS_CAMELLIA_ENCRYPT;
Hanno Becker75788372018-12-12 18:02:18 +000019 size_t off;
20 ((void) off);
21
22 TEST_INVALID_PARAM( mbedtls_camellia_init( NULL ) );
23 TEST_VALID_PARAM( mbedtls_camellia_free( NULL ) );
24
25 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
26 mbedtls_camellia_setkey_enc( NULL,
27 buf,
Hanno Beckere939de72018-12-13 15:39:24 +000028 valid_keybits ) );
Hanno Becker75788372018-12-12 18:02:18 +000029 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
30 mbedtls_camellia_setkey_enc( &ctx,
31 NULL,
Hanno Beckere939de72018-12-13 15:39:24 +000032 valid_keybits ) );
Hanno Becker75788372018-12-12 18:02:18 +000033 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
34 mbedtls_camellia_setkey_enc( &ctx,
35 buf,
Hanno Beckere939de72018-12-13 15:39:24 +000036 invalid_keybits ) );
Hanno Becker75788372018-12-12 18:02:18 +000037
38 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
39 mbedtls_camellia_setkey_dec( NULL,
40 buf,
Hanno Beckere939de72018-12-13 15:39:24 +000041 valid_keybits ) );
Hanno Becker75788372018-12-12 18:02:18 +000042 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
43 mbedtls_camellia_setkey_dec( &ctx,
44 NULL,
Hanno Beckere939de72018-12-13 15:39:24 +000045 valid_keybits ) );
Hanno Becker75788372018-12-12 18:02:18 +000046 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
47 mbedtls_camellia_setkey_dec( &ctx,
48 buf,
Hanno Beckere939de72018-12-13 15:39:24 +000049 invalid_keybits ) );
Hanno Becker75788372018-12-12 18:02:18 +000050
51 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
52 mbedtls_camellia_crypt_ecb( NULL,
Hanno Beckere939de72018-12-13 15:39:24 +000053 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000054 buf, buf ) );
55 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
56 mbedtls_camellia_crypt_ecb( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +000057 invalid_mode,
58 buf, buf ) );
59 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
60 mbedtls_camellia_crypt_ecb( &ctx,
61 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000062 NULL, buf ) );
63 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
64 mbedtls_camellia_crypt_ecb( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +000065 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000066 buf, NULL ) );
67
68#if defined(MBEDTLS_CIPHER_MODE_CBC)
69 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
70 mbedtls_camellia_crypt_cbc( NULL,
Hanno Beckere939de72018-12-13 15:39:24 +000071 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000072 sizeof( buf ),
73 buf, buf, buf ) );
74 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
75 mbedtls_camellia_crypt_cbc( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +000076 invalid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000077 sizeof( buf ),
78 buf, buf, buf ) );
79 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
80 mbedtls_camellia_crypt_cbc( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +000081 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000082 sizeof( buf ),
83 NULL, buf, buf ) );
84 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
85 mbedtls_camellia_crypt_cbc( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +000086 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000087 sizeof( buf ),
88 buf, NULL, buf ) );
89 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
90 mbedtls_camellia_crypt_cbc( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +000091 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000092 sizeof( buf ),
93 buf, buf, NULL ) );
94#endif /* MBEDTLS_CIPHER_MODE_CBC */
95
96#if defined(MBEDTLS_CIPHER_MODE_CFB)
97 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
98 mbedtls_camellia_crypt_cfb128( NULL,
Hanno Beckere939de72018-12-13 15:39:24 +000099 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +0000100 sizeof( buf ),
101 &off, buf,
102 buf, buf ) );
103 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
104 mbedtls_camellia_crypt_cfb128( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +0000105 invalid_mode,
Hanno Becker75788372018-12-12 18:02:18 +0000106 sizeof( buf ),
107 &off, buf,
108 buf, buf ) );
109 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
110 mbedtls_camellia_crypt_cfb128( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +0000111 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +0000112 sizeof( buf ),
113 NULL, buf,
114 buf, buf ) );
115 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
116 mbedtls_camellia_crypt_cfb128( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +0000117 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +0000118 sizeof( buf ),
119 &off, NULL,
120 buf, buf ) );
121 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
122 mbedtls_camellia_crypt_cfb128( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +0000123 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +0000124 sizeof( buf ),
125 &off, buf,
126 NULL, buf ) );
127 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
128 mbedtls_camellia_crypt_cfb128( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +0000129 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +0000130 sizeof( buf ),
131 &off, buf,
132 buf, NULL ) );
133#endif /* MBEDTLS_CIPHER_MODE_CFB */
134
135#if defined(MBEDTLS_CIPHER_MODE_CTR)
136 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
137 mbedtls_camellia_crypt_ctr( NULL,
138 sizeof( buf ),
139 &off,
140 buf, buf,
141 buf, buf ) );
142 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
143 mbedtls_camellia_crypt_ctr( &ctx,
144 sizeof( buf ),
145 NULL,
146 buf, buf,
147 buf, buf ) );
148 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
149 mbedtls_camellia_crypt_ctr( &ctx,
150 sizeof( buf ),
151 &off,
152 NULL, buf,
153 buf, buf ) );
154 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
155 mbedtls_camellia_crypt_ctr( &ctx,
156 sizeof( buf ),
157 &off,
158 buf, NULL,
159 buf, buf ) );
160 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
161 mbedtls_camellia_crypt_ctr( &ctx,
162 sizeof( buf ),
163 &off,
164 buf, buf,
165 NULL, buf ) );
166 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
167 mbedtls_camellia_crypt_ctr( &ctx,
168 sizeof( buf ),
169 &off,
170 buf, buf,
171 buf, NULL ) );
172#endif /* MBEDTLS_CIPHER_MODE_CTR */
173
174exit:
175 return;
176}
177/* END_CASE */
178
Paul Bakker33b43f12013-08-20 11:48:36 +0200179/* BEGIN_CASE */
Azim Khan5fcca462018-06-29 11:05:32 +0100180void camellia_encrypt_ecb( data_t * key_str, data_t * src_str,
181 data_t * hex_dst_string, int setkey_result )
Paul Bakkere896fea2009-07-06 06:40:23 +0000182{
Paul Bakkere896fea2009-07-06 06:40:23 +0000183 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184 mbedtls_camellia_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +0000185
Paul Bakkere896fea2009-07-06 06:40:23 +0000186 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200187 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000188
Paul Bakkere896fea2009-07-06 06:40:23 +0000189
Azim Khand30ca132017-06-09 04:32:58 +0100190 TEST_ASSERT( mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200191 if( setkey_result == 0 )
Paul Bakker2b222c82009-07-27 21:03:45 +0000192 {
Azim Khand30ca132017-06-09 04:32:58 +0100193 TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->x, output ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000194
Azim Khand30ca132017-06-09 04:32:58 +0100195 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
Paul Bakker2b222c82009-07-27 21:03:45 +0000196 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200197
Paul Bakkerbd51b262014-07-10 15:26:12 +0200198exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000200}
Paul Bakker33b43f12013-08-20 11:48:36 +0200201/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000202
Paul Bakker33b43f12013-08-20 11:48:36 +0200203/* BEGIN_CASE */
Azim Khan5fcca462018-06-29 11:05:32 +0100204void camellia_decrypt_ecb( data_t * key_str, data_t * src_str,
205 data_t * hex_dst_string, int setkey_result )
Paul Bakkere896fea2009-07-06 06:40:23 +0000206{
Paul Bakkere896fea2009-07-06 06:40:23 +0000207 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208 mbedtls_camellia_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +0000209
Paul Bakkere896fea2009-07-06 06:40:23 +0000210 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000212
Paul Bakkere896fea2009-07-06 06:40:23 +0000213
Azim Khand30ca132017-06-09 04:32:58 +0100214 TEST_ASSERT( mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200215 if( setkey_result == 0 )
Paul Bakker2b222c82009-07-27 21:03:45 +0000216 {
Azim Khand30ca132017-06-09 04:32:58 +0100217 TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->x, output ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000218
Azim Khand30ca132017-06-09 04:32:58 +0100219 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
Paul Bakker2b222c82009-07-27 21:03:45 +0000220 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200221
Paul Bakkerbd51b262014-07-10 15:26:12 +0200222exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000224}
Paul Bakker33b43f12013-08-20 11:48:36 +0200225/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000226
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200227/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khan5fcca462018-06-29 11:05:32 +0100228void camellia_encrypt_cbc( data_t * key_str, data_t * iv_str,
229 data_t * src_str, data_t * hex_dst_string,
Azim Khand30ca132017-06-09 04:32:58 +0100230 int cbc_result )
Paul Bakkere896fea2009-07-06 06:40:23 +0000231{
Paul Bakkere896fea2009-07-06 06:40:23 +0000232 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200233 mbedtls_camellia_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +0000234
Paul Bakkere896fea2009-07-06 06:40:23 +0000235 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200236 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000237
Paul Bakkere896fea2009-07-06 06:40:23 +0000238
Azim Khand30ca132017-06-09 04:32:58 +0100239 mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
240 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 +0200241 if( cbc_result == 0 )
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000242 {
Paul Bakkere896fea2009-07-06 06:40:23 +0000243
Azim Khand30ca132017-06-09 04:32:58 +0100244 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000245 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200246
Paul Bakkerbd51b262014-07-10 15:26:12 +0200247exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200248 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000249}
Paul Bakker33b43f12013-08-20 11:48:36 +0200250/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000251
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200252/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khan5fcca462018-06-29 11:05:32 +0100253void camellia_decrypt_cbc( data_t * key_str, data_t * iv_str,
254 data_t * src_str, data_t * hex_dst_string,
Azim Khand30ca132017-06-09 04:32:58 +0100255 int cbc_result )
Paul Bakkere896fea2009-07-06 06:40:23 +0000256{
Paul Bakkere896fea2009-07-06 06:40:23 +0000257 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200258 mbedtls_camellia_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +0000259
Paul Bakkere896fea2009-07-06 06:40:23 +0000260 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200261 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000262
Paul Bakkere896fea2009-07-06 06:40:23 +0000263
Azim Khand30ca132017-06-09 04:32:58 +0100264 mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 );
265 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 +0200266 if( cbc_result == 0 )
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000267 {
Paul Bakkere896fea2009-07-06 06:40:23 +0000268
Azim Khand30ca132017-06-09 04:32:58 +0100269 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000270 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200271
Paul Bakkerbd51b262014-07-10 15:26:12 +0200272exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200273 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000274}
Paul Bakker33b43f12013-08-20 11:48:36 +0200275/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000276
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200277/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
Azim Khan5fcca462018-06-29 11:05:32 +0100278void camellia_encrypt_cfb128( data_t * key_str, data_t * iv_str,
279 data_t * src_str,
280 data_t * hex_dst_string )
Paul Bakkere896fea2009-07-06 06:40:23 +0000281{
Paul Bakkere896fea2009-07-06 06:40:23 +0000282 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200283 mbedtls_camellia_context ctx;
Paul Bakker1ef71df2011-06-09 14:14:58 +0000284 size_t iv_offset = 0;
Paul Bakkere896fea2009-07-06 06:40:23 +0000285
Paul Bakkere896fea2009-07-06 06:40:23 +0000286 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200287 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000288
Paul Bakkere896fea2009-07-06 06:40:23 +0000289
Azim Khand30ca132017-06-09 04:32:58 +0100290 mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
291 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 +0000292
Azim Khand30ca132017-06-09 04:32:58 +0100293 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200294
Paul Bakkerbd51b262014-07-10 15:26:12 +0200295exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200296 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000297}
Paul Bakker33b43f12013-08-20 11:48:36 +0200298/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000299
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200300/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
Azim Khan5fcca462018-06-29 11:05:32 +0100301void camellia_decrypt_cfb128( data_t * key_str, data_t * iv_str,
302 data_t * src_str,
303 data_t * hex_dst_string )
Paul Bakkere896fea2009-07-06 06:40:23 +0000304{
Paul Bakkere896fea2009-07-06 06:40:23 +0000305 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200306 mbedtls_camellia_context ctx;
Paul Bakker1ef71df2011-06-09 14:14:58 +0000307 size_t iv_offset = 0;
Paul Bakkere896fea2009-07-06 06:40:23 +0000308
Paul Bakkere896fea2009-07-06 06:40:23 +0000309 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200310 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000311
Paul Bakkere896fea2009-07-06 06:40:23 +0000312
Azim Khand30ca132017-06-09 04:32:58 +0100313 mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
314 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 +0000315
Azim Khand30ca132017-06-09 04:32:58 +0100316 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200317
Paul Bakkerbd51b262014-07-10 15:26:12 +0200318exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200319 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000320}
Paul Bakker33b43f12013-08-20 11:48:36 +0200321/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000322
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200323/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +0100324void camellia_selftest( )
Paul Bakkere896fea2009-07-06 06:40:23 +0000325{
Andres AG93012e82016-09-09 09:10:28 +0100326 TEST_ASSERT( mbedtls_camellia_self_test( 1 ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000327}
Paul Bakker33b43f12013-08-20 11:48:36 +0200328/* END_CASE */