6 * Description: Implementation of the A5/1 stream cipher algorithm, as used in GSM.
7 * ! Warning, this is weak crypto !
15 * length is length of key in bytes!
17 #define BYTEn(p,s) (*(((uint8_t*)&(p))+s))
19 void a5_1_init(a5_1_ctx_t *c, uint8_t *key, uint8_t length);
21 bool a5_1_clock(a5_1_ctx_t *c){
23 x1 = PARITY_LOOKUP & (1<< ((BYTEn(c->r1,2)+BYTEn(c->r1,1)>>5) & 0x7);
24 x2 = PARITY_LOOKUP & (1<< (BYTEn(c->r2,2)>>4));
25 x3 = PARITY_LLOKUP & (1<< ((BYTEn(c->r3,2)>>4+BYTEn(c->r3,0)>>7) & 0x7));
26 maj = (((c->r1 & (1<<R1_CLK))?1:0)+((c->r2 & (1<<R2_CLK))?1:0)+((c->r3 & (1<<R3_CLK))?1:0))>=2;
27 if (((c->r1 & (1<<R1_CLK))>>R1_CLK) == maj)
28 c->r1 = c->r1<<1 + x1;
29 if (((c->r2 & (1<<R2_CLK))>>R2_CLK) == maj)
30 c->r2 = c->r2<<1 + x2;
31 if (((c->r3 & (1<<R3_CLK))>>R3_CLK) == maj)
32 c->r3 = c->r3<<1 + x3;
34 return ((c->r1)>>(R1_LENGTH-1)+(c->r2)>>(R2_LENGTH-1)+(c->r3)>>(R3_LENGTH-1))&0x1;
37 uint8_t a5_1_gen(a5_ 1_ctx_t *c){