fast_pair_data_encryptor.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAST_PAIR_DATA_ENCRYPTOR_H_
  5. #define ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAST_PAIR_DATA_ENCRYPTOR_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <array>
  9. #include "ash/services/quick_pair/public/cpp/decrypted_passkey.h"
  10. #include "ash/services/quick_pair/public/cpp/decrypted_response.h"
  11. #include "base/callback.h"
  12. #include "third_party/abseil-cpp/absl/types/optional.h"
  13. inline constexpr int kBlockSizeBytes = 16;
  14. namespace ash {
  15. namespace quick_pair {
  16. // Holds a secret key for a device and has methods to encrypt bytes, decrypt
  17. // response and decrypt passkey.
  18. class FastPairDataEncryptor {
  19. public:
  20. // Encrypts bytes with the stored secret key.
  21. virtual const std::array<uint8_t, kBlockSizeBytes> EncryptBytes(
  22. const std::array<uint8_t, kBlockSizeBytes>& bytes_to_encrypt) = 0;
  23. virtual const absl::optional<std::array<uint8_t, 64>>& GetPublicKey() = 0;
  24. // Decrypt and parse decrypted response bytes with the stored secret key.
  25. virtual void ParseDecryptedResponse(
  26. const std::vector<uint8_t>& encrypted_response_bytes,
  27. base::OnceCallback<void(const absl::optional<DecryptedResponse>&)>
  28. callback) = 0;
  29. // Decrypt and parse decrypted passkey bytes with the stored secret key.
  30. virtual void ParseDecryptedPasskey(
  31. const std::vector<uint8_t>& encrypted_passkey_bytes,
  32. base::OnceCallback<void(const absl::optional<DecryptedPasskey>&)>
  33. callback) = 0;
  34. virtual ~FastPairDataEncryptor() = default;
  35. };
  36. } // namespace quick_pair
  37. } // namespace ash
  38. #endif // ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAST_PAIR_DATA_ENCRYPTOR_H_