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 #define ECC_PK_LEN 32 25 26 #define CAL_ARRAY_SIZE(arr) ((sizeof(arr)) / (sizeof((arr)[0]))) 27 28 #define CHECK_LEN_ZERO_RETURN_ERROR_CODE(len, paramTag) \ 29 do { \ 30 if ((len) == 0) { \ 31 LOGE("%s is invalid length.", (paramTag)); \ 32 return HAL_ERR_INVALID_LEN; \ 33 } \ 34 } while (0) 35 36 #define CHECK_PTR_RETURN_HAL_ERROR_CODE(ptr, paramTag) \ 37 do { \ 38 if ((ptr) == NULL) { \ 39 LOGE("%s is null.", (paramTag)); \ 40 return HAL_ERR_NULL_PTR; \ 41 } \ 42 } while (0) 43 44 #define CHECK_LEN_LOWER_RETURN(len, min, paramTag) \ 45 do { \ 46 if ((len) < (min)) { \ 47 LOGE("%s is invalid length.", (paramTag)); \ 48 return HAL_ERR_INVALID_LEN; \ 49 } \ 50 } while (0) 51 52 #define CHECK_LEN_HIGHER_RETURN(len, max, paramTag) \ 53 do { \ 54 if ((len) > (max)) { \ 55 LOGE("%s is invalid length.", (paramTag)); \ 56 return HAL_ERR_INVALID_LEN; \ 57 } \ 58 } while (0) 59 60 #define CHECK_LEN_EQUAL_RETURN(len, value, paramTag) \ 61 do { \ 62 if ((len) != (value)) { \ 63 LOGE("%s is invalid length.", (paramTag)); \ 64 return HAL_ERR_INVALID_LEN; \ 65 } \ 66 } while (0) 67 68 struct KeyRoleInfo { 69 uint8_t userType; 70 uint8_t pairType; 71 uint8_t reserved1; 72 uint8_t reserved2; 73 }; 74 75 union KeyRoleInfoUnion { 76 struct KeyRoleInfo roleInfoStruct; 77 uint32_t roleInfo; 78 }; 79 80 #ifdef __cplusplus 81 extern "C" { 82 #endif 83 84 const AlgLoader *GetRealLoaderInstance(void); 85 86 #ifdef __cplusplus 87 } 88 #endif 89 #endif 90