mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
cryptorf: style
This commit is contained in:
parent
a76596c3fe
commit
b134753a08
9 changed files with 1703 additions and 1498 deletions
|
@ -1,9 +1,9 @@
|
|||
/*
|
||||
*
|
||||
*
|
||||
* CryptoMemory simulation
|
||||
*
|
||||
* Copyright (C) 2010, Flavio D. Garcia, Peter van Rossum, Roel Verdult
|
||||
* and Ronny Wichers Schreur. Radboud University Nijmegen
|
||||
* and Ronny Wichers Schreur. Radboud University Nijmegen
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -17,7 +17,7 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
@ -26,71 +26,85 @@
|
|||
#include "cryptolib.h"
|
||||
#include "util.h"
|
||||
#ifdef _MSC_VER
|
||||
// avoid scanf warnings in Visual Studio
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
// avoid scanf warnings in Visual Studio
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
// Cryptomemory state
|
||||
crypto_state_t s;
|
||||
int main(int argc, const char *argv[]) {
|
||||
// Cryptomemory state
|
||||
crypto_state_t s;
|
||||
|
||||
// Main authentication values
|
||||
uint8_t Q[8]; // Reader key-auth random
|
||||
uint8_t Gc[8]; // Secret seed
|
||||
uint8_t Ci[8]; // Card random (last state)
|
||||
uint8_t Ch[8]; // Reader answer (challenge)
|
||||
uint8_t Ci_1[8]; // Card answer
|
||||
uint8_t Ci_2[8]; // Session key
|
||||
|
||||
// Session authentication values
|
||||
uint8_t Qs[8]; // Reader session-auth random
|
||||
uint8_t Chs[8]; // Reader session-answer (challenge)
|
||||
uint8_t Ci_1s[8]; // Card answer for session
|
||||
uint8_t Ci_2s[8]; // Is this used?
|
||||
// Main authentication values
|
||||
uint8_t Q[8]; // Reader key-auth random
|
||||
uint8_t Gc[8]; // Secret seed
|
||||
uint8_t Ci[8]; // Card random (last state)
|
||||
uint8_t Ch[8]; // Reader answer (challenge)
|
||||
uint8_t Ci_1[8]; // Card answer
|
||||
uint8_t Ci_2[8]; // Session key
|
||||
|
||||
// Various argument options
|
||||
uint64_t nGc; // Card secret
|
||||
uint64_t nCi; // Card random
|
||||
uint64_t nQ; // Reader main-random
|
||||
uint64_t nQs; // Reader session-random
|
||||
// Session authentication values
|
||||
uint8_t Qs[8]; // Reader session-auth random
|
||||
uint8_t Chs[8]; // Reader session-answer (challenge)
|
||||
uint8_t Ci_1s[8]; // Card answer for session
|
||||
uint8_t Ci_2s[8]; // Is this used?
|
||||
|
||||
// Show header and help syntax
|
||||
printf("CryptoMemory simulator - (c) Radboud University Nijmegen\n");
|
||||
if (argc < 5)
|
||||
{
|
||||
printf("\nsyntax: cm <Gc> <Ci> <Q> <Q(s)>\n");
|
||||
return 1;
|
||||
}
|
||||
// Various argument options
|
||||
uint64_t nGc; // Card secret
|
||||
uint64_t nCi; // Card random
|
||||
uint64_t nQ; // Reader main-random
|
||||
uint64_t nQs; // Reader session-random
|
||||
|
||||
// Parse arguments
|
||||
sscanf(argv[1],"%016" SCNx64,&nGc); num_to_bytes(nGc,8,Gc);
|
||||
sscanf(argv[2],"%016" SCNx64,&nCi); num_to_bytes(nCi,8,Ci);
|
||||
sscanf(argv[3],"%016" SCNx64,&nQ); num_to_bytes(nQ,8,Q);
|
||||
sscanf(argv[4],"%016" SCNx64,&nQs); num_to_bytes(nQs,8,Qs);
|
||||
// Show header and help syntax
|
||||
printf("CryptoMemory simulator - (c) Radboud University Nijmegen\n");
|
||||
if (argc < 5) {
|
||||
printf("\nsyntax: cm <Gc> <Ci> <Q> <Q(s)>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Calculate authentication
|
||||
cm_auth(Gc,Ci,Q,Ch,Ci_1,Ci_2,&s);
|
||||
// Parse arguments
|
||||
sscanf(argv[1], "%016" SCNx64, &nGc);
|
||||
num_to_bytes(nGc, 8, Gc);
|
||||
sscanf(argv[2], "%016" SCNx64, &nCi);
|
||||
num_to_bytes(nCi, 8, Ci);
|
||||
sscanf(argv[3], "%016" SCNx64, &nQ);
|
||||
num_to_bytes(nQ, 8, Q);
|
||||
sscanf(argv[4], "%016" SCNx64, &nQs);
|
||||
num_to_bytes(nQs, 8, Qs);
|
||||
|
||||
printf("\nAuthenticate\n");
|
||||
printf(" Gc: "); print_bytes(Gc,8);
|
||||
printf(" Ci: "); print_bytes(Ci,8);
|
||||
printf(" Q: "); print_bytes(Q,8);
|
||||
printf(" Ch: "); print_bytes(Ch,8);
|
||||
printf(" Ci+1: "); print_bytes(Ci_1,8);
|
||||
printf(" Ci+2: "); print_bytes(Ci_2,8);
|
||||
// Calculate authentication
|
||||
cm_auth(Gc, Ci, Q, Ch, Ci_1, Ci_2, &s);
|
||||
|
||||
cm_auth(Ci_2,Ci_1,Qs,Chs,Ci_1s,Ci_2s,&s);
|
||||
printf("\nAuthenticate\n");
|
||||
printf(" Gc: ");
|
||||
print_bytes(Gc, 8);
|
||||
printf(" Ci: ");
|
||||
print_bytes(Ci, 8);
|
||||
printf(" Q: ");
|
||||
print_bytes(Q, 8);
|
||||
printf(" Ch: ");
|
||||
print_bytes(Ch, 8);
|
||||
printf(" Ci+1: ");
|
||||
print_bytes(Ci_1, 8);
|
||||
printf(" Ci+2: ");
|
||||
print_bytes(Ci_2, 8);
|
||||
|
||||
printf("\nVerify Crypto (Session Key)\n");
|
||||
printf(" Gc(s): "); print_bytes(Ci_2,8);
|
||||
printf(" Ci(s): "); print_bytes(Ci_1,8);
|
||||
printf(" Q(s): "); print_bytes(Qs,8);
|
||||
printf(" Ch(s): "); print_bytes(Chs,8);
|
||||
printf("Ci+1(s): "); print_bytes(Ci_1s,8);
|
||||
printf("Ci+2(s): "); print_bytes(Ci_2s,8);
|
||||
cm_auth(Ci_2, Ci_1, Qs, Chs, Ci_1s, Ci_2s, &s);
|
||||
|
||||
printf("\n");
|
||||
return 0;
|
||||
printf("\nVerify Crypto (Session Key)\n");
|
||||
printf(" Gc(s): ");
|
||||
print_bytes(Ci_2, 8);
|
||||
printf(" Ci(s): ");
|
||||
print_bytes(Ci_1, 8);
|
||||
printf(" Q(s): ");
|
||||
print_bytes(Qs, 8);
|
||||
printf(" Ch(s): ");
|
||||
print_bytes(Chs, 8);
|
||||
printf("Ci+1(s): ");
|
||||
print_bytes(Ci_1s, 8);
|
||||
printf("Ci+2(s): ");
|
||||
print_bytes(Ci_2s, 8);
|
||||
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/*
|
||||
*
|
||||
*
|
||||
* SecureMemory simulation
|
||||
*
|
||||
* Copyright (C) 2010, Flavio D. Garcia, Peter van Rossum, Roel Verdult
|
||||
* and Ronny Wichers Schreur. Radboud University Nijmegen
|
||||
* and Ronny Wichers Schreur. Radboud University Nijmegen
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -17,7 +17,7 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
@ -26,58 +26,63 @@
|
|||
#include "cryptolib.h"
|
||||
#include "util.h"
|
||||
#ifdef _MSC_VER
|
||||
// avoid scanf warnings in Visual Studio
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
// avoid scanf warnings in Visual Studio
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
// Cryptomemory state
|
||||
crypto_state_t s;
|
||||
size_t pos;
|
||||
int main(int argc, const char *argv[]) {
|
||||
// Cryptomemory state
|
||||
crypto_state_t s;
|
||||
size_t pos;
|
||||
|
||||
uint8_t Q[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; // Reader random
|
||||
uint8_t Gc[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; // Secret seed
|
||||
uint8_t Ci[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; // Card random (last state)
|
||||
uint8_t Ch[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; // Reader answer
|
||||
uint8_t Ci_1[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; // Card answer
|
||||
uint8_t Q[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Reader random
|
||||
uint8_t Gc[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Secret seed
|
||||
uint8_t Ci[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Card random (last state)
|
||||
uint8_t Ch[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Reader answer
|
||||
uint8_t Ci_1[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Card answer
|
||||
|
||||
// Various argument options
|
||||
uint64_t nGc; // Card secret
|
||||
uint64_t nCi; // Card random
|
||||
uint64_t nQ; // Reader main-random
|
||||
// Various argument options
|
||||
uint64_t nGc; // Card secret
|
||||
uint64_t nCi; // Card random
|
||||
uint64_t nQ; // Reader main-random
|
||||
|
||||
// Show header and help syntax
|
||||
printf("SecureMemory simulator - (c) Radboud University Nijmegen\n");
|
||||
if (argc < 4)
|
||||
{
|
||||
printf("\nsyntax: sm <Gc> <Ci> <Q>\n");
|
||||
return 1;
|
||||
}
|
||||
// Show header and help syntax
|
||||
printf("SecureMemory simulator - (c) Radboud University Nijmegen\n");
|
||||
if (argc < 4) {
|
||||
printf("\nsyntax: sm <Gc> <Ci> <Q>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Parse arguments
|
||||
sscanf(argv[1],"%016" SCNx64,&nGc); num_to_bytes(nGc,8,Gc);
|
||||
sscanf(argv[2],"%016" SCNx64,&nCi); num_to_bytes(nCi,8,Ci);
|
||||
sscanf(argv[3],"%016" SCNx64,&nQ); num_to_bytes(nQ,8,Q);
|
||||
// Parse arguments
|
||||
sscanf(argv[1], "%016" SCNx64, &nGc);
|
||||
num_to_bytes(nGc, 8, Gc);
|
||||
sscanf(argv[2], "%016" SCNx64, &nCi);
|
||||
num_to_bytes(nCi, 8, Ci);
|
||||
sscanf(argv[3], "%016" SCNx64, &nQ);
|
||||
num_to_bytes(nQ, 8, Q);
|
||||
|
||||
// Calculate authentication
|
||||
sm_auth(Gc,Ci,Q,Ch,Ci_1,&s);
|
||||
// Calculate authentication
|
||||
sm_auth(Gc, Ci, Q, Ch, Ci_1, &s);
|
||||
|
||||
printf("\nAuthentication info\n\n");
|
||||
printf(" Gc: "); print_bytes(Gc,8);
|
||||
printf(" Ci: "); print_bytes(Ci,8);
|
||||
printf(" Q: "); print_bytes(Q,8);
|
||||
printf(" Ch: "); print_bytes(Ch,8);
|
||||
printf("Ci+1: "); print_bytes(Ci_1,8);
|
||||
printf("\n");
|
||||
printf(" Ks: ");
|
||||
for (pos=0; pos<8; pos++)
|
||||
{
|
||||
printf("%02x ",Ci_1[pos]);
|
||||
printf("%02x ",Ch[pos]);
|
||||
}
|
||||
printf("\n\n");
|
||||
printf("\nAuthentication info\n\n");
|
||||
printf(" Gc: ");
|
||||
print_bytes(Gc, 8);
|
||||
printf(" Ci: ");
|
||||
print_bytes(Ci, 8);
|
||||
printf(" Q: ");
|
||||
print_bytes(Q, 8);
|
||||
printf(" Ch: ");
|
||||
print_bytes(Ch, 8);
|
||||
printf("Ci+1: ");
|
||||
print_bytes(Ci_1, 8);
|
||||
printf("\n");
|
||||
printf(" Ks: ");
|
||||
for (pos = 0; pos < 8; pos++) {
|
||||
printf("%02x ", Ci_1[pos]);
|
||||
printf("%02x ", Ch[pos]);
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,23 +1,21 @@
|
|||
#include "util.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void num_to_bytes(uint64_t n, size_t len, uint8_t *dst)
|
||||
{
|
||||
while (len--) {
|
||||
dst[len] = (uint8_t)n;
|
||||
n >>= 8;
|
||||
}
|
||||
void num_to_bytes(uint64_t n, size_t len, uint8_t *dst) {
|
||||
while (len--) {
|
||||
dst[len] = (uint8_t)n;
|
||||
n >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
void print_bytes(const uint8_t *pbtData, const size_t szLen)
|
||||
{
|
||||
size_t uiPos;
|
||||
for (uiPos = 0; uiPos < szLen; uiPos++) {
|
||||
printf("%02x ", pbtData[uiPos]);
|
||||
if (uiPos > 20) {
|
||||
printf("...");
|
||||
break;
|
||||
void print_bytes(const uint8_t *pbtData, const size_t szLen) {
|
||||
size_t uiPos;
|
||||
for (uiPos = 0; uiPos < szLen; uiPos++) {
|
||||
printf("%02x ", pbtData[uiPos]);
|
||||
if (uiPos > 20) {
|
||||
printf("...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue