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

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: 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
« no previous file with comments | « content/child/webcrypto/webcrypto_util.h ('k') | content/content_child.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 bool KeyUsageAllows(const blink::WebCryptoKey& key, 133 bool KeyUsageAllows(const blink::WebCryptoKey& key,
134 const blink::WebCryptoKeyUsage usage) { 134 const blink::WebCryptoKeyUsage usage) {
135 return ((key.usages() & usage) != 0); 135 return ((key.usages() & usage) != 0);
136 } 136 }
137 137
138 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) { 138 bool IsAlgorithmRsa(blink::WebCryptoAlgorithmId alg_id) {
139 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep || 139 return alg_id == blink::WebCryptoAlgorithmIdRsaOaep ||
140 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5; 140 alg_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5;
141 } 141 }
142 142
143 bool IsAlgorithmAsymmetric(blink::WebCryptoAlgorithmId alg_id) {
144 // TODO(padolph): include all other asymmetric algorithms once they are
145 // defined, e.g. EC and DH.
146 return IsAlgorithmRsa(alg_id);
147 }
148
149 // The WebCrypto spec defines the default value for the tag length, as well as 143 // The WebCrypto spec defines the default value for the tag length, as well as
150 // the allowed values for tag length. 144 // the allowed values for tag length.
151 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params, 145 Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params,
152 unsigned int* tag_length_bits) { 146 unsigned int* tag_length_bits) {
153 *tag_length_bits = 128; 147 *tag_length_bits = 128;
154 if (params->hasTagLengthBits()) 148 if (params->hasTagLengthBits())
155 *tag_length_bits = params->optionalTagLengthBits(); 149 *tag_length_bits = params->optionalTagLengthBits();
156 150
157 if (*tag_length_bits != 32 && *tag_length_bits != 64 && 151 if (*tag_length_bits != 32 && *tag_length_bits != 64 &&
158 *tag_length_bits != 96 && *tag_length_bits != 104 && 152 *tag_length_bits != 96 && *tag_length_bits != 104 &&
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // avoid feeding OpenSSL data that will hang use a whitelist. 242 // avoid feeding OpenSSL data that will hang use a whitelist.
249 if (*public_exponent != 3 && *public_exponent != 65537) 243 if (*public_exponent != 3 && *public_exponent != 65537)
250 return Status::ErrorGenerateKeyPublicExponent(); 244 return Status::ErrorGenerateKeyPublicExponent();
251 245
252 return Status::Success(); 246 return Status::Success();
253 } 247 }
254 248
255 } // namespace webcrypto 249 } // namespace webcrypto
256 250
257 } // namespace content 251 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/webcrypto_util.h ('k') | content/content_child.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698