elockpicker
Member level 4
Hi,
I'm trying to access the bits in a shift register using a two dimensional wire in verilog but when I read the value of each member (of the two dimensional wire) the value (which is an 8-bit vector) is transposed.
Does this have anything to do with the nested generate loops ?
As you can see I have :
I also have a dummy variable to elaborate my point :
Values of Key[0][0] and dummy should be the same but one is transpose of another.
Furthermore the output values of each instantiated block are also transposed.
All of the instantiated blocks are tested successfully before.
My code has many dependencies which is very difficult to include them here(Sorry).
Can anyone give me any help ? it's making me crazy...
My Code is :
I'm trying to access the bits in a shift register using a two dimensional wire in verilog but when I read the value of each member (of the two dimensional wire) the value (which is an 8-bit vector) is transposed.
Does this have anything to do with the nested generate loops ?
As you can see I have :
Code:
generate for(j = 0; j < 16; j = j+1)
begin :Key_Assignment_1
for(n = 0; n < 13; n = n+1)
begin :Key_Assignment_2
assign Key[n][j] = KEY_BITS[(n*128+(j+1)*8-1):(n*128+(j)*8)];
end
end
endgenerate
I also have a dummy variable to elaborate my point :
Code:
wire [7:0] dummy ;
assign dummy = KEY_BITS[7:0];
Values of Key[0][0] and dummy should be the same but one is transpose of another.
Furthermore the output values of each instantiated block are also transposed.
All of the instantiated blocks are tested successfully before.
My code has many dependencies which is very difficult to include them here(Sorry).
Can anyone give me any help ? it's making me crazy...
My Code is :
Code:
module encryptor
(
output wire [7:0]
dout00,dout01,dout02,dout03,
dout10,dout11,dout12,dout13,
dout20,dout21,dout22,dout23,
dout30,dout31,dout32,dout33,
input wire [7:0]
din00,din01,din02,din03,
din10,din11,din12,din13,
din20,din21,din22,din23,
din30,din31,din32,din33,
input wire
keyload,clk
);
//- Variables, Registers and Parameters ---------------------------------------
parameter k = 11; // Number of rounds for 128-bit mode = 11
genvar j,n;
integer i;
reg [1663:0] KEY_BITS; // Shift-register that holds the 13*128 key bits
wire [7:0] Key [k+1:0][15:0]; // Provides access to different round keys
wire [7:0] R[k:0][15:0]; // Signals between encryption rounds
wire [7:0] sigma_rounds [15:0]; // Input (from the first Key-Addition) to first stage of the 11 rounds
reg [7:0] sigma_rounds_reg [15:0];
wire [7:0] rounds_gamma [15:0]; // Output from last stage of the 11 rounds
reg [7:0] rounds_gamma_reg [15:0];
wire [7:0] gamma_tau [15:0]; // Output of the last SBOX which goes to the last Transposition
wire [7:0] tau_theta [15:0]; // Output of the last Transposition and input to the last Key-Addition
reg [7:0] tau_theta_reg [15:0];
//- Instantiations ------------------------------------------------------------
generate for(j = 0; j < k; j = j+1) // 11 Rounds of encryption
begin : Encryption_Rounds
enciphering_round ROUNDS
(
.dout00(R[j+1][0 ]),.dout01(R[j+1][1 ]),.dout02(R[j+1][2 ]),.dout03(R[j+1][3 ]),
.dout10(R[j+1][4 ]),.dout11(R[j+1][5 ]),.dout12(R[j+1][6 ]),.dout13(R[j+1][7 ]),
.dout20(R[j+1][8 ]),.dout21(R[j+1][9 ]),.dout22(R[j+1][10]),.dout23(R[j+1][11]),
.dout30(R[j+1][12]),.dout31(R[j+1][13]),.dout32(R[j+1][14]),.dout33(R[j+1][15]),
.din00(R[j][0 ]),.din01(R[j][1 ]),.din02(R[j][2 ]),.din03(R[j][3 ]),
.din10(R[j][4 ]),.din11(R[j][5 ]),.din12(R[j][6 ]),.din13(R[j][7 ]),
.din20(R[j][8 ]),.din21(R[j][9 ]),.din22(R[j][10]),.din23(R[j][11]),
.din30(R[j][12]),.din31(R[j][13]),.din32(R[j][14]),.din33(R[j][15]),
.k00(Key[j+1][0 ]),.k01(Key[j+1][1 ]),.k02(Key[j+1][2 ]),.k03(Key[j+1][3 ]),
.k10(Key[j+1][4 ]),.k11(Key[j+1][5 ]),.k12(Key[j+1][6 ]),.k13(Key[j+1][7 ]),
.k20(Key[j+1][8 ]),.k21(Key[j+1][9 ]),.k22(Key[j+1][10]),.k23(Key[j+1][11]),
.k30(Key[j+1][12]),.k31(Key[j+1][13]),.k32(Key[j+1][14]),.k33(Key[j+1][15]),
.clk(clk)
);
end
endgenerate
keyaddition KEYADD // First Key-Addition, Output Signal = sigma_rounds
(
.a00(din00),.a01(din01),.a02(din02),.a03(din03),
.a10(din10),.a11(din11),.a12(din12),.a13(din13),
.a20(din20),.a21(din21),.a22(din22),.a23(din23),
.a30(din30),.a31(din31),.a32(din32),.a33(din33),
.b00(Key[0][0 ]),.b01(Key[0][1 ]),.b02(Key[0][2 ]),.b03(Key[0][3 ]),
.b10(Key[0][4 ]),.b11(Key[0][5 ]),.b12(Key[0][6 ]),.b13(Key[0][7 ]),
.b20(Key[0][8 ]),.b21(Key[0][9 ]),.b22(Key[0][10]),.b23(Key[0][11]),
.b30(Key[0][12]),.b31(Key[0][13]),.b32(Key[0][14]),.b33(Key[0][15]),
.c00(sigma_rounds[0 ]),.c01(sigma_rounds[1 ]),.c02(sigma_rounds[2 ]),.c03(sigma_rounds[3 ]),
.c10(sigma_rounds[4 ]),.c11(sigma_rounds[5 ]),.c12(sigma_rounds[6 ]),.c13(sigma_rounds[7 ]),
.c20(sigma_rounds[8 ]),.c21(sigma_rounds[9 ]),.c22(sigma_rounds[10]),.c23(sigma_rounds[11]),
.c30(sigma_rounds[12]),.c31(sigma_rounds[13]),.c32(sigma_rounds[14]),.c33(sigma_rounds[15])
);
generate for(j = 0; j < 16; j = j + 1) // SBOX after 11 rounds, Output Signal = gamma_tau
begin : SBOX
sbox s_box(.y(gamma_tau[j]),.x(rounds_gamma_reg[j]),.clk(clk));
end
endgenerate
transposition TRANSPOSE // Transposition after SBOX (after 11 rounds), Output Signal = tau_theta
(
.a00(gamma_tau[0 ]),.a01(gamma_tau[1 ]),.a02(gamma_tau[2 ]),.a03(gamma_tau[3 ]),
.a10(gamma_tau[4 ]),.a11(gamma_tau[5 ]),.a12(gamma_tau[6 ]),.a13(gamma_tau[7 ]),
.a20(gamma_tau[8 ]),.a21(gamma_tau[9 ]),.a22(gamma_tau[10]),.a23(gamma_tau[11]),
.a30(gamma_tau[12]),.a31(gamma_tau[13]),.a32(gamma_tau[14]),.a33(gamma_tau[15]),
.b00(tau_theta[0 ]),.b01(tau_theta[1 ]),.b02(tau_theta[2 ]),.b03(tau_theta[3 ]),
.b10(tau_theta[4 ]),.b11(tau_theta[5 ]),.b12(tau_theta[6 ]),.b13(tau_theta[7 ]),
.b20(tau_theta[8 ]),.b21(tau_theta[9 ]),.b22(tau_theta[10]),.b23(tau_theta[11]),
.b30(tau_theta[12]),.b31(tau_theta[13]),.b32(tau_theta[14]),.b33(tau_theta[15])
);
keyaddition KEYADD2 // Key-Addition at the end of the encryption, Output Signal = dout
(
.a00(tau_theta_reg[0 ]),.a01(tau_theta_reg[1 ]),.a02(tau_theta_reg[2 ]),.a03(tau_theta_reg[3 ]),
.a10(tau_theta_reg[4 ]),.a11(tau_theta_reg[5 ]),.a12(tau_theta_reg[6 ]),.a13(tau_theta_reg[7 ]),
.a20(tau_theta_reg[8 ]),.a21(tau_theta_reg[9 ]),.a22(tau_theta_reg[10]),.a23(tau_theta_reg[11]),
.a30(tau_theta_reg[12]),.a31(tau_theta_reg[13]),.a32(tau_theta_reg[14]),.a33(tau_theta_reg[15]),
.b00(Key[k+1][0 ]),.b01(Key[k+1][1 ]),.b02(Key[k+1][2 ]),.b03(Key[k+1][3 ]),
.b10(Key[k+1][4 ]),.b11(Key[k+1][5 ]),.b12(Key[k+1][6 ]),.b13(Key[k+1][7 ]),
.b20(Key[k+1][8 ]),.b21(Key[k+1][9 ]),.b22(Key[k+1][10]),.b23(Key[k+1][11]),
.b30(Key[k+1][12]),.b31(Key[k+1][13]),.b32(Key[k+1][14]),.b33(Key[k+1][15]),
.c00(dout00),.c01(dout01),.c02(dout02),.c03(dout03),
.c10(dout10),.c11(dout11),.c12(dout12),.c13(dout13),
.c20(dout20),.c21(dout21),.c22(dout22),.c23(dout23),
.c30(dout30),.c31(dout31),.c32(dout32),.c33(dout33)
);
//- Continuous Assigments------------------------------------------------------
generate for(j = 0; j < 16; j = j+1)
begin :Key_Assignment_1
for(n = 0; n < 13; n = n+1)
begin :Key_Assignment_2
assign Key[n][j] = KEY_BITS[(n*128+(j+1)*8-1):(n*128+(j)*8)];
end
end
endgenerate
wire [7:0] dummy ;
assign dummy = KEY_BITS[7:0];
assign R[0][0 ] = sigma_rounds_reg[0 ];
assign R[0][1 ] = sigma_rounds_reg[1 ];
assign R[0][2 ] = sigma_rounds_reg[2 ];
assign R[0][3 ] = sigma_rounds_reg[3 ];
assign R[0][4 ] = sigma_rounds_reg[4 ];
assign R[0][5 ] = sigma_rounds_reg[5 ];
assign R[0][6 ] = sigma_rounds_reg[6 ];
assign R[0][7 ] = sigma_rounds_reg[7 ];
assign R[0][8 ] = sigma_rounds_reg[8 ];
assign R[0][9 ] = sigma_rounds_reg[9 ];
assign R[0][10] = sigma_rounds_reg[10];
assign R[0][11] = sigma_rounds_reg[11];
assign R[0][12] = sigma_rounds_reg[12];
assign R[0][13] = sigma_rounds_reg[13];
assign R[0][14] = sigma_rounds_reg[14];
assign R[0][15] = sigma_rounds_reg[15];
assign rounds_gamma[0 ] = R[k][0 ];
assign rounds_gamma[1 ] = R[k][1 ];
assign rounds_gamma[2 ] = R[k][2 ];
assign rounds_gamma[3 ] = R[k][3 ];
assign rounds_gamma[4 ] = R[k][4 ];
assign rounds_gamma[5 ] = R[k][5 ];
assign rounds_gamma[6 ] = R[k][6 ];
assign rounds_gamma[7 ] = R[k][7 ];
assign rounds_gamma[8 ] = R[k][8 ];
assign rounds_gamma[9 ] = R[k][9 ];
assign rounds_gamma[10] = R[k][10];
assign rounds_gamma[11] = R[k][11];
assign rounds_gamma[12] = R[k][12];
assign rounds_gamma[13] = R[k][13];
assign rounds_gamma[14] = R[k][14];
assign rounds_gamma[15] = R[k][15];
//- Behavioral Statements -----------------------------------------------------
always @(posedge clk)
begin
if(!keyload) // Encrypts din
begin
for(i = 0; i < 16; i = i+1)
sigma_rounds_reg[i] <= sigma_rounds[i];
for(i = 0; i < 16; i = i+1)
rounds_gamma_reg[i] <= rounds_gamma[i];
for(i = 0; i < 16; i = i+1)
tau_theta_reg[i] <= tau_theta[i];
end
else if(keyload)
KEY_BITS <= {KEY_BITS[1535:0],din33,din32,din31,din30,
din23,din22,din21,din20,
din13,din12,din11,din10,
din03,din02,din01,din00};
end//-----------------------------------------------------------------------------
endmodule