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

Subversion Repositories csa

[/] [csa/] [trunk/] [rtl/] [stream_cypher.v] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 20 simon111
 
2
 
3
// this file implement the stream cypher module
4
 
5
module stream_cypher(clk,rst_n,en,init,ck,sb,cb);
6
input                 clk;
7
input                 rst_n;   // low enable
8
input                 en;      // hi enable
9
input                 init;    // hi enable
10
input  [8 *8-1:0]     ck;
11
input  [8 *8-1:0]     sb;
12
output [8 *8-1:0]     cb;
13
 
14
// intermediate variable
15
reg                en_d;
16
reg    [10*4-1 : 0]A;
17
reg    [10*4-1 : 0]B;
18
reg    [4-1    : 0]X;
19
reg    [4-1    : 0]Y;
20
reg    [4-1    : 0]Z;
21
reg    [4-1    : 0]D;
22
reg    [4-1    : 0]E;
23
reg    [4-1    : 0]F;
24
reg                p;
25
reg                q;
26
reg                r;
27
 
28
wire   [10*4-1 : 0]Ao;
29
wire   [10*4-1 : 0]Ainit;
30
wire   [10*4-1 : 0]Bo;
31
wire   [10*4-1 : 0]Binit;
32
wire   [4-1    : 0]Xo;
33
wire   [4-1    : 0]Yo;
34
wire   [4-1    : 0]Zo;
35
wire   [4-1    : 0]Do;
36
wire   [4-1    : 0]Eo;
37
wire   [4-1    : 0]Fo;
38
wire               po;
39
wire               qo;
40
wire               ro;
41
 
42
assign Ainit = {
43
                4'b0,         4'b0,
44
        ck[7*4-1:6*4],ck[8*4-1:7*4],
45
        ck[5*4-1:4*4],ck[6*4-1:5*4],
46
        ck[3*4-1:2*4],ck[4*4-1:3*4],
47
        ck[1*4-1:0*4],ck[2*4-1:1*4]
48
};
49
 
50
assign Binit = {
51
                   4'b0,           4'b0,
52
        ck[15*4-1:14*4],ck[16*4-1:15*4],
53
        ck[13*4-1:12*4],ck[14*4-1:13*4],
54
        ck[11*4-1:10*4],ck[12*4-1:11*4],
55
        ck[ 9*4-1: 8*4],ck[10*4-1: 9*4]
56
};
57
 
58
always @(posedge clk)
59
begin
60
        if(!rst_n)
61
        begin
62
                A<= 40'h0000000000;
63
                B<= 40'h0000000000;
64
                X<=  8'h00;
65
                Y<=  8'h00;
66
                Z<=  8'h00;
67
                D<=  8'h00;
68
                E<=  8'h00;
69
                F<=  8'h00;
70
                p<=  8'h00;
71
                q<=  8'h00;
72
                r<=  8'h00;
73
                en_d <= 1'h00;
74
        end
75
        else
76
        begin
77
                en_d <= en;
78
                if(en_d)
79
                begin
80
                        A<=  Ao;
81
                        B<=  Bo;
82
                        X<=  Xo;
83
                        Y<=  Yo;
84
                        Z<=  Zo;
85
                        D<=  Do;
86
                        E<=  Eo;
87
                        F<=  Fo;
88
                        p<=  po;
89
                        q<=  qo;
90
                        r<=  ro;
91
 
92
                end
93
        end
94
end
95
 
96
 
97
stream_8bytes b(
98
                        .init(init)
99
                       ,.sb(sb)
100
                       ,.Ai((init)?Ainit:A)
101
                       ,.Bi((init)?Binit:B)
102
                       ,.Di((init)?4'b0 :D)
103
                       ,.Ei((init)?4'b0 :E)
104
                       ,.Fi((init)?4'b0 :F)
105
                       ,.Xi((init)?4'b0 :X)
106
                       ,.Yi((init)?4'b0 :Y)
107
                       ,.Zi((init)?4'b0 :Z)
108
                       ,.pi((init)?1'b0 :p)
109
                       ,.qi((init)?1'b0 :q)
110
                       ,.ri((init)?1'b0 :r)
111
 
112
                       ,.Ao(Ao)
113
                       ,.Bo(Bo)
114
                       ,.Do(Do)
115
                       ,.Eo(Eo)
116
                       ,.Fo(Fo)
117
                       ,.Xo(Xo)
118
                       ,.Yo(Yo)
119
                       ,.Zo(Zo)
120
                       ,.po(po)
121
                       ,.qo(qo)
122
                       ,.ro(ro)
123
                       ,.cb(cb)
124
                );
125
 
126
endmodule

powered by: WebSVN 2.1.0

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