]>
git.zerfleddert.de Git - proxmark3-svn/blob - common/legic_prng.c
1 //-----------------------------------------------------------------------------
2 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
3 // at your option, any later version. See the LICENSE.txt file for the text of
5 //-----------------------------------------------------------------------------
6 // LEFIC's obfuscation function
7 //-----------------------------------------------------------------------------
9 #include "legic_prng.h"
16 void legic_prng_init(uint8_t init
) {
18 if(init
== 0) /* hack to get a always 0 keystream */
21 lfsr
.b
= (init
<< 1) | 1;
24 void legic_prng_forward(int count
) {
28 tmp
^= (lfsr
.a
& 0x40) >> 6;
34 tmp
^= (lfsr
.b
& 4) >> 2;
36 tmp
^= (lfsr
.b
& 8) >> 3;
38 tmp
^= (lfsr
.b
& 0x80) >> 7;
45 uint8_t legic_prng_get_bit() {
46 uint8_t idx
= 7-((lfsr
.a
& 4) | ((lfsr
.a
& 8) >> 2) | ((lfsr
.a
& 0x10) >> 4));
47 return ((lfsr
.b
>> idx
) & 1);