HFE
Class HFE4_3

java.lang.Object
  |
  +--HFE.HFE4_3

class HFE4_3
extends java.lang.Object

This class is the "toy version" of HFE which works on 6 bits over the field F_4 (Field4) which extents to F_64.

Version:
0.1

Field Summary
private static int[] codeVec
          Cipher as a vector.
private  java.security.MessageDigest digest
          Stores a copy of the message digest which is used to get one unique solution
private  Poly64Max privatePoly
          Stores the private polynomial over F_64.
private  Poly4MultiSquare[] publicPoly
          Stores the public key matrix of polynomials over GF(4).
private static int[] resVec
          Message as a vector.
private static int[] textVec
          Message as a vector.
private  Transform4 transS
          Transformation S in HFE
private  Transform4 transT
          Transformation T in HFE
private static int[] valueVec
          Message in a special format as a vector.
 
Constructor Summary
(package private) HFE4_3(long seed)
          Initializes HFE4_3 by generating the public and the private key from the given seed.
 
Method Summary
(package private)  int decrypt(int cipherHash)
          Decryptes a given, 22 bit ciphertext / hash
(package private)  int encrypt(int plain)
          Encryptes a given, 6 bit plain text.
(package private)  int filterRoots(java.util.Collection resColl, int hash)
          Finds out which roots are correct acording to the given hash.
(package private)  void generateKeys(long seed)
          Generates the public and the private key from a given seed and stores them in the object's fields.
private static Poly64Max genPolyPrivate(int[] coeff)
          Generates a private key for HFE.
private  Poly4MultiSquare[] genPolyPublic(int[] coeff)
          Generates the 3 public polynomial from the object's private polynomial.
(package private)  java.util.Collection getRoots(Poly64Max masterPoly, int a)
          Calculates the root for a given Polynomial and a given element of F_64.
(package private)  int giveHash(int plain)
          Produces a 16 bit hash for the given plaintext.
private static void int2vec(int in, int[] out)
          computes an vector of integers out of one integer
static void main(java.lang.String[] args)
          Tests everything in this class
static void speedIt()
           
static void testIt()
          Tests the functionality of the whole class.
private static int vec2int(int[] in)
          computes an vector of integers out of one integer
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

privatePoly

private Poly64Max privatePoly
Stores the private polynomial over F_64. Is used for decryption.

publicPoly

private Poly4MultiSquare[] publicPoly
Stores the public key matrix of polynomials over GF(4). They are used for encryption.

digest

private final java.security.MessageDigest digest
Stores a copy of the message digest which is used to get one unique solution

transS

private Transform4 transS
Transformation S in HFE

transT

private Transform4 transT
Transformation T in HFE

textVec

private static int[] textVec
Message as a vector. For the sake of speed is it a static.

resVec

private static int[] resVec
Message as a vector. For the sake of speed is it a static.

valueVec

private static int[] valueVec
Message in a special format as a vector. For the sake of speed is it a static.

codeVec

private static int[] codeVec
Cipher as a vector. For the sake of speed static.
Constructor Detail

HFE4_3

HFE4_3(long seed)
 throws java.security.NoSuchAlgorithmException
Initializes HFE4_3 by generating the public and the private key from the given seed. Also generates the message digest.
Parameters:
seed - Seed for the cryptographic random number generator. Caution! This seed is to short for cryptographic purposes!
Method Detail

giveHash

int giveHash(int plain)
Produces a 16 bit hash for the given plaintext.
Parameters:
plain - Plaintext in the lower 6 bits

int2vec

private static void int2vec(int in,
                            int[] out)
computes an vector of integers out of one integer

vec2int

private static int vec2int(int[] in)
computes an vector of integers out of one integer

genPolyPrivate

private static Poly64Max genPolyPrivate(int[] coeff)
Generates a private key for HFE. This polynomial has the form f(x) = ax^20 + bx^17 + cx^16 + dx^4 + e where a, b, c, d, e are elements from F_64.
Parameters:
coeff - Coefficients for the private polynomial
Returns:
private polynomial

genPolyPublic

private Poly4MultiSquare[] genPolyPublic(int[] coeff)
Generates the 3 public polynomial from the object's private polynomial.
Parameters:
coeff - Coefficients for the private polynomial
Returns:
3 Polynomials in a matrix over F_4. The matrix has the size n*tau(n) [here: n=3, tau(3)=10]

generateKeys

void generateKeys(long seed)
Generates the public and the private key from a given seed and stores them in the object's fields. For cryptographic purposes, the seed is too short.
Parameters:
seed - Seed for the random number generator

getRoots

java.util.Collection getRoots(Poly64Max masterPoly,
                              int a)
Calculates the root for a given Polynomial and a given element of F_64. The equation is f(x) = a. Returns _all_ x which satisfy this equation. There are up to d (d: degree of the polynomial) solutions.
Currently, this method uses brute force.
Returns:
all x with f(x) = a

filterRoots

int filterRoots(java.util.Collection resColl,
                int hash)
Finds out which roots are correct acording to the given hash.

encrypt

int encrypt(int plain)
Encryptes a given, 6 bit plain text.
Is currently using the private polynomial.
Parameters:
plain - plaintext in the lower 6 bits
Returns:
encyrpted plaintext (lower 6 bits) and hash (16 bits at bit positions 6..21)

decrypt

int decrypt(int cipherHash)
Decryptes a given, 22 bit ciphertext / hash
Parameters:
cipherHash - 22 bit where the lower 6 bits are the cipher text and the bits 6..21 are hash of the plaintext.
Returns:
plaintext in the lower 6 bits (i.e. 0..5)

testIt

public static void testIt()
Tests the functionality of the whole class. If there occurs any error it will be printed on stdout.

speedIt

public static final void speedIt()

main

public static void main(java.lang.String[] args)
Tests everything in this class
See Also:
testIt()