37 #if defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0)
196 #define CRYPTO_DATA_SIZE_IN_BITS (128)
197 #define CRYPTO_DATA_SIZE_IN_BYTES (CRYPTO_DATA_SIZE_IN_BITS/8)
198 #define CRYPTO_DATA_SIZE_IN_32BIT_WORDS (CRYPTO_DATA_SIZE_IN_BYTES/sizeof(uint32_t))
200 #define CRYPTO_KEYBUF_SIZE_IN_BITS (256)
201 #define CRYPTO_KEYBUF_SIZE_IN_BYTES (CRYPTO_DDATA_SIZE_IN_BITS/8)
202 #define CRYPTO_KEYBUF_SIZE_IN_32BIT_WORDS (CRYPTO_DDATA_SIZE_IN_BYTES/sizeof(uint32_t))
204 #define CRYPTO_DDATA_SIZE_IN_BITS (256)
205 #define CRYPTO_DDATA_SIZE_IN_BYTES (CRYPTO_DDATA_SIZE_IN_BITS/8)
206 #define CRYPTO_DDATA_SIZE_IN_32BIT_WORDS (CRYPTO_DDATA_SIZE_IN_BYTES/sizeof(uint32_t))
208 #define CRYPTO_QDATA_SIZE_IN_BITS (512)
209 #define CRYPTO_QDATA_SIZE_IN_BYTES (CRYPTO_QDATA_SIZE_IN_BITS/8)
210 #define CRYPTO_QDATA_SIZE_IN_32BIT_WORDS (CRYPTO_QDATA_SIZE_IN_BYTES/sizeof(uint32_t))
212 #define CRYPTO_DATA260_SIZE_IN_32BIT_WORDS (9)
215 #define CRYPTO_SHA1_DIGEST_SIZE_IN_BITS (160)
216 #define CRYPTO_SHA1_DIGEST_SIZE_IN_BYTES (CRYPTO_SHA1_DIGEST_SIZE_IN_BITS/8)
219 #define CRYPTO_SHA256_DIGEST_SIZE_IN_BITS (256)
220 #define CRYPTO_SHA256_DIGEST_SIZE_IN_BYTES (CRYPTO_SHA256_DIGEST_SIZE_IN_BITS/8)
225 #define CRYPTO_DDATA0_260_BITS_READ(crypto, bigint260) CRYPTO_DData0Read260(crypto, bigint260)
226 #define CRYPTO_DDATA0_260_BITS_WRITE(crypto, bigint260) CRYPTO_DData0Write260(crypto, bigint260)
235 #define CRYPTO_SEQ_LOAD_1(crypto, a1) { \
236 crypto->SEQ0 = a1 | (CRYPTO_CMD_INSTR_END<<8);}
237 #define CRYPTO_SEQ_LOAD_2(crypto, a1, a2) { \
238 crypto->SEQ0 = a1 | (a2<<8) | (CRYPTO_CMD_INSTR_END<<16);}
239 #define CRYPTO_SEQ_LOAD_3(crypto, a1, a2, a3) { \
240 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (CRYPTO_CMD_INSTR_END<<24);}
241 #define CRYPTO_SEQ_LOAD_4(crypto, a1, a2, a3, a4) { \
242 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
243 crypto->SEQ1 = CRYPTO_CMD_INSTR_END;}
244 #define CRYPTO_SEQ_LOAD_5(crypto, a1, a2, a3, a4, a5) { \
245 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
246 crypto->SEQ1 = a5 | (CRYPTO_CMD_INSTR_END<<8);}
247 #define CRYPTO_SEQ_LOAD_6(crypto, a1, a2, a3, a4, a5, a6) { \
248 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
249 crypto->SEQ1 = a5 | (a6<<8) | (CRYPTO_CMD_INSTR_END<<16);}
250 #define CRYPTO_SEQ_LOAD_7(crypto, a1, a2, a3, a4, a5, a6, a7) { \
251 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
252 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (CRYPTO_CMD_INSTR_END<<24);}
253 #define CRYPTO_SEQ_LOAD_8(crypto, a1, a2, a3, a4, a5, a6, a7, a8) { \
254 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
255 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
256 crypto->SEQ2 = CRYPTO_CMD_INSTR_END;}
257 #define CRYPTO_SEQ_LOAD_9(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9) { \
258 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
259 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
260 crypto->SEQ2 = a9 | (CRYPTO_CMD_INSTR_END<<8);}
261 #define CRYPTO_SEQ_LOAD_10(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { \
262 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
263 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
264 crypto->SEQ2 = a9 | (a10<<8) | (CRYPTO_CMD_INSTR_END<<16);}
265 #define CRYPTO_SEQ_LOAD_11(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) { \
266 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
267 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
268 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (CRYPTO_CMD_INSTR_END<<24);}
269 #define CRYPTO_SEQ_LOAD_12(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) { \
270 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
271 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
272 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
273 crypto->SEQ3 = CRYPTO_CMD_INSTR_END;}
274 #define CRYPTO_SEQ_LOAD_13(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) { \
275 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
276 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
277 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
278 crypto->SEQ3 = a13 | (CRYPTO_CMD_INSTR_END<<8);}
279 #define CRYPTO_SEQ_LOAD_14(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) { \
280 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
281 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
282 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
283 crypto->SEQ3 = a13 | (a14<<8) | (CRYPTO_CMD_INSTR_END<<16);}
284 #define CRYPTO_SEQ_LOAD_15(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) { \
285 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
286 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
287 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
288 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (CRYPTO_CMD_INSTR_END<<24);}
289 #define CRYPTO_SEQ_LOAD_16(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) { \
290 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
291 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
292 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
293 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
294 crypto->SEQ4 = CRYPTO_CMD_INSTR_END;}
295 #define CRYPTO_SEQ_LOAD_17(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17) { \
296 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
297 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
298 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
299 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
300 crypto->SEQ4 = a17 | (CRYPTO_CMD_INSTR_END<<8);}
301 #define CRYPTO_SEQ_LOAD_18(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) { \
302 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
303 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
304 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
305 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
306 crypto->SEQ4 = a17 | (a18<<8) | (CRYPTO_CMD_INSTR_END<<16);}
307 #define CRYPTO_SEQ_LOAD_19(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) { \
308 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
309 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
310 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
311 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
312 crypto->SEQ4 = a17 | (a18<<8) | (a19<<16) | (CRYPTO_CMD_INSTR_END<<24);}
313 #define CRYPTO_SEQ_LOAD_20(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) { \
314 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
315 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
316 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
317 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
318 crypto->SEQ4 = a17 | (a18<<8) | (a19<<16) | (a20<<24);}
327 #define CRYPTO_EXECUTE_1(crypto, a1) { \
328 crypto->SEQ0 = a1 | (CRYPTO_CMD_INSTR_EXEC<<8); }
329 #define CRYPTO_EXECUTE_2(crypto, a1, a2) { \
330 crypto->SEQ0 = a1 | (a2<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
331 #define CRYPTO_EXECUTE_3(crypto, a1, a2, a3) { \
332 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
333 #define CRYPTO_EXECUTE_4(crypto, a1, a2, a3, a4) { \
334 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
335 crypto->SEQ1 = CRYPTO_CMD_INSTR_EXEC; }
336 #define CRYPTO_EXECUTE_5(crypto, a1, a2, a3, a4, a5) { \
337 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
338 crypto->SEQ1 = a5 | (CRYPTO_CMD_INSTR_EXEC<<8); }
339 #define CRYPTO_EXECUTE_6(crypto, a1, a2, a3, a4, a5, a6) { \
340 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
341 crypto->SEQ1 = a5 | (a6<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
342 #define CRYPTO_EXECUTE_7(crypto, a1, a2, a3, a4, a5, a6, a7) { \
343 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
344 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
345 #define CRYPTO_EXECUTE_8(crypto, a1, a2, a3, a4, a5, a6, a7, a8) { \
346 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
347 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
348 crypto->SEQ2 = CRYPTO_CMD_INSTR_EXEC; }
349 #define CRYPTO_EXECUTE_9(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9) { \
350 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
351 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
352 crypto->SEQ2 = a9 | (CRYPTO_CMD_INSTR_EXEC<<8); }
353 #define CRYPTO_EXECUTE_10(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { \
354 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
355 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
356 crypto->SEQ2 = a9 | (a10<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
357 #define CRYPTO_EXECUTE_11(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) { \
358 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
359 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
360 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
361 #define CRYPTO_EXECUTE_12(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) { \
362 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
363 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
364 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
365 crypto->SEQ3 = CRYPTO_CMD_INSTR_EXEC; }
366 #define CRYPTO_EXECUTE_13(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) { \
367 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
368 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
369 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
370 crypto->SEQ3 = a13 | (CRYPTO_CMD_INSTR_EXEC<<8); }
371 #define CRYPTO_EXECUTE_14(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) { \
372 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
373 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
374 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
375 crypto->SEQ3 = a13 | (a14<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
376 #define CRYPTO_EXECUTE_15(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) { \
377 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
378 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
379 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
380 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
381 #define CRYPTO_EXECUTE_16(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) { \
382 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
383 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
384 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
385 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
386 crypto->SEQ4 = CRYPTO_CMD_INSTR_EXEC; }
387 #define CRYPTO_EXECUTE_17(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17) { \
388 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
389 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
390 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
391 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
392 crypto->SEQ4 = a17 | (CRYPTO_CMD_INSTR_EXEC<<8); }
393 #define CRYPTO_EXECUTE_18(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) { \
394 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
395 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
396 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
397 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
398 crypto->SEQ4 = a17 | (a18<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
399 #define CRYPTO_EXECUTE_19(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) { \
400 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
401 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
402 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
403 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
404 crypto->SEQ4 = a17 | (a18<<8) | (a19<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
405 #define CRYPTO_EXECUTE_20(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) { \
406 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
407 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
408 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
409 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
410 crypto->SEQ4 = a17 | (a18<<8) | (a19<<16) | (a20<<24); \
411 CRYPTO_InstructionSequenceExecute();}
423 typedef uint32_t CRYPTO_Data_TypeDef[CRYPTO_DATA_SIZE_IN_32BIT_WORDS];
430 typedef uint32_t CRYPTO_DData_TypeDef[CRYPTO_DDATA_SIZE_IN_32BIT_WORDS];
433 typedef uint32_t* CRYPTO_DDataPtr_TypeDef;
441 typedef uint32_t CRYPTO_QData_TypeDef[CRYPTO_QDATA_SIZE_IN_32BIT_WORDS];
451 typedef uint32_t CRYPTO_Data260_TypeDef[CRYPTO_DATA260_SIZE_IN_32BIT_WORDS];
457 typedef uint32_t CRYPTO_KeyBuf_TypeDef[CRYPTO_KEYBUF_SIZE_IN_32BIT_WORDS];
464 typedef volatile uint32_t* CRYPTO_DataReg_TypeDef;
471 typedef volatile uint32_t* CRYPTO_DDataReg_TypeDef;
478 typedef volatile uint32_t* CRYPTO_QDataReg_TypeDef;
483 cryptoModulusBin256 = CRYPTO_WAC_MODULUS_BIN256,
484 cryptoModulusBin128 = CRYPTO_WAC_MODULUS_BIN128,
485 cryptoModulusGcmBin128 = CRYPTO_WAC_MODULUS_GCMBIN128,
486 cryptoModulusEccB233 = CRYPTO_WAC_MODULUS_ECCBIN233P,
487 cryptoModulusEccB163 = CRYPTO_WAC_MODULUS_ECCBIN163P,
488 cryptoModulusEccP256 = CRYPTO_WAC_MODULUS_ECCPRIME256P,
489 cryptoModulusEccP224 = CRYPTO_WAC_MODULUS_ECCPRIME224P,
490 cryptoModulusEccP192 = CRYPTO_WAC_MODULUS_ECCPRIME192P,
491 cryptoModulusEccB233Order = CRYPTO_WAC_MODULUS_ECCBIN233N,
492 cryptoModulusEccB233KOrder = CRYPTO_WAC_MODULUS_ECCBIN233KN,
493 cryptoModulusEccB163Order = CRYPTO_WAC_MODULUS_ECCBIN163N,
494 cryptoModulusEccB163KOrder = CRYPTO_WAC_MODULUS_ECCBIN163KN,
495 cryptoModulusEccP256Order = CRYPTO_WAC_MODULUS_ECCPRIME256N,
496 cryptoModulusEccP224Order = CRYPTO_WAC_MODULUS_ECCPRIME224N,
497 cryptoModulusEccP192Order = CRYPTO_WAC_MODULUS_ECCPRIME192N
498 } CRYPTO_ModulusId_TypeDef;
503 cryptoMulOperand256Bits = CRYPTO_WAC_MULWIDTH_MUL256,
504 cryptoMulOperand128Bits = CRYPTO_WAC_MULWIDTH_MUL128,
505 cryptoMulOperandModulusBits = CRYPTO_WAC_MULWIDTH_MULMOD
508 } CRYPTO_MulOperandWidth_TypeDef;
513 cryptoResult128Bits = CRYPTO_WAC_RESULTWIDTH_128BIT,
514 cryptoResult256Bits = CRYPTO_WAC_RESULTWIDTH_256BIT,
515 cryptoResult260Bits = CRYPTO_WAC_RESULTWIDTH_260BIT
516 } CRYPTO_ResultWidth_TypeDef;
521 cryptoInc1byte = CRYPTO_CTRL_INCWIDTH_INCWIDTH1,
522 cryptoInc2byte = CRYPTO_CTRL_INCWIDTH_INCWIDTH2,
523 cryptoInc3byte = CRYPTO_CTRL_INCWIDTH_INCWIDTH3,
524 cryptoInc4byte = CRYPTO_CTRL_INCWIDTH_INCWIDTH4
525 } CRYPTO_IncWidth_TypeDef;
530 cryptoKey128Bits = 8,
531 cryptoKey256Bits = 16,
532 } CRYPTO_KeyWidth_TypeDef;
537 #define CRYPTO_MAX_SEQUENCE_INSTRUCTIONS (20)
546 typedef uint8_t CRYPTO_InstructionSequence_TypeDef[CRYPTO_MAX_SEQUENCE_INSTRUCTIONS];
552 #define CRYPTO_INSTRUCTIONSEQUENSE_DEFAULT \
553 {CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
554 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
555 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
556 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
557 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
558 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
559 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END}
562 typedef uint8_t CRYPTO_SHA1_Digest_TypeDef[CRYPTO_SHA1_DIGEST_SIZE_IN_BYTES];
565 typedef uint8_t CRYPTO_SHA256_Digest_TypeDef[CRYPTO_SHA256_DIGEST_SIZE_IN_BYTES];
578 typedef void (*CRYPTO_AES_CtrFuncPtr_TypeDef)(uint8_t * ctr);
598 void CRYPTO_ModulusSet(CRYPTO_TypeDef * crypto,
599 CRYPTO_ModulusId_TypeDef modType);
616 void CRYPTO_MulOperandWidthSet(CRYPTO_TypeDef *crypto,
617 CRYPTO_MulOperandWidth_TypeDef mulOperandWidth)
619 uint32_t temp = crypto->WAC & (~_CRYPTO_WAC_MULWIDTH_MASK);
620 crypto->WAC = temp | mulOperandWidth;
637 void CRYPTO_ResultWidthSet(CRYPTO_TypeDef *crypto,
638 CRYPTO_ResultWidth_TypeDef resultWidth)
640 uint32_t temp = crypto->WAC & (~_CRYPTO_WAC_RESULTWIDTH_MASK);
641 crypto->WAC = temp | resultWidth;
658 __STATIC_INLINE
void CRYPTO_IncWidthSet(CRYPTO_TypeDef *crypto,
659 CRYPTO_IncWidth_TypeDef incWidth)
661 uint32_t temp = crypto->CTRL & (~_CRYPTO_CTRL_INCWIDTH_MASK);
662 crypto->CTRL = temp | incWidth;
682 __STATIC_INLINE
void CRYPTO_BurstToCrypto(
volatile uint32_t * reg,
683 const uint32_t * val)
686 register uint32_t v0 = val[0];
687 register uint32_t v1 = val[1];
688 register uint32_t v2 = val[2];
689 register uint32_t v3 = val[3];
714 __STATIC_INLINE
void CRYPTO_BurstFromCrypto(
volatile uint32_t * reg, uint32_t * val)
717 register uint32_t v0 = *reg;
718 register uint32_t v1 = *reg;
719 register uint32_t v2 = *reg;
720 register uint32_t v3 = *reg;
740 __STATIC_INLINE
void CRYPTO_DataWrite(CRYPTO_DataReg_TypeDef dataReg,
741 const CRYPTO_Data_TypeDef val)
743 CRYPTO_BurstToCrypto((
volatile uint32_t *)dataReg, val);
758 __STATIC_INLINE
void CRYPTO_DataRead(CRYPTO_DataReg_TypeDef dataReg,
759 CRYPTO_Data_TypeDef val)
761 CRYPTO_BurstFromCrypto((
volatile uint32_t *)dataReg, val);
776 __STATIC_INLINE
void CRYPTO_DDataWrite(CRYPTO_DDataReg_TypeDef ddataReg,
777 const CRYPTO_DData_TypeDef val)
779 CRYPTO_BurstToCrypto((
volatile uint32_t *)ddataReg, &val[0]);
780 CRYPTO_BurstToCrypto((
volatile uint32_t *)ddataReg, &val[4]);
795 __STATIC_INLINE
void CRYPTO_DDataRead(CRYPTO_DDataReg_TypeDef ddataReg,
796 CRYPTO_DData_TypeDef val)
798 CRYPTO_BurstFromCrypto((
volatile uint32_t *)ddataReg, &val[0]);
799 CRYPTO_BurstFromCrypto((
volatile uint32_t *)ddataReg, &val[4]);
814 __STATIC_INLINE
void CRYPTO_QDataWrite(CRYPTO_QDataReg_TypeDef qdataReg,
815 CRYPTO_QData_TypeDef val)
817 CRYPTO_BurstToCrypto((
volatile uint32_t *)qdataReg, &val[0]);
818 CRYPTO_BurstToCrypto((
volatile uint32_t *)qdataReg, &val[4]);
819 CRYPTO_BurstToCrypto((
volatile uint32_t *)qdataReg, &val[8]);
820 CRYPTO_BurstToCrypto((
volatile uint32_t *)qdataReg, &val[12]);
835 __STATIC_INLINE
void CRYPTO_QDataRead(CRYPTO_QDataReg_TypeDef qdataReg,
836 CRYPTO_QData_TypeDef val)
838 CRYPTO_BurstFromCrypto((
volatile uint32_t *)qdataReg, &val[0]);
839 CRYPTO_BurstFromCrypto((
volatile uint32_t *)qdataReg, &val[4]);
840 CRYPTO_BurstFromCrypto((
volatile uint32_t *)qdataReg, &val[8]);
841 CRYPTO_BurstFromCrypto((
volatile uint32_t *)qdataReg, &val[12]);
860 __STATIC_INLINE
void CRYPTO_KeyBufWrite(CRYPTO_TypeDef *crypto,
861 CRYPTO_KeyBuf_TypeDef val,
862 CRYPTO_KeyWidth_TypeDef keyWidth)
864 if (keyWidth == cryptoKey256Bits)
867 BUS_RegBitWrite(&crypto->CTRL, _CRYPTO_CTRL_AES_SHIFT, _CRYPTO_CTRL_AES_AES256);
869 CRYPTO_DDataWrite(&crypto->DDATA4, (uint32_t *)val);
874 BUS_RegBitWrite(&crypto->CTRL, _CRYPTO_CTRL_AES_SHIFT, _CRYPTO_CTRL_AES_AES128);
875 CRYPTO_BurstToCrypto(&crypto->KEYBUF, &val[0]);
879 void CRYPTO_KeyRead(CRYPTO_TypeDef *crypto,
880 CRYPTO_KeyBuf_TypeDef val,
881 CRYPTO_KeyWidth_TypeDef keyWidth);
896 __STATIC_INLINE
void CRYPTO_KeyBuf128Write(CRYPTO_TypeDef *crypto,
897 const uint32_t * val)
899 CRYPTO_BurstToCrypto(&crypto->KEYBUF, val);
915 __STATIC_INLINE
bool CRYPTO_CarryIsSet(CRYPTO_TypeDef *crypto)
917 return (crypto->DSTATUS & _CRYPTO_DSTATUS_CARRY_MASK)
918 >> _CRYPTO_DSTATUS_CARRY_SHIFT;
935 __STATIC_INLINE uint8_t CRYPTO_DData0_4LSBitsRead(CRYPTO_TypeDef *crypto)
937 return (crypto->DSTATUS & _CRYPTO_DSTATUS_DDATA0LSBS_MASK)
938 >> _CRYPTO_DSTATUS_DDATA0LSBS_SHIFT;
957 __STATIC_INLINE
void CRYPTO_DData0Read260(CRYPTO_TypeDef *crypto,
958 CRYPTO_Data260_TypeDef val)
960 CRYPTO_DDataRead(&crypto->DDATA0, val);
961 val[8] = (crypto->DSTATUS & _CRYPTO_DSTATUS_DDATA0MSBS_MASK)
962 >> _CRYPTO_DSTATUS_DDATA0MSBS_SHIFT;
981 __STATIC_INLINE
void CRYPTO_DData0Write260(CRYPTO_TypeDef *crypto,
982 const CRYPTO_Data260_TypeDef val)
984 CRYPTO_DDataWrite(&crypto->DDATA0, val);
985 crypto->DDATA0BYTE32 = val[8] & _CRYPTO_DDATA0BYTE32_DDATA0BYTE32_MASK;
1004 __STATIC_INLINE
bool CRYPTO_DData1_MSBitRead(CRYPTO_TypeDef *crypto)
1006 return (crypto->DSTATUS & _CRYPTO_DSTATUS_DDATA1MSB_MASK)
1007 >> _CRYPTO_DSTATUS_DDATA1MSB_SHIFT;
1027 void CRYPTO_InstructionSequenceLoad(CRYPTO_TypeDef *crypto,
1028 const CRYPTO_InstructionSequence_TypeDef instructionSequence)
1030 const uint32_t * pas = (
const uint32_t *) instructionSequence;
1032 crypto->SEQ0 = pas[0];
1033 crypto->SEQ1 = pas[1];
1034 crypto->SEQ2 = pas[2];
1035 crypto->SEQ3 = pas[3];
1036 crypto->SEQ4 = pas[4];
1050 __STATIC_INLINE
void CRYPTO_InstructionSequenceExecute(CRYPTO_TypeDef *crypto)
1053 crypto->CMD = CRYPTO_CMD_SEQSTART;
1069 __STATIC_INLINE
bool CRYPTO_InstructionSequenceDone(CRYPTO_TypeDef *crypto)
1072 return !(crypto->STATUS
1073 & (CRYPTO_STATUS_INSTRRUNNING | CRYPTO_STATUS_SEQRUNNING));
1087 __STATIC_INLINE
void CRYPTO_InstructionSequenceWait(CRYPTO_TypeDef *crypto)
1089 while (!CRYPTO_InstructionSequenceDone(crypto))
1104 __STATIC_INLINE
void CRYPTO_InstructionWait(CRYPTO_TypeDef *crypto)
1107 while (!(crypto->IF & CRYPTO_IF_INSTRDONE))
1109 crypto->IFC = CRYPTO_IF_INSTRDONE;
1112 void CRYPTO_SHA_1(CRYPTO_TypeDef *crypto,
1115 CRYPTO_SHA1_Digest_TypeDef digest);
1117 void CRYPTO_SHA_256(CRYPTO_TypeDef *crypto,
1120 CRYPTO_SHA256_Digest_TypeDef digest);
1122 void CRYPTO_Mul(CRYPTO_TypeDef *crypto,
1123 uint32_t * A,
int aSize,
1124 uint32_t * B,
int bSize,
1125 uint32_t * R,
int rSize);
1127 void CRYPTO_AES_CBC128(CRYPTO_TypeDef *crypto,
1131 const uint8_t * key,
1135 void CRYPTO_AES_CBC256(CRYPTO_TypeDef *crypto,
1139 const uint8_t * key,
1143 void CRYPTO_AES_CFB128(CRYPTO_TypeDef *crypto,
1147 const uint8_t * key,
1151 void CRYPTO_AES_CFB256(CRYPTO_TypeDef *crypto,
1155 const uint8_t * key,
1159 void CRYPTO_AES_CTR128(CRYPTO_TypeDef *crypto,
1163 const uint8_t * key,
1165 CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc);
1167 void CRYPTO_AES_CTR256(CRYPTO_TypeDef *crypto,
1171 const uint8_t * key,
1173 CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc);
1175 void CRYPTO_AES_CTRUpdate32Bit(uint8_t * ctr);
1176 void CRYPTO_AES_DecryptKey128(CRYPTO_TypeDef *crypto, uint8_t * out,
const uint8_t * in);
1177 void CRYPTO_AES_DecryptKey256(CRYPTO_TypeDef *crypto, uint8_t * out,
const uint8_t * in);
1179 void CRYPTO_AES_ECB128(CRYPTO_TypeDef *crypto,
1183 const uint8_t * key,
1186 void CRYPTO_AES_ECB256(CRYPTO_TypeDef *crypto,
1190 const uint8_t * key,
1193 void CRYPTO_AES_OFB128(CRYPTO_TypeDef *crypto,
1197 const uint8_t * key,
1198 const uint8_t * iv);
1200 void CRYPTO_AES_OFB256(CRYPTO_TypeDef *crypto,
1204 const uint8_t * key,
1205 const uint8_t * iv);
1218 __STATIC_INLINE
void CRYPTO_IntClear(CRYPTO_TypeDef *crypto, uint32_t flags)
1220 crypto->IFC = flags;
1234 __STATIC_INLINE
void CRYPTO_IntDisable(CRYPTO_TypeDef *crypto, uint32_t flags)
1236 crypto->IEN &= ~(flags);
1255 __STATIC_INLINE
void CRYPTO_IntEnable(CRYPTO_TypeDef *crypto, uint32_t flags)
1257 crypto->IEN |= flags;
1274 __STATIC_INLINE uint32_t CRYPTO_IntGet(CRYPTO_TypeDef *crypto)
1296 __STATIC_INLINE uint32_t CRYPTO_IntGetEnabled(CRYPTO_TypeDef *crypto)
1305 return crypto->IF & tmp;
1319 __STATIC_INLINE
void CRYPTO_IntSet(CRYPTO_TypeDef *crypto, uint32_t flags)
1321 crypto->IFS = flags;
1338 __STATIC_INLINE
void AES_CBC128(uint8_t * out,
1341 const uint8_t * key,
1345 CRYPTO_AES_CBC128(CRYPTO, out, in, len, key, iv, encrypt);
1357 __STATIC_INLINE
void AES_CBC256(uint8_t * out,
1360 const uint8_t * key,
1364 CRYPTO_AES_CBC256(CRYPTO, out, in, len, key, iv, encrypt);
1375 __STATIC_INLINE
void AES_CFB128(uint8_t * out,
1378 const uint8_t * key,
1382 CRYPTO_AES_CFB128(CRYPTO, out, in, len, key, iv, encrypt);
1393 __STATIC_INLINE
void AES_CFB256(uint8_t * out,
1396 const uint8_t * key,
1400 CRYPTO_AES_CFB256(CRYPTO, out, in, len, key, iv, encrypt);
1411 __STATIC_INLINE
void AES_CTR128(uint8_t * out,
1414 const uint8_t * key,
1416 CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc)
1418 CRYPTO_AES_CTR128(CRYPTO, out, in, len, key, ctr, ctrFunc);
1429 __STATIC_INLINE
void AES_CTR256(uint8_t * out,
1432 const uint8_t * key,
1434 CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc)
1436 CRYPTO_AES_CTR256(CRYPTO, out, in, len, key, ctr, ctrFunc);
1449 CRYPTO_AES_CTRUpdate32Bit(ctr);
1463 CRYPTO_AES_DecryptKey128(CRYPTO, out, in);
1475 __STATIC_INLINE
void AES_DecryptKey256(uint8_t * out,
const uint8_t * in)
1477 CRYPTO_AES_DecryptKey256(CRYPTO, out, in);
1489 __STATIC_INLINE
void AES_ECB128(uint8_t * out,
1492 const uint8_t * key,
1495 CRYPTO_AES_ECB128(CRYPTO, out, in, len, key, encrypt);
1507 __STATIC_INLINE
void AES_ECB256(uint8_t * out,
1510 const uint8_t * key,
1513 CRYPTO_AES_ECB256(CRYPTO, out, in, len, key, encrypt);
1524 __STATIC_INLINE
void AES_OFB128(uint8_t * out,
1527 const uint8_t * key,
1530 CRYPTO_AES_OFB128(CRYPTO, out, in, len, key, iv);
1541 __STATIC_INLINE
void AES_OFB256(uint8_t * out,
1544 const uint8_t * key,
1547 CRYPTO_AES_OFB256(CRYPTO, out, in, len, key, iv);
void AES_CTRUpdate32Bit(uint8_t *ctr)
Update last 32 bits of 128 bit counter, by incrementing with 1.
void AES_DecryptKey128(uint8_t *out, const uint8_t *in)
Generate 128 bit decryption key from 128 bit encryption key. The decryption key is used for some ciph...
RAM and peripheral bit-field set and clear API.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
void AES_CTR128(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, uint8_t *ctr, AES_CtrFuncPtr_TypeDef ctrFunc)
Counter (CTR) cipher mode encryption/decryption, 128 bit key.
void AES_OFB128(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv)
Output feedback (OFB) cipher mode encryption/decryption, 128 bit key.
void AES_CBC128(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
Cipher-block chaining (CBC) cipher mode encryption/decryption, 128 bit key.
__STATIC_INLINE void BUS_RegBitWrite(volatile uint32_t *addr, unsigned int bit, unsigned int val)
Perform a single-bit write operation on a peripheral register.
void AES_ECB128(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, bool encrypt)
Electronic Codebook (ECB) cipher mode encryption/decryption, 128 bit key.
void AES_CFB128(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
Cipher feedback (CFB) cipher mode encryption/decryption, 128 bit key.