replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / sample / hw_emul / hw_interface.h
1 /* *****************************************************************\r
2  *\r
3  * Copyright 2017 Samsung Electronics All Rights Reserved.\r
4  *\r
5  *\r
6  *\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *     http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  *\r
19  * *****************************************************************/\r
20 #ifndef HW_INTERFACE_H\r
21 #define HW_INTERFACE_H\r
22 \r
23 #include <mbedtls/ssl.h>\r
24 #include "ss_emul.h"\r
25 \r
26 #ifdef __cplusplus\r
27 extern "C" {\r
28 #endif\r
29 \r
30 \r
31 /**\r
32  * Error-definition for hw interface\r
33  */\r
34 \r
35 typedef enum HwifResult\r
36 {\r
37     HWIF_ERR_INVALID_PARAM    = -100, /**< Invalid Paramter */\r
38     HWIF_ERR_OUT_OF_MEMORY   = -99,  /**< Out of memory */\r
39     HWIF_ERR_NO_DATA                = -98,  /**< No data found */\r
40     HWIF_ERROR         = -1,  /**< Internal Error */\r
41     HWIF_SUCCESS     = 0,    /**< No Error */\r
42 } HwifResult_t;\r
43 \r
44 \r
45 /**\r
46  * This callback will be invoked to get a key context based on specific name indication\r
47  * (service name, key usage, key type). The key context may be same with the alias name.\r
48  *\r
49  * @param[in] service  service name indicates first category name\r
50  * @param[in] usage  usage name indicates sub-category name\r
51  * @param[in] keytype  (optional) key type name indication if any, otherwise it usually will be NULL\r
52  * @return  void type pointer value on success, otherwise NULL\r
53  */\r
54 void* HWGetKeyContext(const char* service, const char* usage, const char* keytype);\r
55 \r
56 /**\r
57  * This callback will deallocate the key context that was retrieved from TZ\r
58  * by calling GetHwKeyContext callback.\r
59  *\r
60  * @param[in] keyContext  key context object to be deallocated,\r
61  *                   which was obtained from GetHwKeyContext callback function\r
62  * @return  0 on success, otherwise a negative value\r
63  */\r
64 int HWFreeKeyContext(void* keyContext);\r
65 \r
66 /**\r
67  * This callback will be invoked to load own(i.e., pre-injected) certificate from HW(e.g., TZ, eSE)\r
68  *\r
69  * @param[in] keyContext  key context object that identifies proper certificate chain\r
70  * @param[out] cert_chain  certificate chain in binary\r
71  * @param[out] cert_chain_len  total length of certificate chain\r
72  * @return  0 on success, otherwise a negative value\r
73  */\r
74 int HWGetOwnCertificateChain(const void* keyContext,\r
75                     unsigned char** cert_chain, size_t* cert_chain_len);\r
76 \r
77 /**\r
78  * This callback should provide setting up alternative functions (e.g., rsa_sign, key_len, etc)\r
79  * of which HW(e.g., TZ, eSE) management library to the specified mbedtls context\r
80  * that will be used during handshake.\r
81  *\r
82  * @param[in] ctx  pointer of pk context of mbedtls\r
83  * @param[in] keyContext  key context object that identifies proper public/private key\r
84  * @return  0 on success, otherwise a negative value\r
85  */\r
86 int HWSetupPkContext(mbedtls_pk_context* ctx, void* key_context);\r
87 \r
88 #ifdef __cplusplus\r
89 }\r
90 #endif\r
91 \r
92 #endif // HW_INTERFACE_H\r
93 \r