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

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: Created 6 years, 3 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 blink::WebCryptoKey* unused_public_key,
160 blink::WebCryptoKey* key) const OVERRIDE {
158 // Prevent generating AES-GCM keys if it is unavailable. 161 // Prevent generating AES-GCM keys if it is unavailable.
159 Status status = NssSupportsAesGcm(); 162 Status status = NssSupportsAesGcm();
160 if (status.IsError()) 163 if (status.IsError())
161 return status; 164 return status;
162 return AesAlgorithm::VerifyKeyUsagesBeforeGenerateKey(usage_mask); 165
166 return AesAlgorithm::GenerateKey(
167 algorithm, extractable, usage_mask, unused_public_key, key);
163 } 168 }
164 169
165 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm, 170 virtual Status Encrypt(const blink::WebCryptoAlgorithm& algorithm,
166 const blink::WebCryptoKey& key, 171 const blink::WebCryptoKey& key,
167 const CryptoData& data, 172 const CryptoData& data,
168 std::vector<uint8_t>* buffer) const OVERRIDE { 173 std::vector<uint8_t>* buffer) const OVERRIDE {
169 return AesGcmEncryptDecrypt(ENCRYPT, algorithm, key, data, buffer); 174 return AesGcmEncryptDecrypt(ENCRYPT, algorithm, key, data, buffer);
170 } 175 }
171 176
172 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm, 177 virtual Status Decrypt(const blink::WebCryptoAlgorithm& algorithm,
173 const blink::WebCryptoKey& key, 178 const blink::WebCryptoKey& key,
174 const CryptoData& data, 179 const CryptoData& data,
175 std::vector<uint8_t>* buffer) const OVERRIDE { 180 std::vector<uint8_t>* buffer) const OVERRIDE {
176 return AesGcmEncryptDecrypt(DECRYPT, algorithm, key, data, buffer); 181 return AesGcmEncryptDecrypt(DECRYPT, algorithm, key, data, buffer);
177 } 182 }
178 }; 183 };
179 184
180 } // namespace 185 } // namespace
181 186
182 AlgorithmImplementation* CreatePlatformAesGcmImplementation() { 187 AlgorithmImplementation* CreatePlatformAesGcmImplementation() {
183 return new AesGcmImplementation; 188 return new AesGcmImplementation;
184 } 189 }
185 190
186 } // namespace webcrypto 191 } // namespace webcrypto
187 192
188 } // namespace content 193 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698