rework cryptorf

This commit is contained in:
Philippe Teuwen 2020-08-19 21:38:21 +02:00
commit 9ade745f07
16 changed files with 693 additions and 985 deletions

View file

@ -20,9 +20,16 @@
*
*/
#include "defines.h"
#include <inttypes.h>
#include <stddef.h>
#include <stdio.h>
#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
#endif
int main(int argc, const char* argv[])
{
@ -30,24 +37,24 @@ int main(int argc, const char* argv[])
crypto_state_t s;
// Main authentication values
byte_t Q[8]; // Reader key-auth random
byte_t Gc[8]; // Secret seed
byte_t Ci[8]; // Card random (last state)
byte_t Ch[8]; // Reader answer (challenge)
byte_t Ci_1[8]; // Card answer
byte_t Ci_2[8]; // Session key
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
byte_t Qs[8]; // Reader session-auth random
byte_t Chs[8]; // Reader session-answer (challenge)
byte_t Ci_1s[8]; // Card answer for session
byte_t Ci_2s[8]; // Is this used?
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?
// Various argument options
ui64 nGc; // Card secret
ui64 nCi; // Card random
ui64 nQ; // Reader main-random
ui64 nQs; // Reader session-random
uint64_t nGc; // Card secret
uint64_t nCi; // Card random
uint64_t nQ; // Reader main-random
uint64_t nQs; // Reader session-random
// Show header and help syntax
printf("CryptoMemory simulator - (c) Radboud University Nijmegen\n");
@ -58,10 +65,10 @@ int main(int argc, const char* argv[])
}
// Parse arguments
sscanf(argv[1],"%016llx",&nGc); num_to_bytes(nGc,8,Gc);
sscanf(argv[2],"%016llx",&nCi); num_to_bytes(nCi,8,Ci);
sscanf(argv[3],"%016llx",&nQ); num_to_bytes(nQ,8,Q);
sscanf(argv[4],"%016llx",&nQs); num_to_bytes(nQs,8,Qs);
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);
// Calculate authentication
cm_auth(Gc,Ci,Q,Ch,Ci_1,Ci_2,&s);