Skip to content

Commit 48cc417

Browse files
committed
Added support for Brainpool curves and Ed448.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
1 parent 2919b37 commit 48cc417

4 files changed

Lines changed: 55 additions & 16 deletions

File tree

src/fido/cbor.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ CborError COSE_key(mbedtls_ecp_keypair *key, CborEncoder *mapEncoderParent,
214214
else if (key->grp.id == MBEDTLS_ECP_DP_ED25519) {
215215
alg = FIDO2_ALG_EDDSA;
216216
}
217+
else if (key->grp.id == MBEDTLS_ECP_DP_ED448) {
218+
alg = FIDO2_ALG_ED448;
219+
}
217220
#endif
218221
return COSE_key_params(crv, alg, &key->grp, &key->Q, mapEncoderParent, mapEncoder);
219222
}

src/fido/cbor_make_credential.c

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,36 @@ int cbor_make_credential(const uint8_t *data, size_t len) {
231231
if (strcmp(pubKeyCredParams[i].type.data, "public-key") != 0) {
232232
CBOR_ERROR(CTAP2_ERR_CBOR_UNEXPECTED_TYPE);
233233
}
234-
if (pubKeyCredParams[i].alg == FIDO2_ALG_ES256) {
234+
if (pubKeyCredParams[i].alg == FIDO2_ALG_ES256 || pubKeyCredParams[i].alg == FIDO2_ALG_ESP256) {
235235
if (curve <= 0) {
236236
curve = FIDO2_CURVE_P256;
237237
}
238238
}
239-
else if (pubKeyCredParams[i].alg == FIDO2_ALG_ES384) {
239+
else if (pubKeyCredParams[i].alg == FIDO2_ALG_ES384 || pubKeyCredParams[i].alg == FIDO2_ALG_ESP384) {
240240
if (curve <= 0) {
241241
curve = FIDO2_CURVE_P384;
242242
}
243243
}
244-
else if (pubKeyCredParams[i].alg == FIDO2_ALG_ES512) {
244+
else if (pubKeyCredParams[i].alg == FIDO2_ALG_ES512 || pubKeyCredParams[i].alg == FIDO2_ALG_ESP512) {
245245
if (curve <= 0) {
246246
curve = FIDO2_CURVE_P521;
247247
}
248248
}
249+
else if (pubKeyCredParams[i].alg == FIDO2_ALG_ESB256) {
250+
if (curve <= 0) {
251+
curve = FIDO2_CURVE_BP256R1;
252+
}
253+
}
254+
else if (pubKeyCredParams[i].alg == FIDO2_ALG_ESB384) {
255+
if (curve <= 0) {
256+
curve = FIDO2_CURVE_BP384R1;
257+
}
258+
}
259+
else if (pubKeyCredParams[i].alg == FIDO2_ALG_ESB512) {
260+
if (curve <= 0) {
261+
curve = FIDO2_CURVE_BP512R1;
262+
}
263+
}
249264
else if (pubKeyCredParams[i].alg == FIDO2_ALG_ES256K
250265
#ifndef ENABLE_EMULATION
251266
&& (phy_data.enabled_curves & PHY_CURVE_SECP256K1)
@@ -256,11 +271,16 @@ int cbor_make_credential(const uint8_t *data, size_t len) {
256271
}
257272
}
258273
#ifdef MBEDTLS_EDDSA_C
259-
else if (pubKeyCredParams[i].alg == FIDO2_ALG_EDDSA) {
274+
else if (pubKeyCredParams[i].alg == FIDO2_ALG_EDDSA || pubKeyCredParams[i].alg == FIDO2_ALG_ED25519) {
260275
if (curve <= 0) {
261276
curve = FIDO2_CURVE_ED25519;
262277
}
263278
}
279+
else if (pubKeyCredParams[i].alg == FIDO2_ALG_ED448) {
280+
if (curve <= 0) {
281+
curve = FIDO2_CURVE_ED448;
282+
}
283+
}
264284
#endif
265285
else if (pubKeyCredParams[i].alg <= FIDO2_ALG_RS256 && pubKeyCredParams[i].alg >= FIDO2_ALG_RS512) {
266286
// pass
@@ -327,9 +347,7 @@ int cbor_make_credential(const uint8_t *data, size_t len) {
327347
continue;
328348
}
329349
Credential ecred = {0};
330-
if (credential_load(excludeList[e].id.data, excludeList[e].id.len, rp_id_hash,
331-
&ecred) == 0 &&
332-
(ecred.extensions.credProtect != CRED_PROT_UV_REQUIRED ||
350+
if (credential_load(excludeList[e].id.data, excludeList[e].id.len, rp_id_hash, &ecred) == 0 && (ecred.extensions.credProtect != CRED_PROT_UV_REQUIRED ||
333351
(flags & FIDO2_AUT_FLAG_UV))) {
334352
credential_free(&ecred);
335353
CBOR_ERROR(CTAP2_ERR_CREDENTIAL_EXCLUDED);
@@ -367,9 +385,7 @@ int cbor_make_credential(const uint8_t *data, size_t len) {
367385
uint8_t cred_id[MAX_CRED_ID_LENGTH] = {0};
368386
size_t cred_id_len = 0;
369387

370-
CBOR_CHECK(credential_create(&rp.id, &user.id, &user.parent.name, &user.displayName, &options,
371-
&extensions, (!ka || ka->use_sign_count == ptrue), alg, curve,
372-
cred_id, &cred_id_len));
388+
CBOR_CHECK(credential_create(&rp.id, &user.id, &user.parent.name, &user.displayName, &options, &extensions, (!ka || ka->use_sign_count == ptrue), alg, curve, cred_id, &cred_id_len));
373389

374390
if (getUserVerifiedFlagValue()) {
375391
flags |= FIDO2_AUT_FLAG_UV;
@@ -523,14 +539,14 @@ int cbor_make_credential(const uint8_t *data, size_t len) {
523539
memcpy(pa, clientDataHash.data, clientDataHash.len);
524540
uint8_t hash[64] = {0}, sig[MBEDTLS_ECDSA_MAX_LEN] = {0};
525541
const mbedtls_md_info_t *md = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
526-
if (ekey.grp.id == MBEDTLS_ECP_DP_SECP384R1) {
542+
if (ekey.grp.id == MBEDTLS_ECP_DP_SECP384R1 || ekey.grp.id == MBEDTLS_ECP_DP_BP384R1) {
527543
md = mbedtls_md_info_from_type(MBEDTLS_MD_SHA384);
528544
}
529-
else if (ekey.grp.id == MBEDTLS_ECP_DP_SECP521R1) {
545+
else if (ekey.grp.id == MBEDTLS_ECP_DP_SECP521R1 || ekey.grp.id == MBEDTLS_ECP_DP_BP512R1) {
530546
md = mbedtls_md_info_from_type(MBEDTLS_MD_SHA512);
531547
}
532548
#ifdef MBEDTLS_EDDSA_C
533-
else if (ekey.grp.id == MBEDTLS_ECP_DP_ED25519) {
549+
else if (ekey.grp.id == MBEDTLS_ECP_DP_ED25519 || ekey.grp.id == MBEDTLS_ECP_DP_ED448) {
534550
md = NULL;
535551
}
536552
#endif

src/fido/fido.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ mbedtls_ecp_group_id fido_curve_to_mbedtls(int curve) {
119119
return MBEDTLS_ECP_DP_ED448;
120120
}
121121
#endif
122+
else if (curve == FIDO2_CURVE_BP256R1) {
123+
return MBEDTLS_ECP_DP_BP256R1;
124+
}
125+
else if (curve == FIDO2_CURVE_BP384R1) {
126+
return MBEDTLS_ECP_DP_BP384R1;
127+
}
128+
else if (curve == FIDO2_CURVE_BP512R1) {
129+
return MBEDTLS_ECP_DP_BP512R1;
130+
}
122131
return MBEDTLS_ECP_DP_NONE;
123132
}
124133
int mbedtls_curve_to_fido(mbedtls_ecp_group_id id) {

src/fido/fido.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,23 @@ extern int encrypt(uint8_t protocol, const uint8_t *key, const uint8_t *in, uint
6060
extern int decrypt(uint8_t protocol, const uint8_t *key, const uint8_t *in, uint16_t in_len, uint8_t *out);
6161
extern int ecdh(uint8_t protocol, const mbedtls_ecp_point *Q, uint8_t *sharedSecret);
6262

63-
#define FIDO2_ALG_ES256 -7 //ECDSA-SHA256 P256
63+
#define FIDO2_ALG_ES256 -7 //ECDSA-SHA256
6464
#define FIDO2_ALG_EDDSA -8 //EdDSA
65-
#define FIDO2_ALG_ES384 -35 //ECDSA-SHA384 P384
66-
#define FIDO2_ALG_ES512 -36 //ECDSA-SHA512 P521
65+
#define FIDO2_ALG_ESP256 -9 //ECDSA-SHA256 P256
66+
#define FIDO2_ALG_ED25519 -19 //EDDSA Ed25519
67+
#define FIDO2_ALG_ES384 -35 //ECDSA-SHA384
68+
#define FIDO2_ALG_ES512 -36 //ECDSA-SHA512
6769
#define FIDO2_ALG_ECDH_ES_HKDF_256 -25 //ECDH-ES + HKDF-256
6870
#define FIDO2_ALG_ES256K -47
71+
#define FIDO2_ALG_ESP384 -51 //ECDSA-SHA384 P384
72+
#define FIDO2_ALG_ESP512 -52 //ECDSA-SHA512 P521
73+
#define FIDO2_ALG_ED448 -53 //EDDSA Ed448
6974
#define FIDO2_ALG_RS256 -257
7075
#define FIDO2_ALG_RS384 -258
7176
#define FIDO2_ALG_RS512 -259
77+
#define FIDO2_ALG_ESB256 -265 //ECDSA-SHA256 BP256r1
78+
#define FIDO2_ALG_ESB384 -267 //ECDSA-SHA384 BP384r1
79+
#define FIDO2_ALG_ESB512 -268 //ECDSA-SHA512 BP512r1
7280

7381
#define FIDO2_CURVE_P256 1
7482
#define FIDO2_CURVE_P384 2
@@ -78,6 +86,9 @@ extern int ecdh(uint8_t protocol, const mbedtls_ecp_point *Q, uint8_t *sharedSec
7886
#define FIDO2_CURVE_ED25519 6
7987
#define FIDO2_CURVE_ED448 7
8088
#define FIDO2_CURVE_P256K1 8
89+
#define FIDO2_CURVE_BP256R1 9
90+
#define FIDO2_CURVE_BP384R1 10
91+
#define FIDO2_CURVE_BP512R1 11
8192

8293
#define FIDO2_AUT_FLAG_UP 0x1
8394
#define FIDO2_AUT_FLAG_UV 0x4

0 commit comments

Comments
 (0)