Top Description Inners Constructors Methods
org.bouncycastle.pqc.crypto.xmss

public Class XMSSUtil

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, .InvalidClassException, .ObjectInputStream, .ObjectOutputStream, .ObjectStreamClass, java.util.HashSet, .Set, org.bouncycastle.crypto.Digest, org.bouncycastle.util.Arrays, org.bouncycastle.util.encoders.Hex

Utils for XMSS implementation.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if all values in 2d-byte array are equal false else.
areEqual
(byte[][]
2d-byte array 1.
a
,
byte[][]
2d-byte array 2.
b
)

Compares two 2d-byte arrays.

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

public static int
calculateTau(int index, int height)

public static byte[]

Returns:

Copy of byte array.
cloneArray
(byte[]
byte array.
in
)

Clone a byte array.

public static byte[][]

Returns:

Copy of 2d byte array.
cloneArray
(byte[][]
2d byte array.
in
)

Clone a 2d byte array.

public static void
copyBytesAtOffset(byte[]
Destination.
dst
,
byte[]
Source.
src
,
int
Destination offset.
offset
)

Copy src byte array to dst byte array at offset.

public static Object
deserialize(byte[] data, final Class<T> clazz)

public static void
dumpByteArray(byte[][]
byte array.
x
)

Dump content of 2d byte array.

public static byte[]

Returns:

New byte array.
extractBytesAtOffset
(byte[]
Source byte array.
src
,
int
Offset in source byte array.
offset
,
int
Length of bytes to copy.
length
)

Copy length bytes at position offset from src.

public static int

Returns:

Digest size.
getDigestSize
(Digest
Digest.
digest
)

Determine digest size of digest.

public static int
getLeafIndex(long index, int xmssTreeHeight)

public static long
getTreeIndex(long index, int xmssTreeHeight)

public static boolean

Returns:

true if at least one null pointer is found false else.
hasNullPointer
(byte[][]
2d byte array.
in
)

Checks whether 2d byte array has null pointers.

public static boolean

Returns:

true if index is valid false else.
isIndexValid
(int
Height of binary tree.
height
,
long
Index to validate.
index
)

Check whether an index is valid or not.

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

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

public static int

Returns:

Logarithm to base 2 of n.
log2
(int
Number.
n
)

Calculates the logarithm base 2 for a given Integer.

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

public static byte[]
public static byte[]

Returns:

int/long as big-endian byte array of size sizeInByte.
toBytesBigEndian
(long
int/long value.
value
,
int
Size of byte array in byte.
sizeInByte
)

Convert int/long to n-byte array.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

XMSSUtilback to summary
public XMSSUtil()

Method Detail

areEqualback to summary
public static boolean areEqual(byte[][] a, byte[][] b)

Compares two 2d-byte arrays.

Parameters
a:byte[][]

2d-byte array 1.

b:byte[][]

2d-byte array 2.

Returns:boolean

true if all values in 2d-byte array are equal false else.

bytesToXBigEndianback to summary
public static long bytesToXBigEndian(byte[] in, int offset, int size)
calculateTauback to summary
public static int calculateTau(int index, int height)
cloneArrayback to summary
public static byte[] cloneArray(byte[] in)

Clone a byte array.

Parameters
in:byte[]

byte array.

Returns:byte[]

Copy of byte array.

cloneArrayback to summary
public static byte[][] cloneArray(byte[][] in)

Clone a 2d byte array.

Parameters
in:byte[][]

2d byte array.

Returns:byte[][]

Copy of 2d byte array.

copyBytesAtOffsetback to summary
public static void copyBytesAtOffset(byte[] dst, byte[] src, int offset)

Copy src byte array to dst byte array at offset.

Parameters
dst:byte[]

Destination.

src:byte[]

Source.

offset:int

Destination offset.

deserializeback to summary
public static Object deserialize(byte[] data, final Class<T> clazz) throws IOException, ClassNotFoundException
dumpByteArrayback to summary
public static void dumpByteArray(byte[][] x)

Dump content of 2d byte array.

Parameters
x:byte[][]

byte array.

extractBytesAtOffsetback to summary
public static byte[] extractBytesAtOffset(byte[] src, int offset, int length)

Copy length bytes at position offset from src.

Parameters
src:byte[]

Source byte array.

offset:int

Offset in source byte array.

length:int

Length of bytes to copy.

Returns:byte[]

New byte array.

getDigestSizeback to summary
public static int getDigestSize(Digest digest)

Determine digest size of digest.

Parameters
digest:Digest

Digest.

Returns:int

Digest size.

getLeafIndexback to summary
public static int getLeafIndex(long index, int xmssTreeHeight)
getTreeIndexback to summary
public static long getTreeIndex(long index, int xmssTreeHeight)
hasNullPointerback to summary
public static boolean hasNullPointer(byte[][] in)

Checks whether 2d byte array has null pointers.

Parameters
in:byte[][]

2d byte array.

Returns:boolean

true if at least one null pointer is found false else.

isIndexValidback to summary
public static boolean isIndexValid(int height, long index)

Check whether an index is valid or not.

Parameters
height:int

Height of binary tree.

index:long

Index to validate.

Returns:boolean

true if index is valid false else.

isNewAuthenticationPathNeededback to summary
public static boolean isNewAuthenticationPathNeeded(long globalIndex, int xmssHeight, int layer)
isNewBDSInitNeededback to summary
public static boolean isNewBDSInitNeeded(long globalIndex, int xmssHeight, int layer)
log2back to summary
public static int log2(int n)

Calculates the logarithm base 2 for a given Integer.

Parameters
n:int

Number.

Returns:int

Logarithm to base 2 of n.

longToBigEndianback to summary
public static void longToBigEndian(long value, byte[] in, int offset)
serializeback to summary
public static byte[] serialize(Object obj) throws IOException
toBytesBigEndianback to summary
public static byte[] toBytesBigEndian(long value, int sizeInByte)

Convert int/long to n-byte array.

Parameters
value:long

int/long value.

sizeInByte:int

Size of byte array in byte.

Returns:byte[]

int/long as big-endian byte array of size sizeInByte.

org.bouncycastle.pqc.crypto.xmss back to summary

private Class XMSSUtil.CheckingStream

extends ObjectInputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final Set<E>
private boolean
private final Class<T>

Constructor Summary

AccessConstructor and Description
pack-priv
CheckingStream(Class<T> mainClass, InputStream in)

Method Summary

Modifier and TypeMethod and Description
protected Class<?>
resolveClass(ObjectStreamClass
an instance of class ObjectStreamClass
desc
)

Overrides java.io.ObjectInputStream.resolveClass.

Load the local class equivalent of the specified stream class description.
Inherited from java.io.ObjectInputStream:
availableclosedefaultReadObjectenableResolveObjectgetObjectInputFilterreadreadreadBooleanreadBytereadCharreadClassDescriptorreadDoublereadFieldsreadFloatreadFullyreadFullyreadIntreadLinereadLongreadObjectreadObjectOverridereadShortreadStreamHeaderreadUnsharedreadUnsignedBytereadUnsignedShortreadUTFregisterValidationresolveObjectresolveProxyClasssetObjectInputFilterskipBytes

Field Detail

componentsback to summary
private static final Set<E> components
foundback to summary
private boolean found
mainClassback to summary
private final Class<T> mainClass

Constructor Detail

CheckingStreamback to summary
pack-priv CheckingStream(Class<T> mainClass, InputStream in) throws IOException

Method Detail

resolveClassback to summary
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException

Overrides java.io.ObjectInputStream.resolveClass.

Doc from java.io.ObjectInputStream.resolveClass.

Load the local class equivalent of the specified stream class description. Subclasses may implement this method to allow classes to be fetched from an alternate source.

The corresponding method in ObjectOutputStream is annotateClass. This method will be invoked only once for each unique class in the stream. This method can be implemented by subclasses to use an alternate loading mechanism but must return a Class object. Once returned, if the class is not an array class, its serialVersionUID is compared to the serialVersionUID of the serialized class, and if there is a mismatch, the deserialization fails and an InvalidClassException is thrown.

The default implementation of this method in ObjectInputStream returns the result of calling

Class.forName(desc.getName(), false, loader)
Class.forName(desc.getName(), false, loader)
where loader is the first class loader on the current thread's stack (starting from the currently executing method) that is neither the platform class loader nor its ancestor; otherwise, loader is the platform class loader. If this call results in a ClassNotFoundException and the name of the passed ObjectStreamClass instance is the Java language keyword for a primitive type or void, then the Class object representing that primitive type or void will be returned (e.g., an ObjectStreamClass with the name "int" will be resolved to Integer.TYPE). Otherwise, the ClassNotFoundException will be thrown to the caller of this method.
Parameters
desc:ObjectStreamClass

an instance of class ObjectStreamClass

Returns:Class<?>

a Class object corresponding to desc

Exceptions
IOException:
any of the usual Input/Output exceptions.
ClassNotFoundException:
if class of a serialized object cannot be found.