File tree Expand file tree Collapse file tree 4 files changed +19
-23
lines changed Expand file tree Collapse file tree 4 files changed +19
-23
lines changed Original file line number Diff line number Diff line change @@ -987,17 +987,7 @@ bool PublicKeyCipher::Cipher(
987987 return false ;
988988 }
989989
990- if (oaep_label.size () != 0 ) {
991- // OpenSSL takes ownership of the label, so we need to create a copy.
992- void * label = OPENSSL_memdup (oaep_label.data (), oaep_label.size ());
993- CHECK_NOT_NULL (label);
994- if (0 >= EVP_PKEY_CTX_set0_rsa_oaep_label (ctx.get (),
995- static_cast <unsigned char *>(label),
996- oaep_label.size ())) {
997- OPENSSL_free (label);
998- return false ;
999- }
1000- }
990+ if (!SetRsaOaepLabel (ctx, oaep_label.ToByteSource ())) return false ;
1001991
1002992 size_t out_len = 0 ;
1003993 if (EVP_PKEY_cipher (
Original file line number Diff line number Diff line change @@ -221,18 +221,7 @@ WebCryptoCipherStatus RSA_Cipher(
221221 return WebCryptoCipherStatus::FAILED;
222222 }
223223
224- size_t label_len = params.label .size ();
225- if (label_len > 0 ) {
226- void * label = OPENSSL_memdup (params.label .data <char >(), label_len);
227- CHECK_NOT_NULL (label);
228- if (EVP_PKEY_CTX_set0_rsa_oaep_label (
229- ctx.get (),
230- static_cast <unsigned char *>(label),
231- label_len) <= 0 ) {
232- OPENSSL_free (label);
233- return WebCryptoCipherStatus::FAILED;
234- }
235- }
224+ if (!SetRsaOaepLabel (ctx, params.label )) return WebCryptoCipherStatus::FAILED;
236225
237226 size_t out_len = 0 ;
238227 if (cipher (
Original file line number Diff line number Diff line change @@ -654,6 +654,21 @@ Maybe<bool> SetEncodedValue(
654654 return target->Set (env->context (), name, value);
655655}
656656
657+ bool SetRsaOaepLabel (const EVPKeyCtxPointer& ctx, const ByteSource& label) {
658+ if (label.size () != 0 ) {
659+ // OpenSSL takes ownership of the label, so we need to create a copy.
660+ void * label_copy = OPENSSL_memdup (label.data (), label.size ());
661+ CHECK_NOT_NULL (label_copy);
662+ int ret = EVP_PKEY_CTX_set0_rsa_oaep_label (
663+ ctx.get (), static_cast <unsigned char *>(label_copy), label.size ());
664+ if (ret <= 0 ) {
665+ OPENSSL_free (label_copy);
666+ return false ;
667+ }
668+ }
669+ return true ;
670+ }
671+
657672CryptoJobMode GetCryptoJobMode (v8::Local<v8::Value> args) {
658673 CHECK (args->IsUint32 ());
659674 uint32_t mode = args.As <v8::Uint32>()->Value ();
Original file line number Diff line number Diff line change @@ -791,6 +791,8 @@ v8::Maybe<bool> SetEncodedValue(
791791 const BIGNUM* bn,
792792 int size = 0 );
793793
794+ bool SetRsaOaepLabel (const EVPKeyCtxPointer& rsa, const ByteSource& label);
795+
794796namespace Util {
795797void Initialize (Environment* env, v8::Local<v8::Object> target);
796798void RegisterExternalReferences (ExternalReferenceRegistry* registry);
You can’t perform that action at this time.
0 commit comments