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.

88 lines
2.2 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. module cbcmac_des (
  19. input reset_i,
  20. input clk_i,
  21. input start_i,
  22. input [0:63] key_i,
  23. input [0:63] data_i,
  24. input valid_i,
  25. output accept_o,
  26. output [0:63] data_o,
  27. output valid_o,
  28. input accept_i
  29. );
  30. // CBCMAC must have fix IV for security reasons
  31. reg [0:63] iv = 0;
  32. reg [0:63] key;
  33. wire [0:63] des_key;
  34. wire [0:63] des_datain;
  35. reg [0:63] des_dataout_d;
  36. assign des_datain = start_i ? iv ^ data_i : des_dataout_d ^ data_i;
  37. assign des_key = start_i ? key_i : key;
  38. // input register
  39. always @(posedge clk_i, negedge reset_i) begin
  40. if (~reset_i) begin
  41. key <= 0;
  42. end
  43. else begin
  44. if (valid_i && accept_o && start_i) begin
  45. key <= key_i;
  46. end
  47. end
  48. end
  49. // output register
  50. always @(posedge clk_i, negedge reset_i) begin
  51. if (~reset_i) begin
  52. des_dataout_d <= 0;
  53. end
  54. else begin
  55. if (valid_o) begin
  56. des_dataout_d <= data_o;
  57. end
  58. end
  59. end
  60. // des instance
  61. des i_des (
  62. .reset_i(reset_i),
  63. .clk_i(clk_i),
  64. .mode_i(1'b0),
  65. .key_i(des_key),
  66. .data_i(des_datain),
  67. .valid_i(valid_i),
  68. .data_o(data_o),
  69. .valid_o(valid_o)
  70. );
  71. endmodule