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

Subversion Repositories rsa_512

[/] [rsa_512/] [trunk/] [rtl/] [n_c.vhd] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 jcastillo
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: Oleg Rasulov
4
-- 
5
-- Create Date:    17:04:24 12/28/2010 
6
-- Design Name: 
7
-- Module Name:    n_c - Behavioral 
8
-- Project Name: 
9
-- Target Devices: Spartan-3 xc3s200-4
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.all;
22
use IEEE.STD_LOGIC_ARITH.all;
23
use IEEE.STD_LOGIC_UNSIGNED.all;
24
 
25
--library UNISIM;
26
--use UNISIM.VComponents.all;
27
 
28
entity n_c_core is
29
  port (clk   : in  std_logic;
30
        m_lsw : in  std_logic_vector(15 downto 0);
31
        ce    : in  std_logic;
32
        n_c   : out std_logic_vector(15 downto 0);
33
        done  : out std_logic
34
        );
35
end n_c_core;
36
 
37
architecture Behavioral of n_c_core is
38
 
39
  type stateNC_type is (stNC_idle, stNC_step1, stNC_step2,
40
                        stNC_step3, stNC_step4, stNC_fin);
41
 
42
  signal stateNC       : stateNC_type;
43
  signal NC_complete   : std_logic := '0';
44
  signal NC_start      : std_logic := '0';
45
  signal LSW_M         : std_logic_vector(15 downto 0);
46
  signal adr_tbl       : std_logic_vector(2 downto 0);
47
  signal X0_tbl        : std_logic_vector(3 downto 0);
48
  signal Z0_tbl        : std_logic_vector(3 downto 0);
49
  signal X1_tbl        : std_logic_vector(3 downto 0);
50
  signal V1x9          : std_logic_vector(3 downto 0);
51
  signal TforNC        : std_logic_vector(15 downto 0);
52
  signal not_TforNCPl3 : std_logic_vector(15 downto 0);
53
  signal NC            : std_logic_vector(15 downto 0);
54
  signal t_NC          : std_logic_vector(15 downto 0);
55
  signal t_NC_out      : std_logic_vector(15 downto 0);
56
  signal b2equalb1     : std_logic;
57
 
58
 
59
-- dummy signals for simulation
60
  signal DUMMY_SIM0 : std_logic_vector(19 downto 0);
61
  signal DUMMY_SIM1 : std_logic_vector(19 downto 0);
62
--
63
  signal mul1, mul2 : std_logic_vector(35 downto 0);
64
begin
65
 
66
  mul1     <= ("00"&t_NC)*("00"&LSW_M);
67
  TforNC   <= mul1(15 downto 0);
68
  mul2     <= ("00"&t_NC)*("00"&not_TforNCPl3);
69
  t_NC_out <= mul2(15 downto 0);
70
 
71
-- TforNC_inst : MULT18X18
72
-- port map (
73
-- P(15 downto 0) => TforNC,
74
-- P(35 downto 16) => DUMMY_SIM0,       --only for sim, normally open
75
--      A(15 downto 0)  => t_NC,
76
--      A(17 downto 16) => "00",
77
--      B(15 downto 0)  => LSW_M,
78
--      B(17 downto 16) => "00"
79
--      );
80
 
81
-- NC_inst : MULT18X18
82
-- port map (
83
-- P(15 downto 0) => t_NC_out,
84
-- P(35 downto 16) => DUMMY_SIM1,       --only for sim, normally open
85
--      A(15 downto 0)  => t_NC,
86
--      A(17 downto 16) => "00",
87
--      B(15 downto 0)  => not_TforNCPl3,
88
--      B(17 downto 16) => "00"
89
--      );
90
--------------------------------------------
91
  WRITELSWM_PROCESS : process(clk, NC_complete)
92
  begin
93
    if(NC_complete = '1') then
94
      NC_start                      <= '0';
95
    elsif rising_edge(clk) then
96
      if(ce = '1') then
97
        LSW_M                       <= m_lsw;
98
        NC_start                    <= '1';
99
      end if;
100
    end if;
101
  end process WRITELSWM_PROCESS;
102
--------------------------------------------
103
  X0_ROM            : process(adr_tbl)
104
  begin
105
    case adr_tbl is
106
      when "000"          => X0_tbl <= X"F";
107
      when "001"          => X0_tbl <= X"5";
108
      when "010"          => X0_tbl <= X"3";
109
      when "011"          => X0_tbl <= X"9";
110
      when "100"          => X0_tbl <= X"7";
111
      when "101"          => X0_tbl <= X"D";
112
      when "110"          => X0_tbl <= X"B";
113
      when others         => X0_tbl <= X"1";
114
    end case;
115
  end process X0_ROM;
116
-------------------------------------------------------------------------------
117
  Z0_ROM            : process(adr_tbl)
118
  begin
119
    case adr_tbl is
120
      when "000"          => Z0_tbl <= X"F";
121
      when "001"          => Z0_tbl <= X"5";
122
      when "010"          => Z0_tbl <= X"3";
123
      when "011"          => Z0_tbl <= X"4";
124
      when "100"          => Z0_tbl <= X"C";
125
      when "101"          => Z0_tbl <= X"5";
126
      when "110"          => Z0_tbl <= X"3";
127
      when others         => Z0_tbl <= X"1";
128
    end case;
129
  end process Z0_ROM;
130
-------------------------------------------------------------------------------
131
  X1_ROM            : process(b2equalb1, LSW_M, Z0_tbl, V1x9)
132
  begin
133
    if(b2equalb1 = '0') then            -- b1==b2
134
      X1_tbl                        <= LSW_M(7 downto 4) + Z0_tbl;
135
    else                                -- b1 != b2
136
      X1_tbl                        <= V1x9 + Z0_tbl;
137
    end if;
138
  end process X1_ROM;
139
-------------------------------------------------------------------------------
140
  STATE_NC_PROCESS  : process(clk)
141
  begin
142
    if rising_edge(clk) then
143
      if(NC_start = '0') then
144
        NC_complete                 <= '0';
145
        stateNC                     <= stNC_idle;
146
        done                        <= '0';
147
      else
148
        case stateNC is
149
          when stNC_idle  =>
150
            done                    <= '0';
151
            stateNC                 <= stNC_step1;
152
            t_NC                    <= X"00" & X1_tbl & X0_tbl;
153
          when stNC_step1 =>
154
            t_NC                    <= t_NC_out;
155
            stateNC                 <= stNC_step2;
156
          when stNC_step2 =>
157
            t_NC                    <= t_NC_out;
158
            stateNC                 <= stNC_step3;
159
          when stNC_step3 =>
160
            t_NC                    <= t_NC_out;
161
            stateNC                 <= stNC_step4;
162
          when stNC_step4 =>
163
            t_NC                    <= t_NC_out;
164
            stateNC                 <= stNC_fin;
165
          when stNC_fin   =>
166
            NC_complete             <= '1';
167
            done                    <= '1';
168
            stateNC                 <= stNC_idle;
169
            NC                      <= (not (t_NC(15 downto 1))) & '1';
170
          when others     =>
171
            stateNC                 <= stNC_idle;
172
        end case;
173
      end if;
174
    end if;
175
  end process STATE_NC_PROCESS;
176
-------------------------------------------------------------------------------
177
  not_TforNCPl3                     <= (not TforNC) + 3;
178
  adr_tbl                           <= LSW_M(3 downto 1);
179
  V1x9                              <= (LSW_M(4) & "000") + LSW_M(7 downto 4);
180
  b2equalb1                         <= LSW_M(5) xor LSW_M(6);
181
  n_c                               <= NC;
182
end Behavioral;
183
 

powered by: WebSVN 2.1.0

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