From 31991a31c38343365bd50d00a25ce8635cc2c87a Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Wed, 3 Dec 2025 16:34:49 +0100 Subject: [PATCH 1/4] Fix MSOS/BOS descriptor. Signed-off-by: Pol Henarejos --- pico-keys-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pico-keys-sdk b/pico-keys-sdk index 53d3a7a..d0dea3d 160000 --- a/pico-keys-sdk +++ b/pico-keys-sdk @@ -1 +1 @@ -Subproject commit 53d3a7ac91fdb0019ba5ec086c0b5197a811eb07 +Subproject commit d0dea3d0c5427549ad56c284a2011d5b3eea42e0 From bb542e3b83740e3fcca9b04393a7a3ac31836ed4 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Sun, 7 Dec 2025 20:34:42 +0100 Subject: [PATCH 2/4] Add is_gpg flag for fido2. Signed-off-by: Pol Henarejos --- src/fido/management.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fido/management.c b/src/fido/management.c index 3a61178..af3a67d 100644 --- a/src/fido/management.c +++ b/src/fido/management.c @@ -23,6 +23,8 @@ #include "asn1.h" #include "management.h" +bool is_gpg = true; + int man_process_apdu(); int man_unload(); @@ -44,6 +46,7 @@ int man_select(app_t *a, uint8_t force) { init_otp(); #endif } + is_gpg = false; return PICOKEY_OK; } From 1867f0330fa051209da6f2074338832413fa5f34 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Tue, 9 Dec 2025 15:56:31 +0100 Subject: [PATCH 3/4] Move EDDSA to another branch. Signed-off-by: Pol Henarejos --- pico-keys-sdk | 2 +- src/fido/cbor.c | 8 -------- src/fido/cbor_get_assertion.c | 10 ---------- src/fido/cbor_get_info.c | 6 ------ src/fido/cbor_make_credential.c | 22 ---------------------- src/fido/fido.c | 21 --------------------- src/fido/fido.h | 8 -------- 7 files changed, 1 insertion(+), 76 deletions(-) diff --git a/pico-keys-sdk b/pico-keys-sdk index d0dea3d..09ec076 160000 --- a/pico-keys-sdk +++ b/pico-keys-sdk @@ -1 +1 @@ -Subproject commit d0dea3d0c5427549ad56c284a2011d5b3eea42e0 +Subproject commit 09ec0767b6a3bd79b2a176fb468e97d9fde28449 diff --git a/src/fido/cbor.c b/src/fido/cbor.c index fec4d2f..b681c83 100644 --- a/src/fido/cbor.c +++ b/src/fido/cbor.c @@ -209,14 +209,6 @@ CborError COSE_key(mbedtls_ecp_keypair *key, CborEncoder *mapEncoderParent, else if (key->grp.id == MBEDTLS_ECP_DP_CURVE25519) { alg = FIDO2_ALG_ECDH_ES_HKDF_256; } -#ifdef MBEDTLS_EDDSA_C - else if (key->grp.id == MBEDTLS_ECP_DP_ED25519) { - alg = FIDO2_ALG_EDDSA; - } - else if (key->grp.id == MBEDTLS_ECP_DP_ED448) { - alg = FIDO2_ALG_ED448; - } -#endif return COSE_key_params(crv, alg, &key->grp, &key->Q, mapEncoderParent, mapEncoder); } CborError COSE_key_shared(mbedtls_ecdh_context *key, diff --git a/src/fido/cbor_get_assertion.c b/src/fido/cbor_get_assertion.c index ee25e79..37264e8 100644 --- a/src/fido/cbor_get_assertion.c +++ b/src/fido/cbor_get_assertion.c @@ -633,20 +633,10 @@ int cbor_get_assertion(const uint8_t *data, size_t len, bool next) { else if (ekey.grp.id == MBEDTLS_ECP_DP_SECP521R1) { md = mbedtls_md_info_from_type(MBEDTLS_MD_SHA512); } -#ifdef MBEDTLS_EDDSA_C - else if (ekey.grp.id == MBEDTLS_ECP_DP_ED25519) { - md = NULL; - } -#endif if (md != NULL) { ret = mbedtls_md(md, aut_data, aut_data_len + clientDataHash.len, hash); ret = mbedtls_ecdsa_write_signature(&ekey, mbedtls_md_get_type(md), hash, mbedtls_md_get_size(md), sig, sizeof(sig), &olen, random_gen, NULL); } -#ifdef MBEDTLS_EDDSA_C - else { - ret = mbedtls_eddsa_write_signature(&ekey, aut_data, aut_data_len + clientDataHash.len, sig, sizeof(sig), &olen, MBEDTLS_EDDSA_PURE, NULL, 0, random_gen, NULL); - } -#endif } else { // Bogus signature diff --git a/src/fido/cbor_get_info.c b/src/fido/cbor_get_info.c index 182e33a..92e32a5 100644 --- a/src/fido/cbor_get_info.c +++ b/src/fido/cbor_get_info.c @@ -114,9 +114,6 @@ int cbor_get_info() { CBOR_CHECK(cbor_encode_uint(&mapEncoder, 0x0A)); uint8_t curves = 3; -#ifdef MBEDTLS_EDDSA_C - curves++; -#endif #ifndef ENABLE_EMULATION if (phy_data.enabled_curves & PHY_CURVE_SECP256K1) { #endif @@ -126,9 +123,6 @@ int cbor_get_info() { #endif CBOR_CHECK(cbor_encoder_create_array(&mapEncoder, &arrayEncoder, curves)); CBOR_CHECK(COSE_public_key(FIDO2_ALG_ES256, &arrayEncoder, &mapEncoder2)); -#ifdef MBEDTLS_EDDSA_C - CBOR_CHECK(COSE_public_key(FIDO2_ALG_EDDSA, &arrayEncoder, &mapEncoder2)); -#endif CBOR_CHECK(COSE_public_key(FIDO2_ALG_ES384, &arrayEncoder, &mapEncoder2)); CBOR_CHECK(COSE_public_key(FIDO2_ALG_ES512, &arrayEncoder, &mapEncoder2)); #ifndef ENABLE_EMULATION diff --git a/src/fido/cbor_make_credential.c b/src/fido/cbor_make_credential.c index 25a5d41..7764d1c 100644 --- a/src/fido/cbor_make_credential.c +++ b/src/fido/cbor_make_credential.c @@ -273,18 +273,6 @@ int cbor_make_credential(const uint8_t *data, size_t len) { curve = FIDO2_CURVE_P256K1; } } -#ifdef MBEDTLS_EDDSA_C - else if (pubKeyCredParams[i].alg == FIDO2_ALG_EDDSA || pubKeyCredParams[i].alg == FIDO2_ALG_ED25519) { - if (curve <= 0) { - curve = FIDO2_CURVE_ED25519; - } - } - else if (pubKeyCredParams[i].alg == FIDO2_ALG_ED448) { - if (curve <= 0) { - curve = FIDO2_CURVE_ED448; - } - } -#endif else if (pubKeyCredParams[i].alg <= FIDO2_ALG_RS256 && pubKeyCredParams[i].alg >= FIDO2_ALG_RS512) { // pass } @@ -578,11 +566,6 @@ int cbor_make_credential(const uint8_t *data, size_t len) { else if (ekey.grp.id == MBEDTLS_ECP_DP_SECP521R1 || ekey.grp.id == MBEDTLS_ECP_DP_BP512R1) { md = mbedtls_md_info_from_type(MBEDTLS_MD_SHA512); } -#ifdef MBEDTLS_EDDSA_C - else if (ekey.grp.id == MBEDTLS_ECP_DP_ED25519 || ekey.grp.id == MBEDTLS_ECP_DP_ED448) { - md = NULL; - } -#endif if (md != NULL) { ret = mbedtls_md(md, aut_data, aut_data_len + clientDataHash.len, hash); } @@ -603,11 +586,6 @@ int cbor_make_credential(const uint8_t *data, size_t len) { if (md != NULL) { ret = mbedtls_ecdsa_write_signature(&ekey, mbedtls_md_get_type(md), hash, mbedtls_md_get_size(md), sig, sizeof(sig), &olen, random_gen, NULL); } -#ifdef MBEDTLS_EDDSA_C - else { - ret = mbedtls_eddsa_write_signature(&ekey, aut_data, aut_data_len + clientDataHash.len, sig, sizeof(sig), &olen, MBEDTLS_EDDSA_PURE, NULL, 0, random_gen, NULL); - } -#endif mbedtls_ecp_keypair_free(&ekey); if (ret != 0) { CBOR_ERROR(CTAP2_ERR_PROCESSING); diff --git a/src/fido/fido.c b/src/fido/fido.c index d6cb9d9..b2849ea 100644 --- a/src/fido/fido.c +++ b/src/fido/fido.c @@ -111,14 +111,6 @@ mbedtls_ecp_group_id fido_curve_to_mbedtls(int curve) { else if (curve == FIDO2_CURVE_X448) { return MBEDTLS_ECP_DP_CURVE448; } -#ifdef MBEDTLS_EDDSA_C - else if (curve == FIDO2_CURVE_ED25519) { - return MBEDTLS_ECP_DP_ED25519; - } - else if (curve == FIDO2_CURVE_ED448) { - return MBEDTLS_ECP_DP_ED448; - } -#endif else if (curve == FIDO2_CURVE_BP256R1) { return MBEDTLS_ECP_DP_BP256R1; } @@ -149,14 +141,6 @@ int mbedtls_curve_to_fido(mbedtls_ecp_group_id id) { else if (id == MBEDTLS_ECP_DP_CURVE448) { return FIDO2_CURVE_X448; } -#ifdef MBEDTLS_EDDSA_C - else if (id == MBEDTLS_ECP_DP_ED25519) { - return FIDO2_CURVE_ED25519; - } - else if (id == MBEDTLS_ECP_DP_ED448) { - return FIDO2_CURVE_ED448; - } -#endif return 0; } @@ -330,11 +314,6 @@ int derive_key(const uint8_t *app_id, bool new_key, uint8_t *key_handle, int cur if (r != 0) { return r; } -#ifdef MBEDTLS_EDDSA_C - if (curve == MBEDTLS_ECP_DP_ED25519) { - return mbedtls_ecp_point_edwards(&key->grp, &key->Q, &key->d, random_gen, NULL); - } -#endif return mbedtls_ecp_mul(&key->grp, &key->Q, &key->d, &key->grp.G, random_gen, NULL); } mbedtls_platform_zeroize(outk, sizeof(outk)); diff --git a/src/fido/fido.h b/src/fido/fido.h index 481aa6c..1c3a257 100644 --- a/src/fido/fido.h +++ b/src/fido/fido.h @@ -28,9 +28,6 @@ #endif #include "mbedtls/ecdsa.h" -#ifdef MBEDTLS_EDDSA_C -#include "mbedtls/eddsa.h" -#endif #include "hid/ctap_hid.h" #define CTAP_PUBKEY_LEN (65) @@ -57,16 +54,13 @@ extern int decrypt(uint8_t protocol, const uint8_t *key, const uint8_t *in, uint extern int ecdh(uint8_t protocol, const mbedtls_ecp_point *Q, uint8_t *sharedSecret); #define FIDO2_ALG_ES256 -7 //ECDSA-SHA256 -#define FIDO2_ALG_EDDSA -8 //EdDSA #define FIDO2_ALG_ESP256 -9 //ECDSA-SHA256 P256 -#define FIDO2_ALG_ED25519 -19 //EDDSA Ed25519 #define FIDO2_ALG_ES384 -35 //ECDSA-SHA384 #define FIDO2_ALG_ES512 -36 //ECDSA-SHA512 #define FIDO2_ALG_ECDH_ES_HKDF_256 -25 //ECDH-ES + HKDF-256 #define FIDO2_ALG_ES256K -47 #define FIDO2_ALG_ESP384 -51 //ECDSA-SHA384 P384 #define FIDO2_ALG_ESP512 -52 //ECDSA-SHA512 P521 -#define FIDO2_ALG_ED448 -53 //EDDSA Ed448 #define FIDO2_ALG_RS256 -257 #define FIDO2_ALG_RS384 -258 #define FIDO2_ALG_RS512 -259 @@ -79,8 +73,6 @@ extern int ecdh(uint8_t protocol, const mbedtls_ecp_point *Q, uint8_t *sharedSec #define FIDO2_CURVE_P521 3 #define FIDO2_CURVE_X25519 4 #define FIDO2_CURVE_X448 5 -#define FIDO2_CURVE_ED25519 6 -#define FIDO2_CURVE_ED448 7 #define FIDO2_CURVE_P256K1 8 #define FIDO2_CURVE_BP256R1 9 #define FIDO2_CURVE_BP384R1 10 From 46720fb387d08a9925a4bb26945c88864bb7e6ed Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Tue, 9 Dec 2025 18:52:13 +0100 Subject: [PATCH 4/4] Move other curves to another branch. Signed-off-by: Pol Henarejos --- src/fido/cbor.c | 15 +------------ src/fido/cbor_get_info.c | 18 +-------------- src/fido/cbor_make_credential.c | 36 +----------------------------- src/fido/fido.c | 39 --------------------------------- src/fido/fido.h | 19 +--------------- 5 files changed, 4 insertions(+), 123 deletions(-) diff --git a/src/fido/cbor.c b/src/fido/cbor.c index b681c83..772ec50 100644 --- a/src/fido/cbor.c +++ b/src/fido/cbor.c @@ -151,8 +151,7 @@ int cbor_process(uint8_t last_cmd, const uint8_t *data, size_t len) { CborError COSE_key_params(int crv, int alg, mbedtls_ecp_group *grp, mbedtls_ecp_point *Q, CborEncoder *mapEncoderParent, CborEncoder *mapEncoder) { CborError error = CborNoError; int kty = 1; - if (crv == FIDO2_CURVE_P256 || crv == FIDO2_CURVE_P384 || crv == FIDO2_CURVE_P521 || - crv == FIDO2_CURVE_P256K1) { + if (crv == FIDO2_CURVE_P256) { kty = 2; } @@ -197,18 +196,6 @@ CborError COSE_key(mbedtls_ecp_keypair *key, CborEncoder *mapEncoderParent, if (key->grp.id == MBEDTLS_ECP_DP_SECP256R1) { alg = FIDO2_ALG_ES256; } - else if (key->grp.id == MBEDTLS_ECP_DP_SECP384R1) { - alg = FIDO2_ALG_ES384; - } - else if (key->grp.id == MBEDTLS_ECP_DP_SECP521R1) { - alg = FIDO2_ALG_ES512; - } - else if (key->grp.id == MBEDTLS_ECP_DP_SECP256K1) { - alg = FIDO2_ALG_ES256K; - } - else if (key->grp.id == MBEDTLS_ECP_DP_CURVE25519) { - alg = FIDO2_ALG_ECDH_ES_HKDF_256; - } return COSE_key_params(crv, alg, &key->grp, &key->Q, mapEncoderParent, mapEncoder); } CborError COSE_key_shared(mbedtls_ecdh_context *key, diff --git a/src/fido/cbor_get_info.c b/src/fido/cbor_get_info.c index 92e32a5..25c8d4d 100644 --- a/src/fido/cbor_get_info.c +++ b/src/fido/cbor_get_info.c @@ -113,25 +113,9 @@ int cbor_get_info() { CBOR_CHECK(cbor_encode_uint(&mapEncoder, 0x0A)); - uint8_t curves = 3; -#ifndef ENABLE_EMULATION - if (phy_data.enabled_curves & PHY_CURVE_SECP256K1) { -#endif - curves++; -#ifndef ENABLE_EMULATION - } -#endif + uint8_t curves = 1; CBOR_CHECK(cbor_encoder_create_array(&mapEncoder, &arrayEncoder, curves)); CBOR_CHECK(COSE_public_key(FIDO2_ALG_ES256, &arrayEncoder, &mapEncoder2)); - CBOR_CHECK(COSE_public_key(FIDO2_ALG_ES384, &arrayEncoder, &mapEncoder2)); - CBOR_CHECK(COSE_public_key(FIDO2_ALG_ES512, &arrayEncoder, &mapEncoder2)); -#ifndef ENABLE_EMULATION - if (phy_data.enabled_curves & PHY_CURVE_SECP256K1) { -#endif - CBOR_CHECK(COSE_public_key(FIDO2_ALG_ES256K, &arrayEncoder, &mapEncoder2)); -#ifndef ENABLE_EMULATION - } -#endif CBOR_CHECK(cbor_encoder_close_container(&mapEncoder, &arrayEncoder)); diff --git a/src/fido/cbor_make_credential.c b/src/fido/cbor_make_credential.c index 7764d1c..01785f4 100644 --- a/src/fido/cbor_make_credential.c +++ b/src/fido/cbor_make_credential.c @@ -234,45 +234,11 @@ int cbor_make_credential(const uint8_t *data, size_t len) { if (strcmp(pubKeyCredParams[i].type.data, "public-key") != 0) { CBOR_ERROR(CTAP2_ERR_CBOR_UNEXPECTED_TYPE); } - if (pubKeyCredParams[i].alg == FIDO2_ALG_ES256 || pubKeyCredParams[i].alg == FIDO2_ALG_ESP256) { + if (pubKeyCredParams[i].alg == FIDO2_ALG_ES256) { if (curve <= 0) { curve = FIDO2_CURVE_P256; } } - else if (pubKeyCredParams[i].alg == FIDO2_ALG_ES384 || pubKeyCredParams[i].alg == FIDO2_ALG_ESP384) { - if (curve <= 0) { - curve = FIDO2_CURVE_P384; - } - } - else if (pubKeyCredParams[i].alg == FIDO2_ALG_ES512 || pubKeyCredParams[i].alg == FIDO2_ALG_ESP512) { - if (curve <= 0) { - curve = FIDO2_CURVE_P521; - } - } - else if (pubKeyCredParams[i].alg == FIDO2_ALG_ESB256) { - if (curve <= 0) { - curve = FIDO2_CURVE_BP256R1; - } - } - else if (pubKeyCredParams[i].alg == FIDO2_ALG_ESB384) { - if (curve <= 0) { - curve = FIDO2_CURVE_BP384R1; - } - } - else if (pubKeyCredParams[i].alg == FIDO2_ALG_ESB512) { - if (curve <= 0) { - curve = FIDO2_CURVE_BP512R1; - } - } - else if (pubKeyCredParams[i].alg == FIDO2_ALG_ES256K -#ifndef ENABLE_EMULATION - && (phy_data.enabled_curves & PHY_CURVE_SECP256K1) -#endif - ) { - if (curve <= 0) { - curve = FIDO2_CURVE_P256K1; - } - } else if (pubKeyCredParams[i].alg <= FIDO2_ALG_RS256 && pubKeyCredParams[i].alg >= FIDO2_ALG_RS512) { // pass } diff --git a/src/fido/fido.c b/src/fido/fido.c index b2849ea..68dc521 100644 --- a/src/fido/fido.c +++ b/src/fido/fido.c @@ -96,51 +96,12 @@ mbedtls_ecp_group_id fido_curve_to_mbedtls(int curve) { if (curve == FIDO2_CURVE_P256) { return MBEDTLS_ECP_DP_SECP256R1; } - else if (curve == FIDO2_CURVE_P384) { - return MBEDTLS_ECP_DP_SECP384R1; - } - else if (curve == FIDO2_CURVE_P521) { - return MBEDTLS_ECP_DP_SECP521R1; - } - else if (curve == FIDO2_CURVE_P256K1) { - return MBEDTLS_ECP_DP_SECP256K1; - } - else if (curve == FIDO2_CURVE_X25519) { - return MBEDTLS_ECP_DP_CURVE25519; - } - else if (curve == FIDO2_CURVE_X448) { - return MBEDTLS_ECP_DP_CURVE448; - } - else if (curve == FIDO2_CURVE_BP256R1) { - return MBEDTLS_ECP_DP_BP256R1; - } - else if (curve == FIDO2_CURVE_BP384R1) { - return MBEDTLS_ECP_DP_BP384R1; - } - else if (curve == FIDO2_CURVE_BP512R1) { - return MBEDTLS_ECP_DP_BP512R1; - } return MBEDTLS_ECP_DP_NONE; } int mbedtls_curve_to_fido(mbedtls_ecp_group_id id) { if (id == MBEDTLS_ECP_DP_SECP256R1) { return FIDO2_CURVE_P256; } - else if (id == MBEDTLS_ECP_DP_SECP384R1) { - return FIDO2_CURVE_P384; - } - else if (id == MBEDTLS_ECP_DP_SECP521R1) { - return FIDO2_CURVE_P521; - } - else if (id == MBEDTLS_ECP_DP_SECP256K1) { - return FIDO2_CURVE_P256K1; - } - else if (id == MBEDTLS_ECP_DP_CURVE25519) { - return MBEDTLS_ECP_DP_CURVE25519; - } - else if (id == MBEDTLS_ECP_DP_CURVE448) { - return FIDO2_CURVE_X448; - } return 0; } diff --git a/src/fido/fido.h b/src/fido/fido.h index 1c3a257..15f9f40 100644 --- a/src/fido/fido.h +++ b/src/fido/fido.h @@ -54,29 +54,12 @@ extern int decrypt(uint8_t protocol, const uint8_t *key, const uint8_t *in, uint extern int ecdh(uint8_t protocol, const mbedtls_ecp_point *Q, uint8_t *sharedSecret); #define FIDO2_ALG_ES256 -7 //ECDSA-SHA256 -#define FIDO2_ALG_ESP256 -9 //ECDSA-SHA256 P256 -#define FIDO2_ALG_ES384 -35 //ECDSA-SHA384 -#define FIDO2_ALG_ES512 -36 //ECDSA-SHA512 -#define FIDO2_ALG_ECDH_ES_HKDF_256 -25 //ECDH-ES + HKDF-256 -#define FIDO2_ALG_ES256K -47 -#define FIDO2_ALG_ESP384 -51 //ECDSA-SHA384 P384 -#define FIDO2_ALG_ESP512 -52 //ECDSA-SHA512 P521 #define FIDO2_ALG_RS256 -257 #define FIDO2_ALG_RS384 -258 #define FIDO2_ALG_RS512 -259 -#define FIDO2_ALG_ESB256 -265 //ECDSA-SHA256 BP256r1 -#define FIDO2_ALG_ESB384 -267 //ECDSA-SHA384 BP384r1 -#define FIDO2_ALG_ESB512 -268 //ECDSA-SHA512 BP512r1 #define FIDO2_CURVE_P256 1 -#define FIDO2_CURVE_P384 2 -#define FIDO2_CURVE_P521 3 -#define FIDO2_CURVE_X25519 4 -#define FIDO2_CURVE_X448 5 -#define FIDO2_CURVE_P256K1 8 -#define FIDO2_CURVE_BP256R1 9 -#define FIDO2_CURVE_BP384R1 10 -#define FIDO2_CURVE_BP512R1 11 +#define FIDO2_ALG_ECDH_ES_HKDF_256 -25 //ECDH-ES + HKDF-256 #define FIDO2_AUT_FLAG_UP 0x1 #define FIDO2_AUT_FLAG_UV 0x4