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/nss/aes_key_nss.h" | 5 #include "content/child/webcrypto/nss/aes_key_nss.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/nss/key_nss.h" | 10 #include "content/child/webcrypto/nss/key_nss.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 const std::string& jwk_suffix) | 31 const std::string& jwk_suffix) |
32 : import_mechanism_(import_mechanism), | 32 : import_mechanism_(import_mechanism), |
33 import_flags_(CKF_ENCRYPT | CKF_DECRYPT), | 33 import_flags_(CKF_ENCRYPT | CKF_DECRYPT), |
34 all_key_usages_(blink::WebCryptoKeyUsageEncrypt | | 34 all_key_usages_(blink::WebCryptoKeyUsageEncrypt | |
35 blink::WebCryptoKeyUsageDecrypt | | 35 blink::WebCryptoKeyUsageDecrypt | |
36 blink::WebCryptoKeyUsageWrapKey | | 36 blink::WebCryptoKeyUsageWrapKey | |
37 blink::WebCryptoKeyUsageUnwrapKey), | 37 blink::WebCryptoKeyUsageUnwrapKey), |
38 jwk_suffix_(jwk_suffix) { | 38 jwk_suffix_(jwk_suffix) { |
39 } | 39 } |
40 | 40 |
41 Status AesAlgorithm::VerifyKeyUsagesBeforeGenerateKey( | 41 Status AesAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm, |
42 blink::WebCryptoKeyUsageMask usage_mask) const { | 42 bool extractable, |
43 return CheckKeyCreationUsages(all_key_usages_, usage_mask); | 43 blink::WebCryptoKeyUsageMask usage_mask, |
44 } | 44 blink::WebCryptoKey*, |
45 | 45 blink::WebCryptoKey* key) const { |
46 Status AesAlgorithm::GenerateSecretKey( | 46 Status status = CheckKeyCreationUsages(all_key_usages_, usage_mask); |
47 const blink::WebCryptoAlgorithm& algorithm, | |
48 bool extractable, | |
49 blink::WebCryptoKeyUsageMask usage_mask, | |
50 blink::WebCryptoKey* key) const { | |
51 unsigned int keylen_bits; | |
52 Status status = | |
53 GetAesKeyGenLengthInBits(algorithm.aesKeyGenParams(), &keylen_bits); | |
54 if (status.IsError()) | 47 if (status.IsError()) |
55 return status; | 48 return status; |
56 | 49 |
| 50 unsigned int keylen_bits; |
| 51 status = GetAesKeyGenLengthInBits(algorithm.aesKeyGenParams(), &keylen_bits); |
| 52 if (status.IsError()) |
| 53 return status; |
| 54 |
57 return GenerateSecretKeyNss( | 55 return GenerateSecretKeyNss( |
58 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits), | 56 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits), |
59 extractable, | 57 extractable, |
60 usage_mask, | 58 usage_mask, |
61 keylen_bits / 8, | 59 keylen_bits / 8, |
62 CKM_AES_KEY_GEN, | 60 CKM_AES_KEY_GEN, |
63 key); | 61 key); |
64 } | 62 } |
65 | 63 |
66 Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey( | 64 Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 key.extractable(), | 126 key.extractable(), |
129 key.usages(), | 127 key.usages(), |
130 buffer); | 128 buffer); |
131 | 129 |
132 return Status::Success(); | 130 return Status::Success(); |
133 } | 131 } |
134 | 132 |
135 } // namespace webcrypto | 133 } // namespace webcrypto |
136 | 134 |
137 } // namespace content | 135 } // namespace content |
OLD | NEW |