diff options
author | Tobias Nießen <tniessen@tnie.de> | 2019-07-19 03:44:31 +0300 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-07-26 09:00:41 +0300 |
commit | 31d9b2f14fe9851b530c213b92e14b4646f6d131 (patch) | |
tree | 6499824adfea4686e4dfd9695204ae187a275905 /src/node_crypto.h | |
parent | 64e4b0c0ac5073e6606b1ccd79a464f2c5925741 (diff) |
crypto: add outputLength option to crypto.createHash
This change adds an outputLength option to crypto.createHash which
allows users to produce variable-length hash values using XOF hash
functons.
Fixes: https://github.com/nodejs/node/issues/28757
PR-URL: https://github.com/nodejs/node/pull/28805
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_crypto.h')
-rw-r--r-- | src/node_crypto.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/node_crypto.h b/src/node_crypto.h index 3e337eaddbe..07ca412e8f7 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -585,7 +585,7 @@ class Hash : public BaseObject { SET_MEMORY_INFO_NAME(Hash) SET_SELF_SIZE(Hash) - bool HashInit(const char* hash_type); + bool HashInit(const char* hash_type, v8::Maybe<unsigned int> xof_md_len); bool HashUpdate(const char* data, int len); protected: @@ -596,18 +596,21 @@ class Hash : public BaseObject { Hash(Environment* env, v8::Local<v8::Object> wrap) : BaseObject(env, wrap), mdctx_(nullptr), - md_len_(0) { + has_md_(false), + md_value_(nullptr) { MakeWeak(); } ~Hash() override { - OPENSSL_cleanse(md_value_, md_len_); + if (md_value_ != nullptr) + OPENSSL_clear_free(md_value_, md_len_); } private: EVPMDPointer mdctx_; - unsigned char md_value_[EVP_MAX_MD_SIZE]; + bool has_md_; unsigned int md_len_; + unsigned char* md_value_; }; class SignBase : public BaseObject { |