lib/sw_apps/rsa_auth_app/src/rsa_auth_app.c
static int AuthenticatePartition(const u8 *Buffer, u32 Size, u8 *CertStart)
{
	int Status = XST_FAILURE;
	u8 DecryptSignature[RSA_PARTITION_SIGNATURE_SIZE];
	u8 HashSignature[HASHLEN];
	u8 *SpkModular;
	u8 *SpkModularEx;
	u32 SpkExp;
	u8 *SignaturePtr;

	/*
	 * Point to Authentication Certificate
	 */
	SignaturePtr = (u8 *)(CertStart);

	/*
	 * Increment the pointer by authentication Header size
	 */
	SignaturePtr += RSA_HEADER_SIZE;

	/*
	 * Increment the pointer by Magic word size
	 */
	SignaturePtr += RSA_MAGIC_WORD_SIZE;

	/*
	 * Increment the pointer beyond the PPK
	 */
	SignaturePtr += RSA_PPK_MODULAR_SIZE;
	SignaturePtr += RSA_PPK_MODULAR_EXT_SIZE;
	SignaturePtr += RSA_PPK_EXPO_SIZE;

	/*
	 * Calculate Hash Signature
	 */
	sha_256((u8 *)SignaturePtr, (RSA_SPK_MODULAR_EXT_SIZE +
				RSA_SPK_EXPO_SIZE + RSA_SPK_MODULAR_SIZE),
				HashSignature);

   	/*
   	 * Extract SPK signature
   	 */
	SpkModular = (u8 *)SignaturePtr;
	SignaturePtr += RSA_SPK_MODULAR_SIZE;
	SpkModularEx = (u8 *)SignaturePtr;
	SignaturePtr += RSA_SPK_MODULAR_EXT_SIZE;
	SpkExp = *((u32 *)SignaturePtr);
	SignaturePtr += RSA_SPK_EXPO_SIZE;

	/*
	 * Decrypt SPK Signature
	 */
	rsa2048_pubexp((RSA_NUMBER)DecryptSignature,
			(RSA_NUMBER)SignaturePtr,
			(u32)PpkExp,
			(RSA_NUMBER)PpkModular,
			(RSA_NUMBER)PpkModularEx);

	Status = RecreatePaddingAndCheck(DecryptSignature, HashSignature);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	SignaturePtr += RSA_SPK_SIGNATURE_SIZE;

	/*
	 * Decrypt Partition Signature
	 */
	rsa2048_pubexp((RSA_NUMBER)DecryptSignature,
			(RSA_NUMBER)SignaturePtr,
			(u32)SpkExp,
			(RSA_NUMBER)SpkModular,
			(RSA_NUMBER)SpkModularEx);

	/*
	 * Partition Authentication
	 * Calculate Hash Signature
	 */
	sha_256((const u8 *)Buffer, (Size - RSA_PARTITION_SIGNATURE_SIZE),
			HashSignature);

	Status = RecreatePaddingAndCheck(DecryptSignature, HashSignature);
END:
	return Status;
}
/*****************************************************************************/
/**
*
* This function authenticates the partition signature
*
* @param	Buffer    Pointer which holds the address of the partition
*                     data which needs to be authenticated
*           Size      size of the partition
*           CertStart Pointer to buffer which holds the starting address of
*                     authentication certificate provided by user
*
* @return   XST_SUCCESS if Authentication passed
*		    XST_FAILURE if Authentication failed
*
* @note		None
*
******************************************************************************/
This function authenticates the partition signature
This function authenticates the partition signature
static int AuthenticatePartition(const u8 *Buffer, u32 Size, u8 *CertStart)
{
	int Status = XST_FAILURE;
	u8 DecryptSignature[RSA_PARTITION_SIGNATURE_SIZE];
	u8 HashSignature[HASHLEN];
	u8 *SpkModular;
	u8 *SpkModularEx;
	u32 SpkExp;
	u8 *SignaturePtr;
	SignaturePtr = (u8 *)(CertStart);
	SignaturePtr += RSA_HEADER_SIZE;
	SignaturePtr += RSA_MAGIC_WORD_SIZE;
	SignaturePtr += RSA_PPK_MODULAR_SIZE;
	SignaturePtr += RSA_PPK_MODULAR_EXT_SIZE;
	SignaturePtr += RSA_PPK_EXPO_SIZE;
	sha_256((u8 *)SignaturePtr, (RSA_SPK_MODULAR_EXT_SIZE +
				RSA_SPK_EXPO_SIZE + RSA_SPK_MODULAR_SIZE),
				HashSignature);
	SpkModular = (u8 *)SignaturePtr;
	SignaturePtr += RSA_SPK_MODULAR_SIZE;
	SpkModularEx = (u8 *)SignaturePtr;
	SignaturePtr += RSA_SPK_MODULAR_EXT_SIZE;
	SpkExp = *((u32 *)SignaturePtr);
	SignaturePtr += RSA_SPK_EXPO_SIZE;
	rsa2048_pubexp((RSA_NUMBER)DecryptSignature,
			(RSA_NUMBER)SignaturePtr,
			(u32)PpkExp,
			(RSA_NUMBER)PpkModular,
			(RSA_NUMBER)PpkModularEx);
	Status = RecreatePaddingAndCheck(DecryptSignature, HashSignature);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	SignaturePtr += RSA_SPK_SIGNATURE_SIZE;
	rsa2048_pubexp((RSA_NUMBER)DecryptSignature,
			(RSA_NUMBER)SignaturePtr,
			(u32)SpkExp,
			(RSA_NUMBER)SpkModular,
			(RSA_NUMBER)SpkModularEx);
	sha_256((const u8 *)Buffer, (Size - RSA_PARTITION_SIGNATURE_SIZE),
			HashSignature);
	Status = RecreatePaddingAndCheck(DecryptSignature, HashSignature);
END:
	return Status;
}
static int AuthenticatePartition ( const u8 * Buffer , u32 Size , u8 * CertStart ) { int Status = XST_FAILURE ; u8 DecryptSignature [ RSA_PARTITION_SIGNATURE_SIZE ] ; u8 HashSignature [ HASHLEN ] ; u8 * SpkModular ; u8 * SpkModularEx ; u32 SpkExp ; u8 * SignaturePtr ; SignaturePtr = ( u8 * ) ( CertStart ) ; SignaturePtr += RSA_HEADER_SIZE ; SignaturePtr += RSA_MAGIC_WORD_SIZE ; SignaturePtr += RSA_PPK_MODULAR_SIZE ; SignaturePtr += RSA_PPK_MODULAR_EXT_SIZE ; SignaturePtr += RSA_PPK_EXPO_SIZE ; sha_256 ( ( u8 * ) SignaturePtr , ( RSA_SPK_MODULAR_EXT_SIZE + RSA_SPK_EXPO_SIZE + RSA_SPK_MODULAR_SIZE ) , HashSignature ) ; SpkModular = ( u8 * ) SignaturePtr ; SignaturePtr += RSA_SPK_MODULAR_SIZE ; SpkModularEx = ( u8 * ) SignaturePtr ; SignaturePtr += RSA_SPK_MODULAR_EXT_SIZE ; SpkExp = * ( ( u32 * ) SignaturePtr ) ; SignaturePtr += RSA_SPK_EXPO_SIZE ; rsa2048_pubexp ( ( RSA_NUMBER ) DecryptSignature , ( RSA_NUMBER ) SignaturePtr , ( u32 ) PpkExp , ( RSA_NUMBER ) PpkModular , ( RSA_NUMBER ) PpkModularEx ) ; Status = RecreatePaddingAndCheck ( DecryptSignature , HashSignature ) ; if ( Status != XST_SUCCESS ) { goto END ; } SignaturePtr += RSA_SPK_SIGNATURE_SIZE ; rsa2048_pubexp ( ( RSA_NUMBER ) DecryptSignature , ( RSA_NUMBER ) SignaturePtr , ( u32 ) SpkExp , ( RSA_NUMBER ) SpkModular , ( RSA_NUMBER ) SpkModularEx ) ; sha_256 ( ( const u8 * ) Buffer , ( Size - RSA_PARTITION_SIGNATURE_SIZE ) , HashSignature ) ; Status = RecreatePaddingAndCheck ( DecryptSignature , HashSignature ) ; END : return Status ; }
This function authenticates the partition signature
This function authenticates the partition signature
/*
	 * Point to Authentication Certificate
	 */ /*
	 * Increment the pointer by authentication Header size
	 */ /*
	 * Increment the pointer by Magic word size
	 */ /*
	 * Increment the pointer beyond the PPK
	 */ /*
	 * Calculate Hash Signature
	 */ /*
   	 * Extract SPK signature
   	 */ /*
	 * Decrypt SPK Signature
	 */ /*
	 * Decrypt Partition Signature
	 */ /*
	 * Partition Authentication
	 * Calculate Hash Signature
	 */