Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
  • Loading branch information
valeriosetti committed Mar 16, 2023
1 parent c80ab78 commit b103855
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
8 changes: 4 additions & 4 deletions include/mbedtls/pk.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ typedef struct mbedtls_pk_debug_item {
typedef struct mbedtls_pk_info_t mbedtls_pk_info_t;

#define MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN \
PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
/**
* \brief Public key container
*/
Expand Down Expand Up @@ -806,11 +806,11 @@ static inline mbedtls_ecp_keypair *mbedtls_pk_ec(const mbedtls_pk_context pk)
}
#if defined(MBEDTLS_USE_PSA_CRYPTO)
int mbedtls_pk_get_public_key(mbedtls_pk_context *pk, unsigned char *buf,
size_t buf_size, size_t *key_len);
size_t buf_size, size_t *key_len);

int mbedtls_pk_get_ec_public_key_props(mbedtls_pk_context *pk,
psa_ecc_family_t *ec_curve,
size_t *bits);
psa_ecc_family_t *ec_curve,
size_t *bits);
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#endif /* MBEDTLS_ECP_C */

Expand Down
2 changes: 1 addition & 1 deletion library/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ void mbedtls_debug_print_crt(const mbedtls_ssl_context *ssl, int level,
debug_print_line_by_line(ssl, level, file, line, buf);

#if defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_ECP_C)
mbedtls_pk_update_keypair_from_public_key((mbedtls_pk_context*)&crt->pk);
mbedtls_pk_update_keypair_from_public_key((mbedtls_pk_context *) &crt->pk);
#endif /* MBEDTLS_USE_PSA_CRYPTO && MBEDTLS_ECP_C */
debug_print_pk(ssl, level, file, line, "crt->", &crt->pk);

Expand Down
26 changes: 13 additions & 13 deletions library/pk.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void mbedtls_pk_init(mbedtls_pk_context *ctx)
ctx->pk_ctx = NULL;
#if defined(MBEDTLS_ECP_C) && defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_platform_zeroize(ctx->MBEDTLS_PRIVATE(pk_raw),
MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN);
MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN);
ctx->pk_raw_len = 0;
ctx->pk_ec_family = 0;
ctx->pk_bits = 0;
Expand Down Expand Up @@ -257,7 +257,7 @@ int mbedtls_pk_gen_ec_keypair(mbedtls_pk_context *pk,
}

ret = mbedtls_ecp_gen_keypair(&keypair->grp, &keypair->d, &keypair->Q,
f_rng, p_rng);
f_rng, p_rng);
if (ret != 0) {
return ret;
}
Expand Down Expand Up @@ -489,7 +489,7 @@ int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx,
* falling back to the mbedtls implementation. Therefore copy the
* raw content of the public key back to the ecp_keypair structure */
if ((mbedtls_ecp_is_zero(&(mbedtls_pk_ec(*ctx)->Q)) == 1) &&
(ctx->pk_raw_len != 0)){
(ctx->pk_raw_len != 0)) {
ret = mbedtls_pk_update_keypair_from_public_key(ctx);
if (ret < 0) {
return ret;
Expand Down Expand Up @@ -517,10 +517,10 @@ int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx,
#if defined(MBEDTLS_USE_PSA_CRYPTO)
if (ctx->pk_info->type == MBEDTLS_PK_RSA) {
return ctx->pk_info->verify_func(ctx->pk_ctx, md_alg, hash, hash_len,
sig, sig_len);
sig, sig_len);
} else {
return ctx->pk_info->verify_func(ctx, md_alg, hash, hash_len,
sig, sig_len);
sig, sig_len);
}
#else /* MBEDTLS_USE_PSA_CRYPTO */
return ctx->pk_info->verify_func(ctx->pk_ctx, md_alg, hash, hash_len,
Expand Down Expand Up @@ -924,7 +924,7 @@ mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx)
#if defined(MBEDTLS_USE_PSA_CRYPTO)
#if defined(MBEDTLS_ECP_C)
int mbedtls_pk_get_public_key(mbedtls_pk_context *pk, unsigned char *buf,
size_t buf_size, size_t *key_len)
size_t buf_size, size_t *key_len)
{
if ((pk == NULL) || (pk->MBEDTLS_PRIVATE(pk_raw_len) == 0)) {
return MBEDTLS_PK_NONE;
Expand All @@ -940,7 +940,7 @@ int mbedtls_pk_get_public_key(mbedtls_pk_context *pk, unsigned char *buf,
}

int mbedtls_pk_get_ec_public_key_props(mbedtls_pk_context *pk,
psa_ecc_family_t *ec_curve, size_t *bits)
psa_ecc_family_t *ec_curve, size_t *bits)
{
if ((pk == NULL) || (ec_curve == NULL) || (bits == NULL)) {
return MBEDTLS_PK_NONE;
Expand Down Expand Up @@ -969,16 +969,16 @@ int mbedtls_pk_update_public_key_from_keypair(mbedtls_pk_context *pk)
ecp_keypair = mbedtls_pk_ec(*pk);

ret = mbedtls_ecp_point_write_binary(&ecp_keypair->grp, &ecp_keypair->Q,
MBEDTLS_ECP_PF_UNCOMPRESSED,
&pk->MBEDTLS_PRIVATE(pk_raw_len),
pk->MBEDTLS_PRIVATE(pk_raw),
MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN);
MBEDTLS_ECP_PF_UNCOMPRESSED,
&pk->MBEDTLS_PRIVATE(pk_raw_len),
pk->MBEDTLS_PRIVATE(pk_raw),
MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN);
if (ret != 0) {
return ret;
}

pk->MBEDTLS_PRIVATE(pk_ec_family) = mbedtls_ecc_group_to_psa(
ecp_keypair->grp.id, &pk->MBEDTLS_PRIVATE(pk_bits));
ecp_keypair->grp.id, &pk->MBEDTLS_PRIVATE(pk_bits));

return 0;
}
Expand Down Expand Up @@ -1006,7 +1006,7 @@ int mbedtls_pk_update_keypair_from_public_key(mbedtls_pk_context *pk)
return ret;
}
ret = mbedtls_ecp_point_read_binary(&(ecp_keypair->grp), &(ecp_keypair->Q),
pk->pk_raw, pk->pk_raw_len);
pk->pk_raw, pk->pk_raw_len);

return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions library/pk_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,8 @@ static int eckey_check_pair(const void *pub, const void *prv,
void *p_rng)
{
#if defined(MBEDTLS_USE_PSA_CRYPTO)
mbedtls_pk_context *prv_pk = (mbedtls_pk_context*)prv;
mbedtls_pk_context *pub_pk = (mbedtls_pk_context*)pub;
mbedtls_pk_context *prv_pk = (mbedtls_pk_context *) prv;
mbedtls_pk_context *pub_pk = (mbedtls_pk_context *) pub;

/* When key pairs are parsed, the private part goes to the
* mbedtls_ecp_keypair structure while the public one is saved in raw
Expand Down
26 changes: 13 additions & 13 deletions library/pkparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ static int pk_use_ecparams(const mbedtls_asn1_buf *params, mbedtls_pk_context *p
* the private key is kept as raw data on the "mbedtls_pk_context"
* structure */
if ((ret = mbedtls_ecp_group_load(&(mbedtls_pk_ec(*pk)->grp),
grp_id)) != 0) {
grp_id)) != 0) {
return ret;
}

Expand All @@ -507,7 +507,7 @@ static int pk_use_ecparams(const mbedtls_asn1_buf *params, mbedtls_pk_context *p
*/
static int pk_convert_compressed_ec(mbedtls_pk_context *pk,
unsigned char *in_start, size_t in_len,
size_t *out_buf_len, unsigned char* out_buf,
size_t *out_buf_len, unsigned char *out_buf,
size_t out_buf_size)
{
mbedtls_ecp_keypair ecp_key;
Expand All @@ -529,8 +529,8 @@ static int pk_convert_compressed_ec(mbedtls_pk_context *pk,
return ret;
}
ret = mbedtls_ecp_point_write_binary(&(ecp_key.grp), &ecp_key.Q,
MBEDTLS_ECP_PF_UNCOMPRESSED,
out_buf_len, out_buf, out_buf_size);
MBEDTLS_ECP_PF_UNCOMPRESSED,
out_buf_len, out_buf, out_buf_size);
if (ret < 0) {
mbedtls_ecp_keypair_free(&ecp_key);
return ret;
Expand All @@ -551,7 +551,7 @@ static int pk_get_ecpubkey(unsigned char **p, const unsigned char *end,

if ((len > PSA_EXPORT_PUBLIC_KEY_MAX_SIZE) ||
(*p == NULL) || (end == NULL) ||
(pk == NULL)) {
(pk == NULL)) {
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
}

Expand All @@ -560,9 +560,9 @@ static int pk_get_ecpubkey(unsigned char **p, const unsigned char *end,
* uncompressed format */
if ((**p == 0x02) || (**p == 0x03)) {
ret = pk_convert_compressed_ec(pk, *p, len,
&(pk->MBEDTLS_PRIVATE(pk_raw_len)),
pk->MBEDTLS_PRIVATE(pk_raw),
PSA_EXPORT_PUBLIC_KEY_MAX_SIZE);
&(pk->MBEDTLS_PRIVATE(pk_raw_len)),
pk->MBEDTLS_PRIVATE(pk_raw),
PSA_EXPORT_PUBLIC_KEY_MAX_SIZE);
if (ret < 0) {
return ret;
}
Expand All @@ -576,17 +576,17 @@ static int pk_get_ecpubkey(unsigned char **p, const unsigned char *end,
psa_set_key_usage_flags(&key_attrs, 0);
psa_set_key_algorithm(&key_attrs, PSA_ALG_ECDSA_ANY);
psa_set_key_type(&key_attrs,
PSA_KEY_TYPE_ECC_PUBLIC_KEY(pk->MBEDTLS_PRIVATE(pk_ec_family)));
PSA_KEY_TYPE_ECC_PUBLIC_KEY(pk->MBEDTLS_PRIVATE(pk_ec_family)));
psa_set_key_bits(&key_attrs, pk->MBEDTLS_PRIVATE(pk_bits));

status = psa_import_key(&key_attrs, pk->MBEDTLS_PRIVATE(pk_raw),
pk->MBEDTLS_PRIVATE(pk_raw_len), &key);
pk->MBEDTLS_PRIVATE(pk_raw_len), &key);
psa_destroy_key(key);
if (status != PSA_SUCCESS) {
mbedtls_platform_zeroize(pk->MBEDTLS_PRIVATE(pk_raw),
MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN);
MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN);
pk->MBEDTLS_PRIVATE(pk_raw_len) = 0;
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
}

*p = (unsigned char *) end;
Expand Down Expand Up @@ -1030,7 +1030,7 @@ static int pk_parse_key_pkcs1_der(mbedtls_rsa_context *rsa,
* Parse a SEC1 encoded private EC key
*/
#if defined(MBEDTLS_USE_PSA_CRYPTO)
static int pk_parse_key_sec1_der(mbedtls_pk_context* pk,
static int pk_parse_key_sec1_der(mbedtls_pk_context *pk,
const unsigned char *key, size_t keylen,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
#else /* MBEDTLS_USE_PSA_CRYPTO */
Expand Down
4 changes: 2 additions & 2 deletions library/pkwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ int mbedtls_pk_write_pubkey(unsigned char **p, unsigned char *start,
#if defined(MBEDTLS_USE_PSA_CRYPTO)
if (mbedtls_pk_get_type(key) == MBEDTLS_PK_ECKEY) {
MBEDTLS_ASN1_CHK_ADD(len, pk_write_ec_pubkey(p, start,
(mbedtls_pk_context*)key));
(mbedtls_pk_context *) key));
} else
#else /* MBEDTLS_USE_PSA_CRYPTO */
if (mbedtls_pk_get_type(key) == MBEDTLS_PK_ECKEY) {
Expand Down Expand Up @@ -454,7 +454,7 @@ int mbedtls_pk_write_key_der(const mbedtls_pk_context *key, unsigned char *buf,
/* publicKey */
#if defined(MBEDTLS_USE_PSA_CRYPTO)
MBEDTLS_ASN1_CHK_ADD(pub_len, pk_write_ec_pubkey(&c, buf,
(mbedtls_pk_context*)key));
(mbedtls_pk_context *) key));
#else /* MBEDTLS_USE_PSA_CRYPTO */
MBEDTLS_ASN1_CHK_ADD(pub_len, pk_write_ec_pubkey(&c, buf, ec));
#endif /* MBEDTLS_USE_PSA_CRYPTO */
Expand Down
2 changes: 1 addition & 1 deletion tests/suites/test_suite_pk.function
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int pk_genkey(mbedtls_pk_context *pk, int parameter)
mbedtls_pk_get_type(pk) == MBEDTLS_PK_ECDSA) {
#if defined(MBEDTLS_USE_PSA_CRYPTO)
return mbedtls_pk_gen_ec_keypair(pk, parameter,
mbedtls_test_rnd_std_rand, NULL);
mbedtls_test_rnd_std_rand, NULL);
#else /* MBEDTLS_USE_PSA_CRYPTO */
int ret;
if ((ret = mbedtls_ecp_group_load(&mbedtls_pk_ec(*pk)->grp,
Expand Down

0 comments on commit b103855

Please sign in to comment.