3 * SecureMemory 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
[]) {
39 uint8_t Q
[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Reader random
40 uint8_t Gc
[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Secret seed
41 uint8_t Ci
[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Card random (last state)
42 uint8_t Ch
[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Reader answer
43 uint8_t Ci_1
[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Card answer
45 // Various argument options
46 uint64_t nGc
; // Card secret
47 uint64_t nCi
; // Card random
48 uint64_t nQ
; // Reader main-random
50 // Show header and help syntax
51 printf("SecureMemory simulator - (c) Radboud University Nijmegen\n");
53 printf("\nsyntax: sm <Gc> <Ci> <Q>\n");
58 sscanf(argv
[1], "%016" SCNx64
, &nGc
);
59 num_to_bytes(nGc
, 8, Gc
);
60 sscanf(argv
[2], "%016" SCNx64
, &nCi
);
61 num_to_bytes(nCi
, 8, Ci
);
62 sscanf(argv
[3], "%016" SCNx64
, &nQ
);
63 num_to_bytes(nQ
, 8, Q
);
65 // Calculate authentication
66 sm_auth(Gc
, Ci
, Q
, Ch
, Ci_1
, &s
);
68 printf("\nAuthentication info\n\n");
81 for (pos
= 0; pos
< 8; pos
++) {
82 printf("%02x ", Ci_1
[pos
]);
83 printf("%02x ", Ch
[pos
]);