| 747 | |
| 748 | |
| 749 | int arc4_test() |
| 750 | { |
| 751 | byte cipher[16]; |
| 752 | byte plain[16]; |
| 753 | |
| 754 | const char* keys[] = |
| 755 | { |
| 756 | "\x01\x23\x45\x67\x89\xab\xcd\xef", |
| 757 | "\x01\x23\x45\x67\x89\xab\xcd\xef", |
| 758 | "\x00\x00\x00\x00\x00\x00\x00\x00", |
| 759 | "\xef\x01\x23\x45" |
| 760 | }; |
| 761 | |
| 762 | testVector test_arc4[] = |
| 763 | { |
| 764 | testVector("\x01\x23\x45\x67\x89\xab\xcd\xef", |
| 765 | "\x75\xb7\x87\x80\x99\xe0\xc5\x96"), |
| 766 | testVector("\x00\x00\x00\x00\x00\x00\x00\x00", |
| 767 | "\x74\x94\xc2\xe7\x10\x4b\x08\x79"), |
| 768 | testVector("\x00\x00\x00\x00\x00\x00\x00\x00", |
| 769 | "\xde\x18\x89\x41\xa3\x37\x5d\x3a"), |
| 770 | testVector("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", |
| 771 | "\xd6\xa1\x41\xa7\xec\x3c\x38\xdf\xbd\x61") |
| 772 | }; |
| 773 | |
| 774 | |
| 775 | int times( sizeof(test_arc4) / sizeof(testVector) ); |
| 776 | for (int i = 0; i < times; ++i) { |
| 777 | ARC4::Encryption enc; |
| 778 | ARC4::Decryption dec; |
| 779 | |
| 780 | enc.SetKey((byte*)keys[i], (word32)strlen(keys[i])); |
| 781 | dec.SetKey((byte*)keys[i], (word32)strlen(keys[i])); |
| 782 | |
| 783 | enc.Process(cipher, test_arc4[i].input_, test_arc4[i].outLen_); |
| 784 | dec.Process(plain, cipher, test_arc4[i].outLen_); |
| 785 | |
| 786 | if (memcmp(plain, test_arc4[i].input_, test_arc4[i].outLen_)) |
| 787 | return -30 - i; |
| 788 | |
| 789 | if (memcmp(cipher, test_arc4[i].output_, test_arc4[i].outLen_)) |
| 790 | return -40 - i; |
| 791 | } |
| 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | |
| 797 | int rabbit_test() |
no test coverage detected