Skip to content

Commit

Permalink
[cryptolib] Add unused result before status_t functions in P-256 headers
Browse files Browse the repository at this point in the history
This commit adds the `OT_WARN_UNUSED_RESULT` macro before `status_t`
functions of p256 files to protect against a caller forgetting to check
and forward the error code.

Signed-off-by: Moritz Wettermann <[email protected]>
  • Loading branch information
wettermo authored and jadephilipoom committed Feb 15, 2024
1 parent 6a66a71 commit c36041b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sw/device/lib/crypto/impl/ecc/ecdh_p256.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef struct ecdh_p256_shared_key {
*
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdh_p256_keypair_start(void);

/**
Expand All @@ -44,6 +45,7 @@ status_t ecdh_p256_keypair_start(void);
* @param[out] public_key Generated public key.
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdh_p256_keypair_finalize(p256_masked_scalar_t *private_key,
p256_point_t *public_key);

Expand All @@ -56,6 +58,7 @@ status_t ecdh_p256_keypair_finalize(p256_masked_scalar_t *private_key,
* @param public_key Public key (Q).
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdh_p256_shared_key_start(const p256_masked_scalar_t *private_key,
const p256_point_t *public_key);

Expand All @@ -69,6 +72,7 @@ status_t ecdh_p256_shared_key_start(const p256_masked_scalar_t *private_key,
* @param[out] shared_key Shared secret key (x-coordinate of d*Q).
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdh_p256_shared_key_finalize(ecdh_p256_shared_key_t *shared_key);

/**
Expand All @@ -81,6 +85,7 @@ status_t ecdh_p256_shared_key_finalize(ecdh_p256_shared_key_t *shared_key);
*
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdh_p256_sideload_keypair_start(void);

/**
Expand All @@ -91,6 +96,7 @@ status_t ecdh_p256_sideload_keypair_start(void);
* @param[out] public_key Generated public key.
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdh_p256_sideload_keypair_finalize(p256_point_t *public_key);

/**
Expand All @@ -104,6 +110,7 @@ status_t ecdh_p256_sideload_keypair_finalize(p256_point_t *public_key);
* @param public_key Public key (Q).
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdh_p256_sideload_shared_key_start(const p256_point_t *public_key);

#ifdef __cplusplus
Expand Down
9 changes: 9 additions & 0 deletions sw/device/lib/crypto/impl/ecc/ecdsa_p256.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef struct ecdsa_p256_signature_t {
*
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdsa_p256_keygen_start(void);

/**
Expand All @@ -43,6 +44,7 @@ status_t ecdsa_p256_keygen_start(void);
*
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdsa_p256_sideload_keygen_start(void);

/**
Expand All @@ -54,6 +56,7 @@ status_t ecdsa_p256_sideload_keygen_start(void);
* @param[out] public_key Generated public key.
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdsa_p256_keygen_finalize(p256_masked_scalar_t *private_key,
p256_point_t *public_key);

Expand All @@ -66,6 +69,7 @@ status_t ecdsa_p256_keygen_finalize(p256_masked_scalar_t *private_key,
* @param[out] public_key Public key.
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdsa_p256_sideload_keygen_finalize(p256_point_t *public_key);

/**
Expand All @@ -77,6 +81,7 @@ status_t ecdsa_p256_sideload_keygen_finalize(p256_point_t *public_key);
* @param private_key Secret key to sign the message with.
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdsa_p256_sign_start(const uint32_t digest[kP256ScalarWords],
const p256_masked_scalar_t *private_key);

Expand All @@ -89,6 +94,7 @@ status_t ecdsa_p256_sign_start(const uint32_t digest[kP256ScalarWords],
* @param digest Digest of the message to sign.
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdsa_p256_sideload_sign_start(
const uint32_t digest[kP256ScalarWords]);

Expand All @@ -102,6 +108,7 @@ status_t ecdsa_p256_sideload_sign_start(
* @param[out] result Buffer in which to store the generated signature.
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdsa_p256_sign_finalize(ecdsa_p256_signature_t *result);

/**
Expand All @@ -116,6 +123,7 @@ status_t ecdsa_p256_sign_finalize(ecdsa_p256_signature_t *result);
* @param public_key Key to check the signature against.
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdsa_p256_verify_start(const ecdsa_p256_signature_t *signature,
const uint32_t digest[kP256ScalarWords],
const p256_point_t *public_key);
Expand All @@ -140,6 +148,7 @@ status_t ecdsa_p256_verify_start(const ecdsa_p256_signature_t *signature,
* otherwise)
* @return Result of the operation (OK or error).
*/
OT_WARN_UNUSED_RESULT
status_t ecdsa_p256_verify_finalize(const ecdsa_p256_signature_t *signature,
hardened_bool_t *result);

Expand Down
1 change: 1 addition & 0 deletions sw/device/lib/crypto/impl/ecc/p256_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ typedef struct p256_point {
* @param share1_addr DMEM address of the second share.
* @return Result of the operation.
*/
OT_WARN_UNUSED_RESULT
status_t p256_masked_scalar_write(const p256_masked_scalar_t *src,
const otbn_addr_t share0_addr,
const otbn_addr_t share1_addr);
Expand Down

0 comments on commit c36041b

Please sign in to comment.