Fabcoin Core
0.16.2
P2P Digital Currency
|
#include "pch.h"
#include "config.h"
#include "integer.h"
#include "secblock.h"
#include "modarith.h"
#include "nbtheory.h"
#include "smartptr.h"
#include "algparam.h"
#include "filters.h"
#include "asn.h"
#include "oids.h"
#include "words.h"
#include "pubkey.h"
#include "sha.h"
#include "cpu.h"
#include "misc.h"
#include <iostream>
Go to the source code of this file.
Classes | |
class | DWord |
struct | DWord::half_words |
class | Word |
struct | NewInteger< i > |
class | KDF2_RNG |
Macros | |
#define | MAYBE_CONST const |
#define | MAYBE_UNCONST_CAST |
#define | CRYPTOPP_INTEGER_SSE2 (CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && (CRYPTOPP_BOOL_X86)) |
#define | Declare2Words(x) dword x; |
#define | MultiplyWords(p, a, b) p = (dword)a*b; |
#define | AssignWord(a, b) a = b; |
#define | Add2WordsBy1(a, b, c) a = b + c; |
#define | Acc2WordsBy2(a, b) a += b; |
#define | LowWord(a) word(a) |
#define | HighWord(a) word(a>>WORD_BITS) |
#define | Double3Words(c, d) d = 2*d + (c>>(WORD_BITS-1)); c *= 2; |
#define | AddWithCarry(u, a, b) u = dword(a) + b + GetCarry(u); |
#define | SubtractWithBorrow(u, a, b) u = dword(a) - b - GetBorrow(u); |
#define | GetCarry(u) HighWord(u) |
#define | GetBorrow(u) word(u>>(WORD_BITS*2-1)) |
#define | MulAcc(c, d, a, b) MultiplyWords(p, a, b); Acc2WordsBy1(p, c); c = LowWord(p); Acc2WordsBy1(d, HighWord(p)); |
#define | Acc2WordsBy1(a, b) Add2WordsBy1(a, a, b) |
#define | Acc3WordsBy2(c, d, e) Acc2WordsBy1(e, c); c = LowWord(e); Add2WordsBy1(e, d, HighWord(e)); |
#define | AddPrologue |
#define | AddEpilogue |
#define | SaveEBX |
#define | RestoreEBX |
#define | SquPrologue |
#define | MulPrologue |
#define | TopPrologue |
#define | SquEpilogue RestoreEBX |
#define | MulEpilogue RestoreEBX |
#define | TopEpilogue RestoreEBX |
#define | Mul_2 |
#define | Mul_4 |
#define | Mul_8 |
#define | Mul_16 |
#define | Squ_2 |
#define | Squ_4 |
#define | Squ_8 |
#define | Squ_16 |
#define | Bot_2 |
#define | Bot_4 |
#define | Bot_8 |
#define | Bot_16 |
#define | Mul_Begin(n) |
#define | Mul_Acc(i, j) MulAcc(c, d, A[i], B[j]) |
#define | Mul_SaveAcc(k, i, j) |
#define | Mul_End(k, i) |
#define | Bot_SaveAcc(k, i, j) |
#define | Bot_Acc(i, j) c += A[i] * B[j]; |
#define | Bot_End(n) R[n-1] = c; |
#define | Squ_Begin(n) |
#define | Squ_NonDiag Double3Words(c, d) |
#define | Squ_SaveAcc(k, i, j) |
#define | Squ_Acc(i, j) MulAcc(c, d, A[i], A[j]) |
#define | Squ_Diag(i) |
#define | Squ_End(n) |
#define | Top_Begin(n) |
#define | Top_Acc(i, j) |
#define | Top_SaveAcc0(i, j) |
#define | Top_SaveAcc1(i, j) |
#define | A0 A |
#define | A1 (A+N2) |
#define | B0 B |
#define | B1 (B+N2) |
#define | T0 T |
#define | T1 (T+N2) |
#define | T2 (T+N) |
#define | T3 (T+N+N2) |
#define | R0 R |
#define | R1 (R+N2) |
#define | R2 (R+N) |
#define | R3 (R+N+N2) |
#define | M0 M |
#define | M1 (M+N2) |
#define | V0 V |
#define | V1 (V+N2) |
#define | X0 X |
#define | X1 (X+N2) |
#define | X2 (X+N) |
#define | X3 (X+N+N2) |
Typedefs | |
typedef int(CRYPTOPP_FASTCALL * | PAdd) (size_t N, word *C, const word *A, const word *B) |
typedef void(* | PMul) (word *C, const word *A, const word *B) |
typedef void(* | PSqu) (word *C, const word *A) |
typedef void(* | PMulTop) (word *C, const word *A, const word *B, word L) |
Functions | |
bool | AssignIntToInteger (const std::type_info &valueType, void *pInteger, const void *pInt) |
template<class S , class D > | |
S | DivideThreeWordsByTwo (S *A, S B0, S B1, D *dummy=NULL) |
template<class S , class D > | |
D | DivideFourWordsByTwo (S *T, const D &Al, const D &Ah, const D &B) |
int CRYPTOPP_FASTCALL | Baseline_Add (size_t N, word *C, const word *A, const word *B) |
int CRYPTOPP_FASTCALL | Baseline_Sub (size_t N, word *C, const word *A, const word *B) |
void | Baseline_Multiply2 (word *R, const word *AA, const word *BB) |
void | Baseline_Multiply4 (word *R, const word *AA, const word *BB) |
void | Baseline_Multiply8 (word *R, const word *AA, const word *BB) |
void | Baseline_Square2 (word *R, const word *AA) |
void | Baseline_Square4 (word *R, const word *AA) |
void | Baseline_Square8 (word *R, const word *AA) |
void | Baseline_MultiplyBottom2 (word *R, const word *AA, const word *BB) |
void | Baseline_MultiplyBottom4 (word *R, const word *AA, const word *BB) |
void | Baseline_MultiplyBottom8 (word *R, const word *AA, const word *BB) |
void | Baseline_MultiplyTop2 (word *R, const word *A, const word *B, word L) |
void | Baseline_MultiplyTop4 (word *R, const word *AA, const word *BB, word L) |
void | Baseline_MultiplyTop8 (word *R, const word *AA, const word *BB, word L) |
void | Baseline_Multiply16 (word *R, const word *AA, const word *BB) |
void | Baseline_Square16 (word *R, const word *AA) |
void | Baseline_MultiplyBottom16 (word *R, const word *AA, const word *BB) |
void | Baseline_MultiplyTop16 (word *R, const word *AA, const word *BB, word L) |
int | Add (word *C, const word *A, const word *B, size_t N) |
int | Subtract (word *C, const word *A, const word *B, size_t N) |
void | RecursiveMultiply (word *R, word *T, const word *A, const word *B, size_t N) |
void | RecursiveSquare (word *R, word *T, const word *A, size_t N) |
void | RecursiveMultiplyBottom (word *R, word *T, const word *A, const word *B, size_t N) |
void | MultiplyTop (word *R, word *T, const word *L, const word *A, const word *B, size_t N) |
void | Multiply (word *R, word *T, const word *A, const word *B, size_t N) |
void | Square (word *R, word *T, const word *A, size_t N) |
void | MultiplyBottom (word *R, word *T, const word *A, const word *B, size_t N) |
void | AsymmetricMultiply (word *R, word *T, const word *A, size_t NA, const word *B, size_t NB) |
void | RecursiveInverseModPower2 (word *R, word *T, const word *A, size_t N) |
void | MontgomeryReduce (word *R, word *T, word *X, const word *M, const word *U, size_t N) |
void | HalfMontgomeryReduce (word *R, word *T, const word *X, const word *M, const word *U, const word *V, size_t N) |
void | Divide (word *R, word *Q, word *T, const word *A, size_t NA, const word *B, size_t NB) |
unsigned int | AlmostInverse (word *R, word *T, const word *A, size_t NA, const word *M, size_t N) |
void | DivideByPower2Mod (word *R, const word *A, size_t k, const word *M, size_t N) |
void | MultiplyByPower2Mod (word *R, const word *A, size_t k, const word *M, size_t N) |
std::istream & | operator>> (std::istream &in, Integer &a) |
std::ostream & | operator<< (std::ostream &out, const Integer &a) |
void | PositiveAdd (Integer &sum, const Integer &a, const Integer &b) |
void | PositiveSubtract (Integer &diff, const Integer &a, const Integer &b) |
template<class T > | |
const T & | STDMAX2 (const T &a, const T &b) |
void | PositiveMultiply (Integer &product, const Integer &a, const Integer &b) |
void | Multiply (Integer &product, const Integer &a, const Integer &b) |
void | PositiveDivide (Integer &remainder, Integer "ient, const Integer &a, const Integer &b) |
Integer | a_times_b_mod_c (const Integer &x, const Integer &y, const Integer &m) |
Integer | a_exp_b_mod_c (const Integer &x, const Integer &e, const Integer &m) |
template<> | |
CRYPTOPP_DLL std::string | IntToString< Integer > (Integer value, unsigned int base) |
Converts an Integer to a string. More... | |
template<> | |
CRYPTOPP_DLL std::string | IntToString< word64 > (word64 value, unsigned int base) |
Converts an unsigned value to a string. More... | |
#define A0 A |
Definition at line 2164 of file integer.cpp.
#define A1 (A+N2) |
Definition at line 2165 of file integer.cpp.
Definition at line 200 of file integer.cpp.
#define Acc3WordsBy2 | ( | c, | |
d, | |||
e | |||
) | Acc2WordsBy1(e, c); c = LowWord(e); Add2WordsBy1(e, d, HighWord(e)); |
Definition at line 203 of file integer.cpp.
#define AddEpilogue |
Definition at line 562 of file integer.cpp.
#define AddPrologue |
Definition at line 557 of file integer.cpp.
Definition at line 191 of file integer.cpp.
#define B0 B |
Definition at line 2166 of file integer.cpp.
#define B1 (B+N2) |
Definition at line 2167 of file integer.cpp.
#define Bot_16 |
Definition at line 1057 of file integer.cpp.
#define Bot_2 |
Definition at line 1034 of file integer.cpp.
#define Bot_4 |
Definition at line 1039 of file integer.cpp.
#define Bot_8 |
Definition at line 1046 of file integer.cpp.
#define Bot_Acc | ( | i, | |
j | |||
) | c += A[i] * B[j]; |
Definition at line 1147 of file integer.cpp.
Definition at line 1150 of file integer.cpp.
#define Bot_SaveAcc | ( | k, | |
i, | |||
j | |||
) |
#define CRYPTOPP_INTEGER_SSE2 (CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && (CRYPTOPP_BOOL_X86)) |
Definition at line 69 of file integer.cpp.
Definition at line 179 of file integer.cpp.
Definition at line 190 of file integer.cpp.
Definition at line 194 of file integer.cpp.
#define GetCarry | ( | u | ) | HighWord(u) |
Definition at line 193 of file integer.cpp.
Definition at line 188 of file integer.cpp.
#define M0 M |
#define M1 (M+N2) |
#define MAYBE_CONST const |
Definition at line 54 of file integer.cpp.
#define MAYBE_UNCONST_CAST |
Definition at line 55 of file integer.cpp.
#define Mul_16 |
Definition at line 941 of file integer.cpp.
#define Mul_2 |
Definition at line 910 of file integer.cpp.
#define Mul_4 |
Definition at line 915 of file integer.cpp.
#define Mul_8 |
Definition at line 924 of file integer.cpp.
Definition at line 1126 of file integer.cpp.
#define Mul_Begin | ( | n | ) |
Definition at line 1118 of file integer.cpp.
#define Mul_End | ( | k, | |
i | |||
) |
Definition at line 1135 of file integer.cpp.
#define Mul_SaveAcc | ( | k, | |
i, | |||
j | |||
) |
Definition at line 1129 of file integer.cpp.
#define MulAcc | ( | c, | |
d, | |||
a, | |||
b | |||
) | MultiplyWords(p, a, b); Acc2WordsBy1(p, c); c = LowWord(p); Acc2WordsBy1(d, HighWord(p)); |
Definition at line 197 of file integer.cpp.
#define MulEpilogue RestoreEBX |
Definition at line 587 of file integer.cpp.
#define MulPrologue |
Definition at line 573 of file integer.cpp.
#define R0 R |
Definition at line 2174 of file integer.cpp.
#define R1 (R+N2) |
Definition at line 2175 of file integer.cpp.
#define R2 (R+N) |
Definition at line 2176 of file integer.cpp.
#define R3 (R+N+N2) |
Definition at line 2177 of file integer.cpp.
#define RestoreEBX |
Definition at line 567 of file integer.cpp.
#define SaveEBX |
Definition at line 566 of file integer.cpp.
#define Squ_16 |
Definition at line 1002 of file integer.cpp.
#define Squ_2 |
Definition at line 974 of file integer.cpp.
#define Squ_4 |
Definition at line 978 of file integer.cpp.
#define Squ_8 |
Definition at line 986 of file integer.cpp.
Definition at line 1177 of file integer.cpp.
#define Squ_Begin | ( | n | ) |
Definition at line 1154 of file integer.cpp.
#define Squ_Diag | ( | i | ) |
Definition at line 1180 of file integer.cpp.
#define Squ_End | ( | n | ) |
Definition at line 1184 of file integer.cpp.
#define Squ_NonDiag Double3Words(c, d) |
Definition at line 1167 of file integer.cpp.
#define Squ_SaveAcc | ( | k, | |
i, | |||
j | |||
) |
Definition at line 1170 of file integer.cpp.
#define SquEpilogue RestoreEBX |
Definition at line 586 of file integer.cpp.
#define SquPrologue |
Definition at line 568 of file integer.cpp.
Definition at line 192 of file integer.cpp.
#define T0 T |
Definition at line 2169 of file integer.cpp.
#define T1 (T+N2) |
Definition at line 2170 of file integer.cpp.
#define T2 (T+N) |
Definition at line 2171 of file integer.cpp.
#define T3 (T+N+N2) |
Definition at line 2172 of file integer.cpp.
#define Top_Acc | ( | i, | |
j | |||
) |
Definition at line 1278 of file integer.cpp.
#define Top_Begin | ( | n | ) |
Definition at line 1271 of file integer.cpp.
#define Top_SaveAcc0 | ( | i, | |
j | |||
) |
Definition at line 1282 of file integer.cpp.
#define Top_SaveAcc1 | ( | i, | |
j | |||
) |
Definition at line 1287 of file integer.cpp.
#define TopEpilogue RestoreEBX |
Definition at line 588 of file integer.cpp.
#define TopPrologue |
Definition at line 579 of file integer.cpp.
#define V0 V |
#define V1 (V+N2) |
#define X0 X |
#define X1 (X+N2) |
#define X2 (X+N) |
#define X3 (X+N+N2) |
typedef int(CRYPTOPP_FASTCALL * PAdd) (size_t N, word *C, const word *A, const word *B) |
Definition at line 2066 of file integer.cpp.
Definition at line 2067 of file integer.cpp.
Definition at line 2069 of file integer.cpp.
Definition at line 2068 of file integer.cpp.
Definition at line 4359 of file integer.cpp.
Definition at line 2143 of file integer.cpp.
unsigned int AlmostInverse | ( | word * | R, |
word * | T, | ||
const word * | A, | ||
size_t | NA, | ||
const word * | M, | ||
size_t | N | ||
) |
Definition at line 2760 of file integer.cpp.
bool AssignIntToInteger | ( | const std::type_info & | valueType, |
void * | pInteger, | ||
const void * | pInt | ||
) |
void AsymmetricMultiply | ( | word * | R, |
word * | T, | ||
const word * | A, | ||
size_t | NA, | ||
const word * | B, | ||
size_t | NB | ||
) |
Definition at line 2344 of file integer.cpp.
int CRYPTOPP_FASTCALL Baseline_Add | ( | size_t | N, |
word * | C, | ||
const word * | A, | ||
const word * | B | ||
) |
Definition at line 1336 of file integer.cpp.
Definition at line 1202 of file integer.cpp.
Definition at line 1211 of file integer.cpp.
Definition at line 1353 of file integer.cpp.
Definition at line 1244 of file integer.cpp.
Definition at line 1253 of file integer.cpp.
Definition at line 1262 of file integer.cpp.
Definition at line 1362 of file integer.cpp.
Definition at line 1303 of file integer.cpp.
Definition at line 1317 of file integer.cpp.
Definition at line 1345 of file integer.cpp.
Definition at line 1220 of file integer.cpp.
Definition at line 1228 of file integer.cpp.
Definition at line 1236 of file integer.cpp.
int CRYPTOPP_FASTCALL Baseline_Sub | ( | size_t | N, |
word * | C, | ||
const word * | A, | ||
const word * | B | ||
) |
Definition at line 2692 of file integer.cpp.
Definition at line 2835 of file integer.cpp.
|
inline |
Definition at line 457 of file integer.cpp.
CRYPTOPP_DLL std::string IntToString< Integer > | ( | Integer | value, |
unsigned int | base | ||
) |
Converts an Integer to a string.
value | the Integer to convert |
base | the base to use during the conversion |
This is a template specialization of IntToString(). Use it like IntToString():
// Print integer in base 10 Integer n... std::string s = IntToString(n, 10);
The string is presented with lowercase letters by default. A hack is available to switch to uppercase letters without modifying the function signature.
// Print integer in base 16, uppercase letters Integer n... const unsigned int UPPER = (1 << 31); std::string s = IntToString(n, (UPPER | 16));
Definition at line 4648 of file integer.cpp.
CRYPTOPP_DLL std::string IntToString< word64 > | ( | word64 | value, |
unsigned int | base | ||
) |
Converts an unsigned value to a string.
value | the value to convert |
base | the base to use during the conversion |
this template function specialization was added to suppress Coverity findings on IntToString() with unsigned types.
Definition at line 4714 of file integer.cpp.
Definition at line 2446 of file integer.cpp.
Definition at line 2324 of file integer.cpp.
Definition at line 2334 of file integer.cpp.
Definition at line 2856 of file integer.cpp.
Definition at line 2275 of file integer.cpp.
std::ostream& operator<< | ( | std::ostream & | out, |
const Integer & | a | ||
) |
out | a reference to a std::ostream |
a | a constant reference to an Integer |
The output integer responds to std::hex, std::oct, std::hex, std::upper and std::lower. The output includes the suffix h (for hex), . (dot, for dec) and o (for octal). There is currently no way to suppress the suffix.
If you want to print an Integer without the suffix or using an arbitrary base, then use IntToString<Integer>().
Definition at line 3629 of file integer.cpp.
std::istream& operator>> | ( | std::istream & | in, |
Integer & | a | ||
) |
in | a reference to a std::istream |
a | a reference to an Integer |
Definition at line 3604 of file integer.cpp.
Definition at line 2413 of file integer.cpp.
Definition at line 2184 of file integer.cpp.
Definition at line 2251 of file integer.cpp.
Definition at line 2226 of file integer.cpp.
Definition at line 2329 of file integer.cpp.
Definition at line 2152 of file integer.cpp.