more testing
[my-code/crypto.git] / test.c
1 /*
2  * test.c - test ciphers ...
3  *
4  * hackbard@hackdaworld.dyndns.org
5  *
6  */
7
8 #include <stdio.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <fcntl.h>
12
13 #include "des.h"
14
15
16 int main() {
17  u8 plain[64];
18  u8 crypted[64];
19  u8 key[8];
20  int fd,i;
21
22  if((fd=open("/dev/urandom",O_RDONLY))<0) {
23   puts("open urandom device failed!");
24   return fd;
25  }
26
27  printf("des crypt/decrypt test:\n");
28  printf("- geberating random key ...\n");
29  read(fd,key,8);
30  printf("key: ");
31  for(i=0;i<8;i++) printf("%02x ",key[i]);
32  puts("");
33
34  memset(plain,0,64);
35  strcpy(plain,"allyouratmels ... :)");
36  
37  printf("encrypting '%s' (ecb mode) ...\n",plain);
38  memset(crypted,0,64);
39  des_encrypt(plain,crypted,key,64,MODE_ECB);
40  printf("crypted: ");
41  for(i=0;i<64;i++) printf("%c",crypted[i]);
42  puts("");
43  printf("encrypting '%s' (cbc mode) ...\n",plain);
44  memset(crypted,0,64);
45  des_encrypt(plain,crypted,key,64,MODE_CBC);
46  printf("crypted: ");
47  for(i=0;i<64;i++) printf("%c",crypted[i]);
48  puts("");
49
50  printf("--\n");
51  printf("verify:\n");
52  des_decrypt(crypted,plain,key,64,MODE_CBC);
53  printf("plain text: ");
54  for(i=0;i<64;i++) printf("%c",plain[i]);
55  puts("");
56
57  puts("done :)");
58
59  return 1;
60 }