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

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

Issue 1461703009: Switch //components from vector_as_array to vector::data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
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/hmac.h> 5 #include <openssl/hmac.h>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/numerics/safe_math.h" 8 #include "base/numerics/safe_math.h"
9 #include "base/stl_util.h"
10 #include "components/webcrypto/algorithm_implementation.h" 9 #include "components/webcrypto/algorithm_implementation.h"
11 #include "components/webcrypto/algorithms/secret_key_util.h" 10 #include "components/webcrypto/algorithms/secret_key_util.h"
12 #include "components/webcrypto/algorithms/util.h" 11 #include "components/webcrypto/algorithms/util.h"
13 #include "components/webcrypto/blink_key_handle.h" 12 #include "components/webcrypto/blink_key_handle.h"
14 #include "components/webcrypto/crypto_data.h" 13 #include "components/webcrypto/crypto_data.h"
15 #include "components/webcrypto/jwk.h" 14 #include "components/webcrypto/jwk.h"
16 #include "components/webcrypto/status.h" 15 #include "components/webcrypto/status.h"
17 #include "crypto/openssl_util.h" 16 #include "crypto/openssl_util.h"
18 #include "crypto/secure_util.h" 17 #include "crypto/secure_util.h"
19 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 18 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 std::vector<uint8_t>* buffer) { 87 std::vector<uint8_t>* buffer) {
89 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); 88 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
90 89
91 const EVP_MD* digest_algorithm = GetDigest(hash); 90 const EVP_MD* digest_algorithm = GetDigest(hash);
92 if (!digest_algorithm) 91 if (!digest_algorithm)
93 return Status::ErrorUnsupported(); 92 return Status::ErrorUnsupported();
94 size_t hmac_expected_length = EVP_MD_size(digest_algorithm); 93 size_t hmac_expected_length = EVP_MD_size(digest_algorithm);
95 94
96 buffer->resize(hmac_expected_length); 95 buffer->resize(hmac_expected_length);
97 crypto::ScopedOpenSSLSafeSizeBuffer<EVP_MAX_MD_SIZE> hmac_result( 96 crypto::ScopedOpenSSLSafeSizeBuffer<EVP_MAX_MD_SIZE> hmac_result(
98 vector_as_array(buffer), hmac_expected_length); 97 buffer->data(), hmac_expected_length);
99 98
100 unsigned int hmac_actual_length; 99 unsigned int hmac_actual_length;
101 unsigned char* const success = HMAC( 100 unsigned char* const success =
102 digest_algorithm, vector_as_array(&raw_key), raw_key.size(), data.bytes(), 101 HMAC(digest_algorithm, raw_key.data(), raw_key.size(), data.bytes(),
103 data.byte_length(), hmac_result.safe_buffer(), &hmac_actual_length); 102 data.byte_length(), hmac_result.safe_buffer(), &hmac_actual_length);
104 if (!success || hmac_actual_length != hmac_expected_length) 103 if (!success || hmac_actual_length != hmac_expected_length)
105 return Status::OperationError(); 104 return Status::OperationError();
106 105
107 return Status::Success(); 106 return Status::Success();
108 } 107 }
109 108
110 class HmacImplementation : public AlgorithmImplementation { 109 class HmacImplementation : public AlgorithmImplementation {
111 public: 110 public:
112 HmacImplementation() {} 111 HmacImplementation() {}
113 112
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 const CryptoData& signature, 242 const CryptoData& signature,
244 const CryptoData& data, 243 const CryptoData& data,
245 bool* signature_match) const override { 244 bool* signature_match) const override {
246 std::vector<uint8_t> result; 245 std::vector<uint8_t> result;
247 Status status = Sign(algorithm, key, data, &result); 246 Status status = Sign(algorithm, key, data, &result);
248 247
249 if (status.IsError()) 248 if (status.IsError())
250 return status; 249 return status;
251 250
252 // Do not allow verification of truncated MACs. 251 // Do not allow verification of truncated MACs.
253 *signature_match = 252 *signature_match = result.size() == signature.byte_length() &&
254 result.size() == signature.byte_length() && 253 crypto::SecureMemEqual(result.data(), signature.bytes(),
255 crypto::SecureMemEqual(vector_as_array(&result), signature.bytes(), 254 signature.byte_length());
256 signature.byte_length());
257 255
258 return Status::Success(); 256 return Status::Success();
259 } 257 }
260 258
261 Status DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm& algorithm, 259 Status DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm& algorithm,
262 blink::WebCryptoKeyType type, 260 blink::WebCryptoKeyType type,
263 bool extractable, 261 bool extractable,
264 blink::WebCryptoKeyUsageMask usages, 262 blink::WebCryptoKeyUsageMask usages,
265 const CryptoData& key_data, 263 const CryptoData& key_data,
266 blink::WebCryptoKey* key) const override { 264 blink::WebCryptoKey* key) const override {
(...skipping 19 matching lines...) Expand all
286 } 284 }
287 }; 285 };
288 286
289 } // namespace 287 } // namespace
290 288
291 scoped_ptr<AlgorithmImplementation> CreateHmacImplementation() { 289 scoped_ptr<AlgorithmImplementation> CreateHmacImplementation() {
292 return make_scoped_ptr(new HmacImplementation); 290 return make_scoped_ptr(new HmacImplementation);
293 } 291 }
294 292
295 } // namespace webcrypto 293 } // namespace webcrypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698