Top Fields Constructors Methods
org.bouncycastle.pqc.legacy.math.ntru.util

public Class Util

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, java.security.SecureRandom, java.util.ArrayList, .Collections, .List, org.bouncycastle.pqc.legacy.math.ntru.euclid.IntEuclidean, org.bouncycastle.pqc.legacy.math.ntru.polynomial.DenseTernaryPolynomial, .SparseTernaryPolynomial, .TernaryPolynomial, org.bouncycastle.util.Integers

Field Summary

Modifier and TypeField and Description
private static volatile boolean
private static volatile boolean

Constructor Summary

AccessConstructor and Description
public
Util()

Method Summary

Modifier and TypeMethod and Description
public static TernaryPolynomial

Returns:

a ternary polynomial
generateRandomTernary
(int N, int numOnes, int numNegOnes, boolean sparse, SecureRandom random)

Generates a "sparse" or "dense" polynomial containing numOnes ints equal to 1, numNegOnes int equal to -1, and the rest equal to 0.

public static int[]

Returns:

an array of integers
generateRandomTernary
(int N, int numOnes, int numNegOnes, SecureRandom random)

Generates an array containing numOnes ints equal to 1, numNegOnes int equal to -1, and the rest equal to 0.

public static int
invert(int n, int modulus)

Calculates the inverse of n mod modulus

public static boolean

Returns:

true if 64-bit support detected, false otherwise
is64BitJVM
()

Takes an educated guess as to whether 64 bits are supported by the JVM.

public static int
pow(int a, int b, int modulus)

Calculates a^b mod modulus

public static long
pow(long a, int b, long modulus)

Calculates a^b mod modulus

public static byte[]

Returns:

an array of length length
readFullLength
(InputStream is, int length)

Reads a given number of bytes from an InputStream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

IS_64_BIT_JVMback to summary
private static volatile boolean IS_64_BIT_JVM
IS_64_BITNESS_KNOWNback to summary
private static volatile boolean IS_64_BITNESS_KNOWN

Constructor Detail

Utilback to summary
public Util()

Method Detail

generateRandomTernaryback to summary
public static TernaryPolynomial generateRandomTernary(int N, int numOnes, int numNegOnes, boolean sparse, SecureRandom random)

Generates a "sparse" or "dense" polynomial containing numOnes ints equal to 1, numNegOnes int equal to -1, and the rest equal to 0.

Parameters
sparse:boolean

whether to create a SparseTernaryPolynomial or DenseTernaryPolynomial

Returns:TernaryPolynomial

a ternary polynomial

generateRandomTernaryback to summary
public static int[] generateRandomTernary(int N, int numOnes, int numNegOnes, SecureRandom random)

Generates an array containing numOnes ints equal to 1, numNegOnes int equal to -1, and the rest equal to 0.

Returns:int[]

an array of integers

invertback to summary
public static int invert(int n, int modulus)

Calculates the inverse of n mod modulus

is64BitJVMback to summary
public static boolean is64BitJVM()

Takes an educated guess as to whether 64 bits are supported by the JVM.

Returns:boolean

true if 64-bit support detected, false otherwise

powback to summary
public static int pow(int a, int b, int modulus)

Calculates a^b mod modulus

powback to summary
public static long pow(long a, int b, long modulus)

Calculates a^b mod modulus

readFullLengthback to summary
public static byte[] readFullLength(InputStream is, int length) throws IOException

Reads a given number of bytes from an InputStream. If there are not enough bytes in the stream, an IOException is thrown.

Returns:byte[]

an array of length length