aboutsummaryrefslogtreecommitdiff
path: root/src/rtl
diff options
context:
space:
mode:
authorJoachim Strömbergson <joachim@secworks.se>2018-05-21 19:03:36 +0200
committerJoachim Strömbergson <joachim@secworks.se>2018-05-21 19:03:36 +0200
commit0ab3199f5aaa792a577fb3ec8b7310c3c4213eb2 (patch)
tree2702f4a02159d151b4688a4f1df243683776baf8 /src/rtl
parent1e9ed5842c3cb72226450403cf49783f2f9d8e86 (diff)
Increased number of inverse S-boxes to 16 and removed S-box scheduling.
Diffstat (limited to 'src/rtl')
-rw-r--r--src/rtl/aes_decipher_block.v104
1 files changed, 27 insertions, 77 deletions
diff --git a/src/rtl/aes_decipher_block.v b/src/rtl/aes_decipher_block.v
index 82bdffb..c2304d6 100644
--- a/src/rtl/aes_decipher_block.v
+++ b/src/rtl/aes_decipher_block.v
@@ -192,12 +192,6 @@ module aes_decipher_block(
//----------------------------------------------------------------
// Registers including update variables and write enable.
//----------------------------------------------------------------
- reg [1 : 0] sword_ctr_reg;
- reg [1 : 0] sword_ctr_new;
- reg sword_ctr_we;
- reg sword_ctr_inc;
- reg sword_ctr_rst;
-
reg [3 : 0] round_ctr_reg;
reg [3 : 0] round_ctr_new;
reg round_ctr_we;
@@ -226,15 +220,24 @@ module aes_decipher_block(
//----------------------------------------------------------------
// Wires.
//----------------------------------------------------------------
- reg [31 : 0] tmp_sboxw;
- wire [31 : 0] new_sboxw;
+ reg [31 : 0] sboxw0;
+ reg [31 : 0] sboxw1;
+ reg [31 : 0] sboxw2;
+ reg [31 : 0] sboxw3;
+ wire [31 : 0] new_sboxw0;
+ wire [31 : 0] new_sboxw1;
+ wire [31 : 0] new_sboxw2;
+ wire [31 : 0] new_sboxw3;
reg [2 : 0] update_type;
//----------------------------------------------------------------
- // Instantiations.
+ // Inverse S-boxes.
//----------------------------------------------------------------
- aes_inv_sbox inv_sbox_inst(.sword(tmp_sboxw), .new_sword(new_sboxw));
+ aes_inv_sbox inv_sbox_inst0(.sword(sboxw0), .new_sword(new_sboxw0));
+ aes_inv_sbox inv_sbox_inst1(.sword(sboxw1), .new_sword(new_sboxw1));
+ aes_inv_sbox inv_sbox_inst2(.sword(sboxw2), .new_sword(new_sboxw2));
+ aes_inv_sbox inv_sbox_inst3(.sword(sboxw3), .new_sword(new_sboxw3));
//----------------------------------------------------------------
@@ -260,7 +263,6 @@ module aes_decipher_block(
block_w1_reg <= 32'h0;
block_w2_reg <= 32'h0;
block_w3_reg <= 32'h0;
- sword_ctr_reg <= 2'h0;
round_ctr_reg <= 4'h0;
ready_reg <= 1'b1;
dec_ctrl_reg <= CTRL_IDLE;
@@ -279,9 +281,6 @@ module aes_decipher_block(
if (block_w3_we)
block_w3_reg <= block_new[031 : 000];
- if (sword_ctr_we)
- sword_ctr_reg <= sword_ctr_new;
-
if (round_ctr_we)
round_ctr_reg <= round_ctr_new;
@@ -308,13 +307,17 @@ module aes_decipher_block(
inv_mixcolumns_block = 128'h0;
addkey_block = 128'h0;
block_new = 128'h0;
- tmp_sboxw = 32'h0;
block_w0_we = 1'b0;
block_w1_we = 1'b0;
block_w2_we = 1'b0;
block_w3_we = 1'b0;
- old_block = {block_w0_reg, block_w1_reg, block_w2_reg, block_w3_reg};
+ sboxw0 = block_w0_reg;
+ sboxw1 = block_w1_reg;
+ sboxw2 = block_w2_reg;
+ sboxw3 = block_w3_reg;
+
+ old_block = {block_w0_reg, block_w1_reg, block_w2_reg, block_w3_reg};
// Update based on update type.
case (update_type)
@@ -333,33 +336,11 @@ module aes_decipher_block(
SBOX_UPDATE:
begin
- block_new = {new_sboxw, new_sboxw, new_sboxw, new_sboxw};
-
- case (sword_ctr_reg)
- 2'h0:
- begin
- tmp_sboxw = block_w0_reg;
- block_w0_we = 1'b1;
- end
-
- 2'h1:
- begin
- tmp_sboxw = block_w1_reg;
- block_w1_we = 1'b1;
- end
-
- 2'h2:
- begin
- tmp_sboxw = block_w2_reg;
- block_w2_we = 1'b1;
- end
-
- 2'h3:
- begin
- tmp_sboxw = block_w3_reg;
- block_w3_we = 1'b1;
- end
- endcase // case (sbox_mux_ctrl_reg)
+ block_new = {new_sboxw0, new_sboxw1, new_sboxw2, new_sboxw3};
+ block_w0_we = 1'b1;
+ block_w1_we = 1'b1;
+ block_w2_we = 1'b1;
+ block_w3_we = 1'b1;
end
MAIN_UPDATE:
@@ -391,29 +372,6 @@ module aes_decipher_block(
//----------------------------------------------------------------
- // sword_ctr
- //
- // The subbytes word counter with reset and increase logic.
- //----------------------------------------------------------------
- always @*
- begin : sword_ctr
- sword_ctr_new = 2'h0;
- sword_ctr_we = 1'b0;
-
- if (sword_ctr_rst)
- begin
- sword_ctr_new = 2'h0;
- sword_ctr_we = 1'b1;
- end
- else if (sword_ctr_inc)
- begin
- sword_ctr_new = sword_ctr_reg + 1'b1;
- sword_ctr_we = 1'b1;
- end
- end // sword_ctr
-
-
- //----------------------------------------------------------------
// round_ctr
//
// The round counter with reset and increase logic.
@@ -450,8 +408,6 @@ module aes_decipher_block(
//----------------------------------------------------------------
always @*
begin: decipher_ctrl
- sword_ctr_inc = 1'b0;
- sword_ctr_rst = 1'b0;
round_ctr_dec = 1'b0;
round_ctr_set = 1'b0;
ready_new = 1'b0;
@@ -475,7 +431,6 @@ module aes_decipher_block(
CTRL_INIT:
begin
- sword_ctr_rst = 1'b1;
update_type = INIT_UPDATE;
dec_ctrl_new = CTRL_SBOX;
dec_ctrl_we = 1'b1;
@@ -483,19 +438,14 @@ module aes_decipher_block(
CTRL_SBOX:
begin
- sword_ctr_inc = 1'b1;
update_type = SBOX_UPDATE;
- if (sword_ctr_reg == 2'h3)
- begin
- round_ctr_dec = 1'b1;
- dec_ctrl_new = CTRL_MAIN;
- dec_ctrl_we = 1'b1;
- end
+ round_ctr_dec = 1'b1;
+ dec_ctrl_new = CTRL_MAIN;
+ dec_ctrl_we = 1'b1;
end
CTRL_MAIN:
begin
- sword_ctr_rst = 1'b1;
if (round_ctr_reg > 0)
begin
update_type = MAIN_UPDATE;
380' href='#n380'>380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683