lib/sw_services/xilsecure/src/common/xsecure_rsa.c
int XSecure_RsaPrivateDecrypt_64Bit(XSecure_Rsa *InstancePtr, u64 Input,
	u32 Size, u64 Result)
{
	int Status = (int)XSECURE_RSA_DATA_VALUE_ERROR;
	u32 Idx;
	u32 InputData;
	u32 ModData;
	u64 ModAddr;

	/* Validate the input arguments */
	if ((InstancePtr == NULL) || (Result == 0x00U) || (Input == 0x00U) ||
		(Size == 0x00U)) {
		Status = (int)XSECURE_RSA_INVALID_PARAM;
		goto END;
	}

	if (InstancePtr->RsaState != XSECURE_RSA_INITIALIZED) {
		Status = (int)XSECURE_RSA_STATE_MISMATCH_ERROR;
		goto END;
	}

#ifdef versal
	ModAddr = InstancePtr->ModAddr;
#else
	ModAddr = (u64)(UINTPTR)(InstancePtr->Mod);
#endif

	/*
	 * Input data should always be smaller than modulus
	 * One byte is being checked at a time to make sure the input data
	 * is smaller than the modulus
	 */
	for (Idx = 0U; Idx < Size; Idx++) {
		ModData = XSecure_InByte64((ModAddr + Idx));
		InputData = XSecure_InByte64((Input + Idx));
		if (ModData > InputData) {
#ifdef versal
			Status = XSecure_RsaOperation(InstancePtr, Input,
					Result, XSECURE_RSA_SIGN_DEC, Size);
#else
			Status = (int)XSecure_RsaOperation(InstancePtr,
					(u8 *)(UINTPTR)Input,
					(u8 *)(UINTPTR)Result,
					XSECURE_RSA_SIGN_DEC,
					Size);
#endif
			break;
		}

		if (ModData < InputData) {
			break;
		}
	}

END:
	return Status;
}
/*****************************************************************************/
/**
 * @brief	This function handles the RSA decryption for data available at
 *  		64-bit address with the private key components provided when
 *  		initializing the RSA cryptographic core with the
 *  		XSecure_RsaInitialize function
 *
 * @param	InstancePtr	- Pointer to the XSecure_Rsa instance
 * @param	Input		- Address of the buffer which contains the input
 *				  data to be decrypted
 * @param	Size		- Key size in bytes, Input size also should be same as
 * 				  Key size mentioned. Inputs supported are
 * 				- XSECURE_RSA_4096_KEY_SIZE,
 * 				- XSECURE_RSA_2048_KEY_SIZE
 * 				- XSECURE_RSA_3072_KEY_SIZE
 * @param	Result		- Address of buffer where resultant decrypted
 *				  data to be stored
 *
 * @return
 *		- XST_SUCCESS - If decryption was successful
 *		- XSECURE_RSA_DATA_VALUE_ERROR - If input data is greater than modulus
 *		- XSECURE_RSA_STATE_MISMATCH_ERROR - If State mismatch is occurred
 *		- XST_FAILURE - On RSA operation failure
 *
 * @note	The Size passed here needs to match the key size used in the
 *  		XSecure_RsaInitialize function
 *
******************************************************************************/
@brief       This function handles the RSA decryption for data available at
64-bit address with the private key components provided when
initializing the RSA cryptographic core with the
XSecure_RsaInitialize function

@param       InstancePtr     - Pointer to the XSecure_Rsa instance
@param       Input           - Address of the buffer which contains the input
data to be decrypted
@param       Size            - Key size in bytes, Input size also should be same as
Key size mentioned. Inputs supported are
- XSECURE_RSA_4096_KEY_SIZE,
- XSECURE_RSA_2048_KEY_SIZE
- XSECURE_RSA_3072_KEY_SIZE
@param       Result          - Address of buffer where resultant decrypted
data to be stored



@note        The Size passed here needs to match the key size used in the
XSecure_RsaInitialize function
@brief This function handles the RSA decryption for data available at 64 - bit address with the private key components provided when initializing the RSA cryptographic core with the XSecure_RsaInitialize function @param InstancePtr - Pointer to the XSecure_Rsa instance @param Input - Address of the buffer which contains the input data to be decrypted @param Size - Key size in bytes Input size also should be same as Key size mentioned . Inputs supported are - XSECURE_RSA_4096_KEY_SIZE - XSECURE_RSA_2048_KEY_SIZE - XSECURE_RSA_3072_KEY_SIZE @param Result - Address of buffer where resultant decrypted data to be stored @note The Size passed here needs to match the key size used in the XSecure_RsaInitialize function
int XSecure_RsaPrivateDecrypt_64Bit(XSecure_Rsa *InstancePtr, u64 Input,
	u32 Size, u64 Result)
{
	int Status = (int)XSECURE_RSA_DATA_VALUE_ERROR;
	u32 Idx;
	u32 InputData;
	u32 ModData;
	u64 ModAddr;
	if ((InstancePtr == NULL) || (Result == 0x00U) || (Input == 0x00U) ||
		(Size == 0x00U)) {
		Status = (int)XSECURE_RSA_INVALID_PARAM;
		goto END;
	}
	if (InstancePtr->RsaState != XSECURE_RSA_INITIALIZED) {
		Status = (int)XSECURE_RSA_STATE_MISMATCH_ERROR;
		goto END;
	}
#ifdef versal
	ModAddr = InstancePtr->ModAddr;
#else
	ModAddr = (u64)(UINTPTR)(InstancePtr->Mod);
#endif
	for (Idx = 0U; Idx < Size; Idx++) {
		ModData = XSecure_InByte64((ModAddr + Idx));
		InputData = XSecure_InByte64((Input + Idx));
		if (ModData > InputData) {
#ifdef versal
			Status = XSecure_RsaOperation(InstancePtr, Input,
					Result, XSECURE_RSA_SIGN_DEC, Size);
#else
			Status = (int)XSecure_RsaOperation(InstancePtr,
					(u8 *)(UINTPTR)Input,
					(u8 *)(UINTPTR)Result,
					XSECURE_RSA_SIGN_DEC,
					Size);
#endif
			break;
		}
		if (ModData < InputData) {
			break;
		}
	}
END:
	return Status;
}
int XSecure_RsaPrivateDecrypt_64Bit ( XSecure_Rsa * InstancePtr , u64 Input , u32 Size , u64 Result ) { int Status = ( int ) XSECURE_RSA_DATA_VALUE_ERROR ; u32 Idx ; u32 InputData ; u32 ModData ; u64 ModAddr ; if ( ( InstancePtr == NULL ) || ( Result == 0x00U ) || ( Input == 0x00U ) || ( Size == 0x00U ) ) { Status = ( int ) XSECURE_RSA_INVALID_PARAM ; goto END ; } if ( InstancePtr -> RsaState != XSECURE_RSA_INITIALIZED ) { Status = ( int ) XSECURE_RSA_STATE_MISMATCH_ERROR ; goto END ; } #ifdef versal ModAddr = InstancePtr -> ModAddr ; #else ModAddr = ( u64 ) ( UINTPTR ) ( InstancePtr -> Mod ) ; #endif for ( Idx = 0U ; Idx < Size ; Idx ++ ) { ModData = XSecure_InByte64 ( ( ModAddr + Idx ) ) ; InputData = XSecure_InByte64 ( ( Input + Idx ) ) ; if ( ModData > InputData ) { #ifdef versal Status = XSecure_RsaOperation ( InstancePtr , Input , Result , XSECURE_RSA_SIGN_DEC , Size ) ; #else Status = ( int ) XSecure_RsaOperation ( InstancePtr , ( u8 * ) ( UINTPTR ) Input , ( u8 * ) ( UINTPTR ) Result , XSECURE_RSA_SIGN_DEC , Size ) ; #endif break ; } if ( ModData < InputData ) { break ; } } END : return Status ; }
@brief       This function handles the RSA decryption for data available at
              64-bit address with the private key components provided when
              initializing the RSA cryptographic core with the
              XSecure_RsaInitialize function
@brief This function handles the RSA decryption for data available at 64 - bit address with the private key components provided when initializing the RSA cryptographic core with the XSecure_RsaInitialize function
/* Validate the input arguments */ /*
	 * Input data should always be smaller than modulus
	 * One byte is being checked at a time to make sure the input data
	 * is smaller than the modulus
	 */