| 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 "components/webcrypto/algorithms/aes.h" | 5 #include "components/webcrypto/algorithms/aes.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "components/webcrypto/algorithms/secret_key_util.h" | 10 #include "components/webcrypto/algorithms/secret_key_util.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 return Status::Success(); | 192 return Status::Success(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 Status AesAlgorithm::DeserializeKeyForClone( | 195 Status AesAlgorithm::DeserializeKeyForClone( |
| 196 const blink::WebCryptoKeyAlgorithm& algorithm, | 196 const blink::WebCryptoKeyAlgorithm& algorithm, |
| 197 blink::WebCryptoKeyType type, | 197 blink::WebCryptoKeyType type, |
| 198 bool extractable, | 198 bool extractable, |
| 199 blink::WebCryptoKeyUsageMask usages, | 199 blink::WebCryptoKeyUsageMask usages, |
| 200 const CryptoData& key_data, | 200 const CryptoData& key_data, |
| 201 blink::WebCryptoKey* key) const { | 201 blink::WebCryptoKey* key) const { |
| 202 if (algorithm.paramsType() != blink::WebCryptoKeyAlgorithmParamsTypeAes || |
| 203 type != blink::WebCryptoKeyTypeSecret) |
| 204 return Status::ErrorUnexpected(); |
| 205 |
| 202 return ImportKeyRaw(key_data, SynthesizeImportAlgorithmForClone(algorithm), | 206 return ImportKeyRaw(key_data, SynthesizeImportAlgorithmForClone(algorithm), |
| 203 extractable, usages, key); | 207 extractable, usages, key); |
| 204 } | 208 } |
| 205 | 209 |
| 206 Status AesAlgorithm::GetKeyLength( | 210 Status AesAlgorithm::GetKeyLength( |
| 207 const blink::WebCryptoAlgorithm& key_length_algorithm, | 211 const blink::WebCryptoAlgorithm& key_length_algorithm, |
| 208 bool* has_length_bits, | 212 bool* has_length_bits, |
| 209 unsigned int* length_bits) const { | 213 unsigned int* length_bits) const { |
| 210 *has_length_bits = true; | 214 *has_length_bits = true; |
| 211 *length_bits = key_length_algorithm.aesDerivedKeyParams()->lengthBits(); | 215 *length_bits = key_length_algorithm.aesDerivedKeyParams()->lengthBits(); |
| 212 | 216 |
| 213 if (*length_bits == 128 || *length_bits == 256) | 217 if (*length_bits == 128 || *length_bits == 256) |
| 214 return Status::Success(); | 218 return Status::Success(); |
| 215 | 219 |
| 216 // 192-bit AES is intentionally unsupported (http://crbug.com/533699). | 220 // 192-bit AES is intentionally unsupported (http://crbug.com/533699). |
| 217 if (*length_bits == 192) | 221 if (*length_bits == 192) |
| 218 return Status::ErrorAes192BitUnsupported(); | 222 return Status::ErrorAes192BitUnsupported(); |
| 219 | 223 |
| 220 return Status::ErrorGetAesKeyLength(); | 224 return Status::ErrorGetAesKeyLength(); |
| 221 } | 225 } |
| 222 | 226 |
| 223 } // namespace webcrypto | 227 } // namespace webcrypto |
| OLD | NEW |