URL
https://opencores.org/ocsvn/rc4-prbs/rc4-prbs/trunk
[/] [rc4-prbs/] [trunk/] [rc4.v] - Diff between revs 17 and 18
Show entire file |
Details |
Blame |
View Log
Rev 17 |
Rev 18 |
Line 39... |
Line 39... |
|
|
// Key
|
// Key
|
reg [7:0] key[0:`KEY_SIZE-1];
|
reg [7:0] key[0:`KEY_SIZE-1];
|
// S array
|
// S array
|
reg [7:0] S[0:256];
|
reg [7:0] S[0:256];
|
reg [9:0] discardCount;
|
reg [10:0] discardCount;
|
|
|
// Key-scheduling state
|
// Key-scheduling state
|
`define KSS_KEYREAD 4'h0
|
`define KSS_KEYREAD 4'h0
|
`define KSS_KEYSCHED1 4'h1
|
`define KSS_KEYSCHED1 4'h1
|
`define KSS_KEYSCHED2 4'h2
|
`define KSS_KEYSCHED2 4'h2
|
Line 109... |
Line 109... |
if (i == 8'hFF)
|
if (i == 8'hFF)
|
begin
|
begin
|
KSState <= `KSS_CRYPTO;
|
KSState <= `KSS_CRYPTO;
|
i <= 8'h01;
|
i <= 8'h01;
|
j <= S[1];
|
j <= S[1];
|
discardCount <= 10'h0;
|
discardCount <= 11'h0;
|
output_ready <= 0; // K not valid yet
|
output_ready <= 0; // K not valid yet
|
end
|
end
|
else begin
|
else begin
|
i <= i + 1;
|
i <= i + 1;
|
KSState <= `KSS_KEYSCHED2;
|
KSState <= `KSS_KEYSCHED2;
|
Line 132... |
Line 132... |
*/
|
*/
|
`KSS_CRYPTO: begin
|
`KSS_CRYPTO: begin
|
S[i] <= S[j];
|
S[i] <= S[j];
|
S[j] <= S[i]; // We can do this because of verilog.
|
S[j] <= S[i]; // We can do this because of verilog.
|
K <= S[ S[i]+S[j] ];
|
K <= S[ S[i]+S[j] ];
|
if (discardCount<10'h3E8) // discard first 1000 values
|
if (discardCount<11'h600) // discard first 1536 values / RFC 4345
|
discardCount<=discardCount+1;
|
discardCount<=discardCount+1;
|
else output_ready <= 1; // Valid K at output
|
else output_ready <= 1; // Valid K at output
|
i <= i+1;
|
i <= i+1;
|
// Here is the secret of 1-clock: we develop all possible values of j in the future
|
// Here is the secret of 1-clock: we develop all possible values of j in the future
|
if (j==i+1)
|
if (j==i+1)
|
j <= (j + S[i]);
|
j <= (j + S[i]);
|
else
|
else
|
if (i==255) j <= (j + S[0]);
|
if (i==255) j <= (j + S[0]);
|
else j <= (j + S[i+1]);
|
else j <= (j + S[i+1]);
|
$display ("rc4: output = %08X",K);
|
//$display ("rc4: output = %08X",K);
|
end
|
end
|
default: begin
|
default: begin
|
end
|
end
|
endcase
|
endcase
|
end
|
end
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.