Проектирование специализированного микроконтроллера, реализующего полнофункциональную RSA схему шифрования, страница 8

    reset_l_1 <= reset_l;

  end if;

end process;

process(clk)

begin

  if clk'event and clk = '1' then

    if reset_l_1 = '0' then

      state <= idle;

    else

      state <= nxstate;

    end if;

  end if;

end process;

add_sub_fsm: process(state, reset_l_1, start)

begin

  nxstate <= state;

  case state is

    when idle => if reset_l_1 = '1' and start = '1' then

                   nxstate <= level0;

                 end if;

    when level0 => nxstate <= level1;

    when level1 => nxstate <= level2;

    when level2 => nxstate <= level3;

    when level3 => nxstate <= level4;

    when level4 => nxstate <= level5;

    when level5 => nxstate <= level6;

    when level6 => nxstate <= level7;

    when level7 => nxstate <= level8;

    when level8 => nxstate <= level9;

    when level9 => nxstate <= level10;

    when level10 => nxstate <= level11;

    when level11 => nxstate <= level12;

    when level12 => nxstate <= level13;

    when level13 => nxstate <= level14;

    when level14 => nxstate <= level15;

    when level15 => nxstate <= level16;

    when level16 => nxstate <= level17;

    when level17 => nxstate <= level18;

    when level18 => nxstate <= level19;

    when level19 => nxstate <= level20;

    when level20 => nxstate <= level21;

    when level21 => nxstate <= level22;

    when level22 => nxstate <= level23;

    when level23 => nxstate <= level24;

    when level24 => nxstate <= level25;

    when level25 => nxstate <= level26;

    when level26 => nxstate <= level27;

    when level27 => nxstate <= level28;

    when level28 => nxstate <= level29;

    when level29 => nxstate <= level30;

    when level30 => nxstate <= level31;

    when level31 => nxstate <= idle;

    when others => nxstate <= idle;

  end case;

end process add_sub_fsm;

process(clk)

begin

  if clk'event and clk = '1' then

    if reset_l_1 = '0' then

      s <= (others => '0');

      c_out <= '0';

      ready <= '0';

      s_valid <= '0';

      a_i <= (others => '0');

      b_i <= (others => '0');

      c_in_i <= '0';

      add_i <= '1';

    else

      ready <= '0';

      s_valid <= '0';

      a_i <= (others => '0');

      b_i <= (others => '0');

      c_in_i <= '0';

      c_out <= '0';

      case state is

        when idle => ready <= '1'; s <= (others => '0');

                     if reset_l_1 = '1' and start = '1' then

                       ready <= '0';

                       a_buf <= a(1023 downto 32);

                       b_buf <= b(1023 downto 32);

                       a_i <= a(31 downto 0);

                       b_i <= b(31 downto 0);

                       c_in_i <= c_in;

                       add_i <= add;

                     end if;

        when level0 => s(31 downto 0) <= s_i;

                       a_i <= a_buf(31 downto 0);

                       b_i <= b_buf(31 downto 0);

                       c_in_i <= c_out_i;

        when level1 => s(63 downto 32) <= s_i;

                       a_i <= a_buf(63 downto 32);

                       b_i <= b_buf(63 downto 32);

                       c_in_i <= c_out_i;

        when level2 => s(95 downto 64) <= s_i;

                       a_i <= a_buf(95 downto 64);

                       b_i <= b_buf(95 downto 64);

                       c_in_i <= c_out_i;

        when level3 => s(127 downto 96) <= s_i;

                       a_i <= a_buf(127 downto 96);

                       b_i <= b_buf(127 downto 96);

                       c_in_i <= c_out_i;

        when level4 => s(159 downto 128) <= s_i;

                       a_i <= a_buf(159 downto 128);

                       b_i <= b_buf(159 downto 128);

                       c_in_i <= c_out_i;

        when level5 => s(191 downto 160) <= s_i;

                       a_i <= a_buf(191 downto 160);