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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [pli/] [bfm_error/] [aes_bfm_wr_error_doutr.h] - 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
static int aes_bfm_wr_error_doutr_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_DOUTR_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
 
431
 
432
 
433
                                }
434
 
435
 
436
                        break;
437
 
438
                        case WAIT:
439
 
440
 
441
                                v_wr.value.integer = 0;
442
                                vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
443
 
444
                                v_wr.value.integer = 0;
445
                                vpi_put_value(PWRITE, &v_wr, NULL, vpiNoDelay);
446
 
447
                                if(counter_wait == 9)
448
                                {
449
 
450
                                        STATE = READ_DOUTR;
451
                                        counter_wait=0;
452
 
453
                                        v_wr.value.integer = ADDR_AES_DOUTR;
454
                                        vpi_put_value(PADDR, &v_wr, NULL, vpiNoDelay);
455
 
456
                                        v_wr.value.integer = 0;
457
                                        vpi_put_value(PWRITE, &v_wr, NULL, vpiNoDelay);
458
 
459
 
460
                                }else
461
                                {
462
 
463
                                        counter_wait++;
464
 
465
                                }
466
                        break;
467
 
468
                        case READ_DOUTR:
469
 
470
                                v_wr.value.integer = 0;
471
                                vpi_put_value(PWRITE, &v_wr, NULL, vpiNoDelay);
472
 
473
                                if(counter == 0)
474
                                {
475
 
476
                                        counter++;
477
                                        counter_write++;
478
 
479
                                        v_wr.value.integer = 1;
480
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
481
 
482
 
483
                                }else if(counter == 1)
484
                                {
485
 
486
                                        v_wr.value.integer = 0;
487
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
488
 
489
                                        counter=0;
490
                                }
491
 
492
 
493
 
494
                                if(counter_write == 14)
495
                                {
496
                                        STATE = READ_RESULTS;
497
                                        counter_write = 0;
498
                                        counter_read  = 0;
499
 
500
                                        v_wr.value.integer = ADDR_AES_DINR;//vector_address[counter_read];
501
                                        vpi_put_value(PADDR, &v_wr, NULL, vpiNoDelay);
502
 
503
                                        v_wr.value.integer = 0;
504
                                        vpi_put_value(PWRITE, &v_wr, NULL, vpiNoDelay);
505
 
506
 
507
                                }
508
 
509
 
510
                        break;
511
 
512
                        case READ_RESULTS:
513
 
514
 
515
 
516
                                if(counter == 0)
517
                                {
518
 
519
                                        v_wr.value.integer = 1;
520
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
521
 
522
                                        counter_read++;
523
                                        counter++;
524
 
525
                                }else if(counter == 1)
526
                                {
527
                                        counter++;
528
 
529
 
530
                                        v_wr.value.integer = 0;
531
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
532
 
533
 
534
                                        v_wr.value.integer = ADDR_AES_SR;//vector_address[counter_read];
535
                                        vpi_put_value(PADDR, &v_wr, NULL, vpiNoDelay);
536
 
537
                                        v_wr.value.integer = 0;
538
                                        vpi_put_value(PWDATA, &v_wr, NULL, vpiNoDelay);
539
 
540
                                        v_wr.value.integer = 1;
541
                                        vpi_put_value(PSEL, &v_wr, NULL, vpiNoDelay);
542
 
543
                                        counter=0;
544
 
545
                                }
546
 
547
                                if(counter_read == 1)
548
                                {
549
                                        STATE = IDLE;
550
                                        counter_read = 0;
551
                                        PACKETS_GENERATED = PACKETS_GENERATED + 1;
552
 
553
                                        v_wr.value.integer = 0;
554
                                        vpi_put_value(PENABLE, &v_wr, NULL, vpiNoDelay);
555
 
556
                                }
557
 
558
                        break;
559
                }
560
 
561
 
562
 
563
        }
564
 
565
 
566
        return 0;
567
}

powered by: WebSVN 2.1.0

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