mode_top.v 2.04 KB
Newer Older
lwc-tester committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
`include "params.vh"
module mode_top (
		 output [BUSWIDTH-1:0] 	  pdo,
		 output [5:0] 		  constant,

		 input [BUSWIDTH-1:0] 	  pdi,
		 input [BUSWIDTH-1:0] 	  sdi,
		 input [7:0] 		  dold, dnew,
		 input [BUSWIDTHBYTE-1:0] decrypt,
		 input 			  clk,
		 input 			  srst, senc, sse,
		 input 			  xrst, xenc, xse,
		 input 			  erst,
		 input 			  sl,
`ifdef TWO
		 input 			  vse, venc, vf, vl, ll, kdf, fv,
 `ifdef MR
		 input vs2,
 `endif
`endif		 
		 input 			  correct_cnt
   ) ;
   parameter BUSWIDTH = 32;
   parameter BUSWIDTHBYTE = 4;
   parameter FFTYPE = 1;   
      
   wire [127:0]  tk1;
   wire [127:0]  tka;
   wire [127:0]  tkc;   
   wire [127:0]  skinnyS;
   wire [127:0]  skinnyX;
   wire [127:0]  S, TKX;
   wire [BUSWIDTH-1:0] li;
`ifdef TWO
   wire [BUSWIDTH-1:0] vo;
   wire [127:0]        K;  
`endif

   assign tkc = correct_cnt ? TKX : tka;
`ifdef TWO
   assign li = ll ? vo : (sl ? pdo : sdi);   
`else
   assign li = sl ? pdo : sdi;   
`endif

`ifdef TWO
   assign K = tka ^ {128'h01};
`endif
   
   generate if (BUSWIDTH == 32) begin
      state_update_32b #(.FFTYPE(FFTYPE)) 
      STATE (.state(S), .pdo(pdo), .skinny_state(skinnyS), .pdi(pdi),
`ifdef TWO	     
	     .vl(vl), .vf(vf), .vse(vse), .venc(venc), .vo(vo), .kdf(kdf), .fv(fv),
 `ifdef MR
	     .vs2(vs2), .sdi(sdi),
 `endif
`endif	     
	     .clk(clk), .rst(srst), .enc(senc), .se(sse),
	     .decrypt(decrypt));
`ifdef TWO
      tkx_update_32b TKEYX (.tkx(TKX), .skinny_tkx(skinnyX), .skinny_tkx_revert(tk1), 
			    .sdi(li), .clk(clk), .rst(xrst), .enc(xenc), .se(xse), .L(K), .kdf(kdf));
`else
      tkx_update_32b TKEYX (.tkx(TKX), .skinny_tkx(skinnyX), .skinny_tkx_revert(tk1), 
			    .sdi(li), .clk(clk), .rst(xrst), .enc(xenc), .se(xse));
`endif
   end
   endgenerate
   
   pt8 permA (.tk1o(tka), .tk1i(TKX));
   doubling CNT (.so(tk1), .si(tkc), .dold(dold), .dnew(dnew));

   RoundFunction SKINNY (.CLK(clk), .INIT(erst), .ROUND_KEY(TKX), 
			 .ROUND_IN(S), .ROUND_OUT(skinnyS), .CONST_OUT(constant));
   KeyExpansion KEYEXP (.ROUND_KEY(skinnyX), .KEY(TKX));
   
endmodule // mode_top