1 /*
2  * Copyright (c) 2020 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 HKS_ERRNO_H
17 #define HKS_ERRNO_H
18 
19 #include "hks_types.h"
20 
21 /* MBEDTLS_SUCCESS */
22 #define HKS_SUCCESS                         ((int32_t)0)
23 /* MBEDTLS_ERROR_UNKNOWN_ERROR */
24 #define HKS_FAILURE                         ((int32_t)-132)
25 /* MBEDTLS_ERROR_NOT_PERMITTED */
26 #define HKS_ERROR_NOT_PERMITTED             ((int32_t)-133)
27 /* MBEDTLS_ERROR_NOT_SUPPORTED */
28 #define HKS_ERROR_NOT_SUPPORTED             ((int32_t)-134)
29 /* MBEDTLS_ERROR_INVALID_ARGUMENT */
30 #define HKS_ERROR_INVALID_ARGUMENT          ((int32_t)-135)
31 /* MBEDTLS_ERROR_INVALID_HANDLE */
32 #define HKS_ERROR_INVALID_HANDLE            ((int32_t)-136)
33 /* MBEDTLS_ERROR_BAD_STATE */
34 #define HKS_ERROR_BAD_STATE                 ((int32_t)-137)
35 /* MBEDTLS_ERROR_BUFFER_TOO_SMALL */
36 #define HKS_ERROR_BUFFER_TOO_SMALL          ((int32_t)-138)
37 /* MBEDTLS_ERROR_OCCUPIED_SLOT */
38 #define HKS_ERROR_OCCUPIED_SLOT             ((int32_t)-139)
39 /* MBEDTLS_ERROR_EMPTY_SLOT */
40 #define HKS_ERROR_EMPTY_SLOT                ((int32_t)-140)
41 /* MBEDTLS_ERROR_INSUFFICIENT_MEMORY */
42 #define HKS_ERROR_INSUFFICIENT_MEMORY       ((int32_t)-141)
43 /* MBEDTLS_ERROR_INSUFFICIENT_STORAGE */
44 #define HKS_ERROR_INSUFFICIENT_STORAGE      ((int32_t)-142)
45 /* MBEDTLS_ERROR_INSUFFICIENT_CAPACITY */
46 #define HKS_ERROR_INSUFFICIENT_CAPACITY     ((int32_t)-143)
47 /* MBEDTLS_ERROR_COMMUNICATION_FAILURE */
48 #define HKS_ERROR_COMMUNICATION_FAILURE     ((int32_t)-145)
49 /* MBEDTLS_ERROR_STORAGE_FAILURE */
50 #define HKS_ERROR_STORAGE_FAILURE           ((int32_t)-146)
51 /* MBEDTLS_ERROR_HARDWARE_FAILURE */
52 #define HKS_ERROR_HARDWARE_FAILURE          ((int32_t)-147)
53 /* MBEDTLS_ERROR_INSUFFICIENT_ENTROPY */
54 #define HKS_ERROR_INSUFFICIENT_ENTROPY      ((int32_t)-148)
55 /* MBEDTLS_ERROR_INVALID_SIGNATURE */
56 #define HKS_ERROR_INVALID_SIGNATURE         ((int32_t)-149)
57 /* MBEDTLS_ERROR_INVALID_PADDING */
58 #define HKS_ERROR_INVALID_PADDING           ((int32_t)-150)
59 /* MBEDTLS_ERROR_TAMPERING_DETECTED */
60 #define HKS_ERROR_TAMPERING_DETECTED        ((int32_t)-151)
61 /* MBEDTLS_ERROR_DATA_CORRUPT */
62 #define HKS_ERROR_DATA_CORRUPT              ((int32_t)-152)
63 #define HKS_ERROR_MBEDTLS_RANGE_MIN         ((int32_t)-153)
64 
65 /*
66  * Error code for hks
67  * Add new error code before HKS_ERROR_RANGE_MIN
68  * Modify the value of HKS_ERROR_RANGE_MIN when adding an error code
69  * The value of HKS_ERROR_RANGE_MIN = The value of new error code - 1
70  * Such as add HKS_ERROR_XXX(-1015),must modify HKS_ERROR_RANGE_MIN to be -1016
71  */
72 #define HKS_STATUS_OK                       ((int32_t)0)
73 #define HKS_ERROR_NULL_POINTER              ((int32_t)-1000)
74 #define HKS_ERROR_DUPLICATED_REG            ((int32_t)-1001)
75 #define HKS_ERROR_FILE_SIZE_FAIL            ((int32_t)-1002)
76 #define HKS_ERROR_READ_FILE_FAIL            ((int32_t)-1003)
77 #define HKS_ERROR_INVALID_PUBLIC_KEY        ((int32_t)-1004)
78 #define HKS_ERROR_INVALID_PRIVATE_KEY       ((int32_t)-1005)
79 #define HKS_ERROR_INVALID_KEY_INFO          ((int32_t)-1006)
80 #define HKS_ERROR_BUF_TOO_SMALL             ((int32_t)-1007)
81 #define HKS_ERROR_UNKNOWN_ERROR             ((int32_t)-1008)
82 #define HKS_ERROR_ASSERT_FAIL               ((int32_t)-1009)
83 #define HKS_ERROR_KEY_NOT_EXIST             ((int32_t)-1010)
84 #define HKS_ERROR_HASH_NOT_EQUAL            ((int32_t)-1011)
85 #define HKS_ERROR_MALLOC_FAIL               ((int32_t)-1012)
86 #define HKS_ERROR_WRITE_FILE_FAIL           ((int32_t)-1013)
87 #define HKS_ERROR_REMOVE_FILE_FAIL          ((int32_t)-1014)
88 #define HKS_ERROR_INVALID_KEY_FILE          ((int32_t)-1015)
89 #define HKS_ERROR_IPC_INITIAL_FAIL          ((int32_t)-1016)
90 #define HKS_ERROR_GET_KEY_PARAM_FAIL        ((int32_t)-1017)
91 #define HKS_ERROR_AES_ENCRYPT_FAIL          ((int32_t)-1018)
92 #define HKS_ERROR_AES_DECRYPT_FAIL          ((int32_t)-1019)
93 #define HKS_ERROR_SIGN_FAIL                 ((int32_t)-1020)
94 #define HKS_ERROR_VERIFY_FAIL               ((int32_t)-1021)
95 #define HKS_ERROR_EXPORT_FAIL               ((int32_t)-1022)
96 #define HKS_ERROR_IMPORT_FAIL               ((int32_t)-1023)
97 #define HKS_ERROR_WRAP_FAIL                 ((int32_t)-1024)
98 #define HKS_ERROR_UNWRAP_FAIL               ((int32_t)-1025)
99 #define HKS_ERROR_DELETE_FAIL               ((int32_t)-1026)
100 #define HKS_ERROR_GENERATE_ASYM_FAIL        ((int32_t)-1027)
101 #define HKS_ERROR_GENERATE_SYM_FAIL         ((int32_t)-1028)
102 #define HKS_ERROR_KEY_ATTEST_FAIL           ((int32_t)-1029)
103 #define HKS_ERROR_CERT_CHAIN_FAIL           ((int32_t)-1030)
104 #define HKS_ERROR_GET_KEY_LIST_FAIL         ((int32_t)-1031)
105 #define HKS_ERROR_RANGE_MIN                 ((int32_t)-1032)
106 #define HKS_ERROR_CERT_NOT_EXIST            ((int32_t)-1033)
107 #define HKS_ERROR_INVALID_PKI_FILE          ((int32_t)-1034)
108 #define HKS_ERROR_CERT_VERIFY_FAIL          ((int32_t)-1035)
109 #define HKS_ERROR_WB_DECRYPT_FAIL           ((int32_t)-1036)
110 #define HKS_ERROR_EFUSE_WRITE_FAIL          ((int32_t)-1037)
111 #define HKS_ERROR_EFUSE_READ_FAIL           ((int32_t)-1038)
112 #define HKS_ERROR_EFUSE_LOCK_FAIL           ((int32_t)-1039)
113 #define HKS_ERROR_INTERNAL_UNKOWN           ((int32_t)-9999)
114 #define HKS_ERROR_IPC_RANGE_MIN             ((int32_t)65536)
115 #define HKS_ERROR_IPC_RANGE_MAX             ((int32_t)65556)
116 #define HKS_ERROR_PERMISSION_DENIED         ((int32_t)0xFF07)
117 
118 #endif /* HKS_ERRNO_H */
119