xilloader
Vitis Drivers API Documentation
xloader_auth_enc.c File Reference

Overview

This file contains authentication and encryption related code.

MODIFICATION HISTORY:
Ver   Who  Date     Changes
----- ---- -------- -------------------------------------------------------
1.00  bm   12/16/20 First release
      kal  12/23/20 Initialize Status to XST_FAILURE in XLoader_AesKatTest
      kpt  01/06/21 Added redundancy for the loop in XLoader_CheckNonZeroPpk
      kpt  01/12/21 Added check to validate keysrc for partitions when
                    DEC only efuse bits are set
      kpt  01/18/21 Added check to validate the index of for loop with lower
                    bounds of ppk offset in XLoader_CheckNonZeroPpk
      har  01/19/21 Added support for P521 KAT
      kpt  01/21/21 Added check to verify revoke id before enabling Auth Jtag
      har  02/01/21 Added check for metaheader encryption source
      bm   02/12/21 Updated logic to use BootHdr directly from PMC RAM
      kpt  02/16/21 Corrected check to return valid error code in case of
                    MetaHeader IV mismatch and fixed gcc warning
      har  03/02/21 Added support to verify IHT as AAD for first secure header
      har  03/17/21 Cleaned up code to use the secure state of boot
      ma   03/24/21 Redirect XilPdi prints to XilLoader
      ma   03/24/21 Minor updates to prints in XilLoader
      bm   04/10/21 Updated scheduler function calls
      kpt  04/14/21 Added check to verify whether the encrypted data is 128 bit
                    aligned
      bm   05/10/21 Updated chunking logic for hashes
      bm   05/13/21 Updated code to use common crypto instances from xilsecure
      ma   05/18/21 Minor code cleanup
      har  05/19/21 Support decryption of partition even if Secure state of
                    boot is A-HWRoT or Emulated A-HWRoT
      ma   05/21/21 Read KAT Status from RTCA Secure Boot State location
1.01  kpt  06/23/21 Added check to compare DNA before enabling Auth Jtag
           07/01/21 Added support to disable Jtag as per the timeout
                    set by user
      td   07/08/21 Fix doxygen warnings
      ma   07/12/21 Register NULL error handler for
                    XLoader_CheckAuthJtagIntStatus scheduler task
      har  07/15/21 Fixed doxygen warnings
      td   07/15/21 Fixed doxygen warnings
      bsv  08/17/21 Code clean up
      rb   08/11/21 Fix compilation warnings
      bm   08/24/2021 Added Extract Metaheader support
      bsv  08/31/21 Code clean up
      kpt  09/02/21 Added support to update KAT status in RTC area
      am   09/09/21 Fixed multiple SPK Authentication while authenticating
                    MetaHeader
      kpt  09/09/21 Fixed SW-BP-BLIND-WRITE in XLoader_AuthEncClear
      kpt  09/15/21 Modified check for PUF HD in XLoader_SecureEncOnlyValidations
      kpt  09/18/21 Fixed SW-BP-REDUNDANCY
                    Added check in XLoader_CheckAuthJtagIntStatus to avoid access
                    to auth jtag if there is a failure in single attempt
                    Renamed BHSignature variable to IHTSignature
      bsv  10/01/21 Addressed code review comments
1.02  kpt  10/01/21 Removed redundant code in XLoader_VerifyRevokeId
      kpt  10/07/21 Decoupled checksum functionality from secure code
      kpt  10/20/21 Modified temporal checks to use temporal variables from
                    data section
      kpt  10/28/21 Fixed PMCDMA1 hang issue in sbi checksum copy to memory
                    mode
1.03  skd  11/18/21 Added time stamps in XLoader_ProcessAuthEncPrtn
      bsv  12/04/21 Address security review comment
      kpt  12/13/21 Replaced standard library utility functions with xilinx
                    maintained functions
      skd  01/11/22 Moved comments to its proper place
      skd  01/12/22 Updated goto labels for better readability
      bsv  02/09/22 Code clean up to reduce stack size
      bsv  02/09/22 Code clean up
      bsv  02/10/22 Code clean up by removing unwanted initializations
      bsv  02/11/22 Code optimization to reduce text size
      bsv  02/13/22 Reduce stack usage of functions
      har  02/17/22 Updated code to limit number of attempts to enable JTAG
                    when efuse bits are set
1.04  skg  06/20/22 Fixed MISRA C Rule 10.3 violation
      bm   07/06/22 Refactor versal and versal_net code
      kpt  07/07/22 Added support to update KAT status
      bsv  07/08/22 Changes related to Optional data in Image header table
      kpt  07/24/22 Added support to go into secure lockdown when KAT fails
      kpt  08/03/22 Added volatile keyword to avoid compiler optimization
                    of loop redundancy checks
1.05  har  10/11/22 Used temporal check macro for redundancy checks for Xil_SMemCpy
      sk   10/19/22 Fix security review comments
      har  11/17/22 Made XLoader_CheckNonZeroPpk as non-static and moved here from xloader_secure.c file
      ng   11/23/22 Updated doxygen comments
1.8   skg  12/07/22 Added Additional PPKs support
      kal  01/05/23 Moved XLoader_GetAuthPubAlgo function to header file
      sk   02/08/23 Renamed XLoader_UpdateKatStatus to XLoader_ClearKatOnPPDI
      sk   02/09/23 Fixed Sec Review comments in XLoader_RsaSignVerify function
1.9   kpt  02/21/23 Fixed bug in XLoader_AuthEncClear
      sk   02/28/23 Removed using of pointer to string literal in XLoader_AuthKat
      sk   03/10/23 Added redundancy for AES Key selection
      sk   03/17/23 Renamed Kekstatus to DecKeySrc in xilpdi structure
      dc   03/30/23 Updated ECDSA authentication logic to support both BE/LE
      ng   03/30/23 Updated algorithm and return values in doxygen comments
      sk   05/18/2023 Deprecate copy to memory feature
      kal  06/18/23 Send device to SLD when 2nd AuthJTag message authentication
                    fails, when AUTH_JTAG_LOCK_DIS eFuse is programmed
      am   06/19/23 Added KAT error code for failure cases
      sk   07/06/23 Added Jtag DAP config support for Non-Secure Debug
      am   07/03/23 Added authentication optimization support
      ng   07/13/23 Added support for system device tree flow
      yog  08/18/23 Added a check to return error when metaheader secure state
                    does not match with plm secure state
      kpt  08/20/23 Updated check to place ECDSA in reset and clear RAM memory when
                PLM_ECDSA_EXCLUDE is not defined
      yog  08/25/23 Removed check to return error code when MH secure state doesn't
                match with plm secure
      dd   09/11/23 MISRA-C violation Rule 10.3 fixed
2.0   kpt  07/31/23 Run KAT every time when AUTH JTAG request is made
      kpt  10/09/23 Fixed compilation warning when PLM_EN_ADD_PPKS macro is enabled
2.1   sk   10/24/23 Added Redundancy in XLoader_EnableJtag
      sk   11/02/23 Updated Redundancy in XLoader_EnableJtag
      kpt  11/22/23 Add support to clear AES keys when RedKeyClear bit is set
      ng   12/27/23 Reduced log level for less frequent prints
      ng   01/28/24 u8 variables optimization
      kpt  02/08/24 Added support to extend secure state to SWPCR during AuthJtag
      yog  02/23/24 Added support to return error when P-521 curve is disabled.
      am   03/02/24 Added MH Optimization support
      kpt  03/15/24 Updated RSA KAT to use 2048-bit key
      sk   03/13/24 Fixed doxygen comments format
      har  04/12/24 Moved glitch checks after respective function calls
      kal  06/04/24 Added XLoader_SecureConfigMeasurement call in
                    XLoader_ProcessAuthEncPrtn after Block 0 processing is success
      mb   06/30/24 Fixed AES Decryption issue when KAT is enabled
      kal  07/24/24 Code refactoring and updates for Versal 2VE and 2VM Devices
      kal  09/18/24 Updated XLoader_PpkVerify to verify 384 bit ppk hash
                    for Versal 2VE and 2VM Devices
      pre  12/09/24 use PMC RAM for Metaheader instead of PPU1 RAM
      kal  01/30/25 Send LMS and HSS data to signature verification
                    without pre-hasing
2.2   sk   02/04/25 Reset Status before each function call in
                    XLoader_AuthHdrsWithHashBlock
      sk   02/04/25 Reset HashStatus before function call in
                    XLoader_IsPpkValid
      sk   02/26/25 Reset Status variable before use in XLoader_SecureEncInit
      pre  03/02/25 Remove data context setting
      obs  03/22/25 Added redundant security checks to mitigate glitch attacks
      har  04/07/25 Updated instruction mask in XLoader_EnableJtag
Note

Macros

#define XLOADER_RSA_PSS_MSB_PADDING_MASK   (u8)(0x80U)
 RSA PSS MSB padding mask. More...
 
#define XLOADER_RSA_EM_MSB_INDEX   (0x0U)
 RSA EM MSB Index. More...
 
#define XLOADER_PUF_SHUT_GLB_VAR_FLTR_EN_SHIFT   (31U)
 Shift for Global Variation Filter in PUF shutter value. More...
 
#define XLOADER_AES_RESET_VAL   (0x1U)
 AES Reset value. More...
 
#define XLOADER_AES_RESET_REG   (0xF11E0010U)
 AES Reset register address. More...
 
#define XLOADER_ECDSA_RSA_RESET_REG   (0xF1200040U)
 ECDSA RSA Reset register address. More...
 
#define XLOADER_ECDSA_RSA_RESET_VAL   (0x1U)
 ECDSA RSA Reset value. More...
 
#define XLOADER_GET_PRTN_HASH_INDEX(PdiPtr)
 Get partition hash index depending on full/partial PDI. More...
 

Functions

int XLoader_SecureAuthInit (XLoader_SecureParams *SecurePtr, const XilPdi_PrtnHdr *PrtnHdr)
 This function initializes authentication parameters of XLoader_SecureParams's instance. More...
 
int XLoader_SecureEncInit (XLoader_SecureParams *SecurePtr, const XilPdi_PrtnHdr *PrtnHdr)
 This function initializes encryption parameters of XLoader_SecureParams's instance. More...
 
int XLoader_SecureValidations (const XLoader_SecureParams *SecurePtr)
 This function checks if authentication/encryption is compulsory. More...
 
int XLoader_ReadAndVerifySecureHdrs (XLoader_SecureParams *SecurePtr, XilPdi_MetaHdr *MetaHdr)
 This function authenticates and/or decrypts the image headers and partition headers and copies the contents to the corresponding structures. More...
 
int XLoader_IsPpkValid (XLoader_PpkSel PpkSelect, const u8 *PpkHash)
 The function reads PPK invalid bits. More...
 
int XLoader_RsaPssSignVerify (u8 *MsgHash, XSecure_Rsa *RsaInstPtr, u8 *Signature, u32 KeySize)
 This function encrypts the RSA signature provided and performs required PSS operations to extract salt and calculates M prime hash and compares with hash obtained from EM. More...
 
int XLoader_AddAuthJtagToScheduler (void)
 This function adds periodic checks of the status of Auth JTAG interrupt status to the scheduler. More...
 
int XLoader_CheckAuthJtagIntStatus (void *Arg)
 This function checks the status of Auth JTAG interrupt status and it disables the Jtag as per the timeout set by user. More...
 
int XLoader_EnableJtag (volatile u32 CfgState)
 This function enables the Jtag. More...
 
int XLoader_DisableJtag (void)
 This function disables the Jtag. More...
 
int XLoader_AuthEncClear (void)
 This function is called to clear secure critical data related to authentication and encryption in case of exceptions. More...
 
void XLoader_ClearKatOnPPDI (XilPdi *PdiPtr, u32 PlmKatMask)
 This function updates the KAT status. More...
 
int XLoader_ClearAesKey (u32 *DecKeySrc)
 This function clears the AES keys when RedKeyClear is set in PMC RAM. More...
 
int XLoader_ProcessAuthEncPrtn (XLoader_SecureParams *SecurePtr, u64 DestAddr, u32 BlockSize, u8 Last)
 This function performs authentication and decryption of the partition. More...
 
int XLoader_CheckSecureState (u32 RegVal, u32 Var, u32 ExpectedValue)
 This function checks if the secure state of boot matches the expected value or not. More...
 
int XLoader_ImgHdrTblAuth (XLoader_SecureParams *SecurePtr)
 This function authenticates the image header table. More...
 
int XLoader_DataAuth (XLoader_SecureParams *SecurePtr, u8 *Hash, u8 *Signature)
 This function authenticates the data with SPK. More...