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

Subversion Repositories mod_mult_exp

[/] [mod_mult_exp/] [trunk/] [bench/] [vhdl/] [mod_exp/] [ModExp64bitTB.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 gajos
-----------------------------------------------------------------------
2
----                                                               ----
3
---- Montgomery modular multiplier and exponentiator               ----
4
----                                                               ----
5
---- This file is part of the Montgomery modular multiplier        ----
6
---- and exponentiator project                                     ----
7
---- http://opencores.org/project,mod_mult_exp                     ----
8
----                                                               ----
9
---- Description:                                                  ----
10
----   This is TestBench for the Montgomery modular exponentiator  ----
11
----   with the 64 bit width.                                      ----
12
----   It takes four nubers - base, power, modulus and Montgomery  ----
13
----   residuum (2^(2*word_length) mod N) as the input and results ----
14
----   the modular exponentiation A^B mod M.                       ----
15
----   In fact input data are read through one input controlled by ----
16
----   the ctrl input.                                             ----
17
---- To Do:                                                        ----
18
----                                                               ----
19
---- Author(s):                                                    ----
20
---- - Krzysztof Gajewski, gajos@opencores.org                     ----
21
----                       k.gajewski@gmail.com                    ----
22
----                                                               ----
23
-----------------------------------------------------------------------
24
----                                                               ----
25
---- Copyright (C) 2014 Authors and OPENCORES.ORG                  ----
26
----                                                               ----
27
---- This source file may be used and distributed without          ----
28
---- restriction provided that this copyright statement is not     ----
29
---- removed from the file and that any derivative work contains   ----
30
---- the original copyright notice and the associated disclaimer.  ----
31
----                                                               ----
32
---- This source file is free software; you can redistribute it    ----
33
---- and-or modify it under the terms of the GNU Lesser General    ----
34
---- Public License as published by the Free Software Foundation;  ----
35
---- either version 2.1 of the License, or (at your option) any    ----
36
---- later version.                                                ----
37
----                                                               ----
38
---- This source is distributed in the hope that it will be        ----
39
---- useful, but WITHOUT ANY WARRANTY; without even the implied    ----
40
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR       ----
41
---- PURPOSE. See the GNU Lesser General Public License for more   ----
42
---- details.                                                      ----
43
----                                                               ----
44
---- You should have received a copy of the GNU Lesser General     ----
45
---- Public License along with this source; if not, download it    ----
46
---- from http://www.opencores.org/lgpl.shtml                      ----
47
----                                                               ----
48
-----------------------------------------------------------------------
49
LIBRARY ieee;
50
use work.properties.ALL;
51
USE ieee.std_logic_1164.ALL;
52
 
53
-- Uncomment the following library declaration if using
54
-- arithmetic functions with Signed or Unsigned values
55
--USE ieee.numeric_std.ALL;
56
 
57
ENTITY ModExp64bitTB IS
58
END ModExp64bitTB;
59
 
60
ARCHITECTURE behavior OF ModExp64bitTB IS
61
 
62
    -- Component Declaration for the Unit Under Test (UUT)
63
 
64
    COMPONENT ModExp
65
    PORT(
66
         input         : in  STD_LOGIC_VECTOR(63 downto 0);
67
         ctrl          : in  STD_LOGIC_VECTOR(2 downto 0);
68
         clk           : in  STD_LOGIC;
69
         reset         : in  STD_LOGIC;
70
                        data_in_ready : in  STD_LOGIC;
71
         ready         : out STD_LOGIC;
72
         output        : out STD_LOGIC_VECTOR(63 downto 0)
73
    );
74
    END COMPONENT;
75
 
76
 
77
   --Inputs
78
   signal input         : STD_LOGIC_VECTOR(63 downto 0) := (others => '0');
79
   signal ctrl          : STD_LOGIC_VECTOR(2 downto 0) := (others => '0');
80
   signal clk           : STD_LOGIC := '0';
81
   signal reset         : STD_LOGIC := '0';
82
        signal data_in_ready : STD_LOGIC := '0';
83
 
84
        --Outputs
85
   signal ready  : STD_LOGIC;
86
   signal output : STD_LOGIC_VECTOR(63 downto 0);
87
 
88
   -- Clock period definitions
89
   constant clk_period : time := 10 ns;
90
 
91
BEGIN
92
 
93
        -- Instantiate the Unit Under Test (UUT)
94
   uut: ModExp PORT MAP (
95
          input => input,
96
          ctrl => ctrl,
97
          clk => clk,
98
          reset => reset,
99
                         data_in_ready => data_in_ready,
100
          ready => ready,
101
          output => output
102
        );
103
 
104
   -- Clock process definitions
105
   clk_process :process
106
   begin
107
                clk <= '1';
108
                wait for clk_period/2;
109
                clk <= '0';
110
                wait for clk_period/2;
111
   end process;
112
 
113
 
114
   -- Stimulus process
115
   stim_proc: process
116
   begin
117
      reset <= '1';
118
      wait for 100 ns;
119
                reset <= '0';
120
      wait for clk_period*10;
121
 
122
---- Preparation for test case 1 -----------------
123
--    base        =  816881283968894723 in decimal
124
--                =  0xb56253322a18703  in hexadecimal
125
--    exponent    =  281474976710679    in decimal
126
--                =  0x1000000000017    in hexhexadecimal
127
--    modulus     =  4612794175830006917 in decimal
128
--                =  0x4003efdd00569c85    in hexhexadecimal
129
--    expected_result = 1851187696912577658 in decimal,  
130
--               in hex 19b0bd66ff0c347a
131
--    power_mod(
132
--         816881283968894723,
133
--         281474976710679,
134
--         4612794175830006917
135
--      ) = 
136
--        = 1851187696912577658
137
--        = 19b0bd66ff0c347a in hexadecimal
138
--    where 1762515348761952014 is the residuum
139
--------------------------------------------------
140
 
141
                data_in_ready <= '1';
142
                ctrl <= mn_read_base;
143
                input <= x"0b56253322a18703";
144
                wait for clk_period*2;
145
 
146
                ctrl <= mn_read_modulus;
147
                input <= x"4003efdd00569c85";
148
                wait for clk_period*2;
149
 
150
                ctrl <= mn_read_exponent;
151
                input <= x"0001000000000017";
152
                wait for clk_period*2;
153
 
154
                ctrl <= mn_read_residuum;
155
                input <= "0001100001110101101101100101111100011010001000010011111100001110";
156
                wait for clk_period*2;
157
 
158
                ctrl <= mn_count_power;
159
 
160
                wait until ready = '1' and clk = '0';
161
 
162
           if output /= x"19b0bd66ff0c347a" then
163
                 report "RESULT MISMATCH! Test case 1 failed" severity ERROR;
164
                 assert false severity failure;
165
           else
166
                 report "Test case 1 successful" severity note;
167
           end if;
168
 
169
                ctrl <= mn_show_result;
170
                wait for clk_period*10;
171
 
172
                ctrl <= mn_prepare_for_data;
173
                wait for clk_period*10;
174
 
175
---- Preparation for test case 2 -----------------
176
--    base        = 816881283968894722 in decimal
177
--                = 0xb56253322a18702 in hexadecimal
178
--    exponent    = 281474976710678 in decimal
179
--                = 0x1000000000016 in hexhexadecimal
180
--    modulus     = 4612794175830006917 in decimal
181
--                = 0x4003efdd00569c85 in hexhexadecimal
182
--    expected_result = 3178815025358931436 in decimal,  
183
--               in hex 2c1d6b6c693185ec
184
--    power_mod(
185
--         816881283968894722,
186
--         281474976710678,
187
--         4612794175830006917
188
--      ) = 
189
--        = 3178815025358931436
190
--        = 2c1d6b6c693185ec in hexadecimal
191
--    where 1762515348761952014 is the residuum
192
--------------------------------------------------              
193
 
194
                ctrl <= mn_read_base;
195
                input <= x"0b56253322a18702";
196
                wait for clk_period*2;
197
 
198
                ctrl <= mn_read_modulus;
199
                input <= x"4003efdd00569c85";
200
                wait for clk_period*2;
201
 
202
                ctrl <= mn_read_exponent;
203
                input <= x"0001000000000016";
204
                wait for clk_period*2;
205
 
206
                ctrl <= mn_read_residuum;
207
                input <= "0001100001110101101101100101111100011010001000010011111100001110";
208
                wait for clk_period*2;
209
 
210
                ctrl <= mn_count_power;
211
 
212
                wait until ready = '1' and clk = '0';
213
 
214
           if output /= x"2c1d6b6c693185ec" then
215
                 report "RESULT MISMATCH! Test case 2 failed" severity ERROR;
216
                 assert false severity failure;
217
           else
218
                 report "Test case 2 successful" severity note;
219
           end if;
220
 
221
                ctrl <= mn_show_result;
222
                wait for clk_period*10;
223
                ctrl <= mn_prepare_for_data;
224
                wait for clk_period*10;
225
 
226
      assert false severity failure;
227
   end process;
228
 
229
END;

powered by: WebSVN 2.1.0

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