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()
165 {
166  uint32_t ui32CtrlVal;
167 
168  // Enable internal interrupts.
171 
172  // Clear any outstanding interrupts.
175 
176  // Wait for interrupt lines from module to be cleared
178 
179  // If using interrupts clear any pending interrupts and enable interrupts
180  // for the Crypto module.
181  if(bIntEnable)
182  {
183  IntPendClear(INT_CRYPTO_RESULT_AVAIL_IRQ);
184  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
185  }
186 
187  // Configure Master Control module.
189 
190  // Enable keys to read (e.g. Key 0).
191  HWREG(CRYPTO_BASE + CRYPTO_O_KEYREADAREA) = ui32KeyLocation;
192 
193  //Wait until key is loaded to the AES module.
194  do
195  {
196  CPUdelay(1);
197  }
199 
200  // Check for Key store Read error.
202  {
203  return (AES_KEYSTORE_READ_ERROR);
204  }
205 
206  // Write initialization vector.
207  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV0) = pui32Nonce[0];
208  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV1) = pui32Nonce[1];
209  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV2) = pui32Nonce[2];
210  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV3) = pui32Nonce[3];
211 
212  // Configure AES engine for AES-CBC with 128-bit key size.
214  if(bEncrypt)
215  {
216  ui32CtrlVal |= CRYPTO_AES128_ENCRYPT;
217  }
218  else
219  {
220  ui32CtrlVal |= CRYPTO_AES128_DECRYPT;
221  }
222  HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) = ui32CtrlVal;
223 
224  // Write the length of the crypto block (plain text).
225  // Low and high part (high part is assumed to be always 0).
226  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN0) = ui32MsgLength;
227  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN1) = 0;
228  HWREG(CRYPTO_BASE + CRYPTO_O_AESAUTHLEN) = 0;
229 
230  // Enable Crypto DMA channel 0.
232 
233  // Base address of the input data in ext. memory.
234  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32MsgIn;
235 
236  // Input data length in bytes, equal to the message.
237  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32MsgLength;
238 
239  // Enable Crypto DMA channel 1.
241 
242  // Set up the address and length of the output data.
243  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1EXTADDR) = (uint32_t)pui32MsgOut;
244  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1LEN) = ui32MsgLength;
245 
246  // Return success
247  return AES_SUCCESS;
248 }
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
Definition: crypto.h:120
void IntPendClear(uint32_t ui32Interrupt)
Unpends an interrupt.
Definition: interrupt.c:440
#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.
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:280
#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()
257 {
258  return(CRYPTOAesEcbStatus());
259 }
uint32_t CRYPTOAesEcbStatus(void)
Check the result of an AES ECB operation.
Definition: crypto.c:350

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()
270 {
271  // Enable internal interrupts.
274 
275  // Clear any outstanding interrupts.
278 
279  // Wait for interrupt lines from module to be cleared
281 
282  // If using interrupts clear any pending interrupts and enable interrupts
283  // for the Crypto module.
284  if(bIntEnable)
285  {
286  IntPendClear(INT_CRYPTO_RESULT_AVAIL_IRQ);
287  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
288  }
289 
290  // Configure Master Control module.
292 
293  // Enable keys to read (e.g. Key 0).
294  HWREG(CRYPTO_BASE + CRYPTO_O_KEYREADAREA) = ui32KeyLocation;
295 
296  //Wait until key is loaded to the AES module.
297  do
298  {
299  CPUdelay(1);
300  }
302 
303  // Check for Key store Read error.
305  {
306  return (AES_KEYSTORE_READ_ERROR);
307  }
308 
309  // Configure AES engine (program AES-ECB-128 encryption and no
310  // initialization vector - IV).
311  if(bEncrypt)
312  {
314  }
315  else
316  {
318  }
319 
320  // Write the length of the data.
322  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN1) = 0;
323 
324  // Enable Crypto DMA channel 0.
326 
327  // Base address of the input data in ext. memory.
328  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32MsgIn;
329 
330  // Input data length in bytes, equal to the message.
332 
333  // Enable Crypto DMA channel 1.
335 
336  // Set up the address and length of the output data.
337  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1EXTADDR) = (uint32_t)pui32MsgOut;
339 
340  // Return success
341  return AES_SUCCESS;
342 }
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
Definition: crypto.h:120
void IntPendClear(uint32_t ui32Interrupt)
Unpends an interrupt.
Definition: interrupt.c:440
#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.
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:280
#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().

351 {
352  uint32_t ui32Status;
353 
354  // Get the current DMA status.
355  ui32Status = HWREG(CRYPTO_BASE + CRYPTO_O_DMASTAT);
356 
357  // Check if DMA is still busy.
358  if(ui32Status & CRYPTO_DMA_BSY)
359  {
360  return (AES_DMA_BSY);
361  }
362 
363  // Check the status of the DMA operation - return error if not success.
364  if(ui32Status & CRYPTO_DMA_BUS_ERROR)
365  {
366  return (AES_DMA_BUS_ERROR);
367  }
368 
369  // Operation successful - disable interrupt and return success.
370  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
371  return (AES_SUCCESS);
372 }
#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:324

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  // Check the arguments.
86  ASSERT((ui32KeyLocation == CRYPTO_KEY_AREA_0) |
87  (ui32KeyLocation == CRYPTO_KEY_AREA_1) |
88  (ui32KeyLocation == CRYPTO_KEY_AREA_2) |
89  (ui32KeyLocation == CRYPTO_KEY_AREA_3) |
90  (ui32KeyLocation == CRYPTO_KEY_AREA_4) |
91  (ui32KeyLocation == CRYPTO_KEY_AREA_5) |
92  (ui32KeyLocation == CRYPTO_KEY_AREA_6) |
93  (ui32KeyLocation == CRYPTO_KEY_AREA_7));
94 
95  // Disable the external interrupt to stop the interrupt form propagating
96  // from the module to the System CPU.
97  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
98 
99  // Enable internal interrupts.
103 
104  // Configure master control module.
106 
107  // Clear any outstanding events.
110 
111  // Configure key store module for 128 bit operation.
114 
115  // Enable keys to write (e.g. Key 0).
116  HWREG(CRYPTO_BASE + CRYPTO_O_KEYWRITEAREA) = (0x00000001 << ui32KeyLocation);
117 
118  // Enable Crypto DMA channel 0.
120 
121  // Base address of the key in ext. memory.
122  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32AesKey;
123 
124  // Total key length in bytes (e.g. 16 for 1 x 128-bit key).
125  // Writing the length of the key enables the DMA operation.
127 
128  // Wait for the DMA operation to complete.
129  do
130  {
131  CPUdelay(1);
132  }
133  while(!(HWREG(CRYPTO_BASE + CRYPTO_O_IRQSTAT) & 0x00000001));
134 
135  // Check for errors in DMA and key store.
136  if((HWREG(CRYPTO_BASE + CRYPTO_O_IRQSTAT) &
139  {
140  // Acknowledge/clear the interrupt and disable the master control.
143  HWREG(CRYPTO_BASE + CRYPTO_O_ALGSEL) = 0x00000000;
144 
145  // Check status, if error return error code.
146  if(HWREG(CRYPTO_BASE + CRYPTO_O_KEYWRITTENAREA) != (0x00000001 << ui32KeyLocation))
147  {
148  return (AES_KEYSTORE_READ_ERROR);
149  }
150  }
151 
152  // Return success.
153  return (AES_SUCCESS);
154 }
#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.
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:324
#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()
385 {
386  uint32_t ui32CtrlVal;
387  uint32_t i;
388  uint32_t *pui32CipherText;
389  union {
390  uint32_t w[4];
391  uint8_t b[16];
392  } ui8InitVec;
393 
394  // Input address for the encryption engine is the same as the output.
395  pui32CipherText = pui32PlainText;
396 
397  // Disable global interrupt, enable local interrupt and clear any pending
398  // interrupts.
399  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
402 
403  // Enable internal interrupts.
407 
408  // Configure master control module for AES operation.
410 
411  // Enable keys to read (e.g. Key 0).
412  HWREG(CRYPTO_BASE + CRYPTO_O_KEYREADAREA) = ui32KeyLocation;
413 
414  // Wait until key is loaded to the AES module.
415  do
416  {
417  CPUdelay(1);
418  }
420 
421  // Check for Key store Read error.
423  {
424  return (AES_KEYSTORE_READ_ERROR);
425  }
426 
427  // Prepare the initialization vector (IV),
428  // Length of Nonce l(n) = 15 - ui32FieldLength.
429  ui8InitVec.b[0] = ui32FieldLength - 1;
430  for(i = 0; i < 12; i++)
431  {
432  ui8InitVec.b[i + 1] = ((uint8_t*)pui32Nonce)[i];
433  }
434  if(ui32FieldLength == 2)
435  {
436  ui8InitVec.b[13] = ((uint8_t*)pui32Nonce)[12];
437  }
438  else
439  {
440  ui8InitVec.b[13] = 0;
441  }
442  ui8InitVec.b[14] = 0;
443  ui8InitVec.b[15] = 0;
444 
445  // Write initialization vector.
446  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV0) = ui8InitVec.w[0];
447  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV1) = ui8InitVec.w[1];
448  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV2) = ui8InitVec.w[2];
449  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV3) = ui8InitVec.w[3];
450 
451  // Configure AES engine.
452  ui32CtrlVal = ((ui32FieldLength - 1) << CRYPTO_AESCTL_CCM_L_S);
453  if ( ui32AuthLength >= 2 ) {
454  ui32CtrlVal |= ((( ui32AuthLength - 2 ) >> 1 ) << CRYPTO_AESCTL_CCM_M_S );
455  }
456  ui32CtrlVal |= CRYPTO_AESCTL_CCM;
457  ui32CtrlVal |= CRYPTO_AESCTL_CTR;
458  ui32CtrlVal |= CRYPTO_AESCTL_SAVE_CONTEXT;
459  ui32CtrlVal |= (KEY_STORE_SIZE_128 << CRYPTO_AESCTL_KEY_SIZE_S);
460  ui32CtrlVal |= (1 << CRYPTO_AESCTL_DIR_S);
461  ui32CtrlVal |= (CRYPTO_AES_CTR_128 << CRYPTO_AESCTL_CTR_WIDTH_S);
462 
463  // Write the configuration for 128 bit AES-CCM.
464  HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) = ui32CtrlVal;
465 
466  // Write the length of the crypto block (plain text).
467  // Low and high part (high part is assumed to be always 0).
468  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN0) = ui32PlainTextLength;
469  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN1) = 0;
470 
471  // Write the length of the header field.
472  // Also called AAD - Additional Authentication Data.
473  HWREG(CRYPTO_BASE + CRYPTO_O_AESAUTHLEN) = ui32HeaderLength;
474 
475  // Check if any header information (AAD).
476  // If so configure the DMA controller to fetch the header.
477  if(ui32HeaderLength != 0)
478  {
479  // Enable DMA channel 0.
481 
482  // Register the base address of the header (AAD).
483  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32Header;
484 
485  // Header length in bytes (may be non-block size aligned).
486  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32HeaderLength;
487 
488  // Wait for completion of the header data transfer, DMA_IN_DONE.
489  do
490  {
491  CPUdelay(1);
492  }
494 
495  // Check for DMA errors.
497  {
498  return AES_DMA_BUS_ERROR;
499  }
500  }
501 
502  // Clear interrupt status.
505 
506  // Wait for interrupt lines from module to be cleared
508 
509  // Disable CRYPTO_IRQEN_DMA_IN_DONE interrupt as we only
510  // want interrupt to trigger once RESULT_AVAIL occurs.
512 
513 
514  // Is using interrupts enable globally.
515  if(bIntEnable)
516  {
517  IntPendClear(INT_CRYPTO_RESULT_AVAIL_IRQ);
518  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
519  }
520 
521  // Enable interrupts locally.
523 
524  // Perform encryption if requested.
525  if(bEncrypt)
526  {
527  // Enable DMA channel 0
529 
530  // base address of the payload data in ext. memory.
532  (uint32_t)pui32PlainText;
533 
534  // Enable DMA channel 1
536 
537  // Base address of the output data buffer.
539  (uint32_t)pui32CipherText;
540 
541  // Payload data length in bytes, equal to the plaintext length.
542  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32PlainTextLength;
543  // Output data length in bytes, equal to the plaintext length.
544  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1LEN) = ui32PlainTextLength;
545  }
546 
547  return AES_SUCCESS;
548 }
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
Definition: crypto.h:120
void IntPendClear(uint32_t ui32Interrupt)
Unpends an interrupt.
Definition: interrupt.c:440
#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.
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:324
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:280
#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.

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

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()
557 {
558  uint32_t ui32Status;
559 
560  // Get the current DMA status.
561  ui32Status = HWREG(CRYPTO_BASE + CRYPTO_O_DMASTAT);
562 
563  // Check if DMA is still busy.
564  if(ui32Status & CRYPTO_DMA_BSY)
565  {
566  return (AES_DMA_BSY);
567  }
568 
569  // Check the status of the DMA operation - return error if not success.
570  if(ui32Status & CRYPTO_DMA_BUS_ERROR)
571  {
572  return (AES_DMA_BUS_ERROR);
573  }
574 
575  // Operation successful - disable interrupt and return success.
576  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
577  return (AES_SUCCESS);
578 }
#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:324

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:
632 {
633  uint32_t ui32CtrlVal;
634  uint32_t i;
635  uint32_t *pui32PlainText;
636  uint32_t ui32CryptoBlockLength;
637  union {
638  uint32_t w[4];
639  uint8_t b[16];
640  } ui8InitVec;
641 
642  // Input address for the encryption engine is the same as the output.
643  pui32PlainText = pui32CipherText;
644 
645  // Disable global interrupt, enable local interrupt and clear any pending.
646  // interrupts.
647  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
650  // Enable internal interrupts.
654 
655  // Configure master control module for AES operation.
657 
658  // Enable keys to read (e.g. Key 0).
659  HWREG(CRYPTO_BASE + CRYPTO_O_KEYREADAREA) = ui32KeyLocation;
660 
661  // Wait until key is loaded to the AES module.
662  do
663  {
664  CPUdelay(1);
665  }
667 
668  // Check for Key store Read error.
670  {
671  return (AES_KEYSTORE_READ_ERROR);
672  }
673 
674  // Prepare the initialization vector (IV),
675  // Length of Nonce l(n) = 15 - ui32FieldLength.
676  ui8InitVec.b[0] = ui32FieldLength - 1;
677  for(i = 0; i < 12; i++)
678  {
679  ui8InitVec.b[i + 1] = ((uint8_t*)pui32Nonce)[i];
680  }
681  if(ui32FieldLength == 2)
682  {
683  ui8InitVec.b[13] = ((uint8_t*)pui32Nonce)[12];
684  }
685  else
686  {
687  ui8InitVec.b[13] = 0;
688  }
689  ui8InitVec.b[14] = 0;
690  ui8InitVec.b[15] = 0;
691 
692  // Write initialization vector.
693  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV0) = ui8InitVec.w[0];
694  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV1) = ui8InitVec.w[1];
695  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV2) = ui8InitVec.w[2];
696  HWREG(CRYPTO_BASE + CRYPTO_O_AESIV3) = ui8InitVec.w[3];
697 
698  // Configure AES engine
699  ui32CryptoBlockLength = ui32CipherTextLength - ui32AuthLength;
700  ui32CtrlVal = ((ui32FieldLength - 1) << CRYPTO_AESCTL_CCM_L_S);
701  if ( ui32AuthLength >= 2 ) {
702  ui32CtrlVal |= ((( ui32AuthLength - 2 ) >> 1 ) << CRYPTO_AESCTL_CCM_M_S );
703  }
704  ui32CtrlVal |= CRYPTO_AESCTL_CCM;
705  ui32CtrlVal |= CRYPTO_AESCTL_CTR;
706  ui32CtrlVal |= CRYPTO_AESCTL_SAVE_CONTEXT;
707  ui32CtrlVal |= (KEY_STORE_SIZE_128 << CRYPTO_AESCTL_KEY_SIZE_S);
708  ui32CtrlVal |= (0 << CRYPTO_AESCTL_DIR_S);
709  ui32CtrlVal |= (CRYPTO_AES_CTR_128 << CRYPTO_AESCTL_CTR_WIDTH_S);
710 
711  // Write the configuration for 128 bit AES-CCM.
712  HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) = ui32CtrlVal;
713 
714  // Write the length of the crypto block (plain text).
715  // Low and high part (high part is assumed to be always 0).
716  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN0) = ui32CryptoBlockLength;
717  HWREG(CRYPTO_BASE + CRYPTO_O_AESDATALEN1) = 0;
718 
719  // Write the length of the header field.
720  // Also called AAD - Additional Authentication Data.
721  HWREG(CRYPTO_BASE + CRYPTO_O_AESAUTHLEN) = ui32HeaderLength;
722 
723  // Check if any header information (AAD).
724  // If so configure the DMA controller to fetch the header.
725  if(ui32HeaderLength != 0)
726  {
727  // Enable DMA channel 0.
729 
730  // Register the base address of the header (AAD).
731  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0EXTADDR) = (uint32_t)pui32Header;
732 
733  // Header length in bytes (may be non-block size aligned).
734  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32HeaderLength;
735 
736  // Wait for completion of the header data transfer, DMA_IN_DONE.
737  do
738  {
739  CPUdelay(1);
740  }
742 
743  // Check for DMA errors.
745  {
746  return AES_DMA_BUS_ERROR;
747  }
748  }
749 
750  // Clear interrupt status.
753 
754  // Wait for interrupt lines from module to be cleared
756 
757  // Disable CRYPTO_IRQEN_DMA_IN_DONE interrupt as we only
758  // want interrupt to trigger once RESULT_AVAIL occurs.
760 
761  // Is using interrupts - clear and enable globally.
762  if(bIntEnable)
763  {
764  IntPendClear(INT_CRYPTO_RESULT_AVAIL_IRQ);
765  IntEnable(INT_CRYPTO_RESULT_AVAIL_IRQ);
766  }
767 
768  // Enable internal interrupts.
771 
772  // Perform decryption if requested.
773  if(bDecrypt)
774  {
775  // Configure the DMA controller - enable both DMA channels.
777 
778  // Base address of the payload data in ext. memory.
780  (uint32_t)pui32CipherText;
781 
782  // Payload data length in bytes, equal to the cipher text length.
783  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH0LEN) = ui32CryptoBlockLength;
784 
785  // Enable DMA channel 1.
787 
788  // Base address of the output data buffer.
790  (uint32_t)pui32PlainText;
791 
792  // Output data length in bytes, equal to the cipher text length.
793  HWREG(CRYPTO_BASE + CRYPTO_O_DMACH1LEN) = ui32CryptoBlockLength;
794  }
795 
796  return AES_SUCCESS;
797 }
#define AES_KEYSTORE_READ_ERROR
Definition: crypto.h:141
Definition: crypto.h:120
void IntPendClear(uint32_t ui32Interrupt)
Unpends an interrupt.
Definition: interrupt.c:440
#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.
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:324
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:280
#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.
839 {
840  uint32_t volatile ui32Tag[4];
841  uint32_t ui32TagIndex;
842  uint32_t i;
843  uint32_t ui32Idx;
844 
845  ui32TagIndex = ui32CipherTextLength - ui32AuthLength;
846 
847  // Result has already been copied to the output buffer by DMA
848  // Disable master control.
849  HWREG(CRYPTO_BASE + CRYPTO_O_ALGSEL) = 0x00000000;
850 
851  // Read tag - wait for the context ready bit.
852  do
853  {
854  CPUdelay(1);
855  }
856  while(!(HWREG(CRYPTO_BASE + CRYPTO_O_AESCTL) &
858 
859  // Read the Tag registers.
860  ui32Tag[0] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT0);
861  ui32Tag[1] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT1);
862  ui32Tag[2] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT2);
863  ui32Tag[3] = HWREG(CRYPTO_BASE + CRYPTO_O_AESTAGOUT3);
864 
865  for(ui32Idx = 0; ui32Idx < ui32AuthLength ; ui32Idx++)
866  {
867  *((uint8_t*)pui32CcmTag + ui32Idx) = *((uint8_t*)ui32Tag + ui32Idx);
868  }
869 
870  // Operation successful - clear interrupt status.
873 
874  // Verify the Tag.
875  for(i = 0; i < ui32AuthLength; i++)
876  {
877  if(*((uint8_t *)pui32CcmTag + i) !=
878  (*((uint8_t *)pui32CipherText + ui32TagIndex + i)))
879  {
881  }
882  }
883 
884  return AES_SUCCESS;
885 }
#define CCM_AUTHENTICATION_FAILED
Definition: crypto.h:144
#define AES_SUCCESS
Definition: crypto.h:140
void CPUdelay(uint32_t ui32Count)
Provide a small delay.

Here is the call graph for this function:

uint32_t CRYPTOCcmInvAuthDecryptStatus ( void  )

Checks CCM decrypt and Inverse Authentication result.

Returns
Returns status of operation:
806 {
807  uint32_t ui32Status;
808 
809  // Get the current DMA status.
810  ui32Status = HWREG(CRYPTO_BASE + CRYPTO_O_DMASTAT);
811 
812  // Check if DMA is still busy.
813  if(ui32Status & CRYPTO_DMA_BSY)
814  {
815  return (AES_DMA_BSY);
816  }
817 
818  // Check the status of the DMA operation - return error if not success.
819  if(ui32Status & CRYPTO_DMA_BUS_ERROR)
820  {
821  return (AES_DMA_BUS_ERROR);
822  }
823 
824  // Operation successful - disable interrupt and return success
825  IntDisable(INT_CRYPTO_RESULT_AVAIL_IRQ);
826  return (AES_SUCCESS);
827 }
#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:324

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
917 {
918  // Check the arguments.
919  ASSERT((ui32Channels & CRYPTO_DMA_CHAN0) |
920  (ui32Channels & CRYPTO_DMA_CHAN1));
921 
922  // Enable the selected channels.
923  if(ui32Channels & CRYPTO_DMA_CHAN0)
924  {
926  }
927  if(ui32Channels & CRYPTO_DMA_CHAN1)
928  {
930  }
931 }
#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
894 {
895  // Check the arguments.
896  ASSERT((ui32Channels & CRYPTO_DMA_CHAN0) |
897  (ui32Channels & CRYPTO_DMA_CHAN1));
898 
899  // Enable the selected channels,
900  if(ui32Channels & CRYPTO_DMA_CHAN0)
901  {
903  }
904  if(ui32Channels & CRYPTO_DMA_CHAN1)
905  {
907  }
908 }
#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:150
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:280

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:186
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:324

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