up
This commit is contained in:
58
Assets/BestHTTP/SecureProtocol/math/field/FiniteFields.cs
Normal file
58
Assets/BestHTTP/SecureProtocol/math/field/FiniteFields.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Math.Field
|
||||
{
|
||||
public abstract class FiniteFields
|
||||
{
|
||||
internal static readonly IFiniteField GF_2 = new PrimeField(BigInteger.ValueOf(2));
|
||||
internal static readonly IFiniteField GF_3 = new PrimeField(BigInteger.ValueOf(3));
|
||||
|
||||
public static IPolynomialExtensionField GetBinaryExtensionField(int[] exponents)
|
||||
{
|
||||
if (exponents[0] != 0)
|
||||
{
|
||||
throw new ArgumentException("Irreducible polynomials in GF(2) must have constant term", "exponents");
|
||||
}
|
||||
for (int i = 1; i < exponents.Length; ++i)
|
||||
{
|
||||
if (exponents[i] <= exponents[i - 1])
|
||||
{
|
||||
throw new ArgumentException("Polynomial exponents must be montonically increasing", "exponents");
|
||||
}
|
||||
}
|
||||
|
||||
return new GenericPolynomialExtensionField(GF_2, new GF2Polynomial(exponents));
|
||||
}
|
||||
|
||||
// public static IPolynomialExtensionField GetTernaryExtensionField(Term[] terms)
|
||||
// {
|
||||
// return new GenericPolynomialExtensionField(GF_3, new GF3Polynomial(terms));
|
||||
// }
|
||||
|
||||
public static IFiniteField GetPrimeField(BigInteger characteristic)
|
||||
{
|
||||
int bitLength = characteristic.BitLength;
|
||||
if (characteristic.SignValue <= 0 || bitLength < 2)
|
||||
{
|
||||
throw new ArgumentException("Must be >= 2", "characteristic");
|
||||
}
|
||||
|
||||
if (bitLength < 3)
|
||||
{
|
||||
switch (characteristic.IntValue)
|
||||
{
|
||||
case 2:
|
||||
return GF_2;
|
||||
case 3:
|
||||
return GF_3;
|
||||
}
|
||||
}
|
||||
|
||||
return new PrimeField(characteristic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc2503dcb7f0f478ab65d353981b5a45
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
Assets/BestHTTP/SecureProtocol/math/field/GF2Polynomial.cs
Normal file
50
Assets/BestHTTP/SecureProtocol/math/field/GF2Polynomial.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Math.Field
|
||||
{
|
||||
internal class GF2Polynomial
|
||||
: IPolynomial
|
||||
{
|
||||
protected readonly int[] exponents;
|
||||
|
||||
internal GF2Polynomial(int[] exponents)
|
||||
{
|
||||
this.exponents = Arrays.Clone(exponents);
|
||||
}
|
||||
|
||||
public virtual int Degree
|
||||
{
|
||||
get { return exponents[exponents.Length - 1]; }
|
||||
}
|
||||
|
||||
public virtual int[] GetExponentsPresent()
|
||||
{
|
||||
return Arrays.Clone(exponents);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
GF2Polynomial other = obj as GF2Polynomial;
|
||||
if (null == other)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Arrays.AreEqual(exponents, other.exponents);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Arrays.GetHashCode(exponents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 064ff37623bbe44b6bb5cc935e22e57f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Math.Field
|
||||
{
|
||||
internal class GenericPolynomialExtensionField
|
||||
: IPolynomialExtensionField
|
||||
{
|
||||
protected readonly IFiniteField subfield;
|
||||
protected readonly IPolynomial minimalPolynomial;
|
||||
|
||||
internal GenericPolynomialExtensionField(IFiniteField subfield, IPolynomial polynomial)
|
||||
{
|
||||
this.subfield = subfield;
|
||||
this.minimalPolynomial = polynomial;
|
||||
}
|
||||
|
||||
public virtual BigInteger Characteristic
|
||||
{
|
||||
get { return subfield.Characteristic; }
|
||||
}
|
||||
|
||||
public virtual int Dimension
|
||||
{
|
||||
get { return subfield.Dimension * minimalPolynomial.Degree; }
|
||||
}
|
||||
|
||||
public virtual IFiniteField Subfield
|
||||
{
|
||||
get { return subfield; }
|
||||
}
|
||||
|
||||
public virtual int Degree
|
||||
{
|
||||
get { return minimalPolynomial.Degree; }
|
||||
}
|
||||
|
||||
public virtual IPolynomial MinimalPolynomial
|
||||
{
|
||||
get { return minimalPolynomial; }
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
GenericPolynomialExtensionField other = obj as GenericPolynomialExtensionField;
|
||||
if (null == other)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return subfield.Equals(other.subfield) && minimalPolynomial.Equals(other.minimalPolynomial);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return subfield.GetHashCode() ^ Integers.RotateLeft(minimalPolynomial.GetHashCode(), 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1bc699e2802264506856548093572dde
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/BestHTTP/SecureProtocol/math/field/IExtensionField.cs
Normal file
16
Assets/BestHTTP/SecureProtocol/math/field/IExtensionField.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Math.Field
|
||||
{
|
||||
public interface IExtensionField
|
||||
: IFiniteField
|
||||
{
|
||||
IFiniteField Subfield { get; }
|
||||
|
||||
int Degree { get; }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74bb34121ce8b44519bb4475ab25903e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/BestHTTP/SecureProtocol/math/field/IFiniteField.cs
Normal file
15
Assets/BestHTTP/SecureProtocol/math/field/IFiniteField.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Math.Field
|
||||
{
|
||||
public interface IFiniteField
|
||||
{
|
||||
BigInteger Characteristic { get; }
|
||||
|
||||
int Dimension { get; }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80c3061f9075f490baf66823cd241c38
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/BestHTTP/SecureProtocol/math/field/IPolynomial.cs
Normal file
19
Assets/BestHTTP/SecureProtocol/math/field/IPolynomial.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Math.Field
|
||||
{
|
||||
public interface IPolynomial
|
||||
{
|
||||
int Degree { get; }
|
||||
|
||||
//BigInteger[] GetCoefficients();
|
||||
|
||||
int[] GetExponentsPresent();
|
||||
|
||||
//Term[] GetNonZeroTerms();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32332c77c9e594af98371dd383602b7e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Math.Field
|
||||
{
|
||||
public interface IPolynomialExtensionField
|
||||
: IExtensionField
|
||||
{
|
||||
IPolynomial MinimalPolynomial { get; }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0caf822f76522413aa85904e46e5620f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
48
Assets/BestHTTP/SecureProtocol/math/field/PrimeField.cs
Normal file
48
Assets/BestHTTP/SecureProtocol/math/field/PrimeField.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Math.Field
|
||||
{
|
||||
internal class PrimeField
|
||||
: IFiniteField
|
||||
{
|
||||
protected readonly BigInteger characteristic;
|
||||
|
||||
internal PrimeField(BigInteger characteristic)
|
||||
{
|
||||
this.characteristic = characteristic;
|
||||
}
|
||||
|
||||
public virtual BigInteger Characteristic
|
||||
{
|
||||
get { return characteristic; }
|
||||
}
|
||||
|
||||
public virtual int Dimension
|
||||
{
|
||||
get { return 1; }
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
PrimeField other = obj as PrimeField;
|
||||
if (null == other)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return characteristic.Equals(other.characteristic);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return characteristic.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
Assets/BestHTTP/SecureProtocol/math/field/PrimeField.cs.meta
Normal file
11
Assets/BestHTTP/SecureProtocol/math/field/PrimeField.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d39e2977cc4b471ea48471081d7a596
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user