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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [pli/] [bfm_error/] [aes_bfm_wr_error_dinr.h] - Blame information for rev 8

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
static int aes_bfm_wr_error_dinr_calltf(char*user_data)
76
{
77
 
78
        vpiHandle PRESETn = vpi_handle_by_name("AES_GLADIC_tb.PRESETn", NULL);
79
        vpiHandle PWDATA = vpi_handle_by_name("AES_GLADIC_tb.PWDATA", NULL);
80
        vpiHandle PENABLE = vpi_handle_by_name("AES_GLADIC_tb.PENABLE", NULL);
81
        vpiHandle PSEL = vpi_handle_by_name("AES_GLADIC_tb.PSEL", NULL);
82
        vpiHandle PWRITE = vpi_handle_by_name("AES_GLADIC_tb.PWRITE", NULL);
83
        vpiHandle PADDR = vpi_handle_by_name("AES_GLADIC_tb.PADDR", NULL);
84
        vpiHandle PRDATA = vpi_handle_by_name("AES_GLADIC_tb.PRDATA", NULL);
85
        vpiHandle PREADY = vpi_handle_by_name("AES_GLADIC_tb.PREADY", NULL);
86
        vpiHandle PSLVERR = vpi_handle_by_name("AES_GLADIC_tb.PSLVERR", NULL);
87
        vpiHandle int_ccf = vpi_handle_by_name("AES_GLADIC_tb.int_ccf", NULL);
88
        vpiHandle int_err = vpi_handle_by_name("AES_GLADIC_tb.int_err", NULL);
89
        vpiHandle dma_req_wr = vpi_handle_by_name("AES_GLADIC_tb.dma_req_wr", NULL);
90
        vpiHandle dma_req_rd = vpi_handle_by_name("AES_GLADIC_tb.dma_req_rd", NULL);
91
 
92
        v_wr.format=vpiIntVal;
93
 
94
 
95
        std::random_device rd;
96
        std::uniform_int_distribution<long int> data_in(0,4294967295);
97
 
98
 
99
        v_wr.format=vpiIntVal;
100
        vpi_get_value(PRESETn, &v_wr);
101
 
102
 
103
        if(type_bfm == AES_WR_ERROR_DINR_ONLY && v_wr.value.integer == 1)
104
        {
105
 
106
                //printf("%i\n",STATE);
107
 
108
                switch(STATE)
109
                {
110
 
111
                        case IDLE:
112
 
113
 
114
                                if(PACKETS_GENERATED >= MAX_ITERATIONS)
115
                                {
116
                                        STATE = IDLE;
117
                                        type_bfm = 0;
118
 
119
                                }else
120
                                {
121
                                        STATE = WRITE;
122
 
123
                                        counter = 0;
124
 
125
                                        v_wr.value.integer = vector_address[0];
126
                                        vpi_put_value(PADDR, &v_wr, NULL, vpiNoDelay);
127
 
128
                                        v_wr.value.integer = 0;
129
                                        vpi_put_value(PWDATA, &v_wr, NULL, vpiNoDelay);
130
 
131
                                        v_wr.value.integer = 1;
132
                                        vpi_put_value(PWRITE, &v_wr, NULL, vpiNoDelay);
133
 
134
                                        v_wr.value.integer = 1;
135
                                        vpi_put_value(PSEL, &v_wr, NULL, vpiNoDelay);
136
                                }
137
 
138
 
139
 
140
                        break;
141
 
142
                        case WRITE:
143
 
144
                                if(counter == 0)
145
                                {
146
 
147
                                        counter_write++;
148
                                        counter++;
149
 
150
                                        v_wr.value.integer = 1;
151
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
152
 
153
 
154
                                }else if(counter == 1)
155
                                {
156
 
157
                                        v_wr.value.integer = 0;
158
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
159
 
160
                                        t_wr.type = vpiScaledRealTime;
161
                                        t_wr.real = 0;
162
                                        v_wr.format=vpiIntVal;
163
 
164
                                        if(counter_write < 9)
165
                                        {
166
 
167
                                        v_wr.value.integer = vector_address[counter_write];
168
                                        vpi_put_value(PADDR, &v_wr, NULL, vpiNoDelay);
169
 
170
                                                if(FIPS_ENABLE == FIPS)
171
                                                {
172
 
173
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR3 || vector_address[counter_write] == ADDR_AES_IVR3)
174
                                                        {
175
                                                                a = a | KEY_FIPS_NOT_DERIVATED[0];
176
                                                                a = a << 8;
177
                                                                a = a | KEY_FIPS_NOT_DERIVATED[1];
178
                                                                a = a << 8;
179
                                                                a = a | KEY_FIPS_NOT_DERIVATED[2];
180
                                                                a = a << 8;
181
                                                                a = a | KEY_FIPS_NOT_DERIVATED[3];
182
                                                                v_wr.value.integer = a;
183
                                                        }
184
 
185
 
186
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR2 || vector_address[counter_write] == ADDR_AES_IVR2)
187
                                                        {
188
                                                                b = b | KEY_FIPS_NOT_DERIVATED[4];
189
                                                                b = b << 8;
190
                                                                b = b | KEY_FIPS_NOT_DERIVATED[5];
191
                                                                b = b << 8;
192
                                                                b = b | KEY_FIPS_NOT_DERIVATED[6];
193
                                                                b = b << 8;
194
                                                                b = b | KEY_FIPS_NOT_DERIVATED[7];
195
                                                                v_wr.value.integer = b;
196
                                                        }
197
 
198
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR1 || vector_address[counter_write] == ADDR_AES_IVR1)
199
                                                        {
200
 
201
                                                                c = c | KEY_FIPS_NOT_DERIVATED[8];
202
                                                                c = c << 8;
203
                                                                c = c | KEY_FIPS_NOT_DERIVATED[9];
204
                                                                c = c << 8;
205
                                                                c = c | KEY_FIPS_NOT_DERIVATED[10];
206
                                                                c = c << 8;
207
                                                                c = c | KEY_FIPS_NOT_DERIVATED[11];
208
                                                                v_wr.value.integer = c;
209
 
210
                                                        }
211
 
212
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR0 || vector_address[counter_write] == ADDR_AES_IVR0)
213
                                                        {
214
                                                                d = d | KEY_FIPS_NOT_DERIVATED[12];
215
                                                                d = d << 8;
216
                                                                d = d | KEY_FIPS_NOT_DERIVATED[13];
217
                                                                d = d << 8;
218
                                                                d = d | KEY_FIPS_NOT_DERIVATED[14];
219
                                                                d = d << 8;
220
                                                                d = d | KEY_FIPS_NOT_DERIVATED[15];
221
                                                                v_wr.value.integer = d;
222
                                                        }
223
 
224
 
225
 
226
                                                }else if(FIPS_ENABLE == RANDOM_DATA)
227
                                                {
228
                                                        v_wr.value.integer = data_in(rd);
229
                                                }
230
                                                vpi_put_value(PWDATA, &v_wr, &t_wr, vpiTransportDelay);
231
 
232
                                                a = 0;
233
                                                b = 0;
234
                                                c = 0;
235
                                                d = 0;
236
 
237
                                                v_wr.value.integer = 1;
238
                                                vpi_put_value(PSEL, &v_wr, NULL, vpiNoDelay);
239
 
240
 
241
                                        }else if(counter_write == 9)
242
                                        {
243
 
244
                                                v_wr.value.integer = vector_address[0];
245
                                                vpi_put_value(PADDR, &v_wr, NULL, vpiNoDelay);
246
 
247
                                                if(PACKETS_GENERATED == 0)//ENCRYPTION
248
                                                {
249
 
250
                                                        v_wr.value.integer = 1;
251
 
252
 
253
                                                }else if(PACKETS_GENERATED == 1)//ENCRYPTION
254
                                                {
255
 
256
                                                        v_wr.value.integer = 1025;
257
 
258
 
259
                                                }else if(PACKETS_GENERATED == 2)//KEY GENERATION
260
                                                {
261
 
262
                                                        v_wr.value.integer = 9;
263
 
264
 
265
                                                }else if(PACKETS_GENERATED == 3)//KEY GENERATION
266
                                                {
267
 
268
                                                        v_wr.value.integer = 1033;
269
 
270
 
271
                                                }else if(PACKETS_GENERATED == 4)//DECRYPTION
272
                                                {
273
 
274
                                                        v_wr.value.integer = 17;
275
 
276
 
277
                                                }else if(PACKETS_GENERATED == 5)//DECRYPTION
278
                                                {
279
 
280
                                                        v_wr.value.integer = 1041;
281
 
282
 
283
                                                }else if(PACKETS_GENERATED == 6)//DEVIRATION_DECRYPTION
284
                                                {
285
 
286
                                                        v_wr.value.integer = 25;
287
 
288
 
289
                                                }else if(PACKETS_GENERATED == 7)//DEVIRATION_DECRYPTION
290
                                                {
291
 
292
                                                        v_wr.value.integer = 1049;
293
 
294
 
295
                                                }else if(PACKETS_GENERATED == 8)//ENCRYPTION_DMA
296
                                                {
297
 
298
                                                        v_wr.value.integer = 6145;
299
 
300
 
301
                                                }else if(PACKETS_GENERATED == 9)//ENCRYPTION_DMA
302
                                                {
303
 
304
                                                        v_wr.value.integer = 7169;
305
 
306
 
307
                                                }else if(PACKETS_GENERATED == 10)//KEY DERIVATION DMA
308
                                                {
309
 
310
                                                        v_wr.value.integer = 6153;
311
 
312
 
313
                                                }else if(PACKETS_GENERATED == 12)//KEY DERIVATION DMA
314
                                                {
315
 
316
                                                        v_wr.value.integer = 7177;
317
 
318
 
319
                                                }else if(PACKETS_GENERATED == 13)//DECRYPTION_DMA
320
                                                {
321
 
322
                                                        v_wr.value.integer = 6161;
323
 
324
 
325
                                                }else if(PACKETS_GENERATED == 14)//DECRYPTION_DMA
326
                                                {
327
 
328
                                                        v_wr.value.integer = 7185;
329
 
330
 
331
                                                }else if(PACKETS_GENERATED == 15)//DEVIRATION_DECRYPTION_DMA
332
                                                {
333
 
334
                                                        v_wr.value.integer = 6169;
335
 
336
                                                }else if(PACKETS_GENERATED == 16)//DEVIRATION_DECRYPTION_DMA
337
                                                {
338
 
339
                                                        v_wr.value.integer = 7193;
340
 
341
                                                }
342
 
343
                                                vpi_put_value(PWDATA, &v_wr, NULL, vpiNoDelay);
344
 
345
                                        }if(counter_write > 9  &&  counter_write < 14) //WRITE DINR
346
                                        {
347
 
348
                                                v_wr.value.integer = ADDR_AES_DINR;
349
                                                vpi_put_value(PADDR, &v_wr, NULL, vpiNoDelay);
350
 
351
 
352
                                                if(FIPS_ENABLE == FIPS)
353
                                                {
354
 
355
                                                        if(counter_write == 10)
356
                                                        {
357
                                                                a = a | TEXT_FIPS_DERIVATED[0];
358
                                                                a = a << 8;
359
                                                                a = a | TEXT_FIPS_DERIVATED[1];
360
                                                                a = a << 8;
361
                                                                a = a | TEXT_FIPS_DERIVATED[2];
362
                                                                a = a << 8;
363
                                                                a = a | TEXT_FIPS_DERIVATED[3];
364
                                                                v_wr.value.integer = a;
365
 
366
                                                        }else if(counter_write == 11)
367
                                                        {
368
                                                                b = b | TEXT_FIPS_DERIVATED[4];
369
                                                                b = b << 8;
370
                                                                b = b | TEXT_FIPS_DERIVATED[5];
371
                                                                b = b << 8;
372
                                                                b = b | TEXT_FIPS_DERIVATED[6];
373
                                                                b = b << 8;
374
                                                                b = b | TEXT_FIPS_DERIVATED[7];
375
                                                                v_wr.value.integer = b;
376
 
377
                                                        }else if(counter_write == 12 )
378
                                                        {
379
 
380
                                                                c = c | TEXT_FIPS_DERIVATED[8];
381
                                                                c = c << 8;
382
                                                                c = c | TEXT_FIPS_DERIVATED[9];
383
                                                                c = c << 8;
384
                                                                c = c | TEXT_FIPS_DERIVATED[10];
385
                                                                c = c << 8;
386
                                                                c = c | TEXT_FIPS_DERIVATED[11];
387
                                                                v_wr.value.integer = c;
388
 
389
                                                        }else if(counter_write == 13 )
390
                                                        {
391
                                                                d = d | TEXT_FIPS_DERIVATED[12];
392
                                                                d = d << 8;
393
                                                                d = d | TEXT_FIPS_DERIVATED[13];
394
                                                                d = d << 8;
395
                                                                d = d | TEXT_FIPS_DERIVATED[14];
396
                                                                d = d << 8;
397
                                                                d = d | TEXT_FIPS_DERIVATED[15];
398
                                                                v_wr.value.integer = d;
399
 
400
                                                        }
401
 
402
 
403
                                                }else if(FIPS_ENABLE == RANDOM_DATA)
404
                                                {
405
                                                        v_wr.value.integer = data_in(rd);
406
                                                }
407
 
408
                                                vpi_put_value(PWDATA, &v_wr, &t_wr, vpiTransportDelay);
409
 
410
                                                a = 0;
411
                                                b = 0;
412
                                                c = 0;
413
                                                d = 0;
414
 
415
 
416
                                        }
417
 
418
                                        counter=0;
419
 
420
                                }//ELSE COUNTER
421
 
422
 
423
 
424
                                if(counter_write == 14)
425
                                {
426
                                        STATE =WAIT;
427
                                        counter_write = 0;
428
                                        counter_read  = 0;
429
 
430
                                        //v_wr.value.integer = 0;
431
                                        //vpi_put_value(PWRITE, &v_wr, NULL, vpiNoDelay);
432
 
433
 
434
                                }
435
 
436
 
437
                        break;
438
 
439
                        case WAIT:
440
 
441
 
442
                                v_wr.value.integer = 0;
443
                                vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
444
 
445
                                v_wr.value.integer = 0;
446
                                vpi_put_value(PWRITE, &v_wr, NULL, vpiNoDelay);
447
 
448
                                if(counter_wait == 9)
449
                                {
450
 
451
                                        STATE = WRITE_DINR;
452
                                        counter_wait=0;
453
 
454
                                        v_wr.value.integer = ADDR_AES_DINR;
455
                                        vpi_put_value(PADDR, &v_wr, NULL, vpiNoDelay);
456
 
457
                                        v_wr.value.integer = 0;
458
                                        vpi_put_value(PWRITE, &v_wr, NULL, vpiNoDelay);
459
 
460
 
461
                                }else
462
                                {
463
 
464
                                        counter_wait++;
465
 
466
                                }
467
                        break;
468
 
469
                        case WRITE_DINR:
470
 
471
                                v_wr.value.integer = 1;
472
                                vpi_put_value(PWRITE, &v_wr, NULL, vpiNoDelay);
473
 
474
                                if(counter == 0)
475
                                {
476
 
477
                                        counter++;
478
                                        counter_write++;
479
 
480
                                        v_wr.value.integer = 1;
481
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
482
 
483
 
484
                                }else if(counter == 1)
485
                                {
486
 
487
                                        v_wr.value.integer = 0;
488
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
489
 
490
                                        counter=0;
491
                                }
492
 
493
 
494
 
495
                                if(counter_write == 14)
496
                                {
497
                                        STATE = READ_RESULTS;
498
                                        counter_write = 0;
499
                                        counter_read  = 0;
500
 
501
                                        v_wr.value.integer = ADDR_AES_DINR;//vector_address[counter_read];
502
                                        vpi_put_value(PADDR, &v_wr, NULL, vpiNoDelay);
503
 
504
                                        v_wr.value.integer = 0;
505
                                        vpi_put_value(PWRITE, &v_wr, NULL, vpiNoDelay);
506
 
507
 
508
                                }
509
 
510
 
511
                        break;
512
 
513
                        case READ_RESULTS:
514
 
515
 
516
 
517
                                if(counter == 0)
518
                                {
519
 
520
                                        v_wr.value.integer = 1;
521
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
522
 
523
                                        counter_read++;
524
                                        counter++;
525
 
526
                                }else if(counter == 1)
527
                                {
528
                                        counter++;
529
 
530
 
531
                                        v_wr.value.integer = 0;
532
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
533
 
534
 
535
                                        v_wr.value.integer = ADDR_AES_SR;//vector_address[counter_read];
536
                                        vpi_put_value(PADDR, &v_wr, NULL, vpiNoDelay);
537
 
538
                                        v_wr.value.integer = 0;
539
                                        vpi_put_value(PWDATA, &v_wr, NULL, vpiNoDelay);
540
 
541
                                        v_wr.value.integer = 1;
542
                                        vpi_put_value(PSEL, &v_wr, NULL, vpiNoDelay);
543
 
544
                                        counter=0;
545
 
546
                                }
547
 
548
                                if(counter_read == 12)
549
                                {
550
                                        STATE = RESET_SR;
551
                                        counter_read = 0;
552
                                        PACKETS_GENERATED = PACKETS_GENERATED + 1;
553
 
554
                                        v_wr.value.integer = 0;
555
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
556
 
557
                                }
558
 
559
                        break;
560
 
561
                case RESET_SR:
562
 
563
                                v_wr.value.integer = 1;
564
                                vpi_put_value(PWRITE, &v_wr, NULL, vpiNoDelay);
565
 
566
                                v_wr.value.integer = 1;
567
                                vpi_put_value(PSEL, &v_wr, NULL, vpiNoDelay);
568
 
569
                                v_wr.value.integer = 0;
570
                                vpi_put_value(PADDR, &v_wr, NULL, vpiNoDelay);
571
 
572
                                v_wr.value.integer = 384;
573
                                vpi_put_value(PWDATA, &v_wr, NULL, vpiNoDelay);
574
 
575
 
576
                                if(counter == 0)
577
                                {
578
 
579
                                        counter_write++;
580
                                        counter++;
581
 
582
                                        v_wr.value.integer = 1;
583
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
584
 
585
                                }else if(counter == 1)
586
                                {
587
 
588
                                        v_wr.value.integer = 0;
589
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
590
                                        counter=0;
591
 
592
                                }
593
 
594
                                if(counter_write < 2)
595
                                {
596
                                        STATE =IDLE;
597
                                        counter_write = 0;
598
                                }
599
 
600
 
601
 
602
                break;
603
                }
604
 
605
 
606
 
607
        }
608
 
609
 
610
        return 0;
611
}

powered by: WebSVN 2.1.0

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