OpenCores
URL https://opencores.org/ocsvn/present/present/trunk

Subversion Repositories present

[/] [present/] [trunk/] [DecodeTesting/] [doc/] [src/] [present_decode_testing.tex] - Blame information for rev 20

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 gajos
\documentclass{gajewski}
2
 
3
\bibliographystyle{IEEEtran}
4
 
5
%%%%%%%%%%%%%%%%%
6
% Document variables
7
%%%%%%%%%%%%%%%%%
8
\docDate{ \today }
9
\docID{Present Decoder ("Decode Testing") - with communication channel with PC}
10 20 gajos
\docRevision{0.2}
11 17 gajos
\docStatus{Draft}
12
\docTitle{\mbox{Present Decoder ("Decode Testing") -} \mbox{with communication channel with PC}}
13
\docTitleShort{Present Decoder ("Decode Testing")...}
14
\authorName{\mbox{Krzysztof Gajewski} \\ and opencores.org}
15
\authorURL{www.opencores.org}
16
\authorAddress{\mbox{}}
17
\authorEmail{gajos@opencores.org}
18
 
19
\revisionList{
20
0.1 & all & 2014/05/25 & First draft & K. Gajewski \\
21 20 gajos
0.2 & all & 2014/09/16 & Some small corrections with the text, typos, etc. & K. Gajewski \\
22 17 gajos
}
23
 
24
\begin{document}
25
 
26
\maketitle
27
 
28
\newpage
29
 
30
\revisionTable
31
 
32
\newpage
33
 
34
\tableofcontents
35
\newpage
36
 
37
\section{Introduction}
38
 
39
Present is "ultra-lightweight" block cipher developed by A. Bogdanov et al. and proposed in 2007 \cite{PRESENT}. It uses 64 bit data block and 80 bit or 128 bit key.
40
This cipher consists of 32 rounds, during which:
41
\begin{itemize}
42
    \item round key is added to plaintext
43
    \item plaintext goes through sBoxes (substitution boxes)
44
    \item plaintext after sBoxes goes through pLayer (permutation layer)
45
    \item round key is updated
46
\end{itemize}
47
After that, ciphertext feeds out the output. Briefly algorithm was shown in Fig. \ref{pAlgorithm}
48
\begin{figure}[!ht]%
49
    \begin{center}
50
    \includegraphics[width=0.66\textwidth]{img/presentAlgorithm.png}
51
    \caption{%
52
        Briefly block scheme of the PRESENT block cipher
53
     }%
54
    \label{pAlgorithm}
55
    \end{center}
56
 \end{figure}
57
 
58 20 gajos
In subprojects \texttt{Pure} and \texttt{PureTesting} Present encoder components was presented. In this project Present decoder was presented. It was attached by shifting registers to RS-232 core developed by Digilent\textsuperscript{\textregistered} to enable communication with PC. Decoding key is firstly generated, basing on the key used for data coding. Next, input data are decoded (taking into account "inverse" direction to the presented in Fig. \ref{pAlgorithm}), and at last feeds the output. This core works with 80 bit key. Target was Xilinx\textsuperscript{\textregistered} Spartan 3E XC3S500E \cite{Spartan} on Spartan 3E  Starter Board \cite{Digilent} made by Digilent\textsuperscript{\textregistered}.
59 17 gajos
 
60
\newpage
61
 
62
\section{Interface}
63
 
64 20 gajos
Top level component of Present Decode Testing was shown in Fig. \ref{pdectest}. The number of inputs and outputs was limited due to RS-232 component in communication interface. All inputs and outputs are synchronous except \texttt{reset} signal and sampled at rising edge of the clock. All signals are \texttt{STD\_LOGIC}.
65 17 gajos
\begin{figure}[!ht]%
66
    \begin{center}
67
    \includegraphics[width=0.5\textwidth]{img/PresentDecodeTesting.png}
68
    \caption{%
69 20 gajos
        Top level component of the Present Decode Testing
70 17 gajos
     }%
71
    \label{pdectest}
72
    \end{center}
73
 \end{figure}
74
 
75
\begin{tabularx}{\textwidth}{|p{30mm}|p{11mm}|p{11mm}|X|}
76
  \hline \bf{Signal name} & \bf{Width} & \bf{In/Out} & \bf{Description}\\
77 20 gajos
  \hline \texttt{clk} & 1  &  in  & clock signal for the component. \\
78
  \hline \texttt{DATA\_RXD} & 1 & in & input data signal. \\
79
  \hline \texttt{reset} & 1  &  in  &  \emph{asynchronous} reset signal.\\
80
  \hline \texttt{DATA\_TXD} & 1 &  out  & output data signal.   \\
81 17 gajos
  \hline
82
\end{tabularx}
83 20 gajos
\captionof{table}{Input/Output signals of the Present Decode Testing component}
84 17 gajos
 
85
\newpage
86
 
87
\section{Internal structure and state machine workflow}
88
 
89 20 gajos
Internal datapath between components was shown in Fig. \ref{pdecinside}. All control signals, \texttt{clk} and \texttt{reset} was omitted for clearance. In these schamatic \texttt{keyReg}, \texttt{textReg} and \texttt{outReg} are shift registers enabling conversion of the input/output serial data into parallel data. They are respectively:
90 17 gajos
\begin{itemize}
91
    \item \texttt{keyReg} - shift register for the key used during decoding,
92
    \item \texttt{textReg} - shift register for the text to be decoded (to be more clearly \texttt{ciphertext}),
93
    \item \texttt{outReg} - shift register for the output data to be sendend by RS232 (to be more clearly \texttt{plaintext}).
94
\end{itemize}
95
\texttt{PresentFullDecoder} - is the decoding core. It was described in \texttt{./Decode/doc/present\_decode.pdf} file ("Decode" subproject documentation). \texttt{RS232} is the serial communication core developed by Digilent\textsuperscript{\textregistered} responsible for the communication with PC computer.
96
\texttt{PresentDecodeCommSM} is state machine which manage communication with PC and data conversion before and after data decoding in \texttt{PresentFullDecoder} component.
97
 
98
\begin{figure}[!ht]%
99
    \begin{center}
100
    \includegraphics[width=0.95\textwidth]{img/PresentDecodeCommInside.png}
101
    \caption{%
102 20 gajos
        Internal structure of the Present Decode Testing core with communication environment.
103 17 gajos
     }%
104
    \label{pdecinside}
105
    \end{center}
106
 \end{figure}
107
 
108 20 gajos
State machine states and transition between them was shown in Fig. \ref{presentDecodeCommSM}.
109 17 gajos
 
110
\begin{figure}[!ht]%
111
    \begin{center}
112
    \includegraphics[width=0.95\textwidth]{img/presentDecodeCommSM.png}
113
    \caption{%
114 20 gajos
        State machine of the Present Decode Testing decipher with added communication component
115 17 gajos
     }%
116
    \label{presentDecodeCommSM}
117
    \end{center}
118
 \end{figure}
119
 
120
 
121 20 gajos
In fact it is the same state machine as in \texttt{Present Pure Testing} subproject, but due to its length, will be reminded. State machine consist of following states:
122 17 gajos
 
123
\begin{itemize}
124 20 gajos
    \item \texttt{NOP} - this is the initial state of the state machine. It is set up after resetting the system. If any data appear in the RS-232 input (\texttt{RDAsig = '1'}), this state will be changed.
125
    \item \texttt{READ\_DATA\_TEXT} / \texttt{READ\_DATA\_KEY} - These states inform the RS-232 component that input data was read (by write enable in \texttt{keyReg} register).
126
    \item \texttt{DECODE\_READ\_TEXT} / \texttt{DECODE\_READ\_KEY}- In these states the number of performed data reading iterations are checked. Because one RS-232 packet was set to 8 bytes - 8 iterations need to be performed for reading full 64 bit text data input (10 iterations for reading full 80 bit key data input).
127 17 gajos
    \item \texttt{TEMP\_STATE} / \texttt{TEMP2\_STATE} / \texttt{TEMP\_OUT} - Here the counter is prepared for key reading / decoding / next "decoding session".
128
    \item \texttt{MOVE\_TEXT} / \texttt{MOVE\_KEY} / - Due to serial data in RS-232 component are stored in 8 bit register, they need to be shifted in appropriate place in given shift registers. It is performed by 8 shifts made in 8 clock cycles.
129
    \item \texttt{NOP\_FOR\_KEY} - Kind of \texttt{NOP} or wait state until 'key' data will arrive.
130
    \item \texttt{PRESENT\_ENCODE} - In this state Present decoding is performed. This state is active until Present component informs about ending of the decoding process (\texttt{readySig = '1'}). [In this part the naming may be a little bit confusing, but this not interfere the work of the core]
131
    \item \texttt{WRITE\_OUT} - state responsible for immediate sending decoded data. It is performed as many number as 64 bits of decoded data will be sent by the RS-232 component to the PC (similarly to "\texttt{DECODE...}" states).
132
    \item \texttt{MOVE\_OUT} - it is similar state to the previous \texttt{MOVE...} states, but here additionally state machine must wait until output data buffer will be prepared for next data which have to be sent.
133
\end{itemize}
134
No "lost data" checking, and data correction protocol was performed. It was assumed "ideal channel" for communication. Some states could be "merged" into one state but it will involve more expanded control logic.
135
 
136
\newpage
137
 
138
\section{FPGA implementations}
139
 
140 20 gajos
The  component  has been verified on a Xilinx\textsuperscript{\textregistered} Spartan 3E XC3S500E FPGA in FG320 package and synthesized  with  Xilinx  ISE  14.2. It was also implemented and practically tested on Spartan 3E Starter Board made by Digilent\textsuperscript{\textregistered}. Appropriate setup files was prepared with the use of ISE Project Navigator, but Makefile scripts was also written. Suitable files was stored in \texttt{./DecodeTesting/syn/XC3ES500/}  directory.
141 17 gajos
Makefile was tested in Windows 8 with use of Cygwin for 64-bit Windows.
142
 
143
Synthesis results was given in Fig. \ref{SynResults}
144
 
145
\begin{tabularx}{\textwidth}{|p{45mm}|p{30mm}|p{30mm}|X|}
146
  \hline \multicolumn{4}{|c|}{Xilinx\textsuperscript{\textregistered} Spartan 3E XC3S500E FPGA in FG320 package} \\
147
  \hline \bf{Parameter} & \bf{Used} & \bf{Available} & \bf{Utilization}\\
148
  \hline Number of Slices & 533 & 4656 & 11\% \\
149
  \hline Number of Slice Flip Flops & 530 & 9312 & 4\% \\
150
  \hline Number of 4 input LUTs & 582 & 9312 & 5\% \\
151
  \hline Number of bonded IOBs & 4 & 232 & 1\% \\
152
  \hline Number of GCLKs & 2 & 24 & 8\%\\
153
  \hline Minimum period & 6.343ns & - & - \\
154
  \hline Maximum Frequency & 157 MHz & - & - \\
155
  \hline
156
\end{tabularx}
157
\label{SynResults}
158
\captionof{table}{Synthesis results for Spartan 3E XC3S500E}
159
 
160
Possible change in used FPGA device may be possible in steps given below\footnotemark[1]:
161
\begin{enumerate}
162
    \item Copy \texttt{./DecodeTesting/syn/XC3ES500/} directory to another one like \\ \texttt{./DecodeTesting/syn/YOUR\_FPGA\_SYMBOL/}
163 20 gajos
    \item Go to \texttt{./DecodeTesting/syn/YOUR\_FPGA\_SYMBOL/}  directory.
164
    \item In \texttt{PresentDecodeComm.xst} file modify the line \texttt{-p xc3s500e-5-fg320} to \texttt{-p YOUR\_FPGA\_CODE}
165
    \item In \texttt{Makefile} file modify the line \texttt{PLATFORM=xc3s500e-fg320-5} to \texttt{PLATFORM=YOUR\_FPGA\_CODE}
166 17 gajos
\end{enumerate}
167
 
168
\textbf{WARNING!!!}
169 20 gajos
With this core there exist one issue related to communication process. It was observed, that every \textbf{first} decoding process after resetting the core, returns incorrect data (not observed during testing in ISE environment). Resending data and performing new calculations fix that. So, using this core it is desirable to force performing first "dummy" calculations after every reset.
170 17 gajos
 
171
\footnotetext[1]{This solution was not tested and is based on my own observations. Additional care should be taken with *.UCF files - this supplied with this project should be appropriate only for Spartan 3E Starter Board made by Digilent\textsuperscript{\textregistered}. You can make this modifications on your own risk}
172
 
173
\newpage
174
 
175
\section{Simulation and software}
176
 
177
\subsection{Simulation}
178
 
179
Self-checking test bench were provided to the components used for Present encoder with RS-232 communication. They are stored in \texttt{./DecodeTesting/bench/vhdl} directory. Suitable configuration files and Makefile used for running test bench was stored in \\
180
\texttt{./DecodeTesting/sim/rtl\_sim/bin} directory. Appropriate test vectors was taken from \cite{PRESENT}. In \texttt{PresentDecodeCommTB.vhd} file with suitable test files stored in \\
181
\texttt{./DecodeTesting/sim/rtl\_sim/bin/test} directory simulation of RS-232 communication was prepared. Due to that only this one test bench is not self checking. Observation and testing of the communication in this case will be most comfortable using isim gui.
182
 
183
Makefile was prepared to make "manual run" of tests. If You want to perform it without gui, remove \texttt{-gui} option in Makefaile.
184
 
185
\subsection{Software}
186
 
187
With this project two tool programs written in Java was included:
188
\begin{itemize}
189
    \item \texttt{PresentDataGenerator} (class with the same file name)
190
    \item "GUI Application" which consist of two classes (Communication.java and Window.java)
191
\end{itemize}
192
They were brought into Eclipse project, which can be easy imported. It was tested with Eclipse Indigo version.
193
 
194
First of them is used to prepare data for \texttt{PresentDecodeCommTB}. It can be used by:
195
\begin{itemize}
196
    \item Setting \texttt{drive}, \texttt{data} and \texttt{key} variables with hexadecimal values as it is desired.
197
    \item Running the compiler and running program.
198
\end{itemize}
199
 
200
On its output it sends set of bits which are sequentially sent to the PresentDecodeComm component during test bench.
201
 
202
"GUI application" enables communication with PC by use of RS-232 connection. RS-232 communication in Java is delivered by  \texttt{rxtx} library. It was partly based on tutorial which can be found at \cite{GUIComm}.
203
This program can be used as follow:
204
\begin{itemize}
205
    \item After connecting FPGA board to the RS-232 port click the "Connect" button.
206
    \item To the "Data" and "Key" write suitable hexadecimal data used for encoding.
207
    \item Press "Send" button.
208
    \item Answer should appear in "Log" box in hexadecimal values.
209
\end{itemize}
210
These programs were not prepared for unusual cases, so entering intended inappropriate values (like non hexadecimal values) are not recommended.
211
 
212
\newpage
213
 
214
\section{Troubleshooting}
215
 
216
During work with Windows 8 64-bit and and Xilinx\textsuperscript{\textregistered} ISE 64-bit some problems may occur:
217
 
218
\begin{enumerate}
219
    \item Xilinx may be unable to open projects in Project Navigator.
220
    \item When you run \texttt{make} in Cygwin and perform testbench it would be unable to open ISIM gui.
221
    \item When you run ISIM gui  (*.exe test bench file) it hangs out or anti virus protection opens.
222
\end{enumerate}
223
 
224
To solve problems listed above you have to perform steps listed below:
225
\begin{enumerate}
226
    \item You have to rename libraries \texttt{libPortabilityNOSH.dll} to \texttt{libPortability.dll} from \texttt{nt64} directories (\href{http://www.gadgetfactory.net/2013/09/having-problems-installing-xilinx-ise-on-windows-8-64bit-here-is-a-fix-video-included/}{http://www.gadgetfactory.net/2013/09/having-problems-installing-xilinx-ise-on-windows-8-64bit-here-is-a-fix-video-included/})
227
    \item Firstly, install Cygwin X11 (\href{http://stackoverflow.com/questions/9393462/cannot-launch-git-gui-using-cygwin-on-windows}{http://stackoverflow.com/questions/9393462/cannot-launch-git-gui-using-cygwin-on-windows})
228
    \item Temporary switch off anti virus protection.
229
\end{enumerate}
230
 
231
\newpage
232
 
233
\section{License and Liability}
234
Copyright\textcopyright \space 2013 Authors and OPENCORES.ORG
235
 
236
This source file may be used and distributed without
237
restriction provided that this copyright statement is not
238
removed from the file and that any derivative work contains
239
the original copyright notice and the associated disclaimer.
240
 
241
This source file is free software; you can redistribute it
242
and-or modify it under the terms of the GNU Lesser General
243
Public License as published by the Free Software Foundation;
244
either version 2.1 of the License, or (at your option) any
245
later version.
246
 
247
This source is distributed in the hope that it will be
248
useful, but WITHOUT ANY WARRANTY; without even the implied
249
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
250
PURPOSE. See the GNU Lesser General Public License for more
251
details.
252
 
253
You should have received a copy of the GNU Lesser General
254
Public License along with this source; if not, download it
255
from \href{http://www.opencores.org/lgpl.shtml}{http://www.opencores.org/lgpl.shtml}
256
 
257
Xilinx, Spartan3E is registered trademark of Xilinx Inc. 2100 Logic Drive, San Jose CA USA
258
 
259
\newpage
260
 
261
\bibliography{bibliography}
262
 
263
\end{document}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.