URL
https://opencores.org/ocsvn/csa/csa/trunk
Subversion Repositories csa
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 41 to Rev 42
- ↔ Reverse comparison
Rev 41 → Rev 42
/csa/trunk/bench/decrypt_tb.v
37,7 → 37,7
$read_data( |
"../test_dat/decrypt.in" |
,8 |
,even_cw |
,odd_cw |
); |
|
encrypted_byte=8'h00; // or can not read data |
62,10 → 62,11
// set odd key |
@(posedge clk); |
ck=odd_cw; |
key_en=1; |
en=0; |
even_odd=1; |
@(posedge clk); |
key_en=1; |
@(posedge clk); |
key_en=0; |
repeat (11)@(posedge clk); |
|
/csa/trunk/rtl/ts_sync.v
9,6 → 9,7
, input [8-1:0] datain |
, output reg valid |
, output reg head // find ts packet head |
, output reg init // the first dec ts packet |
, output reg dec // this ts group need decrypt |
, output reg evenodd // the current key type |
, output reg [8*8-1:0] group |
15,10 → 16,10
, output reg [3:0] bytes // valid bytes in group |
); |
reg sync; |
reg valid_s; |
reg need_dec; // current packet need decrypt; |
reg [8*8-1:0] group_d; |
reg [7:0] ts_cnt; // |
|
always @(posedge clk) |
if(rst) |
begin |
28,18 → 29,18
sync<=1'h0; |
need_dec<=1'h0; |
ts_cnt=8'h0; |
init<=1'h0; |
end |
else |
begin |
head<=1'h0; |
dec<=1'h0; |
valid_s<=1'h0; |
valid<=valid_s; |
valid<=1'h0; |
init<=1'h0; |
|
if(en) |
begin |
group_d <= {datain, group_d[8*8-1:1*8] }; |
group <={datain, group_d[8*8-1:1*8] } ; |
end |
if(sync) |
begin |
47,14 → 48,18
begin |
need_dec<=1'h0; |
sync<=1'h0; // ts packet end |
valid_s<=1'h1; |
|
end |
if(ts_cnt[2:0]==3'h1&&en) |
begin |
valid_s<=1'h1; |
valid<=1'h1; |
dec<=need_dec; |
bytes<=4'h8; |
group <={datain, group_d[8*8-1:1*8] } ; |
|
end |
if(ts_cnt==8'hb1&en) |
init<=1'h1; |
if(en) |
ts_cnt <= ts_cnt - 8'h1; |
end |
/csa/trunk/rtl/group_decrypt.v
0,0 → 1,55
`include "../bench/timescale.v" |
// this moduel do a decrypt group |
|
module group_decrypt( |
input clk |
, input rst |
, input en |
, input dec |
, input init |
, input [ 8*8-1:0] ck |
, input [56*8-1:0] kk |
, input [ 8*8-1:0] group |
, input [ 4-1:0] bytes |
|
, output reg valid |
, output reg [ 8*8-1:0] ogroup |
, output reg [ 4-1:0] obytes |
); |
|
reg init_d; |
wire [8*8-1:0] sc_cb; |
wire [8*8-1:0] ib; |
reg [8*8-1:0] sc_cb_d; |
reg [8*8-1:0] bco_d; |
wire [8*8-1:0] bco; |
|
always @(posedge clk) |
begin |
if(en) |
begin |
sc_cb_d<=sc_cb; |
bco_d<=bco; |
end |
end |
|
|
stream_cypher stream_cypher( |
.clk (clk) |
, .rst (rst) |
, .en (en) |
, .init (init) |
, .ck (ck) |
, .sb (group) |
, .cb (sc_cb) |
); |
|
assign ib=init?sc_cb_d:group^sc_cb; |
block_decypher block_decypher( |
.kk (kk) |
, .ib (ib) |
, .bd (bco) |
); |
|
|
endmodule |
/csa/trunk/rtl/decrypt.v
34,9 → 34,14
); |
|
wire ts_valid; |
wire ts_init; |
wire ts_head; |
wire ts_dec; |
wire ts_evenodd; |
wire [8*8-1:0]group; |
wire [3:0] bytes; |
|
|
ts_sync ts_sync( |
. clk (clk) |
, . rst (rst) |
43,74 → 48,33
, . en (en) |
, . datain (encrypted) |
, . valid (ts_valid) |
, . head () |
, . dec () |
, . evenodd () |
, . head (ts_head) |
, . dec (ts_dec) |
, . init (ts_init) |
, . evenodd (ts_evenodd) |
, . group (group) |
, . bytes (bytes) |
); |
|
//// word grouper |
//reg [8*8-1:0] group; // 64bits |
//reg sync; // find sync |
//reg [8-1:0] ts_cnt; // ts packet count |
//reg using_even_odd_key; // 0 --- using even key; 1 --- using odd key |
//reg need_dec; |
//reg group_valid; |
//reg group_valid_d; |
//reg head; |
//reg [5:0] group_id; |
//reg [4*8-1:0] group_d; |
wire dec_valid; |
wire [8*8-1:0]ogroup; |
wire [ 4-1:0]obytes; |
group_decrypt group_decrypt( |
.clk (clk) |
, .rst (rst) |
, .en (ts_valid) |
, .dec (ts_dec) |
, .init (ts_init) |
, .ck (ts_evenodd?even_ck:odd_ck) |
, .kk (ts_evenodd?even_kk:odd_kk) |
, .group (group) |
, .bytes (bytes) |
, .valid (dec_valid) |
, .ogroup (ogroup) |
, .obytes (obytes) |
); |
|
// |
// |
//always @(posedge clk) |
// if (rst) |
// begin |
// group <= 64'h00000000; |
// sync <= 1'h0; |
// ts_cnt <= 8'h00; |
// using_even_odd_key <= 1'h0; |
// need_dec <= 1'h0; |
// group_valid_d <=1'h0; |
// head <= 1'h0; |
// end |
// else |
// begin |
// group_valid <=1'h0; |
// group_valid_d <= group_valid; |
// head <= 1'h0; |
// group_d <= group; |
// if(en) |
// begin |
// group <= { encrypted, group [8*8-1:1*8] }; |
// if(sync) |
// begin |
// ts_cnt <= ts_cnt + 8'h01; |
// if(ts_cnt[2:0]==3'h7) |
// begin |
// group_valid<=1'h1; |
// group_id<=ts_cnt[7:3]; |
// end |
// if(ts_cnt == 8'hb7 ) // 0xb8=188-4 |
// begin |
// sync <= 1'h0; |
// ts_cnt<=8'h0; |
// end |
// end |
// else |
// begin |
// if(group[5*8-1:4*8]==8'h47) |
// begin |
// sync <= 1; |
// ts_cnt <= 8'h00; |
// using_even_odd_key <= group[62]; |
// head <= 1'h1; |
// group_d <= {1'h0,group[62:32]}; |
// end |
// end |
// end |
// end |
// |
//// decrypt |
//reg [8*8-1:0] db; |
//reg db_valid; |
201,52 → 165,14
// end |
//end |
// |
//// degrouper |
//reg [2:0] cnt; |
//reg valid; |
//reg [7:0] decrypted; |
//reg [7*8-1:0] dec_group_ouput; |
// |
//always @(posedge clk) |
// if(rst) |
// begin |
// dec_group_ouput <= 32'h00000000; |
// cnt <= 2'h0; |
// end |
// else |
// begin |
// valid <= 1'h0; |
// if(db_valid) |
// begin |
// dec_group_ouput <= db[8*8-1:1*8]; |
// decrypted <= db[7:0]; |
// cnt <= 3'h7; |
// valid <= 1'h1; |
// end |
// if(cnt) |
// begin |
// valid <= 1'h1; |
// dec_group_ouput <= {dec_group_ouput [7:0],dec_group_ouput[7*8-1:1*8]}; |
// decrypted <= dec_group_ouput [ 7:0 ]; |
// cnt <= cnt - 2'h1; |
// end |
// if(head) |
// begin |
// dec_group_ouput <= group_d[4*8-1:1*8]; |
// decrypted <= group_d[7:0]; |
// cnt <= 2'h3; |
// valid <= 1'h1; |
// end |
// end |
// |
|
|
ts_serial_out ts_serial_out( |
.clk (clk) |
, .rst (rst) |
, .group (group) |
, .bytes (bytes) |
, .en (ts_valid) |
, .group (ogroup) |
, .bytes (obytes) |
, .en (dec_valid) |
, .dec (decrypted) |
, .valid (valid) |
); |
/csa/trunk/sw_sim/csa.c
384,10 → 384,11
|
/* 1st 8 bytes of initialisation */ |
stream_cypher(1, ck, &encrypted[offset], ib); |
DEBUG_OUTPUT_ARR(ib,8); |
|
for(j=1; j<(N+1); j++) { |
block_decypher(kk, ib, block); |
DEBUG_OUTPUT_ARR(ib,8); |
DEBUG_OUTPUT_ARR(block,8); |
|
if (j != N) { |
stream_cypher(0, ck, NULL, stream); |
401,6 → 402,12
for(i=0; i<8; i++) ib[i] = 0; |
} |
|
#if 0 |
fprintf(stderr,"output \n"); |
DEBUG_OUTPUT_ARR(ib,8); |
DEBUG_OUTPUT_ARR(block,8); |
#endif |
|
/* xor ib x block */ |
for(i=0; i<8; i++) |
decrypted[offset+8*(j-1)+i] = ib[i] ^ block[i]; |