XilinxProcessorIPLib/drivers/hdcp22_tx/src/xhdcp22_tx_crypt.c
static int XHdcp22Tx_RsaOaepEncrypt(const u8 *KeyPubNPtr, int KeyPubNSize,
                                    const u8 *KeyPubEPtr, int KeyEPubSize,
                                    const u8 *Message, const u32 MessageLen,
                                    const u8 *MaskingSeed, u8 *EncryptedMessage)
{
	/* Verify arguments */
	Xil_AssertNonvoid(Message != NULL);
	Xil_AssertNonvoid(MessageLen > 0);
	Xil_AssertNonvoid(MaskingSeed != NULL);
	Xil_AssertNonvoid(EncryptedMessage != NULL);

	u8 em[XHDCP22_TX_CERT_PUB_KEY_N_SIZE];
	int Status;

	/* Step 1: Length checking */
	if(MessageLen > (XHDCP22_TX_CERT_PUB_KEY_N_SIZE - 2*XHDCP22_TX_SHA256_HASH_SIZE - 2))
	{
		return XST_FAILURE;
	}

	/* Step 2: EME-OAEP Encoding */
	Status = XHdcp22Tx_Pkcs1EmeOaepEncode(Message, MessageLen, MaskingSeed, em);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Step 3: RSA encryption */
	Status = XHdcp22Tx_RsaEncryptMsg(KeyPubNPtr, KeyPubNSize, KeyPubEPtr,
	                                 KeyEPubSize, em, KeyPubNSize,
	                                 EncryptedMessage);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	return XST_SUCCESS;
}
/****************************************************************************/
/**
* This function implements the RSAES-OAEP-Encrypt operation. The message
* is encoded using EME-OAEP and then encrypted with the public key
* using RSAEP.
*
* Reference: PKCS#1 v2.1, Section 7.1.1
*
* @param  KeyPubNPtr is the public certicate modulus.
* @param  KeyPubNSize is the size public certicate modulus.
* @param  KeyPubEPtr is the public certicate exponent.
* @param  KeyEPubSizeis the public certicate exponent size.
* @param  Message is the octet string to be encrypted.
* @param  MessageLen is the length of octet string to be encrypted and
*         must be less than or equal to (nLen - 2*hLen - 2)
* @param  MaskingSeed is the random octet string seed of length hLen
*         used by EME-OAEP encoding function.
*
* @return XST_SUCCESS or XST_FAILURE.
*
* @note   None.
*****************************************************************************/
This function implements the RSAES-OAEP-Encrypt operation. The message
is encoded using EME-OAEP and then encrypted with the public key
using RSAEP.


This function implements the RSAES - OAEP - Encrypt operation . The message is encoded using EME - OAEP and then encrypted with the public key using RSAEP .
static int XHdcp22Tx_RsaOaepEncrypt(const u8 *KeyPubNPtr, int KeyPubNSize,
                                    const u8 *KeyPubEPtr, int KeyEPubSize,
                                    const u8 *Message, const u32 MessageLen,
                                    const u8 *MaskingSeed, u8 *EncryptedMessage)
{
	Xil_AssertNonvoid(Message != NULL);
	Xil_AssertNonvoid(MessageLen > 0);
	Xil_AssertNonvoid(MaskingSeed != NULL);
	Xil_AssertNonvoid(EncryptedMessage != NULL);
	u8 em[XHDCP22_TX_CERT_PUB_KEY_N_SIZE];
	int Status;
	if(MessageLen > (XHDCP22_TX_CERT_PUB_KEY_N_SIZE - 2*XHDCP22_TX_SHA256_HASH_SIZE - 2))
	{
		return XST_FAILURE;
	}
	Status = XHdcp22Tx_Pkcs1EmeOaepEncode(Message, MessageLen, MaskingSeed, em);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XHdcp22Tx_RsaEncryptMsg(KeyPubNPtr, KeyPubNSize, KeyPubEPtr,
	                                 KeyEPubSize, em, KeyPubNSize,
	                                 EncryptedMessage);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	return XST_SUCCESS;
}
static int XHdcp22Tx_RsaOaepEncrypt ( const u8 * KeyPubNPtr , int KeyPubNSize , const u8 * KeyPubEPtr , int KeyEPubSize , const u8 * Message , const u32 MessageLen , const u8 * MaskingSeed , u8 * EncryptedMessage ) { Xil_AssertNonvoid ( Message != NULL ) ; Xil_AssertNonvoid ( MessageLen > 0 ) ; Xil_AssertNonvoid ( MaskingSeed != NULL ) ; Xil_AssertNonvoid ( EncryptedMessage != NULL ) ; u8 em [ XHDCP22_TX_CERT_PUB_KEY_N_SIZE ] ; int Status ; if ( MessageLen > ( XHDCP22_TX_CERT_PUB_KEY_N_SIZE - 2 * XHDCP22_TX_SHA256_HASH_SIZE - 2 ) ) { return XST_FAILURE ; } Status = XHdcp22Tx_Pkcs1EmeOaepEncode ( Message , MessageLen , MaskingSeed , em ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XHdcp22Tx_RsaEncryptMsg ( KeyPubNPtr , KeyPubNSize , KeyPubEPtr , KeyEPubSize , em , KeyPubNSize , EncryptedMessage ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } return XST_SUCCESS ; }
This function implements the RSAES-OAEP-Encrypt operation.
This function implements the RSAES - OAEP - Encrypt operation .
/* Verify arguments */ /* Step 1: Length checking */ /* Step 2: EME-OAEP Encoding */ /* Step 3: RSA encryption */