From b64446648b61085715908b2769bbdfee7b2c84e4 Mon Sep 17 00:00:00 2001 From: Tobias Nießen Date: Sun, 8 Sep 2019 04:41:04 +0200 Subject: 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 Reviewed-By: Ben Noordhuis Reviewed-By: Minwoo Jung Reviewed-By: James M Snell --- src/node_crypto.cc | 20 ++++++++++++++++++++ src/node_crypto.h | 2 ++ 2 files changed, 22 insertions(+) (limited to 'src') 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& args) { return THROW_ERR_OSSL_EVP_INVALID_DIGEST(env); } + ArrayBufferViewContents oaep_label; + if (!args[offset + 3]->IsUndefined()) { + CHECK(args[offset + 3]->IsArrayBufferView()); + oaep_label.Read(args[offset + 3].As()); + } + AllocatedBuffer out; ClearErrorOnReturn clear_error_on_return; @@ -5274,6 +5292,8 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo& 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); -- cgit v1.2.3