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.

92 lines
2.3 KiB

  1. // ======================================================================
  2. // CBC-MAC-DES
  3. // Copyright (C) 2015 Torsten Meissner
  4. //-----------------------------------------------------------------------
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. // ======================================================================
  17. `timescale 1ns/1ps
  18. `define ITER
  19. module cbcmac_des (
  20. input reset_i,
  21. input clk_i,
  22. input start_i,
  23. input [0:63] key_i,
  24. input [0:63] data_i,
  25. input valid_i,
  26. output accept_o,
  27. output [0:63] data_o,
  28. output valid_o,
  29. input accept_i
  30. );
  31. // CBCMAC must have fix IV for security reasons
  32. reg [0:63] iv = 0;
  33. reg [0:63] key;
  34. wire [0:63] des_key;
  35. wire [0:63] des_datain;
  36. reg [0:63] des_dataout_d;
  37. assign des_datain = start_i ? iv ^ data_i : des_dataout_d ^ data_i;
  38. assign des_key = start_i ? key_i : key;
  39. // input register
  40. always @(posedge clk_i, negedge reset_i) begin
  41. if (~reset_i) begin
  42. key <= 0;
  43. end
  44. else begin
  45. if (valid_i && accept_o && start_i) begin
  46. key <= key_i;
  47. end
  48. end
  49. end
  50. // output register
  51. always @(posedge clk_i, negedge reset_i) begin
  52. if (~reset_i) begin
  53. des_dataout_d <= 0;
  54. end
  55. else begin
  56. if (valid_o) begin
  57. des_dataout_d <= data_o;
  58. end
  59. end
  60. end
  61. // des instance
  62. des i_des (
  63. .reset_i(reset_i),
  64. .clk_i(clk_i),
  65. .mode_i(1'b0),
  66. .key_i(des_key),
  67. .data_i(des_datain),
  68. .valid_i(valid_i),
  69. .accept_o(accept_o),
  70. .data_o(data_o),
  71. .valid_o(valid_o),
  72. .accept_i(accept_i)
  73. );
  74. endmodule