CC26xx Driver Library
[crypto] Crypto

Functions

uint32_t CRYPTOAesLoadKey (uint32_t *pui32AesKey, uint32_t ui32KeyLocation)
 Write the key into the Key Ram. More...
 
uint32_t CRYPTOAesCbc (uint32_t *pui32MsgIn, uint32_t *pui32MsgOut, uint32_t ui32MsgLength, uint32_t *pui32Nonce, uint32_t ui32KeyLocation, bool bEncrypt, bool bIntEnable)
 Start an AES-CBC operation (encryption or decryption). More...
 
uint32_t CRYPTOAesCbcStatus (void)
 Check the result of an AES CBC operation. More...
 
uint32_t CRYPTOAesEcb (uint32_t *pui32MsgIn, uint32_t *pui32MsgOut, uint32_t ui32KeyLocation, bool bEncrypt, bool bIntEnable)
 Start an AES-ECB operation (encryption or decryption). More...
 
uint32_t CRYPTOAesEcbStatus (void)
 Check the result of an AES ECB operation. More...
 
static void CRYPTOAesEcbFinish (void)
 Finish the encryption operation by resetting the operation mode. More...
 
static void CRYPTOAesCbcFinish (void)
 Finish the encryption operation by resetting the operation mode. More...
 
uint32_t CRYPTOCcmAuthEncrypt (bool bEncrypt, uint32_t ui32AuthLength, uint32_t *pui32Nonce, uint32_t *pui32PlainText, uint32_t ui32PlainTextLength, uint32_t *pui32Header, uint32_t ui32HeaderLength, uint32_t ui32KeyLocation, uint32_t ui32FieldLength, bool bIntEnable)
 Start CCM operation. More...
 
uint32_t CRYPTOCcmAuthEncryptStatus (void)
 Check the result of an AES CCM operation. More...
 
uint32_t CRYPTOCcmAuthEncryptResultGet (uint32_t ui32TagLength, uint32_t *pui32CcmTag)
 Get the result of an AES CCM operation. More...
 
uint32_t CRYPTOCcmInvAuthDecrypt (bool bDecrypt, uint32_t ui32AuthLength, uint32_t *pui32Nonce, uint32_t *pui32CipherText, uint32_t ui32CipherTextLength, uint32_t *pui32Header, uint32_t ui32HeaderLength, uint32_t ui32KeyLocation, uint32_t ui32FieldLength, bool bIntEnable)
 Start a CCM Decryption and Inverse Authentication operation. More...
 
uint32_t CRYPTOCcmInvAuthDecryptStatus (void)
 Checks CCM decrypt and Inverse Authentication result. More...
 
uint32_t CRYPTOCcmInvAuthDecryptResultGet (uint32_t ui32AuthLength, uint32_t *pui32CipherText, uint32_t ui32CipherTextLength, uint32_t *pui32CcmTag)
 Get the result of the CCM operation. More...
 
static uint32_t CRYPTODmaStatus (void)
 Get the current status of the Crypto DMA controller. More...
 
void CRYPTODmaEnable (uint32_t ui32Channels)
 Enable Crypto DMA operation. More...
 
void CRYPTODmaDisable (uint32_t ui32Channels)
 Disable Crypto DMA operation. More...
 
static void CRYPTOIntEnable (uint32_t ui32IntFlags)
 Enables individual Crypto interrupt sources. More...
 
static void CRYPTOIntDisable (uint32_t ui32IntFlags)
 Disables individual CRYPTO interrupt sources. More...
 
static uint32_t CRYPTOIntStatus (bool bMasked)
 Gets the current interrupt status. More...
 
static void CRYPTOIntClear (uint32_t ui32IntFlags)
 Clears Crypto interrupt sources. More...
 
static void CRYPTOIntRegister (void(*pfnHandler)(void))
 Registers an interrupt handler for a Crypto interrupt. More...
 
static void CRYPTOIntUnregister (void)
 Unregisters an interrupt handler for a Crypto interrupt. More...
 

Detailed Description

Function Documentation

uint32_t CRYPTOAesCbc ( uint32_t *  pui32MsgIn,
uint32_t *  pui32MsgOut,
uint32_t  ui32MsgLength,
uint32_t *  pui32Nonce,
uint32_t  ui32KeyLocation,
bool  bEncrypt,
bool  bIntEnable 
)

Start an AES-CBC operation (encryption or decryption).

The function starts an AES CBC mode encypt or decrypt operation. End operation can be deteced by enabling interrupt or by polling CRYPTOAesCbcStatus(). Result of operation is returned by CRYPTOAesCbcStatus().

Parameters
pui32MsgInis a pointer to the input data.
pui32MsgOutis a pointer to the output data.
ui32MsgLengthis the length in bytes of the input data.
pui32Nonceis a pointer to 16-byte Nonce.
ui32KeyLocationis the location of the key in Key RAM. This parameter can have any of the following values:
bEncryptis set true to encrypt or set false to decrypt.
bIntEnableis set true to enable Crypto interrupts or false to disable Crypto interrupt.
Returns
Returns status of the AES-CBC operation:
See also
CRYPTOAesCbcStatus()
173 {
174  uint32_t ui32CtrlVal;
175 
176  // Enable internal interrupts.
179 
180  // Clear any outstanding interrupts.
183 
184  // Wait for interrupt lines from module to be cleared
186 
187  // If using interrupts clear any pending interrupts and enable interrupts
188  // for the Crypto module.
189  if(bIntEnable)
190  {
191  IntPendClear(INT_CRYPTO_RESULT_AVAIL_IRQ);
192  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
193  }
194 
195  // Configure Master Control module.
197 
198  // Enable keys to read (e.g. Key 0).
199  HWREG(CRYPTO_BASE + CRYPTO_O_KEYREADAREA) = ui32KeyLocation;
200 
201  //Wait until key is loaded to the AES module.
202  do
203  {
204  CPUdelay(1);
205  }
207 
208  // Check for Key store Read error.
210  {
211  return (AES_KEYSTORE_READ_ERROR);
212  }
213 
214  // Write initialization vector.
215  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV0) = pui32Nonce[0];
216  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV1) = pui32Nonce[1];
217  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV2) = pui32Nonce[2];
218  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV3) = pui32Nonce[3];
219 
220  // Configure AES engine for AES-CBC with 128-bit key size.
222  if(bEncrypt)
223  {
224  ui32CtrlVal |= CRYPTO_AES128_ENCRYPT;
225  }
226  else
227  {
228  ui32CtrlVal |= CRYPTO_AES128_DECRYPT;
229  }
230  HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) = ui32CtrlVal;
231 
232  // Write the length of the crypto block (plain text).
233  // Low and high part (high part is assumed to be always 0).
234  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN0) = ui32MsgLength;
235  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN1) = 0;
236  HWREG(CRYPTO_BASE + CRYPTO_O_AESAUTHLEN) = 0;
237 
238  // Enable Crypto DMA channel 0.
240 
241  // Base address of the input data in ext. memory.
242  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32MsgIn;
243 
244  // Input data length in bytes, equal to the message.
245  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32MsgLength;
246 
247  // Enable Crypto DMA channel 1.
249 
250  // Set up the address and length of the output data.
251  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1EXTADDR) = (uint32_t)pui32MsgOut;
252  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1LEN) = ui32MsgLength;
253 
254  // Return success
255  return AES_SUCCESS;
256 }
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
Definition: crypto.h:120
void IntPendClear(uint32_t ui32Interrupt)
Unpends an interrupt.
Definition: interrupt.c:442
#define CRYPTO_AES128_ENCRYPT
Definition: crypto.h:126
#define CRYPTO_AES128_DECRYPT
Definition: crypto.h:127
#define AES_SUCCESS
Definition: crypto.h:140
void CPUdelay(uint32_t ui32Count)
Provide a small delay.
Definition: cpu.c:339
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:282
#define CRYPTO_KEY_ST_RD_ERR
Definition: crypto.h:118

Here is the call graph for this function:

static void CRYPTOAesCbcFinish ( void  )
inlinestatic

Finish the encryption operation by resetting the operation mode.

This function should be called after CRYPTOAesCbcStatus() has reported that the operation is finished successfully.

Returns
None
See also
CRYPTOAesCbcStatus()
374 {
375  // Result has already been copied to the output buffer by DMA.
376  // Disable master control/DMA clock and clear the operating mode.
377  HWREG(CRYPTO_BASE + CRYPTO_O_ALGSEL) = 0x00000000;
378  HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) = 0x00000000;
379 }
uint32_t CRYPTOAesCbcStatus ( void  )

Check the result of an AES CBC operation.

This function should be called after CRYPTOAesCbc() function to check if the AES CBC operation was successful.

Returns
Returns the status of the AES CBC operation:
See also
CRYPTOAesCbc()
265 {
266  return(CRYPTOAesEcbStatus());
267 }
uint32_t CRYPTOAesEcbStatus(void)
Check the result of an AES ECB operation.
Definition: crypto.c:358

Here is the call graph for this function:

uint32_t CRYPTOAesEcb ( uint32_t *  pui32MsgIn,
uint32_t *  pui32MsgOut,
uint32_t  ui32KeyLocation,
bool  bEncrypt,
bool  bIntEnable 
)

Start an AES-ECB operation (encryption or decryption).

The ui32KeyLocation parameter is an enumerated type which specifies the Key Ram location in which the key is stored.

Parameters
pui32MsgInis a pointer to the input data.
pui32MsgOutis a pointer to the output data.
ui32KeyLocationis the location of the key in Key RAM. This parameter can have any of the following values:
bEncryptis set true to encrypt or set false to decrypt.
bIntEnableis set true to enable Crypto interrupts or false to disable Crypto interrupt.
Returns
Returns status of the AES-ECB operation:
See also
CRYPTOAesEcbStatus()
278 {
279  // Enable internal interrupts.
282 
283  // Clear any outstanding interrupts.
286 
287  // Wait for interrupt lines from module to be cleared
289 
290  // If using interrupts clear any pending interrupts and enable interrupts
291  // for the Crypto module.
292  if(bIntEnable)
293  {
294  IntPendClear(INT_CRYPTO_RESULT_AVAIL_IRQ);
295  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
296  }
297 
298  // Configure Master Control module.
300 
301  // Enable keys to read (e.g. Key 0).
302  HWREG(CRYPTO_BASE + CRYPTO_O_KEYREADAREA) = ui32KeyLocation;
303 
304  //Wait until key is loaded to the AES module.
305  do
306  {
307  CPUdelay(1);
308  }
310 
311  // Check for Key store Read error.
313  {
314  return (AES_KEYSTORE_READ_ERROR);
315  }
316 
317  // Configure AES engine (program AES-ECB-128 encryption and no
318  // initialization vector - IV).
319  if(bEncrypt)
320  {
322  }
323  else
324  {
326  }
327 
328  // Write the length of the data.
330  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN1) = 0;
331 
332  // Enable Crypto DMA channel 0.
334 
335  // Base address of the input data in ext. memory.
336  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32MsgIn;
337 
338  // Input data length in bytes, equal to the message.
340 
341  // Enable Crypto DMA channel 1.
343 
344  // Set up the address and length of the output data.
345  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1EXTADDR) = (uint32_t)pui32MsgOut;
347 
348  // Return success
349  return AES_SUCCESS;
350 }
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
Definition: crypto.h:120
void IntPendClear(uint32_t ui32Interrupt)
Unpends an interrupt.
Definition: interrupt.c:442
#define CRYPTO_AES128_ENCRYPT
Definition: crypto.h:126
#define CRYPTO_AES128_DECRYPT
Definition: crypto.h:127
#define AES_ECB_LENGTH
Definition: crypto.h:106
#define AES_SUCCESS
Definition: crypto.h:140
void CPUdelay(uint32_t ui32Count)
Provide a small delay.
Definition: cpu.c:339
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:282
#define CRYPTO_KEY_ST_RD_ERR
Definition: crypto.h:118

Here is the call graph for this function:

static void CRYPTOAesEcbFinish ( void  )
inlinestatic

Finish the encryption operation by resetting the operation mode.

This function should be called after CRYPTOAesEcbStatus() has reported that the operation is finished successfully.

Returns
None
See also
CRYPTOAesEcbStatus()
353 {
354  // Result has already been copied to the output buffer by DMA.
355  // Disable master control/DMA clock and clear the operating mode.
356  HWREG(CRYPTO_BASE + CRYPTO_O_ALGSEL) = 0x00000000;
357  HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) = 0x00000000;
358 }
uint32_t CRYPTOAesEcbStatus ( void  )

Check the result of an AES ECB operation.

This function should be called after CRYPTOAesEcb() function to check if the AES ECB operation was successful.

Returns
Returns the status of the AES ECB operation:
See also
CRYPTOAesEcb()

Referenced by CRYPTOAesCbcStatus().

359 {
360  uint32_t ui32Status;
361 
362  // Get the current DMA status.
363  ui32Status = HWREG(CRYPTO_BASE + CRYPTO_O_DMASTAT);
364 
365  // Check if DMA is still busy.
366  if(ui32Status & CRYPTO_DMA_BSY)
367  {
368  return (AES_DMA_BSY);
369  }
370 
371  // Check the status of the DMA operation - return error if not success.
372  if(ui32Status & CRYPTO_DMA_BUS_ERROR)
373  {
374  return (AES_DMA_BUS_ERROR);
375  }
376 
377  // Operation successful - disable interrupt and return success.
378  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
379  return (AES_SUCCESS);
380 }
#define AES_DMA_BSY
Definition: crypto.h:148
#define CRYPTO_DMA_BUS_ERROR
Definition: crypto.h:131
#define AES_DMA_BUS_ERROR
Definition: crypto.h:143
#define CRYPTO_DMA_BSY
Definition: crypto.h:130
#define AES_SUCCESS
Definition: crypto.h:140
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:326

Here is the call graph for this function:

uint32_t CRYPTOAesLoadKey ( uint32_t *  pui32AesKey,
uint32_t  ui32KeyLocation 
)

Write the key into the Key Ram.

The ui32KeyLocation parameter is an enumerated type which specifies the Key Ram location in which the key is stored.

The pointer pui8AesKey has the address where the Key is stored.

Parameters
pui32AesKeyis a pointer to an AES Key.
ui32KeyLocationis the location of the key in Key RAM. This parameter can have any of the following values:
Returns
Returns status of the function:
84 {
85  uint32_t returnStatus = AES_KEYSTORE_READ_ERROR;
86 
87  // Check the arguments.
88  ASSERT((ui32KeyLocation == CRYPTO_KEY_AREA_0) |
89  (ui32KeyLocation == CRYPTO_KEY_AREA_1) |
90  (ui32KeyLocation == CRYPTO_KEY_AREA_2) |
91  (ui32KeyLocation == CRYPTO_KEY_AREA_3) |
92  (ui32KeyLocation == CRYPTO_KEY_AREA_4) |
93  (ui32KeyLocation == CRYPTO_KEY_AREA_5) |
94  (ui32KeyLocation == CRYPTO_KEY_AREA_6) |
95  (ui32KeyLocation == CRYPTO_KEY_AREA_7));
96 
97  // Disable the external interrupt to stop the interrupt form propagating
98  // from the module to the System CPU.
99  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
100 
101  // Clear any previously written key at the keyLocation
102  HWREG(CRYPTO_BASE + CRYPTO_O_KEYWRITTENAREA) = (0x00000001 << ui32KeyLocation);
103 
104  // Enable internal interrupts.
108 
109  // Configure master control module.
111 
112  // Clear any outstanding events.
115 
116  // Configure key store module for 128 bit operation.
117  // Do not write to the register if the correct key size is already set.
118  // Writing to this register causes all current keys to be invalidated.
121  }
122 
123  // Enable keys to write (e.g. Key 0).
124  HWREG(CRYPTO_BASE + CRYPTO_O_KEYWRITEAREA) = (0x00000001 << ui32KeyLocation);
125 
126  // Enable Crypto DMA channel 0.
128 
129  // Base address of the key in ext. memory.
130  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32AesKey;
131 
132  // Total key length in bytes (e.g. 16 for 1 x 128-bit key).
133  // Writing the length of the key enables the DMA operation.
135 
136  // Wait for the DMA operation to complete.
137  do
138  {
139  CPUdelay(1);
140  }
141  while(!(HWREG(CRYPTO_BASE + CRYPTO_O_IRQSTAT) & 0x00000001));
142 
143  // Check for errors in DMA and key store.
144  if((HWREG(CRYPTO_BASE + CRYPTO_O_IRQSTAT) &
147  {
148  // Acknowledge/clear the interrupt and disable the master control.
151  HWREG(CRYPTO_BASE + CRYPTO_O_ALGSEL) = 0x00000000;
152 
153  // Check key status, return success if key valid.
154  if(HWREG(CRYPTO_BASE + CRYPTO_O_KEYWRITTENAREA) & (0x00000001 << ui32KeyLocation))
155  {
156  returnStatus = AES_SUCCESS;
157  }
158  }
159 
160  // Return status.
161  return returnStatus;
162 }
#define CRYPTO_KEY_AREA_3
Definition: crypto.h:170
#define CRYPTO_KEY_AREA_1
Definition: crypto.h:168
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
#define CRYPTO_KEY_AREA_2
Definition: crypto.h:169
Definition: crypto.h:120
#define KEY_STORE_SIZE_128
Definition: crypto.h:155
#define ASSERT(expr)
Definition: debug.h:74
#define CRYPTO_KEY_AREA_7
Definition: crypto.h:174
#define CRYPTO_KEY_AREA_0
Definition: crypto.h:167
#define CRYPTO_KEY_AREA_5
Definition: crypto.h:172
#define CRYPTO_KEY_AREA_4
Definition: crypto.h:171
#define KEY_BLENGTH
Definition: crypto.h:152
#define AES_SUCCESS
Definition: crypto.h:140
void CPUdelay(uint32_t ui32Count)
Provide a small delay.
Definition: cpu.c:339
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:326
#define CRYPTO_KEY_AREA_6
Definition: crypto.h:173

Here is the call graph for this function:

uint32_t CRYPTOCcmAuthEncrypt ( bool  bEncrypt,
uint32_t  ui32AuthLength,
uint32_t *  pui32Nonce,
uint32_t *  pui32PlainText,
uint32_t  ui32PlainTextLength,
uint32_t *  pui32Header,
uint32_t  ui32HeaderLength,
uint32_t  ui32KeyLocation,
uint32_t  ui32FieldLength,
bool  bIntEnable 
)

Start CCM operation.

The ui32KeyLocation is an enumerated type which specifies the Key Ram location in which the key is stored.

Parameters
bEncryptdetermines whether to run encryption or not.
ui32AuthLengthis the the length of the authentication field - 0, 2, 4, 6, 8, 10, 12, 14 or 16 octets.
pui32Nonceis a pointer to 13-byte or 12-byte Nonce (Number used once).
pui32PlainTextis a pointer to the octet string input message.
ui32PlainTextLengthis the length of the message.
pui32Headeris the length of the header (Additional Authentication Data or AAD).
ui32HeaderLengthis the length of the header in octets.
ui32KeyLocationis the location in Key RAM where the key is stored. This parameter can have any of the following values:
ui32FieldLengthis the size of the length field (2 or 3).
bIntEnableenables interrupts.
Returns
Returns the status of the CCM operation
See also
CRYPTOCcmAuthEncryptStatus()
393 {
394  uint32_t ui32CtrlVal;
395  uint32_t i;
396  uint32_t *pui32CipherText;
397  union {
398  uint32_t w[4];
399  uint8_t b[16];
400  } ui8InitVec;
401 
402  // Input address for the encryption engine is the same as the output.
403  pui32CipherText = pui32PlainText;
404 
405  // Disable global interrupt, enable local interrupt and clear any pending
406  // interrupts.
407  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
410 
411  // Enable internal interrupts.
415 
416  // Configure master control module for AES operation.
418 
419  // Enable keys to read (e.g. Key 0).
420  HWREG(CRYPTO_BASE + CRYPTO_O_KEYREADAREA) = ui32KeyLocation;
421 
422  // Wait until key is loaded to the AES module.
423  do
424  {
425  CPUdelay(1);
426  }
428 
429  // Check for Key store Read error.
431  {
432  return (AES_KEYSTORE_READ_ERROR);
433  }
434 
435  // Prepare the initialization vector (IV),
436  // Length of Nonce l(n) = 15 - ui32FieldLength.
437  ui8InitVec.b[0] = ui32FieldLength - 1;
438  for(i = 0; i < 12; i++)
439  {
440  ui8InitVec.b[i + 1] = ((uint8_t*)pui32Nonce)[i];
441  }
442  if(ui32FieldLength == 2)
443  {
444  ui8InitVec.b[13] = ((uint8_t*)pui32Nonce)[12];
445  }
446  else
447  {
448  ui8InitVec.b[13] = 0;
449  }
450  ui8InitVec.b[14] = 0;
451  ui8InitVec.b[15] = 0;
452 
453  // Write initialization vector.
454  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV0) = ui8InitVec.w[0];
455  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV1) = ui8InitVec.w[1];
456  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV2) = ui8InitVec.w[2];
457  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV3) = ui8InitVec.w[3];
458 
459  // Configure AES engine.
460  ui32CtrlVal = ((ui32FieldLength - 1) << CRYPTO_AESCTL_CCM_L_S);
461  if ( ui32AuthLength >= 2 ) {
462  ui32CtrlVal |= ((( ui32AuthLength - 2 ) >> 1 ) << CRYPTO_AESCTL_CCM_M_S );
463  }
464  ui32CtrlVal |= CRYPTO_AESCTL_CCM;
465  ui32CtrlVal |= CRYPTO_AESCTL_CTR;
466  ui32CtrlVal |= CRYPTO_AESCTL_SAVE_CONTEXT;
467  ui32CtrlVal |= (KEY_STORE_SIZE_128 << CRYPTO_AESCTL_KEY_SIZE_S);
468  ui32CtrlVal |= (1 << CRYPTO_AESCTL_DIR_S);
469  ui32CtrlVal |= (CRYPTO_AES_CTR_128 << CRYPTO_AESCTL_CTR_WIDTH_S);
470 
471  // Write the configuration for 128 bit AES-CCM.
472  HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) = ui32CtrlVal;
473 
474  // Write the length of the crypto block (plain text).
475  // Low and high part (high part is assumed to be always 0).
476  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN0) = ui32PlainTextLength;
477  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN1) = 0;
478 
479  // Write the length of the header field.
480  // Also called AAD - Additional Authentication Data.
481  HWREG(CRYPTO_BASE + CRYPTO_O_AESAUTHLEN) = ui32HeaderLength;
482 
483  // Check if any header information (AAD).
484  // If so configure the DMA controller to fetch the header.
485  if(ui32HeaderLength != 0)
486  {
487  // Enable DMA channel 0.
489 
490  // Register the base address of the header (AAD).
491  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32Header;
492 
493  // Header length in bytes (may be non-block size aligned).
494  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32HeaderLength;
495 
496  // Wait for completion of the header data transfer, DMA_IN_DONE.
497  do
498  {
499  CPUdelay(1);
500  }
502 
503  // Check for DMA errors.
505  {
506  return AES_DMA_BUS_ERROR;
507  }
508  }
509 
510  // Clear interrupt status.
513 
514  // Wait for interrupt lines from module to be cleared
516 
517  // Disable CRYPTO_IRQEN_DMA_IN_DONE interrupt as we only
518  // want interrupt to trigger once RESULT_AVAIL occurs.
520 
521 
522  // Is using interrupts enable globally.
523  if(bIntEnable)
524  {
525  IntPendClear(INT_CRYPTO_RESULT_AVAIL_IRQ);
526  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
527  }
528 
529  // Enable interrupts locally.
531 
532  // Perform encryption if requested.
533  if(bEncrypt)
534  {
535  // Enable DMA channel 0
537 
538  // base address of the payload data in ext. memory.
540  (uint32_t)pui32PlainText;
541 
542  // Enable DMA channel 1
544 
545  // Base address of the output data buffer.
547  (uint32_t)pui32CipherText;
548 
549  // Payload data length in bytes, equal to the plaintext length.
550  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32PlainTextLength;
551  // Output data length in bytes, equal to the plaintext length.
552  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1LEN) = ui32PlainTextLength;
553  }
554 
555  return AES_SUCCESS;
556 }
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
Definition: crypto.h:120
void IntPendClear(uint32_t ui32Interrupt)
Unpends an interrupt.
Definition: interrupt.c:442
#define CRYPTO_AES_CTR_128
Definition: crypto.h:196
#define KEY_STORE_SIZE_128
Definition: crypto.h:155
#define CRYPTO_DMA_BUS_ERR
Definition: crypto.h:116
#define AES_DMA_BUS_ERROR
Definition: crypto.h:143
#define AES_SUCCESS
Definition: crypto.h:140
void CPUdelay(uint32_t ui32Count)
Provide a small delay.
Definition: cpu.c:339
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:326
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:282
#define CRYPTO_KEY_ST_RD_ERR
Definition: crypto.h:118

Here is the call graph for this function:

uint32_t CRYPTOCcmAuthEncryptResultGet ( uint32_t  ui32TagLength,
uint32_t *  pui32CcmTag 
)

Get the result of an AES CCM operation.

This function should be called after CRYPTOCcmAuthEncryptStatus().

Parameters
ui32TagLengthis length of the Tag.
pui32CcmTagis the location of the authentication Tag.
Returns
Returns AES_SUCCESS if successful.
See also
CRYPTOCcmAuthEncryptStatus()

Get the result of an AES CCM operation.

595 {
596  uint32_t volatile ui32Tag[4];
597  uint32_t ui32Idx;
598 
599  // Result has already been copied to the output buffer by DMA
600  // Disable master control.
601  HWREG(CRYPTO_BASE + CRYPTO_O_ALGSEL) = 0x00000000;
602 
603  // Read tag - wait for the context ready bit.
604  do
605  {
606  CPUdelay(1);
607  }
608  while(!(HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) &
610 
611  // Read the Tag registers.
612  ui32Tag[0] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT0);
613  ui32Tag[1] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT1);
614  ui32Tag[2] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT2);
615  ui32Tag[3] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT3);
616 
617  for(ui32Idx = 0; ui32Idx < ui32TagLength ; ui32Idx++)
618  {
619  *((uint8_t*)pui32CcmTag + ui32Idx) = *((uint8_t*)ui32Tag + ui32Idx);
620  }
621 
622  // Operation successful - clear interrupt status.
625  return AES_SUCCESS;
626 }
#define AES_SUCCESS
Definition: crypto.h:140
void CPUdelay(uint32_t ui32Count)
Provide a small delay.
Definition: cpu.c:339

Here is the call graph for this function:

uint32_t CRYPTOCcmAuthEncryptStatus ( void  )

Check the result of an AES CCM operation.

This function should be called after CRYPTOCcmAuthEncrypt() function to check if the AES CCM operation was successful.

Returns
Returns the status of the AES CCM operation:
See also
CRYPTOCcmAuthEncrypt()
565 {
566  uint32_t ui32Status;
567 
568  // Get the current DMA status.
569  ui32Status = HWREG(CRYPTO_BASE + CRYPTO_O_DMASTAT);
570 
571  // Check if DMA is still busy.
572  if(ui32Status & CRYPTO_DMA_BSY)
573  {
574  return (AES_DMA_BSY);
575  }
576 
577  // Check the status of the DMA operation - return error if not success.
578  if(ui32Status & CRYPTO_DMA_BUS_ERROR)
579  {
580  return (AES_DMA_BUS_ERROR);
581  }
582 
583  // Operation successful - disable interrupt and return success.
584  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
585  return (AES_SUCCESS);
586 }
#define AES_DMA_BSY
Definition: crypto.h:148
#define CRYPTO_DMA_BUS_ERROR
Definition: crypto.h:131
#define AES_DMA_BUS_ERROR
Definition: crypto.h:143
#define CRYPTO_DMA_BSY
Definition: crypto.h:130
#define AES_SUCCESS
Definition: crypto.h:140
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:326

Here is the call graph for this function:

uint32_t CRYPTOCcmInvAuthDecrypt ( bool  bDecrypt,
uint32_t  ui32AuthLength,
uint32_t *  pui32Nonce,
uint32_t *  pui32CipherText,
uint32_t  ui32CipherTextLength,
uint32_t *  pui32Header,
uint32_t  ui32HeaderLength,
uint32_t  ui32KeyLocation,
uint32_t  ui32FieldLength,
bool  bIntEnable 
)

Start a CCM Decryption and Inverse Authentication operation.

The ui32KeyLocation is an enumerated type which specifies the Key Ram location in which the key is stored.

Parameters
bDecryptdetermines whether to run decryption or not.
ui32AuthLengthis the the length of the authentication field - 0, 2, 4, 6, 8, 10, 12, 14 or 16 octets.
pui32Nonceis a pointer to 13-byte or 12-byte Nonce (Number used once).
pui32CipherTextis a pointer to the octet string encrypted message.
ui32CipherTextLengthis the length of the encrypted message.
pui32Headeris the length of the header (Additional Authentication Data or AAD).
ui32HeaderLengthis the length of the header in octets.
ui32KeyLocationis the location in Key RAM where the key is stored. This parameter can have any of the following values:
ui32FieldLengthis the size of the length field (2 or 3).
bIntEnableenables interrupts.
Returns
Returns the status of the operation:
640 {
641  uint32_t ui32CtrlVal;
642  uint32_t i;
643  uint32_t *pui32PlainText;
644  uint32_t ui32CryptoBlockLength;
645  union {
646  uint32_t w[4];
647  uint8_t b[16];
648  } ui8InitVec;
649 
650  // Input address for the encryption engine is the same as the output.
651  pui32PlainText = pui32CipherText;
652 
653  // Disable global interrupt, enable local interrupt and clear any pending.
654  // interrupts.
655  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
658  // Enable internal interrupts.
662 
663  // Configure master control module for AES operation.
665 
666  // Enable keys to read (e.g. Key 0).
667  HWREG(CRYPTO_BASE + CRYPTO_O_KEYREADAREA) = ui32KeyLocation;
668 
669  // Wait until key is loaded to the AES module.
670  do
671  {
672  CPUdelay(1);
673  }
675 
676  // Check for Key store Read error.
678  {
679  return (AES_KEYSTORE_READ_ERROR);
680  }
681 
682  // Prepare the initialization vector (IV),
683  // Length of Nonce l(n) = 15 - ui32FieldLength.
684  ui8InitVec.b[0] = ui32FieldLength - 1;
685  for(i = 0; i < 12; i++)
686  {
687  ui8InitVec.b[i + 1] = ((uint8_t*)pui32Nonce)[i];
688  }
689  if(ui32FieldLength == 2)
690  {
691  ui8InitVec.b[13] = ((uint8_t*)pui32Nonce)[12];
692  }
693  else
694  {
695  ui8InitVec.b[13] = 0;
696  }
697  ui8InitVec.b[14] = 0;
698  ui8InitVec.b[15] = 0;
699 
700  // Write initialization vector.
701  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV0) = ui8InitVec.w[0];
702  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV1) = ui8InitVec.w[1];
703  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV2) = ui8InitVec.w[2];
704  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV3) = ui8InitVec.w[3];
705 
706  // Configure AES engine
707  ui32CryptoBlockLength = ui32CipherTextLength - ui32AuthLength;
708  ui32CtrlVal = ((ui32FieldLength - 1) << CRYPTO_AESCTL_CCM_L_S);
709  if ( ui32AuthLength >= 2 ) {
710  ui32CtrlVal |= ((( ui32AuthLength - 2 ) >> 1 ) << CRYPTO_AESCTL_CCM_M_S );
711  }
712  ui32CtrlVal |= CRYPTO_AESCTL_CCM;
713  ui32CtrlVal |= CRYPTO_AESCTL_CTR;
714  ui32CtrlVal |= CRYPTO_AESCTL_SAVE_CONTEXT;
715  ui32CtrlVal |= (KEY_STORE_SIZE_128 << CRYPTO_AESCTL_KEY_SIZE_S);
716  ui32CtrlVal |= (0 << CRYPTO_AESCTL_DIR_S);
717  ui32CtrlVal |= (CRYPTO_AES_CTR_128 << CRYPTO_AESCTL_CTR_WIDTH_S);
718 
719  // Write the configuration for 128 bit AES-CCM.
720  HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) = ui32CtrlVal;
721 
722  // Write the length of the crypto block (plain text).
723  // Low and high part (high part is assumed to be always 0).
724  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN0) = ui32CryptoBlockLength;
725  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN1) = 0;
726 
727  // Write the length of the header field.
728  // Also called AAD - Additional Authentication Data.
729  HWREG(CRYPTO_BASE + CRYPTO_O_AESAUTHLEN) = ui32HeaderLength;
730 
731  // Check if any header information (AAD).
732  // If so configure the DMA controller to fetch the header.
733  if(ui32HeaderLength != 0)
734  {
735  // Enable DMA channel 0.
737 
738  // Register the base address of the header (AAD).
739  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32Header;
740 
741  // Header length in bytes (may be non-block size aligned).
742  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32HeaderLength;
743 
744  // Wait for completion of the header data transfer, DMA_IN_DONE.
745  do
746  {
747  CPUdelay(1);
748  }
750 
751  // Check for DMA errors.
753  {
754  return AES_DMA_BUS_ERROR;
755  }
756  }
757 
758  // Clear interrupt status.
761 
762  // Wait for interrupt lines from module to be cleared
764 
765  // Disable CRYPTO_IRQEN_DMA_IN_DONE interrupt as we only
766  // want interrupt to trigger once RESULT_AVAIL occurs.
768 
769  // Is using interrupts - clear and enable globally.
770  if(bIntEnable)
771  {
772  IntPendClear(INT_CRYPTO_RESULT_AVAIL_IRQ);
773  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
774  }
775 
776  // Enable internal interrupts.
779 
780  // Perform decryption if requested.
781  if(bDecrypt)
782  {
783  // Configure the DMA controller - enable both DMA channels.
785 
786  // Base address of the payload data in ext. memory.
788  (uint32_t)pui32CipherText;
789 
790  // Payload data length in bytes, equal to the cipher text length.
791  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32CryptoBlockLength;
792 
793  // Enable DMA channel 1.
795 
796  // Base address of the output data buffer.
798  (uint32_t)pui32PlainText;
799 
800  // Output data length in bytes, equal to the cipher text length.
801  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1LEN) = ui32CryptoBlockLength;
802  }
803 
804  return AES_SUCCESS;
805 }
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
Definition: crypto.h:120
void IntPendClear(uint32_t ui32Interrupt)
Unpends an interrupt.
Definition: interrupt.c:442
#define CRYPTO_AES_CTR_128
Definition: crypto.h:196
#define KEY_STORE_SIZE_128
Definition: crypto.h:155
#define CRYPTO_DMA_BUS_ERR
Definition: crypto.h:116
#define AES_DMA_BUS_ERROR
Definition: crypto.h:143
#define AES_SUCCESS
Definition: crypto.h:140
void CPUdelay(uint32_t ui32Count)
Provide a small delay.
Definition: cpu.c:339
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:326
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:282
#define CRYPTO_KEY_ST_RD_ERR
Definition: crypto.h:118

Here is the call graph for this function:

uint32_t CRYPTOCcmInvAuthDecryptResultGet ( uint32_t  ui32AuthLength,
uint32_t *  pui32CipherText,
uint32_t  ui32CipherTextLength,
uint32_t *  pui32CcmTag 
)

Get the result of the CCM operation.

Parameters
ui32AuthLengthis the the length of the authentication field - 0, 2, 4, 6, 8, 10, 12, 14 or 16 octets.
pui32CipherTextis a pointer to the octet string encrypted message.
ui32CipherTextLengthis the length of the encrypted message.
pui32CcmTagis the location of the authentication Tag.
Returns
Returns AES_SUCCESS if successful.
847 {
848  uint32_t volatile ui32Tag[4];
849  uint32_t ui32TagIndex;
850  uint32_t i;
851  uint32_t ui32Idx;
852 
853  ui32TagIndex = ui32CipherTextLength - ui32AuthLength;
854 
855  // Result has already been copied to the output buffer by DMA
856  // Disable master control.
857  HWREG(CRYPTO_BASE + CRYPTO_O_ALGSEL) = 0x00000000;
858 
859  // Read tag - wait for the context ready bit.
860  do
861  {
862  CPUdelay(1);
863  }
864  while(!(HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) &
866 
867  // Read the Tag registers.
868  ui32Tag[0] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT0);
869  ui32Tag[1] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT1);
870  ui32Tag[2] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT2);
871  ui32Tag[3] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT3);
872 
873  for(ui32Idx = 0; ui32Idx < ui32AuthLength ; ui32Idx++)
874  {
875  *((uint8_t*)pui32CcmTag + ui32Idx) = *((uint8_t*)ui32Tag + ui32Idx);
876  }
877 
878  // Operation successful - clear interrupt status.
881 
882  // Verify the Tag.
883  for(i = 0; i < ui32AuthLength; i++)
884  {
885  if(*((uint8_t *)pui32CcmTag + i) !=
886  (*((uint8_t *)pui32CipherText + ui32TagIndex + i)))
887  {
889  }
890  }
891 
892  return AES_SUCCESS;
893 }
#define CCM_AUTHENTICATION_FAILED
Definition: crypto.h:144
#define AES_SUCCESS
Definition: crypto.h:140
void CPUdelay(uint32_t ui32Count)
Provide a small delay.
Definition: cpu.c:339

Here is the call graph for this function:

uint32_t CRYPTOCcmInvAuthDecryptStatus ( void  )

Checks CCM decrypt and Inverse Authentication result.

Returns
Returns status of operation:
814 {
815  uint32_t ui32Status;
816 
817  // Get the current DMA status.
818  ui32Status = HWREG(CRYPTO_BASE + CRYPTO_O_DMASTAT);
819 
820  // Check if DMA is still busy.
821  if(ui32Status & CRYPTO_DMA_BSY)
822  {
823  return (AES_DMA_BSY);
824  }
825 
826  // Check the status of the DMA operation - return error if not success.
827  if(ui32Status & CRYPTO_DMA_BUS_ERROR)
828  {
829  return (AES_DMA_BUS_ERROR);
830  }
831 
832  // Operation successful - disable interrupt and return success
833  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
834  return (AES_SUCCESS);
835 }
#define AES_DMA_BSY
Definition: crypto.h:148
#define CRYPTO_DMA_BUS_ERROR
Definition: crypto.h:131
#define AES_DMA_BUS_ERROR
Definition: crypto.h:143
#define CRYPTO_DMA_BSY
Definition: crypto.h:130
#define AES_SUCCESS
Definition: crypto.h:140
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:326

Here is the call graph for this function:

void CRYPTODmaDisable ( uint32_t  ui32Channels)

Disable Crypto DMA operation.

The specified Crypto DMA channels are disabled.

Parameters
ui32Channelsis a bitwise OR of the channels to disable.
Returns
None
925 {
926  // Check the arguments.
927  ASSERT((ui32Channels & CRYPTO_DMA_CHAN0) |
928  (ui32Channels & CRYPTO_DMA_CHAN1));
929 
930  // Enable the selected channels.
931  if(ui32Channels & CRYPTO_DMA_CHAN0)
932  {
934  }
935  if(ui32Channels & CRYPTO_DMA_CHAN1)
936  {
938  }
939 }
#define CRYPTO_DMA_CHAN1
Definition: crypto.h:124
#define CRYPTO_DMA_CHAN0
Definition: crypto.h:123
#define ASSERT(expr)
Definition: debug.h:74
void CRYPTODmaEnable ( uint32_t  ui32Channels)

Enable Crypto DMA operation.

The specified Crypto DMA channels are enabled.

Parameters
ui32Channelsis a bitwise OR of the channels to enable.
Returns
None
902 {
903  // Check the arguments.
904  ASSERT((ui32Channels & CRYPTO_DMA_CHAN0) |
905  (ui32Channels & CRYPTO_DMA_CHAN1));
906 
907  // Enable the selected channels,
908  if(ui32Channels & CRYPTO_DMA_CHAN0)
909  {
911  }
912  if(ui32Channels & CRYPTO_DMA_CHAN1)
913  {
915  }
916 }
#define CRYPTO_DMA_CHAN1
Definition: crypto.h:124
#define CRYPTO_DMA_CHAN0
Definition: crypto.h:123
#define ASSERT(expr)
Definition: debug.h:74
static uint32_t CRYPTODmaStatus ( void  )
inlinestatic

Get the current status of the Crypto DMA controller.

This function is used to poll the Crypto DMA controller to check if it is ready for a new operation or if an error has occurred.

The CRYPTO_DMA_BUS_ERROR can also be caught using the crypto event handler.

Returns
Returns the current status of the DMA controller:
555 {
556  // Return the value of the status register.
557  return (HWREG(CRYPTO_BASE + CRYPTO_O_DMASTAT));
558 }
static void CRYPTOIntClear ( uint32_t  ui32IntFlags)
inlinestatic

Clears Crypto interrupt sources.

The specified Crypto interrupt sources are cleared, so that they no longer assert. This function must be called in the interrupt handler to keep the interrupt from being recognized again immediately upon exit.

Note
Due to write buffers and synchronizers in the system it may take several clock cycles from a register write clearing an event in a module and until the event is actually cleared in the NVIC of the system CPU. It is recommended to clear the event source early in the interrupt service routine (ISR) to allow the event clear to propagate to the NVIC before returning from the ISR. At the same time, an early event clear allows new events of the same type to be pended instead of ignored if the event is cleared later in the ISR. It is the responsibility of the programmer to make sure that enough time has passed before returning from the ISR to avoid false re-triggering of the cleared event. A simple, although not necessarily optimal, way of clearing an event before returning from the ISR is:
  1. Write to clear event (interrupt source). (buffered write)
  2. Dummy read from the event source module. (making sure the write has propagated)
  3. Wait two system CPU clock cycles (user code or two NOPs). (allowing cleared event to propagate through any synchronizers)
Parameters
ui32IntFlagsis a bit mask of the interrupt sources to be cleared.
Returns
None
712 {
713  // Check the arguments.
714  ASSERT((ui32IntFlags & CRYPTO_DMA_IN_DONE) |
715  (ui32IntFlags & CRYPTO_RESULT_RDY));
716 
717  // Clear the requested interrupt sources,
718  HWREG(CRYPTO_BASE + CRYPTO_O_IRQCLR) = ui32IntFlags;
719 }
#define CRYPTO_RESULT_RDY
Definition: crypto.h:115
#define CRYPTO_DMA_IN_DONE
Definition: crypto.h:114
#define ASSERT(expr)
Definition: debug.h:74
static void CRYPTOIntDisable ( uint32_t  ui32IntFlags)
inlinestatic

Disables individual CRYPTO interrupt sources.

This function disables the indicated Crypto interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt. Disabled sources have no effect on the processor.

Parameters
ui32IntFlagsis the bitwise OR of the interrupt sources to be enabled.
Returns
None
636 {
637  // Check the arguments.
638  ASSERT((ui32IntFlags & CRYPTO_DMA_IN_DONE) |
639  (ui32IntFlags & CRYPTO_RESULT_RDY));
640 
641  // Disable the specified interrupts.
642  HWREG(CRYPTO_BASE + CRYPTO_O_IRQEN) &= ~ui32IntFlags;
643 }
#define CRYPTO_RESULT_RDY
Definition: crypto.h:115
#define CRYPTO_DMA_IN_DONE
Definition: crypto.h:114
#define ASSERT(expr)
Definition: debug.h:74
static void CRYPTOIntEnable ( uint32_t  ui32IntFlags)
inlinestatic

Enables individual Crypto interrupt sources.

This function enables the indicated Crypto interrupt sources. Only the sources that are enabled can be reflected to the processor interrupt. Disabled sources have no effect on the processor.

Parameters
ui32IntFlagsis the bitwise OR of the interrupt sources to be enabled.
Returns
None
607 {
608  // Check the arguments.
609  ASSERT((ui32IntFlags & CRYPTO_DMA_IN_DONE) |
610  (ui32IntFlags & CRYPTO_RESULT_RDY));
611 
612  // Using level interrupt.
614 
615  // Enable the specified interrupts.
616  HWREG(CRYPTO_BASE + CRYPTO_O_IRQEN) |= ui32IntFlags;
617 }
#define CRYPTO_RESULT_RDY
Definition: crypto.h:115
Definition: crypto.h:120
#define CRYPTO_DMA_IN_DONE
Definition: crypto.h:114
#define ASSERT(expr)
Definition: debug.h:74
static void CRYPTOIntRegister ( void(*)(void)  pfnHandler)
inlinestatic

Registers an interrupt handler for a Crypto interrupt.

This function does the actual registering of the interrupt handler. This function enables the global interrupt in the interrupt controller; specific UART interrupts must be enabled via CRYPTOIntEnable(). It is the interrupt handler's responsibility to clear the interrupt source.

Parameters
pfnHandleris a pointer to the function to be called when the UART interrupt occurs.
Returns
None
See also
IntRegister() for important information about registering interrupt handlers.
741 {
742  // Register the interrupt handler.
743  IntRegister(INT_CRYPTO_RESULT_AVAIL_IRQ, pfnHandler);
744 
745  // Enable the UART interrupt.
746  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
747 }
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function to be called when an interrupt occurs.
Definition: interrupt.c:152
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:282

Here is the call graph for this function:

static uint32_t CRYPTOIntStatus ( bool  bMasked)
inlinestatic

Gets the current interrupt status.

This function returns the interrupt status for the specified Crypto. Either the raw interrupt status or the status of interrupts that are allowed to reflect to the processor can be returned.

Parameters
bMaskedwhether to use raw or masked interrupt status:
  • false : Raw interrupt status is required.
  • true : Masked interrupt status is required.
Returns
Returns the current interrupt status:
664 {
665  uint32_t ui32Mask;
666 
667  // Return either the interrupt status or the raw interrupt status as
668  // requested.
669  if(bMasked)
670  {
671  ui32Mask = HWREG(CRYPTO_BASE + CRYPTO_O_IRQEN);
672  return(ui32Mask & HWREG(CRYPTO_BASE + CRYPTO_O_IRQSTAT));
673  }
674  else
675  {
676  return(HWREG(CRYPTO_BASE + CRYPTO_O_IRQSTAT) & 0x00000003);
677  }
678 }
static void CRYPTOIntUnregister ( void  )
inlinestatic

Unregisters an interrupt handler for a Crypto interrupt.

This function does the actual unregistering of the interrupt handler. It clears the handler to be called when a Crypto interrupt occurs. This function also masks off the interrupt in the interrupt controller so that the interrupt handler no longer is called.

Returns
None
See also
IntRegister() for important information about registering interrupt handlers.
766 {
767  // Disable the interrupt.
768  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
769 
770  // Unregister the interrupt handler.
771  IntUnregister(INT_CRYPTO_RESULT_AVAIL_IRQ);
772 }
void IntUnregister(uint32_t ui32Interrupt)
Unregisters the function to be called when an interrupt occurs.
Definition: interrupt.c:188
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:326

Here is the call graph for this function:

Macro Definition Documentation

#define AES_CCM_TEST_ERROR   10
#define AES_DMA_BSY   11
#define AES_ECB_LENGTH   16

Referenced by CRYPTOAesEcb().

#define AES_ECB_TEST_ERROR   8
#define AES_KEYSTORE_READ_ERROR   1
#define AES_KEYSTORE_WRITE_ERROR   2
#define AES_NULL_ERROR   9
#define CCM_AUTHENTICATION_FAILED   4
#define CRYPTO_AES128_DECRYPT   0x00000008

Referenced by CRYPTOAesCbc(), and CRYPTOAesEcb().

#define CRYPTO_AES128_ENCRYPT   0x0000000C

Referenced by CRYPTOAesCbc(), and CRYPTOAesEcb().

#define CRYPTO_AES_CBC   5
#define CRYPTO_AES_CCM   3
#define CRYPTO_AES_CTR_128   0x3
#define CRYPTO_AES_CTR_32   0x0
#define CRYPTO_AES_CTR_64   0x1
#define CRYPTO_AES_CTR_96   0x2
#define CRYPTO_AES_ECB   2
#define CRYPTO_AES_KEYL0AD   1
#define CRYPTO_AES_NONE   0
#define CRYPTO_AES_RNG   4
#define CRYPTO_DMA_BSY   0x00000003
#define CRYPTO_DMA_BUS_ERR   0x80000000
#define CRYPTO_DMA_BUS_ERROR   0x00020000
#define CRYPTO_DMA_CHAN0   0x00000001
#define CRYPTO_DMA_CHAN1   0x00000002
#define CRYPTO_DMA_IN_DONE   0x00000002
#define CRYPTO_DMA_READY   0x00000000
#define CRYPTO_IRQTYPE_PULSE   0x00000000
#define CRYPTO_KEY_AREA_0   0

Referenced by CRYPTOAesLoadKey().

#define CRYPTO_KEY_AREA_1   1

Referenced by CRYPTOAesLoadKey().

#define CRYPTO_KEY_AREA_2   2

Referenced by CRYPTOAesLoadKey().

#define CRYPTO_KEY_AREA_3   3

Referenced by CRYPTOAesLoadKey().

#define CRYPTO_KEY_AREA_4   4

Referenced by CRYPTOAesLoadKey().

#define CRYPTO_KEY_AREA_5   5

Referenced by CRYPTOAesLoadKey().

#define CRYPTO_KEY_AREA_6   6

Referenced by CRYPTOAesLoadKey().

#define CRYPTO_KEY_AREA_7   7

Referenced by CRYPTOAesLoadKey().

#define CRYPTO_KEY_ST_RD_ERR   0x20000000
#define CRYPTO_KEY_ST_WR_ERR   0x40000000
#define CRYPTO_RESULT_RDY   0x00000001
#define KEY_BLENGTH   16

Referenced by CRYPTOAesLoadKey().

#define KEY_EXP_LENGTH   176
#define KEY_STORE_SIZE_128   0x00000001
#define KEY_STORE_SIZE_192   0x00000002
#define KEY_STORE_SIZE_256   0x00000003
#define KEY_STORE_SIZE_BITS   0x00000003
#define STATE_BLENGTH   16