From ef1fb08378edea9c1a7bcca378c264f1fd8b0803 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 5 Dec 2019 11:17:34 -0800 Subject: [PATCH] quic: simplify and condense PR-URL: https://github.com/nodejs/quic/pull/217 Reviewed-By: Anna Henningsen --- src/node_quic_crypto.cc | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/node_quic_crypto.cc b/src/node_quic_crypto.cc index 56632a3c39..b3cd484037 100644 --- a/src/node_quic_crypto.cc +++ b/src/node_quic_crypto.cc @@ -95,29 +95,20 @@ bool DeriveTokenKey( secret.size())); } -bool MessageDigest( - std::array* dest, - const std::array& rand) { +void GenerateRandData(uint8_t* buf, size_t len) { + std::array rand; + std::array md; + const EVP_MD* meth = EVP_sha256(); + unsigned int mdlen = EVP_MD_size(meth); DeleteFnPtr ctx; ctx.reset(EVP_MD_CTX_new()); CHECK(ctx); - if (EVP_DigestInit_ex(ctx.get(), meth, nullptr) != 1 || - EVP_DigestUpdate(ctx.get(), rand.data(), rand.size()) != 1) { - return false; - } - - unsigned int mdlen = EVP_MD_size(meth); - - return EVP_DigestFinal_ex(ctx.get(), dest->data(), &mdlen) == 1; -} - -void GenerateRandData(uint8_t* buf, size_t len) { - std::array rand; - std::array md; EntropySource(rand.data(), rand.size()); - CHECK(MessageDigest(&md, rand)); + CHECK_EQ(EVP_DigestInit_ex(ctx.get(), meth, nullptr), 1); + CHECK_EQ(EVP_DigestUpdate(ctx.get(), rand.data(), rand.size()), 1); + CHECK_EQ(EVP_DigestFinal_ex(ctx.get(), rand.data(), &mdlen), 1); CHECK_LE(len, md.size()); std::copy_n(std::begin(md), len, buf); }