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

Side by Side Diff: content/child/webcrypto/openssl/hmac_openssl.cc

Issue 404733005: Replace uses of uint8 with uint8_t. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase onto master Created 6 years, 5 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 | Annotate | Revision Log
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 "content/child/webcrypto/algorithm_implementation.h"
8 #include "content/child/webcrypto/crypto_data.h" 9 #include "content/child/webcrypto/crypto_data.h"
9 #include "content/child/webcrypto/jwk.h" 10 #include "content/child/webcrypto/jwk.h"
10 #include "content/child/webcrypto/openssl/key_openssl.h" 11 #include "content/child/webcrypto/openssl/key_openssl.h"
11 #include "content/child/webcrypto/openssl/sym_key_openssl.h" 12 #include "content/child/webcrypto/openssl/sym_key_openssl.h"
12 #include "content/child/webcrypto/openssl/util_openssl.h" 13 #include "content/child/webcrypto/openssl/util_openssl.h"
13 #include "content/child/webcrypto/status.h" 14 #include "content/child/webcrypto/status.h"
14 #include "content/child/webcrypto/webcrypto_util.h" 15 #include "content/child/webcrypto/webcrypto_util.h"
15 #include "crypto/openssl_util.h" 16 #include "crypto/openssl_util.h"
16 #include "crypto/secure_util.h" 17 #include "crypto/secure_util.h"
17 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 18 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
18 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 19 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
19 20
20 namespace content { 21 namespace content {
21 22
22 namespace webcrypto { 23 namespace webcrypto {
23 24
24 namespace { 25 namespace {
25 26
26 const blink::WebCryptoKeyUsageMask kAllKeyUsages = 27 const blink::WebCryptoKeyUsageMask kAllKeyUsages =
27 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify; 28 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify;
28 29
29 Status SignHmac(const std::vector<uint8>& raw_key, 30 Status SignHmac(const std::vector<uint8_t>& raw_key,
30 const blink::WebCryptoAlgorithm& hash, 31 const blink::WebCryptoAlgorithm& hash,
31 const CryptoData& data, 32 const CryptoData& data,
32 std::vector<uint8>* buffer) { 33 std::vector<uint8_t>* buffer) {
33 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); 34 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
34 35
35 const EVP_MD* digest_algorithm = GetDigest(hash.id()); 36 const EVP_MD* digest_algorithm = GetDigest(hash.id());
36 if (!digest_algorithm) 37 if (!digest_algorithm)
37 return Status::ErrorUnsupported(); 38 return Status::ErrorUnsupported();
38 unsigned int hmac_expected_length = EVP_MD_size(digest_algorithm); 39 unsigned int hmac_expected_length = EVP_MD_size(digest_algorithm);
39 40
40 // OpenSSL wierdness here. 41 // OpenSSL wierdness here.
41 // First, HMAC() needs a void* for the key data, so make one up front as a 42 // First, HMAC() needs a void* for the key data, so make one up front as a
42 // cosmetic to avoid a cast. Second, OpenSSL does not like a NULL key, 43 // cosmetic to avoid a cast. Second, OpenSSL does not like a NULL key,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 virtual Status ImportKeyJwk(const CryptoData& key_data, 127 virtual Status ImportKeyJwk(const CryptoData& key_data,
127 const blink::WebCryptoAlgorithm& algorithm, 128 const blink::WebCryptoAlgorithm& algorithm,
128 bool extractable, 129 bool extractable,
129 blink::WebCryptoKeyUsageMask usage_mask, 130 blink::WebCryptoKeyUsageMask usage_mask,
130 blink::WebCryptoKey* key) const OVERRIDE { 131 blink::WebCryptoKey* key) const OVERRIDE {
131 const char* algorithm_name = 132 const char* algorithm_name =
132 GetJwkHmacAlgorithmName(algorithm.hmacImportParams()->hash().id()); 133 GetJwkHmacAlgorithmName(algorithm.hmacImportParams()->hash().id());
133 if (!algorithm_name) 134 if (!algorithm_name)
134 return Status::ErrorUnexpected(); 135 return Status::ErrorUnexpected();
135 136
136 std::vector<uint8> raw_data; 137 std::vector<uint8_t> raw_data;
137 Status status = ReadSecretKeyJwk( 138 Status status = ReadSecretKeyJwk(
138 key_data, algorithm_name, extractable, usage_mask, &raw_data); 139 key_data, algorithm_name, extractable, usage_mask, &raw_data);
139 if (status.IsError()) 140 if (status.IsError())
140 return status; 141 return status;
141 142
142 return ImportKeyRaw( 143 return ImportKeyRaw(
143 CryptoData(raw_data), algorithm, extractable, usage_mask, key); 144 CryptoData(raw_data), algorithm, extractable, usage_mask, key);
144 } 145 }
145 146
146 virtual Status ExportKeyRaw(const blink::WebCryptoKey& key, 147 virtual Status ExportKeyRaw(const blink::WebCryptoKey& key,
147 std::vector<uint8>* buffer) const OVERRIDE { 148 std::vector<uint8_t>* buffer) const OVERRIDE {
148 *buffer = SymKeyOpenSsl::Cast(key)->raw_key_data(); 149 *buffer = SymKeyOpenSsl::Cast(key)->raw_key_data();
149 return Status::Success(); 150 return Status::Success();
150 } 151 }
151 152
152 virtual Status ExportKeyJwk(const blink::WebCryptoKey& key, 153 virtual Status ExportKeyJwk(const blink::WebCryptoKey& key,
153 std::vector<uint8>* buffer) const OVERRIDE { 154 std::vector<uint8_t>* buffer) const OVERRIDE {
154 SymKeyOpenSsl* sym_key = SymKeyOpenSsl::Cast(key); 155 SymKeyOpenSsl* sym_key = SymKeyOpenSsl::Cast(key);
155 const std::vector<uint8>& raw_data = sym_key->raw_key_data(); 156 const std::vector<uint8_t>& raw_data = sym_key->raw_key_data();
156 157
157 const char* algorithm_name = 158 const char* algorithm_name =
158 GetJwkHmacAlgorithmName(key.algorithm().hmacParams()->hash().id()); 159 GetJwkHmacAlgorithmName(key.algorithm().hmacParams()->hash().id());
159 if (!algorithm_name) 160 if (!algorithm_name)
160 return Status::ErrorUnexpected(); 161 return Status::ErrorUnexpected();
161 162
162 WriteSecretKeyJwk(CryptoData(raw_data), 163 WriteSecretKeyJwk(CryptoData(raw_data),
163 algorithm_name, 164 algorithm_name,
164 key.extractable(), 165 key.extractable(),
165 key.usages(), 166 key.usages(),
166 buffer); 167 buffer);
167 168
168 return Status::Success(); 169 return Status::Success();
169 } 170 }
170 171
171 virtual Status Sign(const blink::WebCryptoAlgorithm& algorithm, 172 virtual Status Sign(const blink::WebCryptoAlgorithm& algorithm,
172 const blink::WebCryptoKey& key, 173 const blink::WebCryptoKey& key,
173 const CryptoData& data, 174 const CryptoData& data,
174 std::vector<uint8>* buffer) const OVERRIDE { 175 std::vector<uint8_t>* buffer) const OVERRIDE {
175 const blink::WebCryptoAlgorithm& hash = 176 const blink::WebCryptoAlgorithm& hash =
176 key.algorithm().hmacParams()->hash(); 177 key.algorithm().hmacParams()->hash();
177 178
178 return SignHmac( 179 return SignHmac(
179 SymKeyOpenSsl::Cast(key)->raw_key_data(), hash, data, buffer); 180 SymKeyOpenSsl::Cast(key)->raw_key_data(), hash, data, buffer);
180 } 181 }
181 182
182 virtual Status Verify(const blink::WebCryptoAlgorithm& algorithm, 183 virtual Status Verify(const blink::WebCryptoAlgorithm& algorithm,
183 const blink::WebCryptoKey& key, 184 const blink::WebCryptoKey& key,
184 const CryptoData& signature, 185 const CryptoData& signature,
185 const CryptoData& data, 186 const CryptoData& data,
186 bool* signature_match) const OVERRIDE { 187 bool* signature_match) const OVERRIDE {
187 std::vector<uint8> result; 188 std::vector<uint8_t> result;
188 Status status = Sign(algorithm, key, data, &result); 189 Status status = Sign(algorithm, key, data, &result);
189 190
190 if (status.IsError()) 191 if (status.IsError())
191 return status; 192 return status;
192 193
193 // Do not allow verification of truncated MACs. 194 // Do not allow verification of truncated MACs.
194 *signature_match = result.size() == signature.byte_length() && 195 *signature_match = result.size() == signature.byte_length() &&
195 crypto::SecureMemEqual(Uint8VectorStart(result), 196 crypto::SecureMemEqual(Uint8VectorStart(result),
196 signature.bytes(), 197 signature.bytes(),
197 signature.byte_length()); 198 signature.byte_length());
198 199
199 return Status::Success(); 200 return Status::Success();
200 } 201 }
201 }; 202 };
202 203
203 } // namespace 204 } // namespace
204 205
205 AlgorithmImplementation* CreatePlatformHmacImplementation() { 206 AlgorithmImplementation* CreatePlatformHmacImplementation() {
206 return new HmacImplementation; 207 return new HmacImplementation;
207 } 208 }
208 209
209 } // namespace webcrypto 210 } // namespace webcrypto
210 211
211 } // namespace content 212 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/openssl/aes_kw_openssl.cc ('k') | content/child/webcrypto/openssl/key_openssl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698