Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: content/child/webcrypto/nss/aes_gcm_nss.cc

Issue 512023002: Refactor the interface for generating keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run git-cl format Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/numerics/safe_math.h" 5 #include "base/numerics/safe_math.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "content/child/webcrypto/crypto_data.h" 7 #include "content/child/webcrypto/crypto_data.h"
8 #include "content/child/webcrypto/nss/aes_key_nss.h" 8 #include "content/child/webcrypto/nss/aes_key_nss.h"
9 #include "content/child/webcrypto/nss/key_nss.h" 9 #include "content/child/webcrypto/nss/key_nss.h"
10 #include "content/child/webcrypto/nss/util_nss.h" 10 #include "content/child/webcrypto/nss/util_nss.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 virtual Status VerifyKeyUsagesBeforeImportKey( 146 virtual Status VerifyKeyUsagesBeforeImportKey(
147 blink::WebCryptoKeyFormat format, 147 blink::WebCryptoKeyFormat format,
148 blink::WebCryptoKeyUsageMask usage_mask) const override { 148 blink::WebCryptoKeyUsageMask usage_mask) const override {
149 // Prevent importing AES-GCM keys if it is unavailable. 149 // Prevent importing AES-GCM keys if it is unavailable.
150 Status status = NssSupportsAesGcm(); 150 Status status = NssSupportsAesGcm();
151 if (status.IsError()) 151 if (status.IsError())
152 return status; 152 return status;
153 return AesAlgorithm::VerifyKeyUsagesBeforeImportKey(format, usage_mask); 153 return AesAlgorithm::VerifyKeyUsagesBeforeImportKey(format, usage_mask);
154 } 154 }
155 155
156 virtual Status VerifyKeyUsagesBeforeGenerateKey( 156 virtual Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
157 blink::WebCryptoKeyUsageMask usage_mask) const override { 157 bool extractable,
158 blink::WebCryptoKeyUsageMask usage_mask,
159 GenerateKeyResult* result) const override {
158 // Prevent generating AES-GCM keys if it is unavailable. 160 // Prevent generating AES-GCM keys if it is unavailable.
159 Status status = NssSupportsAesGcm(); 161 Status status = NssSupportsAesGcm();
160 if (status.IsError()) 162 if (status.IsError())
161 return status; 163 return status;
162 return AesAlgorithm::VerifyKeyUsagesBeforeGenerateKey(usage_mask); 164
165 return AesAlgorithm::GenerateKey(
166 algorithm, extractable, usage_mask, result);
163 } 167 }
164 168
165 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, 169 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm,
166 const blink::WebCryptoKey& key, 170 const blink::WebCryptoKey& key,
167 const CryptoData& data, 171 const CryptoData& data,
168 std::vector<uint8_t>* buffer) const override { 172 std::vector<uint8_t>* buffer) const override {
169 return AesGcmEncryptDecrypt(ENCRYPT, algorithm, key, data, buffer); 173 return AesGcmEncryptDecrypt(ENCRYPT, algorithm, key, data, buffer);
170 } 174 }
171 175
172 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, 176 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm,
173 const blink::WebCryptoKey& key, 177 const blink::WebCryptoKey& key,
174 const CryptoData& data, 178 const CryptoData& data,
175 std::vector<uint8_t>* buffer) const override { 179 std::vector<uint8_t>* buffer) const override {
176 return AesGcmEncryptDecrypt(DECRYPT, algorithm, key, data, buffer); 180 return AesGcmEncryptDecrypt(DECRYPT, algorithm, key, data, buffer);
177 } 181 }
178 }; 182 };
179 183
180 } // namespace 184 } // namespace
181 185
182 AlgorithmImplementation* CreatePlatformAesGcmImplementation() { 186 AlgorithmImplementation* CreatePlatformAesGcmImplementation() {
183 return new AesGcmImplementation; 187 return new AesGcmImplementation;
184 } 188 }
185 189
186 } // namespace webcrypto 190 } // namespace webcrypto
187 191
188 } // namespace content 192 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/generate_key_result.cc ('k') | content/child/webcrypto/nss/aes_key_nss.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698