Commit 6004dc58 authored by davidben's avatar davidben Committed by Commit bot

Fix non-noise cpplint errors in //crypto.

There are two that are wrong because cpplint gets confused about
variables named 'copy' and methods named 'swap'. Those I've left alone.

BUG=none

Review-Url: https://codereview.chromium.org/2677583002
Cr-Commit-Position: refs/heads/master@{#447926}
parent 5429b39d
......@@ -120,4 +120,4 @@ size_t Aead::NonceLength() const {
return EVP_AEAD_nonce_length(aead_);
}
} // namespace
} // namespace crypto
......@@ -7,6 +7,8 @@
#include <stddef.h>
#include <string>
#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_
......@@ -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 <Security/Security.h>
......@@ -106,4 +106,4 @@ class CRYPTO_EXPORT AppleKeychain {
} // namespace crypto
#endif // CRYPTO_KEYCHAIN_MAC_H_
#endif // CRYPTO_APPLE_KEYCHAIN_H_
......@@ -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);
......
......@@ -7,6 +7,8 @@
#include <stdint.h>
#include <vector>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "crypto/ec_signature_creator.h"
......
......@@ -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() {
......
......@@ -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[] = {
......
......@@ -7,6 +7,7 @@
#include <stddef.h>
#include <algorithm>
#include <string>
#include "base/logging.h"
#include "base/stl_util.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 <stddef.h>
#include <stdint.h>
......@@ -254,4 +254,4 @@ class CRYPTO_EXPORT MockAppleKeychain : public AppleKeychain {
} // namespace crypto
#endif // CRYPTO_MOCK_KEYCHAIN_MAC_H_
#endif // CRYPTO_MOCK_APPLE_KEYCHAIN_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
......
......@@ -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(
......
......@@ -7,6 +7,8 @@
#include <secmodt.h>
#include <string>
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
......
......@@ -7,6 +7,8 @@
#include <stddef.h>
#include <stdint.h>
#include <string>
#include "base/logging.h"
#include "base/strings/string_piece.h"
#include "third_party/boringssl/src/include/openssl/crypto.h"
......
......@@ -5,14 +5,14 @@
// This code implements SPAKE2, a variant of EKE:
// http://www.di.ens.fr/~pointche/pub.php?reference=AbPo04
#include <crypto/p224_spake.h>
#include "crypto/p224_spake.h"
#include <algorithm>
#include <base/logging.h>
#include <crypto/p224.h>
#include <crypto/random.h>
#include <crypto/secure_util.h>
#include "base/logging.h"
#include "crypto/p224.h"
#include "crypto/random.h"
#include "crypto/secure_util.h"
namespace {
......@@ -27,6 +27,9 @@ namespace {
// #include <openssl/obj_mac.h>
// #include <openssl/sha.h>
//
// // 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);
......
......@@ -5,12 +5,14 @@
#ifndef CRYPTO_P224_SPAKE_H_
#define CRYPTO_P224_SPAKE_H_
#include <crypto/p224.h>
#include <crypto/sha2.h>
#include <stdint.h>
#include <string>
#include "base/gtest_prod_util.h"
#include "base/strings/string_piece.h"
#include "crypto/p224.h"
#include "crypto/sha2.h"
namespace crypto {
......
......@@ -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<const uint8_t*>(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))));
......
......@@ -18,4 +18,4 @@ CRYPTO_EXPORT void RandBytes(void *bytes, size_t length);
}
#endif
#endif // CRYPTO_RANDOM_H_
......@@ -6,6 +6,8 @@
#include <stddef.h>
#include <string>
#include "base/strings/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -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<uint8_t> 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) {
......
......@@ -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;
......
......@@ -7,6 +7,7 @@
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "base/sha1.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_
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment