139
150
0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
142
byte* global_msg = 0; // for block cipher input
143
byte* global_plain = 0; // for cipher decrypt comparison
144
byte* global_cipher = 0; // block output
153
byte* msg = 0; // for block cipher input
154
byte* plain = 0; // for cipher decrypt comparison
155
byte* cipher = 0; // block output
147
158
void taocrypt_test(void* args)
149
160
((func_args*)args)->return_code = -1; // error state
151
global_msg = NEW_TC byte[24];
152
global_plain = NEW_TC byte[24];
153
global_cipher = NEW_TC byte[24];
162
msg = NEW_TC byte[24];
163
plain = NEW_TC byte[24];
164
cipher = NEW_TC byte[24];
155
memcpy(global_msg, msgTmp, 24);
166
memcpy(msg, msgTmp, 24);
158
169
if ( (ret = sha_test()) )
161
172
printf( "SHA test passed!\n");
174
if ( (ret = sha256_test()) )
175
err_sys("SHA-256 test failed!\n", ret);
177
printf( "SHA-256 test passed!\n");
179
if ( (ret = sha224_test()) )
180
err_sys("SHA-224 test failed!\n", ret);
182
printf( "SHA-224 test passed!\n");
184
#ifdef WORD64_AVAILABLE
186
if ( (ret = sha512_test()) )
187
err_sys("SHA-512 test failed!\n", ret);
189
printf( "SHA-512 test passed!\n");
191
if ( (ret = sha384_test()) )
192
err_sys("SHA-384 test failed!\n", ret);
194
printf( "SHA-384 test passed!\n");
163
198
if ( (ret = md5_test()) )
164
199
err_sys("MD5 test failed!\n", ret);
369
byte hash[SHA256::DIGEST_SIZE];
371
testVector test_sha[] =
374
"\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
375
"\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
377
testVector("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
378
"\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
379
"\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
383
int times( sizeof(test_sha) / sizeof(testVector) );
384
for (int i = 0; i < times; ++i) {
385
sha.Update(test_sha[i].input_, test_sha[i].inLen_);
388
if (memcmp(hash, test_sha[i].output_, SHA256::DIGEST_SIZE) != 0)
396
#ifdef WORD64_AVAILABLE
401
byte hash[SHA512::DIGEST_SIZE];
403
testVector test_sha[] =
406
"\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
407
"\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
408
"\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
409
"\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
411
testVector("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
412
"jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
413
"\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
414
"\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
415
"\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
416
"\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
420
int times( sizeof(test_sha) / sizeof(testVector) );
421
for (int i = 0; i < times; ++i) {
422
sha.Update(test_sha[i].input_, test_sha[i].inLen_);
425
if (memcmp(hash, test_sha[i].output_, SHA512::DIGEST_SIZE) != 0)
436
byte hash[SHA384::DIGEST_SIZE];
438
testVector test_sha[] =
441
"\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
442
"\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
443
"\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
445
testVector("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
446
"jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
447
"\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
448
"\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
449
"\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
453
int times( sizeof(test_sha) / sizeof(testVector) );
454
for (int i = 0; i < times; ++i) {
455
sha.Update(test_sha[i].input_, test_sha[i].inLen_);
458
if (memcmp(hash, test_sha[i].output_, SHA384::DIGEST_SIZE) != 0)
465
#endif // WORD64_AVAILABLE
471
byte hash[SHA224::DIGEST_SIZE];
473
testVector test_sha[] =
476
"\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2\x55"
477
"\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7"),
478
testVector("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
479
"\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
480
"\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25")
483
int times( sizeof(test_sha) / sizeof(testVector) );
484
for (int i = 0; i < times; ++i) {
485
sha.Update(test_sha[i].input_, test_sha[i].inLen_);
488
if (memcmp(hash, test_sha[i].output_, SHA224::DIGEST_SIZE) != 0)
606
771
const byte iv[] = { 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef };
608
773
enc.SetKey(key, sizeof(key));
609
enc.Process(global_cipher, global_msg, sz);
774
enc.Process(cipher, msg, sz);
610
775
dec.SetKey(key, sizeof(key));
611
dec.Process(global_plain, global_cipher, sz);
776
dec.Process(plain, cipher, sz);
613
if (memcmp(global_plain, global_msg, sz))
778
if (memcmp(plain, msg, sz))
616
781
const byte verify1[] =
628
793
DES_CBC_Decryption dec2;
630
795
enc2.SetKey(key, sizeof(key), iv);
631
enc2.Process(global_cipher, global_msg, sz);
796
enc2.Process(cipher, msg, sz);
632
797
dec2.SetKey(key, sizeof(key), iv);
633
dec2.Process(global_plain, global_cipher, sz);
798
dec2.Process(plain, cipher, sz);
635
if (memcmp(global_plain, global_msg, sz))
800
if (memcmp(plain, msg, sz))
638
803
const byte verify2[] =
666
831
enc3.SetKey(key3, sizeof(key3), iv3);
667
enc3.Process(global_cipher, global_msg, sz);
832
enc3.Process(cipher, msg, sz);
668
833
dec3.SetKey(key3, sizeof(key3), iv3);
669
dec3.Process(global_plain, global_cipher, sz);
834
dec3.Process(plain, cipher, sz);
671
if (memcmp(global_plain, global_msg, sz))
836
if (memcmp(plain, msg, sz))
674
839
const byte verify3[] =
697
862
enc.SetKey(key, bs, iv);
698
863
dec.SetKey(key, bs, iv);
700
enc.Process(global_cipher, global_msg, bs);
701
dec.Process(global_plain, global_cipher, bs);
865
enc.Process(cipher, msg, bs);
866
dec.Process(plain, cipher, bs);
703
if (memcmp(global_plain, global_msg, bs))
868
if (memcmp(plain, msg, bs))
706
871
const byte verify[] =
718
883
enc2.SetKey(key, bs, iv);
719
884
dec2.SetKey(key, bs, iv);
721
enc2.Process(global_cipher, global_msg, bs);
722
dec2.Process(global_plain, global_cipher, bs);
886
enc2.Process(cipher, msg, bs);
887
dec2.Process(plain, cipher, bs);
724
if (memcmp(global_plain, global_msg, bs))
889
if (memcmp(plain, msg, bs))
727
892
const byte verify2[] =
749
914
enc.SetKey(key, bs, iv);
750
915
dec.SetKey(key, bs, iv);
752
enc.Process(global_cipher, global_msg, bs);
753
dec.Process(global_plain, global_cipher, bs);
917
enc.Process(cipher, msg, bs);
918
dec.Process(plain, cipher, bs);
755
if (memcmp(global_plain, global_msg, bs))
920
if (memcmp(plain, msg, bs))
758
923
const byte verify[] =
770
935
enc2.SetKey(key, bs, iv);
771
936
dec2.SetKey(key, bs, iv);
773
enc2.Process(global_cipher, global_msg, bs);
774
dec2.Process(global_plain, global_cipher, bs);
938
enc2.Process(cipher, msg, bs);
939
dec2.Process(plain, cipher, bs);
776
if (memcmp(global_plain, global_msg, bs))
941
if (memcmp(plain, msg, bs))
779
944
const byte verify2[] =
801
966
enc.SetKey(key, 16, iv);
802
967
dec.SetKey(key, 16, iv);
804
enc.Process(global_cipher, global_msg, bs * 2);
805
dec.Process(global_plain, global_cipher, bs * 2);
969
enc.Process(cipher, msg, bs * 2);
970
dec.Process(plain, cipher, bs * 2);
807
if (memcmp(global_plain, global_msg, bs))
972
if (memcmp(plain, msg, bs))
810
975
const byte verify[] =
822
987
enc2.SetKey(key, 16, iv);
823
988
dec2.SetKey(key, 16, iv);
825
enc2.Process(global_cipher, global_msg, bs * 2);
826
dec2.Process(global_plain, global_cipher, bs * 2);
990
enc2.Process(cipher, msg, bs * 2);
991
dec2.Process(plain, cipher, bs * 2);
828
if (memcmp(global_plain, global_msg, bs))
993
if (memcmp(plain, msg, bs))
831
996
const byte verify2[] =