From f49c57442801b5f76c8e0e7a45c22b90fd0753dc Mon Sep 17 00:00:00 2001 From: Charles-Edouard de la Vergne Date: Thu, 29 Feb 2024 16:38:35 +0100 Subject: [PATCH] custo & formatting --- src/gpg_data.c | 23 +++++++++-------------- src/gpg_gen.c | 4 ---- src/gpg_init.c | 6 +++--- src/gpg_pso.c | 6 ++---- src/gpg_ux_nanox.c | 2 +- src/gpg_ux_nbgl.c | 1 - 6 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/gpg_data.c b/src/gpg_data.c index 8915e13..ad47c59 100644 --- a/src/gpg_data.c +++ b/src/gpg_data.c @@ -395,7 +395,6 @@ int gpg_apdu_put_data(unsigned int ref) { break; } - // --- RSA KEY --- if (keygpg->attributes.value[0] == KEY_ID_RSA) { unsigned int e = 0; unsigned char *p, *q, *pq; @@ -476,14 +475,13 @@ int gpg_apdu_put_data(unsigned int ref) { } sw = SW_OK; } - // --- ECC KEY --- else if ((keygpg->attributes.value[0] == KEY_ID_ECDH) || (keygpg->attributes.value[0] == KEY_ID_ECDSA) || (keygpg->attributes.value[0] == KEY_ID_EDDSA)) { unsigned int curve; curve = gpg_oid2curve(&keygpg->attributes.value[1], keygpg->attributes.length - 1); - if (curve == 0) { + if (curve == CX_CURVE_NONE) { sw = SW_WRONG_DATA; break; } @@ -801,8 +799,8 @@ end: // cmd // resp TID API COMPAT len_pub len_priv priv int gpg_apdu_get_key_data(unsigned int ref) { - cx_aes_key_t keyenc; - gpg_key_t *keygpg; + cx_aes_key_t keyenc = {0}; + gpg_key_t *keygpg = NULL; unsigned int len = 0; cx_err_t error = CX_INTERNAL_ERROR; int sw = SW_UNKNOWN; @@ -832,7 +830,7 @@ int gpg_apdu_get_key_data(unsigned int ref) { // encrypted part switch (keygpg->attributes.value[0]) { - case KEY_ID_RSA: // RSA + case KEY_ID_RSA: // insert pubkey gpg_io_insert_u32(4); gpg_io_insert(keygpg->pub_key.rsa, 4); @@ -853,7 +851,7 @@ int gpg_apdu_get_key_data(unsigned int ref) { sw = SW_OK; break; - case KEY_ID_ECDH: // ECC + case KEY_ID_ECDH: case KEY_ID_ECDSA: case KEY_ID_EDDSA: // insert pubkey @@ -889,10 +887,9 @@ end: // cmd TID API COMPAT len_pub len_priv priv // resp - int gpg_apdu_put_key_data(unsigned int ref) { - cx_aes_key_t keyenc; - gpg_key_t *keygpg; - unsigned int len; - unsigned int offset; + cx_aes_key_t keyenc = {0}; + gpg_key_t *keygpg = NULL; + unsigned int len = 0; cx_err_t error = CX_INTERNAL_ERROR; int sw = SW_UNKNOWN; @@ -920,7 +917,6 @@ int gpg_apdu_put_key_data(unsigned int ref) { gpg_io_fetch_u32(); switch (keygpg->attributes.value[0]) { - // RSA case KEY_ID_RSA: // insert pubkey len = gpg_io_fetch_u32(); @@ -955,8 +951,7 @@ int gpg_apdu_put_key_data(unsigned int ref) { sw = SW_OK; break; - // ECC - case KEY_ID_ECDH: // ECC + case KEY_ID_ECDH: case KEY_ID_ECDSA: case KEY_ID_EDDSA: // insert pubkey diff --git a/src/gpg_gen.c b/src/gpg_gen.c index 17f4864..5327cc3 100644 --- a/src/gpg_gen.c +++ b/src/gpg_gen.c @@ -304,7 +304,6 @@ int gpg_apdu_gen() { case GEN_ASYM_KEY_SEED: if (keygpg->attributes.value[0] == KEY_ID_RSA) { - // RSA sw = gpg_gen_rsa_kyey(keygpg, name); if (sw != SW_OK) { break; @@ -312,7 +311,6 @@ int gpg_apdu_gen() { } else if ((keygpg->attributes.value[0] == KEY_ID_ECDH) || (keygpg->attributes.value[0] == KEY_ID_ECDSA) || (keygpg->attributes.value[0] == KEY_ID_EDDSA)) { - // ECC sw = gpg_gen_ecc_kyey(keygpg, name); if (sw != SW_OK) { break; @@ -323,12 +321,10 @@ int gpg_apdu_gen() { // --- read pubkey --- case READ_ASYM_KEY: if (keygpg->attributes.value[0] == KEY_ID_RSA) { - // read RSA sw = gpg_read_rsa_kyey(keygpg); } else if ((keygpg->attributes.value[0] == KEY_ID_ECDH) || (keygpg->attributes.value[0] == KEY_ID_ECDSA) || (keygpg->attributes.value[0] == KEY_ID_EDDSA)) { - // read ECC sw = gpg_read_ecc_kyey(keygpg); } l = G_gpg_vstate.io_length; diff --git a/src/gpg_init.c b/src/gpg_init.c index 43cbfd5..1cd4185 100644 --- a/src/gpg_init.c +++ b/src/gpg_init.c @@ -56,7 +56,7 @@ const unsigned char C_OID_BRAINPOOL256T1[9] = { const unsigned char C_OID_BRAINPOOL256R1[9] = { 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x08 }; -//brainpool 284r1: 1.3.36.3.3.2.8.1.1.11 +//brainpool 384r1: 1.3.36.3.3.2.8.1.1.11 const unsigned char C_OID_BRAINPOOL384R1[9] = { 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0B }; @@ -66,7 +66,7 @@ const unsigned char C_OID_BRAINPOOL512R1[9] = { }; */ -// Ed25519/curve25519: 1.3.6.1.4.1.11591.15.1 +// "twisted" curve25519 for Ed25519: 1.3.6.1.4.1.11591.15.1 const unsigned char C_OID_Ed25519[9] = { 0x2B, 0x06, @@ -79,7 +79,7 @@ const unsigned char C_OID_Ed25519[9] = { 0x01, }; -// Ed25519/curve25519: 1.3.6.1.4.1.11591.15.1 +// "Montgomery" curve25519 for X25519: 1.3.6.1.4.1.11591.1.5.1 const unsigned char C_OID_cv25519[10] = { 0x2B, 0x06, diff --git a/src/gpg_pso.c b/src/gpg_pso.c index 7d92b8f..7977b27 100644 --- a/src/gpg_pso.c +++ b/src/gpg_pso.c @@ -65,7 +65,6 @@ static void gpg_pso_reset_PW1() { } static int gpg_sign(gpg_key_t *sigkey) { - // --- RSA cx_err_t error = CX_INTERNAL_ERROR; if (sigkey->attributes.value[0] == KEY_ID_RSA) { cx_rsa_private_key_t *key = NULL; @@ -113,7 +112,6 @@ static int gpg_sign(gpg_key_t *sigkey) { gpg_pso_reset_PW1(); return SW_OK; } - // --- ECDSA/EdDSA if ((sigkey->attributes.value[0] == KEY_ID_ECDSA) || (sigkey->attributes.value[0] == KEY_ID_EDDSA)) { cx_ecfp_private_key_t *key; @@ -223,7 +221,7 @@ int gpg_apdu_pso() { // --- PSO:ENC --- case PSO_ENC: { unsigned int msg_len; - cx_aes_key_t *key; + cx_aes_key_t *key = NULL; key = &G_gpg_vstate.kslot->AES_dec; if (!(key->size != 16)) { return SW_CONDITIONS_NOT_SATISFIED; @@ -252,7 +250,7 @@ int gpg_apdu_pso() { switch (pad_byte) { // --- PSO:DEC:RSA case 0x00: { - cx_rsa_private_key_t *key; + cx_rsa_private_key_t *key = NULL; if (G_gpg_vstate.mse_dec->attributes.value[0] != KEY_ID_RSA) { return SW_CONDITIONS_NOT_SATISFIED; } diff --git a/src/gpg_ux_nanox.c b/src/gpg_ux_nanox.c index 909f2b7..89751bc 100644 --- a/src/gpg_ux_nanox.c +++ b/src/gpg_ux_nanox.c @@ -590,7 +590,7 @@ void ui_menu_tmpl_set_action(unsigned int value) { UNUSED(value); LV(attributes, GPG_KEY_ATTRIBUTES_LENGTH); gpg_key_t *dest = NULL; - const unsigned char *oid; + const unsigned char *oid = NULL; unsigned int oid_len; memset(&attributes, 0, sizeof(attributes)); diff --git a/src/gpg_ux_nbgl.c b/src/gpg_ux_nbgl.c index bf21e71..d0acb70 100644 --- a/src/gpg_ux_nbgl.c +++ b/src/gpg_ux_nbgl.c @@ -237,7 +237,6 @@ static uint32_t _getKeyType(const uint8_t key) { } switch (attributes[0]) { case KEY_ID_RSA: - // RSA tag = U2BE(attributes, 1); switch (tag) { case 2048: