blob: 9408348151e90590edc023b73772b47e989f25ea [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 Beckerf1931762018-12-17 14:20:05 +000010/* BEGIN_CASE */
11void camellia_valid_param( )
12{
13 TEST_VALID_PARAM( mbedtls_camellia_free( NULL ) );
14}
15/* END_CASE */
16
Hanno Becker75788372018-12-12 18:02:18 +000017/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
18void camellia_invalid_param( )
19{
20 mbedtls_camellia_context ctx;
21 unsigned char buf[16] = { 0 };
Hanno Beckere939de72018-12-13 15:39:24 +000022 const size_t valid_keybits = 128;
Hanno Beckere939de72018-12-13 15:39:24 +000023 const int invalid_mode = 42;
24 const int valid_mode = MBEDTLS_CAMELLIA_ENCRYPT;
Hanno Becker75788372018-12-12 18:02:18 +000025 size_t off;
26 ((void) off);
27
28 TEST_INVALID_PARAM( mbedtls_camellia_init( NULL ) );
Hanno Becker75788372018-12-12 18:02:18 +000029
30 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
31 mbedtls_camellia_setkey_enc( NULL,
32 buf,
Hanno Beckere939de72018-12-13 15:39:24 +000033 valid_keybits ) );
Hanno Becker75788372018-12-12 18:02:18 +000034 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
35 mbedtls_camellia_setkey_enc( &ctx,
36 NULL,
Hanno Beckere939de72018-12-13 15:39:24 +000037 valid_keybits ) );
Hanno Becker75788372018-12-12 18:02:18 +000038
39 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
40 mbedtls_camellia_setkey_dec( NULL,
41 buf,
Hanno Beckere939de72018-12-13 15:39:24 +000042 valid_keybits ) );
Hanno Becker75788372018-12-12 18:02:18 +000043 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
44 mbedtls_camellia_setkey_dec( &ctx,
45 NULL,
Hanno Beckere939de72018-12-13 15:39:24 +000046 valid_keybits ) );
Hanno Becker75788372018-12-12 18:02:18 +000047
48 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
49 mbedtls_camellia_crypt_ecb( NULL,
Hanno Beckere939de72018-12-13 15:39:24 +000050 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000051 buf, buf ) );
52 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
53 mbedtls_camellia_crypt_ecb( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +000054 invalid_mode,
55 buf, buf ) );
56 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
57 mbedtls_camellia_crypt_ecb( &ctx,
58 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000059 NULL, buf ) );
60 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
61 mbedtls_camellia_crypt_ecb( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +000062 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000063 buf, NULL ) );
64
65#if defined(MBEDTLS_CIPHER_MODE_CBC)
66 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
67 mbedtls_camellia_crypt_cbc( NULL,
Hanno Beckere939de72018-12-13 15:39:24 +000068 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000069 sizeof( buf ),
70 buf, buf, buf ) );
71 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
72 mbedtls_camellia_crypt_cbc( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +000073 invalid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000074 sizeof( buf ),
75 buf, buf, buf ) );
76 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
77 mbedtls_camellia_crypt_cbc( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +000078 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000079 sizeof( buf ),
80 NULL, buf, buf ) );
81 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
82 mbedtls_camellia_crypt_cbc( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +000083 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000084 sizeof( buf ),
85 buf, NULL, buf ) );
86 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
87 mbedtls_camellia_crypt_cbc( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +000088 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000089 sizeof( buf ),
90 buf, buf, NULL ) );
91#endif /* MBEDTLS_CIPHER_MODE_CBC */
92
93#if defined(MBEDTLS_CIPHER_MODE_CFB)
94 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
95 mbedtls_camellia_crypt_cfb128( NULL,
Hanno Beckere939de72018-12-13 15:39:24 +000096 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +000097 sizeof( buf ),
98 &off, buf,
99 buf, buf ) );
100 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
101 mbedtls_camellia_crypt_cfb128( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +0000102 invalid_mode,
Hanno Becker75788372018-12-12 18:02:18 +0000103 sizeof( buf ),
104 &off, buf,
105 buf, buf ) );
106 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
107 mbedtls_camellia_crypt_cfb128( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +0000108 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +0000109 sizeof( buf ),
110 NULL, buf,
111 buf, buf ) );
112 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
113 mbedtls_camellia_crypt_cfb128( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +0000114 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +0000115 sizeof( buf ),
116 &off, NULL,
117 buf, buf ) );
118 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
119 mbedtls_camellia_crypt_cfb128( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +0000120 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +0000121 sizeof( buf ),
122 &off, buf,
123 NULL, buf ) );
124 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
125 mbedtls_camellia_crypt_cfb128( &ctx,
Hanno Beckere939de72018-12-13 15:39:24 +0000126 valid_mode,
Hanno Becker75788372018-12-12 18:02:18 +0000127 sizeof( buf ),
128 &off, buf,
129 buf, NULL ) );
130#endif /* MBEDTLS_CIPHER_MODE_CFB */
131
132#if defined(MBEDTLS_CIPHER_MODE_CTR)
133 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
134 mbedtls_camellia_crypt_ctr( NULL,
135 sizeof( buf ),
136 &off,
137 buf, buf,
138 buf, buf ) );
139 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
140 mbedtls_camellia_crypt_ctr( &ctx,
141 sizeof( buf ),
142 NULL,
143 buf, buf,
144 buf, buf ) );
145 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
146 mbedtls_camellia_crypt_ctr( &ctx,
147 sizeof( buf ),
148 &off,
149 NULL, buf,
150 buf, buf ) );
151 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
152 mbedtls_camellia_crypt_ctr( &ctx,
153 sizeof( buf ),
154 &off,
155 buf, NULL,
156 buf, buf ) );
157 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
158 mbedtls_camellia_crypt_ctr( &ctx,
159 sizeof( buf ),
160 &off,
161 buf, buf,
162 NULL, buf ) );
163 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
164 mbedtls_camellia_crypt_ctr( &ctx,
165 sizeof( buf ),
166 &off,
167 buf, buf,
168 buf, NULL ) );
169#endif /* MBEDTLS_CIPHER_MODE_CTR */
170
171exit:
172 return;
173}
174/* END_CASE */
175
Paul Bakker33b43f12013-08-20 11:48:36 +0200176/* BEGIN_CASE */
Azim Khan5fcca462018-06-29 11:05:32 +0100177void camellia_encrypt_ecb( data_t * key_str, data_t * src_str,
178 data_t * hex_dst_string, int setkey_result )
Paul Bakkere896fea2009-07-06 06:40:23 +0000179{
Paul Bakkere896fea2009-07-06 06:40:23 +0000180 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200181 mbedtls_camellia_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +0000182
Paul Bakkere896fea2009-07-06 06:40:23 +0000183 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000185
Paul Bakkere896fea2009-07-06 06:40:23 +0000186
Azim Khand30ca132017-06-09 04:32:58 +0100187 TEST_ASSERT( mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200188 if( setkey_result == 0 )
Paul Bakker2b222c82009-07-27 21:03:45 +0000189 {
Azim Khand30ca132017-06-09 04:32:58 +0100190 TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->x, output ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000191
Azim Khand30ca132017-06-09 04:32:58 +0100192 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
Paul Bakker2b222c82009-07-27 21:03:45 +0000193 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200194
Paul Bakkerbd51b262014-07-10 15:26:12 +0200195exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200196 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000197}
Paul Bakker33b43f12013-08-20 11:48:36 +0200198/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000199
Paul Bakker33b43f12013-08-20 11:48:36 +0200200/* BEGIN_CASE */
Azim Khan5fcca462018-06-29 11:05:32 +0100201void camellia_decrypt_ecb( data_t * key_str, data_t * src_str,
202 data_t * hex_dst_string, int setkey_result )
Paul Bakkere896fea2009-07-06 06:40:23 +0000203{
Paul Bakkere896fea2009-07-06 06:40:23 +0000204 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200205 mbedtls_camellia_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +0000206
Paul Bakkere896fea2009-07-06 06:40:23 +0000207 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000209
Paul Bakkere896fea2009-07-06 06:40:23 +0000210
Azim Khand30ca132017-06-09 04:32:58 +0100211 TEST_ASSERT( mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200212 if( setkey_result == 0 )
Paul Bakker2b222c82009-07-27 21:03:45 +0000213 {
Azim Khand30ca132017-06-09 04:32:58 +0100214 TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->x, output ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000215
Azim Khand30ca132017-06-09 04:32:58 +0100216 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
Paul Bakker2b222c82009-07-27 21:03:45 +0000217 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200218
Paul Bakkerbd51b262014-07-10 15:26:12 +0200219exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200220 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000221}
Paul Bakker33b43f12013-08-20 11:48:36 +0200222/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000223
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200224/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khan5fcca462018-06-29 11:05:32 +0100225void camellia_encrypt_cbc( data_t * key_str, data_t * iv_str,
226 data_t * src_str, data_t * hex_dst_string,
Azim Khand30ca132017-06-09 04:32:58 +0100227 int cbc_result )
Paul Bakkere896fea2009-07-06 06:40:23 +0000228{
Paul Bakkere896fea2009-07-06 06:40:23 +0000229 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200230 mbedtls_camellia_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +0000231
Paul Bakkere896fea2009-07-06 06:40:23 +0000232 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200233 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000234
Paul Bakkere896fea2009-07-06 06:40:23 +0000235
Azim Khand30ca132017-06-09 04:32:58 +0100236 mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
237 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 +0200238 if( cbc_result == 0 )
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000239 {
Paul Bakkere896fea2009-07-06 06:40:23 +0000240
Azim Khand30ca132017-06-09 04:32:58 +0100241 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000242 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200243
Paul Bakkerbd51b262014-07-10 15:26:12 +0200244exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200245 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000246}
Paul Bakker33b43f12013-08-20 11:48:36 +0200247/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000248
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200249/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khan5fcca462018-06-29 11:05:32 +0100250void camellia_decrypt_cbc( data_t * key_str, data_t * iv_str,
251 data_t * src_str, data_t * hex_dst_string,
Azim Khand30ca132017-06-09 04:32:58 +0100252 int cbc_result )
Paul Bakkere896fea2009-07-06 06:40:23 +0000253{
Paul Bakkere896fea2009-07-06 06:40:23 +0000254 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200255 mbedtls_camellia_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +0000256
Paul Bakkere896fea2009-07-06 06:40:23 +0000257 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200258 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000259
Paul Bakkere896fea2009-07-06 06:40:23 +0000260
Azim Khand30ca132017-06-09 04:32:58 +0100261 mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 );
262 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 +0200263 if( cbc_result == 0 )
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000264 {
Paul Bakkere896fea2009-07-06 06:40:23 +0000265
Azim Khand30ca132017-06-09 04:32:58 +0100266 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000267 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200268
Paul Bakkerbd51b262014-07-10 15:26:12 +0200269exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200270 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000271}
Paul Bakker33b43f12013-08-20 11:48:36 +0200272/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000273
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200274/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
Azim Khan5fcca462018-06-29 11:05:32 +0100275void camellia_encrypt_cfb128( data_t * key_str, data_t * iv_str,
276 data_t * src_str,
277 data_t * hex_dst_string )
Paul Bakkere896fea2009-07-06 06:40:23 +0000278{
Paul Bakkere896fea2009-07-06 06:40:23 +0000279 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280 mbedtls_camellia_context ctx;
Paul Bakker1ef71df2011-06-09 14:14:58 +0000281 size_t iv_offset = 0;
Paul Bakkere896fea2009-07-06 06:40:23 +0000282
Paul Bakkere896fea2009-07-06 06:40:23 +0000283 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200284 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000285
Paul Bakkere896fea2009-07-06 06:40:23 +0000286
Azim Khand30ca132017-06-09 04:32:58 +0100287 mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
288 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 +0000289
Azim Khand30ca132017-06-09 04:32:58 +0100290 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200291
Paul Bakkerbd51b262014-07-10 15:26:12 +0200292exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200293 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000294}
Paul Bakker33b43f12013-08-20 11:48:36 +0200295/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000296
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200297/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
Azim Khan5fcca462018-06-29 11:05:32 +0100298void camellia_decrypt_cfb128( data_t * key_str, data_t * iv_str,
299 data_t * src_str,
300 data_t * hex_dst_string )
Paul Bakkere896fea2009-07-06 06:40:23 +0000301{
Paul Bakkere896fea2009-07-06 06:40:23 +0000302 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200303 mbedtls_camellia_context ctx;
Paul Bakker1ef71df2011-06-09 14:14:58 +0000304 size_t iv_offset = 0;
Paul Bakkere896fea2009-07-06 06:40:23 +0000305
Paul Bakkere896fea2009-07-06 06:40:23 +0000306 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200307 mbedtls_camellia_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000308
Paul Bakkere896fea2009-07-06 06:40:23 +0000309
Azim Khand30ca132017-06-09 04:32:58 +0100310 mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
311 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 +0000312
Azim Khand30ca132017-06-09 04:32:58 +0100313 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200314
Paul Bakkerbd51b262014-07-10 15:26:12 +0200315exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200316 mbedtls_camellia_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000317}
Paul Bakker33b43f12013-08-20 11:48:36 +0200318/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000319
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200320/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +0100321void camellia_selftest( )
Paul Bakkere896fea2009-07-06 06:40:23 +0000322{
Andres AG93012e82016-09-09 09:10:28 +0100323 TEST_ASSERT( mbedtls_camellia_self_test( 1 ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000324}
Paul Bakker33b43f12013-08-20 11:48:36 +0200325/* END_CASE */