35b75a89c321593a171eca65cb2c649bd4e93dc3
[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 #include <unistd.h>
13 #include <string.h>
14 #include "des.h"
15
16
17 int main() {
18  u8 plain[32];
19  u8 crypted[32];
20  u8 key[8];
21  int fd,i;
22
23  if((fd=open("/dev/urandom",O_RDONLY))<0) {
24   puts("open urandom device failed!");
25   return fd;
26  }
27
28  printf("des crypt/decrypt test:\n");
29  printf("- generating simple/random key ...\n");
30  // read(fd,key,8);
31  memset(key,0x90,8);
32  printf("key: ");
33  for(i=0;i<8;i++) printf("%02x ",key[i]);
34  puts("");
35
36  memset(plain,0,32);
37  // strcpy(plain,"allyouratmels ... :)");
38  printf("encrypting '");
39  for(i=0;i<32;i++) printf("%02x%c",plain[i],i==31?'\n':' ');
40  
41  printf("encrypting (ecb mode) ...\n");
42  memset(crypted,0,32);
43  des_encrypt(plain,crypted,key,32,MODE_ECB);
44  printf("plain: ");
45  for(i=0;i<32;i++) printf("%02x ",plain[i]);
46  puts("");
47  printf("crypted: ");
48  for(i=0;i<32;i++) printf("%02x ",crypted[i]);
49  puts("");
50  printf("decrypting (ecb mode) ...\n");
51  memset(plain,0,32);
52  des_decrypt(crypted,plain,key,32,MODE_ECB);
53  printf("crypted: ");
54  for(i=0;i<32;i++) printf("%02x ",crypted[i]);
55  puts("");
56  printf("plain: ");
57  for(i=0;i<32;i++) printf("%02x ",plain[i]);
58  puts("");
59  
60  close(fd);
61
62  puts("done :)");
63
64  return 1;
65 }