XilinxProcessorIPLib/drivers/hdcp22_tx/src/xhdcp22_tx_crypt.c
static int XHdcp22Tx_RsaSignatureVerify(const u8 *MessagePtr, int MessageSize,
                                        const u8 *SignaturePtr,
                                        const u8 *KpubDcpNPtr, int KpubDcpNSize,
                                        const u8 *KpubDcpEPtr, int KpubDcpESize)
{
	/* Verify arguments */
	Xil_AssertNonvoid(MessagePtr   != NULL);
	Xil_AssertNonvoid(SignaturePtr != NULL);
	Xil_AssertNonvoid(KpubDcpNPtr  != NULL);
	Xil_AssertNonvoid(KpubDcpEPtr  != NULL);
	Xil_AssertNonvoid(KpubDcpNSize > 0);
	Xil_AssertNonvoid(KpubDcpESize > 0);

	int i;
	int Result = XST_SUCCESS;
	u8 THash[XHDCP22_TX_SHA256_HASH_SIZE];
	u8 TIdentifer[] = {	0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
					0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
					0x00, 0x04, 0x20};
	u8 Em[XHDCP22_TX_CERT_SIGNATURE_SIZE];
	u8* EmPtr = NULL;

	/* Create hash of first part of the certificate (without the signature). */
	XHdcp22Cmn_Sha256Hash(MessagePtr, MessageSize, THash);

	/* Perform RSA decryption and recover EM */
	Result = XHdcp22Tx_RsaEncryptMsg(KpubDcpNPtr, KpubDcpNSize,
                                   KpubDcpEPtr, KpubDcpESize,
                                   SignaturePtr,
                                   XHDCP22_TX_CERT_SIGNATURE_SIZE,
                                   Em);
	if (Result != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Compare EM to EM'
	 * where EM = 0x00 || 0x01 || PS || 0x00 || T
	 * with size 384 bytes
	 *
	 * Do the following checks:
	 *   Check 1: padding start delimiter (2   bytes)
	 *   Check 2: padding sequence        (330 bytes)
	 *   Check 3: padding end delimiter   (1   bytes)
	 *   Check 4: ASN.1 encoding of hash  (51  bytes)
	 */

	/* Check 1 */
	if ((Em[0] != 0x00) || (Em[1] != 0x01))
		return XST_FAILURE;

	/* Check 2 */
	EmPtr = &Em[2];
	for (i=0; i<330; i++) {
		if (EmPtr[i] != 0xFF)
			return XST_FAILURE;
	}

	/* Check 3 */
	EmPtr = &Em[332];
	if (EmPtr[0] != 0x00)
		return XST_FAILURE;

	/* Check 4 */
	EmPtr = &Em[333];
	if (memcmp(TIdentifer, EmPtr, 19) != 0)
		return XST_FAILURE;
	EmPtr = &Em[352];
	if (memcmp(THash, EmPtr, 32) != 0)
		return XST_FAILURE;

	return Result;
}
/****************************************************************************/
/**
* This function implements RSASSA-PKCS1-v1_5-Verify for signature
* verification. The encoding scheme used to generate EM is EMSA-PKCS1-v1_5.
* The signature size is assumed to be 3072 bits. The underlying hash function
* is SHA256.
*
* Reference: PKCS#1 v2.1, Section 8.2.2 and Section 9.2
*
* @param  MessagePtr is a pointer to the start of the message to be hashed.
* @param  MessageSize is the size of the message to be hashed.
* @param  SignaturePtr is a pointer to the start of the DCP generated signature.
* @param  KpubDcpNPtr is a pointer to the N-value of the certificate signature.
* @param  KpubDcpNSize is the size of the N-value of the certificates signature.
* @param  KpubDcpEPtr iis a pointer to the E-value of the certificate signature.
* @param  KpubDcpESize is the size of the E-value of the certificates signature.
*
* @return
*         - XST_SUCCESS if the certificate is valid.
*         - XST_FAILURE if the certificate is invalid.
* @note   None.
*
*****************************************************************************/
This function implements RSASSA-PKCS1-v1_5-Verify for signature
verification. The encoding scheme used to generate EM is EMSA-PKCS1-v1_5.
The signature size is assumed to be 3072 bits. The underlying hash function
is SHA256.


This function implements RSASSA - PKCS1 - v1_5 - Verify for signature verification . The encoding scheme used to generate EM is EMSA - PKCS1 - v1_5 . The signature size is assumed to be 3072 bits . The underlying hash function is SHA256 .
static int XHdcp22Tx_RsaSignatureVerify(const u8 *MessagePtr, int MessageSize,
                                        const u8 *SignaturePtr,
                                        const u8 *KpubDcpNPtr, int KpubDcpNSize,
                                        const u8 *KpubDcpEPtr, int KpubDcpESize)
{
	Xil_AssertNonvoid(MessagePtr   != NULL);
	Xil_AssertNonvoid(SignaturePtr != NULL);
	Xil_AssertNonvoid(KpubDcpNPtr  != NULL);
	Xil_AssertNonvoid(KpubDcpEPtr  != NULL);
	Xil_AssertNonvoid(KpubDcpNSize > 0);
	Xil_AssertNonvoid(KpubDcpESize > 0);
	int i;
	int Result = XST_SUCCESS;
	u8 THash[XHDCP22_TX_SHA256_HASH_SIZE];
	u8 TIdentifer[] = {	0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
					0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
					0x00, 0x04, 0x20};
	u8 Em[XHDCP22_TX_CERT_SIGNATURE_SIZE];
	u8* EmPtr = NULL;
	XHdcp22Cmn_Sha256Hash(MessagePtr, MessageSize, THash);
	Result = XHdcp22Tx_RsaEncryptMsg(KpubDcpNPtr, KpubDcpNSize,
                                   KpubDcpEPtr, KpubDcpESize,
                                   SignaturePtr,
                                   XHDCP22_TX_CERT_SIGNATURE_SIZE,
                                   Em);
	if (Result != XST_SUCCESS) {
		return XST_FAILURE;
	}
	if ((Em[0] != 0x00) || (Em[1] != 0x01))
		return XST_FAILURE;
	EmPtr = &Em[2];
	for (i=0; i<330; i++) {
		if (EmPtr[i] != 0xFF)
			return XST_FAILURE;
	}
	EmPtr = &Em[332];
	if (EmPtr[0] != 0x00)
		return XST_FAILURE;
	EmPtr = &Em[333];
	if (memcmp(TIdentifer, EmPtr, 19) != 0)
		return XST_FAILURE;
	EmPtr = &Em[352];
	if (memcmp(THash, EmPtr, 32) != 0)
		return XST_FAILURE;
	return Result;
}
static int XHdcp22Tx_RsaSignatureVerify ( const u8 * MessagePtr , int MessageSize , const u8 * SignaturePtr , const u8 * KpubDcpNPtr , int KpubDcpNSize , const u8 * KpubDcpEPtr , int KpubDcpESize ) { Xil_AssertNonvoid ( MessagePtr != NULL ) ; Xil_AssertNonvoid ( SignaturePtr != NULL ) ; Xil_AssertNonvoid ( KpubDcpNPtr != NULL ) ; Xil_AssertNonvoid ( KpubDcpEPtr != NULL ) ; Xil_AssertNonvoid ( KpubDcpNSize > 0 ) ; Xil_AssertNonvoid ( KpubDcpESize > 0 ) ; int i ; int Result = XST_SUCCESS ; u8 THash [ XHDCP22_TX_SHA256_HASH_SIZE ] ; u8 TIdentifer [ ] = { 0x30 , 0x31 , 0x30 , 0x0d , 0x06 , 0x09 , 0x60 , 0x86 , 0x48 , 0x01 , 0x65 , 0x03 , 0x04 , 0x02 , 0x01 , 0x05 , 0x00 , 0x04 , 0x20 } ; u8 Em [ XHDCP22_TX_CERT_SIGNATURE_SIZE ] ; u8 * EmPtr = NULL ; XHdcp22Cmn_Sha256Hash ( MessagePtr , MessageSize , THash ) ; Result = XHdcp22Tx_RsaEncryptMsg ( KpubDcpNPtr , KpubDcpNSize , KpubDcpEPtr , KpubDcpESize , SignaturePtr , XHDCP22_TX_CERT_SIGNATURE_SIZE , Em ) ; if ( Result != XST_SUCCESS ) { return XST_FAILURE ; } if ( ( Em [ 0 ] != 0x00 ) || ( Em [ 1 ] != 0x01 ) ) return XST_FAILURE ; EmPtr = & Em [ 2 ] ; for ( i = 0 ; i < 330 ; i ++ ) { if ( EmPtr [ i ] != 0xFF ) return XST_FAILURE ; } EmPtr = & Em [ 332 ] ; if ( EmPtr [ 0 ] != 0x00 ) return XST_FAILURE ; EmPtr = & Em [ 333 ] ; if ( memcmp ( TIdentifer , EmPtr , 19 ) != 0 ) return XST_FAILURE ; EmPtr = & Em [ 352 ] ; if ( memcmp ( THash , EmPtr , 32 ) != 0 ) return XST_FAILURE ; return Result ; }
This function implements RSASSA-PKCS1-v1_5-Verify for signature
verification.
This function implements RSASSA - PKCS1 - v1_5 - Verify for signature verification .
/* Verify arguments */ /* Create hash of first part of the certificate (without the signature). */ /* Perform RSA decryption and recover EM */ /*
	 * Compare EM to EM'
	 * where EM = 0x00 || 0x01 || PS || 0x00 || T
	 * with size 384 bytes
	 *
	 * Do the following checks:
	 *   Check 1: padding start delimiter (2   bytes)
	 *   Check 2: padding sequence        (330 bytes)
	 *   Check 3: padding end delimiter   (1   bytes)
	 *   Check 4: ASN.1 encoding of hash  (51  bytes)
	 */ /* Check 1 */ /* Check 2 */ /* Check 3 */ /* Check 4 */