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

Subversion Repositories gost28147

[/] [gost28147/] [trunk/] [rtl/] [verilog/] [gost28147-89.sv] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 doka
// $Id:  $ From Russia with love
2
 
3
/////////////////////////////////////////////////////////////////////
4
//   This file is part of the GOST 28147-89 CryptoCore project     //
5
//                                                                 //
6
//   Copyright (c) 2014 Dmitry Murzinov (kakstattakim@gmail.com)   //
7
/////////////////////////////////////////////////////////////////////
8
 
9
`timescale 1ns / 100ps
10
 
11
//`define GOST_R_3411_TESTPARAM (1)
12
//`define GOST_R_3411_CRYPTOPRO (1)
13
//`define GOST_R_3411_BOTH (1)
14
 
15
module gost_28147_89 (clk, rst, mode, select, load, done, kload, key, pdata, cdata);
16
  input  clk;    // Input clock signal for synchronous design
17
  input  rst;    // Syncronous Reset input
18
  input  mode;   // 0 - encrypt, 1 - decrypt
19
  input  select; // if GOST_R_3411_BOTH defined: 0 - Using the GOST R 34.11-94 TestParameter S-boxes; 1 - Using the CryptoPro S-boxes
20
  input  load;   // load plain text and start cipher cycles
21
  output done;   // cipher text ready for output read
22
  input  kload;  // load cipher key
23
  input [255:0] key;   // cipher key input
24
  input  [63:0] pdata; //  plain text input
25
  output [63:0] cdata; // cipher text output
26
 
27 3 doka
`include "gost-sbox.vh"
28 2 doka
 
29
reg [4:0] i; // cipher cycles counter: 0..31;
30
 
31
always_ff @(posedge clk)
32
  if(rst || load)
33
    i <= 5'h0;
34
  else //if(~&i)
35
    i <= i + 1;
36
 
37
//reg run; //running cipher cycles flag
38
 
39
wire [2:0] enc_index = (&i[4:3]) ? ~i[2:0] : i[2:0]; //  cipher key index for encrypt
40
wire [2:0] dec_index = (|i[4:3]) ? ~i[2:0] : i[2:0]; //  cipher key index for decrypt
41
wire [2:0] kindex    = mode ? dec_index : enc_index; //  cipher key index
42
 
43
reg [31:0] K [0:7]; // cipher key storage
44
 
45
always_ff @(posedge clk)
46
  if(rst)
47
    {K[0],K[1],K[2],K[3],K[4],K[5],K[6],K[7]} <= {256{1'b0}};
48
  else if(kload)
49
    {K[0],K[1],K[2],K[3],K[4],K[5],K[6],K[7]} <= key;
50
 
51
 
52
reg   [31:0] b, a; // MSB, LSB of input data
53
wire  [31:0] state_addmod32 = a + K[kindex];  // Adding by module 32
54
wire  [31:0] state_sbox     = `Sbox(state_addmod32,select); // S-box replacing
55
wire  [31:0] state_shift11  = {state_sbox[20:0],state_sbox[31:21]}; // <<11
56
 
57
always_ff @(posedge clk)
58
  if(rst)
59
    {b,a} <= {64{1'b0}};
60
  else if(load)
61
    {b,a} <= pdata;
62
  else /*if(~&i)*/ begin
63
    a <= b ^ state_shift11;
64
    b <= a;
65
  end
66
 
67
reg r_done;
68
always_ff @(posedge clk)
69
  if(rst)
70
    r_done <= 1'b0;
71
  else
72
    r_done <= &i;
73
 
74
assign done  = r_done;  //ready flag for output data
75
assign cdata = {a,b};
76
 
77
endmodule
78
 

powered by: WebSVN 2.1.0

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