MSP430 DriverLib for MSP430FR5xx_6xx Devices  2.21.00.08
 All Data Structures Functions Variables Modules Pages
aes256.h
1 //*****************************************************************************
2 //
3 // aes256.h - Driver for the AES256 Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_AES256_H__
8 #define __MSP430WARE_AES256_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_AES256__
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 to the keyLength parameter for
28 // functions: AES256_setCipherKey(), AES256_setDecipherKey(), and
29 // AES256_startSetDecipherKey().
30 //
31 //*****************************************************************************
32 #define AES256_KEYLENGTH_128BIT 128
33 #define AES256_KEYLENGTH_192BIT 192
34 #define AES256_KEYLENGTH_256BIT 256
35 
36 //*****************************************************************************
37 //
38 // The following are values that can be passed toThe following are values that
39 // can be returned by the AES256_getErrorFlagStatus() function.
40 //
41 //*****************************************************************************
42 #define AES256_ERROR_OCCURRED AESERRFG
43 #define AES256_NO_ERROR 0x00
44 
45 //*****************************************************************************
46 //
47 // The following are values that can be passed toThe following are values that
48 // can be returned by the AES256_isBusy() function.
49 //
50 //*****************************************************************************
51 #define AES256_BUSY AESBUSY
52 #define AES256_NOT_BUSY 0x00
53 
54 //*****************************************************************************
55 //
56 // The following are values that can be passed toThe following are values that
57 // can be returned by the AES256_getInterruptStatus() function.
58 //
59 //*****************************************************************************
60 #define AES256_READY_INTERRUPT AESRDYIE
61 #define AES256_NOTREADY_INTERRUPT 0x00
62 
63 //*****************************************************************************
64 //
65 // Prototypes for the APIs.
66 //
67 //*****************************************************************************
68 
69 //*****************************************************************************
70 //
71 //! \brief Loads a 128, 192 or 256 bit cipher key to AES256 module.
72 //!
73 //! This function loads a 128, 192 or 256 bit cipher key to AES256 module.
74 //! Requires both a key as well as the length of the key provided. Acceptable
75 //! key lengths are AES256_KEYLENGTH_128BIT, AES256_KEYLENGTH_192BIT, or
76 //! AES256_KEYLENGTH_256BIT
77 //!
78 //! \param baseAddress is the base address of the AES256 module.
79 //! \param cipherKey is a pointer to an uint8_t array with a length of 16 bytes
80 //! that contains a 128 bit cipher key.
81 //! \param keyLength is the length of the key.
82 //! Valid values are:
83 //! - \b AES256_KEYLENGTH_128BIT
84 //! - \b AES256_KEYLENGTH_192BIT
85 //! - \b AES256_KEYLENGTH_256BIT
86 //!
87 //! \return STATUS_SUCCESS or STATUS_FAIL of key loading
88 //
89 //*****************************************************************************
90 extern uint8_t AES256_setCipherKey(uint16_t baseAddress,
91  const uint8_t *cipherKey,
92  uint16_t keyLength);
93 
94 //*****************************************************************************
95 //
96 //! \brief Encrypts a block of data using the AES256 module.
97 //!
98 //! The cipher key that is used for encryption should be loaded in advance by
99 //! using function AES256_setCipherKey()
100 //!
101 //! \param baseAddress is the base address of the AES256 module.
102 //! \param data is a pointer to an uint8_t array with a length of 16 bytes that
103 //! contains data to be encrypted.
104 //! \param encryptedData is a pointer to an uint8_t array with a length of 16
105 //! bytes in that the encrypted data will be written.
106 //!
107 //! \return None
108 //
109 //*****************************************************************************
110 extern void AES256_encryptData(uint16_t baseAddress,
111  const uint8_t *data,
112  uint8_t *encryptedData);
113 
114 //*****************************************************************************
115 //
116 //! \brief Decrypts a block of data using the AES256 module.
117 //!
118 //! This function requires a pregenerated decryption key. A key can be loaded
119 //! and pregenerated by using function AES256_setDecipherKey() or
120 //! AES256_startSetDecipherKey(). The decryption takes 167 MCLK.
121 //!
122 //! \param baseAddress is the base address of the AES256 module.
123 //! \param data is a pointer to an uint8_t array with a length of 16 bytes that
124 //! contains encrypted data to be decrypted.
125 //! \param decryptedData is a pointer to an uint8_t array with a length of 16
126 //! bytes in that the decrypted data will be written.
127 //!
128 //! \return None
129 //
130 //*****************************************************************************
131 extern void AES256_decryptData(uint16_t baseAddress,
132  const uint8_t *data,
133  uint8_t *decryptedData);
134 
135 //*****************************************************************************
136 //
137 //! \brief Sets the decipher key.
138 //!
139 //! The API AES256_startSetDecipherKey or AES256_setDecipherKey must be invoked
140 //! before invoking AES256_startDecryptData.
141 //!
142 //! \param baseAddress is the base address of the AES256 module.
143 //! \param cipherKey is a pointer to an uint8_t array with a length of 16 bytes
144 //! that contains a 128 bit cipher key.
145 //! \param keyLength is the length of the key.
146 //! Valid values are:
147 //! - \b AES256_KEYLENGTH_128BIT
148 //! - \b AES256_KEYLENGTH_192BIT
149 //! - \b AES256_KEYLENGTH_256BIT
150 //!
151 //! \return STATUS_SUCCESS or STATUS_FAIL of key loading
152 //
153 //*****************************************************************************
154 extern uint8_t AES256_setDecipherKey(uint16_t baseAddress,
155  const uint8_t *cipherKey,
156  uint16_t keyLength);
157 
158 //*****************************************************************************
159 //
160 //! \brief Clears the AES256 ready interrupt flag.
161 //!
162 //! This function clears the AES256 ready interrupt flag. This flag is
163 //! automatically cleared when AES256ADOUT is read, or when AES256AKEY or
164 //! AES256ADIN is written. This function should be used when the flag needs to
165 //! be reset and it has not been automatically cleared by one of the previous
166 //! actions.
167 //!
168 //! \param baseAddress is the base address of the AES256 module.
169 //!
170 //! Modified bits are \b AESRDYIFG of \b AESACTL0 register.
171 //!
172 //! \return None
173 //
174 //*****************************************************************************
175 extern void AES256_clearInterrupt(uint16_t baseAddress);
176 
177 //*****************************************************************************
178 //
179 //! \brief Gets the AES256 ready interrupt flag status.
180 //!
181 //! This function checks the AES256 ready interrupt flag. This flag is
182 //! automatically cleared when AES256ADOUT is read, or when AES256AKEY or
183 //! AES256ADIN is written. This function can be used to confirm that this has
184 //! been done.
185 //!
186 //! \param baseAddress is the base address of the AES256 module.
187 //!
188 //! \return One of the following:
189 //! - \b AES256_READY_INTERRUPT
190 //! - \b AES256_NOTREADY_INTERRUPT
191 //! \n indicating the status of the AES256 ready status
192 //
193 //*****************************************************************************
194 extern uint32_t AES256_getInterruptStatus(uint16_t baseAddress);
195 
196 //*****************************************************************************
197 //
198 //! \brief Enables AES256 ready interrupt.
199 //!
200 //! Enables AES256 ready interrupt. This interrupt is reset by a PUC, but not
201 //! reset by AES256_reset.
202 //!
203 //! \param baseAddress is the base address of the AES256 module.
204 //!
205 //! Modified bits are \b AESRDYIE of \b AESACTL0 register.
206 //!
207 //! \return None
208 //
209 //*****************************************************************************
210 extern void AES256_enableInterrupt(uint16_t baseAddress);
211 
212 //*****************************************************************************
213 //
214 //! \brief Disables AES256 ready interrupt.
215 //!
216 //! Disables AES256 ready interrupt. This interrupt is reset by a PUC, but not
217 //! reset by AES256_reset.
218 //!
219 //! \param baseAddress is the base address of the AES256 module.
220 //!
221 //! Modified bits are \b AESRDYIE of \b AESACTL0 register.
222 //!
223 //! \return None
224 //
225 //*****************************************************************************
226 extern void AES256_disableInterrupt(uint16_t baseAddress);
227 
228 //*****************************************************************************
229 //
230 //! \brief Resets AES256 Module immediately.
231 //!
232 //! This function performs a software reset on the AES256 Module, note that
233 //! this does not affect the AES256 ready interrupt.
234 //!
235 //! \param baseAddress is the base address of the AES256 module.
236 //!
237 //! Modified bits are \b AESSWRST of \b AESACTL0 register.
238 //!
239 //! \return None
240 //
241 //*****************************************************************************
242 extern void AES256_reset(uint16_t baseAddress);
243 
244 //*****************************************************************************
245 //
246 //! \brief Starts an encryption process on the AES256 module.
247 //!
248 //! The cipher key that is used for decryption should be loaded in advance by
249 //! using function AES256_setCipherKey(). This is a non-blocking equivalent of
250 //! AES256_encryptData(). It is recommended to use the interrupt functionality
251 //! to check for procedure completion then use the AES256_getDataOut() API to
252 //! retrieve the encrypted data.
253 //!
254 //! \param baseAddress is the base address of the AES256 module.
255 //! \param data is a pointer to an uint8_t array with a length of 16 bytes that
256 //! contains data to be encrypted.
257 //!
258 //! \return None
259 //
260 //*****************************************************************************
261 extern void AES256_startEncryptData(uint16_t baseAddress,
262  const uint8_t *data);
263 
264 //*****************************************************************************
265 //
266 //! \brief Decrypts a block of data using the AES256 module.
267 //!
268 //! This is the non-blocking equivalent of AES256_decryptData(). This function
269 //! requires a pregenerated decryption key. A key can be loaded and
270 //! pregenerated by using function AES256_setDecipherKey() or
271 //! AES256_startSetDecipherKey(). The decryption takes 167 MCLK. It is
272 //! recommended to use interrupt to check for procedure completion then use the
273 //! AES256_getDataOut() API to retrieve the decrypted data.
274 //!
275 //! \param baseAddress is the base address of the AES256 module.
276 //! \param data is a pointer to an uint8_t array with a length of 16 bytes that
277 //! contains encrypted data to be decrypted.
278 //!
279 //! \return None
280 //
281 //*****************************************************************************
282 extern void AES256_startDecryptData(uint16_t baseAddress,
283  const uint8_t *data);
284 
285 //*****************************************************************************
286 //
287 //! \brief Sets the decipher key
288 //!
289 //! The API AES256_startSetDecipherKey() or AES256_setDecipherKey() must be
290 //! invoked before invoking AES256_startDecryptData.
291 //!
292 //! \param baseAddress is the base address of the AES256 module.
293 //! \param cipherKey is a pointer to an uint8_t array with a length of 16 bytes
294 //! that contains a 128 bit cipher key.
295 //! \param keyLength is the length of the key.
296 //! Valid values are:
297 //! - \b AES256_KEYLENGTH_128BIT
298 //! - \b AES256_KEYLENGTH_192BIT
299 //! - \b AES256_KEYLENGTH_256BIT
300 //!
301 //! \return STATUS_SUCCESS or STATUS_FAIL of key loading
302 //
303 //*****************************************************************************
304 extern uint8_t AES256_startSetDecipherKey(uint16_t baseAddress,
305  const uint8_t *cipherKey,
306  uint16_t keyLength);
307 
308 //*****************************************************************************
309 //
310 //! \brief Reads back the output data from AES256 module.
311 //!
312 //! This function is meant to use after an encryption or decryption process
313 //! that was started and finished by initiating an interrupt by use of
314 //! AES256_startEncryptData or AES256_startDecryptData functions.
315 //!
316 //! \param baseAddress is the base address of the AES256 module.
317 //! \param outputData is a pointer to an uint8_t array with a length of 16
318 //! bytes in that the data will be written.
319 //!
320 //! \return STATUS_SUCCESS if data is valid, otherwise STATUS_FAIL
321 //
322 //*****************************************************************************
323 extern uint8_t AES256_getDataOut(uint16_t baseAddress,
324  uint8_t *outputData);
325 
326 //*****************************************************************************
327 //
328 //! \brief Gets the AES256 module busy status.
329 //!
330 //! Gets the AES256 module busy status. If a key or data are written while the
331 //! AES256 module is busy, an error flag will be thrown.
332 //!
333 //! \param baseAddress is the base address of the AES256 module.
334 //!
335 //! \return One of the following:
336 //! - \b AES256_BUSY
337 //! - \b AES256_NOT_BUSY
338 //! \n indicating if the AES256 module is busy
339 //
340 //*****************************************************************************
341 extern uint16_t AES256_isBusy(uint16_t baseAddress);
342 
343 //*****************************************************************************
344 //
345 //! \brief Clears the AES256 error flag.
346 //!
347 //! Clears the AES256 error flag that results from a key or data being written
348 //! while the AES256 module is busy.
349 //!
350 //! \param baseAddress is the base address of the AES256 module.
351 //!
352 //! Modified bits are \b AESERRFG of \b AESACTL0 register.
353 //!
354 //! \return None
355 //
356 //*****************************************************************************
357 extern void AES256_clearErrorFlag(uint16_t baseAddress);
358 
359 //*****************************************************************************
360 //
361 //! \brief Gets the AES256 error flag status.
362 //!
363 //! Checks the AES256 error flag that results from a key or data being written
364 //! while the AES256 module is busy. If the flag is set, it needs to be cleared
365 //! using AES256_clearErrorFlag.
366 //!
367 //! \param baseAddress is the base address of the AES256 module.
368 //!
369 //! \return One of the following:
370 //! - \b AES256_ERROR_OCCURRED
371 //! - \b AES256_NO_ERROR
372 //! \n indicating the error flag status
373 //
374 //*****************************************************************************
375 extern uint32_t AES256_getErrorFlagStatus(uint16_t baseAddress);
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_AES256_H__
void AES256_decryptData(uint16_t baseAddress, const uint8_t *data, uint8_t *decryptedData)
Decrypts a block of data using the AES256 module.
Definition: aes256.c:98
uint16_t AES256_isBusy(uint16_t baseAddress)
Gets the AES256 module busy status.
Definition: aes256.c:311
void AES256_encryptData(uint16_t baseAddress, const uint8_t *data, uint8_t *encryptedData)
Encrypts a block of data using the AES256 module.
Definition: aes256.c:62
uint8_t AES256_getDataOut(uint16_t baseAddress, uint8_t *outputData)
Reads back the output data from AES256 module.
Definition: aes256.c:289
void AES256_reset(uint16_t baseAddress)
Resets AES256 Module immediately.
Definition: aes256.c:199
void AES256_startDecryptData(uint16_t baseAddress, const uint8_t *data)
Decrypts a block of data using the AES256 module.
Definition: aes256.c:226
uint8_t AES256_setDecipherKey(uint16_t baseAddress, const uint8_t *cipherKey, uint16_t keyLength)
Sets the decipher key.
Definition: aes256.c:133
void AES256_enableInterrupt(uint16_t baseAddress)
Enables AES256 ready interrupt.
Definition: aes256.c:189
uint8_t AES256_setCipherKey(uint16_t baseAddress, const uint8_t *cipherKey, uint16_t keyLength)
Loads a 128, 192 or 256 bit cipher key to AES256 module.
Definition: aes256.c:21
void AES256_clearErrorFlag(uint16_t baseAddress)
Clears the AES256 error flag.
Definition: aes256.c:316
void AES256_disableInterrupt(uint16_t baseAddress)
Disables AES256 ready interrupt.
Definition: aes256.c:194
uint8_t AES256_startSetDecipherKey(uint16_t baseAddress, const uint8_t *cipherKey, uint16_t keyLength)
Sets the decipher key.
Definition: aes256.c:248
uint32_t AES256_getErrorFlagStatus(uint16_t baseAddress)
Gets the AES256 error flag status.
Definition: aes256.c:321
uint32_t AES256_getInterruptStatus(uint16_t baseAddress)
Gets the AES256 ready interrupt flag status.
Definition: aes256.c:184
void AES256_clearInterrupt(uint16_t baseAddress)
Clears the AES256 ready interrupt flag.
Definition: aes256.c:179
void AES256_startEncryptData(uint16_t baseAddress, const uint8_t *data)
Starts an encryption process on the AES256 module.
Definition: aes256.c:204

Copyright 2015, Texas Instruments Incorporated