1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/*
* Copyright (C) 2017-2022 Alibaba Group Holding Limited
*/
/******************************************************************************
* @file sec_crypt0_des.h
* @brief Header File for DES
* @version V1.0
* @date 24. Oct 2022
* @model des
******************************************************************************/
#ifndef _SC_DES_H_
#define _SC_DES_H_
#include "sec_include_config.h"
#include <stdint.h>
#include "sec_crypto_errcode.h"
#ifdef CONFIG_SYSTEM_SECURE
#ifdef SEC_LIB_VERSION
#include <drv/des.h>
#else
#include "des.h"
#endif
#endif
#ifdef CONFIG_SEC_CRYPTO_DES_SW
#include "crypto_des.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
\brief DES data transfer mode config
*/
typedef enum {
SC_DES_SLAVE_MODE = 0U, ///< slave mode
SC_DES_DMA_MODE, ///< dma mode
} sc_des_trans_mode_t;
/**
\brief DES key-len-bits type
*/
typedef enum {
SC_DES_KEY_LEN_BITS_64 = 0U, ///< 64 Data bits
SC_DES_KEY_LEN_BITS_128, ///< 128 Data bits
SC_TDES_KEY_LEN_BITS_192, ///< 192 Data bits
} sc_des_key_bits_t;
/**
\brief DES Ctrl Block
*/
typedef struct {
#ifdef CONFIG_SYSTEM_SECURE
#ifdef CONFIG_CSI_V1
des_handle_t handle;
unsigned char key[32];
unsigned int key_len;
#endif
#ifdef CONFIG_CSI_V2
csi_des_t csi_des;
//unsigned char sc_ctx[SC_DES_CTX_SIZE];
#endif
#endif
#if defined(CONFIG_TEE_CA)
unsigned char key[32];
unsigned int key_len;
#endif
#if defined(CONFIG_SEC_CRYPTO_DES_SW)
sc_mbedtls_des_context des_ctx;
#endif
//void *ctx;
} sc_des_t;
// Function documentation
/**
\brief Initialize DES Interface. Initializes the resources needed for the DES interface
\param[in] des operate handle
\param[in] idx device id
\return error code \ref uint32_t
*/
uint32_t sc_des_init(sc_des_t *des, uint32_t idx);
/**
\brief De-initialize DES Interface. stops operation and releases the software resources used by the interface
\param[in] des handle to operate
\return None
*/
void sc_des_uninit(sc_des_t *des);
/**
\brief Set encrypt key
\param[in] des handle to operate
\param[in] key Pointer to the key buf
\param[in] key_len Pointer to \ref sc_des_key_bits_t
\return error code \ref uint32_t
*/
uint32_t sc_des_set_encrypt_key(sc_des_t *des, void *key, sc_des_key_bits_t key_len);
/**
\brief Set decrypt key
\param[in] des handle to operate
\param[in] key Pointer to the key buf
\param[in] key_len Pointer to \ref sc_des_key_bits_t
\return error code \ref uint32_t
*/
uint32_t sc_des_set_decrypt_key(sc_des_t *des, void *key, sc_des_key_bits_t key_len);
/**
\brief Des ecb encrypt
\param[in] des handle to operate
\param[in] in Pointer to the Source data
\param[out] out Pointer to the Result data
\param[in] size the Source data size
\return error code \ref uint32_t
*/
uint32_t sc_des_ecb_encrypt(sc_des_t *des, void *in, void *out, uint32_t size);
/**
\brief Des ecb decrypt
\param[in] des handle to operate
\param[in] in Pointer to the Source data
\param[out] out Pointer to the Result data
\param[in] size the Source data size
\return error code \ref uint32_t
*/
uint32_t sc_des_ecb_decrypt(sc_des_t *des, void *in, void *out, uint32_t size);
/**
\brief Des cbc encrypt
\param[in] des handle to operate
\param[in] in Pointer to the Source data
\param[out] out Pointer to the Result data
\param[in] size the Source data size
\param[in] iv init vector
\return error code \ref uint32_t
*/
uint32_t sc_des_cbc_encrypt(sc_des_t *des, void *in, void *out, uint32_t size, void *iv);
/**
\brief Des cbc decrypt
\param[in] des handle to operate
\param[in] in Pointer to the Source data
\param[out] out Pointer to the Result data
\param[in] size the Source data size
\param[in] iv init vector
\return error code \ref uint32_t
*/
uint32_t sc_des_cbc_decrypt(sc_des_t *des, void *in, void *out, uint32_t size, void *iv);
/**
\brief TDes ecb encrypt
\param[in] des handle to operate
\param[in] in Pointer to the Source data
\param[out] out Pointer to the Result data
\param[in] size the Source data size
\return error code \ref uint32_t
*/
uint32_t sc_tdes_ecb_encrypt(sc_des_t *des, void *in, void *out, uint32_t size);
/**
\brief TDes ecb decrypt
\param[in] des handle to operate
\param[in] in Pointer to the Source data
\param[out] out Pointer to the Result data
\param[in] size the Source data size
\return error code \ref uint32_t
*/
uint32_t sc_tdes_ecb_decrypt(sc_des_t *des, void *in, void *out, uint32_t size);
/**
\brief TDes cbc encrypt
\param[in] des handle to operate
\param[in] in Pointer to the Source data
\param[out] out Pointer to the Result data
\param[in] size the Source data size
\param[in] iv init vector
\return error code \ref uint32_t
*/
uint32_t sc_tdes_cbc_encrypt(sc_des_t *des, void *in, void *out, uint32_t size, void *iv);
/**
\brief TDes cbc decrypt
\param[in] des handle to operate
\param[in] in Pointer to the Source data
\param[out] out Pointer to the Result data
\param[in] size the Source data size
\param[in] iv init vector
\return error code \ref uint32_t
*/
uint32_t sc_tdes_cbc_decrypt(sc_des_t *des, void *in, void *out, uint32_t size, void *iv);
/**
\brief Config DES mode dma or slave
\param[in] mode \ref sc_des_trans_mode_t
\return None
*/
void sc_des_trans_config(sc_des_t *des, sc_des_trans_mode_t mode) ;
#ifdef __cplusplus
}
#endif
#endif /* _SC_DES_H_ */
|