Skip to content

Commit

Permalink
replace EVP_MD_fetch with EVP_sha* functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cnt0 committed Jan 5, 2025
1 parent 29bfedb commit 0ed7d19
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions base/openssl_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,19 +472,15 @@ void ShaImpl(bytes::span dst, auto md, Args &&...args) {
EVP_MD_CTX_free(mdctx);
}

inline void ShaTo(bytes::span dst, auto mdname, bytes::const_span data) {
auto md = EVP_MD_fetch(nullptr, mdname, nullptr);
inline void ShaTo(bytes::span dst, auto md, bytes::const_span data) {
Expects(dst.size() >= EVP_MD_size(md));
details::ShaImpl(dst, md, data);
EVP_MD_free(md);
}

template <typename ...Args>
[[nodiscard]] inline bytes::vector Sha(auto mdname, Args &&...args) {
auto md = EVP_MD_fetch(nullptr, mdname, nullptr);
[[nodiscard]] inline bytes::vector Sha(auto md, Args &&...args) {
bytes::vector dst(EVP_MD_size(md));
details::ShaImpl(dst, md, args...);
EVP_MD_free(md);
return dst;
}

Expand Down Expand Up @@ -516,30 +512,30 @@ constexpr auto kSha256Size = size_type(SHA256_DIGEST_LENGTH);
constexpr auto kSha512Size = size_type(SHA512_DIGEST_LENGTH);

inline void Sha1To(bytes::span dst, bytes::const_span data) {
details::ShaTo(dst, "SHA1", data);
details::ShaTo(dst, EVP_sha1(), data);
}

template <typename ...Args>
[[nodiscard]] inline bytes::vector Sha1(Args &&...args) {
return details::Sha("SHA1", args...);
return details::Sha(EVP_sha1(), args...);
}

inline void Sha256To(bytes::span dst, bytes::const_span data) {
details::ShaTo(dst, "SHA256", data);
details::ShaTo(dst, EVP_sha256(), data);
}

template <typename ...Args>
[[nodiscard]] inline bytes::vector Sha256(Args &&...args) {
return details::Sha("SHA256", args...);
return details::Sha(EVP_sha256(), args...);
}

inline void Sha512To(bytes::span dst, bytes::const_span data) {
details::ShaTo(dst, "SHA512", data);
details::ShaTo(dst, EVP_sha512(), data);
}

template <typename ...Args>
[[nodiscard]] inline bytes::vector Sha512(Args &&...args) {
return details::Sha("SHA512", args...);
return details::Sha(EVP_sha512(), args...);
}

inline bytes::vector Pbkdf2Sha512(
Expand Down

0 comments on commit 0ed7d19

Please sign in to comment.