blob: 028ae1a2053165bb8baaee22b61b663d2289f0f3 [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/blowfish.h"
Paul Bakker33b43f12013-08-20 11:48:36 +02003/* END_HEADER */
Paul Bakkera9379c02012-07-04 11:02:11 +00004
Paul Bakker33b43f12013-08-20 11:48:36 +02005/* BEGIN_DEPENDENCIES
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02006 * depends_on:MBEDTLS_BLOWFISH_C
Paul Bakker33b43f12013-08-20 11:48:36 +02007 * END_DEPENDENCIES
8 */
Paul Bakkera9379c02012-07-04 11:02:11 +00009
Hanno Beckere38b4cd2018-12-12 18:46:19 +000010/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
11void blowfish_invalid_param( )
12{
13 mbedtls_blowfish_context ctx;
14 unsigned char buf[16] = { 0 };
15 size_t off;
16 ((void) off);
17
18 TEST_INVALID_PARAM( mbedtls_blowfish_init( NULL ) );
19 TEST_VALID_PARAM( mbedtls_blowfish_free( NULL ) );
20
21 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
22 mbedtls_blowfish_setkey( NULL,
23 buf,
24 128 ) );
25 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
26 mbedtls_blowfish_setkey( &ctx,
27 NULL,
28 128 ) );
29
30 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
31 mbedtls_blowfish_crypt_ecb( NULL,
32 MBEDTLS_BLOWFISH_ENCRYPT,
33 buf, buf ) );
34 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
35 mbedtls_blowfish_crypt_ecb( &ctx,
36 42,
37 buf, buf ) );
38 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
39 mbedtls_blowfish_crypt_ecb( &ctx,
40 MBEDTLS_BLOWFISH_ENCRYPT,
41 NULL, buf ) );
42 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
43 mbedtls_blowfish_crypt_ecb( &ctx,
44 MBEDTLS_BLOWFISH_ENCRYPT,
45 buf, NULL ) );
46
47#if defined(MBEDTLS_CIPHER_MODE_CBC)
48 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
49 mbedtls_blowfish_crypt_cbc( NULL,
50 MBEDTLS_BLOWFISH_ENCRYPT,
51 sizeof( buf ),
52 buf, buf, buf ) );
53 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
54 mbedtls_blowfish_crypt_cbc( &ctx,
55 42,
56 sizeof( buf ),
57 buf, buf, buf ) );
58 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
59 mbedtls_blowfish_crypt_cbc( &ctx,
60 MBEDTLS_BLOWFISH_ENCRYPT,
61 sizeof( buf ),
62 NULL, buf, buf ) );
63 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
64 mbedtls_blowfish_crypt_cbc( &ctx,
65 MBEDTLS_BLOWFISH_ENCRYPT,
66 sizeof( buf ),
67 buf, NULL, buf ) );
68 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
69 mbedtls_blowfish_crypt_cbc( &ctx,
70 MBEDTLS_BLOWFISH_ENCRYPT,
71 sizeof( buf ),
72 buf, buf, NULL ) );
73#endif /* MBEDTLS_CIPHER_MODE_CBC */
74
75#if defined(MBEDTLS_CIPHER_MODE_CFB)
76 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
77 mbedtls_blowfish_crypt_cfb64( NULL,
78 MBEDTLS_BLOWFISH_ENCRYPT,
79 sizeof( buf ),
80 &off, buf,
81 buf, buf ) );
82 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
83 mbedtls_blowfish_crypt_cfb64( &ctx,
84 42,
85 sizeof( buf ),
86 &off, buf,
87 buf, buf ) );
88 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
89 mbedtls_blowfish_crypt_cfb64( &ctx,
90 MBEDTLS_BLOWFISH_ENCRYPT,
91 sizeof( buf ),
92 NULL, buf,
93 buf, buf ) );
94 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
95 mbedtls_blowfish_crypt_cfb64( &ctx,
96 MBEDTLS_BLOWFISH_ENCRYPT,
97 sizeof( buf ),
98 &off, NULL,
99 buf, buf ) );
100 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
101 mbedtls_blowfish_crypt_cfb64( &ctx,
102 MBEDTLS_BLOWFISH_ENCRYPT,
103 sizeof( buf ),
104 &off, buf,
105 NULL, buf ) );
106 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
107 mbedtls_blowfish_crypt_cfb64( &ctx,
108 MBEDTLS_BLOWFISH_ENCRYPT,
109 sizeof( buf ),
110 &off, buf,
111 buf, NULL ) );
112#endif /* MBEDTLS_CIPHER_MODE_CFB */
113
114#if defined(MBEDTLS_CIPHER_MODE_CTR)
115 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
116 mbedtls_blowfish_crypt_ctr( NULL,
117 sizeof( buf ),
118 &off,
119 buf, buf,
120 buf, buf ) );
121 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
122 mbedtls_blowfish_crypt_ctr( &ctx,
123 sizeof( buf ),
124 NULL,
125 buf, buf,
126 buf, buf ) );
127 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
128 mbedtls_blowfish_crypt_ctr( &ctx,
129 sizeof( buf ),
130 &off,
131 NULL, buf,
132 buf, buf ) );
133 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
134 mbedtls_blowfish_crypt_ctr( &ctx,
135 sizeof( buf ),
136 &off,
137 buf, NULL,
138 buf, buf ) );
139 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
140 mbedtls_blowfish_crypt_ctr( &ctx,
141 sizeof( buf ),
142 &off,
143 buf, buf,
144 NULL, buf ) );
145 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
146 mbedtls_blowfish_crypt_ctr( &ctx,
147 sizeof( buf ),
148 &off,
149 buf, buf,
150 buf, NULL ) );
151#endif /* MBEDTLS_CIPHER_MODE_CTR */
152
153exit:
154 return;
155}
156/* END_CASE */
157
Paul Bakker33b43f12013-08-20 11:48:36 +0200158/* BEGIN_CASE */
Azim Khan5fcca462018-06-29 11:05:32 +0100159void blowfish_encrypt_ecb( data_t * key_str, data_t * src_str,
160 data_t * hex_dst_string, int setkey_result )
Paul Bakkera9379c02012-07-04 11:02:11 +0000161{
Paul Bakkera9379c02012-07-04 11:02:11 +0000162 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163 mbedtls_blowfish_context ctx;
Paul Bakkera9379c02012-07-04 11:02:11 +0000164
Paul Bakkera9379c02012-07-04 11:02:11 +0000165 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200166 mbedtls_blowfish_init( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000167
Paul Bakkera9379c02012-07-04 11:02:11 +0000168
Azim Khand30ca132017-06-09 04:32:58 +0100169 TEST_ASSERT( mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200170 if( setkey_result == 0 )
Paul Bakkera9379c02012-07-04 11:02:11 +0000171 {
Azim Khand30ca132017-06-09 04:32:58 +0100172 TEST_ASSERT( mbedtls_blowfish_crypt_ecb( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_str->x, output ) == 0 );
Paul Bakkera9379c02012-07-04 11:02:11 +0000173
Azim Khand30ca132017-06-09 04:32:58 +0100174 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 8, hex_dst_string->len ) == 0 );
Paul Bakkera9379c02012-07-04 11:02:11 +0000175 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200176
Paul Bakkerbd51b262014-07-10 15:26:12 +0200177exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200178 mbedtls_blowfish_free( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000179}
Paul Bakker33b43f12013-08-20 11:48:36 +0200180/* END_CASE */
Paul Bakkera9379c02012-07-04 11:02:11 +0000181
Paul Bakker33b43f12013-08-20 11:48:36 +0200182/* BEGIN_CASE */
Azim Khan5fcca462018-06-29 11:05:32 +0100183void blowfish_decrypt_ecb( data_t * key_str, data_t * src_str,
184 data_t * hex_dst_string, int setkey_result )
Paul Bakkera9379c02012-07-04 11:02:11 +0000185{
Paul Bakkera9379c02012-07-04 11:02:11 +0000186 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200187 mbedtls_blowfish_context ctx;
Paul Bakkera9379c02012-07-04 11:02:11 +0000188
Paul Bakkera9379c02012-07-04 11:02:11 +0000189 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200190 mbedtls_blowfish_init( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000191
Paul Bakkera9379c02012-07-04 11:02:11 +0000192
Azim Khand30ca132017-06-09 04:32:58 +0100193 TEST_ASSERT( mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200194 if( setkey_result == 0 )
Paul Bakkera9379c02012-07-04 11:02:11 +0000195 {
Azim Khand30ca132017-06-09 04:32:58 +0100196 TEST_ASSERT( mbedtls_blowfish_crypt_ecb( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_str->x, output ) == 0 );
Paul Bakkera9379c02012-07-04 11:02:11 +0000197
Azim Khand30ca132017-06-09 04:32:58 +0100198 TEST_ASSERT( hexcmp( output, hex_dst_string->x, 8, hex_dst_string->len ) == 0 );
Paul Bakkera9379c02012-07-04 11:02:11 +0000199 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200200
Paul Bakkerbd51b262014-07-10 15:26:12 +0200201exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200202 mbedtls_blowfish_free( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000203}
Paul Bakker33b43f12013-08-20 11:48:36 +0200204/* END_CASE */
Paul Bakkera9379c02012-07-04 11:02:11 +0000205
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200206/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khan5fcca462018-06-29 11:05:32 +0100207void blowfish_encrypt_cbc( data_t * key_str, data_t * iv_str,
208 data_t * src_str, data_t * hex_dst_string,
Azim Khand30ca132017-06-09 04:32:58 +0100209 int cbc_result )
Paul Bakkera9379c02012-07-04 11:02:11 +0000210{
Paul Bakkera9379c02012-07-04 11:02:11 +0000211 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200212 mbedtls_blowfish_context ctx;
Paul Bakkera9379c02012-07-04 11:02:11 +0000213
Paul Bakkera9379c02012-07-04 11:02:11 +0000214 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200215 mbedtls_blowfish_init( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000216
Paul Bakkera9379c02012-07-04 11:02:11 +0000217
Azim Khand30ca132017-06-09 04:32:58 +0100218 mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 );
Paul Bakkera9379c02012-07-04 11:02:11 +0000219
Azim Khand30ca132017-06-09 04:32:58 +0100220 TEST_ASSERT( mbedtls_blowfish_crypt_cbc( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_str->len , iv_str->x, src_str->x, output ) == cbc_result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200221 if( cbc_result == 0 )
Paul Bakkera9379c02012-07-04 11:02:11 +0000222 {
Paul Bakkera9379c02012-07-04 11:02:11 +0000223
Azim Khand30ca132017-06-09 04:32:58 +0100224 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Paul Bakkera9379c02012-07-04 11:02:11 +0000225 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200226
Paul Bakkerbd51b262014-07-10 15:26:12 +0200227exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228 mbedtls_blowfish_free( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000229}
Paul Bakker33b43f12013-08-20 11:48:36 +0200230/* END_CASE */
Paul Bakkera9379c02012-07-04 11:02:11 +0000231
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khan5fcca462018-06-29 11:05:32 +0100233void blowfish_decrypt_cbc( data_t * key_str, data_t * iv_str,
234 data_t * src_str, data_t * hex_dst_string,
Azim Khand30ca132017-06-09 04:32:58 +0100235 int cbc_result )
Paul Bakkera9379c02012-07-04 11:02:11 +0000236{
Paul Bakkera9379c02012-07-04 11:02:11 +0000237 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200238 mbedtls_blowfish_context ctx;
Paul Bakkera9379c02012-07-04 11:02:11 +0000239
Paul Bakkera9379c02012-07-04 11:02:11 +0000240 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200241 mbedtls_blowfish_init( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000242
Paul Bakkera9379c02012-07-04 11:02:11 +0000243
Azim Khand30ca132017-06-09 04:32:58 +0100244 mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 );
245 TEST_ASSERT( mbedtls_blowfish_crypt_cbc( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_str->len , iv_str->x, src_str->x, output ) == cbc_result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200246 if( cbc_result == 0)
Paul Bakkera9379c02012-07-04 11:02:11 +0000247 {
Paul Bakkera9379c02012-07-04 11:02:11 +0000248
Azim Khand30ca132017-06-09 04:32:58 +0100249 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Paul Bakkera9379c02012-07-04 11:02:11 +0000250 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200251
Paul Bakkerbd51b262014-07-10 15:26:12 +0200252exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200253 mbedtls_blowfish_free( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000254}
Paul Bakker33b43f12013-08-20 11:48:36 +0200255/* END_CASE */
Paul Bakkera9379c02012-07-04 11:02:11 +0000256
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200257/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
Azim Khan5fcca462018-06-29 11:05:32 +0100258void blowfish_encrypt_cfb64( data_t * key_str, data_t * iv_str,
259 data_t * src_str, data_t * hex_dst_string
Azim Khand30ca132017-06-09 04:32:58 +0100260 )
Paul Bakkera9379c02012-07-04 11:02:11 +0000261{
Paul Bakkera9379c02012-07-04 11:02:11 +0000262 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200263 mbedtls_blowfish_context ctx;
Paul Bakkera9379c02012-07-04 11:02:11 +0000264 size_t iv_offset = 0;
Paul Bakkera9379c02012-07-04 11:02:11 +0000265
Paul Bakkera9379c02012-07-04 11:02:11 +0000266 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200267 mbedtls_blowfish_init( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000268
Paul Bakkera9379c02012-07-04 11:02:11 +0000269
Azim Khand30ca132017-06-09 04:32:58 +0100270 mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 );
271 TEST_ASSERT( mbedtls_blowfish_crypt_cfb64( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_str->len, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
Paul Bakkera9379c02012-07-04 11:02:11 +0000272
Azim Khand30ca132017-06-09 04:32:58 +0100273 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200274
Paul Bakkerbd51b262014-07-10 15:26:12 +0200275exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200276 mbedtls_blowfish_free( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000277}
Paul Bakker33b43f12013-08-20 11:48:36 +0200278/* END_CASE */
Paul Bakkera9379c02012-07-04 11:02:11 +0000279
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
Azim Khan5fcca462018-06-29 11:05:32 +0100281void blowfish_decrypt_cfb64( data_t * key_str, data_t * iv_str,
282 data_t * src_str, data_t * hex_dst_string
Azim Khand30ca132017-06-09 04:32:58 +0100283 )
Paul Bakkera9379c02012-07-04 11:02:11 +0000284{
Paul Bakkera9379c02012-07-04 11:02:11 +0000285 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200286 mbedtls_blowfish_context ctx;
Paul Bakkera9379c02012-07-04 11:02:11 +0000287 size_t iv_offset = 0;
Paul Bakkera9379c02012-07-04 11:02:11 +0000288
Paul Bakkera9379c02012-07-04 11:02:11 +0000289 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290 mbedtls_blowfish_init( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000291
Paul Bakkera9379c02012-07-04 11:02:11 +0000292
Azim Khand30ca132017-06-09 04:32:58 +0100293 mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 );
294 TEST_ASSERT( mbedtls_blowfish_crypt_cfb64( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_str->len, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
Paul Bakkera9379c02012-07-04 11:02:11 +0000295
Azim Khand30ca132017-06-09 04:32:58 +0100296 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200297
Paul Bakkerbd51b262014-07-10 15:26:12 +0200298exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200299 mbedtls_blowfish_free( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000300}
Paul Bakker33b43f12013-08-20 11:48:36 +0200301/* END_CASE */
Paul Bakkera9379c02012-07-04 11:02:11 +0000302
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200303/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
Azim Khan5fcca462018-06-29 11:05:32 +0100304void blowfish_encrypt_ctr( data_t * key_str, data_t * iv_str,
305 data_t * src_str, data_t * hex_dst_string )
Paul Bakkera9379c02012-07-04 11:02:11 +0000306{
Paul Bakkera9379c02012-07-04 11:02:11 +0000307 unsigned char stream_str[100];
Paul Bakkera9379c02012-07-04 11:02:11 +0000308 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200309 mbedtls_blowfish_context ctx;
Paul Bakkera9379c02012-07-04 11:02:11 +0000310 size_t iv_offset = 0;
Paul Bakkera9379c02012-07-04 11:02:11 +0000311
Paul Bakkera9379c02012-07-04 11:02:11 +0000312 memset(stream_str, 0x00, 100);
Paul Bakkera9379c02012-07-04 11:02:11 +0000313 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200314 mbedtls_blowfish_init( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000315
Paul Bakkera9379c02012-07-04 11:02:11 +0000316
Azim Khand30ca132017-06-09 04:32:58 +0100317 mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 );
318 TEST_ASSERT( mbedtls_blowfish_crypt_ctr( &ctx, src_str->len, &iv_offset, iv_str->x, stream_str, src_str->x, output ) == 0 );
Paul Bakkera9379c02012-07-04 11:02:11 +0000319
Azim Khand30ca132017-06-09 04:32:58 +0100320 TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200321
Paul Bakkerbd51b262014-07-10 15:26:12 +0200322exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200323 mbedtls_blowfish_free( &ctx );
Paul Bakkera9379c02012-07-04 11:02:11 +0000324}
Paul Bakker33b43f12013-08-20 11:48:36 +0200325/* END_CASE */