diff options
author | Tobias Nießen <tniessen@tnie.de> | 2019-06-21 16:37:06 +0200 |
---|---|---|
committer | Tobias Nießen <tniessen@tnie.de> | 2019-08-07 13:45:42 +0200 |
commit | 0c9ad34427cdc8a68c8b3e7c2d4748f462567680 (patch) | |
tree | 4daa9f7d90a2c5583c1d0052817c26f5a68bdb9a /src | |
parent | 0b5b81c82af70072eac09d39ec43b5707d8d8a0c (diff) | |
download | android-node-v8-0c9ad34427cdc8a68c8b3e7c2d4748f462567680.tar.gz android-node-v8-0c9ad34427cdc8a68c8b3e7c2d4748f462567680.tar.bz2 android-node-v8-0c9ad34427cdc8a68c8b3e7c2d4748f462567680.zip |
crypto: extend RSA-OAEP support with oaepHash
This adds an oaepHash option to asymmetric encryption which allows
users to specify a hash function when using OAEP padding. This
feature is required for interoperability with WebCrypto applications.
PR-URL: https://github.com/nodejs/node/pull/28335
Fixes: https://github.com/nodejs/node/issues/25756
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_crypto.cc | 11 | ||||
-rw-r--r-- | src/node_crypto.h | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 91e62f41b3..70da2e310e 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5225,6 +5225,7 @@ template <PublicKeyCipher::Operation operation, bool PublicKeyCipher::Cipher(Environment* env, const ManagedEVPPKey& pkey, int padding, + const char* oaep_hash, const unsigned char* data, int len, AllocatedBuffer* out) { @@ -5236,6 +5237,12 @@ bool PublicKeyCipher::Cipher(Environment* env, if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), padding) <= 0) return false; + if (oaep_hash != nullptr) { + if (!EVP_PKEY_CTX_md(ctx.get(), EVP_PKEY_OP_TYPE_CRYPT, + EVP_PKEY_CTRL_RSA_OAEP_MD, oaep_hash)) + return false; + } + size_t out_len = 0; if (EVP_PKEY_cipher(ctx.get(), nullptr, &out_len, data, len) <= 0) return false; @@ -5272,6 +5279,9 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) { uint32_t padding; if (!args[offset + 1]->Uint32Value(env->context()).To(&padding)) return; + const node::Utf8Value oaep_str(env->isolate(), args[offset + 2]); + const char* oaep_hash = args[offset + 2]->IsString() ? *oaep_str : nullptr; + AllocatedBuffer out; ClearErrorOnReturn clear_error_on_return; @@ -5280,6 +5290,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) { env, pkey, padding, + oaep_hash, buf.data(), buf.length(), &out); diff --git a/src/node_crypto.h b/src/node_crypto.h index 07ca412e8f..a121c82295 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -713,6 +713,7 @@ class PublicKeyCipher { static bool Cipher(Environment* env, const ManagedEVPPKey& pkey, int padding, + const char* oaep_hash, const unsigned char* data, int len, AllocatedBuffer* out); |