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

Side by Side Diff: content/child/webcrypto/openssl/rsa_key_openssl.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 "content/child/webcrypto/openssl/rsa_key_openssl.h" 5 #include "content/child/webcrypto/openssl/rsa_key_openssl.h"
6 6
7 #include <openssl/evp.h> 7 #include <openssl/evp.h>
8 #include <openssl/pkcs12.h> 8 #include <openssl/pkcs12.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 return CreateWebCryptoPublicKey(pkey.Pass(), 221 return CreateWebCryptoPublicKey(pkey.Pass(),
222 algorithm.id(), 222 algorithm.id(),
223 algorithm.rsaHashedImportParams()->hash(), 223 algorithm.rsaHashedImportParams()->hash(),
224 extractable, 224 extractable,
225 usage_mask, 225 usage_mask,
226 key); 226 key);
227 } 227 }
228 228
229 } // namespace 229 } // namespace
230 230
231 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeGenerateKeyPair( 231 Status RsaHashedAlgorithm::GenerateKey(
232 const blink::WebCryptoAlgorithm& algorithm,
233 bool extractable,
232 blink::WebCryptoKeyUsageMask combined_usage_mask, 234 blink::WebCryptoKeyUsageMask combined_usage_mask,
233 blink::WebCryptoKeyUsageMask* public_usage_mask, 235 blink::WebCryptoKey* public_key,
234 blink::WebCryptoKeyUsageMask* private_usage_mask) const { 236 blink::WebCryptoKey* private_key) const {
235 Status status = CheckKeyCreationUsages( 237 Status status = CheckKeyCreationUsages(
236 all_public_key_usages_ | all_private_key_usages_, combined_usage_mask); 238 all_public_key_usages_ | all_private_key_usages_, combined_usage_mask);
237 if (status.IsError()) 239 if (status.IsError())
238 return status; 240 return status;
239 241
240 *public_usage_mask = combined_usage_mask & all_public_key_usages_; 242 const blink::WebCryptoKeyUsageMask public_usage_mask =
241 *private_usage_mask = combined_usage_mask & all_private_key_usages_; 243 combined_usage_mask & all_public_key_usages_;
244 const blink::WebCryptoKeyUsageMask private_usage_mask =
245 combined_usage_mask & all_private_key_usages_;
242 246
243 return Status::Success();
244 }
245
246 Status RsaHashedAlgorithm::GenerateKeyPair(
247 const blink::WebCryptoAlgorithm& algorithm,
248 bool extractable,
249 blink::WebCryptoKeyUsageMask public_usage_mask,
250 blink::WebCryptoKeyUsageMask private_usage_mask,
251 blink::WebCryptoKey* public_key,
252 blink::WebCryptoKey* private_key) const {
253 const blink::WebCryptoRsaHashedKeyGenParams* params = 247 const blink::WebCryptoRsaHashedKeyGenParams* params =
254 algorithm.rsaHashedKeyGenParams(); 248 algorithm.rsaHashedKeyGenParams();
255 249
256 unsigned int public_exponent = 0; 250 unsigned int public_exponent = 0;
257 unsigned int modulus_length_bits = 0; 251 unsigned int modulus_length_bits = 0;
258 Status status = 252 status =
259 GetRsaKeyGenParameters(params, &public_exponent, &modulus_length_bits); 253 GetRsaKeyGenParameters(params, &public_exponent, &modulus_length_bits);
260 if (status.IsError()) 254 if (status.IsError())
261 return status; 255 return status;
262 256
263 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); 257 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
264 258
265 // Generate an RSA key pair. 259 // Generate an RSA key pair.
266 crypto::ScopedRSA rsa_private_key(RSA_new()); 260 crypto::ScopedRSA rsa_private_key(RSA_new());
267 crypto::ScopedBIGNUM bn(BN_new()); 261 crypto::ScopedBIGNUM bn(BN_new());
268 if (!rsa_private_key.get() || !bn.get() || 262 if (!rsa_private_key.get() || !bn.get() ||
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 return Status::Success(); 493 return Status::Success();
500 494
501 default: 495 default:
502 return Status::ErrorUnexpected(); 496 return Status::ErrorUnexpected();
503 } 497 }
504 } 498 }
505 499
506 } // namespace webcrypto 500 } // namespace webcrypto
507 501
508 } // namespace content 502 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698