The FPX KCPSM Module Exercise Network Data Encryption

































- Slides: 33
The FPX KCPSM Module Exercise: Network Data Encryption / Decryption Using ROT 13 Algorithm Henry Fu Washington University Applied Research Lab Supported by: NSF ANI-0096052 and Xilinx Corp. http: //www. arl. wustl. edu/arl/projects/fpx_kcpsm/ hwf 1@arl. wustl. edu The FPX KCPSM Module Exercise Henry Fu 1
The FPX KCPSM Module Software Exercise • Network data encryption / decryption using ROT 13 algorithm – Rotates characters by 13 places • ‘A’ ‘N’, ‘M’ ‘Z’, ‘a’ ‘n’, ‘m’ ‘z’ – Encryption Example: • ‘Hello World’ encrypts to ‘Uryyb Jbeyq’ – Decryption Example: • ‘Uryyb Jbeyq’ decrypts to ‘Hello World’ The FPX KCPSM Module Exercise Henry Fu 2
Approach to the ROT 13 Algorithm • Consider the following four cases – IF (ch >= ‘A’) && (ch <= ‘M’) • Rotate “Right” ch by 13 characters – IF (ch >= ‘N’) && (ch <= ‘Z’) • Rotate “Left” ch by 13 characters – IF (ch >= ‘a’) && (ch <= ‘m’) • Rotate “Right” ch by 13 characters – IF (ch >= ‘n’) && (ch <= ‘z’) • Rotate “Left” ch by 13 characters The FPX KCPSM Module Exercise Henry Fu 3
The FPX KCPSM Module Package • The FPX KCPSM Module Package includes: – IPTESTBENCH (IP 2 FAKE) • Generates fake ATM cells for simulation – UDPTESTBENCH (UDPTEST, UDPSTR) • Sends and receives UDP program and data packets – KCPSM Package (KCPSMBLE, PSMDEBUG) • Includes an assembler and a debugger for KCPSM – FPX KCPSM Module in VHDL • Includes all the VHDL source codes for the module The FPX KCPSM Module Exercise Henry Fu 4
The FPX KCPSM Module Package (More) • The FPX KCPSM Module Package – Detailed information on the Internet: • http: //www. arl. wustl. edu/arl/projects/fpx_kcpsm/ – Download the FPX KCPSM Module Package • Right click on fpx_kcpsm. tar. gz • Save it to h: – Extract the FPX KCPSM Module Package • Open a cygwin window – cd /cygdrive/h/ – gunzip fpx_kcpsm. tar. gz – tar xvf fpx_kcpsm. tar The FPX KCPSM Module Exercise Henry Fu 5
The FPX KCPSM Module Package • The FPX KCPSM Module Package includes: – IPTESTBENCH/ • Includes the source files, input / output files, and comiple script for the IP 2 FAKE program • Build: Type ‘make’ in the prompt – UDPTESTBENCH/ • Includes the source fiels, input files, and compile script for the UDPTEST, UDPSTR program • Build: Type ‘make’ in the prompt The FPX KCPSM Module Exercise Henry Fu 6
The FPX KCPSM Module Package (More) – KCPSM/ • Includes the KCPSM package from Xilinx Corp. and all the VHDL source codes, simulation script, synthesis script, and COREGEN component files for the FPX_KCPSM Module The FPX KCPSM Module Exercise Henry Fu 7
Programming the KCPSM • The KCPSM executes programs stored in the program memory and accesses data stored in the data memory – Program memory stores up to two programs – Each program is limited to 255 instructions – Program should begin at address 0 x 00 – Interrupt input is used to reset the KCPSM – Data memory stores up to four data packets – Each data packet is limited to 255 bytes The FPX KCPSM Module Exercise Henry Fu 8
Writing a KCPSM Program • Access the KCPSM Package – cd KCPSM/package • Create a subdirectory in the KCPSM package – mkdir ROT 13 – cp kcpsmble. dat ROT 13/ – cd ROT 13 • Create a KCPSM program using a plain text editor – vi ROT 13. PSM The FPX KCPSM Module Exercise Henry Fu 9
The KCPSM: Registers and Constants • The KCPSM has 16 8 -bit registers – Used in the program in the “s. X” format, where ‘X’ is one of the following: • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F – Example: s 0, s. A, s. F • The KCPSM supports constants – Specified in the program in the form of a twodigit hexadecimal value, where they ranges from 0 x 00 to 0 x. FF The FPX KCPSM Module Exercise Henry Fu 10
The KCPSM: Special Instructions • The KCPSM provides special instructions used to handle I/O and Interrupt operations: – INPUT s. X, s. Y • Enables 8 -bit data values external to the KCPSM to be transferred to register s. X, where the port address is indirectly specified by the contents of s. Y – INPUT s. X, pp • Enables 8 -bit data values external to the KCPSM to be transferred to register s. X, where the port address is directly specified as a two-digit hex constant The FPX KCPSM Module Exercise Henry Fu 11
The KCPSM: Special Instructions (More) – OUTPUT s. X, s. Y • Enables 8 -bit data values in register s. X to be transferred to logic external to the KCPSM, where the port address is indirectly specified by the contents of register s. Y – OUTPUT s. X, pp • Enables 8 -bit data values in register s. X to be transferred to logic external to the KCPSM, where the port address is directly specified by the two-digit hex constant The FPX KCPSM Module Exercise Henry Fu 12
The KCPSM: Special Instructions (More) – ENABLE INTERRUPT • Enables future interrupt requests – DISABLE INTERRUPT • Disables future interrupt requests – RETURNI ENABLE • Concludes an interrupt service routine and specifies that future interrupt requests are enabled – RETURNI DISABLE • Concludes an interrupt service routine and specifies that future interrupt requests are disabled The FPX KCPSM Module Exercise Henry Fu 13
The KCPSM: Instructions • For detailed explanations of every instruction available to the KCPSM, please refer to the KCPSM App Notes: – “ 8 -bit Microcontroller for Virtex Devices” • By Ken Chapman of Xilinx Corp. – Download URL: • http: //www. xilinx. com/xapp 213. pdf The FPX KCPSM Module Exercise Henry Fu 14
The KCPSM Program Template • All KCPSM programs should follow a template in order for them to work with the FPX KCPSM Module: – Enables the KCPSM for Interrupt requests – Checks if the data memory is empty – Processes data if data memory is not empty – Signals to the Interface when KCPSM is done – Suspends the KCPSM The FPX KCPSM Module Exercise Henry Fu 15
The KCPSM Program Template (More) ; Enable KCPSM Interrupt so that the KCPSM Interface can reset the KCPSM ENABLE INTERRUPT ; Check if there is new data packet in memory ; if no data, signal KCPSM Interface that process is done with no write ; if there is data, proceed to process data INIT: INPUT SA, 03 ; LOAD M[03] TO SA SUB SA, 00 ; COMPARE SA TO 00 JUMP NZ, CHK ; DATA IN MEMORY, PROCEED LOAD SA, 00 ; NO DATA, LOAD 00 TO SA, no write, signal done OUTPUT SA, FF ; WRITE 00 TO M[FF], no write, signal done JUMP WAIT ; Assembly code to process data CHK: ; Assembly code goes here ; Signal KCPSM Interface that process is done, and needs to write it out DONE: LOAD SA, FF ; LOAD FF TO SA, signal done OUTPUT SA, FF ; WRITE FF TO M[FF], write, signal done ; Suspend KCPSM ADDRESS FE WAIT: JUMP WAIT The FPX KCPSM Module Exercise Henry Fu 16
Assembling a KCPSM Program • An assembler called KCPSMBLE is included in the KCPSM package from Xilinx Corp. – KCPSMBLE needs to be executed in a PC – Programs need to be written in plain text – Programs needs to be saved in a DOS 8. 3 file format with a <. PSM> extension – Usage: • . . /KCPSMBLE ROT 13. PSM The FPX KCPSM Module Exercise Henry Fu 17
Assembling a KCPSM Program (More) • After KCPSMBLE finishes assembling the program, a coefficient file (ROT 13. COE) is generated: – Used by COREGEN to generate a single-port block RAM and initialize the block RAM content to the machine code of the program – Used by CONVERT to generate a dual-port block RAM coefficient file for COREGEN and a <INST. TBP> for simulation and lab testing The FPX KCPSM Module Exercise Henry Fu 18
Debugging a KCPSM Program • A debugger called PSMDEBUG is included in the KCPSM package from Xilinx Corp. – PSMDEBUG needs to be executed in a PC – The <. COE> file used must be generated by KCPSMBLE and must be unmodified – Usage: • . . /PSMDEBUG ROT 13. COE – Detail instructions will appear on screen after PSMDEBUG is executed The FPX KCPSM Module Exercise Henry Fu 19
Converting a KCPSM Program • The <. COE> file generated by KCPSMBLE is targeted to use with single-port block RAM • The <. COE> file generated by KCPSMBLE contains the machine code of the KCPSM program Ø Need a program that converts the <. COE> file generated by KCPSMBLE so that it can be used for simulation, synthesis, and testing The FPX KCPSM Module Exercise Henry Fu 20
Converting a KCPSM Program (More) • A C program called CONVERT is used to convert the <. COE> file generated by KCPSMBLE: – Converts the <. COE> file so that it is targeted to use with dual-port block RAM – Extracts the machine code of the KCPSM from the <. COE> file so that the program can be used in simulation and can be sent to the FPX KCPSM Module through an UDP packet The FPX KCPSM Module Exercise Henry Fu 21
Converting a KCPSM Program (More) • The CONVERT program – Usage: • . . /CONVERT ROT 13. COE – Two files are generated after the CONVERT program is executed • <PROGRAM. COE> A coefficient file used by COREGEN to generate a dual-port block RAM • <INST. TBP> A input file used by the IP 2 FAKE program to generate simulation inputs and the UDPTEST program to send UDP program packet The FPX KCPSM Module Exercise Henry Fu 22
Generating Fake ATM Cells for Simulation • A C program called IP 2 FAKE is used to generate fake ATM cells for simulation – Generate a fake ROT 13 program packet / cell using the <INST. TBP> from CONVERT • Usage: – /cygdrive/h/iptestbench/ip 2 fake INST. TBP ROT 13. DAT – Generate a fake input data packet / cell • Use a plain text editor to create a HELLO. TBP file – vi HELLO. TBP The FPX KCPSM Module Exercise Henry Fu 23
Contents of the HELLO. TBP File # # # # # demo testbench comments start with # commands start with ! parameters are optional to get familiar with the tools run "ip 2 raw TESTBENCH. TBP" and check the outcoming TBRAW. TBP file # UDP block, will be prepended by an UDP header # parameter: ip-address, dest-port, src-port !UDP 192. 168. 0. 1 7 64000 00000001 The The second third first word The fourth word 48656 C 6 C specifies it is ‘o ‘Hell’ a. Wo’ data specifies ‘rld’ 6 F 20576 F packet 726 C 6400 The FPX KCPSM Module Exercise Henry Fu 24
Simulating a KCPSM Program • Modelsim is used to simulate the FPX KCPSM Module – Copy the fake ATM program and data packet / cell to the simulation directory • cp ROT 13. DAT KCPSM/sim/ • cp HELLO. DAT KCPSM/sim/ – Go to the design simulation directory • cd KCPSM/sim/ – Create the simulation input file • cat WAIT. DAT ROT 13. DAT HELLO. DAT > INPUT_CELLS. DAT The FPX KCPSM Module Exercise Henry Fu 25
Simulating a KCPSM Program (More) – Compile the module and Start Modelsim • make compile • make sim – In Modelsim main window, type: • do testbench. do • run 10000 – In Modelsim wave window • Edit > Select All – Right click on the selected waves • Radix > Hexadecimal The FPX KCPSM Module Exercise Henry Fu 26
Simulating a KCPSM Program (More) – In Modelsim wave window • Go through the window and see the internal KCPSM processing details – In the cygwin window, open the simulation output file • vi LC_CELLSOUT. DAT – Scroll through the simulation output file • Each ATM cell is separated by a ‘new_cell’ line • The first to the third to last cells are program packets • The last two cells are the encrypted data packets The FPX KCPSM Module Exercise Henry Fu 27
Simulating a KCPSM Program • The input data cell • The output data cell The FPX KCPSM Module Exercise rd th th – ththword The The 11 10 1 3 8 st –word 213 9 7 nd specifies wordisisthe it Internet data. ATM is string UDP a Protocol data Cell Header ‘Hello packet Header World’ rd th th – ththword The The 11 10 1 3 8 st –word 213 9 7 nd specifies wordisisthe it data Internet ATM is string UDP a Protocol data Cell ‘Uryyb Header packet Header Jbeyq’ Henry Fu 28
Testing a KCPSM Program in the Lab • FTP the. TBP file to fpx – sftp yourlogin@fpx. arl. wustl. edu – put ROT 13. TBP – quit • Login to fpx using ssh (Secure Shell) – ssh -l yourlogin fpx. arl. wustl. edu – mkdir udptestbench/ – cd udptestbench/ – cp ~hwf 1/udptestbench/*. The FPX KCPSM Module Exercise Henry Fu 29
Testing a KCPSM Program in the Lab • Use UDPTEST to send the ROT 13 program packet –. /udptest. . /ROT 13. TBP • Use UDPSTR to send the data packet –. /udpstr –h 192. 168. 10. 1 –p 7 The FPX KCPSM Module Exercise Henry Fu 30
Testing a KCPSM Program in the Lab (More) • Screenshot of the encryption example: The FPX KCPSM Module Exercise Henry Fu 31
Testing a KCPSM Program in the Lab (More) • Screenshot of the decryption example: The FPX KCPSM Module Exercise Henry Fu 32
Conclusion • In this FPX KCPSM Module Exercise – Write, assemble, and debug a KCPSM program using KCPSMBLE, PSMDEBUG – Generate fake program and data ATM cells for simulation using CONVERT, IP 2 FAKE – Simulate a KCPSM program using Modelsim – Test a KCPSM program in the lab using UDPTEST, UDPSTR The FPX KCPSM Module Exercise Henry Fu 33