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/crypto_data.h" | 5 #include "content/child/webcrypto/crypto_data.h" |
6 #include "content/child/webcrypto/nss/aes_key_nss.h" | 6 #include "content/child/webcrypto/nss/aes_key_nss.h" |
7 #include "content/child/webcrypto/nss/key_nss.h" | 7 #include "content/child/webcrypto/nss/key_nss.h" |
8 #include "content/child/webcrypto/nss/util_nss.h" | 8 #include "content/child/webcrypto/nss/util_nss.h" |
9 #include "content/child/webcrypto/status.h" | 9 #include "content/child/webcrypto/status.h" |
10 #include "content/child/webcrypto/webcrypto_util.h" | 10 #include "content/child/webcrypto/webcrypto_util.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 "NSS version doesn't support AES-GCM. Try using version 3.15 or later"); | 49 "NSS version doesn't support AES-GCM. Try using version 3.15 or later"); |
50 } | 50 } |
51 | 51 |
52 // Helper to either encrypt or decrypt for AES-GCM. The result of encryption is | 52 // Helper to either encrypt or decrypt for AES-GCM. The result of encryption is |
53 // the concatenation of the ciphertext and the authentication tag. Similarly, | 53 // the concatenation of the ciphertext and the authentication tag. Similarly, |
54 // this is the expectation for the input to decryption. | 54 // this is the expectation for the input to decryption. |
55 Status AesGcmEncryptDecrypt(EncryptOrDecrypt mode, | 55 Status AesGcmEncryptDecrypt(EncryptOrDecrypt mode, |
56 const blink::WebCryptoAlgorithm& algorithm, | 56 const blink::WebCryptoAlgorithm& algorithm, |
57 const blink::WebCryptoKey& key, | 57 const blink::WebCryptoKey& key, |
58 const CryptoData& data, | 58 const CryptoData& data, |
59 std::vector<uint8>* buffer) { | 59 std::vector<uint8_t>* buffer) { |
60 Status status = NssSupportsAesGcm(); | 60 Status status = NssSupportsAesGcm(); |
61 if (status.IsError()) | 61 if (status.IsError()) |
62 return status; | 62 return status; |
63 | 63 |
64 PK11SymKey* sym_key = SymKeyNss::Cast(key)->key(); | 64 PK11SymKey* sym_key = SymKeyNss::Cast(key)->key(); |
65 const blink::WebCryptoAesGcmParams* params = algorithm.aesGcmParams(); | 65 const blink::WebCryptoAesGcmParams* params = algorithm.aesGcmParams(); |
66 if (!params) | 66 if (!params) |
67 return Status::ErrorUnexpected(); | 67 return Status::ErrorUnexpected(); |
68 | 68 |
69 unsigned int tag_length_bits; | 69 unsigned int tag_length_bits; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // Prevent generating AES-GCM keys if it is unavailable. | 158 // Prevent generating AES-GCM keys if it is unavailable. |
159 Status status = NssSupportsAesGcm(); | 159 Status status = NssSupportsAesGcm(); |
160 if (status.IsError()) | 160 if (status.IsError()) |
161 return status; | 161 return status; |
162 return AesAlgorithm::VerifyKeyUsagesBeforeGenerateKey(usage_mask); | 162 return AesAlgorithm::VerifyKeyUsagesBeforeGenerateKey(usage_mask); |
163 } | 163 } |
164 | 164 |
165 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, | 165 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, |
166 const blink::WebCryptoKey& key, | 166 const blink::WebCryptoKey& key, |
167 const CryptoData& data, | 167 const CryptoData& data, |
168 std::vector<uint8>* buffer) const OVERRIDE { | 168 std::vector<uint8_t>* buffer) const OVERRIDE { |
169 return AesGcmEncryptDecrypt(ENCRYPT, algorithm, key, data, buffer); | 169 return AesGcmEncryptDecrypt(ENCRYPT, algorithm, key, data, buffer); |
170 } | 170 } |
171 | 171 |
172 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, | 172 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, |
173 const blink::WebCryptoKey& key, | 173 const blink::WebCryptoKey& key, |
174 const CryptoData& data, | 174 const CryptoData& data, |
175 std::vector<uint8>* buffer) const OVERRIDE { | 175 std::vector<uint8_t>* buffer) const OVERRIDE { |
176 return AesGcmEncryptDecrypt(DECRYPT, algorithm, key, data, buffer); | 176 return AesGcmEncryptDecrypt(DECRYPT, algorithm, key, data, buffer); |
177 } | 177 } |
178 }; | 178 }; |
179 | 179 |
180 } // namespace | 180 } // namespace |
181 | 181 |
182 AlgorithmImplementation* CreatePlatformAesGcmImplementation() { | 182 AlgorithmImplementation* CreatePlatformAesGcmImplementation() { |
183 return new AesGcmImplementation; | 183 return new AesGcmImplementation; |
184 } | 184 } |
185 | 185 |
186 } // namespace webcrypto | 186 } // namespace webcrypto |
187 | 187 |
188 } // namespace content | 188 } // namespace content |
OLD | NEW |