mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Refactor Crypto Library
PiperOrigin-RevId: 502942033
This commit is contained in:
committed by
Copybara-Service
parent
df6e8d951f
commit
afb76ee45c
@@ -1,21 +1,5 @@
|
||||
# Copyright 2022 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
cc_library(
|
||||
name = "handshake",
|
||||
name = "crypto",
|
||||
srcs = [
|
||||
"fast_pair_decryption.cc",
|
||||
"fast_pair_encryption.cc",
|
||||
@@ -34,6 +18,7 @@ cc_library(
|
||||
],
|
||||
deps = [
|
||||
"//fastpair/common",
|
||||
"//internal/base:bluetooth_address",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:logging",
|
||||
"@boringssl//:crypto",
|
||||
@@ -50,7 +35,7 @@ cc_test(
|
||||
],
|
||||
shard_count = 1,
|
||||
deps = [
|
||||
":handshake",
|
||||
":crypto",
|
||||
"//internal/platform/implementation/g3", # build_cleaner: keep
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
@@ -65,7 +50,7 @@ cc_test(
|
||||
],
|
||||
shard_count = 1,
|
||||
deps = [
|
||||
":handshake",
|
||||
":crypto",
|
||||
"//internal/platform/implementation/g3", # build_cleaner: keep
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
@@ -80,7 +65,7 @@ cc_test(
|
||||
],
|
||||
shard_count = 1,
|
||||
deps = [
|
||||
":handshake",
|
||||
":crypto",
|
||||
"//internal/platform/implementation/g3", # build_cleaner: keep
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
@@ -95,7 +80,7 @@ cc_test(
|
||||
],
|
||||
shard_count = 1,
|
||||
deps = [
|
||||
":handshake",
|
||||
":crypto",
|
||||
"//fastpair/common",
|
||||
"//internal/platform/implementation/g3", # build_cleaner: keep
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
@@ -112,7 +97,7 @@ cc_test(
|
||||
],
|
||||
shard_count = 1,
|
||||
deps = [
|
||||
":handshake",
|
||||
":crypto",
|
||||
"//internal/platform/implementation/g3", # build_cleaner: keep
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_DECRYPTED_PASSKEY_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_DECRYPTED_PASSKEY_H_
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_DECRYPTED_PASSKEY_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_DECRYPTED_PASSKEY_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <array>
|
||||
|
||||
#include "fastpair/common/constant.h"
|
||||
#include "fastpair/handshake/fast_pair_message_type.h"
|
||||
#include "fastpair/crypto/fast_pair_message_type.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
@@ -42,4 +42,4 @@ struct DecryptedPasskey {
|
||||
} // namespace fastpair
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_DECRYPTED_PASSKEY_H_
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_DECRYPTED_PASSKEY_H_
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "fastpair/handshake/decrypted_passkey.h"
|
||||
#include "fastpair/crypto/decrypted_passkey.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_DECRYPTED_RESPONSE_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_DECRYPTED_RESPONSE_H_
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_DECRYPTED_RESPONSE_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_DECRYPTED_RESPONSE_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <array>
|
||||
|
||||
#include "fastpair/common/constant.h"
|
||||
#include "fastpair/handshake/fast_pair_message_type.h"
|
||||
#include "fastpair/crypto/fast_pair_message_type.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
@@ -44,4 +44,4 @@ struct DecryptedResponse {
|
||||
} // namespace fastpair
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_DECRYPTED_RESPONSE_H_
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_DECRYPTED_RESPONSE_H_
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "fastpair/handshake/decrypted_response.h"
|
||||
#include "fastpair/crypto/decrypted_response.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
+5
-5
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "fastpair/handshake/fast_pair_decryption.h"
|
||||
#include "fastpair/crypto/fast_pair_decryption.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -27,8 +27,8 @@
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "fastpair/common/constant.h"
|
||||
#include "fastpair/handshake/decrypted_passkey.h"
|
||||
#include "fastpair/handshake/decrypted_response.h"
|
||||
#include "fastpair/crypto/decrypted_passkey.h"
|
||||
#include "fastpair/crypto/decrypted_response.h"
|
||||
#include <openssl/aes.h>
|
||||
|
||||
namespace nearby {
|
||||
@@ -43,8 +43,8 @@ std::array<uint8_t, kAesBlockByteSize> FastPairDecryption::DecryptBytes(
|
||||
CHECK(aes_key_was_set == 0) << "Invalid AES key size.";
|
||||
std::array<uint8_t, kAesBlockByteSize> decrypted_bytes;
|
||||
// Encrypted_bytes is less than 16 bytes and can be guaranteed to be a
|
||||
// single block, so we encrypt/decrypt it using AES ECB mode
|
||||
// (Approved by: b/73360609)
|
||||
// single block, so we encrypt/decrypt it using AES ECB mode (Approved by:
|
||||
// b/73360609)
|
||||
AES_decrypt(encrypted_bytes.data(), decrypted_bytes.data(), &aes_key);
|
||||
return decrypted_bytes;
|
||||
}
|
||||
@@ -12,15 +12,15 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_FAST_PAIR_DECRYPTION_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_FAST_PAIR_DECRYPTION_H_
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_FAST_PAIR_DECRYPTION_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_FAST_PAIR_DECRYPTION_H_
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "fastpair/handshake/decrypted_passkey.h"
|
||||
#include "fastpair/handshake/decrypted_response.h"
|
||||
#include "fastpair/crypto/decrypted_passkey.h"
|
||||
#include "fastpair/crypto/decrypted_response.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
+2
-2
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "fastpair/handshake/fast_pair_decryption.h"
|
||||
#include "fastpair/crypto/fast_pair_decryption.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "fastpair/handshake/fast_pair_encryption.h"
|
||||
#include "fastpair/crypto/fast_pair_encryption.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
+3
-3
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "fastpair/handshake/fast_pair_encryption.h"
|
||||
#include "fastpair/crypto/fast_pair_encryption.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -29,8 +29,8 @@
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "fastpair/common/constant.h"
|
||||
#include "fastpair/handshake/fast_pair_key_pair.h"
|
||||
#include "fastpair/handshake/fast_pair_message_type.h"
|
||||
#include "fastpair/crypto/fast_pair_key_pair.h"
|
||||
#include "fastpair/crypto/fast_pair_message_type.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/base.h>
|
||||
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_FAST_PAIR_ENCRYPTION_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_FAST_PAIR_ENCRYPTION_H_
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_FAST_PAIR_ENCRYPTION_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_FAST_PAIR_ENCRYPTION_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "fastpair/common/constant.h"
|
||||
#include "fastpair/handshake/fast_pair_key_pair.h"
|
||||
#include "fastpair/crypto/fast_pair_key_pair.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
@@ -43,4 +43,4 @@ class FastPairEncryption {
|
||||
} // namespace fastpair
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_FAST_PAIR_ENCRYPTION_H_
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_FAST_PAIR_ENCRYPTION_H_
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "fastpair/handshake/fast_pair_encryption.h"
|
||||
#include "fastpair/crypto/fast_pair_encryption.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_FAST_PAIR_KEY_PAIR_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_FAST_PAIR_KEY_PAIR_H_
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_FAST_PAIR_KEY_PAIR_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_FAST_PAIR_KEY_PAIR_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -43,4 +43,4 @@ struct KeyPair {
|
||||
} // namespace fastpair
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_FAST_PAIR_KEY_PAIR_H_
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_FAST_PAIR_KEY_PAIR_H_
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "fastpair/handshake/fast_pair_key_pair.h"
|
||||
#include "fastpair/crypto/fast_pair_key_pair.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
+3
-3
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_FAST_PAIR_MESSAGE_TYPE_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_FAST_PAIR_MESSAGE_TYPE_H_
|
||||
#ifndef THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_FAST_PAIR_MESSAGE_TYPE_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_FAST_PAIR_MESSAGE_TYPE_H_
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
@@ -35,4 +35,4 @@ enum class FastPairMessageType {
|
||||
} // namespace fastpair
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_HANDSHAKE_FAST_PAIR_MESSAGE_TYPE_H_
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_CRYPTO_FAST_PAIR_MESSAGE_TYPE_H_
|
||||
Reference in New Issue
Block a user