int main (int argc, char *argv []) { int index = 0; byte key [8], value [8], result [8], tst_buf [8]; while (test_value [index][0] != '\0') { convert_string (key , test_value[index++]); convert_string (value , test_value[index++]); convert_string (result, test_value[index++]); memcpy (tst_buf, value, 8); if (crypt_encode ((byte *)tst_buf, 8, CRYPT_DES, (byte *) key)) { if (memcmp (tst_buf, result, 8) != 0) printf ("Error : line %d -> bad result\n",index/3); else putchar ('.'); } else printf ("\nEncrypt return FALSE\n"); } return (EXIT_SUCCESS); }
clock_t test_crypt (FILE *file, int crypt_type) { static char str_crypt_type [10], read_buffer [32000+1], test_buffer [32000+1]; word read_length; long nb_block; clock_t clk_begin, clk_end; char key [] = "SomeLongText That Can Be Used As A Key"; switch (crypt_type) { case CRYPT_IDEA: strcpy (str_crypt_type, "IDEA"); break; case CRYPT_MDC : strcpy (str_crypt_type, "MDC" ); break; case CRYPT_XOR : strcpy (str_crypt_type, "XOR" ); break; case CRYPT_DES : strcpy (str_crypt_type, "DES" ); break; } memset (read_buffer, 0, sizeof (read_buffer)); memset (test_buffer, 0, sizeof (test_buffer)); fseek (file, 0, SEEK_SET); clk_begin = clock (); while ((read_length = fread (read_buffer, 1, 32000, file)) != 0) { nb_block = (long)(read_length / 32); if (nb_block * 32 != (long)read_length) read_length = (size_t)(nb_block * 32); memcpy (test_buffer, read_buffer, 32000); if (crypt_encode ((byte *) test_buffer, read_length, crypt_type, (byte *) key)) { if (crypt_decode ((byte *)test_buffer, read_length, crypt_type, (byte *)key)) { if (memcmp (read_buffer, test_buffer, read_length) != 0) printf ("Error: On %s ,the return is bad\n", str_crypt_type); } else printf ("Error: crypt_decode failed on %s\n", str_crypt_type); } else printf ("Error: crypt_encode failed on %s\n", str_crypt_type); } clk_end = clock(); return ((clock_t)(clk_end - clk_begin)); }
int main() { void *aesctx; char *s = "hello,world!"; char *r,*t; int len; aesctx = crypt_init(CRYPT_PWD_FILE,CRYPT_PWD_LEN16); if(!aesctx) { printf("call crypt_init() error.\n"); return 1; } r = crypt_encode(aesctx,s,strlen(s),&len); t = crypt_decode(aesctx,r,len,&len); printf("%s\n",t); xfree(r); xfree(t); crypt_free(aesctx); return 0; }