Skip to content

Commit

Permalink
psa: Clear bits in mbedtls_ecc_group_to_psa()
Browse files Browse the repository at this point in the history
Clear bits in mbedtls_ecc_group_to_psa() to avoid static analyzers and
possibly compilers from warning that bits may be used uninitialized in
certain code paths.

For example, if mbedtls_ecc_group_to_psa() were to be inlined in
crypto_extra.h, the following compiler warning is likely.

    In file included from ../include/psa/crypto.h:3774:0,
                     from ../include/mbedtls/pk.h:49,
                     from pk.c:29:
    pk.c: In function 'mbedtls_pk_wrap_as_opaque':
    ../include/psa/crypto_struct.h:460:33: error: 'bits' may be used uninitialized in this function [-Werror=maybe-uninitialized]
             attributes->core.bits = (psa_key_bits_t) bits;
                                     ^~~~~~~~~~~~~~~~~~~~~
    pk.c:608:12: note: 'bits' was declared here
         size_t bits;
                ^~~~

Signed-off-by: Jaeden Amero <[email protected]>
  • Loading branch information
Patater committed May 5, 2020
1 parent 9515d76 commit 1bde9cd
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions library/psa_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ psa_ecc_curve_t mbedtls_ecc_group_to_psa( mbedtls_ecp_group_id grpid,
*bits = 448;
return( PSA_ECC_CURVE_MONTGOMERY );
default:
*bits = 0;
return( 0 );
}
}
Expand Down

0 comments on commit 1bde9cd

Please sign in to comment.