Skip to content

Commit a7fef86

Browse files
committed
pk: minor code restyling
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
1 parent 73b3c45 commit a7fef86

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

include/mbedtls/pk.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ static inline mbedtls_ecp_keypair *mbedtls_pk_ec(const mbedtls_pk_context pk)
800800
#if defined(MBEDTLS_USE_PSA_CRYPTO)
801801
/**
802802
* Return the raw public key content on the provided buffer.
803-
*
803+
*
804804
* \param pk The PK context that will be used to extract the public key.
805805
* \param buf The output buffer into which the key will be copied
806806
* \param buf_size The size of the output buffer
@@ -818,7 +818,7 @@ int mbedtls_pk_get_public_key(mbedtls_pk_context *pk, unsigned char *buf,
818818

819819
/**
820820
* Return EC parameter used in the given PK context.
821-
*
821+
*
822822
* \param pk The PK context that from which the EC's key properties will
823823
* be get.
824824
* \param ec_curve Output variable that will get the EC family.

library/pk.c

+7-14
Original file line numberDiff line numberDiff line change
@@ -479,17 +479,13 @@ int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx,
479479

480480

481481
#if defined(MBEDTLS_USE_PSA_CRYPTO)
482-
if (ctx->pk_info->type == MBEDTLS_PK_RSA) {
483-
return ctx->pk_info->verify_func(ctx->pk_ctx, md_alg, hash, hash_len,
484-
sig, sig_len);
485-
} else {
482+
if (ctx->pk_info->type != MBEDTLS_PK_RSA) {
486483
return ctx->pk_info->verify_func(ctx, md_alg, hash, hash_len,
487484
sig, sig_len);
488-
}
489-
#else /* MBEDTLS_USE_PSA_CRYPTO */
485+
} else
486+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
490487
return ctx->pk_info->verify_func(ctx->pk_ctx, md_alg, hash, hash_len,
491488
sig, sig_len);
492-
#endif /* MBEDTLS_USE_PSA_CRYPTO */
493489
}
494490

495491
/*
@@ -820,14 +816,11 @@ int mbedtls_pk_check_pair(const mbedtls_pk_context *pub,
820816
}
821817

822818
#if defined(MBEDTLS_USE_PSA_CRYPTO)
823-
if (pub->pk_info->type == MBEDTLS_PK_RSA) {
824-
return prv->pk_info->check_pair_func(pub->pk_ctx, prv->pk_ctx, f_rng, p_rng);
825-
} else {
819+
if (pub->pk_info->type != MBEDTLS_PK_RSA) {
826820
return prv->pk_info->check_pair_func(pub, prv, f_rng, p_rng);
827-
}
828-
#else
829-
return prv->pk_info->check_pair_func(pub->pk_ctx, prv->pk_ctx, f_rng, p_rng);
821+
} else
830822
#endif
823+
return prv->pk_info->check_pair_func(pub->pk_ctx, prv->pk_ctx, f_rng, p_rng);
831824
}
832825

833826
/*
@@ -909,7 +902,7 @@ int mbedtls_pk_get_ec_public_key_props(mbedtls_pk_context *pk,
909902
if ((pk == NULL) || (ec_curve == NULL) || (bits == NULL)) {
910903
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
911904
}
912-
if ((pk->MBEDTLS_PRIVATE(pk_ec_family) == 0) ||
905+
if ((pk->MBEDTLS_PRIVATE(pk_ec_family) == 0) ||
913906
(pk->MBEDTLS_PRIVATE(pk_bits) == 0)) {
914907
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
915908
}

tests/suites/test_suite_pk.function

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int pk_genkey(mbedtls_pk_context *pk, int parameter)
5959
&mbedtls_pk_ec(*pk)->Q,
6060
mbedtls_test_rnd_std_rand, NULL);
6161
if (ret != 0) {
62-
return ret;
62+
return ret;
6363
}
6464
#if defined(MBEDTLS_USE_PSA_CRYPTO)
6565
return mbedtls_pk_update_public_key_from_keypair(pk);

0 commit comments

Comments
 (0)