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 GenerateKeyResult* result) const { |
45 | 45 Status status = CheckKeyCreationUsages(all_key_usages_, usage_mask); |
46 Status AesAlgorithm::GenerateSecretKey( | |
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()) | 46 if (status.IsError()) |
55 return status; | 47 return status; |
56 | 48 |
| 49 unsigned int keylen_bits; |
| 50 status = GetAesKeyGenLengthInBits(algorithm.aesKeyGenParams(), &keylen_bits); |
| 51 if (status.IsError()) |
| 52 return status; |
| 53 |
57 return GenerateSecretKeyNss( | 54 return GenerateSecretKeyNss( |
58 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits), | 55 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits), |
59 extractable, | 56 extractable, |
60 usage_mask, | 57 usage_mask, |
61 keylen_bits / 8, | 58 keylen_bits / 8, |
62 CKM_AES_KEY_GEN, | 59 CKM_AES_KEY_GEN, |
63 key); | 60 result); |
64 } | 61 } |
65 | 62 |
66 Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey( | 63 Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey( |
67 blink::WebCryptoKeyFormat format, | 64 blink::WebCryptoKeyFormat format, |
68 blink::WebCryptoKeyUsageMask usage_mask) const { | 65 blink::WebCryptoKeyUsageMask usage_mask) const { |
69 switch (format) { | 66 switch (format) { |
70 case blink::WebCryptoKeyFormatRaw: | 67 case blink::WebCryptoKeyFormatRaw: |
71 case blink::WebCryptoKeyFormatJwk: | 68 case blink::WebCryptoKeyFormatJwk: |
72 return CheckKeyCreationUsages(all_key_usages_, usage_mask); | 69 return CheckKeyCreationUsages(all_key_usages_, usage_mask); |
73 default: | 70 default: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 key.extractable(), | 125 key.extractable(), |
129 key.usages(), | 126 key.usages(), |
130 buffer); | 127 buffer); |
131 | 128 |
132 return Status::Success(); | 129 return Status::Success(); |
133 } | 130 } |
134 | 131 |
135 } // namespace webcrypto | 132 } // namespace webcrypto |
136 | 133 |
137 } // namespace content | 134 } // namespace content |
OLD | NEW |