]> git.zerfleddert.de Git - proxmark3-svn/blob - common/legic_prng.c
alphabet ;)
[proxmark3-svn] / common / legic_prng.c
1 #include "legic_prng.h"
2 /* legic's obfuscation function */
3
4 struct lfsr {
5 uint8_t a;
6 uint8_t b;
7 } lfsr;
8
9 void legic_prng_init(uint8_t init) {
10 lfsr.a = init;
11 if(init == 0) /* hack to get a always 0 keystream */
12 lfsr.b = 0;
13 else
14 lfsr.b = (init << 1) | 1;
15 }
16
17 void legic_prng_forward(int count) {
18 uint8_t tmp;
19 while(count--) {
20 tmp = lfsr.a & 1;
21 tmp ^= (lfsr.a & 0x40) >> 6;
22
23 lfsr.a >>= 1;
24 lfsr.a |= tmp << 6;
25
26 tmp = lfsr.b & 1;
27 tmp ^= (lfsr.b & 4) >> 2;
28 tmp = ~tmp;
29 tmp ^= (lfsr.b & 8) >> 3;
30 tmp = ~tmp;
31 tmp ^= (lfsr.b & 0x80) >> 7;
32
33 lfsr.b >>= 1;
34 lfsr.b |= tmp << 7;
35 }
36 }
37
38 uint8_t legic_prng_get_bit() {
39 uint8_t idx = 7-((lfsr.a & 4) | ((lfsr.a & 8) >> 2) | ((lfsr.a & 0x10) >> 4));
40 return ((lfsr.b >> idx) & 1);
41 }
Impressum, Datenschutz