add all
This commit is contained in:
90
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Bits.cs
vendored
Normal file
90
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Bits.cs
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System.Diagnostics;
|
||||
#if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
using System.Runtime.CompilerServices;
|
||||
#endif
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Raw
|
||||
{
|
||||
internal static class Bits
|
||||
{
|
||||
#if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
internal static uint BitPermuteStep(uint x, uint m, int s)
|
||||
{
|
||||
Debug.Assert((m & (m << s)) == 0U);
|
||||
Debug.Assert((m << s) >> s == m);
|
||||
|
||||
uint t = (x ^ (x >> s)) & m;
|
||||
return t ^ (t << s) ^ x;
|
||||
}
|
||||
|
||||
#if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
internal static ulong BitPermuteStep(ulong x, ulong m, int s)
|
||||
{
|
||||
Debug.Assert((m & (m << s)) == 0UL);
|
||||
Debug.Assert((m << s) >> s == m);
|
||||
|
||||
ulong t = (x ^ (x >> s)) & m;
|
||||
return t ^ (t << s) ^ x;
|
||||
}
|
||||
|
||||
#if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
internal static void BitPermuteStep2(ref uint hi, ref uint lo, uint m, int s)
|
||||
{
|
||||
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP1_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
//Debug.Assert(!Unsafe.AreSame(ref hi, ref lo) || (m & (m << s)) == 0U);
|
||||
#endif
|
||||
Debug.Assert((m << s) >> s == m);
|
||||
|
||||
uint t = ((lo >> s) ^ hi) & m;
|
||||
lo ^= t << s;
|
||||
hi ^= t;
|
||||
}
|
||||
|
||||
#if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
internal static void BitPermuteStep2(ref ulong hi, ref ulong lo, ulong m, int s)
|
||||
{
|
||||
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP1_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
//Debug.Assert(!Unsafe.AreSame(ref hi, ref lo) || (m & (m << s)) == 0UL);
|
||||
#endif
|
||||
Debug.Assert((m << s) >> s == m);
|
||||
|
||||
ulong t = ((lo >> s) ^ hi) & m;
|
||||
lo ^= t << s;
|
||||
hi ^= t;
|
||||
}
|
||||
|
||||
#if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
internal static uint BitPermuteStepSimple(uint x, uint m, int s)
|
||||
{
|
||||
Debug.Assert((m & (m << s)) == 0U);
|
||||
Debug.Assert((m << s) >> s == m);
|
||||
|
||||
return ((x & m) << s) | ((x >> s) & m);
|
||||
}
|
||||
|
||||
#if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
internal static ulong BitPermuteStepSimple(ulong x, ulong m, int s)
|
||||
{
|
||||
Debug.Assert((m & (m << s)) == 0UL);
|
||||
Debug.Assert((m << s) >> s == m);
|
||||
|
||||
return ((x & m) << s) | ((x >> s) & m);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Bits.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Bits.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8a7eec4b1a25894d8af3ea89125bf2c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
250
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Interleave.cs
vendored
Normal file
250
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Interleave.cs
vendored
Normal file
@@ -0,0 +1,250 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
#endif
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Raw
|
||||
{
|
||||
internal abstract class Interleave
|
||||
{
|
||||
private const ulong M32 = 0x55555555UL;
|
||||
private const ulong M64 = 0x5555555555555555UL;
|
||||
private const ulong M64R = 0xAAAAAAAAAAAAAAAAUL;
|
||||
|
||||
internal static uint Expand8to16(uint x)
|
||||
{
|
||||
x &= 0xFFU;
|
||||
x = (x | (x << 4)) & 0x0F0FU;
|
||||
x = (x | (x << 2)) & 0x3333U;
|
||||
x = (x | (x << 1)) & 0x5555U;
|
||||
return x;
|
||||
}
|
||||
|
||||
internal static uint Expand16to32(uint x)
|
||||
{
|
||||
x &= 0xFFFFU;
|
||||
x = (x | (x << 8)) & 0x00FF00FFU;
|
||||
x = (x | (x << 4)) & 0x0F0F0F0FU;
|
||||
x = (x | (x << 2)) & 0x33333333U;
|
||||
x = (x | (x << 1)) & 0x55555555U;
|
||||
return x;
|
||||
}
|
||||
|
||||
internal static ulong Expand32to64(uint x)
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
if (Bmi2.IsSupported)
|
||||
{
|
||||
return (ulong)Bmi2.ParallelBitDeposit(x >> 16, 0x55555555U) << 32
|
||||
| Bmi2.ParallelBitDeposit(x , 0x55555555U);
|
||||
}
|
||||
#endif
|
||||
|
||||
// "shuffle" low half to even bits and high half to odd bits
|
||||
x = Bits.BitPermuteStep(x, 0x0000FF00U, 8);
|
||||
x = Bits.BitPermuteStep(x, 0x00F000F0U, 4);
|
||||
x = Bits.BitPermuteStep(x, 0x0C0C0C0CU, 2);
|
||||
x = Bits.BitPermuteStep(x, 0x22222222U, 1);
|
||||
|
||||
return ((x >> 1) & M32) << 32 | (x & M32);
|
||||
}
|
||||
|
||||
internal static void Expand64To128(ulong x, ulong[] z, int zOff)
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
if (Bmi2.X64.IsSupported)
|
||||
{
|
||||
z[zOff ] = Bmi2.X64.ParallelBitDeposit(x , 0x5555555555555555UL);
|
||||
z[zOff + 1] = Bmi2.X64.ParallelBitDeposit(x >> 32, 0x5555555555555555UL);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// "shuffle" low half to even bits and high half to odd bits
|
||||
x = Bits.BitPermuteStep(x, 0x00000000FFFF0000UL, 16);
|
||||
x = Bits.BitPermuteStep(x, 0x0000FF000000FF00UL, 8);
|
||||
x = Bits.BitPermuteStep(x, 0x00F000F000F000F0UL, 4);
|
||||
x = Bits.BitPermuteStep(x, 0x0C0C0C0C0C0C0C0CUL, 2);
|
||||
x = Bits.BitPermuteStep(x, 0x2222222222222222UL, 1);
|
||||
|
||||
z[zOff ] = (x ) & M64;
|
||||
z[zOff + 1] = (x >> 1) & M64;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
internal static void Expand64To128(ulong x, Span<ulong> z)
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
if (Bmi2.X64.IsSupported)
|
||||
{
|
||||
z[0] = Bmi2.X64.ParallelBitDeposit(x , 0x5555555555555555UL);
|
||||
z[1] = Bmi2.X64.ParallelBitDeposit(x >> 32, 0x5555555555555555UL);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// "shuffle" low half to even bits and high half to odd bits
|
||||
x = Bits.BitPermuteStep(x, 0x00000000FFFF0000UL, 16);
|
||||
x = Bits.BitPermuteStep(x, 0x0000FF000000FF00UL, 8);
|
||||
x = Bits.BitPermuteStep(x, 0x00F000F000F000F0UL, 4);
|
||||
x = Bits.BitPermuteStep(x, 0x0C0C0C0C0C0C0C0CUL, 2);
|
||||
x = Bits.BitPermuteStep(x, 0x2222222222222222UL, 1);
|
||||
|
||||
z[0] = (x ) & M64;
|
||||
z[1] = (x >> 1) & M64;
|
||||
}
|
||||
#endif
|
||||
|
||||
internal static void Expand64To128(ulong[] xs, int xsOff, int xsLen, ulong[] zs, int zsOff)
|
||||
{
|
||||
int xsPos = xsLen, zsPos = zsOff + (xsLen << 1);
|
||||
while (--xsPos >= 0)
|
||||
{
|
||||
zsPos -= 2;
|
||||
Expand64To128(xs[xsOff + xsPos], zs, zsPos);
|
||||
}
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
internal static void Expand64To128(ReadOnlySpan<ulong> xs, Span<ulong> zs)
|
||||
{
|
||||
int xsPos = xs.Length, zsPos = xs.Length << 1;
|
||||
Debug.Assert(!zs[xsPos..zsPos].Overlaps(xs));
|
||||
while (--xsPos >= 0)
|
||||
{
|
||||
zsPos -= 2;
|
||||
Expand64To128(xs[xsPos], zs[zsPos..]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
internal static ulong Expand64To128Rev(ulong x, out ulong low)
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
if (Bmi2.X64.IsSupported)
|
||||
{
|
||||
low = Bmi2.X64.ParallelBitDeposit(x >> 32, 0xAAAAAAAAAAAAAAAAUL);
|
||||
return Bmi2.X64.ParallelBitDeposit(x , 0xAAAAAAAAAAAAAAAAUL);
|
||||
}
|
||||
#endif
|
||||
|
||||
// "shuffle" low half to even bits and high half to odd bits
|
||||
x = Bits.BitPermuteStep(x, 0x00000000FFFF0000UL, 16);
|
||||
x = Bits.BitPermuteStep(x, 0x0000FF000000FF00UL, 8);
|
||||
x = Bits.BitPermuteStep(x, 0x00F000F000F000F0UL, 4);
|
||||
x = Bits.BitPermuteStep(x, 0x0C0C0C0C0C0C0C0CUL, 2);
|
||||
x = Bits.BitPermuteStep(x, 0x2222222222222222UL, 1);
|
||||
|
||||
low = (x ) & M64R;
|
||||
return (x << 1) & M64R;
|
||||
}
|
||||
|
||||
internal static uint Shuffle(uint x)
|
||||
{
|
||||
// "shuffle" low half to even bits and high half to odd bits
|
||||
x = Bits.BitPermuteStep(x, 0x0000FF00U, 8);
|
||||
x = Bits.BitPermuteStep(x, 0x00F000F0U, 4);
|
||||
x = Bits.BitPermuteStep(x, 0x0C0C0C0CU, 2);
|
||||
x = Bits.BitPermuteStep(x, 0x22222222U, 1);
|
||||
return x;
|
||||
}
|
||||
|
||||
internal static ulong Shuffle(ulong x)
|
||||
{
|
||||
// "shuffle" low half to even bits and high half to odd bits
|
||||
x = Bits.BitPermuteStep(x, 0x00000000FFFF0000UL, 16);
|
||||
x = Bits.BitPermuteStep(x, 0x0000FF000000FF00UL, 8);
|
||||
x = Bits.BitPermuteStep(x, 0x00F000F000F000F0UL, 4);
|
||||
x = Bits.BitPermuteStep(x, 0x0C0C0C0C0C0C0C0CUL, 2);
|
||||
x = Bits.BitPermuteStep(x, 0x2222222222222222UL, 1);
|
||||
return x;
|
||||
}
|
||||
|
||||
internal static uint Shuffle2(uint x)
|
||||
{
|
||||
// "shuffle" (twice) low half to even bits and high half to odd bits
|
||||
x = Bits.BitPermuteStep(x, 0x00AA00AAU, 7);
|
||||
x = Bits.BitPermuteStep(x, 0x0000CCCCU, 14);
|
||||
x = Bits.BitPermuteStep(x, 0x00F000F0U, 4);
|
||||
x = Bits.BitPermuteStep(x, 0x0000FF00U, 8);
|
||||
return x;
|
||||
}
|
||||
|
||||
internal static uint Unshuffle(uint x)
|
||||
{
|
||||
// "unshuffle" even bits to low half and odd bits to high half
|
||||
x = Bits.BitPermuteStep(x, 0x22222222U, 1);
|
||||
x = Bits.BitPermuteStep(x, 0x0C0C0C0CU, 2);
|
||||
x = Bits.BitPermuteStep(x, 0x00F000F0U, 4);
|
||||
x = Bits.BitPermuteStep(x, 0x0000FF00U, 8);
|
||||
return x;
|
||||
}
|
||||
|
||||
internal static ulong Unshuffle(ulong x)
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
if (Bmi2.X64.IsSupported)
|
||||
{
|
||||
return Bmi2.X64.ParallelBitExtract(x, 0xAAAAAAAAAAAAAAAAUL) << 32
|
||||
| Bmi2.X64.ParallelBitExtract(x, 0x5555555555555555UL);
|
||||
}
|
||||
#endif
|
||||
|
||||
// "unshuffle" even bits to low half and odd bits to high half
|
||||
x = Bits.BitPermuteStep(x, 0x2222222222222222UL, 1);
|
||||
x = Bits.BitPermuteStep(x, 0x0C0C0C0C0C0C0C0CUL, 2);
|
||||
x = Bits.BitPermuteStep(x, 0x00F000F000F000F0UL, 4);
|
||||
x = Bits.BitPermuteStep(x, 0x0000FF000000FF00UL, 8);
|
||||
x = Bits.BitPermuteStep(x, 0x00000000FFFF0000UL, 16);
|
||||
return x;
|
||||
}
|
||||
|
||||
internal static ulong Unshuffle(ulong x, out ulong even)
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
if (Bmi2.X64.IsSupported)
|
||||
{
|
||||
even = Bmi2.X64.ParallelBitExtract(x, 0x5555555555555555UL);
|
||||
return Bmi2.X64.ParallelBitExtract(x, 0xAAAAAAAAAAAAAAAAUL);
|
||||
}
|
||||
#endif
|
||||
|
||||
ulong u0 = Unshuffle(x);
|
||||
even = u0 & 0x00000000FFFFFFFFUL;
|
||||
return u0 >> 32;
|
||||
}
|
||||
|
||||
internal static ulong Unshuffle(ulong x0, ulong x1, out ulong even)
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
if (Bmi2.X64.IsSupported)
|
||||
{
|
||||
even = Bmi2.X64.ParallelBitExtract(x0, 0x5555555555555555UL)
|
||||
| Bmi2.X64.ParallelBitExtract(x1, 0x5555555555555555UL) << 32;
|
||||
return Bmi2.X64.ParallelBitExtract(x0, 0xAAAAAAAAAAAAAAAAUL)
|
||||
| Bmi2.X64.ParallelBitExtract(x1, 0xAAAAAAAAAAAAAAAAUL) << 32;
|
||||
}
|
||||
#endif
|
||||
|
||||
ulong u0 = Unshuffle(x0);
|
||||
ulong u1 = Unshuffle(x1);
|
||||
even = (u1 << 32) | (u0 & 0x00000000FFFFFFFFUL);
|
||||
return (u0 >> 32) | (u1 & 0xFFFFFFFF00000000UL);
|
||||
}
|
||||
|
||||
internal static uint Unshuffle2(uint x)
|
||||
{
|
||||
// "unshuffle" (twice) even bits to low half and odd bits to high half
|
||||
x = Bits.BitPermuteStep(x, 0x0000FF00U, 8);
|
||||
x = Bits.BitPermuteStep(x, 0x00F000F0U, 4);
|
||||
x = Bits.BitPermuteStep(x, 0x0000CCCCU, 14);
|
||||
x = Bits.BitPermuteStep(x, 0x00AA00AAU, 7);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Interleave.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Interleave.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f203782a670ead4199841bd483d52f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
914
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Mod.cs
vendored
Normal file
914
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Mod.cs
vendored
Normal file
@@ -0,0 +1,914 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Raw
|
||||
{
|
||||
/*
|
||||
* Modular inversion as implemented in this class is based on the paper "Fast constant-time gcd
|
||||
* computation and modular inversion" by Daniel J. Bernstein and Bo-Yin Yang.
|
||||
*/
|
||||
|
||||
internal static class Mod
|
||||
{
|
||||
private const int M30 = 0x3FFFFFFF;
|
||||
private const ulong M32UL = 0xFFFFFFFFUL;
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public static void CheckedModOddInverse(ReadOnlySpan<uint> m, ReadOnlySpan<uint> x, Span<uint> z)
|
||||
#else
|
||||
public static void CheckedModOddInverse(uint[] m, uint[] x, uint[] z)
|
||||
#endif
|
||||
{
|
||||
if (0 == ModOddInverse(m, x, z))
|
||||
throw new ArithmeticException("Inverse does not exist.");
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public static void CheckedModOddInverseVar(ReadOnlySpan<uint> m, ReadOnlySpan<uint> x, Span<uint> z)
|
||||
#else
|
||||
public static void CheckedModOddInverseVar(uint[] m, uint[] x, uint[] z)
|
||||
#endif
|
||||
{
|
||||
if (!ModOddInverseVar(m, x, z))
|
||||
throw new ArithmeticException("Inverse does not exist.");
|
||||
}
|
||||
|
||||
public static uint Inverse32(uint d)
|
||||
{
|
||||
Debug.Assert((d & 1U) == 1U);
|
||||
|
||||
//int x = d + (((d + 1) & 4) << 1); // d.x == 1 mod 2**4
|
||||
uint x = d; // d.x == 1 mod 2**3
|
||||
x *= 2 - d * x; // d.x == 1 mod 2**6
|
||||
x *= 2 - d * x; // d.x == 1 mod 2**12
|
||||
x *= 2 - d * x; // d.x == 1 mod 2**24
|
||||
x *= 2 - d * x; // d.x == 1 mod 2**48
|
||||
Debug.Assert(d * x == 1U);
|
||||
return x;
|
||||
}
|
||||
|
||||
public static ulong Inverse64(ulong d)
|
||||
{
|
||||
Debug.Assert((d & 1UL) == 1UL);
|
||||
|
||||
//ulong x = d + (((d + 1) & 4) << 1); // d.x == 1 mod 2**4
|
||||
ulong x = d; // d.x == 1 mod 2**3
|
||||
x *= 2 - d * x; // d.x == 1 mod 2**6
|
||||
x *= 2 - d * x; // d.x == 1 mod 2**12
|
||||
x *= 2 - d * x; // d.x == 1 mod 2**24
|
||||
x *= 2 - d * x; // d.x == 1 mod 2**48
|
||||
x *= 2 - d * x; // d.x == 1 mod 2**96
|
||||
Debug.Assert(d * x == 1UL);
|
||||
return x;
|
||||
}
|
||||
|
||||
public static uint ModOddInverse(uint[] m, uint[] x, uint[] z)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return ModOddInverse(m.AsSpan(), x.AsSpan(), z.AsSpan());
|
||||
#else
|
||||
int len32 = m.Length;
|
||||
Debug.Assert(len32 > 0);
|
||||
Debug.Assert((m[0] & 1) != 0);
|
||||
Debug.Assert(m[len32 - 1] != 0);
|
||||
|
||||
int bits = (len32 << 5) - Integers.NumberOfLeadingZeros((int)m[len32 - 1]);
|
||||
int len30 = (bits + 29) / 30;
|
||||
|
||||
int[] t = new int[4];
|
||||
int[] D = new int[len30];
|
||||
int[] E = new int[len30];
|
||||
int[] F = new int[len30];
|
||||
int[] G = new int[len30];
|
||||
int[] M = new int[len30];
|
||||
|
||||
E[0] = 1;
|
||||
Encode30(bits, x, 0, G, 0);
|
||||
Encode30(bits, m, 0, M, 0);
|
||||
Array.Copy(M, 0, F, 0, len30);
|
||||
|
||||
int delta = 0;
|
||||
int m0Inv32 = (int)Inverse32((uint)M[0]);
|
||||
int maxDivsteps = GetMaximumDivsteps(bits);
|
||||
|
||||
for (int divSteps = 0; divSteps < maxDivsteps; divSteps += 30)
|
||||
{
|
||||
delta = Divsteps30(delta, F[0], G[0], t);
|
||||
UpdateDE30(len30, D, E, t, m0Inv32, M);
|
||||
UpdateFG30(len30, F, G, t);
|
||||
}
|
||||
|
||||
int signF = F[len30 - 1] >> 31;
|
||||
CNegate30(len30, signF, F);
|
||||
|
||||
/*
|
||||
* D is in the range (-2.M, M). First, conditionally add M if D is negative, to bring it
|
||||
* into the range (-M, M). Then normalize by conditionally negating (according to signF)
|
||||
* and/or then adding M, to bring it into the range [0, M).
|
||||
*/
|
||||
CNormalize30(len30, signF, D, M);
|
||||
|
||||
Decode30(bits, D, 0, z, 0);
|
||||
Debug.Assert(0 != Nat.LessThan(m.Length, z, m));
|
||||
|
||||
return (uint)(EqualTo(len30, F, 1) & EqualToZero(len30, G));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public static uint ModOddInverse(ReadOnlySpan<uint> m, ReadOnlySpan<uint> x, Span<uint> z)
|
||||
{
|
||||
int len32 = m.Length;
|
||||
Debug.Assert(len32 > 0);
|
||||
Debug.Assert((m[0] & 1) != 0);
|
||||
Debug.Assert(m[len32 - 1] != 0);
|
||||
|
||||
int bits = (len32 << 5) - Integers.NumberOfLeadingZeros((int)m[len32 - 1]);
|
||||
int len30 = (bits + 29) / 30;
|
||||
|
||||
Span<int> alloc = len30 <= 50
|
||||
? stackalloc int[len30 * 5]
|
||||
: new int[len30 * 5];
|
||||
|
||||
Span<int> t = stackalloc int[4];
|
||||
Span<int> D = alloc[..len30]; alloc = alloc[len30..];
|
||||
Span<int> E = alloc[..len30]; alloc = alloc[len30..];
|
||||
Span<int> F = alloc[..len30]; alloc = alloc[len30..];
|
||||
Span<int> G = alloc[..len30]; alloc = alloc[len30..];
|
||||
Span<int> M = alloc[..len30];
|
||||
|
||||
E[0] = 1;
|
||||
Encode30(bits, x, G);
|
||||
Encode30(bits, m, M);
|
||||
M.CopyTo(F);
|
||||
|
||||
int delta = 0;
|
||||
int m0Inv32 = (int)Inverse32((uint)M[0]);
|
||||
int maxDivsteps = GetMaximumDivsteps(bits);
|
||||
|
||||
for (int divSteps = 0; divSteps < maxDivsteps; divSteps += 30)
|
||||
{
|
||||
delta = Divsteps30(delta, F[0], G[0], t);
|
||||
UpdateDE30(len30, D, E, t, m0Inv32, M);
|
||||
UpdateFG30(len30, F, G, t);
|
||||
}
|
||||
|
||||
int signF = F[len30 - 1] >> 31;
|
||||
CNegate30(len30, signF, F);
|
||||
|
||||
/*
|
||||
* D is in the range (-2.M, M). First, conditionally add M if D is negative, to bring it
|
||||
* into the range (-M, M). Then normalize by conditionally negating (according to signF)
|
||||
* and/or then adding M, to bring it into the range [0, M).
|
||||
*/
|
||||
CNormalize30(len30, signF, D, M);
|
||||
|
||||
Decode30(bits, D, z);
|
||||
Debug.Assert(0 != Nat.LessThan(m.Length, z, m));
|
||||
|
||||
return (uint)(EqualTo(len30, F, 1) & EqualToZero(len30, G));
|
||||
}
|
||||
#endif
|
||||
|
||||
public static bool ModOddInverseVar(uint[] m, uint[] x, uint[] z)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
return ModOddInverseVar(m.AsSpan(), x.AsSpan(), z.AsSpan());
|
||||
#else
|
||||
int len32 = m.Length;
|
||||
Debug.Assert(len32 > 0);
|
||||
Debug.Assert((m[0] & 1) != 0);
|
||||
Debug.Assert(m[len32 - 1] != 0);
|
||||
|
||||
int bits = (len32 << 5) - Integers.NumberOfLeadingZeros((int)m[len32 - 1]);
|
||||
int len30 = (bits + 29) / 30;
|
||||
|
||||
int[] t = new int[4];
|
||||
int[] D = new int[len30];
|
||||
int[] E = new int[len30];
|
||||
int[] F = new int[len30];
|
||||
int[] G = new int[len30];
|
||||
int[] M = new int[len30];
|
||||
|
||||
E[0] = 1;
|
||||
Encode30(bits, x, 0, G, 0);
|
||||
Encode30(bits, m, 0, M, 0);
|
||||
Array.Copy(M, 0, F, 0, len30);
|
||||
|
||||
int clzG = Integers.NumberOfLeadingZeros(G[len30 - 1] | 1) - (len30 * 30 + 2 - bits);
|
||||
int eta = -1 - clzG;
|
||||
int lenDE = len30, lenFG = len30;
|
||||
int m0Inv32 = (int)Inverse32((uint)M[0]);
|
||||
int maxDivsteps = GetMaximumDivsteps(bits);
|
||||
|
||||
int divsteps = 0;
|
||||
while (!IsZero(lenFG, G))
|
||||
{
|
||||
if (divsteps >= maxDivsteps)
|
||||
return false;
|
||||
|
||||
divsteps += 30;
|
||||
|
||||
eta = Divsteps30Var(eta, F[0], G[0], t);
|
||||
UpdateDE30(lenDE, D, E, t, m0Inv32, M);
|
||||
UpdateFG30(lenFG, F, G, t);
|
||||
|
||||
int fn = F[lenFG - 1];
|
||||
int gn = G[lenFG - 1];
|
||||
|
||||
int cond = (lenFG - 2) >> 31;
|
||||
cond |= fn ^ (fn >> 31);
|
||||
cond |= gn ^ (gn >> 31);
|
||||
|
||||
if (cond == 0)
|
||||
{
|
||||
F[lenFG - 2] |= fn << 30;
|
||||
G[lenFG - 2] |= gn << 30;
|
||||
--lenFG;
|
||||
}
|
||||
}
|
||||
|
||||
int signF = F[lenFG - 1] >> 31;
|
||||
|
||||
/*
|
||||
* D is in the range (-2.M, M). First, conditionally add M if D is negative, to bring it
|
||||
* into the range (-M, M). Then normalize by conditionally negating (according to signF)
|
||||
* and/or then adding M, to bring it into the range [0, M).
|
||||
*/
|
||||
int signD = D[lenDE - 1] >> 31;
|
||||
if (signD < 0)
|
||||
{
|
||||
signD = Add30(lenDE, D, M);
|
||||
}
|
||||
if (signF < 0)
|
||||
{
|
||||
signD = Negate30(lenDE, D);
|
||||
signF = Negate30(lenFG, F);
|
||||
}
|
||||
Debug.Assert(0 == signF);
|
||||
|
||||
if (!IsOne(lenFG, F))
|
||||
return false;
|
||||
|
||||
if (signD < 0)
|
||||
{
|
||||
signD = Add30(lenDE, D, M);
|
||||
}
|
||||
Debug.Assert(0 == signD);
|
||||
|
||||
Decode30(bits, D, 0, z, 0);
|
||||
Debug.Assert(!Nat.Gte(m.Length, z, m));
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public static bool ModOddInverseVar(ReadOnlySpan<uint> m, ReadOnlySpan<uint> x, Span<uint> z)
|
||||
{
|
||||
int len32 = m.Length;
|
||||
Debug.Assert(len32 > 0);
|
||||
Debug.Assert((m[0] & 1) != 0);
|
||||
Debug.Assert(m[len32 - 1] != 0);
|
||||
|
||||
int bits = (len32 << 5) - Integers.NumberOfLeadingZeros((int)m[len32 - 1]);
|
||||
int len30 = (bits + 29) / 30;
|
||||
|
||||
Span<int> alloc = len30 <= 50
|
||||
? stackalloc int[len30 * 5]
|
||||
: new int[len30 * 5];
|
||||
|
||||
Span<int> t = stackalloc int[4];
|
||||
Span<int> D = alloc[..len30]; alloc = alloc[len30..];
|
||||
Span<int> E = alloc[..len30]; alloc = alloc[len30..];
|
||||
Span<int> F = alloc[..len30]; alloc = alloc[len30..];
|
||||
Span<int> G = alloc[..len30]; alloc = alloc[len30..];
|
||||
Span<int> M = alloc[..len30];
|
||||
|
||||
E[0] = 1;
|
||||
Encode30(bits, x, G);
|
||||
Encode30(bits, m, M);
|
||||
M.CopyTo(F);
|
||||
|
||||
int clzG = Integers.NumberOfLeadingZeros(G[len30 - 1] | 1) - (len30 * 30 + 2 - bits);
|
||||
int eta = -1 - clzG;
|
||||
int lenDE = len30, lenFG = len30;
|
||||
int m0Inv32 = (int)Inverse32((uint)M[0]);
|
||||
int maxDivsteps = GetMaximumDivsteps(bits);
|
||||
|
||||
int divsteps = 0;
|
||||
while (!IsZero(lenFG, G))
|
||||
{
|
||||
if (divsteps >= maxDivsteps)
|
||||
return false;
|
||||
|
||||
divsteps += 30;
|
||||
|
||||
eta = Divsteps30Var(eta, F[0], G[0], t);
|
||||
UpdateDE30(lenDE, D, E, t, m0Inv32, M);
|
||||
UpdateFG30(lenFG, F, G, t);
|
||||
|
||||
int fn = F[lenFG - 1];
|
||||
int gn = G[lenFG - 1];
|
||||
|
||||
int cond = (lenFG - 2) >> 31;
|
||||
cond |= fn ^ (fn >> 31);
|
||||
cond |= gn ^ (gn >> 31);
|
||||
|
||||
if (cond == 0)
|
||||
{
|
||||
F[lenFG - 2] |= fn << 30;
|
||||
G[lenFG - 2] |= gn << 30;
|
||||
--lenFG;
|
||||
}
|
||||
}
|
||||
|
||||
int signF = F[lenFG - 1] >> 31;
|
||||
|
||||
/*
|
||||
* D is in the range (-2.M, M). First, conditionally add M if D is negative, to bring it
|
||||
* into the range (-M, M). Then normalize by conditionally negating (according to signF)
|
||||
* and/or then adding M, to bring it into the range [0, M).
|
||||
*/
|
||||
int signD = D[lenDE - 1] >> 31;
|
||||
if (signD < 0)
|
||||
{
|
||||
signD = Add30(lenDE, D, M);
|
||||
}
|
||||
if (signF < 0)
|
||||
{
|
||||
signD = Negate30(lenDE, D);
|
||||
signF = Negate30(lenFG, F);
|
||||
}
|
||||
Debug.Assert(0 == signF);
|
||||
|
||||
if (!IsOne(lenFG, F))
|
||||
return false;
|
||||
|
||||
if (signD < 0)
|
||||
{
|
||||
signD = Add30(lenDE, D, M);
|
||||
}
|
||||
Debug.Assert(0 == signD);
|
||||
|
||||
Decode30(bits, D, z);
|
||||
Debug.Assert(!Nat.Gte(m.Length, z, m));
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
public static uint[] Random(SecureRandom random, uint[] p)
|
||||
{
|
||||
int len = p.Length;
|
||||
uint[] s = Nat.Create(len);
|
||||
|
||||
uint m = p[len - 1];
|
||||
m |= m >> 1;
|
||||
m |= m >> 2;
|
||||
m |= m >> 4;
|
||||
m |= m >> 8;
|
||||
m |= m >> 16;
|
||||
|
||||
byte[] bytes = new byte[len << 2];
|
||||
do
|
||||
{
|
||||
random.NextBytes(bytes);
|
||||
Pack.BE_To_UInt32(bytes, 0, s);
|
||||
s[len - 1] &= m;
|
||||
}
|
||||
while (Nat.Gte(len, s, p));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public static void Random(SecureRandom random, ReadOnlySpan<uint> p, Span<uint> z)
|
||||
{
|
||||
int len = p.Length;
|
||||
if (z.Length < len)
|
||||
throw new ArgumentException("insufficient space", nameof(z));
|
||||
|
||||
var s = z[..len];
|
||||
|
||||
uint m = p[len - 1];
|
||||
m |= m >> 1;
|
||||
m |= m >> 2;
|
||||
m |= m >> 4;
|
||||
m |= m >> 8;
|
||||
m |= m >> 16;
|
||||
|
||||
Span<byte> bytes = len <= 256
|
||||
? stackalloc byte[len << 2]
|
||||
: new byte[len << 2];
|
||||
|
||||
do
|
||||
{
|
||||
random.NextBytes(bytes);
|
||||
Pack.BE_To_UInt32(bytes, s);
|
||||
s[len - 1] &= m;
|
||||
}
|
||||
while (Nat.Gte(len, s, p));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static int Add30(int len30, Span<int> D, ReadOnlySpan<int> M)
|
||||
#else
|
||||
private static int Add30(int len30, int[] D, int[] M)
|
||||
#endif
|
||||
{
|
||||
Debug.Assert(len30 > 0);
|
||||
Debug.Assert(D.Length >= len30);
|
||||
Debug.Assert(M.Length >= len30);
|
||||
|
||||
int c = 0, last = len30 - 1;
|
||||
for (int i = 0; i < last; ++i)
|
||||
{
|
||||
c += D[i] + M[i];
|
||||
D[i] = c & M30; c >>= 30;
|
||||
}
|
||||
c += D[last] + M[last];
|
||||
D[last] = c; c >>= 30;
|
||||
return c;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static void CNegate30(int len30, int cond, Span<int> D)
|
||||
#else
|
||||
private static void CNegate30(int len30, int cond, int[] D)
|
||||
#endif
|
||||
{
|
||||
Debug.Assert(len30 > 0);
|
||||
Debug.Assert(D.Length >= len30);
|
||||
|
||||
int c = 0, last = len30 - 1;
|
||||
for (int i = 0; i < last; ++i)
|
||||
{
|
||||
c += (D[i] ^ cond) - cond;
|
||||
D[i] = c & M30; c >>= 30;
|
||||
}
|
||||
c += (D[last] ^ cond) - cond;
|
||||
D[last] = c;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static void CNormalize30(int len30, int condNegate, Span<int> D, ReadOnlySpan<int> M)
|
||||
#else
|
||||
private static void CNormalize30(int len30, int condNegate, int[] D, int[] M)
|
||||
#endif
|
||||
{
|
||||
Debug.Assert(len30 > 0);
|
||||
Debug.Assert(D.Length >= len30);
|
||||
Debug.Assert(M.Length >= len30);
|
||||
|
||||
int last = len30 - 1;
|
||||
|
||||
{
|
||||
int c = 0, condAdd = D[last] >> 31;
|
||||
for (int i = 0; i < last; ++i)
|
||||
{
|
||||
int di = D[i] + (M[i] & condAdd);
|
||||
di = (di ^ condNegate) - condNegate;
|
||||
c += di; D[i] = c & M30; c >>= 30;
|
||||
}
|
||||
{
|
||||
int di = D[last] + (M[last] & condAdd);
|
||||
di = (di ^ condNegate) - condNegate;
|
||||
c += di; D[last] = c;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int c = 0, condAdd = D[last] >> 31;
|
||||
for (int i = 0; i < last; ++i)
|
||||
{
|
||||
int di = D[i] + (M[i] & condAdd);
|
||||
c += di; D[i] = c & M30; c >>= 30;
|
||||
}
|
||||
{
|
||||
int di = D[last] + (M[last] & condAdd);
|
||||
c += di; D[last] = c;
|
||||
}
|
||||
Debug.Assert(c >> 30 == 0);
|
||||
}
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static void Decode30(int bits, ReadOnlySpan<int> x, Span<uint> z)
|
||||
{
|
||||
Debug.Assert(bits > 0);
|
||||
|
||||
int avail = 0;
|
||||
ulong data = 0L;
|
||||
|
||||
int xOff = 0, zOff = 0;
|
||||
while (bits > 0)
|
||||
{
|
||||
while (avail < System.Math.Min(32, bits))
|
||||
{
|
||||
data |= (ulong)x[xOff++] << avail;
|
||||
avail += 30;
|
||||
}
|
||||
|
||||
z[zOff++] = (uint)data; data >>= 32;
|
||||
avail -= 32;
|
||||
bits -= 32;
|
||||
}
|
||||
}
|
||||
#else
|
||||
private static void Decode30(int bits, int[] x, int xOff, uint[] z, int zOff)
|
||||
{
|
||||
Debug.Assert(bits > 0);
|
||||
|
||||
int avail = 0;
|
||||
ulong data = 0L;
|
||||
|
||||
while (bits > 0)
|
||||
{
|
||||
while (avail < System.Math.Min(32, bits))
|
||||
{
|
||||
data |= (ulong)x[xOff++] << avail;
|
||||
avail += 30;
|
||||
}
|
||||
|
||||
z[zOff++] = (uint)data; data >>= 32;
|
||||
avail -= 32;
|
||||
bits -= 32;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static int Divsteps30(int delta, int f0, int g0, Span<int> t)
|
||||
#else
|
||||
private static int Divsteps30(int delta, int f0, int g0, int[] t)
|
||||
#endif
|
||||
{
|
||||
int u = 1 << 30, v = 0, q = 0, r = 1 << 30;
|
||||
int f = f0, g = g0;
|
||||
|
||||
for (int i = 0; i < 30; ++i)
|
||||
{
|
||||
Debug.Assert((f & 1) == 1);
|
||||
Debug.Assert(((u >> (30 - i)) * f0 + (v >> (30 - i)) * g0) == f << i);
|
||||
Debug.Assert(((q >> (30 - i)) * f0 + (r >> (30 - i)) * g0) == g << i);
|
||||
|
||||
int c1 = delta >> 31;
|
||||
int c2 = -(g & 1);
|
||||
|
||||
int x = f ^ c1;
|
||||
int y = u ^ c1;
|
||||
int z = v ^ c1;
|
||||
|
||||
g -= x & c2;
|
||||
q -= y & c2;
|
||||
r -= z & c2;
|
||||
|
||||
c2 &= ~c1;
|
||||
delta = (delta ^ c2) - (c2 - 1);
|
||||
|
||||
f += g & c2;
|
||||
u += q & c2;
|
||||
v += r & c2;
|
||||
|
||||
g >>= 1;
|
||||
q >>= 1;
|
||||
r >>= 1;
|
||||
}
|
||||
|
||||
t[0] = u;
|
||||
t[1] = v;
|
||||
t[2] = q;
|
||||
t[3] = r;
|
||||
|
||||
return delta;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static int Divsteps30Var(int eta, int f0, int g0, Span<int> t)
|
||||
#else
|
||||
private static int Divsteps30Var(int eta, int f0, int g0, int[] t)
|
||||
#endif
|
||||
{
|
||||
int u = 1, v = 0, q = 0, r = 1;
|
||||
int f = f0, g = g0, m, w, x, y, z;
|
||||
int i = 30, limit, zeros;
|
||||
|
||||
for (; ; )
|
||||
{
|
||||
// Use a sentinel bit to count zeros only up to i.
|
||||
zeros = Integers.NumberOfTrailingZeros(g | (-1 << i));
|
||||
|
||||
g >>= zeros;
|
||||
u <<= zeros;
|
||||
v <<= zeros;
|
||||
eta -= zeros;
|
||||
i -= zeros;
|
||||
|
||||
if (i <= 0)
|
||||
break;
|
||||
|
||||
Debug.Assert((f & 1) == 1);
|
||||
Debug.Assert((g & 1) == 1);
|
||||
Debug.Assert((u * f0 + v * g0) == f << (30 - i));
|
||||
Debug.Assert((q * f0 + r * g0) == g << (30 - i));
|
||||
|
||||
if (eta < 0)
|
||||
{
|
||||
eta = -eta;
|
||||
x = f; f = g; g = -x;
|
||||
y = u; u = q; q = -y;
|
||||
z = v; v = r; r = -z;
|
||||
|
||||
// Handle up to 6 divsteps at once, subject to eta and i.
|
||||
limit = (eta + 1) > i ? i : (eta + 1);
|
||||
m = (int)((uint.MaxValue >> (32 - limit)) & 63U);
|
||||
|
||||
w = (f * g * (f * f - 2)) & m;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle up to 4 divsteps at once, subject to eta and i.
|
||||
limit = (eta + 1) > i ? i : (eta + 1);
|
||||
m = (int)((uint.MaxValue >> (32 - limit)) & 15U);
|
||||
|
||||
w = f + (((f + 1) & 4) << 1);
|
||||
w = (-w * g) & m;
|
||||
}
|
||||
|
||||
g += f * w;
|
||||
q += u * w;
|
||||
r += v * w;
|
||||
|
||||
Debug.Assert((g & m) == 0);
|
||||
}
|
||||
|
||||
t[0] = u;
|
||||
t[1] = v;
|
||||
t[2] = q;
|
||||
t[3] = r;
|
||||
|
||||
return eta;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static void Encode30(int bits, ReadOnlySpan<uint> x, Span<int> z)
|
||||
{
|
||||
Debug.Assert(bits > 0);
|
||||
|
||||
int avail = 0;
|
||||
ulong data = 0UL;
|
||||
|
||||
int xOff = 0, zOff = 0;
|
||||
while (bits > 0)
|
||||
{
|
||||
if (avail < System.Math.Min(30, bits))
|
||||
{
|
||||
data |= (x[xOff++] & M32UL) << avail;
|
||||
avail += 32;
|
||||
}
|
||||
|
||||
z[zOff++] = (int)data & M30; data >>= 30;
|
||||
avail -= 30;
|
||||
bits -= 30;
|
||||
}
|
||||
}
|
||||
#else
|
||||
private static void Encode30(int bits, uint[] x, int xOff, int[] z, int zOff)
|
||||
{
|
||||
Debug.Assert(bits > 0);
|
||||
|
||||
int avail = 0;
|
||||
ulong data = 0UL;
|
||||
|
||||
while (bits > 0)
|
||||
{
|
||||
if (avail < System.Math.Min(30, bits))
|
||||
{
|
||||
data |= (x[xOff++] & M32UL) << avail;
|
||||
avail += 32;
|
||||
}
|
||||
|
||||
z[zOff++] = (int)data & M30; data >>= 30;
|
||||
avail -= 30;
|
||||
bits -= 30;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static int EqualTo(int len, ReadOnlySpan<int> x, int y)
|
||||
#else
|
||||
private static int EqualTo(int len, int[] x, int y)
|
||||
#endif
|
||||
{
|
||||
int d = x[0] ^ y;
|
||||
for (int i = 1; i < len; ++i)
|
||||
{
|
||||
d |= x[i];
|
||||
}
|
||||
d = (int)((uint)d >> 1) | (d & 1);
|
||||
return (d - 1) >> 31;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static int EqualToZero(int len, ReadOnlySpan<int> x)
|
||||
#else
|
||||
private static int EqualToZero(int len, int[] x)
|
||||
#endif
|
||||
{
|
||||
int d = 0;
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
d |= x[i];
|
||||
}
|
||||
d = (int)((uint)d >> 1) | (d & 1);
|
||||
return (d - 1) >> 31;
|
||||
}
|
||||
|
||||
private static int GetMaximumDivsteps(int bits)
|
||||
{
|
||||
return (49 * bits + (bits < 46 ? 80 : 47)) / 17;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static bool IsOne(int len, ReadOnlySpan<int> x)
|
||||
#else
|
||||
private static bool IsOne(int len, int[] x)
|
||||
#endif
|
||||
{
|
||||
if (x[0] != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 1; i < len; ++i)
|
||||
{
|
||||
if (x[i] != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static bool IsZero(int len, ReadOnlySpan<int> x)
|
||||
#else
|
||||
private static bool IsZero(int len, int[] x)
|
||||
#endif
|
||||
{
|
||||
if (x[0] != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 1; i < len; ++i)
|
||||
{
|
||||
if (x[i] != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static int Negate30(int len30, Span<int> D)
|
||||
#else
|
||||
private static int Negate30(int len30, int[] D)
|
||||
#endif
|
||||
{
|
||||
Debug.Assert(len30 > 0);
|
||||
Debug.Assert(D.Length >= len30);
|
||||
|
||||
int c = 0, last = len30 - 1;
|
||||
for (int i = 0; i < last; ++i)
|
||||
{
|
||||
c -= D[i];
|
||||
D[i] = c & M30; c >>= 30;
|
||||
}
|
||||
c -= D[last];
|
||||
D[last] = c; c >>= 30;
|
||||
return c;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static void UpdateDE30(int len30, Span<int> D, Span<int> E, ReadOnlySpan<int> t, int m0Inv32,
|
||||
ReadOnlySpan<int> M)
|
||||
#else
|
||||
private static void UpdateDE30(int len30, int[] D, int[] E, int[] t, int m0Inv32, int[] M)
|
||||
#endif
|
||||
{
|
||||
Debug.Assert(len30 > 0);
|
||||
Debug.Assert(D.Length >= len30);
|
||||
Debug.Assert(E.Length >= len30);
|
||||
Debug.Assert(M.Length >= len30);
|
||||
Debug.Assert(m0Inv32 * M[0] == 1);
|
||||
|
||||
int u = t[0], v = t[1], q = t[2], r = t[3];
|
||||
int di, ei, i, md, me, mi, sd, se;
|
||||
long cd, ce;
|
||||
|
||||
/*
|
||||
* We accept D (E) in the range (-2.M, M) and conceptually add the modulus to the input
|
||||
* value if it is initially negative. Instead of adding it explicitly, we add u and/or v (q
|
||||
* and/or r) to md (me).
|
||||
*/
|
||||
sd = D[len30 - 1] >> 31;
|
||||
se = E[len30 - 1] >> 31;
|
||||
|
||||
md = (u & sd) + (v & se);
|
||||
me = (q & sd) + (r & se);
|
||||
|
||||
mi = M[0];
|
||||
di = D[0];
|
||||
ei = E[0];
|
||||
|
||||
cd = (long)u * di + (long)v * ei;
|
||||
ce = (long)q * di + (long)r * ei;
|
||||
|
||||
/*
|
||||
* Subtract from md/me an extra term in the range [0, 2^30) such that the low 30 bits of the
|
||||
* intermediate D/E values will be 0, allowing clean division by 2^30. The final D/E are
|
||||
* thus in the range (-2.M, M), consistent with the input constraint.
|
||||
*/
|
||||
md -= (m0Inv32 * (int)cd + md) & M30;
|
||||
me -= (m0Inv32 * (int)ce + me) & M30;
|
||||
|
||||
cd += (long)mi * md;
|
||||
ce += (long)mi * me;
|
||||
|
||||
Debug.Assert(((int)cd & M30) == 0);
|
||||
Debug.Assert(((int)ce & M30) == 0);
|
||||
|
||||
cd >>= 30;
|
||||
ce >>= 30;
|
||||
|
||||
for (i = 1; i < len30; ++i)
|
||||
{
|
||||
mi = M[i];
|
||||
di = D[i];
|
||||
ei = E[i];
|
||||
|
||||
cd += (long)u * di + (long)v * ei + (long)mi * md;
|
||||
ce += (long)q * di + (long)r * ei + (long)mi * me;
|
||||
|
||||
D[i - 1] = (int)cd & M30; cd >>= 30;
|
||||
E[i - 1] = (int)ce & M30; ce >>= 30;
|
||||
}
|
||||
|
||||
D[len30 - 1] = (int)cd;
|
||||
E[len30 - 1] = (int)ce;
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
private static void UpdateFG30(int len30, Span<int> F, Span<int> G, ReadOnlySpan<int> t)
|
||||
#else
|
||||
private static void UpdateFG30(int len30, int[] F, int[] G, int[] t)
|
||||
#endif
|
||||
{
|
||||
Debug.Assert(len30 > 0);
|
||||
Debug.Assert(F.Length >= len30);
|
||||
Debug.Assert(G.Length >= len30);
|
||||
|
||||
int u = t[0], v = t[1], q = t[2], r = t[3];
|
||||
int fi, gi, i;
|
||||
long cf, cg;
|
||||
|
||||
fi = F[0];
|
||||
gi = G[0];
|
||||
|
||||
cf = (long)u * fi + (long)v * gi;
|
||||
cg = (long)q * fi + (long)r * gi;
|
||||
|
||||
Debug.Assert(((int)cf & M30) == 0);
|
||||
Debug.Assert(((int)cg & M30) == 0);
|
||||
|
||||
cf >>= 30;
|
||||
cg >>= 30;
|
||||
|
||||
for (i = 1; i < len30; ++i)
|
||||
{
|
||||
fi = F[i];
|
||||
gi = G[i];
|
||||
|
||||
cf += (long)u * fi + (long)v * gi;
|
||||
cg += (long)q * fi + (long)r * gi;
|
||||
|
||||
F[i - 1] = (int)cf & M30; cf >>= 30;
|
||||
G[i - 1] = (int)cg & M30; cg >>= 30;
|
||||
}
|
||||
|
||||
F[len30 - 1] = (int)cf;
|
||||
G[len30 - 1] = (int)cg;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Mod.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Mod.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f21140cfe49f0b44ba52cdfa2ca5bdca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
2905
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat.cs
vendored
Normal file
2905
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5485273b1b8b0f543bd41301d46c1092
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
846
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat128.cs
vendored
Normal file
846
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat128.cs
vendored
Normal file
@@ -0,0 +1,846 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Raw
|
||||
{
|
||||
internal abstract class Nat128
|
||||
{
|
||||
private const ulong M = 0xFFFFFFFFUL;
|
||||
|
||||
public static uint Add(uint[] x, uint[] y, uint[] z)
|
||||
{
|
||||
ulong c = 0;
|
||||
c += (ulong)x[0] + y[0];
|
||||
z[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[1] + y[1];
|
||||
z[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[2] + y[2];
|
||||
z[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[3] + y[3];
|
||||
z[3] = (uint)c;
|
||||
c >>= 32;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static uint AddBothTo(uint[] x, uint[] y, uint[] z)
|
||||
{
|
||||
ulong c = 0;
|
||||
c += (ulong)x[0] + y[0] + z[0];
|
||||
z[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[1] + y[1] + z[1];
|
||||
z[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[2] + y[2] + z[2];
|
||||
z[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[3] + y[3] + z[3];
|
||||
z[3] = (uint)c;
|
||||
c >>= 32;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static uint AddTo(uint[] x, uint[] z)
|
||||
{
|
||||
ulong c = 0;
|
||||
c += (ulong)x[0] + z[0];
|
||||
z[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[1] + z[1];
|
||||
z[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[2] + z[2];
|
||||
z[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[3] + z[3];
|
||||
z[3] = (uint)c;
|
||||
c >>= 32;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static uint AddTo(uint[] x, int xOff, uint[] z, int zOff, uint cIn)
|
||||
{
|
||||
ulong c = cIn;
|
||||
c += (ulong)x[xOff + 0] + z[zOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[xOff + 1] + z[zOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[xOff + 2] + z[zOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[xOff + 3] + z[zOff + 3];
|
||||
z[zOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static uint AddToEachOther(uint[] u, int uOff, uint[] v, int vOff)
|
||||
{
|
||||
ulong c = 0;
|
||||
c += (ulong)u[uOff + 0] + v[vOff + 0];
|
||||
u[uOff + 0] = (uint)c;
|
||||
v[vOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)u[uOff + 1] + v[vOff + 1];
|
||||
u[uOff + 1] = (uint)c;
|
||||
v[vOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)u[uOff + 2] + v[vOff + 2];
|
||||
u[uOff + 2] = (uint)c;
|
||||
v[vOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)u[uOff + 3] + v[vOff + 3];
|
||||
u[uOff + 3] = (uint)c;
|
||||
v[vOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static void Copy(uint[] x, uint[] z)
|
||||
{
|
||||
z[0] = x[0];
|
||||
z[1] = x[1];
|
||||
z[2] = x[2];
|
||||
z[3] = x[3];
|
||||
}
|
||||
|
||||
public static void Copy(uint[] x, int xOff, uint[] z, int zOff)
|
||||
{
|
||||
z[zOff + 0] = x[xOff + 0];
|
||||
z[zOff + 1] = x[xOff + 1];
|
||||
z[zOff + 2] = x[xOff + 2];
|
||||
z[zOff + 3] = x[xOff + 3];
|
||||
}
|
||||
|
||||
public static void Copy64(ulong[] x, ulong[] z)
|
||||
{
|
||||
z[0] = x[0];
|
||||
z[1] = x[1];
|
||||
}
|
||||
|
||||
public static void Copy64(ulong[] x, int xOff, ulong[] z, int zOff)
|
||||
{
|
||||
z[zOff + 0] = x[xOff + 0];
|
||||
z[zOff + 1] = x[xOff + 1];
|
||||
}
|
||||
|
||||
public static uint[] Create()
|
||||
{
|
||||
return new uint[4];
|
||||
}
|
||||
|
||||
public static ulong[] Create64()
|
||||
{
|
||||
return new ulong[2];
|
||||
}
|
||||
|
||||
public static uint[] CreateExt()
|
||||
{
|
||||
return new uint[8];
|
||||
}
|
||||
|
||||
public static ulong[] CreateExt64()
|
||||
{
|
||||
return new ulong[4];
|
||||
}
|
||||
|
||||
public static bool Diff(uint[] x, int xOff, uint[] y, int yOff, uint[] z, int zOff)
|
||||
{
|
||||
bool pos = Gte(x, xOff, y, yOff);
|
||||
if (pos)
|
||||
{
|
||||
Sub(x, xOff, y, yOff, z, zOff);
|
||||
}
|
||||
else
|
||||
{
|
||||
Sub(y, yOff, x, xOff, z, zOff);
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
public static bool Eq(uint[] x, uint[] y)
|
||||
{
|
||||
for (int i = 3; i >= 0; --i)
|
||||
{
|
||||
if (x[i] != y[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Eq64(ulong[] x, ulong[] y)
|
||||
{
|
||||
for (int i = 1; i >= 0; --i)
|
||||
{
|
||||
if (x[i] != y[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static uint GetBit(uint[] x, int bit)
|
||||
{
|
||||
if (bit == 0)
|
||||
{
|
||||
return x[0] & 1;
|
||||
}
|
||||
if ((bit & 127) != bit)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int w = bit >> 5;
|
||||
int b = bit & 31;
|
||||
return (x[w] >> b) & 1;
|
||||
}
|
||||
|
||||
public static bool Gte(uint[] x, uint[] y)
|
||||
{
|
||||
for (int i = 3; i >= 0; --i)
|
||||
{
|
||||
uint x_i = x[i], y_i = y[i];
|
||||
if (x_i < y_i)
|
||||
return false;
|
||||
if (x_i > y_i)
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Gte(uint[] x, int xOff, uint[] y, int yOff)
|
||||
{
|
||||
for (int i = 3; i >= 0; --i)
|
||||
{
|
||||
uint x_i = x[xOff + i], y_i = y[yOff + i];
|
||||
if (x_i < y_i)
|
||||
return false;
|
||||
if (x_i > y_i)
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsOne(uint[] x)
|
||||
{
|
||||
if (x[0] != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 1; i < 4; ++i)
|
||||
{
|
||||
if (x[i] != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsOne64(ulong[] x)
|
||||
{
|
||||
if (x[0] != 1UL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 1; i < 2; ++i)
|
||||
{
|
||||
if (x[i] != 0UL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsZero(uint[] x)
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
if (x[i] != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsZero64(ulong[] x)
|
||||
{
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if (x[i] != 0UL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void Mul(uint[] x, uint[] y, uint[] zz)
|
||||
{
|
||||
ulong y_0 = y[0];
|
||||
ulong y_1 = y[1];
|
||||
ulong y_2 = y[2];
|
||||
ulong y_3 = y[3];
|
||||
|
||||
{
|
||||
ulong c = 0, x_0 = x[0];
|
||||
c += x_0 * y_0;
|
||||
zz[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_1;
|
||||
zz[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_2;
|
||||
zz[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_3;
|
||||
zz[3] = (uint)c;
|
||||
c >>= 32;
|
||||
zz[4] = (uint)c;
|
||||
}
|
||||
|
||||
for (int i = 1; i < 4; ++i)
|
||||
{
|
||||
ulong c = 0, x_i = x[i];
|
||||
c += x_i * y_0 + zz[i + 0];
|
||||
zz[i + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_1 + zz[i + 1];
|
||||
zz[i + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_2 + zz[i + 2];
|
||||
zz[i + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_3 + zz[i + 3];
|
||||
zz[i + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
zz[i + 4] = (uint)c;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Mul(uint[] x, int xOff, uint[] y, int yOff, uint[] zz, int zzOff)
|
||||
{
|
||||
ulong y_0 = y[yOff + 0];
|
||||
ulong y_1 = y[yOff + 1];
|
||||
ulong y_2 = y[yOff + 2];
|
||||
ulong y_3 = y[yOff + 3];
|
||||
|
||||
{
|
||||
ulong c = 0, x_0 = x[xOff + 0];
|
||||
c += x_0 * y_0;
|
||||
zz[zzOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_1;
|
||||
zz[zzOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_2;
|
||||
zz[zzOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_3;
|
||||
zz[zzOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
zz[zzOff + 4] = (uint)c;
|
||||
}
|
||||
|
||||
for (int i = 1; i < 4; ++i)
|
||||
{
|
||||
++zzOff;
|
||||
ulong c = 0, x_i = x[xOff + i];
|
||||
c += x_i * y_0 + zz[zzOff + 0];
|
||||
zz[zzOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_1 + zz[zzOff + 1];
|
||||
zz[zzOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_2 + zz[zzOff + 2];
|
||||
zz[zzOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_3 + zz[zzOff + 3];
|
||||
zz[zzOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
zz[zzOff + 4] = (uint)c;
|
||||
}
|
||||
}
|
||||
|
||||
public static uint MulAddTo(uint[] x, uint[] y, uint[] zz)
|
||||
{
|
||||
ulong y_0 = y[0];
|
||||
ulong y_1 = y[1];
|
||||
ulong y_2 = y[2];
|
||||
ulong y_3 = y[3];
|
||||
|
||||
ulong zc = 0;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
ulong c = 0, x_i = x[i];
|
||||
c += x_i * y_0 + zz[i + 0];
|
||||
zz[i + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_1 + zz[i + 1];
|
||||
zz[i + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_2 + zz[i + 2];
|
||||
zz[i + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_3 + zz[i + 3];
|
||||
zz[i + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
|
||||
zc += c + zz[i + 4];
|
||||
zz[i + 4] = (uint)zc;
|
||||
zc >>= 32;
|
||||
}
|
||||
return (uint)zc;
|
||||
}
|
||||
|
||||
public static uint MulAddTo(uint[] x, int xOff, uint[] y, int yOff, uint[] zz, int zzOff)
|
||||
{
|
||||
ulong y_0 = y[yOff + 0];
|
||||
ulong y_1 = y[yOff + 1];
|
||||
ulong y_2 = y[yOff + 2];
|
||||
ulong y_3 = y[yOff + 3];
|
||||
|
||||
ulong zc = 0;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
ulong c = 0, x_i = x[xOff + i];
|
||||
c += x_i * y_0 + zz[zzOff + 0];
|
||||
zz[zzOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_1 + zz[zzOff + 1];
|
||||
zz[zzOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_2 + zz[zzOff + 2];
|
||||
zz[zzOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_3 + zz[zzOff + 3];
|
||||
zz[zzOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
|
||||
zc += c + zz[zzOff + 4];
|
||||
zz[zzOff + 4] = (uint)zc;
|
||||
zc >>= 32;
|
||||
++zzOff;
|
||||
}
|
||||
return (uint)zc;
|
||||
}
|
||||
|
||||
public static ulong Mul33Add(uint w, uint[] x, int xOff, uint[] y, int yOff, uint[] z, int zOff)
|
||||
{
|
||||
Debug.Assert(w >> 31 == 0);
|
||||
|
||||
ulong c = 0, wVal = w;
|
||||
ulong x0 = x[xOff + 0];
|
||||
c += wVal * x0 + y[yOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
ulong x1 = x[xOff + 1];
|
||||
c += wVal * x1 + x0 + y[yOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
ulong x2 = x[xOff + 2];
|
||||
c += wVal * x2 + x1 + y[yOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
ulong x3 = x[xOff + 3];
|
||||
c += wVal * x3 + x2 + y[yOff + 3];
|
||||
z[zOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x3;
|
||||
return c;
|
||||
}
|
||||
|
||||
public static uint MulWordAddExt(uint x, uint[] yy, int yyOff, uint[] zz, int zzOff)
|
||||
{
|
||||
Debug.Assert(yyOff <= 4);
|
||||
Debug.Assert(zzOff <= 4);
|
||||
|
||||
ulong c = 0, xVal = x;
|
||||
c += xVal * yy[yyOff + 0] + zz[zzOff + 0];
|
||||
zz[zzOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += xVal * yy[yyOff + 1] + zz[zzOff + 1];
|
||||
zz[zzOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += xVal * yy[yyOff + 2] + zz[zzOff + 2];
|
||||
zz[zzOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += xVal * yy[yyOff + 3] + zz[zzOff + 3];
|
||||
zz[zzOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static uint Mul33DWordAdd(uint x, ulong y, uint[] z, int zOff)
|
||||
{
|
||||
Debug.Assert(x >> 31 == 0);
|
||||
Debug.Assert(zOff <= 0);
|
||||
ulong c = 0, xVal = x;
|
||||
ulong y00 = y & M;
|
||||
c += xVal * y00 + z[zOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
ulong y01 = y >> 32;
|
||||
c += xVal * y01 + y00 + z[zOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += y01 + z[zOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += z[zOff + 3];
|
||||
z[zOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static uint Mul33WordAdd(uint x, uint y, uint[] z, int zOff)
|
||||
{
|
||||
Debug.Assert(x >> 31 == 0);
|
||||
Debug.Assert(zOff <= 1);
|
||||
ulong c = 0, yVal = y;
|
||||
c += yVal * x + z[zOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += yVal + z[zOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += z[zOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
return c == 0 ? 0 : Nat.IncAt(4, z, zOff, 3);
|
||||
}
|
||||
|
||||
public static uint MulWordDwordAdd(uint x, ulong y, uint[] z, int zOff)
|
||||
{
|
||||
Debug.Assert(zOff <= 1);
|
||||
ulong c = 0, xVal = x;
|
||||
c += xVal * y + z[zOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += xVal * (y >> 32) + z[zOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += z[zOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
return c == 0 ? 0 : Nat.IncAt(4, z, zOff, 3);
|
||||
}
|
||||
|
||||
public static uint MulWordsAdd(uint x, uint y, uint[] z, int zOff)
|
||||
{
|
||||
Debug.Assert(zOff <= 2);
|
||||
|
||||
ulong c = 0, xVal = x, yVal = y;
|
||||
c += yVal * xVal + z[zOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += z[zOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
return c == 0 ? 0 : Nat.IncAt(4, z, zOff, 2);
|
||||
}
|
||||
|
||||
public static uint MulWord(uint x, uint[] y, uint[] z, int zOff)
|
||||
{
|
||||
ulong c = 0, xVal = x;
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
c += xVal * y[i];
|
||||
z[zOff + i] = (uint)c;
|
||||
c >>= 32;
|
||||
}
|
||||
while (++i < 4);
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static void Square(uint[] x, uint[] zz)
|
||||
{
|
||||
ulong x_0 = x[0];
|
||||
ulong zz_1;
|
||||
|
||||
uint c = 0, w;
|
||||
{
|
||||
int i = 3, j = 8;
|
||||
do
|
||||
{
|
||||
ulong xVal = x[i--];
|
||||
ulong p = xVal * xVal;
|
||||
zz[--j] = (c << 31) | (uint)(p >> 33);
|
||||
zz[--j] = (uint)(p >> 1);
|
||||
c = (uint)p;
|
||||
}
|
||||
while (i > 0);
|
||||
|
||||
{
|
||||
ulong p = x_0 * x_0;
|
||||
zz_1 = (ulong)(c << 31) | (p >> 33);
|
||||
zz[0] = (uint)p;
|
||||
c = (uint)(p >> 32) & 1;
|
||||
}
|
||||
}
|
||||
|
||||
ulong x_1 = x[1];
|
||||
ulong zz_2 = zz[2];
|
||||
|
||||
{
|
||||
zz_1 += x_1 * x_0;
|
||||
w = (uint)zz_1;
|
||||
zz[1] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_2 += zz_1 >> 32;
|
||||
}
|
||||
|
||||
ulong x_2 = x[2];
|
||||
ulong zz_3 = zz[3];
|
||||
ulong zz_4 = zz[4];
|
||||
{
|
||||
zz_2 += x_2 * x_0;
|
||||
w = (uint)zz_2;
|
||||
zz[2] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_3 += (zz_2 >> 32) + x_2 * x_1;
|
||||
zz_4 += zz_3 >> 32;
|
||||
zz_3 &= M;
|
||||
}
|
||||
|
||||
ulong x_3 = x[3];
|
||||
ulong zz_5 = zz[5] + (zz_4 >> 32); zz_4 &= M;
|
||||
ulong zz_6 = zz[6] + (zz_5 >> 32); zz_5 &= M;
|
||||
{
|
||||
zz_3 += x_3 * x_0;
|
||||
w = (uint)zz_3;
|
||||
zz[3] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_4 += (zz_3 >> 32) + x_3 * x_1;
|
||||
zz_5 += (zz_4 >> 32) + x_3 * x_2;
|
||||
zz_6 += zz_5 >> 32;
|
||||
}
|
||||
|
||||
w = (uint)zz_4;
|
||||
zz[4] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = (uint)zz_5;
|
||||
zz[5] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = (uint)zz_6;
|
||||
zz[6] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = zz[7] + (uint)(zz_6 >> 32);
|
||||
zz[7] = (w << 1) | c;
|
||||
}
|
||||
|
||||
public static void Square(uint[] x, int xOff, uint[] zz, int zzOff)
|
||||
{
|
||||
ulong x_0 = x[xOff + 0];
|
||||
ulong zz_1;
|
||||
|
||||
uint c = 0, w;
|
||||
{
|
||||
int i = 3, j = 8;
|
||||
do
|
||||
{
|
||||
ulong xVal = x[xOff + i--];
|
||||
ulong p = xVal * xVal;
|
||||
zz[zzOff + --j] = (c << 31) | (uint)(p >> 33);
|
||||
zz[zzOff + --j] = (uint)(p >> 1);
|
||||
c = (uint)p;
|
||||
}
|
||||
while (i > 0);
|
||||
|
||||
{
|
||||
ulong p = x_0 * x_0;
|
||||
zz_1 = (ulong)(c << 31) | (p >> 33);
|
||||
zz[zzOff + 0] = (uint)p;
|
||||
c = (uint)(p >> 32) & 1;
|
||||
}
|
||||
}
|
||||
|
||||
ulong x_1 = x[xOff + 1];
|
||||
ulong zz_2 = zz[zzOff + 2];
|
||||
|
||||
{
|
||||
zz_1 += x_1 * x_0;
|
||||
w = (uint)zz_1;
|
||||
zz[zzOff + 1] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_2 += zz_1 >> 32;
|
||||
}
|
||||
|
||||
ulong x_2 = x[xOff + 2];
|
||||
ulong zz_3 = zz[zzOff + 3];
|
||||
ulong zz_4 = zz[zzOff + 4];
|
||||
{
|
||||
zz_2 += x_2 * x_0;
|
||||
w = (uint)zz_2;
|
||||
zz[zzOff + 2] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_3 += (zz_2 >> 32) + x_2 * x_1;
|
||||
zz_4 += zz_3 >> 32;
|
||||
zz_3 &= M;
|
||||
}
|
||||
|
||||
ulong x_3 = x[xOff + 3];
|
||||
ulong zz_5 = zz[zzOff + 5] + (zz_4 >> 32); zz_4 &= M;
|
||||
ulong zz_6 = zz[zzOff + 6] + (zz_5 >> 32); zz_5 &= M;
|
||||
{
|
||||
zz_3 += x_3 * x_0;
|
||||
w = (uint)zz_3;
|
||||
zz[zzOff + 3] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_4 += (zz_3 >> 32) + x_3 * x_1;
|
||||
zz_5 += (zz_4 >> 32) + x_3 * x_2;
|
||||
zz_6 += zz_5 >> 32;
|
||||
}
|
||||
|
||||
w = (uint)zz_4;
|
||||
zz[zzOff + 4] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = (uint)zz_5;
|
||||
zz[zzOff + 5] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = (uint)zz_6;
|
||||
zz[zzOff + 6] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = zz[zzOff + 7] + (uint)(zz_6 >> 32);
|
||||
zz[zzOff + 7] = (w << 1) | c;
|
||||
}
|
||||
|
||||
public static int Sub(uint[] x, uint[] y, uint[] z)
|
||||
{
|
||||
long c = 0;
|
||||
c += (long)x[0] - y[0];
|
||||
z[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[1] - y[1];
|
||||
z[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[2] - y[2];
|
||||
z[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[3] - y[3];
|
||||
z[3] = (uint)c;
|
||||
c >>= 32;
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
public static int Sub(uint[] x, int xOff, uint[] y, int yOff, uint[] z, int zOff)
|
||||
{
|
||||
long c = 0;
|
||||
c += (long)x[xOff + 0] - y[yOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[xOff + 1] - y[yOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[xOff + 2] - y[yOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[xOff + 3] - y[yOff + 3];
|
||||
z[zOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
public static int SubBothFrom(uint[] x, uint[] y, uint[] z)
|
||||
{
|
||||
long c = 0;
|
||||
c += (long)z[0] - x[0] - y[0];
|
||||
z[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[1] - x[1] - y[1];
|
||||
z[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[2] - x[2] - y[2];
|
||||
z[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[3] - x[3] - y[3];
|
||||
z[3] = (uint)c;
|
||||
c >>= 32;
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
public static int SubFrom(uint[] x, uint[] z)
|
||||
{
|
||||
long c = 0;
|
||||
c += (long)z[0] - x[0];
|
||||
z[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[1] - x[1];
|
||||
z[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[2] - x[2];
|
||||
z[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[3] - x[3];
|
||||
z[3] = (uint)c;
|
||||
c >>= 32;
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
public static int SubFrom(uint[] x, int xOff, uint[] z, int zOff)
|
||||
{
|
||||
long c = 0;
|
||||
c += (long)z[zOff + 0] - x[xOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[zOff + 1] - x[xOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[zOff + 2] - x[xOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[zOff + 3] - x[xOff + 3];
|
||||
z[zOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
public static BigInteger ToBigInteger(uint[] x)
|
||||
{
|
||||
byte[] bs = new byte[16];
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
uint x_i = x[i];
|
||||
if (x_i != 0)
|
||||
{
|
||||
Pack.UInt32_To_BE(x_i, bs, (3 - i) << 2);
|
||||
}
|
||||
}
|
||||
return new BigInteger(1, bs);
|
||||
}
|
||||
|
||||
public static BigInteger ToBigInteger64(ulong[] x)
|
||||
{
|
||||
byte[] bs = new byte[16];
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
ulong x_i = x[i];
|
||||
if (x_i != 0UL)
|
||||
{
|
||||
Pack.UInt64_To_BE(x_i, bs, (1 - i) << 3);
|
||||
}
|
||||
}
|
||||
return new BigInteger(1, bs);
|
||||
}
|
||||
|
||||
public static void Zero(uint[] z)
|
||||
{
|
||||
z[0] = 0;
|
||||
z[1] = 0;
|
||||
z[2] = 0;
|
||||
z[3] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat128.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat128.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e573d70894015449a2e9b05c1b85cdc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
874
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat160.cs
vendored
Normal file
874
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat160.cs
vendored
Normal file
@@ -0,0 +1,874 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Raw
|
||||
{
|
||||
internal abstract class Nat160
|
||||
{
|
||||
private const ulong M = 0xFFFFFFFFUL;
|
||||
|
||||
public static uint Add(uint[] x, uint[] y, uint[] z)
|
||||
{
|
||||
ulong c = 0;
|
||||
c += (ulong)x[0] + y[0];
|
||||
z[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[1] + y[1];
|
||||
z[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[2] + y[2];
|
||||
z[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[3] + y[3];
|
||||
z[3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[4] + y[4];
|
||||
z[4] = (uint)c;
|
||||
c >>= 32;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static uint AddBothTo(uint[] x, uint[] y, uint[] z)
|
||||
{
|
||||
ulong c = 0;
|
||||
c += (ulong)x[0] + y[0] + z[0];
|
||||
z[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[1] + y[1] + z[1];
|
||||
z[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[2] + y[2] + z[2];
|
||||
z[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[3] + y[3] + z[3];
|
||||
z[3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[4] + y[4] + z[4];
|
||||
z[4] = (uint)c;
|
||||
c >>= 32;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static uint AddTo(uint[] x, uint[] z)
|
||||
{
|
||||
ulong c = 0;
|
||||
c += (ulong)x[0] + z[0];
|
||||
z[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[1] + z[1];
|
||||
z[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[2] + z[2];
|
||||
z[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[3] + z[3];
|
||||
z[3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[4] + z[4];
|
||||
z[4] = (uint)c;
|
||||
c >>= 32;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static uint AddTo(uint[] x, int xOff, uint[] z, int zOff, uint cIn)
|
||||
{
|
||||
ulong c = cIn;
|
||||
c += (ulong)x[xOff + 0] + z[zOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[xOff + 1] + z[zOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[xOff + 2] + z[zOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[xOff + 3] + z[zOff + 3];
|
||||
z[zOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[xOff + 4] + z[zOff + 4];
|
||||
z[zOff + 4] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)x[xOff + 5] + z[zOff + 5];
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static uint AddToEachOther(uint[] u, int uOff, uint[] v, int vOff)
|
||||
{
|
||||
ulong c = 0;
|
||||
c += (ulong)u[uOff + 0] + v[vOff + 0];
|
||||
u[uOff + 0] = (uint)c;
|
||||
v[vOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)u[uOff + 1] + v[vOff + 1];
|
||||
u[uOff + 1] = (uint)c;
|
||||
v[vOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)u[uOff + 2] + v[vOff + 2];
|
||||
u[uOff + 2] = (uint)c;
|
||||
v[vOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)u[uOff + 3] + v[vOff + 3];
|
||||
u[uOff + 3] = (uint)c;
|
||||
v[vOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (ulong)u[uOff + 4] + v[vOff + 4];
|
||||
u[uOff + 4] = (uint)c;
|
||||
v[vOff + 4] = (uint)c;
|
||||
c >>= 32;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static void Copy(uint[] x, uint[] z)
|
||||
{
|
||||
z[0] = x[0];
|
||||
z[1] = x[1];
|
||||
z[2] = x[2];
|
||||
z[3] = x[3];
|
||||
z[4] = x[4];
|
||||
}
|
||||
|
||||
public static void Copy(uint[] x, int xOff, uint[] z, int zOff)
|
||||
{
|
||||
z[zOff + 0] = x[xOff + 0];
|
||||
z[zOff + 1] = x[xOff + 1];
|
||||
z[zOff + 2] = x[xOff + 2];
|
||||
z[zOff + 3] = x[xOff + 3];
|
||||
z[zOff + 4] = x[xOff + 4];
|
||||
}
|
||||
|
||||
public static uint[] Create()
|
||||
{
|
||||
return new uint[5];
|
||||
}
|
||||
|
||||
public static uint[] CreateExt()
|
||||
{
|
||||
return new uint[10];
|
||||
}
|
||||
|
||||
public static bool Diff(uint[] x, int xOff, uint[] y, int yOff, uint[] z, int zOff)
|
||||
{
|
||||
bool pos = Gte(x, xOff, y, yOff);
|
||||
if (pos)
|
||||
{
|
||||
Sub(x, xOff, y, yOff, z, zOff);
|
||||
}
|
||||
else
|
||||
{
|
||||
Sub(y, yOff, x, xOff, z, zOff);
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
public static bool Eq(uint[] x, uint[] y)
|
||||
{
|
||||
for (int i = 4; i >= 0; --i)
|
||||
{
|
||||
if (x[i] != y[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static uint GetBit(uint[] x, int bit)
|
||||
{
|
||||
if (bit == 0)
|
||||
{
|
||||
return x[0] & 1;
|
||||
}
|
||||
int w = bit >> 5;
|
||||
if (w < 0 || w >= 5)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int b = bit & 31;
|
||||
return (x[w] >> b) & 1;
|
||||
}
|
||||
|
||||
public static bool Gte(uint[] x, uint[] y)
|
||||
{
|
||||
for (int i = 4; i >= 0; --i)
|
||||
{
|
||||
uint x_i = x[i], y_i = y[i];
|
||||
if (x_i < y_i)
|
||||
return false;
|
||||
if (x_i > y_i)
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Gte(uint[] x, int xOff, uint[] y, int yOff)
|
||||
{
|
||||
for (int i = 4; i >= 0; --i)
|
||||
{
|
||||
uint x_i = x[xOff + i], y_i = y[yOff + i];
|
||||
if (x_i < y_i)
|
||||
return false;
|
||||
if (x_i > y_i)
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsOne(uint[] x)
|
||||
{
|
||||
if (x[0] != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 1; i < 5; ++i)
|
||||
{
|
||||
if (x[i] != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsZero(uint[] x)
|
||||
{
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
if (x[i] != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void Mul(uint[] x, uint[] y, uint[] zz)
|
||||
{
|
||||
ulong y_0 = y[0];
|
||||
ulong y_1 = y[1];
|
||||
ulong y_2 = y[2];
|
||||
ulong y_3 = y[3];
|
||||
ulong y_4 = y[4];
|
||||
|
||||
{
|
||||
ulong c = 0, x_0 = x[0];
|
||||
c += x_0 * y_0;
|
||||
zz[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_1;
|
||||
zz[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_2;
|
||||
zz[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_3;
|
||||
zz[3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_4;
|
||||
zz[4] = (uint)c;
|
||||
c >>= 32;
|
||||
zz[5] = (uint)c;
|
||||
}
|
||||
|
||||
for (int i = 1; i < 5; ++i)
|
||||
{
|
||||
ulong c = 0, x_i = x[i];
|
||||
c += x_i * y_0 + zz[i + 0];
|
||||
zz[i + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_1 + zz[i + 1];
|
||||
zz[i + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_2 + zz[i + 2];
|
||||
zz[i + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_3 + zz[i + 3];
|
||||
zz[i + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_4 + zz[i + 4];
|
||||
zz[i + 4] = (uint)c;
|
||||
c >>= 32;
|
||||
zz[i + 5] = (uint)c;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Mul(uint[] x, int xOff, uint[] y, int yOff, uint[] zz, int zzOff)
|
||||
{
|
||||
ulong y_0 = y[yOff + 0];
|
||||
ulong y_1 = y[yOff + 1];
|
||||
ulong y_2 = y[yOff + 2];
|
||||
ulong y_3 = y[yOff + 3];
|
||||
ulong y_4 = y[yOff + 4];
|
||||
|
||||
{
|
||||
ulong c = 0, x_0 = x[xOff + 0];
|
||||
c += x_0 * y_0;
|
||||
zz[zzOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_1;
|
||||
zz[zzOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_2;
|
||||
zz[zzOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_3;
|
||||
zz[zzOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_0 * y_4;
|
||||
zz[zzOff + 4] = (uint)c;
|
||||
c >>= 32;
|
||||
zz[zzOff + 5] = (uint)c;
|
||||
}
|
||||
|
||||
for (int i = 1; i < 5; ++i)
|
||||
{
|
||||
++zzOff;
|
||||
ulong c = 0, x_i = x[xOff + i];
|
||||
c += x_i * y_0 + zz[zzOff + 0];
|
||||
zz[zzOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_1 + zz[zzOff + 1];
|
||||
zz[zzOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_2 + zz[zzOff + 2];
|
||||
zz[zzOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_3 + zz[zzOff + 3];
|
||||
zz[zzOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_4 + zz[zzOff + 4];
|
||||
zz[zzOff + 4] = (uint)c;
|
||||
c >>= 32;
|
||||
zz[zzOff + 5] = (uint)c;
|
||||
}
|
||||
}
|
||||
|
||||
public static uint MulAddTo(uint[] x, uint[] y, uint[] zz)
|
||||
{
|
||||
ulong y_0 = y[0];
|
||||
ulong y_1 = y[1];
|
||||
ulong y_2 = y[2];
|
||||
ulong y_3 = y[3];
|
||||
ulong y_4 = y[4];
|
||||
|
||||
ulong zc = 0;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
ulong c = 0, x_i = x[i];
|
||||
c += x_i * y_0 + zz[i + 0];
|
||||
zz[i + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_1 + zz[i + 1];
|
||||
zz[i + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_2 + zz[i + 2];
|
||||
zz[i + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_3 + zz[i + 3];
|
||||
zz[i + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_4 + zz[i + 4];
|
||||
zz[i + 4] = (uint)c;
|
||||
c >>= 32;
|
||||
|
||||
zc += c + zz[i + 5];
|
||||
zz[i + 5] = (uint)zc;
|
||||
zc >>= 32;
|
||||
}
|
||||
return (uint)zc;
|
||||
}
|
||||
|
||||
public static uint MulAddTo(uint[] x, int xOff, uint[] y, int yOff, uint[] zz, int zzOff)
|
||||
{
|
||||
ulong y_0 = y[yOff + 0];
|
||||
ulong y_1 = y[yOff + 1];
|
||||
ulong y_2 = y[yOff + 2];
|
||||
ulong y_3 = y[yOff + 3];
|
||||
ulong y_4 = y[yOff + 4];
|
||||
|
||||
ulong zc = 0;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
ulong c = 0, x_i = x[xOff + i];
|
||||
c += x_i * y_0 + zz[zzOff + 0];
|
||||
zz[zzOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_1 + zz[zzOff + 1];
|
||||
zz[zzOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_2 + zz[zzOff + 2];
|
||||
zz[zzOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_3 + zz[zzOff + 3];
|
||||
zz[zzOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x_i * y_4 + zz[zzOff + 4];
|
||||
zz[zzOff + 4] = (uint)c;
|
||||
c >>= 32;
|
||||
|
||||
zc += c + zz[zzOff + 5];
|
||||
zz[zzOff + 5] = (uint)zc;
|
||||
zc >>= 32;
|
||||
++zzOff;
|
||||
}
|
||||
return (uint)zc;
|
||||
}
|
||||
|
||||
public static ulong Mul33Add(uint w, uint[] x, int xOff, uint[] y, int yOff, uint[] z, int zOff)
|
||||
{
|
||||
Debug.Assert(w >> 31 == 0);
|
||||
|
||||
ulong c = 0, wVal = w;
|
||||
ulong x0 = x[xOff + 0];
|
||||
c += wVal * x0 + y[yOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
ulong x1 = x[xOff + 1];
|
||||
c += wVal * x1 + x0 + y[yOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
ulong x2 = x[xOff + 2];
|
||||
c += wVal * x2 + x1 + y[yOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
ulong x3 = x[xOff + 3];
|
||||
c += wVal * x3 + x2 + y[yOff + 3];
|
||||
z[zOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
ulong x4 = x[xOff + 4];
|
||||
c += wVal * x4 + x3 + y[yOff + 4];
|
||||
z[zOff + 4] = (uint)c;
|
||||
c >>= 32;
|
||||
c += x4;
|
||||
return c;
|
||||
}
|
||||
|
||||
public static uint MulWordAddExt(uint x, uint[] yy, int yyOff, uint[] zz, int zzOff)
|
||||
{
|
||||
Debug.Assert(yyOff <= 5);
|
||||
Debug.Assert(zzOff <= 5);
|
||||
|
||||
ulong c = 0, xVal = x;
|
||||
c += xVal * yy[yyOff + 0] + zz[zzOff + 0];
|
||||
zz[zzOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += xVal * yy[yyOff + 1] + zz[zzOff + 1];
|
||||
zz[zzOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += xVal * yy[yyOff + 2] + zz[zzOff + 2];
|
||||
zz[zzOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += xVal * yy[yyOff + 3] + zz[zzOff + 3];
|
||||
zz[zzOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += xVal * yy[yyOff + 4] + zz[zzOff + 4];
|
||||
zz[zzOff + 4] = (uint)c;
|
||||
c >>= 32;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static uint Mul33DWordAdd(uint x, ulong y, uint[] z, int zOff)
|
||||
{
|
||||
Debug.Assert(x >> 31 == 0);
|
||||
Debug.Assert(zOff <= 1);
|
||||
ulong c = 0, xVal = x;
|
||||
ulong y00 = y & M;
|
||||
c += xVal * y00 + z[zOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
ulong y01 = y >> 32;
|
||||
c += xVal * y01 + y00 + z[zOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += y01 + z[zOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += z[zOff + 3];
|
||||
z[zOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
return c == 0 ? 0 : Nat.IncAt(5, z, zOff, 4);
|
||||
}
|
||||
|
||||
public static uint Mul33WordAdd(uint x, uint y, uint[] z, int zOff)
|
||||
{
|
||||
Debug.Assert(x >> 31 == 0);
|
||||
Debug.Assert(zOff <= 2);
|
||||
ulong c = 0, yVal = y;
|
||||
c += yVal * x + z[zOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += yVal + z[zOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += z[zOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
return c == 0 ? 0 : Nat.IncAt(5, z, zOff, 3);
|
||||
}
|
||||
|
||||
public static uint MulWordDwordAdd(uint x, ulong y, uint[] z, int zOff)
|
||||
{
|
||||
Debug.Assert(zOff <= 2);
|
||||
ulong c = 0, xVal = x;
|
||||
c += xVal * y + z[zOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += xVal * (y >> 32) + z[zOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += z[zOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
return c == 0 ? 0 : Nat.IncAt(5, z, zOff, 3);
|
||||
}
|
||||
|
||||
public static uint MulWordsAdd(uint x, uint y, uint[] z, int zOff)
|
||||
{
|
||||
Debug.Assert(zOff <= 3);
|
||||
|
||||
ulong c = 0, xVal = x, yVal = y;
|
||||
c += yVal * xVal + z[zOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += z[zOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
return c == 0 ? 0 : Nat.IncAt(5, z, zOff, 2);
|
||||
}
|
||||
|
||||
public static uint MulWord(uint x, uint[] y, uint[] z, int zOff)
|
||||
{
|
||||
ulong c = 0, xVal = x;
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
c += xVal * y[i];
|
||||
z[zOff + i] = (uint)c;
|
||||
c >>= 32;
|
||||
}
|
||||
while (++i < 5);
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static void Square(uint[] x, uint[] zz)
|
||||
{
|
||||
ulong x_0 = x[0];
|
||||
ulong zz_1;
|
||||
|
||||
uint c = 0, w;
|
||||
{
|
||||
int i = 4, j = 10;
|
||||
do
|
||||
{
|
||||
ulong xVal = x[i--];
|
||||
ulong p = xVal * xVal;
|
||||
zz[--j] = (c << 31) | (uint)(p >> 33);
|
||||
zz[--j] = (uint)(p >> 1);
|
||||
c = (uint)p;
|
||||
}
|
||||
while (i > 0);
|
||||
|
||||
{
|
||||
ulong p = x_0 * x_0;
|
||||
zz_1 = (ulong)(c << 31) | (p >> 33);
|
||||
zz[0] = (uint)p;
|
||||
c = (uint)(p >> 32) & 1;
|
||||
}
|
||||
}
|
||||
|
||||
ulong x_1 = x[1];
|
||||
ulong zz_2 = zz[2];
|
||||
|
||||
{
|
||||
zz_1 += x_1 * x_0;
|
||||
w = (uint)zz_1;
|
||||
zz[1] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_2 += zz_1 >> 32;
|
||||
}
|
||||
|
||||
ulong x_2 = x[2];
|
||||
ulong zz_3 = zz[3];
|
||||
ulong zz_4 = zz[4];
|
||||
{
|
||||
zz_2 += x_2 * x_0;
|
||||
w = (uint)zz_2;
|
||||
zz[2] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_3 += (zz_2 >> 32) + x_2 * x_1;
|
||||
zz_4 += zz_3 >> 32;
|
||||
zz_3 &= M;
|
||||
}
|
||||
|
||||
ulong x_3 = x[3];
|
||||
ulong zz_5 = zz[5] + (zz_4 >> 32); zz_4 &= M;
|
||||
ulong zz_6 = zz[6] + (zz_5 >> 32); zz_5 &= M;
|
||||
{
|
||||
zz_3 += x_3 * x_0;
|
||||
w = (uint)zz_3;
|
||||
zz[3] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_4 += (zz_3 >> 32) + x_3 * x_1;
|
||||
zz_5 += (zz_4 >> 32) + x_3 * x_2;
|
||||
zz_4 &= M;
|
||||
zz_6 += zz_5 >> 32;
|
||||
zz_5 &= M;
|
||||
}
|
||||
|
||||
ulong x_4 = x[4];
|
||||
ulong zz_7 = zz[7] + (zz_6 >> 32); zz_6 &= M;
|
||||
ulong zz_8 = zz[8] + (zz_7 >> 32); zz_7 &= M;
|
||||
{
|
||||
zz_4 += x_4 * x_0;
|
||||
w = (uint)zz_4;
|
||||
zz[4] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_5 += (zz_4 >> 32) + x_4 * x_1;
|
||||
zz_6 += (zz_5 >> 32) + x_4 * x_2;
|
||||
zz_7 += (zz_6 >> 32) + x_4 * x_3;
|
||||
zz_8 += zz_7 >> 32;
|
||||
}
|
||||
|
||||
w = (uint)zz_5;
|
||||
zz[5] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = (uint)zz_6;
|
||||
zz[6] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = (uint)zz_7;
|
||||
zz[7] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = (uint)zz_8;
|
||||
zz[8] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = zz[9] + (uint)(zz_8 >> 32);
|
||||
zz[9] = (w << 1) | c;
|
||||
}
|
||||
|
||||
public static void Square(uint[] x, int xOff, uint[] zz, int zzOff)
|
||||
{
|
||||
ulong x_0 = x[xOff + 0];
|
||||
ulong zz_1;
|
||||
|
||||
uint c = 0, w;
|
||||
{
|
||||
int i = 4, j = 10;
|
||||
do
|
||||
{
|
||||
ulong xVal = x[xOff + i--];
|
||||
ulong p = xVal * xVal;
|
||||
zz[zzOff + --j] = (c << 31) | (uint)(p >> 33);
|
||||
zz[zzOff + --j] = (uint)(p >> 1);
|
||||
c = (uint)p;
|
||||
}
|
||||
while (i > 0);
|
||||
|
||||
{
|
||||
ulong p = x_0 * x_0;
|
||||
zz_1 = (ulong)(c << 31) | (p >> 33);
|
||||
zz[zzOff + 0] = (uint)p;
|
||||
c = (uint)(p >> 32) & 1;
|
||||
}
|
||||
}
|
||||
|
||||
ulong x_1 = x[xOff + 1];
|
||||
ulong zz_2 = zz[zzOff + 2];
|
||||
|
||||
{
|
||||
zz_1 += x_1 * x_0;
|
||||
w = (uint)zz_1;
|
||||
zz[zzOff + 1] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_2 += zz_1 >> 32;
|
||||
}
|
||||
|
||||
ulong x_2 = x[xOff + 2];
|
||||
ulong zz_3 = zz[zzOff + 3];
|
||||
ulong zz_4 = zz[zzOff + 4];
|
||||
{
|
||||
zz_2 += x_2 * x_0;
|
||||
w = (uint)zz_2;
|
||||
zz[zzOff + 2] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_3 += (zz_2 >> 32) + x_2 * x_1;
|
||||
zz_4 += zz_3 >> 32;
|
||||
zz_3 &= M;
|
||||
}
|
||||
|
||||
ulong x_3 = x[xOff + 3];
|
||||
ulong zz_5 = zz[zzOff + 5] + (zz_4 >> 32); zz_4 &= M;
|
||||
ulong zz_6 = zz[zzOff + 6] + (zz_5 >> 32); zz_5 &= M;
|
||||
{
|
||||
zz_3 += x_3 * x_0;
|
||||
w = (uint)zz_3;
|
||||
zz[zzOff + 3] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_4 += (zz_3 >> 32) + x_3 * x_1;
|
||||
zz_5 += (zz_4 >> 32) + x_3 * x_2;
|
||||
zz_4 &= M;
|
||||
zz_6 += zz_5 >> 32;
|
||||
zz_5 &= M;
|
||||
}
|
||||
|
||||
ulong x_4 = x[xOff + 4];
|
||||
ulong zz_7 = zz[zzOff + 7] + (zz_6 >> 32); zz_6 &= M;
|
||||
ulong zz_8 = zz[zzOff + 8] + (zz_7 >> 32); zz_7 &= M;
|
||||
{
|
||||
zz_4 += x_4 * x_0;
|
||||
w = (uint)zz_4;
|
||||
zz[zzOff + 4] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
zz_5 += (zz_4 >> 32) + x_4 * x_1;
|
||||
zz_6 += (zz_5 >> 32) + x_4 * x_2;
|
||||
zz_7 += (zz_6 >> 32) + x_4 * x_3;
|
||||
zz_8 += zz_7 >> 32;
|
||||
}
|
||||
|
||||
w = (uint)zz_5;
|
||||
zz[zzOff + 5] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = (uint)zz_6;
|
||||
zz[zzOff + 6] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = (uint)zz_7;
|
||||
zz[zzOff + 7] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = (uint)zz_8;
|
||||
zz[zzOff + 8] = (w << 1) | c;
|
||||
c = w >> 31;
|
||||
w = zz[zzOff + 9] + (uint)(zz_8 >> 32);
|
||||
zz[zzOff + 9] = (w << 1) | c;
|
||||
}
|
||||
|
||||
public static int Sub(uint[] x, uint[] y, uint[] z)
|
||||
{
|
||||
long c = 0;
|
||||
c += (long)x[0] - y[0];
|
||||
z[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[1] - y[1];
|
||||
z[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[2] - y[2];
|
||||
z[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[3] - y[3];
|
||||
z[3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[4] - y[4];
|
||||
z[4] = (uint)c;
|
||||
c >>= 32;
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
public static int Sub(uint[] x, int xOff, uint[] y, int yOff, uint[] z, int zOff)
|
||||
{
|
||||
long c = 0;
|
||||
c += (long)x[xOff + 0] - y[yOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[xOff + 1] - y[yOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[xOff + 2] - y[yOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[xOff + 3] - y[yOff + 3];
|
||||
z[zOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)x[xOff + 4] - y[yOff + 4];
|
||||
z[zOff + 4] = (uint)c;
|
||||
c >>= 32;
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
public static int SubBothFrom(uint[] x, uint[] y, uint[] z)
|
||||
{
|
||||
long c = 0;
|
||||
c += (long)z[0] - x[0] - y[0];
|
||||
z[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[1] - x[1] - y[1];
|
||||
z[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[2] - x[2] - y[2];
|
||||
z[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[3] - x[3] - y[3];
|
||||
z[3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[4] - x[4] - y[4];
|
||||
z[4] = (uint)c;
|
||||
c >>= 32;
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
public static int SubFrom(uint[] x, uint[] z)
|
||||
{
|
||||
long c = 0;
|
||||
c += (long)z[0] - x[0];
|
||||
z[0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[1] - x[1];
|
||||
z[1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[2] - x[2];
|
||||
z[2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[3] - x[3];
|
||||
z[3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[4] - x[4];
|
||||
z[4] = (uint)c;
|
||||
c >>= 32;
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
public static int SubFrom(uint[] x, int xOff, uint[] z, int zOff)
|
||||
{
|
||||
long c = 0;
|
||||
c += (long)z[zOff + 0] - x[xOff + 0];
|
||||
z[zOff + 0] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[zOff + 1] - x[xOff + 1];
|
||||
z[zOff + 1] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[zOff + 2] - x[xOff + 2];
|
||||
z[zOff + 2] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[zOff + 3] - x[xOff + 3];
|
||||
z[zOff + 3] = (uint)c;
|
||||
c >>= 32;
|
||||
c += (long)z[zOff + 4] - x[xOff + 4];
|
||||
z[zOff + 4] = (uint)c;
|
||||
c >>= 32;
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
public static BigInteger ToBigInteger(uint[] x)
|
||||
{
|
||||
byte[] bs = new byte[20];
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
uint x_i = x[i];
|
||||
if (x_i != 0)
|
||||
{
|
||||
Pack.UInt32_To_BE(x_i, bs, (4 - i) << 2);
|
||||
}
|
||||
}
|
||||
return new BigInteger(1, bs);
|
||||
}
|
||||
|
||||
public static void Zero(uint[] z)
|
||||
{
|
||||
z[0] = 0;
|
||||
z[1] = 0;
|
||||
z[2] = 0;
|
||||
z[3] = 0;
|
||||
z[4] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat160.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat160.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f023e8d4a45302842b1396603a0cb71f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1041
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat192.cs
vendored
Normal file
1041
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat192.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat192.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat192.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0df4eec1471914e4ab2cce37354523a0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1178
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat224.cs
vendored
Normal file
1178
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat224.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat224.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat224.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e307710879c3c9a419ca12b34097a671
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1454
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat256.cs
vendored
Normal file
1454
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat256.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat256.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat256.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c70eb2d09a9fe1439fc104e0fa629b3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
96
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat320.cs
vendored
Normal file
96
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat320.cs
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Raw
|
||||
{
|
||||
internal abstract class Nat320
|
||||
{
|
||||
public static void Copy64(ulong[] x, ulong[] z)
|
||||
{
|
||||
z[0] = x[0];
|
||||
z[1] = x[1];
|
||||
z[2] = x[2];
|
||||
z[3] = x[3];
|
||||
z[4] = x[4];
|
||||
}
|
||||
|
||||
public static void Copy64(ulong[] x, int xOff, ulong[] z, int zOff)
|
||||
{
|
||||
z[zOff + 0] = x[xOff + 0];
|
||||
z[zOff + 1] = x[xOff + 1];
|
||||
z[zOff + 2] = x[xOff + 2];
|
||||
z[zOff + 3] = x[xOff + 3];
|
||||
z[zOff + 4] = x[xOff + 4];
|
||||
}
|
||||
|
||||
public static ulong[] Create64()
|
||||
{
|
||||
return new ulong[5];
|
||||
}
|
||||
|
||||
public static ulong[] CreateExt64()
|
||||
{
|
||||
return new ulong[10];
|
||||
}
|
||||
|
||||
public static bool Eq64(ulong[] x, ulong[] y)
|
||||
{
|
||||
for (int i = 4; i >= 0; --i)
|
||||
{
|
||||
if (x[i] != y[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsOne64(ulong[] x)
|
||||
{
|
||||
if (x[0] != 1UL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 1; i < 5; ++i)
|
||||
{
|
||||
if (x[i] != 0UL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsZero64(ulong[] x)
|
||||
{
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
if (x[i] != 0UL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static BigInteger ToBigInteger64(ulong[] x)
|
||||
{
|
||||
byte[] bs = new byte[40];
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
ulong x_i = x[i];
|
||||
if (x_i != 0L)
|
||||
{
|
||||
Pack.UInt64_To_BE(x_i, bs, (4 - i) << 3);
|
||||
}
|
||||
}
|
||||
return new BigInteger(1, bs);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat320.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat320.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 309130aee4bc22543a4d95a42c092f6a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat384.cs
vendored
Normal file
50
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat384.cs
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Raw
|
||||
{
|
||||
internal abstract class Nat384
|
||||
{
|
||||
public static void Mul(uint[] x, uint[] y, uint[] zz)
|
||||
{
|
||||
Nat192.Mul(x, y, zz);
|
||||
Nat192.Mul(x, 6, y, 6, zz, 12);
|
||||
|
||||
uint c18 = Nat192.AddToEachOther(zz, 6, zz, 12);
|
||||
uint c12 = c18 + Nat192.AddTo(zz, 0, zz, 6, 0);
|
||||
c18 += Nat192.AddTo(zz, 18, zz, 12, c12);
|
||||
|
||||
uint[] dx = Nat192.Create(), dy = Nat192.Create();
|
||||
bool neg = Nat192.Diff(x, 6, x, 0, dx, 0) != Nat192.Diff(y, 6, y, 0, dy, 0);
|
||||
|
||||
uint[] tt = Nat192.CreateExt();
|
||||
Nat192.Mul(dx, dy, tt);
|
||||
|
||||
c18 += neg ? Nat.AddTo(12, tt, 0, zz, 6) : (uint)Nat.SubFrom(12, tt, 0, zz, 6);
|
||||
Nat.AddWordAt(24, c18, zz, 18);
|
||||
}
|
||||
|
||||
public static void Square(uint[] x, uint[] zz)
|
||||
{
|
||||
Nat192.Square(x, zz);
|
||||
Nat192.Square(x, 6, zz, 12);
|
||||
|
||||
uint c18 = Nat192.AddToEachOther(zz, 6, zz, 12);
|
||||
uint c12 = c18 + Nat192.AddTo(zz, 0, zz, 6, 0);
|
||||
c18 += Nat192.AddTo(zz, 18, zz, 12, c12);
|
||||
|
||||
uint[] dx = Nat192.Create();
|
||||
Nat192.Diff(x, 6, x, 0, dx, 0);
|
||||
|
||||
uint[] m = Nat192.CreateExt();
|
||||
Nat192.Square(dx, m);
|
||||
|
||||
c18 += (uint)Nat.SubFrom(12, m, 0, zz, 6);
|
||||
Nat.AddWordAt(24, c18, zz, 18);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat384.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat384.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: babe821f27a2e0a4abe69c2a8cc40d6b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
138
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat448.cs
vendored
Normal file
138
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat448.cs
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Raw
|
||||
{
|
||||
internal abstract class Nat448
|
||||
{
|
||||
public static void Copy64(ulong[] x, ulong[] z)
|
||||
{
|
||||
z[0] = x[0];
|
||||
z[1] = x[1];
|
||||
z[2] = x[2];
|
||||
z[3] = x[3];
|
||||
z[4] = x[4];
|
||||
z[5] = x[5];
|
||||
z[6] = x[6];
|
||||
}
|
||||
|
||||
public static void Copy64(ulong[] x, int xOff, ulong[] z, int zOff)
|
||||
{
|
||||
z[zOff + 0] = x[xOff + 0];
|
||||
z[zOff + 1] = x[xOff + 1];
|
||||
z[zOff + 2] = x[xOff + 2];
|
||||
z[zOff + 3] = x[xOff + 3];
|
||||
z[zOff + 4] = x[xOff + 4];
|
||||
z[zOff + 5] = x[xOff + 5];
|
||||
z[zOff + 6] = x[xOff + 6];
|
||||
}
|
||||
|
||||
public static ulong[] Create64()
|
||||
{
|
||||
return new ulong[7];
|
||||
}
|
||||
|
||||
public static ulong[] CreateExt64()
|
||||
{
|
||||
return new ulong[14];
|
||||
}
|
||||
|
||||
public static bool Eq64(ulong[] x, ulong[] y)
|
||||
{
|
||||
for (int i = 6; i >= 0; --i)
|
||||
{
|
||||
if (x[i] != y[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsOne64(ulong[] x)
|
||||
{
|
||||
if (x[0] != 1UL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 1; i < 7; ++i)
|
||||
{
|
||||
if (x[i] != 0UL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsZero64(ulong[] x)
|
||||
{
|
||||
for (int i = 0; i < 7; ++i)
|
||||
{
|
||||
if (x[i] != 0UL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void Mul(uint[] x, uint[] y, uint[] zz)
|
||||
{
|
||||
Nat224.Mul(x, y, zz);
|
||||
Nat224.Mul(x, 7, y, 7, zz, 14);
|
||||
|
||||
uint c21 = Nat224.AddToEachOther(zz, 7, zz, 14);
|
||||
uint c14 = c21 + Nat224.AddTo(zz, 0, zz, 7, 0);
|
||||
c21 += Nat224.AddTo(zz, 21, zz, 14, c14);
|
||||
|
||||
uint[] dx = Nat224.Create(), dy = Nat224.Create();
|
||||
bool neg = Nat224.Diff(x, 7, x, 0, dx, 0) != Nat224.Diff(y, 7, y, 0, dy, 0);
|
||||
|
||||
uint[] tt = Nat224.CreateExt();
|
||||
Nat224.Mul(dx, dy, tt);
|
||||
|
||||
c21 += neg ? Nat.AddTo(14, tt, 0, zz, 7) : (uint)Nat.SubFrom(14, tt, 0, zz, 7);
|
||||
Nat.AddWordAt(28, c21, zz, 21);
|
||||
}
|
||||
|
||||
public static void Square(uint[] x, uint[] zz)
|
||||
{
|
||||
Nat224.Square(x, zz);
|
||||
Nat224.Square(x, 7, zz, 14);
|
||||
|
||||
uint c21 = Nat224.AddToEachOther(zz, 7, zz, 14);
|
||||
uint c14 = c21 + Nat224.AddTo(zz, 0, zz, 7, 0);
|
||||
c21 += Nat224.AddTo(zz, 21, zz, 14, c14);
|
||||
|
||||
uint[] dx = Nat224.Create();
|
||||
Nat224.Diff(x, 7, x, 0, dx, 0);
|
||||
|
||||
uint[] tt = Nat224.CreateExt();
|
||||
Nat224.Square(dx, tt);
|
||||
|
||||
c21 += (uint)Nat.SubFrom(14, tt, 0, zz, 7);
|
||||
Nat.AddWordAt(28, c21, zz, 21);
|
||||
}
|
||||
|
||||
public static BigInteger ToBigInteger64(ulong[] x)
|
||||
{
|
||||
byte[] bs = new byte[56];
|
||||
for (int i = 0; i < 7; ++i)
|
||||
{
|
||||
ulong x_i = x[i];
|
||||
if (x_i != 0L)
|
||||
{
|
||||
Pack.UInt64_To_BE(x_i, bs, (6 - i) << 3);
|
||||
}
|
||||
}
|
||||
return new BigInteger(1, bs);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat448.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat448.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9377779e96ae29e40a19ab66c70992c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
363
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat512.cs
vendored
Normal file
363
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat512.cs
vendored
Normal file
@@ -0,0 +1,363 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
#endif
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Raw
|
||||
{
|
||||
internal abstract class Nat512
|
||||
{
|
||||
public static void Mul(uint[] x, uint[] y, uint[] zz)
|
||||
{
|
||||
Nat256.Mul(x, y, zz);
|
||||
Nat256.Mul(x, 8, y, 8, zz, 16);
|
||||
|
||||
uint c24 = Nat256.AddToEachOther(zz, 8, zz, 16);
|
||||
uint c16 = c24 + Nat256.AddTo(zz, 0, zz, 8, 0);
|
||||
c24 += Nat256.AddTo(zz, 24, zz, 16, c16);
|
||||
|
||||
uint[] dx = Nat256.Create(), dy = Nat256.Create();
|
||||
bool neg = Nat256.Diff(x, 8, x, 0, dx, 0) != Nat256.Diff(y, 8, y, 0, dy, 0);
|
||||
|
||||
uint[] tt = Nat256.CreateExt();
|
||||
Nat256.Mul(dx, dy, tt);
|
||||
|
||||
c24 += neg ? Nat.AddTo(16, tt, 0, zz, 8) : (uint)Nat.SubFrom(16, tt, 0, zz, 8);
|
||||
Nat.AddWordAt(32, c24, zz, 24);
|
||||
}
|
||||
|
||||
public static void Square(uint[] x, uint[] zz)
|
||||
{
|
||||
Nat256.Square(x, zz);
|
||||
Nat256.Square(x, 8, zz, 16);
|
||||
|
||||
uint c24 = Nat256.AddToEachOther(zz, 8, zz, 16);
|
||||
uint c16 = c24 + Nat256.AddTo(zz, 0, zz, 8, 0);
|
||||
c24 += Nat256.AddTo(zz, 24, zz, 16, c16);
|
||||
|
||||
uint[] dx = Nat256.Create();
|
||||
Nat256.Diff(x, 8, x, 0, dx, 0);
|
||||
|
||||
uint[] m = Nat256.CreateExt();
|
||||
Nat256.Square(dx, m);
|
||||
|
||||
c24 += (uint)Nat.SubFrom(16, m, 0, zz, 8);
|
||||
Nat.AddWordAt(32, c24, zz, 24);
|
||||
}
|
||||
|
||||
public static void Xor(uint[] x, int xOff, uint[] y, int yOff, uint[] z, int zOff)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
Xor(x.AsSpan(xOff), y.AsSpan(yOff), z.AsSpan(zOff));
|
||||
#else
|
||||
for (int i = 0; i < 16; i += 4)
|
||||
{
|
||||
z[zOff + i + 0] = x[xOff + i + 0] ^ y[yOff + i + 0];
|
||||
z[zOff + i + 1] = x[xOff + i + 1] ^ y[yOff + i + 1];
|
||||
z[zOff + i + 2] = x[xOff + i + 2] ^ y[yOff + i + 2];
|
||||
z[zOff + i + 3] = x[xOff + i + 3] ^ y[yOff + i + 3];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public static void Xor(ReadOnlySpan<uint> x, ReadOnlySpan<uint> y, Span<uint> z)
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
if (Avx2.IsSupported && Unsafe.SizeOf<Vector256<byte>>() == 32)
|
||||
{
|
||||
var X = MemoryMarshal.AsBytes(x[..16]);
|
||||
var Y = MemoryMarshal.AsBytes(y[..16]);
|
||||
var Z = MemoryMarshal.AsBytes(z[..16]);
|
||||
|
||||
var X0 = MemoryMarshal.Read<Vector256<byte>>(X[0x00..0x20]);
|
||||
var X1 = MemoryMarshal.Read<Vector256<byte>>(X[0x20..0x40]);
|
||||
|
||||
var Y0 = MemoryMarshal.Read<Vector256<byte>>(Y[0x00..0x20]);
|
||||
var Y1 = MemoryMarshal.Read<Vector256<byte>>(Y[0x20..0x40]);
|
||||
|
||||
var Z0 = Avx2.Xor(X0, Y0);
|
||||
var Z1 = Avx2.Xor(X1, Y1);
|
||||
|
||||
MemoryMarshal.Write(Z[0x00..0x20], ref Z0);
|
||||
MemoryMarshal.Write(Z[0x20..0x40], ref Z1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Sse2.IsSupported && Unsafe.SizeOf<Vector128<byte>>() == 16)
|
||||
{
|
||||
var X = MemoryMarshal.AsBytes(x[..16]);
|
||||
var Y = MemoryMarshal.AsBytes(y[..16]);
|
||||
var Z = MemoryMarshal.AsBytes(z[..16]);
|
||||
|
||||
var X0 = MemoryMarshal.Read<Vector128<byte>>(X[0x00..0x10]);
|
||||
var X1 = MemoryMarshal.Read<Vector128<byte>>(X[0x10..0x20]);
|
||||
var X2 = MemoryMarshal.Read<Vector128<byte>>(X[0x20..0x30]);
|
||||
var X3 = MemoryMarshal.Read<Vector128<byte>>(X[0x30..0x40]);
|
||||
|
||||
var Y0 = MemoryMarshal.Read<Vector128<byte>>(Y[0x00..0x10]);
|
||||
var Y1 = MemoryMarshal.Read<Vector128<byte>>(Y[0x10..0x20]);
|
||||
var Y2 = MemoryMarshal.Read<Vector128<byte>>(Y[0x20..0x30]);
|
||||
var Y3 = MemoryMarshal.Read<Vector128<byte>>(Y[0x30..0x40]);
|
||||
|
||||
var Z0 = Sse2.Xor(X0, Y0);
|
||||
var Z1 = Sse2.Xor(X1, Y1);
|
||||
var Z2 = Sse2.Xor(X2, Y2);
|
||||
var Z3 = Sse2.Xor(X3, Y3);
|
||||
|
||||
MemoryMarshal.Write(Z[0x00..0x10], ref Z0);
|
||||
MemoryMarshal.Write(Z[0x10..0x20], ref Z1);
|
||||
MemoryMarshal.Write(Z[0x20..0x30], ref Z2);
|
||||
MemoryMarshal.Write(Z[0x30..0x40], ref Z3);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < 16; i += 4)
|
||||
{
|
||||
z[i + 0] = x[i + 0] ^ y[i + 0];
|
||||
z[i + 1] = x[i + 1] ^ y[i + 1];
|
||||
z[i + 2] = x[i + 2] ^ y[i + 2];
|
||||
z[i + 3] = x[i + 3] ^ y[i + 3];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void XorTo(uint[] x, int xOff, uint[] z, int zOff)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
XorTo(x.AsSpan(xOff), z.AsSpan(zOff));
|
||||
#else
|
||||
for (int i = 0; i < 16; i += 4)
|
||||
{
|
||||
z[zOff + i + 0] ^= x[xOff + i + 0];
|
||||
z[zOff + i + 1] ^= x[xOff + i + 1];
|
||||
z[zOff + i + 2] ^= x[xOff + i + 2];
|
||||
z[zOff + i + 3] ^= x[xOff + i + 3];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public static void XorTo(ReadOnlySpan<uint> x, Span<uint> z)
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
if (Avx2.IsSupported && Unsafe.SizeOf<Vector256<byte>>() == 32)
|
||||
{
|
||||
var X = MemoryMarshal.AsBytes(x[..16]);
|
||||
var Z = MemoryMarshal.AsBytes(z[..16]);
|
||||
|
||||
var X0 = MemoryMarshal.Read<Vector256<byte>>(X[0x00..0x20]);
|
||||
var X1 = MemoryMarshal.Read<Vector256<byte>>(X[0x20..0x40]);
|
||||
|
||||
var Y0 = MemoryMarshal.Read<Vector256<byte>>(Z[0x00..0x20]);
|
||||
var Y1 = MemoryMarshal.Read<Vector256<byte>>(Z[0x20..0x40]);
|
||||
|
||||
var Z0 = Avx2.Xor(X0, Y0);
|
||||
var Z1 = Avx2.Xor(X1, Y1);
|
||||
|
||||
MemoryMarshal.Write(Z[0x00..0x20], ref Z0);
|
||||
MemoryMarshal.Write(Z[0x20..0x40], ref Z1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Sse2.IsSupported && Unsafe.SizeOf<Vector128<byte>>() == 16)
|
||||
{
|
||||
var X = MemoryMarshal.AsBytes(x[..16]);
|
||||
var Z = MemoryMarshal.AsBytes(z[..16]);
|
||||
|
||||
var X0 = MemoryMarshal.Read<Vector128<byte>>(X[0x00..0x10]);
|
||||
var X1 = MemoryMarshal.Read<Vector128<byte>>(X[0x10..0x20]);
|
||||
var X2 = MemoryMarshal.Read<Vector128<byte>>(X[0x20..0x30]);
|
||||
var X3 = MemoryMarshal.Read<Vector128<byte>>(X[0x30..0x40]);
|
||||
|
||||
var Y0 = MemoryMarshal.Read<Vector128<byte>>(Z[0x00..0x10]);
|
||||
var Y1 = MemoryMarshal.Read<Vector128<byte>>(Z[0x10..0x20]);
|
||||
var Y2 = MemoryMarshal.Read<Vector128<byte>>(Z[0x20..0x30]);
|
||||
var Y3 = MemoryMarshal.Read<Vector128<byte>>(Z[0x30..0x40]);
|
||||
|
||||
var Z0 = Sse2.Xor(X0, Y0);
|
||||
var Z1 = Sse2.Xor(X1, Y1);
|
||||
var Z2 = Sse2.Xor(X2, Y2);
|
||||
var Z3 = Sse2.Xor(X3, Y3);
|
||||
|
||||
MemoryMarshal.Write(Z[0x00..0x10], ref Z0);
|
||||
MemoryMarshal.Write(Z[0x10..0x20], ref Z1);
|
||||
MemoryMarshal.Write(Z[0x20..0x30], ref Z2);
|
||||
MemoryMarshal.Write(Z[0x30..0x40], ref Z3);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < 16; i += 4)
|
||||
{
|
||||
z[i + 0] ^= x[i + 0];
|
||||
z[i + 1] ^= x[i + 1];
|
||||
z[i + 2] ^= x[i + 2];
|
||||
z[i + 3] ^= x[i + 3];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void Xor64(ulong[] x, int xOff, ulong[] y, int yOff, ulong[] z, int zOff)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
Xor64(x.AsSpan(xOff), y.AsSpan(yOff), z.AsSpan(zOff));
|
||||
#else
|
||||
for (int i = 0; i < 8; i += 4)
|
||||
{
|
||||
z[zOff + i + 0] = x[xOff + i + 0] ^ y[yOff + i + 0];
|
||||
z[zOff + i + 1] = x[xOff + i + 1] ^ y[yOff + i + 1];
|
||||
z[zOff + i + 2] = x[xOff + i + 2] ^ y[yOff + i + 2];
|
||||
z[zOff + i + 3] = x[xOff + i + 3] ^ y[yOff + i + 3];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public static void Xor64(ReadOnlySpan<ulong> x, ReadOnlySpan<ulong> y, Span<ulong> z)
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
if (Avx2.IsSupported && Unsafe.SizeOf<Vector256<byte>>() == 32)
|
||||
{
|
||||
var X = MemoryMarshal.AsBytes(x[..8]);
|
||||
var Y = MemoryMarshal.AsBytes(y[..8]);
|
||||
var Z = MemoryMarshal.AsBytes(z[..8]);
|
||||
|
||||
var X0 = MemoryMarshal.Read<Vector256<byte>>(X[0x00..0x20]);
|
||||
var X1 = MemoryMarshal.Read<Vector256<byte>>(X[0x20..0x40]);
|
||||
|
||||
var Y0 = MemoryMarshal.Read<Vector256<byte>>(Y[0x00..0x20]);
|
||||
var Y1 = MemoryMarshal.Read<Vector256<byte>>(Y[0x20..0x40]);
|
||||
|
||||
var Z0 = Avx2.Xor(X0, Y0);
|
||||
var Z1 = Avx2.Xor(X1, Y1);
|
||||
|
||||
MemoryMarshal.Write(Z[0x00..0x20], ref Z0);
|
||||
MemoryMarshal.Write(Z[0x20..0x40], ref Z1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Sse2.IsSupported && Unsafe.SizeOf<Vector128<byte>>() == 16)
|
||||
{
|
||||
var X = MemoryMarshal.AsBytes(x[..8]);
|
||||
var Y = MemoryMarshal.AsBytes(y[..8]);
|
||||
var Z = MemoryMarshal.AsBytes(z[..8]);
|
||||
|
||||
var X0 = MemoryMarshal.Read<Vector128<byte>>(X[0x00..0x10]);
|
||||
var X1 = MemoryMarshal.Read<Vector128<byte>>(X[0x10..0x20]);
|
||||
var X2 = MemoryMarshal.Read<Vector128<byte>>(X[0x20..0x30]);
|
||||
var X3 = MemoryMarshal.Read<Vector128<byte>>(X[0x30..0x40]);
|
||||
|
||||
var Y0 = MemoryMarshal.Read<Vector128<byte>>(Y[0x00..0x10]);
|
||||
var Y1 = MemoryMarshal.Read<Vector128<byte>>(Y[0x10..0x20]);
|
||||
var Y2 = MemoryMarshal.Read<Vector128<byte>>(Y[0x20..0x30]);
|
||||
var Y3 = MemoryMarshal.Read<Vector128<byte>>(Y[0x30..0x40]);
|
||||
|
||||
var Z0 = Sse2.Xor(X0, Y0);
|
||||
var Z1 = Sse2.Xor(X1, Y1);
|
||||
var Z2 = Sse2.Xor(X2, Y2);
|
||||
var Z3 = Sse2.Xor(X3, Y3);
|
||||
|
||||
MemoryMarshal.Write(Z[0x00..0x10], ref Z0);
|
||||
MemoryMarshal.Write(Z[0x10..0x20], ref Z1);
|
||||
MemoryMarshal.Write(Z[0x20..0x30], ref Z2);
|
||||
MemoryMarshal.Write(Z[0x30..0x40], ref Z3);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < 8; i += 4)
|
||||
{
|
||||
z[i + 0] = x[i + 0] ^ y[i + 0];
|
||||
z[i + 1] = x[i + 1] ^ y[i + 1];
|
||||
z[i + 2] = x[i + 2] ^ y[i + 2];
|
||||
z[i + 3] = x[i + 3] ^ y[i + 3];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void XorTo64(ulong[] x, int xOff, ulong[] z, int zOff)
|
||||
{
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
XorTo64(x.AsSpan(xOff), z.AsSpan(zOff));
|
||||
#else
|
||||
for (int i = 0; i < 8; i += 4)
|
||||
{
|
||||
z[zOff + i + 0] ^= x[xOff + i + 0];
|
||||
z[zOff + i + 1] ^= x[xOff + i + 1];
|
||||
z[zOff + i + 2] ^= x[xOff + i + 2];
|
||||
z[zOff + i + 3] ^= x[xOff + i + 3];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
|
||||
public static void XorTo64(ReadOnlySpan<ulong> x, Span<ulong> z)
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
if (Avx2.IsSupported && Unsafe.SizeOf<Vector256<byte>>() == 32)
|
||||
{
|
||||
var X = MemoryMarshal.AsBytes(x[..8]);
|
||||
var Z = MemoryMarshal.AsBytes(z[..8]);
|
||||
|
||||
var X0 = MemoryMarshal.Read<Vector256<byte>>(X[0x00..0x20]);
|
||||
var X1 = MemoryMarshal.Read<Vector256<byte>>(X[0x20..0x40]);
|
||||
|
||||
var Y0 = MemoryMarshal.Read<Vector256<byte>>(Z[0x00..0x20]);
|
||||
var Y1 = MemoryMarshal.Read<Vector256<byte>>(Z[0x20..0x40]);
|
||||
|
||||
var Z0 = Avx2.Xor(X0, Y0);
|
||||
var Z1 = Avx2.Xor(X1, Y1);
|
||||
|
||||
MemoryMarshal.Write(Z[0x00..0x20], ref Z0);
|
||||
MemoryMarshal.Write(Z[0x20..0x40], ref Z1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Sse2.IsSupported && Unsafe.SizeOf<Vector128<byte>>() == 16)
|
||||
{
|
||||
var X = MemoryMarshal.AsBytes(x[..8]);
|
||||
var Z = MemoryMarshal.AsBytes(z[..8]);
|
||||
|
||||
var X0 = MemoryMarshal.Read<Vector128<byte>>(X[0x00..0x10]);
|
||||
var X1 = MemoryMarshal.Read<Vector128<byte>>(X[0x10..0x20]);
|
||||
var X2 = MemoryMarshal.Read<Vector128<byte>>(X[0x20..0x30]);
|
||||
var X3 = MemoryMarshal.Read<Vector128<byte>>(X[0x30..0x40]);
|
||||
|
||||
var Y0 = MemoryMarshal.Read<Vector128<byte>>(Z[0x00..0x10]);
|
||||
var Y1 = MemoryMarshal.Read<Vector128<byte>>(Z[0x10..0x20]);
|
||||
var Y2 = MemoryMarshal.Read<Vector128<byte>>(Z[0x20..0x30]);
|
||||
var Y3 = MemoryMarshal.Read<Vector128<byte>>(Z[0x30..0x40]);
|
||||
|
||||
var Z0 = Sse2.Xor(X0, Y0);
|
||||
var Z1 = Sse2.Xor(X1, Y1);
|
||||
var Z2 = Sse2.Xor(X2, Y2);
|
||||
var Z3 = Sse2.Xor(X3, Y3);
|
||||
|
||||
MemoryMarshal.Write(Z[0x00..0x10], ref Z0);
|
||||
MemoryMarshal.Write(Z[0x10..0x20], ref Z1);
|
||||
MemoryMarshal.Write(Z[0x20..0x30], ref Z2);
|
||||
MemoryMarshal.Write(Z[0x30..0x40], ref Z3);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < 8; i += 4)
|
||||
{
|
||||
z[i + 0] ^= x[i + 0];
|
||||
z[i + 1] ^= x[i + 1];
|
||||
z[i + 2] ^= x[i + 2];
|
||||
z[i + 3] ^= x[i + 3];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat512.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat512.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 872a1fdcc31253a43b1d02b6a8ebb0a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
104
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat576.cs
vendored
Normal file
104
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat576.cs
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
#pragma warning disable
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
|
||||
|
||||
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Raw
|
||||
{
|
||||
internal abstract class Nat576
|
||||
{
|
||||
public static void Copy64(ulong[] x, ulong[] z)
|
||||
{
|
||||
z[0] = x[0];
|
||||
z[1] = x[1];
|
||||
z[2] = x[2];
|
||||
z[3] = x[3];
|
||||
z[4] = x[4];
|
||||
z[5] = x[5];
|
||||
z[6] = x[6];
|
||||
z[7] = x[7];
|
||||
z[8] = x[8];
|
||||
}
|
||||
|
||||
public static void Copy64(ulong[] x, int xOff, ulong[] z, int zOff)
|
||||
{
|
||||
z[zOff + 0] = x[xOff + 0];
|
||||
z[zOff + 1] = x[xOff + 1];
|
||||
z[zOff + 2] = x[xOff + 2];
|
||||
z[zOff + 3] = x[xOff + 3];
|
||||
z[zOff + 4] = x[xOff + 4];
|
||||
z[zOff + 5] = x[xOff + 5];
|
||||
z[zOff + 6] = x[xOff + 6];
|
||||
z[zOff + 7] = x[xOff + 7];
|
||||
z[zOff + 8] = x[xOff + 8];
|
||||
}
|
||||
|
||||
public static ulong[] Create64()
|
||||
{
|
||||
return new ulong[9];
|
||||
}
|
||||
|
||||
public static ulong[] CreateExt64()
|
||||
{
|
||||
return new ulong[18];
|
||||
}
|
||||
|
||||
public static bool Eq64(ulong[] x, ulong[] y)
|
||||
{
|
||||
for (int i = 8; i >= 0; --i)
|
||||
{
|
||||
if (x[i] != y[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsOne64(ulong[] x)
|
||||
{
|
||||
if (x[0] != 1UL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 1; i < 9; ++i)
|
||||
{
|
||||
if (x[i] != 0UL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsZero64(ulong[] x)
|
||||
{
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
if (x[i] != 0UL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static BigInteger ToBigInteger64(ulong[] x)
|
||||
{
|
||||
byte[] bs = new byte[72];
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
ulong x_i = x[i];
|
||||
if (x_i != 0L)
|
||||
{
|
||||
Pack.UInt64_To_BE(x_i, bs, (8 - i) << 3);
|
||||
}
|
||||
}
|
||||
return new BigInteger(1, bs);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore
|
||||
#endif
|
||||
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat576.cs.meta
vendored
Normal file
11
Packages/com.tivadar.best.http/Runtime/3rdParty/BouncyCastle/math/raw/Nat576.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ea9f7f5581e4ad4a8fc33fa01aa8bef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user