CC26xx Driver Library
[crypto.h] 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 in the dynamic interrupt table. More...
 
static void CRYPTOIntUnregister (void)
 Unregisters an interrupt handler for a Crypto interrupt in the dynamic interrupt table. 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 encrypt or decrypt operation. End operation can be detected 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()
177 {
178  uint32_t ui32CtrlVal;
179 
180  // Enable internal interrupts.
183 
184  // Clear any outstanding interrupts.
187 
188  // Wait for interrupt lines from module to be cleared
190 
191  // If using interrupts clear any pending interrupts and enable interrupts
192  // for the Crypto module.
193  if(bIntEnable)
194  {
195  IntPendClear(INT_CRYPTO_RESULT_AVAIL_IRQ);
196  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
197  }
198 
199  // Configure Master Control module.
201 
202  // Enable keys to read (e.g. Key 0).
203  HWREG(CRYPTO_BASE + CRYPTO_O_KEYREADAREA) = ui32KeyLocation;
204 
205  //Wait until key is loaded to the AES module.
206  do
207  {
208  CPUdelay(1);
209  }
211 
212  // Check for Key store Read error.
214  {
215  return (AES_KEYSTORE_READ_ERROR);
216  }
217 
218  // Write initialization vector.
219  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV0) = pui32Nonce[0];
220  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV1) = pui32Nonce[1];
221  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV2) = pui32Nonce[2];
222  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV3) = pui32Nonce[3];
223 
224  // Configure AES engine for AES-CBC with 128-bit key size.
226  if(bEncrypt)
227  {
228  ui32CtrlVal |= CRYPTO_AES128_ENCRYPT;
229  }
230  else
231  {
232  ui32CtrlVal |= CRYPTO_AES128_DECRYPT;
233  }
234  HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) = ui32CtrlVal;
235 
236  // Write the length of the crypto block (plain text).
237  // Low and high part (high part is assumed to be always 0).
238  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN0) = ui32MsgLength;
239  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN1) = 0;
240  HWREG(CRYPTO_BASE + CRYPTO_O_AESAUTHLEN) = 0;
241 
242  // Enable Crypto DMA channel 0.
244 
245  // Base address of the input data in ext. memory.
246  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32MsgIn;
247 
248  // Input data length in bytes, equal to the message.
249  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32MsgLength;
250 
251  // Enable Crypto DMA channel 1.
253 
254  // Set up the address and length of the output data.
255  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1EXTADDR) = (uint32_t)pui32MsgOut;
256  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1LEN) = ui32MsgLength;
257 
258  // Return success
259  return AES_SUCCESS;
260 }
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
Definition: crypto.h:120
void IntPendClear(uint32_t ui32Interrupt)
Unpends an interrupt.
Definition: interrupt.c:443
#define AES_SUCCESS
Definition: aes.h:121
#define CRYPTO_AES128_ENCRYPT
Definition: crypto.h:126
#define CRYPTO_AES128_DECRYPT
Definition: crypto.h:127
void CPUdelay(uint32_t ui32Count)
Provide a small non-zero delay using a simple loop counter.
Definition: cpu.c:343
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt or system exception.
Definition: interrupt.c:283
#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()
269 {
270  return(CRYPTOAesEcbStatus());
271 }
uint32_t CRYPTOAesEcbStatus(void)
Check the result of an AES ECB operation.
Definition: crypto.c:362

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()
282 {
283  // Enable internal interrupts.
286 
287  // Clear any outstanding interrupts.
290 
291  // Wait for interrupt lines from module to be cleared
293 
294  // If using interrupts clear any pending interrupts and enable interrupts
295  // for the Crypto module.
296  if(bIntEnable)
297  {
298  IntPendClear(INT_CRYPTO_RESULT_AVAIL_IRQ);
299  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
300  }
301 
302  // Configure Master Control module.
304 
305  // Enable keys to read (e.g. Key 0).
306  HWREG(CRYPTO_BASE + CRYPTO_O_KEYREADAREA) = ui32KeyLocation;
307 
308  //Wait until key is loaded to the AES module.
309  do
310  {
311  CPUdelay(1);
312  }
314 
315  // Check for Key store Read error.
317  {
318  return (AES_KEYSTORE_READ_ERROR);
319  }
320 
321  // Configure AES engine (program AES-ECB-128 encryption and no
322  // initialization vector - IV).
323  if(bEncrypt)
324  {
326  }
327  else
328  {
330  }
331 
332  // Write the length of the data.
334  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN1) = 0;
335 
336  // Enable Crypto DMA channel 0.
338 
339  // Base address of the input data in ext. memory.
340  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32MsgIn;
341 
342  // Input data length in bytes, equal to the message.
344 
345  // Enable Crypto DMA channel 1.
347 
348  // Set up the address and length of the output data.
349  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1EXTADDR) = (uint32_t)pui32MsgOut;
351 
352  // Return success
353  return AES_SUCCESS;
354 }
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
Definition: crypto.h:120
void IntPendClear(uint32_t ui32Interrupt)
Unpends an interrupt.
Definition: interrupt.c:443
#define AES_SUCCESS
Definition: aes.h:121
#define CRYPTO_AES128_ENCRYPT
Definition: crypto.h:126
#define CRYPTO_AES128_DECRYPT
Definition: crypto.h:127
#define AES_ECB_LENGTH
Definition: crypto.h:106
void CPUdelay(uint32_t ui32Count)
Provide a small non-zero delay using a simple loop counter.
Definition: cpu.c:343
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt or system exception.
Definition: interrupt.c:283
#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().

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

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) &
146 
147  // Check for errors in DMA and key store.
148  if((HWREG(CRYPTO_BASE + CRYPTO_O_IRQSTAT) &
151  {
152  // Acknowledge/clear the interrupt and disable the master control.
155  HWREG(CRYPTO_BASE + CRYPTO_O_ALGSEL) = 0x00000000;
156 
157  // Check key status, return success if key valid.
158  if(HWREG(CRYPTO_BASE + CRYPTO_O_KEYWRITTENAREA) & (0x00000001 << ui32KeyLocation))
159  {
160  returnStatus = AES_SUCCESS;
161  }
162  }
163 
164  // Return status.
165  return returnStatus;
166 }
#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 AES_SUCCESS
Definition: aes.h:121
#define KEY_STORE_SIZE_128
Definition: crypto.h:155
#define ASSERT(expr)
Definition: debug.h:73
#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
void CPUdelay(uint32_t ui32Count)
Provide a small non-zero delay using a simple loop counter.
Definition: cpu.c:343
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt or system exception.
Definition: interrupt.c:327
#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 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()
397 {
398  uint32_t ui32CtrlVal;
399  uint32_t i;
400  uint32_t *pui32CipherText;
401  union {
402  uint32_t w[4];
403  uint8_t b[16];
404  } ui8InitVec;
405 
406  // Input address for the encryption engine is the same as the output.
407  pui32CipherText = pui32PlainText;
408 
409  // Disable global interrupt, enable local interrupt and clear any pending
410  // interrupts.
411  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
414 
415  // Enable internal interrupts.
419 
420  // Configure master control module for AES operation.
422 
423  // Enable keys to read (e.g. Key 0).
424  HWREG(CRYPTO_BASE + CRYPTO_O_KEYREADAREA) = ui32KeyLocation;
425 
426  // Wait until key is loaded to the AES module.
427  do
428  {
429  CPUdelay(1);
430  }
432 
433  // Check for Key store Read error.
435  {
436  return (AES_KEYSTORE_READ_ERROR);
437  }
438 
439  // Prepare the initialization vector (IV),
440  // Length of Nonce l(n) = 15 - ui32FieldLength.
441  ui8InitVec.b[0] = ui32FieldLength - 1;
442  for(i = 0; i < 12; i++)
443  {
444  ui8InitVec.b[i + 1] = ((uint8_t*)pui32Nonce)[i];
445  }
446  if(ui32FieldLength == 2)
447  {
448  ui8InitVec.b[13] = ((uint8_t*)pui32Nonce)[12];
449  }
450  else
451  {
452  ui8InitVec.b[13] = 0;
453  }
454  ui8InitVec.b[14] = 0;
455  ui8InitVec.b[15] = 0;
456 
457  // Write initialization vector.
458  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV0) = ui8InitVec.w[0];
459  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV1) = ui8InitVec.w[1];
460  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV2) = ui8InitVec.w[2];
461  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV3) = ui8InitVec.w[3];
462 
463  // Configure AES engine.
464  ui32CtrlVal = ((ui32FieldLength - 1) << CRYPTO_AESCTL_CCM_L_S);
465  if ( ui32AuthLength >= 2 ) {
466  ui32CtrlVal |= ((( ui32AuthLength - 2 ) >> 1 ) << CRYPTO_AESCTL_CCM_M_S );
467  }
468  ui32CtrlVal |= CRYPTO_AESCTL_CCM;
469  ui32CtrlVal |= CRYPTO_AESCTL_CTR;
470  ui32CtrlVal |= CRYPTO_AESCTL_SAVE_CONTEXT;
471  ui32CtrlVal |= (KEY_STORE_SIZE_128 << CRYPTO_AESCTL_KEY_SIZE_S);
472  ui32CtrlVal |= (1 << CRYPTO_AESCTL_DIR_S);
473  ui32CtrlVal |= (CRYPTO_AES_CTR_128 << CRYPTO_AESCTL_CTR_WIDTH_S);
474 
475  // Write the configuration for 128 bit AES-CCM.
476  HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) = ui32CtrlVal;
477 
478  // Write the length of the crypto block (plain text).
479  // Low and high part (high part is assumed to be always 0).
480  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN0) = ui32PlainTextLength;
481  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN1) = 0;
482 
483  // Write the length of the header field.
484  // Also called AAD - Additional Authentication Data.
485  HWREG(CRYPTO_BASE + CRYPTO_O_AESAUTHLEN) = ui32HeaderLength;
486 
487  // Check if any header information (AAD).
488  // If so configure the DMA controller to fetch the header.
489  if(ui32HeaderLength != 0)
490  {
491  // Enable DMA channel 0.
493 
494  // Register the base address of the header (AAD).
495  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32Header;
496 
497  // Header length in bytes (may be non-block size aligned).
498  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32HeaderLength;
499 
500  // Wait for completion of the header data transfer, DMA_IN_DONE.
501  do
502  {
503  CPUdelay(1);
504  }
506 
507  // Check for DMA errors.
509  {
510  return AES_DMA_BUS_ERROR;
511  }
512  }
513 
514  // Clear interrupt status.
517 
518  // Wait for interrupt lines from module to be cleared
520 
521  // Disable CRYPTO_IRQEN_DMA_IN_DONE interrupt as we only
522  // want interrupt to trigger once RESULT_AVAIL occurs.
524 
525 
526  // Is using interrupts enable globally.
527  if(bIntEnable)
528  {
529  IntPendClear(INT_CRYPTO_RESULT_AVAIL_IRQ);
530  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
531  }
532 
533  // Enable interrupts locally.
535 
536  // Perform encryption if requested.
537  if(bEncrypt)
538  {
539  // Enable DMA channel 0
541 
542  // base address of the payload data in ext. memory.
544  (uint32_t)pui32PlainText;
545 
546  // Enable DMA channel 1
548 
549  // Base address of the output data buffer.
551  (uint32_t)pui32CipherText;
552 
553  // Payload data length in bytes, equal to the plaintext length.
554  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32PlainTextLength;
555  // Output data length in bytes, equal to the plaintext length.
556  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1LEN) = ui32PlainTextLength;
557  }
558 
559  return AES_SUCCESS;
560 }
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
Definition: crypto.h:120
void IntPendClear(uint32_t ui32Interrupt)
Unpends an interrupt.
Definition: interrupt.c:443
#define CRYPTO_AES_CTR_128
Definition: crypto.h:196
#define AES_SUCCESS
Definition: aes.h:121
#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
void CPUdelay(uint32_t ui32Count)
Provide a small non-zero delay using a simple loop counter.
Definition: cpu.c:343
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt or system exception.
Definition: interrupt.c:327
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt or system exception.
Definition: interrupt.c:283
#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()
599 {
600  uint32_t volatile ui32Tag[4];
601  uint32_t ui32Idx;
602 
603  // Result has already been copied to the output buffer by DMA
604  // Disable master control.
605  HWREG(CRYPTO_BASE + CRYPTO_O_ALGSEL) = 0x00000000;
606 
607  // Read tag - wait for the context ready bit.
608  do
609  {
610  CPUdelay(1);
611  }
612  while(!(HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) &
614 
615  // Read the Tag registers.
616  ui32Tag[0] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT0);
617  ui32Tag[1] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT1);
618  ui32Tag[2] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT2);
619  ui32Tag[3] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT3);
620 
621  for(ui32Idx = 0; ui32Idx < ui32TagLength ; ui32Idx++)
622  {
623  *((uint8_t*)pui32CcmTag + ui32Idx) = *((uint8_t*)ui32Tag + ui32Idx);
624  }
625 
626  // Operation successful - clear interrupt status.
629  return AES_SUCCESS;
630 }
#define AES_SUCCESS
Definition: aes.h:121
void CPUdelay(uint32_t ui32Count)
Provide a small non-zero delay using a simple loop counter.
Definition: cpu.c:343

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()
569 {
570  uint32_t ui32Status;
571 
572  // Get the current DMA status.
573  ui32Status = HWREG(CRYPTO_BASE + CRYPTO_O_DMASTAT);
574 
575  // Check if DMA is still busy.
576  if(ui32Status & CRYPTO_DMA_BSY)
577  {
578  return (AES_DMA_BSY);
579  }
580 
581  // Check the status of the DMA operation - return error if not success.
582  if(ui32Status & CRYPTO_DMA_BUS_ERROR)
583  {
584  return (AES_DMA_BUS_ERROR);
585  }
586 
587  // Operation successful - disable interrupt and return success.
588  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
589  return (AES_SUCCESS);
590 }
#define AES_DMA_BSY
Definition: crypto.h:148
#define CRYPTO_DMA_BUS_ERROR
Definition: crypto.h:131
#define AES_SUCCESS
Definition: aes.h:121
#define AES_DMA_BUS_ERROR
Definition: crypto.h:143
#define CRYPTO_DMA_BSY
Definition: crypto.h:130
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt or system exception.
Definition: interrupt.c:327

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 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:
644 {
645  uint32_t ui32CtrlVal;
646  uint32_t i;
647  uint32_t *pui32PlainText;
648  uint32_t ui32CryptoBlockLength;
649  union {
650  uint32_t w[4];
651  uint8_t b[16];
652  } ui8InitVec;
653 
654  // Input address for the encryption engine is the same as the output.
655  pui32PlainText = pui32CipherText;
656 
657  // Disable global interrupt, enable local interrupt and clear any pending.
658  // interrupts.
659  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
662  // Enable internal interrupts.
666 
667  // Configure master control module for AES operation.
669 
670  // Enable keys to read (e.g. Key 0).
671  HWREG(CRYPTO_BASE + CRYPTO_O_KEYREADAREA) = ui32KeyLocation;
672 
673  // Wait until key is loaded to the AES module.
674  do
675  {
676  CPUdelay(1);
677  }
679 
680  // Check for Key store Read error.
682  {
683  return (AES_KEYSTORE_READ_ERROR);
684  }
685 
686  // Prepare the initialization vector (IV),
687  // Length of Nonce l(n) = 15 - ui32FieldLength.
688  ui8InitVec.b[0] = ui32FieldLength - 1;
689  for(i = 0; i < 12; i++)
690  {
691  ui8InitVec.b[i + 1] = ((uint8_t*)pui32Nonce)[i];
692  }
693  if(ui32FieldLength == 2)
694  {
695  ui8InitVec.b[13] = ((uint8_t*)pui32Nonce)[12];
696  }
697  else
698  {
699  ui8InitVec.b[13] = 0;
700  }
701  ui8InitVec.b[14] = 0;
702  ui8InitVec.b[15] = 0;
703 
704  // Write initialization vector.
705  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV0) = ui8InitVec.w[0];
706  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV1) = ui8InitVec.w[1];
707  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV2) = ui8InitVec.w[2];
708  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV3) = ui8InitVec.w[3];
709 
710  // Configure AES engine
711  ui32CryptoBlockLength = ui32CipherTextLength - ui32AuthLength;
712  ui32CtrlVal = ((ui32FieldLength - 1) << CRYPTO_AESCTL_CCM_L_S);
713  if ( ui32AuthLength >= 2 ) {
714  ui32CtrlVal |= ((( ui32AuthLength - 2 ) >> 1 ) << CRYPTO_AESCTL_CCM_M_S );
715  }
716  ui32CtrlVal |= CRYPTO_AESCTL_CCM;
717  ui32CtrlVal |= CRYPTO_AESCTL_CTR;
718  ui32CtrlVal |= CRYPTO_AESCTL_SAVE_CONTEXT;
719  ui32CtrlVal |= (KEY_STORE_SIZE_128 << CRYPTO_AESCTL_KEY_SIZE_S);
720  ui32CtrlVal |= (0 << CRYPTO_AESCTL_DIR_S);
721  ui32CtrlVal |= (CRYPTO_AES_CTR_128 << CRYPTO_AESCTL_CTR_WIDTH_S);
722 
723  // Write the configuration for 128 bit AES-CCM.
724  HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) = ui32CtrlVal;
725 
726  // Write the length of the crypto block (plain text).
727  // Low and high part (high part is assumed to be always 0).
728  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN0) = ui32CryptoBlockLength;
729  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN1) = 0;
730 
731  // Write the length of the header field.
732  // Also called AAD - Additional Authentication Data.
733  HWREG(CRYPTO_BASE + CRYPTO_O_AESAUTHLEN) = ui32HeaderLength;
734 
735  // Check if any header information (AAD).
736  // If so configure the DMA controller to fetch the header.
737  if(ui32HeaderLength != 0)
738  {
739  // Enable DMA channel 0.
741 
742  // Register the base address of the header (AAD).
743  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32Header;
744 
745  // Header length in bytes (may be non-block size aligned).
746  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32HeaderLength;
747 
748  // Wait for completion of the header data transfer, DMA_IN_DONE.
749  do
750  {
751  CPUdelay(1);
752  }
754 
755  // Check for DMA errors.
757  {
758  return AES_DMA_BUS_ERROR;
759  }
760  }
761 
762  // Clear interrupt status.
765 
766  // Wait for interrupt lines from module to be cleared
768 
769  // Disable CRYPTO_IRQEN_DMA_IN_DONE interrupt as we only
770  // want interrupt to trigger once RESULT_AVAIL occurs.
772 
773  // Is using interrupts - clear and enable globally.
774  if(bIntEnable)
775  {
776  IntPendClear(INT_CRYPTO_RESULT_AVAIL_IRQ);
777  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
778  }
779 
780  // Enable internal interrupts.
783 
784  // Perform decryption if requested.
785  if(bDecrypt)
786  {
787  // Configure the DMA controller - enable both DMA channels.
789 
790  // Base address of the payload data in ext. memory.
792  (uint32_t)pui32CipherText;
793 
794  // Payload data length in bytes, equal to the cipher text length.
795  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32CryptoBlockLength;
796 
797  // Enable DMA channel 1.
799 
800  // Base address of the output data buffer.
802  (uint32_t)pui32PlainText;
803 
804  // Output data length in bytes, equal to the cipher text length.
805  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1LEN) = ui32CryptoBlockLength;
806  }
807 
808  return AES_SUCCESS;
809 }
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
Definition: crypto.h:120
void IntPendClear(uint32_t ui32Interrupt)
Unpends an interrupt.
Definition: interrupt.c:443
#define CRYPTO_AES_CTR_128
Definition: crypto.h:196
#define AES_SUCCESS
Definition: aes.h:121
#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
void CPUdelay(uint32_t ui32Count)
Provide a small non-zero delay using a simple loop counter.
Definition: cpu.c:343
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt or system exception.
Definition: interrupt.c:327
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt or system exception.
Definition: interrupt.c:283
#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 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.
851 {
852  uint32_t volatile ui32Tag[4];
853  uint32_t ui32TagIndex;
854  uint32_t i;
855  uint32_t ui32Idx;
856 
857  ui32TagIndex = ui32CipherTextLength - ui32AuthLength;
858 
859  // Result has already been copied to the output buffer by DMA
860  // Disable master control.
861  HWREG(CRYPTO_BASE + CRYPTO_O_ALGSEL) = 0x00000000;
862 
863  // Read tag - wait for the context ready bit.
864  do
865  {
866  CPUdelay(1);
867  }
868  while(!(HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) &
870 
871  // Read the Tag registers.
872  ui32Tag[0] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT0);
873  ui32Tag[1] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT1);
874  ui32Tag[2] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT2);
875  ui32Tag[3] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT3);
876 
877  for(ui32Idx = 0; ui32Idx < ui32AuthLength ; ui32Idx++)
878  {
879  *((uint8_t*)pui32CcmTag + ui32Idx) = *((uint8_t*)ui32Tag + ui32Idx);
880  }
881 
882  // Operation successful - clear interrupt status.
885 
886  // Verify the Tag.
887  for(i = 0; i < ui32AuthLength; i++)
888  {
889  if(*((uint8_t *)pui32CcmTag + i) !=
890  (*((uint8_t *)pui32CipherText + ui32TagIndex + i)))
891  {
893  }
894  }
895 
896  return AES_SUCCESS;
897 }
#define AES_SUCCESS
Definition: aes.h:121
#define CCM_AUTHENTICATION_FAILED
Definition: crypto.h:144
void CPUdelay(uint32_t ui32Count)
Provide a small non-zero delay using a simple loop counter.
Definition: cpu.c:343

Here is the call graph for this function:

uint32_t CRYPTOCcmInvAuthDecryptStatus ( void  )

Checks CCM decrypt and Inverse Authentication result.

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

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
929 {
930  // Check the arguments.
931  ASSERT((ui32Channels & CRYPTO_DMA_CHAN0) |
932  (ui32Channels & CRYPTO_DMA_CHAN1));
933 
934  // Enable the selected channels.
935  if(ui32Channels & CRYPTO_DMA_CHAN0)
936  {
938  }
939  if(ui32Channels & CRYPTO_DMA_CHAN1)
940  {
942  }
943 }
#define CRYPTO_DMA_CHAN1
Definition: crypto.h:124
#define CRYPTO_DMA_CHAN0
Definition: crypto.h:123
#define ASSERT(expr)
Definition: debug.h:73
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
906 {
907  // Check the arguments.
908  ASSERT((ui32Channels & CRYPTO_DMA_CHAN0) |
909  (ui32Channels & CRYPTO_DMA_CHAN1));
910 
911  // Enable the selected channels,
912  if(ui32Channels & CRYPTO_DMA_CHAN0)
913  {
915  }
916  if(ui32Channels & CRYPTO_DMA_CHAN1)
917  {
919  }
920 }
#define CRYPTO_DMA_CHAN1
Definition: crypto.h:124
#define CRYPTO_DMA_CHAN0
Definition: crypto.h:123
#define ASSERT(expr)
Definition: debug.h:73
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:73
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:73
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:73
static void CRYPTOIntRegister ( void(*)(void)  pfnHandler)
inlinestatic

Registers an interrupt handler for a Crypto interrupt in the dynamic interrupt table.

Note
Only use this function if you want to use the dynamic vector table (in SRAM)!

This function registers a function as the interrupt handler for a specific interrupt and enables the corresponding 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.
744 {
745  // Register the interrupt handler.
746  IntRegister(INT_CRYPTO_RESULT_AVAIL_IRQ, pfnHandler);
747 
748  // Enable the UART interrupt.
749  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
750 }
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function as an interrupt handler in the dynamic vector table.
Definition: interrupt.c:153
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt or system exception.
Definition: interrupt.c:283

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 in the dynamic interrupt table.

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.
769 {
770  // Disable the interrupt.
771  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
772 
773  // Unregister the interrupt handler.
774  IntUnregister(INT_CRYPTO_RESULT_AVAIL_IRQ);
775 }
void IntUnregister(uint32_t ui32Interrupt)
Unregisters an interrupt handler in the dynamic vector table.
Definition: interrupt.c:189
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt or system exception.
Definition: interrupt.c:327

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 AES_SUCCESS   0
#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