Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit ef1fb08

Browse files
jasnelladdaleax
authored andcommitted
quic: simplify and condense
PR-URL: #217 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 42cc8ac commit ef1fb08

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

src/node_quic_crypto.cc

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,20 @@ bool DeriveTokenKey(
9595
secret.size()));
9696
}
9797

98-
bool MessageDigest(
99-
std::array<uint8_t, 32>* dest,
100-
const std::array<uint8_t, 16>& rand) {
98+
void GenerateRandData(uint8_t* buf, size_t len) {
99+
std::array<uint8_t, 16> rand;
100+
std::array<uint8_t, 32> md;
101+
101102
const EVP_MD* meth = EVP_sha256();
103+
unsigned int mdlen = EVP_MD_size(meth);
102104
DeleteFnPtr<EVP_MD_CTX, EVP_MD_CTX_free> ctx;
103105
ctx.reset(EVP_MD_CTX_new());
104106
CHECK(ctx);
105107

106-
if (EVP_DigestInit_ex(ctx.get(), meth, nullptr) != 1 ||
107-
EVP_DigestUpdate(ctx.get(), rand.data(), rand.size()) != 1) {
108-
return false;
109-
}
110-
111-
unsigned int mdlen = EVP_MD_size(meth);
112-
113-
return EVP_DigestFinal_ex(ctx.get(), dest->data(), &mdlen) == 1;
114-
}
115-
116-
void GenerateRandData(uint8_t* buf, size_t len) {
117-
std::array<uint8_t, 16> rand;
118-
std::array<uint8_t, 32> md;
119108
EntropySource(rand.data(), rand.size());
120-
CHECK(MessageDigest(&md, rand));
109+
CHECK_EQ(EVP_DigestInit_ex(ctx.get(), meth, nullptr), 1);
110+
CHECK_EQ(EVP_DigestUpdate(ctx.get(), rand.data(), rand.size()), 1);
111+
CHECK_EQ(EVP_DigestFinal_ex(ctx.get(), rand.data(), &mdlen), 1);
121112
CHECK_LE(len, md.size());
122113
std::copy_n(std::begin(md), len, buf);
123114
}

0 commit comments

Comments
 (0)