mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-11-11 16:48:30 +00:00
提交Unity 联机Pro
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public static class AesUtilities
|
||||
{
|
||||
public static IBlockCipher CreateEngine()
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
if (AesEngine_X86.IsSupported)
|
||||
return new AesEngine_X86();
|
||||
#endif
|
||||
|
||||
return new AesEngine();
|
||||
}
|
||||
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
public static bool IsHardwareAccelerated => AesEngine_X86.IsSupported;
|
||||
#else
|
||||
public static bool IsHardwareAccelerated => false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f78dabbad81b1942bbfcb6d20af6264
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* a holding class for public/private parameter pairs.
|
||||
*/
|
||||
public class AsymmetricCipherKeyPair
|
||||
{
|
||||
private readonly AsymmetricKeyParameter publicParameter;
|
||||
private readonly AsymmetricKeyParameter privateParameter;
|
||||
|
||||
/**
|
||||
* basic constructor.
|
||||
*
|
||||
* @param publicParam a public key parameters object.
|
||||
* @param privateParam the corresponding private key parameters.
|
||||
*/
|
||||
public AsymmetricCipherKeyPair(
|
||||
AsymmetricKeyParameter publicParameter,
|
||||
AsymmetricKeyParameter privateParameter)
|
||||
{
|
||||
if (publicParameter.IsPrivate)
|
||||
throw new ArgumentException("Expected a public key", "publicParameter");
|
||||
if (!privateParameter.IsPrivate)
|
||||
throw new ArgumentException("Expected a private key", "privateParameter");
|
||||
|
||||
this.publicParameter = publicParameter;
|
||||
this.privateParameter = privateParameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the public key parameters.
|
||||
*
|
||||
* @return the public key parameters.
|
||||
*/
|
||||
public AsymmetricKeyParameter Public
|
||||
{
|
||||
get { return publicParameter; }
|
||||
}
|
||||
|
||||
/**
|
||||
* return the private key parameters.
|
||||
*
|
||||
* @return the private key parameters.
|
||||
*/
|
||||
public AsymmetricKeyParameter Private
|
||||
{
|
||||
get { return privateParameter; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eef9b100979b64f49a4f37506e85cbea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public abstract class AsymmetricKeyParameter
|
||||
: ICipherParameters
|
||||
{
|
||||
private readonly bool privateKey;
|
||||
|
||||
protected AsymmetricKeyParameter(
|
||||
bool privateKey)
|
||||
{
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
public bool IsPrivate
|
||||
{
|
||||
get { return privateKey; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
AsymmetricKeyParameter other = obj as AsymmetricKeyParameter;
|
||||
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
AsymmetricKeyParameter other)
|
||||
{
|
||||
return privateKey == other.privateKey;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return privateKey.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a345564cb9c4fb64eb3b18227bc3bc11
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,276 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Modes;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* The AEAD block ciphers already handle buffering internally, so this class
|
||||
* just takes care of implementing IBufferedCipher methods.
|
||||
*/
|
||||
public class BufferedAeadBlockCipher
|
||||
: BufferedCipherBase
|
||||
{
|
||||
private readonly IAeadBlockCipher cipher;
|
||||
|
||||
public BufferedAeadBlockCipher(
|
||||
IAeadBlockCipher cipher)
|
||||
{
|
||||
if (cipher == null)
|
||||
throw new ArgumentNullException("cipher");
|
||||
|
||||
this.cipher = cipher;
|
||||
}
|
||||
|
||||
public override string AlgorithmName
|
||||
{
|
||||
get { return cipher.AlgorithmName; }
|
||||
}
|
||||
|
||||
/**
|
||||
* initialise the cipher.
|
||||
*
|
||||
* @param forEncryption if true the cipher is initialised for
|
||||
* encryption, if false for decryption.
|
||||
* @param param the key and other data required by the cipher.
|
||||
* @exception ArgumentException if the parameters argument is
|
||||
* inappropriate.
|
||||
*/
|
||||
public override void Init(
|
||||
bool forEncryption,
|
||||
ICipherParameters parameters)
|
||||
{
|
||||
if (parameters is ParametersWithRandom)
|
||||
{
|
||||
parameters = ((ParametersWithRandom) parameters).Parameters;
|
||||
}
|
||||
|
||||
cipher.Init(forEncryption, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the blocksize for the underlying cipher.
|
||||
*
|
||||
* @return the blocksize for the underlying cipher.
|
||||
*/
|
||||
public override int GetBlockSize()
|
||||
{
|
||||
return cipher.GetBlockSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* return the size of the output buffer required for an update
|
||||
* an input of len bytes.
|
||||
*
|
||||
* @param len the length of the input.
|
||||
* @return the space required to accommodate a call to update
|
||||
* with len bytes of input.
|
||||
*/
|
||||
public override int GetUpdateOutputSize(
|
||||
int length)
|
||||
{
|
||||
return cipher.GetUpdateOutputSize(length);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the size of the output buffer required for an update plus a
|
||||
* doFinal with an input of len bytes.
|
||||
*
|
||||
* @param len the length of the input.
|
||||
* @return the space required to accommodate a call to update and doFinal
|
||||
* with len bytes of input.
|
||||
*/
|
||||
public override int GetOutputSize(
|
||||
int length)
|
||||
{
|
||||
return cipher.GetOutputSize(length);
|
||||
}
|
||||
|
||||
/**
|
||||
* process a single byte, producing an output block if necessary.
|
||||
*
|
||||
* @param in the input byte.
|
||||
* @param out the space for any output that might be produced.
|
||||
* @param outOff the offset from which the output will be copied.
|
||||
* @return the number of output bytes copied to out.
|
||||
* @exception DataLengthException if there isn't enough space in out.
|
||||
* @exception InvalidOperationException if the cipher isn't initialised.
|
||||
*/
|
||||
public override int ProcessByte(byte input, byte[] output, int outOff)
|
||||
{
|
||||
return cipher.ProcessByte(input, output, outOff);
|
||||
}
|
||||
|
||||
public override byte[] ProcessByte(
|
||||
byte input)
|
||||
{
|
||||
int outLength = GetUpdateOutputSize(1);
|
||||
|
||||
byte[] outBytes = outLength > 0 ? new byte[outLength] : null;
|
||||
|
||||
int pos = ProcessByte(input, outBytes, 0);
|
||||
|
||||
if (outLength > 0 && pos < outLength)
|
||||
{
|
||||
byte[] tmp = new byte[pos];
|
||||
Array.Copy(outBytes, 0, tmp, 0, pos);
|
||||
outBytes = tmp;
|
||||
}
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int ProcessByte(byte input, Span<byte> output)
|
||||
{
|
||||
return cipher.ProcessByte(input, output);
|
||||
}
|
||||
#endif
|
||||
|
||||
public override byte[] ProcessBytes(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
if (length < 1)
|
||||
return null;
|
||||
|
||||
int outLength = GetUpdateOutputSize(length);
|
||||
|
||||
byte[] outBytes = outLength > 0 ? new byte[outLength] : null;
|
||||
|
||||
int pos = ProcessBytes(input, inOff, length, outBytes, 0);
|
||||
|
||||
if (outLength > 0 && pos < outLength)
|
||||
{
|
||||
byte[] tmp = new byte[pos];
|
||||
Array.Copy(outBytes, 0, tmp, 0, pos);
|
||||
outBytes = tmp;
|
||||
}
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* process an array of bytes, producing output if necessary.
|
||||
*
|
||||
* @param in the input byte array.
|
||||
* @param inOff the offset at which the input data starts.
|
||||
* @param len the number of bytes to be copied out of the input array.
|
||||
* @param out the space for any output that might be produced.
|
||||
* @param outOff the offset from which the output will be copied.
|
||||
* @return the number of output bytes copied to out.
|
||||
* @exception DataLengthException if there isn't enough space in out.
|
||||
* @exception InvalidOperationException if the cipher isn't initialised.
|
||||
*/
|
||||
public override int ProcessBytes(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length,
|
||||
byte[] output,
|
||||
int outOff)
|
||||
{
|
||||
return cipher.ProcessBytes(input, inOff, length, output, outOff);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output)
|
||||
{
|
||||
return cipher.ProcessBytes(input, output);
|
||||
}
|
||||
#endif
|
||||
|
||||
public override byte[] DoFinal()
|
||||
{
|
||||
byte[] outBytes = new byte[GetOutputSize(0)];
|
||||
|
||||
int pos = DoFinal(outBytes, 0);
|
||||
|
||||
if (pos < outBytes.Length)
|
||||
{
|
||||
byte[] tmp = new byte[pos];
|
||||
Array.Copy(outBytes, 0, tmp, 0, pos);
|
||||
outBytes = tmp;
|
||||
}
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
public override byte[] DoFinal(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int inLen)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
|
||||
byte[] outBytes = new byte[GetOutputSize(inLen)];
|
||||
|
||||
int pos = (inLen > 0)
|
||||
? ProcessBytes(input, inOff, inLen, outBytes, 0)
|
||||
: 0;
|
||||
|
||||
pos += DoFinal(outBytes, pos);
|
||||
|
||||
if (pos < outBytes.Length)
|
||||
{
|
||||
byte[] tmp = new byte[pos];
|
||||
Array.Copy(outBytes, 0, tmp, 0, pos);
|
||||
outBytes = tmp;
|
||||
}
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the last block in the buffer.
|
||||
*
|
||||
* @param out the array the block currently being held is copied into.
|
||||
* @param outOff the offset at which the copying starts.
|
||||
* @return the number of output bytes copied to out.
|
||||
* @exception DataLengthException if there is insufficient space in out for
|
||||
* the output, or the input is not block size aligned and should be.
|
||||
* @exception InvalidOperationException if the underlying cipher is not
|
||||
* initialised.
|
||||
* @exception InvalidCipherTextException if padding is expected and not found.
|
||||
* @exception DataLengthException if the input is not block size
|
||||
* aligned.
|
||||
*/
|
||||
public override int DoFinal(
|
||||
byte[] output,
|
||||
int outOff)
|
||||
{
|
||||
return cipher.DoFinal(output, outOff);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int DoFinal(Span<byte> output)
|
||||
{
|
||||
return cipher.DoFinal(output);
|
||||
}
|
||||
|
||||
public override int DoFinal(ReadOnlySpan<byte> input, Span<byte> output)
|
||||
{
|
||||
int len = cipher.ProcessBytes(input, output);
|
||||
len += cipher.DoFinal(output[len..]);
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Reset the buffer and cipher. After resetting the object is in the same
|
||||
* state as it was after the last init (if there was one).
|
||||
*/
|
||||
public override void Reset()
|
||||
{
|
||||
cipher.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7341cef11d2e8f24e844590b6747bf16
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,275 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Modes;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* The AEAD ciphers already handle buffering internally, so this class
|
||||
* just takes care of implementing IBufferedCipher methods.
|
||||
*/
|
||||
public class BufferedAeadCipher
|
||||
: BufferedCipherBase
|
||||
{
|
||||
private readonly IAeadCipher cipher;
|
||||
|
||||
public BufferedAeadCipher(IAeadCipher cipher)
|
||||
{
|
||||
if (cipher == null)
|
||||
throw new ArgumentNullException("cipher");
|
||||
|
||||
this.cipher = cipher;
|
||||
}
|
||||
|
||||
public override string AlgorithmName
|
||||
{
|
||||
get { return cipher.AlgorithmName; }
|
||||
}
|
||||
|
||||
/**
|
||||
* initialise the cipher.
|
||||
*
|
||||
* @param forEncryption if true the cipher is initialised for
|
||||
* encryption, if false for decryption.
|
||||
* @param param the key and other data required by the cipher.
|
||||
* @exception ArgumentException if the parameters argument is
|
||||
* inappropriate.
|
||||
*/
|
||||
public override void Init(
|
||||
bool forEncryption,
|
||||
ICipherParameters parameters)
|
||||
{
|
||||
if (parameters is ParametersWithRandom)
|
||||
{
|
||||
parameters = ((ParametersWithRandom)parameters).Parameters;
|
||||
}
|
||||
|
||||
cipher.Init(forEncryption, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the blocksize for the underlying cipher.
|
||||
*
|
||||
* @return the blocksize for the underlying cipher.
|
||||
*/
|
||||
public override int GetBlockSize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the size of the output buffer required for an update
|
||||
* an input of len bytes.
|
||||
*
|
||||
* @param len the length of the input.
|
||||
* @return the space required to accommodate a call to update
|
||||
* with len bytes of input.
|
||||
*/
|
||||
public override int GetUpdateOutputSize(
|
||||
int length)
|
||||
{
|
||||
return cipher.GetUpdateOutputSize(length);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the size of the output buffer required for an update plus a
|
||||
* doFinal with an input of len bytes.
|
||||
*
|
||||
* @param len the length of the input.
|
||||
* @return the space required to accommodate a call to update and doFinal
|
||||
* with len bytes of input.
|
||||
*/
|
||||
public override int GetOutputSize(
|
||||
int length)
|
||||
{
|
||||
return cipher.GetOutputSize(length);
|
||||
}
|
||||
|
||||
/**
|
||||
* process a single byte, producing an output block if necessary.
|
||||
*
|
||||
* @param in the input byte.
|
||||
* @param out the space for any output that might be produced.
|
||||
* @param outOff the offset from which the output will be copied.
|
||||
* @return the number of output bytes copied to out.
|
||||
* @exception DataLengthException if there isn't enough space in out.
|
||||
* @exception InvalidOperationException if the cipher isn't initialised.
|
||||
*/
|
||||
public override int ProcessByte(byte input, byte[] output, int outOff)
|
||||
{
|
||||
return cipher.ProcessByte(input, output, outOff);
|
||||
}
|
||||
|
||||
public override byte[] ProcessByte(
|
||||
byte input)
|
||||
{
|
||||
int outLength = GetUpdateOutputSize(1);
|
||||
|
||||
byte[] outBytes = outLength > 0 ? new byte[outLength] : null;
|
||||
|
||||
int pos = ProcessByte(input, outBytes, 0);
|
||||
|
||||
if (outLength > 0 && pos < outLength)
|
||||
{
|
||||
byte[] tmp = new byte[pos];
|
||||
Array.Copy(outBytes, 0, tmp, 0, pos);
|
||||
outBytes = tmp;
|
||||
}
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int ProcessByte(byte input, Span<byte> output)
|
||||
{
|
||||
return cipher.ProcessByte(input, output);
|
||||
}
|
||||
#endif
|
||||
|
||||
public override byte[] ProcessBytes(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
if (length < 1)
|
||||
return null;
|
||||
|
||||
int outLength = GetUpdateOutputSize(length);
|
||||
|
||||
byte[] outBytes = outLength > 0 ? new byte[outLength] : null;
|
||||
|
||||
int pos = ProcessBytes(input, inOff, length, outBytes, 0);
|
||||
|
||||
if (outLength > 0 && pos < outLength)
|
||||
{
|
||||
byte[] tmp = new byte[pos];
|
||||
Array.Copy(outBytes, 0, tmp, 0, pos);
|
||||
outBytes = tmp;
|
||||
}
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* process an array of bytes, producing output if necessary.
|
||||
*
|
||||
* @param in the input byte array.
|
||||
* @param inOff the offset at which the input data starts.
|
||||
* @param len the number of bytes to be copied out of the input array.
|
||||
* @param out the space for any output that might be produced.
|
||||
* @param outOff the offset from which the output will be copied.
|
||||
* @return the number of output bytes copied to out.
|
||||
* @exception DataLengthException if there isn't enough space in out.
|
||||
* @exception InvalidOperationException if the cipher isn't initialised.
|
||||
*/
|
||||
public override int ProcessBytes(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length,
|
||||
byte[] output,
|
||||
int outOff)
|
||||
{
|
||||
return cipher.ProcessBytes(input, inOff, length, output, outOff);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output)
|
||||
{
|
||||
return cipher.ProcessBytes(input, output);
|
||||
}
|
||||
#endif
|
||||
|
||||
public override byte[] DoFinal()
|
||||
{
|
||||
byte[] outBytes = new byte[GetOutputSize(0)];
|
||||
|
||||
int pos = DoFinal(outBytes, 0);
|
||||
|
||||
if (pos < outBytes.Length)
|
||||
{
|
||||
byte[] tmp = new byte[pos];
|
||||
Array.Copy(outBytes, 0, tmp, 0, pos);
|
||||
outBytes = tmp;
|
||||
}
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
public override byte[] DoFinal(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int inLen)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
|
||||
byte[] outBytes = new byte[GetOutputSize(inLen)];
|
||||
|
||||
int pos = (inLen > 0)
|
||||
? ProcessBytes(input, inOff, inLen, outBytes, 0)
|
||||
: 0;
|
||||
|
||||
pos += DoFinal(outBytes, pos);
|
||||
|
||||
if (pos < outBytes.Length)
|
||||
{
|
||||
byte[] tmp = new byte[pos];
|
||||
Array.Copy(outBytes, 0, tmp, 0, pos);
|
||||
outBytes = tmp;
|
||||
}
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the last block in the buffer.
|
||||
*
|
||||
* @param out the array the block currently being held is copied into.
|
||||
* @param outOff the offset at which the copying starts.
|
||||
* @return the number of output bytes copied to out.
|
||||
* @exception DataLengthException if there is insufficient space in out for
|
||||
* the output, or the input is not block size aligned and should be.
|
||||
* @exception InvalidOperationException if the underlying cipher is not
|
||||
* initialised.
|
||||
* @exception InvalidCipherTextException if padding is expected and not found.
|
||||
* @exception DataLengthException if the input is not block size
|
||||
* aligned.
|
||||
*/
|
||||
public override int DoFinal(
|
||||
byte[] output,
|
||||
int outOff)
|
||||
{
|
||||
return cipher.DoFinal(output, outOff);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int DoFinal(Span<byte> output)
|
||||
{
|
||||
return cipher.DoFinal(output);
|
||||
}
|
||||
|
||||
public override int DoFinal(ReadOnlySpan<byte> input, Span<byte> output)
|
||||
{
|
||||
int len = cipher.ProcessBytes(input, output);
|
||||
len += cipher.DoFinal(output[len..]);
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Reset the buffer and cipher. After resetting the object is in the same
|
||||
* state as it was after the last init (if there was one).
|
||||
*/
|
||||
public override void Reset()
|
||||
{
|
||||
cipher.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 224bf921b8d1f70408f67fcae4aab3fe
|
||||
timeCreated: 1572510026
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,201 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* a buffer wrapper for an asymmetric block cipher, allowing input
|
||||
* to be accumulated in a piecemeal fashion until final processing.
|
||||
*/
|
||||
public class BufferedAsymmetricBlockCipher
|
||||
: BufferedCipherBase
|
||||
{
|
||||
private readonly IAsymmetricBlockCipher cipher;
|
||||
|
||||
private byte[] buffer;
|
||||
private int bufOff;
|
||||
|
||||
/**
|
||||
* base constructor.
|
||||
*
|
||||
* @param cipher the cipher this buffering object wraps.
|
||||
*/
|
||||
public BufferedAsymmetricBlockCipher(
|
||||
IAsymmetricBlockCipher cipher)
|
||||
{
|
||||
this.cipher = cipher;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the amount of data sitting in the buffer.
|
||||
*
|
||||
* @return the amount of data sitting in the buffer.
|
||||
*/
|
||||
internal int GetBufferPosition()
|
||||
{
|
||||
return bufOff;
|
||||
}
|
||||
|
||||
public override string AlgorithmName
|
||||
{
|
||||
get { return cipher.AlgorithmName; }
|
||||
}
|
||||
|
||||
public override int GetBlockSize()
|
||||
{
|
||||
return cipher.GetInputBlockSize();
|
||||
}
|
||||
|
||||
public override int GetOutputSize(
|
||||
int length)
|
||||
{
|
||||
return cipher.GetOutputBlockSize();
|
||||
}
|
||||
|
||||
public override int GetUpdateOutputSize(
|
||||
int length)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialise the buffer and the underlying cipher.
|
||||
*
|
||||
* @param forEncryption if true the cipher is initialised for
|
||||
* encryption, if false for decryption.
|
||||
* @param param the key and other data required by the cipher.
|
||||
*/
|
||||
public override void Init(
|
||||
bool forEncryption,
|
||||
ICipherParameters parameters)
|
||||
{
|
||||
Reset();
|
||||
|
||||
cipher.Init(forEncryption, parameters);
|
||||
|
||||
//
|
||||
// we allow for an extra byte where people are using their own padding
|
||||
// mechanisms on a raw cipher.
|
||||
//
|
||||
this.buffer = new byte[cipher.GetInputBlockSize() + (forEncryption ? 1 : 0)];
|
||||
this.bufOff = 0;
|
||||
}
|
||||
|
||||
public override byte[] ProcessByte(
|
||||
byte input)
|
||||
{
|
||||
if (bufOff >= buffer.Length)
|
||||
throw new DataLengthException("attempt to process message too long for cipher");
|
||||
|
||||
buffer[bufOff++] = input;
|
||||
return null;
|
||||
}
|
||||
|
||||
public override int ProcessByte(byte input, byte[] output, int outOff)
|
||||
{
|
||||
if (bufOff >= buffer.Length)
|
||||
throw new DataLengthException("attempt to process message too long for cipher");
|
||||
|
||||
buffer[bufOff++] = input;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int ProcessByte(byte input, Span<byte> output)
|
||||
{
|
||||
if (bufOff >= buffer.Length)
|
||||
throw new DataLengthException("attempt to process message too long for cipher");
|
||||
|
||||
buffer[bufOff++] = input;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override byte[] ProcessBytes(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length)
|
||||
{
|
||||
if (length < 1)
|
||||
return null;
|
||||
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
if (bufOff + length > buffer.Length)
|
||||
throw new DataLengthException("attempt to process message too long for cipher");
|
||||
|
||||
Array.Copy(input, inOff, buffer, bufOff, length);
|
||||
bufOff += length;
|
||||
return null;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output)
|
||||
{
|
||||
Check.DataLength(input, buffer.Length - bufOff, "attempt to process message too long for cipher");
|
||||
|
||||
input.CopyTo(buffer.AsSpan(bufOff));
|
||||
bufOff += input.Length;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* process the contents of the buffer using the underlying
|
||||
* cipher.
|
||||
*
|
||||
* @return the result of the encryption/decryption process on the
|
||||
* buffer.
|
||||
* @exception InvalidCipherTextException if we are given a garbage block.
|
||||
*/
|
||||
public override byte[] DoFinal()
|
||||
{
|
||||
byte[] outBytes = bufOff > 0
|
||||
? cipher.ProcessBlock(buffer, 0, bufOff)
|
||||
: EmptyBuffer;
|
||||
|
||||
Reset();
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
public override byte[] DoFinal(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length)
|
||||
{
|
||||
ProcessBytes(input, inOff, length);
|
||||
return DoFinal();
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int DoFinal(Span<byte> output)
|
||||
{
|
||||
int result = 0;
|
||||
if (bufOff > 0)
|
||||
{
|
||||
byte[] outBytes = cipher.ProcessBlock(buffer, 0, bufOff);
|
||||
outBytes.CopyTo(output);
|
||||
result = outBytes.Length;
|
||||
}
|
||||
|
||||
Reset();
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>Reset the buffer</summary>
|
||||
public override void Reset()
|
||||
{
|
||||
if (buffer != null)
|
||||
{
|
||||
Array.Clear(buffer, 0, buffer.Length);
|
||||
bufOff = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f143b86b595928a4ba2e043ae553d1ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,425 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Modes;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* A wrapper class that allows block ciphers to be used to process data in
|
||||
* a piecemeal fashion. The BufferedBlockCipher outputs a block only when the
|
||||
* buffer is full and more data is being added, or on a doFinal.
|
||||
* <p>
|
||||
* Note: in the case where the underlying cipher is either a CFB cipher or an
|
||||
* OFB one the last block may not be a multiple of the block size.
|
||||
* </p>
|
||||
*/
|
||||
public class BufferedBlockCipher
|
||||
: BufferedCipherBase
|
||||
{
|
||||
internal byte[] buf;
|
||||
internal int bufOff;
|
||||
internal bool forEncryption;
|
||||
internal IBlockCipherMode m_cipherMode;
|
||||
|
||||
/**
|
||||
* constructor for subclasses
|
||||
*/
|
||||
protected BufferedBlockCipher()
|
||||
{
|
||||
}
|
||||
|
||||
public BufferedBlockCipher(IBlockCipher cipher)
|
||||
: this(EcbBlockCipher.GetBlockCipherMode(cipher))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a buffered block cipher without padding.
|
||||
*
|
||||
* @param cipher the underlying block cipher this buffering object wraps.
|
||||
* false otherwise.
|
||||
*/
|
||||
public BufferedBlockCipher(IBlockCipherMode cipherMode)
|
||||
{
|
||||
if (cipherMode == null)
|
||||
throw new ArgumentNullException(nameof(cipherMode));
|
||||
|
||||
m_cipherMode = cipherMode;
|
||||
buf = new byte[cipherMode.GetBlockSize()];
|
||||
bufOff = 0;
|
||||
}
|
||||
|
||||
public override string AlgorithmName
|
||||
{
|
||||
get { return m_cipherMode.AlgorithmName; }
|
||||
}
|
||||
|
||||
/**
|
||||
* initialise the cipher.
|
||||
*
|
||||
* @param forEncryption if true the cipher is initialised for
|
||||
* encryption, if false for decryption.
|
||||
* @param param the key and other data required by the cipher.
|
||||
* @exception ArgumentException if the parameters argument is
|
||||
* inappropriate.
|
||||
*/
|
||||
// Note: This doubles as the Init in the event that this cipher is being used as an IWrapper
|
||||
public override void Init(bool forEncryption, ICipherParameters parameters)
|
||||
{
|
||||
this.forEncryption = forEncryption;
|
||||
|
||||
if (parameters is ParametersWithRandom withRandom)
|
||||
{
|
||||
parameters = withRandom.Parameters;
|
||||
}
|
||||
|
||||
Reset();
|
||||
|
||||
m_cipherMode.Init(forEncryption, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the blocksize for the underlying cipher.
|
||||
*
|
||||
* @return the blocksize for the underlying cipher.
|
||||
*/
|
||||
public override int GetBlockSize()
|
||||
{
|
||||
return m_cipherMode.GetBlockSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* return the size of the output buffer required for an update
|
||||
* an input of len bytes.
|
||||
*
|
||||
* @param len the length of the input.
|
||||
* @return the space required to accommodate a call to update
|
||||
* with len bytes of input.
|
||||
*/
|
||||
public override int GetUpdateOutputSize(int length)
|
||||
{
|
||||
int total = length + bufOff;
|
||||
int leftOver = total % buf.Length;
|
||||
return total - leftOver;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the size of the output buffer required for an update plus a
|
||||
* doFinal with an input of len bytes.
|
||||
*
|
||||
* @param len the length of the input.
|
||||
* @return the space required to accommodate a call to update and doFinal
|
||||
* with len bytes of input.
|
||||
*/
|
||||
public override int GetOutputSize(int length)
|
||||
{
|
||||
// Note: Can assume IsPartialBlockOkay is true for purposes of this calculation
|
||||
return length + bufOff;
|
||||
}
|
||||
|
||||
/**
|
||||
* process a single byte, producing an output block if necessary.
|
||||
*
|
||||
* @param in the input byte.
|
||||
* @param out the space for any output that might be produced.
|
||||
* @param outOff the offset from which the output will be copied.
|
||||
* @return the number of output bytes copied to out.
|
||||
* @exception DataLengthException if there isn't enough space in out.
|
||||
* @exception InvalidOperationException if the cipher isn't initialised.
|
||||
*/
|
||||
public override int ProcessByte(byte input, byte[] output, int outOff)
|
||||
{
|
||||
buf[bufOff++] = input;
|
||||
|
||||
if (bufOff == buf.Length)
|
||||
{
|
||||
if ((outOff + buf.Length) > output.Length)
|
||||
throw new DataLengthException("output buffer too short");
|
||||
|
||||
bufOff = 0;
|
||||
return m_cipherMode.ProcessBlock(buf, 0, output, outOff);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override byte[] ProcessByte(byte input)
|
||||
{
|
||||
int outLength = GetUpdateOutputSize(1);
|
||||
|
||||
byte[] outBytes = outLength > 0 ? new byte[outLength] : null;
|
||||
|
||||
int pos = ProcessByte(input, outBytes, 0);
|
||||
|
||||
if (outLength > 0 && pos < outLength)
|
||||
{
|
||||
byte[] tmp = new byte[pos];
|
||||
Array.Copy(outBytes, 0, tmp, 0, pos);
|
||||
outBytes = tmp;
|
||||
}
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int ProcessByte(byte input, Span<byte> output)
|
||||
{
|
||||
buf[bufOff++] = input;
|
||||
|
||||
if (bufOff == buf.Length)
|
||||
{
|
||||
Check.OutputLength(output, buf.Length, "output buffer too short");
|
||||
|
||||
bufOff = 0;
|
||||
return m_cipherMode.ProcessBlock(buf, output);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override byte[] ProcessBytes(byte[] input, int inOff, int length)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
if (length < 1)
|
||||
return null;
|
||||
|
||||
int outLength = GetUpdateOutputSize(length);
|
||||
|
||||
byte[] outBytes = outLength > 0 ? new byte[outLength] : null;
|
||||
|
||||
int pos = ProcessBytes(input, inOff, length, outBytes, 0);
|
||||
|
||||
if (outLength > 0 && pos < outLength)
|
||||
{
|
||||
byte[] tmp = new byte[pos];
|
||||
Array.Copy(outBytes, 0, tmp, 0, pos);
|
||||
outBytes = tmp;
|
||||
}
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* process an array of bytes, producing output if necessary.
|
||||
*
|
||||
* @param in the input byte array.
|
||||
* @param inOff the offset at which the input data starts.
|
||||
* @param len the number of bytes to be copied out of the input array.
|
||||
* @param out the space for any output that might be produced.
|
||||
* @param outOff the offset from which the output will be copied.
|
||||
* @return the number of output bytes copied to out.
|
||||
* @exception DataLengthException if there isn't enough space in out.
|
||||
* @exception InvalidOperationException if the cipher isn't initialised.
|
||||
*/
|
||||
public override int ProcessBytes(byte[] input, int inOff, int length, byte[] output, int outOff)
|
||||
{
|
||||
if (length < 1)
|
||||
{
|
||||
if (length < 0)
|
||||
throw new ArgumentException("Can't have a negative input length!");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int blockSize = GetBlockSize();
|
||||
int outLength = GetUpdateOutputSize(length);
|
||||
|
||||
if (outLength > 0)
|
||||
{
|
||||
Check.OutputLength(output, outOff, outLength, "output buffer too short");
|
||||
}
|
||||
|
||||
int resultLen = 0;
|
||||
int gapLen = buf.Length - bufOff;
|
||||
if (length >= gapLen)
|
||||
{
|
||||
Array.Copy(input, inOff, buf, bufOff, gapLen);
|
||||
resultLen = m_cipherMode.ProcessBlock(buf, 0, output, outOff);
|
||||
bufOff = 0;
|
||||
length -= gapLen;
|
||||
inOff += gapLen;
|
||||
while (length >= buf.Length)
|
||||
{
|
||||
resultLen += m_cipherMode.ProcessBlock(input, inOff, output, outOff + resultLen);
|
||||
length -= blockSize;
|
||||
inOff += blockSize;
|
||||
}
|
||||
}
|
||||
Array.Copy(input, inOff, buf, bufOff, length);
|
||||
bufOff += length;
|
||||
return resultLen;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output)
|
||||
{
|
||||
if (input.IsEmpty)
|
||||
return 0;
|
||||
|
||||
int blockSize = GetBlockSize();
|
||||
int outLength = GetUpdateOutputSize(input.Length);
|
||||
|
||||
if (outLength > 0)
|
||||
{
|
||||
Check.OutputLength(output, outLength, "output buffer too short");
|
||||
}
|
||||
|
||||
int resultLen = 0;
|
||||
int gapLen = buf.Length - bufOff;
|
||||
if (input.Length >= gapLen)
|
||||
{
|
||||
input[..gapLen].CopyTo(buf.AsSpan(bufOff));
|
||||
resultLen = m_cipherMode.ProcessBlock(buf, output);
|
||||
bufOff = 0;
|
||||
input = input[gapLen..];
|
||||
while (input.Length >= buf.Length)
|
||||
{
|
||||
resultLen += m_cipherMode.ProcessBlock(input, output[resultLen..]);
|
||||
input = input[blockSize..];
|
||||
}
|
||||
}
|
||||
input.CopyTo(buf.AsSpan(bufOff));
|
||||
bufOff += input.Length;
|
||||
return resultLen;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override byte[] DoFinal()
|
||||
{
|
||||
byte[] outBytes = EmptyBuffer;
|
||||
|
||||
int length = GetOutputSize(0);
|
||||
if (length > 0)
|
||||
{
|
||||
outBytes = new byte[length];
|
||||
|
||||
int pos = DoFinal(outBytes, 0);
|
||||
if (pos < outBytes.Length)
|
||||
{
|
||||
byte[] tmp = new byte[pos];
|
||||
Array.Copy(outBytes, 0, tmp, 0, pos);
|
||||
outBytes = tmp;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
public override byte[] DoFinal(byte[] input, int inOff, int inLen)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
|
||||
int length = GetOutputSize(inLen);
|
||||
|
||||
byte[] outBytes = EmptyBuffer;
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
outBytes = new byte[length];
|
||||
|
||||
int pos = (inLen > 0)
|
||||
? ProcessBytes(input, inOff, inLen, outBytes, 0)
|
||||
: 0;
|
||||
|
||||
pos += DoFinal(outBytes, pos);
|
||||
|
||||
if (pos < outBytes.Length)
|
||||
{
|
||||
byte[] tmp = new byte[pos];
|
||||
Array.Copy(outBytes, 0, tmp, 0, pos);
|
||||
outBytes = tmp;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
return outBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the last block in the buffer.
|
||||
*
|
||||
* @param out the array the block currently being held is copied into.
|
||||
* @param outOff the offset at which the copying starts.
|
||||
* @return the number of output bytes copied to out.
|
||||
* @exception DataLengthException if there is insufficient space in out for
|
||||
* the output, or the input is not block size aligned and should be.
|
||||
* @exception InvalidOperationException if the underlying cipher is not
|
||||
* initialised.
|
||||
* @exception InvalidCipherTextException if padding is expected and not found.
|
||||
* @exception DataLengthException if the input is not block size
|
||||
* aligned.
|
||||
*/
|
||||
public override int DoFinal(byte[] output, int outOff)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (bufOff != 0)
|
||||
{
|
||||
Check.DataLength(!m_cipherMode.IsPartialBlockOkay, "data not block size aligned");
|
||||
Check.OutputLength(output, outOff, bufOff, "output buffer too short for DoFinal()");
|
||||
|
||||
// NB: Can't copy directly, or we may write too much output
|
||||
m_cipherMode.ProcessBlock(buf, 0, buf, 0);
|
||||
Array.Copy(buf, 0, output, outOff, bufOff);
|
||||
}
|
||||
|
||||
return bufOff;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int DoFinal(Span<byte> output)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (bufOff != 0)
|
||||
{
|
||||
Check.DataLength(!m_cipherMode.IsPartialBlockOkay, "data not block size aligned");
|
||||
Check.OutputLength(output, bufOff, "output buffer too short for DoFinal()");
|
||||
|
||||
// NB: Can't copy directly, or we may write too much output
|
||||
m_cipherMode.ProcessBlock(buf, buf);
|
||||
buf.AsSpan(0, bufOff).CopyTo(output);
|
||||
}
|
||||
|
||||
return bufOff;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Reset the buffer and cipher. After resetting the object is in the same
|
||||
* state as it was after the last init (if there was one).
|
||||
*/
|
||||
public override void Reset()
|
||||
{
|
||||
Array.Clear(buf, 0, buf.Length);
|
||||
bufOff = 0;
|
||||
|
||||
m_cipherMode.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e161ee652f7d84c49abc183b5ef37846
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,136 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public abstract class BufferedCipherBase
|
||||
: IBufferedCipher
|
||||
{
|
||||
protected static readonly byte[] EmptyBuffer = new byte[0];
|
||||
|
||||
public abstract string AlgorithmName { get; }
|
||||
|
||||
public abstract void Init(bool forEncryption, ICipherParameters parameters);
|
||||
|
||||
public abstract int GetBlockSize();
|
||||
|
||||
public abstract int GetOutputSize(int inputLen);
|
||||
public abstract int GetUpdateOutputSize(int inputLen);
|
||||
|
||||
public abstract byte[] ProcessByte(byte input);
|
||||
|
||||
public virtual int ProcessByte(
|
||||
byte input,
|
||||
byte[] output,
|
||||
int outOff)
|
||||
{
|
||||
byte[] outBytes = ProcessByte(input);
|
||||
if (outBytes == null)
|
||||
return 0;
|
||||
if (outOff + outBytes.Length > output.Length)
|
||||
throw new DataLengthException("output buffer too short");
|
||||
outBytes.CopyTo(output, outOff);
|
||||
return outBytes.Length;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public abstract int ProcessByte(byte input, Span<byte> output);
|
||||
#endif
|
||||
|
||||
public virtual byte[] ProcessBytes(
|
||||
byte[] input)
|
||||
{
|
||||
return ProcessBytes(input, 0, input.Length);
|
||||
}
|
||||
|
||||
public abstract byte[] ProcessBytes(byte[] input, int inOff, int length);
|
||||
|
||||
public virtual int ProcessBytes(
|
||||
byte[] input,
|
||||
byte[] output,
|
||||
int outOff)
|
||||
{
|
||||
return ProcessBytes(input, 0, input.Length, output, outOff);
|
||||
}
|
||||
|
||||
public virtual int ProcessBytes(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length,
|
||||
byte[] output,
|
||||
int outOff)
|
||||
{
|
||||
byte[] outBytes = ProcessBytes(input, inOff, length);
|
||||
if (outBytes == null)
|
||||
return 0;
|
||||
if (outOff + outBytes.Length > output.Length)
|
||||
throw new DataLengthException("output buffer too short");
|
||||
outBytes.CopyTo(output, outOff);
|
||||
return outBytes.Length;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public abstract int ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output);
|
||||
#endif
|
||||
|
||||
public abstract byte[] DoFinal();
|
||||
|
||||
public virtual byte[] DoFinal(
|
||||
byte[] input)
|
||||
{
|
||||
return DoFinal(input, 0, input.Length);
|
||||
}
|
||||
|
||||
public abstract byte[] DoFinal(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length);
|
||||
|
||||
public virtual int DoFinal(
|
||||
byte[] output,
|
||||
int outOff)
|
||||
{
|
||||
byte[] outBytes = DoFinal();
|
||||
if (outOff + outBytes.Length > output.Length)
|
||||
throw new DataLengthException("output buffer too short");
|
||||
outBytes.CopyTo(output, outOff);
|
||||
return outBytes.Length;
|
||||
}
|
||||
|
||||
public virtual int DoFinal(
|
||||
byte[] input,
|
||||
byte[] output,
|
||||
int outOff)
|
||||
{
|
||||
return DoFinal(input, 0, input.Length, output, outOff);
|
||||
}
|
||||
|
||||
public virtual int DoFinal(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length,
|
||||
byte[] output,
|
||||
int outOff)
|
||||
{
|
||||
int len = ProcessBytes(input, inOff, length, output, outOff);
|
||||
len += DoFinal(output, outOff + len);
|
||||
return len;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public abstract int DoFinal(Span<byte> output);
|
||||
|
||||
public virtual int DoFinal(ReadOnlySpan<byte> input, Span<byte> output)
|
||||
{
|
||||
int len = ProcessBytes(input, output);
|
||||
len += DoFinal(output[len..]);
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
public abstract void Reset();
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c014e96623bd48488c402407e71df96
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,149 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public class BufferedIesCipher
|
||||
: BufferedCipherBase
|
||||
{
|
||||
private readonly IesEngine engine;
|
||||
private bool forEncryption;
|
||||
private MemoryStream buffer = new MemoryStream();
|
||||
|
||||
public BufferedIesCipher(
|
||||
IesEngine engine)
|
||||
{
|
||||
if (engine == null)
|
||||
throw new ArgumentNullException("engine");
|
||||
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
public override string AlgorithmName
|
||||
{
|
||||
// TODO Create IESEngine.AlgorithmName
|
||||
get { return "IES"; }
|
||||
}
|
||||
|
||||
public override void Init(
|
||||
bool forEncryption,
|
||||
ICipherParameters parameters)
|
||||
{
|
||||
this.forEncryption = forEncryption;
|
||||
|
||||
// TODO
|
||||
throw new NotImplementedException("IES");
|
||||
}
|
||||
|
||||
public override int GetBlockSize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override int GetOutputSize(
|
||||
int inputLen)
|
||||
{
|
||||
if (engine == null)
|
||||
throw new InvalidOperationException("cipher not initialised");
|
||||
|
||||
int baseLen = inputLen + Convert.ToInt32(buffer.Length);
|
||||
return forEncryption
|
||||
? baseLen + 20
|
||||
: baseLen - 20;
|
||||
}
|
||||
|
||||
public override int GetUpdateOutputSize(
|
||||
int inputLen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override byte[] ProcessByte(byte input)
|
||||
{
|
||||
buffer.WriteByte(input);
|
||||
return null;
|
||||
}
|
||||
|
||||
public override int ProcessByte(byte input, byte[] output, int outOff)
|
||||
{
|
||||
buffer.WriteByte(input);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int ProcessByte(byte input, Span<byte> output)
|
||||
{
|
||||
buffer.WriteByte(input);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override byte[] ProcessBytes(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("input");
|
||||
if (inOff < 0)
|
||||
throw new ArgumentException("inOff");
|
||||
if (length < 0)
|
||||
throw new ArgumentException("length");
|
||||
if (inOff + length > input.Length)
|
||||
throw new ArgumentException("invalid offset/length specified for input array");
|
||||
|
||||
buffer.Write(input, inOff, length);
|
||||
return null;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output)
|
||||
{
|
||||
buffer.Write(input);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override byte[] DoFinal()
|
||||
{
|
||||
byte[] buf = buffer.ToArray();
|
||||
|
||||
Reset();
|
||||
|
||||
return engine.ProcessBlock(buf, 0, buf.Length);
|
||||
}
|
||||
|
||||
public override byte[] DoFinal(
|
||||
byte[] input,
|
||||
int inOff,
|
||||
int length)
|
||||
{
|
||||
ProcessBytes(input, inOff, length);
|
||||
return DoFinal();
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int DoFinal(Span<byte> output)
|
||||
{
|
||||
byte[] buf = buffer.ToArray();
|
||||
|
||||
Reset();
|
||||
|
||||
byte[] block = engine.ProcessBlock(buf, 0, buf.Length);
|
||||
block.CopyTo(output);
|
||||
return block.Length;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
buffer.SetLength(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b73c34a06bcbdb3449c9b9221fc8a9c2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,141 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public class BufferedStreamCipher
|
||||
: BufferedCipherBase
|
||||
{
|
||||
private readonly IStreamCipher m_cipher;
|
||||
|
||||
public BufferedStreamCipher(IStreamCipher cipher)
|
||||
{
|
||||
if (cipher == null)
|
||||
throw new ArgumentNullException("cipher");
|
||||
|
||||
this.m_cipher = cipher;
|
||||
}
|
||||
|
||||
public override string AlgorithmName
|
||||
{
|
||||
get { return m_cipher.AlgorithmName; }
|
||||
}
|
||||
|
||||
public override void Init(bool forEncryption, ICipherParameters parameters)
|
||||
{
|
||||
if (parameters is ParametersWithRandom withRandom)
|
||||
{
|
||||
parameters = withRandom.Parameters;
|
||||
}
|
||||
|
||||
m_cipher.Init(forEncryption, parameters);
|
||||
}
|
||||
|
||||
public override int GetBlockSize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override int GetOutputSize(int inputLen)
|
||||
{
|
||||
return inputLen;
|
||||
}
|
||||
|
||||
public override int GetUpdateOutputSize(int inputLen)
|
||||
{
|
||||
return inputLen;
|
||||
}
|
||||
|
||||
public override byte[] ProcessByte(byte input)
|
||||
{
|
||||
return new byte[]{ m_cipher.ReturnByte(input) };
|
||||
}
|
||||
|
||||
public override int ProcessByte(byte input, byte[] output, int outOff)
|
||||
{
|
||||
if (outOff >= output.Length)
|
||||
throw new DataLengthException("output buffer too short");
|
||||
|
||||
output[outOff] = m_cipher.ReturnByte(input);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int ProcessByte(byte input, Span<byte> output)
|
||||
{
|
||||
output[0] = m_cipher.ReturnByte(input);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override byte[] ProcessBytes(byte[] input, int inOff, int length)
|
||||
{
|
||||
if (length < 1)
|
||||
return null;
|
||||
|
||||
byte[] output = new byte[length];
|
||||
m_cipher.ProcessBytes(input, inOff, length, output, 0);
|
||||
return output;
|
||||
}
|
||||
|
||||
public override int ProcessBytes(byte[] input, int inOff, int length, byte[] output, int outOff)
|
||||
{
|
||||
if (length < 1)
|
||||
return 0;
|
||||
|
||||
m_cipher.ProcessBytes(input, inOff, length, output, outOff);
|
||||
return length;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output)
|
||||
{
|
||||
m_cipher.ProcessBytes(input, output);
|
||||
return input.Length;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override byte[] DoFinal()
|
||||
{
|
||||
m_cipher.Reset();
|
||||
|
||||
return EmptyBuffer;
|
||||
}
|
||||
|
||||
public override byte[] DoFinal(byte[] input, int inOff, int length)
|
||||
{
|
||||
if (length < 1)
|
||||
return EmptyBuffer;
|
||||
|
||||
byte[] output = new byte[length];
|
||||
m_cipher.ProcessBytes(input, inOff, length, output, 0);
|
||||
m_cipher.Reset();
|
||||
return output;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
public override int DoFinal(Span<byte> output)
|
||||
{
|
||||
m_cipher.Reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override int DoFinal(ReadOnlySpan<byte> input, Span<byte> output)
|
||||
{
|
||||
m_cipher.ProcessBytes(input, output);
|
||||
m_cipher.Reset();
|
||||
return input.Length;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
m_cipher.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f552bd4118a37e46b3c3e8b94df1660
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,43 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
internal class Check
|
||||
{
|
||||
internal static void DataLength(bool condition, string msg)
|
||||
{
|
||||
if (condition)
|
||||
throw new DataLengthException(msg);
|
||||
}
|
||||
|
||||
internal static void DataLength(byte[] buf, int off, int len, string msg)
|
||||
{
|
||||
if (off > (buf.Length - len))
|
||||
throw new DataLengthException(msg);
|
||||
}
|
||||
|
||||
internal static void OutputLength(byte[] buf, int off, int len, string msg)
|
||||
{
|
||||
if (off > (buf.Length - len))
|
||||
throw new OutputLengthException(msg);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
internal static void DataLength(ReadOnlySpan<byte> input, int len, string msg)
|
||||
{
|
||||
if (input.Length < len)
|
||||
throw new DataLengthException(msg);
|
||||
}
|
||||
|
||||
internal static void OutputLength(Span<byte> output, int len, string msg)
|
||||
{
|
||||
if (output.Length < len)
|
||||
throw new OutputLengthException(msg);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6dd41045620467949adfc127f66c0e85
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,85 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* The base class for symmetric, or secret, cipher key generators.
|
||||
*/
|
||||
public class CipherKeyGenerator
|
||||
{
|
||||
protected internal SecureRandom random;
|
||||
protected internal int strength;
|
||||
private bool uninitialised = true;
|
||||
private int defaultStrength;
|
||||
|
||||
public CipherKeyGenerator()
|
||||
{
|
||||
}
|
||||
|
||||
internal CipherKeyGenerator(
|
||||
int defaultStrength)
|
||||
{
|
||||
if (defaultStrength < 1)
|
||||
throw new ArgumentException("strength must be a positive value", "defaultStrength");
|
||||
|
||||
this.defaultStrength = defaultStrength;
|
||||
}
|
||||
|
||||
public int DefaultStrength
|
||||
{
|
||||
get { return defaultStrength; }
|
||||
}
|
||||
|
||||
/**
|
||||
* initialise the key generator.
|
||||
*
|
||||
* @param param the parameters to be used for key generation
|
||||
*/
|
||||
public void Init(KeyGenerationParameters parameters)
|
||||
{
|
||||
if (parameters == null)
|
||||
throw new ArgumentNullException(nameof(parameters));
|
||||
|
||||
this.uninitialised = false;
|
||||
|
||||
EngineInit(parameters);
|
||||
}
|
||||
|
||||
protected virtual void EngineInit(KeyGenerationParameters parameters)
|
||||
{
|
||||
this.random = parameters.Random;
|
||||
this.strength = (parameters.Strength + 7) / 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a secret key.
|
||||
*
|
||||
* @return a byte array containing the key value.
|
||||
*/
|
||||
public byte[] GenerateKey()
|
||||
{
|
||||
if (uninitialised)
|
||||
{
|
||||
if (defaultStrength < 1)
|
||||
throw new InvalidOperationException("Generator has not been initialised");
|
||||
|
||||
uninitialised = false;
|
||||
|
||||
EngineInit(new KeyGenerationParameters(CryptoServicesRegistrar.GetSecureRandom(), defaultStrength));
|
||||
}
|
||||
|
||||
return EngineGenerateKey();
|
||||
}
|
||||
|
||||
protected virtual byte[] EngineGenerateKey()
|
||||
{
|
||||
return SecureRandom.GetNextBytes(random, strength);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83b99673c89b7be4491f695d8e374d3c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
[Serializable]
|
||||
public class CryptoException
|
||||
: Exception
|
||||
{
|
||||
public CryptoException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public CryptoException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public CryptoException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected CryptoException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd38a0fa65d30fc4eae48fa3319f9645
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public static class CryptoServicesRegistrar
|
||||
{
|
||||
public static SecureRandom GetSecureRandom()
|
||||
{
|
||||
return new SecureRandom();
|
||||
}
|
||||
|
||||
public static SecureRandom GetSecureRandom(SecureRandom secureRandom)
|
||||
{
|
||||
return secureRandom ?? new SecureRandom();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5080aaa8a1b6a3a45a17cd1781379690
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,39 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>This exception is thrown if a buffer that is meant to have output copied into it turns out to be too
|
||||
/// short, or if we've been given insufficient input.</summary>
|
||||
/// <remarks>
|
||||
/// In general this exception will get thrown rather than an <see cref="IndexOutOfRangeException"/>.
|
||||
/// </remarks>
|
||||
[Serializable]
|
||||
public class DataLengthException
|
||||
: CryptoException
|
||||
{
|
||||
public DataLengthException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public DataLengthException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public DataLengthException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected DataLengthException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34a508389e47f4745921ea8106b00645
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* Base interface for mapping from an alphabet to a set of indexes
|
||||
* suitable for use with FPE.
|
||||
*/
|
||||
public interface IAlphabetMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the number of characters in the alphabet.
|
||||
/// </summary>
|
||||
/// <returns>the radix for the alphabet.</returns>
|
||||
int Radix { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Return the passed in char[] as a byte array of indexes (indexes
|
||||
/// can be more than 1 byte)
|
||||
/// </summary>
|
||||
/// <returns>an index array.</returns>
|
||||
/// <param name="input">characters to be mapped.</param>
|
||||
byte[] ConvertToIndexes(char[] input);
|
||||
|
||||
/// <summary>
|
||||
/// Return a char[] for this alphabet based on the indexes passed.
|
||||
/// </summary>
|
||||
/// <returns>an array of char corresponding to the index values.</returns>
|
||||
/// <param name="input">input array of indexes.</param>
|
||||
char[] ConvertToChars(byte[] input);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fffa4712c5e427e4bb35b79edb26841d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <remarks>Base interface for a public/private key block cipher.</remarks>
|
||||
public interface IAsymmetricBlockCipher
|
||||
{
|
||||
/// <summary>The name of the algorithm this cipher implements.</summary>
|
||||
string AlgorithmName { get; }
|
||||
|
||||
/// <summary>Initialise the cipher.</summary>
|
||||
/// <param name="forEncryption">Initialise for encryption if true, for decryption if false.</param>
|
||||
/// <param name="parameters">The key or other data required by the cipher.</param>
|
||||
void Init(bool forEncryption, ICipherParameters parameters);
|
||||
|
||||
/// <returns>The maximum size, in bytes, an input block may be.</returns>
|
||||
int GetInputBlockSize();
|
||||
|
||||
/// <returns>The maximum size, in bytes, an output block will be.</returns>
|
||||
int GetOutputBlockSize();
|
||||
|
||||
/// <summary>Process a block.</summary>
|
||||
/// <param name="inBuf">The input buffer.</param>
|
||||
/// <param name="inOff">The offset into <paramref>inBuf</paramref> that the input block begins.</param>
|
||||
/// <param name="inLen">The length of the input block.</param>
|
||||
/// <exception cref="InvalidCipherTextException">Input decrypts improperly.</exception>
|
||||
/// <exception cref="DataLengthException">Input is too large for the cipher.</exception>
|
||||
byte[] ProcessBlock(byte[] inBuf, int inOff, int inLen);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6abbe02392e03f543a957ac413172bd3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* interface that a public/private key pair generator should conform to.
|
||||
*/
|
||||
public interface IAsymmetricCipherKeyPairGenerator
|
||||
{
|
||||
/**
|
||||
* intialise the key pair generator.
|
||||
*
|
||||
* @param the parameters the key pair is to be initialised with.
|
||||
*/
|
||||
void Init(KeyGenerationParameters parameters);
|
||||
|
||||
/**
|
||||
* return an AsymmetricCipherKeyPair containing the Generated keys.
|
||||
*
|
||||
* @return an AsymmetricCipherKeyPair containing the Generated keys.
|
||||
*/
|
||||
AsymmetricCipherKeyPair GenerateKeyPair();
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af1fbd88542b90240bb580ea2247b4cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* The basic interface that basic Diffie-Hellman implementations
|
||||
* conforms to.
|
||||
*/
|
||||
public interface IBasicAgreement
|
||||
{
|
||||
/**
|
||||
* initialise the agreement engine.
|
||||
*/
|
||||
void Init(ICipherParameters parameters);
|
||||
|
||||
/**
|
||||
* return the field size for the agreement algorithm in bytes.
|
||||
*/
|
||||
int GetFieldSize();
|
||||
|
||||
/**
|
||||
* given a public key from a given party calculate the next
|
||||
* message in the agreement sequence.
|
||||
*/
|
||||
BigInteger CalculateAgreement(ICipherParameters pubKey);
|
||||
}
|
||||
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd9d504c0c209eb4ab0ba46c3f015a85
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <remarks>Base interface for a symmetric key block cipher.</remarks>
|
||||
public interface IBlockCipher
|
||||
{
|
||||
/// <summary>The name of the algorithm this cipher implements.</summary>
|
||||
string AlgorithmName { get; }
|
||||
|
||||
/// <summary>Initialise the cipher.</summary>
|
||||
/// <param name="forEncryption">Initialise for encryption if true, for decryption if false.</param>
|
||||
/// <param name="parameters">The key or other data required by the cipher.</param>
|
||||
void Init(bool forEncryption, ICipherParameters parameters);
|
||||
|
||||
/// <returns>The block size for this cipher, in bytes.</returns>
|
||||
int GetBlockSize();
|
||||
|
||||
/// <summary>Process a block.</summary>
|
||||
/// <param name="inBuf">The input buffer.</param>
|
||||
/// <param name="inOff">The offset into <paramref>inBuf</paramref> that the input block begins.</param>
|
||||
/// <param name="outBuf">The output buffer.</param>
|
||||
/// <param name="outOff">The offset into <paramref>outBuf</paramref> to write the output block.</param>
|
||||
/// <exception cref="DataLengthException">If input block is wrong size, or outBuf too small.</exception>
|
||||
/// <returns>The number of bytes processed and produced.</returns>
|
||||
int ProcessBlock(byte[] inBuf, int inOff, byte[] outBuf, int outOff);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
|
||||
/// <summary>Process a block.</summary>
|
||||
/// <param name="input">The input block as a span.</param>
|
||||
/// <param name="output">The output span.</param>
|
||||
/// <exception cref="DataLengthException">If input block is wrong size, or output span too small.</exception>
|
||||
/// <returns>The number of bytes processed and produced.</returns>
|
||||
int ProcessBlock(ReadOnlySpan<byte> input, Span<byte> output);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4935d5699e88bf6459028d927973e8af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Operators that reduce their input to a single block return an object
|
||||
/// of this type.
|
||||
/// </summary>
|
||||
public interface IBlockResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the final result of the operation.
|
||||
/// </summary>
|
||||
/// <returns>A block of bytes, representing the result of an operation.</returns>
|
||||
byte[] Collect();
|
||||
|
||||
/// <summary>
|
||||
/// Store the final result of the operation by copying it into the destination array.
|
||||
/// </summary>
|
||||
/// <returns>The number of bytes copied into destination.</returns>
|
||||
/// <param name="destination">The byte array to copy the result into.</param>
|
||||
/// <param name="offset">The offset into destination to start copying the result at.</param>
|
||||
int Collect(byte[] destination, int offset);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
/// <summary>
|
||||
/// Store the final result of the operation by copying it into the destination span.
|
||||
/// </summary>
|
||||
/// <returns>The number of bytes copied into destination.</returns>
|
||||
/// <param name="destination">The span to copy the result into.</param>
|
||||
int Collect(Span<byte> destination);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ffde966c8f3b9c4282b23834e282a0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,61 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <remarks>Block cipher engines are expected to conform to this interface.</remarks>
|
||||
public interface IBufferedCipher
|
||||
{
|
||||
/// <summary>The name of the algorithm this cipher implements.</summary>
|
||||
string AlgorithmName { get; }
|
||||
|
||||
/// <summary>Initialise the cipher.</summary>
|
||||
/// <param name="forEncryption">If true the cipher is initialised for encryption,
|
||||
/// if false for decryption.</param>
|
||||
/// <param name="parameters">The key and other data required by the cipher.</param>
|
||||
void Init(bool forEncryption, ICipherParameters parameters);
|
||||
|
||||
int GetBlockSize();
|
||||
|
||||
int GetOutputSize(int inputLen);
|
||||
|
||||
int GetUpdateOutputSize(int inputLen);
|
||||
|
||||
byte[] ProcessByte(byte input);
|
||||
int ProcessByte(byte input, byte[] output, int outOff);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
int ProcessByte(byte input, Span<byte> output);
|
||||
#endif
|
||||
|
||||
byte[] ProcessBytes(byte[] input);
|
||||
byte[] ProcessBytes(byte[] input, int inOff, int length);
|
||||
int ProcessBytes(byte[] input, byte[] output, int outOff);
|
||||
int ProcessBytes(byte[] input, int inOff, int length, byte[] output, int outOff);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
int ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output);
|
||||
#endif
|
||||
|
||||
byte[] DoFinal();
|
||||
byte[] DoFinal(byte[] input);
|
||||
byte[] DoFinal(byte[] input, int inOff, int length);
|
||||
int DoFinal(byte[] output, int outOff);
|
||||
int DoFinal(byte[] input, byte[] output, int outOff);
|
||||
int DoFinal(byte[] input, int inOff, int length, byte[] output, int outOff);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
int DoFinal(Span<byte> output);
|
||||
int DoFinal(ReadOnlySpan<byte> input, Span<byte> output);
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Reset the cipher. After resetting the cipher is in the same state
|
||||
/// as it was after the last init (if there was one).
|
||||
/// </summary>
|
||||
void Reset();
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8a92034d413bfc40b6680d876d7f8b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Base interface for a ciphers that do not require data to be block aligned.
|
||||
/// <para>
|
||||
/// Note: In cases where the underlying algorithm is block based, these ciphers may add or remove padding as needed.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public interface ICipher
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the size of the output buffer required for a Write() plus a
|
||||
/// close() with the write() being passed inputLen bytes.
|
||||
/// <para>
|
||||
/// The returned size may be dependent on the initialisation of this cipher
|
||||
/// and may not be accurate once subsequent input data is processed as the cipher may
|
||||
/// add, add or remove padding, as it sees fit.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <returns>The space required to accommodate a call to processBytes and doFinal with inputLen bytes of input.</returns>
|
||||
/// <param name="inputLen">The length of the expected input.</param>
|
||||
int GetMaxOutputSize(int inputLen);
|
||||
|
||||
/// <summary>
|
||||
/// Return the size of the output buffer required for a write() with the write() being
|
||||
/// passed inputLen bytes and just updating the cipher output.
|
||||
/// </summary>
|
||||
/// <returns>The space required to accommodate a call to processBytes with inputLen bytes of input.</returns>
|
||||
/// <param name="inputLen">The length of the expected input.</param>
|
||||
int GetUpdateOutputSize(int inputLen);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the stream for reading/writing data processed/to be processed.
|
||||
/// </summary>
|
||||
/// <value>The stream associated with this cipher.</value>
|
||||
Stream Stream { get; }
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86285cf95551c6e4fb416662bd5c0d13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Base interface for cipher builders.
|
||||
/// </summary>
|
||||
public interface ICipherBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the algorithm and parameter details associated with any cipher built.
|
||||
/// </summary>
|
||||
object AlgorithmDetails { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Return the maximum output size that a given input will produce.
|
||||
/// </summary>
|
||||
/// <param name="inputLen">the length of the expected input.</param>
|
||||
/// <returns>The maximum possible output size that can produced for the expected input length.</returns>
|
||||
int GetMaxOutputSize(int inputLen);
|
||||
|
||||
/// <summary>
|
||||
/// Build a cipher that operates on the passed in stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream to write/read any encrypted/decrypted data.</param>
|
||||
/// <returns>A cipher based around the given stream.</returns>
|
||||
ICipher BuildCipher(Stream stream);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6f3dfacdfa050844888d634d386017f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// A cipher builder that can also return the key it was initialized with.
|
||||
/// </summary>
|
||||
public interface ICipherBuilderWithKey
|
||||
: ICipherBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the key we were initialized with.
|
||||
/// </summary>
|
||||
ICipherParameters Key { get; }
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 951828338ca8a174890e28050ae2f02a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* all parameter classes implement this.
|
||||
*/
|
||||
public interface ICipherParameters
|
||||
{
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48f7fda0d1eff294e9c36d8da4c5b237
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>Interface for classes implementing the Digital Signature Algorithm</summary>
|
||||
public interface IDsa
|
||||
{
|
||||
/// <summary>The algorithm name.</summary>
|
||||
string AlgorithmName { get; }
|
||||
|
||||
/// <summary>Initialise the signer for signature generation or signature verification.</summary>
|
||||
/// <param name="forSigning">true if we are generating a signature, false otherwise.</param>
|
||||
/// <param name="parameters">key parameters for signature generation.</param>
|
||||
void Init(bool forSigning, ICipherParameters parameters);
|
||||
|
||||
/// <summary>Sign the passed in message (usually the output of a hash function).</summary>
|
||||
/// <param name="message">the message to be signed.</param>
|
||||
/// <returns>two big integers representing the r and s values respectively.</returns>
|
||||
BigInteger[] GenerateSignature(byte[] message);
|
||||
|
||||
/// <summary>The order of the group that the r, s values in signatures belong to.</summary>
|
||||
BigInteger Order { get; }
|
||||
|
||||
/// <summary>Verify the message message against the signature values r and s.</summary>
|
||||
/// <param name="message">the message that was supposed to have been signed.</param>
|
||||
/// <param name="r">the r signature value.</param>
|
||||
/// <param name="s">the s signature value.</param>
|
||||
bool VerifySignature(byte[] message, BigInteger r, BigInteger s);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8cc954fc8fc070a45955c5a315ebc07a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface describing a provider of cipher builders for creating decrypting ciphers.
|
||||
/// </summary>
|
||||
public interface IDecryptorBuilderProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Return a cipher builder for creating decrypting ciphers.
|
||||
/// </summary>
|
||||
/// <param name="algorithmDetails">The algorithm details/parameters to use to create the final cipher.</param>
|
||||
/// <returns>A new cipher builder.</returns>
|
||||
ICipherBuilder CreateDecryptorBuilder(object algorithmDetails);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37600e3f2022147409b8c5c4f9e253a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* base interface for general purpose byte derivation functions.
|
||||
*/
|
||||
public interface IDerivationFunction
|
||||
{
|
||||
void Init(IDerivationParameters parameters);
|
||||
|
||||
/**
|
||||
* return the message digest used as the basis for the function
|
||||
*/
|
||||
IDigest Digest { get; }
|
||||
|
||||
int GenerateBytes(byte[] output, int outOff, int length);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
int GenerateBytes(Span<byte> output);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4485e5cea1db5dc4ebed2d30a3bfa672
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* Parameters for key/byte stream derivation classes
|
||||
*/
|
||||
public interface IDerivationParameters
|
||||
{
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea9b134ee70b91b42b1ad2b5bf68204c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <remarks>Base interface for a message digest.</remarks>
|
||||
public interface IDigest
|
||||
{
|
||||
/// <summary>The algorithm name.</summary>
|
||||
string AlgorithmName { get; }
|
||||
|
||||
/// <summary>Return the size, in bytes, of the digest produced by this message digest.</summary>
|
||||
/// <returns>the size, in bytes, of the digest produced by this message digest.</returns>
|
||||
int GetDigestSize();
|
||||
|
||||
/// <summary>Return the size, in bytes, of the internal buffer used by this digest.</summary>
|
||||
/// <returns>the size, in bytes, of the internal buffer used by this digest.</returns>
|
||||
int GetByteLength();
|
||||
|
||||
/// <summary>Update the message digest with a single byte.</summary>
|
||||
/// <param name="input">the input byte to be entered.</param>
|
||||
void Update(byte input);
|
||||
|
||||
/// <summary>Update the message digest with a block of bytes.</summary>
|
||||
/// <param name="input">the byte array containing the data.</param>
|
||||
/// <param name="inOff">the offset into the byte array where the data starts.</param>
|
||||
/// <param name="inLen">the length of the data.</param>
|
||||
void BlockUpdate(byte[] input, int inOff, int inLen);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
/// <summary>Update the message digest with a span of bytes.</summary>
|
||||
/// <param name="input">the span containing the data.</param>
|
||||
void BlockUpdate(ReadOnlySpan<byte> input);
|
||||
#endif
|
||||
|
||||
/// <summary>Close the digest, producing the final digest value.</summary>
|
||||
/// <remarks>This call leaves the digest reset.</remarks>
|
||||
/// <param name="output">the byte array the digest is to be copied into.</param>
|
||||
/// <param name="outOff">the offset into the byte array the digest is to start at.</param>
|
||||
/// <returns>the number of bytes written</returns>
|
||||
int DoFinal(byte[] output, int outOff);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
/// <summary>Close the digest, producing the final digest value.</summary>
|
||||
/// <remarks>This call leaves the digest reset.</remarks>
|
||||
/// <param name="output">the span the digest is to be copied into.</param>
|
||||
/// <returns>the number of bytes written</returns>
|
||||
int DoFinal(Span<byte> output);
|
||||
#endif
|
||||
|
||||
/// <summary>Reset the digest back to its initial state.</summary>
|
||||
void Reset();
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 232948e340c96d0439b8c002b2ab0ec9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Base interface for operator factories that create stream-based digest calculators.
|
||||
/// </summary>
|
||||
public interface IDigestFactory
|
||||
{
|
||||
/// <summary>The algorithm details object for calculators made by this factory.</summary>
|
||||
object AlgorithmDetails { get ; }
|
||||
|
||||
/// <summary>Return the size of the digest associated with this factory.</summary>
|
||||
/// <returns>The length of the digest produced by this calculators from this factory in bytes.</returns>
|
||||
int DigestLength { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a stream calculator for the digest associated with this factory. The stream
|
||||
/// calculator is used for the actual operation of entering the data to be digested
|
||||
/// and producing the digest block.
|
||||
/// </summary>
|
||||
/// <returns>A calculator producing an IBlockResult with the final digest in it.</returns>
|
||||
IStreamCalculator<IBlockResult> CreateCalculator();
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95298a0892f290144b5f75892ba62990
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public interface IEncapsulatedSecretExtractor
|
||||
{
|
||||
/// <summary>
|
||||
/// Generate an exchange pair based on the recipient public key.
|
||||
/// </summary>
|
||||
/// <param name="encapsulation"> the encapsulated secret.</param>
|
||||
byte[] ExtractSecret(byte[] encapsulation);
|
||||
|
||||
/// <summary>
|
||||
/// The length in bytes of the encapsulation.
|
||||
/// </summary>
|
||||
int EncapsulationLength { get; }
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d43d7edf40e958546bc77bcb9954e1f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public interface IEncapsulatedSecretGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Generate an exchange pair based on the recipient public key.
|
||||
/// </summary>
|
||||
/// <param name="recipientKey"></param>
|
||||
/// <returns> An SecretWithEncapsulation derived from the recipient public key.</returns>
|
||||
ISecretWithEncapsulation GenerateEncapsulated(AsymmetricKeyParameter recipientKey);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 642c0e33a85937744af2d35b54685f2c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Base interface describing an entropy source for a DRBG.
|
||||
/// </summary>
|
||||
public interface IEntropySource
|
||||
{
|
||||
/// <summary>
|
||||
/// Return whether or not this entropy source is regarded as prediction resistant.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is prediction resistant; otherwise, <c>false</c>.</value>
|
||||
bool IsPredictionResistant { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Return a byte array of entropy.
|
||||
/// </summary>
|
||||
/// <returns>The entropy bytes.</returns>
|
||||
byte[] GetEntropy();
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
int GetEntropy(Span<byte> output);
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Return the number of bits of entropy this source can produce.
|
||||
/// </summary>
|
||||
/// <value>The size, in bits, of the return value of getEntropy.</value>
|
||||
int EntropySize { get; }
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b41ded217d64e9d4a88e5a4f45785906
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Base interface describing a provider of entropy sources.
|
||||
/// </summary>
|
||||
public interface IEntropySourceProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Return an entropy source providing a block of entropy.
|
||||
/// </summary>
|
||||
/// <param name="bitsRequired">The size of the block of entropy required.</param>
|
||||
/// <returns>An entropy source providing bitsRequired blocks of entropy.</returns>
|
||||
IEntropySource Get(int bitsRequired);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4e94522d8beb6942a87bb520c8bcbe1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Base interface for a key unwrapper.
|
||||
/// </summary>
|
||||
public interface IKeyUnwrapper
|
||||
{
|
||||
/// <summary>
|
||||
/// The parameter set used to configure this key unwrapper.
|
||||
/// </summary>
|
||||
object AlgorithmDetails { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Unwrap the passed in data.
|
||||
/// </summary>
|
||||
/// <param name="cipherText">The array containing the data to be unwrapped.</param>
|
||||
/// <param name="offset">The offset into cipherText at which the unwrapped data starts.</param>
|
||||
/// <param name="length">The length of the data to be unwrapped.</param>
|
||||
/// <returns>an IBlockResult containing the unwrapped key data.</returns>
|
||||
IBlockResult Unwrap(byte[] cipherText, int offset, int length);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e650368ca96964e438ca612547183b5a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Base interface for a key wrapper.
|
||||
/// </summary>
|
||||
public interface IKeyWrapper
|
||||
{
|
||||
/// <summary>
|
||||
/// The parameter set used to configure this key wrapper.
|
||||
/// </summary>
|
||||
object AlgorithmDetails { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Wrap the passed in key data.
|
||||
/// </summary>
|
||||
/// <param name="keyData">The key data to be wrapped.</param>
|
||||
/// <returns>an IBlockResult containing the wrapped key data.</returns>
|
||||
IBlockResult Wrap(byte[] keyData);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08485454896e80b4fb1b674205285bca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>The base interface for implementations of message authentication codes (MACs).</summary>
|
||||
public interface IMac
|
||||
{
|
||||
/// <summary>Initialise the MAC.</summary>
|
||||
/// <param name="parameters">The key or other data required by the MAC.</param>
|
||||
void Init(ICipherParameters parameters);
|
||||
|
||||
/// <summary>The algorithm name.</summary>
|
||||
string AlgorithmName { get; }
|
||||
|
||||
/// <summary>Return the size, in bytes, of the MAC produced by this implementation.</summary>
|
||||
/// <returns>the size, in bytes, of the MAC produced by this implementation.</returns>
|
||||
int GetMacSize();
|
||||
|
||||
/// <summary>Update the MAC with a single byte.</summary>
|
||||
/// <param name="input">the input byte to be entered.</param>
|
||||
void Update(byte input);
|
||||
|
||||
/// <summary>Update the MAC with a block of bytes.</summary>
|
||||
/// <param name="input">the byte array containing the data.</param>
|
||||
/// <param name="inOff">the offset into the byte array where the data starts.</param>
|
||||
/// <param name="inLen">the length of the data.</param>
|
||||
void BlockUpdate(byte[] input, int inOff, int inLen);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
/// <summary>Update the MAC with a span of bytes.</summary>
|
||||
/// <param name="input">the span containing the data.</param>
|
||||
void BlockUpdate(ReadOnlySpan<byte> input);
|
||||
#endif
|
||||
|
||||
/// <summary>Perform final calculations, producing the result MAC.</summary>
|
||||
/// <remarks>This call leaves the MAC reset.</remarks>
|
||||
/// <param name="output">the byte array the MAC is to be copied into.</param>
|
||||
/// <param name="outOff">the offset into the byte array the MAC is to start at.</param>
|
||||
/// <returns>the number of bytes written</returns>
|
||||
int DoFinal(byte[] output, int outOff);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
/// <summary>Perform final calculations, producing the result MAC.</summary>
|
||||
/// <remarks>This call leaves the MAC reset.</remarks>
|
||||
/// <param name="output">the span the MAC is to be copied into.</param>
|
||||
/// <returns>the number of bytes written</returns>
|
||||
int DoFinal(Span<byte> output);
|
||||
#endif
|
||||
|
||||
/// <summary>Reset the MAC back to its initial state.</summary>
|
||||
void Reset();
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06c6c4ff752285d4181fc6f0f7a3bbc1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public interface IMacDerivationFunction
|
||||
: IDerivationFunction
|
||||
{
|
||||
IMac Mac { get; }
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d231b65c9f54dec40a0309d3face6e5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public interface IMacFactory
|
||||
{
|
||||
/// <summary>The algorithm details object for this calculator.</summary>
|
||||
object AlgorithmDetails { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a stream calculator for this signature calculator. The stream
|
||||
/// calculator is used for the actual operation of entering the data to be signed
|
||||
/// and producing the signature block.
|
||||
/// </summary>
|
||||
/// <returns>A calculator producing an IBlockResult with a signature in it.</returns>
|
||||
IStreamCalculator<IBlockResult> CreateCalculator();
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74bbe413ab66ee84e966ede17712327a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public interface IRawAgreement
|
||||
{
|
||||
void Init(ICipherParameters parameters);
|
||||
|
||||
int AgreementSize { get; }
|
||||
|
||||
void CalculateAgreement(ICipherParameters publicKey, byte[] buf, int off);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
void CalculateAgreement(ICipherParameters publicKey, Span<byte> output);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4955c6838f252e4cba62fb0ee5dc679
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public interface IRsa
|
||||
{
|
||||
void Init(bool forEncryption, ICipherParameters parameters);
|
||||
int GetInputBlockSize();
|
||||
int GetOutputBlockSize();
|
||||
BigInteger ConvertInput(byte[] buf, int off, int len);
|
||||
BigInteger ProcessBlock(BigInteger input);
|
||||
byte[] ConvertOutput(BigInteger result);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfae5f5df323ffa4d878ad34f7914052
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public interface ISecretWithEncapsulation
|
||||
: IDisposable
|
||||
{
|
||||
|
||||
///<summary>
|
||||
/// Return the secret associated with the encapsulation.
|
||||
/// </summary>
|
||||
/// <returns> the secret the encapsulation is for.</returns>
|
||||
byte[] GetSecret();
|
||||
|
||||
/// <summary>
|
||||
/// Return the data that carries the secret in its encapsulated form.
|
||||
/// </summary>
|
||||
/// <returns> the encapsulation of the secret.</returns>
|
||||
byte[] GetEncapsulation();
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3160d4314f9a00f41823ce0d5bf32ea4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Base interface for operators that serve as stream-based signature calculators.
|
||||
/// </summary>
|
||||
public interface ISignatureFactory
|
||||
{
|
||||
/// <summary>The algorithm details object for this calculator.</summary>
|
||||
object AlgorithmDetails { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a stream calculator for this signature calculator. The stream
|
||||
/// calculator is used for the actual operation of entering the data to be signed
|
||||
/// and producing the signature block.
|
||||
/// </summary>
|
||||
/// <returns>A calculator producing an IBlockResult with a signature in it.</returns>
|
||||
IStreamCalculator<IBlockResult> CreateCalculator();
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b932d94d8fe22545b8c91109d2bf521
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
public interface ISigner
|
||||
{
|
||||
/// <summary>The algorithm name.</summary>
|
||||
string AlgorithmName { get; }
|
||||
|
||||
/// <summary>Initialise the signer for signing or verification.</summary>
|
||||
/// <param name="forSigning">true if for signing, false otherwise.</param>
|
||||
/// <param name="parameters">necessary parameters.</param>
|
||||
void Init(bool forSigning, ICipherParameters parameters);
|
||||
|
||||
/// <summary>Update the signer with a single byte.</summary>
|
||||
/// <param name="input">the input byte to be entered.</param>
|
||||
void Update(byte input);
|
||||
|
||||
/// <summary>Update the signer with a block of bytes.</summary>
|
||||
/// <param name="input">the byte array containing the data.</param>
|
||||
/// <param name="inOff">the offset into the byte array where the data starts.</param>
|
||||
/// <param name="inLen">the length of the data.</param>
|
||||
void BlockUpdate(byte[] input, int inOff, int inLen);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
/// <summary>Update the signer with a span of bytes.</summary>
|
||||
/// <param name="input">the span containing the data.</param>
|
||||
void BlockUpdate(ReadOnlySpan<byte> input);
|
||||
#endif
|
||||
|
||||
/// <summary>Generate a signature for the message we've been loaded with using the key we were initialised with.
|
||||
/// </summary>
|
||||
/// <returns>A byte array containing the signature for the message.</returns>
|
||||
byte[] GenerateSignature();
|
||||
|
||||
/// <summary>Return true if the internal state represents the signature described in the passed in array.
|
||||
/// </summary>
|
||||
/// <param name="signature">an array containing the candidate signature to verify.</param>
|
||||
/// <returns>true if the internal state represents the signature described in the passed in array.</returns>
|
||||
bool VerifySignature(byte[] signature);
|
||||
|
||||
/// <summary>Reset the signer back to its initial state.</summary>
|
||||
void Reset();
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3bcb10b760d17945bfcb44c2b23d5a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/**
|
||||
* Signer with message recovery.
|
||||
*/
|
||||
public interface ISignerWithRecovery
|
||||
: ISigner
|
||||
{
|
||||
/**
|
||||
* Returns true if the signer has recovered the full message as
|
||||
* part of signature verification.
|
||||
*
|
||||
* @return true if full message recovered.
|
||||
*/
|
||||
bool HasFullMessage();
|
||||
|
||||
/**
|
||||
* Returns a reference to what message was recovered (if any).
|
||||
*
|
||||
* @return full/partial message, null if nothing.
|
||||
*/
|
||||
byte[] GetRecoveredMessage();
|
||||
|
||||
/**
|
||||
* Perform an update with the recovered message before adding any other data. This must
|
||||
* be the first update method called, and calling it will result in the signer assuming
|
||||
* that further calls to update will include message content past what is recoverable.
|
||||
*
|
||||
* @param signature the signature that we are in the process of verifying.
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
void UpdateWithRecoveredMessage(byte[] signature);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e65905090a3ed6d4d8a088adeef895f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System.IO;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Base interface for cryptographic operations such as Hashes, MACs, and Signatures which reduce a stream of data
|
||||
/// to a single value.
|
||||
/// </summary>
|
||||
public interface IStreamCalculator<out TResult>
|
||||
{
|
||||
/// <summary>Return a "sink" stream which only exists to update the implementing object.</summary>
|
||||
/// <returns>A stream to write to in order to update the implementing object.</returns>
|
||||
Stream Stream { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Return the result of processing the stream. This value is only available once the stream
|
||||
/// has been closed.
|
||||
/// </summary>
|
||||
/// <returns>The result of processing the stream.</returns>
|
||||
TResult GetResult();
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71c66ead22110194abc4b7138f2fa247
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>The interface stream ciphers conform to.</summary>
|
||||
public interface IStreamCipher
|
||||
{
|
||||
/// <summary>The name of the algorithm this cipher implements.</summary>
|
||||
string AlgorithmName { get; }
|
||||
|
||||
/// <summary>Initialise the cipher.</summary>
|
||||
/// <param name="forEncryption">If true the cipher is initialised for encryption,
|
||||
/// if false for decryption.</param>
|
||||
/// <param name="parameters">The key and other data required by the cipher.</param>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// If the parameters argument is inappropriate.
|
||||
/// </exception>
|
||||
void Init(bool forEncryption, ICipherParameters parameters);
|
||||
|
||||
/// <summary>encrypt/decrypt a single byte returning the result.</summary>
|
||||
/// <param name="input">the byte to be processed.</param>
|
||||
/// <returns>the result of processing the input byte.</returns>
|
||||
byte ReturnByte(byte input);
|
||||
|
||||
/// <summary>
|
||||
/// Process a block of bytes from <paramref name="input"/>, putting the result into <paramref name="output"/>.
|
||||
/// </summary>
|
||||
/// <param name="input">The input byte array.</param>
|
||||
/// <param name="inOff">
|
||||
/// The offset into <c>input</c> where the data to be processed starts.
|
||||
/// </param>
|
||||
/// <param name="length">The number of bytes to be processed.</param>
|
||||
/// <param name="output">The output buffer the processed bytes go into.</param>
|
||||
/// <param name="outOff">
|
||||
/// The offset into <c>output</c> the processed data starts at.
|
||||
/// </param>
|
||||
/// <exception cref="DataLengthException">If the input buffer is too small.</exception>
|
||||
/// <exception cref="OutputLengthException">If the output buffer is too small.</exception>
|
||||
void ProcessBytes(byte[] input, int inOff, int length, byte[] output, int outOff);
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
|
||||
/// <summary>
|
||||
/// Process a block of bytes from <paramref name="input"/>, putting the result into <paramref name="output"/>.
|
||||
/// </summary>
|
||||
/// <param name="input">The input span.</param>
|
||||
/// <param name="output">The output span.</param>
|
||||
/// <exception cref="OutputLengthException">If the output span is too small.</exception>
|
||||
void ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output);
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Reset the cipher to the same state as it was after the last init (if there was one).
|
||||
/// </summary>
|
||||
void Reset();
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef95f78d58f8f2848a0600acae2dbde9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Operators that reduce their input to the validation of a signature produce this type.
|
||||
/// </summary>
|
||||
public interface IVerifier
|
||||
{
|
||||
/// <summary>
|
||||
/// Return true if the passed in data matches what is expected by the verification result.
|
||||
/// </summary>
|
||||
/// <param name="data">The bytes representing the signature.</param>
|
||||
/// <returns>true if the signature verifies, false otherwise.</returns>
|
||||
bool IsVerified(byte[] data);
|
||||
|
||||
/// <summary>
|
||||
/// Return true if the length bytes from off in the source array match the signature
|
||||
/// expected by the verification result.
|
||||
/// </summary>
|
||||
/// <param name="source">Byte array containing the signature.</param>
|
||||
/// <param name="off">The offset into the source array where the signature starts.</param>
|
||||
/// <param name="length">The number of bytes in source making up the signature.</param>
|
||||
/// <returns>true if the signature verifies, false otherwise.</returns>
|
||||
bool IsVerified(byte[] source, int off, int length);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9b2937c1d75e3a4a853544b58c02a98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user