URL
https://opencores.org/ocsvn/csa/csa/trunk
Subversion Repositories csa
Compare Revisions
- This comparison shows the changes necessary to convert path
/csa/trunk
- from Rev 47 to Rev 48
- ↔ Reverse comparison
Rev 47 → Rev 48
/bench/key_schedule_tb.v
7,6 → 7,8
reg rst; |
reg start; |
wire [56*8-1:0] kk; |
wire done; |
wire busy; |
|
initial |
begin |
27,21 → 29,18
initial |
begin |
|
`ifdef ____DEBUG |
// read CK |
$read_data( |
"../test_dat/key_schedule.in" |
,ck |
); |
`endif |
start=1'h0; |
ck=64'haf361916fd4b4b77; |
|
repeat (4) @(posedge clk); |
start=1'h1; |
@(posedge clk); |
start=1'h0; |
repeat (200) @(posedge clk); |
repeat (20) @(posedge clk); |
|
$display("ck=%h",ck); |
$display("kk=%h",kk); |
48,21 → 47,20
|
// output kk |
|
//$write_data( |
// "../test_dat/key_schedule.out.v" |
// ,"a" |
// ,kk |
// ); |
$finish; |
$write_data( |
"../test_dat/key_schedule.out.v" |
,kk |
); |
$stop; |
end |
|
key_schedule ks( |
key_schedule key_schedule( |
.clk (clk) |
,.rst (rst) |
,.start (start) |
,.i_ck (ck) |
,.busy () |
,.done () |
,.o_kk (kk) |
,.ck (ck) |
,.busy (busy) |
,.done (done) |
,.kk (kk) |
); |
endmodule |
/rtl/key_cnt.v
57,8 → 57,8
, .start(en&~busy) |
, .busy (busy) |
, .done (done) |
, .i_ck (ck_in) |
, .o_kk (kk) |
, .ck (ck_in) |
, .kk (kk) |
); |
|
endmodule |
/rtl/key_schedule.v
1,74 → 1,63
`include "../bench/timescale.v" |
// this key_schedule module |
module key_schedule(clk,rst,start,i_ck,busy,done,o_kk); |
input clk; |
input rst; |
input start; |
input [ 8*8-1:0] i_ck; |
module key_schedule(clk,rst,start,ck,busy,done,kk); |
input clk; // main clock |
input rst; // reset , high active |
input start; // start key |
input [ 8*8-1:0] ck; |
output busy; |
output done; |
output [56*8-1:0] o_kk; |
output done; // one clck width |
output [56*8-1:0] kk; |
|
reg [56*8-1:0] o_kk; |
reg [ 2:0] cnt; |
|
wire [ 8*8-1:0] ik; |
wire [ 8*8-1:0] okd; |
wire [ 8*8-1:0] oki; |
reg [ 8*8-1:0] ok_d; |
reg done; |
wire [56*8-1:0] kk; |
reg busy; |
|
key_perm kpo(.i_key(ok_d), .o_key(okd)); |
key_perm kpi(.i_key(i_ck), .o_key(oki)); |
//////////////////////////////////////////////////////////////////////////////// |
// internal variable |
//////////////////////////////////////////////////////////////////////////////// |
reg [56*8-1:0] kk_arry; // the key array |
reg [ 2:0] cnt; |
wire [ 8*8-1:0] next_kk; // the next roundl kk |
|
|
always @(posedge clk ) |
if(rst) |
cnt<=3'h0; |
else if(start) |
cnt <= 3'h6; |
else if(cnt!=3'h0) |
cnt <= cnt-3'h1; |
|
|
always @(posedge clk) |
begin |
done <= 1'h0; |
if(rst) |
begin |
o_kk <= 448'h0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000; |
cnt <= 3'h0; |
ok_d <= 64'h0000000000000000; |
busy <= 1'h0; |
end |
else |
begin |
if(cnt==3'h0 && busy) |
begin |
busy <= 1'h0; |
done <= 1'h1; |
end |
if(rst) |
busy=1'h0; |
else if(start) |
busy<=1'h1; |
else if(cnt==3'h0) |
busy<=1'h0; |
|
assign done=busy & (cnt==3'h0); |
|
if(start & ~busy) |
begin |
cnt <= 3'h5; |
o_kk <= {o_kk [(6*8)*8-1:8*0], i_ck}; |
busy <= 1'h1; |
ok_d <= oki; |
o_kk <= {o_kk [(6*8)*8-1:8*0], |
i_ck ^ 64'h0606060606060606}; |
end |
always @(posedge clk ) |
if(rst) |
kk_arry<=448'h0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000; |
else if(start) |
kk_arry<={kk_arry[48*8-1:0],ck}; |
else if(cnt!=3'h0) |
kk_arry<={kk_arry[48*8-1:0],next_kk}; |
|
if(busy) |
begin |
o_kk <= {o_kk [(6*8)*8-1:8*0], |
ok_d ^ { |
5'h00, cnt, |
5'h00, cnt, |
5'h00, cnt, |
5'h00, cnt, |
5'h00, cnt, |
5'h00, cnt, |
5'h00, cnt, |
5'h00, cnt |
} |
}; |
if(cnt!=3'h0) |
cnt <= cnt - 3'h1; |
ok_d <= okd; |
end |
end |
end |
assign kk=kk_arry ^ { |
64'h0606060606060606, |
64'h0505050505050505, |
64'h0404040404040404, |
64'h0303030303030303, |
64'h0202020202020202, |
64'h0101010101010101, |
64'h0000000000000000 |
}; |
//assign busy=cnt!=3'h0; |
|
key_perm kpi(.i_key(kk_arry[8*8-1:0]), .o_key(next_kk)); |
|
endmodule |
/sw_sim/key_schedule.c
2,6 → 2,7
|
#include <stdio.h> |
#include <string.h> |
#include "misc.h" |
|
extern void key_schedule(unsigned char *CK, int *kk) ; |
|
9,33 → 10,16
{ |
unsigned char CK[8]; |
int kk[57]; |
int i; |
int c; |
|
memset(CK,0,sizeof CK); |
for (i=63;i>=0;i--) |
{ |
c=getchar(); |
#ifdef DEBUG |
printf("%c",c); |
#endif |
if(c=='1') |
{ |
CK[i/8]|=(1<<(i%8)); |
} |
} |
#ifdef DEBUG |
printf("\n"); |
#endif |
memset(kk,0,sizeof kk); |
READ_DATA(CK,8); |
|
key_schedule(CK,kk); |
for(i=57*8-1;i>=8;i--) |
|
/*WRITE_DATA(&(kk[1]),56);*/ /* note: can not write this array once in here*/ |
{ |
if(kk[i/8]&(1<<(i%8))) |
printf("1"); |
else |
printf("0"); |
int i ; |
for(i=0;i<56;i++) |
WRITE_DATA(&kk[1+i],1); |
} |
printf("\n"); |
return 0; |
} |
/makefile
47,7 → 47,6
str+=$$binstr ; \ |
done ; \ |
echo -n $$str >$(TEST_IN_FILE) ; \ |
hexdump -C $(TEST_IN_FILE) ; |
|
preare_block_decypher: |
$(call preare_fn,64) |