applied cryptography - protocols, algorithms, and source code in c

e wi 0xca62c1d6 e d d c c rot2b b a a

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for (j = 0; j < 256; j += 2) { Blowfish_encipher(c,&ampdatal, &ampdatar); c–>S[i][j] = datal; c–>S[i][j + 1] = datar; } } } void blf_key(blf_ctx *c, char *k, int len){ InitializeBlowfish(c,k,len); } void blf_enc(blf_ctx *c, unsigned long *data, int blocks){ unsigned long *d; int i; d = data; for(i=0;i<blocks;i++){ Blowfish_encipher(c,d,d+1); d += 2; } } void blf_dec(blf_ctx *c, unsigned long *data, int blocks){ unsigned long *d; int i; d = data; for(i=0;i<blocks;i++){ Blowfish_decipher(c,d,d+1); d += 2; } } void main(void){ blf_ctx c; char key=“AAAAA”; unsigned long data[10]; int i; for(i=0;i<10;i++) data[i] = i; blf_key(&ampc,key,5); blf_enc(&ampc,data,5); blf_dec(&ampc,data,1); blf_dec(&ampc,data+2,4); for(i=0;i<10;i+=2) printf(“Block %01d decrypts to: %08lx %08lx.\n”, i/2,data[i],data[i+1]); } 3–Way #define #define #define typedef STRT_E STRT_D NMBR 0×0b0b /* round constant of first encryption round */ 0xb1b1 /* round constant of first decryption round */ 11 /* number of rounds is 11 */ unsigned long int word32 ; /* the program only works correctly if long = 32bits */ typedef unsigned long u4; typedef unsigned char u1; typedef struct { u4 k[3],ki[3], ercon[NMBR+1],drcon[NMBR+1]; } twy_ctx; /* Note: encrypt and decrypt expect full blocks––padding blocks is caller’s responsibility. All bulk encryption is done in ECB mode by these calls. Other modes may be added easily enough. */ /* destroy: Context. */ /* Scrub context of all sensitive data. */ void twy_destroy(twy_ctx *); /* encrypt: Context, ptr to data block, # of blocks. */ void twy_enc(twy_ctx *, u4 *, int); /* decrypt: Context, ptr to data block, # of blocks. */ void twy_dec(twy_ctx *, u4 *, int); /* key: Context, ptr to key data. */ void twy_key(twy_ctx *, u4 *); /* ACCODE––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– */ /* End of AC code pr...
View Full Document

This note was uploaded on 10/18/2010 for the course MATH CS 301 taught by Professor Aliulger during the Fall '10 term at Koç University.

Ask a homework question - tutors are online