mirror of
https://github.com/polhenarejos/pico-fido.git
synced 2025-12-16 16:08:21 +08:00
Revert "Move other curves to another branch."
This reverts commit 46720fb387.
This commit is contained in:
@@ -151,7 +151,8 @@ 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) {
|
||||
if (crv == FIDO2_CURVE_P256 || crv == FIDO2_CURVE_P384 || crv == FIDO2_CURVE_P521 ||
|
||||
crv == FIDO2_CURVE_P256K1) {
|
||||
kty = 2;
|
||||
}
|
||||
|
||||
@@ -196,6 +197,18 @@ 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,
|
||||
|
||||
@@ -113,9 +113,25 @@ int cbor_get_info() {
|
||||
|
||||
CBOR_CHECK(cbor_encode_uint(&mapEncoder, 0x0A));
|
||||
|
||||
uint8_t curves = 1;
|
||||
uint8_t curves = 3;
|
||||
#ifndef ENABLE_EMULATION
|
||||
if (phy_data.enabled_curves & PHY_CURVE_SECP256K1) {
|
||||
#endif
|
||||
curves++;
|
||||
#ifndef ENABLE_EMULATION
|
||||
}
|
||||
#endif
|
||||
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));
|
||||
|
||||
|
||||
@@ -234,11 +234,45 @@ 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) {
|
||||
if (pubKeyCredParams[i].alg == FIDO2_ALG_ES256 || pubKeyCredParams[i].alg == FIDO2_ALG_ESP256) {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -96,12 +96,51 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,12 +54,29 @@ 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_ALG_ECDH_ES_HKDF_256 -25 //ECDH-ES + HKDF-256
|
||||
#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_AUT_FLAG_UP 0x1
|
||||
#define FIDO2_AUT_FLAG_UV 0x4
|
||||
|
||||
Reference in New Issue
Block a user