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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [pli/] [env_aes.c] - Blame information for rev 4

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

Line No. Rev Author Line
1 4 redbear
//////////////////////////////////////////////////////////////////
2
////
3
////
4
////    AES CORE BLOCK
5
////
6
////
7
////
8
//// This file is part of the APB to AES128 project
9
////
10
//// http://www.opencores.org/cores/apbtoaes128/
11
////
12
////
13
////
14
//// Description
15
////
16
//// Implementation of APB IP core according to
17
////
18
//// aes128_spec IP core specification document.
19
////
20
////
21
////
22
//// To Do: Things are right here but always all block can suffer changes
23
////
24
////
25
////
26
////
27
////
28
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
29
////
30
///////////////////////////////////////////////////////////////// 
31
////
32
////
33
//// Copyright (C) 2009 Authors and OPENCORES.ORG
34
////
35
////
36
////
37
//// This source file may be used and distributed without
38
////
39
//// restriction provided that this copyright statement is not
40
////
41
//// removed from the file and that any derivative work contains
42
//// the original copyright notice and the associated disclaimer.
43
////
44
////
45
//// This source file is free software; you can redistribute it
46
////
47
//// and/or modify it under the terms of the GNU Lesser General
48
////
49
//// Public License as published by the Free Software Foundation;
50
//// either version 2.1 of the License, or (at your option) any
51
////
52
//// later version.
53
////
54
////
55
////
56
//// This source is distributed in the hope that it will be
57
////
58
//// useful, but WITHOUT ANY WARRANTY; without even the implied
59
////
60
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
61
////
62
//// PURPOSE. See the GNU Lesser General Public License for more
63
//// details.
64
////
65
////
66
////
67
//// You should have received a copy of the GNU Lesser General
68
////
69
//// Public License along with this source; if not, download it
70
////
71
//// from http://www.opencores.org/lgpl.shtml
72
////
73
////
74
///////////////////////////////////////////////////////////////////
75
 
76
#include "../../iverilog/vpi_user.h"
77
//#include <vpi_user.h>
78
#include <iostream>
79
#include <random>
80
 
81
 
82
s_vpi_value v_generate;
83
 
84
s_vpi_value v_ecb;
85
s_vpi_time  t_ecb;
86
 
87
s_vpi_value v_wr;
88
s_vpi_time  t_wr;
89
 
90
s_vpi_value v_reset;
91
s_vpi_time  t_reset;
92
 
93
 
94
s_vpi_value v_initial;
95
s_vpi_time  t_initial;
96
 
97
 
98
unsigned long  int a;
99
unsigned long  int b;
100
unsigned long  int c;
101
unsigned long  int d;
102
 
103
int type_bfm;
104
 
105
int STATE;
106
int STATE_RESET;
107
 
108
int counter;
109
 
110
int flag;
111
 
112
int reset_counter;
113
int counter_reset_enter;
114
int counter_reset_wait;
115
int FIPS_ENABLE;
116
 
117
int RESET_GENERATED;
118
int PACKETS_GENERATED;
119
 
120
int counter_write;
121
int counter_read;
122
int counter_wait;
123
 
124
/*AES REGISTERS*/
125
#define ADDR_AES_CR 0
126
#define ADDR_AES_SR 4
127
#define ADDR_AES_DINR 8
128
 
129
#define ADDR_AES_DOUTR 12
130
#define ADDR_AES_KEYR0 16
131
#define ADDR_AES_KEYR1 20
132
#define ADDR_AES_KEYR2 24
133
#define ADDR_AES_KEYR3 28
134
 
135
#define ADDR_AES_IVR0 32
136
#define ADDR_AES_IVR1 36
137
#define ADDR_AES_IVR2 40
138
#define ADDR_AES_IVR3 44
139
 
140
int vector_address[11];
141
 
142
/*STATE MACHINE TO WORK WITH BFM*/
143
#define IDLE           0
144
#define WRITE          1
145
#define WAIT           2
146
#define READ_RESULTS   3
147
 
148
#define WRITE_DINR     4
149
#define READ_DOUTR     5
150
#define WAIT_SR        6
151
#define RESET_SR       7 
152
#define READ_KEY_GEN   8
153
 
154
 
155
/*STATE MACHINE TO WORK WITH BFM RESET*/
156
#define ENTER_RESET    9
157
#define WAIT_RESET    10
158
#define GET_OUT_RESET 11
159
 
160
 
161
#define AES_WR_ONLY 99
162
#define AES_WR_ERROR_DINR_ONLY 100
163
#define AES_WR_ERROR_DOUTR_ONLY 100
164
 
165
/*TEST USING NAMES TO ENABLE BFMs*/
166
#define ECB_ENCRYPTION 1
167
#define ECB_DECRYPTION 2
168
#define ECB_KEY_GEN    3
169
#define ECB_DERIVATION_DECRYPTION 4
170
 
171
#define ECB_ENCRYPTION_DMA            5
172
#define ECB_DECRYPTION_DMA            6
173
#define ECB_KEY_GEN_DMA               7
174
#define ECB_DERIVATION_DECRYPTION_DMA 8
175
 
176
#define ECB_ENCRYPTION_CCFIE             9
177
#define ECB_DECRYPTION_CCFIE            10
178
#define ECB_DERIVATION_DECRYPTION_CCFIE 11
179
#define ECB_KEY_GEN_CCFIE               12
180
 
181
/*TYPE CONFIGURATION USED TO INSERT DATA ON DUT*/
182
#define FIPS 0
183
#define RANDOM_DATA 1
184
 
185
 
186
/*MAX PACKETS GENERATION*/
187
#define MAX_ITERATIONS 17
188
 
189
/*MAX RESET GENERATION */
190
#define MAX_RESET_TIMES 4
191
 
192
/*THIS INCLUDE IS USED TO GENERATE DATA DO BE INSERTED ON DUT*/
193
unsigned char TEXT_FIPS_NOT_DERIVATED[] = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF};
194
unsigned char KEY_FIPS_NOT_DERIVATED[]  = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F};
195
 
196
unsigned char TEXT_FIPS_DERIVATED[]     = {0x69,0xC4,0xE0,0xD8,0x6A,0x7B,0x04,0x30,0xD8,0xCD,0xB7,0x80,0x70,0xB4,0xC5,0x5A};
197
unsigned char KEY_FIPS_DERIVATED[]      = {0x13,0x11,0x1D,0x7F,0xE3,0x94,0x4A,0x17,0xF3,0x07,0xA7,0x8B,0x4D,0x2B,0x30,0xC5};
198
 
199
/*BFM CONTROL FLOW*/
200
#include "aes_bfm_generate.h"
201
 
202
/*BASIC TEST WRITE READ*/
203
#include "aes_bfm_wr.h"
204
#include "bfm_error/aes_bfm_wr_error_dinr.h"
205
#include "bfm_error/aes_bfm_wr_error_doutr.h"
206
 
207
/*ECB TEST CASES*/
208
#include "bfm_ecb/aes_bfm_encryption_ecb.h"
209
#include "bfm_ecb/aes_bfm_decryption_ecb.h"
210
#include "bfm_ecb/aes_bfm_derivation_decryption_ecb.h"
211
#include "bfm_ecb/aes_bfm_key_generation_ecb.h"
212
 
213
#include "bfm_ecb/aes_bfm_decryption_dma_ecb.h"
214
#include "bfm_ecb/aes_bfm_encryption_dma_ecb.h"
215
#include "bfm_ecb/aes_bfm_key_generation_dma_ecb.h"
216
#include "bfm_ecb/aes_bfm_derivation_decryption_dma_ecb.h"
217
 
218
 
219
#include "bfm_ecb/aes_bfm_encryption_ccfie_ecb.h"
220
#include "bfm_ecb/aes_bfm_decryption_ccfie_ecb.h"
221
#include "bfm_ecb/aes_bfm_derivation_decryption_ccfie_ecb.h"
222
#include "bfm_ecb/aes_bfm_key_generation_ccfie_ecb.h"
223
 
224
#include "aes_init.h"
225
#include "aes_monitor.h"
226
#include "aes_bfm_reset.h"
227
#include "aes_init_reset.h"
228
 
229
 
230
void AES_GLADIC_register()
231
{
232
 
233
      s_vpi_systf_data tf_data;
234
 
235
      tf_data.type      = vpiSysTask;
236
      tf_data.sysfunctype = 0;
237
      tf_data.tfname    = "$bfm_generate_type";
238
      tf_data.calltf    = aes_bfm_generate_calltf;
239
      tf_data.compiletf = 0;
240
      tf_data.sizetf    = 0;
241
      tf_data.user_data = 0;
242
      vpi_register_systf(&tf_data);
243
 
244
 
245
      tf_data.type      = vpiSysTask;
246
      tf_data.sysfunctype = 0;
247
      tf_data.tfname    = "$bfm_wr_aes128";
248
      tf_data.calltf    = aes_bfm_wr_calltf;
249
      tf_data.compiletf = 0;
250
      tf_data.sizetf    = 0;
251
      tf_data.user_data = 0;
252
      vpi_register_systf(&tf_data);
253
 
254
      //DMA WITH ERROR 
255
      tf_data.type      = vpiSysTask;
256
      tf_data.sysfunctype = 0;
257
      tf_data.tfname    = "$bfm_wr_error_dinr_aes128";
258
      tf_data.calltf    = aes_bfm_wr_error_dinr_calltf;
259
      tf_data.compiletf = 0;
260
      tf_data.sizetf    = 0;
261
      tf_data.user_data = 0;
262
      vpi_register_systf(&tf_data);
263
 
264
      tf_data.type      = vpiSysTask;
265
      tf_data.sysfunctype = 0;
266
      tf_data.tfname    = "$bfm_wr_error_doutr_aes128";
267
      tf_data.calltf    = aes_bfm_wr_error_doutr_calltf;
268
      tf_data.compiletf = 0;
269
      tf_data.sizetf    = 0;
270
      tf_data.user_data = 0;
271
      vpi_register_systf(&tf_data);
272
 
273
      // ENCRYPTION
274
      tf_data.type      = vpiSysTask;
275
      tf_data.sysfunctype = 0;
276
      tf_data.tfname    = "$bfm_encryption_ecb_aes128";
277
      tf_data.calltf    = aes_bfm_encryption_ecb_calltf;
278
      tf_data.compiletf = 0;
279
      tf_data.sizetf    = 0;
280
      tf_data.user_data = 0;
281
      vpi_register_systf(&tf_data);
282
 
283
      tf_data.type      = vpiSysTask;
284
      tf_data.sysfunctype = 0;
285
      tf_data.tfname    = "$bfm_encryption_ecb_dma_aes128";
286
      tf_data.calltf    =  aes_bfm_encryption_ecb_dma_calltf;
287
      tf_data.compiletf = 0;
288
      tf_data.sizetf    = 0;
289
      tf_data.user_data = 0;
290
      vpi_register_systf(&tf_data);
291
 
292
      tf_data.type      = vpiSysTask;
293
      tf_data.sysfunctype = 0;
294
      tf_data.tfname    = "$bfm_encryption_ccfie_ecb_aes128";
295
      tf_data.calltf    =  aes_bfm_encryption_ccfie_ecb_calltf;
296
      tf_data.compiletf = 0;
297
      tf_data.sizetf    = 0;
298
      tf_data.user_data = 0;
299
      vpi_register_systf(&tf_data);
300
 
301
      //DECRYPTION
302
      tf_data.type      = vpiSysTask;
303
      tf_data.sysfunctype = 0;
304
      tf_data.tfname    = "$bfm_decryption_ecb_aes128";
305
      tf_data.calltf    =  aes_bfm_decryption_ecb_calltf;
306
      tf_data.compiletf = 0;
307
      tf_data.sizetf    = 0;
308
      tf_data.user_data = 0;
309
      vpi_register_systf(&tf_data);
310
 
311
      tf_data.type      = vpiSysTask;
312
      tf_data.sysfunctype = 0;
313
      tf_data.tfname    = "$bfm_decryption_ecb_dma_aes128";
314
      tf_data.calltf    =  aes_bfm_decryption_ecb_dma_calltf;
315
      tf_data.compiletf = 0;
316
      tf_data.sizetf    = 0;
317
      tf_data.user_data = 0;
318
      vpi_register_systf(&tf_data);
319
 
320
      tf_data.type      = vpiSysTask;
321
      tf_data.sysfunctype = 0;
322
      tf_data.tfname    = "$bfm_decryption_ccfie_ecb_aes128";
323
      tf_data.calltf    =  aes_bfm_decryption_ccfie_ecb_calltf;
324
      tf_data.compiletf = 0;
325
      tf_data.sizetf    = 0;
326
      tf_data.user_data = 0;
327
      vpi_register_systf(&tf_data);
328
 
329
      //DERIVATION DECRYPTION
330
      tf_data.type      = vpiSysTask;
331
      tf_data.sysfunctype = 0;
332
      tf_data.tfname    = "$bfm_derivation_decryption_ecb_aes128";
333
      tf_data.calltf    =  aes_bfm_derivation_decryption_ecb_calltf;
334
      tf_data.compiletf = 0;
335
      tf_data.sizetf    = 0;
336
      tf_data.user_data = 0;
337
      vpi_register_systf(&tf_data);
338
 
339
      tf_data.type      = vpiSysTask;
340
      tf_data.sysfunctype = 0;
341
      tf_data.tfname    = "$bfm_derivation_decryption_dma_ecb_aes128";
342
      tf_data.calltf    =  aes_bfm_derivation_decryption_dma_ecb_calltf;
343
      tf_data.compiletf = 0;
344
      tf_data.sizetf    = 0;
345
      tf_data.user_data = 0;
346
      vpi_register_systf(&tf_data);
347
 
348
      tf_data.type      = vpiSysTask;
349
      tf_data.sysfunctype = 0;
350
      tf_data.tfname    = "$bfm_derivation_decryption_ccfie_ecb_aes128";
351
      tf_data.calltf    =  aes_bfm_derivation_decryption_ccfie_ecb_calltf;
352
      tf_data.compiletf = 0;
353
      tf_data.sizetf    = 0;
354
      tf_data.user_data = 0;
355
      vpi_register_systf(&tf_data);
356
 
357
      //KEY DERIVATION
358
      tf_data.type      = vpiSysTask;
359
      tf_data.sysfunctype = 0;
360
      tf_data.tfname    = "$bfm_key_generation_ecb_aes128";
361
      tf_data.calltf    =  aes_bfm_key_generation_ecb_calltf;
362
      tf_data.compiletf = 0;
363
      tf_data.sizetf    = 0;
364
      tf_data.user_data = 0;
365
      vpi_register_systf(&tf_data);
366
 
367
      tf_data.type      = vpiSysTask;
368
      tf_data.sysfunctype = 0;
369
      tf_data.tfname    = "$bfm_key_generation_dma_ecb_aes128";
370
      tf_data.calltf    =  aes_bfm_key_generation_dma_ecb_calltf;
371
      tf_data.compiletf = 0;
372
      tf_data.sizetf    = 0;
373
      tf_data.user_data = 0;
374
      vpi_register_systf(&tf_data);
375
 
376
 
377
      tf_data.type      = vpiSysTask;
378
      tf_data.sysfunctype = 0;
379
      tf_data.tfname    = "$bfm_key_generation_ccfie_ecb_aes128";
380
      tf_data.calltf    =  aes_bfm_key_generation_ccfie_ecb_calltf;
381
      tf_data.compiletf = 0;
382
      tf_data.sizetf    = 0;
383
      tf_data.user_data = 0;
384
      vpi_register_systf(&tf_data);
385
 
386
      // RESET BFM
387
      tf_data.type      = vpiSysTask;
388
      tf_data.sysfunctype = 0;
389
      tf_data.tfname    = "$reset_aes128";
390
      tf_data.calltf    = aes_reset_calltf;
391
      tf_data.compiletf = 0;
392
      tf_data.sizetf    = 0;
393
      tf_data.user_data = 0;
394
      vpi_register_systf(&tf_data);
395
 
396
 
397
      //ENV CONFIGURATION
398
      tf_data.type      = vpiSysTask;
399
      tf_data.sysfunctype = 0;
400
      tf_data.tfname    = "$init";
401
      tf_data.calltf    = init_calltf;
402
      tf_data.compiletf = 0;
403
      tf_data.sizetf    = 0;
404
      tf_data.user_data = 0;
405
      vpi_register_systf(&tf_data);
406
 
407
      tf_data.type      = vpiSysTask;
408
      tf_data.sysfunctype = 0;
409
      tf_data.tfname    = "$init_reset";
410
      tf_data.calltf    = init_reset_calltf;
411
      tf_data.compiletf = 0;
412
      tf_data.sizetf    = 0;
413
      tf_data.user_data = 0;
414
      vpi_register_systf(&tf_data);
415
 
416
      tf_data.type      = vpiSysTask;
417
      tf_data.sysfunctype = 0;
418
      tf_data.tfname    = "$monitor_aes";
419
      tf_data.calltf    = mon_calltf;
420
      tf_data.compiletf = 0;
421
      tf_data.sizetf    = 0;
422
      tf_data.user_data = 0;
423
      vpi_register_systf(&tf_data);
424
 
425
}
426
 
427
 
428
void (*vlog_startup_routines[])() = {
429
    AES_GLADIC_register,
430
 
431
};
432
 

powered by: WebSVN 2.1.0

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