added more keys (@equipter)
[RRG-proxmark3.git] / tools / hitag2crack / common / hitagcrypto.h
blob76350eb7c78548de55076b1514a721d58593531c
1 /***************************************************************************
2 * A copy of the GNU GPL is appended to this file. *
3 * *
4 * This licence is based on the nmap licence, and we express our gratitude *
5 * for the work that went into producing it. There is no other connection *
6 * between RFIDler and nmap either expressed or implied. *
7 * *
8 ********************** IMPORTANT RFIDler LICENSE TERMS ********************
9 * *
10 * *
11 * All references to RFIDler herein imply all it's derivatives, namely: *
12 * *
13 * o RFIDler-LF Standard *
14 * o RFIDler-LF Lite *
15 * o RFIDler-LF Nekkid *
16 * *
17 * *
18 * RFIDler is (C) 2013-2014 Aperture Labs Ltd. *
19 * *
20 * This program is free software; you may redistribute and/or modify it *
21 * under the terms of the GNU General Public License as published by the *
22 * Free Software Foundation; Version 2 ("GPL"), BUT ONLY WITH ALL OF THE *
23 * CLARIFICATIONS AND EXCEPTIONS DESCRIBED HEREIN. This guarantees your *
24 * right to use, modify, and redistribute this software under certain *
25 * conditions. If you wish to embed RFIDler technology into proprietary *
26 * software or hardware, we sell alternative licenses *
27 * (contact sales@aperturelabs.com). *
28 * *
29 * Note that the GPL places important restrictions on "derivative works", *
30 * yet it does not provide a detailed definition of that term. To avoid *
31 * misunderstandings, we interpret that term as broadly as copyright law *
32 * allows. For example, we consider an application to constitute a *
33 * derivative work for the purpose of this license if it does any of the *
34 * following with any software or content covered by this license *
35 * ("Covered Software"): *
36 * *
37 * o Integrates source code from Covered Software. *
38 * *
39 * o Is designed specifically to execute Covered Software and parse the *
40 * results (as opposed to typical shell or execution-menu apps, which will *
41 * execute anything you tell them to). *
42 * *
43 * o Includes Covered Software in a proprietary executable installer. The *
44 * installers produced by InstallShield are an example of this. Including *
45 * RFIDler with other software in compressed or archival form does not *
46 * trigger this provision, provided appropriate open source decompression *
47 * or de-archiving software is widely available for no charge. For the *
48 * purposes of this license, an installer is considered to include Covered *
49 * Software even if it actually retrieves a copy of Covered Software from *
50 * another source during runtime (such as by downloading it from the *
51 * Internet). *
52 * *
53 * o Links (statically or dynamically) to a library which does any of the *
54 * above. *
55 * *
56 * o Executes a helper program, module, or script to do any of the above. *
57 * *
58 * This list is not exclusive, but is meant to clarify our interpretation *
59 * of derived works with some common examples. Other people may interpret *
60 * the plain GPL differently, so we consider this a special exception to *
61 * the GPL that we apply to Covered Software. Works which meet any of *
62 * these conditions must conform to all of the terms of this license, *
63 * particularly including the GPL Section 3 requirements of providing *
64 * source code and allowing free redistribution of the work as a whole. *
65 * *
66 * As another special exception to the GPL terms, Aperture Labs Ltd. grants*
67 * permission to link the code of this program with any version of the *
68 * OpenSSL library which is distributed under a license identical to that *
69 * listed in the included docs/licenses/OpenSSL.txt file, and distribute *
70 * linked combinations including the two. *
71 * *
72 * Any redistribution of Covered Software, including any derived works, *
73 * must obey and carry forward all of the terms of this license, including *
74 * obeying all GPL rules and restrictions. For example, source code of *
75 * the whole work must be provided and free redistribution must be *
76 * allowed. All GPL references to "this License", are to be treated as *
77 * including the terms and conditions of this license text as well. *
78 * *
79 * Because this license imposes special exceptions to the GPL, Covered *
80 * Work may not be combined (even as part of a larger work) with plain GPL *
81 * software. The terms, conditions, and exceptions of this license must *
82 * be included as well. This license is incompatible with some other open *
83 * source licenses as well. In some cases we can relicense portions of *
84 * RFIDler or grant special permissions to use it in other open source *
85 * software. Please contact sales@aperturelabs.com with any such requests.*
86 * Similarly, we don't incorporate incompatible open source software into *
87 * Covered Software without special permission from the copyright holders. *
88 * *
89 * If you have any questions about the licensing restrictions on using *
90 * RFIDler in other works, are happy to help. As mentioned above, we also *
91 * offer alternative license to integrate RFIDler into proprietary *
92 * applications and appliances. These contracts have been sold to dozens *
93 * of software vendors, and generally include a perpetual license as well *
94 * as providing for priority support and updates. They also fund the *
95 * continued development of RFIDler. Please email sales@aperturelabs.com *
96 * for further information. *
97 * If you have received a written license agreement or contract for *
98 * Covered Software stating terms other than these, you may choose to use *
99 * and redistribute Covered Software under those terms instead of these. *
101 * Source is provided to this software because we believe users have a *
102 * right to know exactly what a program is going to do before they run it. *
103 * This also allows you to audit the software for security holes (none *
104 * have been found so far). *
106 * Source code also allows you to port RFIDler to new platforms, fix bugs, *
107 * and add new features. You are highly encouraged to send your changes *
108 * to the RFIDler mailing list for possible incorporation into the *
109 * main distribution. By sending these changes to Aperture Labs Ltd. or *
110 * one of the Aperture Labs Ltd. development mailing lists, or checking *
111 * them into the RFIDler source code repository, it is understood (unless *
112 * you specify otherwise) that you are offering the RFIDler Project *
113 * (Aperture Labs Ltd.) the unlimited, non-exclusive right to reuse, *
114 * modify, and relicense the code. RFIDler will always be available Open *
115 * Source, but this is important because the inability to relicense code *
116 * has caused devastating problems for other Free Software projects (such *
117 * as KDE and NASM). We also occasionally relicense the code to third *
118 * parties as discussed above. If you wish to specify special license *
119 * conditions of your contributions, just say so when you send them. *
121 * This program is distributed in the hope that it will be useful, but *
122 * WITHOUT ANY WARRANTY; without even the implied warranty of *
123 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the RFIDler *
124 * license file for more details (it's in a COPYING file included with *
125 * RFIDler, and also available from *
126 * https://github.com/ApertureLabsLtd/RFIDler/COPYING *
128 ***************************************************************************/
130 // Author: unknown.
131 // Modifications for RFIDler: Tony Naggs <tony.naggs@gmail.com>, Adam Laurie <adam@aperturelabs.com>
134 #ifndef HITAGCRYPTO_H
135 #define HITAGCRYPTO_H
137 #include <stdint.h>
140 Our model of Hitag 2 crypto uses 2 parallel shift registers:
141 a. 48 bit Feedback Shift Register, required for inputs to the nonlinear function.
142 b. 48 bit Linear Feedback Shift Register (LFSR).
143 A transform of initial register (a) value, which is then run in parallel.
144 Enables much faster calculation of the feedback values.
146 API:
147 void hitag2_init(Hitag_State* pstate, uint64_t sharedkey, uint32_t serialnum,
148 uint32_t initvector);
149 Initialise state from 48 bit shared (secret) reader/tag key,
150 32 bit tag serial number and 32 bit initialisation vector from reader.
152 uint32_t hitag2_nstep(Hitag_State* pstate, uint32_t steps);
153 update shift register state and generate N cipher bits (N should be <= 32)
157 typedef struct {
158 uint64_t shiftreg; // naive shift register, required for nonlinear fn input
159 uint64_t lfsr; // fast lfsr, used to make software faster
160 } Hitag_State;
162 void hitag2_init(Hitag_State *pstate, uint64_t sharedkey, uint32_t serialnum, uint32_t initvector);
164 uint32_t hitag2_nstep(Hitag_State *pstate, uint32_t steps);
166 #endif /* HITAGCRYPTO_H */