This commit is contained in:
2026-06-15 18:18:16 +08:00
parent 97c9fba14e
commit 2b9f134e5f
4164 changed files with 386922 additions and 79 deletions

View File

@@ -0,0 +1,58 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace Best.HTTP.SecureProtocol.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 monotonically 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);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9d9cf255372aca244b0e0c814b6aa1a0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
#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.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);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bc79bafac44ff7444a7bfa6ae1151239
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,67 @@
#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.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);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9d54072e6e8de5f4c8ca10a77fa0db85
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Field
{
public interface IExtensionField
: IFiniteField
{
IFiniteField Subfield { get; }
int Degree { get; }
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bb7c0110bd6f38f4680ca455c3e474d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Field
{
public interface IFiniteField
{
BigInteger Characteristic { get; }
int Dimension { get; }
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ca84db28bb202064485e5514dc24cc07
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Field
{
public interface IPolynomial
{
int Degree { get; }
//BigInteger[] GetCoefficients();
int[] GetExponentsPresent();
//Term[] GetNonZeroTerms();
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c0d3c2649daade84c9b2259b31e29b13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Field
{
public interface IPolynomialExtensionField
: IExtensionField
{
IPolynomial MinimalPolynomial { get; }
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 59e9df0aff107cf45b99e681a5823847
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace Best.HTTP.SecureProtocol.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();
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4178adfb0014b2044a1565e0e7d752ba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: