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

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [memocodeDesignContest2008/] [xup/] [aesCore/] [AESTester.bsv] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 kfleming
/*
2
Copyright (c) 2008 MIT
3
 
4
Permission is hereby granted, free of charge, to any person
5
obtaining a copy of this software and associated documentation
6
files (the "Software"), to deal in the Software without
7
restriction, including without limitation the rights to use,
8
copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the
10
Software is furnished to do so, subject to the following
11
conditions:
12
 
13
The above copyright notice and this permission notice shall be
14
included in all copies or substantial portions of the Software.
15
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
OTHER DEALINGS IN THE SOFTWARE.
24
 
25
Author: Kermin Fleming
26
*/
27
 
28
import PLBMasterWires::*;
29
import BRAMTargetWires::*;
30
import BRAMInitiatorWires::*;
31
import PLBMaster::*;
32
import BRAMFeeder::*;
33
import BRAMModel::*;
34
import Interfaces::*;
35
import Parameters::*;
36
import FIFO::*;
37
import GetPut::*;
38
import Types::*;
39
import Memocode08Types::*;
40
import aesCipherTop::*;
41
import BRAMFIFO::*;
42
 
43
interface AESTester;
44
  interface PLBMasterWires                  plbMasterWires;
45
  interface BRAMInitiatorWires#(Bit#(14))   bramInitiatorWires;
46
endinterface
47
 
48
typedef enum{
49
  Idle,
50
  Running,
51
  Inputing,
52
  Outputing
53
} TesterState deriving (Bits,Eq);
54
 
55
 
56
module mkAESTester#(Clock fastClock, Reset fastReset) (AESTester);
57
  Feeder feeder <- mkBRAMFeeder();
58
  PLBMaster     plbMaster <- mkPLBMaster;
59
  Clock clk <- exposeCurrentClock;
60
  Reset rst <- exposeCurrentReset;
61
 
62
  Reg#(TesterState) state <- mkReg(Idle);
63
  Reg#(BlockAddr) baseRegLoad <- mkReg(0);
64
  Reg#(BlockAddr) baseRegStore <- mkReg(0);
65
  Reg#(Bit#(20)) commandCount <- mkReg(0);
66
  Reg#(Bit#(20)) maxCommands <- mkReg(0);
67
  Reg#(Bit#(32)) commandsComplete <- mkReg(1);
68
  FIFO#(Record) dataFIFO <- mkBRAMFIFO(8);
69
  Reg#(Bool) evenZero <- mkReg(True);
70
  //AESCores#(4) aesCore <- mkAESCoresMCD(fastClock,clk,fastReset,rst,clocked_by(fastClock),reset_by(fastReset));
71
  AESCores#(1) aesCore <- mkAESCorePipelinedMCD(clk,rst,clocked_by(fastClock),reset_by(fastReset));//mkAESCoresMCD(clk,rst,clocked_by(fastClock),reset_by(fastReset));
72
  //AESCores#(4) aesCore <- mkAESCores;
73
  Reg#(Bool) sendResp <- mkReg(False);
74
  Reg#(Bit#(5)) logMax <- mkReg(0);
75
  //AES aes <- mkAES;
76
  Reg#(Bit#(8)) aesCount <- mkReg(0);
77
 
78
   AES_key key = {8'hB0, 8'h1D, 8'hFA, 8'hCE,
79
                  8'h0D, 8'hEC, 8'h0D, 8'hED,
80
                  8'h0B, 8'hA1, 8'h1A, 8'hDE,
81
                  8'h0E, 8'hFF, 8'hEC, 8'h70};
82
 
83
 
84
  rule grabInstruction(state == Idle);
85
    sendResp <= True;
86
    Instruction inst <- feeder.ppcInstructionOutput.get;
87
    logMax <= truncate(pack(inst));
88
    Bit#(5) size = truncate(pack(inst));
89
    aesCore.start(size);
90
    maxCommands <= 1 << (size); // + 1 since we need R/W -2 for 4/bursts +1 for needing two iters
91
    commandCount <= 0;
92
    baseRegLoad <= 0;
93
    baseRegStore <= 0;
94
    state <= Running;
95
    //aesCount <= 1;
96
    //aes.decrypt(0, key);
97
  endrule
98
 
99
 
100
 
101
  rule issueCommand(state == Running);
102
    commandCount <= commandCount + 1;
103
    if(commandCount + 1 == maxCommands)
104
      begin
105
        state <= Idle;
106
        feeder.ppcMessageInput.put(zeroExtend(pack(maxCommands)));
107
        commandsComplete <= commandsComplete + 1;
108
      end
109
 
110
    if(commandCount[1] == 0)
111
      begin
112
        baseRegLoad <= baseRegLoad + fromInteger(valueof(BlockSize));
113
        plbMaster.plbMasterCommandInput.put(tagged LoadPage (baseRegLoad));
114
 
115
      end
116
    else
117
      begin
118
        baseRegStore <= baseRegStore + fromInteger(valueof(BlockSize));
119
        plbMaster.plbMasterCommandInput.put(tagged StorePage (baseRegStore));
120
      end
121
  endrule
122
 
123
  rule inputing;
124
     Record data <- plbMaster.wordOutput.get;
125
     dataFIFO.enq(data);
126
  endrule
127
 
128
  rule outputing;
129
//    aesCount <= aesCount + 1;
130
//    aes.decrypt(pack(zeroExtend(aesCount)), key);
131
 
132
    Bit#(128) aesVal <- aesCore.get_next();
133
    plbMaster.wordInput.put(aesVal^dataFIFO.first);
134
    dataFIFO.deq;
135
  endrule
136
 
137
  interface plbMasterWires = plbMaster.plbMasterWires;
138
  interface bramInitiatorWires = feeder.bramInitiatorWires;
139
 
140
endmodule

powered by: WebSVN 2.1.0

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