Merge pull request #2664 from piotrva/hf-mf-ultimatecard-script-max-rw-blocks
[RRG-proxmark3.git] / armsrc / optimized_cipherutils.h
blobd6a046bf93c00fdc97ba9b0e38dd583ac82ae981
1 //-----------------------------------------------------------------------------
2 // Borrowed initially from https://github.com/holiman/loclass
3 // Copyright (C) 2014 Martin Holst Swende
4 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // See LICENSE.txt for the text of the license.
17 //-----------------------------------------------------------------------------
18 // WARNING
20 // THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY.
22 // USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL
23 // PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL,
24 // AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES.
26 // THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS.
27 //-----------------------------------------------------------------------------
28 // It is a reconstruction of the cipher engine used in iClass, and RFID techology.
30 // The implementation is based on the work performed by
31 // Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and
32 // Milosch Meriac in the paper "Dismantling IClass".
33 //-----------------------------------------------------------------------------
34 #ifndef CIPHERUTILS_H
35 #define CIPHERUTILS_H
36 #include <stdint.h>
37 #include <stdbool.h>
38 #include <stdlib.h>
40 typedef struct {
41 uint8_t *buffer;
42 uint32_t numbits;
43 uint32_t position;
44 } BitstreamIn_t;
46 typedef struct {
47 uint8_t *buffer;
48 uint32_t numbits;
49 uint32_t position;
50 } BitstreamOut_t;
52 bool headBit(BitstreamIn_t *stream);
53 bool tailBit(BitstreamIn_t *stream);
54 void pushBit(BitstreamOut_t *stream, bool bit);
55 int bitsLeft(BitstreamIn_t *stream);
57 void push6bits(BitstreamOut_t *stream, uint8_t bits);
58 void x_num_to_bytes(uint64_t n, size_t len, uint8_t *dest);
59 uint64_t x_bytes_to_num(uint8_t *src, size_t len);
60 #endif // CIPHERUTILS_H