25 #include "ctc_ripemd.h"
31 /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
32 #pragma warning(disable: 4996)
43 #include "crypto_ntru.h"
48 /* since just testing, use THREADX log printf instead */
49 int dc_log_printf(char*, ...);
51 #define printf dc_log_printf
55 typedef struct testVector
{
80 int openssl_test(); /* test mini api */
85 int PemToDer(const char* inName
, const char* outName
);
88 void err_sys(const char* msg
, int es
)
90 printf("%s error = %d\n", msg
, es
);
96 /* func_args from cyassl_test.h, so don't have to pull in other junk */
97 typedef struct func_args
{
104 void ctaocrypt_test(void* args
)
108 ((func_args
*)args
)->return_code
= -1; /* error state */
110 if ( (ret
= md5_test()) )
111 err_sys("MD5 test failed!\n", ret
);
113 printf( "MD5 test passed!\n");
116 if ( (ret
= md4_test()) )
117 err_sys("MD4 test failed!\n", ret
);
119 printf( "MD4 test passed!\n");
122 if ( (ret
= sha_test()) )
123 err_sys("SHA test failed!\n", ret
);
125 printf( "SHA test passed!\n");
128 if ( (ret
= sha256_test()) )
129 err_sys("SHA-256 test failed!\n", ret
);
131 printf( "SHA-256 test passed!\n");
135 if ( (ret
= sha512_test()) )
136 err_sys("SHA-512 test failed!\n", ret
);
138 printf( "SHA-512 test passed!\n");
142 if ( (ret
= ripemd_test()) )
143 err_sys("RIPEMD test failed!\n", ret
);
145 printf( "RIPEMD test passed!\n");
149 if ( (ret
= hmac_test()) )
150 err_sys("HMAC test failed!\n", ret
);
152 printf( "HMAC test passed!\n");
155 if ( (ret
= arc4_test()) )
156 err_sys("ARC4 test failed!\n", ret
);
158 printf( "ARC4 test passed!\n");
161 if ( (ret
= hc128_test()) )
162 err_sys("HC-128 test failed!\n", ret
);
164 printf( "HC-128 test passed!\n");
168 if ( (ret
= rabbit_test()) )
169 err_sys("Rabbit test failed!\n", ret
);
171 printf( "Rabbit test passed!\n");
175 if ( (ret
= des_test()) )
176 err_sys("DES test failed!\n", ret
);
178 printf( "DES test passed!\n");
182 if ( (ret
= des3_test()) )
183 err_sys("DES3 test failed!\n", ret
);
185 printf( "DES3 test passed!\n");
189 if ( (ret
= aes_test()) )
190 err_sys("AES test failed!\n", ret
);
192 printf( "AES test passed!\n");
195 if ( (ret
= random_test()) )
196 err_sys("RANDOM test failed!\n", ret
);
198 printf( "RANDOM test passed!\n");
200 if ( (ret
= rsa_test()) )
201 err_sys("RSA test failed!\n", ret
);
203 printf( "RSA test passed!\n");
206 if ( (ret
= dh_test()) )
207 err_sys("DH test failed!\n", ret
);
209 printf( "DH test passed!\n");
213 if ( (ret
= dsa_test()) )
214 err_sys("DSA test failed!\n", ret
);
216 printf( "DSA test passed!\n");
220 if ( (ret
= pwdbased_test()) )
221 err_sys("PWDBASED test failed!\n", ret
);
223 printf( "PWDBASED test passed!\n");
227 if ( (ret
= openssl_test()) )
228 err_sys("OPENSSL test failed!\n", ret
);
230 printf( "OPENSSL test passed!\n");
234 if ( (ret
= ecc_test()) )
235 err_sys("ECC test failed!\n", ret
);
237 printf( "ECC test passed!\n");
240 ((func_args
*)args
)->return_code
= ret
;
244 /* so overall tests can pull in test function */
245 #ifndef NO_MAIN_DRIVER
247 int main(int argc
, char** argv
)
254 ctaocrypt_test(&args
);
255 return args
.return_code
;
258 #endif /* NO_MAIN_DRIVER */
264 byte hash
[MD5_DIGEST_SIZE
];
266 testVector a
, b
, c
, d
, e
;
267 testVector test_md5
[5];
268 int times
= sizeof(test_md5
) / sizeof(testVector
), i
;
271 a
.output
= "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
273 a
.inLen
= strlen(a
.input
);
274 a
.outLen
= strlen(a
.output
);
276 b
.input
= "message digest";
277 b
.output
= "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61"
279 b
.inLen
= strlen(b
.input
);
280 b
.outLen
= strlen(b
.output
);
282 c
.input
= "abcdefghijklmnopqrstuvwxyz";
283 c
.output
= "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1"
285 c
.inLen
= strlen(c
.input
);
286 c
.outLen
= strlen(c
.output
);
288 d
.input
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
290 d
.output
= "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d"
292 d
.inLen
= strlen(d
.input
);
293 d
.outLen
= strlen(d
.output
);
295 e
.input
= "1234567890123456789012345678901234567890123456789012345678"
296 "9012345678901234567890";
297 e
.output
= "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
299 e
.inLen
= strlen(e
.input
);
300 e
.outLen
= strlen(e
.output
);
310 for (i
= 0; i
< times
; ++i
) {
311 Md5Update(&md5
, (byte
*)test_md5
[i
].input
, (word32
)test_md5
[i
].inLen
);
312 Md5Final(&md5
, hash
);
314 if (memcmp(hash
, test_md5
[i
].output
, MD5_DIGEST_SIZE
) != 0)
327 byte hash
[MD4_DIGEST_SIZE
];
329 testVector a
, b
, c
, d
, e
, f
, g
;
330 testVector test_md4
[7];
331 int times
= sizeof(test_md4
) / sizeof(testVector
), i
;
334 a
.output
= "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89"
336 a
.inLen
= strlen(a
.input
);
337 a
.outLen
= strlen(a
.output
);
340 b
.output
= "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb"
342 b
.inLen
= strlen(b
.input
);
343 b
.outLen
= strlen(b
.output
);
346 c
.output
= "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72"
348 c
.inLen
= strlen(c
.input
);
349 c
.outLen
= strlen(c
.output
);
351 d
.input
= "message digest";
352 d
.output
= "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01"
354 d
.inLen
= strlen(d
.input
);
355 d
.outLen
= strlen(d
.output
);
357 e
.input
= "abcdefghijklmnopqrstuvwxyz";
358 e
.output
= "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d"
360 e
.inLen
= strlen(e
.input
);
361 e
.outLen
= strlen(e
.output
);
363 f
.input
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
365 f
.output
= "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0"
367 f
.inLen
= strlen(f
.input
);
368 f
.outLen
= strlen(f
.output
);
370 g
.input
= "1234567890123456789012345678901234567890123456789012345678"
371 "9012345678901234567890";
372 g
.output
= "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05"
374 g
.inLen
= strlen(g
.input
);
375 g
.outLen
= strlen(g
.output
);
387 for (i
= 0; i
< times
; ++i
) {
388 Md4Update(&md4
, (byte
*)test_md4
[i
].input
, (word32
)test_md4
[i
].inLen
);
389 Md4Final(&md4
, hash
);
391 if (memcmp(hash
, test_md4
[i
].output
, MD4_DIGEST_SIZE
) != 0)
403 byte hash
[SHA_DIGEST_SIZE
];
405 testVector a
, b
, c
, d
;
406 testVector test_sha
[4];
407 int times
= sizeof(test_sha
) / sizeof(struct testVector
), i
;
410 a
.output
= "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
411 "\x6C\x9C\xD0\xD8\x9D";
412 a
.inLen
= strlen(a
.input
);
413 a
.outLen
= strlen(a
.output
);
415 b
.input
= "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
416 b
.output
= "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29"
417 "\xE5\xE5\x46\x70\xF1";
418 b
.inLen
= strlen(b
.input
);
419 b
.outLen
= strlen(b
.output
);
421 c
.input
= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
423 c
.output
= "\x00\x98\xBA\x82\x4B\x5C\x16\x42\x7B\xD7\xA1\x12\x2A\x5A\x44"
424 "\x2A\x25\xEC\x64\x4D";
425 c
.inLen
= strlen(c
.input
);
426 c
.outLen
= strlen(c
.output
);
428 d
.input
= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
429 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
431 d
.output
= "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
432 "\x53\x99\x5E\x26\xA0";
433 d
.inLen
= strlen(d
.input
);
434 d
.outLen
= strlen(d
.output
);
443 for (i
= 0; i
< times
; ++i
) {
444 ShaUpdate(&sha
, (byte
*)test_sha
[i
].input
, (word32
)test_sha
[i
].inLen
);
445 ShaFinal(&sha
, hash
);
447 if (memcmp(hash
, test_sha
[i
].output
, SHA_DIGEST_SIZE
) != 0)
459 byte hash
[RIPEMD_DIGEST_SIZE
];
461 testVector a
, b
, c
, d
;
462 testVector test_ripemd
[4];
463 int times
= sizeof(test_ripemd
) / sizeof(struct testVector
), i
;
466 a
.output
= "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
467 "\xb0\x87\xf1\x5a\x0b\xfc";
468 a
.inLen
= strlen(a
.input
);
469 a
.outLen
= strlen(a
.output
);
471 b
.input
= "message digest";
472 b
.output
= "\x5d\x06\x89\xef\x49\xd2\xfa\xe5\x72\xb8\x81\xb1\x23\xa8"
473 "\x5f\xfa\x21\x59\x5f\x36";
474 b
.inLen
= strlen(b
.input
);
475 b
.outLen
= strlen(b
.output
);
477 c
.input
= "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
478 c
.output
= "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05\xa0\x6c\x27\xdc"
479 "\xf4\x9a\xda\x62\xeb\x2b";
480 c
.inLen
= strlen(c
.input
);
481 c
.outLen
= strlen(c
.output
);
483 d
.input
= "12345678901234567890123456789012345678901234567890123456"
484 "789012345678901234567890";
485 d
.output
= "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb\xd3\x32\x3c\xab"
486 "\x82\xbf\x63\x32\x6b\xfb";
487 d
.inLen
= strlen(d
.input
);
488 d
.outLen
= strlen(d
.output
);
497 for (i
= 0; i
< times
; ++i
) {
498 RipeMdUpdate(&ripemd
, (byte
*)test_ripemd
[i
].input
,
499 (word32
)test_ripemd
[i
].inLen
);
500 RipeMdFinal(&ripemd
, hash
);
502 if (memcmp(hash
, test_ripemd
[i
].output
, RIPEMD_DIGEST_SIZE
) != 0)
508 #endif /* CYASSL_RIPEMD */
515 byte hash
[SHA256_DIGEST_SIZE
];
518 testVector test_sha
[2];
519 int times
= sizeof(test_sha
) / sizeof(struct testVector
), i
;
522 a
.output
= "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
523 "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
525 a
.inLen
= strlen(a
.input
);
526 a
.outLen
= strlen(a
.output
);
528 b
.input
= "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
529 b
.output
= "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
530 "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
532 b
.inLen
= strlen(b
.input
);
533 b
.outLen
= strlen(b
.output
);
540 for (i
= 0; i
< times
; ++i
) {
541 Sha256Update(&sha
, (byte
*)test_sha
[i
].input
,(word32
)test_sha
[i
].inLen
);
542 Sha256Final(&sha
, hash
);
544 if (memcmp(hash
, test_sha
[i
].output
, SHA256_DIGEST_SIZE
) != 0)
557 byte hash
[SHA512_DIGEST_SIZE
];
560 testVector test_sha
[2];
561 int times
= sizeof(test_sha
) / sizeof(struct testVector
), i
;
564 a
.output
= "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
565 "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
566 "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
567 "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
569 a
.inLen
= strlen(a
.input
);
570 a
.outLen
= strlen(a
.output
);
572 b
.input
= "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
573 "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
574 b
.output
= "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
575 "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
576 "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
577 "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
579 b
.inLen
= strlen(b
.input
);
580 b
.outLen
= strlen(b
.output
);
587 for (i
= 0; i
< times
; ++i
) {
588 Sha512Update(&sha
, (byte
*)test_sha
[i
].input
,(word32
)test_sha
[i
].inLen
);
589 Sha512Final(&sha
, hash
);
591 if (memcmp(hash
, test_sha
[i
].output
, SHA512_DIGEST_SIZE
) != 0)
604 byte hash
[MD5_DIGEST_SIZE
];
608 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
610 "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
614 testVector test_hmac
[3];
616 int times
= sizeof(test_hmac
) / sizeof(testVector
), i
;
618 a
.input
= "Hi There";
619 a
.output
= "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
621 a
.inLen
= strlen(a
.input
);
622 a
.outLen
= strlen(a
.output
);
624 b
.input
= "what do ya want for nothing?";
625 b
.output
= "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7"
627 b
.inLen
= strlen(b
.input
);
628 b
.outLen
= strlen(b
.output
);
630 c
.input
= "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
631 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
632 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
633 "\xDD\xDD\xDD\xDD\xDD\xDD";
634 c
.output
= "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3"
636 c
.inLen
= strlen(c
.input
);
637 c
.outLen
= strlen(c
.output
);
643 for (i
= 0; i
< times
; ++i
) {
644 HmacSetKey(&hmac
, MD5
, (byte
*)keys
[i
], (word32
)strlen(keys
[i
]));
645 HmacUpdate(&hmac
, (byte
*)test_hmac
[i
].input
,
646 (word32
)test_hmac
[i
].inLen
);
647 HmacFinal(&hmac
, hash
);
649 if (memcmp(hash
, test_hmac
[i
].output
, MD5_DIGEST_SIZE
) != 0)
665 "\x01\x23\x45\x67\x89\xab\xcd\xef",
666 "\x01\x23\x45\x67\x89\xab\xcd\xef",
667 "\x00\x00\x00\x00\x00\x00\x00\x00",
671 testVector a
, b
, c
, d
;
672 testVector test_arc4
[4];
674 int times
= sizeof(test_arc4
) / sizeof(testVector
), i
;
676 a
.input
= "\x01\x23\x45\x67\x89\xab\xcd\xef";
677 a
.output
= "\x75\xb7\x87\x80\x99\xe0\xc5\x96";
678 a
.inLen
= strlen(a
.input
);
679 a
.outLen
= strlen(a
.output
);
681 b
.input
= "\x00\x00\x00\x00\x00\x00\x00\x00";
682 b
.output
= "\x74\x94\xc2\xe7\x10\x4b\x08\x79";
683 b
.inLen
= strlen(b
.input
);
684 b
.outLen
= strlen(b
.output
);
686 c
.input
= "\x00\x00\x00\x00\x00\x00\x00\x00";
687 c
.output
= "\xde\x18\x89\x41\xa3\x37\x5d\x3a";
688 c
.inLen
= strlen(c
.input
);
689 c
.outLen
= strlen(c
.output
);
691 d
.input
= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
692 d
.output
= "\xd6\xa1\x41\xa7\xec\x3c\x38\xdf\xbd\x61";
693 d
.inLen
= strlen(d
.input
);
694 d
.outLen
= strlen(d
.output
);
701 for (i
= 0; i
< times
; ++i
) {
705 Arc4SetKey(&enc
, (byte
*)keys
[i
], (word32
)strlen(keys
[i
]));
706 Arc4SetKey(&dec
, (byte
*)keys
[i
], (word32
)strlen(keys
[i
]));
708 Arc4Process(&enc
, cipher
, (byte
*)test_arc4
[i
].input
,
709 (word32
)test_arc4
[i
].outLen
);
710 Arc4Process(&dec
, plain
, cipher
, (word32
)test_arc4
[i
].outLen
);
712 if (memcmp(plain
, test_arc4
[i
].input
, test_arc4
[i
].outLen
))
715 if (memcmp(cipher
, test_arc4
[i
].output
, test_arc4
[i
].outLen
))
731 "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
732 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
733 "\x00\x53\xA6\xF9\x4C\x9F\xF2\x45\x98\xEB\x3E\x91\xE4\x37\x8A\xDD",
734 "\x0F\x62\xB5\x08\x5B\xAE\x01\x54\xA7\xFA\x4D\xA0\xF3\x46\x99\xEC"
739 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
740 "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
741 "\x0D\x74\xDB\x42\xA9\x10\x77\xDE\x45\xAC\x13\x7A\xE1\x48\xAF\x16",
742 "\x28\x8F\xF6\x5D\xC4\x2B\x92\xF9\x60\xC7\x2E\x95\xFC\x63\xCA\x31"
746 testVector a
, b
, c
, d
;
747 testVector test_hc128
[4];
749 int times
= sizeof(test_hc128
) / sizeof(testVector
), i
;
751 a
.input
= "\x00\x00\x00\x00\x00\x00\x00\x00";
752 a
.output
= "\x37\x86\x02\xB9\x8F\x32\xA7\x48";
753 a
.inLen
= strlen(a
.input
);
754 a
.outLen
= strlen(a
.output
);
756 b
.input
= "\x00\x00\x00\x00\x00\x00\x00\x00";
757 b
.output
= "\x33\x7F\x86\x11\xC6\xED\x61\x5F";
758 b
.inLen
= strlen(b
.input
);
759 b
.outLen
= strlen(b
.output
);
761 c
.input
= "\x00\x00\x00\x00\x00\x00\x00\x00";
762 c
.output
= "\x2E\x1E\xD1\x2A\x85\x51\xC0\x5A";
763 c
.inLen
= strlen(c
.input
);
764 c
.outLen
= strlen(c
.output
);
766 d
.input
= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
767 d
.output
= "\x1C\xD8\xAE\xDD\xFE\x52\xE2\x17\xE8\x35\xD0\xB7\xE8\x4E\x29";
768 d
.inLen
= strlen(d
.input
);
769 d
.outLen
= strlen(d
.output
);
776 for (i
= 0; i
< times
; ++i
) {
780 Hc128_SetKey(&enc
, (byte
*)keys
[i
], (byte
*)ivs
[i
]);
781 Hc128_SetKey(&dec
, (byte
*)keys
[i
], (byte
*)ivs
[i
]);
783 Hc128_Process(&enc
, cipher
, (byte
*)test_hc128
[i
].input
,
784 (word32
)test_hc128
[i
].outLen
);
785 Hc128_Process(&dec
, plain
, cipher
, (word32
)test_hc128
[i
].outLen
);
787 if (memcmp(plain
, test_hc128
[i
].input
, test_hc128
[i
].outLen
))
790 if (memcmp(cipher
, test_hc128
[i
].output
, test_hc128
[i
].outLen
))
796 #endif /* NO_HC128 */
807 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
808 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
809 "\xAC\xC3\x51\xDC\xF1\x62\xFC\x3B\xFE\x36\x3D\x2E\x29\x13\x28\x91"
814 "\x00\x00\x00\x00\x00\x00\x00\x00",
815 "\x59\x7E\x26\xC1\x75\xF5\x73\xC3",
821 testVector test_rabbit
[3];
823 int times
= sizeof(test_rabbit
) / sizeof(testVector
), i
;
825 a
.input
= "\x00\x00\x00\x00\x00\x00\x00\x00";
826 a
.output
= "\xED\xB7\x05\x67\x37\x5D\xCD\x7C";
827 a
.inLen
= strlen(a
.input
);
828 a
.outLen
= strlen(a
.output
);
830 b
.input
= "\x00\x00\x00\x00\x00\x00\x00\x00";
831 b
.output
= "\x6D\x7D\x01\x22\x92\xCC\xDC\xE0";
832 b
.inLen
= strlen(b
.input
);
833 b
.outLen
= strlen(b
.output
);
835 c
.input
= "\x00\x00\x00\x00\x00\x00\x00\x00";
836 c
.output
= "\x9C\x51\xE2\x87\x84\xC3\x7F\xE9";
837 c
.inLen
= strlen(c
.input
);
838 c
.outLen
= strlen(c
.output
);
844 for (i
= 0; i
< times
; ++i
) {
848 RabbitSetKey(&enc
, (byte
*)keys
[i
], (byte
*)ivs
[i
]);
849 RabbitSetKey(&dec
, (byte
*)keys
[i
], (byte
*)ivs
[i
]);
851 RabbitProcess(&enc
, cipher
, (byte
*)test_rabbit
[i
].input
,
852 (word32
)test_rabbit
[i
].outLen
);
853 RabbitProcess(&dec
, plain
, cipher
, (word32
)test_rabbit
[i
].outLen
);
855 if (memcmp(plain
, test_rabbit
[i
].input
, test_rabbit
[i
].outLen
))
858 if (memcmp(cipher
, test_rabbit
[i
].output
, test_rabbit
[i
].outLen
))
864 #endif /* NO_RABBIT */
870 const byte vector
[] = { /* "now is the time for all " w/o trailing 0 */
871 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
872 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
873 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
884 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
889 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
892 const byte verify
[] =
894 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
895 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
896 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
900 Des_SetKey(&enc
, key
, iv
, DES_ENCRYPTION
);
901 Des_CbcEncrypt(&enc
, cipher
, vector
, sizeof(vector
));
902 Des_SetKey(&dec
, key
, iv
, DES_DECRYPTION
);
903 Des_CbcDecrypt(&dec
, plain
, cipher
, sizeof(cipher
));
905 if (memcmp(plain
, vector
, sizeof(plain
)))
908 if (memcmp(cipher
, verify
, sizeof(cipher
)))
919 const byte vector
[] = { /* "Now is the time for all " w/o trailing 0 */
920 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
921 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
922 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
933 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
934 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
935 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
939 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
940 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
941 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
945 const byte verify3
[] =
947 0x43,0xa0,0x29,0x7e,0xd1,0x84,0xf8,0x0e,
948 0x89,0x64,0x84,0x32,0x12,0xd5,0x08,0x98,
949 0x18,0x94,0x15,0x74,0x87,0x12,0x7d,0xb0
953 Des3_SetKey(&enc
, key3
, iv3
, DES_ENCRYPTION
);
954 Des3_CbcEncrypt(&enc
, cipher
, vector
, sizeof(vector
));
955 Des3_SetKey(&dec
, key3
, iv3
, DES_DECRYPTION
);
956 Des3_CbcDecrypt(&dec
, plain
, cipher
, sizeof(cipher
));
958 if (memcmp(plain
, vector
, sizeof(plain
)))
961 if (memcmp(cipher
, verify3
, sizeof(cipher
)))
975 const byte msg
[] = { /* "Now is the time for all " w/o trailing 0 */
976 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
977 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
978 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
981 const byte verify
[] =
983 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
984 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
987 byte key
[] = "0123456789abcdef "; /* align */
988 byte iv
[] = "1234567890abcdef "; /* align */
990 byte cipher
[AES_BLOCK_SIZE
];
991 byte plain
[AES_BLOCK_SIZE
];
993 AesSetKey(&enc
, key
, AES_BLOCK_SIZE
, iv
, AES_ENCRYPTION
);
994 AesSetKey(&dec
, key
, AES_BLOCK_SIZE
, iv
, AES_DECRYPTION
);
996 AesCbcEncrypt(&enc
, cipher
, msg
, AES_BLOCK_SIZE
);
997 AesCbcDecrypt(&dec
, plain
, cipher
, AES_BLOCK_SIZE
);
999 if (memcmp(plain
, msg
, AES_BLOCK_SIZE
))
1002 if (memcmp(cipher
, verify
, AES_BLOCK_SIZE
))
1014 int ret
= InitRng(&rng
);
1015 if (ret
!= 0) return -39;
1017 RNG_GenerateBlock(&rng
, block
, sizeof(block
));
1023 #ifndef NO_MAIN_DRIVER
1024 static const char* clientKey
= "../../certs/client-key.der";
1025 static const char* clientCert
= "../../certs/client-cert.der";
1026 #ifdef CYASSL_CERT_GEN
1027 static const char* caKeyFile
= "../../certs/ca-key.der";
1028 static const char* caCertFile
= "../../certs/ca-cert.pem";
1031 static const char* clientKey
= "../certs/client-key.der";
1032 static const char* clientCert
= "../certs/client-cert.der";
1033 #ifdef CYASSL_CERT_GEN
1034 static const char* caKeyFile
= "../certs/ca-key.der";
1035 static const char* caCertFile
= "../certs/ca-cert.pem";
1042 static byte
GetEntropy(ENTROPY_CMD cmd
, byte
* out
)
1047 int ret
= InitRng(&rng
);
1057 if (cmd
== GET_BYTE_OF_ENTROPY
) {
1058 RNG_GenerateBlock(&rng
, out
, 1);
1062 if (cmd
== GET_NUM_BYTES_PER_BYTE_OF_ENTROPY
) {
1070 #endif /* HAVE_NTRU */
1074 byte tmp
[2048], tmp2
[2048];
1075 size_t bytes
, bytes2
;
1080 byte in
[] = "Everyone gets Friday off.";
1081 word32 inLen
= (word32
)strlen((char*)in
);
1086 FILE* file
= fopen(clientKey
, "rb"), * file2
;
1091 bytes
= fread(tmp
, 1, sizeof(tmp
), file
);
1093 InitRsaKey(&key
, 0);
1094 ret
= RsaPrivateKeyDecode(tmp
, &idx
, &key
, (word32
)bytes
);
1095 if (ret
!= 0) return -41;
1097 ret
= InitRng(&rng
);
1098 if (ret
!= 0) return -42;
1100 ret
= RsaPublicEncrypt(in
, inLen
, out
, sizeof(out
), &key
, &rng
);
1102 ret
= RsaPrivateDecrypt(out
, ret
, plain
, sizeof(plain
), &key
);
1104 if (memcmp(plain
, in
, inLen
)) return -45;
1106 ret
= RsaSSL_Sign(in
, inLen
, out
, sizeof(out
), &key
, &rng
);
1107 memset(plain
, 0, sizeof(plain
));
1108 ret
= RsaSSL_Verify(out
, ret
, plain
, sizeof(plain
), &key
);
1110 if (memcmp(plain
, in
, ret
)) return -46;
1112 file2
= fopen(clientCert
, "rb");
1116 bytes2
= fread(tmp2
, 1, sizeof(tmp2
), file2
);
1118 InitDecodedCert(&cert
, (byte
*)&tmp2
, 0);
1120 ret
= ParseCert(&cert
, (word32
)bytes2
, CERT_TYPE
, NO_VERIFY
, 0);
1121 if (ret
!= 0) return -48;
1123 FreeDecodedCert(&cert
);
1128 #ifdef CYASSL_KEY_GEN
1139 InitRsaKey(&genKey
, 0);
1140 ret
= MakeRsaKey(&genKey
, 1024, 65537, &rng
);
1144 derSz
= RsaKeyToDer(&genKey
, der
, sizeof(der
));
1148 keyFile
= fopen("./ker.der", "wb");
1151 ret
= fwrite(der
, derSz
, 1, keyFile
);
1154 pemSz
= DerToPem(der
, derSz
, pem
, sizeof(pem
), PRIVATEKEY_TYPE
);
1158 pemFile
= fopen("./key.pem", "wb");
1161 ret
= fwrite(pem
, pemSz
, 1, pemFile
);
1164 InitRsaKey(&derIn
, 0);
1166 ret
= RsaPrivateKeyDecode(der
, &idx
, &derIn
, derSz
);
1171 FreeRsaKey(&genKey
);
1173 #endif /* CYASSL_KEY_GEN */
1176 #ifdef CYASSL_CERT_GEN
1190 strncpy(myCert
.subject
.country
, "US", NAME_SIZE
);
1191 strncpy(myCert
.subject
.state
, "OR", NAME_SIZE
);
1192 strncpy(myCert
.subject
.locality
, "Portland", NAME_SIZE
);
1193 strncpy(myCert
.subject
.org
, "yaSSL", NAME_SIZE
);
1194 strncpy(myCert
.subject
.unit
, "Development", NAME_SIZE
);
1195 strncpy(myCert
.subject
.commonName
, "www.yassl.com", NAME_SIZE
);
1196 strncpy(myCert
.subject
.email
, "info@yassl.com", NAME_SIZE
);
1198 certSz
= MakeSelfCert(&myCert
, derCert
, sizeof(derCert
), &key
, &rng
);
1202 InitDecodedCert(&decode
, derCert
, 0);
1203 ret
= ParseCert(&decode
, certSz
, CERT_TYPE
, NO_VERIFY
, 0);
1207 derFile
= fopen("./cert.der", "wb");
1210 ret
= fwrite(derCert
, certSz
, 1, derFile
);
1213 pemSz
= DerToPem(derCert
, certSz
, pem
, sizeof(pem
), CERT_TYPE
);
1217 pemFile
= fopen("./cert.pem", "wb");
1220 ret
= fwrite(pem
, pemSz
, 1, pemFile
);
1223 FreeDecodedCert(&decode
);
1241 FILE* file
= fopen(caKeyFile
, "rb");
1246 bytes
= fread(tmp
, 1, sizeof(tmp
), file
);
1248 InitRsaKey(&caKey
, 0);
1249 ret
= RsaPrivateKeyDecode(tmp
, &idx
, &caKey
, (word32
)bytes
);
1250 if (ret
!= 0) return -413;
1254 strncpy(myCert
.subject
.country
, "US", NAME_SIZE
);
1255 strncpy(myCert
.subject
.state
, "OR", NAME_SIZE
);
1256 strncpy(myCert
.subject
.locality
, "Portland", NAME_SIZE
);
1257 strncpy(myCert
.subject
.org
, "yaSSL", NAME_SIZE
);
1258 strncpy(myCert
.subject
.unit
, "Development", NAME_SIZE
);
1259 strncpy(myCert
.subject
.commonName
, "www.yassl.com", NAME_SIZE
);
1260 strncpy(myCert
.subject
.email
, "info@yassl.com", NAME_SIZE
);
1262 ret
= SetIssuer(&myCert
, caCertFile
);
1266 certSz
= MakeCert(&myCert
, derCert
, sizeof(derCert
), &key
, &rng
);
1270 certSz
= SignCert(&myCert
, derCert
, sizeof(derCert
), &caKey
, &rng
);
1275 InitDecodedCert(&decode
, derCert
, 0);
1276 ret
= ParseCert(&decode
, certSz
, CERT_TYPE
, NO_VERIFY
, 0);
1280 derFile
= fopen("./othercert.der", "wb");
1283 ret
= fwrite(derCert
, certSz
, 1, derFile
);
1286 pemSz
= DerToPem(derCert
, certSz
, pem
, sizeof(pem
), CERT_TYPE
);
1290 pemFile
= fopen("./othercert.pem", "wb");
1293 ret
= fwrite(pem
, pemSz
, 1, pemFile
);
1296 FreeDecodedCert(&decode
);
1316 byte public_key
[557]; /* sized for EES401EP2 */
1317 word16 public_key_len
; /* no. of octets in public key */
1318 byte private_key
[607]; /* sized for EES401EP2 */
1319 word16 private_key_len
; /* no. of octets in private key */
1321 static uint8_t const pers_str
[] = {
1322 'C', 'y', 'a', 'S', 'S', 'L', ' ', 't', 'e', 's', 't'
1324 word32 rc
= crypto_drbg_instantiate(112, pers_str
, sizeof(pers_str
),
1329 rc
= crypto_ntru_encrypt_keygen(drbg
, NTRU_EES401EP2
, &public_key_len
,
1330 NULL
, &private_key_len
, NULL
);
1334 rc
= crypto_ntru_encrypt_keygen(drbg
, NTRU_EES401EP2
, &public_key_len
,
1335 public_key
, &private_key_len
, private_key
);
1336 crypto_drbg_uninstantiate(drbg
);
1341 caFile
= fopen(caKeyFile
, "rb");
1346 bytes
= fread(tmp
, 1, sizeof(tmp
), caFile
);
1349 InitRsaKey(&caKey
, 0);
1350 ret
= RsaPrivateKeyDecode(tmp
, &idx
, &caKey
, (word32
)bytes
);
1351 if (ret
!= 0) return -454;
1355 strncpy(myCert
.subject
.country
, "US", NAME_SIZE
);
1356 strncpy(myCert
.subject
.state
, "OR", NAME_SIZE
);
1357 strncpy(myCert
.subject
.locality
, "Portland", NAME_SIZE
);
1358 strncpy(myCert
.subject
.org
, "yaSSL", NAME_SIZE
);
1359 strncpy(myCert
.subject
.unit
, "Development", NAME_SIZE
);
1360 strncpy(myCert
.subject
.commonName
, "www.yassl.com", NAME_SIZE
);
1361 strncpy(myCert
.subject
.email
, "info@yassl.com", NAME_SIZE
);
1363 ret
= SetIssuer(&myCert
, caCertFile
);
1367 certSz
= MakeNtruCert(&myCert
, derCert
, sizeof(derCert
), public_key
,
1368 public_key_len
, &rng
);
1372 certSz
= SignCert(&myCert
, derCert
, sizeof(derCert
), &caKey
, &rng
);
1377 InitDecodedCert(&decode
, derCert
, 0);
1378 ret
= ParseCert(&decode
, certSz
, CERT_TYPE
, NO_VERIFY
, 0);
1382 derFile
= fopen("./ntru-cert.der", "wb");
1385 ret
= fwrite(derCert
, certSz
, 1, derFile
);
1388 pemSz
= DerToPem(derCert
, certSz
, pem
, sizeof(pem
), CERT_TYPE
);
1392 pemFile
= fopen("./ntru-cert.pem", "wb");
1395 ret
= fwrite(pem
, pemSz
, 1, pemFile
);
1398 ntruPrivFile
= fopen("./ntru-key.raw", "wb");
1401 ret
= fwrite(private_key
, private_key_len
, 1, ntruPrivFile
);
1402 fclose(ntruPrivFile
);
1406 FreeDecodedCert(&decode
);
1408 #endif /* HAVE_NTRU */
1409 #endif /* CYASSL_CERT_GEN */
1417 #ifndef NO_MAIN_DRIVER
1418 static const char* dhKey
= "../../certs/dh1024.der";
1420 static const char* dhKey
= "../certs/dh1024.der";
1429 word32 idx
= 0, privSz
, pubSz
, privSz2
, pubSz2
, agreeSz
, agreeSz2
;
1440 FILE* file
= fopen(dhKey
, "rb");
1445 bytes
= (word32
) fread(tmp
, 1, sizeof(tmp
), file
);
1449 ret
= DhKeyDecode(tmp
, &idx
, &key
, bytes
);
1454 ret
= DhKeyDecode(tmp
, &idx
, &key2
, bytes
);
1458 ret
= InitRng(&rng
);
1462 ret
= DhGenerateKeyPair(&key
, &rng
, priv
, &privSz
, pub
, &pubSz
);
1463 ret
= DhGenerateKeyPair(&key2
, &rng
, priv2
, &privSz2
, pub2
, &pubSz2
);
1467 ret
= DhAgree(&key
, agree
, &agreeSz
, priv
, privSz
, pub2
, pubSz2
);
1468 ret
= DhAgree(&key2
, agree2
, &agreeSz2
, priv2
, privSz2
, pub
, pubSz
);
1472 if (memcmp(agree
, agree2
, agreeSz
))
1485 #ifndef NO_MAIN_DRIVER
1486 static const char* dsaKey
= "../../certs/dsa512.der";
1488 static const char* dsaKey
= "../certs/dsa512.der";
1501 FILE* file
= fopen(dsaKey
, "rb");
1503 byte hash
[SHA_DIGEST_SIZE
];
1509 bytes
= (word32
) fread(tmp
, 1, sizeof(tmp
), file
);
1512 ShaUpdate(&sha
, tmp
, bytes
);
1513 ShaFinal(&sha
, hash
);
1516 ret
= DsaPrivateKeyDecode(tmp
, &idx
, &key
, bytes
);
1517 if (ret
!= 0) return -61;
1519 ret
= InitRng(&rng
);
1520 if (ret
!= 0) return -62;
1522 ret
= DsaSign(hash
, signature
, &key
, &rng
);
1523 if (ret
!= 0) return -63;
1525 ret
= DsaVerify(hash
, signature
, &key
, &answer
);
1526 if (ret
!= 0) return -64;
1527 if (answer
!= 1) return -65;
1538 #ifdef OPENSSL_EXTRA
1544 byte hash
[SHA_DIGEST_SIZE
];
1546 a
.input
= "1234567890123456789012345678901234567890123456789012345678"
1547 "9012345678901234567890";
1548 a
.output
= "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
1550 a
.inLen
= strlen(a
.input
);
1551 a
.outLen
= strlen(a
.output
);
1553 EVP_MD_CTX_init(&md_ctx
);
1554 EVP_DigestInit(&md_ctx
, EVP_md5());
1556 EVP_DigestUpdate(&md_ctx
, a
.input
, a
.inLen
);
1557 EVP_DigestFinal(&md_ctx
, hash
, 0);
1559 if (memcmp(hash
, a
.output
, MD5_DIGEST_SIZE
) != 0)
1562 b
.input
= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
1563 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
1565 b
.output
= "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
1566 "\x53\x99\x5E\x26\xA0";
1567 b
.inLen
= strlen(b
.input
);
1568 b
.outLen
= strlen(b
.output
);
1570 EVP_MD_CTX_init(&md_ctx
);
1571 EVP_DigestInit(&md_ctx
, EVP_sha1());
1573 EVP_DigestUpdate(&md_ctx
, b
.input
, b
.inLen
);
1574 EVP_DigestFinal(&md_ctx
, hash
, 0);
1576 if (memcmp(hash
, b
.output
, SHA_DIGEST_SIZE
) != 0)
1579 if (RAND_bytes(hash
, sizeof(hash
)) != 1)
1582 c
.input
= "what do ya want for nothing?";
1583 c
.output
= "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7"
1585 c
.inLen
= strlen(c
.input
);
1586 c
.outLen
= strlen(c
.output
);
1588 HMAC(EVP_md5(), "Jefe", 4, (byte
*)c
.input
, (int)c
.inLen
, hash
, 0);
1590 if (memcmp(hash
, c
.output
, MD5_DIGEST_SIZE
) != 0)
1594 const byte vector
[] = { /* "now is the time for all " w/o trailing 0 */
1595 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
1596 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
1597 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
1603 const_DES_cblock key
=
1605 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
1610 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
1613 DES_key_schedule sched
;
1615 const byte verify
[] =
1617 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
1618 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
1619 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
1622 DES_key_sched(&key
, &sched
);
1624 DES_cbc_encrypt(vector
, cipher
, sizeof(vector
), &sched
, &iv
, DES_ENCRYPT
);
1625 DES_cbc_encrypt(cipher
, plain
, sizeof(vector
), &sched
, &iv
, DES_DECRYPT
);
1627 if (memcmp(plain
, vector
, sizeof(vector
)) != 0)
1630 if (memcmp(cipher
, verify
, sizeof(verify
)) != 0)
1633 /* test changing iv */
1634 DES_ncbc_encrypt(vector
, cipher
, 8, &sched
, &iv
, DES_ENCRYPT
);
1635 DES_ncbc_encrypt(vector
+ 8, cipher
+ 8, 16, &sched
, &iv
, DES_ENCRYPT
);
1637 if (memcmp(cipher
, verify
, sizeof(verify
)) != 0)
1640 } /* end des test */
1645 #endif /* OPENSSL_EXTRA */
1652 char passwd
[] = "password";
1653 const byte salt
[] = { 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
1654 int iterations
= 2048;
1657 const byte verify
[] = {
1658 0xBF, 0xDE, 0x6B, 0xE9, 0x4D, 0xF7, 0xE1, 0x1D, 0xD4, 0x09, 0xBC, 0xE2,
1659 0x0A, 0x02, 0x55, 0xEC, 0x32, 0x7C, 0xB9, 0x36, 0xFF, 0xE9, 0x36, 0x43
1669 char passwd
[] = "password";
1670 const byte salt
[] = { 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
1671 int iterations
= 1000;
1675 const byte verify
[] = {
1676 0xDC, 0x19, 0x84, 0x7E, 0x05, 0xC6, 0x4D, 0x2F, 0xAF, 0x10, 0xEB, 0xFB,
1677 0x4A, 0x3D, 0x2A, 0x20
1680 PBKDF1(derived
, (byte
*)passwd
, strlen(passwd
), salt
, 8, iterations
, kLen
,
1683 if (memcmp(derived
, verify
, sizeof(verify
)) != 0)
1692 return pbkdf1_test();
1695 #endif /* NO_PWDBASED */
1710 ecc_key userA
, userB
, pubKey
;
1712 ret
= InitRng(&rng
);
1720 ret
= ecc_make_key(&rng
, 32, &userA
);
1721 ret
= ecc_make_key(&rng
, 32, &userB
);
1726 x
= sizeof(sharedA
);
1727 ret
= ecc_shared_secret(&userA
, &userB
, sharedA
, &x
);
1729 y
= sizeof(sharedB
);
1730 ret
= ecc_shared_secret(&userB
, &userA
, sharedB
, &y
);
1738 if (memcmp(sharedA
, sharedB
, x
))
1742 ret
= ecc_export_x963(&userA
, export
, &x
);
1746 ret
= ecc_import_x963(export
, x
, &pubKey
);
1751 y
= sizeof(sharedB
);
1752 ret
= ecc_shared_secret(&userB
, &pubKey
, sharedB
, &y
);
1757 if (memcmp(sharedA
, sharedB
, y
))
1760 /* test DSA sign hash */
1761 for (i
= 0; i
< sizeof(digest
); i
++)
1765 ret
= ecc_sign_hash(digest
, sizeof(digest
), sig
, &x
, &rng
, &userA
);
1768 ret
= ecc_verify_hash(sig
, x
, digest
, sizeof(digest
), &verify
, &userA
);
1783 #endif /* HAVE_ECC */