#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Macs
{
///
/// Implementation of the Skein parameterised MAC function in 256, 512 and 1024 bit block sizes,
/// based on the Threefish tweakable block cipher.
///
///
/// This is the 1.3 version of Skein defined in the Skein hash function submission to the NIST SHA-3
/// competition in October 2010.
///
/// Skein was designed by Niels Ferguson - Stefan Lucks - Bruce Schneier - Doug Whiting - Mihir
/// Bellare - Tadayoshi Kohno - Jon Callas - Jesse Walker.
///
///
///
public class SkeinMac
: IMac
{
///
/// 256 bit block size - Skein-256
///
public const int SKEIN_256 = SkeinEngine.SKEIN_256;
///
/// 512 bit block size - Skein-512
///
public const int SKEIN_512 = SkeinEngine.SKEIN_512;
///
/// 1024 bit block size - Skein-1024
///
public const int SKEIN_1024 = SkeinEngine.SKEIN_1024;
private readonly SkeinEngine engine;
///
/// Constructs a Skein MAC with an internal state size and output size.
///
/// the internal state size in bits - one of or
/// .
/// the output/MAC size to produce in bits, which must be an integral number of
/// bytes.
public SkeinMac(int stateSizeBits, int digestSizeBits)
{
this.engine = new SkeinEngine(stateSizeBits, digestSizeBits);
}
public SkeinMac(SkeinMac mac)
{
this.engine = new SkeinEngine(mac.engine);
}
public string AlgorithmName
{
get { return "Skein-MAC-" + (engine.BlockSize * 8) + "-" + (engine.OutputSize * 8); }
}
///
/// Optionally initialises the Skein digest with the provided parameters.
///
/// See for details on the parameterisation of the Skein hash function.
/// the parameters to apply to this engine, or null
to use no parameters.
public void Init(ICipherParameters parameters)
{
SkeinParameters skeinParameters;
if (parameters is SkeinParameters)
{
skeinParameters = (SkeinParameters)parameters;
}
else if (parameters is KeyParameter)
{
skeinParameters = new SkeinParameters.Builder().SetKey(((KeyParameter)parameters).GetKey()).Build();
}
else
{
throw new ArgumentException("Invalid parameter passed to Skein MAC init - "
+ BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(parameters));
}
if (skeinParameters.GetKey() == null)
{
throw new ArgumentException("Skein MAC requires a key parameter.");
}
engine.Init(skeinParameters);
}
public int GetMacSize()
{
return engine.OutputSize;
}
public void Reset()
{
engine.Reset();
}
public void Update(byte inByte)
{
engine.Update(inByte);
}
public void BlockUpdate(byte[] input, int inOff, int len)
{
engine.Update(input, inOff, len);
}
public int DoFinal(byte[] output, int outOff)
{
return engine.DoFinal(output, outOff);
}
}
}
#pragma warning restore
#endif