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

411418 41 rj anderson faster attack on certain stream

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: i]; B = B ^ c–>xk[i]; } /* Expand key into xk. */ if(pk_len>xk_len) num_steps = 3*pk_len;else num_steps = 3*xk_len; A = B = 0; for(i=0;i<num_steps;i++){ A = c–>xk[i%xk_len] = ROTL32(c–>xk[i%xk_len] + A + B,3); rc = (A+B) & 31; B = pk[i%pk_len] = ROTL32(pk[i%pk_len] + A + B,rc); } /* Clobber sensitive data before deallocating memory. */ for(i=0;i<pk_len;i++) pk[i] =0; free(pk); } void main(void){ rc5_ctx c; u4 data[8]; char key = “ABCDE”; int i; printf(“–––––––––––––––––––––––––––––––––––––––––––––––––\n”); for(i=0;i<8;i++) data[i] = i; rc5_init(&ampc,10); /* 10 rounds */ rc5_key(&ampc,key,5); rc5_encrypt(&ampc,data,4); printf(“Encryptions:\n”); for(i=0;i<8;i+=2) printf(“Block %01d = %08lx %08lx\n”, i/2,data[i],data[i+1]); rc5_decrypt(&ampc,data,2); rc5_decrypt(&ampc,data+4,2); printf(“Decryptions:\n”); for(i=0;i<8;i+=2) printf(“Block %01d = %08lx %08lx\n”, i/2,data[i],data[i+1]); } A5 typedef struct { unsigned long r1,r2,r3; } a5_ctx; static int threshold(r1, r2, r3) unsigned int r1; unsigned int r2; unsigned int r3; { int total; total = (((r1 >> 9) & 0x1) == 1) + (((r2 >> 11) & 0x1) == 1) + (((r3 >> 11) & 0x1) == 1); if (total > 1) return (0); else return (1); } unsigned long clock_r1(ctl, r1) int ctl; unsigned long r1; { unsigned long feedback; ctl ^= ((r1 >> 9) & 0x1); if (ctl) { feedback = (r1 >> 18) ^ (r1 >> 17) ^ (r1 >> 16) ^ (r1 >> 13); r1 = (r1 << 1) & 0x7ffff; if (feedback & 0×01) r1 ^= 0×01; } return (r1); } unsigned long clock_r2(ctl, r2) int ctl; unsigned long r2; { unsigned long feedback; ctl ^= ((r2 >> 11) & 0x1); if (ctl) { feedback = (r2 >> 21) ^ (r2 >> 20) ^ (r2 >> 16) ^ (r2 >> 12); r2 = (r2 << 1) & 0x3fffff; if (feedback & 0×01) r2 ^= 0×01; } return (r2); } unsigned long clock_r3(ctl, r3) int ctl; unsigned long r3; { unsigned long feedback; ctl ^= ((r3 >> 11) &...
View Full Document

Ask a homework question - tutors are online