mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
changing {} style to match majority of previous style
This commit is contained in:
parent
da6cdf014b
commit
961d929f4d
320 changed files with 5502 additions and 10485 deletions
|
@ -259,8 +259,7 @@ const APDUCode APDUCodeTable[] = {
|
|||
};
|
||||
const size_t APDUCodeTableLen = sizeof(APDUCodeTable) / sizeof(APDUCode);
|
||||
|
||||
int CodeCmp(const char *code1, const char *code2)
|
||||
{
|
||||
int CodeCmp(const char *code1, const char *code2) {
|
||||
int xsymb = 0;
|
||||
int cmp = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
@ -278,8 +277,7 @@ int CodeCmp(const char *code1, const char *code2)
|
|||
return -1;
|
||||
}
|
||||
|
||||
const APDUCode *const GetAPDUCode(uint8_t sw1, uint8_t sw2)
|
||||
{
|
||||
const APDUCode *const GetAPDUCode(uint8_t sw1, uint8_t sw2) {
|
||||
char buf[6] = {0};
|
||||
int res;
|
||||
int mineq = APDUCodeTableLen;
|
||||
|
@ -310,8 +308,7 @@ const APDUCode *const GetAPDUCode(uint8_t sw1, uint8_t sw2)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
const char *GetAPDUCodeDescription(uint8_t sw1, uint8_t sw2)
|
||||
{
|
||||
const char *GetAPDUCodeDescription(uint8_t sw1, uint8_t sw2) {
|
||||
const APDUCode *cd = GetAPDUCode(sw1, sw2);
|
||||
if (cd)
|
||||
return cd->Description;
|
||||
|
|
|
@ -20,8 +20,7 @@
|
|||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
#define TLV_ADD(tag, value)( tlvdb_change_or_add_node(tlvRoot, tag, sizeof(value) - 1, (const unsigned char *)value) )
|
||||
void ParamLoadDefaults(struct tlvdb *tlvRoot)
|
||||
{
|
||||
void ParamLoadDefaults(struct tlvdb *tlvRoot) {
|
||||
//9F02:(Amount, authorized (Numeric)) len:6
|
||||
TLV_ADD(0x9F02, "\x00\x00\x00\x00\x01\x00");
|
||||
//9F1A:(Terminal Country Code) len:2
|
||||
|
@ -44,8 +43,7 @@ void ParamLoadDefaults(struct tlvdb *tlvRoot)
|
|||
TLV_ADD(0x95, "\x00\x00\x00\x00\x00");
|
||||
}
|
||||
|
||||
void PrintChannel(EMVCommandChannel channel)
|
||||
{
|
||||
void PrintChannel(EMVCommandChannel channel) {
|
||||
switch (channel) {
|
||||
case ECC_CONTACTLESS:
|
||||
PrintAndLogEx(INFO, "Channel: CONTACTLESS");
|
||||
|
@ -56,8 +54,7 @@ void PrintChannel(EMVCommandChannel channel)
|
|||
}
|
||||
}
|
||||
|
||||
int CmdEMVSelect(const char *cmd)
|
||||
{
|
||||
int CmdEMVSelect(const char *cmd) {
|
||||
uint8_t data[APDU_AID_LEN] = {0};
|
||||
int datalen = 0;
|
||||
|
||||
|
@ -108,8 +105,7 @@ int CmdEMVSelect(const char *cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdEMVSearch(const char *cmd)
|
||||
{
|
||||
int CmdEMVSearch(const char *cmd) {
|
||||
|
||||
CLIParserInit("emv search",
|
||||
"Tries to select all applets from applet list:\n",
|
||||
|
@ -159,8 +155,7 @@ int CmdEMVSearch(const char *cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdEMVPPSE(const char *cmd)
|
||||
{
|
||||
int CmdEMVPPSE(const char *cmd) {
|
||||
|
||||
CLIParserInit("emv pse",
|
||||
"Executes PSE/PPSE select command. It returns list of applet on the card:\n",
|
||||
|
@ -215,8 +210,7 @@ int CmdEMVPPSE(const char *cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdEMVGPO(const char *cmd)
|
||||
{
|
||||
int CmdEMVGPO(const char *cmd) {
|
||||
uint8_t data[APDU_RES_LEN] = {0};
|
||||
int datalen = 0;
|
||||
|
||||
|
@ -322,8 +316,7 @@ int CmdEMVGPO(const char *cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdEMVReadRecord(const char *cmd)
|
||||
{
|
||||
int CmdEMVReadRecord(const char *cmd) {
|
||||
uint8_t data[APDU_RES_LEN] = {0};
|
||||
int datalen = 0;
|
||||
|
||||
|
@ -378,8 +371,7 @@ int CmdEMVReadRecord(const char *cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdEMVAC(const char *cmd)
|
||||
{
|
||||
int CmdEMVAC(const char *cmd) {
|
||||
uint8_t data[APDU_RES_LEN] = {0};
|
||||
int datalen = 0;
|
||||
|
||||
|
@ -500,8 +492,7 @@ int CmdEMVAC(const char *cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdEMVGenerateChallenge(const char *cmd)
|
||||
{
|
||||
int CmdEMVGenerateChallenge(const char *cmd) {
|
||||
|
||||
CLIParserInit("emv challenge",
|
||||
"Executes Generate Challenge command. It returns 4 or 8-byte random number from card.\nNeeds a EMV applet to be selected and GPO to be executed.",
|
||||
|
@ -546,8 +537,7 @@ int CmdEMVGenerateChallenge(const char *cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdEMVInternalAuthenticate(const char *cmd)
|
||||
{
|
||||
int CmdEMVInternalAuthenticate(const char *cmd) {
|
||||
uint8_t data[APDU_RES_LEN] = {0};
|
||||
int datalen = 0;
|
||||
|
||||
|
@ -651,8 +641,7 @@ int CmdEMVInternalAuthenticate(const char *cmd)
|
|||
|
||||
#define dreturn(n) {free(pdol_data_tlv); tlvdb_free(tlvSelect); tlvdb_free(tlvRoot); DropFieldEx( channel ); return n;}
|
||||
|
||||
void InitTransactionParameters(struct tlvdb *tlvRoot, bool paramLoadJSON, enum TransactionType TrType, bool GenACGPO)
|
||||
{
|
||||
void InitTransactionParameters(struct tlvdb *tlvRoot, bool paramLoadJSON, enum TransactionType TrType, bool GenACGPO) {
|
||||
|
||||
ParamLoadDefaults(tlvRoot);
|
||||
|
||||
|
@ -685,8 +674,7 @@ void InitTransactionParameters(struct tlvdb *tlvRoot, bool paramLoadJSON, enum T
|
|||
}
|
||||
}
|
||||
|
||||
void ProcessGPOResponseFormat1(struct tlvdb *tlvRoot, uint8_t *buf, size_t len, bool decodeTLV)
|
||||
{
|
||||
void ProcessGPOResponseFormat1(struct tlvdb *tlvRoot, uint8_t *buf, size_t len, bool decodeTLV) {
|
||||
if (buf[0] == 0x80) {
|
||||
if (decodeTLV) {
|
||||
PrintAndLog("GPO response format1:");
|
||||
|
@ -716,8 +704,7 @@ void ProcessGPOResponseFormat1(struct tlvdb *tlvRoot, uint8_t *buf, size_t len,
|
|||
}
|
||||
}
|
||||
|
||||
void ProcessACResponseFormat1(struct tlvdb *tlvRoot, uint8_t *buf, size_t len, bool decodeTLV)
|
||||
{
|
||||
void ProcessACResponseFormat1(struct tlvdb *tlvRoot, uint8_t *buf, size_t len, bool decodeTLV) {
|
||||
if (buf[0] == 0x80) {
|
||||
if (decodeTLV) {
|
||||
PrintAndLog("GPO response format1:");
|
||||
|
@ -761,8 +748,7 @@ void ProcessACResponseFormat1(struct tlvdb *tlvRoot, uint8_t *buf, size_t len, b
|
|||
}
|
||||
}
|
||||
|
||||
int CmdEMVExec(const char *cmd)
|
||||
{
|
||||
int CmdEMVExec(const char *cmd) {
|
||||
uint8_t buf[APDU_RES_LEN] = {0};
|
||||
size_t len = 0;
|
||||
uint16_t sw = 0;
|
||||
|
@ -1359,8 +1345,7 @@ int CmdEMVExec(const char *cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdEMVScan(const char *cmd)
|
||||
{
|
||||
int CmdEMVScan(const char *cmd) {
|
||||
uint8_t AID[APDU_AID_LEN] = {0};
|
||||
size_t AIDlen = 0;
|
||||
uint8_t buf[APDU_RES_LEN] = {0};
|
||||
|
@ -1713,18 +1698,15 @@ int CmdEMVScan(const char *cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdEMVList(const char *Cmd)
|
||||
{
|
||||
int CmdEMVList(const char *Cmd) {
|
||||
return CmdTraceList("7816");
|
||||
}
|
||||
|
||||
int CmdEMVTest(const char *cmd)
|
||||
{
|
||||
int CmdEMVTest(const char *cmd) {
|
||||
return ExecuteCryptoTests(true);
|
||||
}
|
||||
|
||||
int CmdEMVRoca(const char *cmd)
|
||||
{
|
||||
int CmdEMVRoca(const char *cmd) {
|
||||
uint8_t AID[APDU_AID_LEN] = {0};
|
||||
size_t AIDlen = 0;
|
||||
uint8_t buf[APDU_RES_LEN] = {0};
|
||||
|
@ -1980,15 +1962,13 @@ static command_t CommandTable[] = {
|
|||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int CmdEMV(const char *Cmd)
|
||||
{
|
||||
int CmdEMV(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHelp(const char *Cmd)
|
||||
{
|
||||
int CmdHelp(const char *Cmd) {
|
||||
CmdsHelp(CommandTable);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
|
||||
static struct crypto_backend *crypto_backend;
|
||||
|
||||
static bool crypto_init(void)
|
||||
{
|
||||
static bool crypto_init(void) {
|
||||
if (crypto_backend)
|
||||
return true;
|
||||
|
||||
|
@ -37,8 +36,7 @@ static bool crypto_init(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
struct crypto_hash *crypto_hash_open(enum crypto_algo_hash hash)
|
||||
{
|
||||
struct crypto_hash *crypto_hash_open(enum crypto_algo_hash hash) {
|
||||
struct crypto_hash *ch;
|
||||
|
||||
if (!crypto_init())
|
||||
|
@ -51,28 +49,23 @@ struct crypto_hash *crypto_hash_open(enum crypto_algo_hash hash)
|
|||
return ch;
|
||||
}
|
||||
|
||||
void crypto_hash_close(struct crypto_hash *ch)
|
||||
{
|
||||
void crypto_hash_close(struct crypto_hash *ch) {
|
||||
ch->close(ch);
|
||||
}
|
||||
|
||||
void crypto_hash_write(struct crypto_hash *ch, const unsigned char *buf, size_t len)
|
||||
{
|
||||
void crypto_hash_write(struct crypto_hash *ch, const unsigned char *buf, size_t len) {
|
||||
ch->write(ch, buf, len);
|
||||
}
|
||||
|
||||
unsigned char *crypto_hash_read(struct crypto_hash *ch)
|
||||
{
|
||||
unsigned char *crypto_hash_read(struct crypto_hash *ch) {
|
||||
return ch->read(ch);
|
||||
}
|
||||
|
||||
size_t crypto_hash_get_size(const struct crypto_hash *ch)
|
||||
{
|
||||
size_t crypto_hash_get_size(const struct crypto_hash *ch) {
|
||||
return ch->get_size(ch);
|
||||
}
|
||||
|
||||
struct crypto_pk *crypto_pk_open(enum crypto_algo_pk pk, ...)
|
||||
{
|
||||
struct crypto_pk *crypto_pk_open(enum crypto_algo_pk pk, ...) {
|
||||
struct crypto_pk *cp;
|
||||
va_list vl;
|
||||
|
||||
|
@ -89,8 +82,7 @@ struct crypto_pk *crypto_pk_open(enum crypto_algo_pk pk, ...)
|
|||
return cp;
|
||||
}
|
||||
|
||||
struct crypto_pk *crypto_pk_open_priv(enum crypto_algo_pk pk, ...)
|
||||
{
|
||||
struct crypto_pk *crypto_pk_open_priv(enum crypto_algo_pk pk, ...) {
|
||||
struct crypto_pk *cp;
|
||||
va_list vl;
|
||||
|
||||
|
@ -110,8 +102,7 @@ struct crypto_pk *crypto_pk_open_priv(enum crypto_algo_pk pk, ...)
|
|||
return cp;
|
||||
}
|
||||
|
||||
struct crypto_pk *crypto_pk_genkey(enum crypto_algo_pk pk, ...)
|
||||
{
|
||||
struct crypto_pk *crypto_pk_genkey(enum crypto_algo_pk pk, ...) {
|
||||
struct crypto_pk *cp;
|
||||
va_list vl;
|
||||
|
||||
|
@ -131,18 +122,15 @@ struct crypto_pk *crypto_pk_genkey(enum crypto_algo_pk pk, ...)
|
|||
return cp;
|
||||
}
|
||||
|
||||
void crypto_pk_close(struct crypto_pk *cp)
|
||||
{
|
||||
void crypto_pk_close(struct crypto_pk *cp) {
|
||||
cp->close(cp);
|
||||
}
|
||||
|
||||
unsigned char *crypto_pk_encrypt(const struct crypto_pk *cp, const unsigned char *buf, size_t len, size_t *clen)
|
||||
{
|
||||
unsigned char *crypto_pk_encrypt(const struct crypto_pk *cp, const unsigned char *buf, size_t len, size_t *clen) {
|
||||
return cp->encrypt(cp, buf, len, clen);
|
||||
}
|
||||
|
||||
unsigned char *crypto_pk_decrypt(const struct crypto_pk *cp, const unsigned char *buf, size_t len, size_t *clen)
|
||||
{
|
||||
unsigned char *crypto_pk_decrypt(const struct crypto_pk *cp, const unsigned char *buf, size_t len, size_t *clen) {
|
||||
if (!cp->decrypt) {
|
||||
*clen = 0;
|
||||
|
||||
|
@ -152,24 +140,21 @@ unsigned char *crypto_pk_decrypt(const struct crypto_pk *cp, const unsigned char
|
|||
return cp->decrypt(cp, buf, len, clen);
|
||||
}
|
||||
|
||||
enum crypto_algo_pk crypto_pk_get_algo(const struct crypto_pk *cp)
|
||||
{
|
||||
enum crypto_algo_pk crypto_pk_get_algo(const struct crypto_pk *cp) {
|
||||
if (!cp)
|
||||
return PK_INVALID;
|
||||
|
||||
return cp->algo;
|
||||
}
|
||||
|
||||
size_t crypto_pk_get_nbits(const struct crypto_pk *cp)
|
||||
{
|
||||
size_t crypto_pk_get_nbits(const struct crypto_pk *cp) {
|
||||
if (!cp->get_nbits)
|
||||
return 0;
|
||||
|
||||
return cp->get_nbits(cp);
|
||||
}
|
||||
|
||||
unsigned char *crypto_pk_get_parameter(const struct crypto_pk *cp, unsigned param, size_t *plen)
|
||||
{
|
||||
unsigned char *crypto_pk_get_parameter(const struct crypto_pk *cp, unsigned param, size_t *plen) {
|
||||
*plen = 0;
|
||||
|
||||
if (!cp->get_parameter)
|
||||
|
|
|
@ -34,22 +34,19 @@ struct crypto_hash_polarssl {
|
|||
mbedtls_sha1_context ctx;
|
||||
};
|
||||
|
||||
static void crypto_hash_polarssl_close(struct crypto_hash *_ch)
|
||||
{
|
||||
static void crypto_hash_polarssl_close(struct crypto_hash *_ch) {
|
||||
struct crypto_hash_polarssl *ch = (struct crypto_hash_polarssl *)_ch;
|
||||
|
||||
free(ch);
|
||||
}
|
||||
|
||||
static void crypto_hash_polarssl_write(struct crypto_hash *_ch, const unsigned char *buf, size_t len)
|
||||
{
|
||||
static void crypto_hash_polarssl_write(struct crypto_hash *_ch, const unsigned char *buf, size_t len) {
|
||||
struct crypto_hash_polarssl *ch = (struct crypto_hash_polarssl *)_ch;
|
||||
|
||||
mbedtls_sha1_update(&(ch->ctx), buf, len);
|
||||
}
|
||||
|
||||
static unsigned char *crypto_hash_polarssl_read(struct crypto_hash *_ch)
|
||||
{
|
||||
static unsigned char *crypto_hash_polarssl_read(struct crypto_hash *_ch) {
|
||||
struct crypto_hash_polarssl *ch = (struct crypto_hash_polarssl *)_ch;
|
||||
|
||||
static unsigned char sha1sum[20];
|
||||
|
@ -57,16 +54,14 @@ static unsigned char *crypto_hash_polarssl_read(struct crypto_hash *_ch)
|
|||
return sha1sum;
|
||||
}
|
||||
|
||||
static size_t crypto_hash_polarssl_get_size(const struct crypto_hash *ch)
|
||||
{
|
||||
static size_t crypto_hash_polarssl_get_size(const struct crypto_hash *ch) {
|
||||
if (ch->algo == HASH_SHA_1)
|
||||
return 20;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct crypto_hash *crypto_hash_polarssl_open(enum crypto_algo_hash hash)
|
||||
{
|
||||
static struct crypto_hash *crypto_hash_polarssl_open(enum crypto_algo_hash hash) {
|
||||
if (hash != HASH_SHA_1)
|
||||
return NULL;
|
||||
|
||||
|
@ -87,8 +82,7 @@ struct crypto_pk_polarssl {
|
|||
mbedtls_rsa_context ctx;
|
||||
};
|
||||
|
||||
static struct crypto_pk *crypto_pk_polarssl_open_rsa(va_list vl)
|
||||
{
|
||||
static struct crypto_pk *crypto_pk_polarssl_open_rsa(va_list vl) {
|
||||
struct crypto_pk_polarssl *cp = malloc(sizeof(*cp));
|
||||
memset(cp, 0x00, sizeof(*cp));
|
||||
|
||||
|
@ -113,8 +107,7 @@ static struct crypto_pk *crypto_pk_polarssl_open_rsa(va_list vl)
|
|||
return &cp->cp;
|
||||
}
|
||||
|
||||
static struct crypto_pk *crypto_pk_polarssl_open_priv_rsa(va_list vl)
|
||||
{
|
||||
static struct crypto_pk *crypto_pk_polarssl_open_priv_rsa(va_list vl) {
|
||||
struct crypto_pk_polarssl *cp = malloc(sizeof(*cp));
|
||||
memset(cp, 0x00, sizeof(*cp));
|
||||
char *mod = va_arg(vl, char *);
|
||||
|
@ -158,8 +151,7 @@ static struct crypto_pk *crypto_pk_polarssl_open_priv_rsa(va_list vl)
|
|||
return &cp->cp;
|
||||
}
|
||||
|
||||
static int myrand(void *rng_state, unsigned char *output, size_t len)
|
||||
{
|
||||
static int myrand(void *rng_state, unsigned char *output, size_t len) {
|
||||
size_t i;
|
||||
|
||||
if (rng_state != NULL)
|
||||
|
@ -172,8 +164,7 @@ static int myrand(void *rng_state, unsigned char *output, size_t len)
|
|||
}
|
||||
|
||||
|
||||
static struct crypto_pk *crypto_pk_polarssl_genkey_rsa(va_list vl)
|
||||
{
|
||||
static struct crypto_pk *crypto_pk_polarssl_genkey_rsa(va_list vl) {
|
||||
struct crypto_pk_polarssl *cp = malloc(sizeof(*cp));
|
||||
memset(cp, 0x00, sizeof(*cp));
|
||||
|
||||
|
@ -194,16 +185,14 @@ static struct crypto_pk *crypto_pk_polarssl_genkey_rsa(va_list vl)
|
|||
return &cp->cp;
|
||||
}
|
||||
|
||||
static void crypto_pk_polarssl_close(struct crypto_pk *_cp)
|
||||
{
|
||||
static void crypto_pk_polarssl_close(struct crypto_pk *_cp) {
|
||||
struct crypto_pk_polarssl *cp = (struct crypto_pk_polarssl *)_cp;
|
||||
|
||||
mbedtls_rsa_free(&cp->ctx);
|
||||
free(cp);
|
||||
}
|
||||
|
||||
static unsigned char *crypto_pk_polarssl_encrypt(const struct crypto_pk *_cp, const unsigned char *buf, size_t len, size_t *clen)
|
||||
{
|
||||
static unsigned char *crypto_pk_polarssl_encrypt(const struct crypto_pk *_cp, const unsigned char *buf, size_t len, size_t *clen) {
|
||||
struct crypto_pk_polarssl *cp = (struct crypto_pk_polarssl *)_cp;
|
||||
int res;
|
||||
unsigned char *result;
|
||||
|
@ -229,8 +218,7 @@ static unsigned char *crypto_pk_polarssl_encrypt(const struct crypto_pk *_cp, co
|
|||
return result;
|
||||
}
|
||||
|
||||
static unsigned char *crypto_pk_polarssl_decrypt(const struct crypto_pk *_cp, const unsigned char *buf, size_t len, size_t *clen)
|
||||
{
|
||||
static unsigned char *crypto_pk_polarssl_decrypt(const struct crypto_pk *_cp, const unsigned char *buf, size_t len, size_t *clen) {
|
||||
struct crypto_pk_polarssl *cp = (struct crypto_pk_polarssl *)_cp;
|
||||
int res;
|
||||
unsigned char *result;
|
||||
|
@ -256,16 +244,14 @@ static unsigned char *crypto_pk_polarssl_decrypt(const struct crypto_pk *_cp, co
|
|||
return result;
|
||||
}
|
||||
|
||||
static size_t crypto_pk_polarssl_get_nbits(const struct crypto_pk *_cp)
|
||||
{
|
||||
static size_t crypto_pk_polarssl_get_nbits(const struct crypto_pk *_cp) {
|
||||
struct crypto_pk_polarssl *cp = (struct crypto_pk_polarssl *)_cp;
|
||||
|
||||
return cp->ctx.len * 8;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned char *crypto_pk_polarssl_get_parameter(const struct crypto_pk *_cp, unsigned param, size_t *plen)
|
||||
{
|
||||
static unsigned char *crypto_pk_polarssl_get_parameter(const struct crypto_pk *_cp, unsigned param, size_t *plen) {
|
||||
struct crypto_pk_polarssl *cp = (struct crypto_pk_polarssl *)_cp;
|
||||
unsigned char *result = NULL;
|
||||
switch (param) {
|
||||
|
@ -291,8 +277,7 @@ static unsigned char *crypto_pk_polarssl_get_parameter(const struct crypto_pk *_
|
|||
return result;
|
||||
}
|
||||
|
||||
static struct crypto_pk *crypto_pk_polarssl_open(enum crypto_algo_pk pk, va_list vl)
|
||||
{
|
||||
static struct crypto_pk *crypto_pk_polarssl_open(enum crypto_algo_pk pk, va_list vl) {
|
||||
struct crypto_pk *cp;
|
||||
|
||||
if (pk == PK_RSA)
|
||||
|
@ -308,8 +293,7 @@ static struct crypto_pk *crypto_pk_polarssl_open(enum crypto_algo_pk pk, va_list
|
|||
return cp;
|
||||
}
|
||||
|
||||
static struct crypto_pk *crypto_pk_polarssl_open_priv(enum crypto_algo_pk pk, va_list vl)
|
||||
{
|
||||
static struct crypto_pk *crypto_pk_polarssl_open_priv(enum crypto_algo_pk pk, va_list vl) {
|
||||
struct crypto_pk *cp;
|
||||
|
||||
if (pk == PK_RSA)
|
||||
|
@ -326,8 +310,7 @@ static struct crypto_pk *crypto_pk_polarssl_open_priv(enum crypto_algo_pk pk, va
|
|||
return cp;
|
||||
}
|
||||
|
||||
static struct crypto_pk *crypto_pk_polarssl_genkey(enum crypto_algo_pk pk, va_list vl)
|
||||
{
|
||||
static struct crypto_pk *crypto_pk_polarssl_genkey(enum crypto_algo_pk pk, va_list vl) {
|
||||
struct crypto_pk *cp;
|
||||
|
||||
if (pk == PK_RSA)
|
||||
|
@ -351,7 +334,6 @@ static struct crypto_backend crypto_polarssl_backend = {
|
|||
.pk_genkey = crypto_pk_polarssl_genkey,
|
||||
};
|
||||
|
||||
struct crypto_backend *crypto_polarssl_init(void)
|
||||
{
|
||||
struct crypto_backend *crypto_polarssl_init(void) {
|
||||
return &crypto_polarssl_backend;
|
||||
}
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static size_t dol_calculate_len(const struct tlv *tlv, size_t data_len)
|
||||
{
|
||||
static size_t dol_calculate_len(const struct tlv *tlv, size_t data_len) {
|
||||
if (!tlv)
|
||||
return 0;
|
||||
|
||||
|
@ -47,8 +46,7 @@ static size_t dol_calculate_len(const struct tlv *tlv, size_t data_len)
|
|||
return count;
|
||||
}
|
||||
|
||||
struct tlv *dol_process(const struct tlv *tlv, const struct tlvdb *tlvdb, tlv_tag_t tag)
|
||||
{
|
||||
struct tlv *dol_process(const struct tlv *tlv, const struct tlvdb *tlvdb, tlv_tag_t tag) {
|
||||
size_t res_len;
|
||||
if (!tlv || !(res_len = dol_calculate_len(tlv, 0))) {
|
||||
struct tlv *res_tlv = malloc(sizeof(*res_tlv));
|
||||
|
@ -97,8 +95,7 @@ struct tlv *dol_process(const struct tlv *tlv, const struct tlvdb *tlvdb, tlv_ta
|
|||
return res_tlv;
|
||||
}
|
||||
|
||||
struct tlvdb *dol_parse(const struct tlv *tlv, const unsigned char *data, size_t data_len)
|
||||
{
|
||||
struct tlvdb *dol_parse(const struct tlv *tlv, const unsigned char *data, size_t data_len) {
|
||||
if (!tlv)
|
||||
return NULL;
|
||||
|
||||
|
|
|
@ -22,8 +22,7 @@
|
|||
|
||||
#define PRINT_INDENT(level) {for (int i = 0; i < (level); i++) fprintf(f, " ");}
|
||||
|
||||
void dump_buffer_simple(const unsigned char *ptr, size_t len, FILE *f)
|
||||
{
|
||||
void dump_buffer_simple(const unsigned char *ptr, size_t len, FILE *f) {
|
||||
int i;
|
||||
|
||||
if (!f)
|
||||
|
@ -33,8 +32,7 @@ void dump_buffer_simple(const unsigned char *ptr, size_t len, FILE *f)
|
|||
fprintf(f, "%s%02hhX", i ? " " : "", ptr[i]);
|
||||
}
|
||||
|
||||
void dump_buffer(const unsigned char *ptr, size_t len, FILE *f, int level)
|
||||
{
|
||||
void dump_buffer(const unsigned char *ptr, size_t len, FILE *f, int level) {
|
||||
int i, j;
|
||||
|
||||
if (!f)
|
||||
|
|
|
@ -40,8 +40,7 @@
|
|||
|
||||
#define TOHEX(v) ((v) < 10 ? (v) + '0' : (v) - 10 + 'a')
|
||||
|
||||
static ssize_t emv_pk_read_bin(char *buf, unsigned char *bin, size_t size, size_t *read)
|
||||
{
|
||||
static ssize_t emv_pk_read_bin(char *buf, unsigned char *bin, size_t size, size_t *read) {
|
||||
size_t left = size;
|
||||
char *p = buf;
|
||||
while (*p && *p == ' ')
|
||||
|
@ -79,8 +78,7 @@ static ssize_t emv_pk_read_bin(char *buf, unsigned char *bin, size_t size, size_
|
|||
return (p - buf);
|
||||
}
|
||||
|
||||
static ssize_t emv_pk_read_ymv(char *buf, unsigned *ymv)
|
||||
{
|
||||
static ssize_t emv_pk_read_ymv(char *buf, unsigned *ymv) {
|
||||
int i;
|
||||
unsigned char temp[3];
|
||||
char *p = buf;
|
||||
|
@ -116,8 +114,7 @@ static ssize_t emv_pk_read_ymv(char *buf, unsigned *ymv)
|
|||
return (p - buf);
|
||||
}
|
||||
|
||||
static ssize_t emv_pk_read_string(char *buf, char *str, size_t size)
|
||||
{
|
||||
static ssize_t emv_pk_read_string(char *buf, char *str, size_t size) {
|
||||
char *p = buf;
|
||||
while (*p && *p == ' ')
|
||||
p++;
|
||||
|
@ -144,8 +141,7 @@ static ssize_t emv_pk_read_string(char *buf, char *str, size_t size)
|
|||
}
|
||||
|
||||
|
||||
struct emv_pk *emv_pk_parse_pk(char *buf)
|
||||
{
|
||||
struct emv_pk *emv_pk_parse_pk(char *buf) {
|
||||
struct emv_pk *r = calloc(1, sizeof(*r));
|
||||
ssize_t l;
|
||||
char temp[10];
|
||||
|
@ -209,8 +205,7 @@ out:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static size_t emv_pk_write_bin(char *out, size_t outlen, const unsigned char *buf, size_t len)
|
||||
{
|
||||
static size_t emv_pk_write_bin(char *out, size_t outlen, const unsigned char *buf, size_t len) {
|
||||
int i;
|
||||
size_t pos = 0;
|
||||
|
||||
|
@ -231,8 +226,7 @@ static size_t emv_pk_write_bin(char *out, size_t outlen, const unsigned char *bu
|
|||
return pos;
|
||||
}
|
||||
|
||||
static size_t emv_pk_write_str(char *out, size_t outlen, const char *str)
|
||||
{
|
||||
static size_t emv_pk_write_str(char *out, size_t outlen, const char *str) {
|
||||
size_t len = strlen(str);
|
||||
|
||||
if (len == 0)
|
||||
|
@ -245,8 +239,7 @@ static size_t emv_pk_write_str(char *out, size_t outlen, const char *str)
|
|||
return len;
|
||||
}
|
||||
|
||||
char *emv_pk_dump_pk(const struct emv_pk *pk)
|
||||
{
|
||||
char *emv_pk_dump_pk(const struct emv_pk *pk) {
|
||||
size_t outsize = 1024; /* should be enough */
|
||||
char *out = malloc(outsize); /* should be enough */
|
||||
size_t outpos = 0;
|
||||
|
@ -330,8 +323,7 @@ err:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
bool emv_pk_verify(const struct emv_pk *pk)
|
||||
{
|
||||
bool emv_pk_verify(const struct emv_pk *pk) {
|
||||
struct crypto_hash *ch = crypto_hash_open(pk->hash_algo);
|
||||
if (!ch)
|
||||
return false;
|
||||
|
@ -355,8 +347,7 @@ bool emv_pk_verify(const struct emv_pk *pk)
|
|||
return r;
|
||||
}
|
||||
|
||||
struct emv_pk *emv_pk_new(size_t modlen, size_t explen)
|
||||
{
|
||||
struct emv_pk *emv_pk_new(size_t modlen, size_t explen) {
|
||||
struct emv_pk *pk;
|
||||
|
||||
/* Not supported ATM */
|
||||
|
@ -379,8 +370,7 @@ struct emv_pk *emv_pk_new(size_t modlen, size_t explen)
|
|||
return pk;
|
||||
}
|
||||
|
||||
void emv_pk_free(struct emv_pk *pk)
|
||||
{
|
||||
void emv_pk_free(struct emv_pk *pk) {
|
||||
if (!pk)
|
||||
return;
|
||||
|
||||
|
@ -390,8 +380,7 @@ void emv_pk_free(struct emv_pk *pk)
|
|||
|
||||
static struct emv_pk *emv_pk_get_ca_pk_from_file(const char *fname,
|
||||
const unsigned char *rid,
|
||||
unsigned char idx)
|
||||
{
|
||||
unsigned char idx) {
|
||||
if (!fname)
|
||||
return NULL;
|
||||
|
||||
|
@ -424,8 +413,7 @@ static struct emv_pk *emv_pk_get_ca_pk_from_file(const char *fname,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char *emv_pk_get_ca_pk_file(const char *dirname, const unsigned char *rid, unsigned char idx)
|
||||
{
|
||||
char *emv_pk_get_ca_pk_file(const char *dirname, const unsigned char *rid, unsigned char idx) {
|
||||
if (!dirname)
|
||||
dirname = ".";//openemv_config_get_str("capk.dir", NULL);
|
||||
|
||||
|
@ -445,8 +433,7 @@ char *emv_pk_get_ca_pk_file(const char *dirname, const unsigned char *rid, unsig
|
|||
return filename;
|
||||
}
|
||||
|
||||
char *emv_pk_get_ca_pk_rid_file(const char *dirname, const unsigned char *rid)
|
||||
{
|
||||
char *emv_pk_get_ca_pk_rid_file(const char *dirname, const unsigned char *rid) {
|
||||
if (!dirname)
|
||||
dirname = "."; //openemv_config_get_str("capk.dir", NULL);
|
||||
|
||||
|
@ -465,8 +452,7 @@ char *emv_pk_get_ca_pk_rid_file(const char *dirname, const unsigned char *rid)
|
|||
return filename;
|
||||
}
|
||||
|
||||
struct emv_pk *emv_pk_get_ca_pk(const unsigned char *rid, unsigned char idx)
|
||||
{
|
||||
struct emv_pk *emv_pk_get_ca_pk(const unsigned char *rid, unsigned char idx) {
|
||||
struct emv_pk *pk = NULL;
|
||||
|
||||
/* if (!pk) {
|
||||
|
|
|
@ -28,8 +28,7 @@
|
|||
#include <stdarg.h>
|
||||
|
||||
static bool strictExecution = true;
|
||||
void PKISetStrictExecution(bool se)
|
||||
{
|
||||
void PKISetStrictExecution(bool se) {
|
||||
strictExecution = se;
|
||||
}
|
||||
|
||||
|
@ -44,8 +43,7 @@ static unsigned char *emv_pki_decode_message(const struct emv_pk *enc_pk,
|
|||
const struct tlv *cert_tlv,
|
||||
int tlv_count,
|
||||
... /* A list of tlv pointers */
|
||||
)
|
||||
{
|
||||
) {
|
||||
struct crypto_pk *kcp;
|
||||
unsigned char *data;
|
||||
size_t data_len;
|
||||
|
@ -133,8 +131,7 @@ static unsigned char *emv_pki_decode_message(const struct emv_pk *enc_pk,
|
|||
return data;
|
||||
}
|
||||
|
||||
static unsigned emv_cn_length(const struct tlv *tlv)
|
||||
{
|
||||
static unsigned emv_cn_length(const struct tlv *tlv) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < tlv->len; i++) {
|
||||
|
@ -150,8 +147,7 @@ static unsigned emv_cn_length(const struct tlv *tlv)
|
|||
return 2 * tlv->len;
|
||||
}
|
||||
|
||||
static unsigned char emv_cn_get(const struct tlv *tlv, unsigned pos)
|
||||
{
|
||||
static unsigned char emv_cn_get(const struct tlv *tlv, unsigned pos) {
|
||||
if (pos > tlv->len * 2)
|
||||
return 0xf;
|
||||
|
||||
|
@ -172,8 +168,7 @@ static struct emv_pk *emv_pki_decode_key_ex(const struct emv_pk *enc_pk,
|
|||
const struct tlv *add_tlv,
|
||||
const struct tlv *sdatl_tlv,
|
||||
bool showData
|
||||
)
|
||||
{
|
||||
) {
|
||||
size_t pan_length;
|
||||
unsigned char *data;
|
||||
size_t data_len;
|
||||
|
@ -223,7 +218,7 @@ static struct emv_pk *emv_pki_decode_key_ex(const struct emv_pk *enc_pk,
|
|||
unsigned pan2_len = emv_cn_length(&pan2_tlv);
|
||||
|
||||
if (((msgtype == 2) && (pan2_len < 4 || pan2_len > pan_len)) ||
|
||||
((msgtype == 4) && (pan2_len != pan_len))) {
|
||||
((msgtype == 4) && (pan2_len != pan_len))) {
|
||||
printf("ERROR: Invalid PAN lengths\n");
|
||||
free(data);
|
||||
|
||||
|
@ -285,13 +280,11 @@ static struct emv_pk *emv_pki_decode_key(const struct emv_pk *enc_pk,
|
|||
const struct tlv *rem_tlv,
|
||||
const struct tlv *add_tlv,
|
||||
const struct tlv *sdatl_tlv
|
||||
)
|
||||
{
|
||||
) {
|
||||
return emv_pki_decode_key_ex(enc_pk, msgtype, pan_tlv, cert_tlv, exp_tlv, rem_tlv, add_tlv, sdatl_tlv, false);
|
||||
}
|
||||
|
||||
struct emv_pk *emv_pki_recover_issuer_cert(const struct emv_pk *pk, struct tlvdb *db)
|
||||
{
|
||||
struct emv_pk *emv_pki_recover_issuer_cert(const struct emv_pk *pk, struct tlvdb *db) {
|
||||
return emv_pki_decode_key(pk, 2,
|
||||
tlvdb_get(db, 0x5a, NULL),
|
||||
tlvdb_get(db, 0x90, NULL),
|
||||
|
@ -301,8 +294,7 @@ struct emv_pk *emv_pki_recover_issuer_cert(const struct emv_pk *pk, struct tlvdb
|
|||
NULL);
|
||||
}
|
||||
|
||||
struct emv_pk *emv_pki_recover_icc_cert(const struct emv_pk *pk, struct tlvdb *db, const struct tlv *sda_tlv)
|
||||
{
|
||||
struct emv_pk *emv_pki_recover_icc_cert(const struct emv_pk *pk, struct tlvdb *db, const struct tlv *sda_tlv) {
|
||||
size_t sdatl_len;
|
||||
unsigned char *sdatl = emv_pki_sdatl_fill(db, &sdatl_len);
|
||||
struct tlv sda_tdata = {
|
||||
|
@ -323,8 +315,7 @@ struct emv_pk *emv_pki_recover_icc_cert(const struct emv_pk *pk, struct tlvdb *d
|
|||
return res;
|
||||
}
|
||||
|
||||
struct emv_pk *emv_pki_recover_icc_pe_cert(const struct emv_pk *pk, struct tlvdb *db)
|
||||
{
|
||||
struct emv_pk *emv_pki_recover_icc_pe_cert(const struct emv_pk *pk, struct tlvdb *db) {
|
||||
return emv_pki_decode_key(pk, 4,
|
||||
tlvdb_get(db, 0x5a, NULL),
|
||||
tlvdb_get(db, 0x9f2d, NULL),
|
||||
|
@ -334,8 +325,7 @@ struct emv_pk *emv_pki_recover_icc_pe_cert(const struct emv_pk *pk, struct tlvdb
|
|||
NULL);
|
||||
}
|
||||
|
||||
unsigned char *emv_pki_sdatl_fill(const struct tlvdb *db, size_t *sdatl_len)
|
||||
{
|
||||
unsigned char *emv_pki_sdatl_fill(const struct tlvdb *db, size_t *sdatl_len) {
|
||||
uint8_t buf[2048] = {0};
|
||||
size_t len = 0;
|
||||
|
||||
|
@ -365,8 +355,7 @@ unsigned char *emv_pki_sdatl_fill(const struct tlvdb *db, size_t *sdatl_len)
|
|||
}
|
||||
|
||||
|
||||
struct tlvdb *emv_pki_recover_dac_ex(const struct emv_pk *enc_pk, const struct tlvdb *db, const struct tlv *sda_tlv, bool showData)
|
||||
{
|
||||
struct tlvdb *emv_pki_recover_dac_ex(const struct emv_pk *enc_pk, const struct tlvdb *db, const struct tlv *sda_tlv, bool showData) {
|
||||
size_t data_len;
|
||||
|
||||
// Static Data Authentication Tag List
|
||||
|
@ -401,18 +390,15 @@ struct tlvdb *emv_pki_recover_dac_ex(const struct emv_pk *enc_pk, const struct t
|
|||
|
||||
return dac_db;
|
||||
}
|
||||
struct tlvdb *emv_pki_recover_dac(const struct emv_pk *enc_pk, const struct tlvdb *db, const struct tlv *sda_tlv)
|
||||
{
|
||||
struct tlvdb *emv_pki_recover_dac(const struct emv_pk *enc_pk, const struct tlvdb *db, const struct tlv *sda_tlv) {
|
||||
return emv_pki_recover_dac_ex(enc_pk, db, sda_tlv, false);
|
||||
}
|
||||
|
||||
struct tlvdb *emv_pki_recover_idn(const struct emv_pk *enc_pk, const struct tlvdb *db, const struct tlv *dyn_tlv)
|
||||
{
|
||||
struct tlvdb *emv_pki_recover_idn(const struct emv_pk *enc_pk, const struct tlvdb *db, const struct tlv *dyn_tlv) {
|
||||
return emv_pki_recover_idn_ex(enc_pk, db, dyn_tlv, false);
|
||||
}
|
||||
|
||||
struct tlvdb *emv_pki_recover_idn_ex(const struct emv_pk *enc_pk, const struct tlvdb *db, const struct tlv *dyn_tlv, bool showData)
|
||||
{
|
||||
struct tlvdb *emv_pki_recover_idn_ex(const struct emv_pk *enc_pk, const struct tlvdb *db, const struct tlv *dyn_tlv, bool showData) {
|
||||
size_t data_len;
|
||||
unsigned char *data = emv_pki_decode_message(enc_pk, 5, &data_len,
|
||||
tlvdb_get(db, 0x9f4b, NULL),
|
||||
|
@ -447,8 +433,7 @@ struct tlvdb *emv_pki_recover_idn_ex(const struct emv_pk *enc_pk, const struct t
|
|||
return idn_db;
|
||||
}
|
||||
|
||||
struct tlvdb *emv_pki_recover_atc_ex(const struct emv_pk *enc_pk, const struct tlvdb *db, bool showData)
|
||||
{
|
||||
struct tlvdb *emv_pki_recover_atc_ex(const struct emv_pk *enc_pk, const struct tlvdb *db, bool showData) {
|
||||
size_t data_len;
|
||||
unsigned char *data = emv_pki_decode_message(enc_pk, 5, &data_len,
|
||||
tlvdb_get(db, 0x9f4b, NULL),
|
||||
|
@ -486,8 +471,7 @@ struct tlvdb *emv_pki_recover_atc_ex(const struct emv_pk *enc_pk, const struct t
|
|||
return atc_db;
|
||||
}
|
||||
|
||||
static bool tlv_hash(void *data, const struct tlv *tlv, int level, bool is_leaf)
|
||||
{
|
||||
static bool tlv_hash(void *data, const struct tlv *tlv, int level, bool is_leaf) {
|
||||
struct crypto_hash *ch = data;
|
||||
size_t tag_len;
|
||||
unsigned char *tag;
|
||||
|
@ -509,8 +493,7 @@ struct tlvdb *emv_pki_perform_cda(const struct emv_pk *enc_pk, const struct tlvd
|
|||
const struct tlvdb *this_db,
|
||||
const struct tlv *pdol_data_tlv,
|
||||
const struct tlv *crm1_tlv,
|
||||
const struct tlv *crm2_tlv)
|
||||
{
|
||||
const struct tlv *crm2_tlv) {
|
||||
return emv_pki_perform_cda_ex(enc_pk, db, this_db, pdol_data_tlv, crm1_tlv, crm2_tlv, false);
|
||||
}
|
||||
struct tlvdb *emv_pki_perform_cda_ex(const struct emv_pk *enc_pk, const struct tlvdb *db,
|
||||
|
@ -518,8 +501,7 @@ struct tlvdb *emv_pki_perform_cda_ex(const struct emv_pk *enc_pk, const struct t
|
|||
const struct tlv *pdol_data_tlv, // PDOL
|
||||
const struct tlv *crm1_tlv, // CDOL1
|
||||
const struct tlv *crm2_tlv, // CDOL2
|
||||
bool showData)
|
||||
{
|
||||
bool showData) {
|
||||
const struct tlv *un_tlv = tlvdb_get(db, 0x9f37, NULL);
|
||||
const struct tlv *cid_tlv = tlvdb_get(this_db, 0x9f27, NULL);
|
||||
|
||||
|
|
|
@ -26,8 +26,7 @@
|
|||
|
||||
struct emv_pk *emv_pki_make_ca(const struct crypto_pk *cp,
|
||||
const unsigned char *rid, unsigned char index,
|
||||
unsigned int expire, enum crypto_algo_hash hash_algo)
|
||||
{
|
||||
unsigned int expire, enum crypto_algo_hash hash_algo) {
|
||||
size_t modlen, explen;
|
||||
unsigned char *mod, *exp;
|
||||
|
||||
|
@ -85,8 +84,7 @@ static struct tlvdb *emv_pki_sign_message(const struct crypto_pk *cp,
|
|||
tlv_tag_t cert_tag, tlv_tag_t rem_tag,
|
||||
const unsigned char *msg, size_t msg_len,
|
||||
... /* A list of tlv pointers, end with NULL */
|
||||
)
|
||||
{
|
||||
) {
|
||||
size_t tmp_len = (crypto_pk_get_nbits(cp) + 7) / 8;
|
||||
unsigned char *tmp = malloc(tmp_len);
|
||||
if (!tmp)
|
||||
|
@ -175,8 +173,7 @@ static struct tlvdb *emv_pki_sign_key(const struct crypto_pk *cp,
|
|||
tlv_tag_t exp_tag,
|
||||
tlv_tag_t rem_tag,
|
||||
const struct tlv *add_tlv
|
||||
)
|
||||
{
|
||||
) {
|
||||
unsigned pos = 0;
|
||||
unsigned char *msg = malloc(1 + pan_len + 2 + 3 + 1 + 1 + 1 + 1 + ipk->mlen);
|
||||
|
||||
|
@ -219,23 +216,19 @@ static struct tlvdb *emv_pki_sign_key(const struct crypto_pk *cp,
|
|||
return db;
|
||||
}
|
||||
|
||||
struct tlvdb *emv_pki_sign_issuer_cert(const struct crypto_pk *cp, struct emv_pk *issuer_pk)
|
||||
{
|
||||
struct tlvdb *emv_pki_sign_issuer_cert(const struct crypto_pk *cp, struct emv_pk *issuer_pk) {
|
||||
return emv_pki_sign_key(cp, issuer_pk, 2, 4, 0x90, 0x9f32, 0x92, NULL);
|
||||
}
|
||||
|
||||
struct tlvdb *emv_pki_sign_icc_cert(const struct crypto_pk *cp, struct emv_pk *icc_pk, const struct tlv *sda_tlv)
|
||||
{
|
||||
struct tlvdb *emv_pki_sign_icc_cert(const struct crypto_pk *cp, struct emv_pk *icc_pk, const struct tlv *sda_tlv) {
|
||||
return emv_pki_sign_key(cp, icc_pk, 4, 10, 0x9f46, 0x9f47, 0x9f48, sda_tlv);
|
||||
}
|
||||
|
||||
struct tlvdb *emv_pki_sign_icc_pe_cert(const struct crypto_pk *cp, struct emv_pk *icc_pe_pk)
|
||||
{
|
||||
struct tlvdb *emv_pki_sign_icc_pe_cert(const struct crypto_pk *cp, struct emv_pk *icc_pe_pk) {
|
||||
return emv_pki_sign_key(cp, icc_pe_pk, 4, 10, 0x9f2d, 0x9f2e, 0x9f2f, NULL);
|
||||
}
|
||||
|
||||
struct tlvdb *emv_pki_sign_dac(const struct crypto_pk *cp, const struct tlv *dac_tlv, const struct tlv *sda_tlv)
|
||||
{
|
||||
struct tlvdb *emv_pki_sign_dac(const struct crypto_pk *cp, const struct tlv *dac_tlv, const struct tlv *sda_tlv) {
|
||||
unsigned pos = 0;
|
||||
unsigned char *msg = malloc(1 + 1 + dac_tlv->len);
|
||||
|
||||
|
@ -258,8 +251,7 @@ struct tlvdb *emv_pki_sign_dac(const struct crypto_pk *cp, const struct tlv *dac
|
|||
return db;
|
||||
}
|
||||
|
||||
struct tlvdb *emv_pki_sign_idn(const struct crypto_pk *cp, const struct tlv *idn_tlv, const struct tlv *dyn_tlv)
|
||||
{
|
||||
struct tlvdb *emv_pki_sign_idn(const struct crypto_pk *cp, const struct tlv *idn_tlv, const struct tlv *dyn_tlv) {
|
||||
unsigned pos = 0;
|
||||
unsigned char *msg = malloc(1 + 1 + 1 + 1 + idn_tlv->len);
|
||||
|
||||
|
|
|
@ -29,8 +29,7 @@ static uint8_t g_primes[ROCA_PRINTS_LENGTH] = {
|
|||
|
||||
mbedtls_mpi g_prints[ROCA_PRINTS_LENGTH];
|
||||
|
||||
void rocacheck_init(void)
|
||||
{
|
||||
void rocacheck_init(void) {
|
||||
|
||||
for (int i = 0; i < ROCA_PRINTS_LENGTH; i++)
|
||||
mbedtls_mpi_init(&g_prints[i]);
|
||||
|
@ -54,14 +53,12 @@ void rocacheck_init(void)
|
|||
mbedtls_mpi_read_string(&g_prints[16], 10, "126304807362733370595828809000324029340048915994");
|
||||
}
|
||||
|
||||
void rocacheck_cleanup(void)
|
||||
{
|
||||
void rocacheck_cleanup(void) {
|
||||
for (int i = 0; i < ROCA_PRINTS_LENGTH; i++)
|
||||
mbedtls_mpi_free(&g_prints[i]);
|
||||
}
|
||||
|
||||
int bitand_is_zero(mbedtls_mpi *a, mbedtls_mpi *b)
|
||||
{
|
||||
int bitand_is_zero(mbedtls_mpi *a, mbedtls_mpi *b) {
|
||||
|
||||
for (int i = 0; i < mbedtls_mpi_bitlen(a); i++) {
|
||||
|
||||
|
@ -72,8 +69,7 @@ int bitand_is_zero(mbedtls_mpi *a, mbedtls_mpi *b)
|
|||
}
|
||||
|
||||
|
||||
mbedtls_mpi_uint mpi_get_uint(const mbedtls_mpi *X)
|
||||
{
|
||||
mbedtls_mpi_uint mpi_get_uint(const mbedtls_mpi *X) {
|
||||
|
||||
if (X->n == 1 && X->s > 0) {
|
||||
return X->p[0];
|
||||
|
@ -82,8 +78,7 @@ mbedtls_mpi_uint mpi_get_uint(const mbedtls_mpi *X)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void print_mpi(const char *msg, int radix, const mbedtls_mpi *X)
|
||||
{
|
||||
void print_mpi(const char *msg, int radix, const mbedtls_mpi *X) {
|
||||
|
||||
char Xchar[400] = {0};
|
||||
size_t len = 0;
|
||||
|
@ -92,8 +87,7 @@ void print_mpi(const char *msg, int radix, const mbedtls_mpi *X)
|
|||
printf("%s[%ld] %s\n", msg, len, Xchar);
|
||||
}
|
||||
|
||||
bool emv_rocacheck(const unsigned char *buf, size_t buflen, bool verbose)
|
||||
{
|
||||
bool emv_rocacheck(const unsigned char *buf, size_t buflen, bool verbose) {
|
||||
|
||||
mbedtls_mpi t_modulus;
|
||||
mbedtls_mpi_init(&t_modulus);
|
||||
|
@ -144,8 +138,7 @@ cleanup:
|
|||
return ret;
|
||||
}
|
||||
|
||||
int roca_self_test(void)
|
||||
{
|
||||
int roca_self_test(void) {
|
||||
int ret = 0;
|
||||
|
||||
PrintAndLogEx(INFO, "ROCA check vulnerability tests");
|
||||
|
|
|
@ -424,21 +424,18 @@ static const struct emv_tag emv_tags[] = {
|
|||
{ 0xff8106, "Discretionary Data" },
|
||||
};
|
||||
|
||||
static int emv_sort_tag(tlv_tag_t tag)
|
||||
{
|
||||
static int emv_sort_tag(tlv_tag_t tag) {
|
||||
return (int)(tag >= 0x100 ? tag : tag << 8);
|
||||
}
|
||||
|
||||
static int emv_tlv_compare(const void *a, const void *b)
|
||||
{
|
||||
static int emv_tlv_compare(const void *a, const void *b) {
|
||||
const struct tlv *tlv = a;
|
||||
const struct emv_tag *tag = b;
|
||||
|
||||
return emv_sort_tag(tlv->tag) - (emv_sort_tag(tag->tag));
|
||||
}
|
||||
|
||||
static const struct emv_tag *emv_get_tag(const struct tlv *tlv)
|
||||
{
|
||||
static const struct emv_tag *emv_get_tag(const struct tlv *tlv) {
|
||||
struct emv_tag *tag = bsearch(tlv, emv_tags, sizeof(emv_tags) / sizeof(emv_tags[0]),
|
||||
sizeof(emv_tags[0]), emv_tlv_compare);
|
||||
|
||||
|
@ -456,8 +453,7 @@ static const char *bitstrings[] = {
|
|||
"1.......",
|
||||
};
|
||||
|
||||
static void emv_tag_dump_bitmask(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level)
|
||||
{
|
||||
static void emv_tag_dump_bitmask(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level) {
|
||||
const struct emv_tag_bit *bits = tag->data;
|
||||
unsigned bit, byte;
|
||||
|
||||
|
@ -477,8 +473,7 @@ static void emv_tag_dump_bitmask(const struct tlv *tlv, const struct emv_tag *ta
|
|||
}
|
||||
}
|
||||
|
||||
static void emv_tag_dump_dol(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level)
|
||||
{
|
||||
static void emv_tag_dump_dol(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level) {
|
||||
const unsigned char *buf = tlv->value;
|
||||
size_t left = tlv->len;
|
||||
|
||||
|
@ -499,15 +494,13 @@ static void emv_tag_dump_dol(const struct tlv *tlv, const struct emv_tag *tag, F
|
|||
}
|
||||
}
|
||||
|
||||
static void emv_tag_dump_string(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level)
|
||||
{
|
||||
static void emv_tag_dump_string(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level) {
|
||||
fprintf(f, "\tString value '");
|
||||
fwrite(tlv->value, 1, tlv->len, f);
|
||||
fprintf(f, "'\n");
|
||||
}
|
||||
|
||||
static unsigned long emv_value_numeric(const struct tlv *tlv, unsigned start, unsigned end)
|
||||
{
|
||||
static unsigned long emv_value_numeric(const struct tlv *tlv, unsigned start, unsigned end) {
|
||||
unsigned long ret = 0;
|
||||
int i;
|
||||
|
||||
|
@ -537,14 +530,12 @@ static unsigned long emv_value_numeric(const struct tlv *tlv, unsigned start, un
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void emv_tag_dump_numeric(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level)
|
||||
{
|
||||
static void emv_tag_dump_numeric(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level) {
|
||||
PRINT_INDENT(level);
|
||||
fprintf(f, "\tNumeric value %lu\n", emv_value_numeric(tlv, 0, tlv->len * 2));
|
||||
}
|
||||
|
||||
static void emv_tag_dump_yymmdd(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level)
|
||||
{
|
||||
static void emv_tag_dump_yymmdd(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level) {
|
||||
PRINT_INDENT(level);
|
||||
fprintf(f, "\tDate: 20%02ld.%ld.%ld\n",
|
||||
emv_value_numeric(tlv, 0, 2),
|
||||
|
@ -552,14 +543,12 @@ static void emv_tag_dump_yymmdd(const struct tlv *tlv, const struct emv_tag *tag
|
|||
emv_value_numeric(tlv, 4, 6));
|
||||
}
|
||||
|
||||
static uint32_t emv_get_binary(const unsigned char *S)
|
||||
{
|
||||
static uint32_t emv_get_binary(const unsigned char *S) {
|
||||
return (S[0] << 24) | (S[1] << 16) | (S[2] << 8) | (S[3] << 0);
|
||||
}
|
||||
|
||||
// https://github.com/binaryfoo/emv-bertlv/blob/master/src/main/resources/fields/visa-cvr.txt
|
||||
static void emv_tag_dump_cvr(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level)
|
||||
{
|
||||
static void emv_tag_dump_cvr(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level) {
|
||||
if (!tlv || tlv->len < 1) {
|
||||
PRINT_INDENT(level);
|
||||
fprintf(f, "\tINVALID!\n");
|
||||
|
@ -623,8 +612,7 @@ static void emv_tag_dump_cvr(const struct tlv *tlv, const struct emv_tag *tag, F
|
|||
}
|
||||
|
||||
// EMV Book 3
|
||||
static void emv_tag_dump_cid(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level)
|
||||
{
|
||||
static void emv_tag_dump_cid(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level) {
|
||||
if (!tlv || tlv->len < 1) {
|
||||
PRINT_INDENT(level);
|
||||
fprintf(f, "\tINVALID!\n");
|
||||
|
@ -665,8 +653,7 @@ static void emv_tag_dump_cid(const struct tlv *tlv, const struct emv_tag *tag, F
|
|||
}
|
||||
}
|
||||
|
||||
static void emv_tag_dump_cvm_list(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level)
|
||||
{
|
||||
static void emv_tag_dump_cvm_list(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level) {
|
||||
uint32_t X, Y;
|
||||
int i;
|
||||
|
||||
|
@ -764,8 +751,7 @@ static void emv_tag_dump_cvm_list(const struct tlv *tlv, const struct emv_tag *t
|
|||
}
|
||||
}
|
||||
|
||||
static void emv_tag_dump_afl(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level)
|
||||
{
|
||||
static void emv_tag_dump_afl(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level) {
|
||||
if (tlv->len < 4 || tlv->len % 4) {
|
||||
PRINT_INDENT(level);
|
||||
fprintf(f, "\tINVALID!\n");
|
||||
|
@ -778,8 +764,7 @@ static void emv_tag_dump_afl(const struct tlv *tlv, const struct emv_tag *tag, F
|
|||
}
|
||||
}
|
||||
|
||||
bool emv_tag_dump(const struct tlv *tlv, FILE *f, int level)
|
||||
{
|
||||
bool emv_tag_dump(const struct tlv *tlv, FILE *f, int level) {
|
||||
if (!tlv) {
|
||||
fprintf(f, "NULL\n");
|
||||
return false;
|
||||
|
@ -832,8 +817,7 @@ bool emv_tag_dump(const struct tlv *tlv, FILE *f, int level)
|
|||
return true;
|
||||
}
|
||||
|
||||
char *emv_get_tag_name(const struct tlv *tlv)
|
||||
{
|
||||
char *emv_get_tag_name(const struct tlv *tlv) {
|
||||
static char *defstr = "";
|
||||
|
||||
if (!tlv)
|
||||
|
|
|
@ -91,13 +91,11 @@ static const TAIDList AIDlist [] = {
|
|||
static const size_t AIDlistLen = sizeof(AIDlist) / sizeof(TAIDList);
|
||||
|
||||
static bool APDULogging = false;
|
||||
void SetAPDULogging(bool logging)
|
||||
{
|
||||
void SetAPDULogging(bool logging) {
|
||||
APDULogging = logging;
|
||||
}
|
||||
|
||||
enum CardPSVendor GetCardPSVendor(uint8_t *AID, size_t AIDlen)
|
||||
{
|
||||
enum CardPSVendor GetCardPSVendor(uint8_t *AID, size_t AIDlen) {
|
||||
char buf[100] = {0};
|
||||
if (AIDlen < 1)
|
||||
return CV_NA;
|
||||
|
@ -113,8 +111,7 @@ enum CardPSVendor GetCardPSVendor(uint8_t *AID, size_t AIDlen)
|
|||
return CV_NA;
|
||||
}
|
||||
|
||||
static bool print_cb(void *data, const struct tlv *tlv, int level, bool is_leaf)
|
||||
{
|
||||
static bool print_cb(void *data, const struct tlv *tlv, int level, bool is_leaf) {
|
||||
emv_tag_dump(tlv, stdout, level);
|
||||
if (is_leaf) {
|
||||
dump_buffer(tlv->value, tlv->len, stdout, level);
|
||||
|
@ -123,8 +120,7 @@ static bool print_cb(void *data, const struct tlv *tlv, int level, bool is_leaf)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool TLVPrintFromBuffer(uint8_t *data, int datalen)
|
||||
{
|
||||
bool TLVPrintFromBuffer(uint8_t *data, int datalen) {
|
||||
struct tlvdb *t = NULL;
|
||||
t = tlvdb_parse_multi(data, datalen);
|
||||
if (t) {
|
||||
|
@ -139,21 +135,18 @@ bool TLVPrintFromBuffer(uint8_t *data, int datalen)
|
|||
return false;
|
||||
}
|
||||
|
||||
void TLVPrintFromTLVLev(struct tlvdb *tlv, int level)
|
||||
{
|
||||
void TLVPrintFromTLVLev(struct tlvdb *tlv, int level) {
|
||||
if (!tlv)
|
||||
return;
|
||||
|
||||
tlvdb_visit(tlv, print_cb, NULL, level);
|
||||
}
|
||||
|
||||
void TLVPrintFromTLV(struct tlvdb *tlv)
|
||||
{
|
||||
void TLVPrintFromTLV(struct tlvdb *tlv) {
|
||||
TLVPrintFromTLVLev(tlv, 0);
|
||||
}
|
||||
|
||||
void TLVPrintAIDlistFromSelectTLV(struct tlvdb *tlv)
|
||||
{
|
||||
void TLVPrintAIDlistFromSelectTLV(struct tlvdb *tlv) {
|
||||
PrintAndLogEx(NORMAL, "|------------------|--------|-------------------------|");
|
||||
PrintAndLogEx(NORMAL, "| AID |Priority| Name |");
|
||||
PrintAndLogEx(NORMAL, "|------------------|--------|-------------------------|");
|
||||
|
@ -179,8 +172,7 @@ void TLVPrintAIDlistFromSelectTLV(struct tlvdb *tlv)
|
|||
PrintAndLogEx(NORMAL, "|------------------|--------|-------------------------|");
|
||||
}
|
||||
|
||||
struct tlvdb *GetPANFromTrack2(const struct tlv *track2)
|
||||
{
|
||||
struct tlvdb *GetPANFromTrack2(const struct tlv *track2) {
|
||||
char track2Hex[200] = {0};
|
||||
uint8_t PAN[100] = {0};
|
||||
int PANlen = 0;
|
||||
|
@ -207,8 +199,7 @@ struct tlvdb *GetPANFromTrack2(const struct tlv *track2)
|
|||
return tlvdb_fixed(0x5a, PANlen, PAN);
|
||||
}
|
||||
|
||||
struct tlvdb *GetdCVVRawFromTrack2(const struct tlv *track2)
|
||||
{
|
||||
struct tlvdb *GetdCVVRawFromTrack2(const struct tlv *track2) {
|
||||
char track2Hex[200] = {0};
|
||||
char dCVVHex[100] = {0};
|
||||
uint8_t dCVV[100] = {0};
|
||||
|
@ -241,8 +232,7 @@ struct tlvdb *GetdCVVRawFromTrack2(const struct tlv *track2)
|
|||
return tlvdb_fixed(0x02, dCVVlen, dCVV);
|
||||
}
|
||||
|
||||
int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, sAPDU apdu, bool IncludeLe, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv)
|
||||
{
|
||||
int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, sAPDU apdu, bool IncludeLe, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) {
|
||||
uint8_t data[APDU_RES_LEN] = {0};
|
||||
|
||||
*ResultLen = 0;
|
||||
|
@ -315,18 +305,15 @@ int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool LeaveField
|
|||
return 0;
|
||||
}
|
||||
|
||||
int EMVExchange(EMVCommandChannel channel, bool LeaveFieldON, sAPDU apdu, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv)
|
||||
{
|
||||
int EMVExchange(EMVCommandChannel channel, bool LeaveFieldON, sAPDU apdu, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) {
|
||||
return EMVExchangeEx(channel, false, LeaveFieldON, apdu, (channel == ECC_CONTACTLESS), Result, MaxResultLen, ResultLen, sw, tlv);
|
||||
}
|
||||
|
||||
int EMVSelect(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t *AID, size_t AIDLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv)
|
||||
{
|
||||
int EMVSelect(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t *AID, size_t AIDLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) {
|
||||
return EMVExchangeEx(channel, ActivateField, LeaveFieldON, (sAPDU) {0x00, 0xa4, 0x04, 0x00, AIDLen, AID}, (channel == ECC_CONTACTLESS), Result, MaxResultLen, ResultLen, sw, tlv);
|
||||
}
|
||||
|
||||
int EMVSelectPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t PSENum, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw)
|
||||
{
|
||||
int EMVSelectPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t PSENum, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw) {
|
||||
uint8_t buf[APDU_AID_LEN] = {0};
|
||||
*ResultLen = 0;
|
||||
int len = 0;
|
||||
|
@ -348,8 +335,7 @@ int EMVSelectPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldO
|
|||
return res;
|
||||
}
|
||||
|
||||
int EMVSelectWithRetry(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t *AID, size_t AIDLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv)
|
||||
{
|
||||
int EMVSelectWithRetry(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t *AID, size_t AIDLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) {
|
||||
int retrycnt = 0;
|
||||
int res = 0;
|
||||
do {
|
||||
|
@ -376,8 +362,7 @@ int EMVSelectWithRetry(EMVCommandChannel channel, bool ActivateField, bool Leave
|
|||
return res;
|
||||
}
|
||||
|
||||
int EMVCheckAID(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlvdbelm, struct tlvdb *tlv)
|
||||
{
|
||||
int EMVCheckAID(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlvdbelm, struct tlvdb *tlv) {
|
||||
uint8_t data[APDU_RES_LEN] = {0};
|
||||
size_t datalen = 0;
|
||||
int res = 0;
|
||||
|
@ -409,8 +394,7 @@ int EMVCheckAID(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlvdbel
|
|||
return res;
|
||||
}
|
||||
|
||||
int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t PSENum, bool decodeTLV, struct tlvdb *tlv)
|
||||
{
|
||||
int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t PSENum, bool decodeTLV, struct tlvdb *tlv) {
|
||||
uint8_t data[APDU_RES_LEN] = {0};
|
||||
size_t datalen = 0;
|
||||
uint8_t sfidata[0x11][APDU_RES_LEN];
|
||||
|
@ -504,8 +488,7 @@ int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldO
|
|||
return res;
|
||||
}
|
||||
|
||||
int EMVSearch(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, bool decodeTLV, struct tlvdb *tlv)
|
||||
{
|
||||
int EMVSearch(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, bool decodeTLV, struct tlvdb *tlv) {
|
||||
uint8_t aidbuf[APDU_AID_LEN] = {0};
|
||||
int aidlen = 0;
|
||||
uint8_t data[APDU_RES_LEN] = {0};
|
||||
|
@ -550,8 +533,7 @@ int EMVSearch(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int EMVSelectApplication(struct tlvdb *tlv, uint8_t *AID, size_t *AIDlen)
|
||||
{
|
||||
int EMVSelectApplication(struct tlvdb *tlv, uint8_t *AID, size_t *AIDlen) {
|
||||
// check priority. 0x00 - highest
|
||||
int prio = 0xffff;
|
||||
|
||||
|
@ -590,13 +572,11 @@ int EMVSelectApplication(struct tlvdb *tlv, uint8_t *AID, size_t *AIDlen)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int EMVGPO(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *PDOL, size_t PDOLLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv)
|
||||
{
|
||||
int EMVGPO(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *PDOL, size_t PDOLLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) {
|
||||
return EMVExchange(channel, LeaveFieldON, (sAPDU) {0x80, 0xa8, 0x00, 0x00, PDOLLen, PDOL}, Result, MaxResultLen, ResultLen, sw, tlv);
|
||||
}
|
||||
|
||||
int EMVReadRecord(EMVCommandChannel channel, bool LeaveFieldON, uint8_t SFI, uint8_t SFIrec, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv)
|
||||
{
|
||||
int EMVReadRecord(EMVCommandChannel channel, bool LeaveFieldON, uint8_t SFI, uint8_t SFIrec, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) {
|
||||
int res = EMVExchange(channel, LeaveFieldON, (sAPDU) {0x00, 0xb2, SFIrec, (SFI << 3) | 0x04, 0, NULL}, Result, MaxResultLen, ResultLen, sw, tlv);
|
||||
if (*sw == 0x6700) {
|
||||
PrintAndLogEx(INFO, ">>> trying to reissue command withouth Le...");
|
||||
|
@ -605,13 +585,11 @@ int EMVReadRecord(EMVCommandChannel channel, bool LeaveFieldON, uint8_t SFI, uin
|
|||
return res;
|
||||
}
|
||||
|
||||
int EMVAC(EMVCommandChannel channel, bool LeaveFieldON, uint8_t RefControl, uint8_t *CDOL, size_t CDOLLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv)
|
||||
{
|
||||
int EMVAC(EMVCommandChannel channel, bool LeaveFieldON, uint8_t RefControl, uint8_t *CDOL, size_t CDOLLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) {
|
||||
return EMVExchange(channel, LeaveFieldON, (sAPDU) {0x80, 0xae, RefControl, 0x00, CDOLLen, CDOL}, Result, MaxResultLen, ResultLen, sw, tlv);
|
||||
}
|
||||
|
||||
int EMVGenerateChallenge(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv)
|
||||
{
|
||||
int EMVGenerateChallenge(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) {
|
||||
int res = EMVExchange(channel, LeaveFieldON, (sAPDU) {0x00, 0x84, 0x00, 0x00, 0x00, NULL}, Result, MaxResultLen, ResultLen, sw, tlv);
|
||||
if (*sw == 0x6700) {
|
||||
PrintAndLogEx(INFO, ">>> trying to reissue command withouth Le...");
|
||||
|
@ -620,19 +598,16 @@ int EMVGenerateChallenge(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *
|
|||
return res;
|
||||
}
|
||||
|
||||
int EMVInternalAuthenticate(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *DDOL, size_t DDOLLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv)
|
||||
{
|
||||
int EMVInternalAuthenticate(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *DDOL, size_t DDOLLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) {
|
||||
return EMVExchangeEx(channel, false, LeaveFieldON, (sAPDU) {0x00, 0x88, 0x00, 0x00, DDOLLen, DDOL}, true, Result, MaxResultLen, ResultLen, sw, tlv);
|
||||
}
|
||||
|
||||
int MSCComputeCryptoChecksum(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *UDOL, uint8_t UDOLlen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv)
|
||||
{
|
||||
int MSCComputeCryptoChecksum(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *UDOL, uint8_t UDOLlen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) {
|
||||
return EMVExchange(channel, LeaveFieldON, (sAPDU) {0x80, 0x2a, 0x8e, 0x80, UDOLlen, UDOL}, Result, MaxResultLen, ResultLen, sw, tlv);
|
||||
}
|
||||
|
||||
// Authentication
|
||||
struct emv_pk *get_ca_pk(struct tlvdb *db)
|
||||
{
|
||||
struct emv_pk *get_ca_pk(struct tlvdb *db) {
|
||||
const struct tlv *df_tlv = tlvdb_get(db, 0x84, NULL);
|
||||
const struct tlv *caidx_tlv = tlvdb_get(db, 0x8f, NULL);
|
||||
|
||||
|
@ -643,8 +618,7 @@ struct emv_pk *get_ca_pk(struct tlvdb *db)
|
|||
return emv_pk_get_ca_pk(df_tlv->value, caidx_tlv->value[0]);
|
||||
}
|
||||
|
||||
int trSDA(struct tlvdb *tlv)
|
||||
{
|
||||
int trSDA(struct tlvdb *tlv) {
|
||||
|
||||
struct emv_pk *pk = get_ca_pk(tlv);
|
||||
if (!pk) {
|
||||
|
@ -699,8 +673,7 @@ int trSDA(struct tlvdb *tlv)
|
|||
static const unsigned char default_ddol_value[] = {0x9f, 0x37, 0x04};
|
||||
static struct tlv default_ddol_tlv = {.tag = 0x9f49, .len = 3, .value = default_ddol_value };
|
||||
|
||||
int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv)
|
||||
{
|
||||
int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
|
||||
uint8_t buf[APDU_RES_LEN] = {0};
|
||||
size_t len = 0;
|
||||
uint16_t sw = 0;
|
||||
|
@ -926,8 +899,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, struct tlv *ac_data_tlv)
|
||||
{
|
||||
int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, struct tlv *ac_data_tlv) {
|
||||
|
||||
struct emv_pk *pk = get_ca_pk(tlv);
|
||||
if (!pk) {
|
||||
|
@ -1013,8 +985,7 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st
|
|||
return 0;
|
||||
}
|
||||
|
||||
int RecoveryCertificates(struct tlvdb *tlvRoot, json_t *root)
|
||||
{
|
||||
int RecoveryCertificates(struct tlvdb *tlvRoot, json_t *root) {
|
||||
|
||||
struct emv_pk *pk = get_ca_pk(tlvRoot);
|
||||
if (!pk) {
|
||||
|
|
|
@ -60,8 +60,7 @@ static const ApplicationDataElm ApplicationData[] = {
|
|||
};
|
||||
int ApplicationDataLen = sizeof(ApplicationData) / sizeof(ApplicationDataElm);
|
||||
|
||||
char *GetApplicationDataName(tlv_tag_t tag)
|
||||
{
|
||||
char *GetApplicationDataName(tlv_tag_t tag) {
|
||||
for (int i = 0; i < ApplicationDataLen; i++)
|
||||
if (ApplicationData[i].Tag == tag)
|
||||
return ApplicationData[i].Name;
|
||||
|
@ -69,8 +68,7 @@ char *GetApplicationDataName(tlv_tag_t tag)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int JsonSaveJsonObject(json_t *root, char *path, json_t *value)
|
||||
{
|
||||
int JsonSaveJsonObject(json_t *root, char *path, json_t *value) {
|
||||
json_error_t error;
|
||||
|
||||
if (strlen(path) < 1)
|
||||
|
@ -88,18 +86,15 @@ int JsonSaveJsonObject(json_t *root, char *path, json_t *value)
|
|||
}
|
||||
}
|
||||
|
||||
int JsonSaveInt(json_t *root, char *path, int value)
|
||||
{
|
||||
int JsonSaveInt(json_t *root, char *path, int value) {
|
||||
return JsonSaveJsonObject(root, path, json_integer(value));
|
||||
}
|
||||
|
||||
int JsonSaveStr(json_t *root, char *path, char *value)
|
||||
{
|
||||
int JsonSaveStr(json_t *root, char *path, char *value) {
|
||||
return JsonSaveJsonObject(root, path, json_string(value));
|
||||
};
|
||||
|
||||
int JsonSaveBufAsHexCompact(json_t *elm, char *path, uint8_t *data, size_t datalen)
|
||||
{
|
||||
int JsonSaveBufAsHexCompact(json_t *elm, char *path, uint8_t *data, size_t datalen) {
|
||||
char *msg = sprint_hex_inrow(data, datalen);
|
||||
if (msg && strlen(msg) && msg[strlen(msg) - 1] == ' ')
|
||||
msg[strlen(msg) - 1] = '\0';
|
||||
|
@ -107,8 +102,7 @@ int JsonSaveBufAsHexCompact(json_t *elm, char *path, uint8_t *data, size_t datal
|
|||
return JsonSaveStr(elm, path, msg);
|
||||
}
|
||||
|
||||
int JsonSaveBufAsHex(json_t *elm, char *path, uint8_t *data, size_t datalen)
|
||||
{
|
||||
int JsonSaveBufAsHex(json_t *elm, char *path, uint8_t *data, size_t datalen) {
|
||||
char *msg = sprint_hex(data, datalen);
|
||||
if (msg && strlen(msg) && msg[strlen(msg) - 1] == ' ')
|
||||
msg[strlen(msg) - 1] = '\0';
|
||||
|
@ -116,8 +110,7 @@ int JsonSaveBufAsHex(json_t *elm, char *path, uint8_t *data, size_t datalen)
|
|||
return JsonSaveStr(elm, path, msg);
|
||||
}
|
||||
|
||||
int JsonSaveHex(json_t *elm, char *path, uint64_t data, int datalen)
|
||||
{
|
||||
int JsonSaveHex(json_t *elm, char *path, uint64_t data, int datalen) {
|
||||
uint8_t bdata[8] = {0};
|
||||
int len = 0;
|
||||
if (!datalen) {
|
||||
|
@ -137,8 +130,7 @@ int JsonSaveHex(json_t *elm, char *path, uint64_t data, int datalen)
|
|||
return JsonSaveBufAsHex(elm, path, bdata, len);
|
||||
}
|
||||
|
||||
int JsonSaveTLVValue(json_t *root, char *path, struct tlvdb *tlvdbelm)
|
||||
{
|
||||
int JsonSaveTLVValue(json_t *root, char *path, struct tlvdb *tlvdbelm) {
|
||||
const struct tlv *tlvelm = tlvdb_get_tlv(tlvdbelm);
|
||||
if (tlvelm)
|
||||
return JsonSaveBufAsHex(root, path, (uint8_t *)tlvelm->value, tlvelm->len);
|
||||
|
@ -146,8 +138,7 @@ int JsonSaveTLVValue(json_t *root, char *path, struct tlvdb *tlvdbelm)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveName, bool saveValue, bool saveAppDataLink)
|
||||
{
|
||||
int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveName, bool saveValue, bool saveAppDataLink) {
|
||||
json_error_t error;
|
||||
|
||||
if (strlen(path) < 1 || !tlvelm)
|
||||
|
@ -191,13 +182,11 @@ int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveName, b
|
|||
return 0;
|
||||
}
|
||||
|
||||
int JsonSaveTLVTreeElm(json_t *elm, char *path, struct tlvdb *tlvdbelm, bool saveName, bool saveValue, bool saveAppDataLink)
|
||||
{
|
||||
int JsonSaveTLVTreeElm(json_t *elm, char *path, struct tlvdb *tlvdbelm, bool saveName, bool saveValue, bool saveAppDataLink) {
|
||||
return JsonSaveTLVElm(elm, path, (struct tlv *)tlvdb_get_tlv(tlvdbelm), saveName, saveValue, saveAppDataLink);
|
||||
}
|
||||
|
||||
int JsonSaveTLVTree(json_t *root, json_t *elm, char *path, struct tlvdb *tlvdbelm)
|
||||
{
|
||||
int JsonSaveTLVTree(json_t *root, json_t *elm, char *path, struct tlvdb *tlvdbelm) {
|
||||
struct tlvdb *tlvp = tlvdbelm;
|
||||
while (tlvp) {
|
||||
const struct tlv *tlvpelm = tlvdb_get_tlv(tlvp);
|
||||
|
@ -250,8 +239,7 @@ int JsonSaveTLVTree(json_t *root, json_t *elm, char *path, struct tlvdb *tlvdbel
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool HexToBuffer(const char *errormsg, const char *hexvalue, uint8_t *buffer, size_t maxbufferlen, size_t *bufferlen)
|
||||
{
|
||||
bool HexToBuffer(const char *errormsg, const char *hexvalue, uint8_t *buffer, size_t maxbufferlen, size_t *bufferlen) {
|
||||
int buflen = 0;
|
||||
|
||||
switch (param_gethex_to_eol(hexvalue, 0, buffer, maxbufferlen, &buflen)) {
|
||||
|
@ -277,8 +265,7 @@ bool HexToBuffer(const char *errormsg, const char *hexvalue, uint8_t *buffer, si
|
|||
return true;
|
||||
}
|
||||
|
||||
int JsonLoadStr(json_t *root, char *path, char *value)
|
||||
{
|
||||
int JsonLoadStr(json_t *root, char *path, char *value) {
|
||||
if (!value)
|
||||
return 1;
|
||||
|
||||
|
@ -295,8 +282,7 @@ int JsonLoadStr(json_t *root, char *path, char *value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int JsonLoadBufAsHex(json_t *elm, char *path, uint8_t *data, size_t maxbufferlen, size_t *datalen)
|
||||
{
|
||||
int JsonLoadBufAsHex(json_t *elm, char *path, uint8_t *data, size_t maxbufferlen, size_t *datalen) {
|
||||
if (datalen)
|
||||
*datalen = 0;
|
||||
|
||||
|
@ -310,8 +296,7 @@ int JsonLoadBufAsHex(json_t *elm, char *path, uint8_t *data, size_t maxbufferlen
|
|||
return 0;
|
||||
};
|
||||
|
||||
bool ParamLoadFromJson(struct tlvdb *tlv)
|
||||
{
|
||||
bool ParamLoadFromJson(struct tlvdb *tlv) {
|
||||
json_t *root;
|
||||
json_error_t error;
|
||||
|
||||
|
|
|
@ -42,8 +42,7 @@ struct emv_pk c_mchip_05 = {
|
|||
.exp = { 0x03, },
|
||||
.elen = 1,
|
||||
.mlen = 1408 / 8,
|
||||
.modulus = (unsigned char[])
|
||||
{
|
||||
.modulus = (unsigned char[]) {
|
||||
0xb8, 0x04, 0x8a, 0xbc, 0x30, 0xc9, 0x0d, 0x97, 0x63, 0x36, 0x54, 0x3e, 0x3f, 0xd7, 0x09, 0x1c,
|
||||
0x8f, 0xe4, 0x80, 0x0d, 0xf8, 0x20, 0xed, 0x55, 0xe7, 0xe9, 0x48, 0x13, 0xed, 0x00, 0x55, 0x5b,
|
||||
0x57, 0x3f, 0xec, 0xa3, 0xd8, 0x4a, 0xf6, 0x13, 0x1a, 0x65, 0x1d, 0x66, 0xcf, 0xf4, 0x28, 0x4f,
|
||||
|
@ -150,8 +149,7 @@ static const struct tlv crm1_tlv = {
|
|||
.value = c_crm1,
|
||||
};
|
||||
|
||||
static int cda_test_raw(bool verbose)
|
||||
{
|
||||
static int cda_test_raw(bool verbose) {
|
||||
const struct emv_pk *pk = &c_mchip_05;
|
||||
|
||||
struct crypto_pk *kcp = crypto_pk_open(PK_RSA,
|
||||
|
@ -345,8 +343,7 @@ static int cda_test_raw(bool verbose)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cda_test_pk(bool verbose)
|
||||
{
|
||||
static int cda_test_pk(bool verbose) {
|
||||
const struct emv_pk *pk = &c_mchip_05;
|
||||
struct tlvdb *db;
|
||||
|
||||
|
@ -421,8 +418,7 @@ static int cda_test_pk(bool verbose)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int exec_cda_test(bool verbose)
|
||||
{
|
||||
int exec_cda_test(bool verbose) {
|
||||
int ret;
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
|
|
|
@ -25,8 +25,7 @@
|
|||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
static int test_genkey(unsigned int keylength, unsigned char *msg, size_t msg_len, bool verbose)
|
||||
{
|
||||
static int test_genkey(unsigned int keylength, unsigned char *msg, size_t msg_len, bool verbose) {
|
||||
int ret = 1;
|
||||
size_t tmp_len, tmp2_len;
|
||||
unsigned char *tmp, *tmp2;
|
||||
|
@ -192,8 +191,7 @@ static unsigned char pk_I[] = {
|
|||
0xd4, 0x42, 0xc9, 0x17, 0xb2, 0x2c, 0x92, 0x12, 0x37, 0x1b, 0xd3, 0xc5, 0x79, 0xd2, 0x65, 0x61,
|
||||
};
|
||||
|
||||
static int test_pk(bool verbose)
|
||||
{
|
||||
static int test_pk(bool verbose) {
|
||||
int ret = 1;
|
||||
size_t tmp_len, tmp2_len;
|
||||
unsigned char *tmp, *tmp2;
|
||||
|
@ -300,8 +298,7 @@ close_pub:
|
|||
return ret;
|
||||
}
|
||||
|
||||
int exec_crypto_test(bool verbose)
|
||||
{
|
||||
int exec_crypto_test(bool verbose) {
|
||||
unsigned int keylengths[] = {1024, 1152, 1408, 1984, 2048, 3072, 4096};
|
||||
int i;
|
||||
int ret;
|
||||
|
|
|
@ -33,8 +33,7 @@
|
|||
#include "crypto/libpcrypto.h"
|
||||
#include "emv/emv_roca.h"
|
||||
|
||||
int ExecuteCryptoTests(bool verbose)
|
||||
{
|
||||
int ExecuteCryptoTests(bool verbose) {
|
||||
int res;
|
||||
bool TestFail = false;
|
||||
|
||||
|
|
|
@ -44,8 +44,7 @@ struct emv_pk mchip_05 = {
|
|||
.exp = { 0x03, },
|
||||
.elen = 1,
|
||||
.mlen = 1408 / 8,
|
||||
.modulus = (unsigned char[])
|
||||
{
|
||||
.modulus = (unsigned char[]) {
|
||||
0xb8, 0x04, 0x8a, 0xbc, 0x30, 0xc9, 0x0d, 0x97, 0x63, 0x36, 0x54, 0x3e, 0x3f, 0xd7, 0x09, 0x1c,
|
||||
0x8f, 0xe4, 0x80, 0x0d, 0xf8, 0x20, 0xed, 0x55, 0xe7, 0xe9, 0x48, 0x13, 0xed, 0x00, 0x55, 0x5b,
|
||||
0x57, 0x3f, 0xec, 0xa3, 0xd8, 0x4a, 0xf6, 0x13, 0x1a, 0x65, 0x1d, 0x66, 0xcf, 0xf4, 0x28, 0x4f,
|
||||
|
@ -140,8 +139,7 @@ static const struct tlv dd1_tlv = {
|
|||
.value = d_dd1,
|
||||
};
|
||||
|
||||
static int dda_test_raw(bool verbose)
|
||||
{
|
||||
static int dda_test_raw(bool verbose) {
|
||||
const struct emv_pk *pk = &mchip_05;
|
||||
|
||||
struct crypto_pk *kcp = crypto_pk_open(PK_RSA,
|
||||
|
@ -306,8 +304,7 @@ static int dda_test_raw(bool verbose)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int dda_test_pk(bool verbose)
|
||||
{
|
||||
static int dda_test_pk(bool verbose) {
|
||||
const struct emv_pk *pk = &mchip_05;
|
||||
struct tlvdb *db;
|
||||
|
||||
|
@ -369,8 +366,7 @@ static int dda_test_pk(bool verbose)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int exec_dda_test(bool verbose)
|
||||
{
|
||||
int exec_dda_test(bool verbose) {
|
||||
int ret;
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
|
|
|
@ -42,8 +42,7 @@ struct emv_pk vsdc_01 = {
|
|||
.exp = { 0x03, },
|
||||
.elen = 1,
|
||||
.mlen = 1024 / 8,
|
||||
.modulus = (unsigned char[])
|
||||
{
|
||||
.modulus = (unsigned char[]) {
|
||||
0xc6, 0x96, 0x03, 0x42, 0x13, 0xd7, 0xd8, 0x54, 0x69, 0x84, 0x57, 0x9d, 0x1d, 0x0f, 0x0e, 0xa5,
|
||||
0x19, 0xcf, 0xf8, 0xde, 0xff, 0xc4, 0x29, 0x35, 0x4c, 0xf3, 0xa8, 0x71, 0xa6, 0xf7, 0x18, 0x3f,
|
||||
0x12, 0x28, 0xda, 0x5c, 0x74, 0x70, 0xc0, 0x55, 0x38, 0x71, 0x00, 0xcb, 0x93, 0x5a, 0x71, 0x2c,
|
||||
|
@ -100,8 +99,7 @@ const unsigned char pan[] = {
|
|||
0x42, 0x76, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
static int sda_test_raw(bool verbose)
|
||||
{
|
||||
static int sda_test_raw(bool verbose) {
|
||||
const struct emv_pk *pk = &vsdc_01;
|
||||
|
||||
struct crypto_pk *kcp = crypto_pk_open(PK_RSA,
|
||||
|
@ -208,8 +206,7 @@ static int sda_test_raw(bool verbose)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int sda_test_pk(bool verbose)
|
||||
{
|
||||
static int sda_test_pk(bool verbose) {
|
||||
const struct emv_pk *pk = &vsdc_01;
|
||||
struct tlvdb *db;
|
||||
|
||||
|
@ -256,8 +253,7 @@ static int sda_test_pk(bool verbose)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int exec_sda_test(bool verbose)
|
||||
{
|
||||
int exec_sda_test(bool verbose) {
|
||||
int ret;
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
|
|
|
@ -54,8 +54,7 @@ struct tlvdb_root {
|
|||
unsigned char buf[0];
|
||||
};
|
||||
|
||||
static tlv_tag_t tlv_parse_tag(const unsigned char **buf, size_t *len)
|
||||
{
|
||||
static tlv_tag_t tlv_parse_tag(const unsigned char **buf, size_t *len) {
|
||||
tlv_tag_t tag;
|
||||
|
||||
if (*len == 0)
|
||||
|
@ -77,8 +76,7 @@ static tlv_tag_t tlv_parse_tag(const unsigned char **buf, size_t *len)
|
|||
return tag;
|
||||
}
|
||||
|
||||
static size_t tlv_parse_len(const unsigned char **buf, size_t *len)
|
||||
{
|
||||
static size_t tlv_parse_len(const unsigned char **buf, size_t *len) {
|
||||
size_t l;
|
||||
|
||||
if (*len == 0)
|
||||
|
@ -105,8 +103,7 @@ static size_t tlv_parse_len(const unsigned char **buf, size_t *len)
|
|||
return l;
|
||||
}
|
||||
|
||||
bool tlv_parse_tl(const unsigned char **buf, size_t *len, struct tlv *tlv)
|
||||
{
|
||||
bool tlv_parse_tl(const unsigned char **buf, size_t *len, struct tlv *tlv) {
|
||||
tlv->value = 0;
|
||||
|
||||
tlv->tag = tlv_parse_tag(buf, len);
|
||||
|
@ -125,8 +122,7 @@ static struct tlvdb *tlvdb_parse_children(struct tlvdb *parent);
|
|||
static bool tlvdb_parse_one(struct tlvdb *tlvdb,
|
||||
struct tlvdb *parent,
|
||||
const unsigned char **tmp,
|
||||
size_t *left)
|
||||
{
|
||||
size_t *left) {
|
||||
tlvdb->next = tlvdb->children = NULL;
|
||||
tlvdb->parent = parent;
|
||||
|
||||
|
@ -160,8 +156,7 @@ err:
|
|||
return false;
|
||||
}
|
||||
|
||||
static struct tlvdb *tlvdb_parse_children(struct tlvdb *parent)
|
||||
{
|
||||
static struct tlvdb *tlvdb_parse_children(struct tlvdb *parent) {
|
||||
const unsigned char *tmp = parent->tag.value;
|
||||
size_t left = parent->tag.len;
|
||||
struct tlvdb *tlvdb, *first = NULL, *prev = NULL;
|
||||
|
@ -188,8 +183,7 @@ err:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct tlvdb *tlvdb_parse(const unsigned char *buf, size_t len)
|
||||
{
|
||||
struct tlvdb *tlvdb_parse(const unsigned char *buf, size_t len) {
|
||||
struct tlvdb_root *root;
|
||||
const unsigned char *tmp;
|
||||
size_t left;
|
||||
|
@ -218,8 +212,7 @@ err:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct tlvdb *tlvdb_parse_multi(const unsigned char *buf, size_t len)
|
||||
{
|
||||
struct tlvdb *tlvdb_parse_multi(const unsigned char *buf, size_t len) {
|
||||
struct tlvdb_root *root;
|
||||
const unsigned char *tmp;
|
||||
size_t left;
|
||||
|
@ -255,8 +248,7 @@ err:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct tlvdb *tlvdb_fixed(tlv_tag_t tag, size_t len, const unsigned char *value)
|
||||
{
|
||||
struct tlvdb *tlvdb_fixed(tlv_tag_t tag, size_t len, const unsigned char *value) {
|
||||
struct tlvdb_root *root = malloc(sizeof(*root) + len);
|
||||
|
||||
root->len = len;
|
||||
|
@ -270,8 +262,7 @@ struct tlvdb *tlvdb_fixed(tlv_tag_t tag, size_t len, const unsigned char *value)
|
|||
return &root->db;
|
||||
}
|
||||
|
||||
struct tlvdb *tlvdb_external(tlv_tag_t tag, size_t len, const unsigned char *value)
|
||||
{
|
||||
struct tlvdb *tlvdb_external(tlv_tag_t tag, size_t len, const unsigned char *value) {
|
||||
struct tlvdb_root *root = malloc(sizeof(*root));
|
||||
|
||||
root->len = 0;
|
||||
|
@ -284,8 +275,7 @@ struct tlvdb *tlvdb_external(tlv_tag_t tag, size_t len, const unsigned char *val
|
|||
return &root->db;
|
||||
}
|
||||
|
||||
void tlvdb_free(struct tlvdb *tlvdb)
|
||||
{
|
||||
void tlvdb_free(struct tlvdb *tlvdb) {
|
||||
struct tlvdb *next = NULL;
|
||||
|
||||
if (!tlvdb)
|
||||
|
@ -298,16 +288,14 @@ void tlvdb_free(struct tlvdb *tlvdb)
|
|||
}
|
||||
}
|
||||
|
||||
struct tlvdb *tlvdb_find_next(struct tlvdb *tlvdb, tlv_tag_t tag)
|
||||
{
|
||||
struct tlvdb *tlvdb_find_next(struct tlvdb *tlvdb, tlv_tag_t tag) {
|
||||
if (!tlvdb)
|
||||
return NULL;
|
||||
|
||||
return tlvdb_find(tlvdb->next, tag);
|
||||
}
|
||||
|
||||
struct tlvdb *tlvdb_find(struct tlvdb *tlvdb, tlv_tag_t tag)
|
||||
{
|
||||
struct tlvdb *tlvdb_find(struct tlvdb *tlvdb, tlv_tag_t tag) {
|
||||
if (!tlvdb)
|
||||
return NULL;
|
||||
|
||||
|
@ -319,8 +307,7 @@ struct tlvdb *tlvdb_find(struct tlvdb *tlvdb, tlv_tag_t tag)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct tlvdb *tlvdb_find_full(struct tlvdb *tlvdb, tlv_tag_t tag)
|
||||
{
|
||||
struct tlvdb *tlvdb_find_full(struct tlvdb *tlvdb, tlv_tag_t tag) {
|
||||
if (!tlvdb)
|
||||
return NULL;
|
||||
|
||||
|
@ -338,8 +325,7 @@ struct tlvdb *tlvdb_find_full(struct tlvdb *tlvdb, tlv_tag_t tag)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct tlvdb *tlvdb_find_path(struct tlvdb *tlvdb, tlv_tag_t tag[])
|
||||
{
|
||||
struct tlvdb *tlvdb_find_path(struct tlvdb *tlvdb, tlv_tag_t tag[]) {
|
||||
int i = 0;
|
||||
struct tlvdb *tnext = tlvdb;
|
||||
|
||||
|
@ -354,8 +340,7 @@ struct tlvdb *tlvdb_find_path(struct tlvdb *tlvdb, tlv_tag_t tag[])
|
|||
return tnext;
|
||||
}
|
||||
|
||||
void tlvdb_add(struct tlvdb *tlvdb, struct tlvdb *other)
|
||||
{
|
||||
void tlvdb_add(struct tlvdb *tlvdb, struct tlvdb *other) {
|
||||
if (tlvdb == other)
|
||||
return;
|
||||
|
||||
|
@ -369,8 +354,7 @@ void tlvdb_add(struct tlvdb *tlvdb, struct tlvdb *other)
|
|||
tlvdb->next = other;
|
||||
}
|
||||
|
||||
void tlvdb_change_or_add_node_ex(struct tlvdb *tlvdb, tlv_tag_t tag, size_t len, const unsigned char *value, struct tlvdb **tlvdb_elm)
|
||||
{
|
||||
void tlvdb_change_or_add_node_ex(struct tlvdb *tlvdb, tlv_tag_t tag, size_t len, const unsigned char *value, struct tlvdb **tlvdb_elm) {
|
||||
struct tlvdb *telm = tlvdb_find_full(tlvdb, tag);
|
||||
if (telm == NULL) {
|
||||
// new tlv element
|
||||
|
@ -421,13 +405,11 @@ void tlvdb_change_or_add_node_ex(struct tlvdb *tlvdb, tlv_tag_t tag, size_t len,
|
|||
return;
|
||||
}
|
||||
|
||||
void tlvdb_change_or_add_node(struct tlvdb *tlvdb, tlv_tag_t tag, size_t len, const unsigned char *value)
|
||||
{
|
||||
void tlvdb_change_or_add_node(struct tlvdb *tlvdb, tlv_tag_t tag, size_t len, const unsigned char *value) {
|
||||
tlvdb_change_or_add_node_ex(tlvdb, tag, len, value, NULL);
|
||||
}
|
||||
|
||||
void tlvdb_visit(const struct tlvdb *tlvdb, tlv_cb cb, void *data, int level)
|
||||
{
|
||||
void tlvdb_visit(const struct tlvdb *tlvdb, tlv_cb cb, void *data, int level) {
|
||||
struct tlvdb *next = NULL;
|
||||
|
||||
if (!tlvdb)
|
||||
|
@ -440,8 +422,7 @@ void tlvdb_visit(const struct tlvdb *tlvdb, tlv_cb cb, void *data, int level)
|
|||
}
|
||||
}
|
||||
|
||||
static const struct tlvdb *tlvdb_next(const struct tlvdb *tlvdb)
|
||||
{
|
||||
static const struct tlvdb *tlvdb_next(const struct tlvdb *tlvdb) {
|
||||
if (tlvdb->children)
|
||||
return tlvdb->children;
|
||||
|
||||
|
@ -455,8 +436,7 @@ static const struct tlvdb *tlvdb_next(const struct tlvdb *tlvdb)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
const struct tlv *tlvdb_get(const struct tlvdb *tlvdb, tlv_tag_t tag, const struct tlv *prev)
|
||||
{
|
||||
const struct tlv *tlvdb_get(const struct tlvdb *tlvdb, tlv_tag_t tag, const struct tlv *prev) {
|
||||
if (prev) {
|
||||
// tlvdb = tlvdb_next(container_of(prev, struct tlvdb, tag));
|
||||
tlvdb = tlvdb_next((struct tlvdb *)prev);
|
||||
|
@ -473,22 +453,19 @@ const struct tlv *tlvdb_get(const struct tlvdb *tlvdb, tlv_tag_t tag, const stru
|
|||
return NULL;
|
||||
}
|
||||
|
||||
const struct tlv *tlvdb_get_inchild(const struct tlvdb *tlvdb, tlv_tag_t tag, const struct tlv *prev)
|
||||
{
|
||||
const struct tlv *tlvdb_get_inchild(const struct tlvdb *tlvdb, tlv_tag_t tag, const struct tlv *prev) {
|
||||
tlvdb = tlvdb->children;
|
||||
return tlvdb_get(tlvdb, tag, prev);
|
||||
}
|
||||
|
||||
const struct tlv *tlvdb_get_tlv(const struct tlvdb *tlvdb)
|
||||
{
|
||||
const struct tlv *tlvdb_get_tlv(const struct tlvdb *tlvdb) {
|
||||
if (tlvdb)
|
||||
return &tlvdb->tag;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned char *tlv_encode(const struct tlv *tlv, size_t *len)
|
||||
{
|
||||
unsigned char *tlv_encode(const struct tlv *tlv, size_t *len) {
|
||||
size_t size = tlv->len;
|
||||
unsigned char *data;
|
||||
size_t pos;
|
||||
|
@ -530,13 +507,11 @@ unsigned char *tlv_encode(const struct tlv *tlv, size_t *len)
|
|||
return data;
|
||||
}
|
||||
|
||||
bool tlv_is_constructed(const struct tlv *tlv)
|
||||
{
|
||||
bool tlv_is_constructed(const struct tlv *tlv) {
|
||||
return (tlv->tag < 0x100 ? tlv->tag : tlv->tag >> 8) & TLV_TAG_COMPLEX;
|
||||
}
|
||||
|
||||
bool tlv_equal(const struct tlv *a, const struct tlv *b)
|
||||
{
|
||||
bool tlv_equal(const struct tlv *a, const struct tlv *b) {
|
||||
if (!a && !b)
|
||||
return true;
|
||||
|
||||
|
@ -546,29 +521,24 @@ bool tlv_equal(const struct tlv *a, const struct tlv *b)
|
|||
return a->tag == b->tag && a->len == b->len && !memcmp(a->value, b->value, a->len);
|
||||
}
|
||||
|
||||
struct tlvdb *tlvdb_elm_get_next(struct tlvdb *tlvdb)
|
||||
{
|
||||
struct tlvdb *tlvdb_elm_get_next(struct tlvdb *tlvdb) {
|
||||
return tlvdb->next;
|
||||
}
|
||||
|
||||
struct tlvdb *tlvdb_elm_get_children(struct tlvdb *tlvdb)
|
||||
{
|
||||
struct tlvdb *tlvdb_elm_get_children(struct tlvdb *tlvdb) {
|
||||
return tlvdb->children;
|
||||
}
|
||||
|
||||
struct tlvdb *tlvdb_elm_get_parent(struct tlvdb *tlvdb)
|
||||
{
|
||||
struct tlvdb *tlvdb_elm_get_parent(struct tlvdb *tlvdb) {
|
||||
return tlvdb->parent;
|
||||
}
|
||||
|
||||
bool tlvdb_get_uint8(struct tlvdb *tlvRoot, tlv_tag_t tag, uint8_t *value)
|
||||
{
|
||||
bool tlvdb_get_uint8(struct tlvdb *tlvRoot, tlv_tag_t tag, uint8_t *value) {
|
||||
const struct tlv *tlvelm = tlvdb_get(tlvRoot, tag, NULL);
|
||||
return tlv_get_uint8(tlvelm, value);
|
||||
}
|
||||
|
||||
bool tlv_get_uint8(const struct tlv *etlv, uint8_t *value)
|
||||
{
|
||||
bool tlv_get_uint8(const struct tlv *etlv, uint8_t *value) {
|
||||
*value = 0;
|
||||
if (etlv) {
|
||||
if (etlv->len == 0)
|
||||
|
@ -582,8 +552,7 @@ bool tlv_get_uint8(const struct tlv *etlv, uint8_t *value)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool tlv_get_int(const struct tlv *etlv, int *value)
|
||||
{
|
||||
bool tlv_get_int(const struct tlv *etlv, int *value) {
|
||||
*value = 0;
|
||||
if (etlv) {
|
||||
if (etlv->len == 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue