From d32e0f70032fdc8d2f0d5a668556ba7f5cf4d26d Mon Sep 17 00:00:00 2001 From: hackbard Date: Sun, 28 Sep 2003 02:19:12 +0000 Subject: [PATCH] started crypto api - des cipher start --- README | 10 ++++++++ des.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ des.h | 20 +++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 README create mode 100644 des.c create mode 100644 des.h diff --git a/README b/README new file mode 100644 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 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