OpenCores
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 39 to Rev 40
    Reverse comparison

Rev 39 → Rev 40

/bench/decrypt_tb.v
2,25 → 2,22
// this is the test bench for decrypt module
 
 
`define TEST_DECRYPT
`include "../bench/timescale.v"
 
`timescale 10ns/1ns
module decrypt_tb;
 
reg clk;
reg rst;
 
`ifdef TEST_DECRYPT
 
 
integer bytes;
integer out_bytes;
 
reg [204*8-1 : 0] tt;
reg [8*8-1 : 0] even_cw;
reg [8*8-1 : 0] odd_cw;
reg [8-1 : 0] encrypted [188:1];
reg [8-1 : 0] decrypted [188:1];
reg [ 8*8-1 : 0] even_cw;
reg [ 8*8-1 : 0] odd_cw;
reg [188*8-1 : 0] encrypted;
reg [188*8-1 : 0] decrypted;
 
reg [8*8-1:0] ck;
reg even_odd;
34,201 → 31,23
begin
$read_data(
"../test_dat/decrypt.in"
,tt
,even_cw
);
 
even_cw = tt [ 8*8-1 : 0*8 ] ;
odd_cw = tt [16*8-1 : 8*8 ] ;
$read_data(
"../test_dat/decrypt.in"
,8
,even_cw
);
 
$read_data(
"../test_dat/decrypt.in"
,16
,encrypted
);
 
out_bytes = 1;
 
encrypted[188] = tt [204*8-1 :203*8 ] ;
encrypted[187] = tt [203*8-1 :202*8 ] ;
encrypted[186] = tt [202*8-1 :201*8 ] ;
encrypted[185] = tt [201*8-1 :200*8 ] ;
encrypted[184] = tt [200*8-1 :199*8 ] ;
encrypted[183] = tt [199*8-1 :198*8 ] ;
encrypted[182] = tt [198*8-1 :197*8 ] ;
encrypted[181] = tt [197*8-1 :196*8 ] ;
encrypted[180] = tt [196*8-1 :195*8 ] ;
encrypted[179] = tt [195*8-1 :194*8 ] ;
encrypted[178] = tt [194*8-1 :193*8 ] ;
encrypted[177] = tt [193*8-1 :192*8 ] ;
encrypted[176] = tt [192*8-1 :191*8 ] ;
encrypted[175] = tt [191*8-1 :190*8 ] ;
encrypted[174] = tt [190*8-1 :189*8 ] ;
encrypted[173] = tt [189*8-1 :188*8 ] ;
encrypted[172] = tt [188*8-1 :187*8 ] ;
encrypted[171] = tt [187*8-1 :186*8 ] ;
encrypted[170] = tt [186*8-1 :185*8 ] ;
encrypted[169] = tt [185*8-1 :184*8 ] ;
encrypted[168] = tt [184*8-1 :183*8 ] ;
encrypted[167] = tt [183*8-1 :182*8 ] ;
encrypted[166] = tt [182*8-1 :181*8 ] ;
encrypted[165] = tt [181*8-1 :180*8 ] ;
encrypted[164] = tt [180*8-1 :179*8 ] ;
encrypted[163] = tt [179*8-1 :178*8 ] ;
encrypted[162] = tt [178*8-1 :177*8 ] ;
encrypted[161] = tt [177*8-1 :176*8 ] ;
encrypted[160] = tt [176*8-1 :175*8 ] ;
encrypted[159] = tt [175*8-1 :174*8 ] ;
encrypted[158] = tt [174*8-1 :173*8 ] ;
encrypted[157] = tt [173*8-1 :172*8 ] ;
encrypted[156] = tt [172*8-1 :171*8 ] ;
encrypted[155] = tt [171*8-1 :170*8 ] ;
encrypted[154] = tt [170*8-1 :169*8 ] ;
encrypted[153] = tt [169*8-1 :168*8 ] ;
encrypted[152] = tt [168*8-1 :167*8 ] ;
encrypted[151] = tt [167*8-1 :166*8 ] ;
encrypted[150] = tt [166*8-1 :165*8 ] ;
encrypted[149] = tt [165*8-1 :164*8 ] ;
encrypted[148] = tt [164*8-1 :163*8 ] ;
encrypted[147] = tt [163*8-1 :162*8 ] ;
encrypted[146] = tt [162*8-1 :161*8 ] ;
encrypted[145] = tt [161*8-1 :160*8 ] ;
encrypted[144] = tt [160*8-1 :159*8 ] ;
encrypted[143] = tt [159*8-1 :158*8 ] ;
encrypted[142] = tt [158*8-1 :157*8 ] ;
encrypted[141] = tt [157*8-1 :156*8 ] ;
encrypted[140] = tt [156*8-1 :155*8 ] ;
encrypted[139] = tt [155*8-1 :154*8 ] ;
encrypted[138] = tt [154*8-1 :153*8 ] ;
encrypted[137] = tt [153*8-1 :152*8 ] ;
encrypted[136] = tt [152*8-1 :151*8 ] ;
encrypted[135] = tt [151*8-1 :150*8 ] ;
encrypted[134] = tt [150*8-1 :149*8 ] ;
encrypted[133] = tt [149*8-1 :148*8 ] ;
encrypted[132] = tt [148*8-1 :147*8 ] ;
encrypted[131] = tt [147*8-1 :146*8 ] ;
encrypted[130] = tt [146*8-1 :145*8 ] ;
encrypted[129] = tt [145*8-1 :144*8 ] ;
encrypted[128] = tt [144*8-1 :143*8 ] ;
encrypted[127] = tt [143*8-1 :142*8 ] ;
encrypted[126] = tt [142*8-1 :141*8 ] ;
encrypted[125] = tt [141*8-1 :140*8 ] ;
encrypted[124] = tt [140*8-1 :139*8 ] ;
encrypted[123] = tt [139*8-1 :138*8 ] ;
encrypted[122] = tt [138*8-1 :137*8 ] ;
encrypted[121] = tt [137*8-1 :136*8 ] ;
encrypted[120] = tt [136*8-1 :135*8 ] ;
encrypted[119] = tt [135*8-1 :134*8 ] ;
encrypted[118] = tt [134*8-1 :133*8 ] ;
encrypted[117] = tt [133*8-1 :132*8 ] ;
encrypted[116] = tt [132*8-1 :131*8 ] ;
encrypted[115] = tt [131*8-1 :130*8 ] ;
encrypted[114] = tt [130*8-1 :129*8 ] ;
encrypted[113] = tt [129*8-1 :128*8 ] ;
encrypted[112] = tt [128*8-1 :127*8 ] ;
encrypted[111] = tt [127*8-1 :126*8 ] ;
encrypted[110] = tt [126*8-1 :125*8 ] ;
encrypted[109] = tt [125*8-1 :124*8 ] ;
encrypted[108] = tt [124*8-1 :123*8 ] ;
encrypted[107] = tt [123*8-1 :122*8 ] ;
encrypted[106] = tt [122*8-1 :121*8 ] ;
encrypted[105] = tt [121*8-1 :120*8 ] ;
encrypted[104] = tt [120*8-1 :119*8 ] ;
encrypted[103] = tt [119*8-1 :118*8 ] ;
encrypted[102] = tt [118*8-1 :117*8 ] ;
encrypted[101] = tt [117*8-1 :116*8 ] ;
encrypted[100] = tt [116*8-1 :115*8 ] ;
encrypted[ 99] = tt [115*8-1 :114*8 ] ;
encrypted[ 98] = tt [114*8-1 :113*8 ] ;
encrypted[ 97] = tt [113*8-1 :112*8 ] ;
encrypted[ 96] = tt [112*8-1 :111*8 ] ;
encrypted[ 95] = tt [111*8-1 :110*8 ] ;
encrypted[ 94] = tt [110*8-1 :109*8 ] ;
encrypted[ 93] = tt [109*8-1 :108*8 ] ;
encrypted[ 92] = tt [108*8-1 :107*8 ] ;
encrypted[ 91] = tt [107*8-1 :106*8 ] ;
encrypted[ 90] = tt [106*8-1 :105*8 ] ;
encrypted[ 89] = tt [105*8-1 :104*8 ] ;
encrypted[ 88] = tt [104*8-1 :103*8 ] ;
encrypted[ 87] = tt [103*8-1 :102*8 ] ;
encrypted[ 86] = tt [102*8-1 :101*8 ] ;
encrypted[ 85] = tt [101*8-1 :100*8 ] ;
encrypted[ 84] = tt [100*8-1 : 99*8 ] ;
encrypted[ 83] = tt [ 99*8-1 : 98*8 ] ;
encrypted[ 82] = tt [ 98*8-1 : 97*8 ] ;
encrypted[ 81] = tt [ 97*8-1 : 96*8 ] ;
encrypted[ 80] = tt [ 96*8-1 : 95*8 ] ;
encrypted[ 79] = tt [ 95*8-1 : 94*8 ] ;
encrypted[ 78] = tt [ 94*8-1 : 93*8 ] ;
encrypted[ 77] = tt [ 93*8-1 : 92*8 ] ;
encrypted[ 76] = tt [ 92*8-1 : 91*8 ] ;
encrypted[ 75] = tt [ 91*8-1 : 90*8 ] ;
encrypted[ 74] = tt [ 90*8-1 : 89*8 ] ;
encrypted[ 73] = tt [ 89*8-1 : 88*8 ] ;
encrypted[ 72] = tt [ 88*8-1 : 87*8 ] ;
encrypted[ 71] = tt [ 87*8-1 : 86*8 ] ;
encrypted[ 70] = tt [ 86*8-1 : 85*8 ] ;
encrypted[ 69] = tt [ 85*8-1 : 84*8 ] ;
encrypted[ 68] = tt [ 84*8-1 : 83*8 ] ;
encrypted[ 67] = tt [ 83*8-1 : 82*8 ] ;
encrypted[ 66] = tt [ 82*8-1 : 81*8 ] ;
encrypted[ 65] = tt [ 81*8-1 : 80*8 ] ;
encrypted[ 64] = tt [ 80*8-1 : 79*8 ] ;
encrypted[ 63] = tt [ 79*8-1 : 78*8 ] ;
encrypted[ 62] = tt [ 78*8-1 : 77*8 ] ;
encrypted[ 61] = tt [ 77*8-1 : 76*8 ] ;
encrypted[ 60] = tt [ 76*8-1 : 75*8 ] ;
encrypted[ 59] = tt [ 75*8-1 : 74*8 ] ;
encrypted[ 58] = tt [ 74*8-1 : 73*8 ] ;
encrypted[ 57] = tt [ 73*8-1 : 72*8 ] ;
encrypted[ 56] = tt [ 72*8-1 : 71*8 ] ;
encrypted[ 55] = tt [ 71*8-1 : 70*8 ] ;
encrypted[ 54] = tt [ 70*8-1 : 69*8 ] ;
encrypted[ 53] = tt [ 69*8-1 : 68*8 ] ;
encrypted[ 52] = tt [ 68*8-1 : 67*8 ] ;
encrypted[ 51] = tt [ 67*8-1 : 66*8 ] ;
encrypted[ 50] = tt [ 66*8-1 : 65*8 ] ;
encrypted[ 49] = tt [ 65*8-1 : 64*8 ] ;
encrypted[ 48] = tt [ 64*8-1 : 63*8 ] ;
encrypted[ 47] = tt [ 63*8-1 : 62*8 ] ;
encrypted[ 46] = tt [ 62*8-1 : 61*8 ] ;
encrypted[ 45] = tt [ 61*8-1 : 60*8 ] ;
encrypted[ 44] = tt [ 60*8-1 : 59*8 ] ;
encrypted[ 43] = tt [ 59*8-1 : 58*8 ] ;
encrypted[ 42] = tt [ 58*8-1 : 57*8 ] ;
encrypted[ 41] = tt [ 57*8-1 : 56*8 ] ;
encrypted[ 40] = tt [ 56*8-1 : 55*8 ] ;
encrypted[ 39] = tt [ 55*8-1 : 54*8 ] ;
encrypted[ 38] = tt [ 54*8-1 : 53*8 ] ;
encrypted[ 37] = tt [ 53*8-1 : 52*8 ] ;
encrypted[ 36] = tt [ 52*8-1 : 51*8 ] ;
encrypted[ 35] = tt [ 51*8-1 : 50*8 ] ;
encrypted[ 34] = tt [ 50*8-1 : 49*8 ] ;
encrypted[ 33] = tt [ 49*8-1 : 48*8 ] ;
encrypted[ 32] = tt [ 48*8-1 : 47*8 ] ;
encrypted[ 31] = tt [ 47*8-1 : 46*8 ] ;
encrypted[ 30] = tt [ 46*8-1 : 45*8 ] ;
encrypted[ 29] = tt [ 45*8-1 : 44*8 ] ;
encrypted[ 28] = tt [ 44*8-1 : 43*8 ] ;
encrypted[ 27] = tt [ 43*8-1 : 42*8 ] ;
encrypted[ 26] = tt [ 42*8-1 : 41*8 ] ;
encrypted[ 25] = tt [ 41*8-1 : 40*8 ] ;
encrypted[ 24] = tt [ 40*8-1 : 39*8 ] ;
encrypted[ 23] = tt [ 39*8-1 : 38*8 ] ;
encrypted[ 22] = tt [ 38*8-1 : 37*8 ] ;
encrypted[ 21] = tt [ 37*8-1 : 36*8 ] ;
encrypted[ 20] = tt [ 36*8-1 : 35*8 ] ;
encrypted[ 19] = tt [ 35*8-1 : 34*8 ] ;
encrypted[ 18] = tt [ 34*8-1 : 33*8 ] ;
encrypted[ 17] = tt [ 33*8-1 : 32*8 ] ;
encrypted[ 16] = tt [ 32*8-1 : 31*8 ] ;
encrypted[ 15] = tt [ 31*8-1 : 30*8 ] ;
encrypted[ 14] = tt [ 30*8-1 : 29*8 ] ;
encrypted[ 13] = tt [ 29*8-1 : 28*8 ] ;
encrypted[ 12] = tt [ 28*8-1 : 27*8 ] ;
encrypted[ 11] = tt [ 27*8-1 : 26*8 ] ;
encrypted[ 10] = tt [ 26*8-1 : 25*8 ] ;
encrypted[ 9] = tt [ 25*8-1 : 24*8 ] ;
encrypted[ 8] = tt [ 24*8-1 : 23*8 ] ;
encrypted[ 7] = tt [ 23*8-1 : 22*8 ] ;
encrypted[ 6] = tt [ 22*8-1 : 21*8 ] ;
encrypted[ 5] = tt [ 21*8-1 : 20*8 ] ;
encrypted[ 4] = tt [ 20*8-1 : 19*8 ] ;
encrypted[ 3] = tt [ 19*8-1 : 18*8 ] ;
encrypted[ 2] = tt [ 18*8-1 : 17*8 ] ;
encrypted[ 1] = tt [ 17*8-1 : 16*8 ] ;
en=0;
key_en=0;
271,7 → 90,6
// output result
$write_data(
"../test_dat/decrypt.out.v"
,"w"
,decrypted[1]
);
for(out_bytes=2;out_bytes<=188;out_bytes=out_bytes+1)
310,53 → 128,9
 
 
 
`else
 
reg en;
reg init;
reg [8*8-1:0] ck;
reg [8*8-1:0] sb;
wire [8*8-1:0] cb;
 
initial
begin
repeat (12)@(posedge clk);
init=1'h1;
en=1'h1;
ck=64'hffffffffffffffff;
sb=64'hffffffffffffffff;
@(posedge clk);
en=1'h0;
@(posedge clk);
en=1'h1;
init=1'h0;
@(posedge clk);
en=1'h0;
@(posedge clk);
repeat(10)@(posedge clk);
en=1'h1;
@(posedge clk);
en=1'h0;
repeat(10)@(posedge clk);
$stop;
end
 
stream_cypher sc(
.clk (clk)
, .rst (rst)
, .en (en)
, .init (init)
, .ck (ck)
, .sb (sb)
, .cb (cb)
);
 
`endif
 
initial
begin
clk<=1'b0;
forever #5 clk=~clk;
end
/bench/timescale.v
0,0 → 1,9
`timescale 10ns/1ns
/bench/csa_pli.c
67,9 → 67,9
if(trarg_type==vpiConstant)
// offset ?
{
if(vpi_get(vpiConstType,trarg_h)!=vpiBinaryConst)
if(vpi_get(vpiConstType,trarg_h)!=vpiDecConst)
{
vpi_printf("the offset must be dec constant [%d] \n",vpi_get(vpiConstType,trarg_h));
vpi_printf("[%d]the offset must be dec constant [%d] \n",vpi_get(vpiConstType,trarg_h));
tf_dofinish();
return 0;
}
289,9 → 289,9
trarg_type=vpi_get(vpiType,trarg_h);
}
 
if(trarg_type!=vpiConstant&&trarg_type!=vpiReg)
if(trarg_type!=vpiConstant&&trarg_type!=vpiReg&&trarg_type!=vpiPartSelect&&trarg_type!=vpiRegBit)
{
vpi_printf("error, the last argument is not a constant val [%d]\n",trarg_type);
vpi_printf("[%d]error, the last argument is not a constant val [%d]\n",__LINE__,trarg_type);
tf_dofinish();
return 0;
}
321,7 → 321,7
systf_handle = vpi_handle(vpiSysTfCall, NULL);
if(systf_handle== NULL)
{
vpi_printf("ERROR: $pow failed to obtain systf call handles\n");
vpi_printf("ERROR: failed to obtain systf call handles\n");
tf_dofinish();
return(0);
}
328,7 → 328,7
arg_itr = vpi_iterate(vpiArgument, systf_handle);
if (arg_itr == NULL)
{
vpi_printf("ERROR: $pow failed to obtain systf arg handles\n");
vpi_printf("ERROR: failed to obtain systf arg handles\n");
tf_dofinish();
return(0);
}
/bench/makefile
1,9 → 1,9
 
PROJ_NAME ?= key_schedule
PROJ_NAME ?= decrypt
DEBUG ?= y
 
#MODELSIM_DIR=/opt/modeltech
MODELSIM_DIR=/mnt/new_disk/tool/modeltech/modeltech
MODELSIM_DIR=/opt/modeltech/modeltech
#MODELSIM_DIR=/mnt/new_disk/tool/modeltech/modeltech
 
ifeq ($(DEBUG),y)
CFLAGS=-DDEBUG
14,7 → 14,7
all:csa_pli.vpi $(PROJ_NAME).vvp csa_pli_modelsim
 
csa_pli.vpi:csa_pli.c
iverilog-vpi $(CFLAGS) --name=csa_pli $^ >/dev/null
-iverilog-vpi $(CFLAGS) --name=csa_pli $^ >/dev/null
rm -fr csa_pli.o
 
csa_pli_modelsim:csa_pli.sl
28,7 → 28,7
 
 
%.vvp:%_tb.v ../rtl/%.v
iverilog $(CFLAGS) -tvvp -o$@ $^
-iverilog $(CFLAGS) -tvvp -o$@ $^
 
test:csa_pli.vpi $(PROJ_NAME).vvp
vvp -M. -mcsa_pli $(PROJ_NAME).vvp
/modelsim6.2b/csa.mpf
277,7 → 277,7
UserTimeUnit = default
 
; Default run length
RunLength = 5 ns
RunLength = 100 ns
 
; Maximum iterations that can be run without advancing simulation time
IterationLimit = 5000
324,7 → 324,7
 
; Stop the simulator after a VHDL/Verilog immediate assertion message
; 0 = Note 1 = Warning 2 = Error 3 = Failure 4 = Fatal
BreakOnAssertion = 4
BreakOnAssertion = 3
 
; VHDL assertion Message Format
; %S - Severity Level
699,7 → 699,6
; Default is "+acc=lprnb -opt=-merge -opt=-suppressAlways"
; VoptCoverageOptions = +acc=lprnb -opt=-merge -opt=-suppressAlways
 
DelayFileOpen = 1
[lmc]
; The simulator's interface to Logic Modeling's SmartModel SWIFT software
libsm = $MODEL_TECH/libsm.sl
757,7 → 756,9
Project_Version = 6
Project_DefaultLib = work
Project_SortMethod = unused
Project_Files_Count = 0
Project_Files_Count = 1
Project_File_0 = /mnt/new_disk/work/csa_svn/csa/csa/trunk/bench/decrypt_tb.v
Project_File_P_0 = cover_toggle 0 vlog_protect 0 file_type verilog group_id 0 cover_exttoggle 0 cover_cond 0 vlog_nodebug 0 vlog_1995compat 0 vlog_noload 0 folder {Top Level} last_compile 0 cover_fsm 0 cover_branch 0 vlog_enable0In 0 vlog_disableopt 0 vlog_vopt 0 vlog_showsource 0 vlog_hazard 0 vlog_0InOptions {} ood 1 vlog_upper 0 compile_to work vlog_options {} compile_order 0 cover_expr 0 dont_compile 0 cover_stmt 0
Project_Sim_Count = 0
Project_Folder_Count = 0
Echo_Compile_Output = 0
787,6 → 788,6
XML_CustomDoubleClick =
LOGFILE_DoubleClick = Edit
LOGFILE_CustomDoubleClick =
EditorState =
EditorState = {tabbed horizontal 1} {/mnt/new_disk/work/csa_svn/csa/csa/trunk/bench/decrypt_tb.v 0 1}
Project_Major_Version = 6
Project_Minor_Version = 2
/rtl/key_perm.v
1,4 → 1,5
 
`include "../bench/timescale.v"
 
// this module do a key 64bits perm
// author: mengxipeng
/rtl/block_decypher.v
1,4 → 1,6
`include "../bench/timescale.v"
 
 
// this module will do the block decrypter work
module single_block_decyper(ri,kk,ro);
input [8*8-1:0*8] ri;
/rtl/block_perm.v
1,4 → 1,5
 
`include "../bench/timescale.v"
 
module block_perm(in, out);
input [7:0] in;
/rtl/stream_byte.v
1,3 → 1,4
`include "../bench/timescale.v"
 
 
// this module do a stream_byte opertion
/rtl/block_sbox.v
1,4 → 1,5
 
`include "../bench/timescale.v"
module block_sbox(in, out);
input [7:0] in;
output [7:0] out;
/rtl/stream_8bytes.v
1,3 → 1,4
`include "../bench/timescale.v"
 
 
// this module do 8bytes iteration
/rtl/sbox1.v
1,3 → 1,4
`include "../bench/timescale.v"
module sbox1(in,out);
input [4:0]in;
output [1:0]out;
/rtl/sbox2.v
1,3 → 1,4
`include "../bench/timescale.v"
module sbox2(in,out);
input [4:0]in;
output [1:0]out;
/rtl/sbox3.v
1,3 → 1,4
`include "../bench/timescale.v"
module sbox3(in,out);
input [4:0]in;
output [1:0]out;
/rtl/sbox4.v
1,3 → 1,4
`include "../bench/timescale.v"
module sbox4(in,out);
input [4:0]in;
output [1:0]out;
/rtl/sbox5.v
1,3 → 1,4
`include "../bench/timescale.v"
module sbox5(in,out);
input [4:0]in;
output [1:0]out;
/rtl/sbox6.v
1,3 → 1,4
`include "../bench/timescale.v"
module sbox6(in,out);
input [4:0]in;
output [1:0]out;
/rtl/sbox7.v
1,3 → 1,4
`include "../bench/timescale.v"
module sbox7(in,out);
input [4:0]in;
output [1:0]out;
/rtl/sboxes.v
1,3 → 1,4
`include "../bench/timescale.v"
 
//this moudule preform the s-boxes transform
 
/rtl/key_schedule.v
1,3 → 1,4
`include "../bench/timescale.v"
// this key_schedule module
module key_schedule(clk,rst,start,i_ck,busy,done,o_kk);
input clk;
47,7 → 48,7
busy <= 1'h1;
ok_d <= oki;
o_kk <= {o_kk [(6*8)*8-1:8*0],
oki ^ 64'h0606060606060606};
i_ck ^ 64'h0606060606060606};
end
 
if(busy)
70,26 → 71,4
end
end
end
 
 
// wire [64*8-1:0] kb;
// assign kb[(8*8)*8-1:(7*8)*8] = i_ck;
//
// key_perm k1( .i_key(kb[(8*8)*8-1:(7*8)*8]) ,.o_key(kb[(7*8)*8-1:(6*8)*8]));
// key_perm k2( .i_key(kb[(7*8)*8-1:(6*8)*8]) ,.o_key(kb[(6*8)*8-1:(5*8)*8]));
// key_perm k3( .i_key(kb[(6*8)*8-1:(5*8)*8]) ,.o_key(kb[(5*8)*8-1:(4*8)*8]));
// key_perm k4( .i_key(kb[(5*8)*8-1:(4*8)*8]) ,.o_key(kb[(4*8)*8-1:(3*8)*8]));
// key_perm k5( .i_key(kb[(4*8)*8-1:(3*8)*8]) ,.o_key(kb[(3*8)*8-1:(2*8)*8]));
// key_perm k6( .i_key(kb[(3*8)*8-1:(2*8)*8]) ,.o_key(kb[(2*8)*8-1:(1*8)*8]));
// key_perm k7( .i_key(kb[(2*8)*8-1:(1*8)*8]) ,.o_key(kb[(1*8)*8-1:(0*8)*8]));
//
// assign o_kk [(1*8)*8-1:(0*8)*8] = kb[(2*8)*8-1:(1*8)*8] ^ 64'h0000000000000000;
// assign o_kk [(2*8)*8-1:(1*8)*8] = kb[(3*8)*8-1:(2*8)*8] ^ 64'h0101010101010101;
// assign o_kk [(3*8)*8-1:(2*8)*8] = kb[(4*8)*8-1:(3*8)*8] ^ 64'h0202020202020202;
// assign o_kk [(4*8)*8-1:(3*8)*8] = kb[(5*8)*8-1:(4*8)*8] ^ 64'h0303030303030303;
// assign o_kk [(5*8)*8-1:(4*8)*8] = kb[(6*8)*8-1:(5*8)*8] ^ 64'h0404040404040404;
// assign o_kk [(6*8)*8-1:(5*8)*8] = kb[(7*8)*8-1:(6*8)*8] ^ 64'h0505050505050505;
// assign o_kk [(7*8)*8-1:(6*8)*8] = kb[(8*8)*8-1:(7*8)*8] ^ 64'h0606060606060606;
 
 
endmodule
/rtl/stream_cypher.v
1,3 → 1,4
`include "../bench/timescale.v"
 
 
// this file implement the stream cypher module
/rtl/key_computer.v
1,4 → 1,5
 
`include "../bench/timescale.v"
 
// this module is used to computer a key
// author: Simon panti
/rtl/stream_iteration.v
1,3 → 1,4
`include "../bench/timescale.v"
 
// this module do a iteration operation for 2 bit
 
/rtl/decrypt.v
1,4 → 1,5
 
`include "../bench/timescale.v"
// this module will do csa decrypt work
 
module decrypt(clk,rst,ck,key_en,even_odd,en,encrypted,decrypted,invalid);
/sw_sim/misc.h
27,15 → 27,15
fwrite(a,1,n,stdout); \
}while(0)
 
#define DEBUG_OUTPUT_ARR( a , n ) \
do{ \
int i; \
fprintf(stderr,"%s:\n",#a); \
for(i=n-1;i>=0;i--) \
{ \
fprintf(stderr,"%x ",(a)[i]);\
} \
fprintf(stderr,"\n"); \
#define DEBUG_OUTPUT_ARR( a , n ) \
do{ \
int i; \
fprintf(stderr,"%s:\n",#a); \
for(i=n-1;i>=0;i--) \
{ \
fprintf(stderr,"%02x ",(a)[i]);\
} \
fprintf(stderr,"\n"); \
}while(0)
 
#define DEBUG_OUTPUT_VAL( a ) \
/sw_sim/csa.c
263,6 → 263,8
int newbit[64];
int kb[9][8];
 
DEBUG_OUTPUT_ARR(CK,8);
 
/* 56 steps */
/* 56 key bytes kk(56)..kk(1) by key schedule from CK */
 
292,6 → 294,16
}
}
}
DEBUG_OUTPUT_ARR(kb[0],9);
DEBUG_OUTPUT_ARR(kb[1],9);
DEBUG_OUTPUT_ARR(kb[2],9);
DEBUG_OUTPUT_ARR(kb[3],9);
DEBUG_OUTPUT_ARR(kb[4],9);
DEBUG_OUTPUT_ARR(kb[5],9);
DEBUG_OUTPUT_ARR(kb[6],9);
DEBUG_OUTPUT_ARR(kb[7],9);
DEBUG_OUTPUT_ARR(kb[8],9);
DEBUG_OUTPUT_ARR(kb[9],9);
 
/* xor to give kk */
for(i=0; i<7; i++) {
299,6 → 311,7
kk[1+i*8+j] = kb[1+i][1+j] ^ i;
}
}
DEBUG_OUTPUT_ARR(&kk[1],56);
}
 
void block_decypher(int *kk, unsigned char *ib, unsigned char *bd) {
352,6 → 365,8
memcpy(key->even_ck,cws,8);
key_schedule(key->odd_ck,key->odd_kk);
key_schedule(key->even_ck,key->even_kk);
DEBUG_OUTPUT_ARR(key->even_kk,57);
DEBUG_OUTPUT_ARR(key->odd_kk,57);
}
 
void decrypt(struct key *key, unsigned char *encrypted, unsigned char *decrypted) {
380,7 → 395,6
 
/* 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);
400,9 → 414,6
/* xor ib x block */
for(i=0; i<8; i++)
decrypted[offset+8*(j-1)+i] = ib[i] ^ block[i];
DEBUG_OUTPUT_ARR(ib,8);
DEBUG_OUTPUT_ARR(block,8);
DEBUG_OUTPUT_ARR(&decrypted[offset+8*(j-1)+0],8);
} /* for(j=1; j<(N+1); j++) */
 
if (residue) {

powered by: WebSVN 2.1.0

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