Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: Use mbedtls_pkcs5_pbkdf2_hmac_ext if MBEDTLS_DEPRECATED_REMOVED is defined #25213

Merged
merged 2 commits into from
Feb 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/crypto/CHIPCryptoPALmbedTLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,12 @@ CHIP_ERROR PBKDF2_sha256::pbkdf2_sha256(const uint8_t * password, size_t plen, c
{
CHIP_ERROR error = CHIP_NO_ERROR;
int result = 0;
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
const mbedtls_md_info_t * md_info;
mbedtls_md_context_t md_ctxt;
constexpr int use_hmac = 1;

bool free_md_ctxt = false;
bool free_md_ctxt = false;
#endif // !defined(MBEDTLS_DEPRECATED_REMOVED)

VerifyOrExit(password != nullptr, error = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(plen > 0, error = CHIP_ERROR_INVALID_ARGUMENT);
Expand All @@ -375,7 +376,7 @@ CHIP_ERROR PBKDF2_sha256::pbkdf2_sha256(const uint8_t * password, size_t plen, c
VerifyOrExit(slen <= kSpake2p_Max_PBKDF_Salt_Length, error = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(key_length > 0, error = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(output != nullptr, error = CHIP_ERROR_INVALID_ARGUMENT);

#if !defined(MBEDTLS_DEPRECATED_REMOVED)
md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
VerifyOrExit(md_info != nullptr, error = CHIP_ERROR_INTERNAL);

Expand All @@ -387,16 +388,20 @@ CHIP_ERROR PBKDF2_sha256::pbkdf2_sha256(const uint8_t * password, size_t plen, c

result = mbedtls_pkcs5_pbkdf2_hmac(&md_ctxt, Uint8::to_const_uchar(password), plen, Uint8::to_const_uchar(salt), slen,
iteration_count, key_length, Uint8::to_uchar(output));

#else
result = mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA256, Uint8::to_const_uchar(password), plen, Uint8::to_const_uchar(salt),
slen, iteration_count, key_length, Uint8::to_uchar(output));
#endif // !defined(MBEDTLS_DEPRECATED_REMOVED)
VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL);

exit:
_log_mbedTLS_error(result);

#if !defined(MBEDTLS_DEPRECATED_REMOVED)
if (free_md_ctxt)
{
mbedtls_md_free(&md_ctxt);
}
#endif // !defined(MBEDTLS_DEPRECATED_REMOVED)

return error;
}
Expand Down