MSP430 DriverLib for MSP430F5xx_6xx Devices  2.80.00.01
 All Data Structures Functions Variables Modules Pages
aes.h
1 //*****************************************************************************
2 //
3 // aes.h - Driver for the AES Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_AES_H__
8 #define __MSP430WARE_AES_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_AES__
13 
14 //*****************************************************************************
15 //
16 // If building with a C++ compiler, make all of the definitions in this header
17 // have a C binding.
18 //
19 //*****************************************************************************
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 //*****************************************************************************
26 //
27 // The following are values that can be passed toThe following are values that
28 // can be returned by the AES_isBusy() function.
29 //
30 //*****************************************************************************
31 #define AES_BUSY AESBUSY
32 #define AES_NOT_BUSY 0x00
33 
34 //*****************************************************************************
35 //
36 // The following are values that can be passed toThe following are values that
37 // can be returned by the AES_getErrorFlagStatus() function.
38 //
39 //*****************************************************************************
40 #define AES_ERROR_OCCURRED AESERRFG
41 #define AES_NO_ERROR 0x00
42 
43 //*****************************************************************************
44 //
45 // Prototypes for the APIs.
46 //
47 //*****************************************************************************
48 
49 //*****************************************************************************
50 //
51 //! \brief Loads a 128 bit cipher key to AES module.
52 //!
53 //! This function loads a 128 bit cipher key to AES module.
54 //!
55 //! \param baseAddress is the base address of the AES module.
56 //! \param CipherKey is a pointer to an uint8_t array with a length of 16 bytes
57 //! that contains a 128 bit cipher key.
58 //!
59 //! \return STATUS_SUCCESS
60 //
61 //*****************************************************************************
62 extern uint8_t AES_setCipherKey(uint16_t baseAddress,
63  const uint8_t *CipherKey);
64 
65 //*****************************************************************************
66 //
67 //! \brief Encrypts a block of data using the AES module.
68 //!
69 //! The cipher key that is used for encryption should be loaded in advance by
70 //! using function \b AES_setCipherKey()
71 //!
72 //! \param baseAddress is the base address of the AES module.
73 //! \param Data is a pointer to an uint8_t array with a length of 16 bytes that
74 //! contains data to be encrypted.
75 //! \param encryptedData is a pointer to an uint8_t array with a length of 16
76 //! bytes in that the encrypted data will be written.
77 //!
78 //! \return STATUS_SUCCESS
79 //
80 //*****************************************************************************
81 extern uint8_t AES_encryptData(uint16_t baseAddress,
82  const uint8_t *Data,
83  uint8_t *encryptedData);
84 
85 //*****************************************************************************
86 //
87 //! \brief Decrypts a block of data using the AES module.
88 //!
89 //! This function requires a pre-generated decryption key. A key can be loaded
90 //! and pre-generated by using function \b AES_startSetDecipherKey() or \b
91 //! AES_setDecipherKey(). The decryption takes 167 MCLK.
92 //!
93 //! \param baseAddress is the base address of the AES module.
94 //! \param Data is a pointer to an uint8_t array with a length of 16 bytes that
95 //! contains encrypted data to be decrypted.
96 //! \param decryptedData is a pointer to an uint8_t array with a length of 16
97 //! bytes in that the decrypted data will be written.
98 //!
99 //! \return STATUS_SUCCESS
100 //
101 //*****************************************************************************
102 extern uint8_t AES_decryptData(uint16_t baseAddress,
103  const uint8_t *Data,
104  uint8_t *decryptedData);
105 
106 //*****************************************************************************
107 //
108 //! \brief Sets the decipher key The API
109 //!
110 //! The API \b AES_startSetDecipherKey() or \b AES_setDecipherKey() must be
111 //! invoked before invoking \b AES_setDecipherKey().
112 //!
113 //! \param baseAddress is the base address of the AES module.
114 //! \param CipherKey is a pointer to an uint8_t array with a length of 16 bytes
115 //! that contains the initial AES key.
116 //!
117 //! \return STATUS_SUCCESS
118 //
119 //*****************************************************************************
120 extern uint8_t AES_setDecipherKey(uint16_t baseAddress,
121  const uint8_t *CipherKey);
122 
123 //*****************************************************************************
124 //
125 //! \brief Clears the AES ready interrupt flag.
126 //!
127 //! This function clears the AES ready interrupt flag. This flag is
128 //! automatically cleared when AESADOUT is read, or when AESAKEY or AESADIN is
129 //! written. This function should be used when the flag needs to be reset and
130 //! it has not been automatically cleared by one of the previous actions.
131 //!
132 //! \param baseAddress is the base address of the AES module.
133 //!
134 //! Modified bits are \b AESRDYIFG of \b AESACTL0 register.
135 //!
136 //! \return None
137 //
138 //*****************************************************************************
139 extern void AES_clearInterrupt(uint16_t baseAddress);
140 
141 //*****************************************************************************
142 //
143 //! \brief Gets the AES ready interrupt flag status.
144 //!
145 //! This function checks the AES ready interrupt flag. This flag is
146 //! automatically cleared when AESADOUT is read, or when AESAKEY or AESADIN is
147 //! written. This function can be used to confirm that this has been done.
148 //!
149 //! \param baseAddress is the base address of the AES module.
150 //!
151 //! \return uint32_t - AES_READY_INTERRUPT or 0x00.
152 //
153 //*****************************************************************************
154 extern uint32_t AES_getInterruptStatus(uint16_t baseAddress);
155 
156 //*****************************************************************************
157 //
158 //! \brief Enables AES ready interrupt.
159 //!
160 //! Enables AES ready interrupt. This interrupt is reset by a PUC, but not
161 //! reset by AES_reset. Does not clear interrupt flags.
162 //!
163 //! \param baseAddress is the base address of the AES module.
164 //!
165 //! Modified bits are \b AESRDYIE of \b AESACTL0 register.
166 //!
167 //! \return None
168 //
169 //*****************************************************************************
170 extern void AES_enableInterrupt(uint16_t baseAddress);
171 
172 //*****************************************************************************
173 //
174 //! \brief Disables AES ready interrupt.
175 //!
176 //! Disables AES ready interrupt. This interrupt is reset by a PUC, but not
177 //! reset by AES_reset.
178 //!
179 //! \param baseAddress is the base address of the AES module.
180 //!
181 //! Modified bits are \b AESRDYIE of \b AESACTL0 register.
182 //!
183 //! \return None
184 //
185 //*****************************************************************************
186 extern void AES_disableInterrupt(uint16_t baseAddress);
187 
188 //*****************************************************************************
189 //
190 //! \brief Resets AES Module immediately.
191 //!
192 //! This function performs a software reset on the AES Module, note that this
193 //! does not affect the AES ready interrupt.
194 //!
195 //! \param baseAddress is the base address of the AES module.
196 //!
197 //! Modified bits are \b AESSWRST of \b AESACTL0 register.
198 //!
199 //! \return None
200 //
201 //*****************************************************************************
202 extern void AES_reset(uint16_t baseAddress);
203 
204 //*****************************************************************************
205 //
206 //! \brief Starts an encryption process on the AES module.
207 //!
208 //! This is the non-blocking equivalent of AES_encryptData(). The cipher key
209 //! that is used for decryption should be loaded in advance by using function
210 //! \b AES_setCipherKey(). It is recommended to use interrupt to check for
211 //! procedure completion then using AES_getDataOut() API to retrieve the
212 //! encrypted data.
213 //!
214 //! \param baseAddress is the base address of the AES module.
215 //! \param Data is a pointer to an uint8_t array with a length of 16 bytes that
216 //! contains data to be encrypted.
217 //! \param encryptedData is a pointer to an uint8_t array with a length of 16
218 //! bytes in that the encrypted data will be written.
219 //!
220 //! \return STATUS_SUCCESS
221 //
222 //*****************************************************************************
223 extern uint8_t AES_startEncryptData(uint16_t baseAddress,
224  const uint8_t *Data,
225  uint8_t *encryptedData);
226 
227 //*****************************************************************************
228 //
229 //! \brief Decrypts a block of data using the AES module.
230 //!
231 //! This is the non-blocking equivalent of AES_decryptData(). This function
232 //! requires a pre-generated decryption key. A key can be loaded and pre-
233 //! generated by using function \b AES_setDecipherKey() or \b
234 //! AES_startSetDecipherKey(). The decryption takes 167 MCLK. It is recommended
235 //! to use interrupt to check for procedure completion then using
236 //! AES_getDataOut() API to retrieve the decrypted data.
237 //!
238 //! \param baseAddress is the base address of the AES module.
239 //! \param Data is a pointer to an uint8_t array with a length of 16 bytes that
240 //! contains encrypted data to be decrypted.
241 //!
242 //! \return STATUS_SUCCESS
243 //
244 //*****************************************************************************
245 extern uint8_t AES_startDecryptData(uint16_t baseAddress,
246  const uint8_t *Data);
247 
248 //*****************************************************************************
249 //
250 //! \brief Loads the decipher key.
251 //!
252 //! This is the non-blocking equivalent of AES_setDecipherKey(). The API \b
253 //! AES_startSetDecipherKey() or \b AES_setDecipherKey() must be invoked before
254 //! invoking \b AES_startSetDecipherKey().
255 //!
256 //! \param baseAddress is the base address of the AES module.
257 //! \param CipherKey is a pointer to an uint8_t array with a length of 16 bytes
258 //! that contains the initial AES key.
259 //!
260 //! \return STATUS_SUCCESS
261 //
262 //*****************************************************************************
263 extern uint8_t AES_startSetDecipherKey(uint16_t baseAddress,
264  const uint8_t *CipherKey);
265 
266 //*****************************************************************************
267 //
268 //! \brief Reads back the output data from AES module.
269 //!
270 //! This function is meant to use after an encryption or decryption process
271 //! that was started and finished by initiating an interrupt by use of the \b
272 //! AES_startEncryptData() or \b AES_startDecryptData() functions.
273 //!
274 //! \param baseAddress is the base address of the AES module.
275 //! \param OutputData is a pointer to an uint8_t array with a length of 16
276 //! bytes in which the output data of the AES module is available. If
277 //! AES module is busy returns NULL.
278 //!
279 //! \return STATUS_SUCCESS if AES is not busy, STATUS_FAIL if it is busy
280 //
281 //*****************************************************************************
282 extern uint8_t AES_getDataOut(uint16_t baseAddress,
283  uint8_t *OutputData);
284 
285 //*****************************************************************************
286 //
287 //! \brief Gets the AES module busy status.
288 //!
289 //! Gets the AES module busy status. If a key or data are written while the AES
290 //! module is busy, an error flag will be thrown.
291 //!
292 //! \param baseAddress is the base address of the AES module.
293 //!
294 //! \return One of the following:
295 //! - \b AES_BUSY
296 //! - \b AES_NOT_BUSY
297 //! \n indicating if encryption/decryption/key generation is taking
298 //! place
299 //
300 //*****************************************************************************
301 extern uint8_t AES_isBusy(uint16_t baseAddress);
302 
303 //*****************************************************************************
304 //
305 //! \brief Clears the AES error flag.
306 //!
307 //! Clears the AES error flag that results from a key or data being written
308 //! while the AES module is busy. Modified bit is AESERRFG of AESACTL0
309 //! register.
310 //!
311 //! \param baseAddress is the base address of the AES module.
312 //!
313 //! Modified bits are \b AESERRFG of \b AESACTL0 register.
314 //!
315 //! \return None
316 //
317 //*****************************************************************************
318 extern void AES_clearErrorFlag(uint16_t baseAddress);
319 
320 //*****************************************************************************
321 //
322 //! \brief Gets the AES error flag status.
323 //!
324 //! Checks the AES error flag that results from a key or data being written
325 //! while the AES module is busy. If the flag is set, it needs to be cleared
326 //! using AES_clearErrorFlag.
327 //!
328 //! \param baseAddress is the base address of the AES module.
329 //!
330 //! \return One of the following:
331 //! - \b AES_ERROR_OCCURRED
332 //! - \b AES_NO_ERROR
333 //! \n indicating if AESAKEY or AESADIN were written while an AES
334 //! operation was in progress
335 //
336 //*****************************************************************************
337 extern uint32_t AES_getErrorFlagStatus(uint16_t baseAddress);
338 
339 //*****************************************************************************
340 //
341 //! \brief DEPRECATED Starts an decryption process on the AES module.
342 //!
343 //! This is the non-blocking equivalent of AES_decryptDataUsingEncryptionKey().
344 //! This function can be used to decrypt data by using the same key as used for
345 //! a previous performed encryption. The decryption takes 214 MCLK.
346 //!
347 //! \param baseAddress is the base address of the AES module.
348 //! \param Data is a pointer to an uint8_t array with a length of 16 bytes that
349 //! contains encrypted data to be decrypted.
350 //!
351 //! \return STATUS_SUCCESS
352 //
353 //*****************************************************************************
354 extern uint8_t AES_startDecryptDataUsingEncryptionKey(uint16_t baseAddress,
355  const uint8_t *Data);
356 
357 //*****************************************************************************
358 //
359 //! \brief DEPRECATED Decrypts a block of data using the AES module.
360 //!
361 //! This function can be used to decrypt data by using the same key as used for
362 //! a previous performed encryption. The decryption takes 214 MCLK.
363 //!
364 //! \param baseAddress is the base address of the AES module.
365 //! \param Data is a pointer to an uint8_t array with a length of 16 bytes that
366 //! contains encrypted data to be decrypted.
367 //! \param decryptedData is a pointer to an uint8_t array with a length of 16
368 //! bytes in that the decrypted data will be written.
369 //!
370 //! \return STATUS_SUCCESS
371 //
372 //*****************************************************************************
373 extern uint8_t AES_decryptDataUsingEncryptionKey(uint16_t baseAddress,
374  const uint8_t *Data,
375  uint8_t *decryptedData);
376 
377 //*****************************************************************************
378 //
379 // Mark the end of the C bindings section for C++ compilers.
380 //
381 //*****************************************************************************
382 #ifdef __cplusplus
383 }
384 #endif
385 
386 #endif
387 #endif // __MSP430WARE_AES_H__
uint8_t AES_decryptDataUsingEncryptionKey(uint16_t baseAddress, const uint8_t *Data, uint8_t *decryptedData)
DEPRECATED Decrypts a block of data using the AES module.
Definition: aes.c:301
uint8_t AES_decryptData(uint16_t baseAddress, const uint8_t *Data, uint8_t *decryptedData)
Decrypts a block of data using the AES module.
Definition: aes.c:83
void AES_enableInterrupt(uint16_t baseAddress)
Enables AES ready interrupt.
Definition: aes.c:154
uint8_t AES_getDataOut(uint16_t baseAddress, uint8_t *OutputData)
Reads back the output data from AES module.
Definition: aes.c:238
uint32_t AES_getErrorFlagStatus(uint16_t baseAddress)
Gets the AES error flag status.
Definition: aes.c:270
uint32_t AES_getInterruptStatus(uint16_t baseAddress)
Gets the AES ready interrupt flag status.
Definition: aes.c:149
uint8_t AES_startEncryptData(uint16_t baseAddress, const uint8_t *Data, uint8_t *encryptedData)
Starts an encryption process on the AES module.
Definition: aes.c:169
uint8_t AES_isBusy(uint16_t baseAddress)
Gets the AES module busy status.
Definition: aes.c:260
uint8_t AES_encryptData(uint16_t baseAddress, const uint8_t *Data, uint8_t *encryptedData)
Encrypts a block of data using the AES module.
Definition: aes.c:44
uint8_t AES_startDecryptData(uint16_t baseAddress, const uint8_t *Data)
Decrypts a block of data using the AES module.
Definition: aes.c:194
uint8_t AES_startDecryptDataUsingEncryptionKey(uint16_t baseAddress, const uint8_t *Data)
DEPRECATED Starts an decryption process on the AES module.
Definition: aes.c:275
uint8_t AES_startSetDecipherKey(uint16_t baseAddress, const uint8_t *CipherKey)
Loads the decipher key.
Definition: aes.c:218
void AES_clearErrorFlag(uint16_t baseAddress)
Clears the AES error flag.
Definition: aes.c:265
uint8_t AES_setCipherKey(uint16_t baseAddress, const uint8_t *CipherKey)
Loads a 128 bit cipher key to AES module.
Definition: aes.c:21
uint8_t AES_setDecipherKey(uint16_t baseAddress, const uint8_t *CipherKey)
Sets the decipher key The API.
Definition: aes.c:120
void AES_clearInterrupt(uint16_t baseAddress)
Clears the AES ready interrupt flag.
Definition: aes.c:144
void AES_disableInterrupt(uint16_t baseAddress)
Disables AES ready interrupt.
Definition: aes.c:159
void AES_reset(uint16_t baseAddress)
Resets AES Module immediately.
Definition: aes.c:164

Copyright 2016, Texas Instruments Incorporated