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

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

Issue 405693002: [refactor] Use base::CheckedNumeric<> in place of manual checks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix testing order for openssl Created 6 years, 5 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 | Annotate | Revision Log
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/nss/rsa_key_nss.h" 5 #include "content/child/webcrypto/nss/rsa_key_nss.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/numerics/safe_math.h"
8 #include "content/child/webcrypto/crypto_data.h" 9 #include "content/child/webcrypto/crypto_data.h"
9 #include "content/child/webcrypto/jwk.h" 10 #include "content/child/webcrypto/jwk.h"
10 #include "content/child/webcrypto/nss/key_nss.h" 11 #include "content/child/webcrypto/nss/key_nss.h"
11 #include "content/child/webcrypto/nss/util_nss.h" 12 #include "content/child/webcrypto/nss/util_nss.h"
12 #include "content/child/webcrypto/status.h" 13 #include "content/child/webcrypto/status.h"
13 #include "content/child/webcrypto/webcrypto_util.h" 14 #include "content/child/webcrypto/webcrypto_util.h"
14 #include "crypto/scoped_nss_types.h" 15 #include "crypto/scoped_nss_types.h"
15 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 16 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
16 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 17 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
17 18
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 (public_exponent != 3 && public_exponent != 65537)) { 592 (public_exponent != 3 && public_exponent != 65537)) {
592 return Status::ErrorGenerateKeyPublicExponent(); 593 return Status::ErrorGenerateKeyPublicExponent();
593 } 594 }
594 595
595 crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot()); 596 crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot());
596 if (!slot) 597 if (!slot)
597 return Status::OperationError(); 598 return Status::OperationError();
598 599
599 PK11RSAGenParams rsa_gen_params; 600 PK11RSAGenParams rsa_gen_params;
600 // keySizeInBits is a signed type, don't pass in a negative value. 601 // keySizeInBits is a signed type, don't pass in a negative value.
601 if (params->modulusLengthBits() > INT_MAX) 602 base::CheckedNumeric<int> signed_modulus(params->modulusLengthBits());
603 if (!signed_modulus.IsValid())
602 return Status::OperationError(); 604 return Status::OperationError();
603 rsa_gen_params.keySizeInBits = params->modulusLengthBits(); 605 rsa_gen_params.keySizeInBits = signed_modulus.ValueOrDie();
604 rsa_gen_params.pe = public_exponent; 606 rsa_gen_params.pe = public_exponent;
605 607
606 const CK_FLAGS operation_flags_mask = 608 const CK_FLAGS operation_flags_mask =
607 CKF_ENCRYPT | CKF_DECRYPT | CKF_SIGN | CKF_VERIFY | CKF_WRAP | CKF_UNWRAP; 609 CKF_ENCRYPT | CKF_DECRYPT | CKF_SIGN | CKF_VERIFY | CKF_WRAP | CKF_UNWRAP;
608 610
609 // The private key must be marked as insensitive and extractable, otherwise it 611 // The private key must be marked as insensitive and extractable, otherwise it
610 // cannot later be exported in unencrypted form or structured-cloned. 612 // cannot later be exported in unencrypted form or structured-cloned.
611 const PK11AttrFlags attribute_flags = 613 const PK11AttrFlags attribute_flags =
612 PK11_ATTR_INSENSITIVE | PK11_ATTR_EXTRACTABLE; 614 PK11_ATTR_INSENSITIVE | PK11_ATTR_EXTRACTABLE;
613 615
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 return Status::Success(); 890 return Status::Success();
889 } 891 }
890 default: 892 default:
891 return Status::ErrorUnexpected(); 893 return Status::ErrorUnexpected();
892 } 894 }
893 } 895 }
894 896
895 } // namespace webcrypto 897 } // namespace webcrypto
896 898
897 } // namespace content 899 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698