more testing
[my-code/crypto.git] / test.c
diff --git a/test.c b/test.c
new file mode 100644 (file)
index 0000000..a2e7067
--- /dev/null
+++ b/test.c
@@ -0,0 +1,60 @@
+/*
+ * test.c - test ciphers ...
+ *
+ * hackbard@hackdaworld.dyndns.org
+ *
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "des.h"
+
+
+int main() {
+ u8 plain[64];
+ u8 crypted[64];
+ u8 key[8];
+ int fd,i;
+
+ if((fd=open("/dev/urandom",O_RDONLY))<0) {
+  puts("open urandom device failed!");
+  return fd;
+ }
+
+ printf("des crypt/decrypt test:\n");
+ printf("- geberating random key ...\n");
+ read(fd,key,8);
+ printf("key: ");
+ for(i=0;i<8;i++) printf("%02x ",key[i]);
+ puts("");
+
+ memset(plain,0,64);
+ strcpy(plain,"allyouratmels ... :)");
+ printf("encrypting '%s' (ecb mode) ...\n",plain);
+ memset(crypted,0,64);
+ des_encrypt(plain,crypted,key,64,MODE_ECB);
+ printf("crypted: ");
+ for(i=0;i<64;i++) printf("%c",crypted[i]);
+ puts("");
+ printf("encrypting '%s' (cbc mode) ...\n",plain);
+ memset(crypted,0,64);
+ des_encrypt(plain,crypted,key,64,MODE_CBC);
+ printf("crypted: ");
+ for(i=0;i<64;i++) printf("%c",crypted[i]);
+ puts("");
+
+ printf("--\n");
+ printf("verify:\n");
+ des_decrypt(crypted,plain,key,64,MODE_CBC);
+ printf("plain text: ");
+ for(i=0;i<64;i++) printf("%c",plain[i]);
+ puts("");
+
+ puts("done :)");
+
+ return 1;
+}