XilinxProcessorIPLib/drivers/hdcp22_tx/src/xhdcp22_tx_crypt.c
static int XHdcp22Tx_RsaEncryptMsg(const u8 *KeyPubNPtr, int KeyPubNSize,
								   const u8 *KeyPubEPtr, int KeyPubESize,
								   const u8 *MsgPtr, int MsgSize, u8 *EncryptedMsgPtr)
{
	u32 n[BD_MAX_MOD_SIZE], e[BD_MAX_MOD_SIZE],
	        m[BD_MAX_MOD_SIZE], s[BD_MAX_MOD_SIZE];
	unsigned int ModSize = KeyPubNSize / sizeof(u32);


	/* Check if the length of the data is not equal to the key length. */
	if(MsgSize != KeyPubNSize) {
		return XST_FAILURE;
	}

	mpConvFromOctets(n, ModSize, KeyPubNPtr, KeyPubNSize);
	mpConvFromOctets(e, ModSize, KeyPubEPtr, KeyPubESize);

	mpConvFromOctets(m, ModSize, MsgPtr, MsgSize);
	mpModExp(s, m, e, n, ModSize);
	mpConvToOctets(s, ModSize, EncryptedMsgPtr, MsgSize);

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
* RSA verification primitive recovers the message representative from
* the signature representative under the control of a public key.
* This is the same as encryption, but it in a totally different context.
*
* @param  KeyPubNPtr is the RSA public key modulus part.
* @param  KeyPubNSize is size of the RSA public key modulus in bytes.
* @param  KeyPubEPtr is the RSA public key E (exponential) part.
* @param  KeyEPubSize is the sizeof the RSA public key E (exponential) part in
*         bytes.
* @param  MsgPtr is the data to verify (for example a cryptographic signature).
* @param  MsgSize is the size of the data to verify.
* @param  EncodedMsgPtr is the resulting data for verification.
*
* @return
*         - XST_SUCCESS if encryption succeeds.
*         - XST_FAILURE if the message buffer size != key size.
*
* @note		Note: Verification with a public key is the same as RSA encoding.
*
******************************************************************************/
RSA verification primitive recovers the message representative from
the signature representative under the control of a public key.
This is the same as encryption, but it in a totally different context.
RSA verification primitive recovers the message representative from the signature representative under the control of a public key . This is the same as encryption but it in a totally different context .
static int XHdcp22Tx_RsaEncryptMsg(const u8 *KeyPubNPtr, int KeyPubNSize,
								   const u8 *KeyPubEPtr, int KeyPubESize,
								   const u8 *MsgPtr, int MsgSize, u8 *EncryptedMsgPtr)
{
	u32 n[BD_MAX_MOD_SIZE], e[BD_MAX_MOD_SIZE],
	        m[BD_MAX_MOD_SIZE], s[BD_MAX_MOD_SIZE];
	unsigned int ModSize = KeyPubNSize / sizeof(u32);
	if(MsgSize != KeyPubNSize) {
		return XST_FAILURE;
	}
	mpConvFromOctets(n, ModSize, KeyPubNPtr, KeyPubNSize);
	mpConvFromOctets(e, ModSize, KeyPubEPtr, KeyPubESize);
	mpConvFromOctets(m, ModSize, MsgPtr, MsgSize);
	mpModExp(s, m, e, n, ModSize);
	mpConvToOctets(s, ModSize, EncryptedMsgPtr, MsgSize);
	return XST_SUCCESS;
}
static int XHdcp22Tx_RsaEncryptMsg ( const u8 * KeyPubNPtr , int KeyPubNSize , const u8 * KeyPubEPtr , int KeyPubESize , const u8 * MsgPtr , int MsgSize , u8 * EncryptedMsgPtr ) { u32 n [ BD_MAX_MOD_SIZE ] , e [ BD_MAX_MOD_SIZE ] , m [ BD_MAX_MOD_SIZE ] , s [ BD_MAX_MOD_SIZE ] ; unsigned int ModSize = KeyPubNSize / sizeof ( u32 ) ; if ( MsgSize != KeyPubNSize ) { return XST_FAILURE ; } mpConvFromOctets ( n , ModSize , KeyPubNPtr , KeyPubNSize ) ; mpConvFromOctets ( e , ModSize , KeyPubEPtr , KeyPubESize ) ; mpConvFromOctets ( m , ModSize , MsgPtr , MsgSize ) ; mpModExp ( s , m , e , n , ModSize ) ; mpConvToOctets ( s , ModSize , EncryptedMsgPtr , MsgSize ) ; return XST_SUCCESS ; }
RSA verification primitive recovers the message representative from
the signature representative under the control of a public key.
RSA verification primitive recovers the message representative from the signature representative under the control of a public key .
/* Check if the length of the data is not equal to the key length. */