]> git.zerfleddert.de Git - proxmark3-svn/blame_incremental - client/reveng/reveng.h
chg: the windows exe annoys the linux compiler
[proxmark3-svn] / client / reveng / reveng.h
... / ...
CommitLineData
1/* reveng.h
2 * Greg Cook, 30/Jul/2015
3 */
4
5/* CRC RevEng, an arbitrary-precision CRC calculator and algorithm finder
6 * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015 Gregory Cook
7 *
8 * This file is part of CRC RevEng.
9 *
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.
14 *
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.
19 *
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/>.
22 */
23
24#ifndef REVENG_H
25#define REVENG_H 1
26
27/* Configuration options */
28
29#include "config.h"
30
31#ifndef BMP_T
32# error config.h: BMP_T must be defined as unsigned long or a longer unsigned type
33#endif
34
35#ifndef BMP_C
36# error config.h: BMP_C() must define a BMP_T constant
37#endif
38
39#if !defined PRESETS && !defined BMPMACRO
40# undef BMP_BIT
41# undef BMP_SUB
42#endif
43
44#undef BMP_POF2
45
46#ifdef BMP_BIT
47# ifndef BMP_SUB
48# error config.h: BMP_SUB must be defined as the highest power of two that is strictly less than BMP_BIT
49# elif BMP_BIT < 32
50# error config.h: BMP_BIT must be at least 32
51# elif BMP_SUB < 16
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
55# else /* BMP_SUB */
56# define SETBMP()
57# endif /* BMP_SUB */
58# if BMP_BIT == 32
59# define BMP_POF2 5
60# elif BMP_BIT == 64
61# define BMP_POF2 6
62# elif BMP_BIT == 128
63# define BMP_POF2 7
64# elif BMP_BIT == 256
65# define BMP_POF2 8
66# elif BMP_BIT == 512
67# define BMP_POF2 9
68# elif BMP_BIT == 1024
69# define BMP_POF2 10
70# elif BMP_BIT == 2048
71# define BMP_POF2 11
72# elif BMP_BIT == 4096
73# define BMP_POF2 12
74# elif BMP_BIT == 8192
75# define BMP_POF2 13
76# elif BMP_BIT == 16384
77# define BMP_POF2 14
78# elif BMP_BIT == 32768
79# define BMP_POF2 15
80# elif BMP_BIT == 65536
81# define BMP_POF2 16
82/* may extend list as required */
83# elif (BMP_BIT & (BMP_BIT - 1)) == 0
84# define BMP_POF2 1
85# endif
86#else /* BMP_BIT */
87# define BMP_BIT bmpbit
88# define BMP_SUB bmpsub
89# define SETBMP() setbmp()
90#endif /* BMP_BIT */
91
92/* Global definitions */
93
94/* CRC RevEng version string */
95#define VERSION "1.3.1"
96
97/* bmpbit.c */
98typedef BMP_T bmp_t;
99
100extern int bmpbit, bmpsub;
101extern void setbmp(void);
102
103/* poly.c */
104#define P_REFIN 1
105#define P_REFOUT 2
106#define P_MULXN 4
107#define P_RTJUST 8
108#define P_UPPER 16
109#define P_SPACE 32
110#define P_LTLBYT 64
111#define P_DIRECT 128
112
113/* default flags */
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)
118
119/* A poly_t constant representing the polynomial 0. */
120#define PZERO {0UL, (bmp_t *) 0}
121
122typedef struct {
123 unsigned long length; /* number of significant bits */
124 bmp_t *bitmap; /* bitmap, MSB first, */
125 /* left-justified in each word */
126} poly_t;
127
128extern poly_t filtop(FILE *input, unsigned long length, int flags, int bperhx);
129extern poly_t strtop(const char *string, int flags, int bperhx);
130extern char *ptostr(const poly_t poly, int flags, int bperhx);
131extern char *pxsubs(const poly_t poly, int flags, int bperhx, unsigned long start, unsigned long end);
132extern poly_t pclone(const poly_t poly);
133extern void pcpy(poly_t *dest, const poly_t src);
134extern void pcanon(poly_t *poly);
135extern void pnorm(poly_t *poly);
136extern void psnorm(poly_t *poly);
137extern void pchop(poly_t *poly);
138extern void pkchop(poly_t *poly);
139extern unsigned long plen(const poly_t poly);
140extern int pcmp(const poly_t *a, const poly_t *b);
141extern int psncmp(const poly_t *a, const poly_t *b);
142extern int ptst(const poly_t poly);
143extern unsigned long pfirst(const poly_t poly);
144extern unsigned long plast(const poly_t poly);
145extern poly_t psubs(const poly_t src, unsigned long head, unsigned long start, unsigned long end, unsigned long tail);
146extern void pright(poly_t *poly, unsigned long length);
147extern void pshift(poly_t *dest, const poly_t src, unsigned long head, unsigned long start, unsigned long end, unsigned long tail);
148extern void ppaste(poly_t *dest, const poly_t src, unsigned long skip, unsigned long seek, unsigned long end, unsigned long fulllength);
149extern void pdiff(poly_t *dest, const poly_t src, unsigned long ofs);
150extern void psum(poly_t *dest, const poly_t src, unsigned long ofs);
151extern void prev(poly_t *poly);
152extern void prevch(poly_t *poly, int bperhx);
153extern void prcp(poly_t *poly);
154extern void pinv(poly_t *poly);
155extern poly_t pmod(const poly_t dividend, const poly_t divisor);
156extern poly_t pcrc(const poly_t message, const poly_t divisor, const poly_t init, const poly_t xorout, int flags);
157extern int piter(poly_t *poly);
158extern void palloc(poly_t *poly, unsigned long length);
159extern void pfree(poly_t *poly);
160extern void praloc(poly_t *poly, unsigned long length);
161extern int pmpar(const poly_t poly, const poly_t mask);
162extern int pident(const poly_t a, const poly_t b);
163
164/* model.c */
165#define M_OVERWR 256
166
167typedef struct {
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 */
174} model_t;
175
176extern void mcpy(model_t *dest, const model_t *src);
177extern void mfree(model_t *model);
178extern int mcmp(const model_t *a, const model_t *b);
179extern int mbynam(model_t *dest, const char *key);
180extern void mbynum(model_t *dest, int num);
181extern int mcount(void);
182extern char *mnames(void);
183extern char *mtostr(const model_t *model);
184extern void mmatch(model_t *model, int flags);
185extern void mcanon(model_t *model);
186extern void mcheck(model_t *model);
187extern void mrev(model_t *model);
188extern void mnovel(model_t *model);
189
190/* reveng.c */
191#define R_HAVEP 512
192#define R_HAVEI 1024
193#define R_HAVERI 2048
194#define R_HAVERO 4096
195#define R_HAVEX 8192
196#define R_HAVEQ 16384
197
198#define R_SPMASK 0x7FFFFFFUL
199
200extern model_t *reveng(const model_t *guess, const poly_t qpoly, int rflags, int args, const poly_t *argpolys);
201
202/* cli.c */
203#define C_INFILE 1
204#define C_FORCE 2
205#define C_RESULT 4
206
207#define BUFFER 32768
208
209extern int reveng_main(int argc, char *argv[]);
210extern void ufound(const model_t *model);
211extern void uerror(const char *msg);
212extern void uprog(const poly_t gpoly, int flags, unsigned long seq);
213
214#endif /* REVENG_H */
Impressum, Datenschutz