Chameleon-Mini
Crypto1.h
1 #ifndef CRYPTO1_H
2 #define CRYPTO1_H
3 
4 #include <stdint.h>
5 #include <stdbool.h>
6 
7 /* Gets the current keystream-bit, without shifting the internal LFSR */
8 uint8_t Crypto1FilterOutput(void);
9 
10 /* Set up Crypto1 cipher using the given Key, Uid and CardNonce. Also encrypts
11  * the CardNonce in-place while in non-linear mode. */
12 void Crypto1Setup(uint8_t Key[6], uint8_t Uid[4], uint8_t CardNonce[4]);
13 
14 /* Set up Crypto1 cipher using the given Key, Uid and CardNonce. Nested indicates
15  * whether the CardNonce is encrypted (true) or not (false).
16  * If the CardNonce is encrypted, it will we decrypted in-place. If not, it will
17  * be fed into the LFSR, but remains unchanged. */
18 void Crypto1SetupReader(uint8_t Key[6], uint8_t Uid[4], uint8_t CardNonce[4], bool Nested);
19 
20 /* Load the decrypted ReaderNonce into the Crypto1 state LFSR */
21 void Crypto1Auth(uint8_t EncryptedReaderNonce[4]);
22 
23 /* Generate 8 Bits of key stream */
24 uint8_t Crypto1Byte(void);
25 
26 /* Generate 4 Bits of key stream */
27 uint8_t Crypto1Nibble(void);
28 
29 /* Execute 'ClockCount' cycles on the PRNG state 'State' */
30 void Crypto1PRNG(uint8_t State[4], uint16_t ClockCount);
31 
32 /* Encrypts buffer with consideration of parity bits */
33 void Crypto1EncryptWithParity(uint8_t * Buffer, uint16_t BitCount);
34 
35 /* Encrypts buffer with LFSR feedback within reader nonce and considers parity bits */
36 void Crypto1ReaderAuthWithParity(uint8_t PlainReaderAnswerWithParityBits[9]);
37 
38 #endif //CRYPTO1_H