1 /***************************************************************************//**
\r
3 * @brief Cryptography accelerator peripheral API
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
\r
8 *******************************************************************************
\r
10 * Permission is granted to anyone to use this software for any purpose,
\r
11 * including commercial applications, and to alter it and redistribute it
\r
12 * freely, subject to the following restrictions:
\r
14 * 1. The origin of this software must not be misrepresented; you must not
\r
15 * claim that you wrote the original software.
\r
16 * 2. Altered source versions must be plainly marked as such, and must not be
\r
17 * misrepresented as being the original software.
\r
18 * 3. This notice may not be removed or altered from any source distribution.
\r
20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
\r
21 * obligation to support this Software. Silicon Labs is providing the
\r
22 * Software "AS IS", with no express or implied warranties of any kind,
\r
23 * including, but not limited to, any implied warranties of merchantability
\r
24 * or fitness for any particular purpose or warranties against infringement
\r
25 * of any proprietary rights of a third party.
\r
27 * Silicon Labs will not be liable for any consequential, incidental, or
\r
28 * special damages, or any other relief, or for any claim by any third party,
\r
29 * arising from your use of this Software.
\r
31 ******************************************************************************/
\r
32 #ifndef __SILICON_LABS_EM_CRYPTO_H__
\r
33 #define __SILICON_LABS_EM_CRYPTO_H__
\r
35 #include "em_device.h"
\r
37 #if defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0)
\r
40 #include <stdbool.h>
\r
46 /***************************************************************************//**
\r
47 * @addtogroup EM_Library
\r
49 ******************************************************************************/
\r
51 /***************************************************************************//**
\r
52 * @addtogroup CRYPTO
\r
54 ******************************************************************************/
\r
56 /*******************************************************************************
\r
57 ****************************** DEFINES ***********************************
\r
58 ******************************************************************************/
\r
60 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
\r
61 /** Data sizes used by CRYPTO operations. */
\r
62 #define CRYPTO_DATA_SIZE_IN_BITS (128)
\r
63 #define CRYPTO_DATA_SIZE_IN_BYTES (CRYPTO_DATA_SIZE_IN_BITS/8)
\r
64 #define CRYPTO_DATA_SIZE_IN_32BIT_WORDS (CRYPTO_DATA_SIZE_IN_BYTES/sizeof(uint32_t))
\r
66 #define CRYPTO_KEYBUF_SIZE_IN_BITS (256)
\r
67 #define CRYPTO_KEYBUF_SIZE_IN_BYTES (CRYPTO_DDATA_SIZE_IN_BITS/8)
\r
68 #define CRYPTO_KEYBUF_SIZE_IN_32BIT_WORDS (CRYPTO_DDATA_SIZE_IN_BYTES/sizeof(uint32_t))
\r
70 #define CRYPTO_DDATA_SIZE_IN_BITS (256)
\r
71 #define CRYPTO_DDATA_SIZE_IN_BYTES (CRYPTO_DDATA_SIZE_IN_BITS/8)
\r
72 #define CRYPTO_DDATA_SIZE_IN_32BIT_WORDS (CRYPTO_DDATA_SIZE_IN_BYTES/sizeof(uint32_t))
\r
74 #define CRYPTO_QDATA_SIZE_IN_BITS (512)
\r
75 #define CRYPTO_QDATA_SIZE_IN_BYTES (CRYPTO_QDATA_SIZE_IN_BITS/8)
\r
76 #define CRYPTO_QDATA_SIZE_IN_32BIT_WORDS (CRYPTO_QDATA_SIZE_IN_BYTES/sizeof(uint32_t))
\r
78 #define CRYPTO_DATA260_SIZE_IN_32BIT_WORDS (9)
\r
80 /** SHA-1 digest sizes */
\r
81 #define CRYPTO_SHA1_DIGEST_SIZE_IN_BITS (160)
\r
82 #define CRYPTO_SHA1_DIGEST_SIZE_IN_BYTES (CRYPTO_SHA1_DIGEST_SIZE_IN_BITS/8)
\r
84 /** SHA-256 digest sizes */
\r
85 #define CRYPTO_SHA256_DIGEST_SIZE_IN_BITS (256)
\r
86 #define CRYPTO_SHA256_DIGEST_SIZE_IN_BYTES (CRYPTO_SHA256_DIGEST_SIZE_IN_BITS/8)
\r
89 * Read and write all 260 bits of DDATA0 when in 260 bit mode.
\r
91 #define CRYPTO_DDATA0_260_BITS_READ(bigint260) CRYPTO_DData0Read260(bigint260)
\r
92 #define CRYPTO_DDATA0_260_BITS_WRITE(bigint260) CRYPTO_DData0Write260(bigint260)
\r
95 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
\r
97 * Instruction sequence load macros CRYPTO_SEQ_LOAD_X (where X is in the range
\r
98 * 1-20). E.g. @ref CRYPTO_SEQ_LOAD_20.
\r
99 * Use these macros in order for faster execution than the function API.
\r
101 #define CRYPTO_SEQ_LOAD_1(a1) { \
\r
102 CRYPTO->SEQ0 = a1 | (CRYPTO_CMD_INSTR_END<<8);}
\r
103 #define CRYPTO_SEQ_LOAD_2(a1, a2) { \
\r
104 CRYPTO->SEQ0 = a1 | (a2<<8) | (CRYPTO_CMD_INSTR_END<<16);}
\r
105 #define CRYPTO_SEQ_LOAD_3(a1, a2, a3) { \
\r
106 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (CRYPTO_CMD_INSTR_END<<24);}
\r
107 #define CRYPTO_SEQ_LOAD_4(a1, a2, a3, a4) { \
\r
108 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
109 CRYPTO->SEQ1 = CRYPTO_CMD_INSTR_END;}
\r
110 #define CRYPTO_SEQ_LOAD_5(a1, a2, a3, a4, a5) { \
\r
111 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
112 CRYPTO->SEQ1 = a5 | (CRYPTO_CMD_INSTR_END<<8);}
\r
113 #define CRYPTO_SEQ_LOAD_6(a1, a2, a3, a4, a5, a6) { \
\r
114 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
115 CRYPTO->SEQ1 = a5 | (a6<<8) | (CRYPTO_CMD_INSTR_END<<16);}
\r
116 #define CRYPTO_SEQ_LOAD_7(a1, a2, a3, a4, a5, a6, a7) { \
\r
117 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
118 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (CRYPTO_CMD_INSTR_END<<24);}
\r
119 #define CRYPTO_SEQ_LOAD_8(a1, a2, a3, a4, a5, a6, a7, a8) { \
\r
120 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
121 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
122 CRYPTO->SEQ2 = CRYPTO_CMD_INSTR_END;}
\r
123 #define CRYPTO_SEQ_LOAD_9(a1, a2, a3, a4, a5, a6, a7, a8, a9) { \
\r
124 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
125 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
126 CRYPTO->SEQ2 = a9 | (CRYPTO_CMD_INSTR_END<<8);}
\r
127 #define CRYPTO_SEQ_LOAD_10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { \
\r
128 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
129 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
130 CRYPTO->SEQ2 = a9 | (a10<<8) | (CRYPTO_CMD_INSTR_END<<16);}
\r
131 #define CRYPTO_SEQ_LOAD_11(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) { \
\r
132 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
133 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
134 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (CRYPTO_CMD_INSTR_END<<24);}
\r
135 #define CRYPTO_SEQ_LOAD_12(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) { \
\r
136 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
137 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
138 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
139 CRYPTO->SEQ3 = CRYPTO_CMD_INSTR_END;}
\r
140 #define CRYPTO_SEQ_LOAD_13(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) { \
\r
141 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
142 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
143 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
144 CRYPTO->SEQ3 = a13 | (CRYPTO_CMD_INSTR_END<<8);}
\r
145 #define CRYPTO_SEQ_LOAD_14(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) { \
\r
146 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
147 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
148 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
149 CRYPTO->SEQ3 = a13 | (a14<<8) | (CRYPTO_CMD_INSTR_END<<16);}
\r
150 #define CRYPTO_SEQ_LOAD_15(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) { \
\r
151 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
152 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
153 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
154 CRYPTO->SEQ3 = a13 | (a14<<8) | (a15<<16) | (CRYPTO_CMD_INSTR_END<<24);}
\r
155 #define CRYPTO_SEQ_LOAD_16(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) { \
\r
156 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
157 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
158 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
159 CRYPTO->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
\r
160 CRYPTO->SEQ4 = CRYPTO_CMD_INSTR_END;}
\r
161 #define CRYPTO_SEQ_LOAD_17(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17) { \
\r
162 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
163 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
164 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
165 CRYPTO->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
\r
166 CRYPTO->SEQ4 = a17 | (CRYPTO_CMD_INSTR_END<<8);}
\r
167 #define CRYPTO_SEQ_LOAD_18(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) { \
\r
168 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
169 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
170 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
171 CRYPTO->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
\r
172 CRYPTO->SEQ4 = a17 | (a18<<8) | (CRYPTO_CMD_INSTR_END<<16);}
\r
173 #define CRYPTO_SEQ_LOAD_19(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) { \
\r
174 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
175 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
176 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
177 CRYPTO->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
\r
178 CRYPTO->SEQ4 = a17 | (a18<<8) | (a19<<16) | (CRYPTO_CMD_INSTR_END<<24);}
\r
179 #define CRYPTO_SEQ_LOAD_20(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) { \
\r
180 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
181 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
182 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
183 CRYPTO->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
\r
184 CRYPTO->SEQ4 = a17 | (a18<<8) | (a19<<16) | (a20<<24);}
\r
187 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
\r
189 * Instruction sequence execution macros CRYPTO_EXECUTE_X (where X is in the range
\r
190 * 1-20). E.g. @ref CRYPTO_EXECUTE_19.
\r
191 * Use these macros in order for faster execution than the function API.
\r
193 #define CRYPTO_EXECUTE_1(a1) { \
\r
194 CRYPTO->SEQ0 = a1 | (CRYPTO_CMD_INSTR_EXEC<<8); }
\r
195 #define CRYPTO_EXECUTE_2(a1, a2) { \
\r
196 CRYPTO->SEQ0 = a1 | (a2<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
\r
197 #define CRYPTO_EXECUTE_3(a1, a2, a3) { \
\r
198 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
\r
199 #define CRYPTO_EXECUTE_4(a1, a2, a3, a4) { \
\r
200 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
201 CRYPTO->SEQ1 = CRYPTO_CMD_INSTR_EXEC; }
\r
202 #define CRYPTO_EXECUTE_5(a1, a2, a3, a4, a5) { \
\r
203 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
204 CRYPTO->SEQ1 = a5 | (CRYPTO_CMD_INSTR_EXEC<<8); }
\r
205 #define CRYPTO_EXECUTE_6(a1, a2, a3, a4, a5, a6) { \
\r
206 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
207 CRYPTO->SEQ1 = a5 | (a6<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
\r
208 #define CRYPTO_EXECUTE_7(a1, a2, a3, a4, a5, a6, a7) { \
\r
209 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
210 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
\r
211 #define CRYPTO_EXECUTE_8(a1, a2, a3, a4, a5, a6, a7, a8) { \
\r
212 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
213 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
214 CRYPTO->SEQ2 = CRYPTO_CMD_INSTR_EXEC; }
\r
215 #define CRYPTO_EXECUTE_9(a1, a2, a3, a4, a5, a6, a7, a8, a9) { \
\r
216 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
217 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
218 CRYPTO->SEQ2 = a9 | (CRYPTO_CMD_INSTR_EXEC<<8); }
\r
219 #define CRYPTO_EXECUTE_10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { \
\r
220 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
221 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
222 CRYPTO->SEQ2 = a9 | (a10<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
\r
223 #define CRYPTO_EXECUTE_11(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) { \
\r
224 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
225 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
226 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
\r
227 #define CRYPTO_EXECUTE_12(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) { \
\r
228 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
229 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
230 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
231 CRYPTO->SEQ3 = CRYPTO_CMD_INSTR_EXEC; }
\r
232 #define CRYPTO_EXECUTE_13(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) { \
\r
233 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
234 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
235 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
236 CRYPTO->SEQ3 = a13 | (CRYPTO_CMD_INSTR_EXEC<<8); }
\r
237 #define CRYPTO_EXECUTE_14(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) { \
\r
238 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
239 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
240 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
241 CRYPTO->SEQ3 = a13 | (a14<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
\r
242 #define CRYPTO_EXECUTE_15(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) { \
\r
243 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
244 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
245 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
246 CRYPTO->SEQ3 = a13 | (a14<<8) | (a15<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
\r
247 #define CRYPTO_EXECUTE_16(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) { \
\r
248 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
249 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
250 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
251 CRYPTO->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
\r
252 CRYPTO->SEQ4 = CRYPTO_CMD_INSTR_EXEC; }
\r
253 #define CRYPTO_EXECUTE_17(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17) { \
\r
254 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
255 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
256 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
257 CRYPTO->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
\r
258 CRYPTO->SEQ4 = a17 | (CRYPTO_CMD_INSTR_EXEC<<8); }
\r
259 #define CRYPTO_EXECUTE_18(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) { \
\r
260 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
261 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
262 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
263 CRYPTO->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
\r
264 CRYPTO->SEQ4 = a17 | (a18<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
\r
265 #define CRYPTO_EXECUTE_19(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) { \
\r
266 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
267 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
268 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
269 CRYPTO->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
\r
270 CRYPTO->SEQ4 = a17 | (a18<<8) | (a19<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
\r
271 #define CRYPTO_EXECUTE_20(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) { \
\r
272 CRYPTO->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
\r
273 CRYPTO->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
\r
274 CRYPTO->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
\r
275 CRYPTO->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
\r
276 CRYPTO->SEQ4 = a17 | (a18<<8) | (a19<<16) | (a20<<24); \
\r
277 CRYPTO_InstructionSequenceExecute();}
\r
280 /*******************************************************************************
\r
281 ****************************** TYPEDEFS ***********************************
\r
282 ******************************************************************************/
\r
285 * CRYPTO data types used for data load functions. This data type is
\r
286 * capable of storing a 128 bits value as used in the crypto DATA
\r
289 typedef uint32_t CRYPTO_Data_TypeDef[CRYPTO_DATA_SIZE_IN_32BIT_WORDS];
\r
292 * CRYPTO data type used for data load functions. This data type
\r
293 * is capable of storing a 256 bits value as used in the crypto DDATA
\r
296 typedef uint32_t CRYPTO_DData_TypeDef[CRYPTO_DDATA_SIZE_IN_32BIT_WORDS];
\r
298 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
\r
299 typedef uint32_t* CRYPTO_DDataPtr_TypeDef;
\r
303 * CRYPTO data type used for data load functions. This data type is
\r
304 * capable of storing a 512 bits value as used in the crypto QDATA
\r
307 typedef uint32_t CRYPTO_QData_TypeDef[CRYPTO_QDATA_SIZE_IN_32BIT_WORDS];
\r
310 * CRYPTO data type used for data load functions. This data type is
\r
311 * capable of storing a 260 bits value as used by the @ref CRYPTO_DData0Write260
\r
314 * Note that this data type is multiple of 32 bit words, so the
\r
315 * actual storage used by this type is 32x9=288 bits.
\r
317 typedef uint32_t CRYPTO_Data260_TypeDef[CRYPTO_DATA260_SIZE_IN_32BIT_WORDS];
\r
320 * CRYPTO data type used for data load functions. This data type is
\r
321 * capable of storing 256 bits as used in the crypto KEYBUF register.
\r
323 typedef uint32_t CRYPTO_KeyBuf_TypeDef[CRYPTO_KEYBUF_SIZE_IN_32BIT_WORDS];
\r
326 * CRYPTO Data registers. These register are used to load 128 bit values as
\r
327 * input and output data for cryptographic and big integer arithmetic
\r
328 * functions of the CRYPTO module.
\r
332 cryptoRegDATA0 = (uint32_t) &CRYPTO->DATA0, /**< 128 bit DATA0 register */
\r
333 cryptoRegDATA1 = (uint32_t) &CRYPTO->DATA1, /**< 128 bit DATA1 register */
\r
334 cryptoRegDATA2 = (uint32_t) &CRYPTO->DATA2, /**< 128 bit DATA2 register */
\r
335 cryptoRegDATA3 = (uint32_t) &CRYPTO->DATA3, /**< 128 bit DATA3 register */
\r
336 cryptoRegDATA0XOR = (uint32_t) &CRYPTO->DATA0XOR, /**< 128 bit DATA0XOR register */
\r
337 } CRYPTO_DataReg_TypeDef;
\r
340 * CRYPTO DData (Double Data) registers. These registers are used to load
\r
341 * 256 bit values as input and output data for cryptographic and big integer
\r
342 * arithmetic functions of the CRYPTO module.
\r
346 cryptoRegDDATA0 = (uint32_t) &CRYPTO->DDATA0, /**< 256 bit DDATA0 register */
\r
347 cryptoRegDDATA1 = (uint32_t) &CRYPTO->DDATA1, /**< 256 bit DDATA1 register */
\r
348 cryptoRegDDATA2 = (uint32_t) &CRYPTO->DDATA2, /**< 256 bit DDATA2 register */
\r
349 cryptoRegDDATA3 = (uint32_t) &CRYPTO->DDATA3, /**< 256 bit DDATA3 register */
\r
350 cryptoRegDDATA4 = (uint32_t) &CRYPTO->DDATA4, /**< 256 bit DDATA4 register */
\r
351 cryptoRegDDATA0BIG = (uint32_t) &CRYPTO->DDATA0BIG, /**< 256 bit DDATA0BIG register, big endian access to DDATA0 */
\r
352 } CRYPTO_DDataReg_TypeDef;
\r
355 * CRYPTO QData (Quad data) registers. These registers are used to load 512 bit
\r
356 * values as input and output data for cryptographic and big integer arithmetic
\r
357 * functions of the CRYPTO module.
\r
361 cryptoRegQDATA0 = (uint32_t) &CRYPTO->QDATA0, /**< 512 bit QDATA0 register */
\r
362 cryptoRegQDATA1 = (uint32_t) &CRYPTO->QDATA1, /**< 512 bit QDATA1 register */
\r
363 cryptoRegQDATA1BIG = (uint32_t) &CRYPTO->QDATA1BIG, /**< 512 bit QDATA1BIG register, big-endian access to QDATA1 */
\r
364 } CRYPTO_QDataReg_TypeDef;
\r
366 /** CRYPTO modulus types. */
\r
369 cryptoModulusBin256 = CRYPTO_WAC_MODULUS_BIN256, /**< Generic 256 bit modulus 2^256 */
\r
370 cryptoModulusBin128 = CRYPTO_WAC_MODULUS_BIN128, /**< Generic 128 bit modulus 2^128 */
\r
371 cryptoModulusGcmBin128 = CRYPTO_WAC_MODULUS_GCMBIN128, /**< GCM 128 bit modulus = 2^128 + 2^7 + 2^2 + 2 + 1 */
\r
372 cryptoModulusEccB233 = CRYPTO_WAC_MODULUS_ECCBIN233P, /**< ECC B233 prime modulus = 2^233 + 2^74 + 1 */
\r
373 cryptoModulusEccB163 = CRYPTO_WAC_MODULUS_ECCBIN163P, /**< ECC B163 prime modulus = 2^163 + 2^7 + 2^6 + 2^3 + 1 */
\r
374 cryptoModulusEccP256 = CRYPTO_WAC_MODULUS_ECCPRIME256P, /**< ECC P256 prime modulus = 2^256 - 2^224 + 2^192 + 2^96 - 1 */
\r
375 cryptoModulusEccP224 = CRYPTO_WAC_MODULUS_ECCPRIME224P, /**< ECC P224 prime modulus = 2^224 - 2^96 - 1 */
\r
376 cryptoModulusEccP192 = CRYPTO_WAC_MODULUS_ECCPRIME192P, /**< ECC P192 prime modulus = 2^192 - 2^64 - 1 */
\r
377 cryptoModulusEccB233Order = CRYPTO_WAC_MODULUS_ECCBIN233N, /**< ECC B233 order modulus */
\r
378 cryptoModulusEccB233KOrder = CRYPTO_WAC_MODULUS_ECCBIN233KN, /**< ECC B233K order modulus */
\r
379 cryptoModulusEccB163Order = CRYPTO_WAC_MODULUS_ECCBIN163N, /**< ECC B163 order modulus */
\r
380 cryptoModulusEccB163KOrder = CRYPTO_WAC_MODULUS_ECCBIN163KN, /**< ECC B163K order modulus */
\r
381 cryptoModulusEccP256Order = CRYPTO_WAC_MODULUS_ECCPRIME256N, /**< ECC P256 order modulus */
\r
382 cryptoModulusEccP224Order = CRYPTO_WAC_MODULUS_ECCPRIME224N, /**< ECC P224 order modulus */
\r
383 cryptoModulusEccP192Order = CRYPTO_WAC_MODULUS_ECCPRIME192N /**< ECC P192 order modulus */
\r
384 } CRYPTO_ModulusType_TypeDef;
\r
386 /** CRYPTO multiplication widths for wide arithmetic operations. */
\r
389 cryptoMulOperand256Bits = CRYPTO_WAC_MULWIDTH_MUL256, /**< 256 bits operands */
\r
390 cryptoMulOperand128Bits = CRYPTO_WAC_MULWIDTH_MUL128, /**< 128 bits operands */
\r
391 cryptoMulOperandModulusBits = CRYPTO_WAC_MULWIDTH_MULMOD /**< MUL operand width
\r
392 is specified by the
\r
394 } CRYPTO_MulOperandWidth_TypeDef;
\r
396 /** CRYPTO result widths for MUL operations. */
\r
399 cryptoResult128Bits = CRYPTO_WAC_RESULTWIDTH_128BIT, /**< Multiplication result width is 128 bits*/
\r
400 cryptoResult256Bits = CRYPTO_WAC_RESULTWIDTH_256BIT, /**< Multiplication result width is 256 bits*/
\r
401 cryptoResult260Bits = CRYPTO_WAC_RESULTWIDTH_260BIT /**< Multiplication result width is 260 bits*/
\r
402 } CRYPTO_ResultWidth_TypeDef;
\r
404 /** CRYPTO result widths for MUL operations. */
\r
407 cryptoInc1byte = CRYPTO_CTRL_INCWIDTH_INCWIDTH1, /**< inc width is 1 byte*/
\r
408 cryptoInc2byte = CRYPTO_CTRL_INCWIDTH_INCWIDTH2, /**< inc width is 2 byte*/
\r
409 cryptoInc3byte = CRYPTO_CTRL_INCWIDTH_INCWIDTH3, /**< inc width is 3 byte*/
\r
410 cryptoInc4byte = CRYPTO_CTRL_INCWIDTH_INCWIDTH4 /**< inc width is 4 byte*/
\r
411 } CRYPTO_IncWidth_TypeDef;
\r
413 /** CRYPTO key width. */
\r
416 cryptoKey128Bits = 8, /**< Key width is 128 bits*/
\r
417 cryptoKey256Bits = 16, /**< Key width is 256 bits*/
\r
418 } CRYPTO_KeyWidth_TypeDef;
\r
421 * The max number of crypto instructions in an instruction sequence
\r
423 #define CRYPTO_MAX_SEQUENCE_INSTRUCTIONS (20)
\r
426 * Instruction sequence type.
\r
427 * The user should fill in the desired operations from step1, then step2 etc.
\r
428 * The CRYPTO_CMD_INSTR_END marks the end of the sequence.
\r
429 * Bit fields are used to format the memory layout of the struct equal to the
\r
430 * sequence registers in the CRYPTO module.
\r
432 typedef uint8_t CRYPTO_InstructionSequence_TypeDef[CRYPTO_MAX_SEQUENCE_INSTRUCTIONS];
\r
434 /** Default instruction sequence consisting of all ENDs. The user can
\r
435 initialize the instruction sequence with this default value set, and fill
\r
436 in the desired operations from step 1. The first END instruction marks
\r
437 the end of the sequence. */
\r
438 #define CRYPTO_INSTRUCTIONSEQUENSE_DEFAULT \
\r
439 {CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
\r
440 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
\r
441 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
\r
442 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
\r
443 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
\r
444 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
\r
445 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END}
\r
447 /** SHA-1 Digest type. */
\r
448 typedef uint8_t CRYPTO_SHA1_Digest_TypeDef[CRYPTO_SHA1_DIGEST_SIZE_IN_BYTES];
\r
450 /** SHA-256 Digest type. */
\r
451 typedef uint8_t CRYPTO_SHA256_Digest_TypeDef[CRYPTO_SHA256_DIGEST_SIZE_IN_BYTES];
\r
455 * AES counter modification function pointer.
\r
458 * This is defined in order for backwards compatibility with EFM32 em_aes.h.
\r
459 * The CRYPTO implementation of Counter mode does not support counter update
\r
462 * @param[in] ctr Counter value to be modified.
\r
464 typedef void (*CRYPTO_AES_CtrFuncPtr_TypeDef)(uint8_t * ctr);
\r
466 /*******************************************************************************
\r
467 ***************************** PROTOTYPES **********************************
\r
468 ******************************************************************************/
\r
470 /***************************************************************************//**
\r
472 * Set the modulus type used for wide arithmetic operations.
\r
475 * This function sets the modulus type to be used by the Modulus instructions
\r
476 * of the CRYPTO module.
\r
478 * @param[in] modType Modulus type.
\r
479 ******************************************************************************/
\r
480 void CRYPTO_ModulusSet(CRYPTO_ModulusType_TypeDef modType);
\r
482 /***************************************************************************//**
\r
484 * Set the number of bits in the operands of the MUL instruction.
\r
487 * This function sets the number of bits to be used in the operands of
\r
488 * the MUL instruction.
\r
490 * @param[in] mulOperandWidth Multiplication width in bits.
\r
491 ******************************************************************************/
\r
492 __STATIC_INLINE void CRYPTO_MulOperandWidthSet(CRYPTO_MulOperandWidth_TypeDef mulOperandWidth)
\r
494 uint32_t temp = CRYPTO->WAC & (~_CRYPTO_WAC_MULWIDTH_MASK);
\r
495 CRYPTO->WAC = temp | mulOperandWidth;
\r
498 /***************************************************************************//**
\r
500 * Set the width of the results of the non-modulus instructions.
\r
503 * This function sets the result width of the non-modulus instructions.
\r
505 * @param[in] resultWidth Result width of non-modulus instructions.
\r
506 ******************************************************************************/
\r
507 __STATIC_INLINE void CRYPTO_ResultWidthSet(CRYPTO_ResultWidth_TypeDef resultWidth)
\r
509 uint32_t temp = CRYPTO->WAC & (~_CRYPTO_WAC_RESULTWIDTH_MASK);
\r
510 CRYPTO->WAC = temp | resultWidth;
\r
513 /***************************************************************************//**
\r
515 * Set the width of the DATA1 increment instruction DATA1INC.
\r
518 * This function sets the width of the DATA1 increment instruction
\r
519 * @ref CRYPTO_CMD_INSTR_DATA1INC.
\r
521 * @param[in] incWidth incrementation width.
\r
522 ******************************************************************************/
\r
523 __STATIC_INLINE void CRYPTO_IncWidthSet(CRYPTO_IncWidth_TypeDef incWidth)
\r
525 uint32_t temp = CRYPTO->CTRL & (~_CRYPTO_CTRL_INCWIDTH_MASK);
\r
526 CRYPTO->CTRL = temp | incWidth;
\r
529 /***************************************************************************//**
\r
531 * Write a 128 bit value into a crypto register.
\r
534 * This function provide a low-level api for writing to the multi-word
\r
535 * registers in the crypto peripheral. Applications should prefer to use
\r
536 * @ref CRYPTO_DataWrite, @ref CRYPTO_DDataWrite or @ref CRYPTO_QDataWrite
\r
537 * for writing to the DATA, DDATA and QDATA registers.
\r
540 * Pointer to the crypto register.
\r
543 * This is a pointer to 4 32 bit integers that contains the 128 bit value
\r
544 * which will be written to the crypto register.
\r
545 ******************************************************************************/
\r
546 __STATIC_INLINE void CRYPTO_BurstToCrypto(volatile uint32_t * reg, const uint32_t * val)
\r
548 /* Load data from memory into local registers. */
\r
549 register uint32_t v0 = val[0];
\r
550 register uint32_t v1 = val[1];
\r
551 register uint32_t v2 = val[2];
\r
552 register uint32_t v3 = val[3];
\r
553 /* Store data to CRYPTO */
\r
560 /***************************************************************************//**
\r
562 * Read a 128 bit value from a crypto register.
\r
565 * This function provide a low-level api for reading one of the multi-word
\r
566 * registers in the crypto peripheral. Applications should prefer to use
\r
567 * @ref CRYPTO_DataRead, @ref CRYPTO_DDataRead or @ref CRYPTO_QDataRead
\r
568 * for reading the value of the DATA, DDATA and QDATA registers.
\r
571 * Pointer to the crypto register.
\r
574 * This is a pointer to an array that is capable of holding 4 32 bit integers
\r
575 * that will be filled with the 128 bit value from the crypto register.
\r
576 ******************************************************************************/
\r
577 __STATIC_INLINE void CRYPTO_BurstFromCrypto(volatile uint32_t * reg, uint32_t * val)
\r
579 /* Load data from CRYPTO into local registers. */
\r
580 register uint32_t v0 = *reg;
\r
581 register uint32_t v1 = *reg;
\r
582 register uint32_t v2 = *reg;
\r
583 register uint32_t v3 = *reg;
\r
584 /* Store data to memory */
\r
591 /***************************************************************************//**
\r
593 * Write 128 bits of data to a DATAX register in the CRYPTO module.
\r
596 * Write 128 bits of data to a DATAX register in the crypto module. The data
\r
597 * value is typically input to a big integer operation (see crypto
\r
600 * @param[in] dataReg The 128 bit DATA register.
\r
601 * @param[in] val Value of the data to write to the DATA register.
\r
602 ******************************************************************************/
\r
603 __STATIC_INLINE void CRYPTO_DataWrite(CRYPTO_DataReg_TypeDef dataReg,
\r
604 const CRYPTO_Data_TypeDef val)
\r
606 CRYPTO_BurstToCrypto((volatile uint32_t *)dataReg, val);
\r
609 /***************************************************************************//**
\r
611 * Read 128 bits of data from a DATAX register in the CRYPTO module.
\r
614 * Read 128 bits of data from a DATAX register in the crypto module. The data
\r
615 * value is typically output from a big integer operation (see crypto
\r
618 * @param[in] dataReg The 128 bit DATA register.
\r
619 * @param[out] val Location where to store the value in memory.
\r
620 ******************************************************************************/
\r
621 __STATIC_INLINE void CRYPTO_DataRead(CRYPTO_DataReg_TypeDef dataReg,
\r
622 CRYPTO_Data_TypeDef val)
\r
624 CRYPTO_BurstFromCrypto((volatile uint32_t *)dataReg, val);
\r
627 /***************************************************************************//**
\r
629 * Write 256 bits of data to a DDATAX register in the CRYPTO module.
\r
632 * Write 256 bits of data into a DDATAX (Double Data) register in the crypto
\r
633 * module. The data value is typically input to a big integer operation (see
\r
634 * crypto instructions).
\r
636 * @param[in] ddataReg The 256 bit DDATA register.
\r
637 * @param[in] val Value of the data to write to the DDATA register.
\r
638 ******************************************************************************/
\r
639 __STATIC_INLINE void CRYPTO_DDataWrite(CRYPTO_DDataReg_TypeDef ddataReg,
\r
640 const CRYPTO_DData_TypeDef val)
\r
642 CRYPTO_BurstToCrypto((volatile uint32_t *)ddataReg, &val[0]);
\r
643 CRYPTO_BurstToCrypto((volatile uint32_t *)ddataReg, &val[4]);
\r
646 /***************************************************************************//**
\r
648 * Read 256 bits of data from a DDATAX register in the CRYPTO module.
\r
651 * Read 256 bits of data from a DDATAX (Double Data) register in the crypto
\r
652 * module. The data value is typically output from a big integer operation
\r
653 * (see crypto instructions).
\r
655 * @param[in] ddataReg The 256 bit DDATA register.
\r
656 * @param[out] val Location where to store the value in memory.
\r
657 ******************************************************************************/
\r
658 __STATIC_INLINE void CRYPTO_DDataRead(CRYPTO_DDataReg_TypeDef ddataReg,
\r
659 CRYPTO_DData_TypeDef val)
\r
661 CRYPTO_BurstFromCrypto((volatile uint32_t *)ddataReg, &val[0]);
\r
662 CRYPTO_BurstFromCrypto((volatile uint32_t *)ddataReg, &val[4]);
\r
665 /***************************************************************************//**
\r
667 * Write 512 bits of data to a QDATAX register in the CRYPTO module.
\r
670 * Write 512 bits of data into a QDATAX (Quad Data) register in the crypto module
\r
671 * The data value is typically input to a big integer operation (see crypto
\r
674 * @param[in] qdataReg The 512 bits QDATA register.
\r
675 * @param[in] val Value of the data to write to the QDATA register.
\r
676 ******************************************************************************/
\r
677 __STATIC_INLINE void CRYPTO_QDataWrite(CRYPTO_QDataReg_TypeDef qdataReg,
\r
678 CRYPTO_QData_TypeDef val)
\r
680 CRYPTO_BurstToCrypto((volatile uint32_t *)qdataReg, &val[0]);
\r
681 CRYPTO_BurstToCrypto((volatile uint32_t *)qdataReg, &val[4]);
\r
682 CRYPTO_BurstToCrypto((volatile uint32_t *)qdataReg, &val[8]);
\r
683 CRYPTO_BurstToCrypto((volatile uint32_t *)qdataReg, &val[12]);
\r
686 /***************************************************************************//**
\r
688 * Read 512 bits of data from a QDATAX register in the CRYPTO module.
\r
691 * Read 512 bits of data from a QDATAX register in the crypto module. The data
\r
692 * value is typically input to a big integer operation (see crypto
\r
695 * @param[in] qdataReg The 512 bits QDATA register.
\r
696 * @param[in] val Value of the data to write to the QDATA register.
\r
697 ******************************************************************************/
\r
698 __STATIC_INLINE void CRYPTO_QDataRead(CRYPTO_QDataReg_TypeDef qdataReg,
\r
699 CRYPTO_QData_TypeDef val)
\r
701 CRYPTO_BurstFromCrypto((volatile uint32_t *)qdataReg, &val[0]);
\r
702 CRYPTO_BurstFromCrypto((volatile uint32_t *)qdataReg, &val[4]);
\r
703 CRYPTO_BurstFromCrypto((volatile uint32_t *)qdataReg, &val[8]);
\r
704 CRYPTO_BurstFromCrypto((volatile uint32_t *)qdataReg, &val[12]);
\r
707 /***************************************************************************//**
\r
709 * Set the key value to be used by the CRYPTO module.
\r
712 * Write 128 or 256 bit key to the KEYBUF register in the crypto module.
\r
714 * @param[in] val Value of the data to write to the KEYBUF register.
\r
715 * @param[in] keyWidth Key width - 128 or 256 bits
\r
716 ******************************************************************************/
\r
717 __STATIC_INLINE void CRYPTO_KeyBufWrite(CRYPTO_KeyBuf_TypeDef val,
\r
718 CRYPTO_KeyWidth_TypeDef keyWidth)
\r
720 if (keyWidth == cryptoKey256Bits)
\r
722 /* Set AES-256 mode */
\r
723 BUS_RegBitWrite(&CRYPTO->CTRL, _CRYPTO_CTRL_AES_SHIFT, _CRYPTO_CTRL_AES_AES256);
\r
724 /* Load key in KEYBUF register (= DDATA4) */
\r
725 CRYPTO_DDataWrite(cryptoRegDDATA4, (uint32_t *)val);
\r
729 /* Set AES-128 mode */
\r
730 BUS_RegBitWrite(&CRYPTO->CTRL, _CRYPTO_CTRL_AES_SHIFT, _CRYPTO_CTRL_AES_AES128);
\r
731 CRYPTO_BurstToCrypto(&CRYPTO->KEYBUF, &val[0]);
\r
735 void CRYPTO_KeyRead(CRYPTO_KeyBuf_TypeDef val,
\r
736 CRYPTO_KeyWidth_TypeDef keyWidth);
\r
738 /***************************************************************************//**
\r
740 * Quick write 128 bit key to the CRYPTO module.
\r
743 * Quick write 128 bit key to the KEYBUF register in the CRYPTO module.
\r
745 * @param[in] val Value of the data to write to the KEYBUF register.
\r
746 ******************************************************************************/
\r
747 __STATIC_INLINE void CRYPTO_KeyBuf128Write(const uint32_t * val)
\r
749 CRYPTO_BurstToCrypto(&CRYPTO->KEYBUF, val);
\r
752 /***************************************************************************//**
\r
754 * Quick read access of the Carry bit from arithmetic operations.
\r
757 * This function reads the carry bit of the CRYPTO ALU.
\r
760 * Returns 'true' if carry is 1, and 'false' if carry is 0.
\r
761 ******************************************************************************/
\r
762 __STATIC_INLINE bool CRYPTO_CarryIsSet(void)
\r
764 return (CRYPTO->DSTATUS & _CRYPTO_DSTATUS_CARRY_MASK)
\r
765 >> _CRYPTO_DSTATUS_CARRY_SHIFT;
\r
768 /***************************************************************************//**
\r
770 * Quick read access of the 4 LSbits of the DDATA0 register.
\r
773 * This function quickly retrieves the 4 least significant bits of the
\r
774 * DDATA0 register via the DDATA0LSBS bit field in the DSTATUS register.
\r
777 * Returns the 4 LSbits of DDATA0.
\r
778 ******************************************************************************/
\r
779 __STATIC_INLINE uint8_t CRYPTO_DData0_4LSBitsRead(void)
\r
781 return (CRYPTO->DSTATUS & _CRYPTO_DSTATUS_DDATA0LSBS_MASK)
\r
782 >> _CRYPTO_DSTATUS_DDATA0LSBS_SHIFT;
\r
785 /***************************************************************************//**
\r
787 * Read 260 bits from the DDATA0 register.
\r
790 * This functions reads 260 bits from the DDATA0 register in the CRYPTO
\r
791 * module. The data value is typically output from a big integer operation
\r
792 * (see crypto instructions) when the result width is set to 260 bits by
\r
793 * calling @ref CRYPTO_ResultWidthSet(cryptoResult260Bits);
\r
795 * @param[out] val Location where to store the value in memory.
\r
796 ******************************************************************************/
\r
797 __STATIC_INLINE void CRYPTO_DData0Read260(CRYPTO_Data260_TypeDef val)
\r
799 CRYPTO_DDataRead(cryptoRegDDATA0, val);
\r
800 val[8] = (CRYPTO->DSTATUS & _CRYPTO_DSTATUS_DDATA0MSBS_MASK)
\r
801 >> _CRYPTO_DSTATUS_DDATA0MSBS_SHIFT;
\r
804 /***************************************************************************//**
\r
806 * Write 260 bits to the DDATA0 register.
\r
809 * This functions writes 260 bits to the DDATA0 register in the CRYPTO
\r
810 * module. The data value is typically input to a big integer operation
\r
811 * (see crypto instructions) when the result width is set to 260 bits by
\r
812 * calling @ref CRYPTO_ResultWidthSet(cryptoResult260Bits);
\r
814 * @param[out] val Location where of the value in memory.
\r
815 ******************************************************************************/
\r
816 __STATIC_INLINE void CRYPTO_DData0Write260(const CRYPTO_Data260_TypeDef val)
\r
818 CRYPTO_DDataWrite(cryptoRegDDATA0, val);
\r
819 CRYPTO->DDATA0BYTE32 = val[8] & _CRYPTO_DDATA0BYTE32_DDATA0BYTE32_MASK;
\r
822 /***************************************************************************//**
\r
824 * Quick read the MSbit of the DDATA1 register.
\r
827 * This function reads the most significant bit (bit 255) of the DDATA1
\r
828 * register via the DDATA1MSB bit field in the DSTATUS register. This can
\r
829 * be used to quickly check the signedness of a big integer resident in the
\r
833 * Returns 'true' if MSbit is 1, and 'false' if MSbit is 0.
\r
834 ******************************************************************************/
\r
835 __STATIC_INLINE bool CRYPTO_DData1_MSBitRead(void)
\r
837 return (CRYPTO->DSTATUS & _CRYPTO_DSTATUS_DDATA1MSB_MASK)
\r
838 >> _CRYPTO_DSTATUS_DDATA1MSB_SHIFT;
\r
841 /***************************************************************************//**
\r
843 * Load a sequence of instructions to be executed on the current values in
\r
844 * the data registers.
\r
847 * This function loads a sequence of instructions to the crypto module. The
\r
848 * instructions will be executed when the CRYPTO_InstructionSequenceExecute
\r
849 * function is called. The first END marks the end of the sequence.
\r
851 * @param[in] instructionSequence Instruction sequence to load.
\r
852 ******************************************************************************/
\r
853 __STATIC_INLINE void CRYPTO_InstructionSequenceLoad(const CRYPTO_InstructionSequence_TypeDef instructionSequence)
\r
855 const uint32_t * pas = (const uint32_t *) instructionSequence;
\r
857 CRYPTO->SEQ0 = pas[0];
\r
858 CRYPTO->SEQ1 = pas[1];
\r
859 CRYPTO->SEQ2 = pas[2];
\r
860 CRYPTO->SEQ3 = pas[3];
\r
861 CRYPTO->SEQ4 = pas[4];
\r
864 /***************************************************************************//**
\r
866 * Execute the current programmed instruction sequence.
\r
869 * This function starts the execution of the current instruction sequence
\r
870 * in the CRYPTO module.
\r
871 ******************************************************************************/
\r
872 __STATIC_INLINE void CRYPTO_InstructionSequenceExecute(void)
\r
874 /* Start the command sequence. */
\r
875 CRYPTO->CMD = CRYPTO_CMD_SEQSTART;
\r
878 /***************************************************************************//**
\r
880 * Check whether the execution of an instruction sequence has completed.
\r
883 * This function checks whether an instruction sequence has completed.
\r
886 * Returns 'true' if the instruction sequence is done, and 'false' if not.
\r
887 ******************************************************************************/
\r
888 __STATIC_INLINE bool CRYPTO_InstructionSequenceDone(void)
\r
890 /* Return true if operation has completed. */
\r
891 return !(CRYPTO->STATUS
\r
892 & (CRYPTO_STATUS_INSTRRUNNING | CRYPTO_STATUS_SEQRUNNING));
\r
895 /***************************************************************************//**
\r
897 * Wait for completion of the current sequence of instructions.
\r
900 * This function "busy"-waits until the execution of the ongoing instruction
\r
901 * sequence has completed.
\r
902 ******************************************************************************/
\r
903 __STATIC_INLINE void CRYPTO_InstructionSequenceWait(void)
\r
905 while (!CRYPTO_InstructionSequenceDone())
\r
909 /***************************************************************************//**
\r
911 * Wait for completion of the current command.
\r
914 * This function "busy"-waits until the execution of the ongoing instruction
\r
916 ******************************************************************************/
\r
917 __STATIC_INLINE void CRYPTO_InstructionWait(void)
\r
919 /* Wait for completion */
\r
920 while (!(CRYPTO->IF & CRYPTO_IF_INSTRDONE))
\r
922 CRYPTO->IFC = CRYPTO_IF_INSTRDONE;
\r
925 void CRYPTO_SHA_1(const uint8_t * msg,
\r
927 CRYPTO_SHA1_Digest_TypeDef digest);
\r
929 void CRYPTO_SHA_256(const uint8_t * msg,
\r
931 CRYPTO_SHA256_Digest_TypeDef digest);
\r
933 void CRYPTO_Mul(uint32_t * A, int aSize,
\r
934 uint32_t * B, int bSize,
\r
935 uint32_t * R, int rSize);
\r
937 void CRYPTO_AES_CBC128(uint8_t * out,
\r
938 const uint8_t * in,
\r
940 const uint8_t * key,
\r
941 const uint8_t * iv,
\r
944 void CRYPTO_AES_CBC256(uint8_t * out,
\r
945 const uint8_t * in,
\r
947 const uint8_t * key,
\r
948 const uint8_t * iv,
\r
951 void CRYPTO_AES_CFB128(uint8_t * out,
\r
952 const uint8_t * in,
\r
954 const uint8_t * key,
\r
955 const uint8_t * iv,
\r
958 void CRYPTO_AES_CFB256(uint8_t * out,
\r
959 const uint8_t * in,
\r
961 const uint8_t * key,
\r
962 const uint8_t * iv,
\r
965 void CRYPTO_AES_CTR128(uint8_t * out,
\r
966 const uint8_t * in,
\r
968 const uint8_t * key,
\r
970 CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc);
\r
972 void CRYPTO_AES_CTR256(uint8_t * out,
\r
973 const uint8_t * in,
\r
975 const uint8_t * key,
\r
977 CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc);
\r
979 void CRYPTO_AES_CTRUpdate32Bit(uint8_t * ctr);
\r
980 void CRYPTO_AES_DecryptKey128(uint8_t * out, const uint8_t * in);
\r
981 void CRYPTO_AES_DecryptKey256(uint8_t * out, const uint8_t * in);
\r
983 void CRYPTO_AES_ECB128(uint8_t * out,
\r
984 const uint8_t * in,
\r
986 const uint8_t * key,
\r
989 void CRYPTO_AES_ECB256(uint8_t * out,
\r
990 const uint8_t * in,
\r
992 const uint8_t * key,
\r
995 void CRYPTO_AES_OFB128(uint8_t * out,
\r
996 const uint8_t * in,
\r
998 const uint8_t * key,
\r
999 const uint8_t * iv);
\r
1001 void CRYPTO_AES_OFB256(uint8_t * out,
\r
1002 const uint8_t * in,
\r
1004 const uint8_t * key,
\r
1005 const uint8_t * iv);
\r
1007 /***************************************************************************//**
\r
1009 * Clear one or more pending CRYPTO interrupts.
\r
1011 * @param[in] flags
\r
1012 * Pending CRYPTO interrupt source to clear. Use a bitwise logic OR combination of
\r
1013 * valid interrupt flags for the CRYPTO module (CRYPTO_IF_nnn).
\r
1014 ******************************************************************************/
\r
1015 __STATIC_INLINE void CRYPTO_IntClear(uint32_t flags)
\r
1017 CRYPTO->IFC = flags;
\r
1020 /***************************************************************************//**
\r
1022 * Disable one or more CRYPTO interrupts.
\r
1024 * @param[in] flags
\r
1025 * CRYPTO interrupt sources to disable. Use a bitwise logic OR combination of
\r
1026 * valid interrupt flags for the CRYPTO module (CRYPTO_IF_nnn).
\r
1027 ******************************************************************************/
\r
1028 __STATIC_INLINE void CRYPTO_IntDisable(uint32_t flags)
\r
1030 CRYPTO->IEN &= ~(flags);
\r
1033 /***************************************************************************//**
\r
1035 * Enable one or more CRYPTO interrupts.
\r
1038 * Depending on the use, a pending interrupt may already be set prior to
\r
1039 * enabling the interrupt. Consider using CRYPTO_IntClear() prior to enabling
\r
1040 * if such a pending interrupt should be ignored.
\r
1042 * @param[in] flags
\r
1043 * CRYPTO interrupt sources to enable. Use a bitwise logic OR combination of
\r
1044 * valid interrupt flags for the CRYPTO module (CRYPTO_IF_nnn).
\r
1045 ******************************************************************************/
\r
1046 __STATIC_INLINE void CRYPTO_IntEnable(uint32_t flags)
\r
1048 CRYPTO->IEN |= flags;
\r
1051 /***************************************************************************//**
\r
1053 * Get pending CRYPTO interrupt flags.
\r
1056 * The event bits are not cleared by the use of this function.
\r
1059 * CRYPTO interrupt sources pending. A bitwise logic OR combination of valid
\r
1060 * interrupt flags for the CRYPTO module (CRYPTO_IF_nnn).
\r
1061 ******************************************************************************/
\r
1062 __STATIC_INLINE uint32_t CRYPTO_IntGet(void)
\r
1064 return CRYPTO->IF;
\r
1067 /***************************************************************************//**
\r
1069 * Get enabled and pending CRYPTO interrupt flags.
\r
1070 * Useful for handling more interrupt sources in the same interrupt handler.
\r
1073 * Interrupt flags are not cleared by the use of this function.
\r
1076 * Pending and enabled CRYPTO interrupt sources
\r
1077 * The return value is the bitwise AND of
\r
1078 * - the enabled interrupt sources in CRYPTO_IEN and
\r
1079 * - the pending interrupt flags CRYPTO_IF
\r
1080 ******************************************************************************/
\r
1081 __STATIC_INLINE uint32_t CRYPTO_IntGetEnabled(void)
\r
1083 return CRYPTO->IF & CRYPTO->IEN;
\r
1086 /***************************************************************************//**
\r
1088 * Set one or more pending CRYPTO interrupts from SW.
\r
1090 * @param[in] flags
\r
1091 * CRYPTO interrupt sources to set to pending. Use a bitwise logic OR combination
\r
1092 * of valid interrupt flags for the CRYPTO module (CRYPTO_IF_nnn).
\r
1093 ******************************************************************************/
\r
1094 __STATIC_INLINE void CRYPTO_IntSet(uint32_t flags)
\r
1096 CRYPTO->IFS = flags;
\r
1099 /*******************************************************************************
\r
1100 ***** Static inline wrappers for CRYPTO AES functions in order to *****
\r
1101 ***** preserve backwards compatibility with AES module API functions. *****
\r
1102 ******************************************************************************/
\r
1104 /***************************************************************************//**
\r
1106 * AES Cipher-block chaining (CBC) cipher mode encryption/decryption,
\r
1110 * This function is present to preserve backwards compatibility. Use
\r
1111 * @ref CRYPTO_AES_CBC128 instead.
\r
1112 ******************************************************************************/
\r
1113 __STATIC_INLINE void AES_CBC128(uint8_t * out,
\r
1114 const uint8_t * in,
\r
1116 const uint8_t * key,
\r
1117 const uint8_t * iv,
\r
1120 CRYPTO_AES_CBC128(out, in, len, key, iv, encrypt);
\r
1123 /***************************************************************************//**
\r
1125 * AES Cipher-block chaining (CBC) cipher mode encryption/decryption, 256 bit
\r
1129 * This function is present to preserve backwards compatibility. Use
\r
1130 * @ref CRYPTO_AES_CBC256 instead.
\r
1131 ******************************************************************************/
\r
1132 __STATIC_INLINE void AES_CBC256(uint8_t * out,
\r
1133 const uint8_t * in,
\r
1135 const uint8_t * key,
\r
1136 const uint8_t * iv,
\r
1139 CRYPTO_AES_CBC256(out, in, len, key, iv, encrypt);
\r
1142 /***************************************************************************//**
\r
1144 * AES Cipher feedback (CFB) cipher mode encryption/decryption, 128 bit key.
\r
1147 * This function is present to preserve backwards compatibility. Use
\r
1148 * @ref CRYPTO_AES_CFB128 instead.
\r
1149 ******************************************************************************/
\r
1150 __STATIC_INLINE void AES_CFB128(uint8_t * out,
\r
1151 const uint8_t * in,
\r
1153 const uint8_t * key,
\r
1154 const uint8_t * iv,
\r
1157 CRYPTO_AES_CFB128(out, in, len, key, iv, encrypt);
\r
1160 /***************************************************************************//**
\r
1162 * AES Cipher feedback (CFB) cipher mode encryption/decryption, 256 bit key.
\r
1165 * This function is present to preserve backwards compatibility. Use
\r
1166 * @ref CRYPTO_AES_CFB256 instead.
\r
1167 ******************************************************************************/
\r
1168 __STATIC_INLINE void AES_CFB256(uint8_t * out,
\r
1169 const uint8_t * in,
\r
1171 const uint8_t * key,
\r
1172 const uint8_t * iv,
\r
1175 CRYPTO_AES_CFB256(out, in, len, key, iv, encrypt);
\r
1178 /***************************************************************************//**
\r
1180 * AES Counter (CTR) cipher mode encryption/decryption, 128 bit key.
\r
1183 * This function is present to preserve backwards compatibility. Use
\r
1184 * @ref CRYPTO_AES_CTR128 instead.
\r
1185 ******************************************************************************/
\r
1186 __STATIC_INLINE void AES_CTR128(uint8_t * out,
\r
1187 const uint8_t * in,
\r
1189 const uint8_t * key,
\r
1191 CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc)
\r
1193 CRYPTO_AES_CTR128(out, in, len, key, ctr, ctrFunc);
\r
1196 /***************************************************************************//**
\r
1198 * AES Counter (CTR) cipher mode encryption/decryption, 256 bit key.
\r
1201 * This function is present to preserve backwards compatibility. Use
\r
1202 * @ref CRYPTO_AES_CTR256 instead.
\r
1203 ******************************************************************************/
\r
1204 __STATIC_INLINE void AES_CTR256(uint8_t * out,
\r
1205 const uint8_t * in,
\r
1207 const uint8_t * key,
\r
1209 CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc)
\r
1211 CRYPTO_AES_CTR256(out, in, len, key, ctr, ctrFunc);
\r
1214 /***************************************************************************//**
\r
1216 * Update last 32 bits of 128 bit counter, by incrementing with 1.
\r
1219 * This function is present to preserve backwards compatibility. Use
\r
1220 * @ref CRYPTO_AES_CTRUpdate32Bit instead.
\r
1221 ******************************************************************************/
\r
1222 __STATIC_INLINE void AES_CTRUpdate32Bit(uint8_t * ctr)
\r
1224 CRYPTO_AES_CTRUpdate32Bit(ctr);
\r
1227 /***************************************************************************//**
\r
1229 * Generate 128 bit AES decryption key from 128 bit encryption key. The
\r
1230 * decryption key is used for some cipher modes when decrypting.
\r
1233 * This function is present to preserve backwards compatibility. Use
\r
1234 * @ref CRYPTO_AES_DecryptKey128 instead.
\r
1235 ******************************************************************************/
\r
1236 __STATIC_INLINE void AES_DecryptKey128(uint8_t * out, const uint8_t * in)
\r
1238 CRYPTO_AES_DecryptKey128(out, in);
\r
1241 /***************************************************************************//**
\r
1243 * Generate 256 bit AES decryption key from 256 bit encryption key. The
\r
1244 * decryption key is used for some cipher modes when decrypting.
\r
1247 * This function is present to preserve backwards compatibility. Use
\r
1248 * @ref CRYPTO_AES_DecryptKey256 instead.
\r
1249 ******************************************************************************/
\r
1250 __STATIC_INLINE void AES_DecryptKey256(uint8_t * out, const uint8_t * in)
\r
1252 CRYPTO_AES_DecryptKey256(out, in);
\r
1255 /***************************************************************************//**
\r
1257 * AES Electronic Codebook (ECB) cipher mode encryption/decryption,
\r
1261 * This function is present to preserve backwards compatibility. Use
\r
1262 * @ref CRYPTO_AES_ECB128 instead.
\r
1263 ******************************************************************************/
\r
1264 __STATIC_INLINE void AES_ECB128(uint8_t * out,
\r
1265 const uint8_t * in,
\r
1267 const uint8_t * key,
\r
1270 CRYPTO_AES_ECB128(out, in, len, key, encrypt);
\r
1273 /***************************************************************************//**
\r
1275 * AES Electronic Codebook (ECB) cipher mode encryption/decryption,
\r
1279 * This function is present to preserve backwards compatibility. Use
\r
1280 * @ref CRYPTO_AES_ECB256 instead.
\r
1281 ******************************************************************************/
\r
1282 __STATIC_INLINE void AES_ECB256(uint8_t * out,
\r
1283 const uint8_t * in,
\r
1285 const uint8_t * key,
\r
1288 CRYPTO_AES_ECB256(out, in, len, key, encrypt);
\r
1291 /***************************************************************************//**
\r
1293 * AES Output feedback (OFB) cipher mode encryption/decryption, 128 bit key.
\r
1296 * This function is present to preserve backwards compatibility. Use
\r
1297 * @ref CRYPTO_AES_OFB128 instead.
\r
1298 ******************************************************************************/
\r
1299 __STATIC_INLINE void AES_OFB128(uint8_t * out,
\r
1300 const uint8_t * in,
\r
1302 const uint8_t * key,
\r
1303 const uint8_t * iv)
\r
1305 CRYPTO_AES_OFB128(out, in, len, key, iv);
\r
1308 /***************************************************************************//**
\r
1310 * AES Output feedback (OFB) cipher mode encryption/decryption, 256 bit key.
\r
1313 * This function is present to preserve backwards compatibility. Use
\r
1314 * @ref CRYPTO_AES_OFB256 instead.
\r
1315 ******************************************************************************/
\r
1316 __STATIC_INLINE void AES_OFB256(uint8_t * out,
\r
1317 const uint8_t * in,
\r
1319 const uint8_t * key,
\r
1320 const uint8_t * iv)
\r
1322 CRYPTO_AES_OFB256(out, in, len, key, iv);
\r
1325 #ifdef __cplusplus
\r
1329 /** @} (end addtogroup CRYPTO) */
\r
1330 /** @} (end addtogroup EM_Library) */
\r
1332 #endif /* defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0) */
\r
1334 #endif /* __SILICON_LABS_EM_CRYPTO_H__ */
\r