Makefile: display firmware size
[RRG-proxmark3.git] / tools / cryptorf / sm.c
blobb604c9dfad88ac2db9801ba82cbe1c81518a3310
1 /*
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/>.
23 #include <inttypes.h>
24 #include <stddef.h>
25 #include <stdio.h>
26 #include "cryptolib.h"
27 #include "util.h"
28 #ifdef _MSC_VER
29 // avoid scanf warnings in Visual Studio
30 #define _CRT_SECURE_NO_WARNINGS
31 #define _CRT_SECURE_NO_DEPRECATE
32 #endif
34 int main(int argc, const char *argv[]) {
35 // Cryptomemory state
36 crypto_state_t s;
37 size_t pos;
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");
52 if (argc < 4) {
53 printf("\nsyntax: sm <Gc> <Ci> <Q>\n");
54 return 1;
57 // Parse arguments
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");
69 printf(" Gc: ");
70 print_bytes(Gc, 8);
71 printf(" Ci: ");
72 print_bytes(Ci, 8);
73 printf(" Q: ");
74 print_bytes(Q, 8);
75 printf(" Ch: ");
76 print_bytes(Ch, 8);
77 printf("Ci+1: ");
78 print_bytes(Ci_1, 8);
79 printf("\n");
80 printf(" Ks: ");
81 for (pos = 0; pos < 8; pos++) {
82 printf("%02x ", Ci_1[pos]);
83 printf("%02x ", Ch[pos]);
85 printf("\n\n");
87 return 0;