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

Side by Side Diff: content/child/webcrypto/webcrypto_util.cc

Issue 512023002: Refactor the interface for generating keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a new return type "GenerateKeyPairResult" to encapsulate secretkey vs keypair 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 "content/child/webcrypto/webcrypto_util.h" 5 #include "content/child/webcrypto/webcrypto_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "content/child/webcrypto/status.h" 9 #include "content/child/webcrypto/status.h"
10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" 10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 bool KeyUsageAllows(const blink::WebCryptoKey& key, 134 bool KeyUsageAllows(const blink::WebCryptoKey& key,
135 const blink::WebCryptoKeyUsage usage) { 135 const blink::WebCryptoKeyUsage usage) {
136 return ((key.usages() & usage) != 0); 136 return ((key.usages() & usage) != 0);
137 } 137 }
138 138
139 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) { 139 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) {
140 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep || 140 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep ||
141 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5; 141 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5;
142 } 142 }
143 143
144 bool IsAlgorithmAsymmetric(blink::WebCryptoAlgorithmId alg_id) {
145 // TODO(padolph): include all other asymmetric algorithms once they are
146 // defined, e.g. EC and DH.
147 return IsAlgorithmRsa(alg_id);
148 }
149
150 // The WebCrypto spec defines the default value for the tag length, as well as 144 // The WebCrypto spec defines the default value for the tag length, as well as
151 // the allowed values for tag length. 145 // the allowed values for tag length.
152 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params, 146 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params,
153 unsigned int* tag_length_bits) { 147 unsigned int* tag_length_bits) {
154 *tag_length_bits = 128; 148 *tag_length_bits = 128;
155 if (params->hasTagLengthBits()) 149 if (params->hasTagLengthBits())
156 *tag_length_bits = params->optionalTagLengthBits(); 150 *tag_length_bits = params->optionalTagLengthBits();
157 151
158 if (*tag_length_bits != 32 && *tag_length_bits != 64 && 152 if (*tag_length_bits != 32 && *tag_length_bits != 64 &&
159 *tag_length_bits != 96 && *tag_length_bits != 104 && 153 *tag_length_bits != 96 && *tag_length_bits != 104 &&
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // avoid feeding OpenSSL data that will hang use a whitelist. 243 // avoid feeding OpenSSL data that will hang use a whitelist.
250 if (*public_exponent != 3 && *public_exponent != 65537) 244 if (*public_exponent != 3 && *public_exponent != 65537)
251 return Status::ErrorGenerateKeyPublicExponent(); 245 return Status::ErrorGenerateKeyPublicExponent();
252 246
253 return Status::Success(); 247 return Status::Success();
254 } 248 }
255 249
256 } // namespace webcrypto 250 } // namespace webcrypto
257 251
258 } // namespace content 252 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698