//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
////
|
////
|
////
|
////
|
//// AES CORE BLOCK
|
//// AES CORE BLOCK
|
////
|
////
|
////
|
////
|
////
|
////
|
//// This file is part of the APB to AES128 project
|
//// This file is part of the APB to AES128 project
|
////
|
////
|
//// http://www.opencores.org/cores/apbtoaes128/
|
//// http://www.opencores.org/cores/apbtoaes128/
|
////
|
////
|
////
|
////
|
////
|
////
|
//// Description
|
//// Description
|
////
|
////
|
//// Implementation of APB IP core according to
|
//// Implementation of APB IP core according to
|
////
|
////
|
//// aes128_spec IP core specification document.
|
//// aes128_spec IP core specification document.
|
////
|
////
|
////
|
////
|
////
|
////
|
//// To Do: Things are right here but always all block can suffer changes
|
//// To Do: Things are right here but always all block can suffer changes
|
////
|
////
|
////
|
////
|
////
|
////
|
////
|
////
|
////
|
////
|
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
|
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
|
////
|
////
|
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
////
|
////
|
////
|
////
|
//// Copyright (C) 2009 Authors and OPENCORES.ORG
|
//// Copyright (C) 2009 Authors and OPENCORES.ORG
|
////
|
////
|
////
|
////
|
////
|
////
|
//// This source file may be used and distributed without
|
//// This source file may be used and distributed without
|
////
|
////
|
//// restriction provided that this copyright statement is not
|
//// restriction provided that this copyright statement is not
|
////
|
////
|
//// removed from the file and that any derivative work contains
|
//// removed from the file and that any derivative work contains
|
//// the original copyright notice and the associated disclaimer.
|
//// the original copyright notice and the associated disclaimer.
|
////
|
////
|
////
|
////
|
//// This source file is free software; you can redistribute it
|
//// This source file is free software; you can redistribute it
|
////
|
////
|
//// and/or modify it under the terms of the GNU Lesser General
|
//// and/or modify it under the terms of the GNU Lesser General
|
////
|
////
|
//// Public License as published by the Free Software Foundation;
|
//// Public License as published by the Free Software Foundation;
|
//// either version 2.1 of the License, or (at your option) any
|
//// either version 2.1 of the License, or (at your option) any
|
////
|
////
|
//// later version.
|
//// later version.
|
////
|
////
|
////
|
////
|
////
|
////
|
//// This source is distributed in the hope that it will be
|
//// This source is distributed in the hope that it will be
|
////
|
////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied
|
////
|
////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
////
|
////
|
//// PURPOSE. See the GNU Lesser General Public License for more
|
//// PURPOSE. See the GNU Lesser General Public License for more
|
//// details.
|
//// details.
|
////
|
////
|
////
|
////
|
////
|
////
|
//// You should have received a copy of the GNU Lesser General
|
//// You should have received a copy of the GNU Lesser General
|
////
|
////
|
//// Public License along with this source; if not, download it
|
//// Public License along with this source; if not, download it
|
////
|
////
|
//// from http://www.opencores.org/lgpl.shtml
|
//// from http://www.opencores.org/lgpl.shtml
|
////
|
////
|
////
|
////
|
///////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////
|
static int aes_bfm_key_generation_ccfie_cbc_calltf(char*user_data)
|
static int aes_bfm_key_generation_ccfie_cbc_calltf(char*user_data)
|
{
|
{
|
|
|
vpiHandle PRESETn = vpi_handle_by_name("AES_GLADIC_tb.PRESETn", NULL);
|
vpiHandle PRESETn = vpi_handle_by_name("AES_GLADIC_tb.PRESETn", NULL);
|
vpiHandle PWDATA = vpi_handle_by_name("AES_GLADIC_tb.PWDATA", NULL);
|
vpiHandle PWDATA = vpi_handle_by_name("AES_GLADIC_tb.PWDATA", NULL);
|
vpiHandle PENABLE = vpi_handle_by_name("AES_GLADIC_tb.PENABLE", NULL);
|
vpiHandle PENABLE = vpi_handle_by_name("AES_GLADIC_tb.PENABLE", NULL);
|
vpiHandle PSEL = vpi_handle_by_name("AES_GLADIC_tb.PSEL", NULL);
|
vpiHandle PSEL = vpi_handle_by_name("AES_GLADIC_tb.PSEL", NULL);
|
vpiHandle PWRITE = vpi_handle_by_name("AES_GLADIC_tb.PWRITE", NULL);
|
vpiHandle PWRITE = vpi_handle_by_name("AES_GLADIC_tb.PWRITE", NULL);
|
vpiHandle PADDR = vpi_handle_by_name("AES_GLADIC_tb.PADDR", NULL);
|
vpiHandle PADDR = vpi_handle_by_name("AES_GLADIC_tb.PADDR", NULL);
|
vpiHandle PRDATA = vpi_handle_by_name("AES_GLADIC_tb.PRDATA", NULL);
|
vpiHandle PRDATA = vpi_handle_by_name("AES_GLADIC_tb.PRDATA", NULL);
|
vpiHandle PREADY = vpi_handle_by_name("AES_GLADIC_tb.PREADY", NULL);
|
vpiHandle PREADY = vpi_handle_by_name("AES_GLADIC_tb.PREADY", NULL);
|
vpiHandle PSLVERR = vpi_handle_by_name("AES_GLADIC_tb.PSLVERR", NULL);
|
vpiHandle PSLVERR = vpi_handle_by_name("AES_GLADIC_tb.PSLVERR", NULL);
|
vpiHandle int_ccf = vpi_handle_by_name("AES_GLADIC_tb.int_ccf", NULL);
|
vpiHandle int_ccf = vpi_handle_by_name("AES_GLADIC_tb.int_ccf", NULL);
|
vpiHandle int_err = vpi_handle_by_name("AES_GLADIC_tb.int_err", NULL);
|
vpiHandle int_err = vpi_handle_by_name("AES_GLADIC_tb.int_err", NULL);
|
vpiHandle dma_req_wr = vpi_handle_by_name("AES_GLADIC_tb.dma_req_wr", NULL);
|
vpiHandle dma_req_wr = vpi_handle_by_name("AES_GLADIC_tb.dma_req_wr", NULL);
|
vpiHandle dma_req_rd = vpi_handle_by_name("AES_GLADIC_tb.dma_req_rd", NULL);
|
vpiHandle dma_req_rd = vpi_handle_by_name("AES_GLADIC_tb.dma_req_rd", NULL);
|
|
|
std::random_device rd;
|
std::random_device rd;
|
std::uniform_int_distribution<long int> data_in(0,4294967295);
|
std::uniform_int_distribution<long int> data_in(0,4294967295);
|
|
|
v_ecb.format=vpiIntVal;
|
v_ecb.format=vpiIntVal;
|
|
|
vpi_get_value(PRESETn, &v_ecb);
|
vpi_get_value(PRESETn, &v_ecb);
|
|
|
|
|
//printf("%i\n",STATE);
|
//printf("%i\n",STATE);
|
|
|
|
|
if(type_bfm == CBC_KEY_GEN_CCFIE && v_ecb.value.integer == 1)
|
if(type_bfm == CBC_KEY_GEN_CCFIE && v_ecb.value.integer == 1)
|
{
|
{
|
|
|
switch(STATE)
|
switch(STATE)
|
{
|
{
|
|
|
case IDLE:
|
case IDLE:
|
|
|
if(PACKETS_GENERATED >= MAX_ITERATIONS)
|
if(PACKETS_GENERATED >= MAX_ITERATIONS)
|
{
|
{
|
|
|
STATE = IDLE;
|
STATE = IDLE;
|
type_bfm = 0;
|
type_bfm = 0;
|
|
|
}else
|
}else
|
{
|
{
|
STATE = WRITE;
|
STATE = WRITE;
|
|
|
counter = 0;
|
counter = 0;
|
|
|
|
|
v_ecb.value.integer = 0;
|
v_ecb.value.integer = 0;
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
|
|
v_ecb.value.integer = vector_address[0];
|
v_ecb.value.integer = vector_address[0];
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
|
|
v_ecb.value.integer = 0;
|
v_ecb.value.integer = 0;
|
vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
|
|
|
v_ecb.value.integer = 1;
|
v_ecb.value.integer = 1;
|
vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
|
|
|
v_ecb.value.integer = 1;
|
v_ecb.value.integer = 1;
|
vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
|
}
|
}
|
|
|
break;
|
break;
|
|
|
case WRITE:
|
case WRITE:
|
if(counter == 0)
|
if(counter == 0)
|
{
|
{
|
|
|
|
|
counter_write++;
|
counter_write++;
|
counter++;
|
counter++;
|
|
|
v_ecb.value.integer = 1;
|
v_ecb.value.integer = 1;
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
|
|
|
|
}else if(counter == 1)
|
}else if(counter == 1)
|
{
|
{
|
|
|
v_ecb.value.integer = 0;
|
v_ecb.value.integer = 0;
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
|
|
|
|
|
|
if(counter_write < 9)
|
if(counter_write < 9)
|
{
|
{
|
|
|
v_ecb.value.integer = vector_address[counter_write];
|
v_ecb.value.integer = vector_address[counter_write];
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
|
|
t_ecb.type = vpiScaledRealTime;
|
t_ecb.type = vpiScaledRealTime;
|
t_ecb.real = 0;
|
t_ecb.real = 0;
|
v_ecb.format=vpiIntVal;
|
v_ecb.format=vpiIntVal;
|
|
|
if(FIPS_ENABLE == FIPS)
|
if(FIPS_ENABLE == FIPS)
|
{
|
{
|
|
|
if(vector_address[counter_write] == ADDR_AES_KEYR3)
|
if(vector_address[counter_write] == ADDR_AES_KEYR3)
|
{
|
{
|
a = a | KEY_FIPS_CBC_NOT_DERIVATED[0];
|
a = a | KEY_FIPS_CBC_NOT_DERIVATED[0];
|
a = a << 8;
|
a = a << 8;
|
a = a | KEY_FIPS_CBC_NOT_DERIVATED[1];
|
a = a | KEY_FIPS_CBC_NOT_DERIVATED[1];
|
a = a << 8;
|
a = a << 8;
|
a = a | KEY_FIPS_CBC_NOT_DERIVATED[2];
|
a = a | KEY_FIPS_CBC_NOT_DERIVATED[2];
|
a = a << 8;
|
a = a << 8;
|
a = a | KEY_FIPS_CBC_NOT_DERIVATED[3];
|
a = a | KEY_FIPS_CBC_NOT_DERIVATED[3];
|
v_ecb.value.integer = a;
|
v_ecb.value.integer = a;
|
}
|
}
|
|
|
|
|
if(vector_address[counter_write] == ADDR_AES_KEYR2)
|
if(vector_address[counter_write] == ADDR_AES_KEYR2)
|
{
|
{
|
b = b | KEY_FIPS_CBC_NOT_DERIVATED[4];
|
b = b | KEY_FIPS_CBC_NOT_DERIVATED[4];
|
b = b << 8;
|
b = b << 8;
|
b = b | KEY_FIPS_CBC_NOT_DERIVATED[5];
|
b = b | KEY_FIPS_CBC_NOT_DERIVATED[5];
|
b = b << 8;
|
b = b << 8;
|
b = b | KEY_FIPS_CBC_NOT_DERIVATED[6];
|
b = b | KEY_FIPS_CBC_NOT_DERIVATED[6];
|
b = b << 8;
|
b = b << 8;
|
b = b | KEY_FIPS_CBC_NOT_DERIVATED[7];
|
b = b | KEY_FIPS_CBC_NOT_DERIVATED[7];
|
v_ecb.value.integer = b;
|
v_ecb.value.integer = b;
|
}
|
}
|
|
|
if(vector_address[counter_write] == ADDR_AES_KEYR1)
|
if(vector_address[counter_write] == ADDR_AES_KEYR1)
|
{
|
{
|
|
|
c = c | KEY_FIPS_CBC_NOT_DERIVATED[8];
|
c = c | KEY_FIPS_CBC_NOT_DERIVATED[8];
|
c = c << 8;
|
c = c << 8;
|
c = c | KEY_FIPS_CBC_NOT_DERIVATED[9];
|
c = c | KEY_FIPS_CBC_NOT_DERIVATED[9];
|
c = c << 8;
|
c = c << 8;
|
c = c | KEY_FIPS_CBC_NOT_DERIVATED[10];
|
c = c | KEY_FIPS_CBC_NOT_DERIVATED[10];
|
c = c << 8;
|
c = c << 8;
|
c = c | KEY_FIPS_CBC_NOT_DERIVATED[11];
|
c = c | KEY_FIPS_CBC_NOT_DERIVATED[11];
|
v_ecb.value.integer = c;
|
v_ecb.value.integer = c;
|
|
|
}
|
}
|
|
|
if(vector_address[counter_write] == ADDR_AES_KEYR0)
|
if(vector_address[counter_write] == ADDR_AES_KEYR0)
|
{
|
{
|
d = d | KEY_FIPS_CBC_NOT_DERIVATED[12];
|
d = d | KEY_FIPS_CBC_NOT_DERIVATED[12];
|
d = d << 8;
|
d = d << 8;
|
d = d | KEY_FIPS_CBC_NOT_DERIVATED[13];
|
d = d | KEY_FIPS_CBC_NOT_DERIVATED[13];
|
d = d << 8;
|
d = d << 8;
|
d = d | KEY_FIPS_CBC_NOT_DERIVATED[14];
|
d = d | KEY_FIPS_CBC_NOT_DERIVATED[14];
|
d = d << 8;
|
d = d << 8;
|
d = d | KEY_FIPS_CBC_NOT_DERIVATED[15];
|
d = d | KEY_FIPS_CBC_NOT_DERIVATED[15];
|
v_ecb.value.integer = d;
|
v_ecb.value.integer = d;
|
}
|
}
|
|
|
|
|
if(vector_address[counter_write] == ADDR_AES_IVR3)
|
if(vector_address[counter_write] == ADDR_AES_IVR3)
|
{
|
{
|
a = a | IV_FIPS_CBC_NOT_DERIVATED[0];
|
a = a | IV_FIPS_CBC_NOT_DERIVATED[0];
|
a = a << 8;
|
a = a << 8;
|
a = a | IV_FIPS_CBC_NOT_DERIVATED[1];
|
a = a | IV_FIPS_CBC_NOT_DERIVATED[1];
|
a = a << 8;
|
a = a << 8;
|
a = a | IV_FIPS_CBC_NOT_DERIVATED[2];
|
a = a | IV_FIPS_CBC_NOT_DERIVATED[2];
|
a = a << 8;
|
a = a << 8;
|
a = a | IV_FIPS_CBC_NOT_DERIVATED[3];
|
a = a | IV_FIPS_CBC_NOT_DERIVATED[3];
|
v_ecb.value.integer = a;
|
v_ecb.value.integer = a;
|
}
|
}
|
|
|
|
|
if(vector_address[counter_write] == ADDR_AES_IVR2)
|
if(vector_address[counter_write] == ADDR_AES_IVR2)
|
{
|
{
|
b = b | IV_FIPS_CBC_NOT_DERIVATED[4];
|
b = b | IV_FIPS_CBC_NOT_DERIVATED[4];
|
b = b << 8;
|
b = b << 8;
|
b = b | IV_FIPS_CBC_NOT_DERIVATED[5];
|
b = b | IV_FIPS_CBC_NOT_DERIVATED[5];
|
b = b << 8;
|
b = b << 8;
|
b = b | IV_FIPS_CBC_NOT_DERIVATED[6];
|
b = b | IV_FIPS_CBC_NOT_DERIVATED[6];
|
b = b << 8;
|
b = b << 8;
|
b = b | IV_FIPS_CBC_NOT_DERIVATED[7];
|
b = b | IV_FIPS_CBC_NOT_DERIVATED[7];
|
v_ecb.value.integer = b;
|
v_ecb.value.integer = b;
|
}
|
}
|
|
|
if(vector_address[counter_write] == ADDR_AES_IVR1)
|
if(vector_address[counter_write] == ADDR_AES_IVR1)
|
{
|
{
|
|
|
c = c | IV_FIPS_CBC_NOT_DERIVATED[8];
|
c = c | IV_FIPS_CBC_NOT_DERIVATED[8];
|
c = c << 8;
|
c = c << 8;
|
c = c | IV_FIPS_CBC_NOT_DERIVATED[9];
|
c = c | IV_FIPS_CBC_NOT_DERIVATED[9];
|
c = c << 8;
|
c = c << 8;
|
c = c | IV_FIPS_CBC_NOT_DERIVATED[10];
|
c = c | IV_FIPS_CBC_NOT_DERIVATED[10];
|
c = c << 8;
|
c = c << 8;
|
c = c | IV_FIPS_CBC_NOT_DERIVATED[11];
|
c = c | IV_FIPS_CBC_NOT_DERIVATED[11];
|
v_ecb.value.integer = c;
|
v_ecb.value.integer = c;
|
|
|
}
|
}
|
|
|
if(vector_address[counter_write] == ADDR_AES_IVR0)
|
if(vector_address[counter_write] == ADDR_AES_IVR0)
|
{
|
{
|
d = d | IV_FIPS_CBC_NOT_DERIVATED[12];
|
d = d | IV_FIPS_CBC_NOT_DERIVATED[12];
|
d = d << 8;
|
d = d << 8;
|
d = d | IV_FIPS_CBC_NOT_DERIVATED[13];
|
d = d | IV_FIPS_CBC_NOT_DERIVATED[13];
|
d = d << 8;
|
d = d << 8;
|
d = d | IV_FIPS_CBC_NOT_DERIVATED[14];
|
d = d | IV_FIPS_CBC_NOT_DERIVATED[14];
|
d = d << 8;
|
d = d << 8;
|
d = d | IV_FIPS_CBC_NOT_DERIVATED[15];
|
d = d | IV_FIPS_CBC_NOT_DERIVATED[15];
|
v_ecb.value.integer = d;
|
v_ecb.value.integer = d;
|
}
|
}
|
|
|
|
|
|
|
}else if(FIPS_ENABLE == RANDOM_DATA)
|
}else if(FIPS_ENABLE == RANDOM_DATA)
|
{
|
{
|
v_ecb.value.integer = data_in(rd);
|
v_ecb.value.integer = data_in(rd);
|
}
|
}
|
|
|
//vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
|
//vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
|
vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
|
|
|
|
|
a = 0;
|
a = 0;
|
b = 0;
|
b = 0;
|
c = 0;
|
c = 0;
|
d = 0;
|
d = 0;
|
}
|
}else if(counter_write == 9)
|
|
|
|
|
if(counter_write == 9)
|
|
{
|
{
|
|
|
v_ecb.value.integer = ADDR_AES_CR;
|
v_ecb.value.integer = ADDR_AES_CR;
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
|
|
t_ecb.type = vpiScaledRealTime;
|
t_ecb.type = vpiScaledRealTime;
|
t_ecb.real = 0;
|
t_ecb.real = 0;
|
v_ecb.format=vpiIntVal;
|
v_ecb.format=vpiIntVal;
|
v_ecb.value.integer = 553;
|
v_ecb.value.integer = 553;
|
vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
|
vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
|
|
|
}
|
}
|
|
|
|
|
v_ecb.value.integer = 1;
|
v_ecb.value.integer = 1;
|
vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
|
|
|
counter=0;
|
counter=0;
|
}
|
}
|
|
|
if(counter_write == 10)
|
if(counter_write == 10)
|
{
|
{
|
counter_write = 0;
|
counter_write = 0;
|
counter_read = 0;
|
counter_read = 0;
|
|
|
STATE =WAIT_SR;
|
STATE =WAIT_SR;
|
|
|
|
|
}
|
}
|
|
|
break;
|
break;
|
|
|
case WAIT_SR:
|
case WAIT_SR:
|
|
|
v_ecb.value.integer = ADDR_AES_SR;
|
v_ecb.value.integer = ADDR_AES_SR;
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
|
|
v_ecb.value.integer = 0;
|
v_ecb.value.integer = 0;
|
vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
|
|
|
if(counter == 0)
|
if(counter == 0)
|
{
|
{
|
|
|
counter++;
|
counter++;
|
|
|
v_ecb.value.integer = 1;
|
v_ecb.value.integer = 1;
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
|
|
|
|
}else if(counter == 1)
|
}else if(counter == 1)
|
{
|
{
|
v_ecb.value.integer = 0;
|
v_ecb.value.integer = 0;
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
|
|
counter=0;
|
counter=0;
|
}
|
}
|
|
|
v_ecb.value.integer = 0;
|
v_ecb.value.integer = 0;
|
vpi_get_value(PRDATA,&v_ecb);
|
vpi_get_value(PRDATA,&v_ecb);
|
|
|
if(v_ecb.value.integer == 1)
|
if(v_ecb.value.integer == 1)
|
{
|
{
|
STATE = READ_KEY_GEN;
|
STATE = READ_KEY_GEN;
|
|
|
//t_ecb.type = vpiScaledRealTime;
|
//t_ecb.type = vpiScaledRealTime;
|
//t_ecb.real = 10;
|
//t_ecb.real = 10;
|
//v_ecb.format=vpiIntVal;
|
//v_ecb.format=vpiIntVal;
|
//v_ecb.value.integer = ADDR_AES_KEYR3;
|
//v_ecb.value.integer = ADDR_AES_KEYR3;
|
//vpi_put_value(PADDR, &v_ecb, &t_ecb, vpiTransportDelay);
|
//vpi_put_value(PADDR, &v_ecb, &t_ecb, vpiTransportDelay);
|
}
|
}
|
|
|
|
|
break;
|
break;
|
|
|
|
|
case READ_KEY_GEN:
|
case READ_KEY_GEN:
|
|
|
|
|
|
|
if(counter == 0)
|
if(counter == 0)
|
{
|
{
|
|
|
v_ecb.value.integer = 1;
|
v_ecb.value.integer = 1;
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
|
|
counter_read++;
|
counter_read++;
|
counter++;
|
counter++;
|
|
|
|
|
|
|
}else if(counter == 1)
|
}else if(counter == 1)
|
{
|
{
|
|
|
v_ecb.value.integer = 0;
|
v_ecb.value.integer = 0;
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
|
|
if(counter_read < 4)
|
if(counter_read < 4)
|
{
|
{
|
v_ecb.value.integer = ADDR_AES_DOUTR;
|
v_ecb.value.integer = ADDR_AES_DOUTR;
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
}
|
}
|
|
|
if(counter_read == 4)
|
if(counter_read == 4)
|
{
|
{
|
v_ecb.value.integer = ADDR_AES_KEYR3;
|
v_ecb.value.integer = ADDR_AES_KEYR3;
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
}
|
}
|
|
|
if(counter_read == 5)
|
if(counter_read == 5)
|
{
|
{
|
v_ecb.value.integer = ADDR_AES_KEYR2;
|
v_ecb.value.integer = ADDR_AES_KEYR2;
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
}
|
}
|
|
|
|
|
if(counter_read == 6)
|
if(counter_read == 6)
|
{
|
{
|
v_ecb.value.integer = ADDR_AES_KEYR1;
|
v_ecb.value.integer = ADDR_AES_KEYR1;
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
}
|
}
|
|
|
if(counter_read == 7)
|
if(counter_read == 7)
|
{
|
{
|
v_ecb.value.integer = ADDR_AES_KEYR0;
|
v_ecb.value.integer = ADDR_AES_KEYR0;
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
}
|
}
|
|
|
if(counter_read == 8)
|
if(counter_read == 8)
|
{
|
{
|
v_ecb.value.integer = ADDR_AES_IVR3;
|
v_ecb.value.integer = ADDR_AES_IVR3;
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
}
|
}
|
|
|
if(counter_read == 9)
|
if(counter_read == 9)
|
{
|
{
|
v_ecb.value.integer = ADDR_AES_IVR2;
|
v_ecb.value.integer = ADDR_AES_IVR2;
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
}
|
}
|
|
|
if(counter_read == 10)
|
if(counter_read == 10)
|
{
|
{
|
v_ecb.value.integer = ADDR_AES_IVR1;
|
v_ecb.value.integer = ADDR_AES_IVR1;
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
}
|
}
|
|
|
if(counter_read == 11)
|
if(counter_read == 11)
|
{
|
{
|
v_ecb.value.integer = ADDR_AES_IVR0;
|
v_ecb.value.integer = ADDR_AES_IVR0;
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
}
|
}
|
|
|
counter = 0;
|
counter = 0;
|
}
|
}
|
|
|
if(counter_read == 12)
|
if(counter_read == 12)
|
{
|
{
|
STATE = RESET_SR;
|
STATE = RESET_SR;
|
counter_write = 0;
|
counter_write = 0;
|
counter_read = 0;
|
counter_read = 0;
|
}
|
}
|
|
|
break;
|
break;
|
|
|
case RESET_SR:
|
case RESET_SR:
|
|
|
v_ecb.value.integer = 1;
|
v_ecb.value.integer = 1;
|
vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
|
|
|
v_ecb.value.integer = 1;
|
v_ecb.value.integer = 1;
|
vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
|
|
|
v_ecb.value.integer = 0;
|
v_ecb.value.integer = 0;
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
|
|
|
v_ecb.value.integer = 128;
|
v_ecb.value.integer = 128;
|
vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
|
|
|
|
|
if(counter == 0)
|
if(counter == 0)
|
{
|
{
|
|
|
counter_write++;
|
counter_write++;
|
counter++;
|
counter++;
|
|
|
v_ecb.value.integer = 1;
|
v_ecb.value.integer = 1;
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
|
|
}else if(counter == 1)
|
}else if(counter == 1)
|
{
|
{
|
|
|
v_ecb.value.integer = 0;
|
v_ecb.value.integer = 0;
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
|
counter=0;
|
counter=0;
|
|
|
}
|
}
|
|
|
if(counter_write == 1)
|
if(counter_write == 1)
|
{
|
{
|
STATE =IDLE;
|
STATE =IDLE;
|
counter_write = 0;
|
counter_write = 0;
|
counter=0;
|
counter=0;
|
PACKETS_GENERATED = PACKETS_GENERATED + 1;
|
PACKETS_GENERATED = PACKETS_GENERATED + 1;
|
}
|
}
|
|
|
|
|
|
|
break;
|
break;
|
|
|
}
|
}
|
|
|
}
|
}
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|