OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/webcrypto/webcrypto_util.h" | 5 #include "content/child/webcrypto/webcrypto_util.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 9 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
11 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 11 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 | 14 |
15 namespace webcrypto { | 15 namespace webcrypto { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 246 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
247 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 247 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
248 new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); | 248 new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); |
249 } | 249 } |
250 | 250 |
251 blink::WebCryptoAlgorithm CreateRsaOaepImportAlgorithm( | 251 blink::WebCryptoAlgorithm CreateRsaOaepImportAlgorithm( |
252 blink::WebCryptoAlgorithmId hash_id) { | 252 blink::WebCryptoAlgorithmId hash_id) { |
253 DCHECK(IsHashAlgorithm(hash_id)); | 253 DCHECK(IsHashAlgorithm(hash_id)); |
254 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 254 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
255 blink::WebCryptoAlgorithmIdRsaOaep, | 255 blink::WebCryptoAlgorithmIdRsaOaep, |
256 new blink::WebCryptoRsaHashedImportParams( | 256 new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); |
257 CreateAlgorithm(hash_id))); | |
258 } | 257 } |
259 | 258 |
260 | |
261 unsigned int ShaBlockSizeBytes(blink::WebCryptoAlgorithmId hash_id) { | 259 unsigned int ShaBlockSizeBytes(blink::WebCryptoAlgorithmId hash_id) { |
262 switch (hash_id) { | 260 switch (hash_id) { |
263 case blink::WebCryptoAlgorithmIdSha1: | 261 case blink::WebCryptoAlgorithmIdSha1: |
264 case blink::WebCryptoAlgorithmIdSha224: | 262 case blink::WebCryptoAlgorithmIdSha224: |
265 case blink::WebCryptoAlgorithmIdSha256: | 263 case blink::WebCryptoAlgorithmIdSha256: |
266 return 64; | 264 return 64; |
267 case blink::WebCryptoAlgorithmIdSha384: | 265 case blink::WebCryptoAlgorithmIdSha384: |
268 case blink::WebCryptoAlgorithmIdSha512: | 266 case blink::WebCryptoAlgorithmIdSha512: |
269 return 128; | 267 return 128; |
270 default: | 268 default: |
271 NOTREACHED(); | 269 NOTREACHED(); |
272 return 0; | 270 return 0; |
273 } | 271 } |
274 } | 272 } |
275 | 273 |
276 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, | 274 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, |
277 unsigned keylen_bytes, | 275 unsigned keylen_bytes, |
278 blink::WebCryptoKeyAlgorithm* key_algorithm) { | 276 blink::WebCryptoKeyAlgorithm* key_algorithm) { |
279 switch (algorithm.id()) { | 277 switch (algorithm.id()) { |
280 case blink::WebCryptoAlgorithmIdHmac: { | 278 case blink::WebCryptoAlgorithmIdHmac: { |
281 blink::WebCryptoAlgorithm hash = GetInnerHashAlgorithm(algorithm); | 279 blink::WebCryptoAlgorithm hash = GetInnerHashAlgorithm(algorithm); |
282 if (hash.isNull()) | 280 if (hash.isNull()) |
283 return false; | 281 return false; |
284 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( | 282 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( |
285 algorithm.id(), | 283 algorithm.id(), new blink::WebCryptoHmacKeyAlgorithmParams(hash)); |
286 new blink::WebCryptoHmacKeyAlgorithmParams(hash)); | |
287 return true; | 284 return true; |
288 } | 285 } |
289 case blink::WebCryptoAlgorithmIdAesKw: | 286 case blink::WebCryptoAlgorithmIdAesKw: |
290 case blink::WebCryptoAlgorithmIdAesCbc: | 287 case blink::WebCryptoAlgorithmIdAesCbc: |
291 case blink::WebCryptoAlgorithmIdAesCtr: | 288 case blink::WebCryptoAlgorithmIdAesCtr: |
292 case blink::WebCryptoAlgorithmIdAesGcm: | 289 case blink::WebCryptoAlgorithmIdAesGcm: |
293 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( | 290 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( |
294 algorithm.id(), | 291 algorithm.id(), |
295 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); | 292 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); |
296 return true; | 293 return true; |
297 default: | 294 default: |
298 return false; | 295 return false; |
299 } | 296 } |
300 } | 297 } |
301 | 298 |
302 } // namespace webcrypto | 299 } // namespace webcrypto |
303 | 300 |
304 } // namespace content | 301 } // namespace content |
OLD | NEW |