S32 SDK
csec_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
19 #include "csec_driver.h"
20 #include "csec_hw_access.h"
21 
59 /*******************************************************************************
60  * Definitions
61  ******************************************************************************/
62 
63 /* Represents the size of a CSE_PRAM page in bytes */
64 #define CSEC_PAGE_SIZE_IN_BYTES (16U)
65 
66 /* Represents the number of CSE_PRAM pages available for data (excluding the
67 first page, used for command header) */
68 #define CSEC_DATA_PAGES_AVAILABLE (7U)
69 /* Represents the number of bytes in CSE_PRAM available for data (excluding the
70 first page, used for command header) */
71 #define CSEC_DATA_BYTES_AVAILABLE (112U)
72 
73 /* Represents the shift used for converting CSE_PRAM pages number to/from bytes number */
74 #define CSEC_BYTES_TO_FROM_PAGES_SHIFT (4U)
75 /* Represents the shift used for converting CSE_PRAM pages number to/from bits number */
76 #define CSEC_BYTES_TO_FROM_BITS_SHIFT (3U)
77 
78 /* Represents the size in bytes of the M1 entry (used for key management) */
79 #define CSEC_M1_SIZE_IN_BYTES (16U)
80 /* Represents the size in bytes of the M2 entry (used for key management) */
81 #define CSEC_M2_SIZE_IN_BYTES (32U)
82 /* Represents the size in bytes of the M3 entry (used for key management) */
83 #define CSEC_M3_SIZE_IN_BYTES (16U)
84 /* Represents the size in bytes of the M4 entry (used for key management) */
85 #define CSEC_M4_SIZE_IN_BYTES (32U)
86 /* Represents the size in bytes of the M5 entry (used for key management) */
87 #define CSEC_M5_SIZE_IN_BYTES (16U)
88 
89 /* Pointer to runtime state structure.*/
90 static csec_state_t * g_csecStatePtr = NULL;
91 
92 /* The FTFC interrupt handler, used when a CSEc command is completed. */
93 void FTFC_IRQHandler(void);
94 
95 /*******************************************************************************
96  * Private Functions
97  ******************************************************************************/
98 
99 static void CSEC_DRV_InitState(csec_key_id_t keyId,
100  csec_cmd_t cmd,
101  const uint8_t * inBuff,
102  uint8_t * outBuff,
103  uint32_t length);
104 
105 /* Rounds up the value to the first number multiple of roundTo */
106 static inline uint32_t CSEC_DRV_RoundTo(uint32_t value,
107  uint32_t roundTo)
108 {
109  return (value + (roundTo - 1U)) & ~(roundTo - 1U);
110 }
111 
112 static void CSEC_DRV_StartEncDecECBCmd(void);
113 static void CSEC_DRV_ContinueEncDecECBCmd(void);
114 static void CSEC_DRV_StartEncDecCBCCmd(void);
115 static void CSEC_DRV_ContinueEncDecCBCCmd(void);
116 static void CSEC_DRV_StartGenMACCmd(void);
117 static void CSEC_DRV_ContinueGenMACCmd(void);
118 static void CSEC_DRV_StartVerifMACCmd(void);
119 static void CSEC_DRV_ContinueVerifMACCmd(void);
120 
121 /*******************************************************************************
122  * Code
123  ******************************************************************************/
124 
125 /*FUNCTION**********************************************************************
126  *
127  * Function Name : CSEC_DRV_Init
128  * Description : This function initializes the internal state of the driver
129  * and enables the FTFC interrupt.
130  *
131  * Implements : CSEC_DRV_Init_Activity
132  * END**************************************************************************/
134 {
135  DEV_ASSERT(state != NULL);
136 
137  g_csecStatePtr = state;
138  g_csecStatePtr->cmdInProgress = false;
139 
141 }
142 
143 /*FUNCTION**********************************************************************
144  *
145  * Function Name : CSEC_DRV_Deinit
146  * Description : This function clears the internal state of the driver and
147  * disables the FTFC interrupt.
148  *
149  * Implements : CSEC_DRV_Deinit_Activity
150  * END**************************************************************************/
152 {
153  g_csecStatePtr = NULL;
154 
156 }
157 
158 /*FUNCTION**********************************************************************
159  *
160  * Function Name : CSEC_DRV_EncryptECB
161  * Description : This function performs the AES-128 encryption in ECB mode of
162  * the input plain text buffer.
163  *
164  * Implements : CSEC_DRV_EncryptECB_Activity
165  * END**************************************************************************/
167  const uint8_t * plainText,
168  uint32_t length,
169  uint8_t * cipherText)
170 {
171  DEV_ASSERT(plainText != NULL);
172  DEV_ASSERT(cipherText != NULL);
173 
174  if (g_csecStatePtr->cmdInProgress)
175  {
176  return STATUS_BUSY;
177  }
178 
179  /* Initialize the internal state of the driver */
180  CSEC_DRV_InitState(keyId, CSEC_CMD_ENC_ECB, plainText, cipherText, length);
181 
183 
184  while (g_csecStatePtr->cmdInProgress)
185  {
186  /* Wait until the execution of the command is complete */
187  CSEC_WaitCommandCompletion();
188 
190  }
191 
192  return g_csecStatePtr->errCode;
193 }
194 
195 /*FUNCTION**********************************************************************
196  *
197  * Function Name : CSEC_DRV_DecryptECB
198  * Description : This function performs the AES-128 decryption in ECB mode of
199  * the input cipher text buffer.
200  *
201  * Implements : CSEC_DRV_DecryptECB_Activity
202  * END**************************************************************************/
204  const uint8_t * cipherText,
205  uint32_t length,
206  uint8_t * plainText)
207 {
208  DEV_ASSERT(plainText != NULL);
209  DEV_ASSERT(cipherText != NULL);
210 
211  if (g_csecStatePtr->cmdInProgress)
212  {
213  return STATUS_BUSY;
214  }
215  /* Initialize the internal state of the driver */
216  CSEC_DRV_InitState(keyId, CSEC_CMD_DEC_ECB, cipherText, plainText, length);
217 
219 
220  while (g_csecStatePtr->cmdInProgress)
221  {
222  /* Wait until the execution of the command is complete */
223  CSEC_WaitCommandCompletion();
224 
226  }
227 
228  return g_csecStatePtr->errCode;
229 }
230 
231 /*FUNCTION**********************************************************************
232  *
233  * Function Name : CSEC_DRV_EncryptCBC
234  * Description : This function performs the AES-128 encryption in CBC mode of
235  * the input cipher text buffer.
236  *
237  * Implements : CSEC_DRV_EncryptCBC_Activity
238  * END**************************************************************************/
240  const uint8_t * plainText,
241  uint32_t length,
242  const uint8_t * iv,
243  uint8_t * cipherText)
244 {
245  DEV_ASSERT(plainText != NULL);
246  DEV_ASSERT(cipherText != NULL);
247  DEV_ASSERT(iv != NULL);
248 
249  if (g_csecStatePtr->cmdInProgress)
250  {
251  return STATUS_BUSY;
252  }
253 
254  /* Initialize the internal state of the driver */
255  CSEC_DRV_InitState(keyId, CSEC_CMD_ENC_CBC, plainText, cipherText, length);
256  g_csecStatePtr->iv = iv;
257 
259 
260  while (g_csecStatePtr->cmdInProgress)
261  {
262  /* Wait until the execution of the command is complete */
263  CSEC_WaitCommandCompletion();
264 
266  }
267 
268  return g_csecStatePtr->errCode;
269 }
270 
271 /*FUNCTION**********************************************************************
272  *
273  * Function Name : CSEC_DRV_DecryptCBC
274  * Description : This function performs the AES-128 decryption in CBC mode of
275  * the input cipher text buffer.
276  *
277  * Implements : CSEC_DRV_DecryptCBC_Activity
278  * END**************************************************************************/
280  const uint8_t * cipherText,
281  uint16_t length,
282  const uint8_t * iv,
283  uint8_t * plainText)
284 {
285  DEV_ASSERT(plainText != NULL);
286  DEV_ASSERT(cipherText != NULL);
287  DEV_ASSERT(iv != NULL);
288 
289  if (g_csecStatePtr->cmdInProgress)
290  {
291  return STATUS_BUSY;
292  }
293 
294  /* Initialize the internal state of the driver */
295  CSEC_DRV_InitState(keyId, CSEC_CMD_DEC_CBC, cipherText, plainText, length);
296  g_csecStatePtr->iv = iv;
297 
299 
300  while (g_csecStatePtr->cmdInProgress)
301  {
302  /* Wait until the execution of the command is complete */
303  CSEC_WaitCommandCompletion();
304 
306  }
307 
308  return g_csecStatePtr->errCode;
309 }
310 
311 /*FUNCTION**********************************************************************
312  *
313  * Function Name : CSEC_DRV_GenerateMAC
314  * Description : This function calculates the MAC of a given message using
315  * CMAC with AES-128.
316  *
317  * Implements : CSEC_DRV_GenerateMAC_Activity
318  * END**************************************************************************/
320  const uint8_t * msg,
321  uint32_t msgLen,
322  uint8_t * cmac)
323 {
324  DEV_ASSERT(msg != NULL);
325  DEV_ASSERT(cmac != NULL);
326 
327  if (g_csecStatePtr->cmdInProgress)
328  {
329  return STATUS_BUSY;
330  }
331 
332  /* Initialize the internal state of the driver */
334  g_csecStatePtr->msgLen = msgLen;
335 
337 
338  while (g_csecStatePtr->cmdInProgress)
339  {
340  /* Wait until the execution of the command is complete */
341  CSEC_WaitCommandCompletion();
342 
344  }
345 
346  return g_csecStatePtr->errCode;
347 }
348 
349 /*FUNCTION**********************************************************************
350  *
351  * Function Name : CSEC_DRV_GenerateMACAddrMode
352  * Description : This function calculates the MAC of a given message using
353  * CMAC with AES-128. It is different from the CSEC_DRV_GenerateMAC function in
354  * the sense that it does not involve an extra copy of the data on which the
355  * CMAC is computed and the message pointer should be a pointer to Flash memory.
356  *
357  * Implements : CSEC_DRV_GenerateMACAddrMode_Activity
358  * END**************************************************************************/
360  const uint8_t * msg,
361  uint32_t msgLen,
362  uint8_t * cmac)
363 {
364  status_t stat;
365 
366  DEV_ASSERT(msg != NULL);
367  DEV_ASSERT(cmac != NULL);
368 
369  if (g_csecStatePtr->cmdInProgress)
370  {
371  return STATUS_BUSY;
372  }
373  g_csecStatePtr->cmdInProgress = true;
374 
375  /* Write the address of the message */
376  CSEC_WriteCommandWords(FEATURE_CSEC_FLASH_START_ADDRESS_OFFSET, (uint32_t *)&msg, 1U);
377  /* Write the size of the message (in bits) */
378  CSEC_WriteCommandWords(FEATURE_CSEC_MESSAGE_LENGTH_OFFSET, &msgLen, 1U);
379  /* Write the command header. This will trigger the command execution. */
380  CSEC_WriteCmdAndWait(CSEC_CMD_GENERATE_MAC, CSEC_FUNC_FORMAT_ADDR, CSEC_CALL_SEQ_FIRST, keyId);
381 
382  /* Read the status of the execution */
383  stat = CSEC_ReadErrorBits();
384  /* Read the resulted MAC */
385  if (stat == STATUS_SUCCESS)
386  {
387  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_2_OFFSET, cmac, CSEC_PAGE_SIZE_IN_BYTES);
388  }
389 
390  g_csecStatePtr->cmdInProgress = false;
391 
392  return stat;
393 }
394 
395 /*FUNCTION**********************************************************************
396  *
397  * Function Name : CSEC_DRV_VerifyMAC
398  * Description : This function verifies the MAC of a given message using CMAC
399  * with AES-128.
400  *
401  * Implements : CSEC_DRV_VerifyMAC_Activity
402  * END**************************************************************************/
404  const uint8_t * msg,
405  uint32_t msgLen,
406  const uint8_t * mac,
407  uint16_t macLen,
408  bool * verifStatus)
409 {
410  DEV_ASSERT(msg != NULL);
411  DEV_ASSERT(mac != NULL);
412  DEV_ASSERT(verifStatus != NULL);
413 
414  if (g_csecStatePtr->cmdInProgress)
415  {
416  return STATUS_BUSY;
417  }
418 
419  /* Initialize the internal state of the driver */
421  g_csecStatePtr->msgLen = msgLen;
422  g_csecStatePtr->verifStatus = verifStatus;
423  g_csecStatePtr->macWritten = false;
424  g_csecStatePtr->mac = mac;
425  g_csecStatePtr->macLen = macLen;
426 
428 
429  while (g_csecStatePtr->cmdInProgress)
430  {
431  /* Wait until the execution of the command is complete */
432  CSEC_WaitCommandCompletion();
433 
435  }
436 
437  return g_csecStatePtr->errCode;
438 }
439 
440 /*FUNCTION**********************************************************************
441  *
442  * Function Name : CSEC_DRV_VerifyMACAddrMode
443  * Description : This function verifies the MAC of a given message using CMAC
444  * with AES-128. It is different from the CSEC_DRV_VerifyMAC function in the
445  * sense that it does not involve an extra copy of the data on which the CMAC is
446  * computed and the message pointer should be a pointer to Flash memory.
447  *
448  * Implements : CSEC_DRV_VerifyMACAddrMode_Activity
449  * END**************************************************************************/
451  const uint8_t * msg,
452  uint32_t msgLen,
453  const uint8_t * mac,
454  uint16_t macLen,
455  bool * verifStatus)
456 {
457  status_t stat;
458 
459  DEV_ASSERT(msg != NULL);
460  DEV_ASSERT(mac != NULL);
461  DEV_ASSERT(verifStatus != NULL);
462 
463  if (g_csecStatePtr->cmdInProgress)
464  {
465  return STATUS_BUSY;
466  }
467  g_csecStatePtr->cmdInProgress = true;
468 
469  /* Write the address of the message */
470  CSEC_WriteCommandWords(FEATURE_CSEC_FLASH_START_ADDRESS_OFFSET, (uint32_t *)&msg, 1U);
471  /* Write the MAC to be verified */
472  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_2_OFFSET, mac, CSEC_PAGE_SIZE_IN_BYTES);
473  /* Write the size of the message (in bits) */
474  CSEC_WriteCommandWords(FEATURE_CSEC_MESSAGE_LENGTH_OFFSET, &msgLen, 1U);
475  /* Write the number of bits of the MAC to be compared */
476  CSEC_WriteCommandHalfWord(FEATURE_CSEC_MAC_LENGTH_OFFSET, macLen);
477  /* Write the command header. This will trigger the command execution. */
478  CSEC_WriteCmdAndWait(CSEC_CMD_VERIFY_MAC, CSEC_FUNC_FORMAT_ADDR, CSEC_CALL_SEQ_FIRST, keyId);
479 
480  /* Read the status of the execution */
481  stat = CSEC_ReadErrorBits();
482 
483  /* Read the result of the MAC verification */
484  if (stat == STATUS_SUCCESS)
485  {
486  *verifStatus = (CSEC_ReadCommandHalfWord(FEATURE_CSEC_VERIFICATION_STATUS_OFFSET) == 0U);
487  }
488 
489  g_csecStatePtr->cmdInProgress = false;
490 
491  return stat;
492 }
493 
494 /*FUNCTION**********************************************************************
495  *
496  * Function Name : CSEC_DRV_LoadKey
497  * Description : This function updates an internal key per the SHE
498  * specification.
499  *
500  * Implements : CSEC_DRV_LoadKey_Activity
501  * END**************************************************************************/
503  const uint8_t * m1,
504  const uint8_t * m2,
505  const uint8_t * m3,
506  uint8_t * m4,
507  uint8_t * m5)
508 {
509  status_t stat;
510 
511  DEV_ASSERT(m1 != NULL);
512  DEV_ASSERT(m2 != NULL);
513  DEV_ASSERT(m3 != NULL);
514  DEV_ASSERT(m4 != NULL);
515  DEV_ASSERT(m5 != NULL);
516 
517  if (g_csecStatePtr->cmdInProgress)
518  {
519  return STATUS_BUSY;
520  }
521  g_csecStatePtr->cmdInProgress = true;
522 
523  /* Write the values of M1-M3 */
524  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, m1, CSEC_M1_SIZE_IN_BYTES);
525  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_2_OFFSET, m2, CSEC_M2_SIZE_IN_BYTES);
526  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_4_OFFSET, m3, CSEC_M3_SIZE_IN_BYTES);
527  /* Write the command header. This will trigger the command execution. */
528  CSEC_WriteCommandHeader(CSEC_CMD_LOAD_KEY, CSEC_FUNC_FORMAT_COPY, CSEC_CALL_SEQ_FIRST, keyId);
529 
530  /* Wait until the execution of the command is complete */
531  CSEC_WaitCommandCompletion();
532 
533  /* Read the status of the execution */
534  stat = CSEC_ReadErrorBits();
535 
536  /* Read the obtained M4 and M5 */
537  if (stat == STATUS_SUCCESS)
538  {
539  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_5_OFFSET, m4, CSEC_M4_SIZE_IN_BYTES);
540  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_7_OFFSET, m5, CSEC_M5_SIZE_IN_BYTES);
541  }
542 
543  g_csecStatePtr->cmdInProgress = false;
544 
545  return stat;
546 }
547 
548 /*FUNCTION**********************************************************************
549  *
550  * Function Name : CSEC_DRV_LoadPlainKey
551  * Description : Updates the RAM key memory slot with a 128-bit plaintext.
552  *
553  * Implements : CSEC_DRV_LoadPlainKey_Activity
554  * END**************************************************************************/
555 status_t CSEC_DRV_LoadPlainKey(const uint8_t * plainKey)
556 {
557  status_t stat;
558 
559  DEV_ASSERT(plainKey != NULL);
560 
561  if (g_csecStatePtr->cmdInProgress)
562  {
563  return STATUS_BUSY;
564  }
565  g_csecStatePtr->cmdInProgress = true;
566 
567  /* Write the bytes of the key */
568  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, plainKey, CSEC_PAGE_SIZE_IN_BYTES);
569  /* Write the command header. This will trigger the command execution. */
570  CSEC_WriteCommandHeader(CSEC_CMD_LOAD_PLAIN_KEY, CSEC_FUNC_FORMAT_COPY, CSEC_CALL_SEQ_FIRST, CSEC_RAM_KEY);
571 
572  /* Wait until the execution of the command is complete */
573  CSEC_WaitCommandCompletion();
574 
575  /* Read the status of the execution */
576  stat = CSEC_ReadErrorBits();
577 
578  g_csecStatePtr->cmdInProgress = false;
579 
580  return stat;
581 }
582 
583 /*FUNCTION**********************************************************************
584  *
585  * Function Name : CSEC_DRV_ExportRAMKey
586  * Description : This function exports the RAM_KEY into a format protected by
587  * SECRET_KEY.
588  *
589  * Implements : CSEC_DRV_ExportRAMKey_Activity
590  * END**************************************************************************/
592  uint8_t * m2,
593  uint8_t * m3,
594  uint8_t * m4,
595  uint8_t * m5)
596 {
597  status_t stat;
598 
599  DEV_ASSERT(m1 != NULL);
600  DEV_ASSERT(m2 != NULL);
601  DEV_ASSERT(m3 != NULL);
602  DEV_ASSERT(m4 != NULL);
603  DEV_ASSERT(m5 != NULL);
604 
605  if (g_csecStatePtr->cmdInProgress)
606  {
607  return STATUS_BUSY;
608  }
609  g_csecStatePtr->cmdInProgress = true;
610 
611  /* Write the command header. This will trigger the command execution. */
612  CSEC_WriteCommandHeader(CSEC_CMD_EXPORT_RAM_KEY, CSEC_FUNC_FORMAT_COPY, CSEC_CALL_SEQ_FIRST, CSEC_RAM_KEY);
613 
614  /* Wait until the execution of the command is complete */
615  CSEC_WaitCommandCompletion();
616 
617  /* Read the status of the execution */
618  stat = CSEC_ReadErrorBits();
619  if (stat == STATUS_SUCCESS)
620  {
621  /* Read the M1-M5 values associated with the key */
622  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, m1, CSEC_M1_SIZE_IN_BYTES);
623  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_2_OFFSET, m2, CSEC_M2_SIZE_IN_BYTES);
624  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_4_OFFSET, m3, CSEC_M3_SIZE_IN_BYTES);
625  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_5_OFFSET, m4, CSEC_M4_SIZE_IN_BYTES);
626  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_7_OFFSET, m5, CSEC_M5_SIZE_IN_BYTES);
627  }
628 
629  g_csecStatePtr->cmdInProgress = false;
630 
631  return stat;
632 }
633 
634 /*FUNCTION**********************************************************************
635  *
636  * Function Name : CSEC_DRV_InitRNG
637  * Description : The function initializes the seed and derives a key for the
638  * PRNG. The function must be called before CMD_RND after every power cycle/reset.
639  *
640  * Implements : CSEC_DRV_InitRNG_Activity
641  * END**************************************************************************/
643 {
644  status_t stat;
645 
646  if (g_csecStatePtr->cmdInProgress)
647  {
648  return STATUS_BUSY;
649  }
650  g_csecStatePtr->cmdInProgress = true;
651 
652  /* Write the command header. This will trigger the command execution. */
653  CSEC_WriteCommandHeader(CSEC_CMD_INIT_RNG, CSEC_FUNC_FORMAT_COPY, CSEC_CALL_SEQ_FIRST, CSEC_SECRET_KEY);
654 
655  /* Wait until the execution of the command is complete */
656  CSEC_WaitCommandCompletion();
657 
658  /* Read the status of the execution */
659  stat = CSEC_ReadErrorBits();
660 
661  g_csecStatePtr->cmdInProgress = false;
662 
663  return stat;
664 }
665 
666 /*FUNCTION**********************************************************************
667  *
668  * Function Name : CSEC_DRV_ExtendSeed
669  * Description : Extends the seed of the PRNG by compressing the former seed
670  * value and the supplied entropy into a new seed. This new seed is then to be
671  * used to generate a random number by invoking the CMD_RND command. The random
672  * number generator must be initialized by CMD_INIT_RNG before the seed may be
673  * extended.
674  *
675  * Implements : CSEC_DRV_ExtendSeed_Activity
676  * END**************************************************************************/
677 status_t CSEC_DRV_ExtendSeed(const uint8_t * entropy)
678 {
679  status_t stat;
680 
681  DEV_ASSERT(entropy != NULL);
682 
683  if (g_csecStatePtr->cmdInProgress)
684  {
685  return STATUS_BUSY;
686  }
687  g_csecStatePtr->cmdInProgress = true;
688 
689  /* Write the entropy parameter */
690  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, entropy, CSEC_PAGE_SIZE_IN_BYTES);
691  /* Write the command header. This will trigger the command execution. */
692  CSEC_WriteCommandHeader(CSEC_CMD_EXTEND_SEED, CSEC_FUNC_FORMAT_COPY, CSEC_CALL_SEQ_FIRST, CSEC_SECRET_KEY);
693 
694  /* Wait until the execution of the command is complete */
695  CSEC_WaitCommandCompletion();
696 
697  /* Read the status of the execution */
698  stat = CSEC_ReadErrorBits();
699 
700  g_csecStatePtr->cmdInProgress = false;
701 
702  return stat;
703 }
704 
705 /*FUNCTION**********************************************************************
706  *
707  * Function Name : CSEC_DRV_GenerateRND
708  * Description : The function returns a vector of 128 random bits. The random
709  * number generator has to be initialized by calling CSEC_DRV_InitRNG before
710  * random numbers can be supplied.
711  *
712  * Implements : CSEC_DRV_GenerateRND_Activity
713  * END**************************************************************************/
715 {
716  status_t stat;
717 
718  DEV_ASSERT(rnd != NULL);
719 
720  if (g_csecStatePtr->cmdInProgress)
721  {
722  return STATUS_BUSY;
723  }
724  g_csecStatePtr->cmdInProgress = true;
725 
726  /* Write the command header. This will trigger the command execution. */
727  CSEC_WriteCommandHeader(CSEC_CMD_RND, CSEC_FUNC_FORMAT_COPY, CSEC_CALL_SEQ_FIRST, CSEC_SECRET_KEY);
728 
729  /* Wait until the execution of the command is complete */
730  CSEC_WaitCommandCompletion();
731 
732  /* Read the status of the execution */
733  stat = CSEC_ReadErrorBits();
734  /* Read the resulted random bytes */
735  if (stat == STATUS_SUCCESS)
736  {
737  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, rnd, CSEC_PAGE_SIZE_IN_BYTES);
738  }
739 
740  g_csecStatePtr->cmdInProgress = false;
741 
742  return stat;
743 }
744 
745 /*FUNCTION**********************************************************************
746  *
747  * Function Name : CSEC_DRV_BootFailure
748  * Description : The function is called during later stages of the boot
749  * process to detect a failure.
750  *
751  * Implements : CSEC_DRV_BootFailure_Activity
752  * END**************************************************************************/
754 {
755  status_t stat;
756 
757  if (g_csecStatePtr->cmdInProgress)
758  {
759  return STATUS_BUSY;
760  }
761  g_csecStatePtr->cmdInProgress = true;
762 
763  /* Write the command header. This will trigger the command execution. */
764  CSEC_WriteCommandHeader(CSEC_CMD_BOOT_FAILURE, CSEC_FUNC_FORMAT_COPY, CSEC_CALL_SEQ_FIRST, CSEC_SECRET_KEY);
765 
766  /* Wait until the execution of the command is complete */
767  CSEC_WaitCommandCompletion();
768 
769  /* Read the status of the execution */
770  stat = CSEC_ReadErrorBits();
771 
772  g_csecStatePtr->cmdInProgress = false;
773 
774  return stat;
775 }
776 
777 /*FUNCTION**********************************************************************
778  *
779  * Function Name : CSEC_DRV_BootOK
780  * Description : The function is called during later stages of the boot
781  * process to mark successful boot verification.
782  *
783  * Implements : CSEC_DRV_BootOK_Activity
784  * END**************************************************************************/
786 {
787  status_t stat;
788 
789  if (g_csecStatePtr->cmdInProgress)
790  {
791  return STATUS_BUSY;
792  }
793  g_csecStatePtr->cmdInProgress = true;
794 
795  /* Write the command header. This will trigger the command execution. */
796  CSEC_WriteCommandHeader(CSEC_CMD_BOOT_OK, CSEC_FUNC_FORMAT_COPY, CSEC_CALL_SEQ_FIRST, CSEC_SECRET_KEY);
797 
798  /* Wait until the execution of the command is complete */
799  CSEC_WaitCommandCompletion();
800 
801  /* Read the status of the execution */
802  stat = CSEC_ReadErrorBits();
803 
804  g_csecStatePtr->cmdInProgress = false;
805 
806  return stat;
807 }
808 
809 /*FUNCTION**********************************************************************
810  *
811  * Function Name : CSEC_DRV_BootDefine
812  * Description : The function implements an extension of the SHE standard to
813  * define both the user boot size and boot method.
814  *
815  * Implements : CSEC_DRV_BootDefine_Activity
816  * END**************************************************************************/
817 status_t CSEC_DRV_BootDefine(uint32_t bootSize,
818  csec_boot_flavor_t bootFlavor)
819 {
820  uint8_t flavor = (uint8_t)bootFlavor;
821  status_t stat;
822 
823  if (g_csecStatePtr->cmdInProgress)
824  {
825  return STATUS_BUSY;
826  }
827  g_csecStatePtr->cmdInProgress = true;
828 
829  /* Write the boot size and the boot flavor parameters */
830  CSEC_WriteCommandWords(FEATURE_CSEC_BOOT_SIZE_OFFSET, &bootSize, 1U);
831  CSEC_WriteCommandByte(FEATURE_CSEC_BOOT_FLAVOR_OFFSET, flavor);
832  /* Write the command header. This will trigger the command execution. */
833  CSEC_WriteCommandHeader(CSEC_CMD_BOOT_DEFINE, CSEC_FUNC_FORMAT_COPY, CSEC_CALL_SEQ_FIRST, CSEC_SECRET_KEY);
834 
835  /* Wait until the execution of the command is complete */
836  CSEC_WaitCommandCompletion();
837 
838  /* Read the status of the execution */
839  stat = CSEC_ReadErrorBits();
840 
841  g_csecStatePtr->cmdInProgress = false;
842 
843  return stat;
844 }
845 
846 /*FUNCTION**********************************************************************
847  *
848  * Function Name : CSEC_DRV_GetID
849  * Description : This function returns the identity (UID) and the value of the
850  * status register protected by a MAC over a challenge and the data.
851  *
852  * Implements : CSEC_DRV_GetID_Activity
853  * END**************************************************************************/
854 status_t CSEC_DRV_GetID(const uint8_t * challenge,
855  uint8_t * uid,
856  uint8_t * sreg,
857  uint8_t * mac)
858 {
859  status_t stat;
860 
861  DEV_ASSERT(challenge != NULL);
862  DEV_ASSERT(uid != NULL);
863  DEV_ASSERT(sreg != NULL);
864  DEV_ASSERT(mac != NULL);
865 
866  if (g_csecStatePtr->cmdInProgress)
867  {
868  return STATUS_BUSY;
869  }
870  g_csecStatePtr->cmdInProgress = true;
871 
872  /* Write the challenge */
873  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, challenge, CSEC_PAGE_SIZE_IN_BYTES);
874  /* Write the command header. This will trigger the command execution. */
875  CSEC_WriteCommandHeader(CSEC_CMD_GET_ID, CSEC_FUNC_FORMAT_COPY, CSEC_CALL_SEQ_FIRST, CSEC_SECRET_KEY);
876 
877  /* Wait until the execution of the command is complete */
878  CSEC_WaitCommandCompletion();
879 
880  /* Read the status of the execution */
881  stat = CSEC_ReadErrorBits();
882  if (stat == STATUS_SUCCESS)
883  {
884  /* Read the UID */
885  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_2_OFFSET, uid, (uint8_t)(CSEC_PAGE_SIZE_IN_BYTES - 1U));
886  /* Read the value of the SREG register */
887  *sreg = CSEC_ReadCommandByte(FEATURE_CSEC_SREG_OFFSET);
888  /* Read the MAC over the UID and the SREG */
889  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_3_OFFSET, mac, CSEC_PAGE_SIZE_IN_BYTES);
890  }
891 
892  g_csecStatePtr->cmdInProgress = false;
893 
894  return stat;
895 }
896 
897 /*FUNCTION**********************************************************************
898  *
899  * Function Name : CSEC_DRV_DbgChal
900  * Description : This function obtains a random number which the user shall
901  * use along with the MASTER_ECU_KEY and UID to return an authorization request.
902  *
903  * Implements : CSEC_DRV_DbgChal_Activity
904  * END**************************************************************************/
905 status_t CSEC_DRV_DbgChal(uint8_t * challenge)
906 {
907  status_t stat;
908 
909  DEV_ASSERT(challenge != NULL);
910 
911  if (g_csecStatePtr->cmdInProgress)
912  {
913  return STATUS_BUSY;
914  }
915  g_csecStatePtr->cmdInProgress = true;
916 
917  /* Write the command header. This will trigger the command execution. */
918  CSEC_WriteCommandHeader(CSEC_CMD_DBG_CHAL, CSEC_FUNC_FORMAT_COPY, CSEC_CALL_SEQ_FIRST, CSEC_SECRET_KEY);
919 
920  /* Wait until the execution of the command is complete */
921  CSEC_WaitCommandCompletion();
922 
923  /* Read the status of the execution */
924  stat = CSEC_ReadErrorBits();
925  /* Read the challenge generated by the CSEc module */
926  if (stat == STATUS_SUCCESS)
927  {
928  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, challenge, CSEC_PAGE_SIZE_IN_BYTES);
929  }
930 
931  g_csecStatePtr->cmdInProgress = false;
932 
933  return stat;
934 }
935 
936 /*FUNCTION**********************************************************************
937  *
938  * Function Name : CSEC_DRV_DbgAuth
939  * Description : This function erases all keys (actual and outdated) stored in
940  * NVM Memory if the authorization is confirmed by CSEc.
941  *
942  * Implements : CSEC_DRV_DbgAuth_Activity
943  * END**************************************************************************/
944 status_t CSEC_DRV_DbgAuth(const uint8_t * authorization)
945 {
946  status_t stat;
947 
948  DEV_ASSERT(authorization != NULL);
949 
950  if (g_csecStatePtr->cmdInProgress)
951  {
952  return STATUS_BUSY;
953  }
954  g_csecStatePtr->cmdInProgress = true;
955 
956  /* Write the authorization computed from the challenge */
957  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, authorization, CSEC_PAGE_SIZE_IN_BYTES);
958  /* Write the command header. This will trigger the command execution. */
959  CSEC_WriteCommandHeader(CSEC_CMD_DBG_AUTH, CSEC_FUNC_FORMAT_COPY, CSEC_CALL_SEQ_FIRST, CSEC_SECRET_KEY);
960 
961  /* Wait until the execution of the command is complete */
962  CSEC_WaitCommandCompletion();
963 
964  /* Read the status of the execution */
965  stat = CSEC_ReadErrorBits();
966 
967  g_csecStatePtr->cmdInProgress = false;
968 
969  return stat;
970 }
971 
972 /*FUNCTION**********************************************************************
973  *
974  * Function Name : CSEC_DRV_MPCompress
975  * Description : This function accesses a Miyaguchi-Prenell compression
976  * feature within the CSEc feature set to compress the given messages.
977  *
978  * Implements : CSEC_DRV_MPCompress_Activity
979  * END**************************************************************************/
980 status_t CSEC_DRV_MPCompress(const uint8_t * msg,
981  uint16_t msgLen,
982  uint8_t * mpCompress)
983 {
984  DEV_ASSERT(msg != NULL);
985  DEV_ASSERT(mpCompress != NULL);
986 
987  if (g_csecStatePtr->cmdInProgress)
988  {
989  return STATUS_BUSY;
990  }
991 
993  status_t stat = STATUS_SUCCESS;
994  uint32_t index = 0;
995  uint16_t numPagesLeft = msgLen;
996 
997  /* Loop and launch commands until the end of the message */
998  while (numPagesLeft > 0U)
999  {
1000  uint8_t numPages = (uint8_t)((msgLen > CSEC_DATA_PAGES_AVAILABLE) ?
1001  CSEC_DATA_PAGES_AVAILABLE : msgLen);
1002  uint8_t numBytes = (uint8_t)(numPages << CSEC_BYTES_TO_FROM_PAGES_SHIFT);
1003 
1004  /* Write the message */
1005  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, &msg[index], numBytes);
1006  /* Write the size of the message */
1007  CSEC_WriteCommandHalfWord(FEATURE_CSEC_PAGE_LENGTH_OFFSET, msgLen);
1008  /* Write the command header. This will trigger the command execution. */
1009  CSEC_WriteCommandHeader(CSEC_CMD_MP_COMPRESS, CSEC_FUNC_FORMAT_COPY, seq, CSEC_SECRET_KEY);
1010 
1011  /* Wait until the execution of the command is complete */
1012  CSEC_WaitCommandCompletion();
1013 
1014  /* Read the status of the execution */
1015  stat = CSEC_ReadErrorBits();
1016  if (stat != STATUS_SUCCESS)
1017  {
1018  break;
1019  }
1020 
1021  numPagesLeft = (uint16_t)(numPagesLeft - numPages);
1022  index = (uint32_t)(index + numBytes);
1023  if (seq == CSEC_CALL_SEQ_FIRST)
1024  {
1026  }
1027  }
1028 
1029  /* Read the result of the compression */
1030  if (stat == STATUS_SUCCESS)
1031  {
1032  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, mpCompress, CSEC_PAGE_SIZE_IN_BYTES);
1033  }
1034 
1035  return stat;
1036 }
1037 
1038 /*FUNCTION**********************************************************************
1039  *
1040  * Function Name : CSEC_DRV_EncryptECBAsync
1041  * Description : This function starts the AES-128 encryption in ECB mode of
1042  * the input plain text buffer, in an asynchronous manner.
1043  *
1044  * Implements : CSEC_DRV_EncryptECBAsync_Activity
1045  * END**************************************************************************/
1047  const uint8_t * plainText,
1048  uint32_t length,
1049  uint8_t * cipherText)
1050 {
1051  if (g_csecStatePtr->cmdInProgress)
1052  {
1053  return STATUS_BUSY;
1054  }
1055 
1056  CSEC_DRV_InitState(keyId, CSEC_CMD_ENC_ECB, plainText, cipherText, length);
1057 
1059 
1060  /* Enable interrupt */
1061  CSEC_SetInterrupt(true);
1062 
1063  return STATUS_SUCCESS;
1064 }
1065 
1066 /*FUNCTION**********************************************************************
1067  *
1068  * Function Name : CSEC_DRV_DecryptECBAsync
1069  * Description : This function starts the AES-128 decryption in ECB mode of
1070  * the input cipher text buffer, in an asynchronous manner.
1071  *
1072  * Implements : CSEC_DRV_DecryptECBAsync_Activity
1073  * END**************************************************************************/
1075  const uint8_t * cipherText,
1076  uint32_t length,
1077  uint8_t * plainText)
1078 {
1079  if (g_csecStatePtr->cmdInProgress)
1080  {
1081  return STATUS_BUSY;
1082  }
1083 
1084  CSEC_DRV_InitState(keyId, CSEC_CMD_DEC_ECB, cipherText, plainText, length);
1085 
1087 
1088  /* Enable interrupt */
1089  CSEC_SetInterrupt(true);
1090 
1091  return STATUS_SUCCESS;
1092 }
1093 
1094 /*FUNCTION**********************************************************************
1095  *
1096  * Function Name : CSEC_DRV_EncryptCBCAsync
1097  * Description : This function starts the AES-128 encryption in CBC mode of
1098  * the input cipher text buffer, in an asynchronous manner.
1099  *
1100  * Implements : CSEC_DRV_EncryptCBCAsync_Activity
1101  * END**************************************************************************/
1103  const uint8_t * cipherText,
1104  uint16_t length,
1105  const uint8_t * iv,
1106  uint8_t * plainText)
1107 {
1108  if (g_csecStatePtr->cmdInProgress)
1109  {
1110  return STATUS_BUSY;
1111  }
1112 
1113  CSEC_DRV_InitState(keyId, CSEC_CMD_ENC_CBC, cipherText, plainText, length);
1114  g_csecStatePtr->iv = iv;
1115 
1117 
1118  /* Enable interrupt */
1119  CSEC_SetInterrupt(true);
1120 
1121  return STATUS_SUCCESS;
1122 }
1123 
1124 /*FUNCTION**********************************************************************
1125  *
1126  * Function Name : CSEC_DRV_DecryptCBCAsync
1127  * Description : This function starts the AES-128 decryption in CBC mode of
1128  * the input cipher text buffer, in an asynchronous manner.
1129  *
1130  * Implements : CSEC_DRV_DecryptCBCAsync_Activity
1131  * END**************************************************************************/
1133  const uint8_t * cipherText,
1134  uint32_t length,
1135  const uint8_t * iv,
1136  uint8_t * plainText)
1137 {
1138  if (g_csecStatePtr->cmdInProgress)
1139  {
1140  return STATUS_BUSY;
1141  }
1142 
1143  CSEC_DRV_InitState(keyId, CSEC_CMD_DEC_CBC, cipherText, plainText, length);
1144  g_csecStatePtr->iv = iv;
1145 
1147 
1148  /* Enable interrupt */
1149  CSEC_SetInterrupt(true);
1150 
1151  return STATUS_SUCCESS;
1152 }
1153 
1154 /*FUNCTION**********************************************************************
1155  *
1156  * Function Name : CSEC_DRV_GenerateMACAsync
1157  * Description : This function starts the computation the MAC of a given
1158  * message using CMAC with AES-128, in an asynchronous manner.
1159  *
1160  * Implements : CSEC_DRV_GenerateMACAsync_Activity
1161  * END**************************************************************************/
1163  const uint8_t * msg,
1164  uint32_t msgLen,
1165  uint8_t * cmac)
1166 {
1167  if (g_csecStatePtr->cmdInProgress)
1168  {
1169  return STATUS_BUSY;
1170  }
1171 
1173  g_csecStatePtr->msgLen = msgLen;
1174 
1176 
1177  /* Enable interrupt */
1178  CSEC_SetInterrupt(true);
1179 
1180  return STATUS_SUCCESS;
1181 }
1182 
1183 /*FUNCTION**********************************************************************
1184  *
1185  * Function Name : CSEC_DRV_VerifyMACAsync
1186  * Description : This function starts the verification the MAC of a given
1187  * message using CMAC with AES-128, in an asynchronous manner.
1188  *
1189  * Implements : CSEC_DRV_VerifyMACAsync_Activity
1190  * END**************************************************************************/
1192  const uint8_t * msg,
1193  uint32_t msgLen,
1194  const uint8_t * mac,
1195  uint16_t macLen,
1196  bool * verifStatus)
1197 {
1198  if (g_csecStatePtr->cmdInProgress)
1199  {
1200  return STATUS_BUSY;
1201  }
1202 
1204  g_csecStatePtr->msgLen = msgLen;
1205  g_csecStatePtr->verifStatus = verifStatus;
1206  g_csecStatePtr->macWritten = false;
1207  g_csecStatePtr->mac = mac;
1208  g_csecStatePtr->macLen = macLen;
1209 
1211 
1212  /* Enable interrupt */
1213  CSEC_SetInterrupt(true);
1214 
1215  return STATUS_SUCCESS;
1216 }
1217 
1218 /*FUNCTION**********************************************************************
1219  *
1220  * Function Name : CSEC_DRV_GetAsyncCmdStatus
1221  * Description : This function checks the status of the execution of an
1222  * asynchronous command. If the command is still in progress, returns STATUS_BUSY.
1223  *
1224  * Implements : CSEC_DRV_GetAsyncCmdStatus_Activity
1225  * END**************************************************************************/
1227 {
1228  if (!g_csecStatePtr->cmdInProgress)
1229  {
1230  return g_csecStatePtr->errCode;
1231  }
1232 
1233  return STATUS_BUSY;
1234 }
1235 
1236 /*FUNCTION**********************************************************************
1237  *
1238  * Function Name : CSEC_DRV_InitState
1239  * Description : Initializes the internal state of the driver with a given
1240  * input buffer, output buffer, key, length, command, and marks the command as
1241  * in progress.
1242  *
1243  * END**************************************************************************/
1245  csec_cmd_t cmd,
1246  const uint8_t * inBuff,
1247  uint8_t * outBuff,
1248  uint32_t length)
1249 {
1250  g_csecStatePtr->cmdInProgress = true;
1251  g_csecStatePtr->cmd = cmd;
1252  g_csecStatePtr->inputBuff = inBuff;
1253  g_csecStatePtr->outputBuff = outBuff;
1254  g_csecStatePtr->keyId = keyId;
1255  g_csecStatePtr->fullSize = length;
1256  g_csecStatePtr->index = 0U;
1257  g_csecStatePtr->errCode = STATUS_SUCCESS;
1258  g_csecStatePtr->seq = CSEC_CALL_SEQ_FIRST;
1259 }
1260 
1261 /*FUNCTION**********************************************************************
1262  *
1263  * Function Name : FTFC_IRQHandler
1264  * Description : Implementation of the FTFC interrupt handler. Handles completed
1265  * commands lauched by using the asynchronous CSEc driver API which were
1266  *
1267  * END**************************************************************************/
1269 {
1270  uint8_t fstat = (uint8_t)(FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK);
1271 
1272  /* Previous command execution ended, continue execution */
1273  if ((fstat != 0U) && g_csecStatePtr->cmdInProgress)
1274  {
1275  if ((g_csecStatePtr->cmd == CSEC_CMD_ENC_ECB) || (g_csecStatePtr->cmd == CSEC_CMD_DEC_ECB))
1276  {
1278  }
1279  else if ((g_csecStatePtr->cmd == CSEC_CMD_ENC_CBC) || (g_csecStatePtr->cmd == CSEC_CMD_DEC_CBC))
1280  {
1282  }
1283  else if (g_csecStatePtr->cmd == CSEC_CMD_GENERATE_MAC)
1284  {
1286  }
1287  else if (g_csecStatePtr->cmd == CSEC_CMD_VERIFY_MAC)
1288  {
1290  }
1291  else
1292  {
1293  /* Do nothing, all the asynchronous operations were checked above */
1294  }
1295 
1296  /* If finished processing, disable interrupt */
1297  if (!g_csecStatePtr->cmdInProgress)
1298  {
1299  CSEC_SetInterrupt(false);
1300 
1301  if (g_csecStatePtr->callback != NULL)
1302  {
1303  g_csecStatePtr->callback(g_csecStatePtr->cmd, g_csecStatePtr->callbackParam);
1304  }
1305  }
1306  }
1307 }
1308 
1309 /*FUNCTION**********************************************************************
1310  *
1311  * Function Name : CSEC_DRV_StartEncDecECBCmd
1312  * Description : Initializes the CSE_PRAM and the internal state for
1313  * encryption/decryption using ECB mode commands.
1314  *
1315  * END**************************************************************************/
1317 {
1318  uint32_t numPagesLeft = (g_csecStatePtr->fullSize - g_csecStatePtr->index) >> CSEC_BYTES_TO_FROM_PAGES_SHIFT;
1319  uint16_t numPages = (uint16_t)((numPagesLeft > CSEC_DATA_PAGES_AVAILABLE) ? CSEC_DATA_PAGES_AVAILABLE : numPagesLeft);
1320  uint8_t numBytes = (uint8_t)(numPages << CSEC_BYTES_TO_FROM_PAGES_SHIFT);
1321 
1322  /* Write the plain/cipher text */
1323  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, &g_csecStatePtr->inputBuff[g_csecStatePtr->index], numBytes);
1324  /* Write the size of the plain/cipher text (in pages) */
1325  CSEC_WriteCommandHalfWord(FEATURE_CSEC_PAGE_LENGTH_OFFSET, numPages);
1326 
1327  g_csecStatePtr->partSize = numBytes;
1328 
1329  /* Write the command header. This will trigger the command execution. */
1330  CSEC_WriteCommandHeader(g_csecStatePtr->cmd, CSEC_FUNC_FORMAT_COPY, g_csecStatePtr->seq, g_csecStatePtr->keyId);
1331 }
1332 
1333 /*FUNCTION**********************************************************************
1334  *
1335  * Function Name : CSEC_DRV_StartEncDecCBCCmd
1336  * Description : Initializes the CSE_PRAM and the internal state for
1337  * encryption/decryption using CBC mode commands.
1338  *
1339  * END**************************************************************************/
1341 {
1342  uint32_t numPagesLeft = (g_csecStatePtr->fullSize - g_csecStatePtr->index) >> CSEC_BYTES_TO_FROM_PAGES_SHIFT;
1343  uint16_t numPages = (uint16_t)((numPagesLeft > CSEC_DATA_PAGES_AVAILABLE) ? CSEC_DATA_PAGES_AVAILABLE : numPagesLeft);
1344  uint8_t numBytes = (uint8_t)(numPages << CSEC_BYTES_TO_FROM_PAGES_SHIFT);
1345 
1346  if (g_csecStatePtr->seq == CSEC_CALL_SEQ_FIRST)
1347  {
1348  numPages = (uint16_t)((numPagesLeft > (CSEC_DATA_PAGES_AVAILABLE - 1U)) ? (CSEC_DATA_PAGES_AVAILABLE - 1U) : numPagesLeft);
1349  numBytes = (uint8_t)(numPages << CSEC_BYTES_TO_FROM_PAGES_SHIFT);
1350 
1351  /* Write the initialization vector */
1352  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, g_csecStatePtr->iv, CSEC_PAGE_SIZE_IN_BYTES);
1353  /* Write the plain/cipher text */
1354  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_2_OFFSET, &g_csecStatePtr->inputBuff[g_csecStatePtr->index], numBytes);
1355  }
1356  else
1357  {
1358  /* Write the plain/cipher text */
1359  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, &g_csecStatePtr->inputBuff[g_csecStatePtr->index], numBytes);
1360  }
1361 
1362  /* Write the size of the plain/cipher text (in pages) */
1363  CSEC_WriteCommandHalfWord(FEATURE_CSEC_PAGE_LENGTH_OFFSET, (uint16_t)(g_csecStatePtr->fullSize >> CSEC_BYTES_TO_FROM_PAGES_SHIFT));
1364 
1365  g_csecStatePtr->partSize = numBytes;
1366 
1367  /* Write the command header. This will trigger the command execution. */
1368  CSEC_WriteCommandHeader(g_csecStatePtr->cmd, CSEC_FUNC_FORMAT_COPY, g_csecStatePtr->seq, g_csecStatePtr->keyId);
1369 }
1370 
1371 /*FUNCTION**********************************************************************
1372  *
1373  * Function Name : CSEC_DRV_StartGenMACCmd
1374  * Description : Initializes the CSE_PRAM and the internal state for the
1375  * CMAC generation command.
1376  *
1377  * END**************************************************************************/
1379 {
1380  uint8_t numBytes = (uint8_t)(((g_csecStatePtr->fullSize - g_csecStatePtr->index) >
1381  CSEC_DATA_BYTES_AVAILABLE) ? CSEC_DATA_BYTES_AVAILABLE : (g_csecStatePtr->fullSize - g_csecStatePtr->index));
1382 
1383  /* Write the plain/cipher text */
1384  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, &g_csecStatePtr->inputBuff[g_csecStatePtr->index], numBytes);
1385  /* Write the size of the message (in bits) */
1386  CSEC_WriteCommandWords(FEATURE_CSEC_MESSAGE_LENGTH_OFFSET, &g_csecStatePtr->msgLen, 1U);
1387 
1388  g_csecStatePtr->partSize = numBytes;
1389 
1390  /* Write the command header. This will trigger the command execution. */
1391  CSEC_WriteCommandHeader(g_csecStatePtr->cmd, CSEC_FUNC_FORMAT_COPY, g_csecStatePtr->seq, g_csecStatePtr->keyId);
1392 }
1393 
1394 /*FUNCTION**********************************************************************
1395  *
1396  * Function Name : CSEC_DRV_StartVerifMACCmd
1397  * Description : Initializes the CSE_PRAM and the internal state for the
1398  * CMAC verification command.
1399  *
1400  * END**************************************************************************/
1402 {
1403  uint8_t numBytes = (uint8_t)(((g_csecStatePtr->fullSize - g_csecStatePtr->index) >
1404  CSEC_DATA_BYTES_AVAILABLE) ? CSEC_DATA_BYTES_AVAILABLE : (g_csecStatePtr->fullSize - g_csecStatePtr->index));
1405  uint8_t macOffset = (uint8_t)CSEC_DRV_RoundTo(numBytes, 0x10);
1406 
1407  /* Write the plain/cipher text */
1408  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, &g_csecStatePtr->inputBuff[g_csecStatePtr->index], numBytes);
1409  /* Write the size of the message (in bits) */
1410  CSEC_WriteCommandWords(FEATURE_CSEC_MESSAGE_LENGTH_OFFSET, &g_csecStatePtr->msgLen, 1U);
1411 
1412  /* Write the number of bits of the MAC to be compared */
1413  CSEC_WriteCommandHalfWord(FEATURE_CSEC_MAC_LENGTH_OFFSET, (uint16_t)g_csecStatePtr->macLen);
1414 
1415  /* If there is available space in CSE_PRAM, write the MAC to be verified */
1417  {
1418  CSEC_WriteCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET + macOffset, g_csecStatePtr->mac, CSEC_PAGE_SIZE_IN_BYTES);
1419  g_csecStatePtr->macWritten = true;
1420  }
1421 
1422  g_csecStatePtr->partSize = numBytes;
1423 
1424  /* Write the command header. This will trigger the command execution. */
1425  CSEC_WriteCommandHeader(g_csecStatePtr->cmd, CSEC_FUNC_FORMAT_COPY, g_csecStatePtr->seq, g_csecStatePtr->keyId);
1426 }
1427 
1428 /*FUNCTION**********************************************************************
1429  *
1430  * Function Name : CSEC_DRV_ContinueEncDecECBCmd
1431  * Description : Continues the execution of encryption/decryption using ECB
1432  * mode. Reads the partial result, updates the internal state and launches
1433  * another command, if necessary.
1434  *
1435  * END**************************************************************************/
1437 {
1438  /* Read the status of the execution */
1439  g_csecStatePtr->errCode = CSEC_ReadErrorBits();
1440  if (g_csecStatePtr->errCode != STATUS_SUCCESS)
1441  {
1442  /* Do not continue launching commands if an error occurred */
1443  g_csecStatePtr->cmdInProgress = false;
1444  return;
1445  }
1446 
1447  /* Get partial result */
1448  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, &g_csecStatePtr->outputBuff[g_csecStatePtr->index], (uint8_t)g_csecStatePtr->partSize);
1449 
1450  g_csecStatePtr->index += (uint8_t)g_csecStatePtr->partSize;
1451 
1452  /* Decide if more commands are needed */
1453  if (g_csecStatePtr->index >= g_csecStatePtr->fullSize)
1454  {
1455  g_csecStatePtr->cmdInProgress = false;
1456  }
1457  else
1458  {
1459  /* Continue launching commands */
1461  }
1462 }
1463 
1464 /*FUNCTION**********************************************************************
1465  *
1466  * Function Name : CSEC_DRV_ContinueEncDecCBCCmd
1467  * Description : Continues the execution of encryption/decryption using CBC
1468  * mode. Reads the partial result, updates the internal state and launches
1469  * another command, if necessary.
1470  *
1471  * END**************************************************************************/
1473 {
1474  /* Read the status of the execution */
1475  g_csecStatePtr->errCode = CSEC_ReadErrorBits();
1476  if (g_csecStatePtr->errCode != STATUS_SUCCESS)
1477  {
1478  /* Do not continue launching commands if an error occurred */
1479  g_csecStatePtr->cmdInProgress = false;
1480  return;
1481  }
1482 
1483  /* Get partial result */
1484  if (g_csecStatePtr->seq == CSEC_CALL_SEQ_FIRST)
1485  {
1486  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_2_OFFSET, &g_csecStatePtr->outputBuff[g_csecStatePtr->index],
1487  (uint8_t)g_csecStatePtr->partSize);
1488  g_csecStatePtr->seq = CSEC_CALL_SEQ_SUBSEQUENT;
1489  }
1490  else
1491  {
1492  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_1_OFFSET, &g_csecStatePtr->outputBuff[g_csecStatePtr->index],
1493  (uint8_t)g_csecStatePtr->partSize);
1494  }
1495 
1496  g_csecStatePtr->index += (uint8_t)g_csecStatePtr->partSize;
1497 
1498  if (g_csecStatePtr->index >= g_csecStatePtr->fullSize)
1499  {
1500  g_csecStatePtr->cmdInProgress = false;
1501  }
1502  else
1503  {
1504  /* Continue launching commands */
1506  }
1507 }
1508 
1509 
1510 /*FUNCTION**********************************************************************
1511  *
1512  * Function Name : CSEC_DRV_ContinueGenMACCmd
1513  * Description : Continues the execution of CMAC generation. Reads the status
1514  * of the execution, updates the internal state and launches another command,
1515  * if necessary. If there is no need to launch another command, reads the
1516  * resulted CMAC.
1517  *
1518  * END**************************************************************************/
1520 {
1521  /* Read the status of the execution */
1522  g_csecStatePtr->errCode = CSEC_ReadErrorBits();
1523  if (g_csecStatePtr->errCode != STATUS_SUCCESS)
1524  {
1525  /* Do not continue launching commands if an error occurred */
1526  g_csecStatePtr->cmdInProgress = false;
1527  return;
1528  }
1529 
1530  if (g_csecStatePtr->seq == CSEC_CALL_SEQ_FIRST)
1531  {
1532  g_csecStatePtr->seq = CSEC_CALL_SEQ_SUBSEQUENT;
1533  }
1534 
1535  g_csecStatePtr->index += (uint8_t)g_csecStatePtr->partSize;
1536 
1537  /* Decide if more commands are needed */
1538  if (g_csecStatePtr->index >= g_csecStatePtr->fullSize)
1539  {
1540  g_csecStatePtr->cmdInProgress = false;
1541  CSEC_ReadCommandBytes(FEATURE_CSEC_PAGE_2_OFFSET, g_csecStatePtr->outputBuff, CSEC_PAGE_SIZE_IN_BYTES);
1542  }
1543  else
1544  {
1545  /* Continue launching commands */
1547  }
1548 }
1549 
1550 /*FUNCTION**********************************************************************
1551  *
1552  * Function Name : CSEC_DRV_ContinueVerifMACCmd
1553  * Description : Continues the execution of CMAC verification. Reads the status
1554  * of the execution, updates the internal state and launches another command,
1555  * if necessary. If there is no need to launch another command, reads the
1556  * verification status.
1557  *
1558  * END**************************************************************************/
1560 {
1561  /* Read the status of the execution */
1562  g_csecStatePtr->errCode = CSEC_ReadErrorBits();
1563  if (g_csecStatePtr->errCode != STATUS_SUCCESS)
1564  {
1565  /* Do not continue launching commands if an error occurred */
1566  g_csecStatePtr->cmdInProgress = false;
1567  return;
1568  }
1569 
1570  if (g_csecStatePtr->seq == CSEC_CALL_SEQ_FIRST)
1571  {
1572  g_csecStatePtr->seq = CSEC_CALL_SEQ_SUBSEQUENT;
1573  }
1574 
1575  g_csecStatePtr->index += (uint8_t)g_csecStatePtr->partSize;
1576 
1577  /* Decide if more commands are needed */
1578  g_csecStatePtr->cmdInProgress = !g_csecStatePtr->macWritten;
1579 
1580  if (!g_csecStatePtr->cmdInProgress)
1581  {
1582  *(g_csecStatePtr->verifStatus) = (CSEC_ReadCommandHalfWord(FEATURE_CSEC_VERIFICATION_STATUS_OFFSET) == 0U);
1583  }
1584  else
1585  {
1586  /* Continue launching commands */
1588  }
1589 }
1590 
1591 /*FUNCTION**********************************************************************
1592  *
1593  * Function Name : CSEC_DRV_InstallCallback
1594  * Description : Installs a callback function which will be invoked when an
1595  * asynchronous command finishes its execution.
1596  *
1597  * Implements : CSEC_DRV_InstallCallback_Activity
1598  * END**************************************************************************/
1599 void CSEC_DRV_InstallCallback(csec_callback_t callbackFunc, void *callbackParam)
1600 {
1601  g_csecStatePtr->callback = callbackFunc;
1602  g_csecStatePtr->callbackParam = callbackParam;
1603 }
1604 
1605 /******************************************************************************
1606  * EOF
1607  *****************************************************************************/
status_t CSEC_DRV_LoadPlainKey(const uint8_t *plainKey)
Updates the RAM key memory slot with a 128-bit plaintext.
Definition: csec_driver.c:555
status_t CSEC_DRV_GetAsyncCmdStatus()
Checks the status of the execution of an asynchronous command.
Definition: csec_driver.c:1226
bool cmdInProgress
Definition: csec_driver.h:197
#define CSEC_DATA_PAGES_AVAILABLE
Definition: csec_driver.c:68
static void CSEC_DRV_ContinueEncDecECBCmd(void)
Definition: csec_driver.c:1436
#define FEATURE_CSEC_BOOT_FLAVOR_OFFSET
CSE_PRAM offset of the boot flavor parameter used by the following commands: CMD_BOOT_DEFINE.
static void CSEC_DRV_ContinueEncDecCBCCmd(void)
Definition: csec_driver.c:1472
#define CSEC_M3_SIZE_IN_BYTES
Definition: csec_driver.c:83
status_t CSEC_DRV_GetID(const uint8_t *challenge, uint8_t *uid, uint8_t *sreg, uint8_t *mac)
Returns the identity (UID) and the value of the status register protected by a MAC over a challenge a...
Definition: csec_driver.c:854
#define FEATURE_CSEC_PAGE_2_OFFSET
CSE_PRAM offset of page 2.
Internal driver state information.
Definition: csec_driver.h:196
static void CSEC_DRV_StartEncDecECBCmd(void)
Definition: csec_driver.c:1316
#define FTFC_FSTAT_CCIF_MASK
Definition: S32K142.h:3753
#define CSEC_BYTES_TO_FROM_PAGES_SHIFT
Definition: csec_driver.c:74
#define FEATURE_CSEC_FLASH_START_ADDRESS_OFFSET
CSE_PRAM offset of the Flash start address parameter used by the following commands: CMD_GENERATE_MAC...
void CSEC_DRV_Init(csec_state_t *state)
Initializes the internal state of the driver and enables the FTFC interrupt.
Definition: csec_driver.c:133
status_t CSEC_DRV_DbgAuth(const uint8_t *authorization)
Erases all keys (actual and outdated) stored in NVM Memory if the authorization is confirmed by CSEc...
Definition: csec_driver.c:944
status_t CSEC_DRV_VerifyMACAsync(csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, const uint8_t *mac, uint16_t macLen, bool *verifStatus)
Asynchronously verifies the MAC of a given message using CMAC with AES-128.
Definition: csec_driver.c:1191
#define CSEC_M1_SIZE_IN_BYTES
Definition: csec_driver.c:79
csec_key_id_t
Specify the KeyID to be used to implement the requested cryptographic operation.
Definition: csec_driver.h:99
csec_key_id_t keyId
Definition: csec_driver.h:204
status_t CSEC_DRV_BootOK()
Marks a successful boot verification during later stages of the boot process.
Definition: csec_driver.c:785
status_t CSEC_DRV_MPCompress(const uint8_t *msg, uint16_t msgLen, uint8_t *mpCompress)
Compresses the given messages by accessing the Miyaguchi-Prenell compression feature with in the CSEc...
Definition: csec_driver.c:980
#define CSEC_BYTES_TO_FROM_BITS_SHIFT
Definition: csec_driver.c:76
status_t CSEC_DRV_VerifyMACAddrMode(csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, const uint8_t *mac, uint16_t macLen, bool *verifStatus)
Verifies the MAC of a given message (located in Flash) using CMAC with AES-128.
Definition: csec_driver.c:450
status_t CSEC_DRV_InitRNG()
Initializes the seed and derives a key for the PRNG.
Definition: csec_driver.c:642
const uint8_t * iv
Definition: csec_driver.h:206
static void CSEC_DRV_StartVerifMACCmd(void)
Definition: csec_driver.c:1401
void INT_SYS_DisableIRQ(IRQn_Type irqNumber)
Disables an interrupt for a given IRQ number.
#define CSEC_M2_SIZE_IN_BYTES
Definition: csec_driver.c:81
#define CSEC_DATA_BYTES_AVAILABLE
Definition: csec_driver.c:71
status_t CSEC_DRV_ExtendSeed(const uint8_t *entropy)
Extends the seed of the PRNG.
Definition: csec_driver.c:677
static void CSEC_DRV_StartEncDecCBCCmd(void)
Definition: csec_driver.c:1340
#define DEV_ASSERT(x)
Definition: devassert.h:77
status_t CSEC_DRV_BootFailure()
Signals a failure detected during later stages of the boot process.
Definition: csec_driver.c:753
status_t CSEC_DRV_DecryptECBAsync(csec_key_id_t keyId, const uint8_t *cipherText, uint32_t length, uint8_t *plainText)
Asynchronously performs the AES-128 decryption in ECB mode.
Definition: csec_driver.c:1074
static void CSEC_DRV_InitState(csec_key_id_t keyId, csec_cmd_t cmd, const uint8_t *inBuff, uint8_t *outBuff, uint32_t length)
Definition: csec_driver.c:1244
#define FEATURE_CSEC_VERIFICATION_STATUS_OFFSET
CSE_PRAM offset of the verification status parameter used by the following commands: CMD_VERIFY_MAC (...
#define FEATURE_CSEC_PAGE_3_OFFSET
CSE_PRAM offset of page 3.
csec_callback_t callback
Definition: csec_driver.h:213
bool * verifStatus
Definition: csec_driver.h:209
csec_cmd_t cmd
Definition: csec_driver.h:198
status_t CSEC_DRV_EncryptECBAsync(csec_key_id_t keyId, const uint8_t *plainText, uint32_t length, uint8_t *cipherText)
Asynchronously performs the AES-128 encryption in ECB mode.
Definition: csec_driver.c:1046
uint32_t partSize
Definition: csec_driver.h:203
uint32_t msgLen
Definition: csec_driver.h:208
#define CSEC_PAGE_SIZE_IN_BYTES
Definition: csec_driver.c:64
void CSEC_DRV_InstallCallback(csec_callback_t callbackFunc, void *callbackParam)
Installs a callback function which will be invoked when an asynchronous command finishes its executio...
Definition: csec_driver.c:1599
uint8_t * outputBuff
Definition: csec_driver.h:200
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
status_t CSEC_DRV_DecryptCBC(csec_key_id_t keyId, const uint8_t *cipherText, uint16_t length, const uint8_t *iv, uint8_t *plainText)
Performs the AES-128 decryption in CBC mode.
Definition: csec_driver.c:279
status_t CSEC_DRV_DecryptECB(csec_key_id_t keyId, const uint8_t *cipherText, uint32_t length, uint8_t *plainText)
Performs the AES-128 decryption in ECB mode.
Definition: csec_driver.c:203
#define FEATURE_CSEC_PAGE_5_OFFSET
CSE_PRAM offset of page 5.
status_t CSEC_DRV_EncryptCBC(csec_key_id_t keyId, const uint8_t *plainText, uint32_t length, const uint8_t *iv, uint8_t *cipherText)
Performs the AES-128 encryption in CBC mode.
Definition: csec_driver.c:239
#define FTFC
Definition: S32K142.h:3712
status_t CSEC_DRV_GenerateMACAddrMode(csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, uint8_t *cmac)
Calculates the MAC of a given message (located in Flash) using CMAC with AES-128. ...
Definition: csec_driver.c:359
static void CSEC_DRV_ContinueVerifMACCmd(void)
Definition: csec_driver.c:1559
void FTFC_IRQHandler(void)
Definition: csec_driver.c:1268
static void CSEC_DRV_ContinueGenMACCmd(void)
Definition: csec_driver.c:1519
void CSEC_DRV_Deinit()
Clears the internal state of the driver and disables the FTFC interrupt.
Definition: csec_driver.c:151
#define FEATURE_CSEC_PAGE_LENGTH_OFFSET
CSE_PRAM offset of the page length parameter used by the following commands: CMD_ENC_ECB, CMD_ENC_CBC, CMD_DEC_ECB, CMD_DEC_CBC, CMD_MP_COMPRESS.
status_t errCode
Definition: csec_driver.h:205
status_t CSEC_DRV_LoadKey(csec_key_id_t keyId, const uint8_t *m1, const uint8_t *m2, const uint8_t *m3, uint8_t *m4, uint8_t *m5)
Updates an internal key per the SHE specification.
Definition: csec_driver.c:502
uint32_t macLen
Definition: csec_driver.h:212
status_t CSEC_DRV_EncryptECB(csec_key_id_t keyId, const uint8_t *plainText, uint32_t length, uint8_t *cipherText)
Performs the AES-128 encryption in ECB mode.
Definition: csec_driver.c:166
#define FEATURE_CSEC_BOOT_SIZE_OFFSET
CSE_PRAM offset of the boot size parameter used by the following commands: CMD_BOOT_DEFINE.
uint32_t index
Definition: csec_driver.h:201
#define FEATURE_CSEC_PAGE_7_OFFSET
CSE_PRAM offset of page 7.
csec_boot_flavor_t
Specifies the boot type for the BOOT_DEFINE command.
Definition: csec_driver.h:173
const uint8_t * mac
Definition: csec_driver.h:211
status_t CSEC_DRV_DecryptCBCAsync(csec_key_id_t keyId, const uint8_t *cipherText, uint32_t length, const uint8_t *iv, uint8_t *plainText)
Asynchronously performs the AES-128 decryption in CBC mode.
Definition: csec_driver.c:1132
csec_call_sequence_t
Specifies if the information is the first or a following function call.
Definition: csec_driver.h:163
void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
Enables an interrupt for a given IRQ number.
csec_cmd_t
CSEc commands which follow the same values as the SHE command definition.
Definition: csec_driver.h:133
#define FEATURE_CSEC_PAGE_1_OFFSET
CSE_PRAM offset of page 1.
csec_call_sequence_t seq
Definition: csec_driver.h:207
#define FEATURE_CSEC_PAGE_4_OFFSET
CSE_PRAM offset of page 4.
status_t CSEC_DRV_ExportRAMKey(uint8_t *m1, uint8_t *m2, uint8_t *m3, uint8_t *m4, uint8_t *m5)
Exports the RAM_KEY into a format protected by SECRET_KEY.
Definition: csec_driver.c:591
status_t CSEC_DRV_GenerateRND(uint8_t *rnd)
Generates a vector of 128 random bits.
Definition: csec_driver.c:714
status_t CSEC_DRV_EncryptCBCAsync(csec_key_id_t keyId, const uint8_t *cipherText, uint16_t length, const uint8_t *iv, uint8_t *plainText)
Asynchronously performs the AES-128 encryption in CBC mode.
Definition: csec_driver.c:1102
#define CSEC_M4_SIZE_IN_BYTES
Definition: csec_driver.c:85
uint32_t fullSize
Definition: csec_driver.h:202
static uint32_t CSEC_DRV_RoundTo(uint32_t value, uint32_t roundTo)
Definition: csec_driver.c:106
const uint8_t * inputBuff
Definition: csec_driver.h:199
status_t CSEC_DRV_DbgChal(uint8_t *challenge)
Obtains a random number which the user shall use along with the MASTER_ECU_KEY and UID to return an a...
Definition: csec_driver.c:905
void(* csec_callback_t)(csec_cmd_t completedCmd, void *callbackParam)
CSEc asynchronous command complete callback function type.
Definition: csec_driver.h:185
#define FEATURE_CSEC_MESSAGE_LENGTH_OFFSET
CSE_PRAM offset of the message length parameter used by the following commands: CMD_GENERATE_MAC, CMD_VERIFY_MAC (both copy and pointer methods)
void * callbackParam
Definition: csec_driver.h:214
#define FEATURE_CSEC_MAC_LENGTH_OFFSET
CSE_PRAM offset of the MAC length parameter used by the following commands: CMD_VERIFY_MAC (both copy...
static csec_state_t * g_csecStatePtr
Definition: csec_driver.c:90
static void CSEC_DRV_StartGenMACCmd(void)
Definition: csec_driver.c:1378
status_t CSEC_DRV_GenerateMAC(csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, uint8_t *cmac)
Calculates the MAC of a given message using CMAC with AES-128.
Definition: csec_driver.c:319
status_t CSEC_DRV_VerifyMAC(csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, const uint8_t *mac, uint16_t macLen, bool *verifStatus)
Verifies the MAC of a given message using CMAC with AES-128.
Definition: csec_driver.c:403
#define CSEC_M5_SIZE_IN_BYTES
Definition: csec_driver.c:87
status_t CSEC_DRV_BootDefine(uint32_t bootSize, csec_boot_flavor_t bootFlavor)
Implements an extension of the SHE standard to define both the user boot size and boot method...
Definition: csec_driver.c:817
#define FEATURE_CSEC_SREG_OFFSET
CSE_PRAM offset of the SREG parameter used by the following commands: CMD_GET_ID. ...
status_t CSEC_DRV_GenerateMACAsync(csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, uint8_t *cmac)
Asynchronously calculates the MAC of a given message using CMAC with AES-128.
Definition: csec_driver.c:1162