PolarSSL v1.1.4
|
00001 #include "fct.h" 00002 00003 #include <polarssl/camellia.h> 00004 00005 #include <polarssl/config.h> 00006 00007 #ifdef _MSC_VER 00008 #include <basetsd.h> 00009 typedef UINT32 uint32_t; 00010 #else 00011 #include <inttypes.h> 00012 #endif 00013 00014 /* 00015 * 32-bit integer manipulation macros (big endian) 00016 */ 00017 #ifndef GET_ULONG_BE 00018 #define GET_ULONG_BE(n,b,i) \ 00019 { \ 00020 (n) = ( (unsigned long) (b)[(i) ] << 24 ) \ 00021 | ( (unsigned long) (b)[(i) + 1] << 16 ) \ 00022 | ( (unsigned long) (b)[(i) + 2] << 8 ) \ 00023 | ( (unsigned long) (b)[(i) + 3] ); \ 00024 } 00025 #endif 00026 00027 #ifndef PUT_ULONG_BE 00028 #define PUT_ULONG_BE(n,b,i) \ 00029 { \ 00030 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ 00031 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ 00032 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ 00033 (b)[(i) + 3] = (unsigned char) ( (n) ); \ 00034 } 00035 #endif 00036 00037 int unhexify(unsigned char *obuf, const char *ibuf) 00038 { 00039 unsigned char c, c2; 00040 int len = strlen(ibuf) / 2; 00041 assert(!(strlen(ibuf) %1)); // must be even number of bytes 00042 00043 while (*ibuf != 0) 00044 { 00045 c = *ibuf++; 00046 if( c >= '0' && c <= '9' ) 00047 c -= '0'; 00048 else if( c >= 'a' && c <= 'f' ) 00049 c -= 'a' - 10; 00050 else if( c >= 'A' && c <= 'F' ) 00051 c -= 'A' - 10; 00052 else 00053 assert( 0 ); 00054 00055 c2 = *ibuf++; 00056 if( c2 >= '0' && c2 <= '9' ) 00057 c2 -= '0'; 00058 else if( c2 >= 'a' && c2 <= 'f' ) 00059 c2 -= 'a' - 10; 00060 else if( c2 >= 'A' && c2 <= 'F' ) 00061 c2 -= 'A' - 10; 00062 else 00063 assert( 0 ); 00064 00065 *obuf++ = ( c << 4 ) | c2; 00066 } 00067 00068 return len; 00069 } 00070 00071 void hexify(unsigned char *obuf, const unsigned char *ibuf, int len) 00072 { 00073 unsigned char l, h; 00074 00075 while (len != 0) 00076 { 00077 h = (*ibuf) / 16; 00078 l = (*ibuf) % 16; 00079 00080 if( h < 10 ) 00081 *obuf++ = '0' + h; 00082 else 00083 *obuf++ = 'a' + h - 10; 00084 00085 if( l < 10 ) 00086 *obuf++ = '0' + l; 00087 else 00088 *obuf++ = 'a' + l - 10; 00089 00090 ++ibuf; 00091 len--; 00092 } 00093 } 00094 00104 static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len ) 00105 { 00106 size_t i; 00107 00108 if( rng_state != NULL ) 00109 rng_state = NULL; 00110 00111 for( i = 0; i < len; ++i ) 00112 output[i] = rand(); 00113 00114 return( 0 ); 00115 } 00116 00122 static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len ) 00123 { 00124 if( rng_state != NULL ) 00125 rng_state = NULL; 00126 00127 memset( output, 0, len ); 00128 00129 return( 0 ); 00130 } 00131 00132 typedef struct 00133 { 00134 unsigned char *buf; 00135 size_t length; 00136 } rnd_buf_info; 00137 00149 static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len ) 00150 { 00151 rnd_buf_info *info = (rnd_buf_info *) rng_state; 00152 size_t use_len; 00153 00154 if( rng_state == NULL ) 00155 return( rnd_std_rand( NULL, output, len ) ); 00156 00157 use_len = len; 00158 if( len > info->length ) 00159 use_len = info->length; 00160 00161 if( use_len ) 00162 { 00163 memcpy( output, info->buf, use_len ); 00164 info->buf += use_len; 00165 info->length -= use_len; 00166 } 00167 00168 if( len - use_len > 0 ) 00169 return( rnd_std_rand( NULL, output + use_len, len - use_len ) ); 00170 00171 return( 0 ); 00172 } 00173 00181 typedef struct 00182 { 00183 uint32_t key[16]; 00184 uint32_t v0, v1; 00185 } rnd_pseudo_info; 00186 00195 static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len ) 00196 { 00197 rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state; 00198 uint32_t i, *k, sum, delta=0x9E3779B9; 00199 unsigned char result[4]; 00200 00201 if( rng_state == NULL ) 00202 return( rnd_std_rand( NULL, output, len ) ); 00203 00204 k = info->key; 00205 00206 while( len > 0 ) 00207 { 00208 size_t use_len = ( len > 4 ) ? 4 : len; 00209 sum = 0; 00210 00211 for( i = 0; i < 32; i++ ) 00212 { 00213 info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]); 00214 sum += delta; 00215 info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]); 00216 } 00217 00218 PUT_ULONG_BE( info->v0, result, 0 ); 00219 memcpy( output, result, use_len ); 00220 len -= use_len; 00221 } 00222 00223 return( 0 ); 00224 } 00225 00226 00227 FCT_BGN() 00228 { 00229 #ifdef POLARSSL_CAMELLIA_C 00230 00231 00232 FCT_SUITE_BGN(test_suite_camellia) 00233 { 00234 00235 FCT_TEST_BGN(camellia_128_ecb_encrypt_rfc3713_1) 00236 { 00237 unsigned char key_str[100]; 00238 unsigned char src_str[100]; 00239 unsigned char dst_str[100]; 00240 unsigned char output[100]; 00241 camellia_context ctx; 00242 int key_len; 00243 00244 memset(key_str, 0x00, 100); 00245 memset(src_str, 0x00, 100); 00246 memset(dst_str, 0x00, 100); 00247 memset(output, 0x00, 100); 00248 00249 key_len = unhexify( key_str, "0123456789abcdeffedcba9876543210" ); 00250 unhexify( src_str, "0123456789abcdeffedcba9876543210" ); 00251 00252 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00253 if( 0 == 0 ) 00254 { 00255 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00256 hexify( dst_str, output, 16 ); 00257 00258 fct_chk( strcasecmp( (char *) dst_str, "67673138549669730857065648eabe43" ) == 0 ); 00259 } 00260 } 00261 FCT_TEST_END(); 00262 00263 00264 FCT_TEST_BGN(camellia_192_ecb_encrypt_rfc3713_1) 00265 { 00266 unsigned char key_str[100]; 00267 unsigned char src_str[100]; 00268 unsigned char dst_str[100]; 00269 unsigned char output[100]; 00270 camellia_context ctx; 00271 int key_len; 00272 00273 memset(key_str, 0x00, 100); 00274 memset(src_str, 0x00, 100); 00275 memset(dst_str, 0x00, 100); 00276 memset(output, 0x00, 100); 00277 00278 key_len = unhexify( key_str, "0123456789abcdeffedcba98765432100011223344556677" ); 00279 unhexify( src_str, "0123456789abcdeffedcba9876543210" ); 00280 00281 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00282 if( 0 == 0 ) 00283 { 00284 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00285 hexify( dst_str, output, 16 ); 00286 00287 fct_chk( strcasecmp( (char *) dst_str, "b4993401b3e996f84ee5cee7d79b09b9" ) == 0 ); 00288 } 00289 } 00290 FCT_TEST_END(); 00291 00292 00293 FCT_TEST_BGN(camellia_256_ecb_encrypt_rfc3713_1) 00294 { 00295 unsigned char key_str[100]; 00296 unsigned char src_str[100]; 00297 unsigned char dst_str[100]; 00298 unsigned char output[100]; 00299 camellia_context ctx; 00300 int key_len; 00301 00302 memset(key_str, 0x00, 100); 00303 memset(src_str, 0x00, 100); 00304 memset(dst_str, 0x00, 100); 00305 memset(output, 0x00, 100); 00306 00307 key_len = unhexify( key_str, "0123456789abcdeffedcba987654321000112233445566778899aabbccddeeff" ); 00308 unhexify( src_str, "0123456789abcdeffedcba9876543210" ); 00309 00310 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00311 if( 0 == 0 ) 00312 { 00313 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00314 hexify( dst_str, output, 16 ); 00315 00316 fct_chk( strcasecmp( (char *) dst_str, "9acc237dff16d76c20ef7c919e3a7509" ) == 0 ); 00317 } 00318 } 00319 FCT_TEST_END(); 00320 00321 00322 FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_1) 00323 { 00324 unsigned char key_str[100]; 00325 unsigned char src_str[100]; 00326 unsigned char dst_str[100]; 00327 unsigned char output[100]; 00328 camellia_context ctx; 00329 int key_len; 00330 00331 memset(key_str, 0x00, 100); 00332 memset(src_str, 0x00, 100); 00333 memset(dst_str, 0x00, 100); 00334 memset(output, 0x00, 100); 00335 00336 key_len = unhexify( key_str, "000102030405060708090A0B0C0D0E0F" ); 00337 unhexify( src_str, "00112233445566778899AABBCCDDEEFF" ); 00338 00339 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00340 if( 0 == 0 ) 00341 { 00342 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00343 hexify( dst_str, output, 16 ); 00344 00345 fct_chk( strcasecmp( (char *) dst_str, "77CF412067AF8270613529149919546F" ) == 0 ); 00346 } 00347 } 00348 FCT_TEST_END(); 00349 00350 00351 FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_1) 00352 { 00353 unsigned char key_str[100]; 00354 unsigned char src_str[100]; 00355 unsigned char dst_str[100]; 00356 unsigned char output[100]; 00357 camellia_context ctx; 00358 int key_len; 00359 00360 memset(key_str, 0x00, 100); 00361 memset(src_str, 0x00, 100); 00362 memset(dst_str, 0x00, 100); 00363 memset(output, 0x00, 100); 00364 00365 key_len = unhexify( key_str, "000102030405060708090A0B0C0D0E0F1011121314151617" ); 00366 unhexify( src_str, "00112233445566778899AABBCCDDEEFF" ); 00367 00368 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00369 if( 0 == 0 ) 00370 { 00371 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00372 hexify( dst_str, output, 16 ); 00373 00374 fct_chk( strcasecmp( (char *) dst_str, "B22F3C36B72D31329EEE8ADDC2906C68" ) == 0 ); 00375 } 00376 } 00377 FCT_TEST_END(); 00378 00379 00380 FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_1) 00381 { 00382 unsigned char key_str[100]; 00383 unsigned char src_str[100]; 00384 unsigned char dst_str[100]; 00385 unsigned char output[100]; 00386 camellia_context ctx; 00387 int key_len; 00388 00389 memset(key_str, 0x00, 100); 00390 memset(src_str, 0x00, 100); 00391 memset(dst_str, 0x00, 100); 00392 memset(output, 0x00, 100); 00393 00394 key_len = unhexify( key_str, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" ); 00395 unhexify( src_str, "00112233445566778899AABBCCDDEEFF" ); 00396 00397 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00398 if( 0 == 0 ) 00399 { 00400 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00401 hexify( dst_str, output, 16 ); 00402 00403 fct_chk( strcasecmp( (char *) dst_str, "2EDF1F3418D53B88841FC8985FB1ECF2" ) == 0 ); 00404 } 00405 } 00406 FCT_TEST_END(); 00407 00408 00409 FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_1) 00410 { 00411 unsigned char key_str[100]; 00412 unsigned char src_str[100]; 00413 unsigned char dst_str[100]; 00414 unsigned char output[100]; 00415 camellia_context ctx; 00416 int key_len; 00417 00418 memset(key_str, 0x00, 100); 00419 memset(src_str, 0x00, 100); 00420 memset(dst_str, 0x00, 100); 00421 memset(output, 0x00, 100); 00422 00423 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 00424 unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" ); 00425 00426 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00427 if( 0 == 0 ) 00428 { 00429 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00430 hexify( dst_str, output, 16 ); 00431 00432 fct_chk( strcasecmp( (char *) dst_str, "432FC5DCD628115B7C388D770B270C96" ) == 0 ); 00433 } 00434 } 00435 FCT_TEST_END(); 00436 00437 00438 FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_2) 00439 { 00440 unsigned char key_str[100]; 00441 unsigned char src_str[100]; 00442 unsigned char dst_str[100]; 00443 unsigned char output[100]; 00444 camellia_context ctx; 00445 int key_len; 00446 00447 memset(key_str, 0x00, 100); 00448 memset(src_str, 0x00, 100); 00449 memset(dst_str, 0x00, 100); 00450 memset(output, 0x00, 100); 00451 00452 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 00453 unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" ); 00454 00455 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00456 if( 0 == 0 ) 00457 { 00458 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00459 hexify( dst_str, output, 16 ); 00460 00461 fct_chk( strcasecmp( (char *) dst_str, "0BE1F14023782A22E8384C5ABB7FAB2B" ) == 0 ); 00462 } 00463 } 00464 FCT_TEST_END(); 00465 00466 00467 FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_3) 00468 { 00469 unsigned char key_str[100]; 00470 unsigned char src_str[100]; 00471 unsigned char dst_str[100]; 00472 unsigned char output[100]; 00473 camellia_context ctx; 00474 int key_len; 00475 00476 memset(key_str, 0x00, 100); 00477 memset(src_str, 0x00, 100); 00478 memset(dst_str, 0x00, 100); 00479 memset(output, 0x00, 100); 00480 00481 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 00482 unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" ); 00483 00484 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00485 if( 0 == 0 ) 00486 { 00487 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00488 hexify( dst_str, output, 16 ); 00489 00490 fct_chk( strcasecmp( (char *) dst_str, "A0A1ABCD1893AB6FE0FE5B65DF5F8636" ) == 0 ); 00491 } 00492 } 00493 FCT_TEST_END(); 00494 00495 00496 FCT_TEST_BGN(camellia_128_ecb_encrypt_perl_evp_4) 00497 { 00498 unsigned char key_str[100]; 00499 unsigned char src_str[100]; 00500 unsigned char dst_str[100]; 00501 unsigned char output[100]; 00502 camellia_context ctx; 00503 int key_len; 00504 00505 memset(key_str, 0x00, 100); 00506 memset(src_str, 0x00, 100); 00507 memset(dst_str, 0x00, 100); 00508 memset(output, 0x00, 100); 00509 00510 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 00511 unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" ); 00512 00513 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00514 if( 0 == 0 ) 00515 { 00516 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00517 hexify( dst_str, output, 16 ); 00518 00519 fct_chk( strcasecmp( (char *) dst_str, "E61925E0D5DFAA9BB29F815B3076E51A" ) == 0 ); 00520 } 00521 } 00522 FCT_TEST_END(); 00523 00524 00525 FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_1) 00526 { 00527 unsigned char key_str[100]; 00528 unsigned char src_str[100]; 00529 unsigned char dst_str[100]; 00530 unsigned char output[100]; 00531 camellia_context ctx; 00532 int key_len; 00533 00534 memset(key_str, 0x00, 100); 00535 memset(src_str, 0x00, 100); 00536 memset(dst_str, 0x00, 100); 00537 memset(output, 0x00, 100); 00538 00539 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 00540 unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" ); 00541 00542 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00543 if( 0 == 0 ) 00544 { 00545 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00546 hexify( dst_str, output, 16 ); 00547 00548 fct_chk( strcasecmp( (char *) dst_str, "CCCC6C4E138B45848514D48D0D3439D3" ) == 0 ); 00549 } 00550 } 00551 FCT_TEST_END(); 00552 00553 00554 FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_2) 00555 { 00556 unsigned char key_str[100]; 00557 unsigned char src_str[100]; 00558 unsigned char dst_str[100]; 00559 unsigned char output[100]; 00560 camellia_context ctx; 00561 int key_len; 00562 00563 memset(key_str, 0x00, 100); 00564 memset(src_str, 0x00, 100); 00565 memset(dst_str, 0x00, 100); 00566 memset(output, 0x00, 100); 00567 00568 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 00569 unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" ); 00570 00571 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00572 if( 0 == 0 ) 00573 { 00574 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00575 hexify( dst_str, output, 16 ); 00576 00577 fct_chk( strcasecmp( (char *) dst_str, "5713C62C14B2EC0F8393B6AFD6F5785A" ) == 0 ); 00578 } 00579 } 00580 FCT_TEST_END(); 00581 00582 00583 FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_3) 00584 { 00585 unsigned char key_str[100]; 00586 unsigned char src_str[100]; 00587 unsigned char dst_str[100]; 00588 unsigned char output[100]; 00589 camellia_context ctx; 00590 int key_len; 00591 00592 memset(key_str, 0x00, 100); 00593 memset(src_str, 0x00, 100); 00594 memset(dst_str, 0x00, 100); 00595 memset(output, 0x00, 100); 00596 00597 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 00598 unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" ); 00599 00600 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00601 if( 0 == 0 ) 00602 { 00603 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00604 hexify( dst_str, output, 16 ); 00605 00606 fct_chk( strcasecmp( (char *) dst_str, "B40ED2B60EB54D09D030CF511FEEF366" ) == 0 ); 00607 } 00608 } 00609 FCT_TEST_END(); 00610 00611 00612 FCT_TEST_BGN(camellia_192_ecb_encrypt_perl_evp_4) 00613 { 00614 unsigned char key_str[100]; 00615 unsigned char src_str[100]; 00616 unsigned char dst_str[100]; 00617 unsigned char output[100]; 00618 camellia_context ctx; 00619 int key_len; 00620 00621 memset(key_str, 0x00, 100); 00622 memset(src_str, 0x00, 100); 00623 memset(dst_str, 0x00, 100); 00624 memset(output, 0x00, 100); 00625 00626 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 00627 unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" ); 00628 00629 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00630 if( 0 == 0 ) 00631 { 00632 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00633 hexify( dst_str, output, 16 ); 00634 00635 fct_chk( strcasecmp( (char *) dst_str, "909DBD95799096748CB27357E73E1D26" ) == 0 ); 00636 } 00637 } 00638 FCT_TEST_END(); 00639 00640 00641 FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_1) 00642 { 00643 unsigned char key_str[100]; 00644 unsigned char src_str[100]; 00645 unsigned char dst_str[100]; 00646 unsigned char output[100]; 00647 camellia_context ctx; 00648 int key_len; 00649 00650 memset(key_str, 0x00, 100); 00651 memset(src_str, 0x00, 100); 00652 memset(dst_str, 0x00, 100); 00653 memset(output, 0x00, 100); 00654 00655 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 00656 unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" ); 00657 00658 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00659 if( 0 == 0 ) 00660 { 00661 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00662 hexify( dst_str, output, 16 ); 00663 00664 fct_chk( strcasecmp( (char *) dst_str, "BEFD219B112FA00098919CD101C9CCFA" ) == 0 ); 00665 } 00666 } 00667 FCT_TEST_END(); 00668 00669 00670 FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_2) 00671 { 00672 unsigned char key_str[100]; 00673 unsigned char src_str[100]; 00674 unsigned char dst_str[100]; 00675 unsigned char output[100]; 00676 camellia_context ctx; 00677 int key_len; 00678 00679 memset(key_str, 0x00, 100); 00680 memset(src_str, 0x00, 100); 00681 memset(dst_str, 0x00, 100); 00682 memset(output, 0x00, 100); 00683 00684 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 00685 unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" ); 00686 00687 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00688 if( 0 == 0 ) 00689 { 00690 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00691 hexify( dst_str, output, 16 ); 00692 00693 fct_chk( strcasecmp( (char *) dst_str, "C91D3A8F1AEA08A9386CF4B66C0169EA" ) == 0 ); 00694 } 00695 } 00696 FCT_TEST_END(); 00697 00698 00699 FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_3) 00700 { 00701 unsigned char key_str[100]; 00702 unsigned char src_str[100]; 00703 unsigned char dst_str[100]; 00704 unsigned char output[100]; 00705 camellia_context ctx; 00706 int key_len; 00707 00708 memset(key_str, 0x00, 100); 00709 memset(src_str, 0x00, 100); 00710 memset(dst_str, 0x00, 100); 00711 memset(output, 0x00, 100); 00712 00713 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 00714 unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" ); 00715 00716 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00717 if( 0 == 0 ) 00718 { 00719 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00720 hexify( dst_str, output, 16 ); 00721 00722 fct_chk( strcasecmp( (char *) dst_str, "A623D711DC5F25A51BB8A80D56397D28" ) == 0 ); 00723 } 00724 } 00725 FCT_TEST_END(); 00726 00727 00728 FCT_TEST_BGN(camellia_256_ecb_encrypt_perl_evp_4) 00729 { 00730 unsigned char key_str[100]; 00731 unsigned char src_str[100]; 00732 unsigned char dst_str[100]; 00733 unsigned char output[100]; 00734 camellia_context ctx; 00735 int key_len; 00736 00737 memset(key_str, 0x00, 100); 00738 memset(src_str, 0x00, 100); 00739 memset(dst_str, 0x00, 100); 00740 memset(output, 0x00, 100); 00741 00742 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 00743 unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" ); 00744 00745 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == 0 ); 00746 if( 0 == 0 ) 00747 { 00748 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 00749 hexify( dst_str, output, 16 ); 00750 00751 fct_chk( strcasecmp( (char *) dst_str, "7960109FB6DC42947FCFE59EA3C5EB6B" ) == 0 ); 00752 } 00753 } 00754 FCT_TEST_END(); 00755 00756 00757 FCT_TEST_BGN(camellia_128_cbc_encrypt_perl_evp_1) 00758 { 00759 unsigned char key_str[100]; 00760 unsigned char iv_str[100]; 00761 unsigned char src_str[100]; 00762 unsigned char dst_str[100]; 00763 unsigned char output[100]; 00764 camellia_context ctx; 00765 int key_len, data_len; 00766 00767 memset(key_str, 0x00, 100); 00768 memset(iv_str, 0x00, 100); 00769 memset(src_str, 0x00, 100); 00770 memset(dst_str, 0x00, 100); 00771 memset(output, 0x00, 100); 00772 00773 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 00774 unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" ); 00775 data_len = unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" ); 00776 00777 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 00778 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 ); 00779 if( 0 == 0 ) 00780 { 00781 hexify( dst_str, output, data_len ); 00782 00783 fct_chk( strcasecmp( (char *) dst_str, "1607CF494B36BBF00DAEB0B503C831AB" ) == 0 ); 00784 } 00785 } 00786 FCT_TEST_END(); 00787 00788 00789 FCT_TEST_BGN(camellia_128_cbc_encrypt_perl_evp_2) 00790 { 00791 unsigned char key_str[100]; 00792 unsigned char iv_str[100]; 00793 unsigned char src_str[100]; 00794 unsigned char dst_str[100]; 00795 unsigned char output[100]; 00796 camellia_context ctx; 00797 int key_len, data_len; 00798 00799 memset(key_str, 0x00, 100); 00800 memset(iv_str, 0x00, 100); 00801 memset(src_str, 0x00, 100); 00802 memset(dst_str, 0x00, 100); 00803 memset(output, 0x00, 100); 00804 00805 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 00806 unhexify( iv_str, "1607CF494B36BBF00DAEB0B503C831AB" ); 00807 data_len = unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" ); 00808 00809 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 00810 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 ); 00811 if( 0 == 0 ) 00812 { 00813 hexify( dst_str, output, data_len ); 00814 00815 fct_chk( strcasecmp( (char *) dst_str, "A2F2CF671629EF7840C5A5DFB5074887" ) == 0 ); 00816 } 00817 } 00818 FCT_TEST_END(); 00819 00820 00821 FCT_TEST_BGN(camellia_128_cbc_encrypt_perl_evp_3) 00822 { 00823 unsigned char key_str[100]; 00824 unsigned char iv_str[100]; 00825 unsigned char src_str[100]; 00826 unsigned char dst_str[100]; 00827 unsigned char output[100]; 00828 camellia_context ctx; 00829 int key_len, data_len; 00830 00831 memset(key_str, 0x00, 100); 00832 memset(iv_str, 0x00, 100); 00833 memset(src_str, 0x00, 100); 00834 memset(dst_str, 0x00, 100); 00835 memset(output, 0x00, 100); 00836 00837 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 00838 unhexify( iv_str, "A2F2CF671629EF7840C5A5DFB5074887" ); 00839 data_len = unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" ); 00840 00841 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 00842 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 ); 00843 if( 0 == 0 ) 00844 { 00845 hexify( dst_str, output, data_len ); 00846 00847 fct_chk( strcasecmp( (char *) dst_str, "0F06165008CF8B8B5A63586362543E54" ) == 0 ); 00848 } 00849 } 00850 FCT_TEST_END(); 00851 00852 00853 FCT_TEST_BGN(camellia_128_cbc_encrypt_perl_evp_4) 00854 { 00855 unsigned char key_str[100]; 00856 unsigned char iv_str[100]; 00857 unsigned char src_str[100]; 00858 unsigned char dst_str[100]; 00859 unsigned char output[100]; 00860 camellia_context ctx; 00861 int key_len, data_len; 00862 00863 memset(key_str, 0x00, 100); 00864 memset(iv_str, 0x00, 100); 00865 memset(src_str, 0x00, 100); 00866 memset(dst_str, 0x00, 100); 00867 memset(output, 0x00, 100); 00868 00869 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 00870 unhexify( iv_str, "36A84CDAFD5F9A85ADA0F0A993D6D577" ); 00871 data_len = unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" ); 00872 00873 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 00874 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 ); 00875 if( 0 == 0 ) 00876 { 00877 hexify( dst_str, output, data_len ); 00878 00879 fct_chk( strcasecmp( (char *) dst_str, "74C64268CDB8B8FAF5B34E8AF3732980" ) == 0 ); 00880 } 00881 } 00882 FCT_TEST_END(); 00883 00884 00885 FCT_TEST_BGN(camellia_192_cbc_encrypt_perl_evp_1) 00886 { 00887 unsigned char key_str[100]; 00888 unsigned char iv_str[100]; 00889 unsigned char src_str[100]; 00890 unsigned char dst_str[100]; 00891 unsigned char output[100]; 00892 camellia_context ctx; 00893 int key_len, data_len; 00894 00895 memset(key_str, 0x00, 100); 00896 memset(iv_str, 0x00, 100); 00897 memset(src_str, 0x00, 100); 00898 memset(dst_str, 0x00, 100); 00899 memset(output, 0x00, 100); 00900 00901 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 00902 unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" ); 00903 data_len = unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" ); 00904 00905 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 00906 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 ); 00907 if( 0 == 0 ) 00908 { 00909 hexify( dst_str, output, data_len ); 00910 00911 fct_chk( strcasecmp( (char *) dst_str, "2A4830AB5AC4A1A2405955FD2195CF93" ) == 0 ); 00912 } 00913 } 00914 FCT_TEST_END(); 00915 00916 00917 FCT_TEST_BGN(camellia_192_cbc_encrypt_perl_evp_2) 00918 { 00919 unsigned char key_str[100]; 00920 unsigned char iv_str[100]; 00921 unsigned char src_str[100]; 00922 unsigned char dst_str[100]; 00923 unsigned char output[100]; 00924 camellia_context ctx; 00925 int key_len, data_len; 00926 00927 memset(key_str, 0x00, 100); 00928 memset(iv_str, 0x00, 100); 00929 memset(src_str, 0x00, 100); 00930 memset(dst_str, 0x00, 100); 00931 memset(output, 0x00, 100); 00932 00933 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 00934 unhexify( iv_str, "2A4830AB5AC4A1A2405955FD2195CF93" ); 00935 data_len = unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" ); 00936 00937 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 00938 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 ); 00939 if( 0 == 0 ) 00940 { 00941 hexify( dst_str, output, data_len ); 00942 00943 fct_chk( strcasecmp( (char *) dst_str, "5D5A869BD14CE54264F892A6DD2EC3D5" ) == 0 ); 00944 } 00945 } 00946 FCT_TEST_END(); 00947 00948 00949 FCT_TEST_BGN(camellia_192_cbc_encrypt_perl_evp_3) 00950 { 00951 unsigned char key_str[100]; 00952 unsigned char iv_str[100]; 00953 unsigned char src_str[100]; 00954 unsigned char dst_str[100]; 00955 unsigned char output[100]; 00956 camellia_context ctx; 00957 int key_len, data_len; 00958 00959 memset(key_str, 0x00, 100); 00960 memset(iv_str, 0x00, 100); 00961 memset(src_str, 0x00, 100); 00962 memset(dst_str, 0x00, 100); 00963 memset(output, 0x00, 100); 00964 00965 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 00966 unhexify( iv_str, "5D5A869BD14CE54264F892A6DD2EC3D5" ); 00967 data_len = unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" ); 00968 00969 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 00970 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 ); 00971 if( 0 == 0 ) 00972 { 00973 hexify( dst_str, output, data_len ); 00974 00975 fct_chk( strcasecmp( (char *) dst_str, "37D359C3349836D884E310ADDF68C449" ) == 0 ); 00976 } 00977 } 00978 FCT_TEST_END(); 00979 00980 00981 FCT_TEST_BGN(camellia_192_cbc_encrypt_perl_evp_4) 00982 { 00983 unsigned char key_str[100]; 00984 unsigned char iv_str[100]; 00985 unsigned char src_str[100]; 00986 unsigned char dst_str[100]; 00987 unsigned char output[100]; 00988 camellia_context ctx; 00989 int key_len, data_len; 00990 00991 memset(key_str, 0x00, 100); 00992 memset(iv_str, 0x00, 100); 00993 memset(src_str, 0x00, 100); 00994 memset(dst_str, 0x00, 100); 00995 memset(output, 0x00, 100); 00996 00997 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 00998 unhexify( iv_str, "37D359C3349836D884E310ADDF68C449" ); 00999 data_len = unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" ); 01000 01001 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01002 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 ); 01003 if( 0 == 0 ) 01004 { 01005 hexify( dst_str, output, data_len ); 01006 01007 fct_chk( strcasecmp( (char *) dst_str, "01FAAA930B4AB9916E9668E1428C6B08" ) == 0 ); 01008 } 01009 } 01010 FCT_TEST_END(); 01011 01012 01013 FCT_TEST_BGN(camellia_256_cbc_encrypt_perl_evp_1) 01014 { 01015 unsigned char key_str[100]; 01016 unsigned char iv_str[100]; 01017 unsigned char src_str[100]; 01018 unsigned char dst_str[100]; 01019 unsigned char output[100]; 01020 camellia_context ctx; 01021 int key_len, data_len; 01022 01023 memset(key_str, 0x00, 100); 01024 memset(iv_str, 0x00, 100); 01025 memset(src_str, 0x00, 100); 01026 memset(dst_str, 0x00, 100); 01027 memset(output, 0x00, 100); 01028 01029 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 01030 unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" ); 01031 data_len = unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" ); 01032 01033 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01034 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 ); 01035 if( 0 == 0 ) 01036 { 01037 hexify( dst_str, output, data_len ); 01038 01039 fct_chk( strcasecmp( (char *) dst_str, "E6CFA35FC02B134A4D2C0B6737AC3EDA" ) == 0 ); 01040 } 01041 } 01042 FCT_TEST_END(); 01043 01044 01045 FCT_TEST_BGN(camellia_256_cbc_encrypt_perl_evp_2) 01046 { 01047 unsigned char key_str[100]; 01048 unsigned char iv_str[100]; 01049 unsigned char src_str[100]; 01050 unsigned char dst_str[100]; 01051 unsigned char output[100]; 01052 camellia_context ctx; 01053 int key_len, data_len; 01054 01055 memset(key_str, 0x00, 100); 01056 memset(iv_str, 0x00, 100); 01057 memset(src_str, 0x00, 100); 01058 memset(dst_str, 0x00, 100); 01059 memset(output, 0x00, 100); 01060 01061 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 01062 unhexify( iv_str, "E6CFA35FC02B134A4D2C0B6737AC3EDA" ); 01063 data_len = unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" ); 01064 01065 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01066 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 ); 01067 if( 0 == 0 ) 01068 { 01069 hexify( dst_str, output, data_len ); 01070 01071 fct_chk( strcasecmp( (char *) dst_str, "36CBEB73BD504B4070B1B7DE2B21EB50" ) == 0 ); 01072 } 01073 } 01074 FCT_TEST_END(); 01075 01076 01077 FCT_TEST_BGN(camellia_256_cbc_encrypt_perl_evp_3) 01078 { 01079 unsigned char key_str[100]; 01080 unsigned char iv_str[100]; 01081 unsigned char src_str[100]; 01082 unsigned char dst_str[100]; 01083 unsigned char output[100]; 01084 camellia_context ctx; 01085 int key_len, data_len; 01086 01087 memset(key_str, 0x00, 100); 01088 memset(iv_str, 0x00, 100); 01089 memset(src_str, 0x00, 100); 01090 memset(dst_str, 0x00, 100); 01091 memset(output, 0x00, 100); 01092 01093 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 01094 unhexify( iv_str, "36CBEB73BD504B4070B1B7DE2B21EB50" ); 01095 data_len = unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" ); 01096 01097 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01098 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 ); 01099 if( 0 == 0 ) 01100 { 01101 hexify( dst_str, output, data_len ); 01102 01103 fct_chk( strcasecmp( (char *) dst_str, "E31A6055297D96CA3330CDF1B1860A83" ) == 0 ); 01104 } 01105 } 01106 FCT_TEST_END(); 01107 01108 01109 FCT_TEST_BGN(camellia_256_cbc_encrypt_perl_evp_4) 01110 { 01111 unsigned char key_str[100]; 01112 unsigned char iv_str[100]; 01113 unsigned char src_str[100]; 01114 unsigned char dst_str[100]; 01115 unsigned char output[100]; 01116 camellia_context ctx; 01117 int key_len, data_len; 01118 01119 memset(key_str, 0x00, 100); 01120 memset(iv_str, 0x00, 100); 01121 memset(src_str, 0x00, 100); 01122 memset(dst_str, 0x00, 100); 01123 memset(output, 0x00, 100); 01124 01125 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 01126 unhexify( iv_str, "E31A6055297D96CA3330CDF1B1860A83" ); 01127 data_len = unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" ); 01128 01129 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01130 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == 0 ); 01131 if( 0 == 0 ) 01132 { 01133 hexify( dst_str, output, data_len ); 01134 01135 fct_chk( strcasecmp( (char *) dst_str, "5D563F6D1CCCF236051C0C5C1C58F28F" ) == 0 ); 01136 } 01137 } 01138 FCT_TEST_END(); 01139 01140 #ifdef POLARSSL_CIPHER_MODE_CFB 01141 01142 FCT_TEST_BGN(camellia_128_cfb128_encrypt_perl_evp_1) 01143 { 01144 unsigned char key_str[100]; 01145 unsigned char iv_str[100]; 01146 unsigned char src_str[100]; 01147 unsigned char dst_str[100]; 01148 unsigned char output[100]; 01149 camellia_context ctx; 01150 size_t iv_offset = 0; 01151 int key_len; 01152 01153 memset(key_str, 0x00, 100); 01154 memset(iv_str, 0x00, 100); 01155 memset(src_str, 0x00, 100); 01156 memset(dst_str, 0x00, 100); 01157 memset(output, 0x00, 100); 01158 01159 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 01160 unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" ); 01161 unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" ); 01162 01163 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01164 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01165 hexify( dst_str, output, 16 ); 01166 01167 fct_chk( strcasecmp( (char *) dst_str, "14F7646187817EB586599146B82BD719" ) == 0 ); 01168 } 01169 FCT_TEST_END(); 01170 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01171 01172 #ifdef POLARSSL_CIPHER_MODE_CFB 01173 01174 FCT_TEST_BGN(camellia_128_cfb128_encrypt_perl_evp_2) 01175 { 01176 unsigned char key_str[100]; 01177 unsigned char iv_str[100]; 01178 unsigned char src_str[100]; 01179 unsigned char dst_str[100]; 01180 unsigned char output[100]; 01181 camellia_context ctx; 01182 size_t iv_offset = 0; 01183 int key_len; 01184 01185 memset(key_str, 0x00, 100); 01186 memset(iv_str, 0x00, 100); 01187 memset(src_str, 0x00, 100); 01188 memset(dst_str, 0x00, 100); 01189 memset(output, 0x00, 100); 01190 01191 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 01192 unhexify( iv_str, "14F7646187817EB586599146B82BD719" ); 01193 unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" ); 01194 01195 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01196 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01197 hexify( dst_str, output, 16 ); 01198 01199 fct_chk( strcasecmp( (char *) dst_str, "A53D28BB82DF741103EA4F921A44880B" ) == 0 ); 01200 } 01201 FCT_TEST_END(); 01202 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01203 01204 #ifdef POLARSSL_CIPHER_MODE_CFB 01205 01206 FCT_TEST_BGN(camellia_128_cfb128_encrypt_perl_evp_3) 01207 { 01208 unsigned char key_str[100]; 01209 unsigned char iv_str[100]; 01210 unsigned char src_str[100]; 01211 unsigned char dst_str[100]; 01212 unsigned char output[100]; 01213 camellia_context ctx; 01214 size_t iv_offset = 0; 01215 int key_len; 01216 01217 memset(key_str, 0x00, 100); 01218 memset(iv_str, 0x00, 100); 01219 memset(src_str, 0x00, 100); 01220 memset(dst_str, 0x00, 100); 01221 memset(output, 0x00, 100); 01222 01223 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 01224 unhexify( iv_str, "A53D28BB82DF741103EA4F921A44880B" ); 01225 unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" ); 01226 01227 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01228 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01229 hexify( dst_str, output, 16 ); 01230 01231 fct_chk( strcasecmp( (char *) dst_str, "9C2157A664626D1DEF9EA420FDE69B96" ) == 0 ); 01232 } 01233 FCT_TEST_END(); 01234 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01235 01236 #ifdef POLARSSL_CIPHER_MODE_CFB 01237 01238 FCT_TEST_BGN(camellia_128_cfb128_encrypt_perl_evp_4) 01239 { 01240 unsigned char key_str[100]; 01241 unsigned char iv_str[100]; 01242 unsigned char src_str[100]; 01243 unsigned char dst_str[100]; 01244 unsigned char output[100]; 01245 camellia_context ctx; 01246 size_t iv_offset = 0; 01247 int key_len; 01248 01249 memset(key_str, 0x00, 100); 01250 memset(iv_str, 0x00, 100); 01251 memset(src_str, 0x00, 100); 01252 memset(dst_str, 0x00, 100); 01253 memset(output, 0x00, 100); 01254 01255 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 01256 unhexify( iv_str, "9C2157A664626D1DEF9EA420FDE69B96" ); 01257 unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" ); 01258 01259 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01260 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01261 hexify( dst_str, output, 16 ); 01262 01263 fct_chk( strcasecmp( (char *) dst_str, "742A25F0542340C7BAEF24CA8482BB09" ) == 0 ); 01264 } 01265 FCT_TEST_END(); 01266 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01267 01268 #ifdef POLARSSL_CIPHER_MODE_CFB 01269 01270 FCT_TEST_BGN(camellia_128_cfb128_decrypt_perl_evp_1) 01271 { 01272 unsigned char key_str[100]; 01273 unsigned char iv_str[100]; 01274 unsigned char src_str[100]; 01275 unsigned char dst_str[100]; 01276 unsigned char output[100]; 01277 camellia_context ctx; 01278 size_t iv_offset = 0; 01279 int key_len; 01280 01281 memset(key_str, 0x00, 100); 01282 memset(iv_str, 0x00, 100); 01283 memset(src_str, 0x00, 100); 01284 memset(dst_str, 0x00, 100); 01285 memset(output, 0x00, 100); 01286 01287 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 01288 unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" ); 01289 unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" ); 01290 01291 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01292 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01293 hexify( dst_str, output, 16 ); 01294 01295 fct_chk( strcasecmp( (char *) dst_str, "14F7646187817EB586599146B82BD719" ) == 0 ); 01296 } 01297 FCT_TEST_END(); 01298 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01299 01300 #ifdef POLARSSL_CIPHER_MODE_CFB 01301 01302 FCT_TEST_BGN(camellia_128_cfb128_decrypt_perl_evp_2) 01303 { 01304 unsigned char key_str[100]; 01305 unsigned char iv_str[100]; 01306 unsigned char src_str[100]; 01307 unsigned char dst_str[100]; 01308 unsigned char output[100]; 01309 camellia_context ctx; 01310 size_t iv_offset = 0; 01311 int key_len; 01312 01313 memset(key_str, 0x00, 100); 01314 memset(iv_str, 0x00, 100); 01315 memset(src_str, 0x00, 100); 01316 memset(dst_str, 0x00, 100); 01317 memset(output, 0x00, 100); 01318 01319 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 01320 unhexify( iv_str, "14F7646187817EB586599146B82BD719" ); 01321 unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" ); 01322 01323 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01324 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01325 hexify( dst_str, output, 16 ); 01326 01327 fct_chk( strcasecmp( (char *) dst_str, "A53D28BB82DF741103EA4F921A44880B" ) == 0 ); 01328 } 01329 FCT_TEST_END(); 01330 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01331 01332 #ifdef POLARSSL_CIPHER_MODE_CFB 01333 01334 FCT_TEST_BGN(camellia_128_cfb128_decrypt_perl_evp_3) 01335 { 01336 unsigned char key_str[100]; 01337 unsigned char iv_str[100]; 01338 unsigned char src_str[100]; 01339 unsigned char dst_str[100]; 01340 unsigned char output[100]; 01341 camellia_context ctx; 01342 size_t iv_offset = 0; 01343 int key_len; 01344 01345 memset(key_str, 0x00, 100); 01346 memset(iv_str, 0x00, 100); 01347 memset(src_str, 0x00, 100); 01348 memset(dst_str, 0x00, 100); 01349 memset(output, 0x00, 100); 01350 01351 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 01352 unhexify( iv_str, "A53D28BB82DF741103EA4F921A44880B" ); 01353 unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" ); 01354 01355 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01356 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01357 hexify( dst_str, output, 16 ); 01358 01359 fct_chk( strcasecmp( (char *) dst_str, "9C2157A664626D1DEF9EA420FDE69B96" ) == 0 ); 01360 } 01361 FCT_TEST_END(); 01362 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01363 01364 #ifdef POLARSSL_CIPHER_MODE_CFB 01365 01366 FCT_TEST_BGN(camellia_128_cfb128_decrypt_perl_evp_4) 01367 { 01368 unsigned char key_str[100]; 01369 unsigned char iv_str[100]; 01370 unsigned char src_str[100]; 01371 unsigned char dst_str[100]; 01372 unsigned char output[100]; 01373 camellia_context ctx; 01374 size_t iv_offset = 0; 01375 int key_len; 01376 01377 memset(key_str, 0x00, 100); 01378 memset(iv_str, 0x00, 100); 01379 memset(src_str, 0x00, 100); 01380 memset(dst_str, 0x00, 100); 01381 memset(output, 0x00, 100); 01382 01383 key_len = unhexify( key_str, "2B7E151628AED2A6ABF7158809CF4F3C" ); 01384 unhexify( iv_str, "9C2157A664626D1DEF9EA420FDE69B96" ); 01385 unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" ); 01386 01387 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01388 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01389 hexify( dst_str, output, 16 ); 01390 01391 fct_chk( strcasecmp( (char *) dst_str, "742A25F0542340C7BAEF24CA8482BB09" ) == 0 ); 01392 } 01393 FCT_TEST_END(); 01394 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01395 01396 #ifdef POLARSSL_CIPHER_MODE_CFB 01397 01398 FCT_TEST_BGN(camellia_192_cfb128_encrypt_perl_evp_1) 01399 { 01400 unsigned char key_str[100]; 01401 unsigned char iv_str[100]; 01402 unsigned char src_str[100]; 01403 unsigned char dst_str[100]; 01404 unsigned char output[100]; 01405 camellia_context ctx; 01406 size_t iv_offset = 0; 01407 int key_len; 01408 01409 memset(key_str, 0x00, 100); 01410 memset(iv_str, 0x00, 100); 01411 memset(src_str, 0x00, 100); 01412 memset(dst_str, 0x00, 100); 01413 memset(output, 0x00, 100); 01414 01415 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 01416 unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" ); 01417 unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" ); 01418 01419 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01420 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01421 hexify( dst_str, output, 16 ); 01422 01423 fct_chk( strcasecmp( (char *) dst_str, "C832BB9780677DAA82D9B6860DCD565E" ) == 0 ); 01424 } 01425 FCT_TEST_END(); 01426 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01427 01428 #ifdef POLARSSL_CIPHER_MODE_CFB 01429 01430 FCT_TEST_BGN(camellia_192_cfb128_encrypt_perl_evp_2) 01431 { 01432 unsigned char key_str[100]; 01433 unsigned char iv_str[100]; 01434 unsigned char src_str[100]; 01435 unsigned char dst_str[100]; 01436 unsigned char output[100]; 01437 camellia_context ctx; 01438 size_t iv_offset = 0; 01439 int key_len; 01440 01441 memset(key_str, 0x00, 100); 01442 memset(iv_str, 0x00, 100); 01443 memset(src_str, 0x00, 100); 01444 memset(dst_str, 0x00, 100); 01445 memset(output, 0x00, 100); 01446 01447 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 01448 unhexify( iv_str, "C832BB9780677DAA82D9B6860DCD565E" ); 01449 unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" ); 01450 01451 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01452 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01453 hexify( dst_str, output, 16 ); 01454 01455 fct_chk( strcasecmp( (char *) dst_str, "86F8491627906D780C7A6D46EA331F98" ) == 0 ); 01456 } 01457 FCT_TEST_END(); 01458 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01459 01460 #ifdef POLARSSL_CIPHER_MODE_CFB 01461 01462 FCT_TEST_BGN(camellia_192_cfb128_encrypt_perl_evp_3) 01463 { 01464 unsigned char key_str[100]; 01465 unsigned char iv_str[100]; 01466 unsigned char src_str[100]; 01467 unsigned char dst_str[100]; 01468 unsigned char output[100]; 01469 camellia_context ctx; 01470 size_t iv_offset = 0; 01471 int key_len; 01472 01473 memset(key_str, 0x00, 100); 01474 memset(iv_str, 0x00, 100); 01475 memset(src_str, 0x00, 100); 01476 memset(dst_str, 0x00, 100); 01477 memset(output, 0x00, 100); 01478 01479 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 01480 unhexify( iv_str, "86F8491627906D780C7A6D46EA331F98" ); 01481 unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" ); 01482 01483 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01484 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01485 hexify( dst_str, output, 16 ); 01486 01487 fct_chk( strcasecmp( (char *) dst_str, "69511CCE594CF710CB98BB63D7221F01" ) == 0 ); 01488 } 01489 FCT_TEST_END(); 01490 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01491 01492 #ifdef POLARSSL_CIPHER_MODE_CFB 01493 01494 FCT_TEST_BGN(camellia_192_cfb128_encrypt_perl_evp_4) 01495 { 01496 unsigned char key_str[100]; 01497 unsigned char iv_str[100]; 01498 unsigned char src_str[100]; 01499 unsigned char dst_str[100]; 01500 unsigned char output[100]; 01501 camellia_context ctx; 01502 size_t iv_offset = 0; 01503 int key_len; 01504 01505 memset(key_str, 0x00, 100); 01506 memset(iv_str, 0x00, 100); 01507 memset(src_str, 0x00, 100); 01508 memset(dst_str, 0x00, 100); 01509 memset(output, 0x00, 100); 01510 01511 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 01512 unhexify( iv_str, "69511CCE594CF710CB98BB63D7221F01" ); 01513 unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" ); 01514 01515 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01516 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01517 hexify( dst_str, output, 16 ); 01518 01519 fct_chk( strcasecmp( (char *) dst_str, "D5B5378A3ABED55803F25565D8907B84" ) == 0 ); 01520 } 01521 FCT_TEST_END(); 01522 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01523 01524 #ifdef POLARSSL_CIPHER_MODE_CFB 01525 01526 FCT_TEST_BGN(camellia_192_cfb128_decrypt_perl_evp_1) 01527 { 01528 unsigned char key_str[100]; 01529 unsigned char iv_str[100]; 01530 unsigned char src_str[100]; 01531 unsigned char dst_str[100]; 01532 unsigned char output[100]; 01533 camellia_context ctx; 01534 size_t iv_offset = 0; 01535 int key_len; 01536 01537 memset(key_str, 0x00, 100); 01538 memset(iv_str, 0x00, 100); 01539 memset(src_str, 0x00, 100); 01540 memset(dst_str, 0x00, 100); 01541 memset(output, 0x00, 100); 01542 01543 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 01544 unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" ); 01545 unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" ); 01546 01547 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01548 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01549 hexify( dst_str, output, 16 ); 01550 01551 fct_chk( strcasecmp( (char *) dst_str, "C832BB9780677DAA82D9B6860DCD565E" ) == 0 ); 01552 } 01553 FCT_TEST_END(); 01554 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01555 01556 #ifdef POLARSSL_CIPHER_MODE_CFB 01557 01558 FCT_TEST_BGN(camellia_192_cfb128_decrypt_perl_evp_2) 01559 { 01560 unsigned char key_str[100]; 01561 unsigned char iv_str[100]; 01562 unsigned char src_str[100]; 01563 unsigned char dst_str[100]; 01564 unsigned char output[100]; 01565 camellia_context ctx; 01566 size_t iv_offset = 0; 01567 int key_len; 01568 01569 memset(key_str, 0x00, 100); 01570 memset(iv_str, 0x00, 100); 01571 memset(src_str, 0x00, 100); 01572 memset(dst_str, 0x00, 100); 01573 memset(output, 0x00, 100); 01574 01575 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 01576 unhexify( iv_str, "C832BB9780677DAA82D9B6860DCD565E" ); 01577 unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" ); 01578 01579 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01580 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01581 hexify( dst_str, output, 16 ); 01582 01583 fct_chk( strcasecmp( (char *) dst_str, "86F8491627906D780C7A6D46EA331F98" ) == 0 ); 01584 } 01585 FCT_TEST_END(); 01586 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01587 01588 #ifdef POLARSSL_CIPHER_MODE_CFB 01589 01590 FCT_TEST_BGN(camellia_192_cfb128_decrypt_perl_evp_3) 01591 { 01592 unsigned char key_str[100]; 01593 unsigned char iv_str[100]; 01594 unsigned char src_str[100]; 01595 unsigned char dst_str[100]; 01596 unsigned char output[100]; 01597 camellia_context ctx; 01598 size_t iv_offset = 0; 01599 int key_len; 01600 01601 memset(key_str, 0x00, 100); 01602 memset(iv_str, 0x00, 100); 01603 memset(src_str, 0x00, 100); 01604 memset(dst_str, 0x00, 100); 01605 memset(output, 0x00, 100); 01606 01607 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 01608 unhexify( iv_str, "86F8491627906D780C7A6D46EA331F98" ); 01609 unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" ); 01610 01611 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01612 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01613 hexify( dst_str, output, 16 ); 01614 01615 fct_chk( strcasecmp( (char *) dst_str, "69511CCE594CF710CB98BB63D7221F01" ) == 0 ); 01616 } 01617 FCT_TEST_END(); 01618 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01619 01620 #ifdef POLARSSL_CIPHER_MODE_CFB 01621 01622 FCT_TEST_BGN(camellia_192_cfb128_decrypt_perl_evp_4) 01623 { 01624 unsigned char key_str[100]; 01625 unsigned char iv_str[100]; 01626 unsigned char src_str[100]; 01627 unsigned char dst_str[100]; 01628 unsigned char output[100]; 01629 camellia_context ctx; 01630 size_t iv_offset = 0; 01631 int key_len; 01632 01633 memset(key_str, 0x00, 100); 01634 memset(iv_str, 0x00, 100); 01635 memset(src_str, 0x00, 100); 01636 memset(dst_str, 0x00, 100); 01637 memset(output, 0x00, 100); 01638 01639 key_len = unhexify( key_str, "8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B" ); 01640 unhexify( iv_str, "69511CCE594CF710CB98BB63D7221F01" ); 01641 unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" ); 01642 01643 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01644 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01645 hexify( dst_str, output, 16 ); 01646 01647 fct_chk( strcasecmp( (char *) dst_str, "D5B5378A3ABED55803F25565D8907B84" ) == 0 ); 01648 } 01649 FCT_TEST_END(); 01650 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01651 01652 #ifdef POLARSSL_CIPHER_MODE_CFB 01653 01654 FCT_TEST_BGN(camellia_256_cfb128_encrypt_perl_evp_1) 01655 { 01656 unsigned char key_str[100]; 01657 unsigned char iv_str[100]; 01658 unsigned char src_str[100]; 01659 unsigned char dst_str[100]; 01660 unsigned char output[100]; 01661 camellia_context ctx; 01662 size_t iv_offset = 0; 01663 int key_len; 01664 01665 memset(key_str, 0x00, 100); 01666 memset(iv_str, 0x00, 100); 01667 memset(src_str, 0x00, 100); 01668 memset(dst_str, 0x00, 100); 01669 memset(output, 0x00, 100); 01670 01671 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 01672 unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" ); 01673 unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" ); 01674 01675 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01676 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01677 hexify( dst_str, output, 16 ); 01678 01679 fct_chk( strcasecmp( (char *) dst_str, "CF6107BB0CEA7D7FB1BD31F5E7B06C93" ) == 0 ); 01680 } 01681 FCT_TEST_END(); 01682 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01683 01684 #ifdef POLARSSL_CIPHER_MODE_CFB 01685 01686 FCT_TEST_BGN(camellia_256_cfb128_encrypt_perl_evp_2) 01687 { 01688 unsigned char key_str[100]; 01689 unsigned char iv_str[100]; 01690 unsigned char src_str[100]; 01691 unsigned char dst_str[100]; 01692 unsigned char output[100]; 01693 camellia_context ctx; 01694 size_t iv_offset = 0; 01695 int key_len; 01696 01697 memset(key_str, 0x00, 100); 01698 memset(iv_str, 0x00, 100); 01699 memset(src_str, 0x00, 100); 01700 memset(dst_str, 0x00, 100); 01701 memset(output, 0x00, 100); 01702 01703 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 01704 unhexify( iv_str, "CF6107BB0CEA7D7FB1BD31F5E7B06C93" ); 01705 unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" ); 01706 01707 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01708 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01709 hexify( dst_str, output, 16 ); 01710 01711 fct_chk( strcasecmp( (char *) dst_str, "89BEDB4CCDD864EA11BA4CBE849B5E2B" ) == 0 ); 01712 } 01713 FCT_TEST_END(); 01714 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01715 01716 #ifdef POLARSSL_CIPHER_MODE_CFB 01717 01718 FCT_TEST_BGN(camellia_256_cfb128_encrypt_perl_evp_3) 01719 { 01720 unsigned char key_str[100]; 01721 unsigned char iv_str[100]; 01722 unsigned char src_str[100]; 01723 unsigned char dst_str[100]; 01724 unsigned char output[100]; 01725 camellia_context ctx; 01726 size_t iv_offset = 0; 01727 int key_len; 01728 01729 memset(key_str, 0x00, 100); 01730 memset(iv_str, 0x00, 100); 01731 memset(src_str, 0x00, 100); 01732 memset(dst_str, 0x00, 100); 01733 memset(output, 0x00, 100); 01734 01735 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 01736 unhexify( iv_str, "89BEDB4CCDD864EA11BA4CBE849B5E2B" ); 01737 unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" ); 01738 01739 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01740 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01741 hexify( dst_str, output, 16 ); 01742 01743 fct_chk( strcasecmp( (char *) dst_str, "555FC3F34BDD2D54C62D9E3BF338C1C4" ) == 0 ); 01744 } 01745 FCT_TEST_END(); 01746 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01747 01748 #ifdef POLARSSL_CIPHER_MODE_CFB 01749 01750 FCT_TEST_BGN(camellia_256_cfb128_encrypt_perl_evp_4) 01751 { 01752 unsigned char key_str[100]; 01753 unsigned char iv_str[100]; 01754 unsigned char src_str[100]; 01755 unsigned char dst_str[100]; 01756 unsigned char output[100]; 01757 camellia_context ctx; 01758 size_t iv_offset = 0; 01759 int key_len; 01760 01761 memset(key_str, 0x00, 100); 01762 memset(iv_str, 0x00, 100); 01763 memset(src_str, 0x00, 100); 01764 memset(dst_str, 0x00, 100); 01765 memset(output, 0x00, 100); 01766 01767 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 01768 unhexify( iv_str, "555FC3F34BDD2D54C62D9E3BF338C1C4" ); 01769 unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" ); 01770 01771 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01772 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01773 hexify( dst_str, output, 16 ); 01774 01775 fct_chk( strcasecmp( (char *) dst_str, "5953ADCE14DB8C7F39F1BD39F359BFFA" ) == 0 ); 01776 } 01777 FCT_TEST_END(); 01778 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01779 01780 #ifdef POLARSSL_CIPHER_MODE_CFB 01781 01782 FCT_TEST_BGN(camellia_256_cfb128_decrypt_perl_evp_1) 01783 { 01784 unsigned char key_str[100]; 01785 unsigned char iv_str[100]; 01786 unsigned char src_str[100]; 01787 unsigned char dst_str[100]; 01788 unsigned char output[100]; 01789 camellia_context ctx; 01790 size_t iv_offset = 0; 01791 int key_len; 01792 01793 memset(key_str, 0x00, 100); 01794 memset(iv_str, 0x00, 100); 01795 memset(src_str, 0x00, 100); 01796 memset(dst_str, 0x00, 100); 01797 memset(output, 0x00, 100); 01798 01799 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 01800 unhexify( iv_str, "000102030405060708090A0B0C0D0E0F" ); 01801 unhexify( src_str, "6BC1BEE22E409F96E93D7E117393172A" ); 01802 01803 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01804 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01805 hexify( dst_str, output, 16 ); 01806 01807 fct_chk( strcasecmp( (char *) dst_str, "CF6107BB0CEA7D7FB1BD31F5E7B06C93" ) == 0 ); 01808 } 01809 FCT_TEST_END(); 01810 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01811 01812 #ifdef POLARSSL_CIPHER_MODE_CFB 01813 01814 FCT_TEST_BGN(camellia_256_cfb128_decrypt_perl_evp_2) 01815 { 01816 unsigned char key_str[100]; 01817 unsigned char iv_str[100]; 01818 unsigned char src_str[100]; 01819 unsigned char dst_str[100]; 01820 unsigned char output[100]; 01821 camellia_context ctx; 01822 size_t iv_offset = 0; 01823 int key_len; 01824 01825 memset(key_str, 0x00, 100); 01826 memset(iv_str, 0x00, 100); 01827 memset(src_str, 0x00, 100); 01828 memset(dst_str, 0x00, 100); 01829 memset(output, 0x00, 100); 01830 01831 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 01832 unhexify( iv_str, "CF6107BB0CEA7D7FB1BD31F5E7B06C93" ); 01833 unhexify( src_str, "AE2D8A571E03AC9C9EB76FAC45AF8E51" ); 01834 01835 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01836 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01837 hexify( dst_str, output, 16 ); 01838 01839 fct_chk( strcasecmp( (char *) dst_str, "89BEDB4CCDD864EA11BA4CBE849B5E2B" ) == 0 ); 01840 } 01841 FCT_TEST_END(); 01842 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01843 01844 #ifdef POLARSSL_CIPHER_MODE_CFB 01845 01846 FCT_TEST_BGN(camellia_256_cfb128_decrypt_perl_evp_3) 01847 { 01848 unsigned char key_str[100]; 01849 unsigned char iv_str[100]; 01850 unsigned char src_str[100]; 01851 unsigned char dst_str[100]; 01852 unsigned char output[100]; 01853 camellia_context ctx; 01854 size_t iv_offset = 0; 01855 int key_len; 01856 01857 memset(key_str, 0x00, 100); 01858 memset(iv_str, 0x00, 100); 01859 memset(src_str, 0x00, 100); 01860 memset(dst_str, 0x00, 100); 01861 memset(output, 0x00, 100); 01862 01863 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 01864 unhexify( iv_str, "89BEDB4CCDD864EA11BA4CBE849B5E2B" ); 01865 unhexify( src_str, "30C81C46A35CE411E5FBC1191A0A52EF" ); 01866 01867 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01868 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01869 hexify( dst_str, output, 16 ); 01870 01871 fct_chk( strcasecmp( (char *) dst_str, "555FC3F34BDD2D54C62D9E3BF338C1C4" ) == 0 ); 01872 } 01873 FCT_TEST_END(); 01874 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01875 01876 #ifdef POLARSSL_CIPHER_MODE_CFB 01877 01878 FCT_TEST_BGN(camellia_256_cfb128_decrypt_perl_evp_4) 01879 { 01880 unsigned char key_str[100]; 01881 unsigned char iv_str[100]; 01882 unsigned char src_str[100]; 01883 unsigned char dst_str[100]; 01884 unsigned char output[100]; 01885 camellia_context ctx; 01886 size_t iv_offset = 0; 01887 int key_len; 01888 01889 memset(key_str, 0x00, 100); 01890 memset(iv_str, 0x00, 100); 01891 memset(src_str, 0x00, 100); 01892 memset(dst_str, 0x00, 100); 01893 memset(output, 0x00, 100); 01894 01895 key_len = unhexify( key_str, "603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4" ); 01896 unhexify( iv_str, "555FC3F34BDD2D54C62D9E3BF338C1C4" ); 01897 unhexify( src_str, "F69F2445DF4F9B17AD2B417BE66C3710" ); 01898 01899 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01900 fct_chk( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 ); 01901 hexify( dst_str, output, 16 ); 01902 01903 fct_chk( strcasecmp( (char *) dst_str, "5953ADCE14DB8C7F39F1BD39F359BFFA" ) == 0 ); 01904 } 01905 FCT_TEST_END(); 01906 #endif /* POLARSSL_CIPHER_MODE_CFB */ 01907 01908 01909 FCT_TEST_BGN(camellia_ecb_encrypt_invalid_key_length) 01910 { 01911 unsigned char key_str[100]; 01912 unsigned char src_str[100]; 01913 unsigned char dst_str[100]; 01914 unsigned char output[100]; 01915 camellia_context ctx; 01916 int key_len; 01917 01918 memset(key_str, 0x00, 100); 01919 memset(src_str, 0x00, 100); 01920 memset(dst_str, 0x00, 100); 01921 memset(output, 0x00, 100); 01922 01923 key_len = unhexify( key_str, "0123456789abcdeffedcba98765432" ); 01924 unhexify( src_str, "0123456789abcdeffedcba9876543210" ); 01925 01926 fct_chk( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH ); 01927 if( POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH == 0 ) 01928 { 01929 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 ); 01930 hexify( dst_str, output, 16 ); 01931 01932 fct_chk( strcasecmp( (char *) dst_str, "67673138549669730857065648eabe43" ) == 0 ); 01933 } 01934 } 01935 FCT_TEST_END(); 01936 01937 01938 FCT_TEST_BGN(camellia_ecb_decrypt_invalid_key_length) 01939 { 01940 unsigned char key_str[100]; 01941 unsigned char src_str[100]; 01942 unsigned char dst_str[100]; 01943 unsigned char output[100]; 01944 camellia_context ctx; 01945 int key_len; 01946 01947 memset(key_str, 0x00, 100); 01948 memset(src_str, 0x00, 100); 01949 memset(dst_str, 0x00, 100); 01950 memset(output, 0x00, 100); 01951 01952 key_len = unhexify( key_str, "0123456789abcdeffedcba98765432" ); 01953 unhexify( src_str, "0123456789abcdeffedcba9876543210" ); 01954 01955 fct_chk( camellia_setkey_dec( &ctx, key_str, key_len * 8 ) == POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH ); 01956 if( POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH == 0 ) 01957 { 01958 fct_chk( camellia_crypt_ecb( &ctx, CAMELLIA_DECRYPT, src_str, output ) == 0 ); 01959 hexify( dst_str, output, 16 ); 01960 01961 fct_chk( strcasecmp( (char *) dst_str, "67673138549669730857065648eabe43" ) == 0 ); 01962 } 01963 } 01964 FCT_TEST_END(); 01965 01966 01967 FCT_TEST_BGN(camellia_256_cbc_encrypt_invalid_input_length) 01968 { 01969 unsigned char key_str[100]; 01970 unsigned char iv_str[100]; 01971 unsigned char src_str[100]; 01972 unsigned char dst_str[100]; 01973 unsigned char output[100]; 01974 camellia_context ctx; 01975 int key_len, data_len; 01976 01977 memset(key_str, 0x00, 100); 01978 memset(iv_str, 0x00, 100); 01979 memset(src_str, 0x00, 100); 01980 memset(dst_str, 0x00, 100); 01981 memset(output, 0x00, 100); 01982 01983 key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" ); 01984 unhexify( iv_str, "00000000000000000000000000000000" ); 01985 data_len = unhexify( src_str, "ffffffffffffffe000000000000000" ); 01986 01987 camellia_setkey_enc( &ctx, key_str, key_len * 8 ); 01988 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH ); 01989 if( POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH == 0 ) 01990 { 01991 hexify( dst_str, output, data_len ); 01992 01993 fct_chk( strcasecmp( (char *) dst_str, "" ) == 0 ); 01994 } 01995 } 01996 FCT_TEST_END(); 01997 01998 01999 FCT_TEST_BGN(camellia_256_cbc_decrypt_invalid_input_length) 02000 { 02001 unsigned char key_str[100]; 02002 unsigned char iv_str[100]; 02003 unsigned char src_str[100]; 02004 unsigned char dst_str[100]; 02005 unsigned char output[100]; 02006 camellia_context ctx; 02007 int key_len, data_len; 02008 02009 memset(key_str, 0x00, 100); 02010 memset(iv_str, 0x00, 100); 02011 memset(src_str, 0x00, 100); 02012 memset(dst_str, 0x00, 100); 02013 memset(output, 0x00, 100); 02014 02015 key_len = unhexify( key_str, "0000000000000000000000000000000000000000000000000000000000000000" ); 02016 unhexify( iv_str, "00000000000000000000000000000000" ); 02017 data_len = unhexify( src_str, "623a52fcea5d443e48d9181ab32c74" ); 02018 02019 camellia_setkey_dec( &ctx, key_str, key_len * 8 ); 02020 fct_chk( camellia_crypt_cbc( &ctx, CAMELLIA_DECRYPT, data_len, iv_str, src_str, output ) == POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH ); 02021 if( POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH == 0 ) 02022 { 02023 hexify( dst_str, output, data_len ); 02024 02025 fct_chk( strcasecmp( (char *) dst_str, "" ) == 0 ); 02026 } 02027 } 02028 FCT_TEST_END(); 02029 02030 #ifdef POLARSSL_SELF_TEST 02031 02032 FCT_TEST_BGN(camellia_selftest) 02033 { 02034 fct_chk( camellia_self_test( 0 ) == 0 ); 02035 } 02036 FCT_TEST_END(); 02037 #endif /* POLARSSL_SELF_TEST */ 02038 02039 } 02040 FCT_SUITE_END(); 02041 02042 #endif /* POLARSSL_CAMELLIA_C */ 02043 02044 } 02045 FCT_END(); 02046