data/full_repos/permissive/217756734/Verilog2001/Full AES Design And Data Communication/mix_columns.v
1: b'%Error: Cannot find file containing module: AES\n        ... Looked in:\n             data/full_repos/permissive/217756734/Verilog2001/Full/AES\n             data/full_repos/permissive/217756734/Verilog2001/Full/AES.v\n             data/full_repos/permissive/217756734/Verilog2001/Full/AES.sv\n             AES\n             AES.v\n             AES.sv\n             obj_dir/AES\n             obj_dir/AES.v\n             obj_dir/AES.sv\n%Error: Cannot find file containing module: Design\n%Error: Cannot find file containing module: And\n%Error: Cannot find file containing module: Data\n%Error: Cannot find file containing module: Communication,data/full_repos/permissive/217756734\n%Error: Cannot find file containing module: data/full_repos/permissive/217756734/Verilog2001/Full\n%Error: Cannot find file containing module: Communication/mix_columns.v\n%Error: Exiting due to 7 error(s)\n'
module mix_columns #(
	parameter ENCRYPT = 1
)(
	input [127:0] inputData,
	input startTransition,
	output reg [127:0] outputData
);

reg [10:0] tempXORdValue;
reg [7:0] MSDMatrix [0:15];
reg [7:0] row01 [0:3];
reg [7:0] row02 [0:3];
reg [7:0] row03 [0:3];
reg [7:0] row04 [0:3];

initial begin
	
	if(ENCRYPT == 1) begin 
		MSDMatrix[0]  = 8'h02;
		MSDMatrix[1]  = 8'h01;
		MSDMatrix[2]  = 8'h01;
		MSDMatrix[3]  = 8'h03;
		MSDMatrix[4]  = 8'h03;
		MSDMatrix[5]  = 8'h02;
		MSDMatrix[6]  = 8'h01;
		MSDMatrix[7]  = 8'h01;
		MSDMatrix[8]  = 8'h01;
		MSDMatrix[9]  = 8'h03;
		MSDMatrix[10] = 8'h02;
		MSDMatrix[11] = 8'h01;
		MSDMatrix[12] = 8'h01;
		MSDMatrix[13] = 8'h01;
		MSDMatrix[14] = 8'h03;
		MSDMatrix[15] = 8'h02;
	end
	if (ENCRYPT == 0) begin 
		MSDMatrix[0]  = 8'h0e;
		MSDMatrix[1]  = 8'h09;
		MSDMatrix[2]  = 8'h0d;
		MSDMatrix[3]  = 8'h0b;
		MSDMatrix[4]  = 8'h0b;
		MSDMatrix[5]  = 8'h0e;
		MSDMatrix[6]  = 8'h09;
		MSDMatrix[7]  = 8'h0d;
		MSDMatrix[8]  = 8'h0d;
		MSDMatrix[9]  = 8'h0b;
		MSDMatrix[10] = 8'h0e;
		MSDMatrix[11] = 8'h09;
		MSDMatrix[12] = 8'h09;
		MSDMatrix[13] = 8'h0d;
		MSDMatrix[14] = 8'h0b;
		MSDMatrix[15] = 8'h0e;
	end
	
	row01[0] = 8'd0;
	row01[1] = 8'd0;
	row01[2] = 8'd0;
	row01[3] = 8'd0;
	row02[0] = 8'd0;
	row02[1] = 8'd0;
	row02[2] = 8'd0;
	row02[3] = 8'd0;
	row03[0] = 8'd0;
	row03[1] = 8'd0;
	row03[2] = 8'd0;
	row03[3] = 8'd0;
	row04[0] = 8'd0;
	row04[1] = 8'd0;
	row04[2] = 8'd0;
	row04[3] = 8'd0;

end


always @(posedge startTransition) begin: mixColumns

	integer columns;
	integer i;
	i = 0;
	for(columns = 0; columns < 128; columns = columns + 32) begin 
		row01[i] = (GF_mul(inputData[columns +: 8], MSDMatrix[0])		  ^
						GF_mul(inputData[(columns + 8) +: 8], MSDMatrix[4])  ^
						GF_mul(inputData[(columns + 16) +: 8], MSDMatrix[8]) ^ 
						GF_mul(inputData[(columns + 24) +: 8], MSDMatrix[12]));
						
		row02[i] = (GF_mul(inputData[columns +: 8], MSDMatrix[1])   	  ^ 
						GF_mul(inputData[(columns + 8) +: 8], MSDMatrix[5])  ^
						GF_mul(inputData[(columns + 16) +: 8], MSDMatrix[9]) ^ 
						GF_mul(inputData[(columns + 24) +: 8], MSDMatrix[13]));
				
		row03[i] = (GF_mul(inputData[columns +: 8], MSDMatrix[2])   	  ^ 
						GF_mul(inputData[(columns + 8) +: 8], MSDMatrix[6])  ^
						GF_mul(inputData[(columns + 16) +: 8], MSDMatrix[10])^ 
						GF_mul(inputData[(columns + 24) +: 8], MSDMatrix[14]));
				
		row04[i] = (GF_mul(inputData[columns +: 8], MSDMatrix[3])  		  ^ 
						GF_mul(inputData[(columns + 8) +: 8], MSDMatrix[7])  ^
						GF_mul(inputData[(columns + 16) +: 8], MSDMatrix[11])^ 
						GF_mul(inputData[(columns + 24) +: 8], MSDMatrix[15]));
		
		i = i + 1;
	end
	
	outputData = {row04[3], row03[3], row02[3], row01[3],
					  row04[2], row03[2], row02[2], row01[2],
					  row04[1], row03[1], row02[1], row01[1],
					  row04[0], row03[0], row02[0], row01[0]};
end



function [7:0] GF_mul;
	input [7:0] inputValue;
	input [7:0] MSDValue;
begin
	tempXORdValue = 11'b00000000000;
	
	if(MSDValue[0] == 1'b1) begin
		tempXORdValue = inputValue;
	end
	if (MSDValue[1] == 1'b1) begin
		tempXORdValue = tempXORdValue ^ (inputValue << 1);
	end
	if (MSDValue[2] == 1'b1) begin
		tempXORdValue = tempXORdValue ^ (inputValue << 2);
	end
	if (MSDValue[3] == 1'b1) begin
		tempXORdValue = tempXORdValue ^ (inputValue << 3);
	end



	if (tempXORdValue >= 11'd256) begin

		if (tempXORdValue >= 11'd1024) begin
			tempXORdValue = tempXORdValue ^ 11'd1132;
		end
		if (tempXORdValue >= 11'd512 & tempXORdValue <= 11'd1023) begin
			tempXORdValue = tempXORdValue ^ 11'd566;
		end
		if (tempXORdValue >= 11'd256 & tempXORdValue <= 11'd511) begin
			tempXORdValue = tempXORdValue ^ 11'd283;
		end
	end
	GF_mul = tempXORdValue[7:0];
end endfunction

endmodule
module mix_columns #(
	parameter ENCRYPT = 1
)(
	input [127:0] inputData,
	input startTransition,
	output reg [127:0] outputData
);


reg [10:0] tempXORdValue;
reg [7:0] MSDMatrix [0:15];
reg [7:0] row01 [0:3];
reg [7:0] row02 [0:3];
reg [7:0] row03 [0:3];
reg [7:0] row04 [0:3];

initial begin
	
	if(ENCRYPT == 1) begin 
		MSDMatrix[0]  = 8'h02;
		MSDMatrix[1]  = 8'h01;
		MSDMatrix[2]  = 8'h01;
		MSDMatrix[3]  = 8'h03;
		MSDMatrix[4]  = 8'h03;
		MSDMatrix[5]  = 8'h02;
		MSDMatrix[6]  = 8'h01;
		MSDMatrix[7]  = 8'h01;
		MSDMatrix[8]  = 8'h01;
		MSDMatrix[9]  = 8'h03;
		MSDMatrix[10] = 8'h02;
		MSDMatrix[11] = 8'h01;
		MSDMatrix[12] = 8'h01;
		MSDMatrix[13] = 8'h01;
		MSDMatrix[14] = 8'h03;
		MSDMatrix[15] = 8'h02;
	end
	if (ENCRYPT == 0) begin 
		MSDMatrix[0]  = 8'h0e;
		MSDMatrix[1]  = 8'h09;
		MSDMatrix[2]  = 8'h0d;
		MSDMatrix[3]  = 8'h0b;
		MSDMatrix[4]  = 8'h0b;
		MSDMatrix[5]  = 8'h0e;
		MSDMatrix[6]  = 8'h09;
		MSDMatrix[7]  = 8'h0d;
		MSDMatrix[8]  = 8'h0d;
		MSDMatrix[9]  = 8'h0b;
		MSDMatrix[10] = 8'h0e;
		MSDMatrix[11] = 8'h09;
		MSDMatrix[12] = 8'h09;
		MSDMatrix[13] = 8'h0d;
		MSDMatrix[14] = 8'h0b;
		MSDMatrix[15] = 8'h0e;
	end
	
	row01[0] = 8'd0;
	row01[1] = 8'd0;
	row01[2] = 8'd0;
	row01[3] = 8'd0;
	row02[0] = 8'd0;
	row02[1] = 8'd0;
	row02[2] = 8'd0;
	row02[3] = 8'd0;
	row03[0] = 8'd0;
	row03[1] = 8'd0;
	row03[2] = 8'd0;
	row03[3] = 8'd0;
	row04[0] = 8'd0;
	row04[1] = 8'd0;
	row04[2] = 8'd0;
	row04[3] = 8'd0;

end


always @(posedge startTransition) begin: mixColumns

	integer columns;
	integer i;
	i = 0;
	for(columns = 0; columns < 128; columns = columns + 32) begin 
		row01[i] = (GF_mul(inputData[columns +: 8], MSDMatrix[0])		  ^
						GF_mul(inputData[(columns + 8) +: 8], MSDMatrix[4])  ^
						GF_mul(inputData[(columns + 16) +: 8], MSDMatrix[8]) ^ 
						GF_mul(inputData[(columns + 24) +: 8], MSDMatrix[12]));
						
		row02[i] = (GF_mul(inputData[columns +: 8], MSDMatrix[1])   	  ^ 
						GF_mul(inputData[(columns + 8) +: 8], MSDMatrix[5])  ^
						GF_mul(inputData[(columns + 16) +: 8], MSDMatrix[9]) ^ 
						GF_mul(inputData[(columns + 24) +: 8], MSDMatrix[13]));
				
		row03[i] = (GF_mul(inputData[columns +: 8], MSDMatrix[2])   	  ^ 
						GF_mul(inputData[(columns + 8) +: 8], MSDMatrix[6])  ^
						GF_mul(inputData[(columns + 16) +: 8], MSDMatrix[10])^ 
						GF_mul(inputData[(columns + 24) +: 8], MSDMatrix[14]));
				
		row04[i] = (GF_mul(inputData[columns +: 8], MSDMatrix[3])  		  ^ 
						GF_mul(inputData[(columns + 8) +: 8], MSDMatrix[7])  ^
						GF_mul(inputData[(columns + 16) +: 8], MSDMatrix[11])^ 
						GF_mul(inputData[(columns + 24) +: 8], MSDMatrix[15]));
		
		i = i + 1;
	end
	
	outputData = {row04[3], row03[3], row02[3], row01[3],
					  row04[2], row03[2], row02[2], row01[2],
					  row04[1], row03[1], row02[1], row01[1],
					  row04[0], row03[0], row02[0], row01[0]};
end



function [7:0] GF_mul;
	input [7:0] inputValue;
	input [7:0] MSDValue;
begin
	tempXORdValue = 11'b00000000000;
	
	if(MSDValue[0] == 1'b1) begin
		tempXORdValue = inputValue;
	end
	if (MSDValue[1] == 1'b1) begin
		tempXORdValue = tempXORdValue ^ (inputValue << 1);
	end
	if (MSDValue[2] == 1'b1) begin
		tempXORdValue = tempXORdValue ^ (inputValue << 2);
	end
	if (MSDValue[3] == 1'b1) begin
		tempXORdValue = tempXORdValue ^ (inputValue << 3);
	end



	if (tempXORdValue >= 11'd256) begin

		if (tempXORdValue >= 11'd1024) begin
			tempXORdValue = tempXORdValue ^ 11'd1132;
		end
		if (tempXORdValue >= 11'd512 & tempXORdValue <= 11'd1023) begin
			tempXORdValue = tempXORdValue ^ 11'd566;
		end
		if (tempXORdValue >= 11'd256 & tempXORdValue <= 11'd511) begin
			tempXORdValue = tempXORdValue ^ 11'd283;
		end
	end
	GF_mul = tempXORdValue[7:0];
end endfunction

endmodule