Encryption if中的VHDL条件必须是静态的,并且if语句中的组件实例化必须是静态的

Encryption if中的VHDL条件必须是静态的,并且if语句中的组件实例化必须是静态的,encryption,vhdl,Encryption,Vhdl,我正在实现一个分组密码(方形),它由8轮组成(见下文)。密码必须允许两种操作模式:加密和解密(在代码中表示为mode=0或mode=1) 问题:编译成功,但出现警告(IF GENERATE中的条件必须是静态的)。我怎样才能避免这个警告?也许用其他方式重写代码 如Paebbels所述,generate不能动态使用。它需要在编译/合成时保持不变。您可以使用泛型(使用VHDL-2008 if-else生成构造): 如果要动态更改操作模式,则需要生成所有组件,并使用MUX选择输出: entity SQU

我正在实现一个分组密码(方形),它由8轮组成(见下文)。密码必须允许两种操作模式:加密和解密(在代码中表示为
mode=0
mode=1


问题:编译成功,但出现警告(IF GENERATE中的条件必须是静态的)。我怎样才能避免这个警告?也许用其他方式重写代码

如Paebbels所述,
generate
不能动态使用。它需要在编译/合成时保持不变。您可以使用泛型(使用VHDL-2008 if-else生成构造):

如果要动态更改操作模式,则需要生成所有组件,并使用MUX选择输出:

entity SQUARE is
    Port ( mode : in std_logic;
           squarein : in  STD_LOGIC_VECTOR (127 downto 0);
           key : in  STD_LOGIC_VECTOR (127 downto 0);
           squareout : out  STD_LOGIC_VECTOR (127 downto 0) 
    );
end entity;

architecture structural or SQUARE is
begin
    -- encrypt components
    s0 : entity work.preround port map(squarein, key, con0, key1, rin1);
    [...]
    s8 : entity work.lastround port map(rin8, key8, squareout_enc);
    -- decrypt components
    i8 : entity work.invround port map(squarein, key8, con7, invkey7, invrin7);
    [...]
    i0 : entity work.invpreround port map(invrin0, invkey0, squareout_dec);
    -- connect outputs
    squareout <= squareout_enc when mode='0' else squareout_dec;
end architecture;
实体正方形是
端口(模式:标准_逻辑中;
平方:标准逻辑向量中的平方(127到0);
键:标准逻辑向量(127向下至0);
squareout:out标准逻辑向量(127向下至0)
);
终端实体;
建筑结构或广场是
开始
--加密组件
s0:实体工作。预圆端口图(squarein、key、con0、key1、rin1);
[...]
s8:实体工作。最后一轮端口图(rin8,key8,squareout_enc);
--解密组件
i8:实体work.invround端口图(squarein、key8、con7、invkey7、invrin7);
[...]
i0:entity work.invpreround端口图(invrin0、invkey0、squareout_dec);
--连接输出

squareout您只能在generate语句中使用常量(包括泛型参数)。你在用信号。您想在运行时更改模式(然后需要一个信号(使用时)和多路复用器结构)还是在编译时更改模式(然后需要一个泛型参数和一个生成语句(使用时))square.vhd:9:1:错误:需要实体、体系结构、包或配置关键字。。。编译真的成功了吗?正如Brian指出的,您的代码片段不是有效的VHDL,缺少一系列声明,包括外部块round和invround。请注意波浪式提问和波浪式回答之间的相关性。查看Wei Dai的square的Crypt++库实现,我们可以看到一个单独的round,不需要invround。如果您想逐块切换模式,可以使用适当的实现。警告告诉你它会详细说明。结果不会有用。我的意思是,或多或少,让你知道我的用例。无论如何,我接受了杰博纳里的回答。
entity SQUARE is
    generic(mode : std_logic);
    Port ( squarein : in  STD_LOGIC_VECTOR (127 downto 0);
           key : in  STD_LOGIC_VECTOR (127 downto 0);
           squareout : out  STD_LOGIC_VECTOR (127 downto 0) 
    );
end entity;

architecture structural or SQUARE is
begin
    enc : if (mode = '0') generate -- do encryption
        s0 : entity work.preround port map(squarein, key, con0, key1, rin1);
        [...]
    else generate
       -- decrypt
       i8 : entity work.invround port map(squarein, key8, con7, invkey7, invrin7);
       [...]
    end generate;
end architecture;
entity SQUARE is
    Port ( mode : in std_logic;
           squarein : in  STD_LOGIC_VECTOR (127 downto 0);
           key : in  STD_LOGIC_VECTOR (127 downto 0);
           squareout : out  STD_LOGIC_VECTOR (127 downto 0) 
    );
end entity;

architecture structural or SQUARE is
begin
    -- encrypt components
    s0 : entity work.preround port map(squarein, key, con0, key1, rin1);
    [...]
    s8 : entity work.lastround port map(rin8, key8, squareout_enc);
    -- decrypt components
    i8 : entity work.invround port map(squarein, key8, con7, invkey7, invrin7);
    [...]
    i0 : entity work.invpreround port map(invrin0, invkey0, squareout_dec);
    -- connect outputs
    squareout <= squareout_enc when mode='0' else squareout_dec;
end architecture;