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_impl.h" | 5 #include "content/renderer/webcrypto/webcrypto_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 #include <openssl/aes.h> | 8 #include <openssl/aes.h> |
9 #include <openssl/evp.h> | 9 #include <openssl/evp.h> |
10 #include <openssl/hmac.h> | 10 #include <openssl/hmac.h> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 return EVP_aes_128_cbc(); | 44 return EVP_aes_128_cbc(); |
45 case 24: | 45 case 24: |
46 return EVP_aes_192_cbc(); | 46 return EVP_aes_192_cbc(); |
47 case 32: | 47 case 32: |
48 return EVP_aes_256_cbc(); | 48 return EVP_aes_256_cbc(); |
49 default: | 49 default: |
50 return NULL; | 50 return NULL; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 // TODO(eroman): This is wrong. These constants are bytes not bits. Moreover | |
55 // this doesn't match the NSS version. | |
56 unsigned WebCryptoHmacParamsToBlockSizeBytes( | |
57 const blink::WebCryptoHmacKeyParams* params) { | |
58 DCHECK(params); | |
59 switch (params->hash().id()) { | |
60 case blink::WebCryptoAlgorithmIdSha1: | |
61 return SHA_DIGEST_LENGTH / 8; | |
62 case blink::WebCryptoAlgorithmIdSha224: | |
63 return SHA224_DIGEST_LENGTH / 8; | |
64 case blink::WebCryptoAlgorithmIdSha256: | |
65 return SHA256_DIGEST_LENGTH / 8; | |
66 case blink::WebCryptoAlgorithmIdSha384: | |
67 return SHA384_DIGEST_LENGTH / 8; | |
68 case blink::WebCryptoAlgorithmIdSha512: | |
69 return SHA512_DIGEST_LENGTH / 8; | |
70 default: | |
71 return 0; | |
72 } | |
73 } | |
74 | |
75 // OpenSSL constants for EVP_CipherInit_ex(), do not change | 54 // OpenSSL constants for EVP_CipherInit_ex(), do not change |
76 enum CipherOperation { | 55 enum CipherOperation { |
77 kDoDecrypt = 0, | 56 kDoDecrypt = 0, |
78 kDoEncrypt = 1 | 57 kDoEncrypt = 1 |
79 }; | 58 }; |
80 | 59 |
81 bool AesCbcEncryptDecrypt(CipherOperation cipher_operation, | 60 bool AesCbcEncryptDecrypt(CipherOperation cipher_operation, |
82 const blink::WebCryptoAlgorithm& algorithm, | 61 const blink::WebCryptoAlgorithm& algorithm, |
83 const blink::WebCryptoKey& key, | 62 const blink::WebCryptoKey& key, |
84 const unsigned char* data, | 63 const unsigned char* data, |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 } | 267 } |
289 key_type = blink::WebCryptoKeyTypeSecret; | 268 key_type = blink::WebCryptoKeyTypeSecret; |
290 break; | 269 break; |
291 } | 270 } |
292 case blink::WebCryptoAlgorithmIdHmac: { | 271 case blink::WebCryptoAlgorithmIdHmac: { |
293 const blink::WebCryptoHmacKeyParams* params = algorithm.hmacKeyParams(); | 272 const blink::WebCryptoHmacKeyParams* params = algorithm.hmacKeyParams(); |
294 DCHECK(params); | 273 DCHECK(params); |
295 if (params->hasLengthBytes()) { | 274 if (params->hasLengthBytes()) { |
296 keylen_bytes = params->optionalLengthBytes(); | 275 keylen_bytes = params->optionalLengthBytes(); |
297 } else { | 276 } else { |
298 keylen_bytes = WebCryptoHmacParamsToBlockSizeBytes(params); | 277 keylen_bytes = webcrypto::ShaBlockSizeBytes(params->hash().id()); |
299 } | 278 } |
300 key_type = blink::WebCryptoKeyTypeSecret; | 279 key_type = blink::WebCryptoKeyTypeSecret; |
301 break; | 280 break; |
302 } | 281 } |
303 | 282 |
304 default: { return false; } | 283 default: { return false; } |
305 } | 284 } |
306 | 285 |
307 if (keylen_bytes == 0) { | 286 if (keylen_bytes == 0) { |
308 return false; | 287 return false; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 const blink::WebCryptoAlgorithm& algorithm, | 513 const blink::WebCryptoAlgorithm& algorithm, |
535 bool extractable, | 514 bool extractable, |
536 blink::WebCryptoKeyUsageMask usage_mask, | 515 blink::WebCryptoKeyUsageMask usage_mask, |
537 blink::WebCryptoKey* key) { | 516 blink::WebCryptoKey* key) { |
538 // TODO(padolph): Placeholder for OpenSSL implementation. | 517 // TODO(padolph): Placeholder for OpenSSL implementation. |
539 // Issue http://crbug.com/267888. | 518 // Issue http://crbug.com/267888. |
540 return false; | 519 return false; |
541 } | 520 } |
542 | 521 |
543 } // namespace content | 522 } // namespace content |
OLD | NEW |