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

Side by Side Diff: crypto/signature_verifier_unittest.cc

Issue 659943004: Type conversion fixes, crypto/ edition. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: I am dumb 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
« crypto/nss_util_unittest.cc ('K') | « crypto/nss_util_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "crypto/signature_verifier.h" 5 #include "crypto/signature_verifier.h"
6
7 #include "base/numerics/safe_conversions.h"
6 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
7 9
8 TEST(SignatureVerifierTest, BasicTest) { 10 TEST(SignatureVerifierTest, BasicTest) {
9 // The input data in this test comes from real certificates. 11 // The input data in this test comes from real certificates.
10 // 12 //
11 // tbs_certificate ("to-be-signed certificate", the part of a certificate 13 // tbs_certificate ("to-be-signed certificate", the part of a certificate
12 // that is signed), signature_algorithm, and algorithm come from the 14 // that is signed), signature_algorithm, and algorithm come from the
13 // certificate of bugs.webkit.org. 15 // certificate of bugs.webkit.org.
14 // 16 //
15 // public_key_info comes from the certificate of the issuer, Go Daddy Secure 17 // public_key_info comes from the certificate of the issuer, Go Daddy Secure
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 // } 1000 // }
999 static const uint8 kIntegerTag = 0x02; 1001 static const uint8 kIntegerTag = 0x02;
1000 static const uint8 kBitStringTag = 0x03; 1002 static const uint8 kBitStringTag = 0x03;
1001 static const uint8 kSequenceTag = 0x30; 1003 static const uint8 kSequenceTag = 0x30;
1002 public_key_info->clear(); 1004 public_key_info->clear();
1003 1005
1004 // Encode the public exponent e as an INTEGER. 1006 // Encode the public exponent e as an INTEGER.
1005 public_key_info->insert(public_key_info->begin(), 1007 public_key_info->insert(public_key_info->begin(),
1006 public_exponent_e.begin(), 1008 public_exponent_e.begin(),
1007 public_exponent_e.end()); 1009 public_exponent_e.end());
1008 uint8 length = public_exponent_e.size(); 1010 uint8 exponent_size = base::checked_cast<uint8>(public_exponent_e.size());
1009 public_key_info->insert(public_key_info->begin(), length); 1011 public_key_info->insert(public_key_info->begin(), exponent_size);
1010 public_key_info->insert(public_key_info->begin(), kIntegerTag); 1012 public_key_info->insert(public_key_info->begin(), kIntegerTag);
1011 1013
1012 // Encode the modulus n as an INTEGER. 1014 // Encode the modulus n as an INTEGER.
1013 public_key_info->insert(public_key_info->begin(), 1015 public_key_info->insert(public_key_info->begin(),
1014 modulus_n.begin(), modulus_n.end()); 1016 modulus_n.begin(), modulus_n.end());
1015 uint16 length16 = modulus_n.size(); 1017 uint16 modulus_size = base::checked_cast<uint16>(modulus_n.size());
1016 if (modulus_n[0] & 0x80) { 1018 if (modulus_n[0] & 0x80) {
1017 public_key_info->insert(public_key_info->begin(), 0x00); 1019 public_key_info->insert(public_key_info->begin(), 0x00);
1018 length16++; 1020 modulus_size++;
1019 } 1021 }
1020 public_key_info->insert(public_key_info->begin(), length16 & 0xff); 1022 public_key_info->insert(public_key_info->begin(), modulus_size & 0xff);
1021 public_key_info->insert(public_key_info->begin(), (length16 >> 8) & 0xff); 1023 public_key_info->insert(public_key_info->begin(), (modulus_size >> 8) & 0xff);
1022 public_key_info->insert(public_key_info->begin(), 0x82); 1024 public_key_info->insert(public_key_info->begin(), 0x82);
1023 public_key_info->insert(public_key_info->begin(), kIntegerTag); 1025 public_key_info->insert(public_key_info->begin(), kIntegerTag);
1024 1026
1025 // Encode the RSAPublicKey SEQUENCE. 1027 // Encode the RSAPublicKey SEQUENCE.
1026 length16 = public_key_info->size(); 1028 uint16 info_size = base::checked_cast<uint16>(public_key_info->size());
1027 public_key_info->insert(public_key_info->begin(), length16 & 0xff); 1029 public_key_info->insert(public_key_info->begin(), info_size & 0xff);
1028 public_key_info->insert(public_key_info->begin(), (length16 >> 8) & 0xff); 1030 public_key_info->insert(public_key_info->begin(), (info_size >> 8) & 0xff);
1029 public_key_info->insert(public_key_info->begin(), 0x82); 1031 public_key_info->insert(public_key_info->begin(), 0x82);
1030 public_key_info->insert(public_key_info->begin(), kSequenceTag); 1032 public_key_info->insert(public_key_info->begin(), kSequenceTag);
1031 1033
1032 // Encode the BIT STRING. 1034 // Encode the BIT STRING.
1033 // Number of unused bits. 1035 // Number of unused bits.
1034 public_key_info->insert(public_key_info->begin(), 0x00); 1036 public_key_info->insert(public_key_info->begin(), 0x00);
1035 length16 = public_key_info->size(); 1037 info_size = base::checked_cast<uint16>(public_key_info->size());
1036 public_key_info->insert(public_key_info->begin(), length16 & 0xff); 1038 public_key_info->insert(public_key_info->begin(), info_size & 0xff);
1037 public_key_info->insert(public_key_info->begin(), (length16 >> 8) & 0xff); 1039 public_key_info->insert(public_key_info->begin(), (info_size >> 8) & 0xff);
1038 public_key_info->insert(public_key_info->begin(), 0x82); 1040 public_key_info->insert(public_key_info->begin(), 0x82);
1039 public_key_info->insert(public_key_info->begin(), kBitStringTag); 1041 public_key_info->insert(public_key_info->begin(), kBitStringTag);
1040 1042
1041 // Encode the AlgorithmIdentifier. 1043 // Encode the AlgorithmIdentifier.
1042 static const uint8 algorithm[] = { 1044 static const uint8 algorithm[] = {
1043 0x30, 0x0d, // a SEQUENCE of length 13 1045 0x30, 0x0d, // a SEQUENCE of length 13
1044 0x06, 0x09, // an OBJECT IDENTIFIER of length 9 1046 0x06, 0x09, // an OBJECT IDENTIFIER of length 9
1045 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 1047 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
1046 0x05, 0x00, 1048 0x05, 0x00,
1047 }; 1049 };
1048 public_key_info->insert(public_key_info->begin(), 1050 public_key_info->insert(public_key_info->begin(),
1049 algorithm, algorithm + sizeof(algorithm)); 1051 algorithm, algorithm + sizeof(algorithm));
1050 1052
1051 // Encode the outermost SEQUENCE. 1053 // Encode the outermost SEQUENCE.
1052 length16 = public_key_info->size(); 1054 info_size = base::checked_cast<uint16>(public_key_info->size());
1053 public_key_info->insert(public_key_info->begin(), length16 & 0xff); 1055 public_key_info->insert(public_key_info->begin(), info_size & 0xff);
1054 public_key_info->insert(public_key_info->begin(), (length16 >> 8) & 0xff); 1056 public_key_info->insert(public_key_info->begin(), (info_size >> 8) & 0xff);
1055 public_key_info->insert(public_key_info->begin(), 0x82); 1057 public_key_info->insert(public_key_info->begin(), 0x82);
1056 public_key_info->insert(public_key_info->begin(), kSequenceTag); 1058 public_key_info->insert(public_key_info->begin(), kSequenceTag);
1057 1059
1058 return true; 1060 return true;
1059 } 1061 }
1060 1062
1061 TEST(SignatureVerifierTest, VerifyRSAPSS) { 1063 TEST(SignatureVerifierTest, VerifyRSAPSS) {
1062 for (unsigned int i = 0; i < arraysize(pss_test); i++) { 1064 for (unsigned int i = 0; i < arraysize(pss_test); i++) {
1063 std::vector<uint8> modulus_n; 1065 std::vector<uint8> modulus_n;
1064 std::vector<uint8> public_exponent_e; 1066 std::vector<uint8> public_exponent_e;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 &public_key_info[0], 1131 &public_key_info[0],
1130 public_key_info.size()); 1132 public_key_info.size());
1131 signature[0] -= 1; 1133 signature[0] -= 1;
1132 ASSERT_TRUE(ok); 1134 ASSERT_TRUE(ok);
1133 verifier.VerifyUpdate(&message[0], message.size()); 1135 verifier.VerifyUpdate(&message[0], message.size());
1134 ok = verifier.VerifyFinal(); 1136 ok = verifier.VerifyFinal();
1135 EXPECT_FALSE(ok); 1137 EXPECT_FALSE(ok);
1136 } 1138 }
1137 } 1139 }
1138 } 1140 }
OLDNEW
« crypto/nss_util_unittest.cc ('K') | « crypto/nss_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698