replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / sample / hw_emul / ss_emul.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 SS_EMUL_H\r
21 #define SS_EMUL_H\r
22 \r
23 #include <mbedtls/ssl.h>\r
24 \r
25 #ifdef __cplusplus\r
26 extern "C" {\r
27 #endif\r
28 \r
29 /**\r
30  * Type define\r
31  */\r
32  enum SSE_KEY_TYPE\r
33  {\r
34      KEYTYPE_NONE = -1,\r
35      KEYTYPE_RSA,\r
36      KEYTYPE_ECC\r
37  };\r
38 \r
39 /**\r
40  * This function set own certificate file and key file path to use hw emulation\r
41  *\r
42  * @param[in] cert_filepath  path for own certificate file\r
43  * @param[in] key_filepath  path for private key file\r
44  * @param[in] pwd  password for private key file\r
45  * @return  0 on success, otherwise a negative value\r
46  */\r
47 int SSemulSetCertkeyFilepath(const char* cert_filepath,\r
48                                             const char* key_filepath, const char* pwd);\r
49 \r
50 /**\r
51  * This function get type of stored key from hw emulation\r
52  *\r
53  * @param[in] keyContext  key context object that identifies proper certificate chain\r
54  * @return  SSE_KEY_TYPE\r
55  */\r
56 int SSemulGetKeytype(const void* keyContext);\r
57 \r
58 /**\r
59  * This function load own certificate data from hw emulation\r
60  *\r
61  * @param[in] keyContext  key context object that identifies proper certificate chain\r
62  * @param[out] cert_chain  certificate chain in binary\r
63  * @param[out] cert_chain_len  total length of certificate chain\r
64  * @return  0 on success, otherwise a negative value\r
65  */\r
66 int SSemulLoadOwncert(const void* keyContext,\r
67                                            uint8_t** cert_chain, size_t* cert_chain_len);\r
68 \r
69 /**\r
70  * This function get private key length from hw emulation\r
71  *\r
72  * @param[in] keyContext  key context object that identifies proper certificate chain\r
73  * @return  positive value on success, otherwise a negative value or zero\r
74  */\r
75 int SSemulGetKeylen(const void* keyContext);\r
76 \r
77 /**\r
78  * This function sign hash data with RSA private key from hw emulation\r
79  *\r
80  * @param[in] keyContext  key context object that identifies proper certificate chain\r
81  * @param[in] f_rng  RNG function\r
82  * @param[in] p_rng  RNG parameter\r
83  * @param[in] mode  RSA key mode\r
84  * @param[in] md_alg  md algorithm\r
85  * @param[in] hashlen  length of hash\r
86  * @param[in] hash  hash data to be signed\r
87  * @param[in] sig  signature of hash\r
88  * @return  0 on success, otherwise a negative value\r
89  */\r
90 int SSemulRsaSign(const void *keyContext,\r
91                             int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,\r
92                             int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,\r
93                             const unsigned char *hash, unsigned char *sig );\r
94 \r
95 /**\r
96  * This function sign hash data with ECC private key from hw emulation\r
97  *\r
98  * @param[in] ctx  key context poniter of mbedtls_pk_context\r
99  * @param[in] md_alg  md algorithm\r
100  * @param[in] hash  hash data to be signed\r
101  * @param[in] hashlen  length of hash\r
102  * @param[in] sig  signature of hash\r
103  * @param[in] sig_len  length of signature\r
104  * @param[in] f_rng  RNG function\r
105  * @param[in] p_rng  RNG parameter\r
106  * @return  0 on success, otherwise a negative value\r
107  */\r
108 int SSemulEcdsaSign( void *ctx, mbedtls_md_type_t md_alg,\r
109                    const unsigned char *hash, size_t hash_len,\r
110                    unsigned char *sig, size_t *sig_len,\r
111                    int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );\r
112 \r
113 #ifdef __cplusplus\r
114 }\r
115 #endif\r
116 \r
117 #endif // SS_EMUL_H\r
118 \r
119 \r