Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exact Large Finite Field Linear Algebra Library (e.g. GF(2^128) / GF(2^256) ) [closed]

General

I'm looking for a library that is able to do exact calculations on large finite fields such as GF(2128)/𝔽2128 and GF(2256)/𝔽2256. I listed the features that I need and the features that would be cool below. Obviously, the library should be as fast as possible :-). Ah, since I'm no C++ master (and probably most of the libraries are C++), sample code of say generate a random element/a constant and multiply it to it's multiplicative inverse

Must-Have Features

  • Addition of field elements
  • Multiplication of field element
  • Find the multiplicative inverse of a field element

Nice to Have Features

  • Vector/Matrix support
  • Random Element support

Libraries I already looked at that will probably not work

  • FFLAS/FFPACK, seems not to work with such large finite fields
  • Givaro, seems not to work on such large finite fields

Libraries I already looked at that could work (but I was unable to use)

  • NTL, I was not able to invert an element, but it should really work since SAGE seems to use this library when defining GF(2^256) and there an element can be inverted using x^(-1)
  • PARI/GP, I was not able to find everything I need in the documentation, but the SAGE documentation kind of says that it should work

Other notes

  • I'm writing a Haskell program and will interface that library later, so easier Haskell interfacing is better :-)
like image 209
Johannes Weiss Avatar asked Aug 20 '12 15:08

Johannes Weiss


People also ask

What is GF in linear algebra?

GF(2) (also denoted , Z/2Z or ) is the finite field of two elements (GF is the initialism of Galois field, another name for finite fields). Notations Z2 and. may be encountered although they can be confused with the notation of 2-adic integers.

What is the significance of GF 2 N in cryptography?

The order of a finite field refers to the number of elements in the field. So the order of GF(2n) is 2n. More particularly, the bitwise operations needed for directly multiplying two bit patterns in GF(2n) are specific to the irreducible polynomial that defines a given GF(2n).

What does GF mean in math?

GF( ) is called the prime field of order , and is the field of residue classes modulo , where the elements are denoted 0, 1, ..., .

What is field F2?

F2, the chemical formula for fluorine. or GF(2), in mathematics, the Galois field of two elements. F2, a category in the Fujita scale of tornado intensity.


1 Answers

The NTL library seems to work, using this (sorry I'm quite unable to program in C++) code

#include <NTL/GF2E.h>
#include <NTL/GF2EX.h>
#include <NTL/GF2X.h>
#include <NTL/GF2XFactoring.h>

NTL_CLIENT

int main()
{
    GF2X P = BuildIrred_GF2X(256);
    GF2E::init(P);

    GF2E zero = GF2E::zero();
    GF2E one;
    GF2E r = random_GF2E();
    GF2E r2 = random_GF2E();
    conv(one, 1L);
    cout << "Cardinality: " << GF2E::cardinality() << endl;
    cout << "ZERO: " << zero << " --> " << IsZero(zero) << endl;
    cout << "ONE:  " << one  << " --> " << IsOne(one)   << endl;
    cout << "1/r:  " << 1/r  << ", r * (1/r): " << (r * (1/r)) << endl;
    cout << "1/r2:  " << 1/r2  << ", r2 * (1/r2): " << (r2 * (1/r2)) << endl;
}

it seems to work, proof (output of this program):

Cardinality: 115792089237316195423570985008687907853269984665640564039457584007913129639936
ZERO: [] --> 1
ONE:  [1] --> 1
1/r:  [0 1 0 1 1 0 1 1 1 0 1 1 1 0 0 1 1 0 1 1 1 0 1 1 0 0 0 0 0 1 0 1 0 1 1 0 1 1 0 0 0 0 0 0 1 1 1 0 1 1 1 0 1 0 1 0 0 0 1 1 1 0 1 1 1 1 0 1 0 1 0 1 1 0 1 1 1 0 0 0 1 0 0 1 0 1 1 1 0 1 1 0 1 1 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 1 0 0 1 1 0 0 1 0 0 1 0 1 1 1 1 0 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 0 0 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 1 1 1 0 1 0 1 0 0 0 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 0 1 1 0 1 1 0 1 1 1 1 1 0 0 1 1 0 1 0 1 0 0 0 0 1 1 0 0 1 1 1 0 1], r * (1/r): [1]
1/r2:  [1 0 1 1 0 0 0 0 1 0 1 0 0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 1 0 1 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 1 0 1 0 1 1 1 0 0 1 0 1 0 1 0 0 1 0 0 0 1 0 0 1 1 1 1 1 0 0 0 0 1 1 1 0 1 0 1 0 1 0 0 0 1 0 1 0 1 1 0 0 0 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 1 0 1 1 0 0 0 0 1 1 0 1 1 1 0 1 0 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 0 0 0 0 1 0 0 0 0 1 1 1 1 1 0 1 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 1 0 1 1 1 0 1 0 0 0 0 1 0 1 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1 0 1 0 0 1 1], r2 * (1/r2): [1]

Even inverting seems to work (scroll as right as possible in the output sample above) :-)

like image 91
Johannes Weiss Avatar answered Oct 27 '22 00:10

Johannes Weiss