From f17cbfe412a2ab55e285d8f2600995b1a5715774 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Sat, 29 May 2021 15:51:08 +0300 Subject: [PATCH] add some consts and kvv --- client/src/cipurse/cipursecrypto.c | 28 ++++++++++++++++++++-------- client/src/cipurse/cipursecrypto.h | 14 ++++++++++---- client/src/cmdhfcipurse.c | 4 ++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/client/src/cipurse/cipursecrypto.c b/client/src/cipurse/cipursecrypto.c index e020676c6..16917b7aa 100644 --- a/client/src/cipurse/cipursecrypto.c +++ b/client/src/cipurse/cipursecrypto.c @@ -17,9 +17,26 @@ #include "cmdhf14a.h" #include "emv/emvcore.h" #include "emv/emvjson.h" +#include "crypto/libpcrypto.h" #include "ui.h" #include "util.h" +uint8_t AESData0[CIPURSE_AES_KEY_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +static void CipurseCGenerateK0AndGetCp(CipurseContext *ctx) { + +} + +static void CipurseCGenerateCT(uint8_t *RT, uint8_t *CT) { + +} + +void CipurseCGetKVV(uint8_t *key, uint8_t *kvv) { + uint8_t res[16] = {0}; + aes_encode(NULL, key, AESData0, res, CIPURSE_AES_KEY_LENGTH); + memcpy(kvv, res, CIPURSE_KVV_LENGTH); +} + void CipurseClearContext(CipurseContext *ctx) { if (ctx == NULL) return; @@ -54,12 +71,7 @@ void CipurseAuthenticateHost(CipurseContext *ctx) { if (ctx == NULL) return; -/* RT = Random.nextBytes(16) - rT = Random.nextBytes(6) - - val cP = generateK0AndGetCp(key, RP, rP, RT, rT) ?: return Pair(null, null) - - return Pair(cP + RT + rT, generateCT(RT))*/ - - + CipurseSetRandomHost(ctx); + CipurseCGenerateK0AndGetCp(ctx); + CipurseCGenerateCT(ctx->RT, ctx->CT); } diff --git a/client/src/cipurse/cipursecrypto.h b/client/src/cipurse/cipursecrypto.h index 07019f6ca..04e3d27b5 100644 --- a/client/src/cipurse/cipursecrypto.h +++ b/client/src/cipurse/cipursecrypto.h @@ -13,6 +13,11 @@ #include "common.h" +#define CIPURSE_KVV_LENGTH 4 +#define CIPURSE_AES_KEY_LENGTH 16 +#define CIPURSE_SECURITY_PARAM_N 6 +#define OSPT_MAC_LENGTH 8 + #define member_size(type, member) sizeof(((type *)0)->member) enum CipurseChannelSecurityLevel { @@ -24,7 +29,7 @@ enum CipurseChannelSecurityLevel { typedef struct CipurseContextS { uint8_t keyId; - uint8_t key[16]; + uint8_t key[CIPURSE_AES_KEY_LENGTH]; uint8_t RP[16]; uint8_t rP[6]; @@ -33,9 +38,10 @@ typedef struct CipurseContextS { uint8_t frameKey0[16]; uint8_t cP[16]; + uint8_t CT[16]; - uint8_t frameKey[16]; - uint8_t frameKeyNext[16]; + uint8_t frameKey[CIPURSE_AES_KEY_LENGTH]; + uint8_t frameKeyNext[CIPURSE_AES_KEY_LENGTH]; } CipurseContext; void CipurseClearContext(CipurseContext *ctx); @@ -46,6 +52,6 @@ void CipurseSetRandomHost(CipurseContext *ctx); void CipurseAuthenticateHost(CipurseContext *ctx); - +void CipurseCGetKVV(uint8_t *key, uint8_t *kvv); #endif /* __CIPURSECRYPTO_H__ */ diff --git a/client/src/cmdhfcipurse.c b/client/src/cmdhfcipurse.c index 1806e4be4..cac5ab03c 100644 --- a/client/src/cmdhfcipurse.c +++ b/client/src/cmdhfcipurse.c @@ -98,6 +98,10 @@ static int CmdHFCipurseAuth(const char *Cmd) { uint8_t key[] = {0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73}; CipurseContext ctx = {0}; CipurseSetKey(&ctx, 1, key); + + uint8_t kvv[CIPURSE_KVV_LENGTH] = {0}; + CipurseCGetKVV(key, kvv); + PrintAndLogEx(INFO, "Key: %s KVV: %s", sprint_hex(key, CIPURSE_AES_KEY_LENGTH), sprint_hex_inrow(kvv, CIPURSE_KVV_LENGTH)); res = CIPURSEChallenge(buf, sizeof(buf), &len, &sw); if (res != 0 || len != 0x16) {