add some consts and kvv

This commit is contained in:
merlokk committed 2021-06-15 14:05:34 +03:00
1 parent 05c8f313dd
commit f17cbfe412
3 files changed
+34 -12

No files matched your search

+20 -8
View File
@@ -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);
}
+10 -4
View File
@@ -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__ */
+4
View File
@@ -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) {