#include #include #include #define LEN 8 char* code_to_msg(int code) { switch (code) { case DESERR_NONE: return "No error"; case DESERR_NOHWDEVICE: return "Encryption succeeded, but done in software"; case DESERR_HWERROR: return "An error occurred in the hardware or driver."; case DESERR_BADPARAM: return "Bad argument to routine."; default: return "Unknown code"; } } int main(void) { char key1[LEN] = "testkey1"; char key2[LEN] = "T3S7k3y2"; char secret1[LEN] = "secret 1"; char secret2[LEN] = "Hello !!"; char secret3[LEN] = "MoreText"; char ivec[LEN] = "01234567"; des_setparity(key1); int ret = ecb_crypt(key1, secret1, LEN, DES_ENCRYPT); printf("ecb_crypt result: %s | key: %.*s, encrypted buf: %.*s\n", code_to_msg(ret), LEN, key1, LEN, secret1); ret = ecb_crypt(key1, secret1, LEN, DES_DECRYPT); printf("ecb_crypt result: %s | key: %.*s, decrypted buf: %.*s\n", code_to_msg(ret), LEN, key1, LEN, secret1); ret = ecb_crypt(key2, secret2, LEN, DES_ENCRYPT); printf("ecb_crypt (without des_setparity) result: %s | " "key: %.*s, encrypted buf: %.*s\n", code_to_msg(ret), LEN, key2, LEN, secret2); ret = cbc_crypt(key1, secret3, LEN, DES_ENCRYPT, ivec); printf ("cbc_crypt resutl %s | key: %.*s, encrypted buf: %.*s\n", code_to_msg(ret), LEN, key1, LEN, secret3); printf ("ivec: %.*s\n", LEN, ivec); return 0; } /* output restricted@prison1:/usr/home/restricted/projects/ecb_crypt % uname -rps FreeBSD 10.1-STABLE amd64 restricted@prison1:/usr/home/restricted/projects/ecb_crypt % cc poc.c -o poc restricted@prison1:/usr/home/restricted/projects/ecb_crypt % ./poc ecb_crypt result: Encryption succeeded, but done in software | key: udsukdy1, encrypted buf: secret 1 ecb_crypt result: Encryption succeeded, but done in software | key: udsukdy1, decrypted buf: secret 1 ecb_crypt (without des_setparity) result: Encryption succeeded, but done in s oftware | key: T3S7k3y2, encrypted buf: Hello !! cbc_crypt resutl Encryption succeeded, but done in software | key: udsukdy1, encrypted buf: MoreText */