Skip to content

Commit 6de499e

Browse files
committed
Add EdDSA support as a conditional build.
Signed-off-by: Pol Henarejos <[email protected]>
1 parent ddb6b4b commit 6de499e

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/openpgp/cmd_import_data.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,13 @@ int cmd_import_data() {
177177
mbedtls_ecp_keypair_free(&ecdsa);
178178
return SW_EXEC_ERROR();
179179
}
180+
#ifdef MBEDTLS_EDDSA_C
180181
if (ecdsa.grp.id == MBEDTLS_ECP_DP_ED25519) {
181182
r = mbedtls_ecp_point_edwards(&ecdsa.grp, &ecdsa.Q, &ecdsa.d, random_gen, NULL);
182183
}
183-
else {
184+
else
185+
#endif
186+
{
184187
r = mbedtls_ecp_mul(&ecdsa.grp, &ecdsa.Q, &ecdsa.d, &ecdsa.grp.G, random_gen, NULL);
185188
}
186189
if (r != 0) {

src/openpgp/openpgp.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
#include "ccid/ccid.h"
3131
#include "otp.h"
3232
#include "do.h"
33+
#ifdef MBEDTLS_EDDSA_C
3334
#include "mbedtls/eddsa.h"
35+
#endif
3436

3537
uint8_t PICO_PRODUCT = 3;
3638

@@ -573,10 +575,13 @@ int load_private_key_ecdsa(mbedtls_ecp_keypair *ctx, file_t *fkey, bool use_dek)
573575
return PICOKEY_EXEC_ERROR;
574576
}
575577
mbedtls_platform_zeroize(kdata, sizeof(kdata));
578+
#ifdef MBEDTLS_EDDSA_C
576579
if (ctx->grp.id == MBEDTLS_ECP_DP_ED25519) {
577580
r = mbedtls_ecp_point_edwards(&ctx->grp, &ctx->Q, &ctx->d, random_gen, NULL);
578581
}
579-
else {
582+
else
583+
#endif
584+
{
580585
r = mbedtls_ecp_mul(&ctx->grp, &ctx->Q, &ctx->d, &ctx->grp.G, random_gen, NULL);
581586
}
582587
if (r != 0) {
@@ -623,9 +628,11 @@ mbedtls_ecp_group_id get_ec_group_id_from_attr(const uint8_t *algo, size_t algo_
623628
else if (memcmp(algorithm_attr_x448 + 2, algo, algo_len) == 0) {
624629
return MBEDTLS_ECP_DP_CURVE448;
625630
}
631+
#ifdef MBEDTLS_EDDSA_C
626632
else if (memcmp(algorithm_attr_ed25519 + 2, algo, algo_len) == 0) {
627633
return MBEDTLS_ECP_DP_ED25519;
628634
}
635+
#endif
629636
return MBEDTLS_ECP_DP_NONE;
630637
}
631638

@@ -744,10 +751,13 @@ int ecdsa_sign(mbedtls_ecp_keypair *ctx,
744751
size_t *out_len) {
745752

746753
int r = 0;
754+
#ifdef MBEDTLS_EDDSA_C
747755
if (ctx->grp.id == MBEDTLS_ECP_DP_ED25519) {
748756
r = mbedtls_eddsa_write_signature(ctx, data, data_len, out, 64, out_len, MBEDTLS_EDDSA_PURE, NULL, 0, random_gen, NULL);
749757
}
750-
else {
758+
else
759+
#endif
760+
{
751761
mbedtls_mpi ri, si;
752762
mbedtls_mpi_init(&ri);
753763
mbedtls_mpi_init(&si);

tests/build-in-docker.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
source tests/docker_env.sh
44
#run_in_docker rm -rf CMakeFiles
55
run_in_docker mkdir -p build_in_docker
6-
run_in_docker -w "$PWD/build_in_docker" cmake -DENABLE_EMULATION=1 ..
6+
run_in_docker -w "$PWD/build_in_docker" cmake -DENABLE_EMULATION=1 -DENABLE_EDDSA=1 ..
77
run_in_docker -w "$PWD/build_in_docker" make -j ${NUM_PROC}

0 commit comments

Comments
 (0)