From: hackbard Date: Thu, 2 Oct 2003 02:17:56 +0000 (+0000) Subject: begin to add main crypt work (CBC,ECB) X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec19aa63a4642abfa6eb237c23ce7f9fbd710ac4;p=my-code%2Fcrypto.git begin to add main crypt work (CBC,ECB) --- diff --git a/des.c b/des.c index 4c0a358..d71317d 100644 --- a/des.c +++ b/des.c @@ -77,7 +77,14 @@ u8 sbox[DES_SBOXES][DES_SBOX_LEN]={ u8 pbox[DES_PBOX_LEN]={ 16,7,20,21,29,12,28,17,1,15,23,26,5,18,31,10, 2,8,24,14,32,27,3,9,19,13,30,6,22,11,4,25 -}; +}; + +u8 data_final_perm_table[DES_DATA_BLOCK_LEN]={ + 40,8,48,16,56,24,64,32,39,7,47,15,55,23,63,31, + 38,6,46,14,54,22,62,30,37,5,45,13,53,21,61,29, + 36,4,44,12,52,20,60,28,35,3,43,11,51,19,59,27, + 34,2,42,10,50,18,58,26,33,1,41,9,49,17,57,25 +}; int rotate_right(u8 *obj,int len) { u8 tmp=obj[len-1]; @@ -141,7 +148,7 @@ int data_perm(u8 *plain,u8 *pd) { int data_expansion_perm(u8 *right,u8 expanded) { int i; - memset(expanded,0,DES_SUBKEY_LEN); + memset(expanded,0,DES_SUBKEY_LEN/8); for(i=0;i>((8-data_expansion_table[i]%8)&7))&1)<<(7-i%8)); return 1; @@ -153,38 +160,62 @@ int get_sbox_value(u8 *data,int offset,int len,int box) { return(sbox[box][(tmp&1|(tmp&(1<<(len-1))<<1))*16+(tmp&((1<<(len-1))-1)>>1)]); } +int data_pbox_perm(u8 *s,u8 *p) { + int i; + for(i=0;i>((8-pbox[i]%8)&7))&1)<<(7-i%8)); + return 1; +} + int data_s_and_p(u8 *data) { - u8 s[DES_DATA_BLOCK_LEN/2]; - u8 p[DES_DATA_BLOCK_LEN/2]; + u8 s[DES_DATA_BLOCK_LEN/(8*2)]; + u8 p[DES_DATA_BLOCK_LEN/(8*2)]; int i,j; for(i=0;i>((8-data_final_perm_table[i]%8)&7))&1)<<(7-i%8)); + return 1; +} + int progress_data(u8 *data,u8 **subkey,u8 mode) { int i,j; - u8 pd[DES_DATA_BLOCK_LEN]; + u8 pd[DES_DATA_BLOCK_LEN/8]; u8 left[DES_DATA_BLOCK_LEN/(2*8)]; u8 right[DES_DATA_BLOCK_LEN/(2*8)]; - u8 expanded[DES_SUBKEY_LEN]; + u8 tmp[DES_DATA_BLOCK_LEN/(2*8)]; + u8 expanded[DES_SUBKEY_LEN/8]; data_perm(data,pd); memcpy(left,pd,DES_DATA_BLOCK_LEN/(2*8)); memcpy(right,pd+DES_DATA_BLOCK_LEN/(2*8),DES_DATA_BLOCK_LEN/(2*8)); for(i=0;i