LMOtsSignature
using Org.BouncyCastle.Utilities;
using Org.BouncyCastle.Utilities.IO;
using System;
using System.IO;
namespace Org.BouncyCastle.Pqc.Crypto.Lms
{
public sealed class LMOtsSignature : IEncodable
{
private readonly LMOtsParameters m_paramType;
private readonly byte[] m_C;
private readonly byte[] m_y;
public LMOtsParameters ParamType => m_paramType;
[Obsolete("Use 'GetC' instead")]
public byte[] C {
get {
return m_C;
}
}
[Obsolete("Use 'GetY' instead")]
public byte[] Y {
get {
return m_y;
}
}
public LMOtsSignature(LMOtsParameters paramType, byte[] c, byte[] y)
{
m_paramType = paramType;
m_C = c;
m_y = y;
}
public static LMOtsSignature GetInstance(object src)
{
LMOtsSignature lMOtsSignature = src as LMOtsSignature;
if (lMOtsSignature != null)
return lMOtsSignature;
BinaryReader binaryReader = src as BinaryReader;
if (binaryReader != null)
return Parse(binaryReader);
Stream stream = src as Stream;
if (stream != null)
return BinaryReaders.Parse(Parse, stream, true);
byte[] array = src as byte[];
if (array != null)
return BinaryReaders.Parse(Parse, new MemoryStream(array, false), false);
throw new ArgumentException($"""{src}");
}
internal static LMOtsSignature Parse(BinaryReader binaryReader)
{
LMOtsParameters parametersByID = LMOtsParameters.GetParametersByID(BinaryReaders.ReadInt32BigEndian(binaryReader));
byte[] c = BinaryReaders.ReadBytesFully(binaryReader, parametersByID.N);
byte[] y = BinaryReaders.ReadBytesFully(binaryReader, parametersByID.P * parametersByID.N);
return new LMOtsSignature(parametersByID, c, y);
}
public byte[] GetC()
{
return Arrays.Clone(m_C);
}
public byte[] GetY()
{
return Arrays.Clone(m_y);
}
public override bool Equals(object obj)
{
if (this == obj)
return true;
LMOtsSignature lMOtsSignature = obj as LMOtsSignature;
if (lMOtsSignature == null)
return false;
if (object.Equals(m_paramType, lMOtsSignature.m_paramType) && Arrays.AreEqual(m_C, lMOtsSignature.m_C))
return Arrays.AreEqual(m_y, lMOtsSignature.m_y);
return false;
}
public override int GetHashCode()
{
int hashCode = Objects.GetHashCode(m_paramType);
hashCode = 31 * hashCode + Arrays.GetHashCode(m_C);
return 31 * hashCode + Arrays.GetHashCode(m_y);
}
public byte[] GetEncoded()
{
return Composer.Compose().U32Str(m_paramType.ID).Bytes(m_C)
.Bytes(m_y)
.Build();
}
}
}