add all
This commit is contained in:
69
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/AEADParameters.cs
vendored
Normal file
69
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/AEADParameters.cs
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class AeadParameters
|
||||
: ICipherParameters
|
||||
{
|
||||
private readonly byte[] associatedText;
|
||||
private readonly byte[] nonce;
|
||||
private readonly KeyParameter key;
|
||||
private readonly int macSize;
|
||||
|
||||
/**
|
||||
* Base constructor.
|
||||
*
|
||||
* @param key key to be used by underlying cipher
|
||||
* @param macSize macSize in bits
|
||||
* @param nonce nonce to be used
|
||||
*/
|
||||
public AeadParameters(KeyParameter key, int macSize, byte[] nonce)
|
||||
: this(key, macSize, nonce, null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Base constructor.
|
||||
*
|
||||
* @param key key to be used by underlying cipher
|
||||
* @param macSize macSize in bits
|
||||
* @param nonce nonce to be used
|
||||
* @param associatedText associated text, if any
|
||||
*/
|
||||
public AeadParameters(
|
||||
KeyParameter key,
|
||||
int macSize,
|
||||
byte[] nonce,
|
||||
byte[] associatedText)
|
||||
{
|
||||
this.key = key;
|
||||
this.nonce = nonce;
|
||||
this.macSize = macSize;
|
||||
this.associatedText = associatedText;
|
||||
}
|
||||
|
||||
public virtual KeyParameter Key
|
||||
{
|
||||
get { return key; }
|
||||
}
|
||||
|
||||
public virtual int MacSize
|
||||
{
|
||||
get { return macSize; }
|
||||
}
|
||||
|
||||
public virtual byte[] GetAssociatedText()
|
||||
{
|
||||
return associatedText;
|
||||
}
|
||||
|
||||
public virtual byte[] GetNonce()
|
||||
{
|
||||
return nonce;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02ea42e19df577c44977d97e7ae26c23
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
/// <summary>Blake3 Parameters.</summary>
|
||||
public sealed class Blake3Parameters
|
||||
: ICipherParameters
|
||||
{
|
||||
private const int KeyLen = 32;
|
||||
|
||||
private byte[] m_theKey;
|
||||
private byte[] m_theContext;
|
||||
|
||||
/// <summary>Create a key parameter.</summary>
|
||||
/// <param name="pContext">the context</param>
|
||||
/// <returns>the parameter</returns>
|
||||
public static Blake3Parameters Context(byte[] pContext)
|
||||
{
|
||||
if (pContext == null)
|
||||
throw new ArgumentNullException(nameof(pContext));
|
||||
|
||||
Blake3Parameters myParams = new Blake3Parameters();
|
||||
myParams.m_theContext = Arrays.Clone(pContext);
|
||||
return myParams;
|
||||
}
|
||||
|
||||
/// <summary>Create a key parameter.</summary>
|
||||
/// <param name="pKey">the key</param>
|
||||
/// <returns>the parameter</returns>
|
||||
public static Blake3Parameters Key(byte[] pKey)
|
||||
{
|
||||
if (pKey == null)
|
||||
throw new ArgumentNullException(nameof(pKey));
|
||||
if (pKey.Length != KeyLen)
|
||||
throw new ArgumentException("Invalid key length", nameof(pKey));
|
||||
|
||||
Blake3Parameters myParams = new Blake3Parameters();
|
||||
myParams.m_theKey = Arrays.Clone(pKey);
|
||||
return myParams;
|
||||
}
|
||||
|
||||
/// <summary>Obtain the key.</summary>
|
||||
/// <returns>the key</returns>
|
||||
public byte[] GetKey() => Arrays.Clone(m_theKey);
|
||||
|
||||
/// <summary>Clear the key bytes.</summary>
|
||||
public void ClearKey()
|
||||
{
|
||||
Arrays.Fill(m_theKey, 0);
|
||||
}
|
||||
|
||||
/// <summary>Obtain the salt.</summary>
|
||||
/// <returns>the salt</returns>
|
||||
public byte[] GetContext() => Arrays.Clone(m_theContext);
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2db7a9cd5ada5e24e974e87b0d2c7240
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DHKeyGenerationParameters
|
||||
: KeyGenerationParameters
|
||||
{
|
||||
private readonly DHParameters parameters;
|
||||
|
||||
public DHKeyGenerationParameters(
|
||||
SecureRandom random,
|
||||
DHParameters parameters)
|
||||
: base(random, GetStrength(parameters))
|
||||
{
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public DHParameters Parameters
|
||||
{
|
||||
get { return parameters; }
|
||||
}
|
||||
|
||||
internal static int GetStrength(
|
||||
DHParameters parameters)
|
||||
{
|
||||
return parameters.L != 0 ? parameters.L : parameters.P.BitLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5046fc87c33be424cb316fb38b301bc0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,80 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DHKeyParameters
|
||||
: AsymmetricKeyParameter
|
||||
{
|
||||
private readonly DHParameters parameters;
|
||||
private readonly DerObjectIdentifier algorithmOid;
|
||||
|
||||
protected DHKeyParameters(
|
||||
bool isPrivate,
|
||||
DHParameters parameters)
|
||||
: this(isPrivate, parameters, PkcsObjectIdentifiers.DhKeyAgreement)
|
||||
{
|
||||
}
|
||||
|
||||
protected DHKeyParameters(
|
||||
bool isPrivate,
|
||||
DHParameters parameters,
|
||||
DerObjectIdentifier algorithmOid)
|
||||
: base(isPrivate)
|
||||
{
|
||||
// TODO Should we allow parameters to be null?
|
||||
this.parameters = parameters;
|
||||
this.algorithmOid = algorithmOid;
|
||||
}
|
||||
|
||||
public DHParameters Parameters
|
||||
{
|
||||
get { return parameters; }
|
||||
}
|
||||
|
||||
public DerObjectIdentifier AlgorithmOid
|
||||
{
|
||||
get { return algorithmOid; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
DHKeyParameters other = obj as DHKeyParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
DHKeyParameters other)
|
||||
{
|
||||
return Org.BouncyCastle.Utilities.Platform.Equals(parameters, other.parameters)
|
||||
&& base.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hc = base.GetHashCode();
|
||||
|
||||
if (parameters != null)
|
||||
{
|
||||
hc ^= parameters.GetHashCode();
|
||||
}
|
||||
|
||||
return hc;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 452ba3b66b459c148a9e30087dfc5cdb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
189
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/DHParameters.cs
vendored
Normal file
189
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/DHParameters.cs
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DHParameters
|
||||
: ICipherParameters
|
||||
{
|
||||
private const int DefaultMinimumLength = 160;
|
||||
|
||||
private readonly BigInteger p, g, q, j;
|
||||
private readonly int m, l;
|
||||
private readonly DHValidationParameters validation;
|
||||
|
||||
private static int GetDefaultMParam(
|
||||
int lParam)
|
||||
{
|
||||
if (lParam == 0)
|
||||
return DefaultMinimumLength;
|
||||
|
||||
return System.Math.Min(lParam, DefaultMinimumLength);
|
||||
}
|
||||
|
||||
public DHParameters(
|
||||
BigInteger p,
|
||||
BigInteger g)
|
||||
: this(p, g, null, 0)
|
||||
{
|
||||
}
|
||||
|
||||
public DHParameters(
|
||||
BigInteger p,
|
||||
BigInteger g,
|
||||
BigInteger q)
|
||||
: this(p, g, q, 0)
|
||||
{
|
||||
}
|
||||
|
||||
public DHParameters(
|
||||
BigInteger p,
|
||||
BigInteger g,
|
||||
BigInteger q,
|
||||
int l)
|
||||
: this(p, g, q, GetDefaultMParam(l), l, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public DHParameters(
|
||||
BigInteger p,
|
||||
BigInteger g,
|
||||
BigInteger q,
|
||||
int m,
|
||||
int l)
|
||||
: this(p, g, q, m, l, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public DHParameters(
|
||||
BigInteger p,
|
||||
BigInteger g,
|
||||
BigInteger q,
|
||||
BigInteger j,
|
||||
DHValidationParameters validation)
|
||||
: this(p, g, q, DefaultMinimumLength, 0, j, validation)
|
||||
{
|
||||
}
|
||||
|
||||
public DHParameters(
|
||||
BigInteger p,
|
||||
BigInteger g,
|
||||
BigInteger q,
|
||||
int m,
|
||||
int l,
|
||||
BigInteger j,
|
||||
DHValidationParameters validation)
|
||||
{
|
||||
if (p == null)
|
||||
throw new ArgumentNullException("p");
|
||||
if (g == null)
|
||||
throw new ArgumentNullException("g");
|
||||
if (!p.TestBit(0))
|
||||
throw new ArgumentException("field must be an odd prime", "p");
|
||||
if (g.CompareTo(BigInteger.Two) < 0
|
||||
|| g.CompareTo(p.Subtract(BigInteger.Two)) > 0)
|
||||
throw new ArgumentException("generator must in the range [2, p - 2]", "g");
|
||||
if (q != null && q.BitLength >= p.BitLength)
|
||||
throw new ArgumentException("q too big to be a factor of (p-1)", "q");
|
||||
if (m >= p.BitLength)
|
||||
throw new ArgumentException("m value must be < bitlength of p", "m");
|
||||
if (l != 0)
|
||||
{
|
||||
// TODO Check this against the Java version, which has 'l > p.BitLength' here
|
||||
if (l >= p.BitLength)
|
||||
throw new ArgumentException("when l value specified, it must be less than bitlength(p)", "l");
|
||||
if (l < m)
|
||||
throw new ArgumentException("when l value specified, it may not be less than m value", "l");
|
||||
}
|
||||
if (j != null && j.CompareTo(BigInteger.Two) < 0)
|
||||
throw new ArgumentException("subgroup factor must be >= 2", "j");
|
||||
|
||||
// TODO If q, j both provided, validate p = jq + 1 ?
|
||||
|
||||
this.p = p;
|
||||
this.g = g;
|
||||
this.q = q;
|
||||
this.m = m;
|
||||
this.l = l;
|
||||
this.j = j;
|
||||
this.validation = validation;
|
||||
}
|
||||
|
||||
public BigInteger P
|
||||
{
|
||||
get { return p; }
|
||||
}
|
||||
|
||||
public BigInteger G
|
||||
{
|
||||
get { return g; }
|
||||
}
|
||||
|
||||
public BigInteger Q
|
||||
{
|
||||
get { return q; }
|
||||
}
|
||||
|
||||
public BigInteger J
|
||||
{
|
||||
get { return j; }
|
||||
}
|
||||
|
||||
/// <summary>The minimum bitlength of the private value.</summary>
|
||||
public int M
|
||||
{
|
||||
get { return m; }
|
||||
}
|
||||
|
||||
/// <summary>The bitlength of the private value.</summary>
|
||||
public int L
|
||||
{
|
||||
get { return l; }
|
||||
}
|
||||
|
||||
public DHValidationParameters ValidationParameters
|
||||
{
|
||||
get { return validation; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
DHParameters other = obj as DHParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected virtual bool Equals(
|
||||
DHParameters other)
|
||||
{
|
||||
return p.Equals(other.p)
|
||||
&& g.Equals(other.g)
|
||||
&& Org.BouncyCastle.Utilities.Platform.Equals(q, other.q);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hc = p.GetHashCode() ^ g.GetHashCode();
|
||||
|
||||
if (q != null)
|
||||
{
|
||||
hc ^= q.GetHashCode();
|
||||
}
|
||||
|
||||
return hc;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e33a656f0bf94b046960f491bb05f828
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DHPrivateKeyParameters
|
||||
: DHKeyParameters
|
||||
{
|
||||
private readonly BigInteger x;
|
||||
|
||||
public DHPrivateKeyParameters(
|
||||
BigInteger x,
|
||||
DHParameters parameters)
|
||||
: base(true, parameters)
|
||||
{
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public DHPrivateKeyParameters(
|
||||
BigInteger x,
|
||||
DHParameters parameters,
|
||||
DerObjectIdentifier algorithmOid)
|
||||
: base(true, parameters, algorithmOid)
|
||||
{
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public BigInteger X
|
||||
{
|
||||
get { return x; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
DHPrivateKeyParameters other = obj as DHPrivateKeyParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
DHPrivateKeyParameters other)
|
||||
{
|
||||
return x.Equals(other.x) && base.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return x.GetHashCode() ^ base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48fe2ffab16272d4791dbc01a9bd79fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,171 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Raw;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DHPublicKeyParameters
|
||||
: DHKeyParameters
|
||||
{
|
||||
private static BigInteger Validate(BigInteger y, DHParameters dhParams)
|
||||
{
|
||||
if (y == null)
|
||||
throw new ArgumentNullException("y");
|
||||
|
||||
BigInteger p = dhParams.P;
|
||||
|
||||
// TLS check
|
||||
if (y.CompareTo(BigInteger.Two) < 0 || y.CompareTo(p.Subtract(BigInteger.Two)) > 0)
|
||||
throw new ArgumentException("invalid DH public key", "y");
|
||||
|
||||
BigInteger q = dhParams.Q;
|
||||
|
||||
// We can't validate without Q.
|
||||
if (q == null)
|
||||
return y;
|
||||
|
||||
if (p.TestBit(0)
|
||||
&& p.BitLength - 1 == q.BitLength
|
||||
&& p.ShiftRight(1).Equals(q))
|
||||
{
|
||||
// Safe prime case
|
||||
if (1 == Legendre(y, p))
|
||||
return y;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (BigInteger.One.Equals(y.ModPow(q, p)))
|
||||
return y;
|
||||
}
|
||||
|
||||
throw new ArgumentException("value does not appear to be in correct group", "y");
|
||||
}
|
||||
|
||||
private readonly BigInteger y;
|
||||
|
||||
public DHPublicKeyParameters(
|
||||
BigInteger y,
|
||||
DHParameters parameters)
|
||||
: base(false, parameters)
|
||||
{
|
||||
this.y = Validate(y, parameters);
|
||||
}
|
||||
|
||||
public DHPublicKeyParameters(
|
||||
BigInteger y,
|
||||
DHParameters parameters,
|
||||
DerObjectIdentifier algorithmOid)
|
||||
: base(false, parameters, algorithmOid)
|
||||
{
|
||||
this.y = Validate(y, parameters);
|
||||
}
|
||||
|
||||
public virtual BigInteger Y
|
||||
{
|
||||
get { return y; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
DHPublicKeyParameters other = obj as DHPublicKeyParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
DHPublicKeyParameters other)
|
||||
{
|
||||
return y.Equals(other.y) && base.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return y.GetHashCode() ^ base.GetHashCode();
|
||||
}
|
||||
|
||||
private static int Legendre(BigInteger a, BigInteger b)
|
||||
{
|
||||
//int r = 0, bits = b.IntValue;
|
||||
|
||||
//for (;;)
|
||||
//{
|
||||
// int lowestSetBit = a.GetLowestSetBit();
|
||||
// a = a.ShiftRight(lowestSetBit);
|
||||
// r ^= (bits ^ (bits >> 1)) & (lowestSetBit << 1);
|
||||
|
||||
// int cmp = a.CompareTo(b);
|
||||
// if (cmp == 0)
|
||||
// break;
|
||||
|
||||
// if (cmp < 0)
|
||||
// {
|
||||
// BigInteger t = a; a = b; b = t;
|
||||
|
||||
// int oldBits = bits;
|
||||
// bits = b.IntValue;
|
||||
// r ^= oldBits & bits;
|
||||
// }
|
||||
|
||||
// a = a.Subtract(b);
|
||||
//}
|
||||
|
||||
//return BigInteger.One.Equals(b) ? (1 - (r & 2)) : 0;
|
||||
|
||||
int bitLength = b.BitLength;
|
||||
uint[] A = Nat.FromBigInteger(bitLength, a);
|
||||
uint[] B = Nat.FromBigInteger(bitLength, b);
|
||||
|
||||
int r = 0;
|
||||
|
||||
int len = B.Length;
|
||||
for (;;)
|
||||
{
|
||||
while (A[0] == 0)
|
||||
{
|
||||
Nat.ShiftDownWord(len, A, 0);
|
||||
}
|
||||
|
||||
int shift = Integers.NumberOfTrailingZeros((int)A[0]);
|
||||
if (shift > 0)
|
||||
{
|
||||
Nat.ShiftDownBits(len, A, shift, 0);
|
||||
int bits = (int)B[0];
|
||||
r ^= (bits ^ (bits >> 1)) & (shift << 1);
|
||||
}
|
||||
|
||||
int cmp = Nat.Compare(len, A, B);
|
||||
if (cmp == 0)
|
||||
break;
|
||||
|
||||
if (cmp < 0)
|
||||
{
|
||||
r ^= (int)(A[0] & B[0]);
|
||||
uint[] t = A; A = B; B = t;
|
||||
}
|
||||
|
||||
while (A[len - 1] == 0)
|
||||
{
|
||||
len = len - 1;
|
||||
}
|
||||
|
||||
Nat.Sub(len, A, B, A);
|
||||
}
|
||||
|
||||
return Nat.IsOne(len, B) ? (1 - (r & 2)) : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04f5f7feccc128d4db02735df3512cf4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DHValidationParameters
|
||||
{
|
||||
private readonly byte[] seed;
|
||||
private readonly int counter;
|
||||
|
||||
public DHValidationParameters(
|
||||
byte[] seed,
|
||||
int counter)
|
||||
{
|
||||
if (seed == null)
|
||||
throw new ArgumentNullException("seed");
|
||||
|
||||
this.seed = (byte[]) seed.Clone();
|
||||
this.counter = counter;
|
||||
}
|
||||
|
||||
public byte[] GetSeed()
|
||||
{
|
||||
return (byte[]) seed.Clone();
|
||||
}
|
||||
|
||||
public int Counter
|
||||
{
|
||||
get { return counter; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
DHValidationParameters other = obj as DHValidationParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
DHValidationParameters other)
|
||||
{
|
||||
return counter == other.counter
|
||||
&& Arrays.AreEqual(this.seed, other.seed);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return counter.GetHashCode() ^ Arrays.GetHashCode(seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ade7a28f8b712574ab48a733a6a4a8f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DsaParameterGenerationParameters
|
||||
{
|
||||
public const int DigitalSignatureUsage = 1;
|
||||
public const int KeyEstablishmentUsage = 2;
|
||||
|
||||
private readonly int l;
|
||||
private readonly int n;
|
||||
private readonly int certainty;
|
||||
private readonly SecureRandom random;
|
||||
private readonly int usageIndex;
|
||||
|
||||
/**
|
||||
* Construct without a usage index, this will do a random construction of G.
|
||||
*
|
||||
* @param L desired length of prime P in bits (the effective key size).
|
||||
* @param N desired length of prime Q in bits.
|
||||
* @param certainty certainty level for prime number generation.
|
||||
* @param random the source of randomness to use.
|
||||
*/
|
||||
public DsaParameterGenerationParameters(int L, int N, int certainty, SecureRandom random)
|
||||
: this(L, N, certainty, random, -1)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct for a specific usage index - this has the effect of using verifiable canonical generation of G.
|
||||
*
|
||||
* @param L desired length of prime P in bits (the effective key size).
|
||||
* @param N desired length of prime Q in bits.
|
||||
* @param certainty certainty level for prime number generation.
|
||||
* @param random the source of randomness to use.
|
||||
* @param usageIndex a valid usage index.
|
||||
*/
|
||||
public DsaParameterGenerationParameters(int L, int N, int certainty, SecureRandom random, int usageIndex)
|
||||
{
|
||||
this.l = L;
|
||||
this.n = N;
|
||||
this.certainty = certainty;
|
||||
this.random = random;
|
||||
this.usageIndex = usageIndex;
|
||||
}
|
||||
|
||||
public virtual int L
|
||||
{
|
||||
get { return l; }
|
||||
}
|
||||
|
||||
public virtual int N
|
||||
{
|
||||
get { return n; }
|
||||
}
|
||||
|
||||
public virtual int UsageIndex
|
||||
{
|
||||
get { return usageIndex; }
|
||||
}
|
||||
|
||||
public virtual int Certainty
|
||||
{
|
||||
get { return certainty; }
|
||||
}
|
||||
|
||||
public virtual SecureRandom Random
|
||||
{
|
||||
get { return random; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00c9484962292a9448a3af0bc5aca7f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
144
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/DesEdeParameters.cs
vendored
Normal file
144
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/DesEdeParameters.cs
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DesEdeParameters
|
||||
: DesParameters
|
||||
{
|
||||
/*
|
||||
* DES-EDE Key length in bytes.
|
||||
*/
|
||||
public const int DesEdeKeyLength = 24;
|
||||
|
||||
private static byte[] FixKey(
|
||||
byte[] key,
|
||||
int keyOff,
|
||||
int keyLen)
|
||||
{
|
||||
byte[] tmp = new byte[24];
|
||||
|
||||
switch (keyLen)
|
||||
{
|
||||
case 16:
|
||||
Array.Copy(key, keyOff, tmp, 0, 16);
|
||||
Array.Copy(key, keyOff, tmp, 16, 8);
|
||||
break;
|
||||
case 24:
|
||||
Array.Copy(key, keyOff, tmp, 0, 24);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Bad length for DESede key: " + keyLen, "keyLen");
|
||||
}
|
||||
|
||||
if (IsWeakKey(tmp))
|
||||
throw new ArgumentException("attempt to create weak DESede key");
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public DesEdeParameters(
|
||||
byte[] key)
|
||||
: base(FixKey(key, 0, key.Length))
|
||||
{
|
||||
}
|
||||
|
||||
public DesEdeParameters(
|
||||
byte[] key,
|
||||
int keyOff,
|
||||
int keyLen)
|
||||
: base(FixKey(key, keyOff, keyLen))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if the passed in key is a DES-EDE weak key.
|
||||
*
|
||||
* @param key bytes making up the key
|
||||
* @param offset offset into the byte array the key starts at
|
||||
* @param length number of bytes making up the key
|
||||
*/
|
||||
public static bool IsWeakKey(
|
||||
byte[] key,
|
||||
int offset,
|
||||
int length)
|
||||
{
|
||||
for (int i = offset; i < length; i += DesKeyLength)
|
||||
{
|
||||
if (DesParameters.IsWeakKey(key, i))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if the passed in key is a DES-EDE weak key.
|
||||
*
|
||||
* @param key bytes making up the key
|
||||
* @param offset offset into the byte array the key starts at
|
||||
*/
|
||||
public static new bool IsWeakKey(
|
||||
byte[] key,
|
||||
int offset)
|
||||
{
|
||||
return IsWeakKey(key, offset, key.Length - offset);
|
||||
}
|
||||
|
||||
public static new bool IsWeakKey(
|
||||
byte[] key)
|
||||
{
|
||||
return IsWeakKey(key, 0, key.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if the passed in key is a real 2/3 part DES-EDE key.
|
||||
*
|
||||
* @param key bytes making up the key
|
||||
* @param offset offset into the byte array the key starts at
|
||||
*/
|
||||
public static bool IsRealEdeKey(byte[] key, int offset)
|
||||
{
|
||||
return key.Length == 16 ? IsReal2Key(key, offset) : IsReal3Key(key, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if the passed in key is a real 2 part DES-EDE key.
|
||||
*
|
||||
* @param key bytes making up the key
|
||||
* @param offset offset into the byte array the key starts at
|
||||
*/
|
||||
public static bool IsReal2Key(byte[] key, int offset)
|
||||
{
|
||||
bool isValid = false;
|
||||
for (int i = offset; i != offset + 8; i++)
|
||||
{
|
||||
isValid |= (key[i] != key[i + 8]);
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if the passed in key is a real 3 part DES-EDE key.
|
||||
*
|
||||
* @param key bytes making up the key
|
||||
* @param offset offset into the byte array the key starts at
|
||||
*/
|
||||
public static bool IsReal3Key(byte[] key, int offset)
|
||||
{
|
||||
bool diff12 = false, diff13 = false, diff23 = false;
|
||||
for (int i = offset; i != offset + 8; i++)
|
||||
{
|
||||
diff12 |= (key[i] != key[i + 8]);
|
||||
diff13 |= (key[i] != key[i + 16]);
|
||||
diff23 |= (key[i + 8] != key[i + 16]);
|
||||
}
|
||||
return diff12 && diff13 && diff23;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33e292373b4fa564dbabdf56717f5037
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
153
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/DesParameters.cs
vendored
Normal file
153
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/DesParameters.cs
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DesParameters
|
||||
: KeyParameter
|
||||
{
|
||||
public DesParameters(
|
||||
byte[] key)
|
||||
: base(key)
|
||||
{
|
||||
if (IsWeakKey(key))
|
||||
throw new ArgumentException("attempt to create weak DES key");
|
||||
}
|
||||
|
||||
public DesParameters(
|
||||
byte[] key,
|
||||
int keyOff,
|
||||
int keyLen)
|
||||
: base(key, keyOff, keyLen)
|
||||
{
|
||||
if (IsWeakKey(key, keyOff))
|
||||
throw new ArgumentException("attempt to create weak DES key");
|
||||
}
|
||||
|
||||
/*
|
||||
* DES Key Length in bytes.
|
||||
*/
|
||||
public const int DesKeyLength = 8;
|
||||
|
||||
/*
|
||||
* Table of weak and semi-weak keys taken from Schneier pp281
|
||||
*/
|
||||
private const int N_DES_WEAK_KEYS = 16;
|
||||
|
||||
private static readonly byte[] DES_weak_keys =
|
||||
{
|
||||
/* weak keys */
|
||||
(byte)0x01,(byte)0x01,(byte)0x01,(byte)0x01, (byte)0x01,(byte)0x01,(byte)0x01,(byte)0x01,
|
||||
(byte)0x1f,(byte)0x1f,(byte)0x1f,(byte)0x1f, (byte)0x0e,(byte)0x0e,(byte)0x0e,(byte)0x0e,
|
||||
(byte)0xe0,(byte)0xe0,(byte)0xe0,(byte)0xe0, (byte)0xf1,(byte)0xf1,(byte)0xf1,(byte)0xf1,
|
||||
(byte)0xfe,(byte)0xfe,(byte)0xfe,(byte)0xfe, (byte)0xfe,(byte)0xfe,(byte)0xfe,(byte)0xfe,
|
||||
|
||||
/* semi-weak keys */
|
||||
(byte)0x01,(byte)0xfe,(byte)0x01,(byte)0xfe, (byte)0x01,(byte)0xfe,(byte)0x01,(byte)0xfe,
|
||||
(byte)0x1f,(byte)0xe0,(byte)0x1f,(byte)0xe0, (byte)0x0e,(byte)0xf1,(byte)0x0e,(byte)0xf1,
|
||||
(byte)0x01,(byte)0xe0,(byte)0x01,(byte)0xe0, (byte)0x01,(byte)0xf1,(byte)0x01,(byte)0xf1,
|
||||
(byte)0x1f,(byte)0xfe,(byte)0x1f,(byte)0xfe, (byte)0x0e,(byte)0xfe,(byte)0x0e,(byte)0xfe,
|
||||
(byte)0x01,(byte)0x1f,(byte)0x01,(byte)0x1f, (byte)0x01,(byte)0x0e,(byte)0x01,(byte)0x0e,
|
||||
(byte)0xe0,(byte)0xfe,(byte)0xe0,(byte)0xfe, (byte)0xf1,(byte)0xfe,(byte)0xf1,(byte)0xfe,
|
||||
(byte)0xfe,(byte)0x01,(byte)0xfe,(byte)0x01, (byte)0xfe,(byte)0x01,(byte)0xfe,(byte)0x01,
|
||||
(byte)0xe0,(byte)0x1f,(byte)0xe0,(byte)0x1f, (byte)0xf1,(byte)0x0e,(byte)0xf1,(byte)0x0e,
|
||||
(byte)0xe0,(byte)0x01,(byte)0xe0,(byte)0x01, (byte)0xf1,(byte)0x01,(byte)0xf1,(byte)0x01,
|
||||
(byte)0xfe,(byte)0x1f,(byte)0xfe,(byte)0x1f, (byte)0xfe,(byte)0x0e,(byte)0xfe,(byte)0x0e,
|
||||
(byte)0x1f,(byte)0x01,(byte)0x1f,(byte)0x01, (byte)0x0e,(byte)0x01,(byte)0x0e,(byte)0x01,
|
||||
(byte)0xfe,(byte)0xe0,(byte)0xfe,(byte)0xe0, (byte)0xfe,(byte)0xf1,(byte)0xfe,(byte)0xf1
|
||||
};
|
||||
|
||||
/**
|
||||
* DES has 16 weak keys. This method will check
|
||||
* if the given DES key material is weak or semi-weak.
|
||||
* Key material that is too short is regarded as weak.
|
||||
* <p>
|
||||
* See <a href="http://www.counterpane.com/applied.html">"Applied
|
||||
* Cryptography"</a> by Bruce Schneier for more information.
|
||||
* </p>
|
||||
* @return true if the given DES key material is weak or semi-weak,
|
||||
* false otherwise.
|
||||
*/
|
||||
public static bool IsWeakKey(
|
||||
byte[] key,
|
||||
int offset)
|
||||
{
|
||||
if (key.Length - offset < DesKeyLength)
|
||||
throw new ArgumentException("key material too short.");
|
||||
|
||||
//nextkey:
|
||||
for (int i = 0; i < N_DES_WEAK_KEYS; i++)
|
||||
{
|
||||
bool unmatch = false;
|
||||
for (int j = 0; j < DesKeyLength; j++)
|
||||
{
|
||||
if (key[j + offset] != DES_weak_keys[i * DesKeyLength + j])
|
||||
{
|
||||
//continue nextkey;
|
||||
unmatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!unmatch)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsWeakKey(
|
||||
byte[] key)
|
||||
{
|
||||
return IsWeakKey(key, 0);
|
||||
}
|
||||
|
||||
public static byte SetOddParity(byte b)
|
||||
{
|
||||
uint parity = b ^ 1U;
|
||||
parity ^= (parity >> 4);
|
||||
parity ^= (parity >> 2);
|
||||
parity ^= (parity >> 1);
|
||||
parity &= 1U;
|
||||
|
||||
return (byte)(b ^ parity);
|
||||
}
|
||||
|
||||
/**
|
||||
* DES Keys use the LSB as the odd parity bit. This can
|
||||
* be used to check for corrupt keys.
|
||||
*
|
||||
* @param bytes the byte array to set the parity on.
|
||||
*/
|
||||
public static void SetOddParity(byte[] bytes)
|
||||
{
|
||||
for (int i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
bytes[i] = SetOddParity(bytes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetOddParity(byte[] bytes, int off, int len)
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
bytes[off + i] = SetOddParity(bytes[off + i]);
|
||||
}
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public static void SetOddParity(Span<byte> bytes)
|
||||
{
|
||||
for (int i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
bytes[i] = SetOddParity(bytes[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed1acf68a2d39a84db0419ba2242da6d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DsaKeyGenerationParameters
|
||||
: KeyGenerationParameters
|
||||
{
|
||||
private readonly DsaParameters parameters;
|
||||
|
||||
public DsaKeyGenerationParameters(
|
||||
SecureRandom random,
|
||||
DsaParameters parameters)
|
||||
: base(random, parameters.P.BitLength - 1)
|
||||
{
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public DsaParameters Parameters
|
||||
{
|
||||
get { return parameters; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3388e3f46009aa04ab63d742a4d7ec5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public abstract class DsaKeyParameters
|
||||
: AsymmetricKeyParameter
|
||||
{
|
||||
private readonly DsaParameters parameters;
|
||||
|
||||
protected DsaKeyParameters(
|
||||
bool isPrivate,
|
||||
DsaParameters parameters)
|
||||
: base(isPrivate)
|
||||
{
|
||||
// Note: parameters may be null
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public DsaParameters Parameters
|
||||
{
|
||||
get { return parameters; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
DsaKeyParameters other = obj as DsaKeyParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
DsaKeyParameters other)
|
||||
{
|
||||
return Org.BouncyCastle.Utilities.Platform.Equals(parameters, other.parameters)
|
||||
&& base.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hc = base.GetHashCode();
|
||||
|
||||
if (parameters != null)
|
||||
{
|
||||
hc ^= parameters.GetHashCode();
|
||||
}
|
||||
|
||||
return hc;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52229c7d1596b2e4583acc0f3100c03e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
89
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/DsaParameters.cs
vendored
Normal file
89
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/DsaParameters.cs
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DsaParameters
|
||||
: ICipherParameters
|
||||
{
|
||||
private readonly BigInteger p, q , g;
|
||||
private readonly DsaValidationParameters validation;
|
||||
|
||||
public DsaParameters(
|
||||
BigInteger p,
|
||||
BigInteger q,
|
||||
BigInteger g)
|
||||
: this(p, q, g, null)
|
||||
{
|
||||
}
|
||||
|
||||
public DsaParameters(
|
||||
BigInteger p,
|
||||
BigInteger q,
|
||||
BigInteger g,
|
||||
DsaValidationParameters parameters)
|
||||
{
|
||||
if (p == null)
|
||||
throw new ArgumentNullException("p");
|
||||
if (q == null)
|
||||
throw new ArgumentNullException("q");
|
||||
if (g == null)
|
||||
throw new ArgumentNullException("g");
|
||||
|
||||
this.p = p;
|
||||
this.q = q;
|
||||
this.g = g;
|
||||
this.validation = parameters;
|
||||
}
|
||||
|
||||
public BigInteger P
|
||||
{
|
||||
get { return p; }
|
||||
}
|
||||
|
||||
public BigInteger Q
|
||||
{
|
||||
get { return q; }
|
||||
}
|
||||
|
||||
public BigInteger G
|
||||
{
|
||||
get { return g; }
|
||||
}
|
||||
|
||||
public DsaValidationParameters ValidationParameters
|
||||
{
|
||||
get { return validation; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
DsaParameters other = obj as DsaParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
DsaParameters other)
|
||||
{
|
||||
return p.Equals(other.p) && q.Equals(other.q) && g.Equals(other.g);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return p.GetHashCode() ^ q.GetHashCode() ^ g.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3849c5db5ffe55d4ba1eeac4d2b80120
|
||||
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;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DsaPrivateKeyParameters
|
||||
: DsaKeyParameters
|
||||
{
|
||||
private readonly BigInteger x;
|
||||
|
||||
public DsaPrivateKeyParameters(
|
||||
BigInteger x,
|
||||
DsaParameters parameters)
|
||||
: base(true, parameters)
|
||||
{
|
||||
if (x == null)
|
||||
throw new ArgumentNullException("x");
|
||||
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public BigInteger X
|
||||
{
|
||||
get { return x; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
DsaPrivateKeyParameters other = obj as DsaPrivateKeyParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
DsaPrivateKeyParameters other)
|
||||
{
|
||||
return x.Equals(other.x) && base.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return x.GetHashCode() ^ base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 743ebf6feb08d9f488e3a2664940201e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,72 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DsaPublicKeyParameters
|
||||
: DsaKeyParameters
|
||||
{
|
||||
private static BigInteger Validate(BigInteger y, DsaParameters parameters)
|
||||
{
|
||||
// we can't validate without params, fortunately we can't use the key either...
|
||||
if (parameters != null)
|
||||
{
|
||||
if (y.CompareTo(BigInteger.Two) < 0
|
||||
|| y.CompareTo(parameters.P.Subtract(BigInteger.Two)) > 0
|
||||
|| !y.ModPow(parameters.Q, parameters.P).Equals(BigInteger.One))
|
||||
{
|
||||
throw new ArgumentException("y value does not appear to be in correct group");
|
||||
}
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
private readonly BigInteger y;
|
||||
|
||||
public DsaPublicKeyParameters(
|
||||
BigInteger y,
|
||||
DsaParameters parameters)
|
||||
: base(false, parameters)
|
||||
{
|
||||
if (y == null)
|
||||
throw new ArgumentNullException("y");
|
||||
|
||||
this.y = Validate(y, parameters);
|
||||
}
|
||||
|
||||
public BigInteger Y
|
||||
{
|
||||
get { return y; }
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
DsaPublicKeyParameters other = obj as DsaPublicKeyParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
DsaPublicKeyParameters other)
|
||||
{
|
||||
return y.Equals(other.y) && base.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return y.GetHashCode() ^ base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66fa72f172abdc848aaf070bac718cad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,76 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class DsaValidationParameters
|
||||
{
|
||||
private readonly byte[] seed;
|
||||
private readonly int counter;
|
||||
private readonly int usageIndex;
|
||||
|
||||
public DsaValidationParameters(byte[] seed, int counter)
|
||||
: this(seed, counter, -1)
|
||||
{
|
||||
}
|
||||
|
||||
public DsaValidationParameters(
|
||||
byte[] seed,
|
||||
int counter,
|
||||
int usageIndex)
|
||||
{
|
||||
if (seed == null)
|
||||
throw new ArgumentNullException("seed");
|
||||
|
||||
this.seed = (byte[]) seed.Clone();
|
||||
this.counter = counter;
|
||||
this.usageIndex = usageIndex;
|
||||
}
|
||||
|
||||
public virtual byte[] GetSeed()
|
||||
{
|
||||
return (byte[]) seed.Clone();
|
||||
}
|
||||
|
||||
public virtual int Counter
|
||||
{
|
||||
get { return counter; }
|
||||
}
|
||||
|
||||
public virtual int UsageIndex
|
||||
{
|
||||
get { return usageIndex; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
DsaValidationParameters other = obj as DsaValidationParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected virtual bool Equals(
|
||||
DsaValidationParameters other)
|
||||
{
|
||||
return counter == other.counter
|
||||
&& Arrays.AreEqual(seed, other.seed);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return counter.GetHashCode() ^ Arrays.GetHashCode(seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fca71d5da02303b4e94a16c18ef0ee8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
175
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/ECDomainParameters.cs
vendored
Normal file
175
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/ECDomainParameters.cs
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class ECDomainParameters
|
||||
{
|
||||
private readonly ECCurve curve;
|
||||
private readonly byte[] seed;
|
||||
private readonly ECPoint g;
|
||||
private readonly BigInteger n;
|
||||
private readonly BigInteger h;
|
||||
|
||||
private BigInteger hInv;
|
||||
|
||||
public ECDomainParameters(X9ECParameters x9)
|
||||
: this(x9.Curve, x9.G, x9.N, x9.H, x9.GetSeed())
|
||||
{
|
||||
}
|
||||
|
||||
public ECDomainParameters(
|
||||
ECCurve curve,
|
||||
ECPoint g,
|
||||
BigInteger n)
|
||||
: this(curve, g, n, BigInteger.One, null)
|
||||
{
|
||||
}
|
||||
|
||||
public ECDomainParameters(
|
||||
ECCurve curve,
|
||||
ECPoint g,
|
||||
BigInteger n,
|
||||
BigInteger h)
|
||||
: this(curve, g, n, h, null)
|
||||
{
|
||||
}
|
||||
|
||||
public ECDomainParameters(
|
||||
ECCurve curve,
|
||||
ECPoint g,
|
||||
BigInteger n,
|
||||
BigInteger h,
|
||||
byte[] seed)
|
||||
{
|
||||
if (curve == null)
|
||||
throw new ArgumentNullException("curve");
|
||||
if (g == null)
|
||||
throw new ArgumentNullException("g");
|
||||
if (n == null)
|
||||
throw new ArgumentNullException("n");
|
||||
// we can't check for h == null here as h is optional in X9.62 as it is not required for ECDSA
|
||||
|
||||
this.curve = curve;
|
||||
this.g = ValidatePublicPoint(curve, g);
|
||||
this.n = n;
|
||||
this.h = h;
|
||||
this.seed = Arrays.Clone(seed);
|
||||
}
|
||||
|
||||
public ECCurve Curve
|
||||
{
|
||||
get { return curve; }
|
||||
}
|
||||
|
||||
public ECPoint G
|
||||
{
|
||||
get { return g; }
|
||||
}
|
||||
|
||||
public BigInteger N
|
||||
{
|
||||
get { return n; }
|
||||
}
|
||||
|
||||
public BigInteger H
|
||||
{
|
||||
get { return h; }
|
||||
}
|
||||
|
||||
public BigInteger HInv
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (hInv == null)
|
||||
{
|
||||
hInv = BigIntegers.ModOddInverseVar(n, h);
|
||||
}
|
||||
return hInv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] GetSeed()
|
||||
{
|
||||
return Arrays.Clone(seed);
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
ECDomainParameters other = obj as ECDomainParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected virtual bool Equals(
|
||||
ECDomainParameters other)
|
||||
{
|
||||
return curve.Equals(other.curve)
|
||||
&& g.Equals(other.g)
|
||||
&& n.Equals(other.n);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
//return Arrays.GetHashCode(new object[]{ curve, g, n });
|
||||
int hc = 4;
|
||||
hc *= 257;
|
||||
hc ^= curve.GetHashCode();
|
||||
hc *= 257;
|
||||
hc ^= g.GetHashCode();
|
||||
hc *= 257;
|
||||
hc ^= n.GetHashCode();
|
||||
return hc;
|
||||
}
|
||||
|
||||
public BigInteger ValidatePrivateScalar(BigInteger d)
|
||||
{
|
||||
if (null == d)
|
||||
throw new ArgumentNullException("d", "Scalar cannot be null");
|
||||
|
||||
if (d.CompareTo(BigInteger.One) < 0 || (d.CompareTo(N) >= 0))
|
||||
throw new ArgumentException("Scalar is not in the interval [1, n - 1]", "d");
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
public ECPoint ValidatePublicPoint(ECPoint q)
|
||||
{
|
||||
return ValidatePublicPoint(Curve, q);
|
||||
}
|
||||
|
||||
internal static ECPoint ValidatePublicPoint(ECCurve c, ECPoint q)
|
||||
{
|
||||
if (null == q)
|
||||
throw new ArgumentNullException("q", "Point cannot be null");
|
||||
|
||||
q = ECAlgorithms.ImportPoint(c, q).Normalize();
|
||||
|
||||
if (q.IsInfinity)
|
||||
throw new ArgumentException("Point at infinity", "q");
|
||||
|
||||
if (!q.IsValid())
|
||||
throw new ArgumentException("Point not on curve", "q");
|
||||
|
||||
return q;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ae5b01638798984f9a2713b2889de3e
|
||||
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;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class ECGost3410Parameters
|
||||
: ECNamedDomainParameters
|
||||
{
|
||||
private readonly DerObjectIdentifier _publicKeyParamSet;
|
||||
private readonly DerObjectIdentifier _digestParamSet;
|
||||
private readonly DerObjectIdentifier _encryptionParamSet;
|
||||
|
||||
public DerObjectIdentifier PublicKeyParamSet
|
||||
{
|
||||
get { return _publicKeyParamSet; }
|
||||
}
|
||||
|
||||
public DerObjectIdentifier DigestParamSet
|
||||
{
|
||||
get { return _digestParamSet; }
|
||||
}
|
||||
|
||||
public DerObjectIdentifier EncryptionParamSet
|
||||
{
|
||||
get { return _encryptionParamSet; }
|
||||
}
|
||||
|
||||
public ECGost3410Parameters(
|
||||
ECNamedDomainParameters dp,
|
||||
DerObjectIdentifier publicKeyParamSet,
|
||||
DerObjectIdentifier digestParamSet,
|
||||
DerObjectIdentifier encryptionParamSet)
|
||||
: base(dp.Name, dp.Curve, dp.G, dp.N, dp.H, dp.GetSeed())
|
||||
{
|
||||
this._publicKeyParamSet = publicKeyParamSet;
|
||||
this._digestParamSet = digestParamSet;
|
||||
this._encryptionParamSet = encryptionParamSet;
|
||||
}
|
||||
|
||||
public ECGost3410Parameters(ECDomainParameters dp, DerObjectIdentifier publicKeyParamSet,
|
||||
DerObjectIdentifier digestParamSet,
|
||||
DerObjectIdentifier encryptionParamSet)
|
||||
: base(publicKeyParamSet, dp.Curve, dp.G, dp.N, dp.H, dp.GetSeed())
|
||||
{
|
||||
this._publicKeyParamSet = publicKeyParamSet;
|
||||
this._digestParamSet = digestParamSet;
|
||||
this._encryptionParamSet = encryptionParamSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d889c6f2ebb73eb4bb1d6d8275a6b086
|
||||
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 Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class ECKeyGenerationParameters
|
||||
: KeyGenerationParameters
|
||||
{
|
||||
private readonly ECDomainParameters domainParams;
|
||||
private readonly DerObjectIdentifier publicKeyParamSet;
|
||||
|
||||
public ECKeyGenerationParameters(
|
||||
ECDomainParameters domainParameters,
|
||||
SecureRandom random)
|
||||
: base(random, domainParameters.N.BitLength)
|
||||
{
|
||||
this.domainParams = domainParameters;
|
||||
}
|
||||
|
||||
public ECKeyGenerationParameters(
|
||||
DerObjectIdentifier publicKeyParamSet,
|
||||
SecureRandom random)
|
||||
: this(ECKeyParameters.LookupParameters(publicKeyParamSet), random)
|
||||
{
|
||||
this.publicKeyParamSet = publicKeyParamSet;
|
||||
}
|
||||
|
||||
public ECDomainParameters DomainParameters
|
||||
{
|
||||
get { return domainParams; }
|
||||
}
|
||||
|
||||
public DerObjectIdentifier PublicKeyParamSet
|
||||
{
|
||||
get { return publicKeyParamSet; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66a2dda7956d7864592a62e141c5fd40
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
138
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/ECKeyParameters.cs
vendored
Normal file
138
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/ECKeyParameters.cs
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public abstract class ECKeyParameters
|
||||
: AsymmetricKeyParameter
|
||||
{
|
||||
// NB: Use a Dictionary so we can lookup the upper case version
|
||||
private static readonly Dictionary<string, string> Algorithms =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ "EC", "EC" },
|
||||
{ "ECDSA", "ECDSA" },
|
||||
{ "ECDH", "ECDH" },
|
||||
{ "ECDHC", "ECDHC" },
|
||||
{ "ECGOST3410", "ECGOST3410" },
|
||||
{ "ECMQV", "ECMQV" },
|
||||
};
|
||||
|
||||
private readonly string algorithm;
|
||||
private readonly ECDomainParameters parameters;
|
||||
private readonly DerObjectIdentifier publicKeyParamSet;
|
||||
|
||||
protected ECKeyParameters(
|
||||
string algorithm,
|
||||
bool isPrivate,
|
||||
ECDomainParameters parameters)
|
||||
: base(isPrivate)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException("algorithm");
|
||||
if (parameters == null)
|
||||
throw new ArgumentNullException("parameters");
|
||||
|
||||
this.algorithm = VerifyAlgorithmName(algorithm);
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
protected ECKeyParameters(
|
||||
string algorithm,
|
||||
bool isPrivate,
|
||||
DerObjectIdentifier publicKeyParamSet)
|
||||
: base(isPrivate)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException("algorithm");
|
||||
if (publicKeyParamSet == null)
|
||||
throw new ArgumentNullException("publicKeyParamSet");
|
||||
|
||||
this.algorithm = VerifyAlgorithmName(algorithm);
|
||||
this.parameters = LookupParameters(publicKeyParamSet);
|
||||
this.publicKeyParamSet = publicKeyParamSet;
|
||||
}
|
||||
|
||||
public string AlgorithmName
|
||||
{
|
||||
get { return algorithm; }
|
||||
}
|
||||
|
||||
public ECDomainParameters Parameters
|
||||
{
|
||||
get { return parameters; }
|
||||
}
|
||||
|
||||
public DerObjectIdentifier PublicKeyParamSet
|
||||
{
|
||||
get { return publicKeyParamSet; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
ECDomainParameters other = obj as ECDomainParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
ECKeyParameters other)
|
||||
{
|
||||
return parameters.Equals(other.parameters) && base.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return parameters.GetHashCode() ^ base.GetHashCode();
|
||||
}
|
||||
|
||||
internal ECKeyGenerationParameters CreateKeyGenerationParameters(
|
||||
SecureRandom random)
|
||||
{
|
||||
if (publicKeyParamSet != null)
|
||||
{
|
||||
return new ECKeyGenerationParameters(publicKeyParamSet, random);
|
||||
}
|
||||
|
||||
return new ECKeyGenerationParameters(parameters, random);
|
||||
}
|
||||
|
||||
internal static string VerifyAlgorithmName(string algorithm)
|
||||
{
|
||||
if (!Algorithms.TryGetValue(algorithm, out var upper))
|
||||
throw new ArgumentException("unrecognised algorithm: " + algorithm, nameof(algorithm));
|
||||
|
||||
return upper;
|
||||
}
|
||||
|
||||
internal static ECDomainParameters LookupParameters(
|
||||
DerObjectIdentifier publicKeyParamSet)
|
||||
{
|
||||
if (publicKeyParamSet == null)
|
||||
throw new ArgumentNullException("publicKeyParamSet");
|
||||
|
||||
X9ECParameters x9 = ECKeyPairGenerator.FindECCurveByOid(publicKeyParamSet);
|
||||
|
||||
if (x9 == null)
|
||||
throw new ArgumentException("OID is not a valid public key parameter set", "publicKeyParamSet");
|
||||
|
||||
return new ECDomainParameters(x9);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a1dbe9ca49ab3d41a44a888f507d915
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class ECNamedDomainParameters
|
||||
: ECDomainParameters
|
||||
{
|
||||
private readonly DerObjectIdentifier name;
|
||||
|
||||
public DerObjectIdentifier Name
|
||||
{
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public ECNamedDomainParameters(DerObjectIdentifier name, ECDomainParameters dp)
|
||||
: this(name, dp.Curve, dp.G, dp.N, dp.H, dp.GetSeed())
|
||||
{
|
||||
}
|
||||
|
||||
public ECNamedDomainParameters(DerObjectIdentifier name, X9ECParameters x9)
|
||||
: base(x9)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ECNamedDomainParameters(DerObjectIdentifier name, ECCurve curve, ECPoint g, BigInteger n)
|
||||
: base(curve, g, n)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ECNamedDomainParameters(DerObjectIdentifier name, ECCurve curve, ECPoint g, BigInteger n, BigInteger h)
|
||||
: base(curve, g, n, h)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ECNamedDomainParameters(DerObjectIdentifier name, ECCurve curve, ECPoint g, BigInteger n, BigInteger h, byte[] seed)
|
||||
: base(curve, g, n, h, seed)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcf55207868bbff43ab5326a8190c90e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,73 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class ECPrivateKeyParameters
|
||||
: ECKeyParameters
|
||||
{
|
||||
private readonly BigInteger d;
|
||||
|
||||
public ECPrivateKeyParameters(
|
||||
BigInteger d,
|
||||
ECDomainParameters parameters)
|
||||
: this("EC", d, parameters)
|
||||
{
|
||||
}
|
||||
|
||||
public ECPrivateKeyParameters(
|
||||
string algorithm,
|
||||
BigInteger d,
|
||||
ECDomainParameters parameters)
|
||||
: base(algorithm, true, parameters)
|
||||
{
|
||||
this.d = Parameters.ValidatePrivateScalar(d);
|
||||
}
|
||||
|
||||
public ECPrivateKeyParameters(
|
||||
string algorithm,
|
||||
BigInteger d,
|
||||
DerObjectIdentifier publicKeyParamSet)
|
||||
: base(algorithm, true, publicKeyParamSet)
|
||||
{
|
||||
this.d = Parameters.ValidatePrivateScalar(d);
|
||||
}
|
||||
|
||||
public BigInteger D
|
||||
{
|
||||
get { return d; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
ECPrivateKeyParameters other = obj as ECPrivateKeyParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
ECPrivateKeyParameters other)
|
||||
{
|
||||
return d.Equals(other.d) && base.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return d.GetHashCode() ^ base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f7a2bfcdc2089e458399197163fd571
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,72 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class ECPublicKeyParameters
|
||||
: ECKeyParameters
|
||||
{
|
||||
private readonly ECPoint q;
|
||||
|
||||
public ECPublicKeyParameters(
|
||||
ECPoint q,
|
||||
ECDomainParameters parameters)
|
||||
: this("EC", q, parameters)
|
||||
{
|
||||
}
|
||||
|
||||
public ECPublicKeyParameters(
|
||||
string algorithm,
|
||||
ECPoint q,
|
||||
ECDomainParameters parameters)
|
||||
: base(algorithm, false, parameters)
|
||||
{
|
||||
this.q = ECDomainParameters.ValidatePublicPoint(Parameters.Curve, q);
|
||||
}
|
||||
|
||||
public ECPublicKeyParameters(
|
||||
string algorithm,
|
||||
ECPoint q,
|
||||
DerObjectIdentifier publicKeyParamSet)
|
||||
: base(algorithm, false, publicKeyParamSet)
|
||||
{
|
||||
this.q = ECDomainParameters.ValidatePublicPoint(Parameters.Curve, q);
|
||||
}
|
||||
|
||||
public ECPoint Q
|
||||
{
|
||||
get { return q; }
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
ECPublicKeyParameters other = obj as ECPublicKeyParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
ECPublicKeyParameters other)
|
||||
{
|
||||
return q.Equals(other.q) && base.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return q.GetHashCode() ^ base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7092367b0170a3344992fc8394490b16
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class Ed25519KeyGenerationParameters
|
||||
: KeyGenerationParameters
|
||||
{
|
||||
public Ed25519KeyGenerationParameters(SecureRandom random)
|
||||
: base(random, 256)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5a92b404b3ae164cbf754bc6cbd2d02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,144 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Rfc8032;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public sealed class Ed25519PrivateKeyParameters
|
||||
: AsymmetricKeyParameter
|
||||
{
|
||||
public static readonly int KeySize = Ed25519.SecretKeySize;
|
||||
public static readonly int SignatureSize = Ed25519.SignatureSize;
|
||||
|
||||
private readonly byte[] data = new byte[KeySize];
|
||||
|
||||
private Ed25519PublicKeyParameters cachedPublicKey;
|
||||
|
||||
public Ed25519PrivateKeyParameters(SecureRandom random)
|
||||
: base(true)
|
||||
{
|
||||
Ed25519.GeneratePrivateKey(random, data);
|
||||
}
|
||||
|
||||
public Ed25519PrivateKeyParameters(byte[] buf)
|
||||
: this(Validate(buf), 0)
|
||||
{
|
||||
}
|
||||
|
||||
public Ed25519PrivateKeyParameters(byte[] buf, int off)
|
||||
: base(true)
|
||||
{
|
||||
Array.Copy(buf, off, data, 0, KeySize);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public Ed25519PrivateKeyParameters(ReadOnlySpan<byte> buf)
|
||||
: base(true)
|
||||
{
|
||||
if (buf.Length != KeySize)
|
||||
throw new ArgumentException("must have length " + KeySize, nameof(buf));
|
||||
|
||||
buf.CopyTo(data);
|
||||
}
|
||||
#endif
|
||||
|
||||
public Ed25519PrivateKeyParameters(Stream input)
|
||||
: base(true)
|
||||
{
|
||||
if (KeySize != Streams.ReadFully(input, data))
|
||||
throw new EndOfStreamException("EOF encountered in middle of Ed25519 private key");
|
||||
}
|
||||
|
||||
public void Encode(byte[] buf, int off)
|
||||
{
|
||||
Array.Copy(data, 0, buf, off, KeySize);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void Encode(Span<byte> buf)
|
||||
{
|
||||
data.CopyTo(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
public byte[] GetEncoded()
|
||||
{
|
||||
return Arrays.Clone(data);
|
||||
}
|
||||
|
||||
public Ed25519PublicKeyParameters GeneratePublicKey()
|
||||
{
|
||||
lock (data)
|
||||
{
|
||||
if (null == cachedPublicKey)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
Span<byte> publicKey = stackalloc byte[Ed25519.PublicKeySize];
|
||||
Ed25519.GeneratePublicKey(data, publicKey);
|
||||
cachedPublicKey = new Ed25519PublicKeyParameters(publicKey);
|
||||
#else
|
||||
byte[] publicKey = new byte[Ed25519.PublicKeySize];
|
||||
Ed25519.GeneratePublicKey(data, 0, publicKey, 0);
|
||||
cachedPublicKey = new Ed25519PublicKeyParameters(publicKey, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
return cachedPublicKey;
|
||||
}
|
||||
}
|
||||
|
||||
public void Sign(Ed25519.Algorithm algorithm, byte[] ctx, byte[] msg, int msgOff, int msgLen,
|
||||
byte[] sig, int sigOff)
|
||||
{
|
||||
Ed25519PublicKeyParameters publicKey = GeneratePublicKey();
|
||||
|
||||
byte[] pk = new byte[Ed25519.PublicKeySize];
|
||||
publicKey.Encode(pk, 0);
|
||||
|
||||
switch (algorithm)
|
||||
{
|
||||
case Ed25519.Algorithm.Ed25519:
|
||||
{
|
||||
if (null != ctx)
|
||||
throw new ArgumentException("ctx");
|
||||
|
||||
Ed25519.Sign(data, 0, pk, 0, msg, msgOff, msgLen, sig, sigOff);
|
||||
break;
|
||||
}
|
||||
case Ed25519.Algorithm.Ed25519ctx:
|
||||
{
|
||||
Ed25519.Sign(data, 0, pk, 0, ctx, msg, msgOff, msgLen, sig, sigOff);
|
||||
break;
|
||||
}
|
||||
case Ed25519.Algorithm.Ed25519ph:
|
||||
{
|
||||
if (Ed25519.PrehashSize != msgLen)
|
||||
throw new ArgumentException("msgLen");
|
||||
|
||||
Ed25519.SignPrehash(data, 0, pk, 0, ctx, msg, msgOff, sig, sigOff);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new ArgumentException("algorithm");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] Validate(byte[] buf)
|
||||
{
|
||||
if (buf.Length != KeySize)
|
||||
throw new ArgumentException("must have length " + KeySize, nameof(buf));
|
||||
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 774836637c2d0c44cb845ee36c553e38
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Rfc8032;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public sealed class Ed25519PublicKeyParameters
|
||||
: AsymmetricKeyParameter
|
||||
{
|
||||
public static readonly int KeySize = Ed25519.PublicKeySize;
|
||||
|
||||
private readonly byte[] data = new byte[KeySize];
|
||||
|
||||
public Ed25519PublicKeyParameters(byte[] buf)
|
||||
: this(Validate(buf), 0)
|
||||
{
|
||||
}
|
||||
|
||||
public Ed25519PublicKeyParameters(byte[] buf, int off)
|
||||
: base(false)
|
||||
{
|
||||
Array.Copy(buf, off, data, 0, KeySize);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public Ed25519PublicKeyParameters(ReadOnlySpan<byte> buf)
|
||||
: base(false)
|
||||
{
|
||||
if (buf.Length != KeySize)
|
||||
throw new ArgumentException("must have length " + KeySize, nameof(buf));
|
||||
|
||||
buf.CopyTo(data);
|
||||
}
|
||||
#endif
|
||||
|
||||
public Ed25519PublicKeyParameters(Stream input)
|
||||
: base(false)
|
||||
{
|
||||
if (KeySize != Streams.ReadFully(input, data))
|
||||
throw new EndOfStreamException("EOF encountered in middle of Ed25519 public key");
|
||||
}
|
||||
|
||||
public void Encode(byte[] buf, int off)
|
||||
{
|
||||
Array.Copy(data, 0, buf, off, KeySize);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void Encode(Span<byte> buf)
|
||||
{
|
||||
data.CopyTo(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
public byte[] GetEncoded()
|
||||
{
|
||||
return Arrays.Clone(data);
|
||||
}
|
||||
|
||||
private static byte[] Validate(byte[] buf)
|
||||
{
|
||||
if (buf.Length != KeySize)
|
||||
throw new ArgumentException("must have length " + KeySize, nameof(buf));
|
||||
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00027de267dcb674aaf6ee71fc7355d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class Ed448KeyGenerationParameters
|
||||
: KeyGenerationParameters
|
||||
{
|
||||
public Ed448KeyGenerationParameters(SecureRandom random)
|
||||
: base(random, 448)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca183f3e8332e2c4f9f2937aafc74f14
|
||||
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;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Rfc8032;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public sealed class Ed448PrivateKeyParameters
|
||||
: AsymmetricKeyParameter
|
||||
{
|
||||
public static readonly int KeySize = Ed448.SecretKeySize;
|
||||
public static readonly int SignatureSize = Ed448.SignatureSize;
|
||||
|
||||
private readonly byte[] data = new byte[KeySize];
|
||||
|
||||
private Ed448PublicKeyParameters cachedPublicKey;
|
||||
|
||||
public Ed448PrivateKeyParameters(SecureRandom random)
|
||||
: base(true)
|
||||
{
|
||||
Ed448.GeneratePrivateKey(random, data);
|
||||
}
|
||||
|
||||
public Ed448PrivateKeyParameters(byte[] buf)
|
||||
: this(Validate(buf), 0)
|
||||
{
|
||||
}
|
||||
|
||||
public Ed448PrivateKeyParameters(byte[] buf, int off)
|
||||
: base(true)
|
||||
{
|
||||
Array.Copy(buf, off, data, 0, KeySize);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public Ed448PrivateKeyParameters(ReadOnlySpan<byte> buf)
|
||||
: base(true)
|
||||
{
|
||||
if (buf.Length != KeySize)
|
||||
throw new ArgumentException("must have length " + KeySize, nameof(buf));
|
||||
|
||||
buf.CopyTo(data);
|
||||
}
|
||||
#endif
|
||||
|
||||
public Ed448PrivateKeyParameters(Stream input)
|
||||
: base(true)
|
||||
{
|
||||
if (KeySize != Streams.ReadFully(input, data))
|
||||
throw new EndOfStreamException("EOF encountered in middle of Ed448 private key");
|
||||
}
|
||||
|
||||
public void Encode(byte[] buf, int off)
|
||||
{
|
||||
Array.Copy(data, 0, buf, off, KeySize);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void Encode(Span<byte> buf)
|
||||
{
|
||||
data.CopyTo(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
public byte[] GetEncoded()
|
||||
{
|
||||
return Arrays.Clone(data);
|
||||
}
|
||||
|
||||
public Ed448PublicKeyParameters GeneratePublicKey()
|
||||
{
|
||||
lock (data)
|
||||
{
|
||||
if (null == cachedPublicKey)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
Span<byte> publicKey = stackalloc byte[Ed448.PublicKeySize];
|
||||
Ed448.GeneratePublicKey(data, publicKey);
|
||||
cachedPublicKey = new Ed448PublicKeyParameters(publicKey);
|
||||
#else
|
||||
byte[] publicKey = new byte[Ed448.PublicKeySize];
|
||||
Ed448.GeneratePublicKey(data, 0, publicKey, 0);
|
||||
cachedPublicKey = new Ed448PublicKeyParameters(publicKey, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
return cachedPublicKey;
|
||||
}
|
||||
}
|
||||
|
||||
public void Sign(Ed448.Algorithm algorithm, byte[] ctx, byte[] msg, int msgOff, int msgLen,
|
||||
byte[] sig, int sigOff)
|
||||
{
|
||||
Ed448PublicKeyParameters publicKey = GeneratePublicKey();
|
||||
|
||||
byte[] pk = new byte[Ed448.PublicKeySize];
|
||||
publicKey.Encode(pk, 0);
|
||||
|
||||
switch (algorithm)
|
||||
{
|
||||
case Ed448.Algorithm.Ed448:
|
||||
{
|
||||
Ed448.Sign(data, 0, pk, 0, ctx, msg, msgOff, msgLen, sig, sigOff);
|
||||
break;
|
||||
}
|
||||
case Ed448.Algorithm.Ed448ph:
|
||||
{
|
||||
if (Ed448.PrehashSize != msgLen)
|
||||
throw new ArgumentException("msgLen");
|
||||
|
||||
Ed448.SignPrehash(data, 0, pk, 0, ctx, msg, msgOff, sig, sigOff);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new ArgumentException("algorithm");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] Validate(byte[] buf)
|
||||
{
|
||||
if (buf.Length != KeySize)
|
||||
throw new ArgumentException("must have length " + KeySize, nameof(buf));
|
||||
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e80c036f0ed1150468d988bccd9bf6e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Rfc8032;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public sealed class Ed448PublicKeyParameters
|
||||
: AsymmetricKeyParameter
|
||||
{
|
||||
public static readonly int KeySize = Ed448.PublicKeySize;
|
||||
|
||||
private readonly byte[] data = new byte[KeySize];
|
||||
|
||||
public Ed448PublicKeyParameters(byte[] buf)
|
||||
: this(Validate(buf), 0)
|
||||
{
|
||||
}
|
||||
|
||||
public Ed448PublicKeyParameters(byte[] buf, int off)
|
||||
: base(false)
|
||||
{
|
||||
Array.Copy(buf, off, data, 0, KeySize);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public Ed448PublicKeyParameters(ReadOnlySpan<byte> buf)
|
||||
: base(false)
|
||||
{
|
||||
if (buf.Length != KeySize)
|
||||
throw new ArgumentException("must have length " + KeySize, nameof(buf));
|
||||
|
||||
buf.CopyTo(data);
|
||||
}
|
||||
#endif
|
||||
|
||||
public Ed448PublicKeyParameters(Stream input)
|
||||
: base(false)
|
||||
{
|
||||
if (KeySize != Streams.ReadFully(input, data))
|
||||
throw new EndOfStreamException("EOF encountered in middle of Ed448 public key");
|
||||
}
|
||||
|
||||
public void Encode(byte[] buf, int off)
|
||||
{
|
||||
Array.Copy(data, 0, buf, off, KeySize);
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public void Encode(Span<byte> buf)
|
||||
{
|
||||
data.CopyTo(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
public byte[] GetEncoded()
|
||||
{
|
||||
return Arrays.Clone(data);
|
||||
}
|
||||
|
||||
private static byte[] Validate(byte[] buf)
|
||||
{
|
||||
if (buf.Length != KeySize)
|
||||
throw new ArgumentException("must have length " + KeySize, nameof(buf));
|
||||
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d41d849b6de39ab4097a0118070a6501
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class ElGamalKeyGenerationParameters
|
||||
: KeyGenerationParameters
|
||||
{
|
||||
private readonly ElGamalParameters parameters;
|
||||
|
||||
public ElGamalKeyGenerationParameters(
|
||||
SecureRandom random,
|
||||
ElGamalParameters parameters)
|
||||
: base(random, GetStrength(parameters))
|
||||
{
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public ElGamalParameters Parameters
|
||||
{
|
||||
get { return parameters; }
|
||||
}
|
||||
|
||||
internal static int GetStrength(
|
||||
ElGamalParameters parameters)
|
||||
{
|
||||
return parameters.L != 0 ? parameters.L : parameters.P.BitLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cbe76ca416d843408bdcf7cb97e7e26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class ElGamalKeyParameters
|
||||
: AsymmetricKeyParameter
|
||||
{
|
||||
private readonly ElGamalParameters parameters;
|
||||
|
||||
protected ElGamalKeyParameters(
|
||||
bool isPrivate,
|
||||
ElGamalParameters parameters)
|
||||
: base(isPrivate)
|
||||
{
|
||||
// TODO Should we allow 'parameters' to be null?
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public ElGamalParameters Parameters
|
||||
{
|
||||
get { return parameters; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
ElGamalKeyParameters other = obj as ElGamalKeyParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
ElGamalKeyParameters other)
|
||||
{
|
||||
return Org.BouncyCastle.Utilities.Platform.Equals(parameters, other.parameters)
|
||||
&& base.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hc = base.GetHashCode();
|
||||
|
||||
if (parameters != null)
|
||||
{
|
||||
hc ^= parameters.GetHashCode();
|
||||
}
|
||||
|
||||
return hc;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5f8fc98b8b5b6040b86e89ee29cd13e
|
||||
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 Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class ElGamalParameters
|
||||
: ICipherParameters
|
||||
{
|
||||
private readonly BigInteger p, g;
|
||||
private readonly int l;
|
||||
|
||||
public ElGamalParameters(
|
||||
BigInteger p,
|
||||
BigInteger g)
|
||||
: this(p, g, 0)
|
||||
{
|
||||
}
|
||||
|
||||
public ElGamalParameters(
|
||||
BigInteger p,
|
||||
BigInteger g,
|
||||
int l)
|
||||
{
|
||||
if (p == null)
|
||||
throw new ArgumentNullException("p");
|
||||
if (g == null)
|
||||
throw new ArgumentNullException("g");
|
||||
|
||||
this.p = p;
|
||||
this.g = g;
|
||||
this.l = l;
|
||||
}
|
||||
|
||||
public BigInteger P
|
||||
{
|
||||
get { return p; }
|
||||
}
|
||||
|
||||
/**
|
||||
* return the generator - g
|
||||
*/
|
||||
public BigInteger G
|
||||
{
|
||||
get { return g; }
|
||||
}
|
||||
|
||||
/**
|
||||
* return private value limit - l
|
||||
*/
|
||||
public int L
|
||||
{
|
||||
get { return l; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
ElGamalParameters other = obj as ElGamalParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
ElGamalParameters other)
|
||||
{
|
||||
return p.Equals(other.p) && g.Equals(other.g) && l == other.l;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return p.GetHashCode() ^ g.GetHashCode() ^ l;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f82b60239473f6c4eaf26fe31a2769ae
|
||||
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;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class ElGamalPrivateKeyParameters
|
||||
: ElGamalKeyParameters
|
||||
{
|
||||
private readonly BigInteger x;
|
||||
|
||||
public ElGamalPrivateKeyParameters(
|
||||
BigInteger x,
|
||||
ElGamalParameters parameters)
|
||||
: base(true, parameters)
|
||||
{
|
||||
if (x == null)
|
||||
throw new ArgumentNullException("x");
|
||||
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public BigInteger X
|
||||
{
|
||||
get { return x; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
ElGamalPrivateKeyParameters other = obj as ElGamalPrivateKeyParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
ElGamalPrivateKeyParameters other)
|
||||
{
|
||||
return other.x.Equals(x) && base.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return x.GetHashCode() ^ base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8376daa59333e74da0e0e318afe938c
|
||||
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;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class ElGamalPublicKeyParameters
|
||||
: ElGamalKeyParameters
|
||||
{
|
||||
private readonly BigInteger y;
|
||||
|
||||
public ElGamalPublicKeyParameters(
|
||||
BigInteger y,
|
||||
ElGamalParameters parameters)
|
||||
: base(false, parameters)
|
||||
{
|
||||
if (y == null)
|
||||
throw new ArgumentNullException("y");
|
||||
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public BigInteger Y
|
||||
{
|
||||
get { return y; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
ElGamalPublicKeyParameters other = obj as ElGamalPublicKeyParameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
ElGamalPublicKeyParameters other)
|
||||
{
|
||||
return y.Equals(other.y) && base.Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return y.GetHashCode() ^ base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cbffddbeeb8e6d4688e77ee8f55859c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/FpeParameters.cs
vendored
Normal file
53
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/FpeParameters.cs
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public sealed class FpeParameters
|
||||
: ICipherParameters
|
||||
{
|
||||
private readonly KeyParameter key;
|
||||
private readonly int radix;
|
||||
private readonly byte[] tweak;
|
||||
private readonly bool useInverse;
|
||||
|
||||
public FpeParameters(KeyParameter key, int radix, byte[] tweak): this(key, radix, tweak, false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public FpeParameters(KeyParameter key, int radix, byte[] tweak, bool useInverse)
|
||||
{
|
||||
this.key = key;
|
||||
this.radix = radix;
|
||||
this.tweak = Arrays.Clone(tweak);
|
||||
this.useInverse = useInverse;
|
||||
}
|
||||
|
||||
public KeyParameter Key
|
||||
{
|
||||
get { return key; }
|
||||
}
|
||||
|
||||
public int Radix
|
||||
{
|
||||
get { return radix; }
|
||||
}
|
||||
|
||||
public bool UseInverseFunction
|
||||
{
|
||||
get { return useInverse; }
|
||||
}
|
||||
|
||||
public byte[] GetTweak()
|
||||
{
|
||||
return Arrays.Clone(tweak);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cf0e065190672743a91d89fe20f38aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class Gost3410KeyGenerationParameters
|
||||
: KeyGenerationParameters
|
||||
{
|
||||
private readonly Gost3410Parameters parameters;
|
||||
private readonly DerObjectIdentifier publicKeyParamSet;
|
||||
|
||||
public Gost3410KeyGenerationParameters(
|
||||
SecureRandom random,
|
||||
Gost3410Parameters parameters)
|
||||
: base(random, parameters.P.BitLength - 1)
|
||||
{
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public Gost3410KeyGenerationParameters(
|
||||
SecureRandom random,
|
||||
DerObjectIdentifier publicKeyParamSet)
|
||||
: this(random, LookupParameters(publicKeyParamSet))
|
||||
{
|
||||
this.publicKeyParamSet = publicKeyParamSet;
|
||||
}
|
||||
|
||||
public Gost3410Parameters Parameters
|
||||
{
|
||||
get { return parameters; }
|
||||
}
|
||||
|
||||
public DerObjectIdentifier PublicKeyParamSet
|
||||
{
|
||||
get { return publicKeyParamSet; }
|
||||
}
|
||||
|
||||
private static Gost3410Parameters LookupParameters(
|
||||
DerObjectIdentifier publicKeyParamSet)
|
||||
{
|
||||
if (publicKeyParamSet == null)
|
||||
throw new ArgumentNullException("publicKeyParamSet");
|
||||
|
||||
Gost3410ParamSetParameters p = Gost3410NamedParameters.GetByOid(publicKeyParamSet);
|
||||
|
||||
if (p == null)
|
||||
throw new ArgumentException("OID is not a valid CryptoPro public key parameter set", "publicKeyParamSet");
|
||||
|
||||
return new Gost3410Parameters(p.P, p.Q, p.A);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa2bcc504b468e1448e19e919827c4f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public abstract class Gost3410KeyParameters
|
||||
: AsymmetricKeyParameter
|
||||
{
|
||||
private readonly Gost3410Parameters parameters;
|
||||
private readonly DerObjectIdentifier publicKeyParamSet;
|
||||
|
||||
protected Gost3410KeyParameters(
|
||||
bool isPrivate,
|
||||
Gost3410Parameters parameters)
|
||||
: base(isPrivate)
|
||||
{
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
protected Gost3410KeyParameters(
|
||||
bool isPrivate,
|
||||
DerObjectIdentifier publicKeyParamSet)
|
||||
: base(isPrivate)
|
||||
{
|
||||
this.parameters = LookupParameters(publicKeyParamSet);
|
||||
this.publicKeyParamSet = publicKeyParamSet;
|
||||
}
|
||||
|
||||
public Gost3410Parameters Parameters
|
||||
{
|
||||
get { return parameters; }
|
||||
}
|
||||
|
||||
public DerObjectIdentifier PublicKeyParamSet
|
||||
{
|
||||
get { return publicKeyParamSet; }
|
||||
}
|
||||
|
||||
// TODO Implement Equals/GetHashCode
|
||||
|
||||
private static Gost3410Parameters LookupParameters(
|
||||
DerObjectIdentifier publicKeyParamSet)
|
||||
{
|
||||
if (publicKeyParamSet == null)
|
||||
throw new ArgumentNullException("publicKeyParamSet");
|
||||
|
||||
Gost3410ParamSetParameters p = Gost3410NamedParameters.GetByOid(publicKeyParamSet);
|
||||
|
||||
if (p == null)
|
||||
throw new ArgumentException("OID is not a valid CryptoPro public key parameter set", "publicKeyParamSet");
|
||||
|
||||
return new Gost3410Parameters(p.P, p.Q, p.A);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bce9018e6fa82c46971a8d7c758ceae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,90 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class Gost3410Parameters
|
||||
: ICipherParameters
|
||||
{
|
||||
private readonly BigInteger p, q, a;
|
||||
private readonly Gost3410ValidationParameters validation;
|
||||
|
||||
public Gost3410Parameters(
|
||||
BigInteger p,
|
||||
BigInteger q,
|
||||
BigInteger a)
|
||||
: this(p, q, a, null)
|
||||
{
|
||||
}
|
||||
|
||||
public Gost3410Parameters(
|
||||
BigInteger p,
|
||||
BigInteger q,
|
||||
BigInteger a,
|
||||
Gost3410ValidationParameters validation)
|
||||
{
|
||||
if (p == null)
|
||||
throw new ArgumentNullException("p");
|
||||
if (q == null)
|
||||
throw new ArgumentNullException("q");
|
||||
if (a == null)
|
||||
throw new ArgumentNullException("a");
|
||||
|
||||
this.p = p;
|
||||
this.q = q;
|
||||
this.a = a;
|
||||
this.validation = validation;
|
||||
}
|
||||
|
||||
public BigInteger P
|
||||
{
|
||||
get { return p; }
|
||||
}
|
||||
|
||||
public BigInteger Q
|
||||
{
|
||||
get { return q; }
|
||||
}
|
||||
|
||||
public BigInteger A
|
||||
{
|
||||
get { return a; }
|
||||
}
|
||||
|
||||
public Gost3410ValidationParameters ValidationParameters
|
||||
{
|
||||
get { return validation; }
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
Gost3410Parameters other = obj as Gost3410Parameters;
|
||||
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
protected bool Equals(
|
||||
Gost3410Parameters other)
|
||||
{
|
||||
return p.Equals(other.p) && q.Equals(other.q) && a.Equals(other.a);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return p.GetHashCode() ^ q.GetHashCode() ^ a.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c76b526088c176142b7a57dc7fc287ed
|
||||
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 Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class Gost3410PrivateKeyParameters
|
||||
: Gost3410KeyParameters
|
||||
{
|
||||
private readonly BigInteger x;
|
||||
|
||||
public Gost3410PrivateKeyParameters(
|
||||
BigInteger x,
|
||||
Gost3410Parameters parameters)
|
||||
: base(true, parameters)
|
||||
{
|
||||
if (x.SignValue < 1 || x.BitLength > 256 || x.CompareTo(Parameters.Q) >= 0)
|
||||
throw new ArgumentException("Invalid x for GOST3410 private key", "x");
|
||||
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public Gost3410PrivateKeyParameters(
|
||||
BigInteger x,
|
||||
DerObjectIdentifier publicKeyParamSet)
|
||||
: base(true, publicKeyParamSet)
|
||||
{
|
||||
if (x.SignValue < 1 || x.BitLength > 256 || x.CompareTo(Parameters.Q) >= 0)
|
||||
throw new ArgumentException("Invalid x for GOST3410 private key", "x");
|
||||
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public BigInteger X
|
||||
{
|
||||
get { return x; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fced898f49591d54e900e6aeca0edf70
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class Gost3410PublicKeyParameters
|
||||
: Gost3410KeyParameters
|
||||
{
|
||||
private readonly BigInteger y;
|
||||
|
||||
public Gost3410PublicKeyParameters(
|
||||
BigInteger y,
|
||||
Gost3410Parameters parameters)
|
||||
: base(false, parameters)
|
||||
{
|
||||
if (y.SignValue < 1 || y.CompareTo(Parameters.P) >= 0)
|
||||
throw new ArgumentException("Invalid y for GOST3410 public key", "y");
|
||||
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Gost3410PublicKeyParameters(
|
||||
BigInteger y,
|
||||
DerObjectIdentifier publicKeyParamSet)
|
||||
: base(false, publicKeyParamSet)
|
||||
{
|
||||
if (y.SignValue < 1 || y.CompareTo(Parameters.P) >= 0)
|
||||
throw new ArgumentException("Invalid y for GOST3410 public key", "y");
|
||||
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public BigInteger Y
|
||||
{
|
||||
get { return y; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea3b8a6815e38384a8268540bc923098
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class Gost3410ValidationParameters
|
||||
{
|
||||
private int x0;
|
||||
private int c;
|
||||
private long x0L;
|
||||
private long cL;
|
||||
|
||||
public Gost3410ValidationParameters(
|
||||
int x0,
|
||||
int c)
|
||||
{
|
||||
this.x0 = x0;
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
public Gost3410ValidationParameters(
|
||||
long x0L,
|
||||
long cL)
|
||||
{
|
||||
this.x0L = x0L;
|
||||
this.cL = cL;
|
||||
}
|
||||
|
||||
public int C { get { return c; } }
|
||||
public int X0 { get { return x0; } }
|
||||
public long CL { get { return cL; } }
|
||||
public long X0L { get { return x0L; } }
|
||||
|
||||
public override bool Equals(
|
||||
object obj)
|
||||
{
|
||||
Gost3410ValidationParameters other = obj as Gost3410ValidationParameters;
|
||||
|
||||
return other != null
|
||||
&& other.c == this.c
|
||||
&& other.x0 == this.x0
|
||||
&& other.cL == this.cL
|
||||
&& other.x0L == this.x0L;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return c.GetHashCode() ^ x0.GetHashCode() ^ cL.GetHashCode() ^ x0L.GetHashCode();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb8255e8c52a110438fe7242f1d219bb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
123
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/HKDFParameters.cs
vendored
Normal file
123
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/HKDFParameters.cs
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Macs;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
/**
|
||||
* Parameter class for the HkdfBytesGenerator class.
|
||||
*/
|
||||
public class HkdfParameters
|
||||
: IDerivationParameters
|
||||
{
|
||||
private readonly byte[] ikm;
|
||||
private readonly bool skipExpand;
|
||||
private readonly byte[] salt;
|
||||
private readonly byte[] info;
|
||||
|
||||
private HkdfParameters(byte[] ikm, bool skip, byte[] salt, byte[] info)
|
||||
{
|
||||
if (ikm == null)
|
||||
throw new ArgumentNullException("ikm");
|
||||
|
||||
this.ikm = Arrays.Clone(ikm);
|
||||
this.skipExpand = skip;
|
||||
|
||||
if (salt == null || salt.Length == 0)
|
||||
{
|
||||
this.salt = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.salt = Arrays.Clone(salt);
|
||||
}
|
||||
|
||||
if (info == null)
|
||||
{
|
||||
this.info = new byte[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
this.info = Arrays.Clone(info);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates parameters for HKDF, specifying both the optional salt and
|
||||
* optional info. Step 1: Extract won't be skipped.
|
||||
*
|
||||
* @param ikm the input keying material or seed
|
||||
* @param salt the salt to use, may be null for a salt for hashLen zeros
|
||||
* @param info the info to use, may be null for an info field of zero bytes
|
||||
*/
|
||||
public HkdfParameters(byte[] ikm, byte[] salt, byte[] info)
|
||||
: this(ikm, false, salt, info)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method that makes the HKDF skip the extract part of the key
|
||||
* derivation function.
|
||||
*
|
||||
* @param ikm the input keying material or seed, directly used for step 2:
|
||||
* Expand
|
||||
* @param info the info to use, may be null for an info field of zero bytes
|
||||
* @return HKDFParameters that makes the implementation skip step 1
|
||||
*/
|
||||
public static HkdfParameters SkipExtractParameters(byte[] ikm, byte[] info)
|
||||
{
|
||||
return new HkdfParameters(ikm, true, null, info);
|
||||
}
|
||||
|
||||
public static HkdfParameters DefaultParameters(byte[] ikm)
|
||||
{
|
||||
return new HkdfParameters(ikm, false, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the input keying material or seed.
|
||||
*
|
||||
* @return the keying material
|
||||
*/
|
||||
public virtual byte[] GetIkm()
|
||||
{
|
||||
return Arrays.Clone(ikm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if step 1: extract has to be skipped or not
|
||||
*
|
||||
* @return true for skipping, false for no skipping of step 1
|
||||
*/
|
||||
public virtual bool SkipExtract
|
||||
{
|
||||
get { return skipExpand; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the salt, or null if the salt should be generated as a byte array
|
||||
* of HashLen zeros.
|
||||
*
|
||||
* @return the salt, or null
|
||||
*/
|
||||
public virtual byte[] GetSalt()
|
||||
{
|
||||
return Arrays.Clone(salt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the info field, which may be empty (null is converted to empty).
|
||||
*
|
||||
* @return the info field, never null
|
||||
*/
|
||||
public virtual byte[] GetInfo()
|
||||
{
|
||||
return Arrays.Clone(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 618066ec4d1149247b2627394c92c7c1
|
||||
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;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
/**
|
||||
* parameters for Key derivation functions for ISO-18033
|
||||
*/
|
||||
public class Iso18033KdfParameters
|
||||
: IDerivationParameters
|
||||
{
|
||||
byte[] seed;
|
||||
|
||||
public Iso18033KdfParameters(
|
||||
byte[] seed)
|
||||
{
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
public byte[] GetSeed()
|
||||
{
|
||||
return seed;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb1c0ce7c88f0ab42a3b1173a3fd0155
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/IesParameters.cs
vendored
Normal file
53
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/IesParameters.cs
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
/**
|
||||
* parameters for using an integrated cipher in stream mode.
|
||||
*/
|
||||
public class IesParameters : ICipherParameters
|
||||
{
|
||||
private byte[] derivation;
|
||||
private byte[] encoding;
|
||||
private int macKeySize;
|
||||
|
||||
/**
|
||||
* @param derivation the derivation parameter for the KDF function.
|
||||
* @param encoding the encoding parameter for the KDF function.
|
||||
* @param macKeySize the size of the MAC key (in bits).
|
||||
*/
|
||||
public IesParameters(
|
||||
byte[] derivation,
|
||||
byte[] encoding,
|
||||
int macKeySize)
|
||||
{
|
||||
this.derivation = derivation;
|
||||
this.encoding = encoding;
|
||||
this.macKeySize = macKeySize;
|
||||
}
|
||||
|
||||
public byte[] GetDerivationV()
|
||||
{
|
||||
return derivation;
|
||||
}
|
||||
|
||||
public byte[] GetEncodingV()
|
||||
{
|
||||
return encoding;
|
||||
}
|
||||
|
||||
public int MacKeySize
|
||||
{
|
||||
get
|
||||
{
|
||||
return macKeySize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13b5c4ee94d0a304daec7d5d3c6fa887
|
||||
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 Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class IesWithCipherParameters : IesParameters
|
||||
{
|
||||
private int cipherKeySize;
|
||||
|
||||
/**
|
||||
* @param derivation the derivation parameter for the KDF function.
|
||||
* @param encoding the encoding parameter for the KDF function.
|
||||
* @param macKeySize the size of the MAC key (in bits).
|
||||
* @param cipherKeySize the size of the associated Cipher key (in bits).
|
||||
*/
|
||||
public IesWithCipherParameters(
|
||||
byte[] derivation,
|
||||
byte[] encoding,
|
||||
int macKeySize,
|
||||
int cipherKeySize) : base(derivation, encoding, macKeySize)
|
||||
{
|
||||
this.cipherKeySize = cipherKeySize;
|
||||
}
|
||||
|
||||
public int CipherKeySize
|
||||
{
|
||||
get
|
||||
{
|
||||
return cipherKeySize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c95875d41a1abe049a44781c61cbceee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class KdfCounterParameters : IDerivationParameters
|
||||
{
|
||||
private byte[] ki;
|
||||
private byte[] fixedInputDataCounterPrefix;
|
||||
private byte[] fixedInputDataCounterSuffix;
|
||||
private int r;
|
||||
|
||||
/// <summary>
|
||||
/// Base constructor - suffix fixed input data only.
|
||||
/// </summary>
|
||||
/// <param name="ki">the KDF seed</param>
|
||||
/// <param name="fixedInputDataCounterSuffix">fixed input data to follow counter.</param>
|
||||
/// <param name="r">length of the counter in bits</param>
|
||||
public KdfCounterParameters(byte[] ki, byte[] fixedInputDataCounterSuffix, int r) : this(ki, null, fixedInputDataCounterSuffix, r)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Base constructor - prefix and suffix fixed input data.
|
||||
/// </summary>
|
||||
/// <param name="ki">the KDF seed</param>
|
||||
/// <param name="fixedInputDataCounterPrefix">fixed input data to precede counter</param>
|
||||
/// <param name="fixedInputDataCounterSuffix">fixed input data to follow counter.</param>
|
||||
/// <param name="r">length of the counter in bits.</param>
|
||||
public KdfCounterParameters(byte[] ki, byte[] fixedInputDataCounterPrefix, byte[] fixedInputDataCounterSuffix, int r)
|
||||
{
|
||||
if (ki == null)
|
||||
{
|
||||
throw new ArgumentException("A KDF requires Ki (a seed) as input");
|
||||
}
|
||||
this.ki = Arrays.Clone(ki);
|
||||
|
||||
if (fixedInputDataCounterPrefix == null)
|
||||
{
|
||||
this.fixedInputDataCounterPrefix = new byte[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
this.fixedInputDataCounterPrefix = Arrays.Clone(fixedInputDataCounterPrefix);
|
||||
}
|
||||
|
||||
if (fixedInputDataCounterSuffix == null)
|
||||
{
|
||||
this.fixedInputDataCounterSuffix = new byte[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
this.fixedInputDataCounterSuffix = Arrays.Clone(fixedInputDataCounterSuffix);
|
||||
}
|
||||
|
||||
if (r != 8 && r != 16 && r != 24 && r != 32)
|
||||
{
|
||||
throw new ArgumentException("Length of counter should be 8, 16, 24 or 32");
|
||||
}
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public byte[] Ki
|
||||
{
|
||||
get { return ki; }
|
||||
}
|
||||
|
||||
public byte[] FixedInputData
|
||||
{
|
||||
get { return Arrays.Clone(fixedInputDataCounterSuffix); }
|
||||
}
|
||||
|
||||
public byte[] FixedInputDataCounterPrefix
|
||||
{
|
||||
get { return Arrays.Clone(fixedInputDataCounterPrefix); }
|
||||
|
||||
}
|
||||
|
||||
public byte[] FixedInputDataCounterSuffix
|
||||
{
|
||||
get { return Arrays.Clone(fixedInputDataCounterSuffix); }
|
||||
}
|
||||
|
||||
public int R
|
||||
{
|
||||
get { return r; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b1c331d894cfb24dab25bdf2cd012b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,81 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class KdfDoublePipelineIterationParameters : IDerivationParameters
|
||||
{
|
||||
// could be any valid value, using 32, don't know why
|
||||
private static readonly int UNUSED_R = 32;
|
||||
|
||||
private readonly byte[] ki;
|
||||
private readonly bool useCounter;
|
||||
private readonly int r;
|
||||
private readonly byte[] fixedInputData;
|
||||
|
||||
private KdfDoublePipelineIterationParameters(byte[] ki, byte[] fixedInputData, int r, bool useCounter)
|
||||
{
|
||||
if (ki == null)
|
||||
{
|
||||
throw new ArgumentException("A KDF requires Ki (a seed) as input");
|
||||
}
|
||||
|
||||
this.ki = Arrays.Clone(ki);
|
||||
|
||||
if (fixedInputData == null)
|
||||
{
|
||||
this.fixedInputData = new byte[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
this.fixedInputData = Arrays.Clone(fixedInputData);
|
||||
}
|
||||
|
||||
if (r != 8 && r != 16 && r != 24 && r != 32)
|
||||
{
|
||||
throw new ArgumentException("Length of counter should be 8, 16, 24 or 32");
|
||||
}
|
||||
|
||||
this.r = r;
|
||||
|
||||
this.useCounter = useCounter;
|
||||
}
|
||||
|
||||
public static KdfDoublePipelineIterationParameters CreateWithCounter(
|
||||
byte[] ki, byte[] fixedInputData, int r)
|
||||
{
|
||||
return new KdfDoublePipelineIterationParameters(ki, fixedInputData, r, true);
|
||||
}
|
||||
|
||||
public static KdfDoublePipelineIterationParameters CreateWithoutCounter(
|
||||
byte[] ki, byte[] fixedInputData)
|
||||
{
|
||||
return new KdfDoublePipelineIterationParameters(ki, fixedInputData, UNUSED_R, false);
|
||||
}
|
||||
|
||||
public byte[] Ki
|
||||
{
|
||||
get { return Arrays.Clone(ki); }
|
||||
}
|
||||
|
||||
public bool UseCounter
|
||||
{
|
||||
get { return useCounter; }
|
||||
}
|
||||
|
||||
public int R
|
||||
{
|
||||
get { return r; }
|
||||
}
|
||||
|
||||
public byte[] FixedInputData
|
||||
{
|
||||
get { return Arrays.Clone(fixedInputData); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b0f484687c01d6479fba10e557737e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
public class KdfFeedbackParameters : IDerivationParameters
|
||||
{
|
||||
// could be any valid value, using 32, don't know why
|
||||
private static readonly int UNUSED_R = -1;
|
||||
|
||||
private readonly byte[] ki;
|
||||
private readonly byte[] iv;
|
||||
private readonly bool useCounter;
|
||||
private readonly int r;
|
||||
private readonly byte[] fixedInputData;
|
||||
|
||||
private KdfFeedbackParameters(byte[] ki, byte[] iv, byte[] fixedInputData, int r, bool useCounter)
|
||||
{
|
||||
if (ki == null)
|
||||
{
|
||||
throw new ArgumentException("A KDF requires Ki (a seed) as input");
|
||||
}
|
||||
|
||||
this.ki = Arrays.Clone(ki);
|
||||
|
||||
if (fixedInputData == null)
|
||||
{
|
||||
this.fixedInputData = new byte[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
this.fixedInputData = Arrays.Clone(fixedInputData);
|
||||
}
|
||||
|
||||
this.r = r;
|
||||
|
||||
if (iv == null)
|
||||
{
|
||||
this.iv = new byte[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
this.iv = Arrays.Clone(iv);
|
||||
}
|
||||
|
||||
this.useCounter = useCounter;
|
||||
}
|
||||
|
||||
public static KdfFeedbackParameters CreateWithCounter(
|
||||
byte[] ki, byte[] iv, byte[] fixedInputData, int r)
|
||||
{
|
||||
if (r != 8 && r != 16 && r != 24 && r != 32)
|
||||
{
|
||||
throw new ArgumentException("Length of counter should be 8, 16, 24 or 32");
|
||||
}
|
||||
|
||||
return new KdfFeedbackParameters(ki, iv, fixedInputData, r, true);
|
||||
}
|
||||
|
||||
public static KdfFeedbackParameters CreateWithoutCounter(
|
||||
byte[] ki, byte[] iv, byte[] fixedInputData)
|
||||
{
|
||||
return new KdfFeedbackParameters(ki, iv, fixedInputData, UNUSED_R, false);
|
||||
}
|
||||
|
||||
public byte[] Ki
|
||||
{
|
||||
get { return Arrays.Clone(ki); }
|
||||
}
|
||||
|
||||
public byte[] Iv
|
||||
{
|
||||
get { return Arrays.Clone(iv); }
|
||||
}
|
||||
|
||||
public bool UseCounter
|
||||
{
|
||||
get { return useCounter; }
|
||||
}
|
||||
|
||||
public int R
|
||||
{
|
||||
get { return r; }
|
||||
}
|
||||
|
||||
public byte[] FixedInputData
|
||||
{
|
||||
get { return Arrays.Clone(fixedInputData); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75e9f629f8000fa4b849c630e7fabc63
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/KdfParameters.cs
vendored
Normal file
35
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/parameters/KdfParameters.cs
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
|
||||
{
|
||||
/**
|
||||
* parameters for Key derivation functions for IEEE P1363a
|
||||
*/
|
||||
public class KdfParameters
|
||||
: IDerivationParameters
|
||||
{
|
||||
private readonly byte[] m_iv;
|
||||
private readonly byte[] m_shared;
|
||||
|
||||
public KdfParameters(byte[] shared, byte[] iv)
|
||||
{
|
||||
m_shared = shared;
|
||||
m_iv = iv;
|
||||
}
|
||||
|
||||
public byte[] GetSharedSecret()
|
||||
{
|
||||
return m_shared;
|
||||
}
|
||||
|
||||
public byte[] GetIV()
|
||||
{
|
||||
return m_iv;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06b2e18be3f3dd94e9a2cf97336c13d6
|
||||
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