| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 68a6b8d commit 953a850
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3419,16 +3419,20 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) { | |||
| 3419 | 3419 | encoding = ParseEncoding(env->isolate(), args[0], BUFFER); | |
| 3420 | 3420 | } | |
| 3421 | 3421 | ||
| 3422 | - unsigned char md_value[EVP_MAX_MD_SIZE]; | ||
| 3423 | - unsigned int md_len; | ||
| 3424 | - | ||
| 3425 | - EVP_DigestFinal_ex(hash->mdctx_.get(), md_value, &md_len); | ||
| 3422 | + if (hash->md_len_ == 0) { | ||
| 3423 | + // Some hash algorithms such as SHA3 do not support calling | ||
| 3424 | + // EVP_DigestFinal_ex more than once, however, Hash._flush | ||
| 3425 | + // and Hash.digest can both be used to retrieve the digest, | ||
| 3426 | + // so we need to cache it. | ||
| 3427 | + // See https://github.com/nodejs/node/issues/28245. | ||
| 3428 | + EVP_DigestFinal_ex(hash->mdctx_.get(), hash->md_value_, &hash->md_len_); | ||
| 3429 | + } | ||
| 3426 | 3430 | ||
| 3427 | 3431 | Local<Value> error; | |
| 3428 | 3432 | MaybeLocal<Value> rc = | |
| 3429 | 3433 | StringBytes::Encode(env->isolate(), | |
| 3430 | - reinterpret_cast<const char*>(md_value), | ||
| 3431 | - md_len, | ||
| 3434 | + reinterpret_cast<const char*>(hash->md_value_), | ||
| 3435 | + hash->md_len_, | ||
| 3432 | 3436 | encoding, | |
| 3433 | 3437 | &error); | |
| 3434 | 3438 | if (rc.IsEmpty()) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -475,12 +475,19 @@ class Hash : public BaseObject { | |||
| 475 | 475 | ||
| 476 | 476 | Hash(Environment* env, v8::Local<v8::Object> wrap) | |
| 477 | 477 | : BaseObject(env, wrap), | |
| 478 | - mdctx_(nullptr) { | ||
| 478 | + mdctx_(nullptr), | ||
| 479 | + md_len_(0) { | ||
| 479 | 480 | MakeWeak(); | |
| 480 | 481 | } | |
| 481 | 482 | ||
| 483 | + ~Hash() override { | ||
| 484 | + OPENSSL_cleanse(md_value_, md_len_); | ||
| 485 | + } | ||
| 486 | + | ||
| 482 | 487 | private: | |
| 483 | 488 | EVPMDPointer mdctx_; | |
| 489 | + unsigned char md_value_[EVP_MAX_MD_SIZE]; | ||
| 490 | + unsigned int md_len_; | ||
| 484 | 491 | }; | |
| 485 | 492 | ||
| 486 | 493 | class SignBase : public BaseObject { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments