| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3c653cf commit 0606f92
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -987,17 +987,7 @@ bool PublicKeyCipher::Cipher( | |||
| 987 | 987 | return false; | |
| 988 | 988 | } | |
| 989 | 989 | ||
| 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; | ||
| 1001 | 991 | ||
| 1002 | 992 | size_t out_len = 0; | |
| 1003 | 993 | if (EVP_PKEY_cipher( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -221,18 +221,7 @@ WebCryptoCipherStatus RSA_Cipher( | |||
| 221 | 221 | return WebCryptoCipherStatus::FAILED; | |
| 222 | 222 | } | |
| 223 | 223 | ||
| 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; | ||
| 236 | 225 | ||
| 237 | 226 | size_t out_len = 0; | |
| 238 | 227 | if (cipher( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -654,6 +654,21 @@ Maybe<bool> SetEncodedValue( | |||
| 654 | 654 | return target->Set(env->context(), name, value); | |
| 655 | 655 | } | |
| 656 | 656 | ||
| 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 | + | ||
| 657 | 672 | CryptoJobMode GetCryptoJobMode(v8::Local<v8::Value> args) { | |
| 658 | 673 | CHECK(args->IsUint32()); | |
| 659 | 674 | 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( | |||
| 791 | 791 | const BIGNUM* bn, | |
| 792 | 792 | int size = 0); | |
| 793 | 793 | ||
| 794 | + bool SetRsaOaepLabel(const EVPKeyCtxPointer& rsa, const ByteSource& label); | ||
| 795 | + | ||
| 794 | 796 | namespace Util { | |
| 795 | 797 | void Initialize(Environment* env, v8::Local<v8::Object> target); | |
| 796 | 798 | void RegisterExternalReferences(ExternalReferenceRegistry* registry); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments