kexp_d.v 2.48 KB
// This confidential and propriety software may be used
// only as authorized by a licensing agreement from
// Ocean Logic Pty Ltd http://www.ocean-logic.com
// 
// In the event of publication, the following notice is
// applicable
// 
// (C) COPYRIGHT 2001 Ocean Logic Pty Ltd
// ALL RIGHTS RESERVED
//
// the entire notice must be reproduced on all
// authorized copies
// 
// File : kexp_d.vhd
// Author : Vincenzo Liguori
// Date : 01-03-02
// Version 1.0
// Abstract :
// Decryption key expander top module
// 
// Modification history :
// Date      by  Version  Change description
// -------------------------------------------------
// 01-03-02  VL   1.0     Original

module kexp_d(
clk,
rstn,
go,
en,
ksize,
kin,
key,
addr,
key_req,
key_last
);

// Inputs
input clk, rstn;
input go, en;
input[1:0] ksize;
input[31:0] kin;
// Outputs 
output[31:0] key;
output[5:0] addr;
output key_req;
output key_last;

wire   clk;
wire   rstn;
wire   go;
wire   en;
wire  [1:0] ksize;
wire  [31:0] kin;
wire  [31:0] key;
wire  [5:0] addr;
wire   key_req;
wire   key_last;


wire [31:0] keye;
wire [31:0] keyd;
wire  first;
wire  final;
wire [7:0] ke0;
wire [7:0] kb0;
wire [7:0] kd0;
wire [7:0] k90;
wire [7:0] ke1;
wire [7:0] kb1;
wire [7:0] kd1;
wire [7:0] k91;
wire [7:0] ke2;
wire [7:0] kb2;
wire [7:0] kd2;
wire [7:0] k92;
wire [7:0] ke3;
wire [7:0] kb3;
wire [7:0] kd3;
wire [7:0] k93;

  // Instantiate the AES key expander
  kexp kx(
      // Inputs
    .clk(clk),
    .rstn(rstn),
    .go(go),
    .en(en),
    .ksize(ksize),
    .kin(kin),
    // Outputs 
    .key(keye),
    .addr(addr),
    .first(first),
    .final(final),
    .key_req(key_req),
    .key_last(key_last));

  // Perform the mixcol operation
  mixcol mx0(
      .x(keye[31:24] ),
    .do0(ke0),
    .do1(kb0),
    .do2(kd0),
    .do3(k90));

  mixcol mx1(
      .x(keye[23:16] ),
    .do0(ke1),
    .do1(kb1),
    .do2(kd1),
    .do3(k91));

  mixcol mx2(
      .x(keye[15:8] ),
    .do0(ke2),
    .do1(kb2),
    .do2(kd2),
    .do3(k92));

  mixcol mx3(
      .x(keye[7:0] ),
    .do0(ke3),
    .do1(kb3),
    .do2(kd3),
    .do3(k93));

  assign keyd[31:24]  = ke0 ^ kb1 ^ kd2 ^ k93;
  assign keyd[23:16]  = k90 ^ ke1 ^ kb2 ^ kd3;
  assign keyd[15:8]  = kd0 ^ k91 ^ ke2 ^ kb3;
  assign keyd[7:0]  = kb0 ^ kd1 ^ k92 ^ ke3;
  // Select the appropriate expanded key
  assign key = (first | final) == 1'b 1 ? keye : keyd;

endmodule