Vous êtes sur la page 1sur 26

DATA ENCRYPTION STANDARD (DES)

by Engr. Khurram Hashmi

Cryptography

Block Ciphers

Block of plain Text Size: (M)

Cipher Encryption Algorithm

Block of cipher Text Size : (M)

Secret key

Background

The Data Encryption Standard (DES) is a block cipher that uses shared secret encryption. It was selected by the National Bureau of Standards as an official Federal Information Processing Standard (FIPS) for the United States in 1976 Has subsequently enjoyed widespread use internationally. The algorithm was initially controversial because of classified design elements DES consequently came under intense academic analysis which motivated the modern understanding of block ciphers and their cryptanalysis.

Shortfalls

DES is now considered to be insecure for many applications. Chiefly due to the 56-bit key size being too small. The basic method of attack is brute force trying every possible key in turn. The length of the key determines the number of possible keys. DES has a small key size 56-bits and this approach is feasible for breaking it Questions were raised about the adequacy of DES key size even before it was adopted as a standard, and it was the small key size, rather than theoretical cryptanalysis, which dictated a need for a replacement algorithm

Data Encryption Standard

It is a block Cipher
plain Text 64 bit blocks N Blocks Cipher Encryption Algorithm 16 cycles Cipher Text 64 bit blocks N Blocks

Secret key 64 bits

56 bits used

Data is encrypted block by block i.e. 64 bits each time

Encryption Algorithm
32bit

32bit

Data is processed as 32 bit half-blocks Takes 16 rounds to complete In each round, a new subkey from the key scheduler is utilized Data is swapped after each round except the last Initial and final permutations are Inverses of each other

48 bit Subkey 48 bit Subkey

XOR

Structure

Main {
Initial

Permutation ( ) Left , Right Breaking ( ) Main algorithm 16 cycles ( ) Left Right re-combination( ) Final Permutation ( )

Expansion & key XOR ( ) S-Box compression & P-Box ( )

cnv ( ) cnv4( )

Structure

Binary Input One Dimensional arrays.


1 2 3 4 5 6 ... ... ... N

For loops While loops Function calling Sub function calling

Main
B=P1(A); [l,r]=LR(B);

Script file

A=round(rand(1,64))

64 elements (random) 64 elements (permuted)

32 elements

32 elements

[l,r]= mnalgo(l,r);
16 cycles

C=LRbk(l,r); D=P2(C)

Expansion key XOR Compression (S-Box) P-Box L R

64 element final permt 64 element (cipher text)

Initial Permutation: P1( )


function [b]= P1(a)
Shif=[58 50 42 34 26 18 10 2; 60 52 44 36 28 20 12 4; 62 54 46 38 30 22 14 6; 64 56 48 40 32 24 16 8; 57 49 41 33 25 17 9 1; 59 51 43 35 27 19 11 3; 61 53 45 37 29 21 13 5; 63 55 47 39 31 23 15 7;]; l=1; % extra counter %rows %columns % extra counter increment

a original array

58

64

58
b shifting / swapping

for i= 1:8,

for j= 1:8, l=l+1; end end

b(1,l)=a(1,Shif(i,j)); %the actual guided shifting

b shifted / swapped array 58 50 42 34 26 . . . . 7

16 cycles: Main algorithm ( ) l


R function[l,r]= mnalgo(l,r)
cnt=0; L=l; R=E(r); R=S(R); l=r; r=L; cnt=cnt+1; %counter intialization while cnt<16, %32 bits %48 bit output %32 bit output %orig right in left %XORed left in right

L swap l r

L=xor(L,R);

end
cnt %counter display

Left Right Breaking: LR( )


function[l,r]=LR(c) l(1,1:32)=c(1,1:32); %the first 32 of the input elements

r(1,1:32)=c(1,33:64); %the next 32 of the input elements

1.64

left 1.32

right 33..64

Feistel function

Expansion 48 bit data XOR The S-Boxes Non Linear Transformation 4-bit output Enables Swap 6-bit input

32 bit Data Output

Expansion and key XOR ( )


function [b]= E(a) Ex=[32 1 2 3 4 5;

4 5 6 7 8 9;
8 9 10 11 12 13; 12 13 14 15 16 17; 16 17 18 19 20 21; 20 21 22 23 24 25;

Duplication of two columns 1 2 .. . .. 32

Expansion Table

24 25 26 27 28 29;
26 29 30 31 32 1;]; l=1; %extra variable %rows %columns for j= 1:6, for i= 1:8,

32

32

b(1,l)=a(1,Ex(i,j)); end end

%the actual guided shifting

l=l+1; %extra increment

Expansion and key XOR (b)


key=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 0 0 0 0 0 1 1 0 0 1 1 0 1 0 0 0]; %48 bitkey b= xor (b,key); 1 2 3 1 48 1 1 0 key 1

Expanded array

XOR

48

S-Box Compression
function
[b]= S(a) % where a is a 48 element binary array

t=[14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 7;
0 15 7 4 14 2 13 1 10 6 12 11 9 5 3 8; 4 1 14 8 13 6 2 11 15 12 9 7 3 10 5 0; 15 12 8 2 4 9 1 7 5 11 3 14 10 0 6 14]; %S-box Table

S-Box Compression
6bit 6bit 6bit temp cnv( ) cnv4( ) Binary to decimal 1001 9 Decimal to Binary 4bit 32 bit 6bit 48 bit

011011 01

+1 1 rows ref S-Box Table

1101

13 columns 4 bit Replacement element

S-Box Look up table


Non Linear Transformation
Middle 4 bits of input
S5 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 00 0010 1100 0100 0001 0111 1010 1011 0110 1000 0101 0011 1111 1101 0000 1110 1001

Outer bits

01
10 11

1110 1011 0010 1100 0100 0111 1101 0001 0101 0000 1111 1010 0011 1001 1000 0110
0100 0010 0001 1011 1010 1101 0111 1000 1111 1001 1100 0101 0110 0011 0000 1110 1011 1000 1100 0111 0001 1110 0010 1101 0110 1111 0000 1001 1010 0100 0101 0011

Input: 011011

Output: 1001

S-Box: While loop


i=1; j=1; l=1; cn=1; %initializing counters while i<=8, j=l+5; % rows temp= a(l:j); rw=temp(1,1); rw(1,2)=temp(1,6); rw=cnv(rw); %2-bit bin to dec conversion rw=rw+1; %because of 0th loction logic %columns col=temp(2:5); col=cnv4(col); %4-bit bin to dec conversion col=col+1; %because of 0th location logic %reference table ref= t(rw,col); %reference table index rp=(dec2bin(ref,4)-48); %replacement element c(1,cn:(cn+3))=rp(1,1:4); cn=cn+4; i=i+1; %main counter l=l+6;

l i 6 bit

temp rw (bin) rw (dec) col (bin) col (dec)

ref (rw,col)

4 bit output 4bit

end

P-Box permutation
%P-Box permutation
P=[16 7 20 21 29 12 28 17 1 15 23 26 5 18 31 10; 2 8 24 14 32 27 3 9 19 13 30 6 22 11 4 25]; % P-box table l=1; % extra counter %rows %columns % extra counter increment for j= 1:16, l=l+1; end end for i= 1:2,

b(1,l)=c(1,P(i,j)); %the actual guided shifting

32 bit Array

P-Box permuted array

Final Permutation: P2( )


function [b]= P2(a)
ip= [58 50 42 34 26 18 10 2; 60 52 44 36 28 20 12 4; 62 54 46 38 30 22 14 6; 64 56 48 40 32 24 16 8; 57 49 41 33 25 17 9 1; 59 51 43 35 27 19 11 3; 61 53 45 37 29 21 13 5; 63 55 47 39 31 23 15 7;]; The initial permutation table

58

50

42

34

26

18

10

Generating a reverse permutation array that reverses the initial permutation

c=1; for x= 1:64 l=1;

Final Permutation: P2( )


58 Initial permutation table 50 y

for i= 1:8, for j= 1:8,

if ip(i,j) = = x;
iprev(1,c) =l;
c=c+1;

else
;

end
l=l+1; end end end

Reverse Reference index 7

iprev

%iprev
for j= 1:64, %coloumns % extra counter increment

Reverse permuted array


b(1,j)=a(1,iprev(1,j)); %the actual guided shifting %l=l+1;

end

Binary to Decimal conversion


function[b]=cnv(a) 10
%where a is a 2 bit array c=0000; c=(a(1,1)*10)+c; c= a(1,2)+c; b=int2str(c); b=bin2dec(b);

1 1

c=0000 0010

0011
int2str( ) 0011 bin2dec ( ) 3

Encryption
Cipher Encryption Algorithm 16 cycles

plain Text 64 bit blocks N Blocks

Cipher Text 64 bit blocks N Blocks

Secret key 64 bits

56 bits used

Thank You
Questions are Welcome

Vous aimerez peut-être aussi