Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2019-06-21 17:37:06 +0300
committerTobias Nießen <tniessen@tnie.de>2019-08-07 14:45:42 +0300
commit0c9ad34427cdc8a68c8b3e7c2d4748f462567680 (patch)
tree4daa9f7d90a2c5583c1d0052817c26f5a68bdb9a /src/node_crypto.cc
parent0b5b81c82af70072eac09d39ec43b5707d8d8a0c (diff)
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/node_crypto.cc')
-rw-r--r--src/node_crypto.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 91e62f41b3d..70da2e310ea 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);