1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 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 * Description: crypto errno header. \n 16 * 17 * History: \n 18 * 2023-03-22, Create file. \n 19 */ 20 #ifndef CRYPTO_ERRNO_H 21 #define CRYPTO_ERRNO_H 22 23 /** 24 * The Struction of Error Number is as follows: 25 * Env(4 bits) | Layer(4 bits) | Modules(4 bits) | Reserved(12 bits) | Error Code(8 bits) 26 **/ 27 28 /* Error for Environments Definition. */ 29 #define ERROR_ENV_LINUX 0x1 30 #define ERROR_ENV_ITRUSTEE 0x2 31 #define ERROR_ENV_OPTEE 0x3 32 #define ERROR_ENV_LITEOS 0x4 33 #define ERROR_ENV_SELITEOS 0x5 34 #define ERROR_ENV_NOOS 0x6 35 #define ERROR_ENV_FREERTOS 0x7 36 #define ERROR_ENV_ALIOS 0x8 37 38 /* Error for Layer Enumerations. */ 39 enum { 40 ERROR_LAYER_UAPI = 0x1, 41 ERROR_LAYER_DISPATCH, 42 ERROR_LAYER_KAPI, 43 ERROR_LAYER_DRV, 44 ERROR_LAYER_HAL, 45 }; 46 47 /* Error for Module Enumerations. */ 48 enum { 49 ERROR_MODULE_SYMC = 0x1, 50 ERROR_MODULE_HASH, 51 ERROR_MODULE_PKE, 52 ERROR_MODULE_TRNG, 53 ERROR_MODULE_KM, 54 ERROR_MODULE_OTHER 55 }; 56 57 /* Error for Error Code Enumerations. */ 58 enum { 59 /* Common Error Code. 0x00 ~ 0x3F. */ 60 ERROR_INVALID_PARAM = 0x0, /* return when the input param's value is not in the valid range. */ 61 ERROR_PARAM_IS_NULL, /* return when the input param is NULL and required not NULL. */ 62 ERROR_NOT_INIT, /* return when call other functions before call init function. */ 63 ERROR_UNSUPPORT, /* return when some configuration is unsupport. */ 64 ERROR_UNEXPECTED, /* reture when unexpected error occurs. */ 65 ERROR_CHN_BUSY, /* return when try to create one channel but all channels are busy. */ 66 ERROR_CTX_CLOSED, /* return when using one ctx to do something but has been closed. */ 67 ERROR_NOT_SET_CONFIG, /* return when not set_config but need for symc. */ 68 ERROR_NOT_ATTACHED, /* return when not attach but need for symc. */ 69 ERROR_NOT_MAC_START, /* return when not mac_start but need for symc. */ 70 ERROR_INVALID_HANDLE, /* return when pass one invalid handle. */ 71 ERROR_GET_PHYS_ADDR, /* return when transfer from virt_addr to phys_addr failed. */ 72 ERROR_SYMC_LEN_NOT_ALIGNED, /* return when length isn't aligned to 16-Byte except CTR/CCM/GCM. */ 73 ERROR_SYMC_ADDR_NOT_ALIGNED, /* return when the phys_addr writing to register is not aligned to 4-Byte. */ 74 ERROR_PKE_RSA_SAME_DATA, /* return when rsa exp_mod, the input is equal to output. */ 75 ERROR_PKE_RSA_CRYPTO_V15_CHECK, /* return when rsa crypto v15 padding check failed. */ 76 ERROR_PKE_RSA_CRYPTO_OAEP_CHECK, /* return when rsa crypto oaep padding check failed. */ 77 ERROR_PKE_RSA_VERIFY_V15_CHECK, /* return when rsa verify v15 padding check failed. */ 78 ERROR_PKE_RSA_VERIFY_PSS_CHECK, /* return when rsa verify pss padding check failed. */ 79 ERROR_PKE_RSA_GEN_KEY, /* return when rsa generate key failed. */ 80 81 ERROR_PKE_ECDSA_VERIFY_CHECK, /* return when ecdsa verify check failed. */ 82 /* Outer's Error Code. 0x40 ~ 0x5F. */ 83 ERROR_MEMCPY_S = 0x40, /* return when call memcpy_s failed. */ 84 ERROR_MALLOC, /* return when call xxx_malloc failed. */ 85 ERROR_MUTEX_INIT, /* return when call xxx_mutex_init failed. */ 86 ERROR_MUTEX_LOCK, /* return when call xxx_lock failed. */ 87 /* Specific Error Code for UAPI. 0x60 ~ 0x6F. */ 88 ERROR_DEV_OPEN_FAILED, /* return when open dev failed. */ 89 ERROR_COUNT_OVERFLOW, /* return when call init too many times. */ 90 91 /* Specific Error Code for Dispatch. 0x70 ~ 0x7F. */ 92 ERROR_CMD_DISMATCH = 0x70, /* return when cmd is dismatched. */ 93 ERROR_COPY_FROM_USER, /* return when call copy_from_user failed. */ 94 ERROR_COPY_TO_USER, /* return when call copy_to_user failed. */ 95 ERROR_MEM_HANDLE_GET, /* return when parse user's mem handle to kernel's mem handle failed. */ 96 ERROR_GET_OWNER, /* return when call crypto_get_owner failed. */ 97 98 /* Specific Error Code for KAPI. 0x80 ~ 0x8F. */ 99 ERROR_PROCESS_NOT_INIT = 0x80, /* return when one process not call kapi_xxx_init first. */ 100 ERROR_MAX_PROCESS, /* return when process's num is over the limit. */ 101 ERROR_MEMORY_ACCESS, /* return when access the memory that does not belong to itself. */ 102 ERROR_INVALID_PROCESS, /* return when the process accesses resources of other processes. */ 103 /* Specific Error Code for DRV. 0x90 ~ 0x9F. */ 104 105 /* Specific Error Code for HAL. 0xA0 ~ 0xAF. */ 106 ERROR_HASH_LOGIC = 0xA0, /* return when hash logic's error occurs. */ 107 ERROR_PKE_LOGIC, /* return when pke logic's error occurs. */ 108 ERROR_INVALID_CPU_TYPE, /* return when logic get the invalid cpu type. */ 109 ERROR_INVALID_REGISTER_VALUE, /* return when value in register is invalid. */ 110 ERROR_INVALID_PHYS_ADDR, /* return when phys_addr is invalid. */ 111 112 /* Specific Error Code for Timeout. 0xB0 ~ 0xBF. */ 113 ERROR_GET_TRNG_TIMEOUT = 0xB0, /* return when logic get rnd timeout. */ 114 ERROR_HASH_CLEAR_CHN_TIMEOUT, /* return when clear hash channel timeout. */ 115 ERROR_HASH_CALC_TIMEOUT, /* return when hash calculation timeout. */ 116 ERROR_SYMC_CLEAR_CHN_TIMEOUT, /* return when clear symc channel timeout. */ 117 ERROR_SYMC_CALC_TIMEOUT, /* return when symc crypto timeout. */ 118 ERROR_SYMC_GET_TAG_TIMEOUT, /* return when symc get tag timeout. */ 119 ERROR_PKE_LOCK_TIMEOUT, /* return when pke lock timeout. */ 120 ERROR_PKE_WAIT_DONE_TIMEOUT, /* return when pke wait done timeout. */ 121 ERROR_PKE_ROBUST_WARNING, /* return when pke wait done timeout. */ 122 }; 123 124 #define CRYPTO_COMPAT_ERRNO(env, layer, module, err_code) \ 125 ((((env) & 0xF) << 28) | (((layer) & 0xF) << 24) | (((module) & 0xF) << 20) | ((err_code) & 0xFF)) 126 127 /* Notice: you should define CRYPTO_ERROR_ENV as one of ERROR_ENV_XXX before using these macros. */ 128 #define UAPI_COMPAT_ERRNO(module, err_code) \ 129 CRYPTO_COMPAT_ERRNO(CRYPTO_ERROR_ENV, ERROR_LAYER_UAPI, module, err_code) 130 131 #define DISPATCH_COMPAT_ERRNO(module, err_code) \ 132 CRYPTO_COMPAT_ERRNO(CRYPTO_ERROR_ENV, ERROR_LAYER_DISPATCH, module, err_code) 133 134 #define KAPI_COMPAT_ERRNO(module, err_code) \ 135 CRYPTO_COMPAT_ERRNO(CRYPTO_ERROR_ENV, ERROR_LAYER_KAPI, module, err_code) 136 137 #define DRV_COMPAT_ERRNO(module, err_code) \ 138 CRYPTO_COMPAT_ERRNO(CRYPTO_ERROR_ENV, ERROR_LAYER_DRV, module, err_code) 139 140 #define HAL_COMPAT_ERRNO(module, err_code) \ 141 CRYPTO_COMPAT_ERRNO(CRYPTO_ERROR_ENV, ERROR_LAYER_HAL, module, err_code) 142 143 enum { 144 CRYPTO_SUCCESS = 0, 145 CRYPTO_FAILURE = 0xffffffff, 146 }; 147 148 #endif