1 /******************************************************************************
3 * Copyright 2018 Google, Inc.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ******************************************************************************/
25 #include "raw_address.h"
30 class AddressObfuscator {
32 static constexpr unsigned int kOctet32Length = 32;
33 using Octet32 = std::array<uint8_t, kOctet32Length>;
34 static AddressObfuscator* GetInstance() {
35 static auto instance = new AddressObfuscator();
40 * Return true if the input salt is valid
42 * - Salt must be non-zero
45 * @return true if the salt is valid
47 static bool IsSaltValid(const Octet32& salt_256bit);
50 * Initialize this obfuscator with necessary parameters
52 * @param salt_256bit a 256 bit salt used to hash the fixed length address
54 void Initialize(const Octet32& salt_256bit);
57 * Return true if Initialize() was called earlier
62 * Obfuscate Bluetooth MAC address into an anonymous ID string
64 * @param address Bluetooth MAC address to be obfuscated
65 * @return the obfuscated MAC address in 256 bit
67 std::string Obfuscate(const RawAddress& address);
70 AddressObfuscator() : salt_256bit_({0}) {}
72 std::recursive_mutex instance_mutex_;
76 } // namespace bluetooth