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

N references 1 aba bank card standard management and

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: tes the round constants */ int i ; for(i=0 ; i<=NMBR ; i++ ) { rtab[i] = strt ; strt <<= 1 ; if( strt&amp0x10000 ) strt ^= 0x11011 ; } } /* Modified slightly to fit the caller’s needs. */ void encrypt(twy_ctx *c, word32 *a) { char i ; for( i=0 ; i<NMBR ; i++ ) { a[0] ^= c–>k[0] ^ (c–>ercon[i]<<16) ; a[1] ^= c–>k[1] ; a[2] ^= c–>k[2] ^ c–>ercon[i] ; rho(a) ; } a[0] ^= c–>k[0] ^ (c–>ercon[NMBR]<<16) ; a[1] ^= c–>k[1] ; a[2] ^= c–>k[2] ^ c–>ercon[NMBR] ; theta(a) ; } /* Modified slightly to meet caller’s needs. */ void decrypt(twy_ctx *c, word32 *a) { char i ; mu(a) ; for( i=0 ; i<NMBR ; i++ ) { a[0] ^= c–>ki[0] ^ (c–>drcon[i]<<16) ; a[1] ^= c–>ki[1] ; a[2] ^= c–>ki[2] ^ c–>drcon[i] ; rho(a) ; } a[0] ^= c–>ki[0] ^ (c–>drcon[NMBR]<<16) ; a[1] ^= c–>ki[1] ; a[2] ^= c–>ki[2] ^ c–>drcon[NMBR] ; theta(a) ; mu(a) ; } void twy_key(twy_ctx *c, u4 *key){ c–>ki[0] = c–>k[0] = key[0]; c–>ki[1] = c–>k[1] = key[1]; c–>ki[2] = c–>k[2] = key[2]; theta(c–>ki); mu(c–>ki); rndcon_gen(STRT_E,c–>ercon); rndcon_gen(STRT_D,c–>drcon); } /* Encrypt in ECB mode. */ void twy_enc(twy_ctx *c, u4 *data, int blkcnt){ u4 *d; int i; d = data; for(i=0;i<blkcnt;i++) { encrypt(c,d); d +=3; } } /* Decrypt in ECB mode. */ void twy_dec(twy_ctx *c, u4 *data, int blkcnt){ u4 *d; int i; d = data; for(i=0;i<blkcnt;i++){ decrypt(c,d); d+=3; } } /* Scrub sensitive values from memory before deallocating. */ void twy_destroy(twy_ctx *c){ int i; for(i=0;i<3;i++) c–>k[i] = c–>ki[i] = 0; } void printvec(char *chrs, word32 *d){ printf(“%20s : %08lx %08lx %08lx \n”,chrs,d[2],d[1],d[0]); } main() { twy_ctx gc; word32 a[9],k[3]; int i; /* Test vector 1. */ k[0]=k[1]=k[2]=0; a[0]=a[1]=a[2]=1; twy_key(&ampgc,k); printf(“**********\n”); printvec(“KEY = ”,k); printvec(“PLAIN = ”,a); encrypt(&ampgc,a); printvec(“CIPHER = ”,a); /* Test vector 2. */ k[0]=6;k[1]=5;k[2]=4; a[0]=3;a[1]=2;a[2]=1; twy_key(&ampgc,k); printf(“**********\n”); printv...
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