diff --git a/crypto/aead.cc b/crypto/aead.cc index a0ef250d83d154adda84d03ab40eee8d6a276238..7b9bb52e3e9286d71a83a6773e60b14210e25573 100644 --- a/crypto/aead.cc +++ b/crypto/aead.cc @@ -120,4 +120,4 @@ size_t Aead::NonceLength() const { return EVP_AEAD_nonce_length(aead_); } -} // namespace +} // namespace crypto diff --git a/crypto/aead.h b/crypto/aead.h index fa96eab9eb9f1342889f3ff9524bf176bbfe8ca0..220ae42029d2e530c7062c51fd387a6be2ff72ea 100644 --- a/crypto/aead.h +++ b/crypto/aead.h @@ -7,6 +7,8 @@ #include +#include + #include "base/strings/string_piece.h" #include "crypto/crypto_export.h" @@ -46,4 +48,4 @@ class CRYPTO_EXPORT Aead { } // namespace crypto -#endif // CRYPTO_ENCRYPTOR_H_ +#endif // CRYPTO_AEAD_H_ diff --git a/crypto/apple_keychain.h b/crypto/apple_keychain.h index 1ea24735478f5230b6b8986e4b64731b99afafcb..1037b7eccdb1f5fca5dd9303d172965f8c9deb2b 100644 --- a/crypto/apple_keychain.h +++ b/crypto/apple_keychain.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CRYPTO_KEYCHAIN_MAC_H_ -#define CRYPTO_KEYCHAIN_MAC_H_ +#ifndef CRYPTO_APPLE_KEYCHAIN_H_ +#define CRYPTO_APPLE_KEYCHAIN_H_ #include @@ -106,4 +106,4 @@ class CRYPTO_EXPORT AppleKeychain { } // namespace crypto -#endif // CRYPTO_KEYCHAIN_MAC_H_ +#endif // CRYPTO_APPLE_KEYCHAIN_H_ diff --git a/crypto/ec_private_key.cc b/crypto/ec_private_key.cc index 9914c5dde866e9f2e47b9a747ab7584cefff4d19..08fd75dec3c95f74bb381c082e8000dc7f02fa28 100644 --- a/crypto/ec_private_key.cc +++ b/crypto/ec_private_key.cc @@ -46,9 +46,9 @@ bool ExportKeyWithBio(const void* key, if (!export_fn(bio.get(), key)) return false; - char* data = nullptr; - long len = BIO_get_mem_data(bio.get(), &data); - if (!data || len < 0) + const uint8_t* data; + size_t len; + if (!BIO_mem_contents(bio.get(), &data, &len)) return false; output->assign(data, data + len); diff --git a/crypto/ec_signature_creator_impl.h b/crypto/ec_signature_creator_impl.h index 21614f8201d87ce4a5adaf715037b1241787a697..bd06e253a41655a85343ca97314ff932bef23e94 100644 --- a/crypto/ec_signature_creator_impl.h +++ b/crypto/ec_signature_creator_impl.h @@ -7,6 +7,8 @@ #include +#include + #include "base/compiler_specific.h" #include "base/macros.h" #include "crypto/ec_signature_creator.h" diff --git a/crypto/encryptor.cc b/crypto/encryptor.cc index 8aece10be00f8cd418e3b9aab6b04ace77dcc6be..36df136c503f7245ad392ce3787d74ca5b8bfdac 100644 --- a/crypto/encryptor.cc +++ b/crypto/encryptor.cc @@ -32,7 +32,7 @@ const EVP_CIPHER* GetCipherForKey(SymmetricKey* key) { // ERR stack as a convenience. class ScopedCipherCTX { public: - explicit ScopedCipherCTX() { + ScopedCipherCTX() { EVP_CIPHER_CTX_init(&ctx_); } ~ScopedCipherCTX() { diff --git a/crypto/encryptor_unittest.cc b/crypto/encryptor_unittest.cc index 7166c74f6e6baf1f6e721389a49f2eaabbdad0a7..2294bdb173e0e1d1a3558ea7675a62acb503e9e1 100644 --- a/crypto/encryptor_unittest.cc +++ b/crypto/encryptor_unittest.cc @@ -325,7 +325,7 @@ TEST(EncryptorTest, CTRCounter) { counter1.Increment(); counter1.Write(buf); EXPECT_EQ(0, memcmp(buf, kTest1, 15)); - EXPECT_TRUE(buf[15] == 10); + EXPECT_EQ(10, buf[15]); // Check corner cases. const unsigned char kTest2[] = { diff --git a/crypto/hmac.cc b/crypto/hmac.cc index a9bb483f5b7f5708772d02583b8c5a89c8ee7dff..bf89e182d939c2ee45f001bbb3387518bf2d84d6 100644 --- a/crypto/hmac.cc +++ b/crypto/hmac.cc @@ -7,6 +7,7 @@ #include #include +#include #include "base/logging.h" #include "base/stl_util.h" diff --git a/crypto/mock_apple_keychain.h b/crypto/mock_apple_keychain.h index db4fcd8e043845470004de0750bc1dca86d9414f..38e69f2d9d4b5c252f83c79e11299e97c8b66913 100644 --- a/crypto/mock_apple_keychain.h +++ b/crypto/mock_apple_keychain.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CRYPTO_MOCK_KEYCHAIN_MAC_H_ -#define CRYPTO_MOCK_KEYCHAIN_MAC_H_ +#ifndef CRYPTO_MOCK_APPLE_KEYCHAIN_H_ +#define CRYPTO_MOCK_APPLE_KEYCHAIN_H_ #include #include @@ -254,4 +254,4 @@ class CRYPTO_EXPORT MockAppleKeychain : public AppleKeychain { } // namespace crypto -#endif // CRYPTO_MOCK_KEYCHAIN_MAC_H_ +#endif // CRYPTO_MOCK_APPLE_KEYCHAIN_H_ diff --git a/crypto/nss_crypto_module_delegate.h b/crypto/nss_crypto_module_delegate.h index 6c1da68161dd5a085d0c82f557a05e3b53d15415..cf08f2859ffb547696638b1508d899290652f9ba 100644 --- a/crypto/nss_crypto_module_delegate.h +++ b/crypto/nss_crypto_module_delegate.h @@ -35,7 +35,6 @@ class CryptoModuleBlockingPasswordDelegate { // user entered. virtual std::string RequestPassword(const std::string& slot_name, bool retry, bool* cancelled) = 0; - }; // Extends CryptoModuleBlockingPasswordDelegate with the ability to return a diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc index f26bf0979a6ad2181d216fb2049a3255315fc419..358656790078fa6d1f60dc41146037569b9ae2d9 100644 --- a/crypto/nss_util.cc +++ b/crypto/nss_util.cc @@ -264,13 +264,13 @@ class ChromeOSUserData { }; class ScopedChapsLoadFixup { - public: - ScopedChapsLoadFixup(); - ~ScopedChapsLoadFixup(); + public: + ScopedChapsLoadFixup(); + ~ScopedChapsLoadFixup(); - private: + private: #if defined(COMPONENT_BUILD) - void *chaps_handle_; + void* chaps_handle_; #endif }; @@ -368,14 +368,11 @@ class NSSInitSingleton { if (base::WorkerPool::PostTaskAndReply( FROM_HERE, base::Bind(&NSSInitSingleton::InitializeTPMTokenOnWorkerThread, - system_slot_id, - tpm_args_ptr), + system_slot_id, tpm_args_ptr), base::Bind(&NSSInitSingleton::OnInitializedTPMTokenAndSystemSlot, base::Unretained(this), // NSSInitSingleton is leaky - callback, - base::Passed(&tpm_args)), - true /* task_is_slow */ - )) { + callback, base::Passed(&tpm_args)), + true /* task_is_slow */)) { initializing_tpm_token_ = true; } else { base::ThreadTaskRunnerHandle::Get()->PostTask( @@ -530,15 +527,12 @@ class NSSInitSingleton { TPMModuleAndSlot* tpm_args_ptr = tpm_args.get(); base::WorkerPool::PostTaskAndReply( FROM_HERE, - base::Bind(&NSSInitSingleton::InitializeTPMTokenOnWorkerThread, - slot_id, + base::Bind(&NSSInitSingleton::InitializeTPMTokenOnWorkerThread, slot_id, tpm_args_ptr), base::Bind(&NSSInitSingleton::OnInitializedTPMForChromeOSUser, base::Unretained(this), // NSSInitSingleton is leaky - username_hash, - base::Passed(&tpm_args)), - true /* task_is_slow */ - ); + username_hash, base::Passed(&tpm_args)), + true /* task_is_slow */); } void OnInitializedTPMForChromeOSUser( diff --git a/crypto/nss_util_internal.h b/crypto/nss_util_internal.h index 697e376e5a587ceeb8f4137b8dbb2d2ea0b923e1..080ac1026de2b75f4f932197dab8baf8323825f7 100644 --- a/crypto/nss_util_internal.h +++ b/crypto/nss_util_internal.h @@ -7,6 +7,8 @@ #include +#include + #include "base/callback.h" #include "base/compiler_specific.h" #include "base/macros.h" diff --git a/crypto/openssl_util.cc b/crypto/openssl_util.cc index 4ad5c119ad9dbee6844e4471311585ea32313436..0d044c76d4f5460f7209e07a6abb98ba5a99400b 100644 --- a/crypto/openssl_util.cc +++ b/crypto/openssl_util.cc @@ -7,6 +7,8 @@ #include #include +#include + #include "base/logging.h" #include "base/strings/string_piece.h" #include "third_party/boringssl/src/include/openssl/crypto.h" diff --git a/crypto/p224_spake.cc b/crypto/p224_spake.cc index 157410537229a5b78363e1c9074789e88325ec48..7275a45bc679b10fc1b0990e226972c67046b27e 100644 --- a/crypto/p224_spake.cc +++ b/crypto/p224_spake.cc @@ -5,14 +5,14 @@ // This code implements SPAKE2, a variant of EKE: // http://www.di.ens.fr/~pointche/pub.php?reference=AbPo04 -#include +#include "crypto/p224_spake.h" #include -#include -#include -#include -#include +#include "base/logging.h" +#include "crypto/p224.h" +#include "crypto/random.h" +#include "crypto/secure_util.h" namespace { @@ -27,6 +27,9 @@ namespace { // #include // #include // +// // Silence a presubmit. +// #define PRINTF printf +// // static const char kSeed1[] = "P224 point generation seed (M)"; // static const char kSeed2[] = "P224 point generation seed (N)"; // @@ -52,7 +55,7 @@ namespace { // EC_POINT_get_affine_coordinates_GFp(p224, p, &x, &y, NULL); // char* x_str = BN_bn2hex(&x); // char* y_str = BN_bn2hex(&y); -// printf("Found after %u iterations:\n%s\n%s\n", i, x_str, y_str); +// PRINTF("Found after %u iterations:\n%s\n%s\n", i, x_str, y_str); // OPENSSL_free(x_str); // OPENSSL_free(y_str); // BN_free(&x); diff --git a/crypto/p224_spake.h b/crypto/p224_spake.h index f9a44e70e17a3a1cbbf6d63b052c7368b44a7fba..b5cc70ae9e731c61756cacbf2bd9eb4edf758883 100644 --- a/crypto/p224_spake.h +++ b/crypto/p224_spake.h @@ -5,12 +5,14 @@ #ifndef CRYPTO_P224_SPAKE_H_ #define CRYPTO_P224_SPAKE_H_ -#include -#include #include +#include + #include "base/gtest_prod_util.h" #include "base/strings/string_piece.h" +#include "crypto/p224.h" +#include "crypto/sha2.h" namespace crypto { diff --git a/crypto/p224_unittest.cc b/crypto/p224_unittest.cc index faa08ebd360df974aba8a060db52c6e14f58cbde..8cfe6e7dc0d065a8e14fba7e556712bfe44dbde3 100644 --- a/crypto/p224_unittest.cc +++ b/crypto/p224_unittest.cc @@ -778,8 +778,8 @@ TEST(P224, ExternalToInternalAndBack) { const std::string external = point.ToString(); ASSERT_EQ(external.size(), 56u); - EXPECT_TRUE(memcmp(external.data(), kBasePointExternal, - sizeof(kBasePointExternal)) == 0); + EXPECT_EQ(0, memcmp(external.data(), kBasePointExternal, + sizeof(kBasePointExternal))); } TEST(P224, ScalarBaseMult) { @@ -789,8 +789,8 @@ TEST(P224, ScalarBaseMult) { p224::ScalarBaseMult(kNISTTestVectors[i].scalar, &point); const std::string external = point.ToString(); ASSERT_EQ(external.size(), 56u); - EXPECT_TRUE(memcmp(external.data(), kNISTTestVectors[i].affine, - external.size()) == 0); + EXPECT_EQ(0, memcmp(external.data(), kNISTTestVectors[i].affine, + external.size())); } } @@ -804,9 +804,9 @@ TEST(P224, Addition) { p224::Negate(b, &minus_b); p224::Add(a, b, &sum); - EXPECT_TRUE(memcmp(&sum, &a, sizeof(sum)) != 0); + EXPECT_NE(0, memcmp(&sum, &a, sizeof(sum))); p224::Add(minus_b, sum, &a_again); - EXPECT_TRUE(a_again.ToString() == a.ToString()); + EXPECT_EQ(a_again.ToString(), a.ToString()); } TEST(P224, Infinity) { @@ -816,7 +816,7 @@ TEST(P224, Infinity) { // Test that x^0 = ∞. Point a; p224::ScalarBaseMult(reinterpret_cast(zeros), &a); - EXPECT_TRUE(memcmp(zeros, a.ToString().data(), sizeof(zeros)) == 0); + EXPECT_EQ(0, memcmp(zeros, a.ToString().data(), sizeof(zeros))); // We shouldn't allow ∞ to be imported. EXPECT_FALSE(a.SetFromString(std::string(zeros, sizeof(zeros)))); diff --git a/crypto/random.h b/crypto/random.h index 002616bd30ef7818f34fcf33d2750c824af44f80..61cde80719b5b4e13e79f9e7da3f1a540d863057 100644 --- a/crypto/random.h +++ b/crypto/random.h @@ -18,4 +18,4 @@ CRYPTO_EXPORT void RandBytes(void *bytes, size_t length); } -#endif +#endif // CRYPTO_RANDOM_H_ diff --git a/crypto/random_unittest.cc b/crypto/random_unittest.cc index caee512068d1252125f7680e16de67929a0b27f6..dfdcfd507753e10f5a37b4677ce9a6f4662c6e5b 100644 --- a/crypto/random_unittest.cc +++ b/crypto/random_unittest.cc @@ -6,6 +6,8 @@ #include +#include + #include "base/strings/string_util.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/crypto/rsa_private_key_unittest.cc b/crypto/rsa_private_key_unittest.cc index 393a24c536453efcba9135f474dfeb8634c92c09..f9549f3418656621621557cb36fc7e949008ac93 100644 --- a/crypto/rsa_private_key_unittest.cc +++ b/crypto/rsa_private_key_unittest.cc @@ -103,10 +103,8 @@ TEST(RSAPrivateKeyUnitTest, InitRandomTest) { ASSERT_EQ(privkey1.size(), privkey3.size()); ASSERT_EQ(privkey2.size(), privkey4.size()); - ASSERT_TRUE(0 == memcmp(&privkey1.front(), &privkey3.front(), - privkey1.size())); - ASSERT_TRUE(0 == memcmp(&privkey2.front(), &privkey4.front(), - privkey2.size())); + ASSERT_EQ(0, memcmp(&privkey1.front(), &privkey3.front(), privkey1.size())); + ASSERT_EQ(0, memcmp(&privkey2.front(), &privkey4.front(), privkey2.size())); } // Test Copy() method. @@ -195,8 +193,8 @@ TEST(RSAPrivateKeyUnitTest, PublicKeyTest) { std::vector output; ASSERT_TRUE(key->ExportPublicKey(&output)); - ASSERT_TRUE( - memcmp(expected_public_key_info, &output.front(), output.size()) == 0); + ASSERT_EQ(0, + memcmp(expected_public_key_info, &output.front(), output.size())); } // These two test keys each contain an integer that has 0x00 for its most @@ -349,10 +347,8 @@ TEST(RSAPrivateKeyUnitTest, ShortIntegers) { ASSERT_EQ(input1.size(), output1.size()); ASSERT_EQ(input2.size(), output2.size()); - ASSERT_TRUE(0 == memcmp(&output1.front(), &input1.front(), - input1.size())); - ASSERT_TRUE(0 == memcmp(&output2.front(), &input2.front(), - input2.size())); + ASSERT_EQ(0, memcmp(&output1.front(), &input1.front(), input1.size())); + ASSERT_EQ(0, memcmp(&output2.front(), &input2.front(), input2.size())); } TEST(RSAPrivateKeyUnitTest, CreateFromKeyTest) { diff --git a/crypto/scoped_test_system_nss_key_slot.h b/crypto/scoped_test_system_nss_key_slot.h index eb8fbc97a8feb2e2d8560db9a5f1712dae8ccba9..ae9b2cd8a5b7ff8feeacae8152622eeb39a9a913 100644 --- a/crypto/scoped_test_system_nss_key_slot.h +++ b/crypto/scoped_test_system_nss_key_slot.h @@ -27,7 +27,7 @@ class ScopedTestNSSDB; // At most one instance of this helper must be used at a time. class CRYPTO_EXPORT ScopedTestSystemNSSKeySlot { public: - explicit ScopedTestSystemNSSKeySlot(); + ScopedTestSystemNSSKeySlot(); ~ScopedTestSystemNSSKeySlot(); bool ConstructedSuccessfully() const; diff --git a/crypto/signature_creator_unittest.cc b/crypto/signature_creator_unittest.cc index 819e663dacf83322f55239858963e9af5289e8ec..2f135cc7091215cdddf841a91345eef7c4d44194 100644 --- a/crypto/signature_creator_unittest.cc +++ b/crypto/signature_creator_unittest.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include "base/sha1.h" diff --git a/crypto/wincrypt_shim.h b/crypto/wincrypt_shim.h index 48d4b5c5fabd9fef74b8dd3d4fc6be22f8ba06ca..dcfd4adbe51b4162d56615c4526df785a798c9bf 100644 --- a/crypto/wincrypt_shim.h +++ b/crypto/wincrypt_shim.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef NET_CRYPTO_WINCRYPT_SHIM_H_ -#define NET_CRYPTO_WINCRYPT_SHIM_H_ +#ifndef CRYPTO_WINCRYPT_SHIM_H_ +#define CRYPTO_WINCRYPT_SHIM_H_ // wincrypt.h defines macros which conflict with OpenSSL's types. This header // includes wincrypt and undefines the OpenSSL macros which conflict. Any @@ -22,4 +22,4 @@ #define WINCRYPT_X509_EXTENSIONS ((LPCSTR) 5) #define WINCRYPT_X509_NAME ((LPCSTR) 7) -#endif // NET_CRYPTO_WINCRYPT_SHIM_H_ +#endif // CRYPTO_WINCRYPT_SHIM_H_