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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [pli/] [bfm_cbc/] [aes_bfm_decryption_dma_cbc.h] - Blame information for rev 16

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 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_cbc_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 == CBC_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)
175 9 redbear
                                                        {
176
                                                                a = a | KEY_FIPS_CBC_DERIVATED[0];
177
                                                                a = a << 8;
178
                                                                a = a | KEY_FIPS_CBC_DERIVATED[1];
179
                                                                a = a << 8;
180
                                                                a = a | KEY_FIPS_CBC_DERIVATED[2];
181
                                                                a = a << 8;
182
                                                                a = a | KEY_FIPS_CBC_DERIVATED[3];
183
                                                                v_ecb.value.integer = a;
184
                                                        }
185 5 redbear
 
186
 
187 9 redbear
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR2)
188
                                                        {
189
                                                                b = b | KEY_FIPS_CBC_DERIVATED[4];
190
                                                                b = b << 8;
191
                                                                b = b | KEY_FIPS_CBC_DERIVATED[5];
192
                                                                b = b << 8;
193
                                                                b = b | KEY_FIPS_CBC_DERIVATED[6];
194
                                                                b = b << 8;
195
                                                                b = b | KEY_FIPS_CBC_DERIVATED[7];
196
                                                                v_ecb.value.integer = b;
197
                                                        }
198 5 redbear
 
199 9 redbear
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR1)
200
                                                        {
201 5 redbear
 
202 9 redbear
                                                                c = c | KEY_FIPS_CBC_DERIVATED[8];
203
                                                                c = c << 8;
204
                                                                c = c | KEY_FIPS_CBC_DERIVATED[9];
205
                                                                c = c << 8;
206
                                                                c = c | KEY_FIPS_CBC_DERIVATED[10];
207
                                                                c = c << 8;
208
                                                                c = c | KEY_FIPS_CBC_DERIVATED[11];
209
                                                                v_ecb.value.integer = c;
210 5 redbear
 
211 9 redbear
                                                        }
212 5 redbear
 
213 9 redbear
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR0)
214
                                                        {
215
                                                                d = d | KEY_FIPS_CBC_DERIVATED[12];
216
                                                                d = d << 8;
217
                                                                d = d | KEY_FIPS_CBC_DERIVATED[13];
218
                                                                d = d << 8;
219
                                                                d = d | KEY_FIPS_CBC_DERIVATED[14];
220
                                                                d = d << 8;
221
                                                                d = d | KEY_FIPS_CBC_DERIVATED[15];
222
                                                                v_ecb.value.integer = d;
223
                                                        }
224 5 redbear
 
225
 
226 9 redbear
                                                        if(vector_address[counter_write] == ADDR_AES_IVR3)
227
                                                        {
228
                                                                a = a | IV_FIPS_CBC_NOT_DERIVATED[0];
229
                                                                a = a << 8;
230
                                                                a = a | IV_FIPS_CBC_NOT_DERIVATED[1];
231
                                                                a = a << 8;
232
                                                                a = a | IV_FIPS_CBC_NOT_DERIVATED[2];
233
                                                                a = a << 8;
234
                                                                a = a | IV_FIPS_CBC_NOT_DERIVATED[3];
235
                                                                v_ecb.value.integer = a;
236
                                                        }
237 5 redbear
 
238
 
239 9 redbear
                                                        if(vector_address[counter_write] == ADDR_AES_IVR2)
240
                                                        {
241
                                                                b = b | IV_FIPS_CBC_NOT_DERIVATED[4];
242
                                                                b = b << 8;
243
                                                                b = b | IV_FIPS_CBC_NOT_DERIVATED[5];
244
                                                                b = b << 8;
245
                                                                b = b | IV_FIPS_CBC_NOT_DERIVATED[6];
246
                                                                b = b << 8;
247
                                                                b = b | IV_FIPS_CBC_NOT_DERIVATED[7];
248
                                                                v_ecb.value.integer = b;
249
                                                        }
250 5 redbear
 
251 9 redbear
                                                        if(vector_address[counter_write] == ADDR_AES_IVR1)
252
                                                        {
253 5 redbear
 
254 9 redbear
                                                                c = c | IV_FIPS_CBC_NOT_DERIVATED[8];
255
                                                                c = c << 8;
256
                                                                c = c | IV_FIPS_CBC_NOT_DERIVATED[9];
257
                                                                c = c << 8;
258
                                                                c = c | IV_FIPS_CBC_NOT_DERIVATED[10];
259
                                                                c = c << 8;
260
                                                                c = c | IV_FIPS_CBC_NOT_DERIVATED[11];
261
                                                                v_ecb.value.integer = c;
262
                                                        }
263 5 redbear
 
264 9 redbear
                                                        if(vector_address[counter_write] == ADDR_AES_IVR0)
265
                                                        {
266
                                                                d = d | IV_FIPS_CBC_NOT_DERIVATED[12];
267
                                                                d = d << 8;
268
                                                                d = d | IV_FIPS_CBC_NOT_DERIVATED[13];
269
                                                                d = d << 8;
270
                                                                d = d | IV_FIPS_CBC_NOT_DERIVATED[14];
271
                                                                d = d << 8;
272
                                                                d = d | IV_FIPS_CBC_NOT_DERIVATED[15];
273
                                                                v_ecb.value.integer = d;
274
                                                        }
275 5 redbear
 
276
 
277
 
278
 
279
                                                }else if(FIPS_ENABLE == RANDOM_DATA)
280
                                                {
281
                                                        v_ecb.value.integer = data_in(rd);
282
                                                }
283
 
284
                                                //vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);                                              
285
                                                vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
286
 
287
 
288
                                                a = 0;
289
                                                b = 0;
290
                                                c = 0;
291
                                                d = 0;
292
                                        }
293
 
294
 
295
                                        if(counter_write == 9)
296
                                        {
297
 
298 12 redbear
                                                if(DATATYPE == TYPE_00)// NO DINR DOUTR SWAP DATA
299
                                                {
300
                                                        v_ecb.value.integer = ADDR_AES_CR;
301
                                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
302 5 redbear
 
303 12 redbear
                                                        v_ecb.value.integer = 6193;
304
                                                        vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
305
 
306
                                                }else if(DATATYPE == TYPE_01)// 16 BIT DINR DOUTR SWAP DATA
307
                                                {
308
                                                        v_ecb.value.integer = ADDR_AES_CR;
309
                                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
310
 
311
                                                        v_ecb.value.integer = 6195;
312
                                                        vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
313
 
314
                                                }else if(DATATYPE == TYPE_02)// 8 BIT DINR DOUTR SWAP DATA
315
                                                {
316
                                                        v_ecb.value.integer = ADDR_AES_CR;
317
                                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
318
 
319
                                                        v_ecb.value.integer = 6197;
320
                                                        vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
321
 
322
                                                }else if(DATATYPE == TYPE_03)// BIT DINR DOUTR SWAP DATA
323
                                                {
324
                                                        v_ecb.value.integer = ADDR_AES_CR;
325
                                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
326
 
327
                                                        v_ecb.value.integer = 6199;
328
                                                        vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
329
                                                }
330 5 redbear
 
331
                                        }
332
 
333
 
334
                                        if(counter_write > 9  &&  counter_write < 14) //WRITE DINR
335
                                        {
336
 
337
                                                v_ecb.value.integer = ADDR_AES_DINR;
338
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
339
 
340
 
341
                                                if(FIPS_ENABLE == FIPS)
342
                                                {
343
 
344 12 redbear
                                                        if(DATATYPE == TYPE_00)
345 5 redbear
                                                        {
346
 
347 12 redbear
                                                                if(counter_write == 10)
348
                                                                {
349
                                                                        a = a | TEXT_CBC_FIPS_DERIVATED[0];
350
                                                                        a = a << 8;
351
                                                                        a = a | TEXT_CBC_FIPS_DERIVATED[1];
352
                                                                        a = a << 8;
353
                                                                        a = a | TEXT_CBC_FIPS_DERIVATED[2];
354
                                                                        a = a << 8;
355
                                                                        a = a | TEXT_CBC_FIPS_DERIVATED[3];
356
                                                                        v_ecb.value.integer = a;
357
 
358
                                                                }else if(counter_write == 11)
359
                                                                {
360
                                                                        b = b | TEXT_CBC_FIPS_DERIVATED[4];
361
                                                                        b = b << 8;
362
                                                                        b = b | TEXT_CBC_FIPS_DERIVATED[5];
363
                                                                        b = b << 8;
364
                                                                        b = b | TEXT_CBC_FIPS_DERIVATED[6];
365
                                                                        b = b << 8;
366
                                                                        b = b | TEXT_CBC_FIPS_DERIVATED[7];
367
                                                                        v_ecb.value.integer = b;
368
 
369
                                                                }else if(counter_write == 12 )
370
                                                                {
371
 
372
                                                                        c = c | TEXT_CBC_FIPS_DERIVATED[8];
373
                                                                        c = c << 8;
374
                                                                        c = c | TEXT_CBC_FIPS_DERIVATED[9];
375
                                                                        c = c << 8;
376
                                                                        c = c | TEXT_CBC_FIPS_DERIVATED[10];
377
                                                                        c = c << 8;
378
                                                                        c = c | TEXT_CBC_FIPS_DERIVATED[11];
379
                                                                        v_ecb.value.integer = c;
380
 
381
                                                                }else if(counter_write == 13 )
382
                                                                {
383
                                                                        d = d | TEXT_CBC_FIPS_DERIVATED[12];
384
                                                                        d = d << 8;
385
                                                                        d = d | TEXT_CBC_FIPS_DERIVATED[13];
386
                                                                        d = d << 8;
387
                                                                        d = d | TEXT_CBC_FIPS_DERIVATED[14];
388
                                                                        d = d << 8;
389
                                                                        d = d | TEXT_CBC_FIPS_DERIVATED[15];
390
                                                                        v_ecb.value.integer = d;
391
 
392
                                                                }
393
 
394
                                                        }else if(DATATYPE == TYPE_01)
395 5 redbear
                                                        {
396
 
397 12 redbear
 
398
                                                                if(counter_write == 10)
399
                                                                {
400
                                                                        a = a | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[0];
401
                                                                        a = a << 8;
402
                                                                        a = a | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[1];
403
                                                                        a = a << 8;
404
                                                                        a = a | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[2];
405
                                                                        a = a << 8;
406
                                                                        a = a | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[3];
407
                                                                        v_ecb.value.integer = a;
408
 
409
                                                                }else if(counter_write == 11)
410
                                                                {
411
                                                                        b = b | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[4];
412
                                                                        b = b << 8;
413
                                                                        b = b | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[5];
414
                                                                        b = b << 8;
415
                                                                        b = b | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[6];
416
                                                                        b = b << 8;
417
                                                                        b = b | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[7];
418
                                                                        v_ecb.value.integer = b;
419
 
420
                                                                }else if(counter_write == 12 )
421
                                                                {
422
 
423
                                                                        c = c | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[8];
424
                                                                        c = c << 8;
425
                                                                        c = c | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[9];
426
                                                                        c = c << 8;
427
                                                                        c = c | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[10];
428
                                                                        c = c << 8;
429
                                                                        c = c | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[11];
430
                                                                        v_ecb.value.integer = c;
431
 
432
                                                                }else if(counter_write == 13 )
433
                                                                {
434
                                                                        d = d | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[12];
435
                                                                        d = d << 8;
436
                                                                        d = d | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[13];
437
                                                                        d = d << 8;
438
                                                                        d = d | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[14];
439
                                                                        d = d << 8;
440
                                                                        d = d | TEXT_CBC_FIPS_DATATYPE_T01_DERIVATED[15];
441
                                                                        v_ecb.value.integer = d;
442
 
443
                                                                }
444
 
445
                                                        }else if(DATATYPE == TYPE_02)
446 5 redbear
                                                        {
447 12 redbear
                                                                if(counter_write == 10)
448
                                                                {
449
                                                                        a = a | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[0];
450
                                                                        a = a << 8;
451
                                                                        a = a | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[1];
452
                                                                        a = a << 8;
453
                                                                        a = a | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[2];
454
                                                                        a = a << 8;
455
                                                                        a = a | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[3];
456
                                                                        v_ecb.value.integer = a;
457 5 redbear
 
458 12 redbear
                                                                }else if(counter_write == 11)
459
                                                                {
460
                                                                        b = b | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[4];
461
                                                                        b = b << 8;
462
                                                                        b = b | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[5];
463
                                                                        b = b << 8;
464
                                                                        b = b | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[6];
465
                                                                        b = b << 8;
466
                                                                        b = b | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[7];
467
                                                                        v_ecb.value.integer = b;
468 5 redbear
 
469 12 redbear
                                                                }else if(counter_write == 12 )
470
                                                                {
471
 
472
                                                                        c = c | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[8];
473
                                                                        c = c << 8;
474
                                                                        c = c | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[9];
475
                                                                        c = c << 8;
476
                                                                        c = c | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[10];
477
                                                                        c = c << 8;
478
                                                                        c = c | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[11];
479
                                                                        v_ecb.value.integer = c;
480
 
481
                                                                }else if(counter_write == 13 )
482
                                                                {
483
                                                                        d = d | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[12];
484
                                                                        d = d << 8;
485
                                                                        d = d | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[13];
486
                                                                        d = d << 8;
487
                                                                        d = d | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[14];
488
                                                                        d = d << 8;
489
                                                                        d = d | TEXT_CBC_FIPS_DATATYPE_T02_DERIVATED[15];
490
                                                                        v_ecb.value.integer = d;
491
 
492
                                                                }
493
 
494
 
495
 
496
                                                        }else if(DATATYPE == TYPE_03)
497 5 redbear
                                                        {
498 12 redbear
                                                                if(counter_write == 10)
499
                                                                {
500
                                                                        a = a | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[0];
501
                                                                        a = a << 8;
502
                                                                        a = a | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[1];
503
                                                                        a = a << 8;
504
                                                                        a = a | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[2];
505
                                                                        a = a << 8;
506
                                                                        a = a | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[3];
507
                                                                        v_ecb.value.integer = a;
508 5 redbear
 
509 12 redbear
                                                                }else if(counter_write == 11)
510
                                                                {
511
                                                                        b = b | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[4];
512
                                                                        b = b << 8;
513
                                                                        b = b | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[5];
514
                                                                        b = b << 8;
515
                                                                        b = b | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[6];
516
                                                                        b = b << 8;
517
                                                                        b = b | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[7];
518
                                                                        v_ecb.value.integer = b;
519
 
520
                                                                }else if(counter_write == 12 )
521
                                                                {
522
 
523
                                                                        c = c | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[8];
524
                                                                        c = c << 8;
525
                                                                        c = c | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[9];
526
                                                                        c = c << 8;
527
                                                                        c = c | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[10];
528
                                                                        c = c << 8;
529
                                                                        c = c | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[11];
530
                                                                        v_ecb.value.integer = c;
531
 
532
                                                                }else if(counter_write == 13 )
533
                                                                {
534
                                                                        d = d | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[12];
535
                                                                        d = d << 8;
536
                                                                        d = d | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[13];
537
                                                                        d = d << 8;
538
                                                                        d = d | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[14];
539
                                                                        d = d << 8;
540
                                                                        d = d | TEXT_CBC_FIPS_DATATYPE_T03_DERIVATED[15];
541
                                                                        v_ecb.value.integer = d;
542
 
543
                                                                }
544
 
545
 
546
 
547 5 redbear
                                                        }
548
 
549
 
550
                                                }else if(FIPS_ENABLE == RANDOM_DATA)
551
                                                {
552
                                                        v_ecb.value.integer = data_in(rd);
553
                                                }
554
 
555
                                                //vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
556
                                                vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
557
 
558
                                                a = 0;
559
                                                b = 0;
560
                                                c = 0;
561
                                                d = 0;
562
 
563
 
564
                                        }
565
 
566
                                        v_ecb.value.integer = 1;
567
                                        vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
568
 
569
                                        counter=0;
570
                                }
571
 
572
                                if(counter_write == 14)
573
                                {
574
                                        counter_write = 0;
575
 
576
                                        STATE =WAIT_SR;
577
 
578
 
579
 
580
 
581
 
582
                                }
583
 
584
                  break;
585
 
586
                  case WAIT_SR:
587
 
588
                                v_ecb.value.integer = ADDR_AES_SR;
589
                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
590
 
591
                                v_ecb.value.integer = 0;
592
                                vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
593
 
594
                                if(counter == 0)
595
                                {
596
 
597
                                        counter++;
598
 
599
                                        v_ecb.value.integer = 1;
600
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
601
 
602 9 redbear
                                        v_ecb.value.integer = 0;
603
                                        vpi_get_value(PRDATA,&v_ecb);
604 5 redbear
 
605 9 redbear
                                        if(v_ecb.value.integer == 1)
606
                                        {
607
                                                STATE = READ_DOUTR;
608
 
609
                                                //t_ecb.type = vpiScaledRealTime;
610
                                                //t_ecb.real = 0;
611
                                                //v_ecb.format=vpiIntVal;
612
                                                //v_ecb.value.integer = ADDR_AES_DOUTR;
613
                                                //vpi_put_value(PADDR, &v_ecb, &t_ecb, vpiTransportDelay);
614
                                        }
615
 
616
 
617 5 redbear
                                }else if(counter == 1)
618
                                {
619
                                        v_ecb.value.integer = 0;
620
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
621
 
622
                                        counter=0;
623
                                }
624
 
625
 
626
 
627
 
628
                  break;
629
 
630
 
631
                 case READ_DOUTR:
632
 
633
 
634
 
635
                                if(counter == 0)
636
                                {
637
 
638
                                        v_ecb.value.integer = 1;
639
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
640
 
641
                                        counter_read++;
642
                                        counter++;
643
 
644
 
645
 
646
                                }else if(counter == 1)
647
                                {
648
                                        v_ecb.value.integer = 0;
649
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
650
 
651
 
652
                                        if(counter_read < 4)
653
                                        {
654
 
655
                                                v_ecb.value.integer = ADDR_AES_DOUTR;
656
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
657
 
658
                                        }
659
 
660
 
661
                                        if(counter_read == 4)
662
                                        {
663
 
664
                                                v_ecb.value.integer = ADDR_AES_KEYR3;
665
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
666
 
667
                                        }
668
 
669
 
670
                                        if(counter_read == 5)
671
                                        {
672
 
673
                                                v_ecb.value.integer = ADDR_AES_KEYR2;
674
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
675
 
676
                                        }
677
 
678
 
679
 
680
                                        if(counter_read == 6)
681
                                        {
682
 
683
                                                v_ecb.value.integer = ADDR_AES_KEYR1;
684
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
685
 
686
                                        }
687
 
688
 
689
                                        if(counter_read == 7)
690
                                        {
691
 
692
                                                v_ecb.value.integer = ADDR_AES_KEYR0;
693
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
694
 
695
                                        }
696
 
697
 
698
                                        if(counter_read == 8)
699
                                        {
700
 
701
                                                v_ecb.value.integer = ADDR_AES_IVR3;
702
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
703
 
704
                                        }
705
 
706
 
707
                                        if(counter_read == 9)
708
                                        {
709
 
710
                                                v_ecb.value.integer = ADDR_AES_IVR2;
711
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
712
 
713
                                        }
714
 
715
 
716
 
717
                                        if(counter_read == 10)
718
                                        {
719
 
720
                                                v_ecb.value.integer = ADDR_AES_IVR1;
721
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
722
 
723
                                        }
724
 
725
 
726
                                        if(counter_read == 11)
727
                                        {
728
 
729
                                                v_ecb.value.integer = ADDR_AES_IVR0;
730
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
731
 
732
                                        }
733
 
734
 
735
                                        counter = 0;
736
                                }
737
 
738
                                if(counter_read == 12)
739
                                {
740
                                        STATE = RESET_SR;
741
                                        counter_read = 0;
742
                                }
743
 
744
                 break;
745
 
746
                case RESET_SR:
747
 
748
                                v_ecb.value.integer = 1;
749
                                vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
750
 
751
                                v_ecb.value.integer = 1;
752
                                vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
753
 
754
                                v_ecb.value.integer = 0;
755
                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
756
 
757
                                v_ecb.value.integer = 128;
758
                                vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
759
 
760
 
761
                                if(counter == 0)
762
                                {
763
 
764
                                        counter_write++;
765
                                        counter++;
766
 
767
                                        v_ecb.value.integer = 1;
768
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
769
 
770
                                }else if(counter == 1)
771
                                {
772
 
773
                                        v_ecb.value.integer = 0;
774
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
775
                                        counter=0;
776
 
777
                                }
778
 
779
                                if(counter_write == 1)
780
                                {
781
                                        STATE =IDLE;
782
                                        counter_write = 0;
783
                                        counter=0;
784
                                        PACKETS_GENERATED = PACKETS_GENERATED + 1;
785
                                }
786
 
787
 
788
 
789
                break;
790
 
791
                }
792
 
793
        }
794
 
795
        return 0;
796
}

powered by: WebSVN 2.1.0

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