| 903 | |
| 904 | |
| 905 | int des_test() |
| 906 | { |
| 907 | //ECB mode |
| 908 | DES_ECB_Encryption enc; |
| 909 | DES_ECB_Decryption dec; |
| 910 | |
| 911 | const int sz = TaoCrypt::DES_BLOCK_SIZE * 3; |
| 912 | const byte key[] = { 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef }; |
| 913 | const byte iv[] = { 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef }; |
| 914 | |
| 915 | enc.SetKey(key, sizeof(key)); |
| 916 | enc.Process(cipher, msg, sz); |
| 917 | dec.SetKey(key, sizeof(key)); |
| 918 | dec.Process(plain, cipher, sz); |
| 919 | |
| 920 | if (memcmp(plain, msg, sz)) |
| 921 | return -50; |
| 922 | |
| 923 | const byte verify1[] = |
| 924 | { |
| 925 | 0xf9,0x99,0xb8,0x8e,0xaf,0xea,0x71,0x53, |
| 926 | 0x6a,0x27,0x17,0x87,0xab,0x88,0x83,0xf9, |
| 927 | 0x89,0x3d,0x51,0xec,0x4b,0x56,0x3b,0x53 |
| 928 | }; |
| 929 | |
| 930 | if (memcmp(cipher, verify1, sz)) |
| 931 | return -51; |
| 932 | |
| 933 | // CBC mode |
| 934 | DES_CBC_Encryption enc2; |
| 935 | DES_CBC_Decryption dec2; |
| 936 | |
| 937 | enc2.SetKey(key, sizeof(key), iv); |
| 938 | enc2.Process(cipher, msg, sz); |
| 939 | dec2.SetKey(key, sizeof(key), iv); |
| 940 | dec2.Process(plain, cipher, sz); |
| 941 | |
| 942 | if (memcmp(plain, msg, sz)) |
| 943 | return -52; |
| 944 | |
| 945 | const byte verify2[] = |
| 946 | { |
| 947 | 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8, |
| 948 | 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73, |
| 949 | 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b |
| 950 | }; |
| 951 | |
| 952 | if (memcmp(cipher, verify2, sz)) |
| 953 | return -53; |
| 954 | |
| 955 | // EDE3 CBC mode |
| 956 | DES_EDE3_CBC_Encryption enc3; |
| 957 | DES_EDE3_CBC_Decryption dec3; |
| 958 | |
| 959 | const byte key3[] = |
| 960 | { |
| 961 | 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, |
| 962 | 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10, |
no test coverage detected