4
A randomized cryptographic algorithm and its simulation in C and MATLAB with its hardware implementation in Verilog HDL Soumyabrata Dev, (IEEE, Student Member); Ziaul Haque Choudhury National Institute of Technology, Silchar [email protected] ; [email protected] Abstract-Fascinating commerce activities, transactions and services are possible if communications over open networks can be conducted in a secure manner. An effective solution to securing communications over open networks is to apply cryptography. Encryptions, digital signatures, password-based user authentication, are some of the most basic cryptographic techniques for securing communications. But, however, for many “fancier” applications, the basic cryptographic techniques are no longer adequate. Hence, the need of the hour is an efficient but simple, encryption and decryption algorithm for encrypting any kind of data. Also, the keys required for encryption and decryption must be randomized and randomly generated from the changing data bits. Our newly proposed algorithm humbly tries to satisfy the above two criteria to some extent. I. INTRODUCTION With a symmetric cryptosystem it is necessary to transfer a secret key to both communication parties before secure communication can begin. The establishment of a shared secret key between communication parties had always been a difficult problem because the task needed a secure confidential channel, and often such a channel meant physical delivery of keys by a special courier. An important edge of this new algorithm is that the keys are generated automatically once the data bits come to the user for encryption. And every time the keys are generated it is random and has no correspondence with the previously generated keys. The complete algorithm for its encryption and decryption are provided in the following discussion. Its simulation has been successfully implemented in C and MATLAB. C, being a popular programming language has been chosen for simulation so that its code can be understood easily by even a novice in the science of cryptography. MATLAB is an excellent platform for hardware interface and so its .m file is introduced here for further modifications and suggestions from the users. Its complete hardware implementation can be performed in Verilog HDL which is provided in the later section. II. PROPOSED CRYPTOGRAPHIC ALGORITHM A. Our new proposed algorithm has a two-level cryptographic algorithm which consists of: a) Parity checking level b) Dibit checking level B. The new cryptographic algorithm can be understood easily by the following case study. Let the 8-bit data be 10 11 01 10. Encryption algorithm Step I) The 8 bits are indexed at the very outset for easy reference (Table 1). Step II) the level 1 of encryption (parity checking level) starts here. The fundamental aspect of this level is that the key for encryption is stored in the data bits pattern itself and this key varies according to the varying data bits. The encryption is done in bit- by-bit operation. For encrypting data bits having index number 1 3 5 7, its corresponding key is data bits having index number 2 4 6 8. The two nibbles are then checked bit-by-bit so that the final result has even parity with data bits 1 3 5 7. This final result is the pseudo-encrypted bit pattern 1` 3` 5` 7` (Table 2). The pseudo-encrypted bit pattern 1` 3` 5` 7` becomes the key for the bit pattern 2 4 6 8. In he same manner, even parity is checked with the key and we get the pseudo- encrypted bit pattern 2` 4` 6` 8` (Table 3). Let us illustrate this with our example. The same parity checking is done for the data bits having index number 2 4 6 8. The key in this case is the pseudo- encrypted bit pattern 1` 3` 5` 7`. Thus the complete pseudo-encrypted bit pattern having index number 1` 2` 3` ….8` becomes: 11 01 10 00. Step III) the level 2 (di-bit checking level) starts here. In the same way as level 1, the 8-bits are indexed as 1` 2` 3`…8` for easy reference (Table 4). Step IV) The bits having index numbers 1` and 8` are extracted from the 1 byte data. The dibit pair 1` 8` (consisting of the bits having index number 1` and 8`) becomes the reference dibit for the other three dibit pairs (viz. 2`-3`, 4`-5` and 6`-7`). Now a virtual table is prepared with four columns. The fields in the columns are NC (not- complement), LSB-C (least significant bit-complement), MSB-C (most significant bit-complement), FC (full- complement). In order to represent the four fields, we need at least 4 bits. Let the four fields, NC, LSB-C, MSB-C and FC be

[IEEE 2009 3rd International Conference on Anti-counterfeiting, Security, and Identification in Communication (2009 ASID) - Hong Kong, China (2009.08.20-2009.08.22)] 2009 3rd International

Embed Size (px)

Citation preview

Page 1: [IEEE 2009 3rd International Conference on Anti-counterfeiting, Security, and Identification in Communication (2009 ASID) - Hong Kong, China (2009.08.20-2009.08.22)] 2009 3rd International

A randomized cryptographic algorithm and its simulation in C and MATLAB with its hardware

implementation in Verilog HDL Soumyabrata Dev, (IEEE, Student Member); Ziaul Haque Choudhury

National Institute of Technology, Silchar [email protected]; [email protected]

Abstract-Fascinating commerce activities, transactions and services are possible if communications over open networks can be conducted in a secure manner. An effective solution to securing communications over open networks is to apply cryptography. Encryptions, digital signatures, password-based user authentication, are some of the most basic cryptographic techniques for securing communications. But, however, for many “fancier” applications, the basic cryptographic techniques are no longer adequate. Hence, the need of the hour is an efficient but simple, encryption and decryption algorithm for encrypting any kind of data. Also, the keys required for encryption and decryption must be randomized and randomly generated from the changing data bits. Our newly proposed algorithm humbly tries to satisfy the above two criteria to some extent.

I. INTRODUCTION With a symmetric cryptosystem it is necessary to transfer a secret key to both communication parties before secure communication can begin. The establishment of a shared secret key between communication parties had always been a difficult problem because the task needed a secure confidential channel, and often such a channel meant physical delivery of keys by a special courier. An important edge of this new algorithm is that the keys are generated automatically once the data bits come to the user for encryption. And every time the keys are generated it is random and has no correspondence with the previously generated keys. The complete algorithm for its encryption and decryption are provided in the following discussion. Its simulation has been successfully implemented in C and MATLAB. C, being a popular programming language has been chosen for simulation so that its code can be understood easily by even a novice in the science of cryptography. MATLAB is an excellent platform for hardware interface and so its .m file is introduced here for further modifications and suggestions from the users. Its complete hardware implementation can be performed in Verilog HDL which is provided in the later section.

II. PROPOSED CRYPTOGRAPHIC ALGORITHM A. Our new proposed algorithm has a two-level

cryptographic algorithm which consists of:

a) Parity checking level

b) Dibit checking level

B. The new cryptographic algorithm can be understood easily by the following case study. Let the 8-bit data be 10 11 01 10.

Encryption algorithm

Step I) The 8 bits are indexed at the very outset for easy reference (Table 1).

Step II) the level 1 of encryption (parity checking level) starts here. The fundamental aspect of this level is that the key for encryption is stored in the data bits pattern itself and this key varies according to the varying data bits. The encryption is done in bit- by-bit operation. For encrypting data bits having index number 1 3 5 7, its corresponding key is data bits having index number 2 4 6 8. The two nibbles are then checked bit-by-bit so that the final result has even parity with data bits 1 3 5 7. This final result is the pseudo-encrypted bit pattern 1` 3` 5` 7` (Table 2).

The pseudo-encrypted bit pattern 1` 3` 5` 7` becomes the key for the bit pattern 2 4 6 8. In he same manner, even parity is checked with the key and we get the pseudo-encrypted bit pattern 2` 4` 6` 8` (Table 3). Let us illustrate this with our example.

The same parity checking is done for the data bits having index number 2 4 6 8. The key in this case is the pseudo-encrypted bit pattern 1` 3` 5` 7`.

Thus the complete pseudo-encrypted bit pattern having index number 1` 2` 3` ….8` becomes: 11 01 10 00.

Step III) the level 2 (di-bit checking level) starts here. In the same way as level 1, the 8-bits are indexed as 1` 2` 3`…8` for easy reference (Table 4).

Step IV) The bits having index numbers 1` and 8` are extracted from the 1 byte data. The dibit pair 1` 8` (consisting of the bits having index number 1` and 8`) becomes the reference dibit for the other three dibit pairs (viz. 2`-3`, 4`-5` and 6`-7`). Now a virtual table is prepared with four columns. The fields in the columns are NC (not-complement), LSB-C (least significant bit-complement), MSB-C (most significant bit-complement), FC (full-complement). In order to represent the four fields, we need at least 4 bits. Let the four fields, NC, LSB-C, MSB-C and FC be

Page 2: [IEEE 2009 3rd International Conference on Anti-counterfeiting, Security, and Identification in Communication (2009 ASID) - Hong Kong, China (2009.08.20-2009.08.22)] 2009 3rd International

represented respectively as 00, 01, 10 and 11. Our objective in this step is to obtain the dibit pairs

INDEX 1 2 3 4 5 6 7 8 BITS 1 0 1 1 0 1 1 0

Fig 1: Indexing of bits

1 1 0 1 // data bits 1 3 5 7 0 1 1 0 // data bits 2 4 6 8 (key) 1 0 1 1 // pseudo-encrypted bits 1` 3` 5` 7`

Fig 2: Encryption of bits 1 3 5 7

0 1 1 0 // data bits 2 4 6 8 1 0 1 1 // data bits 1` 3` 5` 7` 1 1 0 1 // pseudo-encrypted bits 2` 4` 6` 8`

Fig 3: Encryption of bits 2 4 6 8

INDEX 1` 2` 3` 4` 5` 6` 7` 8` BITS 1 1 0 1 1 0 1 1

Fig 4: Indexing of bits

REFERENCE DIBIT 11

DIBIT PAIR

00 NC

01 LSB-C

10 MSB-C

11 FC

2`-3` ▲ 4`-5` ▲ 6`-7` ▲

Fig 5: Formation of virtual table

2`-3`, 4`-5` and 6`-7` from the reference bit 1`-8` by any one of the four methods NC, LSB-C, MSB-C or FC.; NC means the dibit pair is same as the reference dibit; LSB-C means the dibit pair is obtained from the reference dibit pair by complementing the least significant bit, MSB-C means the dibit pair is obtained from the reference dibit pair by complementing the most significant bit and FC means the dibit pair is obtained from the reference dibit pair by complementing both the bits. The logic of the encryption then follows the following rule: Dibits 2`-3`, 4`-5` and 6`-7` are coded with their individual field codes and the bit 1` and 8` are appended both at the beginning and at the end respectively. Let us illustrate this with our current example. The dibit pair 1`-8` (viz 11) is extracted. This becomes the reference dibit for the other three dibit pairs 2`-3` (viz. 10), 4`-5` (viz. 11) and 6`-7` (viz. 01). Now the logic goes like this: 10 (Dibit pair 2`-3`) is obtained from 11 (reference bit) by the method LSB-C ;11 (Dibit pair 4`-5`) is obtained from 11 (reference bit) by the method NC; 01 (Dibit pair 6`-7`) is obtained from 11 (reference bit) by the method MSB-C The virtual table looks like (Table 5): NC corresponds to the code 00 LSB-C corresponds to the code 01 MSB-C corresponds to the code 10 FC corresponds to the code 11. Thus, the dibit encryption follows as: Dibit pair 2`-3` is coded as 01 Dibit pair 4`-5` is coded as 00 Dibit pair 6`-7` is coded as 10. And the bits 1` and 8` are appended at the beginning and at the end respectively. Thus the final encrypted code word becomes: 1 01 00 10 1.

C. Decryption algorithm Step I) The 8 bits of encrypted data are indexed again at the very outset for easy reference (Table 6). Step II) The bits having index numbers 1 and 8 are extracted from the 1 byte data. The dibit pair 1-8 (consisting of the bits having index number 1 and 8) becomes the reference dibit for the other three dibit pairs (viz. 2-3, 4-5 and 6-7). The virtual table having the fields NC, MSB-C, LSB-C and FC is prepared again and the codes are entered accordingly in the appropriate places. The table looks like (Table 7) For dibit 2-3 ▲ is placed in LSB-C field indicating the pseudo-decrypted dibit 2`-3` is obtained by complementing the least significant bit of the reference dibit. For dibit 4-5, ▲ is placed in NC field indicating the pseudo-decrypted dibit 4`-5` is the same as the reference dibit. And for dibit 6-7, ▲ is placed in MSB-C field indicating the pseudo-decrypted dibit 6`-7` is obtained by complementing both the MSB of the reference dibit. Thus, we get: 1 10 11 01 1, the pseudo-decrypted bit pattern Step III) The pseudo-decrypted bit pattern goes for the next stage of decryption logic. For decrypting data bits having index number 2` 4` 6` 8`, its corresponding key is data bits having index number 1` 3` 5` 7`. The two nibbles are then checked bit-by-bit so that the final result has even parity with data bits 1` 3` 5` 7`. This final result is the decrypted bit pattern 1 3 5 7. The decrypted bit pattern 1 3 5 7 becomes the key for the bit pattern 2` 4` 6` 8`. In the same manner, even parity is checked with the key and we get the decrypted bit pattern 2 4 6 8 (Table 8). The same parity checking is done for the data bits having index number 1` 3` 5` 7`. The key in this case is the decrypted bit pattern 2 4 6 8 (Table 9). Thus the complete decrypted bit pattern having index number 1 2 3 ….8 becomes: 10 11 01 10. This is exactly the same as the original plaintext 10 11 01 10. INDEX 1 2 3 4 5 6 7 8 BITS 1 0 1 0 0 1 0 1

Fig 6: Indexing of bits

REFERENCE DIBIT 11

00 NC

01 LSB-C

10 MSB-C

11 FC

▲ ▲ ▲

Fig 7: Formation of virtual table 1 1 0 1 // data bits 2` 4` 6` 8` 1 0 1 1 // data bits 1` 3` 5` 7` (key) 0 1 1 0 // decrypted bits 2 4 6 8

Fig 8: Decryption of bits 2 4 6 8 1 0 1 1 // data bits 1` 3` 5` 7` 0 1 1 0 // decrypted data bits 2 4 6 8 (key) 1 1 0 1 // decrypted bits 1 3 5 7

Fig 9: Decryption of bits 1 3 5 7

Page 3: [IEEE 2009 3rd International Conference on Anti-counterfeiting, Security, and Identification in Communication (2009 ASID) - Hong Kong, China (2009.08.20-2009.08.22)] 2009 3rd International

III. SIMULATION OF THE PROPOSED CRYPTOGRAPHIC ALGORITHM

a. Simulation in C: Encryption Code void encrypt(int *bit_string) { for(i=0;i<2;i++) { j=i+1; l=2-i; for(int k=0;k<4;k++) { bit_string[j]=xor(bit_string[j],bit_string[l]); printf("\nbit[%d]=%d xor bit[%d] =%d equals %d \n",j,bit_string[j],l,bit_string[l],bit_string[j]); j+=2; l+=2; } printf("\n\n\n"); } printf("\n\nthe semi encrypted data is \n\n"); for(i=1;i<9;i++) printf("%d",bit_string[i]); make_table(bit_string); printf("\n\nthe code table is \n\n"); for(int x=0;x<3;x++) { for(int y=0;y<4;y++) printf("%d",code_table[x][y]); printf("\n"); } generate_code(bit_string); printf("the final encrypted data is \n\n\n"); for(i=1;i<9;i++) printf("%d",bit_string[i]); return; } Decryption Code void decrypt(int *bit_string) { bit1=bit_string[1]; bit2=bit_string[8]; rf_number=make_num(bit1,bit2); j=2; for(i=0;i<3;i++) { bit1=bit_string[j]; bit2=bit_string[j+1]; new_number=make_num(bit1,bit2); xor_number=xor(rf_number,new_number); bits=generate_bits(xor_number);

bit_string[j]=bits[0]; bit_string[j+1]=bits[1]; j+=2; } for(i=0;i<2;i++) { j=2-i; l=i+1; for(int k=0;k<4;k++) { bit_string[j]=xor(bit_string[j],bit_string[l]); printf("\nbit[%d]=%d xor bit[%d] =%d equals %d \n",j,bit_string[j],l,bit_string[l],bit_string[j]); j+=2; l+=2; } printf("\n\n\n"); } printf("\n\nthe recovered string is \n\n\n"); for(i=1;i<9;i++) printf("%d",bit_string[i]); } Main () function main() { for(i=0;i<strlen(buffer);i++) { printf("%c",buffer[i]); if(buffer[i]=='0') bit_string[i+1]=0; else bit_string[i+1]=1; } encrypt(bit_string); printf("\n\n THE DECRYPRION STEPS\n\n\n"); decrypt(bit_string); }

b. Simulation in MATLAB: %preparing pseudo data byte a=input('enter the data byte ','s'); b=bin2dec(a); bit_array=bitget(b,8:-1:1); for i=1:2:7 ps_enc(i)=xor((bit_array(i)),(bit_array(i+1))); end for i=2:2:8 ps_enc(i)=xor((bit_array(i)),ps_enc(i-1)); end display('The pseudo encrypted data byte is '); display(ps_enc); %preparing the reference bit ref_bit(1)=ps_enc(1);

Page 4: [IEEE 2009 3rd International Conference on Anti-counterfeiting, Security, and Identification in Communication (2009 ASID) - Hong Kong, China (2009.08.20-2009.08.22)] 2009 3rd International

ref_bit(2)=ps_enc(8); display ('The reference bit is ');ref_bit %the final encryption algorithm for j=2:2:6 final_enc(j)=xor((ref_bit(1)),(ps_enc(j))); final_enc(j+1)=xor((ref_bit(2)),(ps_enc(j+1))); end final_enc(1)=ref_bit(1); final_enc(8)=ref_bit(2); display ('The final encrypted data byte is ');final_enc %preparing the decryption algorithm for k=2:2:6 ps_dec(k)=xor((ref_bit(1)), (final_enc(k))); ps_dec(k+1)=xor((ref_bit(2)), (final_enc(k+1))); end ps_dec(1)=ref_bit(1); ps_dec(8)=ref_bit(2); display('The pseudo decrypted data byte is ');ps_dec for m=2:2:8 final_dec(m)=xor((ps_dec(m)),(ps_dec(m-1))); end for m=1:2:7 final_dec(m)=xor((ps_dec(m)),(final_dec(m+1))); end display('The final decrypted data byte is ');final_dec

c. Hardware implementation in Verilog HDL Verilog HDL is a hardware description language that can be used to model a digital system at many levels of abstraction ranging from the algorithmic-level to the gate-level to the switch level. Here is the basic syntax of a module. module module_name (port list); declarations: reg, wire, parameter, input, output, inout, function, task….. Statements: Initial statement Always statement Module installation gate installation

UDP installation Continuous assignment Endmodule

The basic building block in our proposed encryption and decryption algorithm is the XOR function. The C and MATLAB code when analysed properly, we can observe that the XOR function is used in several places. Hence the Verilog module of a XOR function is given below: module algo (A, B, Cin, Sum, Cout);

input A, B, Cin; output Sum, Cout; wire S1, T1, T2, T3 xor X1 (S1, A, B); X2 (Sum, S1, Cin); endmodule

IV. ADVANTAGES OF THE PROPOSED CRYPTOGRAPHIC ALGORITHM

With a general cryptosystem it is necessary to transfer a secret key to both the communication parties before secure communication can begin. It is quite difficult to achieve a shared secret key in the communication channel and often such a channel meant physical delivery of keys by a special courier. An important advantage that this proposed algorithm provides is the achievement of exchanging a secret key between remote communication parties with no need of a secure confidential channel. Also the key required for encryption and decryption are different making the algorithm comparatively tougher to decipher. The keys for encryption and decryption are not always the same data bits; they depend on the changing data bits. If the plaintext message input to a basic cryptographic function has a random distribution, then the function provides a strong protection in hiding the plaintext information, even down to the level of an individual bit. A padding scheme like our algorithm has a random input value which adds randomness to the distribution of the random result, that is, it makes the input to have a more random distribution. Thus, to sequentially combine the randomized padding scheme, we sincerely hope to make use of the strong bit-security.

REFERENCES [1] Modern Cryptography: Theory and practice by Wenbo Mao Hewlett-

Packard Company [2] An article on An Introduction to Cryptography by Edward J.

Delp,Purdue University School of Electrical and Computer Engineering

[3] An article on “A Brief History of Cryptography”, S. Hebert [4] C.E. Shannon, “Communication Theory of Secrecy Systems,” Bell

System Tech. [5] Public-Key Cryptography and Open Systems Interconnection by

~~Warwick Ford and Brian 0 ’Higgins [6] Communication System by Simon Haykin [7] A Cost Effective Symmetric Key Cryptographic Algorithm for Small

Amount of Data by Mohammad Zakir Hossain Sarker and Md. Shafiul Parvez

[8] Programming in C by Byron S. Gottfried, Schaum’s Outlines [9] C Unleashed by the Sams Group Publisher BPB [10] An article on An Introduction to Matlab Version 2.3 by David

F.Griffiths, Department of Mathematics, The University Dundee [11] Verilog Digital System Design 2nd edition by Zainalabedin Navabi [12] A Verilog HDL Primer 2nd edition by J. Bhasker, BS Publications