Browse Source

internal mode is now a latched copy of mode_i (ITER)

T. Meissner 5 years ago
parent
commit
80443e531d
1 changed files with 25 additions and 33 deletions
  1. 25
    33
      des/rtl/vhdl/des.vhd

+ 25
- 33
des/rtl/vhdl/des.vhd View File

@@ -21,8 +21,9 @@
21 21
 
22 22
 library ieee;
23 23
   use ieee.std_logic_1164.all;
24
-  use ieee.numeric_std.ALL;
25
-  use work.des_pkg.ALL;
24
+  use ieee.numeric_std.all;
25
+  use work.des_pkg.all;
26
+
26 27
 
27 28
 
28 29
 entity des is
@@ -349,8 +350,6 @@ begin
349 350
 
350 351
   AreaG : if design_type = "ITER" generate
351 352
 
352
-    type t_mode is (NOP, CRYPT, DECRYPT);
353
-
354 353
     signal s_accept : std_logic;
355 354
     signal s_valid  : std_logic;
356 355
 
@@ -361,13 +360,10 @@ begin
361 360
 
362 361
 
363 362
     cryptP : process (clk_i, reset_i) is
364
-      -- variables for key calculation
365
-      variable v_c : std_logic_vector(0 to 27);
366
-      variable v_d : std_logic_vector(0 to 27);
367
-      -- key variables
368
-      variable v_key : std_logic_vector(0 to 47);
369
-      -- variables for mode & valid shift registers
370
-      variable v_mode  : t_mode;
363
+      variable v_c       : std_logic_vector(0 to 27);
364
+      variable v_d       : std_logic_vector(0 to 27);
365
+      variable v_key     : std_logic_vector(0 to 47);
366
+      variable v_mode    : std_logic;
371 367
       variable v_rnd_cnt : natural;
372 368
     begin
373 369
       if(reset_i = '0') then
@@ -377,7 +373,7 @@ begin
377 373
         s_l       <= (others => '0');
378 374
         s_r       <= (others => '0');
379 375
         v_rnd_cnt := 0;
380
-        v_mode    := NOP;
376
+        v_mode    := '0';
381 377
         s_accept  <= '0';
382 378
         s_valid   <= '0';
383 379
       elsif rising_edge(clk_i) then
@@ -394,17 +390,13 @@ begin
394 390
               s_r       <= ip(data_i)(32 to 63);
395 391
               v_c       := pc1_c(key_i);
396 392
               v_d       := pc1_d(key_i);
393
+              v_mode    := mode_i;
397 394
               v_rnd_cnt := v_rnd_cnt + 1;
398
-              if (mode_i = '0') then
399
-                v_mode := CRYPT;
400
-              else
401
-                v_mode := DECRYPT;
402
-              end if;
403 395
             end if;
404 396
 
405 397
           -- stage 1
406 398
           when 1 =>
407
-            if (v_mode = CRYPT) then
399
+            if (v_mode = '0') then
408 400
               v_c := v_c(1 to 27) & v_c(0);
409 401
               v_d := v_d(1 to 27) & v_d(0);
410 402
             end if;
@@ -414,7 +406,7 @@ begin
414 406
             v_rnd_cnt := v_rnd_cnt + 1;
415 407
 
416 408
           when 2 =>
417
-            if (v_mode = CRYPT) then
409
+            if (v_mode = '0') then
418 410
               v_c := v_c(1 to 27) & v_c(0);
419 411
               v_d := v_d(1 to 27) & v_d(0);
420 412
             else
@@ -427,7 +419,7 @@ begin
427 419
             v_rnd_cnt := v_rnd_cnt + 1;
428 420
 
429 421
           when 3 =>
430
-            if (v_mode = CRYPT) then
422
+            if (v_mode = '0') then
431 423
               v_c := v_c(2 to 27) & v_c(0 to 1);
432 424
               v_d := v_d(2 to 27) & v_d(0 to 1);
433 425
             else
@@ -440,7 +432,7 @@ begin
440 432
             v_rnd_cnt := v_rnd_cnt + 1;
441 433
 
442 434
           when 4 =>
443
-            if (v_mode = CRYPT) then
435
+            if (v_mode = '0') then
444 436
               v_c := v_c(2 to 27) & v_c(0 to 1);
445 437
               v_d := v_d(2 to 27) & v_d(0 to 1);
446 438
             else
@@ -453,7 +445,7 @@ begin
453 445
             v_rnd_cnt := v_rnd_cnt + 1;
454 446
 
455 447
           when 5 =>
456
-            if (v_mode = CRYPT) then
448
+            if (v_mode = '0') then
457 449
               v_c := v_c(2 to 27) & v_c(0 to 1);
458 450
               v_d := v_d(2 to 27) & v_d(0 to 1);
459 451
             else
@@ -466,7 +458,7 @@ begin
466 458
             v_rnd_cnt := v_rnd_cnt + 1;
467 459
 
468 460
           when 6 =>
469
-            if (v_mode = CRYPT) then
461
+            if (v_mode = '0') then
470 462
               v_c := v_c(2 to 27) & v_c(0 to 1);
471 463
               v_d := v_d(2 to 27) & v_d(0 to 1);
472 464
             else
@@ -479,7 +471,7 @@ begin
479 471
             v_rnd_cnt := v_rnd_cnt + 1;
480 472
 
481 473
           when 7 =>
482
-            if (v_mode = CRYPT) then
474
+            if (v_mode = '0') then
483 475
               v_c := v_c(2 to 27) & v_c(0 to 1);
484 476
               v_d := v_d(2 to 27) & v_d(0 to 1);
485 477
             else
@@ -492,7 +484,7 @@ begin
492 484
             v_rnd_cnt := v_rnd_cnt + 1;
493 485
 
494 486
           when 8 =>
495
-            if (v_mode = CRYPT) then
487
+            if (v_mode = '0') then
496 488
               v_c := v_c(2 to 27) & v_c(0 to 1);
497 489
               v_d := v_d(2 to 27) & v_d(0 to 1);
498 490
             else
@@ -505,7 +497,7 @@ begin
505 497
             v_rnd_cnt := v_rnd_cnt + 1;
506 498
 
507 499
           when 9 =>
508
-            if (v_mode = CRYPT) then
500
+            if (v_mode = '0') then
509 501
               v_c := v_c(1 to 27) & v_c(0);
510 502
               v_d := v_d(1 to 27) & v_d(0);
511 503
             else
@@ -518,7 +510,7 @@ begin
518 510
             v_rnd_cnt := v_rnd_cnt + 1;
519 511
 
520 512
           when 10 =>
521
-            if (v_mode = CRYPT) then
513
+            if (v_mode = '0') then
522 514
               v_c := v_c(2 to 27) & v_c(0 to 1);
523 515
               v_d := v_d(2 to 27) & v_d(0 to 1);
524 516
             else
@@ -532,7 +524,7 @@ begin
532 524
 
533 525
           when 11 =>
534 526
             -- 11. stage
535
-            if (v_mode = CRYPT) then
527
+            if (v_mode = '0') then
536 528
               v_c := v_c(2 to 27) & v_c(0 to 1);
537 529
               v_d := v_d(2 to 27) & v_d(0 to 1);
538 530
             else
@@ -545,7 +537,7 @@ begin
545 537
             v_rnd_cnt := v_rnd_cnt + 1;
546 538
 
547 539
           when 12 =>
548
-            if (v_mode = CRYPT) then
540
+            if (v_mode = '0') then
549 541
               v_c := v_c(2 to 27) & v_c(0 to 1);
550 542
               v_d := v_d(2 to 27) & v_d(0 to 1);
551 543
             else
@@ -558,7 +550,7 @@ begin
558 550
             v_rnd_cnt := v_rnd_cnt + 1;
559 551
 
560 552
           when 13 =>
561
-            if (v_mode = CRYPT) then
553
+            if (v_mode = '0') then
562 554
               v_c := v_c(2 to 27) & v_c(0 to 1);
563 555
               v_d := v_d(2 to 27) & v_d(0 to 1);
564 556
             else
@@ -571,7 +563,7 @@ begin
571 563
             v_rnd_cnt := v_rnd_cnt + 1;
572 564
 
573 565
           when 14 =>
574
-            if (v_mode = CRYPT) then
566
+            if (v_mode = '0') then
575 567
               v_c := v_c(2 to 27) & v_c(0 to 1);
576 568
               v_d := v_d(2 to 27) & v_d(0 to 1);
577 569
             else
@@ -584,7 +576,7 @@ begin
584 576
             v_rnd_cnt := v_rnd_cnt + 1;
585 577
 
586 578
           when 15 =>
587
-            if (v_mode = CRYPT) then
579
+            if (v_mode = '0') then
588 580
               v_c := v_c(2 to 27) & v_c(0 to 1);
589 581
               v_d := v_d(2 to 27) & v_d(0 to 1);
590 582
             else
@@ -597,7 +589,7 @@ begin
597 589
             v_rnd_cnt := v_rnd_cnt + 1;
598 590
 
599 591
           when 16 =>
600
-            if (v_mode = CRYPT) then
592
+            if (v_mode = '0') then
601 593
               v_c := v_c(1 to 27) & v_c(0);
602 594
               v_d := v_d(1 to 27) & v_d(0);
603 595
             else