cryptography ip-cores in vhdl / verilog
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.8 KiB

  1. // ======================================================================
  2. // DES encryption/decryption testbench
  3. // tests according to NIST 800-17 special publication
  4. // Copyright (C) 2012 Torsten Meissner
  5. //-----------------------------------------------------------------------
  6. // This program is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation; either version 2 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. // ======================================================================
  20. module tb_des;
  21. initial begin
  22. $dumpfile ("tb_des.vcd");
  23. $dumpvars (0, tb_des);
  24. end
  25. reg reset;
  26. reg clk = 0;
  27. reg mode;
  28. reg [0:63] key;
  29. reg [0:63] datain;
  30. reg validin;
  31. integer index;
  32. integer outdex;
  33. wire [0:63] dataout;
  34. wire validout;
  35. reg [0:63] variable_plaintext_known_answers [0:63];
  36. initial begin
  37. $readmemh("stimuli.txt", variable_plaintext_known_answers);
  38. end
  39. initial begin
  40. reset = 1;
  41. #1 reset = 0;
  42. #20 reset = 1;
  43. #1000 $finish;
  44. end
  45. always #5 clk = !clk;
  46. initial
  47. forever @(negedge reset) begin
  48. disable stimuli;
  49. disable checker;
  50. mode <= 0;
  51. validin <= 0;
  52. key <= 0;
  53. datain <= 0;
  54. end
  55. always begin : stimuli
  56. wait (reset)
  57. @(posedge clk)
  58. // Variable plaintext known answer test
  59. datain <= 64'h8000000000000000;
  60. mode <= 0;
  61. validin <= 1;
  62. key <= 64'h0101010101010101;
  63. for(index = 0; index < 64; index = index + 1)
  64. begin
  65. @(posedge clk)
  66. datain <= {1'b0, datain[0:62]};
  67. end
  68. validin <= 0;
  69. end
  70. always begin : checker
  71. wait (reset)
  72. // Variable plaintext known answer test
  73. wait (validout)
  74. for(outdex = 0; outdex < 64; outdex = outdex + 1)
  75. begin
  76. @(posedge clk)
  77. if (dataout == variable_plaintext_known_answers[outdex]) begin
  78. $display ("okay");
  79. end else begin
  80. $display ("error, output was %h - should have been %h", dataout, variable_plaintext_known_answers[outdex]);
  81. end
  82. end
  83. @(posedge clk)
  84. $finish;
  85. end
  86. des i_des (
  87. .reset_i(reset),
  88. .clk_i(clk),
  89. .mode_i(mode),
  90. .key_i(key),
  91. .data_i(datain),
  92. .valid_i(validin),
  93. .data_o(dataout),
  94. .valid_o(validout)
  95. );
  96. endmodule