6#include "Misc/AssertionMacros.h"
7#include "HAL/UnrealMemory.h"
8#include "Containers/UnrealString.h"
11
12
13
14
15
16
17template <int32 NumBits,
bool bSigned =
true>
35 static_assert(NumBits >= 64,
"TBigInt must have at least 64 bits.");
41
42
43
44
45
46
47
66
67
68
69
70
71
99
100
101
102
117
118
119
120
127
128
135
136
137 explicit TBigInt(
const uint8* InData, uint32 InNumBytes)
150
151
158
159
160
161
193
194
208
209
210
211
243
244
258
259
273
274
283
284
298
299
306
307
318
319
328
329
361
362
380
381
455
456
464
465
483
484
518
519
527
528
544
545
554
555
571
572
573
574
596
597
598
599
621
622
632
633
643
644
654
655
670
671
691
692
712
713
733
734
754
755
764
765
772
773
781 return !!(
Bits[0] & 1);
784
785
960
961
968
969
989
990
1013
1014
1025template<int32 NumBits,
bool bSigned>
1034
1035
1036template <
typename IntType>
1045
1046
1050
1051
1052 template <
typename IntType>
1073 while ((
ValueA & 1) == 0)
1081 while ((
ValueB & 1) == 0)
1100
1101
1102
1103
1104
1105 template <
typename IntType>
1143
1144
1145 template <
typename IntType>
1168
1169
1170 template <
typename IntType>
1171 static IntType
ModularPow(IntType Base, IntType Exponent, IntType Modulus)
1188
1189
1190 template <
typename IntType>
1200
1201
1202 template <
typename IntType>
1216
1217
1222 while (Exponent.IsGreaterThanZero())
1224 if (Exponent.IsFirstBitSet())
1226 Result.MultiplyFast(Base);
1227 Result.Modulo(Modulus);
1229 Exponent.ShiftRightByOneInternal();
1230 Base.MultiplyFast(Base);
1231 Base.Modulo(Modulus);
1238template <
class InDataType>
1276
1277
1299 OutEncryptedSignature.Data = FEncryption::ModularPow(TEncryptionInt(InUnencryptedSignature.Data), EncryptionKey.Exponent, EncryptionKey.Modulus);
1304 OutUnencryptedSignature.Data = (FDecryptedSignature::DataType)FEncryption::ModularPow(TEncryptionInt(InEncryptedSignature.Data), EncryptionKey.Exponent, EncryptionKey.Modulus).ToInt();
TBigInt< 512 > TEncryptionInt
TEncryptionKey< TEncryptionInt > FEncryptionKey
#define UE_ARRAY_COUNT(array)
FORCEINLINE uint32 * GetBits()
bool operator!=(const BigInt &Other) const
void ShiftRightByOneInternal()
bool IsEqual(const BigInt &Other) const
bool IsFirstBitSet() const
bool operator[](int32 BitIndex) const
void ShiftLeftByOneInternal()
bool IsGreater(const BigInt &Other) const
BigInt operator*(const BigInt &Other) const
BigInt operator>>(int32 Count) const
BigInt & operator&=(const BigInt &Other)
bool IsGreaterOrEqual(const BigInt &Other) const
bool operator==(const BigInt &Other) const
BigInt operator+(const BigInt &Other) const
int32 GetHighestNonZeroWord() const
BigInt & operator/=(const BigInt &Divider)
void SetBit(int32 BitIndex, int32 Value)
bool operator<=(const BigInt &Other) const
BigInt & operator-=(const BigInt &Other)
TBigInt(const uint8 *InData, uint32 InNumBytes)
static FORCEINLINE void RestoreSign(BigInt &Result, int32 SignA, int32 SignB)
void Multiply(const BigInt &Factor)
BigInt operator|(const BigInt &Other) const
void Subtract(const BigInt &Other)
TBigInt & operator=(int64 Other)
FORCEINLINE void Set(int64 Value)
BigInt & operator|=(const BigInt &Other)
bool IsLessOrEqual(const BigInt &Other) const
bool operator>(const BigInt &Other) const
BigInt operator-(const BigInt &Other) const
BigInt & operator*=(const BigInt &Other)
void ShiftRight(const int32 BitCount)
void ShiftRightInternal(const int32 BitCount)
void MultiplyFast(const BigInt &Factor)
void ShiftLeftInternal(const int32 BitCount)
static FORCEINLINE void MakePositiveFactors(BigInt &FactorA, int32 &SignA, BigInt &FactorB, int32 &SignB)
TBigInt(const FString &Value)
bool operator<(const BigInt &Other) const
TBigInt(const uint32 *InBits)
void ShiftLeft(const int32 BitCount)
void BitwiseAnd(const BigInt &Other)
bool IsGreaterThanZero() const
int32 GetBit(int32 BitIndex) const
BigInt operator%(const BigInt &Modulus) const
FORCEINLINE const uint32 * GetBits() const
BigInt operator/(const BigInt &Divider) const
void Modulo(const BigInt &Modulus)
void DivideWithRemainder(const BigInt &Divisor, BigInt &Remainder)
void BitwiseOr(const BigInt &Other)
void Add(const BigInt &Other)
BigInt & operator>>=(int32 Count)
TBigInt< NumBits, bSigned > BigInt
void Parse(const FString &Value)
BigInt operator&(const BigInt &Other) const
int32 GetHighestNonZeroBit() const
bool IsLessThanZero() const
BigInt & operator+=(const BigInt &Other)
void Divide(const BigInt &Divisor)
BigInt & operator%=(const BigInt &Modulus)
bool operator>=(const BigInt &Other) const
bool IsLess(const BigInt &Other) const
static IntType CalculateMultiplicativeInverseOfExponent(IntType Exponent, IntType Totient)
static void EncryptBytes(IntType *EncryptedData, const uint8 *Data, const int64 DataLength, const FEncryptionKey &EncryptionKey)
static void EncryptSignature(const FDecryptedSignature &InUnencryptedSignature, FEncryptedSignature &OutEncryptedSignature, const FEncryptionKey &EncryptionKey)
static IntType CalculateGCD(IntType ValueA, IntType ValueB)
static void DecryptSignature(const FEncryptedSignature &InEncryptedSignature, FDecryptedSignature &OutUnencryptedSignature, const FEncryptionKey &EncryptionKey)
static IntType ModularPow(IntType Base, IntType Exponent, IntType Modulus)
static void DecryptBytes(uint8 *DecryptedData, const IntType *Data, const int64 DataLength, const FEncryptionKey &DecryptionKey)
static void GenerateKeyPair(const IntType &P, const IntType &Q, FEncryptionKey &PublicKey, FEncryptionKey &PrivateKey)
bool operator==(const FSignatureBase &InOther)
bool operator!=(const FSignatureBase &InOther)
void Serialize(FArchive &Ar)