From 78f97ef2e31cb204a6da0923e6d0236c971719a8 Mon Sep 17 00:00:00 2001 From: hai007 Date: Thu, 10 Oct 2024 09:53:08 -0700 Subject: [PATCH] Move crypto-related symbols from ::crypto:: to ::nearby::crypto:: to deconflict them with chromium ::crypto symbols of the same names. PiperOrigin-RevId: 684480231 --- internal/crypto/ed25519.cc | 4 ++-- internal/crypto/ed25519.h | 4 ++-- internal/crypto/ed25519_unittest.cc | 4 ++-- internal/crypto_cros/aead.cc | 4 ++-- internal/crypto_cros/aead.h | 4 ++-- internal/crypto_cros/aead_unittest.cc | 2 ++ internal/crypto_cros/ec_private_key.cc | 4 ++-- internal/crypto_cros/ec_private_key.h | 4 ++-- internal/crypto_cros/ec_private_key_unittest.cc | 3 +++ internal/crypto_cros/ec_signature_creator.cc | 4 ++-- internal/crypto_cros/ec_signature_creator.h | 4 ++-- internal/crypto_cros/ec_signature_creator_impl.cc | 4 ++-- internal/crypto_cros/ec_signature_creator_impl.h | 4 ++-- internal/crypto_cros/ec_signature_creator_unittest.cc | 4 ++++ internal/crypto_cros/encryptor.cc | 4 ++-- internal/crypto_cros/encryptor.h | 4 ++-- internal/crypto_cros/encryptor_unittest.cc | 4 ++++ internal/crypto_cros/hkdf.cc | 4 ++-- internal/crypto_cros/hkdf.h | 4 ++-- internal/crypto_cros/hmac.cc | 4 ++-- internal/crypto_cros/hmac.h | 4 ++-- internal/crypto_cros/hmac_unittest.cc | 4 ++++ internal/crypto_cros/openssl_util.cc | 4 ++-- internal/crypto_cros/openssl_util.h | 4 ++-- internal/crypto_cros/rsa_private_key.cc | 4 ++-- internal/crypto_cros/rsa_private_key.h | 4 ++-- internal/crypto_cros/rsa_private_key_unittest.cc | 3 +++ internal/crypto_cros/secure_hash.cc | 4 ++-- internal/crypto_cros/secure_hash.h | 4 ++-- internal/crypto_cros/secure_hash_unittest.cc | 4 ++++ internal/crypto_cros/secure_util.cc | 4 ++-- internal/crypto_cros/secure_util.h | 4 ++-- internal/crypto_cros/sha2.cc | 4 ++-- internal/crypto_cros/sha2.h | 4 ++-- internal/crypto_cros/sha2_unittest.cc | 4 ++++ internal/crypto_cros/signature_verifier.cc | 4 ++-- internal/crypto_cros/signature_verifier.h | 4 ++-- internal/crypto_cros/signature_verifier_unittest.cc | 4 ++++ internal/crypto_cros/symmetric_key.cc | 4 ++-- internal/crypto_cros/symmetric_key.h | 4 ++-- internal/crypto_cros/symmetric_key_unittest.cc | 4 ++++ presence/implementation/credential_manager_impl.cc | 8 +------- 42 files changed, 99 insertions(+), 69 deletions(-) diff --git a/internal/crypto/ed25519.cc b/internal/crypto/ed25519.cc index 7f73667cb7e..35c17a0adf2 100644 --- a/internal/crypto/ed25519.cc +++ b/internal/crypto/ed25519.cc @@ -26,7 +26,7 @@ #include #include -namespace crypto { +namespace nearby::crypto { constexpr size_t kEd25519SignatureSize = 64; constexpr size_t kEd25519PrivateKeySize = 32; @@ -181,4 +181,4 @@ absl::Status Ed25519Verifier::Verify(absl::string_view data, : absl::InternalError("Signature is invalid."); } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto/ed25519.h b/internal/crypto/ed25519.h index 9fee90e90ef..06c752666b2 100644 --- a/internal/crypto/ed25519.h +++ b/internal/crypto/ed25519.h @@ -25,7 +25,7 @@ #include #include -namespace crypto { +namespace nearby::crypto { #ifdef OPENSSL_IS_BORINGSSL using CryptoKeyUniquePtr = ::bssl::UniquePtr; @@ -73,6 +73,6 @@ class CRYPTO_EXPORT Ed25519Verifier { CryptoKeyUniquePtr public_key_; }; -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_ED25519_H_ diff --git a/internal/crypto/ed25519_unittest.cc b/internal/crypto/ed25519_unittest.cc index 5d580c4aa3c..97be492d9c8 100644 --- a/internal/crypto/ed25519_unittest.cc +++ b/internal/crypto/ed25519_unittest.cc @@ -21,7 +21,7 @@ #include "gtest/gtest.h" #include "absl/strings/escaping.h" -namespace crypto { +namespace nearby::crypto { namespace { using ::absl::StatusCode; @@ -211,4 +211,4 @@ TEST(Ed25519SignerVerifierTest, NewKeypairFromRandomSeedRoundtrip) { } } // namespace -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/aead.cc b/internal/crypto_cros/aead.cc index 98bc66c47ca..f25699eeb60 100644 --- a/internal/crypto_cros/aead.cc +++ b/internal/crypto_cros/aead.cc @@ -34,7 +34,7 @@ #include "internal/crypto_cros/openssl_util.h" #include -namespace crypto { +namespace nearby::crypto { Aead::Aead(AeadAlgorithm algorithm) { EnsureOpenSSLInit(); @@ -186,4 +186,4 @@ bool Aead::Open(absl::Span plaintext, return true; } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/aead.h b/internal/crypto_cros/aead.h index 12da8a57f51..6ed16bbdc5a 100644 --- a/internal/crypto_cros/aead.h +++ b/internal/crypto_cros/aead.h @@ -28,7 +28,7 @@ #include "internal/crypto_cros/crypto_export.h" #include -namespace crypto { +namespace nearby::crypto { // This class exposes the AES-128-CTR-HMAC-SHA256 and AES_256_GCM AEAD. Note // that there are two versions of most methods: an historical version based @@ -89,6 +89,6 @@ class CRYPTO_EXPORT Aead { const EVP_AEAD* aead_; }; -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_AEAD_H_ diff --git a/internal/crypto_cros/aead_unittest.cc b/internal/crypto_cros/aead_unittest.cc index 9474eb33bab..df1c4750c59 100644 --- a/internal/crypto_cros/aead_unittest.cc +++ b/internal/crypto_cros/aead_unittest.cc @@ -20,6 +20,7 @@ #include "gtest/gtest.h" +namespace nearby { namespace { const crypto::Aead::AeadAlgorithm kAllAlgorithms[]{ @@ -98,3 +99,4 @@ TEST_P(AeadTest, SealOpenWrongKey) { } } // namespace +} // namespace nearby diff --git a/internal/crypto_cros/ec_private_key.cc b/internal/crypto_cros/ec_private_key.cc index 3e937c2a2cf..14af7a8f6c6 100644 --- a/internal/crypto_cros/ec_private_key.cc +++ b/internal/crypto_cros/ec_private_key.cc @@ -40,7 +40,7 @@ #include #include -namespace crypto { +namespace nearby::crypto { ECPrivateKey::~ECPrivateKey() = default; @@ -186,4 +186,4 @@ bool ECPrivateKey::ExportRawPublicKey(std::string* output) const { ECPrivateKey::ECPrivateKey() = default; -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/ec_private_key.h b/internal/crypto_cros/ec_private_key.h index 9b1dd1b9b4c..fd4e9efa246 100644 --- a/internal/crypto_cros/ec_private_key.h +++ b/internal/crypto_cros/ec_private_key.h @@ -26,7 +26,7 @@ #include "internal/crypto_cros/crypto_export.h" #include -namespace crypto { +namespace nearby::crypto { // Encapsulates an elliptic curve (EC) private key. Can be used to generate new // keys, export keys to other formats, or to extract a public key. @@ -91,6 +91,6 @@ class CRYPTO_EXPORT ECPrivateKey { bssl::UniquePtr key_; }; -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_EC_PRIVATE_KEY_H_ diff --git a/internal/crypto_cros/ec_private_key_unittest.cc b/internal/crypto_cros/ec_private_key_unittest.cc index 43c6dcbbe71..e1ff8f94199 100644 --- a/internal/crypto_cros/ec_private_key_unittest.cc +++ b/internal/crypto_cros/ec_private_key_unittest.cc @@ -23,6 +23,7 @@ #include "gtest/gtest.h" +namespace nearby { namespace { void ExpectKeysEqual(const crypto::ECPrivateKey* keypair1, @@ -331,3 +332,5 @@ TEST(ECPrivateKeyUnitTest, LoadOldOpenSSLKeyTest) { EXPECT_TRUE(keypair_openssl); } + +} // namespace nearby diff --git a/internal/crypto_cros/ec_signature_creator.cc b/internal/crypto_cros/ec_signature_creator.cc index dcf41083dad..75b896610b0 100644 --- a/internal/crypto_cros/ec_signature_creator.cc +++ b/internal/crypto_cros/ec_signature_creator.cc @@ -18,7 +18,7 @@ #include "internal/crypto_cros/ec_signature_creator_impl.h" -namespace crypto { +namespace nearby::crypto { // static std::unique_ptr ECSignatureCreator::Create( @@ -26,4 +26,4 @@ std::unique_ptr ECSignatureCreator::Create( return std::make_unique(key); } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/ec_signature_creator.h b/internal/crypto_cros/ec_signature_creator.h index f0dfd79015c..90b738e5863 100644 --- a/internal/crypto_cros/ec_signature_creator.h +++ b/internal/crypto_cros/ec_signature_creator.h @@ -24,7 +24,7 @@ #include "absl/types/span.h" #include "internal/crypto_cros/crypto_export.h" -namespace crypto { +namespace nearby::crypto { class ECPrivateKey; class ECSignatureCreator; @@ -60,6 +60,6 @@ class CRYPTO_EXPORT ECSignatureCreator { std::vector* out_raw_sig) = 0; }; -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_EC_SIGNATURE_CREATOR_H_ diff --git a/internal/crypto_cros/ec_signature_creator_impl.cc b/internal/crypto_cros/ec_signature_creator_impl.cc index a7b20a889ea..ad904191aa0 100644 --- a/internal/crypto_cros/ec_signature_creator_impl.cc +++ b/internal/crypto_cros/ec_signature_creator_impl.cc @@ -27,7 +27,7 @@ #include #include -namespace crypto { +namespace nearby::crypto { ECSignatureCreatorImpl::ECSignatureCreatorImpl(ECPrivateKey* key) : key_(key) { EnsureOpenSSLInit(); @@ -80,4 +80,4 @@ bool ECSignatureCreatorImpl::DecodeSignature( return true; } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/ec_signature_creator_impl.h b/internal/crypto_cros/ec_signature_creator_impl.h index 8024bbc89a2..79b66dd5c2d 100644 --- a/internal/crypto_cros/ec_signature_creator_impl.h +++ b/internal/crypto_cros/ec_signature_creator_impl.h @@ -22,7 +22,7 @@ #include "absl/types/span.h" #include "internal/crypto_cros/ec_signature_creator.h" -namespace crypto { +namespace nearby::crypto { class ECSignatureCreatorImpl : public ECSignatureCreator { public: @@ -43,6 +43,6 @@ class ECSignatureCreatorImpl : public ECSignatureCreator { ECPrivateKey* key_; }; -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_EC_SIGNATURE_CREATOR_IMPL_H_ diff --git a/internal/crypto_cros/ec_signature_creator_unittest.cc b/internal/crypto_cros/ec_signature_creator_unittest.cc index 753f4e733b1..48ea4c5b70d 100644 --- a/internal/crypto_cros/ec_signature_creator_unittest.cc +++ b/internal/crypto_cros/ec_signature_creator_unittest.cc @@ -26,6 +26,8 @@ #include "internal/crypto_cros/nearby_base.h" #include "internal/crypto_cros/signature_verifier.h" +namespace nearby { + TEST(ECSignatureCreatorTest, BasicTest) { // Do a verify round trip. std::unique_ptr key_original( @@ -59,3 +61,5 @@ TEST(ECSignatureCreatorTest, BasicTest) { verifier.VerifyUpdate(nearbybase::as_bytes(absl::MakeSpan(data))); ASSERT_TRUE(verifier.VerifyFinal()); } + +} // namespace nearby diff --git a/internal/crypto_cros/encryptor.cc b/internal/crypto_cros/encryptor.cc index b901ea968f9..a6a7c4c5b97 100644 --- a/internal/crypto_cros/encryptor.cc +++ b/internal/crypto_cros/encryptor.cc @@ -41,7 +41,7 @@ #include #include -namespace crypto { +namespace nearby::crypto { namespace { @@ -225,4 +225,4 @@ absl::optional Encryptor::CryptCTR(bool do_encrypt, return input.size(); } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/encryptor.h b/internal/crypto_cros/encryptor.h index ce100d5cc04..6fe5c8770b1 100644 --- a/internal/crypto_cros/encryptor.h +++ b/internal/crypto_cros/encryptor.h @@ -28,7 +28,7 @@ #include "absl/types/span.h" #include "internal/crypto_cros/crypto_export.h" -namespace crypto { +namespace nearby::crypto { class SymmetricKey; @@ -105,6 +105,6 @@ class CRYPTO_EXPORT Encryptor { std::vector iv_; }; -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_ENCRYPTOR_H_ diff --git a/internal/crypto_cros/encryptor_unittest.cc b/internal/crypto_cros/encryptor_unittest.cc index 207911c04bd..dff9cd00f6c 100644 --- a/internal/crypto_cros/encryptor_unittest.cc +++ b/internal/crypto_cros/encryptor_unittest.cc @@ -27,6 +27,8 @@ #include "internal/crypto_cros/nearby_base.h" #include "internal/crypto_cros/symmetric_key.h" +namespace nearby { + TEST(EncryptorTest, EncryptDecrypt) { std::unique_ptr key( crypto::SymmetricKey::DeriveKeyFromPasswordUsingPbkdf2( @@ -570,3 +572,5 @@ TEST(EncryptorTest, CipherTextNotMultipleOfBlockSize) { EXPECT_FALSE( encryptor.Decrypt(absl::string_view(ciphertext.get(), 1), &plaintext)); } + +} // namespace nearby diff --git a/internal/crypto_cros/hkdf.cc b/internal/crypto_cros/hkdf.cc index 1e50ea6d21f..781e2476743 100644 --- a/internal/crypto_cros/hkdf.cc +++ b/internal/crypto_cros/hkdf.cc @@ -34,7 +34,7 @@ #include "internal/crypto_cros/hmac.h" #include -namespace crypto { +namespace nearby::crypto { std::string HkdfSha256(absl::string_view secret, absl::string_view salt, absl::string_view info, size_t derived_key_size) { @@ -62,4 +62,4 @@ std::vector HkdfSha256(absl::Span secret, return ret; } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/hkdf.h b/internal/crypto_cros/hkdf.h index 3174021859a..9ee355700ea 100644 --- a/internal/crypto_cros/hkdf.h +++ b/internal/crypto_cros/hkdf.h @@ -24,7 +24,7 @@ #include "absl/types/span.h" #include "internal/crypto_cros/crypto_export.h" -namespace crypto { +namespace nearby::crypto { CRYPTO_EXPORT std::string HkdfSha256(absl::string_view secret, absl::string_view salt, @@ -36,6 +36,6 @@ std::vector HkdfSha256(absl::Span secret, absl::Span info, size_t derived_key_size); -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_HKDF_H_ diff --git a/internal/crypto_cros/hmac.cc b/internal/crypto_cros/hmac.cc index 78d6f998d97..94bf37b5a15 100644 --- a/internal/crypto_cros/hmac.cc +++ b/internal/crypto_cros/hmac.cc @@ -33,7 +33,7 @@ #include "internal/crypto_cros/secure_util.h" #include "internal/crypto_cros/symmetric_key.h" -namespace crypto { +namespace nearby::crypto { HMAC::HMAC(HashAlgorithm hash_alg) : hash_alg_(hash_alg), initialized_(false) { // Only SHA-1 and SHA-256 hash algorithms are supported now. @@ -118,4 +118,4 @@ bool HMAC::VerifyTruncated(absl::Span data, return SecureMemEqual(digest.data(), computed_digest, digest.size()); } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/hmac.h b/internal/crypto_cros/hmac.h index 12c806ba0c8..f2d46cbdd96 100644 --- a/internal/crypto_cros/hmac.h +++ b/internal/crypto_cros/hmac.h @@ -31,7 +31,7 @@ #include "internal/crypto_cros/crypto_export.h" #include "internal/crypto_cros/nearby_base.h" -namespace crypto { +namespace nearby::crypto { // Simplify the interface and reduce includes by abstracting out the internals. class SymmetricKey; @@ -120,6 +120,6 @@ class CRYPTO_EXPORT HMAC { std::vector key_; }; -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_HMAC_H_ diff --git a/internal/crypto_cros/hmac_unittest.cc b/internal/crypto_cros/hmac_unittest.cc index 5676f3be64d..8faf0b07d9f 100644 --- a/internal/crypto_cros/hmac_unittest.cc +++ b/internal/crypto_cros/hmac_unittest.cc @@ -26,6 +26,8 @@ #include "absl/strings/string_view.h" #include "absl/types/span.h" +namespace nearby { + static const size_t kSHA1DigestSize = 20; static const size_t kSHA256DigestSize = 32; @@ -376,3 +378,5 @@ TEST(HMACTest, Bytes) { EXPECT_FALSE(hmac.VerifyTruncated( data, absl::MakeSpan(calculated_hmac, kSHA256DigestSize / 2))); } + +} // namespace nearby diff --git a/internal/crypto_cros/openssl_util.cc b/internal/crypto_cros/openssl_util.cc index ac7b62e1bfe..c533f287b17 100644 --- a/internal/crypto_cros/openssl_util.cc +++ b/internal/crypto_cros/openssl_util.cc @@ -30,7 +30,7 @@ #include #include -namespace crypto { +namespace nearby::crypto { void EnsureOpenSSLInit() { // CRYPTO_library_init may be safely called concurrently. @@ -41,4 +41,4 @@ void ClearOpenSSLERRStack() { ERR_clear_error(); } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/openssl_util.h b/internal/crypto_cros/openssl_util.h index 07bbe8dcb23..58ab000c75f 100644 --- a/internal/crypto_cros/openssl_util.h +++ b/internal/crypto_cros/openssl_util.h @@ -20,7 +20,7 @@ #include "internal/crypto_cros/crypto_export.h" -namespace crypto { +namespace nearby::crypto { // Provides a buffer of at least MIN_SIZE bytes, for use when calling OpenSSL's // SHA256, HMAC, etc functions, adapting the buffer sizing rules to meet those @@ -98,6 +98,6 @@ class OpenSSLErrStackTracer { ~OpenSSLErrStackTracer() { ClearOpenSSLERRStack(); } }; -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_OPENSSL_UTIL_H_ diff --git a/internal/crypto_cros/rsa_private_key.cc b/internal/crypto_cros/rsa_private_key.cc index b275954eb44..da217146e0d 100644 --- a/internal/crypto_cros/rsa_private_key.cc +++ b/internal/crypto_cros/rsa_private_key.cc @@ -36,7 +36,7 @@ #include #include -namespace crypto { +namespace nearby::crypto { // static std::unique_ptr RSAPrivateKey::Create(uint16_t num_bits) { @@ -126,4 +126,4 @@ bool RSAPrivateKey::ExportPublicKey(std::vector* output) const { return true; } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/rsa_private_key.h b/internal/crypto_cros/rsa_private_key.h index 5aaeb59bead..be52bdf1ea6 100644 --- a/internal/crypto_cros/rsa_private_key.h +++ b/internal/crypto_cros/rsa_private_key.h @@ -25,7 +25,7 @@ #include "internal/crypto_cros/crypto_export.h" #include -namespace crypto { +namespace nearby::crypto { // Encapsulates an RSA private key. Can be used to generate new keys, export // keys to other formats, or to extract a public key. @@ -69,6 +69,6 @@ class CRYPTO_EXPORT RSAPrivateKey { bssl::UniquePtr key_; }; -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_RSA_PRIVATE_KEY_H_ diff --git a/internal/crypto_cros/rsa_private_key_unittest.cc b/internal/crypto_cros/rsa_private_key_unittest.cc index 24212cf0b2a..de7988a68b3 100644 --- a/internal/crypto_cros/rsa_private_key_unittest.cc +++ b/internal/crypto_cros/rsa_private_key_unittest.cc @@ -21,6 +21,7 @@ #include "gtest/gtest.h" +namespace nearby { namespace { const uint8_t kTestPrivateKeyInfo[] = { @@ -384,3 +385,5 @@ TEST(RSAPrivateKeyUnitTest, CreateFromKeyTest) { ASSERT_EQ(privkey, privkey_copy); ASSERT_EQ(pubkey, pubkey_copy); } + +} // namespace nearby diff --git a/internal/crypto_cros/secure_hash.cc b/internal/crypto_cros/secure_hash.cc index bf19c33883c..09e55808c85 100644 --- a/internal/crypto_cros/secure_hash.cc +++ b/internal/crypto_cros/secure_hash.cc @@ -22,7 +22,7 @@ #include #include -namespace crypto { +namespace nearby::crypto { namespace { @@ -73,4 +73,4 @@ std::unique_ptr SecureHash::Create(Algorithm algorithm) { } } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/secure_hash.h b/internal/crypto_cros/secure_hash.h index 1f5ec9e1c7c..34bd0164348 100644 --- a/internal/crypto_cros/secure_hash.h +++ b/internal/crypto_cros/secure_hash.h @@ -21,7 +21,7 @@ #include "internal/crypto_cros/crypto_export.h" -namespace crypto { +namespace nearby::crypto { // A wrapper to calculate secure hashes incrementally, allowing to // be used when the full input is not known in advance. The end result will the @@ -52,6 +52,6 @@ class CRYPTO_EXPORT SecureHash { SecureHash() {} }; -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_SECURE_HASH_H_ diff --git a/internal/crypto_cros/secure_hash_unittest.cc b/internal/crypto_cros/secure_hash_unittest.cc index ea6a55b5feb..bcdb012e4cb 100644 --- a/internal/crypto_cros/secure_hash_unittest.cc +++ b/internal/crypto_cros/secure_hash_unittest.cc @@ -23,6 +23,8 @@ #include "gtest/gtest.h" #include "internal/crypto_cros/sha2.h" +namespace nearby { + TEST(SecureHashTest, TestUpdate) { // Example B.3 from FIPS 180-2: long message. std::string input3(500000, 'a'); // 'a' repeated half a million times @@ -115,3 +117,5 @@ TEST(SecureHashTest, Equality) { // The hash should be the same. EXPECT_EQ(0, memcmp(output1, output2, crypto::kSHA256Length)); } + +} // namespace nearby diff --git a/internal/crypto_cros/secure_util.cc b/internal/crypto_cros/secure_util.cc index a026810e200..89842539ee8 100644 --- a/internal/crypto_cros/secure_util.cc +++ b/internal/crypto_cros/secure_util.cc @@ -16,10 +16,10 @@ #include -namespace crypto { +namespace nearby::crypto { bool SecureMemEqual(const void* s1, const void* s2, size_t n) { return CRYPTO_memcmp(s1, s2, n) == 0; } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/secure_util.h b/internal/crypto_cros/secure_util.h index 64322ecafe6..ae7eae154e3 100644 --- a/internal/crypto_cros/secure_util.h +++ b/internal/crypto_cros/secure_util.h @@ -19,7 +19,7 @@ #include "internal/crypto_cros/crypto_export.h" -namespace crypto { +namespace nearby::crypto { // Performs a constant-time comparison of two strings, returning true if the // strings are equal. @@ -33,6 +33,6 @@ namespace crypto { // http://groups.google.com/group/keyczar-discuss/browse_thread/thread/5571eca0948b2a13 CRYPTO_EXPORT bool SecureMemEqual(const void* s1, const void* s2, size_t n); -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_SECURE_UTIL_H_ diff --git a/internal/crypto_cros/sha2.cc b/internal/crypto_cros/sha2.cc index 77407f2b087..1932376c066 100644 --- a/internal/crypto_cros/sha2.cc +++ b/internal/crypto_cros/sha2.cc @@ -24,7 +24,7 @@ #include "internal/crypto_cros/secure_hash.h" #include -namespace crypto { +namespace nearby::crypto { std::array SHA256Hash(absl::Span input) { std::array digest; @@ -44,4 +44,4 @@ std::string SHA256HashString(absl::string_view str) { return output; } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/sha2.h b/internal/crypto_cros/sha2.h index ca9e7fb85fc..d06ebf8a960 100644 --- a/internal/crypto_cros/sha2.h +++ b/internal/crypto_cros/sha2.h @@ -25,7 +25,7 @@ #include "absl/types/span.h" #include "internal/crypto_cros/crypto_export.h" -namespace crypto { +namespace nearby::crypto { // These functions perform SHA-256 operations. // @@ -47,6 +47,6 @@ CRYPTO_EXPORT std::string SHA256HashString(absl::string_view str); CRYPTO_EXPORT void SHA256HashString(absl::string_view str, void* output, size_t len); -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_SHA2_H_ diff --git a/internal/crypto_cros/sha2_unittest.cc b/internal/crypto_cros/sha2_unittest.cc index 65c869ae7f2..2dec9a62931 100644 --- a/internal/crypto_cros/sha2_unittest.cc +++ b/internal/crypto_cros/sha2_unittest.cc @@ -21,6 +21,8 @@ #include "gtest/gtest.h" +namespace nearby { + TEST(Sha256Test, Test1) { // Example B.1 from FIPS 180-2: one-block message. std::string input1 = "abc"; @@ -96,3 +98,5 @@ TEST(Sha256Test, Test3) { for (size_t i = 0; i < sizeof(output_truncated3); i++) EXPECT_EQ(expected3[i], static_cast(output_truncated3[i])); } + +} // namespace nearby diff --git a/internal/crypto_cros/signature_verifier.cc b/internal/crypto_cros/signature_verifier.cc index 01cbe278d29..31899499967 100644 --- a/internal/crypto_cros/signature_verifier.cc +++ b/internal/crypto_cros/signature_verifier.cc @@ -30,7 +30,7 @@ #include #include -namespace crypto { +namespace nearby::crypto { struct SignatureVerifier::VerifyContext { bssl::ScopedEVP_MD_CTX ctx; @@ -119,4 +119,4 @@ void SignatureVerifier::Reset() { signature_.clear(); } -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/signature_verifier.h b/internal/crypto_cros/signature_verifier.h index 6ce8af2f706..eff0083b310 100644 --- a/internal/crypto_cros/signature_verifier.h +++ b/internal/crypto_cros/signature_verifier.h @@ -23,7 +23,7 @@ #include "absl/types/span.h" #include "internal/crypto_cros/crypto_export.h" -namespace crypto { +namespace nearby::crypto { // The SignatureVerifier class verifies a signature using a bare public key // (as opposed to a certificate). @@ -76,6 +76,6 @@ class CRYPTO_EXPORT SignatureVerifier { std::unique_ptr verify_context_; }; -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_SIGNATURE_VERIFIER_H_ diff --git a/internal/crypto_cros/signature_verifier_unittest.cc b/internal/crypto_cros/signature_verifier_unittest.cc index c6f7bd82707..09f4f8f9eac 100644 --- a/internal/crypto_cros/signature_verifier_unittest.cc +++ b/internal/crypto_cros/signature_verifier_unittest.cc @@ -23,6 +23,8 @@ #include "gtest/gtest.h" #include "absl/types/span.h" +namespace nearby { + TEST(SignatureVerifierTest, BasicTest) { // The input data in this test comes from real certificates. // @@ -422,3 +424,5 @@ TEST(SignatureVerifierTest, VerifyRSAPSS) { verifier.VerifyUpdate(kPSSMessage); EXPECT_FALSE(verifier.VerifyFinal()); } + +} // namespace nearby diff --git a/internal/crypto_cros/symmetric_key.cc b/internal/crypto_cros/symmetric_key.cc index 06178d1e242..e69d56cebb7 100644 --- a/internal/crypto_cros/symmetric_key.cc +++ b/internal/crypto_cros/symmetric_key.cc @@ -35,7 +35,7 @@ #include #include -namespace crypto { +namespace nearby::crypto { namespace { @@ -144,4 +144,4 @@ std::unique_ptr SymmetricKey::Import(Algorithm algorithm, SymmetricKey::SymmetricKey() = default; -} // namespace crypto +} // namespace nearby::crypto diff --git a/internal/crypto_cros/symmetric_key.h b/internal/crypto_cros/symmetric_key.h index cdcc2d8abcc..e86ed97eb55 100644 --- a/internal/crypto_cros/symmetric_key.h +++ b/internal/crypto_cros/symmetric_key.h @@ -22,7 +22,7 @@ #include "internal/crypto_cros/crypto_export.h" -namespace crypto { +namespace nearby::crypto { // Wraps a platform-specific symmetric key and allows it to be held in a // scoped_ptr. @@ -84,6 +84,6 @@ class CRYPTO_EXPORT SymmetricKey { std::string key_; }; -} // namespace crypto +} // namespace nearby::crypto #endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_SYMMETRIC_KEY_H_ diff --git a/internal/crypto_cros/symmetric_key_unittest.cc b/internal/crypto_cros/symmetric_key_unittest.cc index ad3e684dc4f..71fe86493e5 100644 --- a/internal/crypto_cros/symmetric_key_unittest.cc +++ b/internal/crypto_cros/symmetric_key_unittest.cc @@ -21,6 +21,8 @@ #include "absl/strings/ascii.h" #include "internal/crypto_cros/nearby_base.h" +namespace nearby { + TEST(SymmetricKeyTest, GenerateRandomKey) { std::unique_ptr key( crypto::SymmetricKey::GenerateRandomKey(crypto::SymmetricKey::AES, 256)); @@ -260,3 +262,5 @@ INSTANTIATE_TEST_SUITE_P(All, SymmetricKeyDeriveKeyFromPasswordUsingPbkdf2Test, INSTANTIATE_TEST_SUITE_P(All, SymmetricKeyDeriveKeyFromPasswordUsingScryptTest, testing::ValuesIn(kTestVectorsScrypt)); + +} // namespace nearby diff --git a/presence/implementation/credential_manager_impl.cc b/presence/implementation/credential_manager_impl.cc index f957273edd2..8c552316af5 100644 --- a/presence/implementation/credential_manager_impl.cc +++ b/presence/implementation/credential_manager_impl.cc @@ -31,15 +31,9 @@ #include "absl/types/variant.h" #include "internal/platform/byte_array.h" #include "internal/platform/count_down_latch.h" -#ifdef NEARBY_CHROMIUM -#include "crypto/aead.h" -#include "crypto/ec_private_key.h" -#include "crypto/hkdf.h" -#else #include "internal/crypto_cros/aead.h" #include "internal/crypto_cros/ec_private_key.h" #include "internal/crypto_cros/hkdf.h" -#endif #include "internal/platform/base64_utils.h" #include "internal/platform/crypto.h" #include "internal/platform/future.h" @@ -86,7 +80,7 @@ absl::Duration RandomDuration(absl::Duration max_duration) { } std::string CustomizeBytesSize(absl::string_view bytes, size_t len) { - return ::crypto::HkdfSha256( + return crypto::HkdfSha256( /*ikm=*/std::string(bytes), // NOLINT /*salt=*/std::string(CredentialManagerImpl::kAuthenticityKeyByteSize, 0), /*info=*/"", /*derived_key_size=*/len);