lib/sw_services/xilskey/examples/xilskey_puf_regeneration_example.c
u32 XilSKey_Puf_Encrypt_data()
{
	u32 Status;
	u32 DataOut;
	u32 ArrayIn;
	u32 DataIn;
	XCsuDma_Configure ConfigurValues = {0};
	xil_printf("In XilSKey_Puf_Encrypt_data\r\n");
	/*
	 * Convert the IV from string to hex format. This is the IV used to
	 * encrypt the data using PUF key
	 */
	Status = XilSKey_Efuse_ConvertStringToHexBE(
				(const char *)(XSK_PUF_KEY_IV),
				&PufIV[0], XSK_IV_LENGTH_IN_BITS);

	if (Status != XST_SUCCESS) {
		Status = XPUF_STRING_INVALID_ERROR;
		xPuf_printf(XPUF_DEBUG_GENERAL,
		"App: String Conversion error (IV):%08x !!!\r\n", Status);
		goto ENDENCRYPT;
	} else {

		xPuf_printf(XPUF_DEBUG_GENERAL, "App: Black key IV - ");
		for (ArrayIn = 0; ArrayIn < XSK_ZYNQMP_PUF_KEY_IV_LEN_IN_BYTES;
				ArrayIn++) {
			xPuf_printf(XPUF_DEBUG_GENERAL, "%02x", PufIV[ArrayIn]);
		}
		xPuf_printf(XPUF_DEBUG_GENERAL, "\r\n");
	}

	Status = XilSKey_Efuse_ConvertStringToHexBE(
			(const char *)(XSK_INPUT_DATA),
			&EncInput[0], XSK_DATA_LEN_IN_BITS);
	if (Status != XST_SUCCESS) {
		Status = XPUF_STRING_INVALID_ERROR;
		xPuf_printf(XPUF_DEBUG_GENERAL,
		"App: String Conversion error (INPUT_DATA):%08x !!!\r\n",
		Status);
		goto ENDENCRYPT;
	} else {
		xPuf_printf(XPUF_DEBUG_GENERAL,
				"App: Input data to Aes encrypt - ");
		for (DataIn = 0; DataIn < XSK_DATA_LEN_IN_BYTES; DataIn++) {
		xPuf_printf(XPUF_DEBUG_GENERAL, "%02x",
					EncInput[DataIn]);
	}
		xPuf_printf(XPUF_DEBUG_GENERAL, "\r\n");
	}

	/* Initialize AES engine */
	xPuf_printf(XPUF_DEBUG_GENERAL, "App: AES initialize \n\r");
	Status = XSecure_AesInitialize(&AesInstance, &CsuDma,
				XSK_PUF_DEVICE_KEY,
				(u32*)&PufIV[0], NULL);

	if (Status != XST_SUCCESS) {
		Status = XPUF_AES_INIT_FAILED_ERROR;
		xPuf_printf(XPUF_DEBUG_GENERAL,
			"App: AES Initialize failed \n\r");
		goto ENDENCRYPT;
	}
	/* Set the data endianness for IV */
	XCsuDma_GetConfig(&CsuDma, XCSUDMA_SRC_CHANNEL,
				&ConfigurValues);
	ConfigurValues.EndianType = 1U;
	XCsuDma_SetConfig(&CsuDma, XCSUDMA_SRC_CHANNEL,
					&ConfigurValues);

	/* Enable CSU DMA Dst channel for byte swapping.*/
	XCsuDma_GetConfig(&CsuDma, XCSUDMA_DST_CHANNEL,
			&ConfigurValues);
	ConfigurValues.EndianType = 1U;
	XCsuDma_SetConfig(&CsuDma, XCSUDMA_DST_CHANNEL,
			&ConfigurValues);

	/* Request to encrypt the data using PUF Key	 */
	xPuf_printf(XPUF_DEBUG_GENERAL, "App: AES encryption \r\n");
	XSecure_AesEncryptData(&AesInstance, &EncOutput[0],
			&EncInput[0], XSK_DATA_LEN_IN_BYTES);
	xPuf_printf(XPUF_DEBUG_GENERAL, "App: Encrypted data generated\r\n");

	for (DataOut = 0; DataOut < XSK_DATA_LEN_IN_BYTES ; DataOut++) {
		xPuf_printf(XPUF_DEBUG_GENERAL,
			"%02x", EncOutput[DataOut]);
	}
	xPuf_printf(XPUF_DEBUG_GENERAL, "\r\n");
	xPuf_printf(XPUF_DEBUG_GENERAL, "App: Gcm Tag\r\n");
	for (DataOut = XSK_DATA_LEN_IN_BYTES ;
		DataOut < XSK_DATA_LEN_IN_BYTES + XSK_GCM_TAG_LEN; DataOut++) {
		xPuf_printf(XPUF_DEBUG_GENERAL,"%02x", EncOutput[DataOut]);
	}
	xPuf_printf(XPUF_DEBUG_GENERAL, "\r\n");

ENDENCRYPT:
	return Status;

}
/*****************************************************************************/
/**
 * Encrypts data blob using PUF key.
 *
 * @return
 *		- XST_SUCCESS encryption was successful.
 *		- ERROR if encryption was unsuccessful.
 *
 ******************************************************************************/
Encrypts data blob using PUF key.
@return
- XST_SUCCESS encryption was successful.
- ERROR if encryption was unsuccessful.
Encrypts data blob using PUF key . @return - XST_SUCCESS encryption was successful . - ERROR if encryption was unsuccessful .
u32 XilSKey_Puf_Encrypt_data()
{
	u32 Status;
	u32 DataOut;
	u32 ArrayIn;
	u32 DataIn;
	XCsuDma_Configure ConfigurValues = {0};
	xil_printf("In XilSKey_Puf_Encrypt_data\r\n");
	Status = XilSKey_Efuse_ConvertStringToHexBE(
				(const char *)(XSK_PUF_KEY_IV),
				&PufIV[0], XSK_IV_LENGTH_IN_BITS);
	if (Status != XST_SUCCESS) {
		Status = XPUF_STRING_INVALID_ERROR;
		xPuf_printf(XPUF_DEBUG_GENERAL,
		"App: String Conversion error (IV):%08x !!!\r\n", Status);
		goto ENDENCRYPT;
	} else {
		xPuf_printf(XPUF_DEBUG_GENERAL, "App: Black key IV - ");
		for (ArrayIn = 0; ArrayIn < XSK_ZYNQMP_PUF_KEY_IV_LEN_IN_BYTES;
				ArrayIn++) {
			xPuf_printf(XPUF_DEBUG_GENERAL, "%02x", PufIV[ArrayIn]);
		}
		xPuf_printf(XPUF_DEBUG_GENERAL, "\r\n");
	}
	Status = XilSKey_Efuse_ConvertStringToHexBE(
			(const char *)(XSK_INPUT_DATA),
			&EncInput[0], XSK_DATA_LEN_IN_BITS);
	if (Status != XST_SUCCESS) {
		Status = XPUF_STRING_INVALID_ERROR;
		xPuf_printf(XPUF_DEBUG_GENERAL,
		"App: String Conversion error (INPUT_DATA):%08x !!!\r\n",
		Status);
		goto ENDENCRYPT;
	} else {
		xPuf_printf(XPUF_DEBUG_GENERAL,
				"App: Input data to Aes encrypt - ");
		for (DataIn = 0; DataIn < XSK_DATA_LEN_IN_BYTES; DataIn++) {
		xPuf_printf(XPUF_DEBUG_GENERAL, "%02x",
					EncInput[DataIn]);
	}
		xPuf_printf(XPUF_DEBUG_GENERAL, "\r\n");
	}
	xPuf_printf(XPUF_DEBUG_GENERAL, "App: AES initialize \n\r");
	Status = XSecure_AesInitialize(&AesInstance, &CsuDma,
				XSK_PUF_DEVICE_KEY,
				(u32*)&PufIV[0], NULL);
	if (Status != XST_SUCCESS) {
		Status = XPUF_AES_INIT_FAILED_ERROR;
		xPuf_printf(XPUF_DEBUG_GENERAL,
			"App: AES Initialize failed \n\r");
		goto ENDENCRYPT;
	}
	XCsuDma_GetConfig(&CsuDma, XCSUDMA_SRC_CHANNEL,
				&ConfigurValues);
	ConfigurValues.EndianType = 1U;
	XCsuDma_SetConfig(&CsuDma, XCSUDMA_SRC_CHANNEL,
					&ConfigurValues);
	XCsuDma_GetConfig(&CsuDma, XCSUDMA_DST_CHANNEL,
			&ConfigurValues);
	ConfigurValues.EndianType = 1U;
	XCsuDma_SetConfig(&CsuDma, XCSUDMA_DST_CHANNEL,
			&ConfigurValues);
	xPuf_printf(XPUF_DEBUG_GENERAL, "App: AES encryption \r\n");
	XSecure_AesEncryptData(&AesInstance, &EncOutput[0],
			&EncInput[0], XSK_DATA_LEN_IN_BYTES);
	xPuf_printf(XPUF_DEBUG_GENERAL, "App: Encrypted data generated\r\n");
	for (DataOut = 0; DataOut < XSK_DATA_LEN_IN_BYTES ; DataOut++) {
		xPuf_printf(XPUF_DEBUG_GENERAL,
			"%02x", EncOutput[DataOut]);
	}
	xPuf_printf(XPUF_DEBUG_GENERAL, "\r\n");
	xPuf_printf(XPUF_DEBUG_GENERAL, "App: Gcm Tag\r\n");
	for (DataOut = XSK_DATA_LEN_IN_BYTES ;
		DataOut < XSK_DATA_LEN_IN_BYTES + XSK_GCM_TAG_LEN; DataOut++) {
		xPuf_printf(XPUF_DEBUG_GENERAL,"%02x", EncOutput[DataOut]);
	}
	xPuf_printf(XPUF_DEBUG_GENERAL, "\r\n");
ENDENCRYPT:
	return Status;
}
u32 XilSKey_Puf_Encrypt_data ( ) { u32 Status ; u32 DataOut ; u32 ArrayIn ; u32 DataIn ; XCsuDma_Configure ConfigurValues = { 0 } ; xil_printf ( " \r \n " ) ; Status = XilSKey_Efuse_ConvertStringToHexBE ( ( const char * ) ( XSK_PUF_KEY_IV ) , & PufIV [ 0 ] , XSK_IV_LENGTH_IN_BITS ) ; if ( Status != XST_SUCCESS ) { Status = XPUF_STRING_INVALID_ERROR ; xPuf_printf ( XPUF_DEBUG_GENERAL , " \r \n " , Status ) ; goto ENDENCRYPT ; } else { xPuf_printf ( XPUF_DEBUG_GENERAL , " " ) ; for ( ArrayIn = 0 ; ArrayIn < XSK_ZYNQMP_PUF_KEY_IV_LEN_IN_BYTES ; ArrayIn ++ ) { xPuf_printf ( XPUF_DEBUG_GENERAL , " " , PufIV [ ArrayIn ] ) ; } xPuf_printf ( XPUF_DEBUG_GENERAL , " \r \n " ) ; } Status = XilSKey_Efuse_ConvertStringToHexBE ( ( const char * ) ( XSK_INPUT_DATA ) , & EncInput [ 0 ] , XSK_DATA_LEN_IN_BITS ) ; if ( Status != XST_SUCCESS ) { Status = XPUF_STRING_INVALID_ERROR ; xPuf_printf ( XPUF_DEBUG_GENERAL , " \r \n " , Status ) ; goto ENDENCRYPT ; } else { xPuf_printf ( XPUF_DEBUG_GENERAL , " " ) ; for ( DataIn = 0 ; DataIn < XSK_DATA_LEN_IN_BYTES ; DataIn ++ ) { xPuf_printf ( XPUF_DEBUG_GENERAL , " " , EncInput [ DataIn ] ) ; } xPuf_printf ( XPUF_DEBUG_GENERAL , " \r \n " ) ; } xPuf_printf ( XPUF_DEBUG_GENERAL , " \n \r " ) ; Status = XSecure_AesInitialize ( & AesInstance , & CsuDma , XSK_PUF_DEVICE_KEY , ( u32 * ) & PufIV [ 0 ] , NULL ) ; if ( Status != XST_SUCCESS ) { Status = XPUF_AES_INIT_FAILED_ERROR ; xPuf_printf ( XPUF_DEBUG_GENERAL , " \n \r " ) ; goto ENDENCRYPT ; } XCsuDma_GetConfig ( & CsuDma , XCSUDMA_SRC_CHANNEL , & ConfigurValues ) ; ConfigurValues . EndianType = 1U ; XCsuDma_SetConfig ( & CsuDma , XCSUDMA_SRC_CHANNEL , & ConfigurValues ) ; XCsuDma_GetConfig ( & CsuDma , XCSUDMA_DST_CHANNEL , & ConfigurValues ) ; ConfigurValues . EndianType = 1U ; XCsuDma_SetConfig ( & CsuDma , XCSUDMA_DST_CHANNEL , & ConfigurValues ) ; xPuf_printf ( XPUF_DEBUG_GENERAL , " \r \n " ) ; XSecure_AesEncryptData ( & AesInstance , & EncOutput [ 0 ] , & EncInput [ 0 ] , XSK_DATA_LEN_IN_BYTES ) ; xPuf_printf ( XPUF_DEBUG_GENERAL , " \r \n " ) ; for ( DataOut = 0 ; DataOut < XSK_DATA_LEN_IN_BYTES ; DataOut ++ ) { xPuf_printf ( XPUF_DEBUG_GENERAL , " " , EncOutput [ DataOut ] ) ; } xPuf_printf ( XPUF_DEBUG_GENERAL , " \r \n " ) ; xPuf_printf ( XPUF_DEBUG_GENERAL , " \r \n " ) ; for ( DataOut = XSK_DATA_LEN_IN_BYTES ; DataOut < XSK_DATA_LEN_IN_BYTES + XSK_GCM_TAG_LEN ; DataOut ++ ) { xPuf_printf ( XPUF_DEBUG_GENERAL , " " , EncOutput [ DataOut ] ) ; } xPuf_printf ( XPUF_DEBUG_GENERAL , " \r \n " ) ; ENDENCRYPT : return Status ; }
Encrypts data blob using PUF key.
Encrypts data blob using PUF key .
/*
	 * Convert the IV from string to hex format. This is the IV used to
	 * encrypt the data using PUF key
	 */ /* Initialize AES engine */ /* Set the data endianness for IV */ /* Enable CSU DMA Dst channel for byte swapping.*/ /* Request to encrypt the data using PUF Key	 */