mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
crypto: support outputLength option in crypto.hash for XOF functions
Support `outputLength` option in crypto.hash() for XOF hash functions to align with the behaviour of crypto.createHash() API closes: https://github.com/nodejs/node/issues/57312 Co-authored-by: Filip Skokan <panva.ip@gmail.com> PR-URL: https://github.com/nodejs/node/pull/58121 Fixes: https://github.com/nodejs/node/issues/57312 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
parent
c7eff619c2
commit
1c4fe6d795
8 changed files with 258 additions and 23 deletions
16
deps/ncrypto/ncrypto.cc
vendored
16
deps/ncrypto/ncrypto.cc
vendored
|
@ -4191,6 +4191,22 @@ DataPointer hashDigest(const Buffer<const unsigned char>& buf,
|
|||
return data.resize(result_size);
|
||||
}
|
||||
|
||||
DataPointer xofHashDigest(const Buffer<const unsigned char>& buf,
|
||||
const EVP_MD* md,
|
||||
size_t output_length) {
|
||||
if (md == nullptr) return {};
|
||||
|
||||
EVPMDCtxPointer ctx = EVPMDCtxPointer::New();
|
||||
if (!ctx) return {};
|
||||
if (ctx.digestInit(md) != 1) {
|
||||
return {};
|
||||
}
|
||||
if (ctx.digestUpdate(reinterpret_cast<const Buffer<const void>&>(buf)) != 1) {
|
||||
return {};
|
||||
}
|
||||
return ctx.digestFinal(output_length);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
X509Name::X509Name() : name_(nullptr), total_(0) {}
|
||||
|
|
5
deps/ncrypto/ncrypto.h
vendored
5
deps/ncrypto/ncrypto.h
vendored
|
@ -278,8 +278,13 @@ class Digest final {
|
|||
const EVP_MD* md_ = nullptr;
|
||||
};
|
||||
|
||||
// Computes a fixed-length digest.
|
||||
DataPointer hashDigest(const Buffer<const unsigned char>& data,
|
||||
const EVP_MD* md);
|
||||
// Computes a variable-length digest for XOF algorithms (e.g. SHAKE128).
|
||||
DataPointer xofHashDigest(const Buffer<const unsigned char>& data,
|
||||
const EVP_MD* md,
|
||||
size_t length);
|
||||
|
||||
class Cipher final {
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue