Browse Source

Update & restructure DES testbench to use openSSL and random simuli

T. Meissner 1 week ago
parent
commit
81df6e0215
5 changed files with 698 additions and 348 deletions
  1. 94
    0
      des/sim/vhdl/Makefile
  2. 0
    40
      des/sim/vhdl/makefile
  3. 182
    0
      des/sim/vhdl/tb_des.c
  4. 294
    308
      des/sim/vhdl/tb_des.vhd
  5. 128
    0
      des/sim/vhdl/tb_des_pkg.vhd

+ 94
- 0
des/sim/vhdl/Makefile View File

@@ -0,0 +1,94 @@
1
+# ======================================================================
2
+# DES encryption/decryption
3
+# algorithm according to FIPS 46-3 specification
4
+# Copyright (C) 2011 Torsten Meissner
5
+#-----------------------------------------------------------------------
6
+# This program is free software; you can redistribute it and/or modify
7
+# it under the terms of the GNU General Public License as published by
8
+# the Free Software Foundation; either version 2 of the License, or
9
+# (at your option) any later version.
10
+
11
+# This program is distributed in the hope that it will be useful,
12
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+# GNU General Public License for more details.
15
+
16
+# You should have received a copy of the GNU General Public License
17
+# along with this program; if not, write to the Free Software
18
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
+# ======================================================================
20
+
21
+
22
+TB := tb_des
23
+
24
+RTL_SRC := \
25
+  ../../rtl/vhdl/des_pkg.vhd \
26
+  ../../rtl/vhdl/des.vhd
27
+
28
+
29
+SIM_SRC   := ${TB}_pkg.vhd ${TB}.vhd
30
+C_SRC     := ${TB}.c
31
+
32
+OSVVM_DIR := ../../../lib/osvvm
33
+OSVVM_SRC := \
34
+  ${OSVVM_DIR}/NamePkg.vhd  \
35
+  ${OSVVM_DIR}/OsvvmGlobalPkg.vhd  \
36
+  ${OSVVM_DIR}/VendorCovApiPkg.vhd  \
37
+  ${OSVVM_DIR}/TranscriptPkg.vhd  \
38
+  ${OSVVM_DIR}/TextUtilPkg.vhd  \
39
+  ${OSVVM_DIR}/AlertLogPkg.vhd  \
40
+  ${OSVVM_DIR}/MessagePkg.vhd  \
41
+  ${OSVVM_DIR}/SortListPkg_int.vhd  \
42
+  ${OSVVM_DIR}/RandomBasePkg.vhd  \
43
+  ${OSVVM_DIR}/RandomPkg.vhd  \
44
+  ${OSVVM_DIR}/CoveragePkg.vhd  \
45
+  ${OSVVM_DIR}/MemoryPkg.vhd  \
46
+  ${OSVVM_DIR}/ScoreboardGenericPkg.vhd  \
47
+  ${OSVVM_DIR}/ScoreboardPkg_slv.vhd  \
48
+  ${OSVVM_DIR}/ScoreboardPkg_int.vhd  \
49
+  ${OSVVM_DIR}/ResolutionPkg.vhd  \
50
+  ${OSVVM_DIR}/TbUtilPkg.vhd  \
51
+  ${OSVVM_DIR}/OsvvmContext.vhd
52
+
53
+VHD_STD := 08
54
+
55
+
56
+.PHONY: sim
57
+sim: ${TB}.ghw
58
+
59
+
60
+.PHONY: compile
61
+compile: ${TB}
62
+
63
+
64
+osvvm work:
65
+	mkdir $@
66
+
67
+
68
+osvvm/OsvvmContext.o: ${OSVVM_SRC} | osvvm
69
+	@echo "Analyze OSVVM library ..."
70
+	ghdl -a --std=${VHD_STD} -Wno-hide --work=osvvm --workdir=osvvm ${OSVVM_SRC}
71
+
72
+
73
+${TB}: ${RTL_SRC} ${SIM_SRC} ${C_SRC} osvvm/OsvvmContext.o | work
74
+	@echo "Analyze testbench & design ..."
75
+	ghdl -a --std=${VHD_STD} -fpsl --workdir=work -P=osvvm ${RTL_SRC} ${SIM_SRC}
76
+	@echo "Elaborate testbench & design ..."
77
+	ghdl -e --std=${VHD_STD} -fpsl --workdir=work -P=osvvm -Wl,$@.c -Wl,-lcrypto -Wl,-lssl $@
78
+
79
+
80
+${TB}.ghw: ${TB}
81
+	@echo "Run testbench ..."
82
+	ghdl -r $(basename $@) --wave=$@ --assert-level=error --psl-report=$(basename $@)_psl_report.json
83
+
84
+
85
+.PHONY: wave
86
+wave: ${TB}.ghw
87
+	@echo "Run GTKwave ..."
88
+	gtkwave -S ${TB}.tcl $@
89
+
90
+
91
+.PHONY: clean
92
+clean:
93
+	@echo "Cleaning simulation files ..."
94
+	rm -rf ${TB} ${TB}.ghw *.o *.json work/ osvvm/

+ 0
- 40
des/sim/vhdl/makefile View File

@@ -1,40 +0,0 @@
1
-# ======================================================================
2
-# DES encryption/decryption
3
-# algorithm according to FIPS 46-3 specification
4
-# Copyright (C) 2011 Torsten Meissner
5
-#-----------------------------------------------------------------------
6
-# This program is free software; you can redistribute it and/or modify
7
-# it under the terms of the GNU General Public License as published by
8
-# the Free Software Foundation; either version 2 of the License, or
9
-# (at your option) any later version.
10
-
11
-# This program is distributed in the hope that it will be useful,
12
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
-# GNU General Public License for more details.
15
-
16
-# You should have received a copy of the GNU General Public License
17
-# along with this program; if not, write to the Free Software
18
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
-# ======================================================================
20
-
21
-
22
-all : sim wave
23
-
24
-sim : tb_des.ghw
25
-
26
-
27
-tb_des.ghw : ../../rtl/vhdl/*.vhd tb_des.vhd
28
-	ghdl -a ../../rtl/vhdl/des_pkg.vhd ../../rtl/vhdl/des.vhd tb_des.vhd
29
-	ghdl -e tb_des
30
-	ghdl -r tb_des --wave=tb_des.ghw --assert-level=error --stop-time=100us
31
-
32
-wave : tb_des.ghw
33
-	gtkwave -S tb_des.tcl tb_des.ghw
34
-
35
-clean :
36
-	echo "# cleaning simulation files"
37
-	rm -f tb_des
38
-	rm -f *.o
39
-	rm -f tb_des.ghw
40
-	rm -f work*.cf

+ 182
- 0
des/sim/vhdl/tb_des.c View File

@@ -0,0 +1,182 @@
1
+#include <stdio.h>
2
+#include <string.h>
3
+#include <openssl/conf.h>
4
+#include <openssl/evp.h>
5
+#include <openssl/err.h>
6
+
7
+static const char HDL_LOGIC_CHAR[] = { 'U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-'};
8
+
9
+enum HDL_LOGIC_STATES {
10
+HDL_U = 0,
11
+HDL_X = 1,
12
+HDL_0 = 2,
13
+HDL_1 = 3,
14
+HDL_Z = 4,
15
+HDL_W = 5,
16
+HDL_L = 6,
17
+HDL_H = 7,
18
+HDL_D = 8,
19
+};
20
+
21
+
22
+
23
+void slv_to_uchar(char* datain, unsigned char* dataout, int bytelen) {
24
+
25
+  for (int i = 0; i < bytelen; i++) {
26
+    for (int y = 0; y < 8; y++) {
27
+      if (*datain == HDL_1) {
28
+        *dataout |= 1 << y;
29
+      } else if (*datain == HDL_0) {
30
+        *dataout &= ~(1 << y);
31
+      }
32
+      datain++;
33
+    }
34
+    dataout++;
35
+  }
36
+
37
+  return;
38
+
39
+}
40
+
41
+
42
+void slv_to_string(char* datain, char* dataout, int bytelen) {
43
+
44
+  for (int i = 0; i < bytelen; i++) {
45
+    *dataout = HDL_LOGIC_CHAR[*datain];
46
+    datain++;
47
+    dataout++;
48
+  }
49
+
50
+  return;
51
+
52
+}
53
+
54
+
55
+void uchar_to_slv(unsigned char* datain, char* dataout, int bytelen) {
56
+
57
+  for (int i = 0; i < bytelen; i++) {
58
+    for (int y = 0; y < 8; y++) {
59
+      if ((*datain >> y) & 1 == 1) {
60
+        *dataout = HDL_1 ;
61
+      } else {
62
+        *dataout = HDL_0;
63
+      }
64
+      dataout++;
65
+    }
66
+    datain++;
67
+  }
68
+
69
+  return;
70
+
71
+}
72
+
73
+
74
+void handleErrors(void) {
75
+
76
+  ERR_print_errors_fp(stderr);
77
+  abort();
78
+
79
+}
80
+
81
+
82
+int encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key,
83
+            unsigned char *ciphertext) {
84
+
85
+  EVP_CIPHER_CTX *ctx;
86
+
87
+  int len;
88
+  int ciphertext_len;
89
+
90
+  // Create and initialise the context
91
+  if(!(ctx = EVP_CIPHER_CTX_new()))
92
+      handleErrors();
93
+
94
+  // Initialise the encryption operation, no IV needed in ECB mode
95
+  if(1 != EVP_EncryptInit_ex(ctx, EVP_des_ecb(), NULL, key, NULL))
96
+      handleErrors();
97
+
98
+  // We don't want padding
99
+  if(1 != EVP_CIPHER_CTX_set_padding(ctx, 0))
100
+    handleErrors();
101
+
102
+  // Provide the message to be encrypted, and obtain the encrypted output
103
+  if(1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len))
104
+      handleErrors();
105
+  ciphertext_len = len;
106
+
107
+  //  Finalise the encryption. No further bytes are written as padding is switched off
108
+  if(1 != EVP_EncryptFinal_ex(ctx, ciphertext + len, &len))
109
+      handleErrors();
110
+  ciphertext_len += len;
111
+
112
+  // Clean up
113
+  EVP_CIPHER_CTX_free(ctx);
114
+
115
+  return ciphertext_len;
116
+
117
+}
118
+
119
+
120
+int decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key,
121
+            unsigned char *plaintext) {
122
+
123
+  EVP_CIPHER_CTX *ctx;
124
+
125
+  int len;
126
+  int plaintext_len;
127
+
128
+  // Create and initialise the context
129
+  if(!(ctx = EVP_CIPHER_CTX_new()))
130
+      handleErrors();
131
+
132
+  // Initialise the decryption operation, no IV needed in ECB mode
133
+  if(1 != EVP_DecryptInit_ex(ctx, EVP_des_ecb(), NULL, key, NULL))
134
+      handleErrors();
135
+
136
+  // We don't want padding
137
+  if(1 != EVP_CIPHER_CTX_set_padding(ctx, 0))
138
+    handleErrors();
139
+
140
+  // Provide the message to be decrypted, and obtain the decrypted output
141
+  if(1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
142
+      handleErrors();
143
+  plaintext_len = len;
144
+
145
+  //  Finalise the decryption. No further bytes are written as padding is switched off
146
+  if(1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
147
+      handleErrors();
148
+  plaintext_len += len;
149
+
150
+  // Clean up
151
+  EVP_CIPHER_CTX_free(ctx);
152
+
153
+  return plaintext_len;
154
+
155
+}
156
+
157
+
158
+void cryptData(char* datain, char* key, char mode, char* dataout, int bytelen) {
159
+
160
+  int crypt_len;
161
+  unsigned char c_din[bytelen];
162
+  unsigned char c_key[bytelen];
163
+  unsigned char c_dout[bytelen];
164
+
165
+  slv_to_uchar(datain, c_din, bytelen);
166
+  slv_to_uchar(key, c_key, bytelen);
167
+
168
+  if (mode) {
169
+    crypt_len = encrypt(c_din, bytelen, c_key, c_dout);
170
+  } else {
171
+    crypt_len = decrypt(c_din, bytelen, c_key, c_dout);
172
+  }
173
+
174
+  if (crypt_len != 8) {
175
+    printf("Warning: crypt operation returned with unexpected length %d\n", crypt_len);
176
+  }
177
+
178
+  uchar_to_slv(c_dout, dataout, bytelen);
179
+
180
+  return;
181
+
182
+}

+ 294
- 308
des/sim/vhdl/tb_des.vhd View File

@@ -23,6 +23,14 @@ library ieee;
23 23
   use ieee.std_logic_1164.all;
24 24
   use ieee.numeric_std.all;
25 25
 
26
+library osvvm;
27
+  use osvvm.RandomPkg.all;
28
+
29
+use std.env.all;
30
+
31
+use work.des_pkg.all;
32
+use work.tb_des_pkg.all;
33
+
26 34
 
27 35
 entity tb_des is
28 36
 end entity tb_des;
@@ -31,106 +39,6 @@ end entity tb_des;
31 39
 architecture rtl of tb_des is
32 40
 
33 41
 
34
-  type t_array is array (natural range <>) of std_logic_vector(0 to 63);
35
-
36
-  constant c_variable_plaintext_known_answers : t_array(0 to 63) :=
37
-    (x"95F8A5E5DD31D900", x"DD7F121CA5015619", x"2E8653104F3834EA",
38
-     x"4BD388FF6CD81D4F", x"20B9E767B2FB1456", x"55579380D77138EF",
39
-     x"6CC5DEFAAF04512F", x"0D9F279BA5D87260", x"D9031B0271BD5A0A",
40
-     x"424250B37C3DD951", x"B8061B7ECD9A21E5", x"F15D0F286B65BD28",
41
-     x"ADD0CC8D6E5DEBA1", x"E6D5F82752AD63D1", x"ECBFE3BD3F591A5E",
42
-     x"F356834379D165CD", x"2B9F982F20037FA9", x"889DE068A16F0BE6",
43
-     x"E19E275D846A1298", x"329A8ED523D71AEC", x"E7FCE22557D23C97",
44
-     x"12A9F5817FF2D65D", x"A484C3AD38DC9C19", x"FBE00A8A1EF8AD72",
45
-     x"750D079407521363", x"64FEED9C724C2FAF", x"F02B263B328E2B60",
46
-     x"9D64555A9A10B852", x"D106FF0BED5255D7", x"E1652C6B138C64A5",
47
-     x"E428581186EC8F46", x"AEB5F5EDE22D1A36", x"E943D7568AEC0C5C",
48
-     x"DF98C8276F54B04B", x"B160E4680F6C696F", x"FA0752B07D9C4AB8",
49
-     x"CA3A2B036DBC8502", x"5E0905517BB59BCF", x"814EEB3B91D90726",
50
-     x"4D49DB1532919C9F", x"25EB5FC3F8CF0621", x"AB6A20C0620D1C6F",
51
-     x"79E90DBC98F92CCA", x"866ECEDD8072BB0E", x"8B54536F2F3E64A8",
52
-     x"EA51D3975595B86B", x"CAFFC6AC4542DE31", x"8DD45A2DDF90796C",
53
-     x"1029D55E880EC2D0", x"5D86CB23639DBEA9", x"1D1CA853AE7C0C5F",
54
-     x"CE332329248F3228", x"8405D1ABE24FB942", x"E643D78090CA4207",
55
-     x"48221B9937748A23", x"DD7C0BBD61FAFD54", x"2FBC291A570DB5C4",
56
-     x"E07C30D7E4E26E12", x"0953E2258E8E90A1", x"5B711BC4CEEBF2EE",
57
-     x"CC083F1E6D9E85F6", x"D2FD8867D50D2DFE", x"06E7EA22CE92708F",
58
-     x"166B40B44ABA4BD6");
59
-
60
-  constant c_variable_key_known_answers : t_array(0 to 55) :=
61
-    (x"95A8D72813DAA94D", x"0EEC1487DD8C26D5", x"7AD16FFB79C45926",
62
-     x"D3746294CA6A6CF3", x"809F5F873C1FD761", x"C02FAFFEC989D1FC",
63
-     x"4615AA1D33E72F10", x"2055123350C00858", x"DF3B99D6577397C8",
64
-     x"31FE17369B5288C9", x"DFDD3CC64DAE1642", x"178C83CE2B399D94",
65
-     x"50F636324A9B7F80", x"A8468EE3BC18F06D", x"A2DC9E92FD3CDE92",
66
-     x"CAC09F797D031287", x"90BA680B22AEB525", x"CE7A24F350E280B6",
67
-     x"882BFF0AA01A0B87", x"25610288924511C2", x"C71516C29C75D170",
68
-     x"5199C29A52C9F059", x"C22F0A294A71F29F", x"EE371483714C02EA",
69
-     x"A81FBD448F9E522F", x"4F644C92E192DFED", x"1AFA9A66A6DF92AE",
70
-     x"B3C1CC715CB879D8", x"19D032E64AB0BD8B", x"3CFAA7A7DC8720DC",
71
-     x"B7265F7F447AC6F3", x"9DB73B3C0D163F54", x"8181B65BABF4A975",
72
-     x"93C9B64042EAA240", x"5570530829705592", x"8638809E878787A0",
73
-     x"41B9A79AF79AC208", x"7A9BE42F2009A892", x"29038D56BA6D2745",
74
-     x"5495C6ABF1E5DF51", x"AE13DBD561488933", x"024D1FFA8904E389",
75
-     x"D1399712F99BF02E", x"14C1D7C1CFFEC79E", x"1DE5279DAE3BED6F",
76
-     x"E941A33F85501303", x"DA99DBBC9A03F379", x"B7FC92F91D8E92E9",
77
-     x"AE8E5CAA3CA04E85", x"9CC62DF43B6EED74", x"D863DBB5C59A91A0",
78
-     x"A1AB2190545B91D7", x"0875041E64C570F7", x"5A594528BEBEF1CC",
79
-     x"FCDB3291DE21F0C0", x"869EFD7F9F265A09");
80
-
81
-  constant c_permutation_operation_known_answers_keys : t_array(0 to 31) :=
82
-    (x"1046913489980131", x"1007103489988020", x"10071034C8980120",
83
-     x"1046103489988020", x"1086911519190101", x"1086911519580101",
84
-     x"5107B01519580101", x"1007B01519190101", x"3107915498080101",
85
-     x"3107919498080101", x"10079115B9080140", x"3107911598080140",
86
-     x"1007D01589980101", x"9107911589980101", x"9107D01589190101",
87
-     x"1007D01598980120", x"1007940498190101", x"0107910491190401",
88
-     x"0107910491190101", x"0107940491190401", x"19079210981A0101",
89
-     x"1007911998190801", x"10079119981A0801", x"1007921098190101",
90
-     x"100791159819010B", x"1004801598190101", x"1004801598190102",
91
-     x"1004801598190108", x"1002911598100104", x"1002911598190104",
92
-     x"1002911598100201", x"1002911698100101");
93
-
94
-  constant c_permutation_operation_known_answers_cipher : t_array(0 to 31) :=
95
-    (x"88D55E54F54C97B4", x"0C0CC00C83EA48FD", x"83BC8EF3A6570183",
96
-     x"DF725DCAD94EA2E9", x"E652B53B550BE8B0", x"AF527120C485CBB0",
97
-     x"0F04CE393DB926D5", x"C9F00FFC74079067", x"7CFD82A593252B4E",
98
-     x"CB49A2F9E91363E3", x"00B588BE70D23F56", x"406A9A6AB43399AE",
99
-     x"6CB773611DCA9ADA", x"67FD21C17DBB5D70", x"9592CB4110430787",
100
-     x"A6B7FF68A318DDD3", x"4D102196C914CA16", x"2DFA9F4573594965",
101
-     x"B46604816C0E0774", x"6E7E6221A4F34E87", x"AA85E74643233199",
102
-     x"2E5A19DB4D1962D6", x"23A866A809D30894", x"D812D961F017D320",
103
-     x"055605816E58608F", x"ABD88E8B1B7716F1", x"537AC95BE69DA1E1",
104
-     x"AED0F6AE3C25CDD8", x"B3E35A5EE53E7B8D", x"61C79C71921A2EF8",
105
-     x"E2F5728F0995013C", x"1AEAC39A61F0A464");
106
-
107
-  constant c_substitution_table_test_keys : t_array(0 to 18) :=
108
-    (x"7CA110454A1A6E57", x"0131D9619DC1376E", x"07A1133E4A0B2686",
109
-     x"3849674C2602319E", x"04B915BA43FEB5B6", x"0113B970FD34F2CE",
110
-     x"0170F175468FB5E6", x"43297FAD38E373FE", x"07A7137045DA2A16",
111
-     x"04689104C2FD3B2F", x"37D06BB516CB7546", x"1F08260D1AC2465E",
112
-     x"584023641ABA6176", x"025816164629B007", x"49793EBC79B3258F",
113
-     x"4FB05E1515AB73A7", x"49E95D6D4CA229BF", x"018310DC409B26D6",
114
-     x"1C587F1C13924FEF");
115
-
116
-  constant c_substitution_table_test_plain : t_array(0 to 18) :=
117
-    (x"01A1D6D039776742", x"5CD54CA83DEF57DA", x"0248D43806F67172",
118
-     x"51454B582DDF440A", x"42FD443059577FA2", x"059B5E0851CF143A",
119
-     x"0756D8E0774761D2", x"762514B829BF486A", x"3BDD119049372802",
120
-     x"26955F6835AF609A", x"164D5E404F275232", x"6B056E18759F5CCA",
121
-     x"004BD6EF09176062", x"480D39006EE762F2", x"437540C8698F3CFA",
122
-     x"072D43A077075292", x"02FE55778117F12A", x"1D9D5C5018F728C2",
123
-     x"305532286D6F295A");
124
-
125
-  constant c_substitution_table_test_cipher : t_array(0 to 18) :=
126
-    (x"690F5B0D9A26939B", x"7A389D10354BD271", x"868EBB51CAB4599A",
127
-     x"7178876E01F19B2A", x"AF37FB421F8C4095", x"86A560F10EC6D85B",
128
-     x"0CD3DA020021DC09", x"EA676B2CB7DB2B7A", x"DFD64A815CAF1A0F",
129
-     x"5C513C9C4886C088", x"0A2AEEAE3FF4AB77", x"EF1BF03E5DFA575A",
130
-     x"88BF0DB6D70DEE56", x"A1F9915541020B56", x"6FBF1CAFCFFD0556",
131
-     x"2F22E49BAB7CA1AC", x"5A6B612CC26CCE4A", x"5F4C038ED12B2E41",
132
-     x"63FAC0D034D9F793");
133
-
134 42
   signal s_reset     : std_logic := '0';
135 43
   signal s_clk       : std_logic := '0';
136 44
   signal s_mode      : std_logic := '0';
@@ -143,23 +51,27 @@ architecture rtl of tb_des is
143 51
   signal s_acceptin  : std_logic;
144 52
 
145 53
 
146
-  component des is
147
-    generic (
148
-      design_type : string := "ITER"
149
-    );
150
-    port (
151
-      reset_i     : in  std_logic;
152
-      clk_i       : in  std_logic;
153
-      mode_i      : in  std_logic;
154
-      key_i       : in  std_logic_vector(0 TO 63);
155
-      data_i      : in  std_logic_vector(0 TO 63);
156
-      valid_i     : in  std_logic;
157
-      accept_o    : out std_logic;
158
-      data_o      : out std_logic_vector(0 TO 63);
159
-      valid_o     : out std_logic;
160
-      accept_i    : in  std_logic
161
-    );
162
-  end component des;
54
+  procedure cryptData(datain  : in  std_logic_vector(0 to 63);
55
+                      key     : in  std_logic_vector(0 to 63);
56
+                      mode    : in  boolean;
57
+                      dataout : out std_logic_vector(0 to 63);
58
+                      bytelen : in  integer) is
59
+  begin
60
+    report "VHPIDIRECT cryptData" severity failure;
61
+  end procedure;
62
+
63
+  attribute foreign of cryptData: procedure is "VHPIDIRECT cryptData";
64
+
65
+  function swap (datain : std_logic_vector(0 to 63)) return std_logic_vector is
66
+    variable v_data : std_logic_vector(0 to 63);
67
+  begin
68
+    for i in 0 to 7 loop
69
+      for y in 0 to 7 loop
70
+        v_data((i*8)+y) := datain((i*8)+7-y);
71
+      end loop;
72
+    end loop;
73
+    return v_data;
74
+  end function;
163 75
 
164 76
 
165 77
 begin
@@ -169,256 +81,330 @@ begin
169 81
   s_reset <= '1' after 100 ns;
170 82
 
171 83
 
172
-  teststimuliP : process is
84
+  testP : process is
85
+    variable v_key       : std_logic_vector(0 to 63);
86
+    variable v_datain    : std_logic_vector(0 to 63);
87
+    variable v_dataout   : std_logic_vector(0 to 63);
88
+    variable v_plaintext : std_logic_vector(0 to 63) := x"8000000000000000";
89
+    variable v_random    : RandomPType;
173 90
   begin
174 91
     -- ENCRYPTION TESTS
175
-    s_mode    <= '0';
176
-    s_validin <= '0';
177
-    s_key     <= x"0101010101010101";
178
-    s_datain  <= x"8000000000000000";
92
+    s_validin  <= '0';
93
+    s_acceptin <= '0';
94
+    s_mode     <= '0';
95
+    s_datain   <= (others => '0');
96
+    s_key      <= (others => '0');
179 97
     wait until s_reset = '1';
180
-    wait until rising_edge(s_clk);
98
+    report "# ENCRYPTION TESTS";
99
+
181 100
     -- Variable plaintext known answer test
101
+    report "# Variable plaintext known answer test";
102
+    v_key     := x"0101010101010101";
103
+    v_datain  := x"8000000000000000";
182 104
     for index in c_variable_plaintext_known_answers'range loop
105
+      wait until rising_edge(s_clk);
183 106
       s_validin <= '1';
184
-      if(index /= 0) then
185
-        s_datain <= '0' & s_datain(0 to 62);
186
-      end if;
107
+      s_key     <= v_key;
108
+      s_datain  <= v_datain;
109
+      cryptData(swap(v_datain), swap(v_key), true, v_dataout, v_datain'length/8);
187 110
       wait until rising_edge(s_clk) and s_acceptout = '1';
111
+      s_validin <= '0';
112
+      wait until rising_edge(s_clk) and s_validout = '1';
113
+      s_acceptin <= '1';
114
+      assert s_dataout = c_variable_plaintext_known_answers(index)
115
+        report "Encryption error"
116
+        severity failure;
117
+      assert s_dataout = swap(v_dataout)
118
+        report "Encryption openSSL reference error"
119
+        severity failure;
120
+      wait until rising_edge(s_clk);
121
+      s_acceptin <= '0';
122
+      v_datain  := '0' & v_datain(0 to 62);
188 123
     end loop;
189
-    s_mode    <= '0';
190
-    s_validin <= '0';
191
-    s_key     <= (others => '0');
192
-    s_datain  <= (others => '0');
193
-    wait for 100 ns;
194
-    wait until rising_edge(s_clk);
124
+
195 125
     -- Inverse permutation known answer test
196
-    s_key     <= x"0101010101010101";
126
+    report "# Inverse permutation known answer test";
127
+    v_key := x"0101010101010101";
197 128
     for index in c_variable_plaintext_known_answers'range loop
129
+      v_datain  := c_variable_plaintext_known_answers(index);
198 130
       s_validin <= '1';
199
-      s_datain  <= c_variable_plaintext_known_answers(index);
131
+      s_key     <= v_key;
132
+      s_datain  <= v_datain;
133
+      cryptData(swap(v_datain), swap(v_key), true, v_dataout, v_datain'length/8);
200 134
       wait until rising_edge(s_clk) and s_acceptout = '1';
135
+      s_validin <= '0';
136
+      wait until rising_edge(s_clk) and s_validout = '1';
137
+      s_acceptin <= '1';
138
+      assert s_dataout = v_plaintext
139
+        report "Encryption error"
140
+        severity failure;
141
+      assert s_dataout = swap(v_dataout)
142
+        report "Encryption openSSL reference error"
143
+        severity failure;
144
+      wait until rising_edge(s_clk);
145
+      s_acceptin <= '0';
146
+      v_plaintext := '0' & v_plaintext(0 to 62);
201 147
     end loop;
202
-    s_mode    <= '0';
203
-    s_validin <= '0';
204
-    s_key     <= (others => '0');
205
-    s_datain  <= (others => '0');
206
-    wait for 100 ns;
207
-    wait until rising_edge(s_clk);
148
+
208 149
     -- Variable key known answer test
209
-    s_key     <= x"8000000000000000";
150
+    report "# Variable key known answer test";
151
+    v_key     := x"8000000000000000";
152
+    v_datain  := (others => '0');
210 153
     for index in c_variable_key_known_answers'range loop
211 154
       s_validin <= '1';
212
-      if(index /= 0) then
213
-        if(index = 7 or index = 14 or index = 21 or index = 28 or index = 35 or
214
-           index = 42 or index = 49) then
215
-          s_key <= "00" & s_key(0 to 61);
216
-        else
217
-          s_key <= '0' & s_key(0 to 62);
218
-        end if;
219
-      end if;
155
+      s_key     <= v_key;
156
+      s_datain  <= v_datain;
157
+      cryptData(swap(v_datain), swap(v_key), true, v_dataout, v_datain'length/8);
220 158
       wait until rising_edge(s_clk) and s_acceptout = '1';
159
+      s_validin <= '0';
160
+      wait until rising_edge(s_clk) and s_validout = '1';
161
+      s_acceptin <= '1';
162
+      assert s_dataout = c_variable_key_known_answers(index)
163
+        report "Encryption error"
164
+        severity failure;
165
+      assert s_dataout = swap(v_dataout)
166
+        report "Encryption openSSL reference error"
167
+        severity failure;
168
+      wait until rising_edge(s_clk);
169
+      s_acceptin <= '0';
170
+      if (index = 6 or index = 13 or index = 20 or index = 27 or index = 34 or
171
+          index = 41 or index = 48) then
172
+        v_key := "00" & v_key(0 to 61);
173
+      else
174
+        v_key := '0' & v_key(0 to 62);
175
+      end if;
221 176
     end loop;
222
-    s_mode    <= '0';
223
-    s_validin <= '0';
224
-    s_key     <= (others => '0');
225
-    s_datain  <= (others => '0');
226
-    wait for 100 ns;
227
-    wait until rising_edge(s_clk);
177
+
228 178
     -- Permutation operation known answer test
229
-    s_datain <= x"0000000000000000";
179
+    report "# Permutation operation known answer test";
180
+    v_datain  := (others => '0');
230 181
     for index in c_permutation_operation_known_answers_keys'range loop
182
+      wait until rising_edge(s_clk);
183
+      v_key     := c_permutation_operation_known_answers_keys(index);
231 184
       s_validin <= '1';
232
-      s_key     <= c_permutation_operation_known_answers_keys(index);
185
+      s_key     <= v_key;
186
+      s_datain  <= v_datain;
187
+      cryptData(swap(v_datain), swap(v_key), true, v_dataout, v_datain'length/8);
233 188
       wait until rising_edge(s_clk) and s_acceptout = '1';
189
+      s_validin <= '0';
190
+      wait until rising_edge(s_clk) and s_validout = '1';
191
+      s_acceptin <= '1';
192
+      assert s_dataout = c_permutation_operation_known_answers_cipher(index)
193
+        report "Encryption error"
194
+        severity failure;
195
+      assert s_dataout = swap(v_dataout)
196
+        report "Encryption openSSL reference error"
197
+        severity failure;
198
+      wait until rising_edge(s_clk);
199
+      s_acceptin <= '0';
234 200
     end loop;
235
-    s_mode    <= '0';
236
-    s_validin <= '0';
237
-    s_key     <= (others => '0');
238
-    s_datain  <= (others => '0');
239
-    wait for 100 ns;
240
-    wait until rising_edge(s_clk);
201
+
241 202
     -- Substitution table known answer test
203
+    report "# Substitution table known answer test";
242 204
     for index in c_substitution_table_test_keys'range loop
205
+      wait until rising_edge(s_clk);
206
+      v_key     := c_substitution_table_test_keys(index);
207
+      v_datain  := c_substitution_table_test_plain(index);
208
+      s_validin <= '1';
209
+      s_key     <= v_key;
210
+      s_datain  <= v_datain;
211
+      cryptData(swap(v_datain), swap(v_key), true, v_dataout, v_datain'length/8);
212
+      wait until rising_edge(s_clk) and s_acceptout = '1';
213
+      s_validin <= '0';
214
+      wait until rising_edge(s_clk) and s_validout = '1';
215
+      s_acceptin <= '1';
216
+      assert s_dataout = c_substitution_table_test_cipher(index)
217
+        report "Encryption error"
218
+        severity failure;
219
+      assert s_dataout = swap(v_dataout)
220
+        report "Encryption openSSL reference error"
221
+        severity failure;
222
+      wait until rising_edge(s_clk);
223
+      s_acceptin <= '0';
224
+    end loop;
225
+
226
+    -- Random key & data openSSL reference test
227
+    report "# Random key & data openSSL reference test";
228
+    for index in 0 to 63 loop
229
+      wait until rising_edge(s_clk);
230
+      v_key    := v_random.RandSlv(64);
231
+      v_datain := v_random.RandSlv(64);
243 232
       s_validin <= '1';
244
-      s_key     <= c_substitution_table_test_keys(index);
245
-      s_datain  <= c_substitution_table_test_plain(index);
233
+      s_key     <= v_key;
234
+      s_datain  <= v_datain;
235
+      cryptData(swap(v_datain), swap(v_key), true, v_dataout, v_datain'length/8);
246 236
       wait until rising_edge(s_clk) and s_acceptout = '1';
237
+      s_validin <= '0';
238
+      wait until rising_edge(s_clk) and s_validout = '1';
239
+      s_acceptin <= '1';
240
+      assert s_dataout = swap(v_dataout)
241
+        report "Encryption openSSL reference error"
242
+        severity failure;
243
+      wait until rising_edge(s_clk);
244
+      s_acceptin <= '0';
247 245
     end loop;
246
+
248 247
     -- DECRYPTION TESTS
249
-    s_mode    <= '0';
250
-    s_validin <= '0';
251
-    s_key     <= (others => '0');
252
-    s_datain  <= (others => '0');
253
-    wait for 100 ns;
254
-    wait until rising_edge(s_clk);
248
+    report "# DECRYPTION TESTS";
249
+    s_mode <= '1';
250
+
255 251
     -- Variable ciphertext known answer test
256
-    s_key     <= x"0101010101010101";
252
+    report "# Variable ciphertext known answer test";
253
+    v_key       := x"0101010101010101";
254
+    v_plaintext := x"8000000000000000";
257 255
     for index in c_variable_plaintext_known_answers'range loop
258
-      s_mode    <= '1';
256
+      wait until rising_edge(s_clk);
257
+      v_datain  := c_variable_plaintext_known_answers(index);
259 258
       s_validin <= '1';
260
-      s_datain  <= c_variable_plaintext_known_answers(index);
259
+      s_key     <= v_key;
260
+      s_datain  <= v_datain;
261
+      cryptData(swap(v_datain), swap(v_key), false, v_dataout, v_datain'length/8);
261 262
       wait until rising_edge(s_clk) and s_acceptout = '1';
263
+      s_validin <= '0';
264
+      wait until rising_edge(s_clk) and s_validout = '1';
265
+      s_acceptin <= '1';
266
+      assert s_dataout = v_plaintext
267
+        report "Encryption error"
268
+        severity failure;
269
+      assert s_dataout = swap(v_dataout)
270
+        report "Encryption openSSL reference error"
271
+        severity failure;
272
+      wait until rising_edge(s_clk);
273
+      s_acceptin <= '0';
274
+      v_plaintext := '0' & v_plaintext(0 to 62);
262 275
     end loop;
263
-    s_mode    <= '0';
264
-    s_validin <= '0';
265
-    s_key     <= (others => '0');
266
-    s_datain  <= (others => '0');
267
-    wait for 100 ns;
268
-    wait until rising_edge(s_clk);
276
+
269 277
     -- Initial permutation known answer test
270
-    s_key     <= x"0101010101010101";
271
-    s_datain  <= x"8000000000000000";
278
+    report "# Initial permutation known answer test";
279
+    v_key     := x"0101010101010101";
280
+    v_datain  := x"8000000000000000";
272 281
     for index in c_variable_plaintext_known_answers'range loop
273
-      s_mode    <= '1';
282
+      wait until rising_edge(s_clk);
274 283
       s_validin <= '1';
275
-      if(index /= 0) then
276
-        s_datain <= '0' & s_datain(0 to 62);
277
-      end if;
284
+      s_key     <= v_key;
285
+      s_datain  <= v_datain;
286
+      cryptData(swap(v_datain), swap(v_key), false, v_dataout, v_datain'length/8);
278 287
       wait until rising_edge(s_clk) and s_acceptout = '1';
288
+      s_validin <= '0';
289
+      wait until rising_edge(s_clk) and s_validout = '1';
290
+      s_acceptin <= '1';
291
+      assert s_dataout = c_variable_plaintext_known_answers(index)
292
+        report "Encryption error"
293
+        severity failure;
294
+      assert s_dataout = swap(v_dataout)
295
+        report "Encryption openSSL reference error"
296
+        severity failure;
297
+      wait until rising_edge(s_clk);
298
+      s_acceptin <= '0';
299
+      v_datain  := '0' & v_datain(0 to 62);
279 300
     end loop;
280
-    s_mode    <= '0';
281
-    s_validin <= '0';
282
-    s_key     <= (others => '0');
283
-    s_datain  <= (others => '0');
284
-    wait for 100 ns;
285
-    wait until rising_edge(s_clk);
301
+
286 302
     -- Variable key known answer test
287
-    s_key     <= x"8000000000000000";
303
+    report "# Variable key known answer test";
304
+    v_key     := x"8000000000000000";
288 305
     for index in c_variable_key_known_answers'range loop
289
-      s_mode    <= '1';
306
+      v_datain  := c_variable_key_known_answers(index);
290 307
       s_validin <= '1';
291
-      s_datain  <= c_variable_key_known_answers(index);
292
-      if(index /= 0) then
293
-        if(index = 7 or index = 14 or index = 21 or index = 28 or index = 35 or
294
-           index = 42 or index = 49) then
295
-          s_key <= "00" & s_key(0 to 61);
296
-        else
297
-          s_key <= '0' & s_key(0 to 62);
298
-        end if;
299
-      end if;
308
+      s_key     <= v_key;
309
+      s_datain  <= v_datain;
310
+      cryptData(swap(v_datain), swap(v_key), false, v_dataout, v_datain'length/8);
300 311
       wait until rising_edge(s_clk) and s_acceptout = '1';
312
+      s_validin <= '0';
313
+      wait until rising_edge(s_clk) and s_validout = '1';
314
+      s_acceptin <= '1';
315
+      assert s_dataout = 64x"0"
316
+        report "Encryption error"
317
+        severity failure;
318
+      assert s_dataout = swap(v_dataout)
319
+        report "Encryption openSSL reference error"
320
+        severity failure;
321
+      wait until rising_edge(s_clk);
322
+      s_acceptin <= '0';
323
+      if (index = 6 or index = 13 or index = 20 or index = 27 or index = 34 or
324
+          index = 41 or index = 48) then
325
+        v_key := "00" & v_key(0 to 61);
326
+      else
327
+        v_key := '0' & v_key(0 to 62);
328
+      end if;
301 329
     end loop;
302
-    s_mode    <= '0';
303
-    s_validin <= '0';
304
-    s_key     <= (others => '0');
305
-    s_datain  <= (others => '0');
306
-    wait for 100 ns;
307
-    wait until rising_edge(s_clk);
330
+
308 331
     -- Permutation operation known answer test
332
+    report "# Permutation operation known answer test";
333
+    v_datain  := (others => '0');
309 334
     for index in c_permutation_operation_known_answers_keys'range loop
310
-      s_mode    <= '1';
335
+      wait until rising_edge(s_clk);
336
+      v_key     := c_permutation_operation_known_answers_keys(index);
337
+      v_datain  := c_permutation_operation_known_answers_cipher(index);
311 338
       s_validin <= '1';
312
-      s_datain  <= c_permutation_operation_known_answers_cipher(index);
313
-      s_key     <= c_permutation_operation_known_answers_keys(index);
339
+      s_key     <= v_key;
340
+      s_datain  <= v_datain;
341
+      cryptData(swap(v_datain), swap(v_key), false, v_dataout, v_datain'length/8);
314 342
       wait until rising_edge(s_clk) and s_acceptout = '1';
343
+      s_validin <= '0';
344
+      wait until rising_edge(s_clk) and s_validout = '1';
345
+      s_acceptin <= '1';
346
+      assert s_dataout = 64x"0"
347
+        report "Encryption error"
348
+        severity failure;
349
+      assert s_dataout = swap(v_dataout)
350
+        report "Encryption openSSL reference error"
351
+        severity failure;
352
+      wait until rising_edge(s_clk);
353
+      s_acceptin <= '0';
315 354
     end loop;
316
-    s_mode    <= '0';
317
-    s_validin <= '0';
318
-    s_key     <= (others => '0');
319
-    s_datain  <= (others => '0');
320
-    wait for 100 ns;
321
-    wait until rising_edge(s_clk);
355
+
322 356
     -- Substitution table known answer test
357
+    report "# Substitution table known answer test";
323 358
     for index in c_substitution_table_test_keys'range loop
324
-      s_mode    <= '1';
359
+      wait until rising_edge(s_clk);
360
+      v_key     := c_substitution_table_test_keys(index);
361
+      v_datain  := c_substitution_table_test_cipher(index);
325 362
       s_validin <= '1';
326
-      s_key     <= c_substitution_table_test_keys(index);
327
-      s_datain  <= c_substitution_table_test_cipher(index);
363
+      s_key     <= v_key;
364
+      s_datain  <= v_datain;
365
+      cryptData(swap(v_datain), swap(v_key), false, v_dataout, v_datain'length/8);
328 366
       wait until rising_edge(s_clk) and s_acceptout = '1';
329
-    end loop;
330
-    s_mode    <= '0';
331
-    s_validin <= '0';
332
-    s_key     <= (others => '0');
333
-    s_datain  <= (others => '0');
334
-    wait;
335
-  end process teststimuliP;
336
-
337
-
338
-  testcheckerP : process is
339
-    variable v_plaintext : std_logic_vector(0 to 63) := x"8000000000000000";
340
-  begin
341
-    s_acceptin <= '1';
342
-    wait until s_reset = '1';
343
-    report "# ENCRYPTION TESTS";
344
-    report "# Variable plaintext known answer test";
345
-    for index in c_variable_plaintext_known_answers'range loop
346
-      wait until rising_edge(s_clk) and s_validout = '1';
347
-        assert (s_dataout = c_variable_plaintext_known_answers(index))
348
-          report "encryption error"
349
-          severity error;
350
-    end loop;
351
-    report "# Inverse permutation known answer test";
352
-    for index in c_variable_plaintext_known_answers'range loop
353
-      wait until rising_edge(s_clk) and s_validout = '1';
354
-        assert (s_dataout = v_plaintext)
355
-          report "encryption error"
356
-          severity error;
357
-        v_plaintext := '0' & v_plaintext(0 to 62);
358
-    end loop;
359
-    report "# Variable key known answer test";
360
-    for index in c_variable_key_known_answers'range loop
361
-      wait until rising_edge(s_clk) and s_validout = '1';
362
-        assert (s_dataout = c_variable_key_known_answers(index))
363
-          report "encryption error"
364
-          severity error;
365
-    end loop;
366
-    report "# Permutation operation known answer test";
367
-    for index in c_permutation_operation_known_answers_cipher'range loop
368
-      wait until rising_edge(s_clk) and s_validout = '1';
369
-        assert (s_dataout = c_permutation_operation_known_answers_cipher(index))
370
-          report "encryption error"
371
-          severity error;
372
-    end loop;
373
-    report "# Substitution table known answer test";
374
-    for index in c_substitution_table_test_cipher'range loop
375
-      wait until rising_edge(s_clk) and s_validout = '1';
376
-        assert (s_dataout = c_substitution_table_test_cipher(index))
377
-          report "encryption error"
378
-          severity error;
379
-    end loop;
380
-    report "# DECRYPTION TESTS";
381
-    report "# Variable ciphertext known answer test";
382
-    v_plaintext := x"8000000000000000";
383
-    for index in c_variable_plaintext_known_answers'range loop
384
-      wait until rising_edge(s_clk) and s_validout = '1';
385
-        assert (s_dataout = v_plaintext)
386
-          report "decryption error"
387
-          severity error;
388
-        v_plaintext := '0' & v_plaintext(0 to 62);
389
-    end loop;
390
-    report "# Initial permutation known answer test";
391
-    for index in c_variable_plaintext_known_answers'range loop
392
-      wait until rising_edge(s_clk) and s_validout = '1';
393
-        assert (s_dataout = c_variable_plaintext_known_answers(index))
394
-          report "decryption error"
395
-          severity error;
396
-    end loop;
397
-    report "# Variable key known answer test";
398
-    for index in c_variable_key_known_answers'range loop
367
+      s_validin <= '0';
399 368
       wait until rising_edge(s_clk) and s_validout = '1';
400
-        assert (s_dataout = x"0000000000000000")
401
-          report "decryption error"
402
-          severity error;
369
+      s_acceptin <= '1';
370
+      assert s_dataout = c_substitution_table_test_plain(index)
371
+        report "Encryption error"
372
+        severity failure;
373
+      assert s_dataout = swap(v_dataout)
374
+        report "Encryption openSSL reference error"
375
+        severity failure;
376
+      wait until rising_edge(s_clk);
377
+      s_acceptin <= '0';
403 378
     end loop;
404
-    report "# Permutation operation known answer test";
405
-    for index in c_permutation_operation_known_answers_keys'range loop
406
-      wait until rising_edge(s_clk) and s_validout = '1';
407
-        assert (s_dataout = x"0000000000000000")
408
-          report "decryption error"
409
-          severity error;
410
-    end loop;
411
-    report "# Substitution table known answer test";
412
-    for index in c_substitution_table_test_cipher'range loop
379
+
380
+    -- Random key & data openSSL reference test
381
+    report "# Random key & data openSSL reference test";
382
+    for index in 0 to 63 loop
383
+      wait until rising_edge(s_clk);
384
+      v_key    := v_random.RandSlv(64);
385
+      v_datain := v_random.RandSlv(64);
386
+      s_validin <= '1';
387
+      s_key     <= v_key;
388
+      s_datain  <= v_datain;
389
+      cryptData(swap(v_datain), swap(v_key), false, v_dataout, v_datain'length/8);
390
+      wait until rising_edge(s_clk) and s_acceptout = '1';
391
+      s_validin <= '0';
413 392
       wait until rising_edge(s_clk) and s_validout = '1';
414
-        assert (s_dataout = c_substitution_table_test_plain(index))
415
-          report "decryption error"
416
-          severity error;
393
+      s_acceptin <= '1';
394
+      assert s_dataout = swap(v_dataout)
395
+        report "Encryption openSSL reference error"
396
+        severity failure;
397
+      wait until rising_edge(s_clk);
398
+      s_acceptin <= '0';
417 399
     end loop;
400
+
401
+    wait for 100 ns;
418 402
     report "# Successfully passed all tests";
419
-    assert false;
403
+    finish(0);
420 404
     wait;
421
-  end process testcheckerP;
405
+
406
+  end process testP;
407
+
422 408
 
423 409
 
424 410
   i_des : des

+ 128
- 0
des/sim/vhdl/tb_des_pkg.vhd View File

@@ -0,0 +1,128 @@
1
+-- ======================================================================
2
+-- DES encryption/decryption testbench
3
+-- tests according to NIST 800-17 special publication
4
+-- Copyright (C) 2011 Torsten Meissner
5
+-------------------------------------------------------------------------
6
+-- This program is free software; you can redistribute it and/or modify
7
+-- it under the terms of the GNU General Public License as published by
8
+-- the Free Software Foundation; either version 2 of the License, or
9
+-- (at your option) any later version.
10
+
11
+-- This program is distributed in the hope that it will be useful,
12
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+-- GNU General Public License for more details.
15
+
16
+-- You should have received a copy of the GNU General Public License
17
+-- along with this program; if not, write to the Free Software
18
+-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
+-- ======================================================================
20
+
21
+
22
+library ieee;
23
+  use ieee.std_logic_1164.all;
24
+
25
+
26
+package tb_des_pkg is
27
+
28
+  type t_array is array (natural range <>) of std_logic_vector(0 to 63);
29
+
30
+  constant c_variable_plaintext_known_answers : t_array(0 to 63) :=
31
+    (x"95F8A5E5DD31D900", x"DD7F121CA5015619", x"2E8653104F3834EA",
32
+     x"4BD388FF6CD81D4F", x"20B9E767B2FB1456", x"55579380D77138EF",
33
+     x"6CC5DEFAAF04512F", x"0D9F279BA5D87260", x"D9031B0271BD5A0A",
34
+     x"424250B37C3DD951", x"B8061B7ECD9A21E5", x"F15D0F286B65BD28",
35
+     x"ADD0CC8D6E5DEBA1", x"E6D5F82752AD63D1", x"ECBFE3BD3F591A5E",
36
+     x"F356834379D165CD", x"2B9F982F20037FA9", x"889DE068A16F0BE6",
37
+     x"E19E275D846A1298", x"329A8ED523D71AEC", x"E7FCE22557D23C97",
38
+     x"12A9F5817FF2D65D", x"A484C3AD38DC9C19", x"FBE00A8A1EF8AD72",
39
+     x"750D079407521363", x"64FEED9C724C2FAF", x"F02B263B328E2B60",
40
+     x"9D64555A9A10B852", x"D106FF0BED5255D7", x"E1652C6B138C64A5",
41
+     x"E428581186EC8F46", x"AEB5F5EDE22D1A36", x"E943D7568AEC0C5C",
42
+     x"DF98C8276F54B04B", x"B160E4680F6C696F", x"FA0752B07D9C4AB8",
43
+     x"CA3A2B036DBC8502", x"5E0905517BB59BCF", x"814EEB3B91D90726",
44
+     x"4D49DB1532919C9F", x"25EB5FC3F8CF0621", x"AB6A20C0620D1C6F",
45
+     x"79E90DBC98F92CCA", x"866ECEDD8072BB0E", x"8B54536F2F3E64A8",
46
+     x"EA51D3975595B86B", x"CAFFC6AC4542DE31", x"8DD45A2DDF90796C",
47
+     x"1029D55E880EC2D0", x"5D86CB23639DBEA9", x"1D1CA853AE7C0C5F",
48
+     x"CE332329248F3228", x"8405D1ABE24FB942", x"E643D78090CA4207",
49
+     x"48221B9937748A23", x"DD7C0BBD61FAFD54", x"2FBC291A570DB5C4",
50
+     x"E07C30D7E4E26E12", x"0953E2258E8E90A1", x"5B711BC4CEEBF2EE",
51
+     x"CC083F1E6D9E85F6", x"D2FD8867D50D2DFE", x"06E7EA22CE92708F",
52
+     x"166B40B44ABA4BD6");
53
+
54
+  constant c_variable_key_known_answers : t_array(0 to 55) :=
55
+    (x"95A8D72813DAA94D", x"0EEC1487DD8C26D5", x"7AD16FFB79C45926",
56
+     x"D3746294CA6A6CF3", x"809F5F873C1FD761", x"C02FAFFEC989D1FC",
57
+     x"4615AA1D33E72F10", x"2055123350C00858", x"DF3B99D6577397C8",
58
+     x"31FE17369B5288C9", x"DFDD3CC64DAE1642", x"178C83CE2B399D94",
59
+     x"50F636324A9B7F80", x"A8468EE3BC18F06D", x"A2DC9E92FD3CDE92",
60
+     x"CAC09F797D031287", x"90BA680B22AEB525", x"CE7A24F350E280B6",
61
+     x"882BFF0AA01A0B87", x"25610288924511C2", x"C71516C29C75D170",
62
+     x"5199C29A52C9F059", x"C22F0A294A71F29F", x"EE371483714C02EA",
63
+     x"A81FBD448F9E522F", x"4F644C92E192DFED", x"1AFA9A66A6DF92AE",
64
+     x"B3C1CC715CB879D8", x"19D032E64AB0BD8B", x"3CFAA7A7DC8720DC",
65
+     x"B7265F7F447AC6F3", x"9DB73B3C0D163F54", x"8181B65BABF4A975",
66
+     x"93C9B64042EAA240", x"5570530829705592", x"8638809E878787A0",
67
+     x"41B9A79AF79AC208", x"7A9BE42F2009A892", x"29038D56BA6D2745",
68
+     x"5495C6ABF1E5DF51", x"AE13DBD561488933", x"024D1FFA8904E389",
69
+     x"D1399712F99BF02E", x"14C1D7C1CFFEC79E", x"1DE5279DAE3BED6F",
70
+     x"E941A33F85501303", x"DA99DBBC9A03F379", x"B7FC92F91D8E92E9",
71
+     x"AE8E5CAA3CA04E85", x"9CC62DF43B6EED74", x"D863DBB5C59A91A0",
72
+     x"A1AB2190545B91D7", x"0875041E64C570F7", x"5A594528BEBEF1CC",
73
+     x"FCDB3291DE21F0C0", x"869EFD7F9F265A09");
74
+
75
+  constant c_permutation_operation_known_answers_keys : t_array(0 to 31) :=
76
+    (x"1046913489980131", x"1007103489988020", x"10071034C8980120",
77
+     x"1046103489988020", x"1086911519190101", x"1086911519580101",
78
+     x"5107B01519580101", x"1007B01519190101", x"3107915498080101",
79
+     x"3107919498080101", x"10079115B9080140", x"3107911598080140",
80
+     x"1007D01589980101", x"9107911589980101", x"9107D01589190101",
81
+     x"1007D01598980120", x"1007940498190101", x"0107910491190401",
82
+     x"0107910491190101", x"0107940491190401", x"19079210981A0101",
83
+     x"1007911998190801", x"10079119981A0801", x"1007921098190101",
84
+     x"100791159819010B", x"1004801598190101", x"1004801598190102",
85
+     x"1004801598190108", x"1002911598100104", x"1002911598190104",
86
+     x"1002911598100201", x"1002911698100101");
87
+
88
+  constant c_permutation_operation_known_answers_cipher : t_array(0 to 31) :=
89
+    (x"88D55E54F54C97B4", x"0C0CC00C83EA48FD", x"83BC8EF3A6570183",
90
+     x"DF725DCAD94EA2E9", x"E652B53B550BE8B0", x"AF527120C485CBB0",
91
+     x"0F04CE393DB926D5", x"C9F00FFC74079067", x"7CFD82A593252B4E",
92
+     x"CB49A2F9E91363E3", x"00B588BE70D23F56", x"406A9A6AB43399AE",
93
+     x"6CB773611DCA9ADA", x"67FD21C17DBB5D70", x"9592CB4110430787",
94
+     x"A6B7FF68A318DDD3", x"4D102196C914CA16", x"2DFA9F4573594965",
95
+     x"B46604816C0E0774", x"6E7E6221A4F34E87", x"AA85E74643233199",
96
+     x"2E5A19DB4D1962D6", x"23A866A809D30894", x"D812D961F017D320",
97
+     x"055605816E58608F", x"ABD88E8B1B7716F1", x"537AC95BE69DA1E1",
98
+     x"AED0F6AE3C25CDD8", x"B3E35A5EE53E7B8D", x"61C79C71921A2EF8",
99
+     x"E2F5728F0995013C", x"1AEAC39A61F0A464");
100
+
101
+  constant c_substitution_table_test_keys : t_array(0 to 18) :=
102
+    (x"7CA110454A1A6E57", x"0131D9619DC1376E", x"07A1133E4A0B2686",
103
+     x"3849674C2602319E", x"04B915BA43FEB5B6", x"0113B970FD34F2CE",
104
+     x"0170F175468FB5E6", x"43297FAD38E373FE", x"07A7137045DA2A16",
105
+     x"04689104C2FD3B2F", x"37D06BB516CB7546", x"1F08260D1AC2465E",
106
+     x"584023641ABA6176", x"025816164629B007", x"49793EBC79B3258F",
107
+     x"4FB05E1515AB73A7", x"49E95D6D4CA229BF", x"018310DC409B26D6",
108
+     x"1C587F1C13924FEF");
109
+
110
+  constant c_substitution_table_test_plain : t_array(0 to 18) :=
111
+    (x"01A1D6D039776742", x"5CD54CA83DEF57DA", x"0248D43806F67172",
112
+     x"51454B582DDF440A", x"42FD443059577FA2", x"059B5E0851CF143A",
113
+     x"0756D8E0774761D2", x"762514B829BF486A", x"3BDD119049372802",
114
+     x"26955F6835AF609A", x"164D5E404F275232", x"6B056E18759F5CCA",
115
+     x"004BD6EF09176062", x"480D39006EE762F2", x"437540C8698F3CFA",
116
+     x"072D43A077075292", x"02FE55778117F12A", x"1D9D5C5018F728C2",
117
+     x"305532286D6F295A");
118
+
119
+  constant c_substitution_table_test_cipher : t_array(0 to 18) :=
120
+    (x"690F5B0D9A26939B", x"7A389D10354BD271", x"868EBB51CAB4599A",
121
+     x"7178876E01F19B2A", x"AF37FB421F8C4095", x"86A560F10EC6D85B",
122
+     x"0CD3DA020021DC09", x"EA676B2CB7DB2B7A", x"DFD64A815CAF1A0F",
123
+     x"5C513C9C4886C088", x"0A2AEEAE3FF4AB77", x"EF1BF03E5DFA575A",
124
+     x"88BF0DB6D70DEE56", x"A1F9915541020B56", x"6FBF1CAFCFFD0556",
125
+     x"2F22E49BAB7CA1AC", x"5A6B612CC26CCE4A", x"5F4C038ED12B2E41",
126
+     x"63FAC0D034D9F793");
127
+
128
+end package tb_des_pkg;