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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [testbench/] [tb_aes_ip.v] - Blame information for rev 6

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

Line No. Rev Author Line
1 3 redbear
//////////////////////////////////////////////////////////////////
2
////
3
////
4
////    AES TESTBENCH 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
////              Julio Cesar 
30
////
31
///////////////////////////////////////////////////////////////// 
32
////
33
////
34
//// Copyright (C) 2009 Authors and OPENCORES.ORG
35
////
36
////
37
////
38
//// This source file may be used and distributed without
39
////
40
//// restriction provided that this copyright statement is not
41
////
42
//// removed from the file and that any derivative work contains
43
//// the original copyright notice and the associated disclaimer.
44
////
45
////
46
//// This source file is free software; you can redistribute it
47
////
48
//// and/or modify it under the terms of the GNU Lesser General
49
////
50
//// Public License as published by the Free Software Foundation;
51
//// either version 2.1 of the License, or (at your option) any
52
////
53
//// later version.
54
////
55
////
56
////
57
//// This source is distributed in the hope that it will be
58
////
59
//// useful, but WITHOUT ANY WARRANTY; without even the implied
60
////
61
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
62
////
63
//// PURPOSE. See the GNU Lesser General Public License for more
64
//// details.
65
////
66
////
67
////
68
//// You should have received a copy of the GNU Lesser General
69
////
70
//// Public License along with this source; if not, download it
71
////
72
//// from http://www.opencores.org/lgpl.shtml
73
////
74
////
75
///////////////////////////////////////////////////////////////////
76 2 redbear
module tb_aes_ip();
77
 
78
localparam AES_CR    = 4'd00;
79
localparam AES_SR    = 4'd01;
80
localparam AES_DINR  = 4'd02;
81
localparam AES_DOUTR = 4'd03;
82
localparam AES_KEYR0 = 4'd04;
83
localparam AES_KEYR1 = 4'd05;
84
localparam AES_KEYR2 = 4'd06;
85
localparam AES_KEYR3 = 4'd07;
86
localparam AES_IVR0  = 4'd08;
87
localparam AES_IVR1  = 4'd09;
88
localparam AES_IVR2  = 4'd10;
89
localparam AES_IVR3  = 4'd11;
90
 
91
// Configuratin Bits
92
localparam DMAOUTEN    = 32'h00000001 << 12;
93
localparam DMAINEN     = 32'h00000001 << 11;
94
localparam ERRIE       = 32'h00000001 << 10;
95
localparam CCFIE       = 32'h00000001 << 9;
96
localparam ERRC        = 32'h00000001 << 8;
97
localparam CCFC        = 32'h00000001 << 7;
98
localparam EBC         = 32'h00000000;
99
localparam CBC         = 32'h00000001 << 5;
100
localparam CTR         = 32'h00000001 << 6;
101
localparam ENCRYPTION  = 32'h00000000;
102
localparam KEY_DERIV   = 32'h00000001 << 3;
103
localparam DECRYPTION  = 32'h00000001 << 4;
104
localparam KEY_DECRYP  = KEY_DERIV | DECRYPTION;
105
localparam ENABLE      = 32'h00000001;
106
localparam DISABLE     = 32'h00000000;
107
 
108
wire int_ccf, int_err;
109
wire dma_req_wr, dma_req_rd;
110
wire [31:0] PRDATA;
111
 
112
reg [31:0] PWDATA;
113
reg [3:0] PADDR;
114
reg PCLK, PRESETn;
115
reg PSEL, PENABLE, PWRITE;
116
 
117
reg [31:0] data_rd;
118
 
119
reg [127:0] data_in;
120
reg [127:0] key_in;
121
reg [127:0] iv_in;
122
reg [127:0] result;
123
reg [127:0] golden;
124
reg [127:0] result_rd;
125
reg [127:0] iv_rd;
126
reg [127:0] key_rd;
127
reg error_chk;
128
 
129
aes_ip AES_IP
130
(
131
        .int_ccf    ( int_ccf    ),
132
        .int_err    ( int_err    ),
133
        .dma_req_wr ( dma_req_wr ),
134
        .dma_req_rd ( dma_req_rd ),
135
        .PRDATA     ( PRDATA     ),
136
        .PREADY     ( PREADY     ),
137
  .PSLVERR    ( PSLVERR    ),
138
  .PWDATA     ( PWDATA     ),
139
  .PADDR      ( PADDR      ),
140
  .PSEL       ( PSEL       ),
141
  .PENABLE    ( PENABLE    ),
142
  .PWRITE     ( PWRITE     ),
143
  .PCLK       ( PCLK       ),
144
  .PRESETn    ( PRESETn    )
145
);
146
initial
147
 begin
148
    $dumpfile("tb_aes_ip.vcd");
149
    $dumpvars(0,tb_aes_ip);
150
 end
151
task reset;
152
        begin
153
                PCLK = 0;
154
                PSEL = 0;
155
                PENABLE = 0;
156
                PWDATA = 0;
157
                PWRITE = 0;
158
                PADDR = 0;
159
                PRESETn = 0;
160
                @(posedge PCLK);
161
                PRESETn = 1;
162
        end
163
endtask
164
 
165
task apb_write;
166
        input [31:0] addr;
167
        input [31:0] data_in;
168
        begin
169
                PSEL <= 1;
170
                PWRITE <= 1;
171
                PENABLE <= 0;
172
                PADDR <= addr;
173
                PWDATA <= data_in;
174
                @(posedge PCLK);
175
                PENABLE <= 1;
176
                @(posedge PCLK);
177
                PSEL <= 0;
178
                PENABLE <= 0;
179
        end
180
endtask
181
 
182
task apb_read;
183
        input  [31:0] addr;
184
        output [31:0] data_out;
185
        begin
186
                PSEL <= 1;
187
                PENABLE <= 0;
188
                PWRITE <= 0;
189
                PADDR <= addr;
190
                @(posedge PCLK);
191
                PENABLE <= 1;
192
                @(posedge PCLK);
193
                data_out = PRDATA;
194
                PENABLE <= 0;
195
                PSEL <= 0;
196
        end
197
endtask
198
 
199
task write_iv;
200
        input [127:0] iv_in;
201
        begin
202
                apb_write(AES_IVR0, iv_in[ 31:0]);
203
                apb_write(AES_IVR1, iv_in[ 63:32]);
204
                apb_write(AES_IVR2, iv_in[ 95:64]);
205
                apb_write(AES_IVR3, iv_in[127:96]);
206
        end
207
endtask
208
 
209
task read_iv;
210
        output [127:0] iv_out;
211
        begin
212
                apb_read(AES_IVR0, iv_out[ 31:0]);
213
                apb_read(AES_IVR1, iv_out[ 63:32]);
214
                apb_read(AES_IVR2, iv_out[ 95:64]);
215
                apb_read(AES_IVR3, iv_out[127:96]);
216
        end
217
endtask
218
 
219
task write_key;
220
        input [127:0] key_in;
221
        begin
222
                apb_write(AES_KEYR0, key_in[ 31:0]);
223
                apb_write(AES_KEYR1, key_in[ 63:32]);
224
                apb_write(AES_KEYR2, key_in[ 95:64]);
225
                apb_write(AES_KEYR3, key_in[127:96]);
226
        end
227
endtask
228
 
229
task read_key;
230
        output [127:0] key_out;
231
        begin
232
                apb_read(AES_KEYR0, key_out[ 31:0]);
233
                apb_read(AES_KEYR1, key_out[ 63:32]);
234
                apb_read(AES_KEYR2, key_out[ 95:64]);
235
                apb_read(AES_KEYR3, key_out[127:96]);
236
        end
237
endtask
238
 
239
task write_data;
240
        input [127:0] data_in;
241
        begin
242
                apb_write(AES_DINR, data_in[127:96]);
243
                apb_write(AES_DINR, data_in[ 95:64]);
244
                apb_write(AES_DINR, data_in[ 63:32]);
245
                apb_write(AES_DINR, data_in[ 31: 0]);
246
        end
247
endtask
248
 
249
task write_data_dma;
250
        input [127:0] data_in;
251
        begin
252
                @(posedge dma_req_wr);
253
                apb_write(AES_DINR, data_in[127:96]);
254
                @(posedge dma_req_wr);
255
                apb_write(AES_DINR, data_in[ 95:64]);
256
                @(posedge dma_req_wr);
257
                apb_write(AES_DINR, data_in[ 63:32]);
258
                @(posedge dma_req_wr);
259
                apb_write(AES_DINR, data_in[ 31: 0]);
260
        end
261
endtask
262
 
263
task read_data;
264
        output [127:0] data_rd;
265
        begin
266
                apb_read(AES_DOUTR, data_rd[127:96]);
267
                apb_read(AES_DOUTR, data_rd[ 95:64]);
268
                apb_read(AES_DOUTR, data_rd[ 63:32]);
269
                apb_read(AES_DOUTR, data_rd[ 31: 0]);
270
        end
271
endtask
272
 
273
task read_data_dma;
274
        output [127:0] data_rd;
275
        begin
276
                @(posedge dma_req_rd);
277
                apb_read(AES_DOUTR, data_rd[127:96]);
278
                @(posedge dma_req_rd);
279
                apb_read(AES_DOUTR, data_rd[ 95:64]);
280
                @(posedge dma_req_rd);
281
                apb_read(AES_DOUTR, data_rd[ 63:32]);
282
                @(posedge dma_req_rd);
283
                apb_read(AES_DOUTR, data_rd[ 31: 0]);
284
        end
285
endtask
286
 
287
task check_result;
288
        input [127:0] result;
289
        input [127:0] golden;
290
        output error;
291
        begin
292
                error = 0;
293
                if(result != golden)
294
                        begin
295
                                $display("TEST FAILED!");
296
                                $display("Expected %x, obtained %x", golden, result);
297
                                error = 1;
298
                        end
299
        end
300
endtask
301
 
302
integer i, error;
303
 
304
initial
305
        begin
306
                reset;
307
                iv_in  = 128'h2b7e151628aed2a6abf7158809cf4f3c;
308
                key_in = 128'h00112233445566778899aabbccddeeff;
309
                write_iv(iv_in);
310
                read_iv(iv_rd);
311
                if(iv_rd != iv_in)
312
                        begin
313
                                $display("Access to IV register failed!");
314
                                $display("Expected %x, obtained %x", iv_in, iv_rd);
315
                                $stop;
316
                        end
317
                write_key(key_in);
318
                read_key(key_rd);
319
                if(key_rd != key_in)
320
                        begin
321
                                $display("Access to KEY register failed!");
322
                                $display("Expected %x, obtained %x", key_in, key_rd);
323
                                $stop;
324
                        end
325
                apb_write(AES_CR, ENABLE);
326
                write_key(128'd50);
327
                read_iv(data_rd);
328
                read_data(result);
329
                apb_write(AES_CR, DISABLE);
330
                apb_read(AES_SR, data_rd);
331
                apb_write(AES_CR, ERRC);
332
 
333
                //ECB TESTS
334
                //ENCRYPTION
335
                error = 0;
336
                data_in = 128'h00112233445566778899aabbccddeeff;
337
                key_in  = 128'h000102030405060708090a0b0c0d0e0f;
338
                golden  = 128'h69c4e0d86a7b0430d8cdb78070b4c55a;
339
                write_key(key_in);
340
                apb_write(AES_CR, ENABLE | CCFIE);
341
                write_data(data_in);
342
                @(posedge int_ccf);
343
                read_data(result);
344
                check_result(result, golden, error_chk);
345
                error = error + error_chk;
346
 
347
                data_in = 128'h3243f6a8885a308d313198a2e0370734;
348
                key_in  = 128'h2b7e151628aed2a6abf7158809cf4f3c;
349
                golden  = 128'h3925841d02dc09fbdc118597196a0b32;
350
                apb_write(AES_CR, DISABLE);
351
                write_key(key_in);
352
                apb_write(AES_CR, ENABLE | CCFIE);
353
                write_data(data_in);
354
                @(posedge int_ccf);
355
                read_data(result);
356
                check_result(result, golden, error_chk);
357
                error = error + error_chk;
358
 
359
                // KEY DERIVATION
360
                key_in  = 128'h2b7e151628aed2a6abf7158809cf4f3c;
361
                golden  = 128'hd014f9a8c9ee2589e13f0cc8b6630ca6;
362
                apb_write(AES_CR, DISABLE);
363
                write_key(key_in);
364
                apb_write(AES_CR, KEY_DERIV | ENABLE | CCFIE);
365
                @(posedge int_ccf);
366
                @(posedge PCLK);
367
                read_key(result);
368
                check_result(result, golden, error_chk);
369
                error = error + error_chk;
370
 
371
                // DECRYPTION
372
                data_in = 128'h69c4e0d86a7b0430d8cdb78070b4c55a;
373
                key_in  = 128'h13111d7fe3944a17f307a78b4d2b30c5;
374
                golden  = 128'h00112233445566778899aabbccddeeff;
375
                apb_write(AES_CR, DISABLE);
376
                write_key(key_in);
377
                apb_write(AES_CR, DECRYPTION | ENABLE | CCFIE);
378
                write_data(data_in);
379
                @(posedge int_ccf);
380
                read_data(result);
381
                check_result(result, golden, error_chk);
382
                error = error + error_chk;
383
 
384
                // DECCYPTION WITH DERIVATION
385
                data_in = 128'h69c4e0d86a7b0430d8cdb78070b4c55a;
386
                key_in  = 128'h000102030405060708090a0b0c0d0e0f;
387
                golden  = 128'h00112233445566778899aabbccddeeff;
388
                apb_write(AES_CR, DISABLE);
389
                write_key(key_in);
390
                apb_write(AES_CR, KEY_DECRYP | ENABLE | CCFIE);
391
                write_data(data_in);
392
                @(posedge int_ccf);
393
                read_data(result);
394
                check_result(result, golden, error_chk);
395
                error = error + error_chk;
396
 
397
                key_in  = 128'h000102030405060708090a0b0c0d0e0f;
398
                apb_write(AES_CR, DISABLE);
399
                write_key(key_in);
400
                apb_write(AES_CR, KEY_DERIV | ENABLE | CCFIE);
401
                @(posedge int_ccf);
402
                data_in = 128'h69c4e0d86a7b0430d8cdb78070b4c55a;
403
                golden  = 128'h00112233445566778899aabbccddeeff;
404
                apb_write(AES_CR, DISABLE);
405
                apb_write(AES_CR, DECRYPTION | ENABLE | CCFIE);
406
                write_data(data_in);
407
                @(posedge int_ccf);
408
                read_data(result);
409
                check_result(result, golden, error_chk);
410
                error = error + error_chk;
411
                if(!error)
412
                        $display("ECB TEST PASSED!");
413
                else
414
                        $display("ECB TEST FAILED!\n Founded %d errors", error);
415
 
416
                // CBC Encryption
417
                error = 0;
418
                apb_write(AES_CR, DISABLE);
419
                key_in  = 128'h2b7e151628aed2a6abf7158809cf4f3c;
420
                iv_in   = 128'h000102030405060708090a0b0c0d0e0f;
421
 
422
                //BLOCK 1
423
                data_in = 128'h6bc1bee22e409f96e93d7e117393172a;
424
                golden  = 128'h7649abac8119b246cee98e9b12e9197d;
425
                write_key(key_in);
426
                write_iv(iv_in);
427
                apb_write(AES_CR, CBC | ENABLE | CCFIE);
428
                write_data(data_in);
429
                @(posedge int_ccf);
430
                read_data(result);
431
                check_result(result, golden, error_chk);
432
                error = error + error_chk;
433
 
434
                // BLOCK 2
435
                data_in = 128'hae2d8a571e03ac9c9eb76fac45af8e51;
436
                golden = 128'h5086cb9b507219ee95db113a917678b2;
437
                write_data(data_in);
438
                @(posedge int_ccf);
439
                read_data(result);
440
                check_result(result, golden, error_chk);
441
                error = error + error_chk;
442
 
443
                // BLOCK 3
444
                data_in = 128'h30c81c46a35ce411e5fbc1191a0a52ef;
445
                golden = 128'h73bed6b8e3c1743b7116e69e22229516;
446
                write_data(data_in);
447
                @(posedge int_ccf);
448
                read_data(result);
449
                check_result(result, golden, error_chk);
450
                error = error + error_chk;
451
 
452
                // BLOCK 4
453
                data_in = 128'hf69f2445df4f9b17ad2b417be66c3710;
454
                golden = 128'h3ff1caa1681fac09120eca307586e1a7;
455
                write_data(data_in);
456
                @(posedge int_ccf);
457
                read_data(result);
458
                check_result(result, golden, error_chk);
459
                error = error + error_chk;
460
 
461
                // CBC DECRYPTION
462
                apb_write(AES_CR, DISABLE);
463
                key_in  = 128'h2b7e151628aed2a6abf7158809cf4f3c;
464
                iv_in   = 128'h000102030405060708090a0b0c0d0e0f;
465
 
466
                //BLOCK 1
467
                data_in = 128'h7649abac8119b246cee98e9b12e9197d;
468
                golden  = 128'h6bc1bee22e409f96e93d7e117393172a;
469
                write_key(key_in);
470
                write_iv(iv_in);
471
                apb_write(AES_CR, CBC | KEY_DECRYP | ENABLE | CCFIE);
472
                write_data(data_in);
473
                @(posedge int_ccf);
474
                read_data(result);
475
                check_result(result, golden, error_chk);
476
                error = error + error_chk;
477
 
478
                // BLOCK 2
479
                data_in = 128'h5086cb9b507219ee95db113a917678b2;
480
                golden = 128'hae2d8a571e03ac9c9eb76fac45af8e51 ;
481
                write_data(data_in);
482
                @(posedge int_ccf);
483
                read_data(result);
484
                check_result(result, golden, error_chk);
485
                error = error + error_chk;
486
 
487
                // BLOCK 3
488
                data_in = 128'h73bed6b8e3c1743b7116e69e22229516;
489
                golden = 128'h30c81c46a35ce411e5fbc1191a0a52ef ;
490
                write_data(data_in);
491
                @(posedge int_ccf);
492
                read_data(result);
493
                check_result(result, golden, error_chk);
494
                error = error + error_chk;
495
 
496
                // BLOCK 4
497
                data_in = 128'h3ff1caa1681fac09120eca307586e1a7;
498
                golden  = 128'hf69f2445df4f9b17ad2b417be66c3710;
499
                write_data(data_in);
500
                @(posedge int_ccf);
501
                read_data(result);
502
                check_result(result, golden, error_chk);
503
                error = error + error_chk;
504
                if(!error)
505
                        $display("CBC TEST PASSED!");
506
                else
507
                        $display("CBC TEST FAILED!\n Founded %d errors", error);
508
 
509
                // CTR Encryption
510
                error = 0;
511
                apb_write(AES_CR, DISABLE);
512
                key_in  = 128'h2b7e151628aed2a6abf7158809cf4f3c;
513
                iv_in   = 128'hf0f1f2f3f4f5f6f7f8f9fafbfcfdfeff;
514
 
515
                //BLOCK 1
516
                data_in = 128'h6bc1bee22e409f96e93d7e117393172a;
517
                golden  = 128'h874d6191b620e3261bef6864990db6ce ;
518
                write_key(key_in);
519
                write_iv(iv_in);
520
                apb_write(AES_CR, CTR | ENABLE | CCFIE);
521
                write_data(data_in);
522
                @(posedge int_ccf);
523
                read_data(result);
524
                check_result(result, golden, error_chk);
525
                error = error + error_chk;
526
 
527
                // BLOCK 2
528
                data_in = 128'hae2d8a571e03ac9c9eb76fac45af8e51;
529
                golden = 128'h9806f66b7970fdff8617187bb9fffdff;
530
                write_data(data_in);
531
                @(posedge int_ccf);
532
                read_data(result);
533
                check_result(result, golden, error_chk);
534
                error = error + error_chk;
535
 
536
                // BLOCK 3
537
                data_in = 128'h30c81c46a35ce411e5fbc1191a0a52ef;
538
                golden = 128'h5ae4df3edbd5d35e5b4f09020db03eab;
539
                write_data(data_in);
540
                @(posedge int_ccf);
541
                read_data(result);
542
                check_result(result, golden, error_chk);
543
                error = error + error_chk;
544
 
545
                // BLOCK 4
546
                data_in = 128'hf69f2445df4f9b17ad2b417be66c3710;
547
                golden = 128'h1e031dda2fbe03d1792170a0f3009cee ;
548
                write_data(data_in);
549
                @(posedge int_ccf);
550
                read_data(result);
551
                check_result(result, golden, error_chk);
552
                error = error + error_chk;
553
 
554
                // CTR DECRYPTION
555
                apb_write(AES_CR, DISABLE);
556
                iv_in   = 128'hf0f1f2f3f4f5f6f7f8f9fafbfcfdfeff;
557
                //BLOCK 1
558
                data_in = 128'h874d6191b620e3261bef6864990db6ce;
559
                golden  = 128'h6bc1bee22e409f96e93d7e117393172a;
560
                write_iv(iv_in);
561
                apb_write(AES_CR, CTR | KEY_DECRYP | ENABLE | CCFIE);
562
                write_data(data_in);
563
                @(posedge int_ccf);
564
                read_data(result);
565
                check_result(result, golden, error_chk);
566
                error = error + error_chk;
567
 
568
                // BLOCK 2
569
                data_in = 128'h9806f66b7970fdff8617187bb9fffdff;
570
                golden  = 128'hae2d8a571e03ac9c9eb76fac45af8e51;
571
                write_data(data_in);
572
                @(posedge int_ccf);
573
                read_data(result);
574
                check_result(result, golden, error_chk);
575
                error = error + error_chk;
576
 
577
                // BLOCK 3
578
                data_in = 128'h5ae4df3edbd5d35e5b4f09020db03eab;
579
                golden  = 128'h30c81c46a35ce411e5fbc1191a0a52ef;
580
                write_data(data_in);
581
                @(posedge int_ccf);
582
                read_data(result);
583
                check_result(result, golden, error_chk);
584
                error = error + error_chk;
585
 
586
                // BLOCK 4
587
                data_in = 128'h1e031dda2fbe03d1792170a0f3009cee;
588
                golden  = 128'hf69f2445df4f9b17ad2b417be66c3710;
589
                write_data(data_in);
590
                @(posedge int_ccf);
591
                read_data(result);
592
                check_result(result, golden, error_chk);
593
                error = error + error_chk;
594
                if(!error)
595
                        $display("CTR TEST PASSED!");
596
                else
597
                        $display("CTR TEST FAILED!\n Founded %d errors", error);
598
 
599
                error = 0;
600
                data_in = 128'h00112233445566778899aabbccddeeff;
601
                key_in  = 128'h000102030405060708090a0b0c0d0e0f;
602
                golden  = 128'h69c4e0d86a7b0430d8cdb78070b4c55a;
603
                write_key(key_in);
604
                apb_write(AES_CR, ENABLE | CCFIE);
605
                write_data(data_in);
606
                repeat(30)
607
                        @(posedge PCLK);
608
                apb_write(AES_CR, DISABLE);
609
                // KEY DERIVATION
610
                key_in  = 128'h2b7e151628aed2a6abf7158809cf4f3c;
611
                golden  = 128'hd014f9a8c9ee2589e13f0cc8b6630ca6;
612
                write_key(key_in);
613
                apb_write(AES_CR, KEY_DERIV | ENABLE | CCFIE);
614
                @(posedge int_ccf);
615
                @(posedge PCLK); // A LEITURA DA CHAVE DEVE SER INICIADA UM CLOCK AP\D2S A SUBIDA DE CCF
616
                read_key(result);
617
                check_result(result, golden, error_chk);
618
 
619
                // TEST SUSPEND FUNCTIONALITY
620
                key_in  = 128'h2b7e151628aed2a6abf7158809cf4f3c;
621
                iv_in   = 128'h000102030405060708090a0b0c0d0e0f;
622
 
623
                //BLOCK 1
624
                data_in = 128'h6bc1bee22e409f96e93d7e117393172a;
625
                golden  = 128'h7649abac8119b246cee98e9b12e9197d;
626
                write_key(key_in);
627
                write_iv(iv_in);
628
                apb_write(AES_CR, CBC | ENABLE | CCFIE);
629
                write_data(data_in);
630
                @(posedge int_ccf);
631
                read_data(result);
632
                check_result(result, golden, error_chk);
633
                error = error + error_chk;
634
 
635
                // BLOCK 2
636
                data_in = 128'hae2d8a571e03ac9c9eb76fac45af8e51;
637
                golden = 128'h5086cb9b507219ee95db113a917678b2;
638
                write_data(data_in);
639
                @(posedge int_ccf);
640
                read_data(result);
641
                check_result(result, golden, error_chk);
642
                error = error + error_chk;
643
 
644
                //suspend processing
645
                apb_write(AES_CR, DISABLE);
646
                result_rd = result;
647
                read_iv(iv_rd);
648
                read_key(key_rd);
649
 
650
                //begin new processing          
651
                key_in  = 128'h2b7e151628aed2a6abf7158809cf4f3c;
652
                golden  = 128'hd014f9a8c9ee2589e13f0cc8b6630ca6;
653
                write_key(key_in);
654
                apb_write(AES_CR, KEY_DERIV | ENABLE | CCFIE);
655
                @(posedge int_ccf);
656
                @(posedge PCLK); // A LEITURA DA CHAVE DEVE SER INICIADA UM CLOCK AP\D2S A SUBIDA DE CCF
657
                read_key(result);
658
                check_result(result, golden, error_chk);
659
                error = error + error_chk;
660
 
661
                //continues processing
662
                // BLOCK 3
663
                key_in  = 128'h2b7e151628aed2a6abf7158809cf4f3c;
664
                apb_write(AES_CR, DISABLE);
665
                write_key(key_in);
666
                write_iv(result_rd);
667
                data_in = 128'h30c81c46a35ce411e5fbc1191a0a52ef;
668
                golden = 128'h73bed6b8e3c1743b7116e69e22229516;
669
                apb_write(AES_CR, CBC | ENABLE | CCFIE);
670
                write_data(data_in);
671
                @(posedge int_ccf);
672
                read_data(result);
673
                check_result(result, golden, error_chk);
674
                error = error + error_chk;
675
 
676
                // BLOCK 4
677
                data_in = 128'hf69f2445df4f9b17ad2b417be66c3710;
678
                golden = 128'h3ff1caa1681fac09120eca307586e1a7;
679
                write_data(data_in);
680
                @(posedge int_ccf);
681
                read_data(result);
682
                check_result(result, golden, error_chk);
683
                error = error + error_chk;
684
                if(!error)
685
                        $display("SUSPEND MODE TEST PASSED!");
686
                else
687
                        $display("SUSPEND MODE TEST FAILED!\n Founded %d errors", error);
688
 
689
                //DMA TEST
690
                error = 0;
691
                apb_write(AES_CR, DISABLE);
692
                data_in = 128'h00112233445566778899aabbccddeeff;
693
                key_in  = 128'h000102030405060708090a0b0c0d0e0f;
694
                golden  = 128'h69c4e0d86a7b0430d8cdb78070b4c55a;
695
                write_key(key_in);
696
                apb_write(AES_CR, DMAINEN | DMAOUTEN | ENABLE | CCFIE);
697
                write_data_dma(data_in);
698
                @(posedge int_ccf);
699
                read_data_dma(result);
700
                check_result(result, golden, error_chk);
701
                error = error + error_chk;
702
                if(!error)
703
                        $display("DMA TEST PASSED!");
704
                else
705
                        $display("DMA TEST FAILED!\n Founded %d errors", error);
706
                $stop;
707
        end
708
 
709
always #10
710
        PCLK = !PCLK;
711
endmodule

powered by: WebSVN 2.1.0

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