Home | History | Annotate | Download | only in keymasterV4_0
      1 /*
      2  * Copyright (C) 2018 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 HARDWARE_INTERFACES_KEYMASTER_40_SUPPORT_KEYMASTER_UTILS_H_
     18 #define HARDWARE_INTERFACES_KEYMASTER_40_SUPPORT_KEYMASTER_UTILS_H_
     19 
     20 #include <android/hardware/keymaster/4.0/types.h>
     21 
     22 namespace android {
     23 namespace hardware {
     24 namespace keymaster {
     25 namespace V4_0 {
     26 
     27 /**
     28  * Define a lexicographical ordering on HmacSharingParameters.  The parameters to
     29  * IKeymasterDevice::computeSharedHmac are required to be delivered in the order specified by this
     30  * comparison operator.
     31  */
     32 bool operator<(const HmacSharingParameters& a, const HmacSharingParameters& b);
     33 
     34 namespace support {
     35 
     36 inline static hidl_vec<uint8_t> blob2hidlVec(const uint8_t* data, const size_t length) {
     37     hidl_vec<uint8_t> result(data, data + length);
     38     return result;
     39 }
     40 
     41 inline static hidl_vec<uint8_t> blob2hidlVec(const std::string& value) {
     42     hidl_vec<uint8_t> result(reinterpret_cast<const uint8_t*>(value.data()),
     43                              reinterpret_cast<const uint8_t*>(value.data()) + value.size());
     44     return result;
     45 }
     46 
     47 inline static hidl_vec<uint8_t> blob2hidlVec(const std::vector<uint8_t>& blob) {
     48     hidl_vec<uint8_t> result(blob.data(), blob.data() + static_cast<size_t>(blob.size()));
     49     return result;
     50 }
     51 
     52 HardwareAuthToken hidlVec2AuthToken(const hidl_vec<uint8_t>& buffer);
     53 hidl_vec<uint8_t> authToken2HidlVec(const HardwareAuthToken& token);
     54 
     55 }  // namespace support
     56 }  // namespace V4_0
     57 }  // namespace keymaster
     58 }  // namespace hardware
     59 }  // namespace android
     60 
     61 #endif  // HARDWARE_INTERFACES_KEYMASTER_40_SUPPORT_KEYMASTER_UTILS_H_
     62