3 * CryptoMemory simulation
5 * Copyright (C) 2010, Flavio D. Garcia, Peter van Rossum, Roel Verdult
6 * and Ronny Wichers Schreur. Radboud University Nijmegen
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "cryptolib.h"
29 // avoid scanf warnings in Visual Studio
30 #define _CRT_SECURE_NO_WARNINGS
31 #define _CRT_SECURE_NO_DEPRECATE
34 int main(int argc
, const char *argv
[]) {
38 // Main authentication values
39 uint8_t Q
[8]; // Reader key-auth random
40 uint8_t Gc
[8]; // Secret seed
41 uint8_t Ci
[8]; // Card random (last state)
42 uint8_t Ch
[8]; // Reader answer (challenge)
43 uint8_t Ci_1
[8]; // Card answer
44 uint8_t Ci_2
[8]; // Session key
46 // Session authentication values
47 uint8_t Qs
[8]; // Reader session-auth random
48 uint8_t Chs
[8]; // Reader session-answer (challenge)
49 uint8_t Ci_1s
[8]; // Card answer for session
50 uint8_t Ci_2s
[8]; // Is this used?
52 // Various argument options
53 uint64_t nGc
; // Card secret
54 uint64_t nCi
; // Card random
55 uint64_t nQ
; // Reader main-random
56 uint64_t nQs
; // Reader session-random
58 // Show header and help syntax
59 printf("CryptoMemory simulator - (c) Radboud University Nijmegen\n");
61 printf("\nsyntax: cm <Gc> <Ci> <Q> <Q(s)>\n");
66 sscanf(argv
[1], "%016" SCNx64
, &nGc
);
67 num_to_bytes(nGc
, 8, Gc
);
68 sscanf(argv
[2], "%016" SCNx64
, &nCi
);
69 num_to_bytes(nCi
, 8, Ci
);
70 sscanf(argv
[3], "%016" SCNx64
, &nQ
);
71 num_to_bytes(nQ
, 8, Q
);
72 sscanf(argv
[4], "%016" SCNx64
, &nQs
);
73 num_to_bytes(nQs
, 8, Qs
);
75 // Calculate authentication
76 cm_auth(Gc
, Ci
, Q
, Ch
, Ci_1
, Ci_2
, &s
);
78 printf("\nAuthenticate\n");
92 cm_auth(Ci_2
, Ci_1
, Qs
, Chs
, Ci_1s
, Ci_2s
, &s
);
94 printf("\nVerify Crypto (Session Key)\n");
104 print_bytes(Ci_1s
, 8);
106 print_bytes(Ci_2s
, 8);