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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [pli/] [env_aes.c] - Rev 4

Go to most recent revision | Compare with Previous | Blame | View Log

//////////////////////////////////////////////////////////////////
////
////
//// 	AES CORE BLOCK
////
////
////
//// This file is part of the APB to AES128 project
////
//// http://www.opencores.org/cores/apbtoaes128/
////
////
////
//// Description
////
//// Implementation of APB IP core according to
////
//// aes128_spec IP core specification document.
////
////
////
//// To Do: Things are right here but always all block can suffer changes
////
////
////
////
////
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
////
///////////////////////////////////////////////////////////////// 
////
////
//// Copyright (C) 2009 Authors and OPENCORES.ORG
////
////
////
//// This source file may be used and distributed without
////
//// restriction provided that this copyright statement is not
////
//// removed from the file and that any derivative work contains
//// the original copyright notice and the associated disclaimer.
////
////
//// This source file is free software; you can redistribute it
////
//// and/or modify it under the terms of the GNU Lesser General
////
//// Public License as published by the Free Software Foundation;
//// either version 2.1 of the License, or (at your option) any
////
//// later version.
////
////
////
//// This source is distributed in the hope that it will be
////
//// useful, but WITHOUT ANY WARRANTY; without even the implied
////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
////
//// PURPOSE. See the GNU Lesser General Public License for more
//// details.
////
////
////
//// You should have received a copy of the GNU Lesser General
////
//// Public License along with this source; if not, download it
////
//// from http://www.opencores.org/lgpl.shtml
////
////
///////////////////////////////////////////////////////////////////
 
#include "../../iverilog/vpi_user.h"
//#include <vpi_user.h>
#include <iostream>
#include <random>
 
 
s_vpi_value v_generate;
 
s_vpi_value v_ecb;
s_vpi_time  t_ecb;
 
s_vpi_value v_wr;
s_vpi_time  t_wr;
 
s_vpi_value v_reset;
s_vpi_time  t_reset;
 
 
s_vpi_value v_initial;
s_vpi_time  t_initial;
 
 
unsigned long  int a;
unsigned long  int b;
unsigned long  int c;
unsigned long  int d;
 
int type_bfm;
 
int STATE;
int STATE_RESET;
 
int counter;
 
int flag;
 
int reset_counter;
int counter_reset_enter;
int counter_reset_wait;
int FIPS_ENABLE;
 
int RESET_GENERATED;
int PACKETS_GENERATED;
 
int counter_write;
int counter_read;
int counter_wait;
 
/*AES REGISTERS*/
#define ADDR_AES_CR 0
#define ADDR_AES_SR 4
#define ADDR_AES_DINR 8
 
#define ADDR_AES_DOUTR 12
#define ADDR_AES_KEYR0 16
#define ADDR_AES_KEYR1 20
#define ADDR_AES_KEYR2 24
#define ADDR_AES_KEYR3 28
 
#define ADDR_AES_IVR0 32
#define ADDR_AES_IVR1 36
#define ADDR_AES_IVR2 40
#define ADDR_AES_IVR3 44
 
int vector_address[11];
 
/*STATE MACHINE TO WORK WITH BFM*/
#define IDLE           0
#define WRITE          1
#define WAIT           2
#define READ_RESULTS   3
 
#define WRITE_DINR     4
#define READ_DOUTR     5
#define WAIT_SR	       6
#define RESET_SR       7 
#define READ_KEY_GEN   8
 
 
/*STATE MACHINE TO WORK WITH BFM RESET*/
#define ENTER_RESET    9
#define WAIT_RESET    10
#define GET_OUT_RESET 11
 
 
#define AES_WR_ONLY 99
#define AES_WR_ERROR_DINR_ONLY 100
#define AES_WR_ERROR_DOUTR_ONLY 100
 
/*TEST USING NAMES TO ENABLE BFMs*/
#define ECB_ENCRYPTION 1
#define ECB_DECRYPTION 2
#define ECB_KEY_GEN    3
#define ECB_DERIVATION_DECRYPTION 4
 
#define ECB_ENCRYPTION_DMA            5
#define ECB_DECRYPTION_DMA   	      6
#define ECB_KEY_GEN_DMA      	      7
#define ECB_DERIVATION_DECRYPTION_DMA 8
 
#define ECB_ENCRYPTION_CCFIE             9
#define ECB_DECRYPTION_CCFIE            10
#define ECB_DERIVATION_DECRYPTION_CCFIE 11
#define ECB_KEY_GEN_CCFIE		12
 
/*TYPE CONFIGURATION USED TO INSERT DATA ON DUT*/
#define FIPS 0
#define RANDOM_DATA 1
 
 
/*MAX PACKETS GENERATION*/
#define MAX_ITERATIONS 17
 
/*MAX RESET GENERATION */
#define MAX_RESET_TIMES 4
 
/*THIS INCLUDE IS USED TO GENERATE DATA DO BE INSERTED ON DUT*/
unsigned char TEXT_FIPS_NOT_DERIVATED[] = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF};
unsigned char KEY_FIPS_NOT_DERIVATED[]  = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F};
 
unsigned char TEXT_FIPS_DERIVATED[] 	= {0x69,0xC4,0xE0,0xD8,0x6A,0x7B,0x04,0x30,0xD8,0xCD,0xB7,0x80,0x70,0xB4,0xC5,0x5A};
unsigned char KEY_FIPS_DERIVATED[]  	= {0x13,0x11,0x1D,0x7F,0xE3,0x94,0x4A,0x17,0xF3,0x07,0xA7,0x8B,0x4D,0x2B,0x30,0xC5};
 
/*BFM CONTROL FLOW*/
#include "aes_bfm_generate.h"
 
/*BASIC TEST WRITE READ*/
#include "aes_bfm_wr.h"
#include "bfm_error/aes_bfm_wr_error_dinr.h"
#include "bfm_error/aes_bfm_wr_error_doutr.h"
 
/*ECB TEST CASES*/
#include "bfm_ecb/aes_bfm_encryption_ecb.h"
#include "bfm_ecb/aes_bfm_decryption_ecb.h"
#include "bfm_ecb/aes_bfm_derivation_decryption_ecb.h"
#include "bfm_ecb/aes_bfm_key_generation_ecb.h"
 
#include "bfm_ecb/aes_bfm_decryption_dma_ecb.h"
#include "bfm_ecb/aes_bfm_encryption_dma_ecb.h"
#include "bfm_ecb/aes_bfm_key_generation_dma_ecb.h"
#include "bfm_ecb/aes_bfm_derivation_decryption_dma_ecb.h"
 
 
#include "bfm_ecb/aes_bfm_encryption_ccfie_ecb.h"
#include "bfm_ecb/aes_bfm_decryption_ccfie_ecb.h"
#include "bfm_ecb/aes_bfm_derivation_decryption_ccfie_ecb.h"
#include "bfm_ecb/aes_bfm_key_generation_ccfie_ecb.h"
 
#include "aes_init.h"
#include "aes_monitor.h"
#include "aes_bfm_reset.h"
#include "aes_init_reset.h"
 
 
void AES_GLADIC_register()
{
 
      s_vpi_systf_data tf_data;
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_generate_type";
      tf_data.calltf    = aes_bfm_generate_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_wr_aes128";
      tf_data.calltf    = aes_bfm_wr_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      //DMA WITH ERROR 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_wr_error_dinr_aes128";
      tf_data.calltf    = aes_bfm_wr_error_dinr_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_wr_error_doutr_aes128";
      tf_data.calltf    = aes_bfm_wr_error_doutr_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      // ENCRYPTION
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_encryption_ecb_aes128";
      tf_data.calltf    = aes_bfm_encryption_ecb_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_encryption_ecb_dma_aes128";
      tf_data.calltf    =  aes_bfm_encryption_ecb_dma_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_encryption_ccfie_ecb_aes128";
      tf_data.calltf    =  aes_bfm_encryption_ccfie_ecb_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      //DECRYPTION
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_decryption_ecb_aes128";
      tf_data.calltf    =  aes_bfm_decryption_ecb_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_decryption_ecb_dma_aes128";
      tf_data.calltf    =  aes_bfm_decryption_ecb_dma_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_decryption_ccfie_ecb_aes128";
      tf_data.calltf    =  aes_bfm_decryption_ccfie_ecb_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      //DERIVATION DECRYPTION
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_derivation_decryption_ecb_aes128";
      tf_data.calltf    =  aes_bfm_derivation_decryption_ecb_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_derivation_decryption_dma_ecb_aes128";
      tf_data.calltf    =  aes_bfm_derivation_decryption_dma_ecb_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_derivation_decryption_ccfie_ecb_aes128";
      tf_data.calltf    =  aes_bfm_derivation_decryption_ccfie_ecb_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      //KEY DERIVATION
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_key_generation_ecb_aes128";
      tf_data.calltf    =  aes_bfm_key_generation_ecb_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_key_generation_dma_ecb_aes128";
      tf_data.calltf    =  aes_bfm_key_generation_dma_ecb_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$bfm_key_generation_ccfie_ecb_aes128";
      tf_data.calltf    =  aes_bfm_key_generation_ccfie_ecb_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      // RESET BFM
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$reset_aes128";
      tf_data.calltf    = aes_reset_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
 
      //ENV CONFIGURATION
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$init";
      tf_data.calltf    = init_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$init_reset";
      tf_data.calltf    = init_reset_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
      tf_data.type      = vpiSysTask;
      tf_data.sysfunctype = 0;
      tf_data.tfname    = "$monitor_aes";
      tf_data.calltf    = mon_calltf;
      tf_data.compiletf = 0;
      tf_data.sizetf    = 0;
      tf_data.user_data = 0;
      vpi_register_systf(&tf_data);
 
}
 
 
void (*vlog_startup_routines[])() = {
    AES_GLADIC_register,
    0
};
 
 

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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