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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [pli/] [bfm_ecb/] [aes_bfm_encryption_dma_ecb.h] - Blame information for rev 11

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

powered by: WebSVN 2.1.0

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