aes algorithm implementation

257
A.E.S . ABSTRACT The report deals with AES algorithm and proposes the optimized mode of implementing the same. Various scenarios have been discussed for implementations of the AES algorithm. These comprise of a number of modes of operation, e.g. CBC, ECB, and ICBC, in combination with multithreaded and non threaded architectures. The first algorithm architecture is the implementation under ECB (Electronic Code Book) mode. The second architecture is the implementation in CBC (Cipher Block Chaining) mode. The above discussed modes are also implemented using multi-threading. Next is the multi-threaded version of ICBC (Interleaved Cipher Block Chaining) mode. In this mode first thread acts on the first block with an Initial Vector IV1, the second thread acts on the second block with another Initial Vector IV2, 1

Upload: sarthak-gupta

Post on 24-Mar-2015

106 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: AES Algorithm Implementation

A.E.S.

ABSTRACT

The repor t dea ls wi th AES a lgor i thm and proposes the

opt imized mode of implement ing the same. Var ious scenar ios

have been discussed for implementa t ions of the AES a lgor i thm.

These comprise of a number of modes of opera t ion , e .g . CBC,

ECB, and ICBC, in combinat ion wi th mul t i threaded and non

threaded archi tec tures . The f i rs t a lgor i thm archi tec ture i s the

implementa t ion under ECB (Elec t ronic Code Book) mode. The

second archi tec ture i s the implementa t ion in CBC (Cipher

Block Chaining) mode. The above d iscussed modes are a lso

implemented us ing mul t i - threading. Next i s the mul t i - threaded

vers ion of ICBC (In ter leaved Cipher Block Chaining) mode. In

th is mode f i rs t thread ac ts on the f i rs t b lock wi th an In i t ia l

Vector IV1, the second thread ac ts on the second block wi th

another In i t ia l Vector IV2, and so on. The output of the f i rs t

b lock ac ts as the input for N+1th b lock, where N is the number

of threads used. These modes have been implemented and

tes ted for var ious numbers of threads . The behavior of the

code , w.r . t . execut ion t ime, has been scrut in ized for var ious

threads e .g . 2 ,3 ,6 ,9 ,10,16,20 n more , each thread wi th var ious

f i le s ized inputs , ranging f rom 100 KB to 2 MBs. We conclude

and zero in on the bes t poss ib le approach for implement ing the

AES a lgor i thm, in te rms of memory requi rement and

performance i ssues . The memory requi rement of a l l

1

Page 2: AES Algorithm Implementation

A.E.S.

a rchi tec tures i s presented in the conclus ion. The p la t form used

for a l l the implementa t ion

is JAVA 2. The codes have been developed and tes ted on 32-

bi t , x86 processors , In te l HT™ Processors . The appl ica t ion has

been tes ted on LINUX and WINDOWS environment .

Technical Speci f icat ion

The Advanced Encrypt ion Standard (AES) speci f ies a NIST-

approved cryptographic a lgor i thm tha t can be used to protec t

e lec t ronic da ta . The AES a lgor i thm is a symmetr ic b lock c ipher

tha t can encrypt (encipher) and decrypt (dec ipher) informat ion.

Encrypt ion conver ts da ta to an uninte l l ig ib le form ca l led c ipher

text ; decrypt ing the c ipher text conver ts the da ta back in to i t s

or ig ina l form, ca l led p la in text .

The AES a lgor i thm is capable of us ing cryptographic keys of

128, 192, and 256 bi t s to encrypt and decrypt da ta in b locks of

128 bi t s .

JAVA is a p la teform independent language and i t of fers an

ef f ic ient and opt imized methods to implement AES

2

Page 3: AES Algorithm Implementation

A.E.S.

TABLE OF CONTENTS

CHAPTER NO. TITLE PAGENO.

ABSTRACT 1

LIST OF TABLE 6

LIST OF FIGURES 7

LIST OF SYMBOLS 9

1 INTRODUCTION 10

1 .1 SYMMETRIC KEY CRYPTOGRAPHY 10

1 .2 VARIOUS BLOCK CIPHER TECHNIQUES

1 .2 .1 F IESTAL CIPHER 11

1 .2 .2 DES 13

1 .2 .3 TYPES OF ATTACK ON DES 13

1 .2 .4 TRIPLE DES 14

1 .2 .5 AES 14

1 .2 .6 STRENGHT OF AES 14

1 .2 .7 MULTITHREADING 16

2 PREVIOUS WORK 18

2 . 1 BLOCK CIPHER 18

2 . 2 ATTACK ON BLOCK CIPHERS

2 . 2 .1 B IRTHDAY ATTACK 19

2 . 2 .2 BRUTE FORCE ATTACK 20

2 . 2 .3WEAKKEY 20

2 . 2 .4MEETIN THE MIDDLE 21

2 .3 A.E .S 22

3

Page 4: AES Algorithm Implementation

A.E.S.

3 PROPOSED WORK 24

3 .1 BLOCK CIPHER MODES OF OPERATION

3 . 1 .1ECB 24

3 . 1 .2CBC 26

3 . 2 SOFTWARE REQUIREMENT SPECIFICATION

3 . 2 .1 INTRODUCTION 28

3 . 2 .2 USAGE SCENARIO 29

3 . 2 .3 SOFTWARE INTERFACE DESCRIPTION 30

3 . 2 .4 RESTRICTIONS,LIMITATIONS 31

3 . 3 SOFTWARE DESIGN SPECIFICATION

3 . 3 .1 INTRODUCTION 31

3 . 3 .2 DATADESIGN 32

3 . 3 .3 COMPONENT LEVELDESIGN 33

3 . 3 .3 .1 PROGRAM STRUCTURE 34

3 . 3 .3 .2ARCHITECTUREDIAGRAM 34

3 . 3 .3 .3SOFTWARE INTERFACE 38

3 . 3 .4 USER INTERFACE DESIGN 39

3 . 4 FUNCTIONS DESCRIPTION

3 . 41 . DECRYPTION FUNCTION 40

3 . 4 .2 ENCRYPTION FUNCTION 41

3 . 5 MODULE WISE DESCRIPTION 42

3 . 5 .1 INPUTS AND OUTPUT 42

3 . 5 .2 . SUB-BYTES TRANSFORMATION 42

3 . 5 .3 SHIFT ROW TRANSFORMATION 43

3 . 5 .4 ADD ROUND KEY 44

3 . 5 .5 KEY EXPANSION 45

4

Page 5: AES Algorithm Implementation

A.E.S.

3 . 6 DESIGN

3 .6 .1 SOFTWARE ARCHITECTURE 48

3 . 6 .2 ACTIVITY DIAGRAM 49

3 . 6 .3 . SEQUENCE DAIGRAM 50

3 . 6 .4 FUNCTIONAL BLOCK DIAGRAM 51

3 . 6 .5 STATE TRANSITION DIAGRAM 54

3 . 6 .6 FORM 55

4 RESULT AND ANALYSIS 56

5 CONCLUSION 58

6 FUTURE WORK 62

7 APPENDICES

7 .1 ABOUT JAVA 64

7 . 2 MATHEMATICAL DESCRIPITON 67

7 . 3 CODING 83

7 . 4 TEST CASES 160

8 REFRERENCES 181

9 BIO DATA OF MEMBERS 183

5

Page 6: AES Algorithm Implementation

A.E.S.

LIST OF TABLES

S .NO. TABLE NAME PAGE NO .

1 C IPHER ENCRYPT 76

2 INVERSE CIPHER DECRYPT 78

3 EQUIVALENT INVERSE CIPHER 80

DECRYPT

6

Page 7: AES Algorithm Implementation

A.E.S.

LIST OF FIGURES

SNO. FIGURE NAME PAGE NO.

1 FIESTAL CIPHER 12

2 ECB ENCRYPTION MODE 24

3 ECB DECRYPTION MODE 25

4 IMAGE ENCRYPTION USING E.C.B 25

5 CBC ENCRYPTION MODE 26

6 CBC DECRYPTION MODE 27

7 ARCHITECTURE DIAGRAM 34

8 INTERFACE 39

9 DECRYPTION FUNCTION 40

10 ENCRYPTION FUNCTION 41

11 BYTE SUB 43

12 SHIFT ROWS TRANSFORMATION 44

13 ADD ROUND KEY 45

14 KEY EXPANSION 47

15 ACTIVITY DIAGRAM 49

7

Page 8: AES Algorithm Implementation

A.E.S.

16 SEQUENCE DIAGRAM 50

17 FUNCTIONAL BLOCK DIAGRAM 51

18 STATE TRANSITION DIAGRAM 54

19 ANALYSIS OF THE PROJECT 56

20 ICBC 63

21 ENCRYPTION AND DECRYPTION IN ECB 67

22 ECB MULTI-THREADED ENCRYPTION 67

23 ECB MULTI-THREADED DECRYPTION 68

24 CBC ENCRYPTION 69

25 CBC DECRYPTION 70

26 CBC MULTI-THREADED DECRYPTION 71

8

Page 9: AES Algorithm Implementation

A.E.S.

LIST OF SYMBOLS

S .NO SYMBOLS PAGE NO.

1 E K ,M, E K- 1 19

2 C ,P ,E K 1 ,E K 2 22

3 Nb,Nk,Nr ,Rcon 73

4 PutBytes ,Pr in t ,Copy,Hex 75

5 GetByte 76

.

9

Page 10: AES Algorithm Implementation

A.E.S.

CHAPTER 1

INTRODUCTION

Cryptography     i s the prac t ice and s tudy of h id ing   informat ion.

In modern t imes cryptography i s cons idered a branch of both

mathemat ics   and  computer sc ience  and i s a f f i l ia ted c lose ly

wi th   informat ion theory ,computer secur i ty   and  engineer ing .

Cryptography i s used in appl ica t ions present in technologica l ly

advanced socie t ies ; examples inc lude the secur i ty of  ATM

cards , computer passwords  and  e lec t ronic commerce  which a l l

depend on cryptography.

Symmetric-key cryptography re fers to encrypt ion methods in

which both the sender and rece iver share the same key.The

s tudy of symmetr ic-key c iphers re la tes mainly to the s tudy

of  b lock c iphers   and  s t ream c iphers   and to the i r appl ica t ions . A

block c ipher take as input a b lock of p la in text and a key, and

output a b lock of c ipher text of the same s ize . S ince messages

are a lmost a lways longer than a s ingle b lock, some method of

kni t t ing together success ive b locks are requi red .

The goal of c ryptanalys is i s to f ind some weakness or

insecur i ty in a c ryptographic scheme, thus permi t t ing i t s

subvers ion or evas ion.

There are a wide var ie ty of c ryptanalyt ic a t tacks , and they can

be c lass i f ied in any of severa l ways . A common dis t inc t ion

10

Page 11: AES Algorithm Implementation

A.E.S.

turns on what an a t tacker knows and what capabi l i t ies a re

avai lable . In a  c ipher text -only a t tack , the cryptanalys t has

access only to the c ipher text . In a  known-pla in text a t tack , the

cryptanalys t has access to a c ipher text and i t s corresponding

pla in text . In a  chosen-pla in text a t tack , the cryptanalys t may

choose a p la in text and learn i t s corresponding c ipher text .

F ina l ly , in a  chosen-c ipher text a t tack , the cryptanalys t may be

able to  choose  c ipher texts and learn the i r corresponding

pla in texts .  

VARIOUS BLOCK CIPHER TECHNIQUES

FIESTEL CIPHERS

The diagram shows the general design of a Feistel cipher, a scheme used by

almost all modern block ciphers. The input is broken into two equal size blocks,

generally called left (L) and right (R), which are then repeatedly cycled through

the algorithm. At each cycle, a hash function (f) is applied to the right block and

the key, and the result of the hash is XOR-ed into the left block. The blocks are

then swapped. The XOR-ed result becomes the new right block and the

unaltered right block becomes the left block. The process is then repeated a

number of times.

11

Page 12: AES Algorithm Implementation

A.E.S.

FIESTAL CIPHER

The hash function is just a bit scrambler. The correct operation of the algorithm

is not based on any property of the hash function, other than it be completely

deterministic; i.e, if it's run again with the exact same inputs, identical output

will be produced. To decrypt, the ciphertext is broken into L and R blocks, and

the key and the R block are run through the hash function to get the same hash

result used in the last cycle of encryption; notice that the R block was

unchanged in the last encryption cycle. The hash is then XOR'ed into the L

block to reverse the last encryption cycle, and the process is repeated until all

the encryption cycles have been backed out. The security of a Feistel cipher

depends primarily on the key size and the irreversibility of the hash function.

Ideally, the output of the hash function should appear to be random bits from

which nothing can be determined about the input(s).

12

Page 13: AES Algorithm Implementation

A.E.S.

DATA ENCRYPTION STANDARD(D.E.S)

DES i s the  b lock c ipher  — an a lgor i thm tha t takes a f ixed-

length s t r ing of  p la in text b i t s and t ransforms i t through a ser ies

of compl ica ted opera t ions in to another  c ipher text b i t s t r ing of

the same length . In the case of DES, the  b lock s ize   i s 64 b i t s .

DES a lso uses a  key to cus tomize the t ransformat ion, so tha t

decrypt ion can supposedly only be performed by those who

know the par t icular key used to encrypt . The key os tens ib ly

consis t s of 64 b i t s ; however , only 56 of these are ac tua l ly used

by the a lgor i thm. Eight b i t s a re used sole ly for checking par i ty ,

and are thereaf ter d iscarded. Hence the ef fec t ive  key length   i s

56 b i t s , and i t i s usual ly quoted as such.

There are three attacks known tha t can break the fu l l s ix teen

rounds of DES wi th less complexi ty than a brute- force

search:  d i f ferent ia l c ryptanalys is   (DC),   l inear

c ryptanalys is   (LC) , and  Davies ' a t tack .

Different ia l cryptanalys is   : To break the fu l l 16 rounds ,

d i f ferent ia l c ryptanalys is requi res 2 4 7   chosen p la in texts . DES

was des igned to be res is tant to DC.

Linear cryptanalys is   needs 2 4 3  known pla in texts .There i s no

evidence tha t DES was ta i lored to be res is tant to th is type of

a t tack .

Improved Davies ' at tack : The most powerful form of the

a t tack requi res 2 5 0   known pla in text has a computa t ional

complexi ty of 2 5 0 , and has a 51% success ra te .

13

Page 14: AES Algorithm Implementation

A.E.S.

TRIPLE DES

In Tr ip le DES wi th three independent keys has a key length of

168 bi t s ( three 56-bi t DES keys) , but due to the  meet - in- the-

middle a t tack   the ef fec t ive secur i ty i t provides i s only 112 bi t s .

Keying opt ion 2 , reduces the key s ize to 112 bi t s . However ,

th is opt ion i s suscept ib le to cer ta in  chosen-pla in text or  known-

pla in text   a t tacks  and thus i t i s des ignated by NIST to have

only 80 b i t s of secur i ty .

AES

I t has a f ixed  b lock s ize  of 128  bi t s  and a  key s ize  of 128, 192,

or 256 bi t s , whereas Ri jndael can be speci f ied wi th b lock and

key s izes in any mul t ip le of 32 b i t s , wi th a minimum of 128

bi t s and a maximum of 256 bi t s .AES is fas t in both  

sof tware  and hardware ,   i s re la t ive ly easy to implement , and

requi res l i t t le  memory . Unl ike i t s predecessor DES, AES does

not use a  Feis te l ne twork .

STRENGTH OF AES

A few fac ts should be pointed out about the s t rengths of 2-key

and 3-key TDES, especia l ly in re la t ion to the s t rength of

AES.In a pure ly theore t ica l way, the s t rength of the 3-key

vers ion of TDES may be reduced to the s t rength of the 2-key

vers ion us ing a “meet - in- the-middle” a t tack . Therefore , we may

assume tha t a TDES key i s 112 bi t s and the only way to a t tack

a TDES key i s v ia an exhaust ive search .

14

Page 15: AES Algorithm Implementation

A.E.S.

In order to i l lus t ra te the s t rength of 2-key TDES vis-à-vis

s ingle key DES, assume the fo l lowing:

Suppose a DES Cracker device can break a s ingle length DES

key in 24 hours , then the t ime taken to break a 112-bi t key on

the same DES Cracker device would be approximate ly

200,000,000,000,000 years , longer than the l i fe t ime of the

known universe and probably af ter the solar sys tem has been

devoured by an expanding sun.

Put another way, i f we bui ld a TDES Cracker which i s s imply

1 ,000,000 DES Crackers working in para l le l (cos t ing

approximate ly $250,000,000,000 US dol lars) , then i t wi l l s t i l l

take roughly 200 mi l l ion years to break the key. Of course a

comple te ly new technique may be developed to a t tack TDES,

but then who is to say tha t AES would not a lso be vulnerable to

such an a t tack .

The bot tom l ine i s tha t AES and TDES (2-key and 3-key

vers ions) a re current ly invulnerable to a t tack and are l ike ly to

remain so for some considerable per iod of t ime. There are no

obvious secur i ty reasons for an organiza t ion to upgrade the i r

sys tems f rom TDES to AES a t th is t ime. Fur thermore , many

organiza t ions in the banking and f inancia l a reas are in the

middle of an ext remely expensive projec t to upgrade f rom DES

to TDES and i t i s h ighly unl ike ly tha t such organiza t ions wi l l

wr i te of f th is inves tment . From a secur i ty perspect ive , there i s

p lenty of t ime for organiza t ions to migra te f rom TDES to AES

in a cont ro l led and ef f ic ient manner .

15

Page 16: AES Algorithm Implementation

A.E.S.

MULTITHREADING

A  thread   in  computer sc ience   i s shor t for a   thread of

execut ion . Threads are a way for a  program   to sp l i t i t se l f in to

two or more s imul taneously (or pseudo-s imul taneously)

running   tasks   . Threads and processes  d i f fer f rom one  opera t ing

sys tem   to another but , in genera l , a thread i s conta ined ins ide a

process and di f ferent threads in the same process share some

resources whi le d i f ferent  processes  do not

Multithreading   generally occurs by time-division

multiplexing  ("time slicing") in very much the same way as the

parallel execution of multiple tasks ( computer multitasking):

the processors witches between different threads. This  context

switching can happen so fast as to give the il lusion of

simultaneity to an end user. On a  multiprocessor  or multi-

core  system, threading can be achieved via multiprocessing ,

wherein different threads and processes can run literally

simultaneously on different processors or cores.

This advantage of a mul t i threaded program a l lows i t to opera te

fas ter on  computer sys tems   tha t have mul t ip le  CPUs, CPUs

wi th mul t ip le cores , or across a  c lus ter  of machines . This i s

because the threads of the program natura l ly lend themselves to

t ru ly  concurrent  execut ion . In such a case ,

the  programmer  needs to be careful to avoid   race condi t ions ,

and o ther non- in tu i t ive behaviors .

16

Page 17: AES Algorithm Implementation

A.E.S.

In order for da ta to be correc t ly manipula ted , threads wi l l of ten

need to   rendezvous   in t ime in order to process the da ta in the

correc t order .

Some advantages inc lude:

I f a thread ge ts a lo t of cache misses , the o ther thread(s)

can cont inue , taking advantage of the unused comput ing

resources , which thus can lead to fas ter overa l l execut ion ,

as these resources would have been id le i f only a s ingle

thread was executed .

I f a thread can not use a l l the comput ing resources of the

CPU (because ins t ruc t ions depend on each o ther ' s resul t ) ,

running another thread permi ts to not leave these id le .

I f severa l threads work on the same se t of da ta , they can

ac tua l ly share i t s caching, leading to be t te r cache usage or

synchroniza t ion on i t s va lues .

17

Page 18: AES Algorithm Implementation

A.E.S.

CHAPTER 2

PREVIOUS WORK

BLOCK CIPHER

In cryptography, a b lock c ipher i s a symmetr ic key c ipher

which opera tes on f ixed- length groups of b i t s , te rmed blocks ,

wi th an unvarying t ransformat ion. When encrypt ing , a b lock

c ipher might take ( for example) a 128-bi t b lock of p la in text as

input , and output a corresponding 128-bi t b lock of c ipher text .

The exact t ransformat ion i s cont ro l led us ing a second input —

the secre t key. Decrypt ion i s s imi lar : the decrypt ion a lgor i thm

takes , in th is example , a 128-bi t b lock of c ipher text together

wi th the secre t key, and y ie lds the or ig ina l 128-bi t b lock of

p la in text .

To encrypt messages longer than the b lock s ize (128 bi t s in the

above example) , a mode of opera t ion i s used.

Block c iphers can be cont ras ted wi th s t ream c iphers ; a s t ream

c ipher opera tes on individual d ig i t s one a t a t ime, and the

t ransformat ion var ies dur ing the encrypt ion . The d is t inc t ion

be tween the two types i s not a lways c lear-cut : a b lock c ipher ,

when used in cer ta in modes of opera t ion , ac ts e f fec t ive ly as a

s t ream c ipher .

A block c ipher consis t s of two pai red a lgor i thms, one for

encrypt ion , E , and another for decrypt ion , E-1 . Both a lgor i thms

accept two inputs : an input b lock of s ize n b i t s and a key of

18

Page 19: AES Algorithm Implementation

A.E.S.

s ize k b i t s , y ie ld ing an n-bi t output b lock. For any one f ixed

key, decrypt ion i s the inverse funct ion of encrypt ion , so tha t

for any block M and key K.

For each key K, EK is a permuta t ion (a b i jec t ive mapping) over

the se t of input b locks . Each key se lec ts one permuta t ion f rom

the poss ib le se t of 2n! .

The b lock s ize , n , i s typica l ly 64 or 128 bi t s , a l though some

c iphers have a var iable b lock s ize . 64 b i t s was the most

common length unt i l the mid-1990s , when new des igns began to

swi tch to the longer 128-bi t length . One of severa l modes of

opera t ion i s genera l ly used a long wi th a padding scheme to

a l low pla in texts of a rb i t rary lengths to be encrypted . Each

mode has d i f ferent charac ter i s t ics in regard to er ror

propagat ion , ease of random access and vulnerabi l i ty to cer ta in

types of a t tack . Typica l key s izes (k) inc lude 40, 56 , 64 , 80 ,

128, 192 and 256 bi t s . As of 2006, 80 b i t s i s normal ly taken as

the minimum key length needed to prevent brute force a t tacks .

ATTACK ON BLOCK CIPHERS

Birthday attack

A birthday attack   is a type of  cryptographic  attack,

so named because it exploits

the mathematics  behind the birthday

problem   in probabil i ty theory . Given a function  f , the

goal of the attack is to f ind two inputs  x 1 ,x 2  such

that  f (x 1 ) =   f (x 2 ) . Such a pair  x 1 ,x 2   is cal led a col l is ion .

The method used to f ind a col l is ion is to simply

19

Page 20: AES Algorithm Implementation

A.E.S.

evaluate the function  f   for different input values

that may be chosen randomly or pseudo randomly

unti l the same result is found more than once.

Because of the aforementioned birthday problem

this method can be rather eff icient. Specif ical ly, i f

a function   f (x )yields any of  H  different outputs with

equal probabil i ty and H   is suff iciently large, then we

expect to obtain a pair of different

arguments x 1  and x 2with  f (x 1 ) =   f (x 2 )  after evaluating

the function for about    different arguments

on average.

Brute force attack

In cryptanalysis, a brute force attack is a method of defeating

a cryptographic scheme by systematically trying a large number of possibilities;

for example, a large number of the possible keys in a key space in order to

decrypt a message. In most schemes, the theoretical possibility of a brute force

attack is recognized, but it is set up in such a way that it would be

computationally infeasible to carry out. Accordingly, one definition of

"breaking" a cryptographic scheme is to find a method faster than a brute force

attack.

The selection of an appropriate key length depends on the practical feasibility of

performing a brute force attack. By obfuscating the data to be encoded, brute

force attacks are made less effective as it is more difficult to determine when

one has succeeded in breaking the code.

20

Page 21: AES Algorithm Implementation

A.E.S.

Weak key

In  cryptography , a  weak key   i s a  key  which when used wi th a

speci f ic  c ipher , makes the c ipher behave in some undes i rable

way. Weak keys usual ly represent a very smal l f rac t ion of the

overa l l keyspace , which usual ly means tha t i f one genera tes a

random key to encrypt a message weak keys are very unl ike ly

to g ive r i se to a secur i ty problem. Never the less , i t i s

cons idered des i rable for a c ipher to have no weak keys . A

c ipher wi th no weak keys i s sa id to have a   f la t , or   l inear ,  key

space .

Meet- in-the-middle attack

The Meet-in-the-middle attack is a cryptographic attack which, like

the birthday attack, makes use of a space-time tradeoff. While the birthday

attack attempts to find two values in the domain of a function that map to the

same value in its range, the meet-in-the-middle attack attempts to find a value in

each of the ranges and domains of the composition of two functions such that

the forward mapping of one through the first function is the same as the inverse

image of the other through the second function -- quite literally meeting in the

middle of the composed function.

It was first developed as an attack on an attempted expansion of a block

cipher by Diffie and Hellman in 1977. When trying to improve the security of a

block cipher, one might get the idea to simply use two independent keys to

encrypt the data twice. Naively, one might think that this would square the

security of the double-encryption scheme. Certainly, an exhaustive search of all

possible combination of keys would take 22n attempts if each key is n bits long,

compared to the 2n attempts required for a single key.

21

Page 22: AES Algorithm Implementation

A.E.S.

Diffie and Hellman, however, devised a time-memory tradeoff that could break

the scheme in only double the time to break the single-encryption scheme.[1] The

attack works by encrypting from one end and decrypting from the other end,

thus meeting in the middle.

Assume the attacker knows a set of plaintext and ciphertext: P and C. That is,

,

where E is the encryption function (cipher), and K1 and K2 are the two keys.

The attacker can then compute EK(P) for all possible keys K and store the results

in memory. Afterwards he can decrypt the ciphertext by computing DK(C) for

each K. Any matches between these two resulting sets are likely to reveal the

correct keys. (To speed up the comparison, the EK(P) set is stored in an in-

memory lookup table, then each DK(C) can be matched against the values in the

lookup table to find the candidate keys.)

Once the matches are discovered, they can be verified with a second test-set of

plaintext and ciphertext. If the keysize is n, this attack uses only2n + 1encryptions

(and O(2n) space) in contrast to the naive attack, which needs 22n encryptions

(but only O(1) space).

AES

The Advanced Encrypt ion Standard (AES) i s a NIST s tandard ,

FIPS 197, speci fy ing a new symmetr ic encrypt ion a lgor i thm.

The AES uses a b lock s ize of 128 bi t s (16 bytes) and can be

used wi th keys in lengths of 128, 192 or 256 bi t s . According to

the FIPS 197 document , “ th is s tandard may be used by Federa l

depar tments and agencies when an agency determines tha t

sens i t ive (unclass i f ied) informat ion requi res cryptographic

protec t ion ,” and “ in addi t ion , th is s tandard may be adopted and

used by non-Federa l Government organiza t ions .” Two

22

Page 23: AES Algorithm Implementation

A.E.S.

researchers who developed and submit ted the Ri jndael

a lgor i thm for cons idera t ion are both cryptographers f rom

Belgium: Dr . Joan Daemen of Proton World In ternat ional and

Dr . Vincent Ri jmen.

The Nat ional Ins t i tu te of Standards and technology (NIST)

se lec ted the Ri jndael a lgor i thm for AES because i t of fers a

combinat ion of secur i ty , performance , e f f ic iency, ease of

implementa t ion , and f lexib i l i ty . Speci f ica l ly , Ri jndael appears

to be consis tent ly a very good performer in both hardware and

sof tware across a wide range of comput ing envi ronments

regardless of i t s use in feedback or non-feedback modes . I t s

key se tup t ime i s excel lent , and i t s key agi l i ty i s good. The

very low memory requi rements of the Ri jndael a lgor i thm make

i t very wel l su i ted for res t r ic ted-space envi ronments , in which

i t a l so demonst ra tes excel lent performance .The Ri jndael

a lgor i thm opera t ions are among the eas ies t to defend agains t

power and t iming a t tacks . Addi t ional ly , i t appears tha t some

defense can be provided agains t such a t tacks wi thout

s igni f icant ly impact ing the a lgor i thm's performance .

23

Page 24: AES Algorithm Implementation

A.E.S.

CHAPTER 3

PROPOSED WORK

Block Cipher Modes of Operat ion

Electronic Code Book(E.C.B) -

The simplest of the encryption modes is the electronic codebook (ECB) mode.

The message is divided into blocks and each block is encrypted separately. The

disadvantage of this method is that identical plaintext blocks are encrypted into

identical ciphertext blocks; thus, it does not hide data patterns well. In some

senses, it doesn't provide serious message confidentiality, and it is not

recommended for use in cryptographic protocols at all.

24

Page 25: AES Algorithm Implementation

A.E.S.

Here's a striking example of the degree to which ECB can leave plaintext data

patterns in the ciphertext. A pixel-map version of the image on the left was

encrypted with ECB mode to create the center image:

IMAGE ENCRYPTION USING ECB

25

Page 26: AES Algorithm Implementation

A.E.S.

Or ig ina lEncrypted us ing ECB mode

Encrypted us ing o ther modes

The image on the right is how the image might look encrypted with CBC, CTR

or any of the other more secure modes -- indistinguishable from random noise.

Note that the random appearance of the image on the right tells us very little

about whether the image has been securely encrypted; many kinds of insecure

encryption have been developed which would produce output just as 'random-

looking'.

ECB mode can also make protocols without integrity protection even more

susceptible to replay attacks, since each block gets decrypted in exactly the

same way. For example, the Phantasy Star Online: Blue Burst online video

game uses Blowfish in ECB mode. Before the key exchange system was

cracked leading to even easier methods, cheaters repeated encrypted "monster

killed" message packets, each an encrypted Blowfish block, to illegitimately

gain experience points quickly.

26

Page 27: AES Algorithm Implementation

A.E.S.

Cipher-Block Chaining (C.B.C.)

CBC mode of operation was invented by IBM in 1976. [1] In the cipher-block

chaining (CBC) mode, each block of plaintext is XORed with the previous

ciphertext block before being encrypted. This way, each ciphertext block is

dependent on all plaintext blocks processed up to that point. Also, to make each

message unique, an initialization vector must be used in the first block.

The encrypt ion in CBC mode requi res the output of the f i rs t

b lock as the input to the second block. Therefore whi le

27

Page 28: AES Algorithm Implementation

A.E.S.

threading the encrypt ion process ; the second block cannot s ta r t

i t s job , unt i l the f i rs t b lock i s not f in ished. The th i rd b lock

cannot s ta r t unt i l the second i s not f in ished and so on and so

for th . Thus subsequent b locks cannot be encrypted

s imul taneously . This ent i re ly defea ts the purpose of mul t i -

threading, as the la ter a ims a t execut ion of a l l the threads

s imul taneously .

The decrypt ion can be done in an order such tha t the output of

the f i rs t b lock i s not requi red for the decrypt ion of second. The

decrypt ion was hence implemented

SOFTWARE REQUIREMENT SPECIFICATION

1.0 Introduct ion

This sec t ion provides the requi rement documenta t ion .

Goals and Object ives

The projec t a ims a t developing an appl ica t ion to

implement the AES encrypt ion s tandard as speci f ied in the

FIPS document da ted 2001 through Mul t i threading.

1.1 Statement of Scope

28

Page 29: AES Algorithm Implementation

A.E.S.

The sys tem wi l l be des igned to read the da ta f rom a f i le ,

through a g iven pa th and encrypt the da ta us ing the

speci f ied AES s tandard . The users wi l l be able to use the

sof tware to keep the i r da ta secure f rom external in t ruders

and for o ther fac tors .

1.2 Software ContextThe sof tware a ims a t the people and the organiza t ions who are keen to keep the i r da ta secre t and conf ident ia l . The u t i l i ty of the code i s to protec t the da ta f rom in t ruders .

1.3 Major ConstraintsThe sys tem wi l l be p la t form independent for execut ion ,

but requi res the respect ive JAVA Environment ins ta l led as

the pre- requi rement .

2.0 Usage scenario

This section provides a usage scenario for the software.

2.1 User profiles

The system does not provide the any specific user profiles. All the users

are given the same amount of preference. All users will provide a path for

the required file and the system will generate the output file as the

encrypted or decrypted text, as requested by the user.

2.2 Use-cases

a) User provides the f i lename and the f i le path .

29

Page 30: AES Algorithm Implementation

A.E.S.

Goal : Provide the sys tem wi th the f i le name and f i le

pa th .

Pr imary Actors : The user

Secondary Actors : The sys tem

Precondi t ion: The user has access to the sys tem.

Post condi t ion: The sys tem gets the f i le to be opera ted

upon.

b)User chooses between Encrypt ion and Decrypt ion

Goal : Provide the sys tem wi th h is choice .

Pr imary Actors : The user

Secondary Actors : The sys tem

Precondi t ion: The user has provided the f i le name and

f i le pa th .

Post condi t ion: The sys tem now knows what to do wi th

the requi red f i le .

2.3 Special usage considerations

The software can be available on all platforms. The application being a

stand-alone application, the data cannot be modified while any user is

retrieving the data.

3.0 Software Interface Descript ion

3.1 External machine interfaces

30

Page 31: AES Algorithm Implementation

A.E.S.

The main sof tware module and the da ta connect iv i ty

wi l l be provided through JAVA2

language , us ing JDK 1. 5 toolki t .

3.2 External system interfaces

The sof tware module wi l l not communica te wi th any

external sys tem. The sys tem is ent i re ly des igned to

be a s tand-a lone one .

3.3 Human Interface

The sof tware wi l l not provide much of a human

in ter face . The essence of the implementa t ion i s the

secur i ty re la ted i ssues ra ther any and in ter face

des ign i ssues .

4.0 Restr ict ions , Limitat ions and constraints

The sof tware package wi l l be a s tand-a lone appl ica t ion

wi thout any access by outs ide ent i ty . I t i s p la t form

independent but needs speci f ic Java envi ronments for

respect ive p la t forms.

SOFTWARE DESIGN SPECIFICATION

1.0 Introduct ion

This sec t ion provides the Design documenta t ion .

Goals and Object ives

31

Page 32: AES Algorithm Implementation

A.E.S.

The projec t a ims a t developing an appl ica t ion to implement the AES encrypt ion s tandard as speci f ied in the FIPS document da ted 2001 through Mul t i threading.

1.4 Statement of Scope

The sys tem wi l l be des igned to read the da ta f rom a f i le , through a g iven pa th and encrypt the da ta us ing the speci f ied AES s tandard . The users wi l l be able to use the sof tware to keep the i r da ta secure f rom external in t ruders and for o ther fac tors .

1.5 Software Context

The sof tware a ims a t the people and the organiza t ions who

are keen to keep the i r da ta secre t and conf ident ia l . The

u t i l i ty of the code i s to protec t the da ta f rom in t ruders .

1.6 Major Constraints

The sys tem wi l l be p la t form independent for execut ion ,

but requi res the respect ive JAVA Environment ins ta l led as

the pre- requi rement .

2.0 Data Design

This section provides with the information regarding all data structures

including internal, global, and temporary data structures.

2.1 Internal Software data s tructure

The des igned sof tware wi l l be to ta l ly Objec t Or iented ,

programmed in JAVA. This wi l l be achieved by the use of

Java Development Ki t . The re levant da ta s t ruc tures have

32

Page 33: AES Algorithm Implementation

A.E.S.

to used. Pr imar i ly the s t ruc tures l ike ar rays wi l l be used.

They are scope-speci f ic . Extens ive use of f i le -handl ing

wi l l a l so be done .

2.2 Global Data Structure

The sys tem wi l l be to ta l ly objec t -or iented and hence wi l l

not use any global objec ts . The da ta which i s to be made

avai lable throughout the implementa t ion wi l l be read f rom

the respect ive f i les .

2.3 Temporary Data Structure

The sof tware wi l l use the ar rays as the temporary da ta

s t ruc tures to s tore the in ter im s ta tes of the da ta which i s

be ing encrypted or decrypted .

2.4 Database descript ion

The ac tua l f i le , which conta ins the da ta to be encrypted ,

ac ts as the avai lable da tabase throughout the opera t ion .

This f i le conta ins the da ta in s imple a lpha-numeric form

and feeds the implementa t ion wi th the same.

3.0 Component-Level Design

The software will be a stand-alone application and will be developed on the

JAVA platform using the JDK tool-kit. Hence the main components of the

software contain the modules in the form of objects. The main module will be

directly linked with these objects and the relevant objects are instantiated and

the methods invoked as and when required.

33

Page 34: AES Algorithm Implementation

A.E.S.

3.1 Program Structure

As the implementation is done is JAVA, the required objects will be

created and then their methods are put to use wherever required. The

modules will interact with each other whenever required and share the

data among them. The code will be sequential in nature, i.e. all the

modules would be executed in a certain order sometime or the other,

irrespective of any event taking pace at the console.

3 .2 Architecture Diagram

34

Page 35: AES Algorithm Implementation

A.E.S.

3.2 .1Process ing narrat ive for component 1

The f i rs t component i s the module to ask the user whether

he wants to encrypt a p la in text f i le or decrypt a c ipher

text . Also i t wi l l prompt the user for the fu l l pa th of the

f i le .

3.2 .1 .1 Component 1 interface descript ion

Input : Choice be tween Encrypt ion or

Decrypt ion .Ful l Pa th of the f i le to be opera ted upon.

Output : The Cipher / Decipher module .

35

Decrypt ion Encrypt ion

Main Module

Accept Text

KeyAccept

Key

Cipher Text

Key

Pla in Text

Accept Text

Accept Key

Encrypted Code

E or D

?? 10 Rounds

10 Rounds

Decrypted Code

Page 36: AES Algorithm Implementation

A.E.S.

3.2 .1 .2 Component 1 Process ing Detai l

A deta i led a lgor i thmic descr ip t ion of main module .

3.2 .1 .2 .1 Interface Descript ion

The main module prompts the user to enter

h is choice be tween the running the

decrypt ion module and the encrypt ion

module .After making the appropr ia te

choice the user i s asked to enter the fu l l

pa th name of the requi red f i le .

3.2 .1 .2 .2 Algori thmic Model

Step 1 : Get user’s choice .

Step 2 : Get the f i le name and path of the

f i le to be accessed.

Step 3 : Proceed to the next module .

3.2 .1 .2 .3 Restr ict ions / Limitat ions

The user has to provide the fu l l f i le pa th

name before proceeding for the ac tua l

encrypt ion or decrypt ion . The user needs to

type in the whole pa th .

36

Page 37: AES Algorithm Implementation

A.E.S.

3.2 .1 .2 .4 Local Data Structures

The f i le name and the choice of the user

a re preferably s tored in s t r ings .

3.2 .2 Process ing narrat ive for component 2

The second component accepts the key and the text ,

genera tes the S-boxes and the requi red rounds for the

encrypt ion process , depending upon the s ize of the

key, and produces the output text .

3 .2 .2 .1Component 1 interface descript ion

Input :The encrypt ion key and the text f rom the f i le .

Output : The Cipher / Decipher text .

3.2 .2 .2 Component 2 Process ing Detai l

A deta i led a lgor i thmic descr ip t ion of the

c ipher /decipher module .

3.2 .2 .2 .1 Interface Descript ion

37

Page 38: AES Algorithm Implementation

A.E.S.

This module accepts the text f rom the f i le

and keys requi red for the appropr ia te

process .

Af ter reading the f i les , the module does the

c ipher in requi red number of rounds . The

number of rounds depends on the s ize of

key used for the process .

3.2 .2 .2 .2 Algori thmic Model

Step 1 : Get key f rom f i le .

Step 2 : Get the text f rom the f i le .

Step 3 : Genera te the requi red S-Box.

Step 4 : Genera te the number of rounds

Step 5 : Repeat the a lgor i thm for the

number of rounds .

3.2 .2 .2 .3 Restr ict ions / Limitat ions

The f i le conta in ing the key and the text a re

to be read.

The number of rounds needs to be

de termined before ac tua l process ing.

3.2 .2 .2 .4 Local Data Structures

The in termedia te s ta te of the da ta which i s

be ing encrypted i s preferably s tored in

double-dimensional a r rays .

38

Page 39: AES Algorithm Implementation

A.E.S.

3.3 Software Interface Descript ion

The sof tware ' s in ter face i s d iscussed be low .

3.3 .1 External system interfaces

The sof tware i s the s tand-a lone appl ica t ion , as

ment ioned above and hence not avai lable onl ine on

any network.

3.3 .2 Human interface

The human in ter face i s a graphica l console based

user in ter face , which accepts the f i le name and fu l l

pa th of the same f rom the user . Reads key f rom the

da tabase , genera tes the number of requi red rounds

and a lso genera tes the Subst i tu t ion Boxes .

Subsequent ly d isplays the re levant da ta af te r

performing the process .

39

Page 40: AES Algorithm Implementation

A.E.S.

4.0 User interface design

A descr ip t ion of the user in ter face des ign of the sof tware i s

presented be low.

40

Page 41: AES Algorithm Implementation

A.E.S.

FUNCTIONS DESCRIPTION

DECRYPTION FUNCTION

MRHNHT

41

Page 42: AES Algorithm Implementation

A.E.S.

MNNMH;’J.J…J.THEN

ENCRYPTION FUNCTION

GBBBB

MMM

KUKJKKU,,

42

Page 43: AES Algorithm Implementation

A.E.S.

FFFFFEON F MODULE WISE DESCRIPTION CTINSN

MMEN

INPUTS AND OUTPUT

The input and output for the AES a lgor i thm each consis t

of sequences of 128 bi t s (d ig i t s wi th va lues of 0 or 1) .

These sequences wi l l somet imes be refer red to as b locks

and the number of b i t s they conta in wi l l be refer red to as

the i r length . The Cipher Key for the AES a lgor i thm is a

sequence of 128, 192 or 256 bi t s . Other input , output and

Cipher Key lengths are not permi t ted by th is s tandard .

The b i t s wi th in such sequences wi l l be numbered s tar t ing

a t zero and ending a t one less than the sequence length

(b lock length or key length) . The number i a t tached to a

b i t i s known as i t s index and wi l l be in one of the ranges 0

<= i < 128, 0<= i < 192 or 0 <= i < 256 depending on

the b lock length and key length (speci f ied above) .

The SubBytes / InvSubBytes transformation

The SubBytes Transformat ion i s a non- l inear byte

subs t i tu t ion , opera t ing on each of the Sta te bytes

independent ly . The subs t i tu t ion table (or S-box ) i s

inver t ib le and i s cons t ruc ted by the composi t ion of two

t ransformat ions :

43

Page 44: AES Algorithm Implementation

A.E.S.

1 . Fi rs t , tak ing the mul t ip l ica t ive inverse in GF(28) , ‘00’

i s mapped onto i t se l f .

2 . Then, applying an af f ine (over GF(2) ) t ransformat ion

def ined by: S-box

F igure : ByteSub acts on the individual bytes of the State .

The inverse of ByteSub is the byte subs t i tu t ion where the

inverse table i s appl ied . This i s obta ined by the inverse of the

af f ine mapping fo l lowed by taking the mul t ip l ica t ive inverse in

GF(28) .

ShiftRows() / InvShif tRows Transformation

In the Shi f tRows() t ransformat ion, the bytes in the las t

three rows of the Sta te are cycl ica l ly sh i f ted over

d i f ferent numbers of bytes (of fse ts ) . The f i rs t row, r = 0 ,

i s not sh i f ted .Speci f ica l ly , the Shi f tRows() t ransformat ion

proceeds by row number as fo l lows: the shi f t va lue shi f t ( r

44

Page 45: AES Algorithm Implementation

A.E.S.

, Nb) depends on the row number , r , as fo l lows ( reca l l tha t

Nb = 4) :

sh i f t (1 ,4) =1; sh i f t (2 ,4) = 2 ; sh i f t (3 ,4) = 3

This has the ef fec t of moving bytes to “ lower” pos i t ions in

the row ( i .e . , lower va lues of c in a g iven row) , whi le the

“ lowest” bytes wrap around in to the “ top” of the row ( i .e . ,

h igher va lues of c in a g iven row) .

F igure i l lus t ra tes the ShiftRows() t ransformat ion

AddRoundKey ( )

In the AddRoundKey() t ransformat ion, a Round Key is added to

the Sta te by a s imple b i twise XOR opera t ion . Each Round Key

consis ts of Nb words f rom the key schedule . Those Nb words

are each added in to the columns of the Sta te . In the Cipher , the

in i t ia l Round Key addi t ion occurs when round = 0 , pr ior to the

f i rs t appl ica t ion of the round funct ion (see Fig . 5) . The

45

Page 46: AES Algorithm Implementation

A.E.S.

appl ica t ion of the AddRoundKey() t ransformat ion to the Nr

rounds of the Cipher occurs when

1<=round <=Nr.

The ac t ion of th is t ransformat ion i s i l lus t ra ted in Fig , where l =

round * Nb.

ADD ROUND KEY

Key Expansion-

Algori thm -

KeyExpansion(byte key[4*Nk] , word w[Nb*(Nr+1)] , Nk)

begin

word temp

i = 0

46

Page 47: AES Algorithm Implementation

A.E.S.

whi le ( i < Nk)

w[i ]=word(key[4*i ] , key[4*i+1] , key[4*i+2] , key[4*i+3])

i = i+1

end whi le

i = Nk

whi le ( i < Nb * (Nr+1)]

temp = w[i -1]

i f ( i mod Nk = 0)

temp = SubWord(RotWord( temp)) xor Rcon[ i /Nk]

e lse i f (Nk > 6 and i mod Nk = 4)

temp = SubWord( temp)

end i f

w[ i ] = w[i -Nk] xor temp

i = i + 1

end whi le

end

47

Page 48: AES Algorithm Implementation

A.E.S.

KEY EXPANSION WORKING

The AES a lgor i thm takes the Cipher Key, K, and performs a

Key Expansion rout ine to genera te akey schedule . The Key

Expansion genera tes a to ta l of Nb (Nr + 1) words : the

a lgor i thm requi res an in i t ia l se t of Nb words , and each of the

Nr rounds requi res Nb words of key da ta . Theresul t ing key

schedule consis t s of a l inear a r ray of 4-byte words , denoted [ wi

] , wi th i in the range 0 <= i < Nb(Nr + 1) .

48

Page 49: AES Algorithm Implementation

A.E.S.

DESIGN

SOFTWARE ARCHITECTURE

49

Decrypt ion Encrypt ion

Main Module

Accept Text

KeyAccept

Key

Cipher Text

Key

Pla in Text

Accept Text

Accept

Key

Encrypted Code

E or D

??10 Rounds

10 Rounds

Decrypted Code

Page 50: AES Algorithm Implementation

A.E.S.

ACTIVITY DIAGRAM

50

PutBytes

In ter face

(F i rs t Window)1.Encrypt ion

2.Decrypt ion

Encryption

Decryption

In ter face (SecondWindow)128

192256

Par t icular

Module

128 192

256

Eng2Hex

Pla in Text

GetBytes

Key

Append num of threads in c ipher text

AES Encrypt

Pr in t

New Thread

?

Page 51: AES Algorithm Implementation

A.E.S.

SEQUENCE DIAGRAM

Diagram ( i i i ) : Sequence Diagram

51

Inter face

Eng2Hex putf i le :

PutBytesget Input : GetBytesgetkey :

GetBytesaes : AESencrypttab:AES

table

N

N threads

Nt : NewThread

Page 52: AES Algorithm Implementation

A.E.S.

FUNCTIONAL BLOCK DIAGRAM -

52

Page 53: AES Algorithm Implementation

A.E.S.

State-Transi t ion Diagram

Events

Event 1: User g ives f i le name and f i le

pa th .

Event 2: User chooses be tween Encrypt ion

and Decrypt ion

Event 3: Determine number of rounds .

Event 4 : S tar t Rounds

Event 5: Read Key

Event 6: Read Sta te

Event 7: Perform Encrypt ion

Event 8: Perform Decrypt ion

Event 9: Record Sta te

Event 10: Genera te Output Fi le

53

Page 54: AES Algorithm Implementation

A.E.S.

States

State 1: The sof tware i s in ready s ta te

(Star t S ta te)

State 2: F i le Path and Name accepted

State 3: User choice accepted .

State 4: Rounds de termined

State 5: Rounds Star ted .

State 6: Key is read .

State 7: S ta te i s Read

State 8: Encrypt ion Performed.

State 9: Decrypt ion Performed.

State 10: Sa te Recorded

State 11: Output Fi le Genera ted (Stop )

54

Page 55: AES Algorithm Implementation

A.E.S.

STATE TRANSITION DIAGRAM

55

Event 9 Event 9

Event 8Event 7

Event 6Event 6

Event 10Event 10

Event 5Event 5

Event 4 (Decrypt ion)

Event 4 (Encrypt ion)

Event 3

Event 2

Event 1

Sta te 1

Sta te 2

Sta te 3

Sta te 4

Sta te 5 Sta te 5

Sta te 6 Sta te 6

Sta te 7 Sta te 7

State 8 State 9

State 10 Sta te 10

Sta te11 1111

Page 56: AES Algorithm Implementation

A.E.S.

FORM

56

Page 57: AES Algorithm Implementation

A.E.S.

CHAPTER 4

RESULT AND ANALYSIS

We have implemented AES in NORMAL mode and by us ing

MULTITHREADING on di f ferent processors and the be low

graph shows the t ime in mi l l i seconds taken for encrypt ion of

da ta by d i f ferent processors , the graph i s as fo l lows :

Time for encrypt ion and decrypt ion ge t reduced to la rge extent

when we use the mul t i threading concept in AES.

57

Page 58: AES Algorithm Implementation

A.E.S.

The be low drawn graphs represent the t ime taken for

encrypt ion and decrypt ion of d i f ferent s ize da ta by us ing d i f f

key s ize in the mul t i threaded envi ronment .

128 bit - 100 KB

010000

200003000040000

500006000070000

8000090000

0 5 10 15 20 25

No of Threads

Execu

tio

n T

ime (

ms)

Encryption Time

Decryption Time

192 bit - 100 KB

010000

200003000040000

500006000070000

8000090000

0 5 10 15 20 25

No of Threads

Execu

tio

n T

ime (

ms)

Encryption Time

Decryption Time

256 bit - 100 KB

0100002000030000400005000060000700008000090000

100000

0 5 10 15 20 25

No of Threads

Exe

cuti

on

Tim

e (m

s)

Encryption Time

Decryption Time

58

Page 59: AES Algorithm Implementation

A.E.S.

CHAPTER 5

CONCLUSION

AES is the most secure encrypt ion a lgor i thm known t i l l da te .

Hence i t i s necessary to opt imize the a lgor i thm so tha t i t can be

used in d i f ferent appl ica t ions l ike embedded sys tems, mobi le

appl ica t ions e tc . Opt imiza t ion i s in two domains , t ime as wel l

as space e f f ic iency. For opt imized ef f ic iency in the t ime

domain we used Mul t i Threading. Fur ther when we used mul t i

threading for encrypt ion , we had a const ra in t of us ing same

number of threads in the decrypt ion process as wel l .

Fur ther more ; th is be ing an encrypt ion a lgor i thm, the

encrypt ion and decrypt ion process i s car r ied out on d i f ferent

machines . These machines may di f fer in the performance and

can have d i f ferent hardware conf igura t ions , thus changing the

opt imal number of threads requi red for the processes . Now, for

the improved performance of the a lgor i thm, i t i s necessary to

work wi th opt imal number of threads .

We have t r ied to opt imized the most secure encrypt ion

a lgor i thm wi th respect to t ime so tha t i t can be fur ther used in

the appl ica t ions tha t have t ime const ra in ts . The a lgor i thm has

been opt imized wi th respect to execut ion t ime by us ing mul t i

threading in a l l the modes of opera t ion . Thus enabl ing th is

a lgor i thm to be more f lexib le and hence a l lowing i t to be used

in more d ivers i f ied f ie lds .

59

Page 60: AES Algorithm Implementation

A.E.S.

What i s the problem you have tr ied to solve? Why this work

is important?

AES is the most secure encrypt ion a lgor i thm known t i l l da te .

Hence i t i s necessary to opt imize the a lgor i thm so tha t i t can be

used in d i f ferent appl ica t ions l ike embedded sys tems, mobi le

appl ica t ions e tc . Opt imiza t ion i s in two domains , t ime as wel l

as space ef f ic iency. For opt imized ef f ic iency in the t ime

domain we use Mul t i Threading. Fur ther when we use mul t i

threading for encrypt ion , we have a const ra in t of us ing same

number of threads in the decrypt ion process as wel l . Hence we

have proposed a d i f ferent mode of opera t ion in which the

decrypt ion can use d i f ferent number of threads as used in

encrypt ion .

Fur ther more ; th is be ing an encrypt ion a lgor i thm, the

encrypt ion and decrypt ion process i s car r ied out on d i f ferent

machines . These machines may di f fer in the performance and

can have d i f ferent hardware conf igura t ions , thus changing the

opt imal number of threads requi red for the processes . Now, for

the improved performance of the a lgor i thm, i t i s necessary to

work wi th opt imal number of threads . Hence , we have proposed

an a lgor i thm for f inding the opt imal number of threads wi th

respect to the g iven machine .

We have opt imized the most secure encrypt ion a lgor i thm wi th

respect to t ime so tha t i t can be fur ther used in the appl ica t ions

tha t have memory const ra in ts . The a lgor i thm has been

opt imized wi th respect to execut ion t ime by us ing mul t i

threading in a l l the modes of opera t ion . Thus enabl ing th is

60

Page 61: AES Algorithm Implementation

A.E.S.

a lgor i thm to be more f lexib le and hence a l lowing i t to be used

in more d ivers i f ied f ie lds .

.What i s your approach or solut ion?

The f i rs t par t of the solu t ion deals wi th Mul t i Threading in the

ICBC mode. To accompl ish the bes t throughput t ime the ICBC

mode had to be implemented. S ince the CBC mode does not

suppor t mul t i threading dur ing encrypt ion , the ICBC mode

proves to be be t te r . The o ther ment ioned problem is the use of

d i f ferent number of threads for the encrypt ion and decrypt ion

processes .

Why is i t better /di f ferent than other exist ing approaches or

solut ions?

ICBC is one of the proposed modes of opera t ion in research

papers , which i s the mul t i threaded form of CBC (Cipher Block

Chaining) . But t i l l da te , no work had been done on i t s

implementa t ion on AES. Hence we have implemented the ICBC

mode of opera t ion , which enables us to use mul t i threading in

encrypt ion as wel l as decrypt ion . Ear l ie r , in CBC mode mul t i

threading was not poss ib le in encrypt ion , as the encrypt ion was

performed in chained mode i .e . encrypt ion of previous b lock

was a pre- requis i te for encrypt ion of new block. Therefore ,

wi th the use of mul t i threading in encrypt ion , the a lgor i thm

becomes more opt imized wi th respect to execut ion t ime.

Fur ther , no work had been done emphasiz ing on us ing d i f ferent

number of threads in encrypt ion and decrypt ion . Hence we have

proposed a novel a lgor i thm which a l lows the machine to use

opt imal number of threads depending on the i r performance ,

61

Page 62: AES Algorithm Implementation

A.E.S.

ra ther than compel l ing the decrypt ing machine to use same

number of threads as used by encrypt ing one .

Our o ther proposed a lgor i thm a l lows the machine to f ind

opt imized number of threads according to the const ra in ts . No

concre te work had been done t i l l da te in th is f ie ld .

62

Page 63: AES Algorithm Implementation

A.E.S.

CHAPTER 6

FUTURE WORK

Interleaved Cipher Block Chaining (ICBC)

Both the above methods implemented are not useful when i t

comes to mul t i - threading. To del iver h igh performance whi le

mainta in ing h igh level of secur i ty assurance in rea l sys tems,

th is par t icular mode was proposed. This mode crea tes mul t ip le

in ter leaved encrypt ion s t reams ins tead of jus t one . In an ‘n’

way in ter leaved chaining, the f i rs t and every (n+1) th b lock

thereaf ter a re encrypted in CBC mode, the second (n+2) th and

every n th b lock thereaf ter a re encrypted as another s t ream, and

so on.

Since encrypt ion was not s t ra ightaway poss ib le in CBC mode,

th is ca l led for an implementa t ion in a new type of mode of

opera t ion . The new mode was ICBC.In th is mode f i rs t thread

ac ts on the f i rs t b lock wi th an In i t ia l Vector IV1, the second

thread ac ts on the second block wi th another In i t ia l Vector IV2,

and so on. The output of the f i rs t b lock ac ts as the input for

N+1th b lock. The f i rs t N blocks are s imul taneously processed,

independent of each o ther and para l le l to each o ther . Only the

N+1th b lock requi res the output of the f i rs t b lock, and s ince

both the b locks are be ing ac ted upon by the same thread, th is

makes i t poss ib le to incorpora te mul t i threading in the

encrypt ion process .

63

Page 64: AES Algorithm Implementation

A.E.S.

64

Chain 1 Chain

2 Chain 3 Chain

4ICBC m ode o f ope ra t i on

Page 65: AES Algorithm Implementation

A.E.S.

APPENDICES

Java

The inventors of Java wanted to des ign a language which could

offer so lu t ions to some of the problems encountered in modern

programming. They wanted the language to be not only

re l iable , por table and dis t r ibuted but a lso s imple , compact and

in terac t ive . Sun Microsys tems off ic ia l ly descr ibes Java wi th

fo l lowing a t t r ibutes :

Compi led and in terpre ted

Pla t form independent and por table

Object Or iented

Robust and secure

Dist r ibuted

Famil iar , s imple and smal l

Mult i threaded and in terac t ive

High performance

Dynamic and extens ib le

In the Java programming language , a l l source code i s f i r s t

wr i t ten in p la in text f i les ending wi th the . java extens ion.

Those source f i les a re then compi led in to .c lass f i les by the

javac compi ler . A .c lass f i le does not conta in code tha t i s

na t ive to your processor ; i t ins tead conta ins bytecodes — the

machine language of the Java Vir tua l Machine 1 ( Java VM). The

java launcher tool then runs your appl ica t ion wi th an ins tance

of the Java Vir tua l Machine

65

Page 66: AES Algorithm Implementation

A.E.S.

Because the Java VM is avai lable on many di f ferent opera t ing

sys tems, the same .c lass f i les a re capable of running on

Microsof t Windows, the Solar i s TM Opera t ing System (Solar is

OS) , Linux, or Mac OS. Some vi r tua l machines , such as the

Java HotSpot v i r tua l machine , per form addi t ional s teps a t

runt ime to g ive your appl ica t ion a performance boost . This

inc lude var ious tasks such as f inding performance bot t lenecks

and recompi l ing ( to na t ive code) f requent ly used sec t ions of

code .

Through the Java VM, the same application is capable

of running on multiple platforms.

66

Page 67: AES Algorithm Implementation

A.E.S.

The Java Platform

A pla t form is the hardware or sof tware envi ronment in which a

program runs . We 've a l ready ment ioned some of the most

popular p la t forms l ike Microsof t Windows, Linux, Solar i s OS,

and Mac OS. Most p la t forms can be descr ibed as a combinat ion

of the opera t ing sys tem and under ly ing hardware . The Java

p la t form di f fers f rom most o ther p la t forms in tha t i t ' s a

sof tware-only p la t form tha t runs on top of o ther hardware-

based p la t forms.

The Java p la t form has two components :

The Java Vir tua l Machine

The Java Appl ica t ion Programming In ter face (API)

You 've a l ready been in t roduced to the Java Vir tua l Machine;

i t ' s the base for the Java p la t form and i s por ted onto var ious

hardware-based p la t forms. The API i s a la rge col lec t ion of

ready-made sof tware components tha t provide many useful

capabi l i t ies . I t i s grouped in to l ibrar ies of re la ted c lasses and

in ter faces ; these l ibrar ies are known as packages

The API and Java Vir tua l Machine insula te the program from

the under ly ing hardware .

67

Page 68: AES Algorithm Implementation

A.E.S.

MATHEMATICAL DESCRIPTION

ENCRYPTION AND DECRYPTION IN ECB MODE

ECB-MULTI THREADED ENCRYPTION

68

Page 69: AES Algorithm Implementation

A.E.S.

ECB MULTI THREADED DECRYPTION

69

Page 70: AES Algorithm Implementation

A.E.S.

CIPHER BLOCK CHAINING ENCRYPTION

Here Each thread i s dependent on previous output hence

mul t i threading i s not poss ib le (same in CFB and OFB)

70

Page 71: AES Algorithm Implementation

A.E.S.

CBC DECRYPTION

71

Page 72: AES Algorithm Implementation

A.E.S.

72

Page 73: AES Algorithm Implementation

A.E.S.

DESCRIPTION OF SYMBOLS :

Main Module Acts as user in ter face for accept ing f i le , key

and for performing encrypt ion or decrypt ion funct ion .

AddRoundKey Transformat ion in the Cipher and Inverse

Cipher in which a Round Key is added to the Sta te us ing an

XOR opera t ion . The length of a Round Key equals the s ize of

the Sta te ( i .e . , for Nb = 4 , the RoundKey length equals 128

bi t s /16 bytes) .

MixColumns Transformat ion in the Cipher tha t takes a l l of

the columns of the S ta te and mixes the i r da ta ( independent ly

of one another) to produce new columns.

ShiftRows Transformat ion in the Cipher tha t processes the

Sta te by cycl ica l ly sh i f t ing the las t three rows of the Sta te by

d i f ferent of fse ts .

SubBytes Transformat ion in the Cipher tha t processes the

Sta te us ing a nonl inear byte subs t i tu t ion table (S-box) tha t

opera tes on each of the Sta te bytes independent ly .

SubWord Funct ion used in the Key Expansion rout ine tha t

takes a four-byte input word and appl ies an S-box to each of

the four bytes to produce an output word.

InvMixColumns Transformat ion in the Inverse Cipher tha t i s

the inverse of MixColumns() .

InvShif tRows Transformat ion in the Inverse Cipher tha t i s

the inverse of ShiftRows() .

73

Page 74: AES Algorithm Implementation

A.E.S.

InvSubBytes Transformat ion in the Inverse Cipher tha t i s the

inverse of SubBytes() .

Nb : No. of columns(32 bi t ) compris ing the s ta te . For th is

s tandard Nb=4

Nk : No. of 32 b i t words compris ing the c ipher key. For th is

Nk=4,6 or 8

Nr : No. of rounds which i s a funct ion of Nk and Nb( which i s

f ixed) . For th is s tandard Nr=10,12,14

Rcon : The round constant word ar ray

Rot Word : Funct ion used in the key expansion rout ine tha t

takes a four byte word and performs a cycl ic permuta t ion

Print- Using funct ion over loading 3 func . of printarray()

would be crea ted and would be ca l led upon as per the va lues

passed. This module wi l l conta in a l l the pr in t funct ion used for

the projec t . Al l pr in t funct ion means pr in t for s imple ECB,

CBC, ICBC modes wi l l requi re s imple pr in t ing but threading

wi l l requi re number of threads crea ted a t the t ime of

Encrypt ion as per FIPS document .

Copy- Using const ruc tor over loading copy() named 3

const ruc tor wi l l be crea ted d i f ferent ia ted on the bas is of va lues

passed. Copy wi l l conta in the s ta te ar ray . This i s the in i t ia l

s ta te a r ray and update i t so tha t i t can be used wi th d i f ferent

funct ions . S ta te ar ray wi l l be requi red by a l l 4 funct ions .

74

Page 75: AES Algorithm Implementation

A.E.S.

PutBytes-

Will be us ing three funct ion put() , putByte() and

thread() . Put ( ) and putByte() for Pbox and thread() for

ge t t ing number of threads .

AESencrypt-

Will have fo l lowing funct ion Cipher() , InvCipher() ,

KeyExpansion() . Cipher( ) and InvCipher( ) wi l l use the

over loading concept to pass he va lues . For s imple we

have text and key as input whereas for threading no. of

threads wi l l be added. KeyExpansion() wi l l be used as per

keyExpansion Algor i thm

EngtoHex-

Will have three funct ion toHex() , toEng() and convert( )

for conver t ing Eng to hex and vise versa .

AEStables

This wi l l ac t as the backup for projec t . S ta te as wel l as

Rcon ar ray wi l l be updated everyt ime a funct ion runs so

th is would s tore the updated ar rays . Sbox wi l l be

implemented in th is .

AEStest-

This wi l be the ca l l ing or s ta r t ing module . Take the f i le

and key as input .

GetBytes Implements GetByte funct ion .

75

Page 76: AES Algorithm Implementation

A.E.S.

76

Page 77: AES Algorithm Implementation

A.E.S.

WORKING:

AES-128 (Nk=4,Nr=10)

PLAINTEXT: 00112233445566778899aabbccddeeff

KEY: 000102030405060708090a0b0c0d0e0f

CIPHER (ENCRYPT):

round[ 0] . input 00112233445566778899aabbccddeeff

round[0] .k_sch 000102030405060708090a0b0c0d0e0f

round[ 1] . s ta r t 00102030405060708090a0b0c0d0e0f0

round[1] .s_box 63cab7040953d051cd60e0e7ba70e18c

round[1] .s_row 6353e08c0960e104cd70b751bacad0e7

round[1] .m_col 5f72641557f5bc92f7be3b291db9f91a

round[ 1] .k_sch d6aa74fdd2af72fadaa678f1d6ab76fe

round[ 2] . s ta r t 89d810e8855ace682d1843d8cb128fe4

77

Page 78: AES Algorithm Implementation

A.E.S.

round[2] .s_box a761ca9b97be8b45d8ad1a611fc97369

round[2] .s_row a7be1a6997ad739bd8c9ca451f618b61

round[2] .m_col f f87968431d86a51645151fa773ad009

round[2] .k_sch b692cf0b643dbdf1be9bc5006830b3fe

round[3] .s ta r t 4915598f55e5d7a0daca94fa1f0a63f7

round[3] .s_box 3b59cb73fcd90ee05774222dc067fb68

round[3] .s_row 3bd92268fc74fb735767cbe0c0590e2d

round[3] .m_col 4c9c1e66f771f0762c3f868e534df256

round[3] .k_sch b6ff744ed2c2c9bf6c590cbf0469bf41

round[4] .s ta r t fa636a2825b339c940668a3157244d17

round[4] .s_box 2dfb02343f6d12dd09337ec75b36e3f0

round[4] .s_row 2d6d7ef03f33e334093602dd5bfb12c7

round[4] .m_col 6385b79ffc538df997be478e7547d691

round[4] .k_sch 47f7f7bc95353e03f96c32bcfd058dfd

round[5] .s ta r t 247240236966b3fa6ed2753288425b6c

round[5] .s_box 36400926f9336d2d9fb59d23c42c3950

round[5] .s_row 36339d50f9b539269f2c092dc4406d23

round[5] .m_col f4bcd45432e554d075f1d6c51dd03b3c

round[5] .k_sch 3caaa3e8a99f9deb50f3af57adf622aa

round[6] .s ta r t c81677bc9b7ac93b25027992b0261996

round[6] .s_box e847f56514dadde23f77b64fe7f7d490

round[6] .s_row e8dab6901477d4653ff7f5e2e747dd4f

round[6] .m_col 9816ee7400f87f556b2c049c8e5ad036

round[6] .k_sch 5e390f7df7a69296a7553dc10aa31f6b

round[ 7] . s ta r t c62fe109f75eedc3cc79395d84f9cf5d

round[7] .s_box b415f8016858552e4bb6124c5f998a4c

round[7] .s_row b458124c68b68a014b99f82e5f15554c

78

Page 79: AES Algorithm Implementation

A.E.S.

round[7] .m_col c57e1c159a9bd286f05f4be098c63439

round[7] .k_sch 14f9701ae35fe28c440adf4d4ea9c026

round[ 8] . s ta r t d1876c0f79c4300ab45594add66ff41f

round[ 8] . s_box 3e175076b61c04678dfc2295f6a8bfc0

round[ 8] . s_row 3e1c22c0b6fcbf768da85067f6170495

round[ 8] .m_colbaa03de7a1f9b56ed5512cba5f414d23

round[ 8] .k_sch 47438735a41c65b9e016baf4aebf7ad2

round[ 9] . s ta r t fde3bad205e5d0d73547964ef1fe37f1

round[ 9] . s_box5411f4b56bd9700e96a0902fa1bb9aa1

round[ 9] . s_row54d990a16ba09ab596bbf40ea111702f

round[ 9] .m_col e9f74eec023020f61bf2ccf2353c21c7

round[ 9] .k_sch549932d1f08557681093ed9cbe2c974e

round[10] .s tar t bd6e7c3df2b5779e0b61216e8b10b689

round[10] .s_box 7a9f102789d5f50b2beffd9f3dca4ea7

round[10] .s_row 7ad5fda789ef4e272bca100b3d9ff59f

round[10] .k_sch13111d7fe3944a17f307a78b4d2b30c5

round[10] .output69c4e0d86a7b0430d8cdb78070b4c55

a

INVERSE CIPHER (DECRYPT):

round[0] . input69c4e0d86a7b0430d8cdb78070b4c55a

round[0] . ik_sch13111d7fe3944a17f307a78b4d2b30c5

round[ 1] . i s ta r t 7ad5fda789ef4e272bca100b3d9ff59f

round[ 1] . i s_row7a9f102789d5f50b2beffd9f3dca4ea7

round[1] . i s_boxbd6e7c3df2b5779e0b61216e8b10b689

round[1] . ik_sch549932d1f08557681093ed9cbe2c974e

round[1] . ik_add e9f74eec023020f61bf2ccf2353c21c7

79

Page 80: AES Algorithm Implementation

A.E.S.

round[ 2] . i s ta r t 54d990a16ba09ab596bbf40ea111702f

round[ 2] . i s_row 5411f4b56bd9700e96a0902fa1bb9aa1

round[ 2] . i s_box fde3bad205e5d0d73547964ef1fe37f1

round[ 2] . ik_sch 47438735a41c65b9e016baf4aebf7ad2

round[ 2] . ik_add baa03de7a1f9b56ed5512cba5f414d23

round[ 3] . i s ta r t 3e1c22c0b6fcbf768da85067f6170495

round[ 3] . i s_row 3e175076b61c04678dfc2295f6a8bfc0

round[ 3] . i s_box d1876c0f79c4300ab45594add66ff41f

round[ 3] . ik_sch 14f9701ae35fe28c440adf4d4ea9c026

round[3] . ik_addc57e1c159a9bd286f05f4be098c63439

round[ 4] . i s ta r t b458124c68b68a014b99f82e5f15554c

round[4] . i s_row b415f8016858552e4bb6124c5f998a4c

round[4] . i s_box c62fe109f75eedc3cc79395d84f9cf5d

round[4] . ik_sch 5e390f7df7a69296a7553dc10aa31f6b

round[4] . ik_add 9816ee7400f87f556b2c049c8e5ad036

round[ 5] . i s ta r t e8dab6901477d4653ff7f5e2e747dd4f

round[5] . i s_row e847f56514dadde23f77b64fe7f7d490

round[5] . i s_box c81677bc9b7ac93b25027992b0261996

round[ 5] . ik_sch 3caaa3e8a99f9deb50f3af57adf622aa

round[5] . ik_add f4bcd45432e554d075f1d6c51dd03b3c

round[6] . i s ta r t 36339d50f9b539269f2c092dc4406d23

round[6] . i s_row 36400926f9336d2d9fb59d23c42c3950

round[6] . i s_box 247240236966b3fa6ed2753288425b6c

round[6] . ik_sch 47f7f7bc95353e03f96c32bcfd058dfd

round[6] . ik_add 6385b79ffc538df997be478e7547d691

round[ 7] . i s ta r t 2d6d7ef03f33e334093602dd5bfb12c7

round[7] . i s_row 2dfb02343f6d12dd09337ec75b36e3f0

round[7] . i s_box fa636a2825b339c940668a3157244d17

80

Page 81: AES Algorithm Implementation

A.E.S.

round[7] . ik_sch b6ff744ed2c2c9bf6c590cbf0469bf41

round[7] . ik_add 4c9c1e66f771f0762c3f868e534df256

round[ 8] . i s ta r t 3bd92268fc74fb735767cbe0c0590e2d

round[8] . i s_row 3b59cb73fcd90ee05774222dc067fb68

round[8] . i s_box 4915598f55e5d7a0daca94fa1f0a63f7

round[8] . ik_sch b692cf0b643dbdf1be9bc5006830b3fe

round[8] . ik_add f f87968431d86a51645151fa773ad009

round[ 9] . i s ta r t a7be1a6997ad739bd8c9ca451f618b61

round[9] . i s_row a761ca9b97be8b45d8ad1a611fc97369

round[9] . i s_box 89d810e8855ace682d1843d8cb128fe4

round[ 9] . ik_sch d6aa74fdd2af72fadaa678f1d6ab76fe

round[9] . ik_add 5f72641557f5bc92f7be3b291db9f91a

round[10] . i s ta r t 6353e08c0960e104cd70b751bacad0e7

round[10] . i s_row63cab7040953d051cd60e0e7ba70e18c

round[10] . i s_box00102030405060708090a0b0c0d0e0f

round[10] . ik_sch000102030405060708090a0b0c0d0e0f

round[10] . ioutput00112233445566778899aabbccddeeff

EQUIVALENT INVERSE CIPHER DECRYPT:

round[ 0] . i input 69c4e0d86a7b0430d8cdb78070b4c55a

round[ 1] . ik_sch 13aa29be9c8faff6f770f58000f7bf03

round[ 2] . i s ta r t 54d990a16ba09ab596bbf40ea111702f

round[ 2] . i s_box fde596f1054737d235febad7f1e3d04e

round[ 2] . i s_row fde3bad205e5d0d73547964ef1fe37f1

round[ 2] . im_col 2d7e86a339d9393ee6570a1101904e16

round[ 2] . ik_sch 1362a4638f2586486bff5a76f7874a83

81

Page 82: AES Algorithm Implementation

A.E.S.

round[ 3] . i s ta r t 3e1c22c0b6fcbf768da85067f6170495

round[ 3] . i s_box d1c4941f7955f40fb46f6c0ad68730ad

round[ 3] . i s_row d1876c0f79c4300ab45594add66ff41f

round[ 3] . im_col 39daee38f4f1a82aaf432410c36d45b9

round[ 3] . ik_sch 8d82fc749c47222be4dadc3e9c7810f5

round[ 4] . i s ta r t b458124c68b68a014b99f82e5f15554c

round[ 4] . i s_box c65e395df779cf09ccf9e1c3842fed5d

round[ 4] . i s_row c62fe109f75eedc3cc79395d84f9cf5d

round[ 4] . im_col 9a39bf1d05b20a3a476a0bf79fe51184

round[ 4] . ik_sch 72e3098d11c5de5f789dfe1578a2cccb

round[ 5] . i s ta r t e8dab6901477d4653ff7f5e2e747dd4f

round[ 5] . i s_box c87a79969b0219bc2526773bb016c992

round[ 5] . i s_row c81677bc9b7ac93b25027992b0261996

round[ 5] . im_col 18f78d779a93eef4f6742967c47f5ffd

round[ 5] . ik_sch 2ec410276326d7d26958204a003f32de

round[ 6] . i s ta r t 36339d50f9b539269f2c092dc4406d23

round[ 6] . i s_box 2466756c69d25b236e4240fa8872b332

round[ 6] . i s_row 247240236966b3fa6ed2753288425b6c

round[ 6] . im_col 85cf8bf472d124c10348f545329c0053

round[ 6] . ik_sch a8a2f5044de2c7f50a7ef79869671294

round[ 7] . i s ta r t 2d6d7ef03f33e334093602dd5bfb12c7

round[ 7] . i s_box fab38a1725664d2840246ac957633931

round[ 7] . i s_row fa636a2825b339c940668a3157244d17

round[ 7] . im_col fc1fc1f91934c98210fbfb8da340eb21

round[ 7] . ik_sch c7c6e391e54032f1479c306d6319e50c

round[ 8] . i s ta r t 3bd92268fc74fb735767cbe0c0590e2d

round[ 8] . i s_box 49e594f755ca638fda0a59a01f15d7fa

82

Page 83: AES Algorithm Implementation

A.E.S.

round[ 8] . i s_row 4915598f55e5d7a0daca94fa1f0a63f7

round[ 8] . im_col 076518f0b52ba2fb7a15c8d93be45e00

round[ 8] . ik_sch a0db02992286d160a2dc029c2485d561

round[ 9] . i s ta r t a7be1a6997ad739bd8c9ca451f618b61

round[ 9] . i s_box 895a43e485188fe82d121068cbd8ced8

round[ 9] . i s_row 89d810e8855ace682d1843d8cb128fe4

round[ 9] . im_col e f053f7c8b3d32fd4d2a64ad3c93071a

round[ 9] . ik_sch 8c56dff0825dd3f9805ad3fc8659d7fd

round[10] . i s ta r t 6353e08c0960e104cd70b751bacad0e7

round[10] . i s_box 0050a0f04090e03080d02070c01060b0

round[10] . i s_row 00102030405060708090a0b0c0d0e0f0

round[10] . ik_sch 000102030405060708090a0b0c0d0e0

83

Page 84: AES Algorithm Implementation

A.E.S.

CODING

ECB MODE (FLOW OF CONTROL):

INTERFACE CODING USING JAVA SWINGS :

impor t java .awt .* ;

impor t java .awt .event .* ;

impor t javax.swing.*;

impor t java . io .* ;

publ ic c lass crypto1 extends JFrame

{

pr iva te JLabel jLabel1;

pr iva te JLabel jLabel3;

84

Page 85: AES Algorithm Implementation

A.E.S.

pr iva te JLabel jLabel4;

Fi leDia log f i ledia log_1;

pr iva te JRadioBut ton jRadioBut ton1;

pr iva te JRadioBut ton jRadioBut ton2;

pr iva te JRadioBut ton jRadioBut ton3;

pr iva te JRadioBut ton jRadioBut ton4;

pr iva te JRadioBut ton jRadioBut ton5;

pr iva te JComboBox jComboBox1;

pr iva te JBut ton jBut ton1;

pr iva te JBut ton jBut ton2;

pr iva te JBut ton jBut ton3;

pr iva te JPanel contentPane;

publ ic c rypto1()

{

super( ) ;

in i t ia l izeComponent( ) ;

th is . se tVis ib le( t rue) ;

}

pr iva te void in i t ia l izeComponent( )

{

jLabel1 = new JLabel ( ) ;

jLabel3 = new JLabel ( ) ;

jLabel4 = new JLabel ( ) ;

85

Page 86: AES Algorithm Implementation

A.E.S.

jRadioBut ton1 = new JRadioBut ton() ;

jRadioBut ton2 = new JRadioBut ton() ;

jRadioBut ton3 = new JRadioBut ton() ;

jRadioBut ton4 = new JRadioBut ton() ;

jRadioBut ton5 = new JRadioBut ton() ;

jComboBox1 = new JComboBox() ;

jComboBox1.addI tem("128") ;

jComboBox1.addI tem("192") ;

jComboBox1.addI tem("256") ;

jComboBox1.se tToolTipText("se lec t key s ize") ;

jBut ton1 = new JBut ton() ;

jBut ton2 = new JBut ton() ;

jBut ton3 = new JBut ton() ;

contentPane = (JPanel ) th is .ge tContentPane() ;

jLabel1 .se tText ("Execut ion Time:") ;

jLabel3 .se tText (" jLabel3") ;

jLabel4 .se tText ("Advanced Encrypt ion Standards") ;

jRadioBut ton1.se tText ("Encrypt ion") ;

jRadioBut ton1.se tSelec ted( t rue) ;

jRadioBut ton1.addI temLis tener(new I temLis tener( )

{

publ ic void i temSta teChanged(I temEvent e)

{

jRadioBut ton1_i temSta teChanged(e) ;

86

Page 87: AES Algorithm Implementation

A.E.S.

}

}) ;

jRadioBut ton2.se tText ("Decrypt ion") ;

jRadioBut ton2.se tSelec ted(fa lse) ;

jRadioBut ton2.addI temLis tener(new I temLis tener( ) {

publ ic void i temSta teChanged(I temEvent e)

{

jRadioBut ton2_i temSta teChanged(e) ;

}

} ) ;

jRadioBut ton3.se tText ("128") ;

jRadioBut ton3.se tSelec ted( t rue) ;

jRadioBut ton3.addI temLis tener(new I temLis tener( ) {

publ ic void i temSta teChanged(I temEvent e)

{

jRadioBut ton3_i temSta teChanged(e) ;

}

} ) ;

jRadioBut ton4.se tText ("192") ;

jRadioBut ton4.se tSelec ted(fa lse) ;

jRadioBut ton4.addI temLis tener(new I temLis tener( ) {

publ ic void i temSta teChanged(I temEvent e)

{

jRadioBut ton4_i temSta teChanged(e) ;

87

Page 88: AES Algorithm Implementation

A.E.S.

}

}) ;

jRadioBut ton5.se tText ("256") ;

jRadioBut ton5.se tSelec ted(fa lse) ;

jRadioBut ton5.addI temLis tener(new I temLis tener( ) {

publ ic void i temSta teChanged(I temEvent e)

{

jRadioBut ton5_i temSta teChanged(e) ;

}

} ) ;

jComboBox1.addAct ionLis tener(new Act ionLis tener( ) {

publ ic void ac t ionPerformed(Act ionEvent e )

{

jComboBox1_act ionPerformed(e) ;

}

} ) ;

jBut ton1.se tText ("Pla in Text") ;

jBut ton1.addAct ionLis tener(new Act ionLis tener( ) {

publ ic void ac t ionPerformed(Act ionEvent e )

{

jBut ton1_act ionPerformed(e) ;

}

} ) ;

jBut ton2.se tText ("Key") ;

88

Page 89: AES Algorithm Implementation

A.E.S.

jBut ton2.addAct ionLis tener(new Act ionLis tener( ) {

publ ic void ac t ionPerformed(Act ionEvent e )

{

jBut ton2_act ionPerformed(e) ;

}

} ) ;

jBut ton3.se tText ("Output") ;

jBut ton3.addAct ionLis tener(new Act ionLis tener( ) {

publ ic void ac t ionPerformed(Act ionEvent e )

{

jBut ton3_act ionPerformed(e) ;

}

} ) ;

contentPane .se tLayout(nul l ) ;

contentPane .se tBackground(newColor(228,217,217)) ;

addComponent(contentPane , jLabel1 , 12 ,348,80,27) ;

addComponent(contentPane , jLabel4 , 12 ,16,331,83) ;

addComponent(contentPane , jLabel3 , 133,349,60,26) ;

addComponent(contentPane , jRadioBut ton1,26,122,100,24) ;

addComponent(contentPane , jRadioBut ton2,248,122,100,24) ;

addComponent(contentPane , jRadioBut ton3, 26 ,156,100,24) ;

addComponent(contentPane , jRadioBut ton4,149,156,100,24) ;

addComponent(contentPane , jRadioBut ton5,272,156,100,24) ;

addComponent(contentPane , jComboBox1, 135,103,100,21) ;

89

Page 90: AES Algorithm Implementation

A.E.S.

addComponent(contentPane , jBut ton1, 12 ,213,83,28) ;

addComponent(contentPane , jBut ton2, 12 ,254,83,28) ;

addComponent(contentPane , jBut ton3, 12 ,295,83,28) ;

th is . se tTi t le ("crypto1 - extends JFrame") ;

th is . se tLocat ion(new Point (0 , 0) ) ;

th is . se tSize(new Dimension(400, 432)) ;

}

pr iva te void addComponent(Conta iner conta iner ,Component c , in t x , in t y , in t width , in t he ight )

{ c . se tBounds(x ,y ,width ,he ight ) ;

conta iner .add(c) ;

}

pr iva te void jRadioBut ton1_i temSta teChanged(I temEvent e)

{ Sys tem.out .pr in t ln(" \n jRadioBut ton1_i temSta teChanged(I temEvent e) ca l led .") ;

Sys tem.out .pr in t ln(">>" + ( (e .ge tSta teChange() == I temEvent .SELECTED) ? "se lec ted" :"unse lec ted")) ;

}

pr iva te void jRadioBut ton2_i temSta teChanged(I temEvent e)

{

Sys tem.out .pr in t ln(" \n jRadioBut ton2_i temSta teChanged(I temEvent e) ca l led .") ;

Sys tem.out .pr in t ln(">>" + ( (e .ge tSta teChange() == I temEvent .SELECTED) ? "se lec ted" :"unse lec ted")) ;

/ / TODO: Add any handl ing code here

90

Page 91: AES Algorithm Implementation

A.E.S.

}

pr iva te void jRadioBut ton3_i temSta teChanged(I temEvent e)

{

Sys tem.out .pr in t ln(" \n jRadioBut ton3_i temSta teChanged(I temEvent e) ca l led .") ;

Sys tem.out .pr in t ln(">>" + ( (e .ge tSta teChange() == I temEvent .SELECTED) ? "se lec ted" :"unse lec ted")) ;

}

pr iva te void jRadioBut ton4_i temSta teChanged(I temEvent e)

{

Sys tem.out .pr in t ln(" \n jRadioBut ton4_i temSta teChanged(I temEvent e) ca l led .") ;

Sys tem.out .pr in t ln(">>" + ( (e .ge tSta teChange() == I temEvent .SELECTED) ? "se lec ted" :"unse lec ted")) ;

}

pr iva te void jRadioBut ton5_i temSta teChanged(I temEvent e)

{

Sys tem.out .pr in t ln(" \n jRadioBut ton5_i temSta teChanged(I temEvent e) ca l led .") ;

Sys tem.out .pr in t ln(">>" + ( (e .ge tSta teChange() == I temEvent .SELECTED) ? "se lec ted" :"unse lec ted")) ;

}

pr iva te void jComboBox1_act ionPerformed(Act ionEvent e )

{

Sys tem.out .pr in t ln(" \n jComboBox1_act ionPerformed(Act ionEvent e ) ca l led .") ;

91

Page 92: AES Algorithm Implementation

A.E.S.

Objec t o = jComboBox1.getSelec tedI tem() ;

Sys tem.out .pr in t ln(">>" + ( (o==nul l )? "nul l" : o . toSt r ing() ) + " i s se lec ted .") ;

}

pr iva te void jBut ton1_act ionPerformed(Act ionEvent e )

{

in t a r r len = 10000;

byte[ ] inf i le = new byte[ar r len] ;

Frame parent = new Frame() ;

Fi leDia log fd = new Fi leDia log(parent , "Please choose a f i le :" ,

F i leDia log.LOAD);

fd .show() ;

St r ing se lec tedI tem = fd .ge tFi le( ) ;

i f ( se lec tedI tem == nul l ) {

} e lse {

Fi le f f i le = new Fi le( fd .ge tDirec tory() + Fi le . separa tor + fd .ge tFi le( ) ) ;

Sys tem.out .pr in t ln("reading f i le " + fd .ge tDirec tory() + F i le . separa tor + fd .ge tFi le( ) ) ;

t ry {

Fi leInputSt ream f is = new Fi leInputSt ream(ff i le ) ;

BufferedInputSt ream bis = newBufferedInputSt ream(f is ) ;

DataInputSt ream dis = new DataInputSt ream(bis) ;

t ry {

in t f i le length = d is . read( inf i le ) ;

92

Page 93: AES Algorithm Implementation

A.E.S.

S t r ing f i les t r ing = new Str ing( inf i le , 0 , f i le length) ;

Sys tem.out .pr in t ln("FILE CONTENT=" + f i les t r ing) ;

} ca tch(IOExcept ion iox) {

System.out .pr in t ln("Fi le read er ror . . . " ) ;

iox .pr in tStackTrace() ;

}

} ca tch (Fi leNotFoundExcept ion fnf) {

System.out .pr in t ln("Fi le not found. . . " ) ;

fnf .pr in tStackTrace() ;

}

}

}

pr iva te void jBut ton2_act ionPerformed(Act ionEvent e )

{

in t a r r len = 10000;

byte[ ] inf i le = new byte[ar r len] ;

Frame parent = new Frame() ;

Fi leDia log fd = new Fi leDia log(parent , "Please choose a f i le :" ,

F i leDia log.LOAD);

fd .show() ;

St r ing se lec tedI tem = fd .ge tFi le( ) ;

i f ( se lec tedI tem == nul l ) {

} e lse {

93

Page 94: AES Algorithm Implementation

A.E.S.

F i le f f i le = new Fi le( fd .ge tDirec tory() + Fi le . separa tor + fd .ge tFi le( ) ) ;

/ / read the f i le

System.out .pr in t ln("reading f i le " + fd .ge tDirec tory() +

F i le . separa tor + fd .ge tFi le( ) ) ;

t ry {

Fi leInputSt ream f is = new Fi leInputSt ream(ff i le ) ;

BufferedInputSt ream bis = new BufferedInputSt ream(f is ) ;

DataInputSt ream dis = new DataInputSt ream(bis) ;

t ry {

in t f i le length = d is . read( inf i le ) ;

St r ing f i les t r ing = new Str ing( inf i le , 0 , f i le length) ;

System.out .pr in t ln("FILE CONTENT=" + f i les t r ing) ;

} ca tch(IOExcept ion iox) {

System.out .pr in t ln("Fi le read er ror . . . " ) ;

iox .pr in tStackTrace() ;

}

} ca tch (Fi leNotFoundExcept ion fnf) {

System.out .pr in t ln("Fi le not found. . . " ) ;

fnf .pr in tStackTrace() ;

}

}

}

pr iva te void jBut ton3_act ionPerformed(Act ionEvent e )

94

Page 95: AES Algorithm Implementation

A.E.S.

{

in t a r r len = 10000;

byte[ ] inf i le = new byte[ar r len] ;

Frame parent = new Frame() ;

Fi leDia log fd = new Fi leDia log(parent , "Please choose a f i le :" ,

F i leDia log.LOAD);

fd .show() ;

St r ing se lec tedI tem = fd .ge tFi le( ) ;

i f ( se lec tedI tem == nul l ) {

} e lse {

Fi le f f i le = new Fi le( fd .ge tDirec tory() + Fi le . separa tor + fd .ge tFi le( ) ) ;

Sys tem.out .pr in t ln("reading f i le " + fd .ge tDirec tory() + Fi le . separa tor + fd .ge tFi le( ) ) ;

t ry {

Fi leInputSt ream f is = new Fi leInputSt ream(ff i le ) ;

BufferedInputSt ream bis = new BufferedInputSt ream(f is ) ;

DataInputSt ream dis = new DataInputSt ream(bis) ;

t ry {

in t f i le length = d is . read( inf i le ) ;

St r ing f i les t r ing = new Str ing( inf i le , 0 , f i le length) ;

System.out .pr in t ln("FILE CONTENT=" + f i les t r ing) ;

} ca tch(IOExcept ion iox) {

95

Page 96: AES Algorithm Implementation

A.E.S.

Sys tem.out .pr in t ln("Fi le read er ror . . . " ) ;

iox .pr in tStackTrace() ;

}

} ca tch (Fi leNotFoundExcept ion fnf) {

System.out .pr in t ln("Fi le not found. . . " ) ;

fnf .pr in tStackTrace() ;

}

}

}

publ ic s ta t ic void main(St r ing[] a rgs)

{

JFrame.se tDefaul tLookAndFeelDecora ted( t rue) ;

JDia log.se tDefaul tLookAndFeelDecora ted( t rue) ;

t ry

{

UIManager .se tLookAndFeel ("com.sun. java .swing.plaf .windows.WindowsLookAndFeel") ;

}

ca tch (Except ion ex)

{

Sys tem.out .pr in t ln("Fai led loading L&F: ") ;

Sys tem.out .pr in t ln(ex) ;

}

new crypto1() ;}}

96

Page 97: AES Algorithm Implementation

A.E.S.

FUNCTION WISE

Eng2Hex

impor t java . io .* ;

impor t java . lang.*;

/**

Class conver ts the user f i le to be encrypted(ASCII fomrat )

to i t s equivalent Hexa-Decimal format as requi red by the

appl ica t ion .

* /

publ ic c lass Eng2Hex

{

Fi leInputSt ream fs t ream;

DataInputSt ream in ;

in t ch;

in t ch2;

in t length;

Fi leOutputSt ream out ;

Pr in tSt ream p;

void conver t (St r ing f i leName)

{

Str ing Hex=new Str ing() ;

97

Page 98: AES Algorithm Implementation

A.E.S.

length=0;

t ry

{

out = new Fi leOutputSt ream("in ter im. tx t") ;

p = new Pr in tSt ream( out ) ; / /he lps to pr in t the da ta in f i le wi thout except ion(copies the or ig ina l da ta)

f s t ream = new Fi leInputSt ream(f i leName); / / Input f i le passed for opening

in = new DataInputSt ream(fs t ream);

}

catch(IOExcept ion e)

{

System.out .pr in t ln("Error opening f i le " ) ;

}

t ry

{

whi le( (ch = in . read() ) !=-1)

{

Hex="\0" ;

Hex=toHex(ch) ;

length+=Hex. length() ;

St r ing reversed = new Str ing() ;

for ( in t i=0; i<Hex. length() ; i++)

{

98

Page 99: AES Algorithm Implementation

A.E.S.

reversed = Hex.subs t r ing( i , i+1) + reversed;

}

p.pr in t ( reversed) ;

}

/ /NOW IT IS REQUIRED TO APPEND SPACES TO THE TEXT SO AS TO MAKE ITS LENGTH A MULTIPLE OF 32

int addi t ions=0;

i f ( length%32!=0) addi t ions=32-( length%32);

for( in t i=0; i<addi t ions ; i++)

{

p.pr in t ("20") ;

}

p .c lose() ;

in .c lose() ;

}

ca tch ( IOExcept ion e)

{

System.out .pr in t ln("Except ion reading charac ter") ;

}

}

Str ing toHex( in t ch)

{

in t n=ch;

in t i=0;

in t t ;

99

Page 100: AES Algorithm Implementation

A.E.S.

char hex= ' \0 ' ;

S t r ing HexTemp=new Str ing() ;

HexTemp="";

whi le(n>0)

{

t=n%16;

n=n/16;

swi tch( t )

{

case (10) : { hex= 'A' ; break;}

case (11) : { hex= 'B ' ; break;}

case (12) : { hex= 'C ' ; break;}

case (13) : { hex= 'D' ; break;}

case (14) : { hex= 'E ' ; break;}

case (15) : { hex= 'F ' ; break;}

defaul t : { hex=(char) ( t+48) ; break;}

}

HexTemp+=hex;

i++;

}

i f (ch<16)

HexTemp = HexTemp + "0" ;

re turn(HexTemp);

}

100

Page 101: AES Algorithm Implementation

A.E.S.

void toEng(Str ing f i leName)

{

Str ing Hex=new Str ing() ;

in t ch1=0;

t ry

{

St r ing Eng;

out = new Fi leOutputSt ream(f i leName);

p = new Pr in tSt ream( out ) ;

f s t ream = new Fi leInputSt ream("in ter im. tx t") ;

in = new DataInputSt ream(fs t ream);

whi le( (ch1 = in . read() ) !=-1)

{

ch2= in . read() ;

in t no=0;

swi tch(ch1)

{

case (65) : { ch1=10; break;}

case (66) : { ch1=11; break;}

case (67) : { ch1=12; break;}

case (68) : { ch1=13; break;}

case (69) : { ch1=14; break;}

case (70) : { ch1=15; break;}

101

Page 102: AES Algorithm Implementation

A.E.S.

case (97) : { ch1=10; break;}

case (98) : { ch1=11; break;}

case (99) : { ch1=12; break;}

case (100) : { ch1=13; break;}

case (101) : { ch1=14; break;}

case (102) : { ch1=15; break;}

defaul t : { ch1=ch1-48; break;}

}

swi tch(ch2)

{

case (65) : { ch2=10; break;}

case (66) : { ch2=11; break;}

case (67) : { ch2=12; break;}

case (68) : { ch2=13; break;}

case (69) : { ch2=14; break;}

case (70) : { ch2=15; break;}

case (97) : { ch2=10; break;}

case (98) : { ch2=11; break;}

case (99) : { ch2=12; break;}

case (100) : { ch2=13; break;}

case (101) : { ch2=14; break;}

case (102) : { ch2=15; break;}

defaul t : { ch2=ch2-48; break;}

}no=ch2+ch1*16;

102

Page 103: AES Algorithm Implementation

A.E.S.

char chr=(char)no;

p .pr in t (chr) ;

}

p .pr in t ( ' \0 ' ) ;

p .c lose() ;

in .c lose() ;

}

ca tch ( IOExcept ion e)

{

System.out .pr in t ln("Except ion reading charac ter") ;

}}};

GetBytes

impor t java . io .* ;

/**

Takes the input f rom the f i le to be encrypt b lock by b lock.* /

publ ic c lass GetBytes

{

in t f lag=0;

in t temp;

pr iva te St r ing f i lename;

pr iva te in t a r raySize ;

pr iva te Reader in ;

pr iva te DataInputSt ream dis ;

103

Page 104: AES Algorithm Implementation

A.E.S.

/**

Opens the f i le to be read.

* /

publ ic GetBytes(St r ing f i le , in t n)

{

f i lename = f i le ;

ar raySize = n ;

t ry

{

in = new Fi leReader( f i lename) ;

}

ca tch(IOExcept ion e)

{

System.out .pr in t ln("Except ion opening " + f i lename) ;

}

}

/**

Reads the next charac ter of the f i le .

* /

pr iva te char ge tNextChar( )

{

char ch = ' ' ;

t ry

{

104

Page 105: AES Algorithm Implementation

A.E.S.

i f ( ( temp=in. read() )==-1)

{

f lag=1;

in .c lose() ;

}

ch = (char) temp;

}

catch ( IOExcept ion e)

{

System.out .pr in t ln("Except ion reading charac ter") ;

}

re turn ch;

}

/**

Returns the equivalent Hexa-Decimal of the passed ASCII va lue .

* /

pr iva te in t va l (char ch)

{

i f (ch >= '0 ' && ch <= '9 ' )

re turn ch - '0 ' ;

i f (ch >= 'a ' && ch <= ' f ' )

re turn ch - ' a ' + 10;

i f (ch >= 'A ' && ch <= 'F ' )

re turn ch - 'A ' + 10;

105

Page 106: AES Algorithm Implementation

A.E.S.

re turn -1000000;

}

/**

Reads the next two bytes as wr i t ten in the f i le so as to ge t the hexadecimal va lue .

* /

publ ic byte[ ] ge tBytes( )

{

byte[ ] re t = new byte[ar raySize] ;

for ( in t i = 0 ; i < ar raySize ; i++)

{

char ch1 = ge tNextChar( ) ;

i f ( temp==-1)

re turn re t ;

char ch2 = ge tNextChar( ) ;

i f ( temp==-1)

re turn re t ;

re t [ i ] = (byte) (va l (ch1)*16 + va l (ch2)) ;

}

re turn re t ;

}

/**

Gets the number of threads for decrypt ion as used dur ing encrypt ion .

* /

106

Page 107: AES Algorithm Implementation

A.E.S.

publ ic in t ge tThread()

{

in t va l=0;

char ch = ge tNextChar( ) ;

va l = ( temp-48)*100;

ch = ge tNextChar( ) ;

va l = va l + ( temp-48)*10;

ch = ge tNextChar( ) ;

va l = va l + ( temp-48) ;

re turn (va l ) ;

}

/**

Shif t s the f i le pointer to the input f i le ahead by one byte .

* /

publ ic void shi f t ( )

{

t ry

{

temp=in. read() ;

}

ca tch(IOExcept ion e)

{

System.out .pr in t ln(e) ;

}}}

107

Page 108: AES Algorithm Implementation

A.E.S.

PutBytes

impor t java . io .* ;

/**

Class to wr i te the encrypted/decrypted da ta in to the output f i le .

* /

publ ic c lass PutBytes

{

pr iva te s ta t ic f ina l in t Nb = 4;

pr iva te s ta t ic St r ing[] d ig = {"0" ,"1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" ,"8" ,"9" ,"a" ,"b" ,"c" ,"d" ,"e" ," f"} ;

pr iva te DataOutputSt ream dos;

Fi leOutputSt ream fs t ream;

Pr in tSt ream out ;

/**

Opens the f i le to be wri t ten in to .

* /

publ ic PutBytes(St r ing out f i le )

{

t ry

{

fs t ream=new Fi leOutputSt ream(outf i le ) ;

out=new Pr in tSt ream(fs t ream);

}

108

Page 109: AES Algorithm Implementation

A.E.S.

ca tch(IOExcept ion e)

{

System.out .pr in t ln("Except ion Caught in opening f i le : " + out f i le ) ;

}

}

/**Opens f i le to be wri t ten in to in append mode.

*/

publ ic PutBytes(St r ing out f i le , in t f lag)

{

t ry

{

fs t ream=new Fi leOutputSt ream(outf i le ) ;

fs t ream.c lose() ;

fs t ream=new Fi leOutputSt ream(outf i le , t rue) ;

out=new Pr in tSt ream(fs t ream);

}

catch(IOExcept ion e)

{

System.out .pr in t ln("Except ion Caught in opening f i le : " + out f i le ) ;

}

}

/**

Returns the Hexa-Decimal equivalent .

109

Page 110: AES Algorithm Implementation

A.E.S.

* /

publ ic s ta t ic St r ing hex(byte a)

{

re turn d ig[(a & 0xff ) >> 4] + d ig[a & 0x0f] ;

}

/**

Wri tes a one d imensional a r ray in to the output f i le .

* /

publ ic void put (byte[ ] re t )

{

for ( in t i = 0 ; i < re t . length; i++)

{

out .pr in t (hex(re t [ i ] ) ) ;

}

}

/**

Wri tes a one d imensional a r ray in to the output f i le for a se t number of threads .

* /

publ ic void put (byte[ ] re t , in t th)

{

for ( in t i = 0 ; i <16*th; i++)

{

out .pr in t (hex(re t [ i ] ) ) ;}}

110

Page 111: AES Algorithm Implementation

A.E.S.

/**Wri tes a two0dimensional a r ray in to the output f i le .* /

publ ic void put (byte[ ] [ ] re t )

{

for ( in t c = 0 ; c < Nb; c++)

{

for ( in t r = 0 ; r < 4 ; r++)

{

out .pr in t (hex(re t [ r ] [c] ) ) ;

}

}

}

/**

Wri tes the number of threads used dur ing encrypt ion in to

the output f i le .

* /

publ ic void put ( in t thread)

{

out .pr in t ( thread) ;

}

}

111

Page 112: AES Algorithm Implementation

A.E.S.

AEStables

**

This c lass i s the backend of the appl ica t ion . I t in i t ia l izes the S-

Box and other v i ta l a r rays and has a l l the background

computa t ion .

* /

publ ic c lass AEStables

{

publ ic AEStables( )

{

loadE() ;

loadL() ;

loadInv() ;

loadS() ;

loadInvS() ;

loadPowX() ;

}

pr iva te byte[ ] E = new byte[256] ;

pr iva te byte[ ] L = new byte[256] ;

pr iva te byte[ ] S = new byte[256] ;

112

Page 113: AES Algorithm Implementation

A.E.S.

pr iva te byte[ ] invS = new byte[256] ;

The round constant word ar ray .

* /

publ ic byte Rcon( in t i )

{

re turn powX[i-1] ;

}

publ ic byte FFMulFas t (byte a , byte b)

{

in t t = 0 ;

i f (a == 0 | | b == 0)

re turn 0 ;

t = (L[(a & 0xff ) ] & 0xff ) + (L[(b & 0xff ) ] & 0xff ) ;

i f ( t > 255) t = t - 255;

re turn E[( t & 0xff ) ] ;

}

publ ic byte FFMul(byte a , byte b)

{

byte aa = a , bb = b , r = 0 , t ;

113

Page 114: AES Algorithm Implementation

A.E.S.

whi le (aa != 0)

{

i f ( (aa & 1) != 0)

r = (byte) ( r ^ bb) ;

t = (byte) (bb & 0x80) ;

bb = (byte) (bb << 1) ;

i f ( t != 0)

bb = (byte) (bb ^ 0x1b) ;

aa = (byte) ( (aa & 0xff ) >> 1) ;

}

re turn r ;

}

pr iva te void loadE()

{

byte x = (byte)0x01;

in t index = 0 ;

E[ index++] = (byte)0x01;

for ( in t i = 0 ; i < 255; i++)

{

byte y = FFMul(x , (byte)0x03) ;

114

Page 115: AES Algorithm Implementation

A.E.S.

E[ index++] = y ;

x = y ;

}

}

pr iva te void loadL()

{

in t index;

for ( in t i = 0 ; i < 255; i++)

{

L[E[ i ] & 0xff ] = (byte) i ;

}

}

pr iva te void loadS()

{

in t index;

for ( in t i = 0 ; i < 256; i++)

S[ i ] = (byte) (subBytes( (byte) ( i & 0xff ) ) & 0xff ) ;

}

pr iva te void loadInv()

{

115

Page 116: AES Algorithm Implementation

A.E.S.

in t index;

for ( in t i = 0 ; i < 256; i++)

inv[ i ] = (byte) (FFInv((byte) ( i & 0xff ) ) & 0xff ) ;

}

pr iva te void loadInvS()

{

in t index;

for ( in t i = 0 ; i < 256; i++)

{

invS[S[ i ] & 0xff ] = (byte) i ;

}

}

pr iva te void loadPowX()

{

int index;

byte x = (byte)0x02;

byte xp = x ;

powX[0] = 1 ; powX[1] = x ;

for ( in t i = 2 ; i < 15; i++)

{

116

Page 117: AES Algorithm Implementation

A.E.S.

xp = FFMul(xp, x) ;

powX[i] = xp;

}

}

publ ic byte FFInv(byte b)

{

byte e = L[b & 0xff ] ;

re turn E[0xff - (e & 0xff ) ] ;

}

publ ic in t i thBi t (byte b , in t i )

{

in t m[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40,

0x80};

re turn (b & m[i ] ) >> i ;

}

publ ic in t subBytes(byte b)

{

byte inB = b;

in t res = 0 ;

i f (b != 0)

b = (byte) (FFInv(b) & 0xff ) ;

117

Page 118: AES Algorithm Implementation

A.E.S.

byte c = (byte)0x63;

for ( in t i = 0 ; i < 8 ; i++)

{

int temp = 0;

temp = i thBi t (b , i ) ^ i thBi t (b , ( i+4)%8) ^ i thBi t (b , ( i+5)%8) ^

i thBi t (b , ( i+6)%8) ^ i thBi t (b , ( i+7)%8) ^ i thBi t (c , i ) ;

res = res | ( temp << i ) ;

}

re turn res ;

}

}

pr iva te byte[ ] inv = new byte[256] ;

pr iva te byte[ ] powX = new byte[15] ;

/**

Returns the requi red va lue of the S-Box

*/

publ ic byte SBox(byte b)

{

re turn S[b & 0xff ] ;

}

/**

118

Page 119: AES Algorithm Implementation

A.E.S.

Returns the requi red va lue of the Inverse S-Box

*/

publ ic byte InvSBox(byte b)

{ re turn invS[b & 0xff ] ; }

AESencrypt

/**The main implementa t ion of the AES a lgor i thm res ides in

th is c lass .* /

publ ic c lass AESencrypt

{

pr iva te f ina l in t Nb = 4; / /b lock s ize

pr iva te in t Nk; / /key s ize

pr iva te in t Nr ; / / rounds

pr iva te in t wCount ;

pr iva te AEStables tab;

pr iva te byte[ ] w;

/**Ini t ia l izes the var iables of Number of rounds , key s ize and

other v i ta l parameters .

* /

publ ic AESencrypt (byte[ ] key, in t NkIn)

{

Nk = NkIn;

119

Page 120: AES Algorithm Implementation

A.E.S.

Nr = Nk + 6;

tab = new AEStables( ) ;

w = new byte[4*Nb*(Nr+1)] ;

KeyExpansion(key, w) ;

}

/**This i s the ac tua l encrypt ion funct ion of AES. Cal ls a l l the

requis i te funct ions .* /

publ ic void Cipher(byte[ ] in , byte[ ] out )

{

wCount = 0 ;

byte[ ] [ ] s ta te = new byte[4][Nb] ;

Copy.copy(s ta te , in) ;

AddRoundKey(s ta te) ;

for ( in t round = 1 ; round < Nr; round++)

{

/ / Pr in t .pr in tArray("Star t round " + round + " :" ,

s ta te) ;

SubBytes(s ta te) ;

Shi f tRows(s ta te) ;

MixColumns(s ta te) ;

AddRoundKey(s ta te) ;

120

Page 121: AES Algorithm Implementation

A.E.S.

}

/ / Pr in t .pr in tArray("Star t round " + Nr + " :" , s ta te) ;

SubBytes(s ta te) ;

Shi f tRows(s ta te) ;

AddRoundKey(s ta te) ;

Copy.copy(out , s ta te) ;

}

/**

--Deprecated--

*/

publ ic void Cipher(byte[ ] in , byte[ ] out , in t thread)

{

wCount = 0 ;

byte[ ] [ ] s ta te = new byte[4][Nb] ;

Copy.copy(s ta te , in) ;

AddRoundKey(s ta te) ;

for ( in t round = 1 ; round < Nr; round++)

{

/ / Pr in t .pr in tArray("Star t round " + round + " :" , s ta te) ;

SubBytes(s ta te) ;

121

Page 122: AES Algorithm Implementation

A.E.S.

Shi f tRows(s ta te) ;

MixColumns(s ta te) ;

AddRoundKey(s ta te) ;

}

/ / Pr in t .pr in tArray("Star t round " + Nr + " :" , s ta te) ;

SubBytes(s ta te) ;

Shi f tRows(s ta te) ;

AddRoundKey(s ta te) ;

Copy.copy(out , s ta te , thread) ;

}

/**

This i s the decrypt ion funct ion of AES. Cal ls a l l the

requis i te funct ions .

* /

publ ic void InvCipher(byte[ ] in , byte[ ] out )

{

wCount = 4*Nb*(Nr+1) ;

byte[ ] [ ] s ta te = new byte[4][Nb] ;

Copy.copy(s ta te , in) ;

InvAddRoundKey(s ta te) ;

for ( in t round = Nr-1; round >= 1; round-- )

122

Page 123: AES Algorithm Implementation

A.E.S.

{

/ / Pr in t .pr in tArray("Star t round " + (Nr - round) + " :" ,

s ta te) ;

InvShif tRows(s ta te) ;

InvSubBytes(s ta te) ;

InvAddRoundKey(s ta te) ;

InvMixColumns(s ta te) ;

/ / Pr in t .pr in tArray("Star t round " + Nr + " :" , s ta te) ;

InvShif tRows(s ta te) ;

InvSubBytes(s ta te) ;

InvAddRoundKey(s ta te) ;

Copy.copy(out , s ta te) ;

}

/**

--Deprecated--

*/

publ ic void InvCipher(byte[ ] in , byte[ ] out , in t thread)

{

wCount = 4*Nb*(Nr+1) ;

byte[ ] [ ] s ta te = new byte[4][Nb] ;

Copy.copy(s ta te , in) ;

123

Page 124: AES Algorithm Implementation

A.E.S.

InvAddRoundKey(s ta te) ;

for ( in t round = Nr-1; round >= 1; round-- )

{

/ / Pr in t .pr in tArray("Star t round " + (Nr - round) + " :" ,

s ta te) ;

InvShif tRows(s ta te) ;

InvSubBytes(s ta te) ;

InvAddRoundKey(s ta te) ;

InvMixColumns(s ta te) ;

}

/ / Pr in t .pr in tArray("Star t round " + Nr + " :" , s ta te) ;

InvShif tRows(s ta te) ;

InvSubBytes(s ta te) ;

InvAddRoundKey(s ta te) ;

Copy.copy(out , s ta te , thread) ;

}

/**The AES a lgor i thm takes the Cipher Key, K, and performs a

Key Expansion rout ine to genera te a key schedule . The Key

Expansion genera tes a to ta l of Nb (Nr + 1) words : the

a lgor i thm requi res an in i t ia l se t of Nb words , and each of the

Nr rounds requi res Nb words of key da ta . The resul t ing key

schedule consis t s of a l inear a r ray of 4-byte words , denoted [wi

] , wi th i in the range .0 <= i < Nb(Nr + 1) .* /

124

Page 125: AES Algorithm Implementation

A.E.S.

pr iva te void KeyExpansion(byte[ ] key, byte[ ] w)

{

byte[ ] temp = new byte[4] ;

in t j = 0 , i=0;

whi le ( j < 4*Nk)

{

w[j ] = key[ j++] ;

}

whi le( j < 4*Nb*(Nr+1))

{

i = j /4 ;

for ( in t iTemp = 0; iTemp < 4; iTemp++)

temp[iTemp] = w[j -4+iTemp];

i f ( i % Nk == 0)

{

byte t temp, tRcon;

byte o ld temp0 = temp[0] ;

for ( in t iTemp = 0; iTemp < 4; iTemp++)

{

i f ( iTemp == 3)

125

Page 126: AES Algorithm Implementation

A.E.S.

t temp = old temp0;

e lse t temp = temp[iTemp+1];

i f ( iTemp == 0)

tRcon = tab .Rcon( i /Nk) ;

e lse

tRcon = 0 ;

temp[iTemp] = (byte) ( tab .SBox( t temp) ^ tRcon) ;

}

}

else i f (Nk > 6 && ( i%Nk) == 4)

{

for ( in t iTemp = 0; iTemp < 4; iTemp++)

temp[iTemp] = tab .SBox( temp[iTemp]) ;

}

for ( in t iTemp = 0; iTemp < 4; iTemp++)

w[j+iTemp] = (byte) (w[j - 4*Nk + iTemp] ^ temp[iTemp]) ;

j = j + 4 ;

}

}

/**

126

Page 127: AES Algorithm Implementation

A.E.S.

Transformat ion in the Cipher tha t processes the Sta te

us ing a nonl inear byte subs t i tu t ion table (S-box) tha t opera tes

on each of the Sta te bytes independent ly .

* /

pr iva te void SubBytes(byte[ ] [ ] s ta te)

{

for ( in t row = 0; row < 4; row++)

{

for ( in t col = 0 ; col < Nb; col++)

{

s ta te[ row][col ] = tab .SBox(s ta te[ row]

[col ] ) ;

}

}

}

/**

Is the inverse of the byte subs t i tu t ion t ransformat ion, in

which the inverse Sbox i s appl ied to each byte of the Sta te .* /

pr iva te void InvSubBytes(byte[ ] [ ] s ta te)

{

for( in t row = 0; row < 4; row++)

{

127

Page 128: AES Algorithm Implementation

A.E.S.

for ( in t col = 0 ; col < Nb; col++)

{

s ta te[ row][col ] = tab . InvSBox(s ta te[ row][col ] ) ;

}

}

}

/**

Transformat ion in the Cipher tha t processes the Sta te by

cycl ica l ly sh i f t ing the las t three rows of the Sta te by d i f ferent

of fse ts .

* /

pr iva te void Shi f tRows(byte[ ] [ ] s ta te)

{

byte[ ] t sh i f t = new byte[4] ;

for ( in t r = 1 ; r < 4 ; r++)

{

for ( in t c = 0 ; c < Nb; c++)

tshi f t [c] = s ta te[ r ] [ (c + r )%Nb];

for ( in t c = 0 ; c < Nb; c++)

s ta te[ r ] [c] = t sh i f t [c] ;

}

128

Page 129: AES Algorithm Implementation

A.E.S.

}

/**

Inverse of the Shi f tRows() t ransformat ion. The bytes in

the las t three rows of the Sta te are cycl ica l ly sh i f ted over

d i f ferent numbers of bytes (of fse ts ) .

* /

pr iva te void InvShif tRows(byte[ ] [ ] s ta te)

{

byte[ ] t sh i f t = new byte[4] ;

for ( in t r = 1 ; r < 4 ; r++)

{

for ( in t c = 0 ; c < Nb; c++)

tshi f t [c] = s ta te[ r ] [ (Nb-(r -c) )%Nb];

for ( in t c = 0 ; c < Nb; c++)

s ta te[ r ] [c] = t sh i f t [c] ;

} }

/**

The MixColumns() t ransformat ion opera tes on the Sta te

column-by-column, t rea t ing each column as a four- term

polynomial . The columns are considered as polynomials over

GF(2^8) and mul t ip l ied modulo x^4 + 1 wi th a f ixed

polynomial a (x) , g iven by a(x) = {03}x^3 + {01}x^2 + {01}x +

{02}.

129

Page 130: AES Algorithm Implementation

A.E.S.

* /

pr iva te void MixColumns(byte[ ] [ ] s )

{

in t [ ] sdash = new in t [4] ;

byte b02 = (byte)0x02, b03 = (byte)0x03;

for ( in t c = 0 ; c < 4 ; c++)

{

sdash[0]=tab .FFMul(b02,s[0][c] )^ tab .FFMul(b03,s[1]

[c] ) ^ s [2][c] ^ s [3][c] ;

sdash[1]=s[0][c]^ tab .FFMul(b02,s[1][c] )^

tab .FFMul(b03,s[2][c] ) ^ s [3][c] ;

sdash[2] = s [0][c] ^ s [1][c] ^ tab .FFMul(b02,s[2][c] ) ^

tab .FFMul(b03,s[3][c] ) ;

sdash[3] = tab .FFMul(b03,s[0][c] ) ^ s [1][c] ^ s [2][c] ^

tab .FFMul(b02,s[3][c] ) ;

for ( in t i = 0 ; i < 4 ; i++)

s[ i ] [c] = (byte) (sdash[ i ] ) ;

}

}

/**

The inverse of the MixColumns() t ransformat ion.

* /

130

Page 131: AES Algorithm Implementation

A.E.S.

pr iva te void InvMixColumns(byte[ ] [ ] s )

{

in t [ ] sdash = new in t [4] ;

byte b0e = (byte)0x0e, b09 = (byte)0x09, b0d = (byte)0x0d,

b0b = (byte)0x0b;

for ( in t c = 0 ; c < 4 ; c++)

{

sdash[0]=tab .FFMul(b0e ,s [0][c] )^ tab .FFMul(b0b,s[1][c] ) ^

tab .FFMul(b0d,s[2][c] ) ^ tab .FFMul(b09,s[3][c] ) ;

sdash[1]=tab .FFMul(b09,s[0][c] ) ^ tab .FFMul(b0e ,s [1][c] )

^ tab .FFMul(b0b,s[2][c] ) ^ tab .FFMul(b0d,s[3][c] ) ;

sdash[2]=tab .FFMul(b0d,s[0][c] ) ^ tab .FFMul(b09,s[1][c] )

^ tab .FFMul(b0e ,s [2][c] ) ^ tab .FFMul(b0b,s[3][c] ) ;

sdash[3]=tab .FFMul(b0b,s[0][c] ) ^ tab .FFMul(b0d,s[1][c] )

^ tab .FFMul(b09,s[2][c] ) ^ tab .FFMul(b0e ,s [3][c] ) ;

for ( in t i = 0 ; i < 4 ; i++)

s[ i ] [c] = (byte) (sdash[ i ] ) ;

}

}

/**

Round Key is added to the Sta te by a s imple b i twise XOR

opera t ion . Each Round Key consis ts of Nb words f rom the key

schedule .

131

Page 132: AES Algorithm Implementation

A.E.S.

* /

pr iva te void AddRoundKey(byte[ ] [ ] s ta te)

{

for ( in t c = 0 ; c < Nb; c++)

{

for ( in t r = 0 ; r < 4 ; r++)

{

s ta te[ r ] [c] = (byte) (s ta te[ r ] [c] ^ w[wCount++]) ;

}

}

}

pr iva te void InvAddRoundKey(byte[ ] [ ] s ta te)

{

for ( in t c = Nb - 1 ; c >= 0; c - - )

{

for ( in t r = 3 ; r >= 0 ; r - - )

{

s ta te[ r ] [c] = (byte) (s ta te[ r ] [c] ^ w[--wCount] ) ;

}}

} }

AESecbmult i

/ / 128-bi t use 16, 16 , and 4 be low

/ / 192-bi t use 16, 24 and 6 be low

132

Page 133: AES Algorithm Implementation

A.E.S.

/ / 256-bi t use 16, 32 and 8 be low

impor t java . io .* ;

publ ic c lass AESecbmul t i

{

s ta t ic AESencrypt aes2 , aes3;

s ta t ic NThreadecb nt1 ,n t2 ,n t3 ;

s ta t ic byte[ ] out2;

s ta t ic byte[ ] out3;

publ ic s ta t ic void main(St r ing[] a rgs) throws IOExcept ion

{

Str ing f i le ,keyf i le ,encdec , out f i le , in i tvecf i le ;

in t f lag=1,numbi ts=1, th=0;

byte[ ] in ;

long s tar t , end;

BufferedReader br = new BufferedReader(new InputSt reamReader(System. in)) ;

whi le( f lag>0)

{

Sys tem.out .pr in t ln("1 . Encrypt ion") ;

Sys tem.out .pr in t ln("2 . Decrypt ion") ;

encdec = br . readLine() ;

Sys tem.out .pr in t ln("") ;

f lag = In teger .parseInt (encdec) ;

i f ( f lag==1| | f lag==2)

break;

e l se

133

Page 134: AES Algorithm Implementation

A.E.S.

{

Sys tem.out .pr in t ln("Erronous Input . . . t ry again . . " ) ;

f lag=1;

}

}

whi le(numbi ts>0)

{

Sys tem.out .pr in t ln("1 . 128-bi t" ) ;

Sys tem.out .pr in t ln("2 . 192-bi t" ) ;

Sys tem.out .pr in t ln("3 . 256-bi t" ) ;

encdec = br . readLine() ;

numbi ts = In teger .parseInt (encdec) ;

i f (numbi ts==1)

{

numbi ts=4;

break;

}

e l se i f (numbi ts==2)

{

numbi ts=6;

134

Page 135: AES Algorithm Implementation

A.E.S.

break;

}

e l se i f (numbi ts==3)

{

numbi ts=8;

break;

}

e l se

{

Sys tem.out .pr in t ln("Erroneous Input . . . . t ry

again") ;

Sys tem.out .pr in t ln("") ;

numbi ts=1;

}

}

System.out .pr in t ln("Enter fu l l pa th of the f i le : " ) ;

f i le = br . readLine() ;

Sys tem.out .pr in t ln("") ;

Sys tem.out .pr in t ln("") ;

Sys tem.out .pr in t ln("Enter fu l l pa th of key f i le") ;

keyf i le = br . readLine() ;

135

Page 136: AES Algorithm Implementation

A.E.S.

Sys tem.out .pr in t ln("") ;

Sys tem.out .pr in t ln("") ;

Sys tem.out .pr in t ln("Enter pa th of output f i le : " ) ;

out f i le = br . readLine() ;

Eng2Hex eng = new Eng2Hex() ;

i f ( f lag==1)

{

eng.conver t ( f i le ) ;

}

PutBytes put f i le ;

GetBytes ge t Input ;

i f ( f lag==1)

{

putf i le = new PutBytes(out f i le ) ;

ge t Input = new GetBytes(" in ter im. tx t" , 16) ;

}

e lse

{

putf i le = new PutBytes(" in ter im. tx t" ,1) ;

ge t Input = new GetBytes( f i le , 16) ;

136

Page 137: AES Algorithm Implementation

A.E.S.

}

s tar t = System.currentTimeMil l i s ( ) ;

GetBytes ge tKey = new GetBytes(keyf i le ,

numbi ts*4) ;

byte[ ] key = ge tKey.getBytes( ) ;

AESencrypt aes1 = new AESencrypt (key, numbi ts ) ;

i f ( f lag!=1)

{

aes2 = new AESencrypt (key, numbi ts ) ;

aes3 = new AESencrypt (key, numbi ts ) ;

out2 = new byte[16] ;

out3 = new byte[16] ;

}

byte[ ] out1 = new byte[16] ;

Pr in t .pr in tArray("Key: " , key) ;

whi le(get Input . f lag!=1)

{

in = ge t Input .ge tBytes( ) ;

i f (ge t Input . f lag!=1)

{

System.out .pr in t ("") ;

137

Page 138: AES Algorithm Implementation

A.E.S.

i f ( f lag==1)

{

Pr in t .pr in tArray("Pla in text : " , in) ;

aes1 .Cipher( in , out1) ;

Pr in t .pr in tArray("Cipher text : " , out1) ;

put f i le .put (out1) ;

}

e lse

{

th=0;

nt1= new NThreadecb("One" , in ,aes1 ,out1) ;

i f (ge t Input . f lag!=1)

{

in = ge t Input .ge tBytes( ) ;

i f (ge t Input . f lag!=1)

{

nt2= new NThreadecb("Two", in ,aes2 ,out2) ;

th++;

}

}

138

Page 139: AES Algorithm Implementation

A.E.S.

i f (ge t Input . f lag!=1)

{

in = ge t Input .ge tBytes( ) ;

i f (ge t Input . f lag!=1)

{

nt3=newNThreadecb("Three" , in ,aes3 ,out3) ;

th++;

}

}

t ry

{

System.out .pr in t ln("Wai t ing for threads to f in ish .") ;

n t1 . t . jo in() ;

put f i le .put (out1) ;

i f ( th>=1)

{

nt2 . t . jo in() ;

put f i le .put (out2) ;

}

139

Page 140: AES Algorithm Implementation

A.E.S.

i f ( th==2)

{

nt3 . t . jo in() ;

put f i le .put (out3) ;

}

}

catch ( In ter ruptedExcept ion e)

{

System.out .pr in t ln("Main thread In ter rupted") ;

}

}

}

}

end = System.currentTimeMil l i s ( ) ;

i f ( f lag!=1)

{

eng. toEng(out f i le ) ;

}

System.out .pr in t ln("Execut ion t ime i s : "+ (end-s tar t ) ) ;

140

Page 141: AES Algorithm Implementation

A.E.S.

}

}

NThreadecb

class NThreadecb implements Runnable

{

/ / St r ing name; / / name of thread

Thread t ;

AESencrypt taes ;

byte[ ] t in ;

byte[ ] tout ;

NThreadecb(St r ing threadname, byte[ ] in , AESencrypt aes ,

byte[ ] out )

{

/ / name = threadname;

t in = new byte[16] ;

System.arraycopy( in ,0 , t in ,0 , in . length) ;

tout = out ;

taes=aes ;

t = new Thread( th is , threadname);

141

Page 142: AES Algorithm Implementation

A.E.S.

Sys tem.out .pr in t ln("New thread: " + t ) ;

t . s ta r t ( ) ; / / S tar t the thread

}

/ / Ent ry point for thread.

publ ic void run()

{

t ry

{

Pr in t .pr in tArray("Cipher text : " , t in) ;

taes . InvCipher( t in , tout ) ;

Pr in t .pr in tArray("Pla inText : " , tout ) ;

}

ca tch (Except ion e)

{

System.out .pr in t ln(" in ter rupted .") ;

}

System.out .pr in t ln("Thread Ends . . . . " ) ;

}}

AEStestcbc

142

Page 143: AES Algorithm Implementation

A.E.S.

/ / 128-bi t use 16, 16 , and 4 be low

/ / 192-bi t use 16, 24 and 6 be low

/ / 256-bi t use 16, 32 and 8 be low

impor t java . io .* ;

publ ic c lass AEStes tcbc

{

publ ic s ta t ic void main(St r ing[] a rgs) throws IOExcept ion

{

Str ing f i le ,keyf i le ,encdec , out f i le , in i tvecf i le ;

in t f lag=1,numbi ts=1;

byte[ ] in ;

byte[ ] iv ;

long s tar t , end;

BufferedReader br=new BufferedReader(new

InputSt reamReader(System. in)) ;

whi le( f lag>0)

{

Sys tem.out .pr in t ln("1 . Encrypt ion") ;

Sys tem.out .pr in t ln("2 . Decrypt ion") ;

encdec = br . readLine() ;

Sys tem.out .pr in t ln("") ;

143

Page 144: AES Algorithm Implementation

A.E.S.

f lag = In teger .parseInt (encdec) ;

i f ( f lag==1| | f lag==2)

break;

e l se

{

Sys tem.out .pr in t ln("Erronous Input . . . t ry again . . " ) ;

f lag=1;

}

}

whi le(numbi ts>0)

{

Sys tem.out .pr in t ln("1 . 128-bi t" ) ;

Sys tem.out .pr in t ln("2 . 192-bi t" ) ;

Sys tem.out .pr in t ln("3 . 256-bi t" ) ;

encdec = br . readLine() ;

numbi ts = In teger .parseInt (encdec) ;

i f (numbi ts==1)

{

numbi ts=4;

break;

144

Page 145: AES Algorithm Implementation

A.E.S.

}

e l se i f (numbi ts==2)

{

numbi ts=6;

break;

}

e l se i f (numbi ts==3)

{

numbi ts=8;

break;

}

e l se

{

Sys tem.out .pr in t ln("Erroneous Input . . . . t ry again") ;

Sys tem.out .pr in t ln("") ;

numbi ts=1;

}

}

System.out .pr in t ln("Enter fu l l pa th of the f i le : " ) ;

f i le = br . readLine() ;

145

Page 146: AES Algorithm Implementation

A.E.S.

Sys tem.out .pr in t ln("") ;

Sys tem.out .pr in t ln("") ;

Sys tem.out .pr in t ln("Enter fu l l pa th of key f i le") ;

keyf i le = br . readLine() ;

Sys tem.out .pr in t ln("") ;

Sys tem.out .pr in t ln("") ;

Sys tem.out .pr in t ln("Enter pa th of output f i le : " ) ;

out f i le = br . readLine() ;

Sys tem.out .pr in t ln("Enter the pa th of the IV f i le :" ) ;

in i tvecf i le = br . readLine() ;

GetBytes in i tvec ;

in i tvec = new GetBytes( in i tvecf i le , 16) ;

iv = in i tvec .ge tBytes( ) ;

Eng2Hex eng = new Eng2Hex() ;

i f ( f lag==1)

{

eng.conver t ( f i le ) ;

}

PutBytes put f i le ;

GetBytes ge t Input ;

146

Page 147: AES Algorithm Implementation

A.E.S.

i f ( f lag==1)

{

putf i le = new PutBytes(out f i le ) ;

ge t Input = new GetBytes(" in ter im. tx t" , 16) ;

}

e lse

{

putf i le = new PutBytes(" in ter im. tx t") ;

ge t Input = new GetBytes( f i le , 16) ;

}

s tar t = System.currentTimeMil l i s ( ) ;

GetBytes ge tKey = new GetBytes(keyf i le , numbi ts*4) ;

byte[ ] key = ge tKey.getBytes( ) ;

AESencrypt aes = new AESencrypt (key, numbi ts ) ;

byte[ ] out = new byte[16] ;

Pr in t .pr in tArray("Key: " , key) ;

whi le(get Input . f lag!=1)

{

in = ge t Input .ge tBytes( ) ;

i f (ge t Input . f lag!=1)

147

Page 148: AES Algorithm Implementation

A.E.S.

{

System.out .pr in t ("") ;

i f ( f lag==1)

{

Pr in t .pr in tArray("Pla in text : " , in) ;

for (numbi ts=0;numbi ts<16;numbi ts+

+)

{

in[numbi ts ] = (byte) ( in[numbi ts ] ^ iv[numbi ts ] ) ;

}

aes .Cipher( in , out ) ;

Pr in t .pr in tArray("Cipher text : " , out ) ;

Sys tem.arraycopy(out ,0 , iv ,0 ,out . length) ;

}

e lse

{

Pr in t .pr in tArray("Cipher text : " , in) ;

aes . InvCipher( in ,out ) ;

for (numbi ts=0;numbi ts<16;numbi ts+

+)

148

Page 149: AES Algorithm Implementation

A.E.S.

{

out [numbi ts ] = (byte) (out [numbi ts ] ^ iv[numbi ts ] ) ;

}

System.arraycopy( in ,0 , iv ,0 , in . length) ;

Pr in t .pr in tArray("Pla inText : " , out ) ;

}

put f i le .put (out ) ;

}

}

end = System.currentTimeMil l i s ( ) ;

i f ( f lag!=1)

{

eng. toEng(out f i le ) ;

}

System.out .pr in t ln("Excut ion t ime i s :"+ (end-

s tar t ) ) ;

}

}

AEStest

/ /Sequent ia l implementa t ion in ECB mode

149

Page 150: AES Algorithm Implementation

A.E.S.

/ / 128-bi t 16 , 16 , and 4

/ / 192-bi t 16 , 24 and 6

/ / 256-bi t 16 , 32 and 8

impor t java . io .* ;

/** Appl ica t ion implement ing the AES a lgor i thm as def ined in FIPS-197

*/

publ ic c lass AEStes t

{

publ ic s ta t ic void main(St r ing[] a rgs) throws IOExcept ion

{

Str ing f i le ,keyf i le ,encdec , out f i le ;

in t f lag=1,numbi ts=1;

byte[ ] in ;

BufferedReader br = new BufferedReader(new

InputSt reamReader(System. in)) ;

long s tar t ,end;

whi le( f lag>0)

{

Sys tem.out .pr in t ln("1 . Encrypt ion") ;

Sys tem.out .pr in t ln("2 . Decrypt ion") ;

encdec = br . readLine() ;

150

Page 151: AES Algorithm Implementation

A.E.S.

Sys tem.out .pr in t ln("") ;

f lag = In teger .parseInt (encdec) ;

i f ( f lag==1| | f lag==2)

break;

e l se

{

Sys tem.out .pr in t ln("ErronousInput . . . t ry aga in . . " ) ;

f lag=1;

}

}

whi le(numbi ts>0)

{

Sys tem.out .pr in t ln("1 . 128-bi t" ) ;

Sys tem.out .pr in t ln("2 . 192-bi t" ) ;

Sys tem.out .pr in t ln("3 . 256-bi t" ) ;

encdec = br . readLine() ;

numbi ts = In teger .parseInt (encdec) ;

i f (numbi ts==1)

{

numbi ts=4;

151

Page 152: AES Algorithm Implementation

A.E.S.

break;

}

e l se i f (numbi ts==2)

{

numbi ts=6;

break;

}

e l se i f (numbi ts==3)

{

numbi ts=8;

break;

}

e l se

{

Sys tem.out .pr in t ln("Erroneous Input . . . . t ry again") ;

Sys tem.out .pr in t ln("") ;

numbi ts=1;

}

}

System.out .pr in t ln("Enter fu l l pa th of the f i le : " ) ;

152

Page 153: AES Algorithm Implementation

A.E.S.

f i le = br . readLine() ;

Sys tem.out .pr in t ln("") ;

Sys tem.out .pr in t ln("") ;

Sys tem.out .pr in t ln("Enter fu l l pa th of key f i le") ;

keyf i le = br . readLine() ;

Sys tem.out .pr in t ln("") ;

Sys tem.out .pr in t ln("") ;

Sys tem.out .pr in t ln("Enter pa th of output f i le : " ) ;

out f i le = br . readLine() ;

Eng2Hex eng = new Eng2Hex() ;

i f ( f lag==1)

{

eng.conver t ( f i le ) ;

}

PutBytes put f i le ;

GetBytes ge t Input ;

i f ( f lag==1)

{

putf i le = new PutBytes(out f i le ) ;

ge t Input = new GetBytes(" in ter im. tx t" , 16) ;

153

Page 154: AES Algorithm Implementation

A.E.S.

}

e lse

{

putf i le = new PutBytes(" in ter im. tx t") ;

ge t Input = new GetBytes( f i le , 16) ;

}

s tar t = System.currentTimeMil l i s ( ) ;

GetBytes ge tKey = new GetBytes(keyf i le , numbi ts*4) ;

byte[ ] key = ge tKey.getBytes( ) ;

AESencrypt aes = new AESencrypt (key, numbi ts ) ;

byte[ ] out = new byte[16] ;

/ /Pr in t .pr in tArray("Key: " , key) ;

whi le(get Input . f lag!=1)

{

in = ge t Input .ge tBytes( ) ;

i f (ge t Input . f lag!=1)

{

System.out .pr in t ("") ;

i f ( f lag==1)

{

154

Page 155: AES Algorithm Implementation

A.E.S.

Pr in t .pr in tArray("Pla in text : " , in) ;

aes .Cipher( in , out ) ;

Pr in t .pr in tArray("Cipher text : " , out ) ;

}

e lse

{

Pr in t .pr in tArray("Cipher text : " , in) ;

aes . InvCipher( in ,out ) ;

Pr in t .pr in tArray("Pla inText : " , out ) ;

}

put f i le .put (out ) ;

}

}

end = System.currentTimeMil l i s ( ) ;

i f ( f lag!=1)

{

eng. toEng(out f i le ) ;

}

System.out .pr in t ln("Execut ion t ime i s :"+ (end-s tar t ) ) ;

}

155

Page 156: AES Algorithm Implementation

A.E.S.

}

Copy

**

Class has s ta t ic funct ions thay map 1-D arrays to a 2-D

arrays and vice versa

*/

publ ic c lass Copy

{

pr iva te s ta t ic f ina l in t Nb = 4;

publ ic s ta t ic void copy(byte[ ] [ ] s ta te , byte[ ] in)

{

in t inLoc = 0 ;

for ( in t c = 0 ; c < Nb; c++)

{

for ( in t r = 0 ; r < 4 ; r++)

{

s ta te[ r ] [c] = in[ inLoc++];

}

}

}

156

Page 157: AES Algorithm Implementation

A.E.S.

publ ic s ta t ic void copy(byte[ ] out , byte[ ] [ ] s ta te)

{

in t outLoc = 0 ;

for ( in t c = 0 ; c < Nb; c++)

{

for ( in t r = 0 ; r < 4 ; r++)

{

out[outLoc++] = s ta te[ r ] [c] ;

}

}

}

publ ic s ta t ic void copy(byte[ ] out , byte[ ] [ ] s ta te , in t

thread)

{

in t outLoc = thread*16;

outLoc=outLoc-16;

for ( in t c = 0 ; c < Nb; c++)

{

for ( in t r = 0 ; r < 4 ; r++)

{

out[outLoc++] = s ta te[ r ] [c] ;

157

Page 158: AES Algorithm Implementation

A.E.S.

}

}

}

}

Print

/**

Has s ta t ic funct ions to perform pr in t ing opera t ions on one

and two dimensional byte ar rays .* /

publ ic c lass Pr in t

{

pr iva te s ta t ic f ina l in t Nb = 4;

pr iva te s ta t ic St r ing[] d ig =

{"0" ,"1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" ,"8" ,"9" ,"a" ,"b" ,"c" ,"d" ,"e" ," f"

} ;

publ ic s ta t ic St r ing hex(byte a)

{

re turn d ig[(a & 0xff ) >> 4] + d ig[a & 0x0f] ;

}

/ />> used for le f t sh i f t , & used for b i twise AND

publ ic s ta t ic void pr in tArray(St r ing name, byte[ ] a )

158

Page 159: AES Algorithm Implementation

A.E.S.

{

System.out .pr in t (name + " " ) ;

for ( in t i = 0 ; i < a . length; i++)

System.out .pr in t (hex(a[ i ] ) + " " ) ;

Sys tem.out .pr in t ln( ) ;

}

publ ic s ta t ic void pr in tArray(St r ing name, byte[ ] a , in t

thread)

{

System.out .pr in t (name + " " ) ;

in t i= thread*16;

for ( i = i -16; i < thread*16; i++)

System.out .pr in t (hex(a[ i ] ) + " " ) ;

Sys tem.out .pr in t ln( ) ;

}

publ ic s ta t ic void pr in tArray(St r ing name, byte[ ] [ ] s )

{

System.out .pr in t (name + " " ) ;

for ( in t c = 0 ; c < Nb; c++)

{

for ( in t r = 0 ; r < 4 ; r++)

159

Page 160: AES Algorithm Implementation

A.E.S.

{

System.out .pr in t (hex(s[ r ] [c] ) + " " ) ;

}

}

System.out .pr in t ln( ) ;

}

}

TEST CASES

S Input Actual Output Expected Error

160

Page 161: AES Algorithm Implementation

A.E.S.

No. Output

1 1.Encrypt ion

2.Decrypt ion

1

1. 128

2. 192

3. 256

1. 128

2. 192

3. 256

No Error

2 1.Encrypt ion

2.Decrypt ion

2

1. 128

2. 192

3. 256

1. 128

2. 192

3. 256

No Error

3 1.Encrypt ion

2.Decrypt ion

3

Erroneous Input . . . t ry again . .

Erronous Input . . . t ry again . .

No Error

4 1.Encrypt ion

2.Decrypt ion

34534534545

Program Hal ts Erronous Input . . . t ry again . .

Error

5 1.Encrypt ion

2.Decrypt ion

1w

Program Hal ts Erronous Input . . . t ry again . .

Error

6 1.Encrypt ion

2.Decrypt ion

Program Hal ts Erronous Input . . . t ry again . .

Error

161

Page 162: AES Algorithm Implementation

A.E.S.

!

7 1 .Encrypt ion

2.Decrypt ion

Program Hal ts Erronous Input . . . t ry again . .

Error

8 1.Encrypt ion

2.Decrypt ion

1

1. 128

2. 192

3. 256

1

Executes encrypt ion for key s ize 128

Executes for key s ize 128

No Error

9 1.Encrypt ion

2.Decrypt ion

1

1. 128

2. 192

3. 256

Executes encrypt ion for key s ize 192

No Error

162

Page 163: AES Algorithm Implementation

A.E.S.

2

10 1.Encrypt ion

2.Decrypt ion

1

1. 128

2. 192

3. 256

3

Executes encrypt ion for key s ize 256

Executes for key s ize 256

No Error

11 1.Encrypt ion

2.Decrypt ion

2

1. 128

2. 192

3. 256

1

Executes decrypt ion for key s ize 128

Executes for key s ize 128

No Error

12 1.Encrypt ion

2.Decrypt ion

Executes decrypt ion for key s ize 192

Executes decrypt ion for key

No Error

163

Page 164: AES Algorithm Implementation

A.E.S.

2

1 . 128

2. 192

3. 256

2

size 192

13 1.Encrypt ion

2.Decrypt ion

2

1. 128

2. 192

3. 256

3

Executes decrypt ion for key s ize 256

Executes decrypt ion for key s ize 256

No Error

14 1.Encrypt ion

2.Decrypt ion

2

Erroneous Input . . . t ry again . .

Erroneous Input . . . t ry again . .

Error

164

Page 165: AES Algorithm Implementation

A.E.S.

1 . 128

2. 192

3. 256

5

15 1.Encrypt ion

2.Decrypt ion

2

1. 128

2. 192

3. 256

aes

Program Hal ts Erroneous Input . . . t ry again . .

Error

16 Key = 2b7e151628aed2a6abf7158809cf4f3c

Pla in Text =”” (Blank)

Cipher Text=”” (Blank)

Decrypted Text=””(Blank)

Decrypted Text=””(Blank)

No Error

17 Key= 000102030405060708090a0b0c0d0e0f101112131415

Cipher Text = 762541b9ee516fd644a13c2d22ea620ad4ef6250835a82dce704311f55b774dc

Decrypted Text =“hel lo . . !! how are you doing

No Error

165

Page 166: AES Algorithm Implementation

A.E.S.

1617

Pla in Text = “hel lo . . ! ! how are you doing ?”

Decrypted Text =“hel lo . . ! ! how are you doing ?”

?”

18 Key= 000102030405060708090a0b0c0d0e0f1011121314151617

Pla in Text=” The Advanced Encrypt ion Standard (AES) speci f ies a FIPS-approved

cryptographic a lgor i thm tha t can be used to protec t e lec t ronic da ta . The AES a lgor i thm is a

Cipher Text= 9ea176aa7bc8e1044405ef9d9c29710aea41b3fda528ee3afe54079b52196c8afc418f5f39aae45b2fd962e461adde69e8d6c3813c1cf22602e0f71b64fef76b1e1c99698165b0475c0f8f8c7b45405ef9c3ec8dd7e74572f02404327a542567f9fe5b045a723a2a186c4b91d7c168a19bdd19947781bd673df6cd6c143e72fc1e26d4ba7d6fd3c67d164da8fc67226803013109b9d7676470daff7b071e01e30aa8aa4a6ef42c67b5a612de431f0f91e423ffe9473eb5af7a162275377078beb74b723d33547a6e2da81de73a560f628765400fc943db914833c6f489fe4aba02eb95b83dfa931289694ea986bbe993b063eaa4db

Pla in Text = The Advanced Encrypt ion Standard (AES) speci f ies a FIPS-approved cryptographic a lgor i thm tha t can be used to protec t e lec t ronic da ta . The AES a lgor i thm is a symmetr ic b lock c ipher tha t can encrypt (encipher) and

Error

166

Page 167: AES Algorithm Implementation

A.E.S.

symmetr ic b lock c ipher tha t can encrypt (encipher) and decrypt (dec ipher) informat ion.

Encrypt ion conver ts da ta to an uninte l l ig ib le form ca l led c ipher text ; decrypt ing the c ipher text

conver ts the da ta back in to i t s or ig ina l form, ca l led p la in text .

The AES a lgor i thm is capable of us ing cryptographic keys of 128, 192, and 256 bi t s to encrypt

and decrypt da ta in b locks of 128 bi t s .

c550330e56b9caba64c8390576bb83691488455063aff f0baaa942168b0094ae0dd145aa55004f8c7aee162da893c55e5c322b2e29057f3a571c7471bc23906d3c20b464cf019bf870252d0df314285132c5841604edcfaec67002b18d4af6ec5de81f630b5f53a89ddbaae43e52cec12436bc215bd91df05a1409010b8a9afef3636e77f1b8adcceb6022dffd9008e1d2d7c868e32619eb34e7fd6061ef784f587dbeacc79bf6c77fc4726db6a9741197f3305321fde66e8c55667bcbf3afedff586330adff91e663e70ca9a7505d219d7cc9358860724f364988301b663c72c72560113c69c9c5fd968dbaec4b324b8a27aee0714396bdb2b41f238f4e381c3942901260d96a9bbedfecce606a482cc31669afb6215f783e8b3c302943807ab182f3fcef0625e0b47621

Decrypted Text = The Advanced

decrypt (dec ipher) informat ion.

Encrypt ion conver ts da ta to an uninte l l ig ib le form ca l led c ipher text; decrypt ing the c ipher text conver ts the da ta back in to s or ig ina l form, ca l led p la in text .

The AES a lgor i thm is capable of us ing cryptographic keys of 128, 192, and 256 bi t s to encrypt and

167

Page 168: AES Algorithm Implementation

A.E.S.

“ Encrypt ion Standard (AES) speci f ies a FIPS-approved cryptographic a lgor i thm tha t can be used to protec t e lec t ronic da ta . The AES a lgor i thm is a symmetr ic b lock c ipher tha t can encrypt (encipher) and decrypt (dec ipher) informat ion.Encrypt ion conver ts da ta to an uninte l l ig ib le form ca l led c ipher text ; decrypt ing the c ipher text conver ts the da ta back in to s or ig ina l form, ca l led p la in text . ÚÚThe AES a lgor i thm is capable of us ing cryptographic keys of 128, 192, and 256 bi t s to encrypt and decrypt da ta in b locks of 128 bi t s . “

decrypt da ta in b locks of 128 bi t s .

19 Key =

000102030405060708090a0b0c0d0e0f1011121314151617

Cipher Text=”” (Blank)

Decrypted Text=””(Blank)

Decrypted Text=””(Blank)

No Error

168

Page 169: AES Algorithm Implementation

A.E.S.

P la in Text =”” (Blank)

20 Key =

*&%&^$%&^$^%#%^$*^!^*&!^&!)&*)!@(&)*(!*^@*&^@*^(

Pla in Text=”Hi i i…”

Cipher Text= 9a623aa765593d69072f79f0bcaf3be1

Decrypted Text =”Hi i i…”

Except ion= “Wrong form of key”

Error

21 Key =

000102030405060708090a0b0c0d0e0f1011121314151617

Pla in Text=

”!! ! ! ! ! ! !”

Cipher Text= 9a623aa765593d69072f79f0bcaf3be1

Decrypted Text=”!! ! ! ! ! ! ! “

Decrypted Text=”!! ! !! ! ! !“

22 Key =

000102030405060708090a0b0c0d0e0f1011121314151617

Cipher Text = d79739e18fdc343b513c16ca050bad18

Decrypted Text= “ †††††††”ⁱ

Pla in Text=”q”

Error

169

Page 170: AES Algorithm Implementation

A.E.S.

P la in Text=”q”

23 Key =

000102030405060708090a0b0c0d0e0f1011121314151617

Pla in Text=” a y”

Cipher Text = e279ce454abb84cb9e1cb054331df6972df992e7571025cc741f61c80980c9272df992e7571025cc741f61c80980c9278678f53fec764b24810fc2d0fcb653eb

Decrypted Text= “a y “

Pla in Text=” a y”

No Error

24 Key =

000102030405060708090a0b0c0d0e0f1011121314151617

Pla in Text=”1”

Cipher Text = cdd9d044d0a7341f6aacef06eb4e1ea3

Decrypted Text=”1”

Pla in Text =”1”

No Error

25 Key =

000102030405060708090a0b0c0d0e0f1011121314151617

Cipher Text=

da9832b746f905c2c50e6a96760a4cf2

Decrypted Text=”1234567890”

Pla in Text=”1234567890”

No Error

170

Page 171: AES Algorithm Implementation

A.E.S.

P la in Text=”1234567890”

26 Key =

000102030405060708090a0b0c0d0e0f1011121314151617

Pla in Text=”&^%&^%&^%&%”

Cipher Text=

f407e2bba66af09bf7d36210a494627b

Decrypted Text=”&^%&^%&^%&% “

Pla in Text=”&^%&^%&^%&%”

No Error

27 Key =

000102030405060708090a0b0c0d0e0f1011121314151617

Pla in Text=”~”

Cipher Text= ae939299c947806fe2134b5aac6b00b8

Decrypted Text= “~ “

Pla in Text=”~”

No Error

28 Key =

000102030405060708090a0b0c0d0e0f1

Cipher Text= 2df992e7571025cc741f61c80980c927

Pla in Text=” “

No Error

171

Page 172: AES Algorithm Implementation

A.E.S.

011121314151617

Pla in Text=” “

Decrypted Text= “ “

29 Key=

00000000000000000000000000000000

Cipher Text=”3AD78E726C1EC02B7EBFE92B23D9EC34

Pla in text=”80000000000000000000000000000000” ( in hex)

=”? “ ( in eng)

Pla in text=”80000000000000000000000000000000” ( in hex)

No Error

30 Key=

00000000000000000000000000000000

Cipher Text= 45BC707D29E8204D88DFBA2F0B0CAD9B

Plain Text = “40000000000000000000000000000000” ( in hex)

= “@” ( in eng)

Pla in Text = “40000000000000000000000000000000”

No Error

31 Key=

00000000000000000000000000000000

Pla in Text = “20000000000000000000000000000000” ( in hex)

Pla in Text = “20000000000000000000000

No Error

172

Page 173: AES Algorithm Implementation

A.E.S.

Cipher Text =161556838018F52805CDBD6202002E3F

=” “ ( in eng)

000000000” ( in hex)

32 Key=

00000000000000000000000000000000

Cipher Text= F5569B3AB6A6D11EFDE1BF0A64C6854A

Plain Text=”10000000000000000000000000000000” ( in Hex)

=““( in eng)

Pla in Text=”10000000000000000000000000000000” ( in Hex)

No Error

33 Key=

00000000000000000000000000000000

Cipher text= 64E82B50E501FBD7DD4116921159B83E

Pla in Text=”08000000000000000000000000000000” ( in Hex)

=”“( in eng)

Pla in Text=”08000000000000000000000000000000” ( in Hex)

No Error

34 Key=

00000000000000000000000000000000

Pla in Text=” 04000000000000000000000000000000” ( in Hex)

=“ “

Pla in Text=” 04000000000000000000000000000000

No Error

173

Page 174: AES Algorithm Implementation

A.E.S.

Cipher text=

BAAC12FB613A7DE11450375C74034041

” ( in Hex)

35 Key=

00000000000000000000000000000000

Cipher text=

BCF176A7EAAD8085EBACEA362462A281

Pla in Text=” 02000000000000000000000000000000” ( in Hex)

““ ( in eng)

Pla in Text=” 02000000000000000000000000000000” ( in Hex)

No Error

36 Key=

00000000000000000000000000000000

Cipher Text= 47711816E91D6FF059BBBF2BF58E0FD3

Pla in Text=”01000000000000000000000000000000” ( in Hex)

=” “ ( in eng)

Pla in Text=”01000000000000000000000000000000” ( in Hex)

No Error

37 Key=

00000000000000000000000000000000

Pla in Text= ”00800000000000000000000000000000” ( in Hex)

Pla in Text= ”00800000000000000000000

No Error

174

Page 175: AES Algorithm Implementation

A.E.S.

Cipher Text= ”B970DFBE40698AF1638FE38BD3DF3B2F”

= “ ? “ ( in eng)

000000000” ( in Hex)

38 Key=

00000000000000000000000000000000

Cipher Text= ”F95B59A44F391E14CF20B74BDC32FCFF”

Pla in Text= “ 00400000000000000000000000000000” ( in Hex)

= “ @ “ ( in eng)

Pla in Text= “ 00400000000000000000000000000000” ( in Hex)

No Error

39 Key=

00000000000000000000000000000000

Cipher Text= ” 720F74AE04A2A435B9A7256E49378F5B”

Pla in Text= “ 00200000000000000000000000000000” ( in Hex)

= “ “ ( in eng)

Pla in Text= “ 00200000000000000000000000000000” ( in Hex)

No Error

40 Key=

00000000000000000000000000000000

Pla in Text= “ 00100000000000000000000000000000” ( in Hex)

Pla in Text= “ 001000000000000000000000

No Error

175

Page 176: AES Algorithm Implementation

A.E.S.

Cipher Text= ” 2A0445F61D36BFA7E277070730CF76DA ”

= “ “ ( in eng) 00000000” ( in Hex)

41 Key=

00000000000000000000000000000000

Cipher Text= ” 8D0536B997AEFEC1D94011BAB6699A03 ”

Pla in Text= “ 00080000000000000000000000000000” ( in Hex)

= “ “ ( in eng)

Pla in Text= “ 00080000000000000000000000000000” ( in Hex)

No Error

42 Key=

00000000000000000000000000000000

Cipher Text= ”674F002E19F6ED47EFF319E51FAD4498”

Pla in Text= “ 00040000000000000000000000000000” ( in Hex)

= “ “ ( in eng)

Pla in Text= “ 00040000000000000000000000000000” ( in Hex)

No Error

43 Key=

0000000000000000000000

Pla in Text= “ 00020000000000000000000000000000”

Pla in Text= “ 0002000000000000

No Error

176

Page 177: AES Algorithm Implementation

A.E.S.

0000000000

Cipher Text= ”292C02C5CB9163C80AC0F6CF1DD8E92D”

(in Hex)

= “ “ ( in eng)

0000000000000000” ( in Hex)

44 Key=

00000000000000000000000000000000

Cipher Text= ” FA321CF18EF5FE727DD82A5C1E945141 ”

Pla in Text= “ 00010000000000000000000000000000” ( in Hex)

= “ “ ( in eng)

Pla in Text= “ 00010000000000000000000000000000” ( in Hex)

No Error

45 Key=

00000000000000000000000000000000

Cipher Text= ” A5A7AFE1034C39CCCEBE3C584BC0BE05 ”

Pla in Text= “ 00008000000000000000000000000000 ” ( in Hex)

= “ ? “ ( in eng)

Pla in Text= “ 00008000000000000000000000000000 ” ( in Hex)

No Error

46 Key=

00000000000

Pla in Text= “ 00004000000000000

Pla in Text= “

No Error

177

Page 178: AES Algorithm Implementation

A.E.S.

000000000000000000000

Cipher Text= ” 4FF5A52E697E77D081205DBDB21CEA39 ”

000000000000000” ( in Hex)

= “ @ “ ( in eng)

00004000000000000000000000000000 ” ( in Hex)

47 Key=

00000000000000000000000000000000

Cipher Text= ” 209E88DC94C9003000CE0769AF7B7166 ”

Pla in Text= “ 00002000000000000000000000000000 ” ( in Hex)

= “ “ ( in eng)

Pla in Text= “ 00002000000000000000000000000000 ” ( in Hex)

No Error

48 Key=

00000000000000000000000000000000

Cipher Text= ” 5DEE41AF864CB4B650E5F51551824D38 ”

Pla in Text= “ 00001000000000000000000000000000 ” ( in Hex)

= “ “ ( in eng)

Pla in Text= “ 00001000000000000000000000000000 ” ( in Hex)

No Error

178

Page 179: AES Algorithm Implementation

A.E.S.

49 Key=

00000000000000000000000000000000

Cipher Text= ” A79A63FA7E4503AE6D6E09F5F9053030 ”

Pla in Text= “ 00000800000000000000000000000000 ” ( in Hex)

= “ “ ( in eng)

Pla in Text= “ 00000800000000000000000000000000 ” ( in Hex)

No Error

50 Key=

00000000000000000000000000000000

Cipher Text= ” A48316749FAE7FAC7002031A6AFD8BA7 ”

Pla in Text= “ 00000400000000000000000000000000 ” ( in Hex)

= “ “ ( in eng)

Pla in Text= “ 00000400000000000000000000000000 ” ( in Hex)

No Error

51 Key=

00000000000000000000000000000000

Cipher Text= ” D6EEE8A7357A0E1D6426

Pla in Text= “ 00000200000000000000000000000000” ( in Hex)

= “ “ ( in eng)

Pla in Text= “ 00000200000000000000000000000000 ” ( in Hex)

No Error

179

Page 180: AES Algorithm Implementation

A.E.S.

2CA9C337AC42”

52 Key=

00000000000000000000000000000000

Cipher Text= ” B013CA8A62A858053E9FB667ED39829E ”

Pla in Text= “ 00000100000000000000000000000000” ( in Hex)

= “ “ ( in eng)

Pla in Text= “ 00000100000000000000000000000000 ” ( in Hex)

No Error

53 Key=

00000000000000000000000000000000

Cipher Text= ” DF6EA9E4538A45A52D5C1A43C88F4B55”

Pla in Text= “ 00000080000000000000000000000000 ” ( in Hex)

= “ ? “ ( in eng)

Pla in Text= “ 00000080000000000000000000000000” ( in Hex)

No Error

54 Key=

00000000000000000000000000000000

Cipher Text= ”

P la in Text= “ 00000040000000000000000000000000 ” ( in Hex)

= “ @ ” ( in eng)

Pla in Text= “ 00000040000000000000000000000000 ” ( in Hex)

No Error

180

Page 181: AES Algorithm Implementation

A.E.S.

7D03BA451371591D3FD5547D9165C73B ”

55 Key=

00000000000000000000000000000000

Cipher Text= ” 0E0426281A6277E186499D365D5F49FF ”

Pla in Text= “ 00000020000000000000000000000000 ” ( in Hex)

= “ ” ( in eng)

Pla in Text= “ 00000020000000000000000000000000 ” ( in Hex)

No Error

56 Key=

00000000000000000000000000000000

Cipher Text= ” DBC02169DD2059E6CC4C57C1FEDF5AB4 “

Pla in Text= “ 00000010000000000000000000000000 ” ( in Hex)

=” “ ( in eng)

Pla in Text= “ 00000010000000000000000000000000 ” ( in Hex)

No Error

REFRENCES

181

Page 182: AES Algorithm Implementation

A.E.S.

1. A. Lee , NIST Specia l Publ ica t ion 800-21, November

1999 Guidel ine for Implement ing Cryptography in the

Federa l Government , Nat ional Ins t i tu te of Standards and

Technology

2. Cameron Pat terson, Apr 2000.High performance

DESencrypt ion in Vir tex FPGAs us ing JBi ts . In Kenneth

L. Pocek and Jef f rey M. Arnold , edi tors , IEEE

Symposium on Fie ld-Programmable Custom Comput ing

Machines (FCCM 2000) pages 113–121 .

3 . Cameron Pat terson ,Aug 2000 . A dynamic FPGA

implementa t ion of the Serpent b lock c ipher . In

C¸e t inKoc and Chr is tof Paar , edi tors ,Second

In ternat ional Workshop on Cryptographic Hardware and

Embedded Systems (CHES 2000) pages 141–155.

Spr inger-Ver lag Lecture Notes in Computer Science ,

Volume 1965

4. Federa l Regis ter62, Sep 1997.Nat ional Ins t i tu te of

Standards and Technology. Announcing reques t for

candidate a lgor i thm nominat ions for the Advanced

Encrypt ion Standard (AES) . (117) :48051–48058

5. James Nechvata l , Ela ine Barker , Lawrence Bassham,

Wil l iam Burr , Morr is Dworkin , James Fot i , and

Edward Roback Oct2 , 2000. Repor t on the development

182

Page 183: AES Algorithm Implementation

A.E.S.

of the Advanced Encrypt ion Standard1. (AES) . Avai lable

a t h t tp : / /www.nis t .gov/aes / round2/r2repor t .pdf

6 . J . Daemen and V. Ri jmen September 3 , 1999, AES

Proposal : Ri jndael , AES Algor i thm Submiss ion, ,

ava i lable a t [1] .

Books-

1)Cryptography and Network Secur i ty-Wil l iam S ta l l ing

2)Cryptography and Secur i ty-Frozun

WEBSITES

1. h t tp : / /www.cs .u tsa .edu/~wagner / laws/AESEncrypt .h tml

2 . h t tp : / /csrc .n is t .gov/archive/aes / index.html

3 . h t tp : / /www.hoozi .com/Art ic les /AES_Encrypt ion.h tm

4 . h t tp : / /www.hoozi .com/Art ic les /AES_Decrypt ion.h tm

5 . h t tp : / /www.snia .org/home

BIODATA

183

Page 184: AES Algorithm Implementation

A.E.S.

184