| 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 unsigned WebCryptoHmacParamsToBlockSize( | 54 // TODO(eroman): This is wrong. These constants are bytes not bits. Moreover |
| 55 // this doesn't match the NSS version. |
| 56 unsigned WebCryptoHmacParamsToBlockSizeBytes( |
| 55 const blink::WebCryptoHmacKeyParams* params) { | 57 const blink::WebCryptoHmacKeyParams* params) { |
| 56 DCHECK(params); | 58 DCHECK(params); |
| 57 switch (params->hash().id()) { | 59 switch (params->hash().id()) { |
| 58 case blink::WebCryptoAlgorithmIdSha1: | 60 case blink::WebCryptoAlgorithmIdSha1: |
| 59 return SHA_DIGEST_LENGTH / 8; | 61 return SHA_DIGEST_LENGTH / 8; |
| 60 case blink::WebCryptoAlgorithmIdSha224: | 62 case blink::WebCryptoAlgorithmIdSha224: |
| 61 return SHA224_DIGEST_LENGTH / 8; | 63 return SHA224_DIGEST_LENGTH / 8; |
| 62 case blink::WebCryptoAlgorithmIdSha256: | 64 case blink::WebCryptoAlgorithmIdSha256: |
| 63 return SHA256_DIGEST_LENGTH / 8; | 65 return SHA256_DIGEST_LENGTH / 8; |
| 64 case blink::WebCryptoAlgorithmIdSha384: | 66 case blink::WebCryptoAlgorithmIdSha384: |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 blink::WebCryptoKeyUsageMask usage_mask, | 273 blink::WebCryptoKeyUsageMask usage_mask, |
| 272 blink::WebCryptoKey* key) { | 274 blink::WebCryptoKey* key) { |
| 273 | 275 |
| 274 unsigned keylen_bytes = 0; | 276 unsigned keylen_bytes = 0; |
| 275 blink::WebCryptoKeyType key_type; | 277 blink::WebCryptoKeyType key_type; |
| 276 switch (algorithm.id()) { | 278 switch (algorithm.id()) { |
| 277 case blink::WebCryptoAlgorithmIdAesCbc: { | 279 case blink::WebCryptoAlgorithmIdAesCbc: { |
| 278 const blink::WebCryptoAesKeyGenParams* params = | 280 const blink::WebCryptoAesKeyGenParams* params = |
| 279 algorithm.aesKeyGenParams(); | 281 algorithm.aesKeyGenParams(); |
| 280 DCHECK(params); | 282 DCHECK(params); |
| 281 if (params->length() % 8) | 283 if (params->lengthBits() % 8) |
| 282 return false; | 284 return false; |
| 283 keylen_bytes = params->length() / 8; | 285 keylen_bytes = params->lengthBits() / 8; |
| 284 if (!GetAESCipherByKeyLength(keylen_bytes)) { | 286 if (!GetAESCipherByKeyLength(keylen_bytes)) { |
| 285 return false; | 287 return false; |
| 286 } | 288 } |
| 287 key_type = blink::WebCryptoKeyTypeSecret; | 289 key_type = blink::WebCryptoKeyTypeSecret; |
| 288 break; | 290 break; |
| 289 } | 291 } |
| 290 case blink::WebCryptoAlgorithmIdHmac: { | 292 case blink::WebCryptoAlgorithmIdHmac: { |
| 291 const blink::WebCryptoHmacKeyParams* params = algorithm.hmacKeyParams(); | 293 const blink::WebCryptoHmacKeyParams* params = algorithm.hmacKeyParams(); |
| 292 DCHECK(params); | 294 DCHECK(params); |
| 293 if (!params->getLength(keylen_bytes)) { | 295 if (params->hasLengthBytes()) { |
| 294 keylen_bytes = WebCryptoHmacParamsToBlockSize(params); | 296 keylen_bytes = params->optionalLengthBytes(); |
| 297 } else { |
| 298 keylen_bytes = WebCryptoHmacParamsToBlockSizeBytes(params); |
| 295 } | 299 } |
| 296 key_type = blink::WebCryptoKeyTypeSecret; | 300 key_type = blink::WebCryptoKeyTypeSecret; |
| 297 break; | 301 break; |
| 298 } | 302 } |
| 299 | 303 |
| 300 default: { return false; } | 304 default: { return false; } |
| 301 } | 305 } |
| 302 | 306 |
| 303 if (keylen_bytes == 0) { | 307 if (keylen_bytes == 0) { |
| 304 return false; | 308 return false; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 const blink::WebCryptoAlgorithm& algorithm, | 534 const blink::WebCryptoAlgorithm& algorithm, |
| 531 bool extractable, | 535 bool extractable, |
| 532 blink::WebCryptoKeyUsageMask usage_mask, | 536 blink::WebCryptoKeyUsageMask usage_mask, |
| 533 blink::WebCryptoKey* key) { | 537 blink::WebCryptoKey* key) { |
| 534 // TODO(padolph): Placeholder for OpenSSL implementation. | 538 // TODO(padolph): Placeholder for OpenSSL implementation. |
| 535 // Issue http://crbug.com/267888. | 539 // Issue http://crbug.com/267888. |
| 536 return false; | 540 return false; |
| 537 } | 541 } |
| 538 | 542 |
| 539 } // namespace content | 543 } // namespace content |
| OLD | NEW |