| OLD | NEW |
| 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 "content/child/webcrypto/openssl/aes_key_openssl.h" | 5 #include "content/child/webcrypto/openssl/aes_key_openssl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/child/webcrypto/crypto_data.h" | 8 #include "content/child/webcrypto/crypto_data.h" |
| 9 #include "content/child/webcrypto/jwk.h" | 9 #include "content/child/webcrypto/jwk.h" |
| 10 #include "content/child/webcrypto/openssl/key_openssl.h" | 10 #include "content/child/webcrypto/openssl/key_openssl.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 default: | 58 default: |
| 59 return Status::ErrorUnsupportedImportKeyFormat(); | 59 return Status::ErrorUnsupportedImportKeyFormat(); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 Status AesAlgorithm::ImportKeyRaw(const CryptoData& key_data, | 63 Status AesAlgorithm::ImportKeyRaw(const CryptoData& key_data, |
| 64 const blink::WebCryptoAlgorithm& algorithm, | 64 const blink::WebCryptoAlgorithm& algorithm, |
| 65 bool extractable, | 65 bool extractable, |
| 66 blink::WebCryptoKeyUsageMask usages, | 66 blink::WebCryptoKeyUsageMask usages, |
| 67 blink::WebCryptoKey* key) const { | 67 blink::WebCryptoKey* key) const { |
| 68 if (usages == 0) |
| 69 return Status::ErrorImportKeyEmptyUsages(); |
| 70 |
| 68 const unsigned int keylen_bytes = key_data.byte_length(); | 71 const unsigned int keylen_bytes = key_data.byte_length(); |
| 69 Status status = VerifyAesKeyLengthForImport(keylen_bytes); | 72 Status status = VerifyAesKeyLengthForImport(keylen_bytes); |
| 70 if (status.IsError()) | 73 if (status.IsError()) |
| 71 return status; | 74 return status; |
| 72 | 75 |
| 73 // No possibility of overflow. | 76 // No possibility of overflow. |
| 74 unsigned int keylen_bits = keylen_bytes * 8; | 77 unsigned int keylen_bits = keylen_bytes * 8; |
| 75 | 78 |
| 76 return ImportKeyRawOpenSsl(key_data, blink::WebCryptoKeyAlgorithm::createAes( | 79 return ImportKeyRawOpenSsl(key_data, blink::WebCryptoKeyAlgorithm::createAes( |
| 77 algorithm.id(), keylen_bits), | 80 algorithm.id(), keylen_bits), |
| 78 extractable, usages, key); | 81 extractable, usages, key); |
| 79 } | 82 } |
| 80 | 83 |
| 81 Status AesAlgorithm::ImportKeyJwk(const CryptoData& key_data, | 84 Status AesAlgorithm::ImportKeyJwk(const CryptoData& key_data, |
| 82 const blink::WebCryptoAlgorithm& algorithm, | 85 const blink::WebCryptoAlgorithm& algorithm, |
| 83 bool extractable, | 86 bool extractable, |
| 84 blink::WebCryptoKeyUsageMask usages, | 87 blink::WebCryptoKeyUsageMask usages, |
| 85 blink::WebCryptoKey* key) const { | 88 blink::WebCryptoKey* key) const { |
| 89 if (usages == 0) |
| 90 return Status::ErrorImportKeyEmptyUsages(); |
| 91 |
| 86 std::vector<uint8_t> raw_data; | 92 std::vector<uint8_t> raw_data; |
| 87 Status status = ReadAesSecretKeyJwk(key_data, jwk_suffix_, extractable, | 93 Status status = ReadAesSecretKeyJwk(key_data, jwk_suffix_, extractable, |
| 88 usages, &raw_data); | 94 usages, &raw_data); |
| 89 if (status.IsError()) | 95 if (status.IsError()) |
| 90 return status; | 96 return status; |
| 91 | 97 |
| 92 return ImportKeyRaw(CryptoData(raw_data), algorithm, extractable, usages, | 98 return ImportKeyRaw(CryptoData(raw_data), algorithm, extractable, usages, |
| 93 key); | 99 key); |
| 94 } | 100 } |
| 95 | 101 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 125 blink::WebCryptoKeyUsageMask usages, | 131 blink::WebCryptoKeyUsageMask usages, |
| 126 const CryptoData& key_data, | 132 const CryptoData& key_data, |
| 127 blink::WebCryptoKey* key) const { | 133 blink::WebCryptoKey* key) const { |
| 128 return ImportKeyRaw(key_data, CreateAlgorithm(algorithm.id()), extractable, | 134 return ImportKeyRaw(key_data, CreateAlgorithm(algorithm.id()), extractable, |
| 129 usages, key); | 135 usages, key); |
| 130 } | 136 } |
| 131 | 137 |
| 132 } // namespace webcrypto | 138 } // namespace webcrypto |
| 133 | 139 |
| 134 } // namespace content | 140 } // namespace content |
| OLD | NEW |