1 /***********************************************************************
2  * All rights reserved.
3  * Filename    : aes.h
4  * Description : aes driver header file
5  * Author(s)   : Eric
6  * version     : V1.0
7  * Modify date : 2016-03-24
8  ***********************************************************************/
9 #ifndef __AES_H__
10 #define __AES_H__
11 
12 #include "ACM32Fxx_HAL.h"
13 
14 #define AES_ENCRYPTION   		1
15 #define AES_DECRYPTION   		0
16 #define AES_ECB_MODE	   		0
17 #define AES_CBC_MODE	   		1
18 #define AES_SWAP_ENABLE  		1
19 #define AES_SWAP_DISABLE 		0
20 
21 #define AES_NORMAL_MODE   	0x12345678
22 #define AES_SECURITY_MODE 	0
23 
24 #define AES_KEY_128     0
25 #define AES_KEY_192     1
26 #define AES_KEY_256     2
27 
28 #define AES_FAIL   0x00
29 #define AES_PASS   0xa59ada68
30 
31 #define BIT_AES        (1<<28)
32 
33 /************************************************************************
34  * function   : delay
35  * Description: delay for a while.
36  * input :
37  *         count: count to decrease
38  * return: none
39  ************************************************************************/
40  extern void delay(uint32_t count);
41 
42 
43 /******************************************************************************
44  * Name:     HAL_AES_SetKey
45  * Function: set key of AES
46  * Input:
47 		     keyin		 --	pointer to buffer of key
48 		     key_len     --	select length of key(AES_KEY_128/ AES_KEY_192/ AES_KEY_256)
49 		     swap_en     -- AES_SWAP_ENABLE, AES_SWAP_DISABLE
50  * Return:	 None
51 *******************************************************************************/
52 void HAL_AES_SetKey(UINT32 *keyin, UINT8 key_len, UINT8 swap_en);
53 void HAL_AES_SetKey_U8(UINT8 *keyin, UINT8 key_len, UINT8 swap_en);
54 
55 
56 /******************************************************************************
57 Name:		 HAL_AES_Crypt
58 Function:	 Function for AES encryption and decryption
59 Input:
60          indata		       --   pointer to buffer of input
61          outdata	       --	pointer to buffer of result
62          block_len	       --	block(128bit) length for aes cryption
63          operation	       --	AES_ENCRYPTION,AES_DECRYPTION
64          mode              --   AES_ECB_MODE, AES_CBC_MODE,
65          iv                --   initial vector for CBC mode
66          security_mode     --   AES_NORMAL_MODE, AES_SECURITY_MODE
67 Return:	 None
68 
69 *******************************************************************************/
70 uint32_t HAL_AES_Crypt(
71     uint32_t *indata,
72     uint32_t *outdata,
73     uint32_t block_len,
74     uint8_t  operation,
75     uint8_t  mode,
76     uint32_t *iv,
77     uint32_t security_mode
78 );
79 
80 
81 uint32_t HAL_AES_Crypt_U8(
82     uint8_t *indata,
83     uint8_t *outdata,
84     uint32_t block_len,
85     uint8_t  operation,
86     uint8_t  mode,
87     uint8_t *iv,
88     uint32_t security_mode
89 );
90 
91 #endif
92 /******************************************************************************
93  * end of file
94 *******************************************************************************/
95