Skip to content

Commit 0ed7d19

Browse files
committed
replace EVP_MD_fetch with EVP_sha* functions
1 parent 29bfedb commit 0ed7d19

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
@@ -472,19 +472,15 @@ void ShaImpl(bytes::span dst, auto md, Args &&...args) {
472472
EVP_MD_CTX_free(mdctx);
473473
}
474474

475-
inline void ShaTo(bytes::span dst, auto mdname, bytes::const_span data) {
476-
auto md = EVP_MD_fetch(nullptr, mdname, nullptr);
475+
inline void ShaTo(bytes::span dst, auto md, bytes::const_span data) {
477476
Expects(dst.size() >= EVP_MD_size(md));
478477
details::ShaImpl(dst, md, data);
479-
EVP_MD_free(md);
480478
}
481479

482480
template <typename ...Args>
483-
[[nodiscard]] inline bytes::vector Sha(auto mdname, Args &&...args) {
484-
auto md = EVP_MD_fetch(nullptr, mdname, nullptr);
481+
[[nodiscard]] inline bytes::vector Sha(auto md, Args &&...args) {
485482
bytes::vector dst(EVP_MD_size(md));
486483
details::ShaImpl(dst, md, args...);
487-
EVP_MD_free(md);
488484
return dst;
489485
}
490486

@@ -516,30 +512,30 @@ constexpr auto kSha256Size = size_type(SHA256_DIGEST_LENGTH);
516512
constexpr auto kSha512Size = size_type(SHA512_DIGEST_LENGTH);
517513

518514
inline void Sha1To(bytes::span dst, bytes::const_span data) {
519-
details::ShaTo(dst, "SHA1", data);
515+
details::ShaTo(dst, EVP_sha1(), data);
520516
}
521517

522518
template <typename ...Args>
523519
[[nodiscard]] inline bytes::vector Sha1(Args &&...args) {
524-
return details::Sha("SHA1", args...);
520+
return details::Sha(EVP_sha1(), args...);
525521
}
526522

527523
inline void Sha256To(bytes::span dst, bytes::const_span data) {
528-
details::ShaTo(dst, "SHA256", data);
524+
details::ShaTo(dst, EVP_sha256(), data);
529525
}
530526

531527
template <typename ...Args>
532528
[[nodiscard]] inline bytes::vector Sha256(Args &&...args) {
533-
return details::Sha("SHA256", args...);
529+
return details::Sha(EVP_sha256(), args...);
534530
}
535531

536532
inline void Sha512To(bytes::span dst, bytes::const_span data) {
537-
details::ShaTo(dst, "SHA512", data);
533+
details::ShaTo(dst, EVP_sha512(), data);
538534
}
539535

540536
template <typename ...Args>
541537
[[nodiscard]] inline bytes::vector Sha512(Args &&...args) {
542-
return details::Sha("SHA512", args...);
538+
return details::Sha(EVP_sha512(), args...);
543539
}
544540

545541
inline bytes::vector Pbkdf2Sha512(

0 commit comments

Comments
 (0)