org.bouncycastle.pqc.crypto.xmss

## Class XMSSUtil

- java.lang.Object
- - org.bouncycastle.pqc.crypto.xmss.XMSSUtil

-     public class XMSSUtil
      extends java.lang.Object

  Utils for XMSS implementation.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `XMSSUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `areEqual(byte[][] a, byte[][] b)` Compares two 2d-byte arrays.
    `static long` | `bytesToXBigEndian(byte[] in, int offset, int size)`
    `static int` | `calculateTau(int index, int height)`
    `static byte[]` | `cloneArray(byte[] in)` Clone a byte array.
    `static byte[][]` | `cloneArray(byte[][] in)` Clone a 2d byte array.
    `static void` | `copyBytesAtOffset(byte[] dst, byte[] src, int offset)` Copy src byte array to dst byte array at offset.
    `static java.lang.Object` | `deserialize(byte[] data, java.lang.Class clazz)`
    `static void` | `dumpByteArray(byte[][] x)` Dump content of 2d byte array.
    `static byte[]` | `extractBytesAtOffset(byte[] src, int offset, int length)` Copy length bytes at position offset from src.
    `static int` | `getDigestSize(Digest digest)` Determine digest size of digest.
    `static int` | `getLeafIndex(long index, int xmssTreeHeight)`
    `static long` | `getTreeIndex(long index, int xmssTreeHeight)`
    `static boolean` | `hasNullPointer(byte[][] in)` Checks whether 2d byte array has null pointers.
    `static boolean` | `isIndexValid(int height, long index)` Check whether an index is valid or not.
    `static boolean` | `isNewAuthenticationPathNeeded(long globalIndex, int xmssHeight, int layer)`
    `static boolean` | `isNewBDSInitNeeded(long globalIndex, int xmssHeight, int layer)`
    `static int` | `log2(int n)` Calculates the logarithm base 2 for a given Integer.
    `static void` | `longToBigEndian(long value, byte[] in, int offset)`
    `static byte[]` | `serialize(java.lang.Object obj)`
    `static byte[]` | `toBytesBigEndian(long value, int sizeInByte)` Convert int/long to n-byte array.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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)

    - #### serialize

          public static byte[] serialize(java.lang.Object obj)
                                  throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### deserialize

          public static java.lang.Object deserialize(byte[] data,
                                                     java.lang.Class clazz)
                                              throws java.io.IOException,
                                                     java.lang.ClassNotFoundException

      Throws:
        `java.io.IOException`
        `java.lang.ClassNotFoundException`

    - #### 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)