TizenRT Public API  v2.0 M2
security_common.h
1 /****************************************************************************
2  *
3  * Copyright 2019 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 
19 #ifndef _SECURITY_API_COMMON_H__
20 #define _SECURITY_API_COMMON_H__
21 
22 #include <stdint.h>
23 
24 #define SECURITY_MAX_KEY_BUF 256
25 #define SECURITY_MAX_CERT_BUF 2048
26 #define SECURITY_MAX_SS_BUF 4096
27 #define SECURITY_MAX_BUF SECURITY_MAX_SS_BUF
28 
29 struct security_ctx;
30 typedef struct security_ctx *security_handle;
31 
32 typedef struct _security_data {
33  void *data;
34  unsigned int length;
36 
37 typedef enum {
38  SECURITY_OK,
39 
40  SECURITY_ERROR,
41  SECURITY_ALLOC_ERROR,
42  SECURITY_INVALID_INPUT_PARAMS,
43  SECURITY_INVALID_CERT_INDEX,
44  SECURITY_INVALID_KEY_INDEX,
45  SECURITY_INVALID_BUFFER_SIZE,
46  SECURITY_MUTEX_INIT_ERROR,
47  SECURITY_MUTEX_LOCK_ERROR,
48  SECURITY_MUTEX_UNLOCK_ERROR,
49  SECURITY_MUTEX_FREE_ERROR,
50 
51  SECURITY_WRITE_CERT_ERROR,
52  SECURITY_READ_CERT_ERROR,
53  SECURITY_GET_HASH_ERROR,
54  SECURITY_GET_RANDOM_ERROR,
55  SECURITY_ECDSA_SIGN_ERROR,
56  SECURITY_ECDSA_VERIFY_ERROR,
57  SECURITY_ECDH_COMPUTE_ERROR,
58 
59  SECURITY_KEY_STORAGE_IN_USE,
60  SECURITY_RSC_BUSY,
61  SECURITY_NOT_SUPPORT,
62 } security_error;
63 
64 typedef struct _security_csr {
65  unsigned char issuer_country[128];
66  unsigned char issuer_organization[128];
67  unsigned char issuer_cn[128];
68  unsigned char issuer_keyname[20];
69  unsigned int issuer_algorithm;
70  unsigned char subject_country[128];
71  unsigned char subject_organization[128];
72  unsigned char subject_cn[128];
73  unsigned char subject_keyname[20];
74  unsigned int subject_algorithm;
75  unsigned int serial;
76  unsigned int cert_years;
77 } security_csr;
78 
79 typedef enum {
80  RSASSA_PKCS1_V1_5,
81  RSASSA_PKCS1_PSS_MGF1,
82  RSASSA_UNKNOWN,
83 } security_rsa_mode;
84 
85 typedef enum {
86  ECDSA_BRAINPOOL_P256R1,
87  ECDSA_BRAINPOOL_P384R1,
88  ECDSA_BRAINPOOL_P512R1,
89  ECDSA_SEC_P192R1,
90  ECDSA_SEC_P224R1,
91  ECDSA_SEC_P256R1,
92  ECDSA_SEC_P384R1,
93  ECDSA_SEC_P512R1,
94  ECDSA_UNKNOWN,
95 } security_ecdsa_mode;
96 
97 typedef enum {
98  DH_1024,
99  DH_2048,
100  DH_4096,
101  DH_UNKNOWN,
102 } security_dh_mode;
103 
104 typedef enum {
105  KEY_AES_128,
106  KEY_AES_192,
107  KEY_AES_256,
108  KEY_RSA_1024,
109  KEY_RSA_2048,
110  KEY_RSA_3072,
111  KEY_RSA_4096,
112  KEY_ECC_BRAINPOOL_P256R1,
113  KEY_ECC_BRAINPOOL_P384R1,
114  KEY_ECC_BRAINPOOL_P512R1,
115  KEY_ECC_SEC_P192R1,
116  KEY_ECC_SEC_P224R1,
117  KEY_ECC_SEC_P256R1,
118  KEY_ECC_SEC_P384R1,
119  KEY_ECC_SEC_P512R1,
120  KEY_HMAC_MD5,
121  KEY_HMAC_SHA1,
122  KEY_HMAC_SHA224,
123  KEY_HMAC_SHA256,
124  KEY_HMAC_SHA384,
125  KEY_HMAC_SHA512,
126  KEY_UNKNOWN,
127 } security_key_type;
128 
129 typedef enum {
130  HMAC_MD5,
131  HMAC_SHA1,
132  HMAC_SHA224,
133  HMAC_SHA256,
134  HMAC_SHA384,
135  HMAC_SHA512,
136  HMAC_UNKNOWN,
137 } security_hmac_mode;
138 
139 
140 typedef enum {
141  AES_ECB_NOPAD,
142  AES_ECB_ISO9797_M1,
143  AES_ECB_ISO9797_M2,
144  AES_ECB_PKCS5,
145  AES_ECB_PKCS7,
146  AES_CBC_NOPAD,
147  AES_CBC_ISO9797_M1,
148  AES_CBC_ISO9797_M2,
149  AES_CBC_PKCS5,
150  AES_CBC_PKCS7,
151  AES_CTR,
152  AES_UNKNOWN,
153 } security_aes_mode;
154 
155 typedef enum {
156  HASH_MD5,
157  HASH_SHA1,
158  HASH_SHA224,
159  HASH_SHA256,
160  HASH_SHA384,
161  HASH_SHA512,
162  HASH_UNKNOWN,
163 } security_hash_mode;
164 
165 typedef struct _security_rsa_param {
166  security_rsa_mode rsa_a;
167  security_hash_mode hash_t;
168  security_hash_mode mgf;
169  uint32_t salt_byte_len;
171 
172 typedef struct _security_aes_param {
173  security_aes_mode mode;
174  unsigned char *iv;
175  unsigned int iv_len;
177 
178 typedef struct _security_ecdsa_param {
179  security_ecdsa_mode curve;
180  security_hash_mode hash_t;
182 
183 typedef struct _security_dh_param {
184  security_dh_mode mode;
185  security_data *G;
186  security_data *P;
187  security_data *pubkey;
189 
190 typedef struct _security_ecdh_param {
191  security_ecdsa_mode curve;
192  security_data *pubkey_x;
193  security_data *pubkey_y;
195 
196 #define SEC_DATA_INITIALIZER {NULL, 0}
197 #define SEC_DHPARAM_INITIALIZER {DH_UNKNOWN, NULL, NULL}
198 
201 security_error security_init(security_handle *hnd);
202 security_error security_deinit(security_handle hnd);
203 security_error security_free_data(security_data *data);
204 security_error security_get_status(int *status);
205 
206 #endif // _SECURITY_API_COMMON_H__