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

Subversion Repositories present_encryptor

[/] [present_encryptor/] [trunk/] [rtl/] [verilog/] [present_encryptor_top.v] - Blame information for rev 21

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 rameli
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@//
2
// Design Name: Present Cipher Encryption Core                    //
3
// Module Name: present_encryptor_top                             //
4
// Language:    Verilog                                           //
5
// Date Created: 1/16/2011                                        //
6
// Author: Reza Ameli                                             //
7
//         Digital Systems Lab                                    //
8
//         Ferdowsi University of Mashhad, Iran                   //
9
//         http://commeng.um.ac.ir/dslab                          //
10
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@//
11
//                                                                //
12
// This source file may be used and distributed without           //
13
// restriction provided that this copyright statement is not      //
14
// removed from the file and that any derivative work contains    //
15
// the original copyright notice and the associated disclaimer.   //
16
//                                                                //
17
// This source file is free software; you can redistribute it     //
18
// and/or modify it under the terms of the GNU Lesser General     //
19
// Public License as published by the Free Software Foundation;   //
20
// either version 2.1 of the License, or (at your option) any     //
21
// later version.                                                 //
22
//                                                                //
23
// This source is distributed in the hope that it will be         //
24
// useful, but WITHOUT ANY WARRANTY; without even the implied     //
25
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR        //
26
// PURPOSE. See the GNU Lesser General Public License for more    //
27
// details.                                                       //
28
//                                                                //
29
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@//
30
 
31
module present_encryptor_top(data_o,data_i,data_load,key_load,clk_i);
32
//- Module IOs ----------------------------------------------------------------
33
 
34
output wire[63:0] data_o; // ciphertext will appear here
35
input  wire[79:0] data_i; // plaintext and key must be fed here
36
input  wire clk_i; // clock signal
37
input  wire key_load; // when '1', data_i will loaded into key register
38
input  wire data_load; // when '1', first 64 bits of data_i will be loaded into state register
39
 
40
//- Variables, Registers and Parameters ---------------------------------------
41
 
42
reg  [63 : 0] state; // 64-bit state of the cipher
43
reg  [4  : 0] round_counter; // 5-bit round-counter (from 1 to 31)
44
reg  [79 : 0] key; // 80-bit register holding the key and updates of the key
45
 
46
wire [63 : 0] round_key; // 64-bit round-key. The round-keys are derived from the key register
47
wire [63 : 0] sub_per_input; // 64-bit input to the substitution-permutation network
48
wire [63 : 0] sub_per_output; // 64-bit output of the substitution-permutation network
49
wire [79 : 0] key_update_output; // 80-bit output of the keyupdate procedure. This value replaces the value of the key register
50
 
51
//- Instantiations ------------------------------------------------------------
52
 
53
sub_per present_cipher_sp(.data_o(sub_per_output),.data_i(sub_per_input));
54
    // instantion of  substitution and permutation module
55
    // this module is used 31 times iteratively
56
 
57
key_update present_cipher_key_update(.data_o(key_update_output),.data_i(key),.round_counter(round_counter));
58
    // instantiation of the key-update procedure
59
    // this module is used 31 times iteratively
60
 
61
//- Continuous Assigments------------------------------------------------------
62
 
63
assign round_key = key[79:16]; // iurrent round-key is the 64 left most bits of the key register
64
 
65
assign sub_per_input = state^round_key; // input to the Substitution-Permutation network is the cipher state xored by the round key
66
 
67
assign data_o = sub_per_input; // the output of the cipher will finally be one of the inputs to the Substitution-Permutation network.
68
                             // output will be valid when round-counter is 31
69
 
70
//- Behavioral Statements -----------------------------------------------------
71
 
72
always @(posedge clk_i)
73
begin
74
    if(key_load) // loading the key
75
    begin
76
        key <= data_i;
77
    end
78
    else if(!key_load) // not loading the key
79
    begin
80
        if(data_load) // loading plaintext
81
        begin
82
            state <= data_i[63:0];
83
            round_counter <= 5'b00001; // round_counter starts from 1 and ends at 31
84
        end
85
        else if(!data_load) // normal operation (neither loading the key nor loading the plaitext)
86
        begin
87
            round_counter <= round_counter + 1'b1; // round counter is increased by one
88
            state <= sub_per_output; // state is updated
89
            key <= key_update_output; // key register is updated
90
        end
91
    end
92
end
93
//-----------------------------------------------------------------------------
94
endmodule

powered by: WebSVN 2.1.0

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