]> hackdaworld.org Git - my-code/crypto.git/commitdiff
started crypto api - des cipher start
authorhackbard <hackbard>
Sun, 28 Sep 2003 02:19:12 +0000 (02:19 +0000)
committerhackbard <hackbard>
Sun, 28 Sep 2003 02:19:12 +0000 (02:19 +0000)
README [new file with mode: 0644]
des.c [new file with mode: 0644]
des.h [new file with mode: 0644]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..f8063ff
--- /dev/null
+++ b/README
@@ -0,0 +1,10 @@
+crypto
+------
+
+some crypto algorithms:
+
+- des
+- rsa
+
+author: hackbard@hackdaworld.dyndns.org
+
diff --git a/des.c b/des.c
new file mode 100644 (file)
index 0000000..a1cdbba
--- /dev/null
+++ b/des.c
@@ -0,0 +1,77 @@
+/*
+ * des.c - data encryption standard algo
+ *
+ * author: hackbard@hackdaworld.dyndns.org
+ *
+ */
+
+#include "des.h"
+
+u8 key_perm_table[DES_SUBKEY_LEN]={
+ 57,49,41,33,25,17,9,1,58,50,42,34,26,18,
+ 10,2,59,51,43,35,27,18,11,3,60,52,44,36,
+ 63,55,47,39,31,23,15,7,62,54,46,38,30,22,
+ 14,6,61,53,45,37,29,21,13,5,28,20,12,4
+};
+
+u8 rot_per_round_table[DES_ROUNDS]={
+ 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1
+};
+
+u8 subkey_perm_table[DES_PERMC_LEN]={
+ 14,17,11,24,1,5,3,28,15,6,21,10,
+ 23,19,12,4,26,8,16,7,27,20,13,2,
+ 41,52,31,37,47,55,30,40,51,45,33,48,
+ 44,49,39,56,34,53,46,42,50,36,29,32
+};
+
+int rotate_right(u8 *obj,int len) {
+ u8 tmp=obj[len-1];
+ while(--len) obj[len]=obj[len-1];
+ obj[0]=tmp;
+ return 1;
+}
+
+int rotate_left(u8 *obj,int len) {
+ int i=0;
+ u8 tmp=obj[0];
+ while(len-(i++)) obj[i-1]=obj[i];
+ obj[len-1]=tmp;
+ return 1;
+}
+
+key_perm(u8 *key) {
+ int i;
+ u8 *new[DES_SUBKEY_LEN];
+ for(i=0;i<DES_SUBKEY_LEN;i++)
+  new[i]=key[key_perm_table[i]];
+ memcpy(key,new,DES_SUBKEY_LEN);
+ return 1;
+}
+
+int subkey_trans(u8 *key,int round) {
+ int i;
+ for(i=0;i<rot_per_round_table[round];i++) {
+  rotate_left(key,DES_SUBKEY_LEN/2);
+  rotate_left(key+DES_SUBKEY_LEN/2,DES_SUBKEY_LEN/2);
+ }
+ return 1;
+}
+
+int des_crypt(u8 *plain,u8 *crypted,u8 *key) {
+ int round;
+
+ key_perm(key);
+ for(round=0;round<DES_ROUND;round++) {
+  subkey_trans(key,round);
+  // fuckup_data(key,round);
+ }
+
+ return 1;
+}
+
+int des_decrypt(u8 *crypted,u8 *plain,u8 *key) {
+
+
+ return 1;
+}
diff --git a/des.h b/des.h
new file mode 100644 (file)
index 0000000..ed1750c
--- /dev/null
+++ b/des.h
@@ -0,0 +1,20 @@
+/*
+ * des.h - data encryption standard header file
+ *
+ * author: hackbard@hackdaworld.dyndns.org
+ *
+ */
+
+#ifndef DES_H
+#define DES_H
+
+#define DES_ROUNDS 16
+#define DES_SUBKEY_LEN 56
+#define DES_PERMC_LEN 48
+
+typedef unsigned char u8;
+
+int des_encrypt(u8 *plain,u8 *crypted,u8 *key);
+int des_decrypt(u8 *crypted,u8 *plain,u8 *key);
+
+#endif /* DES_H */