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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [pli/] [bfm_ecb/] [aes_bfm_decryption_ccfie_ecb.h] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 redbear
//////////////////////////////////////////////////////////////////
2
////
3
////
4
////    AES CORE BLOCK
5
////
6
////
7
////
8
//// This file is part of the APB to AES128 project
9
////
10
//// http://www.opencores.org/cores/apbtoaes128/
11
////
12
////
13
////
14
//// Description
15
////
16
//// Implementation of APB IP core according to
17
////
18
//// aes128_spec IP core specification document.
19
////
20
////
21
////
22
//// To Do: Things are right here but always all block can suffer changes
23
////
24
////
25
////
26
////
27
////
28 5 redbear
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
29 4 redbear
////
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_ccfie_ecb_calltf(char*user_data)
76
{
77
 
78
        vpiHandle PRESETn = vpi_handle_by_name("AES_GLADIC_tb.PRESETn", NULL);
79
        vpiHandle PWDATA = vpi_handle_by_name("AES_GLADIC_tb.PWDATA", NULL);
80
        vpiHandle PENABLE = vpi_handle_by_name("AES_GLADIC_tb.PENABLE", NULL);
81
        vpiHandle PSEL = vpi_handle_by_name("AES_GLADIC_tb.PSEL", NULL);
82
        vpiHandle PWRITE = vpi_handle_by_name("AES_GLADIC_tb.PWRITE", NULL);
83
        vpiHandle PADDR = vpi_handle_by_name("AES_GLADIC_tb.PADDR", NULL);
84
        vpiHandle PRDATA = vpi_handle_by_name("AES_GLADIC_tb.PRDATA", NULL);
85
        vpiHandle PREADY = vpi_handle_by_name("AES_GLADIC_tb.PREADY", NULL);
86
        vpiHandle PSLVERR = vpi_handle_by_name("AES_GLADIC_tb.PSLVERR", NULL);
87
        vpiHandle int_ccf = vpi_handle_by_name("AES_GLADIC_tb.int_ccf", NULL);
88
        vpiHandle int_err = vpi_handle_by_name("AES_GLADIC_tb.int_err", NULL);
89
        vpiHandle dma_req_wr = vpi_handle_by_name("AES_GLADIC_tb.dma_req_wr", NULL);
90
        vpiHandle dma_req_rd = vpi_handle_by_name("AES_GLADIC_tb.dma_req_rd", NULL);
91
 
92
        std::random_device rd;
93
        std::uniform_int_distribution<long int> data_in(0,4294967295);
94
 
95
        v_ecb.format=vpiIntVal;
96
 
97
        vpi_get_value(PRESETn, &v_ecb);
98
 
99
 
100
        //printf("%i\n",STATE);
101
 
102
 
103
        if(type_bfm == ECB_DECRYPTION_CCFIE && v_ecb.value.integer == 1)
104
        {
105
 
106
                switch(STATE)
107
                {
108
 
109
                  case IDLE:
110
 
111
                                if(PACKETS_GENERATED >= MAX_ITERATIONS)
112
                                {
113
 
114
                                        STATE = IDLE;
115
                                        type_bfm = 0;
116
 
117
                                }else
118
                                {
119
                                        STATE = WRITE;
120
 
121
                                        counter = 0;
122
 
123
 
124
                                        v_ecb.value.integer = 0;
125
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
126
 
127
                                        v_ecb.value.integer = vector_address[0];
128
                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
129
 
130
                                        v_ecb.value.integer = 0;
131
                                        vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
132
 
133
                                        v_ecb.value.integer = 1;
134
                                        vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
135
 
136
                                        v_ecb.value.integer = 1;
137
                                        vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
138
                                }
139
 
140
                  break;
141
 
142
                  case WRITE:
143
                                if(counter == 0)
144
                                {
145
 
146
 
147
                                        counter_write++;
148
                                        counter++;
149
 
150
                                        v_ecb.value.integer = 1;
151
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
152
 
153
 
154
                                }else if(counter == 1)
155
                                {
156
 
157
                                        v_ecb.value.integer = 0;
158
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
159
 
160
 
161
 
162
                                        if(counter_write < 9)
163
                                        {
164
 
165
                                                v_ecb.value.integer = vector_address[counter_write];
166
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
167
 
168
                                                t_ecb.type = vpiScaledRealTime;
169
                                                t_ecb.real = 0;
170
                                                v_ecb.format=vpiIntVal;
171
                                                if(FIPS_ENABLE == FIPS)
172
                                                {
173
 
174
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR3 || vector_address[counter_write] == ADDR_AES_IVR3)
175
                                                        {
176
                                                                a = a | KEY_FIPS_DERIVATED[0];
177
                                                                a = a << 8;
178
                                                                a = a | KEY_FIPS_DERIVATED[1];
179
                                                                a = a << 8;
180
                                                                a = a | KEY_FIPS_DERIVATED[2];
181
                                                                a = a << 8;
182
                                                                a = a | KEY_FIPS_DERIVATED[3];
183
                                                                v_ecb.value.integer = a;
184
                                                        }
185
 
186
 
187
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR2 || vector_address[counter_write] == ADDR_AES_IVR2)
188
                                                        {
189
                                                                b = b | KEY_FIPS_DERIVATED[4];
190
                                                                b = b << 8;
191
                                                                b = b | KEY_FIPS_DERIVATED[5];
192
                                                                b = b << 8;
193
                                                                b = b | KEY_FIPS_DERIVATED[6];
194
                                                                b = b << 8;
195
                                                                b = b | KEY_FIPS_DERIVATED[7];
196
                                                                v_ecb.value.integer = b;
197
                                                        }
198
 
199
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR1 || vector_address[counter_write] == ADDR_AES_IVR1)
200
                                                        {
201
 
202
                                                                c = c | KEY_FIPS_DERIVATED[8];
203
                                                                c = c << 8;
204
                                                                c = c | KEY_FIPS_DERIVATED[9];
205
                                                                c = c << 8;
206
                                                                c = c | KEY_FIPS_DERIVATED[10];
207
                                                                c = c << 8;
208
                                                                c = c | KEY_FIPS_DERIVATED[11];
209
                                                                v_ecb.value.integer = c;
210
 
211
                                                        }
212
 
213
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR0 || vector_address[counter_write] == ADDR_AES_IVR0)
214
                                                        {
215
                                                                d = d | KEY_FIPS_DERIVATED[12];
216
                                                                d = d << 8;
217
                                                                d = d | KEY_FIPS_DERIVATED[13];
218
                                                                d = d << 8;
219
                                                                d = d | KEY_FIPS_DERIVATED[14];
220
                                                                d = d << 8;
221
                                                                d = d | KEY_FIPS_DERIVATED[15];
222
                                                                v_ecb.value.integer = d;
223
                                                        }
224
 
225
 
226
 
227
                                                }else if(FIPS_ENABLE == RANDOM_DATA)
228
                                                {
229
                                                        v_ecb.value.integer = data_in(rd);
230
                                                }
231
 
232
                                                //vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);                                              
233
                                                vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
234
 
235
 
236
                                                a = 0;
237
                                                b = 0;
238
                                                c = 0;
239
                                                d = 0;
240
                                        }
241
 
242
 
243
                                        if(counter_write == 9)
244
                                        {
245
 
246 12 redbear
                                                if(DATATYPE == TYPE_00)// NO DINR DOUTR SWAP DATA
247
                                                {
248
                                                        v_ecb.value.integer = ADDR_AES_CR;
249
                                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
250 4 redbear
 
251 12 redbear
                                                        v_ecb.value.integer = 529;
252
                                                        vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
253
 
254
                                                }else if(DATATYPE == TYPE_01)// 16 BIT DINR DOUTR SWAP DATA
255
                                                {
256
                                                        v_ecb.value.integer = ADDR_AES_CR;
257
                                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
258
 
259
                                                        v_ecb.value.integer = 531;
260
                                                        vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
261
 
262
                                                }else if(DATATYPE == TYPE_02)// 8 BIT DINR DOUTR SWAP DATA
263
                                                {
264
                                                        v_ecb.value.integer = ADDR_AES_CR;
265
                                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
266
 
267
                                                        v_ecb.value.integer = 533;
268
                                                        vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
269
 
270
                                                }else if(DATATYPE == TYPE_03)// BIT DINR DOUTR SWAP DATA
271
                                                {
272
                                                        v_ecb.value.integer = ADDR_AES_CR;
273
                                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
274
 
275
                                                        v_ecb.value.integer = 535;
276
                                                        vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
277
                                                }
278 4 redbear
 
279
                                        }
280
 
281
 
282
                                        if(counter_write > 9  &&  counter_write < 14) //WRITE DINR
283
                                        {
284
 
285
                                                v_ecb.value.integer = ADDR_AES_DINR;
286
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
287
 
288
 
289
                                                if(FIPS_ENABLE == FIPS)
290
                                                {
291
 
292 12 redbear
                                                        if(DATATYPE == TYPE_00)
293 4 redbear
                                                        {
294
 
295 12 redbear
                                                                if(counter_write == 10)
296
                                                                {
297
                                                                        a = a | TEXT_FIPS_DERIVATED[0];
298
                                                                        a = a << 8;
299
                                                                        a = a | TEXT_FIPS_DERIVATED[1];
300
                                                                        a = a << 8;
301
                                                                        a = a | TEXT_FIPS_DERIVATED[2];
302
                                                                        a = a << 8;
303
                                                                        a = a | TEXT_FIPS_DERIVATED[3];
304
                                                                        v_ecb.value.integer = a;
305
 
306
                                                                }else if(counter_write == 11)
307
                                                                {
308
                                                                        b = b | TEXT_FIPS_DERIVATED[4];
309
                                                                        b = b << 8;
310
                                                                        b = b | TEXT_FIPS_DERIVATED[5];
311
                                                                        b = b << 8;
312
                                                                        b = b | TEXT_FIPS_DERIVATED[6];
313
                                                                        b = b << 8;
314
                                                                        b = b | TEXT_FIPS_DERIVATED[7];
315
                                                                        v_ecb.value.integer = b;
316
 
317
                                                                }else if(counter_write == 12 )
318
                                                                {
319
 
320
                                                                        c = c | TEXT_FIPS_DERIVATED[8];
321
                                                                        c = c << 8;
322
                                                                        c = c | TEXT_FIPS_DERIVATED[9];
323
                                                                        c = c << 8;
324
                                                                        c = c | TEXT_FIPS_DERIVATED[10];
325
                                                                        c = c << 8;
326
                                                                        c = c | TEXT_FIPS_DERIVATED[11];
327
                                                                        v_ecb.value.integer = c;
328
 
329
                                                                }else if(counter_write == 13 )
330
                                                                {
331
                                                                        d = d | TEXT_FIPS_DERIVATED[12];
332
                                                                        d = d << 8;
333
                                                                        d = d | TEXT_FIPS_DERIVATED[13];
334
                                                                        d = d << 8;
335
                                                                        d = d | TEXT_FIPS_DERIVATED[14];
336
                                                                        d = d << 8;
337
                                                                        d = d | TEXT_FIPS_DERIVATED[15];
338
                                                                        v_ecb.value.integer = d;
339
 
340
                                                                }
341
 
342
                                                        }else if(DATATYPE == TYPE_01)
343 4 redbear
                                                        {
344
 
345 12 redbear
 
346
                                                                if(counter_write == 10)
347
                                                                {
348
                                                                        a = a | TEXT_FIPS_DATATYPE_T01_DERIVATED[0];
349
                                                                        a = a << 8;
350
                                                                        a = a | TEXT_FIPS_DATATYPE_T01_DERIVATED[1];
351
                                                                        a = a << 8;
352
                                                                        a = a | TEXT_FIPS_DATATYPE_T01_DERIVATED[2];
353
                                                                        a = a << 8;
354
                                                                        a = a | TEXT_FIPS_DATATYPE_T01_DERIVATED[3];
355
                                                                        v_ecb.value.integer = a;
356
 
357
                                                                }else if(counter_write == 11)
358
                                                                {
359
                                                                        b = b | TEXT_FIPS_DATATYPE_T01_DERIVATED[4];
360
                                                                        b = b << 8;
361
                                                                        b = b | TEXT_FIPS_DATATYPE_T01_DERIVATED[5];
362
                                                                        b = b << 8;
363
                                                                        b = b | TEXT_FIPS_DATATYPE_T01_DERIVATED[6];
364
                                                                        b = b << 8;
365
                                                                        b = b | TEXT_FIPS_DATATYPE_T01_DERIVATED[7];
366
                                                                        v_ecb.value.integer = b;
367
 
368
                                                                }else if(counter_write == 12 )
369
                                                                {
370
 
371
                                                                        c = c | TEXT_FIPS_DATATYPE_T01_DERIVATED[8];
372
                                                                        c = c << 8;
373
                                                                        c = c | TEXT_FIPS_DATATYPE_T01_DERIVATED[9];
374
                                                                        c = c << 8;
375
                                                                        c = c | TEXT_FIPS_DATATYPE_T01_DERIVATED[10];
376
                                                                        c = c << 8;
377
                                                                        c = c | TEXT_FIPS_DATATYPE_T01_DERIVATED[11];
378
                                                                        v_ecb.value.integer = c;
379
 
380
                                                                }else if(counter_write == 13 )
381
                                                                {
382
                                                                        d = d | TEXT_FIPS_DATATYPE_T01_DERIVATED[12];
383
                                                                        d = d << 8;
384
                                                                        d = d | TEXT_FIPS_DATATYPE_T01_DERIVATED[13];
385
                                                                        d = d << 8;
386
                                                                        d = d | TEXT_FIPS_DATATYPE_T01_DERIVATED[14];
387
                                                                        d = d << 8;
388
                                                                        d = d | TEXT_FIPS_DATATYPE_T01_DERIVATED[15];
389
                                                                        v_ecb.value.integer = d;
390
 
391
                                                                }
392
 
393
                                                        }else if(DATATYPE == TYPE_02)
394 4 redbear
                                                        {
395 12 redbear
                                                                if(counter_write == 10)
396
                                                                {
397
                                                                        a = a | TEXT_FIPS_DATATYPE_T02_DERIVATED[0];
398
                                                                        a = a << 8;
399
                                                                        a = a | TEXT_FIPS_DATATYPE_T02_DERIVATED[1];
400
                                                                        a = a << 8;
401
                                                                        a = a | TEXT_FIPS_DATATYPE_T02_DERIVATED[2];
402
                                                                        a = a << 8;
403
                                                                        a = a | TEXT_FIPS_DATATYPE_T02_DERIVATED[3];
404
                                                                        v_ecb.value.integer = a;
405 4 redbear
 
406 12 redbear
                                                                }else if(counter_write == 11)
407
                                                                {
408
                                                                        b = b | TEXT_FIPS_DATATYPE_T02_DERIVATED[4];
409
                                                                        b = b << 8;
410
                                                                        b = b | TEXT_FIPS_DATATYPE_T02_DERIVATED[5];
411
                                                                        b = b << 8;
412
                                                                        b = b | TEXT_FIPS_DATATYPE_T02_DERIVATED[6];
413
                                                                        b = b << 8;
414
                                                                        b = b | TEXT_FIPS_DATATYPE_T02_DERIVATED[7];
415
                                                                        v_ecb.value.integer = b;
416 4 redbear
 
417 12 redbear
                                                                }else if(counter_write == 12 )
418
                                                                {
419
 
420
                                                                        c = c | TEXT_FIPS_DATATYPE_T02_DERIVATED[8];
421
                                                                        c = c << 8;
422
                                                                        c = c | TEXT_FIPS_DATATYPE_T02_DERIVATED[9];
423
                                                                        c = c << 8;
424
                                                                        c = c | TEXT_FIPS_DATATYPE_T02_DERIVATED[10];
425
                                                                        c = c << 8;
426
                                                                        c = c | TEXT_FIPS_DATATYPE_T02_DERIVATED[11];
427
                                                                        v_ecb.value.integer = c;
428
 
429
                                                                }else if(counter_write == 13 )
430
                                                                {
431
                                                                        d = d | TEXT_FIPS_DATATYPE_T02_DERIVATED[12];
432
                                                                        d = d << 8;
433
                                                                        d = d | TEXT_FIPS_DATATYPE_T02_DERIVATED[13];
434
                                                                        d = d << 8;
435
                                                                        d = d | TEXT_FIPS_DATATYPE_T02_DERIVATED[14];
436
                                                                        d = d << 8;
437
                                                                        d = d | TEXT_FIPS_DATATYPE_T02_DERIVATED[15];
438
                                                                        v_ecb.value.integer = d;
439
 
440
                                                                }
441
 
442
 
443
 
444
                                                        }else if(DATATYPE == TYPE_03)
445 4 redbear
                                                        {
446 12 redbear
                                                                if(counter_write == 10)
447
                                                                {
448
                                                                        a = a | TEXT_FIPS_DATATYPE_T03_DERIVATED[0];
449
                                                                        a = a << 8;
450
                                                                        a = a | TEXT_FIPS_DATATYPE_T03_DERIVATED[1];
451
                                                                        a = a << 8;
452
                                                                        a = a | TEXT_FIPS_DATATYPE_T03_DERIVATED[2];
453
                                                                        a = a << 8;
454
                                                                        a = a | TEXT_FIPS_DATATYPE_T03_DERIVATED[3];
455
                                                                        v_ecb.value.integer = a;
456 4 redbear
 
457 12 redbear
                                                                }else if(counter_write == 11)
458
                                                                {
459
                                                                        b = b | TEXT_FIPS_DATATYPE_T03_DERIVATED[4];
460
                                                                        b = b << 8;
461
                                                                        b = b | TEXT_FIPS_DATATYPE_T03_DERIVATED[5];
462
                                                                        b = b << 8;
463
                                                                        b = b | TEXT_FIPS_DATATYPE_T03_DERIVATED[6];
464
                                                                        b = b << 8;
465
                                                                        b = b | TEXT_FIPS_DATATYPE_T03_DERIVATED[7];
466
                                                                        v_ecb.value.integer = b;
467
 
468
                                                                }else if(counter_write == 12 )
469
                                                                {
470
 
471
                                                                        c = c | TEXT_FIPS_DATATYPE_T03_DERIVATED[8];
472
                                                                        c = c << 8;
473
                                                                        c = c | TEXT_FIPS_DATATYPE_T03_DERIVATED[9];
474
                                                                        c = c << 8;
475
                                                                        c = c | TEXT_FIPS_DATATYPE_T03_DERIVATED[10];
476
                                                                        c = c << 8;
477
                                                                        c = c | TEXT_FIPS_DATATYPE_T03_DERIVATED[11];
478
                                                                        v_ecb.value.integer = c;
479
 
480
                                                                }else if(counter_write == 13 )
481
                                                                {
482
                                                                        d = d | TEXT_FIPS_DATATYPE_T03_DERIVATED[12];
483
                                                                        d = d << 8;
484
                                                                        d = d | TEXT_FIPS_DATATYPE_T03_DERIVATED[13];
485
                                                                        d = d << 8;
486
                                                                        d = d | TEXT_FIPS_DATATYPE_T03_DERIVATED[14];
487
                                                                        d = d << 8;
488
                                                                        d = d | TEXT_FIPS_DATATYPE_T03_DERIVATED[15];
489
                                                                        v_ecb.value.integer = d;
490
 
491
                                                                }
492
 
493
 
494
 
495 4 redbear
                                                        }
496
 
497
 
498
                                                }else if(FIPS_ENABLE == RANDOM_DATA)
499
                                                {
500
                                                        v_ecb.value.integer = data_in(rd);
501
                                                }
502
 
503
                                                //vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
504
                                                vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
505
 
506
                                                a = 0;
507
                                                b = 0;
508
                                                c = 0;
509
                                                d = 0;
510
 
511
 
512
                                        }
513
 
514
                                        v_ecb.value.integer = 1;
515
                                        vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
516
 
517
                                        counter=0;
518
                                }
519
 
520
                                if(counter_write == 14)
521
                                {
522
                                        counter_write = 0;
523
 
524
                                        STATE =WAIT_SR;
525
                                }
526
 
527
                  break;
528
 
529
                  case WAIT_SR:
530
 
531
                                v_ecb.value.integer = ADDR_AES_SR;
532
                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
533
 
534
                                v_ecb.value.integer = 0;
535
                                vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
536
 
537 9 redbear
                                v_ecb.value.integer = 0;
538
                                vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
539
 
540
                                /*
541 4 redbear
                                if(counter == 0)
542
                                {
543
 
544
                                        counter++;
545
 
546
                                        v_ecb.value.integer = 1;
547
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
548
 
549
 
550
                                }else if(counter == 1)
551
                                {
552
                                        v_ecb.value.integer = 0;
553
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
554
 
555
                                        counter=0;
556
                                }
557 9 redbear
                                */
558 4 redbear
                                v_ecb.value.integer = 0;
559 9 redbear
                                vpi_get_value(int_ccf,&v_ecb);
560 4 redbear
 
561
                                if(v_ecb.value.integer == 1)
562
                                {
563
                                        STATE = READ_DOUTR;
564 9 redbear
                                        counter=1;
565 4 redbear
                                }
566
 
567
 
568
                  break;
569
 
570
 
571
                 case READ_DOUTR:
572
 
573
 
574
 
575
                                if(counter == 0)
576
                                {
577
 
578
                                        v_ecb.value.integer = 1;
579
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
580
 
581 5 redbear
                                        counter_read++;
582 4 redbear
                                        counter++;
583
 
584
 
585
 
586
                                }else if(counter == 1)
587
                                {
588
                                        v_ecb.value.integer = 0;
589
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
590
 
591 5 redbear
 
592
                                        if(counter_read < 4)
593
                                        {
594
 
595
                                                v_ecb.value.integer = ADDR_AES_DOUTR;
596
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
597
 
598
                                        }
599
 
600
 
601
                                        if(counter_read == 4)
602
                                        {
603
 
604
                                                v_ecb.value.integer = ADDR_AES_KEYR3;
605
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
606
 
607
                                        }
608
 
609
 
610
                                        if(counter_read == 5)
611
                                        {
612
 
613
                                                v_ecb.value.integer = ADDR_AES_KEYR2;
614
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
615
 
616
                                        }
617
 
618
 
619
 
620
                                        if(counter_read == 6)
621
                                        {
622
 
623
                                                v_ecb.value.integer = ADDR_AES_KEYR1;
624
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
625
 
626
                                        }
627
 
628
 
629
                                        if(counter_read == 7)
630
                                        {
631
 
632
                                                v_ecb.value.integer = ADDR_AES_KEYR0;
633
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
634
 
635
                                        }
636
 
637
 
638
                                        if(counter_read == 8)
639
                                        {
640
 
641
                                                v_ecb.value.integer = ADDR_AES_IVR3;
642
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
643
 
644
                                        }
645
 
646
 
647
                                        if(counter_read == 9)
648
                                        {
649
 
650
                                                v_ecb.value.integer = ADDR_AES_IVR2;
651
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
652
 
653
                                        }
654
 
655
 
656
 
657
                                        if(counter_read == 10)
658
                                        {
659
 
660
                                                v_ecb.value.integer = ADDR_AES_IVR1;
661
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
662
 
663
                                        }
664
 
665
 
666
                                        if(counter_read == 11)
667
                                        {
668
 
669
                                                v_ecb.value.integer = ADDR_AES_IVR0;
670
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
671
 
672
                                        }
673
 
674
 
675 4 redbear
                                        counter = 0;
676
                                }
677
 
678 5 redbear
                                if(counter_read == 12)
679 4 redbear
                                {
680
                                        STATE = RESET_SR;
681 5 redbear
                                        counter_read = 0;
682 4 redbear
                                }
683
 
684
                 break;
685
 
686
                case RESET_SR:
687
 
688
                                v_ecb.value.integer = 1;
689
                                vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
690
 
691
                                v_ecb.value.integer = 1;
692
                                vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
693
 
694
                                v_ecb.value.integer = 0;
695
                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
696
 
697
                                v_ecb.value.integer = 128;
698
                                vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
699
 
700
 
701
                                if(counter == 0)
702
                                {
703
 
704
                                        counter_write++;
705
                                        counter++;
706
 
707
                                        v_ecb.value.integer = 1;
708
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
709
 
710
                                }else if(counter == 1)
711
                                {
712
 
713
                                        v_ecb.value.integer = 0;
714
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
715
                                        counter=0;
716
 
717
                                }
718
 
719
                                if(counter_write == 1)
720
                                {
721
                                        STATE =IDLE;
722
                                        counter_write = 0;
723
                                        counter=0;
724
                                        PACKETS_GENERATED = PACKETS_GENERATED + 1;
725
                                }
726
 
727
 
728
 
729
                break;
730
 
731
                }
732
 
733
        }
734
 
735
        return 0;
736
}

powered by: WebSVN 2.1.0

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