]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/reveng/reveng.h
2 * Greg Cook, 30/Jul/2015
5 /* CRC RevEng, an arbitrary-precision CRC calculator and algorithm finder
6 * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015 Gregory Cook
8 * This file is part of CRC RevEng.
10 * CRC RevEng is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * CRC RevEng is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with CRC RevEng. If not, see <http://www.gnu.org/licenses/>.
27 /* Configuration options */
32 # error config.h: BMP_T must be defined as unsigned long or a longer unsigned type
36 # error config.h: BMP_C() must define a BMP_T constant
39 #if !defined PRESETS && !defined BMPMACRO
48 # error config.h: BMP_SUB must be defined as the highest power of two that is strictly less than BMP_BIT
50 # error config.h: BMP_BIT must be at least 32
52 # error config.h: BMP_SUB must be at least 16
53 # elif (BMP_SUB >= BMP_BIT || BMP_SUB << 1 < BMP_BIT || BMP_SUB & (BMP_SUB - 1))
54 # error config.h: BMP_SUB must be defined as the highest power of two that is strictly less than BMP_BIT
68 # elif BMP_BIT == 1024
70 # elif BMP_BIT == 2048
72 # elif BMP_BIT == 4096
74 # elif BMP_BIT == 8192
76 # elif BMP_BIT == 16384
78 # elif BMP_BIT == 32768
80 # elif BMP_BIT == 65536
82 /* may extend list as required */
83 # elif (BMP_BIT & (BMP_BIT - 1)) == 0
87 # define BMP_BIT bmpbit
88 # define BMP_SUB bmpsub
89 # define SETBMP() setbmp()
92 /* Global definitions */
94 /* CRC RevEng version string */
95 #define VERSION "1.3.1"
100 extern int bmpbit
, bmpsub
;
101 extern void setbmp(void);
114 #define P_BE (P_RTJUST | P_MULXN)
115 #define P_LE (P_REFIN | P_REFOUT | P_MULXN)
116 #define P_BELE (P_REFOUT | P_MULXN)
117 #define P_LEBE (P_REFIN | P_RTJUST | P_MULXN)
119 /* A poly_t constant representing the polynomial 0. */
120 #define PZERO {0UL, (bmp_t *) 0}
123 unsigned long length
; /* number of significant bits */
124 bmp_t
*bitmap
; /* bitmap, MSB first, */
125 /* left-justified in each word */
128 extern poly_t
filtop(FILE *input
, unsigned long length
, int flags
, int bperhx
);
129 extern poly_t
strtop(const char *string
, int flags
, int bperhx
);
130 extern char *ptostr(const poly_t poly
, int flags
, int bperhx
);
131 extern char *pxsubs(const poly_t poly
, int flags
, int bperhx
, unsigned long start
, unsigned long end
);
132 extern poly_t
pclone(const poly_t poly
);
133 extern void pcpy(poly_t
*dest
, const poly_t src
);
134 extern void pcanon(poly_t
*poly
);
135 extern void pnorm(poly_t
*poly
);
136 extern void psnorm(poly_t
*poly
);
137 extern void pchop(poly_t
*poly
);
138 extern void pkchop(poly_t
*poly
);
139 extern unsigned long plen(const poly_t poly
);
140 extern int pcmp(const poly_t
*a
, const poly_t
*b
);
141 extern int psncmp(const poly_t
*a
, const poly_t
*b
);
142 extern int ptst(const poly_t poly
);
143 extern unsigned long pfirst(const poly_t poly
);
144 extern unsigned long plast(const poly_t poly
);
145 extern poly_t
psubs(const poly_t src
, unsigned long head
, unsigned long start
, unsigned long end
, unsigned long tail
);
146 extern void pright(poly_t
*poly
, unsigned long length
);
147 extern void pshift(poly_t
*dest
, const poly_t src
, unsigned long head
, unsigned long start
, unsigned long end
, unsigned long tail
);
148 extern void ppaste(poly_t
*dest
, const poly_t src
, unsigned long skip
, unsigned long seek
, unsigned long end
, unsigned long fulllength
);
149 extern void pdiff(poly_t
*dest
, const poly_t src
, unsigned long ofs
);
150 extern void psum(poly_t
*dest
, const poly_t src
, unsigned long ofs
);
151 extern void prev(poly_t
*poly
);
152 extern void prevch(poly_t
*poly
, int bperhx
);
153 extern void prcp(poly_t
*poly
);
154 extern void pinv(poly_t
*poly
);
155 extern poly_t
pmod(const poly_t dividend
, const poly_t divisor
);
156 extern poly_t
pcrc(const poly_t message
, const poly_t divisor
, const poly_t init
, const poly_t xorout
, int flags
);
157 extern int piter(poly_t
*poly
);
158 extern void palloc(poly_t
*poly
, unsigned long length
);
159 extern void pfree(poly_t
*poly
);
160 extern void praloc(poly_t
*poly
, unsigned long length
);
161 extern int pmpar(const poly_t poly
, const poly_t mask
);
162 extern int pident(const poly_t a
, const poly_t b
);
168 poly_t spoly
; /* polynomial with highest-order term removed. length determines CRC width */
169 poly_t init
; /* initial register value. length == poly.length */
170 int flags
; /* P_REFIN and P_REFOUT indicate reflected input/output */
171 poly_t xorout
; /* final register XOR mask. length == poly.length */
172 poly_t check
; /* optional check value, the CRC of the UTF-8 string "123456789" */
173 const char *name
; /* optional canonical name of the model */
176 extern void mcpy(model_t
*dest
, const model_t
*src
);
177 extern void mfree(model_t
*model
);
178 extern int mcmp(const model_t
*a
, const model_t
*b
);
179 extern int mbynam(model_t
*dest
, const char *key
);
180 extern void mbynum(model_t
*dest
, int num
);
181 extern int mcount(void);
182 extern char *mnames(void);
183 extern char *mtostr(const model_t
*model
);
184 extern void mmatch(model_t
*model
, int flags
);
185 extern void mcanon(model_t
*model
);
186 extern void mcheck(model_t
*model
);
187 extern void mrev(model_t
*model
);
188 extern void mnovel(model_t
*model
);
193 #define R_HAVERI 2048
194 #define R_HAVERO 4096
196 #define R_HAVEQ 16384
198 #define R_SPMASK 0x7FFFFFFUL
200 extern model_t
*reveng(const model_t
*guess
, const poly_t qpoly
, int rflags
, int args
, const poly_t
*argpolys
);
209 extern int reveng_main(int argc
, char *argv
[]);
210 extern void ufound(const model_t
*model
);
211 extern void uerror(const char *msg
);
212 extern void uprog(const poly_t gpoly
, int flags
, unsigned long seq
);
214 #endif /* REVENG_H */