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 5

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

powered by: WebSVN 2.1.0

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