Class XMSSUtil


  • public class XMSSUtil
    extends Object
    Utils for XMSS implementation.
    • Constructor Detail

      • XMSSUtil

        public XMSSUtil()
    • Method Detail

      • log2

        public static int log2​(int n)
        Calculates the logarithm base 2 for a given Integer.
        Parameters:
        n - Number.
        Returns:
        Logarithm to base 2 of n.
      • toBytesBigEndian

        public static byte[] toBytesBigEndian​(long value,
                                              int sizeInByte)
        Convert int/long to n-byte array.
        Parameters:
        value - int/long value.
        sizeInByte - Size of byte array in byte.
        Returns:
        int/long as big-endian byte array of size sizeInByte.
      • longToBigEndian

        public static void longToBigEndian​(long value,
                                           byte[] in,
                                           int offset)
      • bytesToXBigEndian

        public static long bytesToXBigEndian​(byte[] in,
                                             int offset,
                                             int size)
      • cloneArray

        public static byte[] cloneArray​(byte[] in)
        Clone a byte array.
        Parameters:
        in - byte array.
        Returns:
        Copy of byte array.
      • cloneArray

        public static byte[][] cloneArray​(byte[][] in)
        Clone a 2d byte array.
        Parameters:
        in - 2d byte array.
        Returns:
        Copy of 2d byte array.
      • areEqual

        public static boolean areEqual​(byte[][] a,
                                       byte[][] b)
        Compares two 2d-byte arrays.
        Parameters:
        a - 2d-byte array 1.
        b - 2d-byte array 2.
        Returns:
        true if all values in 2d-byte array are equal false else.
      • dumpByteArray

        public static void dumpByteArray​(byte[][] x)
        Dump content of 2d byte array.
        Parameters:
        x - byte array.
      • hasNullPointer

        public static boolean hasNullPointer​(byte[][] in)
        Checks whether 2d byte array has null pointers.
        Parameters:
        in - 2d byte array.
        Returns:
        true if at least one null pointer is found false else.
      • copyBytesAtOffset

        public static void copyBytesAtOffset​(byte[] dst,
                                             byte[] src,
                                             int offset)
        Copy src byte array to dst byte array at offset.
        Parameters:
        dst - Destination.
        src - Source.
        offset - Destination offset.
      • extractBytesAtOffset

        public static byte[] extractBytesAtOffset​(byte[] src,
                                                  int offset,
                                                  int length)
        Copy length bytes at position offset from src.
        Parameters:
        src - Source byte array.
        offset - Offset in source byte array.
        length - Length of bytes to copy.
        Returns:
        New byte array.
      • isIndexValid

        public static boolean isIndexValid​(int height,
                                           long index)
        Check whether an index is valid or not.
        Parameters:
        height - Height of binary tree.
        index - Index to validate.
        Returns:
        true if index is valid false else.
      • getDigestSize

        public static int getDigestSize​(Digest digest)
        Determine digest size of digest.
        Parameters:
        digest - Digest.
        Returns:
        Digest size.
      • getTreeIndex

        public static long getTreeIndex​(long index,
                                        int xmssTreeHeight)
      • getLeafIndex

        public static int getLeafIndex​(long index,
                                       int xmssTreeHeight)
      • calculateTau

        public static int calculateTau​(int index,
                                       int height)
      • isNewBDSInitNeeded

        public static boolean isNewBDSInitNeeded​(long globalIndex,
                                                 int xmssHeight,
                                                 int layer)
      • isNewAuthenticationPathNeeded

        public static boolean isNewAuthenticationPathNeeded​(long globalIndex,
                                                            int xmssHeight,
                                                            int layer)