lib/sw_services/xilsecure/src/common/xsecure_rsa.c
int XSecure_RsaSignVerification_64Bit(const u64 Signature, const u64 Hash,
	u32 HashLen)
{
	int Status = XST_FAILURE;
	const u8 *Tpadding = (u8 *)XNULL;
	u32 PadLength;
	volatile u32 SignIndex;
	u64 PadIndex = Signature;

	/* Validate the input arguments */
	if ((Signature == 0x00U) || (Hash == 0x00U) ||
		(HashLen != XSECURE_HASH_TYPE_SHA3)) {
		Status = (int)XSECURE_RSA_INVALID_PARAM;
		goto ENDF;
	}
	PadLength = XSECURE_FSBL_SIG_SIZE - XSECURE_RSA_BYTE_PAD_LENGTH
				- XSECURE_RSA_T_PAD_LENGTH - HashLen;

	Tpadding = XSecure_RsaGetTPadding();

	/*
	 * Re-Create PKCS#1v1.5 Padding
	* MSB  ------------------------------------------------------------LSB
	* 0x0 || 0x1 || 0xFF(for 202 bytes) || 0x0 || T_padding || SHA384 Hash
	*/

	if (XSECURE_RSA_BYTE_PAD1 != XSecure_InByte64(PadIndex)) {
		goto ENDF;
	}
	PadIndex++;

	if (XSECURE_RSA_BYTE_PAD2 != XSecure_InByte64(PadIndex)) {
		goto ENDF;
	}
	PadIndex++;

	for (SignIndex = 0U; SignIndex < PadLength; SignIndex++) {
		if (XSECURE_RSA_BYTE_PAD3 != XSecure_InByte64(PadIndex)) {
			goto ENDF;
		}
		PadIndex++;
	}

	if (XSECURE_RSA_BYTE_PAD1 != XSecure_InByte64(PadIndex)) {
		goto ENDF;
	}
	PadIndex++;

	for (SignIndex = 0U; SignIndex < XSECURE_RSA_T_PAD_LENGTH; SignIndex++) {
		if (XSecure_InByte64(PadIndex) != Tpadding[SignIndex]) {
			goto ENDF;
		}
		PadIndex++;
	}

	for (SignIndex = 0U; SignIndex < HashLen; SignIndex++) {
		if (XSecure_InByte64(PadIndex) != XSecure_InByte64((Hash +SignIndex))) {
			goto ENDF;
		}
		PadIndex++;
	}

	if (SignIndex == HashLen) {
		Status = XST_SUCCESS;
	}

ENDF:
	return Status;
}
/*****************************************************************************/
/**
 * @brief	This function verifies the RSA decrypted data located at a
 *  		64-bit address provided is either matching with the provided
 *  		expected hash by taking care of PKCS padding
 *
 * @param	Signature - Address of the buffer which holds the decrypted
 *			    RSA signature
 * @param	Hash	  - Address of the buffer which has the hash calculated
 *		 	    on the data to be authenticated
 * @param	HashLen	  - Length of Hash used
 *			  - For SHA3 it should be 48 bytes
 *
 * @return	- XST_SUCCESS - If decryption was successful
 *		- XSECURE_RSA_INVALID_PARAM - On invalid arguments
 *		- XST_FAILURE - In case of mismatch
 *
 ******************************************************************************/
@brief       This function verifies the RSA decrypted data located at a
64-bit address provided is either matching with the provided
expected hash by taking care of PKCS padding

@param       Signature - Address of the buffer which holds the decrypted
RSA signature
@param       Hash      - Address of the buffer which has the hash calculated
on the data to be authenticated
@param       HashLen   - Length of Hash used
- For SHA3 it should be 48 bytes


@brief This function verifies the RSA decrypted data located at a 64 - bit address provided is either matching with the provided expected hash by taking care of PKCS padding @param Signature - Address of the buffer which holds the decrypted RSA signature @param Hash - Address of the buffer which has the hash calculated on the data to be authenticated @param HashLen - Length of Hash used - For SHA3 it should be 48 bytes
int XSecure_RsaSignVerification_64Bit(const u64 Signature, const u64 Hash,
	u32 HashLen)
{
	int Status = XST_FAILURE;
	const u8 *Tpadding = (u8 *)XNULL;
	u32 PadLength;
	volatile u32 SignIndex;
	u64 PadIndex = Signature;
	if ((Signature == 0x00U) || (Hash == 0x00U) ||
		(HashLen != XSECURE_HASH_TYPE_SHA3)) {
		Status = (int)XSECURE_RSA_INVALID_PARAM;
		goto ENDF;
	}
	PadLength = XSECURE_FSBL_SIG_SIZE - XSECURE_RSA_BYTE_PAD_LENGTH
				- XSECURE_RSA_T_PAD_LENGTH - HashLen;
	Tpadding = XSecure_RsaGetTPadding();
	if (XSECURE_RSA_BYTE_PAD1 != XSecure_InByte64(PadIndex)) {
		goto ENDF;
	}
	PadIndex++;
	if (XSECURE_RSA_BYTE_PAD2 != XSecure_InByte64(PadIndex)) {
		goto ENDF;
	}
	PadIndex++;
	for (SignIndex = 0U; SignIndex < PadLength; SignIndex++) {
		if (XSECURE_RSA_BYTE_PAD3 != XSecure_InByte64(PadIndex)) {
			goto ENDF;
		}
		PadIndex++;
	}
	if (XSECURE_RSA_BYTE_PAD1 != XSecure_InByte64(PadIndex)) {
		goto ENDF;
	}
	PadIndex++;
	for (SignIndex = 0U; SignIndex < XSECURE_RSA_T_PAD_LENGTH; SignIndex++) {
		if (XSecure_InByte64(PadIndex) != Tpadding[SignIndex]) {
			goto ENDF;
		}
		PadIndex++;
	}
	for (SignIndex = 0U; SignIndex < HashLen; SignIndex++) {
		if (XSecure_InByte64(PadIndex) != XSecure_InByte64((Hash +SignIndex))) {
			goto ENDF;
		}
		PadIndex++;
	}
	if (SignIndex == HashLen) {
		Status = XST_SUCCESS;
	}
ENDF:
	return Status;
}
int XSecure_RsaSignVerification_64Bit ( const u64 Signature , const u64 Hash , u32 HashLen ) { int Status = XST_FAILURE ; const u8 * Tpadding = ( u8 * ) XNULL ; u32 PadLength ; volatile u32 SignIndex ; u64 PadIndex = Signature ; if ( ( Signature == 0x00U ) || ( Hash == 0x00U ) || ( HashLen != XSECURE_HASH_TYPE_SHA3 ) ) { Status = ( int ) XSECURE_RSA_INVALID_PARAM ; goto ENDF ; } PadLength = XSECURE_FSBL_SIG_SIZE - XSECURE_RSA_BYTE_PAD_LENGTH - XSECURE_RSA_T_PAD_LENGTH - HashLen ; Tpadding = XSecure_RsaGetTPadding ( ) ; if ( XSECURE_RSA_BYTE_PAD1 != XSecure_InByte64 ( PadIndex ) ) { goto ENDF ; } PadIndex ++ ; if ( XSECURE_RSA_BYTE_PAD2 != XSecure_InByte64 ( PadIndex ) ) { goto ENDF ; } PadIndex ++ ; for ( SignIndex = 0U ; SignIndex < PadLength ; SignIndex ++ ) { if ( XSECURE_RSA_BYTE_PAD3 != XSecure_InByte64 ( PadIndex ) ) { goto ENDF ; } PadIndex ++ ; } if ( XSECURE_RSA_BYTE_PAD1 != XSecure_InByte64 ( PadIndex ) ) { goto ENDF ; } PadIndex ++ ; for ( SignIndex = 0U ; SignIndex < XSECURE_RSA_T_PAD_LENGTH ; SignIndex ++ ) { if ( XSecure_InByte64 ( PadIndex ) != Tpadding [ SignIndex ] ) { goto ENDF ; } PadIndex ++ ; } for ( SignIndex = 0U ; SignIndex < HashLen ; SignIndex ++ ) { if ( XSecure_InByte64 ( PadIndex ) != XSecure_InByte64 ( ( Hash + SignIndex ) ) ) { goto ENDF ; } PadIndex ++ ; } if ( SignIndex == HashLen ) { Status = XST_SUCCESS ; } ENDF : return Status ; }
@brief       This function verifies the RSA decrypted data located at a
              64-bit address provided is either matching with the provided
              expected hash by taking care of PKCS padding
@brief This function verifies the RSA decrypted data located at a 64 - bit address provided is either matching with the provided expected hash by taking care of PKCS padding
/* Validate the input arguments */ /*
	 * Re-Create PKCS#1v1.5 Padding
	* MSB  ------------------------------------------------------------LSB
	* 0x0 || 0x1 || 0xFF(for 202 bytes) || 0x0 || T_padding || SHA384 Hash
	*/