3 * this uses the RFIDler hitag2 PRNG code to generate test cases to test the tables
6 #include "ht2crackutils.h"
8 static int makerandom(char *hex
, unsigned int len
, int fd
) {
13 printf("makerandom: hex is NULL\n");
17 if (!len
|| (len
> 32)) {
18 printf("makerandom: len must be between 1 and 32 inclusive\n");
22 if (read(fd
, raw
, len
) != len
) {
23 printf("makerandom: cannot read random bytes\n");
27 for (i
= 0; i
< len
; i
++) {
28 sprintf(hex
+ (2 * i
), "%02X", raw
[i
]);
35 int main(int argc
, char *argv
[]) {
46 printf("%s number\n", argv
[0]);
50 numtests
= atoi(argv
[1]);
52 printf("need positive number of tests\n");
56 urandomfd
= open("/dev/urandom", O_RDONLY
);
58 printf("cannot open /dev/urandom\n");
63 for (i
= 0; i
< numtests
; i
++) {
65 makerandom(key
, 6, urandomfd
);
66 makerandom(uid
, 4, urandomfd
);
67 makerandom(nR
, 4, urandomfd
);
68 sprintf(filename
, "keystream.key-%s.uid-%s.nR-%s", key
, uid
, nR
);
70 FILE *fp
= fopen(filename
, "w");
72 printf("cannot open file '%s' for writing\n", filename
);
79 hitag2_init(&hstate
, rev64(hexreversetoulonglong(key
)), rev32(hexreversetoulong(uid
)), rev32(hexreversetoulong(nR
)));
81 hitag2_nstep(&hstate
, 64);
83 for (j
= 0; j
< 64; j
++) {
84 fprintf(fp
, "%08X\n", hitag2_nstep(&hstate
, 32));