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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [pli/] [bfm_ecb/] [aes_bfm_decryption_dma_ecb.h] - Blame information for rev 9

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

powered by: WebSVN 2.1.0

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