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

Subversion Repositories csa

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 48 to Rev 49
    Reverse comparison

Rev 48 → Rev 49

/csa/trunk/bench/group_decrypt_tb.v
0,0 → 1,143
 
 
// this is the test bench for decrypt module
 
 
`include "../bench/timescale.v"
 
module group_decrypt_tb;
 
reg clk;
reg rst;
 
 
reg [ 8*8-1:0] ck;
reg ks_start;
reg init;
reg last;
reg gd_en;
wire [ 8*8-1:0] dec_packet;
reg [ 8*8-1:0] enc_packet;
wire [56*8-1:0] kk;
wire valid;
integer ii;
integer jj;
integer offset;
initial
begin
$read_data(
"../test_dat/group_decrypt.in"
,ck
);
 
 
init=1'h0;
 
// calculate kk
repeat(4) @(posedge clk)
ks_start=1'h1;
@(posedge clk);
ks_start=1'h0;
repeat(14) @(posedge clk)
jj=0;
$display("kk=%x",kk);
 
// input encrypt packets
offset=8+(0)*8;
$read_data(
"../test_dat/group_decrypt.in"
, offset
, enc_packet);
init=1'h1;
last=1'h0;
gd_en=1'h1;
@(posedge clk);
 
for(ii=1;ii<23-1;ii=ii+1)
begin
init=1'h0;
last=1'h0;
gd_en=1'h1;
offset=8+(ii)*8;
$read_data(
"../test_dat/group_decrypt.in"
, offset
, enc_packet);
@(posedge clk);
end
 
offset=8+(23-1)*8;
$read_data(
"../test_dat/group_decrypt.in"
, offset
, enc_packet);
init=1'h0;
last=1'h1;
gd_en=1'h1;
@(posedge clk);
gd_en=1'h0;
 
repeat(10)@(posedge clk);
 
$stop;
end
 
always @(posedge clk)
if(valid)
begin
if(jj==0)
begin
$write_data(
"../test_dat/group_decrypt.out.v"
, dec_packet);
jj=1;
end
else
$write_data(
"../test_dat/group_decrypt.out.v"
, "a"
, dec_packet);
end
 
 
 
group_decrypt group_decrypt(
. clk (clk)
, . rst (rst)
, . en (gd_en)
, . init (init)
, . last (last)
, . ck (ck)
, . kk (kk)
, . group (enc_packet)
, . valid (valid)
, . ogroup (dec_packet)
);
 
key_schedule key_schedule(
.clk (clk)
, .rst (rst)
, .start (ks_start)
, .ck (ck)
, .busy ()
, .done ()
, .kk (kk)
);
 
 
 
initial
begin
clk=1'b0;
forever #5 clk=~clk;
end
 
initial
begin
rst=1'b1;
@(posedge clk);
@(posedge clk);
rst=1'h0;
end
endmodule
/csa/trunk/bench/timescale.v
1,0 → 1,143
`timescale 10ns/1ns
`timescale 1ns/100ps
/csa/trunk/modelsim6.2b/stream_cypher.do
62,17 → 62,17
set last_compile_time 0
}
foreach {library file_list} $library_file_list {
vmap work work
foreach file $file_list {
if { $last_compile_time < [file mtime $file] } {
if [regexp {.vhdl?$} $file] {
vcom -93 $file
} else {
vlog $file
}
set last_compile_time 0
}
}
vmap work work
foreach file $file_list {
if { $last_compile_time < [file mtime $file] } {
if [regexp {.vhdl?$} $file] {
vcom -93 $file
} else {
vlog $file
}
set last_compile_time 0
}
}
}
set last_compile_time $time_now
 
/csa/trunk/modelsim6.2b/group_decrypt.do
0,0 → 1,91
 
quit -sim
 
vlib work
vmap work work
 
 
puts {
ModelSimSE general compile script version 1.1
Copyright (c) Doulos June 2004, SD
}
 
# Simply change the project settings in this section
# for each new project. There should be no need to
# modify the rest of the script.
 
set library_file_list {
../rtl/decrypt.v
../rtl/key_cnt.v
../rtl/key_perm.v
../rtl/block_decypher.v
../rtl/block_perm.v
../rtl/block_sbox.v
../rtl/key_schedule.v
../rtl/stream_cypher.v
../rtl/stream_iteration.v
../rtl/stream_8bytes.v
../rtl/sboxes.v
../rtl/sbox1.v
../rtl/sbox2.v
../rtl/sbox3.v
../rtl/stream_byte.v
../rtl/sbox4.v
../rtl/sbox5.v
../rtl/sbox6.v
../rtl/sbox7.v
../rtl/group_decrypt.v
../bench/group_decrypt_tb.v
}
set top_level work.group_decrypt_tb
 
set wave_radices {
hexadecimal {data q}
}
 
 
# After sourcing the script from ModelSim for the
# first time use these commands to recompile.
 
proc r {} {uplevel #0 source compile.tcl}
proc rr {} {global last_compile_time
set last_compile_time 0
r }
proc q {} {quit -force }
 
#Does this installation support Tk?
set tk_ok 1
if [catch {package require Tk}] {set tk_ok 0}
 
# Prefer a fixed point font for the transcript
set PrefMain(font) {Courier 10 roman normal}
 
# Compile out of date files
set time_now [clock seconds]
if [catch {set last_compile_time}] {
set last_compile_time 0
}
vlib work
vmap work work
foreach file $library_file_list {
# if { $last_compile_time < [file mtime $file] } {
if [regexp {.vhdl?$} $file] {
vcom -93 $file
} else {
vlog $file
}
set last_compile_time 0
# }
}
set last_compile_time $time_now
 
# Load the simulation
vsim $top_level -pli ../bench/csa_pli.sl
add wave -r /*
radix -hexadecimal
 
 
# Run the simulation
run -all
 
 
/csa/trunk/rtl/group_decrypt.v
2,40 → 2,29
// 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 valid
, output [ 8*8-1:0] ogroup
, output [ 4-1:0] obytes
input clk // clk
, input rst // rst, high active
, input en // input enable
, input init // the first packet
, input last // the last packet
, input [ 8*8-1:0] ck // ck
, input [56*8-1:0] kk // kk
, input [ 8*8-1:0] group // packet
, output valid // output vaild
, output [ 8*8-1:0] ogroup // output packet
);
wire [8*8-1:0] stream;
wire [8*8-1:0] block;
reg [8*8-1:0] block_d;
reg [8*8-1:0] init_d;
reg [8*8-1:0] last_d;
reg [8*8-1:0] last_dd;
reg [8*8-1:0] en_d;
reg [8*8-1:0] en_dd;
 
reg init_d;
wire [8*8-1:0] stream;
reg busy;
wire [8*8-1:0] ib;
reg [8*8-1:0] bco_d;
wire [8*8-1:0] bco;
reg en_d;
 
always @(posedge clk)
en_d<=en;
 
always @(posedge clk)
init_d<=init;
 
always @(posedge clk)
if(en_d)
bco_d<=bco;
 
assign ib=(init_d)?group:group^stream;
 
stream_cypher stream_cypher(
.clk (clk)
, .rst (rst)
44,17 → 33,50
, .ck (ck)
, .sb (group)
, .cb (stream)
);
);
 
block_decypher block_decypher(
.kk (kk)
, .ib (ib)
, .bd (bco)
);
assign ogroup=group^bco_d^stream;
assign valid=en_d & ~init_d;
assign obytes=4'h8;
endmodule
block_decypher block_decypher (
.kk (kk)
, .ib (ib)
, .bd (block)
);
 
 
always @(posedge clk)
if(en_d)
block_d<=block;
 
always @(posedge clk)
if(en)
init_d<=init;
 
always @(posedge clk)
last_dd<=last_d;
 
always @(posedge clk)
if(en)
last_d<=last;
 
always @(posedge clk)
en_d<=en;
 
always @(posedge clk)
en_dd<=en_d;
 
assign ogroup=(en_dd&last_dd)?block_d:ib^block_d;
 
assign valid=((busy)&en) | (en_dd&last_dd);
 
assign ib=(init)?group:group^stream;
 
always @(posedge clk )
if(rst)
busy<=1'h0;
else
begin
if(init_d)
busy<=1'h1;
if(last_d)
busy<=1'h0;
end
endmodule
/csa/trunk/rtl/key_schedule.v
56,7 → 56,6
64'h0101010101010101,
64'h0000000000000000
};
//assign busy=cnt!=3'h0;
 
key_perm kpi(.i_key(kk_arry[8*8-1:0]), .o_key(next_kk));
 
/csa/trunk/rtl/stream_cypher.v
13,6 → 13,7
output [8 *8-1:0] cb;
 
 
 
// intermediate variable
reg [10*4-1 : 0]A;
reg [10*4-1 : 0]B;
25,7 → 26,6
reg p;
reg q;
reg r;
reg [8 *8-1 : 0]cb;
 
wire [10*4-1 : 0]Ao;
wire [10*4-1 : 0]Ainit;
78,7 → 78,6
begin
if(en)
begin
cb <= cbo;
A<= Ao;
B<= Bo;
X<= Xo;
124,4 → 123,6
,.cb(cbo)
);
 
assign cb=cbo;
 
endmodule
/csa/trunk/rtl/makefile
1,4 → 1,4
PROJ_NAME ?=decrypt
PROJ_NAME ?=group_decrypt
DEBUG ?=y
 
ifeq ($(DEBUG),y)
21,6 → 21,25
block_perm.v \
block_sbox.v
 
group_decrypt:
iverilog -S $(VFLAGS) -tnull $@.v \
stream_cypher.v \
stream_8bytes.v \
stream_byte.v \
stream_iteration.v \
sboxes.v \
sbox1.v \
sbox2.v \
sbox3.v \
sbox4.v \
sbox5.v \
sbox6.v \
sbox7.v \
block_perm.v \
block_sbox.v \
block_decypher.v
 
 
stream_cypher:
iverilog -S $(VFLAGS) -tnull $@.v \
sbox1.v \
/csa/trunk/rtl/decrypt.v
74,99 → 74,6
, .obytes (obytes)
);
 
//
//// decrypt
//reg [8*8-1:0] db;
//reg db_valid;
//
//wire [56*8-1:0]kk_decrypt;
//wire [ 8*8-1:0]ck_decrypt;
//
//assign kk_decrypt = (using_even_odd_key) ? odd_kk : even_kk ;
//assign ck_decrypt = (using_even_odd_key) ? odd_ck : even_ck ;
//
//wire [8*8-1:0] sc_sb;
//wire [8*8-1:0] sc_cb;
//wire init;
//wire sc_en;
//wire last;
//
//assign sc_sb = group;
//assign init = group_id == 5'h00;
//assign last = group_id == 5'd22;
//reg [2:0] last_cnt;
//reg last_run;
//assign sc_en = group_valid;
//
//stream_cypher sc(
// .clk (clk)
// , .rst (rst)
// , .en (sc_en)
// , .init (init)
// , .ck (ck_decrypt)
// , .sb (sc_sb)
// , .cb (sc_cb)
// );
//
//wire [ 8*8-1:0] bco;
//reg [ 8*8-1:0] bc;
//reg [ 8*8-1:0] ib;
//block_decypher bcm(
// .kk (kk_decrypt)
// , .ib (ib[8*8-1:0])
// , .bd (bco)
// );
//
//
//always @(posedge clk)
//if(rst)
//begin
// db <= 64'h00;
// ib <= 128'h00000000000000000000000000000000;
// bc <= 64'hffffffffffffffff;
// last_cnt<=3'h0;
// last_run<=1'h0;
//end
//else
//begin
// db_valid<=1'h0;
// if(group_valid_d)
// begin
// bc<=bco;
// if(init)
// begin
// ib<={ ib[8*8-1:0],sc_cb };
// db<=bco^sc_cb;
// end
// else
// begin
// ib<={ ib[8*8-1:0],sc_cb^sc_sb };
// db<=bco^sc_cb^sc_sb;
// end
// if(group_id>1'h0)
// begin
// db_valid<=1'h1;
// end
//
// if(last)
// last_run<=1'h1;
//
// end
// if(last_run)
// begin
// last_cnt<=last_cnt+3'h1;
// if(last_cnt==3'h7)
// begin
// db_valid<=1'h1;
// db<=bco;
// last_run<=1'h0;
// end
//
// end
//end
//
 
 
ts_serial_out ts_serial_out(
.clk (clk)
, .rst (rst)
/csa/trunk/sw_sim/csa.c
392,8 → 392,6
stream_cypher(0, ck, NULL, stream);
 
/* xor sb x stream */
DEBUG_OUTPUT_ARR(&encrypted[offset+8*j+0],8);
DEBUG_OUTPUT_ARR(stream,8);
for(i=0; i<8; i++)
ib[i] = encrypted[offset+8*j+i] ^ stream[i];
}
409,10 → 407,8
#endif
 
/* xor ib x block */
DEBUG_OUTPUT_ARR(block,8);
for(i=0; i<8; i++)
decrypted[offset+8*(j-1)+i] = ib[i] ^ block[i];
DEBUG_OUTPUT_ARR(&decrypted[offset+8*(j-1)+0],8);
} /* for(j=1; j<(N+1); j++) */
 
if (residue) {
/csa/trunk/sw_sim/group_decrypt.c
0,0 → 1,81
/*
* =====================================================================================
*
* Filename: group_decrypt.c
*
* Description: test group decryp module
*
* Version: 1.0
* Created: 04/25/2009 11:56:00 AM
* Revision: none
* Compiler: gcc
*
* Author: mengxipeng@gmail.com
*
* =====================================================================================
*/
 
#include <stdio.h>
#include <string.h>
#include "misc.h"
#include "csa.h"
 
void key_schedule(unsigned char *CK, int *kk) ;
void stream_cypher(int init, unsigned char *CK, unsigned char *sb, unsigned char *cb) ;
void block_decypher(int *kk, unsigned char *ib, unsigned char *bd) ;
 
int main()
{
unsigned char ck[8];
int kk[57];
unsigned char encrypted[184];
unsigned char decrypted[184];
READ_DATA(ck,8);
key_schedule(ck,kk);
READ_DATA(encrypted,184);
{
int i,j,offset=0,N;
unsigned char stream[8];
unsigned char ib[8];
unsigned char block[8];
int residue;
 
N = (184 - offset) / 8;
residue = (184 - offset) % 8;
/* 1st 8 bytes of initialisation */
stream_cypher(1, ck, &encrypted[offset], ib);
 
 
for(j=1; j<(N+1); j++) {
block_decypher(kk, ib, block);
DEBUG_OUTPUT_ARR(block,8);
 
if (j != N) {
stream_cypher(0, ck, NULL, stream);
 
/* xor sb x stream */
for(i=0; i<8; i++)
ib[i] = encrypted[offset+8*j+i] ^ stream[i];
}
else {
/* last block - sb[N+1] = IV(initialisation vetor)(=0) */
for(i=0; i<8; i++) ib[i] = 0;
}
 
/* xor ib x block */
for(i=0; i<8; i++)
decrypted[offset+8*(j-1)+i] = ib[i] ^ block[i];
DEBUG_OUTPUT_ARR(&decrypted[offset+8*(j-1)+0],8);
} /* for(j=1; j<(N+1); j++) */
 
if (residue) {
stream_cypher(0, ck, NULL, stream);
for (i=0;i<residue;i++)
decrypted[184-residue+i] = encrypted[184-residue+i] ^ stream[i];
}
}
WRITE_DATA(decrypted,184);
return 0;
}
 
/csa/trunk/sw_sim/makefile
1,5 → 1,5
 
PROJ_NAME ?= decrypt
PROJ_NAME ?= group_decrypt
DEBUG ?=y
 
CFLAGS=-g -ggdb -ansi -Wall
14,10 → 14,10
rm -fr $(PROJ_NAME)
rm -fr *.o
 
test:$(PROJ_NAME)
tt:$(PROJ_NAME)
./$(PROJ_NAME) <../test_dat/$(PROJ_NAME).in >../test_dat/$(PROJ_NAME).out.sw
 
debug:$(PROJ_NAME)
dd:$(PROJ_NAME)
echo "set args <../test_dat/$(PROJ_NAME).in >../test_dat/$(PROJ_NAME).out.sw " >gdb-command
ddd ./$(PROJ_NAME) -x gdb-command
32,6 → 32,8
 
stream_cypher:csa.o stream_cypher.o
 
group_decrypt:csa.o group_decrypt.o
 
-include .depend
 
CSRCS= \

powered by: WebSVN 2.1.0

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