1 /* *****************************************************************
\r
3 * Copyright 2017 Samsung Electronics All Rights Reserved.
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
19 * *****************************************************************/
\r
20 #ifndef HW_INTERFACE_H
\r
21 #define HW_INTERFACE_H
\r
23 #include <mbedtls/ssl.h>
\r
24 #include "ss_emul.h"
\r
32 * Error-definition for hw interface
\r
35 typedef enum HwifResult
\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
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
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
54 void* HWGetKeyContext(const char* service, const char* usage, const char* keytype);
\r
57 * This callback will deallocate the key context that was retrieved from TZ
\r
58 * by calling GetHwKeyContext callback.
\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
64 int HWFreeKeyContext(void* keyContext);
\r
67 * This callback will be invoked to load own(i.e., pre-injected) certificate from HW(e.g., TZ, eSE)
\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
74 int HWGetOwnCertificateChain(const void* keyContext,
\r
75 unsigned char** cert_chain, size_t* cert_chain_len);
\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
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
86 int HWSetupPkContext(mbedtls_pk_context* ctx, void* key_context);
\r
92 #endif // HW_INTERFACE_H
\r