Skip to content

Commit f844b9b

Browse files
committed
replace EVP_MD_fetch with EVP_sha* functions
1 parent 2719b63 commit f844b9b

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

base/openssl_help.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,19 +470,15 @@ void ShaImpl(bytes::span dst, auto md, Args &&...args) {
470470
EVP_MD_CTX_free(mdctx);
471471
}
472472

473-
inline void ShaTo(bytes::span dst, auto mdname, bytes::const_span data) {
474-
auto md = EVP_MD_fetch(nullptr, mdname, nullptr);
473+
inline void ShaTo(bytes::span dst, auto md, bytes::const_span data) {
475474
Expects(dst.size() >= EVP_MD_size(md));
476475
details::ShaImpl(dst, md, data);
477-
EVP_MD_free(md);
478476
}
479477

480478
template <typename ...Args>
481-
[[nodiscard]] inline bytes::vector Sha(auto mdname, Args &&...args) {
482-
auto md = EVP_MD_fetch(nullptr, mdname, nullptr);
479+
[[nodiscard]] inline bytes::vector Sha(auto md, Args &&...args) {
483480
bytes::vector dst(EVP_MD_size(md));
484481
details::ShaImpl(dst, md, args...);
485-
EVP_MD_free(md);
486482
return dst;
487483
}
488484

@@ -514,30 +510,30 @@ constexpr auto kSha256Size = size_type(SHA256_DIGEST_LENGTH);
514510
constexpr auto kSha512Size = size_type(SHA512_DIGEST_LENGTH);
515511

516512
inline void Sha1To(bytes::span dst, bytes::const_span data) {
517-
details::ShaTo(dst, "SHA1", data);
513+
details::ShaTo(dst, EVP_sha1(), data);
518514
}
519515

520516
template <typename ...Args>
521517
[[nodiscard]] inline bytes::vector Sha1(Args &&...args) {
522-
return details::Sha("SHA1", args...);
518+
return details::Sha(EVP_sha1(), args...);
523519
}
524520

525521
inline void Sha256To(bytes::span dst, bytes::const_span data) {
526-
details::ShaTo(dst, "SHA256", data);
522+
details::ShaTo(dst, EVP_sha256(), data);
527523
}
528524

529525
template <typename ...Args>
530526
[[nodiscard]] inline bytes::vector Sha256(Args &&...args) {
531-
return details::Sha("SHA256", args...);
527+
return details::Sha(EVP_sha256(), args...);
532528
}
533529

534530
inline void Sha512To(bytes::span dst, bytes::const_span data) {
535-
details::ShaTo(dst, "SHA512", data);
531+
details::ShaTo(dst, EVP_sha512(), data);
536532
}
537533

538534
template <typename ...Args>
539535
[[nodiscard]] inline bytes::vector Sha512(Args &&...args) {
540-
return details::Sha("SHA512", args...);
536+
return details::Sha(EVP_sha512(), args...);
541537
}
542538

543539
inline bytes::vector Pbkdf2Sha512(

0 commit comments

Comments
 (0)