summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2019-09-08 04:41:04 +0200
committerTobias Nießen <tniessen@tnie.de>2019-09-13 16:58:41 +0200
commitb64446648b61085715908b2769bbdfee7b2c84e4 (patch)
tree26ec47a23bb197aeb926a18cde73bf15ff23d0d0 /src
parentdff22dd176d584f3c050a659fa514f079ab5f208 (diff)
downloadandroid-node-v8-b64446648b61085715908b2769bbdfee7b2c84e4.tar.gz
android-node-v8-b64446648b61085715908b2769bbdfee7b2c84e4.tar.bz2
android-node-v8-b64446648b61085715908b2769bbdfee7b2c84e4.zip
crypto: add oaepLabel option
The label acts as the "L" input to the RSA-OAEP algorithm. PR-URL: https://github.com/nodejs/node/pull/29489 Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_crypto.cc20
-rw-r--r--src/node_crypto.h2
2 files changed, 22 insertions, 0 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index b1d8145e6d..40dad6827b 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -5204,6 +5204,8 @@ bool PublicKeyCipher::Cipher(Environment* env,
const ManagedEVPPKey& pkey,
int padding,
const EVP_MD* digest,
+ const void* oaep_label,
+ size_t oaep_label_len,
const unsigned char* data,
int len,
AllocatedBuffer* out) {
@@ -5220,6 +5222,16 @@ bool PublicKeyCipher::Cipher(Environment* env,
return false;
}
+ if (oaep_label_len != 0) {
+ // OpenSSL takes ownership of the label, so we need to create a copy.
+ void* label = OPENSSL_memdup(oaep_label, oaep_label_len);
+ CHECK_NOT_NULL(label);
+ if (!EVP_PKEY_CTX_set0_rsa_oaep_label(ctx.get(), label, oaep_label_len)) {
+ OPENSSL_free(label);
+ return false;
+ }
+ }
+
size_t out_len = 0;
if (EVP_PKEY_cipher(ctx.get(), nullptr, &out_len, data, len) <= 0)
return false;
@@ -5265,6 +5277,12 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
return THROW_ERR_OSSL_EVP_INVALID_DIGEST(env);
}
+ ArrayBufferViewContents<unsigned char> oaep_label;
+ if (!args[offset + 3]->IsUndefined()) {
+ CHECK(args[offset + 3]->IsArrayBufferView());
+ oaep_label.Read(args[offset + 3].As<ArrayBufferView>());
+ }
+
AllocatedBuffer out;
ClearErrorOnReturn clear_error_on_return;
@@ -5274,6 +5292,8 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
pkey,
padding,
digest,
+ oaep_label.data(),
+ oaep_label.length(),
buf.data(),
buf.length(),
&out);
diff --git a/src/node_crypto.h b/src/node_crypto.h
index 99e6c48117..e335491612 100644
--- a/src/node_crypto.h
+++ b/src/node_crypto.h
@@ -714,6 +714,8 @@ class PublicKeyCipher {
const ManagedEVPPKey& pkey,
int padding,
const EVP_MD* digest,
+ const void* oaep_label,
+ size_t oaep_label_size,
const unsigned char* data,
int len,
AllocatedBuffer* out);