Skip to content

Commit

Permalink
Move crypto-related symbols from ::crypto:: to ::nearby::crypto:: to …
Browse files Browse the repository at this point in the history
…deconflict

them with chromium ::crypto symbols of the same names.

PiperOrigin-RevId: 684566882
  • Loading branch information
hai007 authored and copybara-github committed Oct 10, 2024
1 parent 526ebc8 commit 05ae558
Show file tree
Hide file tree
Showing 42 changed files with 99 additions and 69 deletions.
4 changes: 2 additions & 2 deletions internal/crypto/ed25519.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <openssl/base.h>
#include <openssl/evp.h>

namespace crypto {
namespace nearby::crypto {

constexpr size_t kEd25519SignatureSize = 64;
constexpr size_t kEd25519PrivateKeySize = 32;
Expand Down Expand Up @@ -181,4 +181,4 @@ absl::Status Ed25519Verifier::Verify(absl::string_view data,
: absl::InternalError("Signature is invalid.");
}

} // namespace crypto
} // namespace nearby::crypto
4 changes: 2 additions & 2 deletions internal/crypto/ed25519.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <openssl/digest.h>
#include <openssl/evp.h>

namespace crypto {
namespace nearby::crypto {

#ifdef OPENSSL_IS_BORINGSSL
using CryptoKeyUniquePtr = ::bssl::UniquePtr<EVP_PKEY>;
Expand Down Expand Up @@ -73,6 +73,6 @@ class CRYPTO_EXPORT Ed25519Verifier {
CryptoKeyUniquePtr public_key_;
};

} // namespace crypto
} // namespace nearby::crypto

#endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_ED25519_H_
4 changes: 2 additions & 2 deletions internal/crypto/ed25519_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "gtest/gtest.h"
#include "absl/strings/escaping.h"

namespace crypto {
namespace nearby::crypto {
namespace {

using ::absl::StatusCode;
Expand Down Expand Up @@ -211,4 +211,4 @@ TEST(Ed25519SignerVerifierTest, NewKeypairFromRandomSeedRoundtrip) {
}

} // namespace
} // namespace crypto
} // namespace nearby::crypto
4 changes: 2 additions & 2 deletions internal/crypto_cros/aead.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "internal/crypto_cros/openssl_util.h"
#include <openssl/aead.h>

namespace crypto {
namespace nearby::crypto {

Aead::Aead(AeadAlgorithm algorithm) {
EnsureOpenSSLInit();
Expand Down Expand Up @@ -186,4 +186,4 @@ bool Aead::Open(absl::Span<const uint8_t> plaintext,
return true;
}

} // namespace crypto
} // namespace nearby::crypto
4 changes: 2 additions & 2 deletions internal/crypto_cros/aead.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "internal/crypto_cros/crypto_export.h"
#include <openssl/base.h>

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
Expand Down Expand Up @@ -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_
2 changes: 2 additions & 0 deletions internal/crypto_cros/aead_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "gtest/gtest.h"

namespace nearby {
namespace {

const crypto::Aead::AeadAlgorithm kAllAlgorithms[]{
Expand Down Expand Up @@ -98,3 +99,4 @@ TEST_P(AeadTest, SealOpenWrongKey) {
}

} // namespace
} // namespace nearby
4 changes: 2 additions & 2 deletions internal/crypto_cros/ec_private_key.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <openssl/mem.h>
#include <openssl/pkcs8.h>

namespace crypto {
namespace nearby::crypto {

ECPrivateKey::~ECPrivateKey() = default;

Expand Down Expand Up @@ -186,4 +186,4 @@ bool ECPrivateKey::ExportRawPublicKey(std::string* output) const {

ECPrivateKey::ECPrivateKey() = default;

} // namespace crypto
} // namespace nearby::crypto
4 changes: 2 additions & 2 deletions internal/crypto_cros/ec_private_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "internal/crypto_cros/crypto_export.h"
#include <openssl/base.h>

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.
Expand Down Expand Up @@ -91,6 +91,6 @@ class CRYPTO_EXPORT ECPrivateKey {
bssl::UniquePtr<EVP_PKEY> key_;
};

} // namespace crypto
} // namespace nearby::crypto

#endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_EC_PRIVATE_KEY_H_
3 changes: 3 additions & 0 deletions internal/crypto_cros/ec_private_key_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "gtest/gtest.h"

namespace nearby {
namespace {

void ExpectKeysEqual(const crypto::ECPrivateKey* keypair1,
Expand Down Expand Up @@ -331,3 +332,5 @@ TEST(ECPrivateKeyUnitTest, LoadOldOpenSSLKeyTest) {

EXPECT_TRUE(keypair_openssl);
}

} // namespace nearby
4 changes: 2 additions & 2 deletions internal/crypto_cros/ec_signature_creator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

#include "internal/crypto_cros/ec_signature_creator_impl.h"

namespace crypto {
namespace nearby::crypto {

// static
std::unique_ptr<ECSignatureCreator> ECSignatureCreator::Create(
ECPrivateKey* key) {
return std::make_unique<ECSignatureCreatorImpl>(key);
}

} // namespace crypto
} // namespace nearby::crypto
4 changes: 2 additions & 2 deletions internal/crypto_cros/ec_signature_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,6 +60,6 @@ class CRYPTO_EXPORT ECSignatureCreator {
std::vector<uint8_t>* out_raw_sig) = 0;
};

} // namespace crypto
} // namespace nearby::crypto

#endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_EC_SIGNATURE_CREATOR_H_
4 changes: 2 additions & 2 deletions internal/crypto_cros/ec_signature_creator_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <openssl/evp.h>
#include <openssl/sha.h>

namespace crypto {
namespace nearby::crypto {

ECSignatureCreatorImpl::ECSignatureCreatorImpl(ECPrivateKey* key) : key_(key) {
EnsureOpenSSLInit();
Expand Down Expand Up @@ -80,4 +80,4 @@ bool ECSignatureCreatorImpl::DecodeSignature(
return true;
}

} // namespace crypto
} // namespace nearby::crypto
4 changes: 2 additions & 2 deletions internal/crypto_cros/ec_signature_creator_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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_
4 changes: 4 additions & 0 deletions internal/crypto_cros/ec_signature_creator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<crypto::ECPrivateKey> key_original(
Expand Down Expand Up @@ -59,3 +61,5 @@ TEST(ECSignatureCreatorTest, BasicTest) {
verifier.VerifyUpdate(nearbybase::as_bytes(absl::MakeSpan(data)));
ASSERT_TRUE(verifier.VerifyFinal());
}

} // namespace nearby
4 changes: 2 additions & 2 deletions internal/crypto_cros/encryptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <openssl/aes.h>
#include <openssl/evp.h>

namespace crypto {
namespace nearby::crypto {

namespace {

Expand Down Expand Up @@ -225,4 +225,4 @@ absl::optional<size_t> Encryptor::CryptCTR(bool do_encrypt,
return input.size();
}

} // namespace crypto
} // namespace nearby::crypto
4 changes: 2 additions & 2 deletions internal/crypto_cros/encryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "absl/types/span.h"
#include "internal/crypto_cros/crypto_export.h"

namespace crypto {
namespace nearby::crypto {

class SymmetricKey;

Expand Down Expand Up @@ -105,6 +105,6 @@ class CRYPTO_EXPORT Encryptor {
std::vector<uint8_t> iv_;
};

} // namespace crypto
} // namespace nearby::crypto

#endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_ENCRYPTOR_H_
4 changes: 4 additions & 0 deletions internal/crypto_cros/encryptor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<crypto::SymmetricKey> key(
crypto::SymmetricKey::DeriveKeyFromPasswordUsingPbkdf2(
Expand Down Expand Up @@ -570,3 +572,5 @@ TEST(EncryptorTest, CipherTextNotMultipleOfBlockSize) {
EXPECT_FALSE(
encryptor.Decrypt(absl::string_view(ciphertext.get(), 1), &plaintext));
}

} // namespace nearby
4 changes: 2 additions & 2 deletions internal/crypto_cros/hkdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "internal/crypto_cros/hmac.h"
#include <openssl/digest.h>

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) {
Expand Down Expand Up @@ -62,4 +62,4 @@ std::vector<uint8_t> HkdfSha256(absl::Span<const uint8_t> secret,
return ret;
}

} // namespace crypto
} // namespace nearby::crypto
4 changes: 2 additions & 2 deletions internal/crypto_cros/hkdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -36,6 +36,6 @@ std::vector<uint8_t> HkdfSha256(absl::Span<const uint8_t> secret,
absl::Span<const uint8_t> info,
size_t derived_key_size);

} // namespace crypto
} // namespace nearby::crypto

#endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_HKDF_H_
4 changes: 2 additions & 2 deletions internal/crypto_cros/hmac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -118,4 +118,4 @@ bool HMAC::VerifyTruncated(absl::Span<const uint8_t> data,
return SecureMemEqual(digest.data(), computed_digest, digest.size());
}

} // namespace crypto
} // namespace nearby::crypto
4 changes: 2 additions & 2 deletions internal/crypto_cros/hmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -120,6 +120,6 @@ class CRYPTO_EXPORT HMAC {
std::vector<unsigned char> key_;
};

} // namespace crypto
} // namespace nearby::crypto

#endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_HMAC_H_
4 changes: 4 additions & 0 deletions internal/crypto_cros/hmac_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -376,3 +378,5 @@ TEST(HMACTest, Bytes) {
EXPECT_FALSE(hmac.VerifyTruncated(
data, absl::MakeSpan(calculated_hmac, kSHA256DigestSize / 2)));
}

} // namespace nearby
4 changes: 2 additions & 2 deletions internal/crypto_cros/openssl_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <openssl/crypto.h>
#include <openssl/err.h>

namespace crypto {
namespace nearby::crypto {

void EnsureOpenSSLInit() {
// CRYPTO_library_init may be safely called concurrently.
Expand All @@ -41,4 +41,4 @@ void ClearOpenSSLERRStack() {
ERR_clear_error();
}

} // namespace crypto
} // namespace nearby::crypto
4 changes: 2 additions & 2 deletions internal/crypto_cros/openssl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,6 +98,6 @@ class OpenSSLErrStackTracer {
~OpenSSLErrStackTracer() { ClearOpenSSLERRStack(); }
};

} // namespace crypto
} // namespace nearby::crypto

#endif // THIRD_PARTY_NEARBY_INTERNAL_CRYPTO_OPENSSL_UTIL_H_
4 changes: 2 additions & 2 deletions internal/crypto_cros/rsa_private_key.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <openssl/mem.h>
#include <openssl/rsa.h>

namespace crypto {
namespace nearby::crypto {

// static
std::unique_ptr<RSAPrivateKey> RSAPrivateKey::Create(uint16_t num_bits) {
Expand Down Expand Up @@ -126,4 +126,4 @@ bool RSAPrivateKey::ExportPublicKey(std::vector<uint8_t>* output) const {
return true;
}

} // namespace crypto
} // namespace nearby::crypto
Loading

0 comments on commit 05ae558

Please sign in to comment.