1 #include "encrypt.h" 2 #include <string.h> 3 #include <stdlib.h> 4 #include <unistd.h> 5 #include <stdio.h> 6 7 #define TEST_LEN 16 8 #define TEST_VAL "This is a test!" 9 10 11 int main(void) { 12 int i,x; 13 unsigned char key[256]; 14 unsigned char *data, *crypted, *decrypt; 15 data=calloc(TEST_LEN, 1); 16 crypted=calloc(TEST_LEN, 1); 17 decrypt=calloc(TEST_LEN, 1); 18 for (i=0;i<=1000;i++) { 19 memcpy(data,TEST_VAL,TEST_LEN); 20 memcpy(key,generatekey(),256); 21 memcpy(crypted,cryptdata(key, data, TEST_LEN), TEST_LEN); 22 memcpy(decrypt,decryptdata(key, crypted, TEST_LEN), TEST_LEN); 23 if (crypted[0]==crypted[1] || crypted[0]==crypted[2] || crypted[0] == crypted[3] || crypted[1]==crypted[2] || crypted[1]==crypted[3] || crypted[2]==crypted[3]) { 24 printf("!!! WARNING !!!\n"); 25 for (x=0;x<256;x++) 26 printf("%2x ",key[x]); 27 printf("\n"); 28 } 29 if ( memcmp(data,decrypt,5) !=0) { 30 printf("!!! ERROR !!!\n%s != %s\n",data, decrypt); 31 } 32 for (x=0;x<TEST_LEN;x++) 33 printf("0x%-2x ",crypted[x]); 34 printf("\n"); 35 free(decrypt); 36 free(crypted); 37 } 38 free(data); 39 free(crypted); 40 free(decrypt); 41 return(0); 42 } |