java.lang.Object
org.bouncycastle.pqc.legacy.math.ntru.util.Util

public class Util extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    static int
    invert(int n, int modulus)
    Calculates the inverse of n mod modulus
    static boolean
    Takes an educated guess as to whether 64 bits are supported by the JVM.
    static int
    pow(int a, int b, int modulus)
    Calculates a^b mod modulus
    static long
    pow(long a, int b, long modulus)
    Calculates a^b mod modulus
    static byte[]
    readFullLength(InputStream is, int length)
    Reads a given number of bytes from an InputStream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • invert

      public static int invert(int n, int modulus)
      Calculates the inverse of n mod modulus
    • pow

      public static int pow(int a, int b, int modulus)
      Calculates a^b mod modulus
    • pow

      public static long pow(long a, int b, long modulus)
      Calculates a^b mod modulus
    • generateRandomTernary

      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:
      N -
      numOnes -
      numNegOnes -
      sparse - whether to create a SparseTernaryPolynomial or DenseTernaryPolynomial
      Returns:
      a ternary polynomial
    • generateRandomTernary

      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.
      Parameters:
      N -
      numOnes -
      numNegOnes -
      Returns:
      an array of integers
    • is64BitJVM

      public static boolean is64BitJVM()
      Takes an educated guess as to whether 64 bits are supported by the JVM.
      Returns:
      true if 64-bit support detected, false otherwise
    • readFullLength

      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.
      Parameters:
      is -
      length -
      Returns:
      an array of length length
      Throws:
      IOException