• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************/
18 /**	@page AES
19  *
20  *	Introduction
21  *	===============
22  *	TLSRB91 supports hardware AES function.
23  *
24  *	API Reference
25  *	===============
26  *	Header File: aes.h
27  */
28 #ifndef _AES_H_
29 #define _AES_H_
30 
31 #include "./reg_include/aes_reg.h"
32 #include "compiler.h"
33 
34 /**********************************************************************************************************************
35  *                                         global constants                                                           *
36  *********************************************************************************************************************/
37 
38 /**********************************************************************************************************************
39  *                                           global macro                                                             *
40  *********************************************************************************************************************/
41 
42 /**********************************************************************************************************************
43  *                                         global data type                                                           *
44  *********************************************************************************************************************/
45 /**
46  * @brief AES mode.
47  */
48 typedef enum {
49     AES_ENCRYPT_MODE = 0,
50     AES_DECRYPT_MODE = 2,
51 } aes_mode_e;
52 /**********************************************************************************************************************
53  *                                     global variable declaration                                                    *
54  *********************************************************************************************************************/
55 
56 /**********************************************************************************************************************
57  *                                      global function prototype                                                     *
58  *********************************************************************************************************************/
59 /* @brief     This function refer to encrypt. AES module register must be used by word. , all data need big endian.
60  * @param[in] key       - the key of encrypt.
61  * @param[in] plaintext - the plaintext of encrypt.
62  * @param[in] result    - the result of encrypt.
63  * @return    none
64  */
65 int aes_encrypt(unsigned char *key, unsigned char *plaintext, unsigned char *result);
66 
67 /**
68  * @brief     This function refer to decrypt. AES module register must be used by word., all data need big endian.
69  * @param[in] key         - the key of decrypt.
70  * @param[in] decrypttext - the decrypttext of decrypt.
71  * @param[in] result      - the result of decrypt.
72  * @return    none.
73  */
74 int aes_decrypt(unsigned char *key, unsigned char *decrypttext, unsigned char *result);
75 
76 /**
77  * @brief     This function refer to set the base addr of data which use in CEVA module
78  * @param[in] addr - the base addr of CEVA data.
79  * @return    none.
80  */
81 void aes_set_em_base_addr(unsigned int addr);
82 
83 /**
84  * @brief     This function refer to encrypt/decrypt to set key and data. AES module register must be used by word.
85  * 				All data need Little endian.
86  * @param[in] key  - the key of encrypt/decrypt.
87  * @param[in] data - the data which to do encrypt/decrypt.
88  * @return    none
89  */
90 void aes_set_key_data(unsigned char *key, unsigned char *data);
91 
92 /**
93  * @brief     This function refer to encrypt/decrypt to get result. AES module register must be used by word.
94  * @param[in] result - the result of encrypt/decrypt. Little endian
95  * @return    none.
96  */
97 void aes_get_result(unsigned char *result);
98 
99 /**
100  * @brief     This function refer to set aes mode.
101  * @param[in] mode - the irq mask.
102  * @return    none.
103  */
aes_set_mode(aes_mode_e mode)104 static inline void aes_set_mode(aes_mode_e mode)
105 {
106     reg_aes_mode = (FLD_AES_START | mode);
107 }
108 
109 /**
110  * @brief     This function refer to set aes irq mask.
111  * @param[in] mask - the irq mask.
112  * @return    none.
113  */
aes_set_irq_mask(aes_irq_e mask)114 static inline void aes_set_irq_mask(aes_irq_e mask)
115 {
116     reg_aes_irq_mask |= mask;
117 }
118 
119 /**
120  * @brief     This function refer to clr aes irq mask.
121  * @param[in] mask - the irq mask.
122  * @return    none.
123  */
aes_clr_irq_mask(aes_irq_e mask)124 static inline void aes_clr_irq_mask(aes_irq_e mask)
125 {
126     reg_aes_irq_mask &= (~mask);
127 }
128 
129 /**
130  * @brief     This function refer to get aes irq status.
131  * @param[in] status - the irq status to get.
132  * @return    none.
133  */
aes_get_irq_status(aes_irq_e status)134 static inline int aes_get_irq_status(aes_irq_e status)
135 {
136     return (reg_aes_irq_status & status);
137 }
138 
139 /**
140  * @brief     This function refer to clr aes irq status.
141  * @param[in] status - the irq status to clear.
142  * @return    none.
143  */
aes_clr_irq_status(aes_irq_e status)144 static inline void aes_clr_irq_status(aes_irq_e status)
145 {
146     reg_aes_clr_irq_status = (status);
147 }
148 
149 #endif /* _AES_H_ */
150