add all
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
#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.Kisa;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Misc;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ntt;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities
|
||||
{
|
||||
public class AlgorithmIdentifierFactory
|
||||
{
|
||||
public static readonly DerObjectIdentifier IDEA_CBC = new DerObjectIdentifier("1.3.6.1.4.1.188.7.1.1.2");
|
||||
public static readonly DerObjectIdentifier CAST5_CBC = new DerObjectIdentifier("1.2.840.113533.7.66.10");
|
||||
|
||||
private static readonly short[] rc2Table = {
|
||||
0xbd, 0x56, 0xea, 0xf2, 0xa2, 0xf1, 0xac, 0x2a, 0xb0, 0x93, 0xd1, 0x9c, 0x1b, 0x33, 0xfd, 0xd0,
|
||||
0x30, 0x04, 0xb6, 0xdc, 0x7d, 0xdf, 0x32, 0x4b, 0xf7, 0xcb, 0x45, 0x9b, 0x31, 0xbb, 0x21, 0x5a,
|
||||
0x41, 0x9f, 0xe1, 0xd9, 0x4a, 0x4d, 0x9e, 0xda, 0xa0, 0x68, 0x2c, 0xc3, 0x27, 0x5f, 0x80, 0x36,
|
||||
0x3e, 0xee, 0xfb, 0x95, 0x1a, 0xfe, 0xce, 0xa8, 0x34, 0xa9, 0x13, 0xf0, 0xa6, 0x3f, 0xd8, 0x0c,
|
||||
0x78, 0x24, 0xaf, 0x23, 0x52, 0xc1, 0x67, 0x17, 0xf5, 0x66, 0x90, 0xe7, 0xe8, 0x07, 0xb8, 0x60,
|
||||
0x48, 0xe6, 0x1e, 0x53, 0xf3, 0x92, 0xa4, 0x72, 0x8c, 0x08, 0x15, 0x6e, 0x86, 0x00, 0x84, 0xfa,
|
||||
0xf4, 0x7f, 0x8a, 0x42, 0x19, 0xf6, 0xdb, 0xcd, 0x14, 0x8d, 0x50, 0x12, 0xba, 0x3c, 0x06, 0x4e,
|
||||
0xec, 0xb3, 0x35, 0x11, 0xa1, 0x88, 0x8e, 0x2b, 0x94, 0x99, 0xb7, 0x71, 0x74, 0xd3, 0xe4, 0xbf,
|
||||
0x3a, 0xde, 0x96, 0x0e, 0xbc, 0x0a, 0xed, 0x77, 0xfc, 0x37, 0x6b, 0x03, 0x79, 0x89, 0x62, 0xc6,
|
||||
0xd7, 0xc0, 0xd2, 0x7c, 0x6a, 0x8b, 0x22, 0xa3, 0x5b, 0x05, 0x5d, 0x02, 0x75, 0xd5, 0x61, 0xe3,
|
||||
0x18, 0x8f, 0x55, 0x51, 0xad, 0x1f, 0x0b, 0x5e, 0x85, 0xe5, 0xc2, 0x57, 0x63, 0xca, 0x3d, 0x6c,
|
||||
0xb4, 0xc5, 0xcc, 0x70, 0xb2, 0x91, 0x59, 0x0d, 0x47, 0x20, 0xc8, 0x4f, 0x58, 0xe0, 0x01, 0xe2,
|
||||
0x16, 0x38, 0xc4, 0x6f, 0x3b, 0x0f, 0x65, 0x46, 0xbe, 0x7e, 0x2d, 0x7b, 0x82, 0xf9, 0x40, 0xb5,
|
||||
0x1d, 0x73, 0xf8, 0xeb, 0x26, 0xc7, 0x87, 0x97, 0x25, 0x54, 0xb1, 0x28, 0xaa, 0x98, 0x9d, 0xa5,
|
||||
0x64, 0x6d, 0x7a, 0xd4, 0x10, 0x81, 0x44, 0xef, 0x49, 0xd6, 0xae, 0x2e, 0xdd, 0x76, 0x5c, 0x2f,
|
||||
0xa7, 0x1c, 0xc9, 0x09, 0x69, 0x9a, 0x83, 0xcf, 0x29, 0x39, 0xb9, 0xe9, 0x4c, 0xff, 0x43, 0xab
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create an AlgorithmIdentifier for the passed in encryption algorithm.
|
||||
*
|
||||
* @param encryptionOID OID for the encryption algorithm
|
||||
* @param keySize key size in bits (-1 if unknown)
|
||||
* @param random SecureRandom to use for parameter generation.
|
||||
* @return a full AlgorithmIdentifier including parameters
|
||||
* @throws IllegalArgumentException if encryptionOID cannot be matched
|
||||
*/
|
||||
public static AlgorithmIdentifier GenerateEncryptionAlgID(DerObjectIdentifier encryptionOID, int keySize, SecureRandom random)
|
||||
|
||||
{
|
||||
if (encryptionOID.Equals(NistObjectIdentifiers.IdAes128Cbc)
|
||||
|| encryptionOID.Equals(NistObjectIdentifiers.IdAes192Cbc)
|
||||
|| encryptionOID.Equals(NistObjectIdentifiers.IdAes256Cbc)
|
||||
|| encryptionOID.Equals(NttObjectIdentifiers.IdCamellia128Cbc)
|
||||
|| encryptionOID.Equals(NttObjectIdentifiers.IdCamellia192Cbc)
|
||||
|| encryptionOID.Equals(NttObjectIdentifiers.IdCamellia256Cbc)
|
||||
|| encryptionOID.Equals(KisaObjectIdentifiers.IdSeedCbc))
|
||||
{
|
||||
byte[] iv = new byte[16];
|
||||
|
||||
random.NextBytes(iv);
|
||||
|
||||
return new AlgorithmIdentifier(encryptionOID, new DerOctetString(iv));
|
||||
}
|
||||
else if (encryptionOID.Equals(PkcsObjectIdentifiers.DesEde3Cbc)
|
||||
|| encryptionOID.Equals(IDEA_CBC)
|
||||
|| encryptionOID.Equals(OiwObjectIdentifiers.DesCbc))
|
||||
{
|
||||
byte[] iv = new byte[8];
|
||||
|
||||
random.NextBytes(iv);
|
||||
|
||||
return new AlgorithmIdentifier(encryptionOID, new DerOctetString(iv));
|
||||
}
|
||||
else if (encryptionOID.Equals(CAST5_CBC))
|
||||
{
|
||||
byte[] iv = new byte[8];
|
||||
|
||||
random.NextBytes(iv);
|
||||
|
||||
Cast5CbcParameters cbcParams = new Cast5CbcParameters(iv, keySize);
|
||||
|
||||
return new AlgorithmIdentifier(encryptionOID, cbcParams);
|
||||
}
|
||||
else if (encryptionOID.Equals(PkcsObjectIdentifiers.rc4))
|
||||
{
|
||||
return new AlgorithmIdentifier(encryptionOID, DerNull.Instance);
|
||||
}
|
||||
else if (encryptionOID.Equals(PkcsObjectIdentifiers.RC2Cbc))
|
||||
{
|
||||
byte[] iv = new byte[8];
|
||||
|
||||
random.NextBytes(iv);
|
||||
|
||||
RC2CbcParameter cbcParams = new RC2CbcParameter(rc2Table[128], iv);
|
||||
|
||||
return new AlgorithmIdentifier(encryptionOID, cbcParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("unable to match algorithm");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d9d23d4907245041a87a26c0795cea2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
112
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/util/BasicAlphabetMapper.cs
vendored
Normal file
112
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/util/BasicAlphabetMapper.cs
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities
|
||||
{
|
||||
/**
|
||||
* A basic alphabet mapper that just creates a mapper based on the
|
||||
* passed in array of characters.
|
||||
*/
|
||||
public class BasicAlphabetMapper
|
||||
: IAlphabetMapper
|
||||
{
|
||||
private readonly IDictionary<char, int> m_indexMap = new Dictionary<char, int>();
|
||||
private readonly IList<char> m_charMap = new List<char>();
|
||||
|
||||
/**
|
||||
* Base constructor.
|
||||
*
|
||||
* @param alphabet a string of characters making up the alphabet.
|
||||
*/
|
||||
public BasicAlphabetMapper(string alphabet) :
|
||||
this(alphabet.ToCharArray())
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Base constructor.
|
||||
*
|
||||
* @param alphabet an array of characters making up the alphabet.
|
||||
*/
|
||||
public BasicAlphabetMapper(char[] alphabet)
|
||||
{
|
||||
for (int i = 0; i != alphabet.Length; i++)
|
||||
{
|
||||
if (m_indexMap.ContainsKey(alphabet[i]))
|
||||
throw new ArgumentException("duplicate key detected in alphabet: " + alphabet[i]);
|
||||
|
||||
m_indexMap.Add(alphabet[i], i);
|
||||
m_charMap.Add(alphabet[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public int Radix
|
||||
{
|
||||
get { return m_charMap.Count; }
|
||||
}
|
||||
|
||||
public byte[] ConvertToIndexes(char[] input)
|
||||
{
|
||||
byte[] outBuf;
|
||||
|
||||
if (m_charMap.Count <= 256)
|
||||
{
|
||||
outBuf = new byte[input.Length];
|
||||
for (int i = 0; i != input.Length; i++)
|
||||
{
|
||||
if (!m_indexMap.TryGetValue(input[i], out var idx))
|
||||
throw new InvalidOperationException();
|
||||
|
||||
outBuf[i] = (byte)idx;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
outBuf = new byte[input.Length * 2];
|
||||
for (int i = 0; i != input.Length; i++)
|
||||
{
|
||||
if (!m_indexMap.TryGetValue(input[i], out var idx))
|
||||
throw new InvalidOperationException();
|
||||
|
||||
outBuf[i * 2 + 0] = (byte)(idx >> 8);
|
||||
outBuf[i * 2 + 1] = (byte)idx;
|
||||
}
|
||||
}
|
||||
|
||||
return outBuf;
|
||||
}
|
||||
|
||||
public char[] ConvertToChars(byte[] input)
|
||||
{
|
||||
char[] outBuf;
|
||||
|
||||
if (m_charMap.Count <= 256)
|
||||
{
|
||||
outBuf = new char[input.Length];
|
||||
for (int i = 0; i != input.Length; i++)
|
||||
{
|
||||
outBuf[i] = m_charMap[input[i]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((input.Length & 0x1) != 0)
|
||||
{
|
||||
throw new ArgumentException("two byte radix and input string odd.Length");
|
||||
}
|
||||
|
||||
outBuf = new char[input.Length / 2];
|
||||
for (int i = 0; i != input.Length; i += 2)
|
||||
{
|
||||
outBuf[i / 2] = m_charMap[(input[i] << 8) | input[i + 1]];
|
||||
}
|
||||
}
|
||||
|
||||
return outBuf;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4148365d0789f143810f079bab7ca3c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
149
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/util/CipherFactory.cs
vendored
Normal file
149
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/util/CipherFactory.cs
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
#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.Kisa;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Misc;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ntt;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Modes;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Paddings;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities
|
||||
{
|
||||
public class CipherFactory
|
||||
{
|
||||
private CipherFactory()
|
||||
{
|
||||
}
|
||||
|
||||
private static readonly short[] rc2Ekb =
|
||||
{
|
||||
0x5d, 0xbe, 0x9b, 0x8b, 0x11, 0x99, 0x6e, 0x4d, 0x59, 0xf3, 0x85, 0xa6, 0x3f, 0xb7, 0x83, 0xc5,
|
||||
0xe4, 0x73, 0x6b, 0x3a, 0x68, 0x5a, 0xc0, 0x47, 0xa0, 0x64, 0x34, 0x0c, 0xf1, 0xd0, 0x52, 0xa5,
|
||||
0xb9, 0x1e, 0x96, 0x43, 0x41, 0xd8, 0xd4, 0x2c, 0xdb, 0xf8, 0x07, 0x77, 0x2a, 0xca, 0xeb, 0xef,
|
||||
0x10, 0x1c, 0x16, 0x0d, 0x38, 0x72, 0x2f, 0x89, 0xc1, 0xf9, 0x80, 0xc4, 0x6d, 0xae, 0x30, 0x3d,
|
||||
0xce, 0x20, 0x63, 0xfe, 0xe6, 0x1a, 0xc7, 0xb8, 0x50, 0xe8, 0x24, 0x17, 0xfc, 0x25, 0x6f, 0xbb,
|
||||
0x6a, 0xa3, 0x44, 0x53, 0xd9, 0xa2, 0x01, 0xab, 0xbc, 0xb6, 0x1f, 0x98, 0xee, 0x9a, 0xa7, 0x2d,
|
||||
0x4f, 0x9e, 0x8e, 0xac, 0xe0, 0xc6, 0x49, 0x46, 0x29, 0xf4, 0x94, 0x8a, 0xaf, 0xe1, 0x5b, 0xc3,
|
||||
0xb3, 0x7b, 0x57, 0xd1, 0x7c, 0x9c, 0xed, 0x87, 0x40, 0x8c, 0xe2, 0xcb, 0x93, 0x14, 0xc9, 0x61,
|
||||
0x2e, 0xe5, 0xcc, 0xf6, 0x5e, 0xa8, 0x5c, 0xd6, 0x75, 0x8d, 0x62, 0x95, 0x58, 0x69, 0x76, 0xa1,
|
||||
0x4a, 0xb5, 0x55, 0x09, 0x78, 0x33, 0x82, 0xd7, 0xdd, 0x79, 0xf5, 0x1b, 0x0b, 0xde, 0x26, 0x21,
|
||||
0x28, 0x74, 0x04, 0x97, 0x56, 0xdf, 0x3c, 0xf0, 0x37, 0x39, 0xdc, 0xff, 0x06, 0xa4, 0xea, 0x42,
|
||||
0x08, 0xda, 0xb4, 0x71, 0xb0, 0xcf, 0x12, 0x7a, 0x4e, 0xfa, 0x6c, 0x1d, 0x84, 0x00, 0xc8, 0x7f,
|
||||
0x91, 0x45, 0xaa, 0x2b, 0xc2, 0xb1, 0x8f, 0xd5, 0xba, 0xf2, 0xad, 0x19, 0xb2, 0x67, 0x36, 0xf7,
|
||||
0x0f, 0x0a, 0x92, 0x7d, 0xe3, 0x9d, 0xe9, 0x90, 0x3e, 0x23, 0x27, 0x66, 0x13, 0xec, 0x81, 0x15,
|
||||
0xbd, 0x22, 0xbf, 0x9f, 0x7e, 0xa9, 0x51, 0x4b, 0x4c, 0xfb, 0x02, 0xd3, 0x70, 0x86, 0x31, 0xe7,
|
||||
0x3b, 0x05, 0x03, 0x54, 0x60, 0x48, 0x65, 0x18, 0xd2, 0xcd, 0x5f, 0x32, 0x88, 0x0e, 0x35, 0xfd
|
||||
};
|
||||
|
||||
public static object CreateContentCipher(bool forEncryption, ICipherParameters encKey,
|
||||
AlgorithmIdentifier encryptionAlgID)
|
||||
{
|
||||
DerObjectIdentifier encAlg = encryptionAlgID.Algorithm;
|
||||
|
||||
if (encAlg.Equals(PkcsObjectIdentifiers.rc4))
|
||||
{
|
||||
IStreamCipher cipher = new RC4Engine();
|
||||
cipher.Init(forEncryption, encKey);
|
||||
return cipher;
|
||||
}
|
||||
else
|
||||
{
|
||||
BufferedBlockCipher cipher = CreateCipher(encryptionAlgID.Algorithm);
|
||||
Asn1Object sParams = encryptionAlgID.Parameters.ToAsn1Object();
|
||||
|
||||
if (sParams != null && !(sParams is DerNull))
|
||||
{
|
||||
if (encAlg.Equals(PkcsObjectIdentifiers.DesEde3Cbc)
|
||||
|| encAlg.Equals(AlgorithmIdentifierFactory.IDEA_CBC)
|
||||
|| encAlg.Equals(NistObjectIdentifiers.IdAes128Cbc)
|
||||
|| encAlg.Equals(NistObjectIdentifiers.IdAes192Cbc)
|
||||
|| encAlg.Equals(NistObjectIdentifiers.IdAes256Cbc)
|
||||
|| encAlg.Equals(NttObjectIdentifiers.IdCamellia128Cbc)
|
||||
|| encAlg.Equals(NttObjectIdentifiers.IdCamellia192Cbc)
|
||||
|| encAlg.Equals(NttObjectIdentifiers.IdCamellia256Cbc)
|
||||
|| encAlg.Equals(KisaObjectIdentifiers.IdSeedCbc)
|
||||
|| encAlg.Equals(OiwObjectIdentifiers.DesCbc))
|
||||
{
|
||||
cipher.Init(forEncryption, new ParametersWithIV(encKey,
|
||||
Asn1OctetString.GetInstance(sParams).GetOctets()));
|
||||
}
|
||||
else if (encAlg.Equals(AlgorithmIdentifierFactory.CAST5_CBC))
|
||||
{
|
||||
Cast5CbcParameters cbcParams = Cast5CbcParameters.GetInstance(sParams);
|
||||
|
||||
cipher.Init(forEncryption, new ParametersWithIV(encKey, cbcParams.GetIV()));
|
||||
}
|
||||
else if (encAlg.Equals(PkcsObjectIdentifiers.RC2Cbc))
|
||||
{
|
||||
RC2CbcParameter cbcParams = RC2CbcParameter.GetInstance(sParams);
|
||||
|
||||
cipher.Init(forEncryption, new ParametersWithIV(new RC2Parameters(((KeyParameter)encKey).GetKey(), rc2Ekb[cbcParams.RC2ParameterVersion.IntValue]), cbcParams.GetIV()));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("cannot match parameters");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (encAlg.Equals(PkcsObjectIdentifiers.DesEde3Cbc)
|
||||
|| encAlg.Equals(AlgorithmIdentifierFactory.IDEA_CBC)
|
||||
|| encAlg.Equals(AlgorithmIdentifierFactory.CAST5_CBC))
|
||||
{
|
||||
cipher.Init(forEncryption, new ParametersWithIV(encKey, new byte[8]));
|
||||
}
|
||||
else
|
||||
{
|
||||
cipher.Init(forEncryption, encKey);
|
||||
}
|
||||
}
|
||||
|
||||
return cipher;
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedBlockCipher CreateCipher(DerObjectIdentifier algorithm)
|
||||
{
|
||||
IBlockCipherMode cipher;
|
||||
|
||||
if (NistObjectIdentifiers.IdAes128Cbc.Equals(algorithm)
|
||||
|| NistObjectIdentifiers.IdAes192Cbc.Equals(algorithm)
|
||||
|| NistObjectIdentifiers.IdAes256Cbc.Equals(algorithm))
|
||||
{
|
||||
cipher = new CbcBlockCipher(AesUtilities.CreateEngine());
|
||||
}
|
||||
else if (PkcsObjectIdentifiers.DesEde3Cbc.Equals(algorithm))
|
||||
{
|
||||
cipher = new CbcBlockCipher(new DesEdeEngine());
|
||||
}
|
||||
else if (OiwObjectIdentifiers.DesCbc.Equals(algorithm))
|
||||
{
|
||||
cipher = new CbcBlockCipher(new DesEngine());
|
||||
}
|
||||
else if (PkcsObjectIdentifiers.RC2Cbc.Equals(algorithm))
|
||||
{
|
||||
cipher = new CbcBlockCipher(new RC2Engine());
|
||||
}
|
||||
else if (MiscObjectIdentifiers.cast5CBC.Equals(algorithm))
|
||||
{
|
||||
cipher = new CbcBlockCipher(new Cast5Engine());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("cannot recognise cipher: " + algorithm);
|
||||
}
|
||||
|
||||
return new PaddedBufferedBlockCipher(cipher, new Pkcs7Padding());
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/util/CipherFactory.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/util/CipherFactory.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f98da949918d7e48bbc642576f52373
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,95 @@
|
||||
#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.Kisa;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ntt;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities
|
||||
{
|
||||
public static class CipherKeyGeneratorFactory
|
||||
{
|
||||
/**
|
||||
* Create a key generator for the passed in Object Identifier.
|
||||
*
|
||||
* @param algorithm the Object Identifier indicating the algorithn the generator is for.
|
||||
* @param random a source of random to initialise the generator with.
|
||||
* @return an initialised CipherKeyGenerator.
|
||||
* @throws IllegalArgumentException if the algorithm cannot be identified.
|
||||
*/
|
||||
public static CipherKeyGenerator CreateKeyGenerator(DerObjectIdentifier algorithm, SecureRandom random)
|
||||
{
|
||||
if (NistObjectIdentifiers.IdAes128Cbc.Equals(algorithm))
|
||||
{
|
||||
return CreateCipherKeyGenerator(random, 128);
|
||||
}
|
||||
else if (NistObjectIdentifiers.IdAes192Cbc.Equals(algorithm))
|
||||
{
|
||||
return CreateCipherKeyGenerator(random, 192);
|
||||
}
|
||||
else if (NistObjectIdentifiers.IdAes256Cbc.Equals(algorithm))
|
||||
{
|
||||
return CreateCipherKeyGenerator(random, 256);
|
||||
}
|
||||
else if (PkcsObjectIdentifiers.DesEde3Cbc.Equals(algorithm))
|
||||
{
|
||||
DesEdeKeyGenerator keyGen = new DesEdeKeyGenerator();
|
||||
keyGen.Init(new KeyGenerationParameters(random, 192));
|
||||
return keyGen;
|
||||
}
|
||||
else if (NttObjectIdentifiers.IdCamellia128Cbc.Equals(algorithm))
|
||||
{
|
||||
return CreateCipherKeyGenerator(random, 128);
|
||||
}
|
||||
else if (NttObjectIdentifiers.IdCamellia192Cbc.Equals(algorithm))
|
||||
{
|
||||
return CreateCipherKeyGenerator(random, 192);
|
||||
}
|
||||
else if (NttObjectIdentifiers.IdCamellia256Cbc.Equals(algorithm))
|
||||
{
|
||||
return CreateCipherKeyGenerator(random, 256);
|
||||
}
|
||||
else if (KisaObjectIdentifiers.IdSeedCbc.Equals(algorithm))
|
||||
{
|
||||
return CreateCipherKeyGenerator(random, 128);
|
||||
}
|
||||
else if (AlgorithmIdentifierFactory.CAST5_CBC.Equals(algorithm))
|
||||
{
|
||||
return CreateCipherKeyGenerator(random, 128);
|
||||
}
|
||||
else if (OiwObjectIdentifiers.DesCbc.Equals(algorithm))
|
||||
{
|
||||
DesKeyGenerator keyGen = new DesKeyGenerator();
|
||||
keyGen.Init(new KeyGenerationParameters(random, 64));
|
||||
return keyGen;
|
||||
}
|
||||
else if (PkcsObjectIdentifiers.rc4.Equals(algorithm))
|
||||
{
|
||||
return CreateCipherKeyGenerator(random, 128);
|
||||
}
|
||||
else if (PkcsObjectIdentifiers.RC2Cbc.Equals(algorithm))
|
||||
{
|
||||
return CreateCipherKeyGenerator(random, 128);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("cannot recognise cipher: " + algorithm);
|
||||
}
|
||||
}
|
||||
|
||||
private static CipherKeyGenerator CreateCipherKeyGenerator(SecureRandom random, int keySize)
|
||||
{
|
||||
CipherKeyGenerator keyGen = new CipherKeyGenerator();
|
||||
keyGen.Init(new KeyGenerationParameters(random, keySize));
|
||||
return keyGen;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd8ebdb99f9824346b8a6814ae72f7d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
760
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/util/Pack.cs
vendored
Normal file
760
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/util/Pack.cs
vendored
Normal file
@@ -0,0 +1,760 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
using System.Buffers.Binary;
|
||||
#endif
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities
|
||||
{
|
||||
internal static class Pack
|
||||
{
|
||||
internal static void UInt16_To_BE(ushort n, byte[] bs)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
BinaryPrimitives.WriteUInt16BigEndian(bs, n);
|
||||
#else
|
||||
bs[0] = (byte)(n >> 8);
|
||||
bs[1] = (byte)n;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void UInt16_To_BE(ushort n, byte[] bs, int off)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
BinaryPrimitives.WriteUInt16BigEndian(bs.AsSpan(off), n);
|
||||
#else
|
||||
bs[off] = (byte)(n >> 8);
|
||||
bs[off + 1] = (byte)n;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void UInt16_To_BE(ushort[] ns, byte[] bs, int off)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
UInt16_To_BE(ns[i], bs, off);
|
||||
off += 2;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UInt16_To_BE(ushort[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
|
||||
{
|
||||
for (int i = 0; i < nsLen; ++i)
|
||||
{
|
||||
UInt16_To_BE(ns[nsOff + i], bs, bsOff);
|
||||
bsOff += 2;
|
||||
}
|
||||
}
|
||||
|
||||
internal static byte[] UInt16_To_BE(ushort n)
|
||||
{
|
||||
byte[] bs = new byte[2];
|
||||
UInt16_To_BE(n, bs, 0);
|
||||
return bs;
|
||||
}
|
||||
|
||||
internal static byte[] UInt16_To_BE(ushort[] ns)
|
||||
{
|
||||
return UInt16_To_BE(ns, 0, ns.Length);
|
||||
}
|
||||
|
||||
internal static byte[] UInt16_To_BE(ushort[] ns, int nsOff, int nsLen)
|
||||
{
|
||||
byte[] bs = new byte[2 * nsLen];
|
||||
UInt16_To_BE(ns, nsOff, nsLen, bs, 0);
|
||||
return bs;
|
||||
}
|
||||
|
||||
internal static ushort BE_To_UInt16(byte[] bs, int off)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return BinaryPrimitives.ReadUInt16BigEndian(bs.AsSpan(off));
|
||||
#else
|
||||
uint n = (uint)bs[off] << 8
|
||||
| bs[off + 1];
|
||||
return (ushort)n;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void BE_To_UInt16(byte[] bs, int bsOff, ushort[] ns, int nsOff)
|
||||
{
|
||||
ns[nsOff] = BE_To_UInt16(bs, bsOff);
|
||||
}
|
||||
|
||||
internal static ushort[] BE_To_UInt16(byte[] bs)
|
||||
{
|
||||
return BE_To_UInt16(bs, 0, bs.Length);
|
||||
}
|
||||
|
||||
internal static ushort[] BE_To_UInt16(byte[] bs, int off, int len)
|
||||
{
|
||||
if ((len & 1) != 0)
|
||||
throw new ArgumentException("must be a multiple of 2", "len");
|
||||
|
||||
ushort[] ns = new ushort[len / 2];
|
||||
for (int i = 0; i < len; i += 2)
|
||||
{
|
||||
BE_To_UInt16(bs, off + i, ns, i >> 1);
|
||||
}
|
||||
return ns;
|
||||
}
|
||||
|
||||
internal static void UInt32_To_BE(uint n, byte[] bs)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
BinaryPrimitives.WriteUInt32BigEndian(bs, n);
|
||||
#else
|
||||
bs[0] = (byte)(n >> 24);
|
||||
bs[1] = (byte)(n >> 16);
|
||||
bs[2] = (byte)(n >> 8);
|
||||
bs[3] = (byte)n;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void UInt32_To_BE(uint n, byte[] bs, int off)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
BinaryPrimitives.WriteUInt32BigEndian(bs.AsSpan(off), n);
|
||||
#else
|
||||
bs[off] = (byte)(n >> 24);
|
||||
bs[off + 1] = (byte)(n >> 16);
|
||||
bs[off + 2] = (byte)(n >> 8);
|
||||
bs[off + 3] = (byte)n;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void UInt32_To_BE(uint[] ns, byte[] bs, int off)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
UInt32_To_BE(ns[i], bs, off);
|
||||
off += 4;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UInt32_To_BE(uint[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
|
||||
{
|
||||
for (int i = 0; i < nsLen; ++i)
|
||||
{
|
||||
UInt32_To_BE(ns[nsOff + i], bs, bsOff);
|
||||
bsOff += 4;
|
||||
}
|
||||
}
|
||||
|
||||
internal static byte[] UInt32_To_BE(uint n)
|
||||
{
|
||||
byte[] bs = new byte[4];
|
||||
UInt32_To_BE(n, bs, 0);
|
||||
return bs;
|
||||
}
|
||||
|
||||
internal static byte[] UInt32_To_BE(uint[] ns)
|
||||
{
|
||||
byte[] bs = new byte[4 * ns.Length];
|
||||
UInt32_To_BE(ns, bs, 0);
|
||||
return bs;
|
||||
}
|
||||
|
||||
internal static uint BE_To_UInt32(byte[] bs)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return BinaryPrimitives.ReadUInt32BigEndian(bs);
|
||||
#else
|
||||
return (uint)bs[0] << 24
|
||||
| (uint)bs[1] << 16
|
||||
| (uint)bs[2] << 8
|
||||
| bs[3];
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static uint BE_To_UInt32(byte[] bs, int off)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return BinaryPrimitives.ReadUInt32BigEndian(bs.AsSpan(off));
|
||||
#else
|
||||
return (uint)bs[off] << 24
|
||||
| (uint)bs[off + 1] << 16
|
||||
| (uint)bs[off + 2] << 8
|
||||
| bs[off + 3];
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static uint BE_To_UInt32_Partial(byte[] bs, int off, int len)
|
||||
{
|
||||
Debug.Assert(1 <= len && len <= 4);
|
||||
|
||||
uint result = bs[off];
|
||||
for (int i = 1; i < len; ++i)
|
||||
{
|
||||
result <<= 8;
|
||||
result |= bs[off + i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void BE_To_UInt32(byte[] bs, int off, uint[] ns)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
ns[i] = BE_To_UInt32(bs, off);
|
||||
off += 4;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void BE_To_UInt32(byte[] bs, int bsOff, uint[] ns, int nsOff, int nsLen)
|
||||
{
|
||||
for (int i = 0; i < nsLen; ++i)
|
||||
{
|
||||
ns[nsOff + i] = BE_To_UInt32(bs, bsOff);
|
||||
bsOff += 4;
|
||||
}
|
||||
}
|
||||
|
||||
internal static byte[] UInt64_To_BE(ulong n)
|
||||
{
|
||||
byte[] bs = new byte[8];
|
||||
UInt64_To_BE(n, bs, 0);
|
||||
return bs;
|
||||
}
|
||||
|
||||
internal static void UInt64_To_BE(ulong n, byte[] bs)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
BinaryPrimitives.WriteUInt64BigEndian(bs, n);
|
||||
#else
|
||||
UInt32_To_BE((uint)(n >> 32), bs);
|
||||
UInt32_To_BE((uint)n, bs, 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void UInt64_To_BE(ulong n, byte[] bs, int off)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
BinaryPrimitives.WriteUInt64BigEndian(bs.AsSpan(off), n);
|
||||
#else
|
||||
UInt32_To_BE((uint)(n >> 32), bs, off);
|
||||
UInt32_To_BE((uint)n, bs, off + 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static byte[] UInt64_To_BE(ulong[] ns)
|
||||
{
|
||||
byte[] bs = new byte[8 * ns.Length];
|
||||
UInt64_To_BE(ns, bs, 0);
|
||||
return bs;
|
||||
}
|
||||
|
||||
internal static void UInt64_To_BE(ulong[] ns, byte[] bs, int off)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
UInt64_To_BE(ns[i], bs, off);
|
||||
off += 8;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UInt64_To_BE(ulong[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
|
||||
{
|
||||
for (int i = 0; i < nsLen; ++i)
|
||||
{
|
||||
UInt64_To_BE(ns[nsOff + i], bs, bsOff);
|
||||
bsOff += 8;
|
||||
}
|
||||
}
|
||||
|
||||
internal static ulong BE_To_UInt64(byte[] bs)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return BinaryPrimitives.ReadUInt64BigEndian(bs);
|
||||
#else
|
||||
uint hi = BE_To_UInt32(bs);
|
||||
uint lo = BE_To_UInt32(bs, 4);
|
||||
return ((ulong)hi << 32) | (ulong)lo;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static ulong BE_To_UInt64(byte[] bs, int off)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return BinaryPrimitives.ReadUInt64BigEndian(bs.AsSpan(off));
|
||||
#else
|
||||
uint hi = BE_To_UInt32(bs, off);
|
||||
uint lo = BE_To_UInt32(bs, off + 4);
|
||||
return ((ulong)hi << 32) | (ulong)lo;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static ulong BE_To_UInt64_Partial(byte[] bs, int off, int len)
|
||||
{
|
||||
Debug.Assert(1 <= len && len <= 8);
|
||||
|
||||
ulong result = bs[off];
|
||||
for (int i = 1; i < len; ++i)
|
||||
{
|
||||
result <<= 8;
|
||||
result |= bs[off + i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void BE_To_UInt64(byte[] bs, int off, ulong[] ns)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
ns[i] = BE_To_UInt64(bs, off);
|
||||
off += 8;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void BE_To_UInt64(byte[] bs, int bsOff, ulong[] ns, int nsOff, int nsLen)
|
||||
{
|
||||
for (int i = 0; i < nsLen; ++i)
|
||||
{
|
||||
ns[nsOff + i] = BE_To_UInt64(bs, bsOff);
|
||||
bsOff += 8;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UInt16_To_LE(ushort n, byte[] bs)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(bs, n);
|
||||
#else
|
||||
bs[0] = (byte)n;
|
||||
bs[1] = (byte)(n >> 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void UInt16_To_LE(ushort n, byte[] bs, int off)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(bs.AsSpan(off), n);
|
||||
#else
|
||||
bs[off] = (byte)n;
|
||||
bs[off + 1] = (byte)(n >> 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static byte[] UInt16_To_LE(ushort n)
|
||||
{
|
||||
byte[] bs = new byte[2];
|
||||
UInt16_To_LE(n, bs, 0);
|
||||
return bs;
|
||||
}
|
||||
|
||||
internal static ushort LE_To_UInt16(byte[] bs)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return BinaryPrimitives.ReadUInt16LittleEndian(bs);
|
||||
#else
|
||||
uint n = bs[0]
|
||||
| (uint)bs[1] << 8;
|
||||
return (ushort)n;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static ushort LE_To_UInt16(byte[] bs, int off)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return BinaryPrimitives.ReadUInt16LittleEndian(bs.AsSpan(off));
|
||||
#else
|
||||
uint n = bs[off]
|
||||
| (uint)bs[off + 1] << 8;
|
||||
return (ushort)n;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static byte[] UInt32_To_LE(uint n)
|
||||
{
|
||||
byte[] bs = new byte[4];
|
||||
UInt32_To_LE(n, bs, 0);
|
||||
return bs;
|
||||
}
|
||||
|
||||
internal static void UInt32_To_LE(uint n, byte[] bs)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(bs, n);
|
||||
#else
|
||||
bs[0] = (byte)n;
|
||||
bs[1] = (byte)(n >> 8);
|
||||
bs[2] = (byte)(n >> 16);
|
||||
bs[3] = (byte)(n >> 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void UInt32_To_LE(uint n, byte[] bs, int off)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(bs.AsSpan(off), n);
|
||||
#else
|
||||
bs[off] = (byte)n;
|
||||
bs[off + 1] = (byte)(n >> 8);
|
||||
bs[off + 2] = (byte)(n >> 16);
|
||||
bs[off + 3] = (byte)(n >> 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static byte[] UInt32_To_LE(uint[] ns)
|
||||
{
|
||||
byte[] bs = new byte[4 * ns.Length];
|
||||
UInt32_To_LE(ns, bs, 0);
|
||||
return bs;
|
||||
}
|
||||
|
||||
internal static void UInt32_To_LE(uint[] ns, byte[] bs, int off)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
UInt32_To_LE(ns[i], bs, off);
|
||||
off += 4;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UInt32_To_LE(uint[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
|
||||
{
|
||||
for (int i = 0; i < nsLen; ++i)
|
||||
{
|
||||
UInt32_To_LE(ns[nsOff + i], bs, bsOff);
|
||||
bsOff += 4;
|
||||
}
|
||||
}
|
||||
|
||||
internal static uint LE_To_UInt24(byte[] bs, int off)
|
||||
{
|
||||
return bs[off]
|
||||
| (uint)bs[off + 1] << 8
|
||||
| (uint)bs[off + 2] << 16;
|
||||
}
|
||||
|
||||
internal static uint LE_To_UInt32(byte[] bs)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return BinaryPrimitives.ReadUInt32LittleEndian(bs);
|
||||
#else
|
||||
return bs[0]
|
||||
| (uint)bs[1] << 8
|
||||
| (uint)bs[2] << 16
|
||||
| (uint)bs[3] << 24;
|
||||
#endif
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static uint LE_To_UInt32(byte[] bs, int off)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return BinaryPrimitives.ReadUInt32LittleEndian(bs.AsSpan(off));
|
||||
#else
|
||||
return bs[off]
|
||||
| (uint)bs[off + 1] << 8
|
||||
| (uint)bs[off + 2] << 16
|
||||
| (uint)bs[off + 3] << 24;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void LE_To_UInt32(byte[] bs, int off, uint[] ns)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
ns[i] = LE_To_UInt32(bs, off);
|
||||
off += 4;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void LE_To_UInt32(byte[] bs, int bOff, uint[] ns, int nOff, int count)
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
ns[nOff + i] = LE_To_UInt32(bs, bOff);
|
||||
bOff += 4;
|
||||
}
|
||||
}
|
||||
|
||||
internal static uint[] LE_To_UInt32(byte[] bs, int off, int count)
|
||||
{
|
||||
uint[] ns = new uint[count];
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
ns[i] = LE_To_UInt32(bs, off);
|
||||
off += 4;
|
||||
}
|
||||
return ns;
|
||||
}
|
||||
|
||||
internal static byte[] UInt64_To_LE(ulong n)
|
||||
{
|
||||
byte[] bs = new byte[8];
|
||||
UInt64_To_LE(n, bs, 0);
|
||||
return bs;
|
||||
}
|
||||
|
||||
internal static void UInt64_To_LE(ulong n, byte[] bs)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
BinaryPrimitives.WriteUInt64LittleEndian(bs, n);
|
||||
#else
|
||||
UInt32_To_LE((uint)n, bs);
|
||||
UInt32_To_LE((uint)(n >> 32), bs, 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void UInt64_To_LE(ulong n, byte[] bs, int off)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
BinaryPrimitives.WriteUInt64LittleEndian(bs.AsSpan(off), n);
|
||||
#else
|
||||
UInt32_To_LE((uint)n, bs, off);
|
||||
UInt32_To_LE((uint)(n >> 32), bs, off + 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static byte[] UInt64_To_LE(ulong[] ns)
|
||||
{
|
||||
byte[] bs = new byte[8 * ns.Length];
|
||||
UInt64_To_LE(ns, bs, 0);
|
||||
return bs;
|
||||
}
|
||||
|
||||
internal static void UInt64_To_LE(ulong[] ns, byte[] bs, int off)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
UInt64_To_LE(ns[i], bs, off);
|
||||
off += 8;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UInt64_To_LE(ulong[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
|
||||
{
|
||||
for (int i = 0; i < nsLen; ++i)
|
||||
{
|
||||
UInt64_To_LE(ns[nsOff + i], bs, bsOff);
|
||||
bsOff += 8;
|
||||
}
|
||||
}
|
||||
|
||||
internal static ulong LE_To_UInt64(byte[] bs)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return BinaryPrimitives.ReadUInt64LittleEndian(bs);
|
||||
#else
|
||||
uint lo = LE_To_UInt32(bs);
|
||||
uint hi = LE_To_UInt32(bs, 4);
|
||||
return ((ulong)hi << 32) | (ulong)lo;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static ulong LE_To_UInt64(byte[] bs, int off)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return BinaryPrimitives.ReadUInt64LittleEndian(bs.AsSpan(off));
|
||||
#else
|
||||
uint lo = LE_To_UInt32(bs, off);
|
||||
uint hi = LE_To_UInt32(bs, off + 4);
|
||||
return ((ulong)hi << 32) | (ulong)lo;
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void LE_To_UInt64(byte[] bs, int off, ulong[] ns)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
ns[i] = LE_To_UInt64(bs, off);
|
||||
off += 8;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void LE_To_UInt64(byte[] bs, int bsOff, ulong[] ns, int nsOff, int nsLen)
|
||||
{
|
||||
for (int i = 0; i < nsLen; ++i)
|
||||
{
|
||||
ns[nsOff + i] = LE_To_UInt64(bs, bsOff);
|
||||
bsOff += 8;
|
||||
}
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static uint BE_To_UInt32(ReadOnlySpan<byte> bs)
|
||||
{
|
||||
return BinaryPrimitives.ReadUInt32BigEndian(bs);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void BE_To_UInt32(ReadOnlySpan<byte> bs, Span<uint> ns)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
ns[i] = BE_To_UInt32(bs);
|
||||
bs = bs[4..];
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static uint BE_To_UInt32_Partial(ReadOnlySpan<byte> bs)
|
||||
{
|
||||
int len = bs.Length;
|
||||
Debug.Assert(1 <= len && len <= 4);
|
||||
|
||||
uint result = bs[0];
|
||||
for (int i = 1; i < len; ++i)
|
||||
{
|
||||
result <<= 8;
|
||||
result |= bs[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static ulong BE_To_UInt64(ReadOnlySpan<byte> bs)
|
||||
{
|
||||
return BinaryPrimitives.ReadUInt64BigEndian(bs);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void BE_To_UInt64(ReadOnlySpan<byte> bs, Span<ulong> ns)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
ns[i] = BE_To_UInt64(bs);
|
||||
bs = bs[8..];
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static ulong BE_To_UInt64_Partial(ReadOnlySpan<byte> bs)
|
||||
{
|
||||
int len = bs.Length;
|
||||
Debug.Assert(1 <= len && len <= 8);
|
||||
|
||||
ulong result = bs[0];
|
||||
for (int i = 1; i < len; ++i)
|
||||
{
|
||||
result <<= 8;
|
||||
result |= bs[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static ushort LE_To_UInt16(ReadOnlySpan<byte> bs)
|
||||
{
|
||||
return BinaryPrimitives.ReadUInt16LittleEndian(bs);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static uint LE_To_UInt32(ReadOnlySpan<byte> bs)
|
||||
{
|
||||
return BinaryPrimitives.ReadUInt32LittleEndian(bs);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void LE_To_UInt32(ReadOnlySpan<byte> bs, Span<uint> ns)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
ns[i] = LE_To_UInt32(bs);
|
||||
bs = bs[4..];
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static ulong LE_To_UInt64(ReadOnlySpan<byte> bs)
|
||||
{
|
||||
return BinaryPrimitives.ReadUInt64LittleEndian(bs);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void LE_To_UInt64(ReadOnlySpan<byte> bs, Span<ulong> ns)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
ns[i] = LE_To_UInt64(bs);
|
||||
bs = bs[8..];
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void UInt16_To_BE(ushort n, Span<byte> bs)
|
||||
{
|
||||
BinaryPrimitives.WriteUInt16BigEndian(bs, n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void UInt16_To_LE(ushort n, Span<byte> bs)
|
||||
{
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(bs, n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void UInt32_To_BE(uint n, Span<byte> bs)
|
||||
{
|
||||
BinaryPrimitives.WriteUInt32BigEndian(bs, n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void UInt32_To_BE(ReadOnlySpan<uint> ns, Span<byte> bs)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
UInt32_To_BE(ns[i], bs);
|
||||
bs = bs[4..];
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void UInt32_To_LE(uint n, Span<byte> bs)
|
||||
{
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(bs, n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void UInt32_To_LE(ReadOnlySpan<uint> ns, Span<byte> bs)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
UInt32_To_LE(ns[i], bs);
|
||||
bs = bs[4..];
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void UInt64_To_BE(ulong n, Span<byte> bs)
|
||||
{
|
||||
BinaryPrimitives.WriteUInt64BigEndian(bs, n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void UInt64_To_BE(ReadOnlySpan<ulong> ns, Span<byte> bs)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
UInt64_To_BE(ns[i], bs);
|
||||
bs = bs[8..];
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void UInt64_To_LE(ulong n, Span<byte> bs)
|
||||
{
|
||||
BinaryPrimitives.WriteUInt64LittleEndian(bs, n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void UInt64_To_LE(ReadOnlySpan<ulong> ns, Span<byte> bs)
|
||||
{
|
||||
for (int i = 0; i < ns.Length; ++i)
|
||||
{
|
||||
UInt64_To_LE(ns[i], bs);
|
||||
bs = bs[8..];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/util/Pack.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/crypto/util/Pack.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c2ac9bc12a27b64b876a7edeb5623d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user