| NUC472_NUC442_BSP V3.03.003 The Board Support Package for NUC472/NUC442

crypto.h
Go to the documentation of this file.
1/**************************************************************************/
12#ifndef __CRYPTO_H__
13#define __CRYPTO_H__
14
15#ifdef __cplusplus
16 extern "C"
17{
18#endif
19
33#define PRNG_KEY_SIZE_64 0
34#define PRNG_KEY_SIZE_128 1
35#define PRNG_KEY_SIZE_192 2
36#define PRNG_KEY_SIZE_256 3
38#define PRNG_SEED_CONT 0
39#define PRNG_SEED_RELOAD 1
41#define AES_KEY_SIZE_128 0
42#define AES_KEY_SIZE_192 1
43#define AES_KEY_SIZE_256 2
45#define AES_MODE_ECB 0
46#define AES_MODE_CBC 1
47#define AES_MODE_CFB 2
48#define AES_MODE_OFB 3
49#define AES_MODE_CTR 4
50#define AES_MODE_CBC_CS1 0x10
51#define AES_MODE_CBC_CS2 0x11
52#define AES_MODE_CBC_CS3 0x12
54#define AES_NO_SWAP 0
55#define AES_OUT_SWAP 1
56#define AES_IN_SWAP 2
57#define AES_IN_OUT_SWAP 3
59#define DES_MODE_ECB 0x000
60#define DES_MODE_CBC 0x100
61#define DES_MODE_CFB 0x200
62#define DES_MODE_OFB 0x300
63#define DES_MODE_CTR 0x400
64#define TDES_MODE_ECB 0x004
65#define TDES_MODE_CBC 0x104
66#define TDES_MODE_CFB 0x204
67#define TDES_MODE_OFB 0x304
68#define TDES_MODE_CTR 0x404
70#define TDES_NO_SWAP 0
71#define TDES_WHL_SWAP 1
72#define TDES_OUT_SWAP 2
73#define TDES_OUT_WHL_SWAP 3
74#define TDES_IN_SWAP 4
75#define TDES_IN_WHL_SWAP 5
76#define TDES_IN_OUT_SWAP 6
77#define TDES_IN_OUT_WHL_SWAP 7
79#define SHA_MODE_SHA1 0
80#define SHA_MODE_SHA224 5
81#define SHA_MODE_SHA256 4
83#define SHA_NO_SWAP 0
84#define SHA_OUT_SWAP 1
85#define SHA_IN_SWAP 2
86#define SHA_IN_OUT_SWAP 3
88#define CRYPTO_DMA_ONE_SHOT 0x5
89#define CRYPTO_DMA_CONTINUE 0x6
90#define CRYPTO_DMA_LAST 0x6 /* end of group NUC472_442_CRYPTO_EXPORTED_CONSTANTS */
93
94
95
96
101/*----------------------------------------------------------------------------------------------*/
102/* Macros */
103/*----------------------------------------------------------------------------------------------*/
104
111#define PRNG_ENABLE_INT() (CRPT->INTEN |= CRPT_INTEN_PRNGIEN_Msk)
112
119#define PRNG_DISABLE_INT() (CRPT->INTEN &= ~CRPT_INTEN_PRNGIEN_Msk)
120
127#define PRNG_GET_INT_FLAG() (CRPT->INTSTS & CRPT_INTSTS_PRNGIF_Msk)
128
135#define PRNG_CLR_INT_FLAG() (CRPT->INTSTS = CRPT_INTSTS_PRNGIF_Msk)
136
143#define AES_ENABLE_INT() (CRPT->INTEN |= (CRPT_INTEN_AESIEN_Msk|CRPT_INTEN_AESERRIEN_Msk))
144
151#define AES_DISABLE_INT() (CRPT->INTEN &= ~(CRPT_INTEN_AESIEN_Msk|CRPT_INTEN_AESERRIEN_Msk))
152
159#define AES_GET_INT_FLAG() (CRPT->INTSTS & (CRPT_INTSTS_AESIF_Msk|CRPT_INTSTS_AESERRIF_Msk))
160
167#define AES_CLR_INT_FLAG() (CRPT->INTSTS = (CRPT_INTSTS_AESIF_Msk|CRPT_INTSTS_AESERRIF_Msk))
168
175#define AES_ENABLE_KEY_PROTECT() (CRPT->AES_CTL |= CRPT_AES_CTL_KEYPRT_Msk)
176
183#define AES_DISABLE_KEY_PROTECT() (CRPT->AES_CTL = (CRPT->AES_CTL & ~CRPT_AES_CTL_KEYPRT_Msk) | (0x16<<CRPT_AES_CTL_KEYUNPRT_Pos))
184
191#define TDES_ENABLE_INT() (CRPT->INTEN |= (CRPT_INTEN_TDESIEN_Msk|CRPT_INTEN_TDESERRIEN_Msk))
192
199#define TDES_DISABLE_INT() (CRPT->INTEN &= ~(CRPT_INTEN_TDESIEN_Msk|CRPT_INTEN_TDESERRIEN_Msk))
200
207#define TDES_GET_INT_FLAG() (CRPT->INTSTS & (CRPT_INTSTS_TDESIF_Msk|CRPT_INTSTS_TDESERRIF_Msk))
208
215#define TDES_CLR_INT_FLAG() (CRPT->INTSTS = (CRPT_INTSTS_TDESIF_Msk|CRPT_INTSTS_TDESERRIF_Msk))
216
223#define TDES_ENABLE_KEY_PROTECT() (CRPT->TDES_CTL |= CRPT_TDES_CTL_KEYPRT_Msk)
224
231#define TDES_DISABLE_KEY_PROTECT() (CRPT->TDES_CTL = (CRPT->TDES_CTL & ~CRPT_TDES_CTL_KEYPRT_Msk) | (0x16<<CRPT_TDES_CTL_KEYUNPRT_Pos))
232
239#define SHA_ENABLE_INT() (CRPT->INTEN |= (CRPT_INTEN_SHAIEN_Msk|CRPT_INTEN_SHAERRIEN_Msk))
240
247#define SHA_DISABLE_INT() (CRPT->INTEN &= ~(CRPT_INTEN_SHAIEN_Msk|CRPT_INTEN_SHAERRIEN_Msk))
248
255#define SHA_GET_INT_FLAG() (CRPT->INTSTS & (CRPT_INTSTS_SHAIF_Msk|CRPT_INTSTS_SHAERRIF_Msk))
256
263#define SHA_CLR_INT_FLAG() (CRPT->INTSTS = (CRPT_INTSTS_SHAIF_Msk|CRPT_INTSTS_SHAERRIF_Msk))
264
265
266
267/*---------------------------------------------------------------------------------------------------------*/
268/* Functions */
269/*---------------------------------------------------------------------------------------------------------*/
270
271 void PRNG_Open(uint32_t u32KeySize, uint32_t u32SeedReload, uint32_t u32Seed);
272 void PRNG_Start(void);
273 void PRNG_Read(uint32_t u32RandKey[]);
274 void AES_Open(uint32_t u32Channel, uint32_t u32EncDec, uint32_t u32OpMode, uint32_t u32KeySize, uint32_t u32SwapType);
275 void AES_Start(int32_t u32Channel, uint32_t u32DMAMode);
276 void AES_SetKey(uint32_t u32Channel, uint32_t au32Keys[], uint32_t u32KeySize);
277 void AES_SetInitVect(uint32_t u32Channel, uint32_t au32IV[]);
278 void AES_SetDMATransfer(uint32_t u32Channel, uint32_t u32SrcAddr, uint32_t u32DstAddr, uint32_t u32TransCnt);
279 void TDES_Open(uint32_t u32Channel, uint32_t u32EncDec, int32_t Is3DES, int32_t Is3Key, uint32_t u32OpMode, uint32_t u32SwapType);
280 void TDES_Start(int32_t u32Channel, uint32_t u32DMAMode);
281 void TDES_SetKey(uint32_t u32Channel, uint32_t au32Keys[3][2]);
282 void TDES_SetInitVect(uint32_t u32Channel, uint32_t u32IVH, uint32_t u32IVL);
283 void TDES_SetDMATransfer(uint32_t u32Channel, uint32_t u32SrcAddr, uint32_t u32DstAddr, uint32_t u32TransCnt);
284 void SHA_Open(uint32_t u32OpMode, uint32_t u32SwapType);
285 void SHA_Start(uint32_t u32DMAMode);
286 void SHA_SetDMATransfer(uint32_t u32SrcAddr, uint32_t u32TransCnt);
287 void SHA_Read(uint32_t u32Digest[]);
288
289 /* end of group NUC472_442_CRYPTO_EXPORTED_FUNCTIONS */
291 /* end of group NUC472_442_CRYPTO_Driver */
293 /* end of group NUC472_442_Device_Driver */
295
296#ifdef __cplusplus
297}
298#endif
299
300#endif // __CRYPTO_H__
301
302/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
303
TDES_Open
void TDES_Open(uint32_t u32Channel, uint32_t u32EncDec, int32_t Is3DES, int32_t Is3Key, uint32_t u32OpMode, uint32_t u32SwapType)
Open TDES encrypt/decrypt function.
Definition: crypto.c:222
SHA_Open
void SHA_Open(uint32_t u32OpMode, uint32_t u32SwapType)
Open SHA encrypt function.
Definition: crypto.c:328
TDES_SetDMATransfer
void TDES_SetDMATransfer(uint32_t u32Channel, uint32_t u32SrcAddr, uint32_t u32DstAddr, uint32_t u32TransCnt)
Set TDES DMA transfer configuration.
Definition: crypto.c:300
AES_Open
void AES_Open(uint32_t u32Channel, uint32_t u32EncDec, uint32_t u32OpMode, uint32_t u32KeySize, uint32_t u32SwapType)
Open AES encrypt/decrypt function.
Definition: crypto.c:107
PRNG_Open
void PRNG_Open(uint32_t u32KeySize, uint32_t u32SeedReload, uint32_t u32Seed)
Open PRNG function.
Definition: crypto.c:49
SHA_Read
void SHA_Read(uint32_t u32Digest[])
Read the SHA digest.
Definition: crypto.c:365
PRNG_Read
void PRNG_Read(uint32_t u32RandKey[])
Read the PRNG key.
Definition: crypto.c:73
AES_SetInitVect
void AES_SetInitVect(uint32_t u32Channel, uint32_t au32IV[])
Set AES initial vectors.
Definition: crypto.c:163
PRNG_Start
void PRNG_Start(void)
Start to generate one PRNG key.
Definition: crypto.c:63
AES_SetDMATransfer
void AES_SetDMATransfer(uint32_t u32Channel, uint32_t u32SrcAddr, uint32_t u32DstAddr, uint32_t u32TransCnt)
Set AES DMA transfer configuration.
Definition: crypto.c:184
TDES_SetKey
void TDES_SetKey(uint32_t u32Channel, uint32_t au32Keys[3][2])
Set TDES keys.
Definition: crypto.c:259
TDES_Start
void TDES_Start(int32_t u32Channel, uint32_t u32DMAMode)
Start TDES encrypt/decrypt.
Definition: crypto.c:247
AES_SetKey
void AES_SetKey(uint32_t u32Channel, uint32_t au32Keys[], uint32_t u32KeySize)
Set AES keys.
Definition: crypto.c:143
AES_Start
void AES_Start(int32_t u32Channel, uint32_t u32DMAMode)
Start AES encrypt/decrypt.
Definition: crypto.c:127
SHA_Start
void SHA_Start(uint32_t u32DMAMode)
Start SHA encrypt.
Definition: crypto.c:342
SHA_SetDMATransfer
void SHA_SetDMATransfer(uint32_t u32SrcAddr, uint32_t u32TransCnt)
Set SHA DMA transfer.
Definition: crypto.c:354
TDES_SetInitVect
void TDES_SetInitVect(uint32_t u32Channel, uint32_t u32IVH, uint32_t u32IVL)
Set TDES initial vectors.
Definition: crypto.c:281