| 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 12 matching lines...) Expand all Loading... |
| 23 } | 23 } |
| 24 | 24 |
| 25 AesAlgorithm::AesAlgorithm(const std::string& jwk_suffix) | 25 AesAlgorithm::AesAlgorithm(const std::string& jwk_suffix) |
| 26 : all_key_usages_(blink::WebCryptoKeyUsageEncrypt | | 26 : all_key_usages_(blink::WebCryptoKeyUsageEncrypt | |
| 27 blink::WebCryptoKeyUsageDecrypt | | 27 blink::WebCryptoKeyUsageDecrypt | |
| 28 blink::WebCryptoKeyUsageWrapKey | | 28 blink::WebCryptoKeyUsageWrapKey | |
| 29 blink::WebCryptoKeyUsageUnwrapKey), | 29 blink::WebCryptoKeyUsageUnwrapKey), |
| 30 jwk_suffix_(jwk_suffix) { | 30 jwk_suffix_(jwk_suffix) { |
| 31 } | 31 } |
| 32 | 32 |
| 33 Status AesAlgorithm::VerifyKeyUsagesBeforeGenerateKey( | 33 Status AesAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm, |
| 34 blink::WebCryptoKeyUsageMask usage_mask) const { | 34 bool extractable, |
| 35 return CheckKeyCreationUsages(all_key_usages_, usage_mask); | 35 blink::WebCryptoKeyUsageMask usage_mask, |
| 36 } | 36 blink::WebCryptoKey*, |
| 37 | 37 blink::WebCryptoKey* key) const { |
| 38 Status AesAlgorithm::GenerateSecretKey( | 38 Status status = CheckKeyCreationUsages(all_key_usages_, usage_mask); |
| 39 const blink::WebCryptoAlgorithm& algorithm, | |
| 40 bool extractable, | |
| 41 blink::WebCryptoKeyUsageMask usage_mask, | |
| 42 blink::WebCryptoKey* key) const { | |
| 43 unsigned int keylen_bits; | |
| 44 Status status = | |
| 45 GetAesKeyGenLengthInBits(algorithm.aesKeyGenParams(), &keylen_bits); | |
| 46 if (status.IsError()) | 39 if (status.IsError()) |
| 47 return status; | 40 return status; |
| 48 | 41 |
| 42 unsigned int keylen_bits; |
| 43 status = GetAesKeyGenLengthInBits(algorithm.aesKeyGenParams(), &keylen_bits); |
| 44 if (status.IsError()) |
| 45 return status; |
| 46 |
| 49 return GenerateSecretKeyOpenSsl( | 47 return GenerateSecretKeyOpenSsl( |
| 50 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits), | 48 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits), |
| 51 extractable, | 49 extractable, |
| 52 usage_mask, | 50 usage_mask, |
| 53 keylen_bits / 8, | 51 keylen_bits / 8, |
| 54 key); | 52 key); |
| 55 } | 53 } |
| 56 | 54 |
| 57 Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey( | 55 Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey( |
| 58 blink::WebCryptoKeyFormat format, | 56 blink::WebCryptoKeyFormat format, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 key.extractable(), | 116 key.extractable(), |
| 119 key.usages(), | 117 key.usages(), |
| 120 buffer); | 118 buffer); |
| 121 | 119 |
| 122 return Status::Success(); | 120 return Status::Success(); |
| 123 } | 121 } |
| 124 | 122 |
| 125 } // namespace webcrypto | 123 } // namespace webcrypto |
| 126 | 124 |
| 127 } // namespace content | 125 } // namespace content |
| OLD | NEW |