PolarSSL v1.1.4
|
00001 #include "fct.h" 00002 00003 #include <polarssl/des.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_DES_C 00230 00231 00232 FCT_SUITE_BGN(test_suite_des) 00233 { 00234 00235 FCT_TEST_BGN(des_encrypt_openssl_test_vector_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 des_context ctx; 00242 00243 memset(key_str, 0x00, 100); 00244 memset(src_str, 0x00, 100); 00245 memset(dst_str, 0x00, 100); 00246 memset(output, 0x00, 100); 00247 00248 unhexify( key_str, "0000000000000000" ); 00249 unhexify( src_str, "0000000000000000" ); 00250 00251 des_setkey_enc( &ctx, key_str ); 00252 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00253 hexify( dst_str, output, 8 ); 00254 00255 fct_chk( strcasecmp( (char *) dst_str, "8CA64DE9C1B123A7" ) == 0 ); 00256 } 00257 FCT_TEST_END(); 00258 00259 00260 FCT_TEST_BGN(des_encrypt_openssl_test_vector_2) 00261 { 00262 unsigned char key_str[100]; 00263 unsigned char src_str[100]; 00264 unsigned char dst_str[100]; 00265 unsigned char output[100]; 00266 des_context ctx; 00267 00268 memset(key_str, 0x00, 100); 00269 memset(src_str, 0x00, 100); 00270 memset(dst_str, 0x00, 100); 00271 memset(output, 0x00, 100); 00272 00273 unhexify( key_str, "FFFFFFFFFFFFFFFF" ); 00274 unhexify( src_str, "FFFFFFFFFFFFFFFF" ); 00275 00276 des_setkey_enc( &ctx, key_str ); 00277 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00278 hexify( dst_str, output, 8 ); 00279 00280 fct_chk( strcasecmp( (char *) dst_str, "7359B2163E4EDC58" ) == 0 ); 00281 } 00282 FCT_TEST_END(); 00283 00284 00285 FCT_TEST_BGN(des_encrypt_openssl_test_vector_3) 00286 { 00287 unsigned char key_str[100]; 00288 unsigned char src_str[100]; 00289 unsigned char dst_str[100]; 00290 unsigned char output[100]; 00291 des_context ctx; 00292 00293 memset(key_str, 0x00, 100); 00294 memset(src_str, 0x00, 100); 00295 memset(dst_str, 0x00, 100); 00296 memset(output, 0x00, 100); 00297 00298 unhexify( key_str, "3000000000000000" ); 00299 unhexify( src_str, "1000000000000001" ); 00300 00301 des_setkey_enc( &ctx, key_str ); 00302 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00303 hexify( dst_str, output, 8 ); 00304 00305 fct_chk( strcasecmp( (char *) dst_str, "958E6E627A05557B" ) == 0 ); 00306 } 00307 FCT_TEST_END(); 00308 00309 00310 FCT_TEST_BGN(des_encrypt_openssl_test_vector_4) 00311 { 00312 unsigned char key_str[100]; 00313 unsigned char src_str[100]; 00314 unsigned char dst_str[100]; 00315 unsigned char output[100]; 00316 des_context ctx; 00317 00318 memset(key_str, 0x00, 100); 00319 memset(src_str, 0x00, 100); 00320 memset(dst_str, 0x00, 100); 00321 memset(output, 0x00, 100); 00322 00323 unhexify( key_str, "1111111111111111" ); 00324 unhexify( src_str, "1111111111111111" ); 00325 00326 des_setkey_enc( &ctx, key_str ); 00327 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00328 hexify( dst_str, output, 8 ); 00329 00330 fct_chk( strcasecmp( (char *) dst_str, "F40379AB9E0EC533" ) == 0 ); 00331 } 00332 FCT_TEST_END(); 00333 00334 00335 FCT_TEST_BGN(des_encrypt_openssl_test_vector_5) 00336 { 00337 unsigned char key_str[100]; 00338 unsigned char src_str[100]; 00339 unsigned char dst_str[100]; 00340 unsigned char output[100]; 00341 des_context ctx; 00342 00343 memset(key_str, 0x00, 100); 00344 memset(src_str, 0x00, 100); 00345 memset(dst_str, 0x00, 100); 00346 memset(output, 0x00, 100); 00347 00348 unhexify( key_str, "0123456789ABCDEF" ); 00349 unhexify( src_str, "1111111111111111" ); 00350 00351 des_setkey_enc( &ctx, key_str ); 00352 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00353 hexify( dst_str, output, 8 ); 00354 00355 fct_chk( strcasecmp( (char *) dst_str, "17668DFC7292532D" ) == 0 ); 00356 } 00357 FCT_TEST_END(); 00358 00359 00360 FCT_TEST_BGN(des_encrypt_openssl_test_vector_6) 00361 { 00362 unsigned char key_str[100]; 00363 unsigned char src_str[100]; 00364 unsigned char dst_str[100]; 00365 unsigned char output[100]; 00366 des_context ctx; 00367 00368 memset(key_str, 0x00, 100); 00369 memset(src_str, 0x00, 100); 00370 memset(dst_str, 0x00, 100); 00371 memset(output, 0x00, 100); 00372 00373 unhexify( key_str, "1111111111111111" ); 00374 unhexify( src_str, "0123456789ABCDEF" ); 00375 00376 des_setkey_enc( &ctx, key_str ); 00377 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00378 hexify( dst_str, output, 8 ); 00379 00380 fct_chk( strcasecmp( (char *) dst_str, "8A5AE1F81AB8F2DD" ) == 0 ); 00381 } 00382 FCT_TEST_END(); 00383 00384 00385 FCT_TEST_BGN(des_encrypt_openssl_test_vector_7) 00386 { 00387 unsigned char key_str[100]; 00388 unsigned char src_str[100]; 00389 unsigned char dst_str[100]; 00390 unsigned char output[100]; 00391 des_context ctx; 00392 00393 memset(key_str, 0x00, 100); 00394 memset(src_str, 0x00, 100); 00395 memset(dst_str, 0x00, 100); 00396 memset(output, 0x00, 100); 00397 00398 unhexify( key_str, "0000000000000000" ); 00399 unhexify( src_str, "0000000000000000" ); 00400 00401 des_setkey_enc( &ctx, key_str ); 00402 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00403 hexify( dst_str, output, 8 ); 00404 00405 fct_chk( strcasecmp( (char *) dst_str, "8CA64DE9C1B123A7" ) == 0 ); 00406 } 00407 FCT_TEST_END(); 00408 00409 00410 FCT_TEST_BGN(des_encrypt_openssl_test_vector_8) 00411 { 00412 unsigned char key_str[100]; 00413 unsigned char src_str[100]; 00414 unsigned char dst_str[100]; 00415 unsigned char output[100]; 00416 des_context ctx; 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 unhexify( key_str, "FEDCBA9876543210" ); 00424 unhexify( src_str, "0123456789ABCDEF" ); 00425 00426 des_setkey_enc( &ctx, key_str ); 00427 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00428 hexify( dst_str, output, 8 ); 00429 00430 fct_chk( strcasecmp( (char *) dst_str, "ED39D950FA74BCC4" ) == 0 ); 00431 } 00432 FCT_TEST_END(); 00433 00434 00435 FCT_TEST_BGN(des_encrypt_openssl_test_vector_9) 00436 { 00437 unsigned char key_str[100]; 00438 unsigned char src_str[100]; 00439 unsigned char dst_str[100]; 00440 unsigned char output[100]; 00441 des_context ctx; 00442 00443 memset(key_str, 0x00, 100); 00444 memset(src_str, 0x00, 100); 00445 memset(dst_str, 0x00, 100); 00446 memset(output, 0x00, 100); 00447 00448 unhexify( key_str, "7CA110454A1A6E57" ); 00449 unhexify( src_str, "01A1D6D039776742" ); 00450 00451 des_setkey_enc( &ctx, key_str ); 00452 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00453 hexify( dst_str, output, 8 ); 00454 00455 fct_chk( strcasecmp( (char *) dst_str, "690F5B0D9A26939B" ) == 0 ); 00456 } 00457 FCT_TEST_END(); 00458 00459 00460 FCT_TEST_BGN(des_encrypt_openssl_test_vector_10) 00461 { 00462 unsigned char key_str[100]; 00463 unsigned char src_str[100]; 00464 unsigned char dst_str[100]; 00465 unsigned char output[100]; 00466 des_context ctx; 00467 00468 memset(key_str, 0x00, 100); 00469 memset(src_str, 0x00, 100); 00470 memset(dst_str, 0x00, 100); 00471 memset(output, 0x00, 100); 00472 00473 unhexify( key_str, "0131D9619DC1376E" ); 00474 unhexify( src_str, "5CD54CA83DEF57DA" ); 00475 00476 des_setkey_enc( &ctx, key_str ); 00477 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00478 hexify( dst_str, output, 8 ); 00479 00480 fct_chk( strcasecmp( (char *) dst_str, "7A389D10354BD271" ) == 0 ); 00481 } 00482 FCT_TEST_END(); 00483 00484 00485 FCT_TEST_BGN(des_encrypt_openssl_test_vector_11) 00486 { 00487 unsigned char key_str[100]; 00488 unsigned char src_str[100]; 00489 unsigned char dst_str[100]; 00490 unsigned char output[100]; 00491 des_context ctx; 00492 00493 memset(key_str, 0x00, 100); 00494 memset(src_str, 0x00, 100); 00495 memset(dst_str, 0x00, 100); 00496 memset(output, 0x00, 100); 00497 00498 unhexify( key_str, "07A1133E4A0B2686" ); 00499 unhexify( src_str, "0248D43806F67172" ); 00500 00501 des_setkey_enc( &ctx, key_str ); 00502 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00503 hexify( dst_str, output, 8 ); 00504 00505 fct_chk( strcasecmp( (char *) dst_str, "868EBB51CAB4599A" ) == 0 ); 00506 } 00507 FCT_TEST_END(); 00508 00509 00510 FCT_TEST_BGN(des_encrypt_openssl_test_vector_12) 00511 { 00512 unsigned char key_str[100]; 00513 unsigned char src_str[100]; 00514 unsigned char dst_str[100]; 00515 unsigned char output[100]; 00516 des_context ctx; 00517 00518 memset(key_str, 0x00, 100); 00519 memset(src_str, 0x00, 100); 00520 memset(dst_str, 0x00, 100); 00521 memset(output, 0x00, 100); 00522 00523 unhexify( key_str, "3849674C2602319E" ); 00524 unhexify( src_str, "51454B582DDF440A" ); 00525 00526 des_setkey_enc( &ctx, key_str ); 00527 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00528 hexify( dst_str, output, 8 ); 00529 00530 fct_chk( strcasecmp( (char *) dst_str, "7178876E01F19B2A" ) == 0 ); 00531 } 00532 FCT_TEST_END(); 00533 00534 00535 FCT_TEST_BGN(des_encrypt_openssl_test_vector_13) 00536 { 00537 unsigned char key_str[100]; 00538 unsigned char src_str[100]; 00539 unsigned char dst_str[100]; 00540 unsigned char output[100]; 00541 des_context ctx; 00542 00543 memset(key_str, 0x00, 100); 00544 memset(src_str, 0x00, 100); 00545 memset(dst_str, 0x00, 100); 00546 memset(output, 0x00, 100); 00547 00548 unhexify( key_str, "04B915BA43FEB5B6" ); 00549 unhexify( src_str, "42FD443059577FA2" ); 00550 00551 des_setkey_enc( &ctx, key_str ); 00552 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00553 hexify( dst_str, output, 8 ); 00554 00555 fct_chk( strcasecmp( (char *) dst_str, "AF37FB421F8C4095" ) == 0 ); 00556 } 00557 FCT_TEST_END(); 00558 00559 00560 FCT_TEST_BGN(des_encrypt_openssl_test_vector_14) 00561 { 00562 unsigned char key_str[100]; 00563 unsigned char src_str[100]; 00564 unsigned char dst_str[100]; 00565 unsigned char output[100]; 00566 des_context ctx; 00567 00568 memset(key_str, 0x00, 100); 00569 memset(src_str, 0x00, 100); 00570 memset(dst_str, 0x00, 100); 00571 memset(output, 0x00, 100); 00572 00573 unhexify( key_str, "0113B970FD34F2CE" ); 00574 unhexify( src_str, "059B5E0851CF143A" ); 00575 00576 des_setkey_enc( &ctx, key_str ); 00577 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00578 hexify( dst_str, output, 8 ); 00579 00580 fct_chk( strcasecmp( (char *) dst_str, "86A560F10EC6D85B" ) == 0 ); 00581 } 00582 FCT_TEST_END(); 00583 00584 00585 FCT_TEST_BGN(des_encrypt_openssl_test_vector_15) 00586 { 00587 unsigned char key_str[100]; 00588 unsigned char src_str[100]; 00589 unsigned char dst_str[100]; 00590 unsigned char output[100]; 00591 des_context ctx; 00592 00593 memset(key_str, 0x00, 100); 00594 memset(src_str, 0x00, 100); 00595 memset(dst_str, 0x00, 100); 00596 memset(output, 0x00, 100); 00597 00598 unhexify( key_str, "0170F175468FB5E6" ); 00599 unhexify( src_str, "0756D8E0774761D2" ); 00600 00601 des_setkey_enc( &ctx, key_str ); 00602 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00603 hexify( dst_str, output, 8 ); 00604 00605 fct_chk( strcasecmp( (char *) dst_str, "0CD3DA020021DC09" ) == 0 ); 00606 } 00607 FCT_TEST_END(); 00608 00609 00610 FCT_TEST_BGN(des_encrypt_openssl_test_vector_16) 00611 { 00612 unsigned char key_str[100]; 00613 unsigned char src_str[100]; 00614 unsigned char dst_str[100]; 00615 unsigned char output[100]; 00616 des_context ctx; 00617 00618 memset(key_str, 0x00, 100); 00619 memset(src_str, 0x00, 100); 00620 memset(dst_str, 0x00, 100); 00621 memset(output, 0x00, 100); 00622 00623 unhexify( key_str, "43297FAD38E373FE" ); 00624 unhexify( src_str, "762514B829BF486A" ); 00625 00626 des_setkey_enc( &ctx, key_str ); 00627 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00628 hexify( dst_str, output, 8 ); 00629 00630 fct_chk( strcasecmp( (char *) dst_str, "EA676B2CB7DB2B7A" ) == 0 ); 00631 } 00632 FCT_TEST_END(); 00633 00634 00635 FCT_TEST_BGN(des_encrypt_openssl_test_vector_17) 00636 { 00637 unsigned char key_str[100]; 00638 unsigned char src_str[100]; 00639 unsigned char dst_str[100]; 00640 unsigned char output[100]; 00641 des_context ctx; 00642 00643 memset(key_str, 0x00, 100); 00644 memset(src_str, 0x00, 100); 00645 memset(dst_str, 0x00, 100); 00646 memset(output, 0x00, 100); 00647 00648 unhexify( key_str, "07A7137045DA2A16" ); 00649 unhexify( src_str, "3BDD119049372802" ); 00650 00651 des_setkey_enc( &ctx, key_str ); 00652 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00653 hexify( dst_str, output, 8 ); 00654 00655 fct_chk( strcasecmp( (char *) dst_str, "DFD64A815CAF1A0F" ) == 0 ); 00656 } 00657 FCT_TEST_END(); 00658 00659 00660 FCT_TEST_BGN(des_encrypt_openssl_test_vector_18) 00661 { 00662 unsigned char key_str[100]; 00663 unsigned char src_str[100]; 00664 unsigned char dst_str[100]; 00665 unsigned char output[100]; 00666 des_context ctx; 00667 00668 memset(key_str, 0x00, 100); 00669 memset(src_str, 0x00, 100); 00670 memset(dst_str, 0x00, 100); 00671 memset(output, 0x00, 100); 00672 00673 unhexify( key_str, "04689104C2FD3B2F" ); 00674 unhexify( src_str, "26955F6835AF609A" ); 00675 00676 des_setkey_enc( &ctx, key_str ); 00677 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00678 hexify( dst_str, output, 8 ); 00679 00680 fct_chk( strcasecmp( (char *) dst_str, "5C513C9C4886C088" ) == 0 ); 00681 } 00682 FCT_TEST_END(); 00683 00684 00685 FCT_TEST_BGN(des_encrypt_openssl_test_vector_19) 00686 { 00687 unsigned char key_str[100]; 00688 unsigned char src_str[100]; 00689 unsigned char dst_str[100]; 00690 unsigned char output[100]; 00691 des_context ctx; 00692 00693 memset(key_str, 0x00, 100); 00694 memset(src_str, 0x00, 100); 00695 memset(dst_str, 0x00, 100); 00696 memset(output, 0x00, 100); 00697 00698 unhexify( key_str, "37D06BB516CB7546" ); 00699 unhexify( src_str, "164D5E404F275232" ); 00700 00701 des_setkey_enc( &ctx, key_str ); 00702 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00703 hexify( dst_str, output, 8 ); 00704 00705 fct_chk( strcasecmp( (char *) dst_str, "0A2AEEAE3FF4AB77" ) == 0 ); 00706 } 00707 FCT_TEST_END(); 00708 00709 00710 FCT_TEST_BGN(des_encrypt_openssl_test_vector_20) 00711 { 00712 unsigned char key_str[100]; 00713 unsigned char src_str[100]; 00714 unsigned char dst_str[100]; 00715 unsigned char output[100]; 00716 des_context ctx; 00717 00718 memset(key_str, 0x00, 100); 00719 memset(src_str, 0x00, 100); 00720 memset(dst_str, 0x00, 100); 00721 memset(output, 0x00, 100); 00722 00723 unhexify( key_str, "1F08260D1AC2465E" ); 00724 unhexify( src_str, "6B056E18759F5CCA" ); 00725 00726 des_setkey_enc( &ctx, key_str ); 00727 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00728 hexify( dst_str, output, 8 ); 00729 00730 fct_chk( strcasecmp( (char *) dst_str, "EF1BF03E5DFA575A" ) == 0 ); 00731 } 00732 FCT_TEST_END(); 00733 00734 00735 FCT_TEST_BGN(des_encrypt_openssl_test_vector_21) 00736 { 00737 unsigned char key_str[100]; 00738 unsigned char src_str[100]; 00739 unsigned char dst_str[100]; 00740 unsigned char output[100]; 00741 des_context ctx; 00742 00743 memset(key_str, 0x00, 100); 00744 memset(src_str, 0x00, 100); 00745 memset(dst_str, 0x00, 100); 00746 memset(output, 0x00, 100); 00747 00748 unhexify( key_str, "584023641ABA6176" ); 00749 unhexify( src_str, "004BD6EF09176062" ); 00750 00751 des_setkey_enc( &ctx, key_str ); 00752 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00753 hexify( dst_str, output, 8 ); 00754 00755 fct_chk( strcasecmp( (char *) dst_str, "88BF0DB6D70DEE56" ) == 0 ); 00756 } 00757 FCT_TEST_END(); 00758 00759 00760 FCT_TEST_BGN(des_encrypt_openssl_test_vector_22) 00761 { 00762 unsigned char key_str[100]; 00763 unsigned char src_str[100]; 00764 unsigned char dst_str[100]; 00765 unsigned char output[100]; 00766 des_context ctx; 00767 00768 memset(key_str, 0x00, 100); 00769 memset(src_str, 0x00, 100); 00770 memset(dst_str, 0x00, 100); 00771 memset(output, 0x00, 100); 00772 00773 unhexify( key_str, "025816164629B007" ); 00774 unhexify( src_str, "480D39006EE762F2" ); 00775 00776 des_setkey_enc( &ctx, key_str ); 00777 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00778 hexify( dst_str, output, 8 ); 00779 00780 fct_chk( strcasecmp( (char *) dst_str, "A1F9915541020B56" ) == 0 ); 00781 } 00782 FCT_TEST_END(); 00783 00784 00785 FCT_TEST_BGN(des_encrypt_openssl_test_vector_23) 00786 { 00787 unsigned char key_str[100]; 00788 unsigned char src_str[100]; 00789 unsigned char dst_str[100]; 00790 unsigned char output[100]; 00791 des_context ctx; 00792 00793 memset(key_str, 0x00, 100); 00794 memset(src_str, 0x00, 100); 00795 memset(dst_str, 0x00, 100); 00796 memset(output, 0x00, 100); 00797 00798 unhexify( key_str, "49793EBC79B3258F" ); 00799 unhexify( src_str, "437540C8698F3CFA" ); 00800 00801 des_setkey_enc( &ctx, key_str ); 00802 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00803 hexify( dst_str, output, 8 ); 00804 00805 fct_chk( strcasecmp( (char *) dst_str, "6FBF1CAFCFFD0556" ) == 0 ); 00806 } 00807 FCT_TEST_END(); 00808 00809 00810 FCT_TEST_BGN(des_encrypt_openssl_test_vector_24) 00811 { 00812 unsigned char key_str[100]; 00813 unsigned char src_str[100]; 00814 unsigned char dst_str[100]; 00815 unsigned char output[100]; 00816 des_context ctx; 00817 00818 memset(key_str, 0x00, 100); 00819 memset(src_str, 0x00, 100); 00820 memset(dst_str, 0x00, 100); 00821 memset(output, 0x00, 100); 00822 00823 unhexify( key_str, "4FB05E1515AB73A7" ); 00824 unhexify( src_str, "072D43A077075292" ); 00825 00826 des_setkey_enc( &ctx, key_str ); 00827 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00828 hexify( dst_str, output, 8 ); 00829 00830 fct_chk( strcasecmp( (char *) dst_str, "2F22E49BAB7CA1AC" ) == 0 ); 00831 } 00832 FCT_TEST_END(); 00833 00834 00835 FCT_TEST_BGN(des_encrypt_openssl_test_vector_25) 00836 { 00837 unsigned char key_str[100]; 00838 unsigned char src_str[100]; 00839 unsigned char dst_str[100]; 00840 unsigned char output[100]; 00841 des_context ctx; 00842 00843 memset(key_str, 0x00, 100); 00844 memset(src_str, 0x00, 100); 00845 memset(dst_str, 0x00, 100); 00846 memset(output, 0x00, 100); 00847 00848 unhexify( key_str, "49E95D6D4CA229BF" ); 00849 unhexify( src_str, "02FE55778117F12A" ); 00850 00851 des_setkey_enc( &ctx, key_str ); 00852 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00853 hexify( dst_str, output, 8 ); 00854 00855 fct_chk( strcasecmp( (char *) dst_str, "5A6B612CC26CCE4A" ) == 0 ); 00856 } 00857 FCT_TEST_END(); 00858 00859 00860 FCT_TEST_BGN(des_encrypt_openssl_test_vector_26) 00861 { 00862 unsigned char key_str[100]; 00863 unsigned char src_str[100]; 00864 unsigned char dst_str[100]; 00865 unsigned char output[100]; 00866 des_context ctx; 00867 00868 memset(key_str, 0x00, 100); 00869 memset(src_str, 0x00, 100); 00870 memset(dst_str, 0x00, 100); 00871 memset(output, 0x00, 100); 00872 00873 unhexify( key_str, "018310DC409B26D6" ); 00874 unhexify( src_str, "1D9D5C5018F728C2" ); 00875 00876 des_setkey_enc( &ctx, key_str ); 00877 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00878 hexify( dst_str, output, 8 ); 00879 00880 fct_chk( strcasecmp( (char *) dst_str, "5F4C038ED12B2E41" ) == 0 ); 00881 } 00882 FCT_TEST_END(); 00883 00884 00885 FCT_TEST_BGN(des_encrypt_openssl_test_vector_27) 00886 { 00887 unsigned char key_str[100]; 00888 unsigned char src_str[100]; 00889 unsigned char dst_str[100]; 00890 unsigned char output[100]; 00891 des_context ctx; 00892 00893 memset(key_str, 0x00, 100); 00894 memset(src_str, 0x00, 100); 00895 memset(dst_str, 0x00, 100); 00896 memset(output, 0x00, 100); 00897 00898 unhexify( key_str, "1C587F1C13924FEF" ); 00899 unhexify( src_str, "305532286D6F295A" ); 00900 00901 des_setkey_enc( &ctx, key_str ); 00902 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00903 hexify( dst_str, output, 8 ); 00904 00905 fct_chk( strcasecmp( (char *) dst_str, "63FAC0D034D9F793" ) == 0 ); 00906 } 00907 FCT_TEST_END(); 00908 00909 00910 FCT_TEST_BGN(des_encrypt_openssl_test_vector_28) 00911 { 00912 unsigned char key_str[100]; 00913 unsigned char src_str[100]; 00914 unsigned char dst_str[100]; 00915 unsigned char output[100]; 00916 des_context ctx; 00917 00918 memset(key_str, 0x00, 100); 00919 memset(src_str, 0x00, 100); 00920 memset(dst_str, 0x00, 100); 00921 memset(output, 0x00, 100); 00922 00923 unhexify( key_str, "0101010101010101" ); 00924 unhexify( src_str, "0123456789ABCDEF" ); 00925 00926 des_setkey_enc( &ctx, key_str ); 00927 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00928 hexify( dst_str, output, 8 ); 00929 00930 fct_chk( strcasecmp( (char *) dst_str, "617B3A0CE8F07100" ) == 0 ); 00931 } 00932 FCT_TEST_END(); 00933 00934 00935 FCT_TEST_BGN(des_encrypt_openssl_test_vector_29) 00936 { 00937 unsigned char key_str[100]; 00938 unsigned char src_str[100]; 00939 unsigned char dst_str[100]; 00940 unsigned char output[100]; 00941 des_context ctx; 00942 00943 memset(key_str, 0x00, 100); 00944 memset(src_str, 0x00, 100); 00945 memset(dst_str, 0x00, 100); 00946 memset(output, 0x00, 100); 00947 00948 unhexify( key_str, "1F1F1F1F0E0E0E0E" ); 00949 unhexify( src_str, "0123456789ABCDEF" ); 00950 00951 des_setkey_enc( &ctx, key_str ); 00952 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00953 hexify( dst_str, output, 8 ); 00954 00955 fct_chk( strcasecmp( (char *) dst_str, "DB958605F8C8C606" ) == 0 ); 00956 } 00957 FCT_TEST_END(); 00958 00959 00960 FCT_TEST_BGN(des_encrypt_openssl_test_vector_30) 00961 { 00962 unsigned char key_str[100]; 00963 unsigned char src_str[100]; 00964 unsigned char dst_str[100]; 00965 unsigned char output[100]; 00966 des_context ctx; 00967 00968 memset(key_str, 0x00, 100); 00969 memset(src_str, 0x00, 100); 00970 memset(dst_str, 0x00, 100); 00971 memset(output, 0x00, 100); 00972 00973 unhexify( key_str, "E0FEE0FEF1FEF1FE" ); 00974 unhexify( src_str, "0123456789ABCDEF" ); 00975 00976 des_setkey_enc( &ctx, key_str ); 00977 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 00978 hexify( dst_str, output, 8 ); 00979 00980 fct_chk( strcasecmp( (char *) dst_str, "EDBFD1C66C29CCC7" ) == 0 ); 00981 } 00982 FCT_TEST_END(); 00983 00984 00985 FCT_TEST_BGN(des_encrypt_openssl_test_vector_31) 00986 { 00987 unsigned char key_str[100]; 00988 unsigned char src_str[100]; 00989 unsigned char dst_str[100]; 00990 unsigned char output[100]; 00991 des_context ctx; 00992 00993 memset(key_str, 0x00, 100); 00994 memset(src_str, 0x00, 100); 00995 memset(dst_str, 0x00, 100); 00996 memset(output, 0x00, 100); 00997 00998 unhexify( key_str, "0000000000000000" ); 00999 unhexify( src_str, "FFFFFFFFFFFFFFFF" ); 01000 01001 des_setkey_enc( &ctx, key_str ); 01002 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01003 hexify( dst_str, output, 8 ); 01004 01005 fct_chk( strcasecmp( (char *) dst_str, "355550B2150E2451" ) == 0 ); 01006 } 01007 FCT_TEST_END(); 01008 01009 01010 FCT_TEST_BGN(des_encrypt_openssl_test_vector_32) 01011 { 01012 unsigned char key_str[100]; 01013 unsigned char src_str[100]; 01014 unsigned char dst_str[100]; 01015 unsigned char output[100]; 01016 des_context ctx; 01017 01018 memset(key_str, 0x00, 100); 01019 memset(src_str, 0x00, 100); 01020 memset(dst_str, 0x00, 100); 01021 memset(output, 0x00, 100); 01022 01023 unhexify( key_str, "FFFFFFFFFFFFFFFF" ); 01024 unhexify( src_str, "0000000000000000" ); 01025 01026 des_setkey_enc( &ctx, key_str ); 01027 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01028 hexify( dst_str, output, 8 ); 01029 01030 fct_chk( strcasecmp( (char *) dst_str, "CAAAAF4DEAF1DBAE" ) == 0 ); 01031 } 01032 FCT_TEST_END(); 01033 01034 01035 FCT_TEST_BGN(des_encrypt_openssl_test_vector_33) 01036 { 01037 unsigned char key_str[100]; 01038 unsigned char src_str[100]; 01039 unsigned char dst_str[100]; 01040 unsigned char output[100]; 01041 des_context ctx; 01042 01043 memset(key_str, 0x00, 100); 01044 memset(src_str, 0x00, 100); 01045 memset(dst_str, 0x00, 100); 01046 memset(output, 0x00, 100); 01047 01048 unhexify( key_str, "0123456789ABCDEF" ); 01049 unhexify( src_str, "0000000000000000" ); 01050 01051 des_setkey_enc( &ctx, key_str ); 01052 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01053 hexify( dst_str, output, 8 ); 01054 01055 fct_chk( strcasecmp( (char *) dst_str, "D5D44FF720683D0D" ) == 0 ); 01056 } 01057 FCT_TEST_END(); 01058 01059 01060 FCT_TEST_BGN(des_encrypt_openssl_test_vector_34) 01061 { 01062 unsigned char key_str[100]; 01063 unsigned char src_str[100]; 01064 unsigned char dst_str[100]; 01065 unsigned char output[100]; 01066 des_context ctx; 01067 01068 memset(key_str, 0x00, 100); 01069 memset(src_str, 0x00, 100); 01070 memset(dst_str, 0x00, 100); 01071 memset(output, 0x00, 100); 01072 01073 unhexify( key_str, "FEDCBA9876543210" ); 01074 unhexify( src_str, "FFFFFFFFFFFFFFFF" ); 01075 01076 des_setkey_enc( &ctx, key_str ); 01077 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01078 hexify( dst_str, output, 8 ); 01079 01080 fct_chk( strcasecmp( (char *) dst_str, "2A2BB008DF97C2F2" ) == 0 ); 01081 } 01082 FCT_TEST_END(); 01083 01084 01085 FCT_TEST_BGN(des_decrypt_openssl_test_vector_1) 01086 { 01087 unsigned char key_str[100]; 01088 unsigned char src_str[100]; 01089 unsigned char dst_str[100]; 01090 unsigned char output[100]; 01091 des_context ctx; 01092 01093 memset(key_str, 0x00, 100); 01094 memset(src_str, 0x00, 100); 01095 memset(dst_str, 0x00, 100); 01096 memset(output, 0x00, 100); 01097 01098 unhexify( key_str, "0000000000000000" ); 01099 unhexify( src_str, "8CA64DE9C1B123A7" ); 01100 01101 des_setkey_dec( &ctx, key_str ); 01102 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01103 hexify( dst_str, output, 8 ); 01104 01105 fct_chk( strcasecmp( (char *) dst_str, "0000000000000000" ) == 0 ); 01106 } 01107 FCT_TEST_END(); 01108 01109 01110 FCT_TEST_BGN(des_decrypt_openssl_test_vector_2) 01111 { 01112 unsigned char key_str[100]; 01113 unsigned char src_str[100]; 01114 unsigned char dst_str[100]; 01115 unsigned char output[100]; 01116 des_context ctx; 01117 01118 memset(key_str, 0x00, 100); 01119 memset(src_str, 0x00, 100); 01120 memset(dst_str, 0x00, 100); 01121 memset(output, 0x00, 100); 01122 01123 unhexify( key_str, "FFFFFFFFFFFFFFFF" ); 01124 unhexify( src_str, "7359B2163E4EDC58" ); 01125 01126 des_setkey_dec( &ctx, key_str ); 01127 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01128 hexify( dst_str, output, 8 ); 01129 01130 fct_chk( strcasecmp( (char *) dst_str, "FFFFFFFFFFFFFFFF" ) == 0 ); 01131 } 01132 FCT_TEST_END(); 01133 01134 01135 FCT_TEST_BGN(des_decrypt_openssl_test_vector_3) 01136 { 01137 unsigned char key_str[100]; 01138 unsigned char src_str[100]; 01139 unsigned char dst_str[100]; 01140 unsigned char output[100]; 01141 des_context ctx; 01142 01143 memset(key_str, 0x00, 100); 01144 memset(src_str, 0x00, 100); 01145 memset(dst_str, 0x00, 100); 01146 memset(output, 0x00, 100); 01147 01148 unhexify( key_str, "3000000000000000" ); 01149 unhexify( src_str, "958E6E627A05557B" ); 01150 01151 des_setkey_dec( &ctx, key_str ); 01152 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01153 hexify( dst_str, output, 8 ); 01154 01155 fct_chk( strcasecmp( (char *) dst_str, "1000000000000001" ) == 0 ); 01156 } 01157 FCT_TEST_END(); 01158 01159 01160 FCT_TEST_BGN(des_decrypt_openssl_test_vector_4) 01161 { 01162 unsigned char key_str[100]; 01163 unsigned char src_str[100]; 01164 unsigned char dst_str[100]; 01165 unsigned char output[100]; 01166 des_context ctx; 01167 01168 memset(key_str, 0x00, 100); 01169 memset(src_str, 0x00, 100); 01170 memset(dst_str, 0x00, 100); 01171 memset(output, 0x00, 100); 01172 01173 unhexify( key_str, "1111111111111111" ); 01174 unhexify( src_str, "F40379AB9E0EC533" ); 01175 01176 des_setkey_dec( &ctx, key_str ); 01177 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01178 hexify( dst_str, output, 8 ); 01179 01180 fct_chk( strcasecmp( (char *) dst_str, "1111111111111111" ) == 0 ); 01181 } 01182 FCT_TEST_END(); 01183 01184 01185 FCT_TEST_BGN(des_decrypt_openssl_test_vector_5) 01186 { 01187 unsigned char key_str[100]; 01188 unsigned char src_str[100]; 01189 unsigned char dst_str[100]; 01190 unsigned char output[100]; 01191 des_context ctx; 01192 01193 memset(key_str, 0x00, 100); 01194 memset(src_str, 0x00, 100); 01195 memset(dst_str, 0x00, 100); 01196 memset(output, 0x00, 100); 01197 01198 unhexify( key_str, "0123456789ABCDEF" ); 01199 unhexify( src_str, "17668DFC7292532D" ); 01200 01201 des_setkey_dec( &ctx, key_str ); 01202 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01203 hexify( dst_str, output, 8 ); 01204 01205 fct_chk( strcasecmp( (char *) dst_str, "1111111111111111" ) == 0 ); 01206 } 01207 FCT_TEST_END(); 01208 01209 01210 FCT_TEST_BGN(des_decrypt_openssl_test_vector_6) 01211 { 01212 unsigned char key_str[100]; 01213 unsigned char src_str[100]; 01214 unsigned char dst_str[100]; 01215 unsigned char output[100]; 01216 des_context ctx; 01217 01218 memset(key_str, 0x00, 100); 01219 memset(src_str, 0x00, 100); 01220 memset(dst_str, 0x00, 100); 01221 memset(output, 0x00, 100); 01222 01223 unhexify( key_str, "1111111111111111" ); 01224 unhexify( src_str, "8A5AE1F81AB8F2DD" ); 01225 01226 des_setkey_dec( &ctx, key_str ); 01227 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01228 hexify( dst_str, output, 8 ); 01229 01230 fct_chk( strcasecmp( (char *) dst_str, "0123456789ABCDEF" ) == 0 ); 01231 } 01232 FCT_TEST_END(); 01233 01234 01235 FCT_TEST_BGN(des_decrypt_openssl_test_vector_7) 01236 { 01237 unsigned char key_str[100]; 01238 unsigned char src_str[100]; 01239 unsigned char dst_str[100]; 01240 unsigned char output[100]; 01241 des_context ctx; 01242 01243 memset(key_str, 0x00, 100); 01244 memset(src_str, 0x00, 100); 01245 memset(dst_str, 0x00, 100); 01246 memset(output, 0x00, 100); 01247 01248 unhexify( key_str, "0000000000000000" ); 01249 unhexify( src_str, "8CA64DE9C1B123A7" ); 01250 01251 des_setkey_dec( &ctx, key_str ); 01252 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01253 hexify( dst_str, output, 8 ); 01254 01255 fct_chk( strcasecmp( (char *) dst_str, "0000000000000000" ) == 0 ); 01256 } 01257 FCT_TEST_END(); 01258 01259 01260 FCT_TEST_BGN(des_decrypt_openssl_test_vector_8) 01261 { 01262 unsigned char key_str[100]; 01263 unsigned char src_str[100]; 01264 unsigned char dst_str[100]; 01265 unsigned char output[100]; 01266 des_context ctx; 01267 01268 memset(key_str, 0x00, 100); 01269 memset(src_str, 0x00, 100); 01270 memset(dst_str, 0x00, 100); 01271 memset(output, 0x00, 100); 01272 01273 unhexify( key_str, "FEDCBA9876543210" ); 01274 unhexify( src_str, "ED39D950FA74BCC4" ); 01275 01276 des_setkey_dec( &ctx, key_str ); 01277 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01278 hexify( dst_str, output, 8 ); 01279 01280 fct_chk( strcasecmp( (char *) dst_str, "0123456789ABCDEF" ) == 0 ); 01281 } 01282 FCT_TEST_END(); 01283 01284 01285 FCT_TEST_BGN(des_decrypt_openssl_test_vector_9) 01286 { 01287 unsigned char key_str[100]; 01288 unsigned char src_str[100]; 01289 unsigned char dst_str[100]; 01290 unsigned char output[100]; 01291 des_context ctx; 01292 01293 memset(key_str, 0x00, 100); 01294 memset(src_str, 0x00, 100); 01295 memset(dst_str, 0x00, 100); 01296 memset(output, 0x00, 100); 01297 01298 unhexify( key_str, "7CA110454A1A6E57" ); 01299 unhexify( src_str, "690F5B0D9A26939B" ); 01300 01301 des_setkey_dec( &ctx, key_str ); 01302 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01303 hexify( dst_str, output, 8 ); 01304 01305 fct_chk( strcasecmp( (char *) dst_str, "01A1D6D039776742" ) == 0 ); 01306 } 01307 FCT_TEST_END(); 01308 01309 01310 FCT_TEST_BGN(des_decrypt_openssl_test_vector_10) 01311 { 01312 unsigned char key_str[100]; 01313 unsigned char src_str[100]; 01314 unsigned char dst_str[100]; 01315 unsigned char output[100]; 01316 des_context ctx; 01317 01318 memset(key_str, 0x00, 100); 01319 memset(src_str, 0x00, 100); 01320 memset(dst_str, 0x00, 100); 01321 memset(output, 0x00, 100); 01322 01323 unhexify( key_str, "0131D9619DC1376E" ); 01324 unhexify( src_str, "7A389D10354BD271" ); 01325 01326 des_setkey_dec( &ctx, key_str ); 01327 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01328 hexify( dst_str, output, 8 ); 01329 01330 fct_chk( strcasecmp( (char *) dst_str, "5CD54CA83DEF57DA" ) == 0 ); 01331 } 01332 FCT_TEST_END(); 01333 01334 01335 FCT_TEST_BGN(des_decrypt_openssl_test_vector_11) 01336 { 01337 unsigned char key_str[100]; 01338 unsigned char src_str[100]; 01339 unsigned char dst_str[100]; 01340 unsigned char output[100]; 01341 des_context ctx; 01342 01343 memset(key_str, 0x00, 100); 01344 memset(src_str, 0x00, 100); 01345 memset(dst_str, 0x00, 100); 01346 memset(output, 0x00, 100); 01347 01348 unhexify( key_str, "07A1133E4A0B2686" ); 01349 unhexify( src_str, "868EBB51CAB4599A" ); 01350 01351 des_setkey_dec( &ctx, key_str ); 01352 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01353 hexify( dst_str, output, 8 ); 01354 01355 fct_chk( strcasecmp( (char *) dst_str, "0248D43806F67172" ) == 0 ); 01356 } 01357 FCT_TEST_END(); 01358 01359 01360 FCT_TEST_BGN(des_decrypt_openssl_test_vector_12) 01361 { 01362 unsigned char key_str[100]; 01363 unsigned char src_str[100]; 01364 unsigned char dst_str[100]; 01365 unsigned char output[100]; 01366 des_context ctx; 01367 01368 memset(key_str, 0x00, 100); 01369 memset(src_str, 0x00, 100); 01370 memset(dst_str, 0x00, 100); 01371 memset(output, 0x00, 100); 01372 01373 unhexify( key_str, "3849674C2602319E" ); 01374 unhexify( src_str, "7178876E01F19B2A" ); 01375 01376 des_setkey_dec( &ctx, key_str ); 01377 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01378 hexify( dst_str, output, 8 ); 01379 01380 fct_chk( strcasecmp( (char *) dst_str, "51454B582DDF440A" ) == 0 ); 01381 } 01382 FCT_TEST_END(); 01383 01384 01385 FCT_TEST_BGN(des_decrypt_openssl_test_vector_13) 01386 { 01387 unsigned char key_str[100]; 01388 unsigned char src_str[100]; 01389 unsigned char dst_str[100]; 01390 unsigned char output[100]; 01391 des_context ctx; 01392 01393 memset(key_str, 0x00, 100); 01394 memset(src_str, 0x00, 100); 01395 memset(dst_str, 0x00, 100); 01396 memset(output, 0x00, 100); 01397 01398 unhexify( key_str, "04B915BA43FEB5B6" ); 01399 unhexify( src_str, "AF37FB421F8C4095" ); 01400 01401 des_setkey_dec( &ctx, key_str ); 01402 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01403 hexify( dst_str, output, 8 ); 01404 01405 fct_chk( strcasecmp( (char *) dst_str, "42FD443059577FA2" ) == 0 ); 01406 } 01407 FCT_TEST_END(); 01408 01409 01410 FCT_TEST_BGN(des_decrypt_openssl_test_vector_14) 01411 { 01412 unsigned char key_str[100]; 01413 unsigned char src_str[100]; 01414 unsigned char dst_str[100]; 01415 unsigned char output[100]; 01416 des_context ctx; 01417 01418 memset(key_str, 0x00, 100); 01419 memset(src_str, 0x00, 100); 01420 memset(dst_str, 0x00, 100); 01421 memset(output, 0x00, 100); 01422 01423 unhexify( key_str, "0113B970FD34F2CE" ); 01424 unhexify( src_str, "86A560F10EC6D85B" ); 01425 01426 des_setkey_dec( &ctx, key_str ); 01427 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01428 hexify( dst_str, output, 8 ); 01429 01430 fct_chk( strcasecmp( (char *) dst_str, "059B5E0851CF143A" ) == 0 ); 01431 } 01432 FCT_TEST_END(); 01433 01434 01435 FCT_TEST_BGN(des_decrypt_openssl_test_vector_15) 01436 { 01437 unsigned char key_str[100]; 01438 unsigned char src_str[100]; 01439 unsigned char dst_str[100]; 01440 unsigned char output[100]; 01441 des_context ctx; 01442 01443 memset(key_str, 0x00, 100); 01444 memset(src_str, 0x00, 100); 01445 memset(dst_str, 0x00, 100); 01446 memset(output, 0x00, 100); 01447 01448 unhexify( key_str, "0170F175468FB5E6" ); 01449 unhexify( src_str, "0CD3DA020021DC09" ); 01450 01451 des_setkey_dec( &ctx, key_str ); 01452 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01453 hexify( dst_str, output, 8 ); 01454 01455 fct_chk( strcasecmp( (char *) dst_str, "0756D8E0774761D2" ) == 0 ); 01456 } 01457 FCT_TEST_END(); 01458 01459 01460 FCT_TEST_BGN(des_decrypt_openssl_test_vector_16) 01461 { 01462 unsigned char key_str[100]; 01463 unsigned char src_str[100]; 01464 unsigned char dst_str[100]; 01465 unsigned char output[100]; 01466 des_context ctx; 01467 01468 memset(key_str, 0x00, 100); 01469 memset(src_str, 0x00, 100); 01470 memset(dst_str, 0x00, 100); 01471 memset(output, 0x00, 100); 01472 01473 unhexify( key_str, "43297FAD38E373FE" ); 01474 unhexify( src_str, "EA676B2CB7DB2B7A" ); 01475 01476 des_setkey_dec( &ctx, key_str ); 01477 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01478 hexify( dst_str, output, 8 ); 01479 01480 fct_chk( strcasecmp( (char *) dst_str, "762514B829BF486A" ) == 0 ); 01481 } 01482 FCT_TEST_END(); 01483 01484 01485 FCT_TEST_BGN(des_decrypt_openssl_test_vector_17) 01486 { 01487 unsigned char key_str[100]; 01488 unsigned char src_str[100]; 01489 unsigned char dst_str[100]; 01490 unsigned char output[100]; 01491 des_context ctx; 01492 01493 memset(key_str, 0x00, 100); 01494 memset(src_str, 0x00, 100); 01495 memset(dst_str, 0x00, 100); 01496 memset(output, 0x00, 100); 01497 01498 unhexify( key_str, "07A7137045DA2A16" ); 01499 unhexify( src_str, "DFD64A815CAF1A0F" ); 01500 01501 des_setkey_dec( &ctx, key_str ); 01502 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01503 hexify( dst_str, output, 8 ); 01504 01505 fct_chk( strcasecmp( (char *) dst_str, "3BDD119049372802" ) == 0 ); 01506 } 01507 FCT_TEST_END(); 01508 01509 01510 FCT_TEST_BGN(des_decrypt_openssl_test_vector_18) 01511 { 01512 unsigned char key_str[100]; 01513 unsigned char src_str[100]; 01514 unsigned char dst_str[100]; 01515 unsigned char output[100]; 01516 des_context ctx; 01517 01518 memset(key_str, 0x00, 100); 01519 memset(src_str, 0x00, 100); 01520 memset(dst_str, 0x00, 100); 01521 memset(output, 0x00, 100); 01522 01523 unhexify( key_str, "04689104C2FD3B2F" ); 01524 unhexify( src_str, "5C513C9C4886C088" ); 01525 01526 des_setkey_dec( &ctx, key_str ); 01527 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01528 hexify( dst_str, output, 8 ); 01529 01530 fct_chk( strcasecmp( (char *) dst_str, "26955F6835AF609A" ) == 0 ); 01531 } 01532 FCT_TEST_END(); 01533 01534 01535 FCT_TEST_BGN(des_decrypt_openssl_test_vector_19) 01536 { 01537 unsigned char key_str[100]; 01538 unsigned char src_str[100]; 01539 unsigned char dst_str[100]; 01540 unsigned char output[100]; 01541 des_context ctx; 01542 01543 memset(key_str, 0x00, 100); 01544 memset(src_str, 0x00, 100); 01545 memset(dst_str, 0x00, 100); 01546 memset(output, 0x00, 100); 01547 01548 unhexify( key_str, "37D06BB516CB7546" ); 01549 unhexify( src_str, "0A2AEEAE3FF4AB77" ); 01550 01551 des_setkey_dec( &ctx, key_str ); 01552 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01553 hexify( dst_str, output, 8 ); 01554 01555 fct_chk( strcasecmp( (char *) dst_str, "164D5E404F275232" ) == 0 ); 01556 } 01557 FCT_TEST_END(); 01558 01559 01560 FCT_TEST_BGN(des_decrypt_openssl_test_vector_20) 01561 { 01562 unsigned char key_str[100]; 01563 unsigned char src_str[100]; 01564 unsigned char dst_str[100]; 01565 unsigned char output[100]; 01566 des_context ctx; 01567 01568 memset(key_str, 0x00, 100); 01569 memset(src_str, 0x00, 100); 01570 memset(dst_str, 0x00, 100); 01571 memset(output, 0x00, 100); 01572 01573 unhexify( key_str, "1F08260D1AC2465E" ); 01574 unhexify( src_str, "EF1BF03E5DFA575A" ); 01575 01576 des_setkey_dec( &ctx, key_str ); 01577 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01578 hexify( dst_str, output, 8 ); 01579 01580 fct_chk( strcasecmp( (char *) dst_str, "6B056E18759F5CCA" ) == 0 ); 01581 } 01582 FCT_TEST_END(); 01583 01584 01585 FCT_TEST_BGN(des_decrypt_openssl_test_vector_21) 01586 { 01587 unsigned char key_str[100]; 01588 unsigned char src_str[100]; 01589 unsigned char dst_str[100]; 01590 unsigned char output[100]; 01591 des_context ctx; 01592 01593 memset(key_str, 0x00, 100); 01594 memset(src_str, 0x00, 100); 01595 memset(dst_str, 0x00, 100); 01596 memset(output, 0x00, 100); 01597 01598 unhexify( key_str, "584023641ABA6176" ); 01599 unhexify( src_str, "88BF0DB6D70DEE56" ); 01600 01601 des_setkey_dec( &ctx, key_str ); 01602 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01603 hexify( dst_str, output, 8 ); 01604 01605 fct_chk( strcasecmp( (char *) dst_str, "004BD6EF09176062" ) == 0 ); 01606 } 01607 FCT_TEST_END(); 01608 01609 01610 FCT_TEST_BGN(des_decrypt_openssl_test_vector_22) 01611 { 01612 unsigned char key_str[100]; 01613 unsigned char src_str[100]; 01614 unsigned char dst_str[100]; 01615 unsigned char output[100]; 01616 des_context ctx; 01617 01618 memset(key_str, 0x00, 100); 01619 memset(src_str, 0x00, 100); 01620 memset(dst_str, 0x00, 100); 01621 memset(output, 0x00, 100); 01622 01623 unhexify( key_str, "025816164629B007" ); 01624 unhexify( src_str, "A1F9915541020B56" ); 01625 01626 des_setkey_dec( &ctx, key_str ); 01627 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01628 hexify( dst_str, output, 8 ); 01629 01630 fct_chk( strcasecmp( (char *) dst_str, "480D39006EE762F2" ) == 0 ); 01631 } 01632 FCT_TEST_END(); 01633 01634 01635 FCT_TEST_BGN(des_decrypt_openssl_test_vector_23) 01636 { 01637 unsigned char key_str[100]; 01638 unsigned char src_str[100]; 01639 unsigned char dst_str[100]; 01640 unsigned char output[100]; 01641 des_context ctx; 01642 01643 memset(key_str, 0x00, 100); 01644 memset(src_str, 0x00, 100); 01645 memset(dst_str, 0x00, 100); 01646 memset(output, 0x00, 100); 01647 01648 unhexify( key_str, "49793EBC79B3258F" ); 01649 unhexify( src_str, "6FBF1CAFCFFD0556" ); 01650 01651 des_setkey_dec( &ctx, key_str ); 01652 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01653 hexify( dst_str, output, 8 ); 01654 01655 fct_chk( strcasecmp( (char *) dst_str, "437540C8698F3CFA" ) == 0 ); 01656 } 01657 FCT_TEST_END(); 01658 01659 01660 FCT_TEST_BGN(des_decrypt_openssl_test_vector_24) 01661 { 01662 unsigned char key_str[100]; 01663 unsigned char src_str[100]; 01664 unsigned char dst_str[100]; 01665 unsigned char output[100]; 01666 des_context ctx; 01667 01668 memset(key_str, 0x00, 100); 01669 memset(src_str, 0x00, 100); 01670 memset(dst_str, 0x00, 100); 01671 memset(output, 0x00, 100); 01672 01673 unhexify( key_str, "4FB05E1515AB73A7" ); 01674 unhexify( src_str, "2F22E49BAB7CA1AC" ); 01675 01676 des_setkey_dec( &ctx, key_str ); 01677 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01678 hexify( dst_str, output, 8 ); 01679 01680 fct_chk( strcasecmp( (char *) dst_str, "072D43A077075292" ) == 0 ); 01681 } 01682 FCT_TEST_END(); 01683 01684 01685 FCT_TEST_BGN(des_decrypt_openssl_test_vector_25) 01686 { 01687 unsigned char key_str[100]; 01688 unsigned char src_str[100]; 01689 unsigned char dst_str[100]; 01690 unsigned char output[100]; 01691 des_context ctx; 01692 01693 memset(key_str, 0x00, 100); 01694 memset(src_str, 0x00, 100); 01695 memset(dst_str, 0x00, 100); 01696 memset(output, 0x00, 100); 01697 01698 unhexify( key_str, "49E95D6D4CA229BF" ); 01699 unhexify( src_str, "5A6B612CC26CCE4A" ); 01700 01701 des_setkey_dec( &ctx, key_str ); 01702 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01703 hexify( dst_str, output, 8 ); 01704 01705 fct_chk( strcasecmp( (char *) dst_str, "02FE55778117F12A" ) == 0 ); 01706 } 01707 FCT_TEST_END(); 01708 01709 01710 FCT_TEST_BGN(des_decrypt_openssl_test_vector_26) 01711 { 01712 unsigned char key_str[100]; 01713 unsigned char src_str[100]; 01714 unsigned char dst_str[100]; 01715 unsigned char output[100]; 01716 des_context ctx; 01717 01718 memset(key_str, 0x00, 100); 01719 memset(src_str, 0x00, 100); 01720 memset(dst_str, 0x00, 100); 01721 memset(output, 0x00, 100); 01722 01723 unhexify( key_str, "018310DC409B26D6" ); 01724 unhexify( src_str, "5F4C038ED12B2E41" ); 01725 01726 des_setkey_dec( &ctx, key_str ); 01727 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01728 hexify( dst_str, output, 8 ); 01729 01730 fct_chk( strcasecmp( (char *) dst_str, "1D9D5C5018F728C2" ) == 0 ); 01731 } 01732 FCT_TEST_END(); 01733 01734 01735 FCT_TEST_BGN(des_decrypt_openssl_test_vector_27) 01736 { 01737 unsigned char key_str[100]; 01738 unsigned char src_str[100]; 01739 unsigned char dst_str[100]; 01740 unsigned char output[100]; 01741 des_context ctx; 01742 01743 memset(key_str, 0x00, 100); 01744 memset(src_str, 0x00, 100); 01745 memset(dst_str, 0x00, 100); 01746 memset(output, 0x00, 100); 01747 01748 unhexify( key_str, "1C587F1C13924FEF" ); 01749 unhexify( src_str, "63FAC0D034D9F793" ); 01750 01751 des_setkey_dec( &ctx, key_str ); 01752 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01753 hexify( dst_str, output, 8 ); 01754 01755 fct_chk( strcasecmp( (char *) dst_str, "305532286D6F295A" ) == 0 ); 01756 } 01757 FCT_TEST_END(); 01758 01759 01760 FCT_TEST_BGN(des_decrypt_openssl_test_vector_28) 01761 { 01762 unsigned char key_str[100]; 01763 unsigned char src_str[100]; 01764 unsigned char dst_str[100]; 01765 unsigned char output[100]; 01766 des_context ctx; 01767 01768 memset(key_str, 0x00, 100); 01769 memset(src_str, 0x00, 100); 01770 memset(dst_str, 0x00, 100); 01771 memset(output, 0x00, 100); 01772 01773 unhexify( key_str, "0101010101010101" ); 01774 unhexify( src_str, "617B3A0CE8F07100" ); 01775 01776 des_setkey_dec( &ctx, key_str ); 01777 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01778 hexify( dst_str, output, 8 ); 01779 01780 fct_chk( strcasecmp( (char *) dst_str, "0123456789ABCDEF" ) == 0 ); 01781 } 01782 FCT_TEST_END(); 01783 01784 01785 FCT_TEST_BGN(des_decrypt_openssl_test_vector_29) 01786 { 01787 unsigned char key_str[100]; 01788 unsigned char src_str[100]; 01789 unsigned char dst_str[100]; 01790 unsigned char output[100]; 01791 des_context ctx; 01792 01793 memset(key_str, 0x00, 100); 01794 memset(src_str, 0x00, 100); 01795 memset(dst_str, 0x00, 100); 01796 memset(output, 0x00, 100); 01797 01798 unhexify( key_str, "1F1F1F1F0E0E0E0E" ); 01799 unhexify( src_str, "DB958605F8C8C606" ); 01800 01801 des_setkey_dec( &ctx, key_str ); 01802 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01803 hexify( dst_str, output, 8 ); 01804 01805 fct_chk( strcasecmp( (char *) dst_str, "0123456789ABCDEF" ) == 0 ); 01806 } 01807 FCT_TEST_END(); 01808 01809 01810 FCT_TEST_BGN(des_decrypt_openssl_test_vector_30) 01811 { 01812 unsigned char key_str[100]; 01813 unsigned char src_str[100]; 01814 unsigned char dst_str[100]; 01815 unsigned char output[100]; 01816 des_context ctx; 01817 01818 memset(key_str, 0x00, 100); 01819 memset(src_str, 0x00, 100); 01820 memset(dst_str, 0x00, 100); 01821 memset(output, 0x00, 100); 01822 01823 unhexify( key_str, "E0FEE0FEF1FEF1FE" ); 01824 unhexify( src_str, "EDBFD1C66C29CCC7" ); 01825 01826 des_setkey_dec( &ctx, key_str ); 01827 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01828 hexify( dst_str, output, 8 ); 01829 01830 fct_chk( strcasecmp( (char *) dst_str, "0123456789ABCDEF" ) == 0 ); 01831 } 01832 FCT_TEST_END(); 01833 01834 01835 FCT_TEST_BGN(des_decrypt_openssl_test_vector_31) 01836 { 01837 unsigned char key_str[100]; 01838 unsigned char src_str[100]; 01839 unsigned char dst_str[100]; 01840 unsigned char output[100]; 01841 des_context ctx; 01842 01843 memset(key_str, 0x00, 100); 01844 memset(src_str, 0x00, 100); 01845 memset(dst_str, 0x00, 100); 01846 memset(output, 0x00, 100); 01847 01848 unhexify( key_str, "0000000000000000" ); 01849 unhexify( src_str, "355550B2150E2451" ); 01850 01851 des_setkey_dec( &ctx, key_str ); 01852 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01853 hexify( dst_str, output, 8 ); 01854 01855 fct_chk( strcasecmp( (char *) dst_str, "FFFFFFFFFFFFFFFF" ) == 0 ); 01856 } 01857 FCT_TEST_END(); 01858 01859 01860 FCT_TEST_BGN(des_decrypt_openssl_test_vector_32) 01861 { 01862 unsigned char key_str[100]; 01863 unsigned char src_str[100]; 01864 unsigned char dst_str[100]; 01865 unsigned char output[100]; 01866 des_context ctx; 01867 01868 memset(key_str, 0x00, 100); 01869 memset(src_str, 0x00, 100); 01870 memset(dst_str, 0x00, 100); 01871 memset(output, 0x00, 100); 01872 01873 unhexify( key_str, "FFFFFFFFFFFFFFFF" ); 01874 unhexify( src_str, "CAAAAF4DEAF1DBAE" ); 01875 01876 des_setkey_dec( &ctx, key_str ); 01877 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01878 hexify( dst_str, output, 8 ); 01879 01880 fct_chk( strcasecmp( (char *) dst_str, "0000000000000000" ) == 0 ); 01881 } 01882 FCT_TEST_END(); 01883 01884 01885 FCT_TEST_BGN(des_decrypt_openssl_test_vector_33) 01886 { 01887 unsigned char key_str[100]; 01888 unsigned char src_str[100]; 01889 unsigned char dst_str[100]; 01890 unsigned char output[100]; 01891 des_context ctx; 01892 01893 memset(key_str, 0x00, 100); 01894 memset(src_str, 0x00, 100); 01895 memset(dst_str, 0x00, 100); 01896 memset(output, 0x00, 100); 01897 01898 unhexify( key_str, "0123456789ABCDEF" ); 01899 unhexify( src_str, "D5D44FF720683D0D" ); 01900 01901 des_setkey_dec( &ctx, key_str ); 01902 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01903 hexify( dst_str, output, 8 ); 01904 01905 fct_chk( strcasecmp( (char *) dst_str, "0000000000000000" ) == 0 ); 01906 } 01907 FCT_TEST_END(); 01908 01909 01910 FCT_TEST_BGN(des_decrypt_openssl_test_vector_34) 01911 { 01912 unsigned char key_str[100]; 01913 unsigned char src_str[100]; 01914 unsigned char dst_str[100]; 01915 unsigned char output[100]; 01916 des_context ctx; 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 unhexify( key_str, "FEDCBA9876543210" ); 01924 unhexify( src_str, "2A2BB008DF97C2F2" ); 01925 01926 des_setkey_dec( &ctx, key_str ); 01927 fct_chk( des_crypt_ecb( &ctx, src_str, output ) == 0 ); 01928 hexify( dst_str, output, 8 ); 01929 01930 fct_chk( strcasecmp( (char *) dst_str, "FFFFFFFFFFFFFFFF" ) == 0 ); 01931 } 01932 FCT_TEST_END(); 01933 01934 01935 FCT_TEST_BGN(des_cbc_encrypt_openssl_test_vector_1) 01936 { 01937 unsigned char key_str[100]; 01938 unsigned char iv_str[100]; 01939 unsigned char src_str[100]; 01940 unsigned char dst_str[100]; 01941 unsigned char output[100]; 01942 des_context ctx; 01943 int src_len; 01944 01945 memset(key_str, 0x00, 100); 01946 memset(iv_str, 0x00, 100); 01947 memset(src_str, 0x00, 100); 01948 memset(dst_str, 0x00, 100); 01949 memset(output, 0x00, 100); 01950 01951 unhexify( key_str, "0123456789abcdef" ); 01952 unhexify( iv_str, "fedcba9876543210" ); 01953 src_len = unhexify( src_str, "37363534333231204E6F77206973207468652074696D6520" ); 01954 01955 des_setkey_enc( &ctx, key_str ); 01956 fct_chk( des_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == 0 ); 01957 if( 0 == 0 ) 01958 { 01959 hexify( dst_str, output, src_len ); 01960 01961 fct_chk( strcasecmp( (char *) dst_str, "ccd173ffab2039f4acd8aefddfd8a1eb468e91157888ba68" ) == 0 ); 01962 } 01963 } 01964 FCT_TEST_END(); 01965 01966 01967 FCT_TEST_BGN(des_cbc_decrypt_openssl_test_vector_1) 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 des_context ctx; 01975 int src_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 unhexify( key_str, "0123456789abcdef" ); 01984 unhexify( iv_str, "fedcba9876543210" ); 01985 src_len = unhexify( src_str, "ccd173ffab2039f4acd8aefddfd8a1eb468e91157888ba68" ); 01986 01987 des_setkey_dec( &ctx, key_str ); 01988 fct_chk( des_crypt_cbc( &ctx, DES_DECRYPT, src_len, iv_str, src_str, output ) == 0 ); 01989 if( 0 == 0 ) 01990 { 01991 hexify( dst_str, output, src_len ); 01992 01993 fct_chk( strcasecmp( (char *) dst_str, "37363534333231204E6F77206973207468652074696D6520" ) == 0 ); 01994 } 01995 } 01996 FCT_TEST_END(); 01997 01998 01999 FCT_TEST_BGN(3des_ecb_2key_encrypt_openssl_test_vector_1) 02000 { 02001 unsigned char key_str[100]; 02002 unsigned char src_str[100]; 02003 unsigned char dst_str[100]; 02004 unsigned char output[100]; 02005 des3_context ctx; 02006 02007 memset(key_str, 0x00, 100); 02008 memset(src_str, 0x00, 100); 02009 memset(dst_str, 0x00, 100); 02010 memset(output, 0x00, 100); 02011 02012 unhexify( key_str, "0000000000000000FFFFFFFFFFFFFFFF" ); 02013 unhexify( src_str, "0000000000000000" ); 02014 02015 if( 2 == 2 ) 02016 des3_set2key_enc( &ctx, key_str ); 02017 else if( 2 == 3 ) 02018 des3_set3key_enc( &ctx, key_str ); 02019 else 02020 fct_chk( 0 ); 02021 02022 fct_chk( des3_crypt_ecb( &ctx, src_str, output ) == 0 ); 02023 hexify( dst_str, output, 8 ); 02024 02025 fct_chk( strcasecmp( (char *) dst_str, "9295B59BB384736E" ) == 0 ); 02026 } 02027 FCT_TEST_END(); 02028 02029 02030 FCT_TEST_BGN(3des_ecb_2key_encrypt_openssl_test_vector_2) 02031 { 02032 unsigned char key_str[100]; 02033 unsigned char src_str[100]; 02034 unsigned char dst_str[100]; 02035 unsigned char output[100]; 02036 des3_context ctx; 02037 02038 memset(key_str, 0x00, 100); 02039 memset(src_str, 0x00, 100); 02040 memset(dst_str, 0x00, 100); 02041 memset(output, 0x00, 100); 02042 02043 unhexify( key_str, "FFFFFFFFFFFFFFFF3000000000000000" ); 02044 unhexify( src_str, "FFFFFFFFFFFFFFFF" ); 02045 02046 if( 2 == 2 ) 02047 des3_set2key_enc( &ctx, key_str ); 02048 else if( 2 == 3 ) 02049 des3_set3key_enc( &ctx, key_str ); 02050 else 02051 fct_chk( 0 ); 02052 02053 fct_chk( des3_crypt_ecb( &ctx, src_str, output ) == 0 ); 02054 hexify( dst_str, output, 8 ); 02055 02056 fct_chk( strcasecmp( (char *) dst_str, "199E9D6DF39AA816" ) == 0 ); 02057 } 02058 FCT_TEST_END(); 02059 02060 02061 FCT_TEST_BGN(3des_ecb_2key_decrypt_openssl_test_vector_1) 02062 { 02063 unsigned char key_str[100]; 02064 unsigned char src_str[100]; 02065 unsigned char dst_str[100]; 02066 unsigned char output[100]; 02067 des3_context ctx; 02068 02069 memset(key_str, 0x00, 100); 02070 memset(src_str, 0x00, 100); 02071 memset(dst_str, 0x00, 100); 02072 memset(output, 0x00, 100); 02073 02074 unhexify( key_str, "0000000000000000FFFFFFFFFFFFFFFF" ); 02075 unhexify( src_str, "9295B59BB384736E" ); 02076 02077 if( 2 == 2 ) 02078 des3_set2key_dec( &ctx, key_str ); 02079 else if( 2 == 3 ) 02080 des3_set3key_dec( &ctx, key_str ); 02081 else 02082 fct_chk( 0 ); 02083 02084 fct_chk( des3_crypt_ecb( &ctx, src_str, output ) == 0 ); 02085 hexify( dst_str, output, 8 ); 02086 02087 fct_chk( strcasecmp( (char *) dst_str, "0000000000000000" ) == 0 ); 02088 } 02089 FCT_TEST_END(); 02090 02091 02092 FCT_TEST_BGN(3des_ecb_2key_decrypt_openssl_test_vector_2) 02093 { 02094 unsigned char key_str[100]; 02095 unsigned char src_str[100]; 02096 unsigned char dst_str[100]; 02097 unsigned char output[100]; 02098 des3_context ctx; 02099 02100 memset(key_str, 0x00, 100); 02101 memset(src_str, 0x00, 100); 02102 memset(dst_str, 0x00, 100); 02103 memset(output, 0x00, 100); 02104 02105 unhexify( key_str, "FFFFFFFFFFFFFFFF3000000000000000" ); 02106 unhexify( src_str, "199E9D6DF39AA816" ); 02107 02108 if( 2 == 2 ) 02109 des3_set2key_dec( &ctx, key_str ); 02110 else if( 2 == 3 ) 02111 des3_set3key_dec( &ctx, key_str ); 02112 else 02113 fct_chk( 0 ); 02114 02115 fct_chk( des3_crypt_ecb( &ctx, src_str, output ) == 0 ); 02116 hexify( dst_str, output, 8 ); 02117 02118 fct_chk( strcasecmp( (char *) dst_str, "FFFFFFFFFFFFFFFF" ) == 0 ); 02119 } 02120 FCT_TEST_END(); 02121 02122 02123 FCT_TEST_BGN(3des_cbc_3key_encrypt_openssl_test_vector_1) 02124 { 02125 unsigned char key_str[100]; 02126 unsigned char iv_str[100]; 02127 unsigned char src_str[100]; 02128 unsigned char dst_str[100]; 02129 unsigned char output[100]; 02130 des3_context ctx; 02131 int src_len; 02132 02133 memset(key_str, 0x00, 100); 02134 memset(iv_str, 0x00, 100); 02135 memset(src_str, 0x00, 100); 02136 memset(dst_str, 0x00, 100); 02137 memset(output, 0x00, 100); 02138 02139 unhexify( key_str, "0123456789abcdeff1e0d3c2b5a49786fedcba9876543210" ); 02140 unhexify( iv_str, "fedcba9876543210" ); 02141 src_len = unhexify( src_str, "37363534333231204E6F77206973207468652074696D6520" ); 02142 02143 if( 3 == 2 ) 02144 des3_set2key_enc( &ctx, key_str ); 02145 else if( 3 == 3 ) 02146 des3_set3key_enc( &ctx, key_str ); 02147 else 02148 fct_chk( 0 ); 02149 02150 fct_chk( des3_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == 0 ); 02151 02152 if( 0 == 0 ) 02153 { 02154 hexify( dst_str, output, src_len ); 02155 02156 fct_chk( strcasecmp( (char *) dst_str, "3FE301C962AC01D02213763C1CBD4CDC799657C064ECF5D4" ) == 0 ); 02157 } 02158 } 02159 FCT_TEST_END(); 02160 02161 02162 FCT_TEST_BGN(3des_cbc_3key_decrypt_openssl_test_vector_1) 02163 { 02164 unsigned char key_str[100]; 02165 unsigned char iv_str[100]; 02166 unsigned char src_str[100]; 02167 unsigned char dst_str[100]; 02168 unsigned char output[100]; 02169 des3_context ctx; 02170 int src_len; 02171 02172 memset(key_str, 0x00, 100); 02173 memset(iv_str, 0x00, 100); 02174 memset(src_str, 0x00, 100); 02175 memset(dst_str, 0x00, 100); 02176 memset(output, 0x00, 100); 02177 02178 unhexify( key_str, "0123456789abcdeff1e0d3c2b5a49786fedcba9876543210" ); 02179 unhexify( iv_str, "fedcba9876543210" ); 02180 src_len = unhexify( src_str, "3FE301C962AC01D02213763C1CBD4CDC799657C064ECF5D4" ); 02181 02182 if( 3 == 2 ) 02183 des3_set2key_dec( &ctx, key_str ); 02184 else if( 3 == 3 ) 02185 des3_set3key_dec( &ctx, key_str ); 02186 else 02187 fct_chk( 0 ); 02188 02189 fct_chk( des3_crypt_cbc( &ctx, DES_DECRYPT, src_len, iv_str, src_str, output ) == 0 ); 02190 02191 if( 0 == 0 ) 02192 { 02193 hexify( dst_str, output, src_len ); 02194 02195 fct_chk( strcasecmp( (char *) dst_str, "37363534333231204E6F77206973207468652074696D6520" ) == 0 ); 02196 } 02197 } 02198 FCT_TEST_END(); 02199 02200 02201 FCT_TEST_BGN(des_cbc_encrypt_invalid_input_length) 02202 { 02203 unsigned char key_str[100]; 02204 unsigned char iv_str[100]; 02205 unsigned char src_str[100]; 02206 unsigned char dst_str[100]; 02207 unsigned char output[100]; 02208 des_context ctx; 02209 int src_len; 02210 02211 memset(key_str, 0x00, 100); 02212 memset(iv_str, 0x00, 100); 02213 memset(src_str, 0x00, 100); 02214 memset(dst_str, 0x00, 100); 02215 memset(output, 0x00, 100); 02216 02217 unhexify( key_str, "0123456789abcdef" ); 02218 unhexify( iv_str, "fedcba9876543210" ); 02219 src_len = unhexify( src_str, "37363534333231204E6F77206973207468652074696D65" ); 02220 02221 des_setkey_enc( &ctx, key_str ); 02222 fct_chk( des_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == POLARSSL_ERR_DES_INVALID_INPUT_LENGTH ); 02223 if( POLARSSL_ERR_DES_INVALID_INPUT_LENGTH == 0 ) 02224 { 02225 hexify( dst_str, output, src_len ); 02226 02227 fct_chk( strcasecmp( (char *) dst_str, "" ) == 0 ); 02228 } 02229 } 02230 FCT_TEST_END(); 02231 02232 02233 FCT_TEST_BGN(3des_cbc_3key_encrypt_invalid_input_length) 02234 { 02235 unsigned char key_str[100]; 02236 unsigned char iv_str[100]; 02237 unsigned char src_str[100]; 02238 unsigned char dst_str[100]; 02239 unsigned char output[100]; 02240 des3_context ctx; 02241 int src_len; 02242 02243 memset(key_str, 0x00, 100); 02244 memset(iv_str, 0x00, 100); 02245 memset(src_str, 0x00, 100); 02246 memset(dst_str, 0x00, 100); 02247 memset(output, 0x00, 100); 02248 02249 unhexify( key_str, "0123456789abcdeff1e0d3c2b5a49786fedcba9876543210" ); 02250 unhexify( iv_str, "fedcba9876543210" ); 02251 src_len = unhexify( src_str, "37363534333231204E6F77206973207468652074696D65" ); 02252 02253 if( 3 == 2 ) 02254 des3_set2key_enc( &ctx, key_str ); 02255 else if( 3 == 3 ) 02256 des3_set3key_enc( &ctx, key_str ); 02257 else 02258 fct_chk( 0 ); 02259 02260 fct_chk( des3_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == POLARSSL_ERR_DES_INVALID_INPUT_LENGTH ); 02261 02262 if( POLARSSL_ERR_DES_INVALID_INPUT_LENGTH == 0 ) 02263 { 02264 hexify( dst_str, output, src_len ); 02265 02266 fct_chk( strcasecmp( (char *) dst_str, "" ) == 0 ); 02267 } 02268 } 02269 FCT_TEST_END(); 02270 02271 02272 FCT_TEST_BGN(run_through_parity_bit_tests) 02273 { 02274 int i, j, cnt; 02275 unsigned char key[DES_KEY_SIZE]; 02276 unsigned int parity; 02277 02278 memset( key, 0, DES_KEY_SIZE ); 02279 cnt = 0; 02280 02281 // Iterate through all possible byte values 02282 // 02283 for( i = 0; i < 32; i++ ) 02284 { 02285 for( j = 0; j < 8; j++ ) 02286 key[j] = cnt++; 02287 02288 // Set the key parity according to the table 02289 // 02290 des_key_set_parity( key ); 02291 02292 // Check the parity with a function 02293 // 02294 for( j = 0; j < 8; j++ ) 02295 { 02296 parity = key[j] ^ ( key[j] >> 4 ); 02297 parity = parity ^ 02298 ( parity >> 1 ) ^ 02299 ( parity >> 2 ) ^ 02300 ( parity >> 3 ); 02301 parity &= 1; 02302 02303 if( parity != 1 ) 02304 fct_chk( 0 ); 02305 } 02306 02307 // Check the parity with the table 02308 // 02309 fct_chk( des_key_check_key_parity( key ) == 0 ); 02310 } 02311 } 02312 FCT_TEST_END(); 02313 02314 #ifdef POLARSSL_SELF_TEST 02315 02316 FCT_TEST_BGN(des_selftest) 02317 { 02318 fct_chk( des_self_test( 0 ) == 0 ); 02319 } 02320 FCT_TEST_END(); 02321 #endif /* POLARSSL_SELF_TEST */ 02322 02323 } 02324 FCT_SUITE_END(); 02325 02326 #endif /* POLARSSL_DES_C */ 02327 02328 } 02329 FCT_END(); 02330