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

Side by Side Diff: components/webcrypto/algorithms/hkdf.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/err.h> 5 #include <openssl/err.h>
6 #include <openssl/hkdf.h> 6 #include <openssl/hkdf.h>
7 7
8 #include "base/logging.h" 8 #include "base/logging.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/status.h" 14 #include "components/webcrypto/status.h"
16 #include "crypto/openssl_util.h" 15 #include "crypto/openssl_util.h"
17 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 16 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
18 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 17 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
19 18
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 if (!digest_algorithm) 61 if (!digest_algorithm)
63 return Status::ErrorUnsupported(); 62 return Status::ErrorUnsupported();
64 63
65 // Size output to fit length 64 // Size output to fit length
66 unsigned int derived_bytes_len = NumBitsToBytes(optional_length_bits); 65 unsigned int derived_bytes_len = NumBitsToBytes(optional_length_bits);
67 derived_bytes->resize(derived_bytes_len); 66 derived_bytes->resize(derived_bytes_len);
68 67
69 // Algorithm dispatch checks that the algorithm in |base_key| matches 68 // Algorithm dispatch checks that the algorithm in |base_key| matches
70 // |algorithm|. 69 // |algorithm|.
71 const std::vector<uint8_t>& raw_key = GetSymmetricKeyData(base_key); 70 const std::vector<uint8_t>& raw_key = GetSymmetricKeyData(base_key);
72 if (!HKDF(vector_as_array(derived_bytes), derived_bytes_len, 71 if (!HKDF(derived_bytes->data(), derived_bytes_len, digest_algorithm,
73 digest_algorithm, vector_as_array(&raw_key), raw_key.size(), 72 raw_key.data(), raw_key.size(), params->salt().data(),
74 params->salt().data(), params->salt().size(), 73 params->salt().size(), params->info().data(),
75 params->info().data(), params->info().size())) { 74 params->info().size())) {
76 uint32_t error = ERR_get_error(); 75 uint32_t error = ERR_get_error();
77 if (ERR_GET_LIB(error) == ERR_LIB_HKDF && 76 if (ERR_GET_LIB(error) == ERR_LIB_HKDF &&
78 ERR_GET_REASON(error) == HKDF_R_OUTPUT_TOO_LARGE) { 77 ERR_GET_REASON(error) == HKDF_R_OUTPUT_TOO_LARGE) {
79 return Status::ErrorHkdfLengthTooLong(); 78 return Status::ErrorHkdfLengthTooLong();
80 } 79 }
81 return Status::OperationError(); 80 return Status::OperationError();
82 } 81 }
83 82
84 TruncateToBitLength(optional_length_bits, derived_bytes); 83 TruncateToBitLength(optional_length_bits, derived_bytes);
85 return Status::Success(); 84 return Status::Success();
(...skipping 17 matching lines...) Expand all
103 } 102 }
104 }; 103 };
105 104
106 } // namespace 105 } // namespace
107 106
108 scoped_ptr<AlgorithmImplementation> CreateHkdfImplementation() { 107 scoped_ptr<AlgorithmImplementation> CreateHkdfImplementation() {
109 return make_scoped_ptr(new HkdfImplementation); 108 return make_scoped_ptr(new HkdfImplementation);
110 } 109 }
111 110
112 } // namespace webcrypto 111 } // namespace webcrypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698