mirror of
https://github.com/polhenarejos/pico-openpgp.git
synced 2025-12-18 18:01:09 +08:00
Submodule pico-keys-sdk updated: 09ec0767b6...d0dea3d0c5
@@ -177,7 +177,15 @@ int cmd_import_data() {
|
|||||||
mbedtls_ecp_keypair_free(&ecdsa);
|
mbedtls_ecp_keypair_free(&ecdsa);
|
||||||
return SW_EXEC_ERROR();
|
return SW_EXEC_ERROR();
|
||||||
}
|
}
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
|
if (ecdsa.grp.id == MBEDTLS_ECP_DP_ED25519) {
|
||||||
|
r = mbedtls_ecp_point_edwards(&ecdsa.grp, &ecdsa.Q, &ecdsa.d, random_gen, NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
r = mbedtls_ecp_mul(&ecdsa.grp, &ecdsa.Q, &ecdsa.d, &ecdsa.grp.G, random_gen, NULL);
|
r = mbedtls_ecp_mul(&ecdsa.grp, &ecdsa.Q, &ecdsa.d, &ecdsa.grp.G, random_gen, NULL);
|
||||||
|
}
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
mbedtls_ecp_keypair_free(&ecdsa);
|
mbedtls_ecp_keypair_free(&ecdsa);
|
||||||
return SW_EXEC_ERROR();
|
return SW_EXEC_ERROR();
|
||||||
|
|||||||
@@ -256,6 +256,20 @@ const uint8_t algorithm_attr_cv25519[] = {
|
|||||||
0x2b, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01
|
0x2b, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
|
const uint8_t algorithm_attr_ed25519[] = {
|
||||||
|
10,
|
||||||
|
ALGO_EDDSA,
|
||||||
|
0x2b, 0x06, 0x01, 0x04, 0x01, 0xda, 0x47, 0x0f, 0x01
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint8_t algorithm_attr_ed448[] = {
|
||||||
|
4,
|
||||||
|
ALGO_EDDSA,
|
||||||
|
0x2b, 0x65, 0x71
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
int parse_algo(const uint8_t *algo, uint16_t tag) {
|
int parse_algo(const uint8_t *algo, uint16_t tag) {
|
||||||
res_APDU[res_APDU_size++] = tag & 0xff;
|
res_APDU[res_APDU_size++] = tag & 0xff;
|
||||||
memcpy(res_APDU + res_APDU_size, algo, algo[0] + 1);
|
memcpy(res_APDU + res_APDU_size, algo, algo[0] + 1);
|
||||||
@@ -281,6 +295,10 @@ int parse_algoinfo(const file_t *f, int mode) {
|
|||||||
datalen += parse_algo(algorithm_attr_bp256r1, EF_ALGO_SIG);
|
datalen += parse_algo(algorithm_attr_bp256r1, EF_ALGO_SIG);
|
||||||
datalen += parse_algo(algorithm_attr_bp384r1, EF_ALGO_SIG);
|
datalen += parse_algo(algorithm_attr_bp384r1, EF_ALGO_SIG);
|
||||||
datalen += parse_algo(algorithm_attr_bp512r1, EF_ALGO_SIG);
|
datalen += parse_algo(algorithm_attr_bp512r1, EF_ALGO_SIG);
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
|
datalen += parse_algo(algorithm_attr_ed25519, EF_ALGO_SIG);
|
||||||
|
datalen += parse_algo(algorithm_attr_ed448, EF_ALGO_SIG);
|
||||||
|
#endif
|
||||||
|
|
||||||
datalen += parse_algo(algorithm_attr_rsa1k, EF_ALGO_DEC);
|
datalen += parse_algo(algorithm_attr_rsa1k, EF_ALGO_DEC);
|
||||||
datalen += parse_algo(algorithm_attr_rsa2k, EF_ALGO_DEC);
|
datalen += parse_algo(algorithm_attr_rsa2k, EF_ALGO_DEC);
|
||||||
@@ -307,7 +325,10 @@ int parse_algoinfo(const file_t *f, int mode) {
|
|||||||
datalen += parse_algo(algorithm_attr_bp256r1, EF_ALGO_AUT);
|
datalen += parse_algo(algorithm_attr_bp256r1, EF_ALGO_AUT);
|
||||||
datalen += parse_algo(algorithm_attr_bp384r1, EF_ALGO_AUT);
|
datalen += parse_algo(algorithm_attr_bp384r1, EF_ALGO_AUT);
|
||||||
datalen += parse_algo(algorithm_attr_bp512r1, EF_ALGO_AUT);
|
datalen += parse_algo(algorithm_attr_bp512r1, EF_ALGO_AUT);
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
|
datalen += parse_algo(algorithm_attr_ed25519, EF_ALGO_AUT);
|
||||||
|
datalen += parse_algo(algorithm_attr_ed448, EF_ALGO_AUT);
|
||||||
|
#endif
|
||||||
uint16_t lpdif = res_APDU + res_APDU_size - lp - 2;
|
uint16_t lpdif = res_APDU + res_APDU_size - lp - 2;
|
||||||
*lp++ = lpdif >> 8;
|
*lp++ = lpdif >> 8;
|
||||||
*lp++ = lpdif & 0xff;
|
*lp++ = lpdif & 0xff;
|
||||||
|
|||||||
@@ -26,3 +26,7 @@ extern const uint8_t algorithm_attr_cv25519[];
|
|||||||
extern const uint8_t algorithm_attr_x448[];
|
extern const uint8_t algorithm_attr_x448[];
|
||||||
extern const uint8_t algorithm_attr_rsa2k[];
|
extern const uint8_t algorithm_attr_rsa2k[];
|
||||||
extern const uint8_t algorithm_attr_rsa4096[];
|
extern const uint8_t algorithm_attr_rsa4096[];
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
|
extern const uint8_t algorithm_attr_ed25519[];
|
||||||
|
extern const uint8_t algorithm_attr_ed448[];
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -30,6 +30,9 @@
|
|||||||
#include "ccid/ccid.h"
|
#include "ccid/ccid.h"
|
||||||
#include "otp.h"
|
#include "otp.h"
|
||||||
#include "do.h"
|
#include "do.h"
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
|
#include "mbedtls/eddsa.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
bool has_pw1 = false;
|
bool has_pw1 = false;
|
||||||
bool has_pw2 = false;
|
bool has_pw2 = false;
|
||||||
@@ -570,7 +573,15 @@ int load_private_key_ecdsa(mbedtls_ecp_keypair *ctx, file_t *fkey, bool use_dek)
|
|||||||
return PICOKEY_EXEC_ERROR;
|
return PICOKEY_EXEC_ERROR;
|
||||||
}
|
}
|
||||||
mbedtls_platform_zeroize(kdata, sizeof(kdata));
|
mbedtls_platform_zeroize(kdata, sizeof(kdata));
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
|
if (ctx->grp.id == MBEDTLS_ECP_DP_ED25519 || ctx->grp.id == MBEDTLS_ECP_DP_ED448) {
|
||||||
|
r = mbedtls_ecp_point_edwards(&ctx->grp, &ctx->Q, &ctx->d, random_gen, NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
r = mbedtls_ecp_mul(&ctx->grp, &ctx->Q, &ctx->d, &ctx->grp.G, random_gen, NULL);
|
r = mbedtls_ecp_mul(&ctx->grp, &ctx->Q, &ctx->d, &ctx->grp.G, random_gen, NULL);
|
||||||
|
}
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
mbedtls_ecdsa_free(ctx);
|
mbedtls_ecdsa_free(ctx);
|
||||||
return PICOKEY_EXEC_ERROR;
|
return PICOKEY_EXEC_ERROR;
|
||||||
@@ -615,6 +626,14 @@ mbedtls_ecp_group_id get_ec_group_id_from_attr(const uint8_t *algo, size_t algo_
|
|||||||
else if (memcmp(algorithm_attr_x448 + 2, algo, algo_len) == 0) {
|
else if (memcmp(algorithm_attr_x448 + 2, algo, algo_len) == 0) {
|
||||||
return MBEDTLS_ECP_DP_CURVE448;
|
return MBEDTLS_ECP_DP_CURVE448;
|
||||||
}
|
}
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
|
else if (memcmp(algorithm_attr_ed25519 + 2, algo, algo_len) == 0) {
|
||||||
|
return MBEDTLS_ECP_DP_ED25519;
|
||||||
|
}
|
||||||
|
else if (memcmp(algorithm_attr_ed448 + 2, algo, algo_len) == 0) {
|
||||||
|
return MBEDTLS_ECP_DP_ED448;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return MBEDTLS_ECP_DP_NONE;
|
return MBEDTLS_ECP_DP_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -733,6 +752,13 @@ int ecdsa_sign(mbedtls_ecp_keypair *ctx,
|
|||||||
size_t *out_len) {
|
size_t *out_len) {
|
||||||
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
|
if (ctx->grp.id == MBEDTLS_ECP_DP_ED25519 || ctx->grp.id == MBEDTLS_ECP_DP_ED448) {
|
||||||
|
r = mbedtls_eddsa_write_signature(ctx, data, data_len, out, 114, out_len, MBEDTLS_EDDSA_PURE, NULL, 0, random_gen, NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
mbedtls_mpi ri, si;
|
mbedtls_mpi ri, si;
|
||||||
mbedtls_mpi_init(&ri);
|
mbedtls_mpi_init(&ri);
|
||||||
mbedtls_mpi_init(&si);
|
mbedtls_mpi_init(&si);
|
||||||
@@ -745,6 +771,7 @@ int ecdsa_sign(mbedtls_ecp_keypair *ctx,
|
|||||||
}
|
}
|
||||||
mbedtls_mpi_free(&ri);
|
mbedtls_mpi_free(&ri);
|
||||||
mbedtls_mpi_free(&si);
|
mbedtls_mpi_free(&si);
|
||||||
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user