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

Unified Diff: crypto/signature_verifier_unittest.cc

Issue 851503003: Update from https://crrev.com/311076 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crypto/mock_apple_keychain.h ('k') | gin/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/signature_verifier_unittest.cc
diff --git a/crypto/signature_verifier_unittest.cc b/crypto/signature_verifier_unittest.cc
index b521bd7bcd295f6b0d8b3f7ef4dc3ecdc81866f9..a661ff7f8ab8ce990cd4ffc5ffe51a84d738e261 100644
--- a/crypto/signature_verifier_unittest.cc
+++ b/crypto/signature_verifier_unittest.cc
@@ -1000,6 +1000,23 @@ static bool DecodeTestInput(const char* in, std::vector<uint8>* out) {
return true;
}
+// PrependASN1Length prepends an ASN.1 serialized length to the beginning of
+// |out|.
+static void PrependASN1Length(std::vector<uint8>* out, size_t len) {
+ if (len < 128) {
+ out->insert(out->begin(), static_cast<uint8>(len));
+ } else if (len < 256) {
+ out->insert(out->begin(), static_cast<uint8>(len));
+ out->insert(out->begin(), 0x81);
+ } else if (len < 0x10000) {
+ out->insert(out->begin(), static_cast<uint8>(len));
+ out->insert(out->begin(), static_cast<uint8>(len >> 8));
+ out->insert(out->begin(), 0x82);
+ } else {
+ CHECK(false) << "ASN.1 length not handled: " << len;
+ }
+}
+
static bool EncodeRSAPublicKey(const std::vector<uint8>& modulus_n,
const std::vector<uint8>& public_exponent_e,
std::vector<uint8>* public_key_info) {
@@ -1027,37 +1044,28 @@ static bool EncodeRSAPublicKey(const std::vector<uint8>& modulus_n,
public_key_info->insert(public_key_info->begin(),
public_exponent_e.begin(),
public_exponent_e.end());
- uint8 exponent_size = base::checked_cast<uint8>(public_exponent_e.size());
- public_key_info->insert(public_key_info->begin(), exponent_size);
+ PrependASN1Length(public_key_info, public_exponent_e.size());
public_key_info->insert(public_key_info->begin(), kIntegerTag);
// Encode the modulus n as an INTEGER.
public_key_info->insert(public_key_info->begin(),
modulus_n.begin(), modulus_n.end());
- uint16 modulus_size = base::checked_cast<uint16>(modulus_n.size());
+ size_t modulus_size = modulus_n.size();
if (modulus_n[0] & 0x80) {
public_key_info->insert(public_key_info->begin(), 0x00);
modulus_size++;
}
- public_key_info->insert(public_key_info->begin(), modulus_size & 0xff);
- public_key_info->insert(public_key_info->begin(), (modulus_size >> 8) & 0xff);
- public_key_info->insert(public_key_info->begin(), 0x82);
+ PrependASN1Length(public_key_info, modulus_size);
public_key_info->insert(public_key_info->begin(), kIntegerTag);
// Encode the RSAPublicKey SEQUENCE.
- uint16 info_size = base::checked_cast<uint16>(public_key_info->size());
- public_key_info->insert(public_key_info->begin(), info_size & 0xff);
- public_key_info->insert(public_key_info->begin(), (info_size >> 8) & 0xff);
- public_key_info->insert(public_key_info->begin(), 0x82);
+ PrependASN1Length(public_key_info, public_key_info->size());
public_key_info->insert(public_key_info->begin(), kSequenceTag);
// Encode the BIT STRING.
// Number of unused bits.
public_key_info->insert(public_key_info->begin(), 0x00);
- info_size = base::checked_cast<uint16>(public_key_info->size());
- public_key_info->insert(public_key_info->begin(), info_size & 0xff);
- public_key_info->insert(public_key_info->begin(), (info_size >> 8) & 0xff);
- public_key_info->insert(public_key_info->begin(), 0x82);
+ PrependASN1Length(public_key_info, public_key_info->size());
public_key_info->insert(public_key_info->begin(), kBitStringTag);
// Encode the AlgorithmIdentifier.
@@ -1071,10 +1079,7 @@ static bool EncodeRSAPublicKey(const std::vector<uint8>& modulus_n,
algorithm, algorithm + sizeof(algorithm));
// Encode the outermost SEQUENCE.
- info_size = base::checked_cast<uint16>(public_key_info->size());
- public_key_info->insert(public_key_info->begin(), info_size & 0xff);
- public_key_info->insert(public_key_info->begin(), (info_size >> 8) & 0xff);
- public_key_info->insert(public_key_info->begin(), 0x82);
+ PrependASN1Length(public_key_info, public_key_info->size());
public_key_info->insert(public_key_info->begin(), kSequenceTag);
return true;
@@ -1082,6 +1087,7 @@ static bool EncodeRSAPublicKey(const std::vector<uint8>& modulus_n,
TEST(SignatureVerifierTest, VerifyRSAPSS) {
for (unsigned int i = 0; i < arraysize(pss_test); i++) {
+ SCOPED_TRACE(i);
std::vector<uint8> modulus_n;
std::vector<uint8> public_exponent_e;
ASSERT_TRUE(DecodeTestInput(pss_test[i].modulus_n, &modulus_n));
@@ -1092,6 +1098,7 @@ TEST(SignatureVerifierTest, VerifyRSAPSS) {
&public_key_info));
for (unsigned int j = 0; j < arraysize(pss_test[i].example); j++) {
+ SCOPED_TRACE(j);
std::vector<uint8> message;
std::vector<uint8> salt;
std::vector<uint8> signature;
« no previous file with comments | « crypto/mock_apple_keychain.h ('k') | gin/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698