Implementation of Finite Field Arithmetic Operations for Large Prime and Binary Fields Using Java Biginteger C Lass
Total Page:16
File Type:pdf, Size:1020Kb
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 Field Arithmetic 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 finite field 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 mathematics 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 coding theory, cryptography, algebraic showed that for a field to be finite, the number of elements geometry and number theory. should be pm , where p is a prime number called the Nowadays, a finite field is very important structure in characteristic 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 logarithm problems are frequently implemented over finite an extension field. The order 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 multiplicative inverse 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 polynomial basis representation. Here, the elements of and mod methods of BigInteger class for the logic GF(2m) are the binary polynomials (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 long division 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 m and division of elements (a, b) in the binary field GF(2 ) 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:(푞, 푟) = (푎 ÷ 푏).