From: hackbard Date: Sun, 5 Oct 2003 22:32:48 +0000 (+0000) Subject: ecb mode working, still bug in cbc mode. X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=9b5b929c697773fd53f7d82fc33a4a02dab6af7b;p=my-code%2Fcrypto.git ecb mode working, still bug in cbc mode. --- diff --git a/Makefile b/Makefile index ddd24c4..ca582f1 100644 --- a/Makefile +++ b/Makefile @@ -10,3 +10,8 @@ all: $(TARGETS) test: des.o des.o: des.c + +clean: + rm -f *.o test + +remake: clean all diff --git a/des.c b/des.c index 2101a95..a001060 100644 --- a/des.c +++ b/des.c @@ -5,7 +5,6 @@ * */ -#include #include #include "des.h" @@ -111,9 +110,6 @@ int rotate_left(u8 *obj) { for(i=4;i<6;i++) obj[i]=(obj[i]<<1)|(obj[i+1]>>7); obj[6]=obj[6]<<1|((mid&8)>>3); - printf("debug: "); - for(i=0;i<7;i++) printf("%02x ",obj[i]); - printf("\n"); return 1; } @@ -137,8 +133,6 @@ int compute_subkeys(u8 *key0,u8 subkey[DES_SUBKEYS][DES_SUBKEY_LEN/8]) { u8 key0_56[DES_INITIAL_KEY_LEN/8]; /* initial permutation of key */ table_trans(key0,key0_56,key_perm_table,DES_INITIAL_KEY_LEN); - for(i=0;i<7;i++) printf("%02x ",key0_56[i]); - printf("\n"); for(i=0;i #include "des.h" +#define LEN 32 int main() { - u8 plain[32]; - u8 crypted[32]; + u8 plain[LEN]; + u8 crypted[LEN]; + u8 plain_new[LEN]; u8 key[8]; int fd,i; @@ -27,35 +29,52 @@ int main() { printf("des crypt/decrypt test:\n"); printf("- generating simple/random key ...\n"); - // read(fd,key,8); - memset(key,0x90,8); + read(fd,key,8); printf("key: "); for(i=0;i<8;i++) printf("%02x ",key[i]); puts(""); - memset(plain,0,32); - // strcpy(plain,"allyouratmels ... :)"); - printf("encrypting '"); - for(i=0;i<32;i++) printf("%02x%c",plain[i],i==31?'\n':' '); + memset(plain,0,LEN); + strcpy(plain,"allyourbase"); + printf("encrypting '%s' \n",plain); - printf("encrypting (ecb mode) ...\n"); - memset(crypted,0,32); - des_encrypt(plain,crypted,key,32,MODE_ECB); + printf("ecb mode:\n"); + memset(crypted,0,LEN); + des_encrypt(plain,crypted,key,LEN,MODE_ECB); printf("plain: "); - for(i=0;i<32;i++) printf("%02x ",plain[i]); + for(i=0;i