Chameleon-Mini
 All Classes Files Functions Variables Macros Pages
Crypto1.h
1 /* Copyright 2013 Timo Kasper, Simon Küppers, David Oswald ("ORIGINAL
2  * AUTHORS"). All rights reserved.
3  *
4  * DEFINITIONS:
5  *
6  * "WORK": The material covered by this license includes the schematic
7  * diagrams, designs, circuit or circuit board layouts, mechanical
8  * drawings, documentation (in electronic or printed form), source code,
9  * binary software, data files, assembled devices, and any additional
10  * material provided by the ORIGINAL AUTHORS in the ChameleonMini project
11  * (https://github.com/skuep/ChameleonMini).
12  *
13  * LICENSE TERMS:
14  *
15  * Redistributions and use of this WORK, with or without modification, or
16  * of substantial portions of this WORK are permitted provided that the
17  * following conditions are met:
18  *
19  * Redistributions and use of this WORK, with or without modification, or
20  * of substantial portions of this WORK must include the above copyright
21  * notice, this list of conditions, the below disclaimer, and the following
22  * attribution:
23  *
24  * "Based on ChameleonMini an open-source RFID emulator:
25  * https://github.com/skuep/ChameleonMini"
26  *
27  * The attribution must be clearly visible to a user, for example, by being
28  * printed on the circuit board and an enclosure, and by being displayed by
29  * software (both in binary and source code form).
30  *
31  * At any time, the majority of the ORIGINAL AUTHORS may decide to give
32  * written permission to an entity to use or redistribute the WORK (with or
33  * without modification) WITHOUT having to include the above copyright
34  * notice, this list of conditions, the below disclaimer, and the above
35  * attribution.
36  *
37  * DISCLAIMER:
38  *
39  * THIS PRODUCT IS PROVIDED BY THE ORIGINAL AUTHORS "AS IS" AND ANY EXPRESS
40  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
41  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42  * DISCLAIMED. IN NO EVENT SHALL THE ORIGINAL AUTHORS OR CONTRIBUTORS BE
43  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48  * ARISING IN ANY WAY OUT OF THE USE OF THIS PRODUCT, EVEN IF ADVISED OF
49  * THE POSSIBILITY OF SUCH DAMAGE.
50  *
51  * The views and conclusions contained in the hardware, software, and
52  * documentation should not be interpreted as representing official
53  * policies, either expressed or implied, of the ORIGINAL AUTHORS.
54  */
55 
56 #ifndef CRYPTO1_H
57 #define CRYPTO1_H
58 
59 #include <stdint.h>
60 
61 /* Gets the current keystream-bit, without shifting the internal LFSR */
62 uint8_t Crypto1FilterOutput(void);
63 
64 /* Set up Crypto1 cipher using the given Key, Uid and CardNonce. Also encrypts
65  * the CardNonce in-place while in non-linear mode. */
66 void Crypto1Setup(uint8_t Key[6], uint8_t Uid[4], uint8_t CardNonce[4]);
67 
68 /* Load the decrypted ReaderNonce into the Crypto1 state LFSR */
69 void Crypto1Auth(uint8_t EncryptedReaderNonce[4]);
70 
71 /* Generate 8 Bits of key stream */
72 uint8_t Crypto1Byte(void);
73 
74 /* Generate 4 Bits of key stream */
75 uint8_t Crypto1Nibble(void);
76 
77 /* Execute 'ClockCount' cycles on the PRNG state 'State' */
78 void Crypto1PRNG(uint8_t State[4], uint16_t ClockCount);
79 
80 #endif //CRYPTO1_H