Commit 9461a418 by farnoud

updated README, final code cleanup

parent b2f4196f
......@@ -50,3 +50,11 @@ If you would like to generate a bitstream for an accelerator core other than
NTRUEncrypt RTL polymult, you can open the Vivado project created in
vivado_project/platform_project and replace the polymult IP core with another
accelerator and generate a new bitstream.
The program is expected to print out the execution time of Key Generation,
Encapsulation, and Decapsulation (in cycles of AXI Timer set by default to 200
MHz) for software only implementation and software/hardware implementation, as
well as the achieved speed-up.
You can also set the "POLY_MUL_EXE" parameter to 1 in the DMA_Transfer_def.h to
print out the execution time of hardware accelerator only.
// =============================================================================
// Copyright © 2019 by Cryptographic Engineering Research Group (CERG),
// ECE Department, George Mason University
// Fairfax, VA, U.S.A.
// Author: Farnoud Farahmand
// Based on the open source code from Xilinx Wiki
// =============================================================================
#include "DMA_Transfer_def.h"
/*****************************************************************************/
......@@ -308,39 +315,10 @@ static int DMA_Transfer(dma_t *TxBuffer, u32 ARRAY_LENGTH_TX_in, dma_t *RxBuffer
u32 BYTES_TO_TRANSFER_TX_in = ARRAY_LENGTH_TX_in*(sizeof(dma_t));
u32 BYTES_TO_TRANSFER_RX_in = ARRAY_LENGTH_RX_in*(sizeof(dma_t));
#if PROFILE_TRAN
XTmrCtr_Reset(&TMRInst, 0);
XTmrCtr_Start(&TMRInst, 0);
#endif
OUTPUT_FIFO_2CLK_mWriteReg(OUTPUT_FIFO_BASE_ADDR, OUTPUT_FIFO_transfer_length_OFFSET, ARRAY_LENGTH_RX_in);
//OUTPUT_FIFO_2CLK_mWriteReg(OUTPUT_FIFO_BASE_ADDR, OUTPUT_FIFO_start_delay_OFFSET, ARRAY_LENGTH_TX_in);
#if PROFILE_TRAN
XTmrCtr_Stop(&TMRInst, 0);
execution_time = XTmrCtr_GetValue(&TMRInst, 0); // Read Timer value
xil_printf("\r\n >>> OUTPUT_FIFO_2CLK_mWriteReg Time = %d ||||< \r\n", execution_time);
#endif
#if PROFILE_TRAN
XTmrCtr_Reset(&TMRInst, 0);
XTmrCtr_Start(&TMRInst, 0);
#endif
//Xil_DCacheFlushRange((dma_t)TxBuffer, BYTES_TO_TRANSFER_TX_in);
#if PROFILE_TRAN
XTmrCtr_Stop(&TMRInst, 0);
execution_time = XTmrCtr_GetValue(&TMRInst, 0); // Read Timer value
xil_printf("\r\n >>> Xil_DCacheFlushRange Time = %d ||||< \r\n", execution_time);
#endif
#if PROFILE_TRAN
XTmrCtr_Reset(&TMRInst, 0);
XTmrCtr_Start(&TMRInst, 0);
#endif
//Xil_DCacheInvalidateRange((dma_t)RxBuffer, BYTES_TO_TRANSFER_RX_in);
#if PROFILE_TRAN
XTmrCtr_Stop(&TMRInst, 0);
execution_time = XTmrCtr_GetValue(&TMRInst, 0); // Read Timer value
xil_printf("\r\n >>> Xil_DCacheInvalidateRange Time = %d ||||< \r\n", execution_time);
#endif
Status = XAxiDma_SimpleTransfer(&AxiDma,(dma_t) RxBuffer, BYTES_TO_TRANSFER_RX_in, XAXIDMA_DEVICE_TO_DMA);
if (Status != XST_SUCCESS) {
......@@ -355,7 +333,7 @@ static int DMA_Transfer(dma_t *TxBuffer, u32 ARRAY_LENGTH_TX_in, dma_t *RxBuffer
}
/* Wait RX done */
while (RxDone == 0) { /* xil_printf("Wait for intrupt \r\n"); NOP */ }
while (RxDone == 0) { /* NOP xil_printf("Wait for intrupt \r\n"); */ }
if (Error) {
xil_printf("Failed test transmit %s done, receive %s done\r\n", TxDone? "":" not", RxDone? "":" not");
......
// =============================================================================
// Copyright © 2019 by Cryptographic Engineering Research Group (CERG),
// ECE Department, George Mason University
// Fairfax, VA, U.S.A.
// Author: Farnoud Farahmand
// =============================================================================
#ifndef _DMATRANSFER_H_
#define _DMATRANSFER_H_
#include "xaxidma.h"
#include "xil_printf.h"
#include "xparameters.h"
......@@ -44,14 +49,12 @@
/* Timeout loop counter for reset */
#define RESET_TIMEOUT_COUNTER 10000
// #define RUN_DMA 0
// #define HW_MULT 0
#define DEBUG_HW 0
#define INIT_TIME 0
/* Set to 1 to measure Poly Mult execution time */
#define POLY_MUL_EXE 0
#define DEBUG_HW 0
#define INIT_TIME 0
/************************** Variable Definitions *****************************/
typedef u64 dma_t;
......
......@@ -464,7 +464,7 @@ encrypt_cca(
#if POLY_MUL_EXE
XTmrCtr_Stop(&TMRInst, 0);
execution_time = XTmrCtr_GetValue(&TMRInst, 0);
xil_printf("\r\n Encrypt Mult Execution Time (ENC) = %d \r\n", execution_time);
xil_printf("\r\n Poly Mult Execution Time (ENC) = %d \r\n", execution_time);
#endif
for(tx_rx_c = 0; tx_rx_c < 743; tx_rx_c++) {
......@@ -486,7 +486,7 @@ encrypt_cca(
#if POLY_MUL_EXE
XTmrCtr_Stop(&TMRInst, 0);
execution_time = XTmrCtr_GetValue(&TMRInst, 0);
xil_printf("\r\n Encrypt Mult Execution Time (ENC) = %d \r\n", execution_time);
xil_printf("\r\n Poly Mult Execution Time (ENC) = %d \r\n", execution_time);
#endif
#endif
}
......@@ -603,7 +603,7 @@ int decrypt_cca(
#if POLY_MUL_EXE
XTmrCtr_Stop(&TMRInst, 0);
execution_time = XTmrCtr_GetValue(&TMRInst, 0);
xil_printf("\r\n Decrypt Mult Execution Time (DEC1) = %d \r\n", execution_time);
xil_printf("\r\n Poly Mult Execution Time (DEC1) = %d \r\n", execution_time);
#endif
for(tx_rx_c = 0; tx_rx_c < 743; tx_rx_c++) {
......@@ -624,7 +624,7 @@ int decrypt_cca(
#if POLY_MUL_EXE
XTmrCtr_Stop(&TMRInst, 0);
execution_time = XTmrCtr_GetValue(&TMRInst, 0);
xil_printf("\r\n Decrypt Mult Execution Time (DEC1) = %d \r\n", execution_time);
xil_printf("\r\n Poly Mult Execution Time (DEC1) = %d \r\n", execution_time);
#endif
#endif
}
......@@ -689,6 +689,7 @@ int decrypt_cca(
XTmrCtr_Reset(&TMRInst, 0);
XTmrCtr_Start(&TMRInst, 0);
#endif
Status = DMA_Transfer(TxBuffer, ARRAY_LENGTH_TX, RxBuffer, ARRAY_LENGTH_RX);
if(Status != XST_SUCCESS) {
xil_printf("STATUS FAILURE\r\n");
......@@ -698,7 +699,7 @@ int decrypt_cca(
#if POLY_MUL_EXE
XTmrCtr_Stop(&TMRInst, 0);
execution_time = XTmrCtr_GetValue(&TMRInst, 0);
xil_printf("\r\n Decrypt Mult Execution Time (DEC2) = %d \r\n", execution_time);
xil_printf("\r\n Poly Mult Execution Time (DEC2) = %d \r\n", execution_time);
#endif
for(tx_rx_c = 0; tx_rx_c < 743; tx_rx_c++) {
......@@ -719,7 +720,7 @@ int decrypt_cca(
#if POLY_MUL_EXE
XTmrCtr_Stop(&TMRInst, 0);
execution_time = XTmrCtr_GetValue(&TMRInst, 0);
xil_printf("\r\n Decrypt Mult Execution Time (DEC2) = %d \r\n", execution_time);
xil_printf("\r\n Poly Mult Execution Time (DEC2) = %d \r\n", execution_time);
#endif
#endif
}
......
......@@ -4,14 +4,14 @@ ECE Department, George Mason University
Fairfax, VA, U.S.A.
Authors: Farnoud Farahmand, Viet Dang
Description: This directory contains the C implementation of NTRUEncrypt
algorithm which based on the reference implementation available in the
submission package to NIST PQC Round1 available at:
Description: This directory contains the C implementation of NTRUEncrypt, which
is based on the reference implementation available in the submission package to
NIST PQC Round 1 available at:
https://csrc.nist.gov/CSRC/media/Projects/Post-Quantum-Cryptography/documents/
round-1/submissions/pqNTRUsign.zip
The reference implementation is modified to support our SW/HW co-design platform
and baremetal execution on ARM A53 core.
and the bare metal execution on ARM A53 core.
================================================================================
List of source code and their description:
......@@ -22,7 +22,7 @@ List of source code and their description:
./DMA_Transfer_def.h
./DMA_Transfer_def.c
The C code provided for running DMA transactions in baremetal mode on Zynq
The C code provided for running DMA transactions in bare metal mode on Zynq
platforms.
./clk_wiz_driver.h
......
// =============================================================================
// Copyright © 2017-2018 by Cryptographic Engineering Research Group (CERG),
// Copyright © 2019 by Cryptographic Engineering Research Group (CERG),
// ECE Department, George Mason University
// Fairfax, VA, U.S.A.
// Author: Farnoud Farahmand
......
// =============================================================================
// Copyright © 2017-2018 by Cryptographic Engineering Research Group (CERG),
// Copyright © 2019 by Cryptographic Engineering Research Group (CERG),
// ECE Department, George Mason University
// Fairfax, VA, U.S.A.
// Author: Farnoud Farahmand
......
......@@ -124,7 +124,10 @@ frequency during the runtime) */
XTmrCtr_Stop(&TMRInst, 0);
/* Read Timer value*/
execution_time = XTmrCtr_GetValue(&TMRInst, 0);
xil_printf(">>> Key Gen Done: %d\r\n", execution_time);
#if !POLY_MUL_EXE
xil_printf(">>> Key Gen Done: %d\r\n", execution_time);
#endif
XTmrCtr_Reset(&TMRInst, 0);
XTmrCtr_Start(&TMRInst, 0);
......@@ -140,7 +143,10 @@ frequency during the runtime) */
execution_time = execution_time-dma_init_cycles_encaps-pubkey_ld_cycles;
hw_encaps_time = execution_time;}
else{sw_encaps_time = execution_time;}
xil_printf(">>> Encaps Done: %d\r\n", execution_time);
#if !POLY_MUL_EXE
xil_printf(">>> Encaps Done: %d\r\n", execution_time);
#endif
XTmrCtr_Reset(&TMRInst, 0);
XTmrCtr_Start(&TMRInst, 0);
......@@ -156,7 +162,10 @@ frequency during the runtime) */
execution_time = execution_time-dma_init_cycles_decaps-privkey_ld_cycles;
hw_decaps_time = execution_time;}
else{sw_decaps_time = execution_time;}
xil_printf(">>> Decaps Done: %d\r\n", execution_time);
#if !POLY_MUL_EXE
xil_printf(">>> Decaps Done: %d\r\n", execution_time);
#endif
xil_printf("---------------------------------------- \r\n");
......@@ -181,6 +190,7 @@ frequency during the runtime) */
HW_MULT = 1;
}
#if !POLY_MUL_EXE
xil_printf("*** TOTAL SPEED-UP ***\r\n");
speedup = (float)sw_encaps_time/hw_encaps_time;
speedup_int = speedup;
......@@ -191,6 +201,7 @@ frequency during the runtime) */
speedup_fl = (speedup-speedup_int)*1000;
xil_printf(">>> Decapsulation Speed-up: %d.%3d\r\n", speedup_int,speedup_fl);
xil_printf("---------------------------------------- \r\n");
#endif
/* Disable TX and RX Ring interrupts and return success */
DisableIntrSystem(&Intc, TX_INTR_ID, RX_INTR_ID);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment