blob: ee41ad1aac6e1160dfc6dc22350c3d8853f05c1c [file] [log] [blame]
David Zeuthen81603152020-02-11 22:04:24 -05001/*
2 * Copyright 2019, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_HARDWARE_IDENTITY_UTIL_H
18#define ANDROID_HARDWARE_IDENTITY_UTIL_H
19
20#include <aidl/android/hardware/identity/BnIdentityCredential.h>
21#include <android/hardware/identity/support/IdentityCredentialSupport.h>
22
23#include <map>
24#include <optional>
25#include <set>
26#include <string>
27#include <vector>
28
29#include <cppbor/cppbor.h>
30
31namespace aidl::android::hardware::identity {
32
33using ::std::optional;
34using ::std::string;
35using ::std::vector;
36
37// Returns the hardware-bound AES-128 key.
38const vector<uint8_t>& getHardwareBoundKey();
39
40// Calculates the MAC for |profile| using |storageKey|.
41optional<vector<uint8_t>> secureAccessControlProfileCalcMac(
42 const SecureAccessControlProfile& profile, const vector<uint8_t>& storageKey);
43
44// Checks authenticity of the MAC in |profile| using |storageKey|.
45bool secureAccessControlProfileCheckMac(const SecureAccessControlProfile& profile,
46 const vector<uint8_t>& storageKey);
47
48// Creates the AdditionalData CBOR used in the addEntryValue() HIDL method.
49vector<uint8_t> entryCreateAdditionalData(const string& nameSpace, const string& name,
50 const vector<int32_t> accessControlProfileIds);
51
52vector<uint8_t> byteStringToUnsigned(const vector<int8_t>& value);
53
54vector<int8_t> byteStringToSigned(const vector<uint8_t>& value);
55
56} // namespace aidl::android::hardware::identity
57
58#endif // ANDROID_HARDWARE_IDENTITY_UTIL_H