Bouncy Castle Cryptography 1.50

org.bouncycastle.pqc.math.ntru.util
Class ArrayEncoder

java.lang.Object
  extended by org.bouncycastle.pqc.math.ntru.util.ArrayEncoder

public class ArrayEncoder
extends java.lang.Object

Converts a coefficient array to a compact byte array and vice versa.


Constructor Summary
ArrayEncoder()
           
 
Method Summary
static int[] decodeMod3Sves(byte[] data, int N)
          Decodes a byte array encoded with encodeMod3Sves(int[]) back to an int array with N coefficients between -1 and 1.
Ignores any excess bytes.
See P1363.1 section 9.2.2.
static int[] decodeMod3Tight(byte[] b, int N)
          Converts a byte array produced by encodeMod3Tight(int[]) back to an int array.
static int[] decodeMod3Tight(java.io.InputStream is, int N)
          Converts data produced by encodeMod3Tight(int[]) back to an int array.
static int[] decodeModQ(byte[] data, int N, int q)
          Decodes a byte array encoded with encodeModQ(int[], int) back to an int array.
N is the number of coefficients.
static int[] decodeModQ(java.io.InputStream is, int N, int q)
          Decodes data encoded with encodeModQ(int[], int) back to an int array.
N is the number of coefficients.
static byte[] encodeMod3Sves(int[] arr)
          Encodes an int array whose elements are between -1 and 1, to a byte array.
static byte[] encodeMod3Tight(int[] intArray)
          Encodes an int array whose elements are between -1 and 1, to a byte array.
static byte[] encodeModQ(int[] a, int q)
          Encodes an int array whose elements are between 0 and q, to a byte array leaving no gaps between bits.
q must be a power of 2.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayEncoder

public ArrayEncoder()
Method Detail

encodeModQ

public static byte[] encodeModQ(int[] a,
                                int q)
Encodes an int array whose elements are between 0 and q, to a byte array leaving no gaps between bits.
q must be a power of 2.

Parameters:
a - the input array
q - the modulus
Returns:
the encoded array

decodeModQ

public static int[] decodeModQ(byte[] data,
                               int N,
                               int q)
Decodes a byte array encoded with encodeModQ(int[], int) back to an int array.
N is the number of coefficients. q must be a power of 2.
Ignores any excess bytes.

Parameters:
data - an encoded ternary polynomial
N - number of coefficients
q -
Returns:
an array containing N coefficients between 0 and q-1

decodeModQ

public static int[] decodeModQ(java.io.InputStream is,
                               int N,
                               int q)
                        throws java.io.IOException
Decodes data encoded with encodeModQ(int[], int) back to an int array.
N is the number of coefficients. q must be a power of 2.
Ignores any excess bytes.

Parameters:
is - an encoded ternary polynomial
N - number of coefficients
q -
Returns:
the decoded polynomial
Throws:
java.io.IOException

decodeMod3Sves

public static int[] decodeMod3Sves(byte[] data,
                                   int N)
Decodes a byte array encoded with encodeMod3Sves(int[]) back to an int array with N coefficients between -1 and 1.
Ignores any excess bytes.
See P1363.1 section 9.2.2.

Parameters:
data - an encoded ternary polynomial
N - number of coefficients
Returns:
the decoded coefficients

encodeMod3Sves

public static byte[] encodeMod3Sves(int[] arr)
Encodes an int array whose elements are between -1 and 1, to a byte array. coeffs[2*i] and coeffs[2*i+1] must not both equal -1 for any integer i, so this method is only safe to use with arrays produced by decodeMod3Sves(byte[], int).
See P1363.1 section 9.2.3.

Parameters:
arr -
Returns:
the encoded array

encodeMod3Tight

public static byte[] encodeMod3Tight(int[] intArray)
Encodes an int array whose elements are between -1 and 1, to a byte array.

Returns:
the encoded array

decodeMod3Tight

public static int[] decodeMod3Tight(byte[] b,
                                    int N)
Converts a byte array produced by encodeMod3Tight(int[]) back to an int array.

Parameters:
b - a byte array
N - number of coefficients
Returns:
the decoded array

decodeMod3Tight

public static int[] decodeMod3Tight(java.io.InputStream is,
                                    int N)
                             throws java.io.IOException
Converts data produced by encodeMod3Tight(int[]) back to an int array.

Parameters:
is - an input stream containing the data to decode
N - number of coefficients
Returns:
the decoded array
Throws:
java.io.IOException

Bouncy Castle Cryptography 1.50