1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HUKS_ADAPTER_H 17 #define HUKS_ADAPTER_H 18 19 #include "alg_defs.h" 20 #include "hal_error.h" 21 #include "hc_types.h" 22 23 #define BITS_PER_BYTE 8 24 25 #define CAL_ARRAY_SIZE(arr) ((sizeof(arr)) / (sizeof((arr)[0]))) 26 27 #define CHECK_LEN_ZERO_RETURN_ERROR_CODE(len, paramTag) \ 28 do { \ 29 if ((len) == 0) { \ 30 LOGE("%s is invalid length.", (paramTag)); \ 31 return HAL_ERR_INVALID_LEN; \ 32 } \ 33 } while (0) 34 35 #define CHECK_PTR_RETURN_HAL_ERROR_CODE(ptr, paramTag) \ 36 do { \ 37 if ((ptr) == NULL) { \ 38 LOGE("%s is null.", (paramTag)); \ 39 return HAL_ERR_NULL_PTR; \ 40 } \ 41 } while (0) 42 43 #define CHECK_LEN_LOWER_RETURN(len, min, paramTag) \ 44 do { \ 45 if ((len) < (min)) { \ 46 LOGE("%s is invalid length.", (paramTag)); \ 47 return HAL_ERR_INVALID_LEN; \ 48 } \ 49 } while (0) 50 51 #define CHECK_LEN_HIGHER_RETURN(len, max, paramTag) \ 52 do { \ 53 if ((len) > (max)) { \ 54 LOGE("%s is invalid length.", (paramTag)); \ 55 return HAL_ERR_INVALID_LEN; \ 56 } \ 57 } while (0) 58 59 #define CHECK_LEN_EQUAL_RETURN(len, value, paramTag) \ 60 do { \ 61 if ((len) != (value)) { \ 62 LOGE("%s is invalid length.", (paramTag)); \ 63 return HAL_ERR_INVALID_LEN; \ 64 } \ 65 } while (0) 66 67 struct KeyRoleInfo { 68 uint8_t userType; 69 uint8_t pairType; 70 uint8_t reserved1; 71 uint8_t reserved2; 72 }; 73 74 union KeyRoleInfoUnion { 75 struct KeyRoleInfo roleInfoStruct; 76 uint32_t roleInfo; 77 }; 78 79 #ifdef __cplusplus 80 extern "C" { 81 #endif 82 83 const AlgLoader *GetRealLoaderInstance(void); 84 85 #ifdef __cplusplus 86 } 87 #endif 88 #endif 89