`` set configurations { {} {ACC_PIPE} {ACC_PIPE MIX_SHIFT_REG} } ::tgpp::renameOutput "" foreach conf $configurations { ::tgpp::off all set c [list drygascon128] if {"" != $conf} { set c [concat $c $conf] } set name [join $c "_"].v #puts $name ::tgpp::on "$name" `` //Configuration flags: "`$conf`" `backtick`timescale 1ns / 1ps `backtick`default_nettype none `` set ACC_PIPE 0 set MIX_SHIFT_REG 0 set MIX_PIPE_IDX 0 set MIX_PIPE_XW 0 set MIX_PIPE_OUT 0 set CORE_PIPE 0 foreach a $conf { set $a 1 } set MIX_PIPE [expr $MIX_PIPE_IDX | $MIX_PIPE_XW | $MIX_PIPE_OUT] set CORE_PIPE_S0 $CORE_PIPE if {$MIX_PIPE && $CORE_PIPE} { error "can't pipe both MIX and CORE" } set PIPE [expr $MIX_PIPE || $CORE_PIPE] if {$PIPE && $MIX_SHIFT_REG} { error "can't pipe and use shift reg for MIX" } `` module birotr( input wire [64-1:0] din, input wire [ 6-1:0] shift, output reg [64-1:0] out ); wire [32-1:0] i0 = din[0*32+:32]; wire [32-1:0] i1 = din[1*32+:32]; wire [ 6-1:0] shift2 = shift>>1; wire [ 6-1:0] shift3 = (shift2 + 1'b1) % 6'd32; always @* begin if(shift & 1'b1) begin out[ 0+:32] = (i1>>shift2) | (i1 << (6'd32-shift2)); out[32+:32] = (i0>>shift3) | (i0 << (6'd32-shift3)); end else begin out[ 0+:32] = (i0>>shift2) | (i0 << (6'd32-shift2)); out[32+:32] = (i1>>shift2) | (i1 << (6'd32-shift2)); end end endmodule module gascon5_round( ``if {$CORE_PIPE} {`` input wire clk, input wire clk_en, ``}`` input wire [320-1:0] din, input wire [4-1:0] round, output reg [320-1:0] out ); wire [5*6-1:0] rot_lut0 = {6'd07,6'd10,6'd01,6'd61,6'd19}; wire [5*6-1:0] rot_lut1 = {6'd40,6'd17,6'd06,6'd38,6'd28}; `` set rot_lut0 {6'd19 6'd61 6'd01 6'd10 6'd07} set rot_lut1 {6'd28 6'd38 6'd06 6'd17 6'd40} `` reg [7:0] round_constant; always @* round_constant = (((4'hf - round)<<4) | round); reg [320-1:0] add_constant_out; always @* add_constant_out = din ^ {{5*64-8-2*64{1'b0}},round_constant,{2*64{1'b0}}}; reg [320-1:0] sbox_stage0; ``if {$CORE_PIPE_S0} { proc := {} {return "<="} `` always @(posedge clk) if(clk_en) begin ``} else { proc := {} {return "="} `` always @* begin ``}`` sbox_stage0 `:=` add_constant_out; `` set mid 2 set cwords 5 for {set i 0} {$i <= $mid} {incr i} { set d [expr 2*$i] set s [expr ($cwords + $d - 1) % $cwords] `` sbox_stage0[`$d`*64+:64] `:=` add_constant_out[`$d`*64+:64] ^ add_constant_out[`$s`*64+:64]; ``}`` end reg [320-1:0] t; always @* begin ``for {set i 0} {$i < $cwords} {incr i} { set s [expr ($i + 1) % $cwords] `` t[`$i`*64+:64] = (~sbox_stage0[`$i`*64+:64]) & sbox_stage0[`$s`*64+:64]; ``}`` end reg [320-1:0] sbox_stage1; always @* begin ``for {set i 0} {$i < $cwords} {incr i} { set s [expr ($i + 1) % $cwords] `` sbox_stage1[`$i`*64+:64] = sbox_stage0[`$i`*64+:64] ^ t[`$s`*64+:64]; ``}`` end reg [320-1:0] sbox_stage2; always @* begin sbox_stage2 = sbox_stage1; `` for {set i 0} {$i <= $mid} {incr i} { set s [expr 2*$i] set d [expr ($s + 1) % $cwords] `` sbox_stage2[`$d`*64+:64] = sbox_stage1[`$d`*64+:64] ^ sbox_stage1[`$s`*64+:64]; ``}`` end reg [320-1:0] sbox_stage3; always @* begin sbox_stage3 = sbox_stage2; sbox_stage3[`$mid`*64+:64] = ~sbox_stage2[`$mid`*64+:64]; end wire [320-1:0] lin_layer_r0; wire [320-1:0] lin_layer_r1; ``for {set i 0} {$i < $cwords} {incr i} { set r0 [lindex $rot_lut0 $i] set r1 [lindex $rot_lut1 $i] `` birotr u_birotr0`$i`(.out(lin_layer_r0[`$i`*64+:64]), .din(sbox_stage3[`$i`*64+:64]), .shift(`$r0`)); birotr u_birotr1`$i`(.out(lin_layer_r1[`$i`*64+:64]), .din(sbox_stage3[`$i`*64+:64]), .shift(`$r1`)); ``}`` reg [320-1:0] lin_layer; always @* begin ``for {set i 0} {$i < $cwords} {incr i} {`` lin_layer[`$i`*64+:64] = sbox_stage3[`$i`*64+:64] ^ lin_layer_r0[`$i`*64+:64] ^ lin_layer_r1[`$i`*64+:64]; ``}`` end always @* out = lin_layer; endmodule module mixsx32( ``if {$MIX_PIPE} {`` input wire clk, input wire clk_en, ``}`` input wire [320-1:0] c, input wire [128-1:0] x, input wire [10-1:0] d, output reg [320-1:0] out ); ``for {set j 0} {$j<5} {incr j} {`` reg [2-1:0] idx`$j`; reg [32-1:0] xw`$j`; `` if {$MIX_PIPE_IDX} {`` always @(posedge clk) if(clk_en) idx`$j` <= d[`$j`*2+:2]; `` } else {`` always @* idx`$j` = d[`$j`*2+:2]; `` }`` `` if {$MIX_PIPE_XW} {`` always @(posedge clk) if(clk_en) xw`$j` <= x[idx`$j`*32+:32]; `` } else {`` always @* xw`$j` = x[idx`$j`*32+:32]; `` }`` `` if {$MIX_PIPE_OUT} {`` always @(posedge clk) if(clk_en) out[`$j`*64+:64] <= c[`$j`*64+:64] ^ {{32{1'b0}},xw`$j`}; `` } else {`` always @* out[`$j`*64+:64] = c[`$j`*64+:64] ^ {{32{1'b0}},xw`$j`}; `` }`` ``}`` endmodule ``if {0} { module gascon5_round( input [320-1:0] din, input [4-1:0] round, output reg [320-1:0] out ); wire [5*6-1:0] rot_lut0 = {6'd07,6'd10,6'd01,6'd61,6'd19}; wire [5*6-1:0] rot_lut1 = {6'd40,6'd17,6'd06,6'd38,6'd28}; always @* begin: ROUND reg [4-1:0] r; integer i; integer mid; integer cwords; integer d; integer s; reg [64-1:0] wi; reg [64-1:0] ws; reg [320-1:0] t; reg [320-1:0] c; integer dummy; c = din; mid = 2; cwords = 5; //$display("i: %x",c); //add constant r = round; c[mid*64+:64] = c[mid*64+:64] ^ (((4'hf - r)<<4) | r); //$display("c mid: %x, r=%x",c[mid*64+:64],r); //$display("c: %x",c); //sbox for(i=0;i<=2;i=i+1'b1) begin d = 2*i; s = (cwords + d - 1'b1) % cwords; c[d*64+:64] = c[d*64+:64] ^ c[s*64+:64]; end for(i=0;i= 1)) r <= accu_out; ``} else {`` r <= accu_out; ``}`` if(rounds-1==cnt) begin cnt <= {4{1'b0}}; ``if {$ACC_PIPE} {`` state <= STATE_G_EXIT; ``} else {`` state <= STATE_IDLE; idle <= 1'b1; ``}`` end else begin cnt <= absorb ? {{3{1'b0}},1'b1} : cnt +1'b1; end ``if {$PIPE} {`` end ``}`` end ``if {$ACC_PIPE} {`` STATE_G_EXIT: begin r <= accu_out; state <= STATE_IDLE; idle <= 1'b1; end ``}`` default: begin end endcase end end end endmodule `backtick`default_nettype wire ``}``