Laboratory 4
In laboratory 4 you will be using your system-on-chipi design from laboratory 3. In laboratory 3 you were required to write a C program which encrypted 64-bit data blocks using the OPB BlowFish hardware which was provided to you. In this laboratory you will be rewriting your C program in Microblaze assembly. Like in laboratory 3, at the end of this laboratory you should have a system-on-chipi design which is capable of encrypting and decrypting 64-bit data blocks with a 128-bit encryption key. The encryption and decryption itself is performed by the hardware.
Project Directions
The basic project directions for this laboratory are the same as for laboratory 3. For the hardware part of the lab you can simply reuse your existing design from laboratory 3. You can also use the laboratory 3 solution provided by your TA. For this laboratory you will need to create another software application using the Xilinxi tools and then implement that software application in MicroBlazei assembly. The MicroBlaze Assembly Tutorials provide a lot of useful and practical information and reading them will be invaluable towards completing this project. Additionally, the MicroBlaze Reference provides detailed information about all of the instructions supported by the MicroBlazei processor.
The steps required to complete this project are as follows:
- Make a copy of your laboratory 3 project or the reference solution provided by the TA
- Open the copy using Xilinxi Platform Studio
- Create a new software application
- Add a new source file named "lab4.S" to the software application
The actual file name "lab4" is not important, you can name the file anything you like. However, the file must have ".S" (a capital S) as the file extension to indicate that it is an assembly file. - Create a subroutine named "readline" in assembly
The readline subroutine will be used to read a line of input from the serial port into an array of bytes. Your read line routine should take as parameters a pointer to an array to fill with the data, an unsigned integer specifying the maximum number of bytes to read from the serial port, and a pointer to a string. The subroutine should then print out the string by calling the "xil_printf" C function. Afterward, the program should read input from the serial port until either the maximum number of bytes has been read or the user pressed the return key. - Create a subroutine named "printline" in assembly
The printline subroutine should take the same three parameters as the readline subroutine: an array pointer, the maximum bytes to output, and a string. The subroutine should first print out the string by calling the C function "xil_printf". After that the subroutine should print out the data in the array using the C function "xil_printf" until the maximum number of bytes to output has been reached. - Create a subroutine named "setkey" in assembly
The setkey subroutine should take a single parameters: a pointer to a 128-bit (16 byte) array of data. The subroutine should initialize the Blowfish hardware with this key in the same way as the hardware was initialized in laboratory 3. - Create a subroutine named "processblock" in assembly
The processblock subroutine should take two parameters: a pointer to a 64-bit (8 byte) array of data and an integer indicating whether encryption or decryption should be performed. The processblock routine should then place the data into the hardware registers, encrypt or decrypt the data, read the results out, and then place the results back into the data array. - Create a subroutine named "process" in assembly
The process subroutine should take four parameters: a pointer to an array of data, a pointer to an array of resulting data, an unsigned integer specifying the number of bytes to encrypt, and an unsigned integer which indicated encryption or decryption. The process subroutine will then need to encrypt or decrypt the contents of the data array, placing the results into the result array. The contents of the data array should not be changed during the encryption and decryption process. This subroutine should invoke processblock as part of its operation. - Create a subroutine named "main" in assembly
The main subroutine is the entry point of your program. The basic steps for successful completion of this project are the same as in laboratory 3. First, you should read a 128-bit key from the serial port using your readline subroutine and then initialize the hardware using that key with your setkey subroutine. Then you will, in an infinite loop, read up to 64-bytes of data from the serial port using your readline subroutine and encrypt that data using your process subroutine. After that you will decrypt the encrypted data, again using your process subroutine. Lastly, your will print your original data, the encrypted data, and the decrypted data using your printline subroutine.
