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

0x5ad6b472 0xe8d3c48d 0xf7960e44 0xc3eb9e15 0xf59c66fb

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: ; n1 ^= f(c,n2+c–>k[5]); n2 ^= f(c,n1+c–>k[6]); n1 ^= f(c,n2+c–>k[7]); n2 n2 n2 n2 n2 n2 n2 n2 n2 n2 n2 n2 ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= f(c,n1+c–>k[0]); f(c,n1+c–>k[2]); f(c,n1+c–>k[4]); f(c,n1+c–>k[6]); f(c,n1+c–>k[0]); f(c,n1+c–>k[2]); f(c,n1+c–>k[4]); f(c,n1+c–>k[6]); f(c,n1+c–>k[7]); f(c,n1+c–>k[5]); f(c,n1+c–>k[3]); f(c,n1+c–>k[1]); n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= f(c,n2+c–>k[1]); f(c,n2+c–>k[3]); f(c,n2+c–>k[5]); f(c,n2+c–>k[7]); f(c,n2+c–>k[1]); f(c,n2+c–>k[3]); f(c,n2+c–>k[5]); f(c,n2+c–>k[7]); f(c,n2+c–>k[6]); f(c,n2+c–>k[4]); f(c,n2+c–>k[2]); f(c,n2+c–>k[0]); d[0] = n2; d[1] = n1; } void gostdecrypt(gost_ctx *c, u4 *d){ register word32 n1, n2; /* As named in the GOST */ n1 = d[0]; n2 = d[1]; n2 n2 n2 n2 n2 n2 n2 n2 n2 n2 n2 n2 n2 n2 n2 n2 ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= f(c,n1+c–>k[0]); f(c,n1+c–>k[2]); f(c,n1+c–>k[4]); f(c,n1+c–>k[6]); f(c,n1+c–>k[7]); f(c,n1+c–>k[5]); f(c,n1+c–>k[3]); f(c,n1+c–>k[1]); f(c,n1+c–>k[7]); f(c,n1+c–>k[5]); f(c,n1+c–>k[3]); f(c,n1+c–>k[1]); f(c,n1+c–>k[7]); f(c,n1+c–>k[5]); f(c,n1+c–>k[3]); f(c,n1+c–>k[1]); n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= ^= f(c,n2+c–>k[1]); f(c,n2+c–>k[3]); f(c,n2+c–>k[5]); f(c,n2+c–>k[7]); f(c,n2+c–>k[6]); f(c,n2+c–>k[4]); f(c,n2+c–>k[2]); f(c,n2+c–>k[0]); f(c,n2+c–>k[6]); f(c,n2+c–>k[4]); f(c,n2+c–>k[2]); f(c,n2+c–>k[0]); f(c,n2+c–>k[6]); f(c,n2+c–>k[4]); f(c,n2+c–>k[2]); f(c,n2+c–>k[0]); d[0] = n2; d[1] = n1; } void gost_enc(gost_ctx *c, u4 *d, int blocks){ int i; for(i=0;i<blocks;i++){ gostcrypt(c,d); d+=2; } } void gost_dec(gost_ctx *c, u4 *d, int blocks){ int i; for(i=0;i<blocks;i++){ gostdecrypt(c,d); d+=2; } } void gost_key(gost_ctx *c, u4 *k){ int i; for(i=0;i<8;i++) c–>k[i]=k[i]; } void gost_init(gost_ctx *c){ kboxinit(c); } void gost_destroy(gost_ctx *c){ int i; for(i=0;i<8;i++) c–>k[i]=0; } void main(void){ gost_ctx gc; u4 k[8],data[10]; int i; /* Initialize GOST context. */ gost_init(&ampgc); /* Prepare key––a simple key should be OK, with this many rounds! */ for(i=0;i<8;i++) k[i] = i; gost_key(&ampgc,k); /* Try some test vectors. */ da...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online