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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [pli/] [bfm_ctr/] [aes_bfm_decryption_dma_ctr.h] - Blame information for rev 15

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

powered by: WebSVN 2.1.0

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