OpenCores
URL https://opencores.org/ocsvn/aes_highthroughput_lowarea/aes_highthroughput_lowarea/trunk

Subversion Repositories aes_highthroughput_lowarea

[/] [aes_highthroughput_lowarea/] [trunk/] [verilog/] [bench/] [tb_kat.v] - Diff between revs 8 and 11

Only display areas with differences | Details | Blame | View Log

Rev 8 Rev 11
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
//      Project:                        High Throughput & Low Area AES Core 
//      Project:                        High Throughput & Low Area AES Core 
//
//
//      File name:                      tb_kat.v                        (Jan 1, 2011)
//      File name:                      tb_kat.v                        (Jan 1, 2011)
//
//
//      Writer:                         Moti Litochevski 
//      Writer:                         Moti Litochevski 
//
//
//      Description:
//      Description:
//              This file contains the core test bench to check compatibility with the Known 
//              This file contains the core test bench to check compatibility with the Known 
//              Answer Test (KAT) vectors. The test bench runs all files listed in the 
//              Answer Test (KAT) vectors. The test bench runs all files listed in the 
//              "KAT_files.txt" file. 
//              "KAT_files.txt" file. 
//              Note that only ECB mode test vectors should be included since other modes require 
//              Note that only ECB mode test vectors should be included since other modes require 
//              additional logic to be implemented around the AES algorithm core. 
//              additional logic to be implemented around the AES algorithm core. 
//
//
//      Revision History:
//      Revision History:
//
//
//      Rev <revnumber>                 <Date>                  <owner> 
//      Rev <revnumber>                 <Date>                  <owner> 
//              <comment>
//              <comment>
// 
// 
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
 
 
`timescale 1ns / 10ps
`timescale 1ns / 10ps
 
 
module test ();
module test ();
 
 
// define input list file name 
// define input list file name 
`define IN_FILE         "KAT_files.txt"
`define IN_FILE         "KAT_files.txt"
 
 
// global definitions 
// global definitions 
`define EOF                             -1
`define EOF                             -1
 
`define EOF16                   16'hffff
`define CHAR_CR                 8'h0d
`define CHAR_CR                 8'h0d
`define CHAR_LF                 8'h0a
`define CHAR_LF                 8'h0a
`define CHAR_0                  8'h30
`define CHAR_0                  8'h30
`define CHAR_9                  8'h39
`define CHAR_9                  8'h39
`define CHAR_Eq                 8'h3D
`define CHAR_Eq                 8'h3D
`define CHAR_A                  8'h41
`define CHAR_A                  8'h41
`define CHAR_F                  8'h46
`define CHAR_F                  8'h46
`define CHAR_Z                  8'h5A
`define CHAR_Z                  8'h5A
`define CHAR_a                  8'h61
`define CHAR_a                  8'h61
`define CHAR_f                  8'h66
`define CHAR_f                  8'h66
`define CHAR_z                  8'h7A
`define CHAR_z                  8'h7A
 
 
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
// test bench signals 
// test bench signals 
reg clk;
reg clk;
reg reset;
reg reset;
reg [255:0] in_file_name;
reg [255:0] in_file_name;
reg key_start, enc_dec, data_in_valid, enable, test_start;
reg key_start, enc_dec, data_in_valid, enable, test_start;
reg [255:0] key_in;
reg [255:0] key_in;
reg [1:0] key_mode;
reg [1:0] key_mode;
reg [127:0] data_in, exp_data_out, init_vec, tmp_val;
reg [127:0] data_in, exp_data_out, init_vec, tmp_val;
wire [127:0] data_out;
wire [127:0] data_out;
wire key_ready, ready_out;
wire key_ready, ready_out;
reg [15:0] param_name;
reg [15:0] param_name;
integer listfid, infid, intmp, tst_count, key_len;
integer listfid, infid, intmp, tst_count, key_len;
 
 
// function to read a line from an input file 
// function to read a line from an input file 
function [255:0] fgetl;
function [255:0] fgetl;
input [31:0] fileid;
input [31:0] fileid;
integer intint;
integer intint;
reg [255:0] outline;
reg [255:0] outline;
begin
begin
        // init output line 
        // init output line 
        outline = 0;
        outline = 0;
 
 
        // pass over any CR and LF characters 
        // pass over any CR and LF characters 
        intint = $fgetc(fileid);
        intint = $fgetc(fileid);
        while (((intint == `CHAR_CR) || (intint == `CHAR_LF)) && (intint != `EOF))
        while (((intint == `CHAR_CR) || (intint == `CHAR_LF)) && (intint != `EOF))
                intint = $fgetc(fileid);
                intint = $fgetc(fileid);
 
 
        // update output line 
        // update output line 
        while ((intint != `CHAR_CR) && (intint != `CHAR_LF) && (intint != `EOF))
        while ((intint != `CHAR_CR) && (intint != `CHAR_LF) && (intint != `EOF))
        begin
        begin
                outline[255:8] = outline[247:0];
                outline[255:8] = outline[247:0];
                outline[7:0] = intint;
                outline[7:0] = intint;
                intint = $fgetc(fileid);
                intint = $fgetc(fileid);
        end
        end
 
 
        // return the line read 
        // return the line read 
        fgetl = outline;
        fgetl = outline;
end
end
endfunction
endfunction
 
 
// function to read the next field name from the input file 
// function to read the next field name from the input file 
function [15:0] fgetfield;
function [15:0] fgetfield;
input [31:0] fileid;
input [31:0] fileid;
integer intint;
integer intint;
reg [15:0] outfield;
reg [15:0] outfield;
begin
begin
        // search for the start of the new line 
        // search for the start of the new line 
        intint = $fgetc(fileid);
        intint = $fgetc(fileid);
        while ((intint != `CHAR_CR) && (intint != `CHAR_LF) && (intint != `EOF))
        while ((intint != `CHAR_CR) && (intint != `CHAR_LF) && (intint != `EOF))
                intint = $fgetc(fileid);
                intint = $fgetc(fileid);
        while (((intint < `CHAR_A) || (intint > `CHAR_Z)) && (intint != `EOF))
        while (((intint < `CHAR_A) || (intint > `CHAR_Z)) && (intint != `EOF))
                intint = $fgetc(fileid);
                intint = $fgetc(fileid);
 
 
        // the first two characters of the new line are the next field name 
        // the first two characters of the new line are the next field name 
        outfield[15:8] = intint;
        outfield[15:8] = intint;
        intint = $fgetc(fileid);
        intint = $fgetc(fileid);
        outfield[7:0] = intint;
        outfield[7:0] = intint;
 
 
        // return the result 
        // return the result 
        fgetfield = outfield;
        fgetfield = outfield;
end
end
endfunction
endfunction
 
 
// function to read the file to the start of the parameter value 
// function to read the file to the start of the parameter value 
function [7:0] fgetparam;
function [7:0] fgetparam;
input [31:0] fileid;
input [31:0] fileid;
integer intint;
integer intint;
begin
begin
        // search for the equal sign 
        // search for the equal sign 
        intint = $fgetc(fileid);
        intint = $fgetc(fileid);
        while (intint != `CHAR_Eq)
        while (intint != `CHAR_Eq)
                intint = $fgetc(fileid);
                intint = $fgetc(fileid);
        // read first char of parameter 
        // read first char of parameter 
        while ((intint < `CHAR_0) || ((intint > `CHAR_9) && (intint < `CHAR_A)) ||
        while ((intint < `CHAR_0) || ((intint > `CHAR_9) && (intint < `CHAR_A)) ||
                        ((intint > `CHAR_Z) && (intint < `CHAR_a)) || (intint > `CHAR_z))
                        ((intint > `CHAR_Z) && (intint < `CHAR_a)) || (intint > `CHAR_z))
                intint = $fgetc(fileid);
                intint = $fgetc(fileid);
 
 
        // return the read character 
        // return the read character 
        fgetparam = intint;
        fgetparam = intint;
end
end
endfunction
endfunction
 
 
// function to convert a character to its HEX value 
// function to convert a character to its HEX value 
function [7:0] char2val;
function [7:0] char2val;
input [7:0] char_val;
input [7:0] char_val;
integer out_val;
integer out_val;
begin
begin
        if ((char_val >= `CHAR_0) && (char_val <= `CHAR_9))
        if ((char_val >= `CHAR_0) && (char_val <= `CHAR_9))
                out_val = char_val - `CHAR_0;
                out_val = char_val - `CHAR_0;
        else if ((char_val >= `CHAR_A) && (char_val <= `CHAR_F))
        else if ((char_val >= `CHAR_A) && (char_val <= `CHAR_F))
                out_val = char_val - `CHAR_A + 'd10;
                out_val = char_val - `CHAR_A + 'd10;
        else if ((char_val >= `CHAR_a) && (char_val <= `CHAR_f))
        else if ((char_val >= `CHAR_a) && (char_val <= `CHAR_f))
                out_val = char_val - `CHAR_a + 'd10;
                out_val = char_val - `CHAR_a + 'd10;
        else
        else
                out_val = 0;
                out_val = 0;
 
 
        // return the resulting value 
        // return the resulting value 
        char2val = out_val;
        char2val = out_val;
end
end
endfunction
endfunction
 
 
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
// test bench implementation 
// test bench implementation 
// global clock generator 
// global clock generator 
initial         clk = 1'b1;
initial         clk = 1'b1;
always          #10 clk = ~clk;
always          #10 clk = ~clk;
 
 
// gloabl reset generator 
// gloabl reset generator 
initial
initial
begin
begin
        reset = 1'b1;
        reset = 1'b1;
        #100;
        #100;
        reset = 1'b0;
        reset = 1'b0;
end
end
 
 
// cosmetics 
// cosmetics 
initial
initial
begin
begin
        // announce start of simulation 
        // announce start of simulation 
        $display("");
        $display("");
        $display("-------------------------------------");
        $display("-------------------------------------");
        $display("        AES_HT_LA Simulation");
        $display("        AES_HT_LA Simulation");
        $display("-------------------------------------");
        $display("-------------------------------------");
        $display("");
        $display("");
 
 
        // VCD dump 
        // VCD dump 
        $dumpfile("test.vcd");
        $dumpfile("test.vcd");
        $dumpvars(0, test);
        $dumpvars(0, test);
        $display("");
        $display("");
end
end
 
 
// main test bench contorl module 
// main test bench contorl module 
initial
initial
begin
begin
        // signals reset values 
        // signals reset values 
        enc_dec = 1'b0;                 // 0: encryption; 1: decryption
        enc_dec = 1'b0;                 // 0: encryption; 1: decryption
        key_mode = 'b0;                 // 0: 128; 1: 192; 2: 256 
        key_mode = 'b0;                 // 0: 128; 1: 192; 2: 256 
        key_in = 'b0;
        key_in = 'b0;
        key_start = 1'b0;
        key_start = 1'b0;
        data_in_valid = 1'b0;
        data_in_valid = 1'b0;
        data_in = 'b0;
        data_in = 'b0;
        enable = 1;
        enable = 1;
        test_start = 0;
        test_start = 0;
        @(posedge clk);
        @(posedge clk);
 
 
        // wait for global reset 
        // wait for global reset 
        wait (reset == 1'b0);
        wait (reset == 1'b0);
        repeat (10) @(posedge clk);
        repeat (10) @(posedge clk);
 
 
        // open input list file 
        // open input list file 
        listfid = $fopen(`IN_FILE, "rb");
        listfid = $fopen(`IN_FILE, "rb");
 
 
        // read first input filename 
        // read first input filename 
        in_file_name = fgetl(listfid);
        in_file_name = fgetl(listfid);
 
 
        // loop through input files 
        // loop through input files 
        while (in_file_name != 0)
        while (in_file_name != 0)
        begin
        begin
                // announce start of simulation for the current file 
                // announce start of simulation for the current file 
                $display("Starting simulation for input file: %0s", in_file_name);
                $display("Starting simulation for input file: %0s", in_file_name);
                $display("--------------------------------------------------------------------------");
                $display("--------------------------------------------------------------------------");
                $display("");
                $display("");
 
 
                // open current simulation input file 
                // open current simulation input file 
                infid = $fopen(in_file_name, "rb");
                infid = $fopen(in_file_name, "rb");
 
 
                // read core mode for the current file 
                // read core mode for the current file 
                intmp = $fgetc(infid);  // first char is "[" 
                intmp = $fgetc(infid);  // first char is "[" 
                intmp = $fgetc(infid);  // second char should be either "E" or "D" 
                intmp = $fgetc(infid);  // second char should be either "E" or "D" 
                // check read character for mode of operation 
                // check read character for mode of operation 
                if (intmp == "E")
                if (intmp == "E")
                        // set flag accordingly 
                        // set flag accordingly 
                        enc_dec = 1'b0;
                        enc_dec = 1'b0;
                else if (intmp == "D")
                else if (intmp == "D")
                        // set flag accordingly 
                        // set flag accordingly 
                        enc_dec = 1'b1;
                        enc_dec = 1'b1;
                else
                else
                begin
                begin
                        // no valid mode was found, announce error and quit simulation 
                        // no valid mode was found, announce error and quit simulation 
                        $display("ERROR: Simulation mode could not be determined!");
                        $display("ERROR: Simulation mode could not be determined!");
                        $finish;
                        $finish;
                end
                end
 
 
                // repeat reading the file till end of file 
                // repeat reading the file till end of file 
                param_name = fgetfield(infid);
                param_name = fgetfield(infid);
                while (param_name != `EOF)
                while (param_name != `EOF16)
                begin
                begin
                        // clear test start flag 
                        // clear test start flag 
                        test_start = 0;
                        test_start = 0;
 
 
                        // check read parameter name  
                        // check read parameter name  
                        if (param_name == "CO")
                        if (param_name == "CO")
                        begin
                        begin
                                // init test count 
                                // init test count 
                                tst_count = 0;
                                tst_count = 0;
                                // get file pointer to the start of value 
                                // get file pointer to the start of value 
                                intmp = fgetparam(infid);
                                intmp = fgetparam(infid);
                                // update test count value 
                                // update test count value 
                                while ((intmp >= `CHAR_0) && (intmp <= `CHAR_9))
                                while ((intmp >= `CHAR_0) && (intmp <= `CHAR_9))
                                begin
                                begin
                                        tst_count = (tst_count * 10) + (intmp - `CHAR_0);
                                        tst_count = (tst_count * 10) + (intmp - `CHAR_0);
                                        intmp = $fgetc(infid);
                                        intmp = $fgetc(infid);
                                end
                                end
                        end
                        end
                        else if (param_name == "KE")
                        else if (param_name == "KE")
                        begin
                        begin
                                // init key value and length 
                                // init key value and length 
                                key_in = 0;
                                key_in = 0;
                                key_len = 0;
                                key_len = 0;
 
 
                                // get file pointer to the start of value 
                                // get file pointer to the start of value 
                                intmp = fgetparam(infid);
                                intmp = fgetparam(infid);
 
 
                                // update key value & length 
                                // update key value & length 
                                while (((intmp >= `CHAR_0) && (intmp <= `CHAR_9)) ||
                                while (((intmp >= `CHAR_0) && (intmp <= `CHAR_9)) ||
                                       ((intmp >= `CHAR_A) && (intmp <= `CHAR_F)) ||
                                       ((intmp >= `CHAR_A) && (intmp <= `CHAR_F)) ||
                                       ((intmp >= `CHAR_a) && (intmp <= `CHAR_f)))
                                       ((intmp >= `CHAR_a) && (intmp <= `CHAR_f)))
                                begin
                                begin
                                        key_in[255:4] = key_in[251:0];
                                        key_in[255:4] = key_in[251:0];
                                        key_in[3:0] = char2val(intmp);
                                        key_in[3:0] = char2val(intmp);
                                        key_len = key_len + 4;
                                        key_len = key_len + 4;
                                        intmp = $fgetc(infid);
                                        intmp = $fgetc(infid);
                                end
                                end
 
 
                                // check key length to see if it is legal and if the key needs zero padding 
                                // check key length to see if it is legal and if the key needs zero padding 
                                if (key_len == 'd128)
                                if (key_len == 'd128)
                                begin
                                begin
                                        // update key value and mode 
                                        // update key value and mode 
                                        key_in = {key_in[127:0], 128'b0};
                                        key_in = {key_in[127:0], 128'b0};
                                        key_mode = 2'd0;
                                        key_mode = 2'd0;
                                end
                                end
                                else if (key_len == 'd192)
                                else if (key_len == 'd192)
                                begin
                                begin
                                        // update key value and mode 
                                        // update key value and mode 
                                        key_in = {key_in[191:0], 64'b0};
                                        key_in = {key_in[191:0], 64'b0};
                                        key_mode = 2'd1;
                                        key_mode = 2'd1;
                                end
                                end
                                else if (key_len == 'd256)
                                else if (key_len == 'd256)
                                begin
                                begin
                                        // update key mode 
                                        // update key mode 
                                        key_mode = 2'd2;
                                        key_mode = 2'd2;
                                end
                                end
                                else
                                else
                                begin
                                begin
                                        // illegal key length error 
                                        // illegal key length error 
                                        $display("ERROR: Illegal key length at test %0d (%0d)", tst_count, key_len);
                                        $display("ERROR: Illegal key length at test %0d (%0d)", tst_count, key_len);
                                        $finish;
                                        $finish;
                                end
                                end
                        end
                        end
                        else if (param_name == "IV")
                        else if (param_name == "IV")
                        begin
                        begin
                                // init init vector value 
                                // init init vector value 
                                init_vec = 0;
                                init_vec = 0;
 
 
                                // get file pointer to the start of value 
                                // get file pointer to the start of value 
                                intmp = fgetparam(infid);
                                intmp = fgetparam(infid);
                                // update init vector value 
                                // update init vector value 
                                while (((intmp >= `CHAR_0) && (intmp <= `CHAR_9)) ||
                                while (((intmp >= `CHAR_0) && (intmp <= `CHAR_9)) ||
                                       ((intmp >= `CHAR_A) && (intmp <= `CHAR_F)) ||
                                       ((intmp >= `CHAR_A) && (intmp <= `CHAR_F)) ||
                                       ((intmp >= `CHAR_a) && (intmp <= `CHAR_f)))
                                       ((intmp >= `CHAR_a) && (intmp <= `CHAR_f)))
                                begin
                                begin
                                        init_vec[127:4] = init_vec[123:0];
                                        init_vec[127:4] = init_vec[123:0];
                                        init_vec[3:0] = char2val(intmp);
                                        init_vec[3:0] = char2val(intmp);
                                        intmp = $fgetc(infid);
                                        intmp = $fgetc(infid);
                                end
                                end
                        end
                        end
                        else if (param_name == "CI")
                        else if (param_name == "CI")
                        begin
                        begin
                                // init temp value 
                                // init temp value 
                                tmp_val = 0;
                                tmp_val = 0;
 
 
                                // get file pointer to the start of value 
                                // get file pointer to the start of value 
                                intmp = fgetparam(infid);
                                intmp = fgetparam(infid);
                                // update temp value 
                                // update temp value 
                                while (((intmp >= `CHAR_0) && (intmp <= `CHAR_9)) ||
                                while (((intmp >= `CHAR_0) && (intmp <= `CHAR_9)) ||
                                       ((intmp >= `CHAR_A) && (intmp <= `CHAR_F)) ||
                                       ((intmp >= `CHAR_A) && (intmp <= `CHAR_F)) ||
                                       ((intmp >= `CHAR_a) && (intmp <= `CHAR_f)))
                                       ((intmp >= `CHAR_a) && (intmp <= `CHAR_f)))
                                begin
                                begin
                                        tmp_val[127:4] = tmp_val[123:0];
                                        tmp_val[127:4] = tmp_val[123:0];
                                        tmp_val[3:0] = char2val(intmp);
                                        tmp_val[3:0] = char2val(intmp);
                                        intmp = $fgetc(infid);
                                        intmp = $fgetc(infid);
                                end
                                end
 
 
                                // check simulation mode to determine if this is the last value and if 
                                // check simulation mode to determine if this is the last value and if 
                                // it is the data input or the expected data 
                                // it is the data input or the expected data 
                                if (enc_dec == 1'b0)
                                if (enc_dec == 1'b0)
                                begin
                                begin
                                        // for encryption the CIPHERTEXT is the expected result and the 
                                        // for encryption the CIPHERTEXT is the expected result and the 
                                        // simulation should start 
                                        // simulation should start 
                                        exp_data_out = tmp_val;
                                        exp_data_out = tmp_val;
                                        test_start = 1'b1;
                                        test_start = 1'b1;
                                end
                                end
                                else
                                else
                                        // for decryption the CIPHERTEXT is the input data 
                                        // for decryption the CIPHERTEXT is the input data 
                                        data_in = tmp_val;
                                        data_in = tmp_val;
                        end
                        end
                        else if (param_name == "PL")
                        else if (param_name == "PL")
                        begin
                        begin
                                // init temp value 
                                // init temp value 
                                tmp_val = 0;
                                tmp_val = 0;
 
 
                                // get file pointer to the start of value 
                                // get file pointer to the start of value 
                                intmp = fgetparam(infid);
                                intmp = fgetparam(infid);
                                // update temp value 
                                // update temp value 
                                while (((intmp >= `CHAR_0) && (intmp <= `CHAR_9)) ||
                                while (((intmp >= `CHAR_0) && (intmp <= `CHAR_9)) ||
                                       ((intmp >= `CHAR_A) && (intmp <= `CHAR_F)) ||
                                       ((intmp >= `CHAR_A) && (intmp <= `CHAR_F)) ||
                                       ((intmp >= `CHAR_a) && (intmp <= `CHAR_f)))
                                       ((intmp >= `CHAR_a) && (intmp <= `CHAR_f)))
                                begin
                                begin
                                        tmp_val[127:4] = tmp_val[123:0];
                                        tmp_val[127:4] = tmp_val[123:0];
                                        tmp_val[3:0] = char2val(intmp);
                                        tmp_val[3:0] = char2val(intmp);
                                        intmp = $fgetc(infid);
                                        intmp = $fgetc(infid);
                                end
                                end
 
 
                                // check simulation mode to determine if this is the last value and if 
                                // check simulation mode to determine if this is the last value and if 
                                // it is the data input or the expected data 
                                // it is the data input or the expected data 
                                if (enc_dec == 1'b0)
                                if (enc_dec == 1'b0)
                                        // for encryption the PLAINTEXT is the input data 
                                        // for encryption the PLAINTEXT is the input data 
                                        data_in = tmp_val;
                                        data_in = tmp_val;
                                else
                                else
                                begin
                                begin
                                        // for decryption the PLAINTEXT is the expected result and the 
                                        // for decryption the PLAINTEXT is the expected result and the 
                                        // simulation should start 
                                        // simulation should start 
                                        exp_data_out = tmp_val;
                                        exp_data_out = tmp_val;
                                        test_start = 1'b1;
                                        test_start = 1'b1;
                                end
                                end
                        end
                        end
                        else
                        else
                        begin
                        begin
                                // no matching parameter was found 
                                // no matching parameter was found 
                                $display("ERROR: Could not find a matching parameter after test %0d", tst_count);
                                $display("ERROR: Could not find a matching parameter after test %0d", tst_count);
                                $finish;
                                $finish;
                        end
                        end
 
 
                        // check if simulation should start 
                        // check if simulation should start 
                        if (test_start)
                        if (test_start)
                        begin
                        begin
                                // run core simulation 
                                // run core simulation 
                                repeat (10) @(posedge clk);
                                repeat (10) @(posedge clk);
                                // update input key 
                                // update input key 
                                key_start <= 1'b1;
                                key_start <= 1'b1;
                                @ (posedge clk);
                                @ (posedge clk);
                                key_start <= 1'b0;
                                key_start <= 1'b0;
                                @ (posedge clk);
                                @ (posedge clk);
                                // wait for key to be ready 
                                // wait for key to be ready 
                                while (!key_ready)
                                while (!key_ready)
                                        @(posedge clk);
                                        @(posedge clk);
                                // sign input data is valid 
                                // sign input data is valid 
                                data_in_valid <= 1'b1;
                                data_in_valid <= 1'b1;
                                @(posedge clk);
                                @(posedge clk);
                            data_in_valid <= 1'b0;
                            data_in_valid <= 1'b0;
                                repeat (3) @ (posedge clk);
                                repeat (3) @ (posedge clk);
                                // wait for result to be ready 
                                // wait for result to be ready 
                                while (!data_out_valid)
                                while (!data_out_valid)
                                        @ (posedge clk);
                                        @ (posedge clk);
                                @ (posedge clk);
                                @ (posedge clk);
                                // check expected result 
                                // check expected result 
                                if (exp_data_out != data_out)
                                if (exp_data_out != data_out)
                                begin
                                begin
                                        // data output error 
                                        // data output error 
                                        $display("ERROR: Expected data output error at test %0d", tst_count);
                                        $display("ERROR: Expected data output error at test %0d", tst_count);
                                        repeat (10) @(posedge clk);
                                        repeat (10) @(posedge clk);
                                        $finish;
                                        $finish;
                                end
                                end
                                else
                                else
                                begin
                                begin
                                        $display("Test finished OK!");
                                        $display("Test finished OK!");
                                        $display("");
                                        $display("");
                                end
                                end
                        end
                        end
 
 
                        // read next parameter name 
                        // read next parameter name 
                        param_name = fgetfield(infid);
                        param_name = fgetfield(infid);
                end
                end
 
 
                // close input file 
                // close input file 
                $fclose(infid);
                $fclose(infid);
 
 
                // read next input filename 
                // read next input filename 
                in_file_name = fgetl(listfid);
                in_file_name = fgetl(listfid);
        end
        end
 
 
        // close input list file 
        // close input list file 
        $fclose(listfid);
        $fclose(listfid);
        // finish simulation 
        // finish simulation 
        $finish;
        $finish;
end
end
 
 
aes dut(
aes dut(
   .clk(clk),
   .clk(clk),
   .reset(reset),
   .reset(reset),
   .i_start(key_start),
   .i_start(key_start),
   .i_enable(enable), //TBD
   .i_enable(enable), //TBD
   .i_ende(enc_dec),
   .i_ende(enc_dec),
   .i_key(key_in),
   .i_key(key_in),
   .i_key_mode(key_mode),
   .i_key_mode(key_mode),
   .i_data(data_in),
   .i_data(data_in),
   .i_data_valid(data_in_valid),
   .i_data_valid(data_in_valid),
   .o_ready(ready_out),
   .o_ready(ready_out),
   .o_data(data_out),
   .o_data(data_out),
   .o_data_valid(data_out_valid),
   .o_data_valid(data_out_valid),
   .o_key_ready(key_ready)
   .o_key_ready(key_ready)
);
);
 
 
// display mode of operation, input key length and value 
// display mode of operation, input key length and value 
always @ (posedge clk)
always @ (posedge clk)
        if (key_start)
        if (key_start)
        begin
        begin
                // display mode of operation 
                // display mode of operation 
                if (enc_dec)
                if (enc_dec)
                        $display("Decryption test, count %0d, in file %0s", tst_count, in_file_name);
                        $display("Decryption test, count %0d, in file %0s", tst_count, in_file_name);
                else
                else
                        $display("Encryption test, count %0d, in file %0s", tst_count, in_file_name);
                        $display("Encryption test, count %0d, in file %0s", tst_count, in_file_name);
 
 
                // display key size 
                // display key size 
                case (key_mode)
                case (key_mode)
                        2'b00:  $display("Key size is 128 bits");
                        2'b00:  $display("Key size is 128 bits");
                        2'b01:  $display("Key size is 192 bits");
                        2'b01:  $display("Key size is 192 bits");
                        2'b10:  $display("Key size is 256 bits");
                        2'b10:  $display("Key size is 256 bits");
                        2'b11:  $display("ERROR: Illegal key size");
                        2'b11:  $display("ERROR: Illegal key size");
                endcase
                endcase
                // display key value 
                // display key value 
                $display("Key In:      %16h",key_in);
                $display("Key In:      %16h",key_in);
        end
        end
 
 
// display input data 
// display input data 
always @ (posedge clk)
always @ (posedge clk)
        if (data_in_valid)
        if (data_in_valid)
                $display("Data In:     %16h",data_in);
                $display("Data In:     %16h",data_in);
 
 
// display output data 
// display output data 
always @ (posedge clk)
always @ (posedge clk)
        if (data_out_valid)
        if (data_out_valid)
                $display("Data Out:    %16h",data_out);
                $display("Data Out:    %16h",data_out);
 
 
endmodule
endmodule
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
//                                              Th.. Th.. Th.. Thats all folks !!!
//                                              Th.. Th.. Th.. Thats all folks !!!
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.