Professional Documents
Culture Documents
Project Repport 24
Project Repport 24
1. INTRODUCTION
1.1 Aim
1.2 Objectives
1.3 Scope of the work
1.4 Problem Formulation
1.5 AES-Encryption and
Decryption Specification
2. LITERATURE SURVEY
3. METHODOLOGY
3.1 Advance encryption process
3.1.1. AES Process
3.2. AES Encryption
3.2.1. Substitution Bytes
3.2.2. Mix Columns
3.2,3. Add Round Key
3.3. AES Decryption
3.3.1. Inverse Substitution Bytes
3.3.2. Inverse Shift Row
3.3.3. Inverse Mix Column
4.
Chapter 1
INTRODUCTION
With worldwide communication of private and confidential data over the computer
networks or the Internet, there is always a possibility of threat to data
confidentiality, data integrity and, also data availability. Data encryption maintains
data confidentiality, integrity and authentication. Information has become of the
most important assets in growing demand of need to store every single importance
of events in everyday life. Messages need to be secured from unauthorized party.
The AES is an iterative algorithm and uses four operations in different rounds,
namely SubBytes, ShiftRows, MixColumns and Key Additions transformations.
SubBytes transformation is done through S-box. S-box is the vital component in
the AES architecture that decides the speed/throughput of the AES. The composite
field arithmetic is more suitable for S-box (substitution) implementation its
hardware optimization for VLSI implementation is very important to reduce the
area and power of the AES architecture.
1.1 Aim
1.2 Objective
The objective criteria is that to get required data, to be encrypted in form text or
images. The secret private key is given to algorithm. Then based on the key the
text or image is encrypted. To decrypt the encrypted image, encrypted data (text) is
given to the algorithm, Then the correct secret key is given, algorithm verify the
secret key, then encrypted data, is decrypted to original form.
The primary goal is to implement AES encryption and decryption for securing
both text and image data.
Implement AES encryption and decryption algorithms for 128-bit key size.
Develop functionalities to encrypt and decrypt both text and image files.
AES is called AES-128, AES-192 and AES-256. This classification depends on the
different key size used for cryptographic process. Those different key sizes are
used to increase the security level. As, the key size increases the security level
increases. Hence, key size is directly proportional to the security level. The input
for AES process is a single block of 128 bits. The processing is carried out in
several number of rounds where it depends on the key length: 16-byte key consists
of 10 rounds, 24 byte key consists of 12 rounds, and 32 byte key consists of 14
rounds. The first round of encryption process consists of four distinct
transformation functions:
Substitution Bytes
ShiftRows
MixColumns
AddRoundKey
The final round consists of only three transformations ignoring MixColumns. The
Decryption method is the reverse of encryption and it consists of four
transformations.
Inverse ShiftRows
Inverse MixColumns
AddRoundKey
Chapter 2
LITERATURE SURVEY
The paper provides an overview of the AES algorithm and its significance in
cryptography, particularly in securing sensitive information. AES, adopted by the
U.S. government, offers robust protection against various forms of attacks,
ensuring data confidentiality and integrity. The method employs symmetric key
encryption, where both parties involved in communication share the same secret
key.
The document elaborates on the encryption and decryption processes using AES
for text files, images, and audio files, employing OpenSSL commands. Time
measurements are included to assess the execution efficiency of these operations.
The results demonstrate that text file encryption takes the longest time, followed
by images and audio files. Additionally, decryption generally consumes more time
compared to encryption.
METHODOLOGY
The characteristics of AES algorithm are Uses common (Symmetric) key and so, It
is called as Symmetric block cipher. The size of data is 128 bits, and so the key
size varies from 128/192/256 bits. It is highly robust and 6 times faster than 3-DES
and much faster and powerful than RSA. It uses single S-box for all rounds rather
than DES, where it uses eight Sboxes. The process involved in AES is iterative
when compared with Feistel cipher. AES is generally based on Substitution and
Permutations operations.
The 16 bytes which is produced from MixColumns is equal to 128 bits which is
XORed with the round key of 128 bits. The above process has been repeated until
final round to produce the corresponding cipher text.
3.3 AES Decryption
IMPLIMENTATION
The AES decryption is an inverse of encryption process. The below figure shows
the decryption process. The decryption process takes the cipher-image (or) cipher-
text as input and it performs the four transformations (i.e.) Inverse subbytes,
Inverse Shiftrows, Inverse Mixcolumns and Addroundkey until 9 rounds and the
10th round performs three transformation ignoring Inverse Mixcolumns.The
output of decryption process will produce the original image to the receiver.
Fig.7 AES ENCRYPTION.
Source code:
module AES_TOP(clk,finalout);
input clk;
output [7:0] finalout;
wire [127:0] tempout;
aescipher u1(.clk(clk),.datain(128'h 54776f204f6e65204e696e652054776f),.key(128'h
5468617473206d79204b756e67204675),.dataout(tempout));
assign finalout = tempout[127:120];
endmodule.
module AES_TB;
Inputs reg clk;
Outputs wire [7:0] finalout;
Instantiate the Unit Under Test (UUT)
AES_TOP uut (clk(clk),finalout(finalout));
initial begin
clk = 0;
#100;
end
endmodule
module aescipher(clk,datain,key,dataout);
input clk;
input [127:0] datain;
input [127:0] key;
output[127:0] dataout;
endmodule
module subbytes_tb;
module rounndlast(clk,rc,rin,keylastin,fout);
input clk;
input [3:0]rc;
input [127:0]rin;
input [127:0]keylastin;
output [127:0]fout;
wire [127:0] sb,sr,mcl,keyout;
KeyGeneration t0(rc,keylastin,keyout);
subbytes t1(rin,sb);
shiftrow t2(sb,sr);
assign fout= keyout^sr;
endmodule
module rounndlast_tb;
parameter CLK_PERIOD = 10; // Clock period in ns
reg clk;
reg [3:0] rc;
reg [127:0] rin;
reg [127:0] keylastin;
wire [127:0] fout;
rounndlast dut (.clk(clk), .rc(rc),.rin(rin), .keylastin(keylastin),.fout(fout));
initial begin
clk = 0;
forever #((CLK_PERIOD/2)) clk = ~clk;
end
initial begin
rc = 4'b0000; // Example: Setting rc to 0
rin = 128'h09a2f07b66b1fc3b8b9ae6307865c489; // Example: Setting rin to all zeros
keylastin = 128'h28fddef86da4244accc0a4fe3b316f26; // Example: Setting keylastin to all
zeros
#100; // Wait for a few clock cycles
$display("rc: %h", rc);
$display("rin: %h", rin);
$display("keylastin: %h", keylastin);
$display("fout: %h", fout);
$finish;
end
endmodule
module rounds(clk,rc,data,keyin,keyout,rndout);
input clk;
input [3:0]rc;
input [127:0]data;
input [127:0]keyin;
output [127:0]keyout;
output [127:0]rndout;
wire [127:0] sb,sr,mcl;
KeyGeneration t0(rc,keyin,keyout);
subbytes t1(data,sb);
shiftrow t2(sb,sr);
mixcolumn t3(sr,mcl);
assign rndout= keyout^mcl;
endmodule.
module rounds_tb;
parameter CLK_PERIOD = 10; // Clock period in ns
reg clk;
reg [3:0] rc;
reg [127:0] data;
reg [127:0] keyin;
wire [127:0] keyout;
wire [127:0] rndout;
rounds dut (.clk(clk),.rc(rc), .data(data),.keyin(keyin),keyout(keyout),.rndout(rndout));
initial begin
clk = 0;
forever #((CLK_PERIOD/2)) clk = ~clk;
end
initial begin
rc = 4'b0000; // Example: Setting rc to 0
data = 128'h00000000000000000000000000000000; // Example: Setting data to all zeros
keyin = 128'h00000000000000000000000000000000; // Example: Setting keyin to all zeros
#100; // Wait for a few clock cycles
$display("rc: %h", rc);
$display("data: %h", data);
$display("keyin: %h", keyin);
$display("keyout: %h", keyout);
$display("rndout: %h", rndout);
$finish;
end
endmodule.
module KeyGeneration(rc,key,keyout);
input [3:0] rc;
input [127:0]key;
output [127:0] keyout;
wire [31:0] w0,w1,w2,w3,tem;
assign w0 = key[127:96];
assign w1 = key[95:64];
assign w2 = key[63:32];
assign w3 = key[31:0];
assign keyout[127:96]= w0 ^ tem ^ rcon(rc);
assign keyout[95:64] = w0 ^ tem ^ rcon(rc)^ w1;
assign keyout[63:32] = w0 ^ tem ^ rcon(rc)^ w1 ^ w2;
assign keyout[31:0] = w0 ^ tem ^ rcon(rc)^ w1 ^ w2 ^ w3;
sbox a1(.a(w3[23:16]),.c(tem[31:24]));
sbox a2(.a(w3[15:8]),.c(tem[23:16]));
sbox a3(.a(w3[7:0]),.c(tem[15:8]));
sbox a4(.a(w3[31:24]),.c(tem[7:0]));
function [31:0] rcon;
input [3:0] rc;
case(rc)
4'h0: rcon=32'h01_00_00_00;
4'h1: rcon=32'h02_00_00_00;
4'h2: rcon=32'h04_00_00_00;
4'h3: rcon=32'h08_00_00_00;
4'h4: rcon=32'h10_00_00_00;
4'h5: rcon=32'h20_00_00_00;
4'h6: rcon=32'h40_00_00_00;
4'h7: rcon=32'h80_00_00_00;
4'h8: rcon=32'h1b_00_00_00;
4'h9: rcon=32'h36_00_00_00;
default: rcon=32'h00_00_00_00;
endcase
endfunction
endmodule.
module KeyGeneration_tb;
parameter CLK_PERIOD = 10; // Clock period in ns
reg [3:0] rc;
reg [127:0] key;
wire [127:0] keyout;
KeyGeneration dut ( .rc(rc),.key(key),.keyout(keyout));
reg clk = 0;
always #((CLK_PERIOD/2)) clk = ~clk;
initial begin
rc = 4'b0000; // Example: Setting rc to 0
key = 128'h5468617473206d79204b756e67204675; // Example: Setting key to all zeros
#10; // Wait for a few clock cycles
$display("rc: %h", rc);
$display("key: %h", key);
$display("keyout: %h", keyout);
$finish;
end
endmodule.
module shiftrow_tb;
parameter CLK_PERIOD = 10; // Clock period in ns
reg [127:0] sb;
wire [127:0] sr;
shiftrow dut (.sb(sb), .sr(sr));
reg clk = 0;
always #((CLK_PERIOD/2)) clk = ~clk;
initial begin
sb = 128'h0123456789ABCDEF0123456789ABCDEF; // Example input value
#10; // Wait for a few clock cycles
$display("Input: %h", sb);
#10;
$display("Output: %h", sr);
$finish;
end
endmodule.
module mixcolumn(a,mcl);
input [127:0] a;
output [127:0] mcl;
assign mcl[127:120]= mixcolumn32 (a[127:120],a[119:112],a[111:104],a[103:96]);
assign mcl[119:112]= mixcolumn32 (a[119:112],a[111:104],a[103:96],a[127:120]);
assign mcl[111:104]= mixcolumn32 (a[111:104],a[103:96],a[127:120],a[119:112]);
assign mcl[103:96]= mixcolumn32 (a[103:96],a[127:120],a[119:112],a[111:104]);
assign mcl[95:88]= mixcolumn32 (a[95:88],a[87:80],a[79:72],a[71:64]);
assign mcl[87:80]= mixcolumn32 (a[87:80],a[79:72],a[71:64],a[95:88]);
assign mcl[79:72]= mixcolumn32 (a[79:72],a[71:64],a[95:88],a[87:80]);
assign mcl[71:64]= mixcolumn32 (a[71:64],a[95:88],a[87:80],a[79:72]);
assign mcl[63:56]= mixcolumn32 (a[63:56],a[55:48],a[47:40],a[39:32]);
assign mcl[55:48]= mixcolumn32 (a[55:48],a[47:40],a[39:32],a[63:56]);
assign mcl[47:40]= mixcolumn32 (a[47:40],a[39:32],a[63:56],a[55:48]);
assign mcl[39:32]= mixcolumn32 (a[39:32],a[63:56],a[55:48],a[47:40]);
assign mcl[31:24]= mixcolumn32 (a[31:24],a[23:16],a[15:8],a[7:0]);
assign mcl[23:16]= mixcolumn32 (a[23:16],a[15:8],a[7:0],a[31:24]);
assign mcl[15:8]= mixcolumn32 (a[15:8],a[7:0],a[31:24],a[23:16]);
assign mcl[7:0]= mixcolumn32 (a[7:0],a[31:24],a[23:16],a[15:8]);
function [7:0] mixcolumn32;
input [7:0] i1,i2,i3,i4;
begin
mixcolumn32[7]=i1[6] ^ i2[6] ^ i2[7] ^ i3[7] ^ i4[7];
mixcolumn32[6]=i1[5] ^ i2[5] ^ i2[6] ^ i3[6] ^ i4[6];
mixcolumn32[5]=i1[4] ^ i2[4] ^ i2[5] ^ i3[5] ^ i4[5];
mixcolumn32[4]=i1[3] ^ i1[7] ^ i2[3] ^ i2[4] ^ i2[7] ^ i3[4] ^ i4[4];
mixcolumn32[3]=i1[2] ^ i1[7] ^ i2[2] ^ i2[3] ^ i2[7] ^ i3[3] ^ i4[3];
mixcolumn32[2]=i1[1] ^ i2[1] ^ i2[2] ^ i3[2] ^ i4[2];
mixcolumn32[1]=i1[0] ^ i1[7] ^ i2[0] ^ i2[1] ^ i2[7] ^ i3[1] ^ i4[1];
mixcolumn32[0]=i1[7] ^ i2[7] ^ i2[0] ^ i3[0] ^ i4[0];
end
endfunction
endmodule.
module mixcolumn_tb;
parameter CLK_PERIOD = 10; // Clock period in ns
reg [127:0] a;
wire [127:0] mcl;
mixcolumn dut ( .a(a),.mcl(mcl));
reg clk = 0;
always #((CLK_PERIOD/2)) clk = ~clk;
initial begin
a = 128'h0123456789ABCDEF0123456789ABCDEF; // Example input value
#10; // Wait for a few clock cycles
$display("Input: %h", a);
#10;
$display("Output: %h", mcl);
$finish;
end
endmodule
module sbox(a,c);
input [7:0] a;
output [7:0] c;
reg [7:0] c;
always @(a)
case (a)
8'h00: c=8'h63;
8'h01: c=8'h7c;
8'h02: c=8'h77;
8'h03: c=8'h7b;
8'h04: c=8'hf2;
8'h05: c=8'h6b;
8'h06: c=8'h6f;
8'h07: c=8'hc5;
8'h08: c=8'h30;
8'h09: c=8'h01;
8'h0a: c=8'h67;
8'h0b: c=8'h2b;
8'h0c: c=8'hfe;
8'h0d: c=8'hd7;
8'h0e: c=8'hab;
8'h0f: c=8'h76;
8'h10: c=8'hca;
8'h11: c=8'h82;
8'h12: c=8'hc9;
8'h13: c=8'h7d;
8'h14: c=8'hfa;
8'h15: c=8'h59;
8'h16: c=8'h47;
8'h17: c=8'hf0;
8'h18: c=8'had;
8'h19: c=8'hd4;
8'h1a: c=8'ha2;
8'h1b: c=8'haf;
8'h1c: c=8'h9c;
8'h1d: c=8'ha4;
8'h1e: c=8'h72;
8'h1f: c=8'hc0;
8'h20: c=8'hb7;
8'h21: c=8'hfd;
8'h22: c=8'h93;
8'h23: c=8'h26;
8'h24: c=8'h36;
8'h25: c=8'h3f;
8'h26: c=8'hf7;
8'h27: c=8'hcc;
8'h28: c=8'h34;
8'h29: c=8'ha5;
8'h2a: c=8'he5;
8'h2b: c=8'hf1;
8'h2c: c=8'h71;
8'h2d: c=8'hd8;
8'h2e: c=8'h31;
8'h2f: c=8'h15;
8'h30: c=8'h04;
8'h31: c=8'hc7;
8'h32: c=8'h23;
8'h33: c=8'hc3;
8'h34: c=8'h18;
8'h35: c=8'h96;
8'h36: c=8'h05;
8'h37: c=8'h9a;
8'h38: c=8'h07;
8'h39: c=8'h12;
8'h3a: c=8'h80;
8'h3b: c=8'he2;
8'h3c: c=8'heb;
8'h3d: c=8'h27;
8'h3e: c=8'hb2;
8'h3f: c=8'h75;
8'h40: c=8'h09;
8'h41: c=8'h83;
8'h42: c=8'h2c;
8'h43: c=8'h1a;
8'h44: c=8'h1b;
8'h45: c=8'h6e;
8'h46: c=8'h5a;
8'h47: c=8'ha0;
8'h48: c=8'h52;
8'h49: c=8'h3b;
8'h4a: c=8'hd6;
8'h4b: c=8'hb3;
8'h4c: c=8'h29;
8'h4d: c=8'he3;
8'h4e: c=8'h2f;
8'h4f: c=8'h84;
8'h50: c=8'h53;
8'h51: c=8'hd1;
8'h52: c=8'h00;
8'h53: c=8'hed;
8'h54: c=8'h20;
8'h55: c=8'hfc;
8'h56: c=8'hb1;
8'h57: c=8'h5b;
8'h58: c=8'h6a;
8'h59: c=8'hcb;
8'h5a: c=8'hbe;
8'h5b: c=8'h39;
8'h5c: c=8'h4a;
8'h5d: c=8'h4c;
8'h5e: c=8'h58;
8'h5f: c=8'hcf;
8'h60: c=8'hd0;
8'h61: c=8'hef;
8'h62: c=8'haa;
8'h63: c=8'hfb;
8'h64: c=8'h43;
8'h65: c=8'h4d;
8'h66: c=8'h33;
8'h67: c=8'h85;
8'h68: c=8'h45;
8'h69: c=8'hf9;
8'h6a: c=8'h02;
8'h6b: c=8'h7f;
8'h6c: c=8'h50;
8'h6d: c=8'h3c;
8'h6e: c=8'h9f;
8'h6f: c=8'ha8;
8'h70: c=8'h51;
8'h71: c=8'ha3;
8'h72: c=8'h40;
8'h73: c=8'h8f;
8'h74: c=8'h92;
8'h75: c=8'h9d;
8'h76: c=8'h38;
8'h77: c=8'hf5;
8'h78: c=8'hbc;
8'h79: c=8'hb6;
8'h7a: c=8'hda;
8'h7b: c=8'h21;
8'h7c: c=8'h10;
8'h7d: c=8'hff;
8'h7e: c=8'hf3;
8'h7f: c=8'hd2;
8'h80: c=8'hcd;
8'h81: c=8'h0c;
8'h82: c=8'h13;
8'h83: c=8'hec;
8'h84: c=8'h5f;
8'h85: c=8'h97;
8'h86: c=8'h44;
8'h87: c=8'h17;
8'h88: c=8'hc4;
8'h89: c=8'ha7;
8'h8a: c=8'h7e;
8'h8b: c=8'h3d;
8'h8c: c=8'h64;
8'h8d: c=8'h5d;
8'h8e: c=8'h19;
8'h8f: c=8'h73;
8'h90: c=8'h60;
8'h91: c=8'h81;
8'h92: c=8'h4f;
8'h93: c=8'hdc;
8'h94: c=8'h22;
8'h95: c=8'h2a;
8'h96: c=8'h90;
8'h97: c=8'h88;
8'h98: c=8'h46;
8'h99: c=8'hee;
8'h9a: c=8'hb8;
8'h9b: c=8'h14;
8'h9c: c=8'hde;
8'h9d: c=8'h5e;
8'h9e: c=8'h0b;
8'h9f: c=8'hdb;
8'ha0: c=8'he0;
8'ha1: c=8'h32;
8'ha2: c=8'h3a;
8'ha3: c=8'h0a;
8'ha4: c=8'h49;
8'ha5: c=8'h06;
8'ha6: c=8'h24;
8'ha7: c=8'h5c;
8'ha8: c=8'hc2;
8'ha9: c=8'hd3;
8'haa: c=8'hac;
8'hab: c=8'h62;
8'hac: c=8'h91;
8'had: c=8'h95;
8'hae: c=8'he4;
8'haf: c=8'h79;
8'hb0: c=8'he7;
8'hb1: c=8'hc8;
8'hd5: c=8'h03;
8'hd6: c=8'hf6;
8'hd7: c=8'h0e;
8'hd8: c=8'h61;
8'hd9: c=8'h35;
8'hda: c=8'h57;
8'hdb: c=8'hb9;
8'hdc: c=8'h86;
8'hdd: c=8'hc1;
8'hde: c=8'h1d;
8'hdf: c=8'h9e;
8'he0: c=8'he1;
8'he1: c=8'hf8;
8'he2: c=8'h98;
8'he3: c=8'h11;
8'he4: c=8'h69;
8'he5: c=8'hd9;
8'he6: c=8'h8e;
8'he7: c=8'h94;
8'he8: c=8'h9b;
8'he9: c=8'h1e;
8'hea: c=8'h87;
8'heb: c=8'he9;
8'hec: c=8'hce;
8'hed: c=8'h55;
8'hee: c=8'h28;
8'hef: c=8'hdf;
8'hf0: c=8'h8c;
8'hf1: c=8'ha1;
8'hf2: c=8'h89;
8'hf3: c=8'h0d;
8'hf4: c=8'hbf;
8'hf5: c=8'he6;
8'hf6: c=8'h42;
8'hf7: c=8'h68;
8'hf8: c=8'h41;
8'hf9: c=8'h99;
8'hfa: c=8'h2d;
8'hfb: c=8'h0f;
8'hfc: c=8'hb0;
8'hfd: c=8'h54;
8'hfe: c=8'hbb;
8'hff: c=8'h16;
endcase
8'hb2: c=8'h37;
8'hb3: c=8'h6d;
8'hb4: c=8'h8d;
8'hb5: c=8'hd5;
8'hb6: c=8'h4e;
8'hb7: c=8'ha9;
8'hb8: c=8'h6c;
8'hb9: c=8'h56;
8'hba: c=8'hf4;
8'hbb: c=8'hea;
8'hbc: c=8'h65;
8'hbd: c=8'h7a;
8'hbe: c=8'hae;
8'hbf: c=8'h08;
8'hc0: c=8'hba;
8'hc1: c=8'h78;
8'hc2: c=8'h25;
8'hc3: c=8'h2e;
8'hc4: c=8'h1c;
8'hc5: c=8'ha6;
8'hc6: c=8'hb4;
8'hc7: c=8'hc6;
8'hc8: c=8'he8;
8'hc9: c=8'hdd;
8'hca: c=8'h74;
8'hcb: c=8'h1f;
8'hcc: c=8'h4b;
8'hcd: c=8'hbd;
8'hce: c=8'h8b;
8'hcf: c=8'h8a;
8'hd0: c=8'h70;
8'hd1: c=8'h3e;
8'hd2: c=8'hb5;
8'hd3: c=8'h66;
8'hd4: c=8'h48;
8'hd5: c=8'h03;
8'hd6: c=8'hf6;
8'hd7: c=8'h0e;
8'hd8: c=8'h61;
8'hd9: c=8'h35;
8'hda: c=8'h57;
8'hdb: c=8'hb9;
8'hdc: c=8'h86;
8'hdd: c=8'hc1;
8'hde: c=8'h1d;
8'hdf: c=8'h9e;
8'he0: c=8'he1;
8'he1: c=8'hf8;
8'he2: c=8'h98;
8'he3: c=8'h11;
8'he4: c=8'h69;
8'he5: c=8'hd9;
8'he6: c=8'h8e;
8'he7: c=8'h94;
8'he8: c=8'h9b;
8'he9: c=8'h1e;
8'hea: c=8'h87;
8'heb: c=8'he9;
8'hec: c=8'hce;
8'hed: c=8'h55;
8'hee: c=8'h28;
8'hef: c=8'hdf;
8'hf0: c=8'h8c;
8'hf1: c=8'ha1;
8'hf2: c=8'h89;
8'hf3: c=8'h0d;
8'hf4: c=8'hbf;
8'hf5: c=8'he6;
8'hf6: c=8'h42;
8'hf7: c=8'h68;
8'hf8: c=8'h41;
8'hf9: c=8'h99;
8'hfa: c=8'h2d;
8'hfb: c=8'h0f;
8'hfc: c=8'hb0;
8'hfd: c=8'h54;
8'hfe: c=8'hbb;
8'hff: c=8'h16;
endcase
endmodule
module sbox_tb;
parameter CLK_PERIOD = 10; // Clock period in ns
reg [7:0] a;
reg i;
wire [7:0] c;
sbox dut (.a(a),.c(c));
reg clk = 0;
always #((CLK_PERIOD/2)) clk = ~clk;
reg [7:0] test_values [0:255];
initial begin
for (i = 0; i < 256; i = i + 1) begin
test_values[i] = 8'h00;
end
end
initial begin
for (i = 0; i < 256; i = i + 1) begin
a = test_values[i];
#10; // Wait for a few clock cycles
$display("Input: %h", a);
$display("Output: %h", c);
end
$finish;
end
endmodule.
REPORTS:
Synthesis report:
Area report
Power report
Timing report
5.2 AES Decryption
Source code:
module AES(enable, e128, d128);
output wire e128;
output wire d128;
input enable;
wire[127:0] in = 128'h29c3505f571420f6402299b31a02d73a;
wire[127:0] key128 = 128'h5468617473206d79204b756e67204675;
wire[127:0] encrypted128;
wire[127:0] decrypted128;
AES_Decrypt a2(encrypted128,key128,decrypted128);
assign d128 = (decrypted128 == in && enable) ? 1'b1 : 1'b0;
endmodule
module AES_tb();
wire e128;
wire d128;
reg enable;
AES a(enable,e128,d128);
initial begin
$monitor("Encrypt128 = %b,Decrypt128 = %b",e128,d128);
enable = 1;
#10;
enable = 0;
#10;
enable = 1;
#10;
end
endmodule
module inverseSubBytes(in,out);
input [127:0] in;
output [127:0] out;
genvar i;
generate
for(i=0;i<128;i=i+8) begin :sub_Bytes
inverseSbox s(in[i +:8],out[i +:8]);
end
endgenerate
endmodule
module inverseSubBytes_tb;
reg [127:0] in;
wire [127:0]out;
inverseSubBytes isb(in,out);
initial begin
$monitor("input= %h ,output= %h",in,out);
in=128'h29c3505f571420f6402299b31a02d73a;
#10;
$finish;
end
endmodule
module inverseShiftRows_tb;
reg [127:0] in;
wire [127:0] out;
inverseShiftRows m (in,out);
initial begin
$monitor("input= %H , output= %h",in,out);
in = 128'h29c3505f571420f6402299b31a02d73a;
#100;
end
endmodule
module addRoundkey_tb;
reg [127:0] in;
reg [127:0] key;
wire [127:0] out;
addRoundKey m (in, out, key);
initial begin
$monitor("input= %H, output= %h, key = %h", in, out, key);
in = 128'h29c3505f571420f6402299b31a02d73a;
key = 128'h5468617473206d79204b756e67204675;
#100;
end
endmodule
module inverseMixColumns(state_in,state_out);
input [127:0] state_in;
output [127:0] state_out;
function[7:0] multiply(input [7:0]x,input integer n);
integer i;
begin
for(i=0;i<n;i=i+1)begin
if(x[7] == 1) x = ((x << 1) ^ 8'h1b);
else x = x << 1;
end
multiply=x;
end
endfunction
function [7:0] mb0e; //multiply by {0e}
input [7:0] x;
begin
mb0e=multiply(x,3) ^ multiply(x,2)^ multiply(x,1);
end
endfunction
function [7:0] mb0d; //multiply by {0d}
input [7:0] x;
begin
mb0d=multiply(x,3) ^ multiply(x,2)^ x;
end
endfunction
function [7:0] mb0b; //multiply by {0b}
input [7:0] x;
begin
mb0b=multiply(x,3) ^ multiply(x,1)^ x;
end
endfunction
function [7:0] mb09; //multiply by {09}
input [7:0] x;
begin
mb09=multiply(x,3) ^ x;
end
endfunction
genvar i;
generate
for(i=0;i< 4;i=i+1) begin : m_col
end
endgenerate
endmodule
module inverseMixColumns_tb;
reg [0:127] in;
wire [0:127] out;
inverseMixColumns m (in,out);
initial begin
$monitor("input= %H , output= %h",in,out);
in= 128'h29c3505f571420f6402299b31a02d73a;
#10;
end
endmodule.
module AES_Decrypt_tb;
reg [127:0] in1;
wire [127:0] out1;
reg [127:0] key1;
AES_Decrypt a(in1,key1,out1);
initial begin
$monitor("in128= %h, key128= %h ,out128= %h",in1,key1,out1);
in1=128'h29c3505f571420f6402299b31a02d73a;
key1=128'h5468617473206d79204b756e67204675;
#10;
end
endmodule.
Reports:
5.3.Implementation of Text and Image Encryption and
Decryption using Python code:
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
def main():
# Generate a random 128-bit (16-byte) key
key = get_random_bytes(16)
# Message to be encrypted
message = "secret message"
# Encryption
ciphertext, iv = encrypt_message(message, key)
print("Encrypted:", ciphertext.hex())
# Decryption
decrypted_message = decrypt_message(ciphertext, iv, key)
print("Decrypted:", decrypted_message)
if __name__ == "__main__":
main()
Certainly! Let’s break down the provided Python code for AES (Advanced Encryption
Standard) encryption and decryption using the CBC (Cipher Block Chaining) mode.
AES Overview:
AES is a symmetric encryption algorithm that operates on fixed-size blocks of data (usually
128 bits or 16 bytes).
It uses a secret key to encrypt and decrypt data.
CBC mode is more secure than ECB (Electronic Code Book) mode because it introduces
diffusion (spreading out the influence of one plaintext block over multiple ciphertext blocks).
Code Explanation:
The code imports necessary modules from the Crypto package.
It defines three functions: encrypt_message, decrypt_message, and main.
encrypt_message Function:
Takes two arguments: message (the data to be encrypted) and key (the secret key).
Creates an AES cipher object in CBC mode with a random initialization vector (IV).
Pads the plaintext message to a multiple of the block size (16 bytes) using PKCS7 padding.
Encrypts the padded plaintext using the AES cipher.
Returns the ciphertext and the IV.
decrypt_message Function:
Takes three arguments: ct_bytes (the encrypted data), iv (the initialization vector), and key.
Creates an AES cipher object with the same key and IV in CBC mode.
Decrypts the ciphertext using the AES cipher.
Removes the padding to obtain the original plaintext.
Returns the decrypted data.
main Function:
Generates a random 128-bit key (key) using get_random_bytes(16).
Sets the plaintext message to "secret message".
Calls the encrypt_message function to encrypt the message.
Calls the decrypt_message function to decrypt the ciphertext back to the original plaintext.
Prints the results.
Important Notes:
Initialization Vector (IV): The IV is crucial for CBC mode. It ensures that identical plaintext
blocks result in different ciphertext blocks.
Padding: PKCS7 padding ensures that the plaintext is a multiple of the block size.
Security Considerations: While CBC mode is more secure than ECB, it still has
vulnerabilities (such as padding oracle attacks). For stronger security, consider using
authenticated encryption modes like GCM (Galois/Counter Mode).
Remember to handle keys and IVs securely, and choose the appropriate mode based on your
use case. If you have any further questions, feel free to ask! 👍
The Cipher Block Chaining (CBC) mode is a typical block cipher mode of operation using
block cipher algorithm. In this version, we provide Data Encryption Standard (DES) and
Advanced Encryption Standard (AES) processing ability, the cipherkey length for DES
should be 64 bits, and 128/192/256 bits for AES.
IMAGE PROCESSING:
#!/usr/bin/env python
# ----------------- Header Files ---------------------#
import sys
import random
import argparse
import logging
from tkinter import * # Changed from Tkinter to tkinter for Python 3
from tkinter import filedialog # Changed from tkFileDialog to filedialog for
Python 3
from tkinter import messagebox # Changed from tkMessageBox to messagebox for
Python 3
import os
from PIL import Image
import math
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
from tkinter import Tk, Button, LEFT, RIGHT, Entry, Label, Message, Canvas
import hashlib
import binascii
import numpy as np
global password
def load_image(name):
return Image.open(name)
return new_secret_image
return ciphered_image
return new_image
#------------------------Encryption -------------------#
def level_one_encrypt(Imagename):
message_image = load_image(Imagename)
size = message_image.size
width, height = size
secret_image = generate_secret(size)
secret_image.save("secret.jpeg")
im = Image.open(imagename)
pix = im.load()
width = im.size[0]
height = im.size[1]
# break up the image into a list, each with pixel values and then append
to a string
for y in range(0, height):
for x in range(0, width):
print(pix[x, y])
plaintext.append(pix[x, y])
print(width)
print(height)
# add 100 to each tuple value to make sure each are 3 digits long.
for i in range(0, len(plaintext)):
for j in range(0, 3):
aa = int(plaintext[i][j]) + 100
plaintextstr += str(aa).encode()
# encrypt plaintext
obj = AES.new(password, AES.MODE_CBC, b'This is an IV456')
ciphertext = obj.encrypt(plaintextstr)
try:
# Open the encrypted file in binary mode
with open(ciphername, 'rb') as cipher_file:
ciphertext = cipher_file.read()
except Exception as e:
print("Error during decryption:", e)
# GUI stuff
def pass_alert():
messagebox.showinfo("Password Alert", "Please enter a password.")
def image_open():
global file_path_e
enc_pass = passg.get()
if enc_pass == "":
pass_alert()
else:
password = hashlib.sha256(enc_pass.encode()).digest()
filename = filedialog.askopenfilename()
file_path_e = os.path.dirname(filename)
encrypt(filename, password)
def cipher_open():
global file_path_d
dec_pass = passg.get()
if dec_pass == "":
pass_alert()
else:
password = hashlib.sha256(dec_pass.encode()).digest()
filename = filedialog.askopenfilename()
file_path_d = os.path.dirname(filename)
decrypt(filename, password)
class App:
def __init__(self, master):
global passg
title = "Image Encryption"
author = "Made by Aditya"
msgtitle = Message(master, text=title)
msgtitle.config(font=('helvetica', 17, 'bold'), width=200)
msgauthor = Message(master, text=author)
msgauthor.config(font=('helvetica', 10), width=200)
canvas_width = 200
canvas_height = 50
w = Canvas(master,
width=canvas_width,
height=canvas_height)
msgtitle.pack()
msgauthor.pack()
w.pack()
# Main function
root = Tk()
root.wm_title("Image Encryption")
app = App(root)
root.mainloop()
name__ == "__main__":
RESULTS:
Chapter 6
6.1.CONCLUSION
The proposed work makes use of AES algorithm to encrypt and decrypt the image
and text. It makes use of 128 bit key for encryption which makes AES secure and
faster than DES.As the key size is larger, it helps to overcome several attacks such
as brute force attack and man in the middle attack. In our proposed system,
encryption image doesn’t remain the same. The encryption image is chosen in
random. So, it is difficult for intruder to differentiate the encrypted image and the
original image. So, AES algorithm is most suited for image encryption in real time
applications. As a future work, we are planning for a different encryption keys in
each round to perform encryption.
The proposed work makes use of AES algorithm to encrypt and decrypt the image
and text. It makes use of 128 bit key for encryption which makes AES secure and
faster than DES.As the key size is larger, it helps to overcome several attacks such
as brute force attack and man in the middle attack. In our proposed system,
encryption image doesn’t remain the same. The encryption image is chosen in
random. So, it is difficult for intruder to differentiate the encrypted image and the
original image. So, AES algorithm is most suited for image encryption in real time
applications. As a future work, we are planning for a different encryption keys in
each round to perform encryption.
6.2FUTURE SCOPE: