Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: components/webcrypto/algorithms/rsa_oaep.cc

Issue 2407633002: Use new BoringSSL scopers in //components. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/webcrypto/algorithms/rsa.cc ('k') | components/webcrypto/algorithms/rsa_sign.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <openssl/evp.h> 5 #include <openssl/evp.h>
6 #include <openssl/mem.h>
7 #include <openssl/rsa.h>
6 #include <stddef.h> 8 #include <stddef.h>
7 #include <stdint.h> 9 #include <stdint.h>
8 #include <string.h> 10 #include <string.h>
9 11
10 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
11 #include "components/webcrypto/algorithms/rsa.h" 13 #include "components/webcrypto/algorithms/rsa.h"
12 #include "components/webcrypto/algorithms/util.h" 14 #include "components/webcrypto/algorithms/util.h"
13 #include "components/webcrypto/blink_key_handle.h" 15 #include "components/webcrypto/blink_key_handle.h"
14 #include "components/webcrypto/crypto_data.h" 16 #include "components/webcrypto/crypto_data.h"
15 #include "components/webcrypto/status.h" 17 #include "components/webcrypto/status.h"
16 #include "crypto/openssl_util.h" 18 #include "crypto/openssl_util.h"
17 #include "crypto/scoped_openssl_types.h"
18 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 19 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
19 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 20 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
20 21
21 namespace webcrypto { 22 namespace webcrypto {
22 23
23 namespace { 24 namespace {
24 25
25 typedef int (*InitFunc)(EVP_PKEY_CTX* ctx); 26 typedef int (*InitFunc)(EVP_PKEY_CTX* ctx);
26 typedef int (*EncryptDecryptFunc)(EVP_PKEY_CTX* ctx, 27 typedef int (*EncryptDecryptFunc)(EVP_PKEY_CTX* ctx,
27 unsigned char* out, 28 unsigned char* out,
(...skipping 14 matching lines...) Expand all
42 const blink::WebCryptoKey& key, 43 const blink::WebCryptoKey& key,
43 const CryptoData& data, 44 const CryptoData& data,
44 std::vector<uint8_t>* buffer) { 45 std::vector<uint8_t>* buffer) {
45 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); 46 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
46 47
47 EVP_PKEY* pkey = GetEVP_PKEY(key); 48 EVP_PKEY* pkey = GetEVP_PKEY(key);
48 const EVP_MD* digest = GetDigest(key.algorithm().rsaHashedParams()->hash()); 49 const EVP_MD* digest = GetDigest(key.algorithm().rsaHashedParams()->hash());
49 if (!digest) 50 if (!digest)
50 return Status::ErrorUnsupported(); 51 return Status::ErrorUnsupported();
51 52
52 crypto::ScopedEVP_PKEY_CTX ctx(EVP_PKEY_CTX_new(pkey, NULL)); 53 bssl::UniquePtr<EVP_PKEY_CTX> ctx(EVP_PKEY_CTX_new(pkey, NULL));
53 54
54 if (!init_func(ctx.get()) || 55 if (!init_func(ctx.get()) ||
55 !EVP_PKEY_CTX_set_rsa_padding(ctx.get(), RSA_PKCS1_OAEP_PADDING) || 56 !EVP_PKEY_CTX_set_rsa_padding(ctx.get(), RSA_PKCS1_OAEP_PADDING) ||
56 !EVP_PKEY_CTX_set_rsa_oaep_md(ctx.get(), digest) || 57 !EVP_PKEY_CTX_set_rsa_oaep_md(ctx.get(), digest) ||
57 !EVP_PKEY_CTX_set_rsa_mgf1_md(ctx.get(), digest)) { 58 !EVP_PKEY_CTX_set_rsa_mgf1_md(ctx.get(), digest)) {
58 return Status::OperationError(); 59 return Status::OperationError();
59 } 60 }
60 61
61 const blink::WebVector<uint8_t>& label = 62 const blink::WebVector<uint8_t>& label =
62 algorithm.rsaOaepParams()->optionalLabel(); 63 algorithm.rsaOaepParams()->optionalLabel();
63 64
64 if (label.size()) { 65 if (label.size()) {
65 // Make a copy of the label, since the ctx takes ownership of it when 66 // Make a copy of the label, since the ctx takes ownership of it when
66 // calling set0_rsa_oaep_label(). 67 // calling set0_rsa_oaep_label().
67 crypto::ScopedOpenSSLBytes label_copy; 68 bssl::UniquePtr<uint8_t> label_copy;
68 label_copy.reset(static_cast<uint8_t*>(OPENSSL_malloc(label.size()))); 69 label_copy.reset(static_cast<uint8_t*>(OPENSSL_malloc(label.size())));
69 memcpy(label_copy.get(), label.data(), label.size()); 70 memcpy(label_copy.get(), label.data(), label.size());
70 71
71 if (1 != EVP_PKEY_CTX_set0_rsa_oaep_label(ctx.get(), label_copy.release(), 72 if (1 != EVP_PKEY_CTX_set0_rsa_oaep_label(ctx.get(), label_copy.release(),
72 label.size())) { 73 label.size())) {
73 return Status::OperationError(); 74 return Status::OperationError();
74 } 75 }
75 } 76 }
76 77
77 // Determine the maximum length of the output. 78 // Determine the maximum length of the output.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 140 }
140 }; 141 };
141 142
142 } // namespace 143 } // namespace
143 144
144 std::unique_ptr<AlgorithmImplementation> CreateRsaOaepImplementation() { 145 std::unique_ptr<AlgorithmImplementation> CreateRsaOaepImplementation() {
145 return base::WrapUnique(new RsaOaepImplementation); 146 return base::WrapUnique(new RsaOaepImplementation);
146 } 147 }
147 148
148 } // namespace webcrypto 149 } // namespace webcrypto
OLDNEW
« no previous file with comments | « components/webcrypto/algorithms/rsa.cc ('k') | components/webcrypto/algorithms/rsa_sign.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698