public byte[] toByteArray()
{
int n = params.getDigestSize();
int len = params.getWOTSPlus().getParams().getLen();
int indexSize = (int)Math.ceil(params.getHeight() / (double)8);
int randomSize = n;
int reducedSignatureSizeSingle = ((params.getHeight() / params.getLayers()) + len) * n;
int reducedSignaturesSizeTotal = reducedSignatureSizeSingle * params.getLayers();
int totalSize = indexSize + randomSize + reducedSignaturesSizeTotal;
byte[] out = new byte[totalSize];
int position = 0;
byte[] indexBytes = XMSSUtil.toBytesBigEndian(index, indexSize);
XMSSUtil.copyBytesAtOffset(out, indexBytes, position);
position += indexSize;
XMSSUtil.copyBytesAtOffset(out, random, position);
position += randomSize;
for (XMSSReducedSignature reducedSignature : reducedSignatures)
{
byte[] signature = reducedSignature.toByteArray();
XMSSUtil.copyBytesAtOffset(out, signature, position);
position += reducedSignatureSizeSingle;
}
return out;
}