<<

Published by : International Journal of Engineering Research & Technology (IJERT) http://www.ijert.org ISSN: 2278-0181 Vol. 6 Issue 08, August - 2017 Implementation of Finite Operations for Large Prime and Binary Fields using java BigInteger C lass

Ni Ni Hla Tun Myat Aung University of Computer Studies, Yangon University of Computer Studies, Yangon Myanmar Myanmar

Abstract—Many cryptographic protocols are based on the II. INTRODUCTION TO FINITE FIELDS difficulty of factoring large composite integers or a related problem. Therefore, we implement the arithmetic A finite field is a field containing a finite number of operations for large prime and binary fields by using java elements. Fields are abstractions of familiar number systems BigInteger class to study our research under large integers for (such as the rational numbers Q, the real numbers R, and the public key cryptosystems and elliptic curve. complex numbers C) and their essential properties. They consist of a set F together with two operations, addition Keywords — Finite Field Arithmetic; Prime Field; Binary Field, (denoted by +) and multiplication (denoted by ·), that satisfy Large Integer the usual arithmetic properties:

I. INTRODUCTION  (F,+) is an abelian group with (additive) identity denoted The origins and history of finite fields can be traced back by 0. to the 17th and 18th centuries, but there, these fields played  (F\{0}, ·) is an abelian group with (multiplicative) identity only a minor role in the of the day. In more denoted by 1. recent times, however, finite fields have assumed a much more  The distributive law holds: (a+b) · c = (a · c) + (b · c) for fundamental role and in fact are of rapidly increasing all a, b, c ∈ F. importance because of practical applications in a wide variety If the set F is finite, then the field is said to be finite. Galois of areas such as , , algebraic showed that for a field to be finite, the number of elements geometry and number theory. should be pm , where p is a called the Nowadays, a finite field is very important structure in of F and m is a positive integer. The finite fields cryptography. Many cryptographic applications use finite field are usually called Galois fields and also denoted as GF(pm). If arithmetic. Public key systems based on various discrete m = 1, then GF is called a prime field. If m ≥ 2, then F is called problems are frequently implemented over finite an extension field. The of a finite field is the number of fields to provide structure and efficient arithmetic. elements in the field. Any two fields are said to be isomorphic if their orders are the same[4]. The finite field arithmetic operations need to be implemented for the development and research of stream A. Field Operations ciphers, block ciphers, public key cryptosystems and A field F is equipped with two operations, addition and cryptographic schemes over elliptic curves. Many multiplication. Subtraction of field elements is defined in cryptographic protocols are based on the difficulty of factoring terms of addition: for a,b ∈ F, a −b = a +(−b) where −b is the large composite integers or a related problem. Therefore, we unique element in F such that b+(−b) = 0 (−b is called the implement the finite field arithmetic operations for large prime negative or additive inverse of b). Similarly, division of field and binary fields by using java BigInteger class to study our elements is defined in terms of multiplication: for a,b ∈ F with research under large integers. b = 0, a/b = a · b−1 where b−1 is the unique element in F such −1 −1 The organization of this paper is as follows: section 2 is that b · b = 1. (b is called the of b.) devoted to finite fields and their properties. In section 3, how B. Prime Field to implement finite field arithmetic operations under prime field and binary field are described. Some algorithms applied Let p be a prime number. The integers modulo p, in the implementation are listed in section 4. The results of consisting of the integers {0,1,2, . . ., p −1} with addition and implementation for finite field arithmetic operations under multiplication performed modulo p, is a finite field of order p. prime field and binary field are shown in section 5. Finally, we We shall denote this field by GF(p) and call p the modulus of conclude our discussion in section 6. GF(p). For any integer a, a mod p shall denote the unique integer remainder r, 0 ≤r ≤ p−1, obtained upon dividing a by p; this operation is called reduction modulo p.

IJERTV6IS080209 www.ijert.org 450 (This work is licensed under a Creative Commons Attribution 4.0 International License.) Published by : International Journal of Engineering Research & Technology (IJERT) http://www.ijert.org ISSN: 2278-0181 Vol. 6 Issue 08, August - 2017

Example 1. (prime field GF(29)) The elements of GF(29) A. Arithmetic Operations of Prime Field are {0,1,2, . . .,28}. The following are some examples of The arithmetic operations of prime field need to be arithmetic operations in GF(29). implemented to study our research under prime fields. (i) Addition: 17+20 = 8 since 37 mod 29 = 8. Therefore, we implement a PrimeField class with methods of (ii) Subtraction: 17−20 = 26 since −3 mod 29 = 26. arithmetic operations for addition, subtraction, multiplication (iii) Multiplication: 17 · 20 = 21 since 340 mod 29 = 21. and division of elements (a, b) in the prime field GF(p). The (iv) Inversion: 17−1 = 12 since 17 · 12 mod 29 = 1. methods of PrimeField class are implemented as follows. C. Binary Field (i). The addition method is implemented by add and mod Finite fields of order 2m are called binary fields or methods of BigInteger class for the logic statement: a + b = ( a + b ) mod p. characteristic-two finite fields. One way to construct GF(2m) is (ii). The subtraction method is implemented by add, subtract, to use a basis representation. Here, the elements of and mod methods of BigInteger class for the logic GF(2m) are the binary (polynomials whose coefficients are in the field GF(2) = {0,1}) of degree at most m statement: a - b = (a + (- b )) mod p. In this case, -b is an −1: additive inverse of prime number p. The logic statement of additive inverse -b is (p – b). 푚 푚−1 푚−2 2 퐺퐹(2 ) = 푎푚−1푥 + 푎푚−2푥 + ⋯ + 푎2푥 + 푎1푥 + (iii). The multiplication method is implemented by multiply 푎0: 푎푖 ∈ {0,1}. and mod methods of BigInteger class for the logic statement: 푎 . 푏 = (푎 × 푏) 푚표푑 푝. An irreducible binary polynomial f (x) of degree m is (iv). The division method is implemented by multiply and chosen. Irreducibility of f(x) means that f(x) cannot be factored modInverse methods of BigInteger class for the logic as a product of binary polynomials each of degree less than m. statement: 푎 ÷ 푏 = (푎 × 푏−1) 푚표푑 푝. In this case, b-1 Addition of field elements is the usual addition of is a multiplicative inverse of prime number p. polynomials, with coefficient arithmetic performed modulo 2. (v). The multiplicative inverse method is adopted from the Multiplication of field elements is performed modulo the modInverse method. reduction polynomial f(x). For any binary polynomial a(x), a(x) mod f(x) shall denote the unique remainder polynomial B. Arithmetic Operations of Binary Field r(x) of degree less than m obtained upon of a(x) The arithmetic operations of binary field need to be by f(x); this operation is called reduction modulo f(x). implemented to study our research under prime fields. Example 2. (binary field GF(24)) The elements of GF(24) Therefore, we implement a BinaryField class with methods of are the 16 binary polynomials of degree at most 3: arithmetic operations for addition, subtraction, multiplication and division of elements (a, b) in the binary field GF(2m) with 0 푥2 푥3 푥3 + 푥2 reduction polynomial p. The methods of BinaryField class are 1 푥2 + 1 푥3 + 1 푥3 + 푥2 + 1 implemented as follows. 2 3 3 2 푥 푥 + 푥 푥 + 푥 푥 + 푥 + 푥 (i). The addition method is implemented by xor method of 푥 + 1 푥2 + 푥 + 1 푥3 + 푥 + 1 푥3 + 푥2 + 푥 + 1 BigInteger class for the logic statement:푎 + 푏 = 푎 ⊕ 푏.

In this case, The addition operation is implemented by The following are some examples of arithmetic operations bitwise XOR operation of all bits of the two operands. in GF(24) with reduction Polynomial 푓(푥) = 푥4 + 푥 + 1. (ii). The subtraction method is identical to the addition

method as above. (i). Addition: (푥3 + 푥2 + 1) + (푥2 + 푥 + 1) = 푥3 + 푥 (iii). The multiplication method is implemented by shifLeft and 3 2 ( 2 ) 3 (ii). Subtraction: (푥 + 푥 + 1) − 푥 + 푥 + 1 = 푥 + 푥 xor methods of BigInteger class for the logic (iii). Multiplication: (푥3 + 푥2 + 1). (푥2 + 푥 + 1) = 푥2 + 1 3 2 2 5 statement: 푎 . 푏 = (푎 × 푏) 푚표푑 푝. The algorithm for since (푥 + 푥 + 1). (푥 + 푥 + 1) = 푥 + 푥 + 1 and multiplication of two polynomials in GF(2m) is given in (푥5 + 푥 + 1) 푚표푑 (푥4 + 푥 + 1) = 푥2 + 1. 3 2 −1 2 Algorithm (1)[ 1]. (iv). Inversion: (푥 + 푥 + 1) = 푥 since (iv). The quotientAndRemainder method is implemented by 3 2 2 4 (푥 + 푥 + 1). 푥 푚표푑 (푥 + 푥 + 1) = 1. shifLeft and setBit methods of BigInteger class for the logic statement:(푞, 푟) = (푎 ÷ 푏). The algorithm to find III. IMPLEMENTATION OF FIELD OPERATIONS quotient (q) and remainder (r) from division of two The finite field arithmetic operations: addition, subtraction, polynomials in GF(2m) is given in Algorithm (2). division, multiplication and multiplicative inverse, need to be (v). The multiplicativeInverse method is implemented by implemented for the development and research of stream quotientAndRemainder and multiplication methods of ciphers, public key cryptosystems and cryptographic schemes BinaryField class and xor method of BigInteger for the over elliptic curves. We implement the finite field arithmetic logic statement: b · b−1 mod p= 1. The multiplicative operations by using java BigInteger class to study our research inverse b-1 is computed by using Extended Euclidean under large numbers. GCD algorithm given in Algorithm (3)[ 2]. (vi). The division operation is implemented by multiplication and multiplicativeInverse methods of BinaryField class for the logic statement: 푎 ÷ 푏 = (푎 × 푏−1) 푚표푑 푝. In this case, b-1 is a multiplicative inverse of prime

IJERTV6IS080209 www.ijert.org 451 (This work is licensed under a Creative Commons Attribution 4.0 International License.) Published by : International Journal of Engineering Research & Technology (IJERT) http://www.ijert.org ISSN: 2278-0181 Vol. 6 Issue 08, August - 2017

polynomial p. The multiplicative inverse is adopted from V. RESULTS OF IMPLEMENTATION the multiplicativeInverse method. We measure the performance of finite field arithmetic operations: addition, subtraction, division, multiplication and IV. ALGORITHMS multiplicative inverse, under prime field and binary field for Algorithm (1). shift-and-xor method comparison of execution time on the processor Intel Core Input: a, b, p as polynomials [email protected], 2.30GHz. The finite field arithmetic operations Output: result use the large integers of the prime field and the binary field Begin defined by NIST recommended elliptic curve for federal Set result= 0; government [6]. The results are listed in Table (1). For( i=0; i= 0; Multiplicative Inverse of X Z = 4501487661668459201131201625760338945286855411 term--) 592992703750. begin if (bitLength of a == bitLength of b + term) Binary Field (K-163) Set a = a xor shiftLeft(term of b). 푝(푡) = 푡163 + 푡7 + 푡6 + 푡3 + 1 Set quotient = setBit(term of quotient). X = 2fe13c0537bbc11ac aa07d793de4e6d5e5c94eee8 Y = 289070fb05d38ff58321f2e800536d538ccdaa3d9 endIf Addition end Z = X + Y. Set remainder = a. Z = 7714cfe32684eef49818f913db78b866904e4d31 Return quotient, remainder Subtraction Z = X - Y. End Z = 7714cfe32684eef49818f913db78b866904e4d31 (3). Extended Euclidean GCD algorithm Z = X . Y. Z = 4d741872162b253d5a381f1f680b47e5c0ad3aa2a Division Input: x, p as polynomials Z = X % Y. Output: a Z = 498d03bb544d83614e0b5963052f604eb8ec8d0cd Begin Multiplicative Inverse of X Set y = x. Z = 63f514f39f4587684f96c8dd6558e69339a1efed9

Set x = p. Table (1). The results of performance Set a = 0. Finite Field Prime Field Binary Field Set b = 1. Arithmetic Operations (ms/100000times) (ms/100000times) while (푦 ≠ 0) Addition 31 16 Subtraction 62 16 begin Division 2262 70497 Set 푞 = 푥 / 푦. Multiplication 156 2808 Set 푟 = 푥 푚표푑 푦. Multiplicative inverse 2028 70153 Set x = y. Set y = r. Set 푡푒푚푝 = 푎 ⨁ (푞 × 푏). Set a = b. Set b = temp; end if (x = 1) return a. endIf End

IJERTV6IS080209 www.ijert.org 452 (This work is licensed under a Creative Commons Attribution 4.0 International License.) Published by : International Journal of Engineering Research & Technology (IJERT) http://www.ijert.org ISSN: 2278-0181 Vol. 6 Issue 08, August - 2017

REFERENCES VI. CONCLUSION [1]. Annabell Kuldmaa, Efficient Multiplication in Binary Fields, 2015. This is the first step to study our research under large [2]. Behrouz A. Forouzan, Cryptography and Network Security, integers for public key cryptosystems and elliptic curve. The McGraw-Hill press, International Edition, 2008. [3]. Darrel Hankerson, Alfred Menezes, Scott Vanstone. Guide to Elliptic performance of addition and subtraction operations of binary Curve Cryptography, Springer press, 2004. field are more efficient than prime field. The performance of [4]. Dave K. Kythe, Prem K. Kythe. Algebraic and Stochastic Coding division, multiplication and multiplicative inverse operations Theory, CRC Press, 2012. of prime field are more efficient than binary field. Therefore, a [5]. Rudolf Lidl and Harald Niederreiter, Introduction to Finite Field Arithmetic and their Applications, Cambridge University Press, 1986. java BigInteger class is more efficient for the software [6]. Recommended Elliptic Curves for Federal Government Use, NIST, implementation of finite field arithmetic operations in prime 1999. field.

IJERTV6IS080209 www.ijert.org 453 (This work is licensed under a Creative Commons Attribution 4.0 International License.)