-
Notifications
You must be signed in to change notification settings - Fork 41
/
prime.h
89 lines (56 loc) · 1.51 KB
/
prime.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* prime.h
*
* Created on: 03.05.2014
* Author: mad
*/
#ifndef PRIME_H_
#define PRIME_H_
#include <gmp.h>
#include <gmpxx.h>
#include "uint256.h"
extern const unsigned int nFractionalBits;
extern unsigned int nTargetInitialLength;
extern unsigned int nTargetMinLength;
enum // prime chain type
{
PRIME_CHAIN_CUNNINGHAM1 = 1u,
PRIME_CHAIN_CUNNINGHAM2 = 2u,
PRIME_CHAIN_BI_TWIN = 3u,
};
class CPrimalityTestParams
{
public:
// GMP C++ variables
mpz_class mpzHashFixedMult;
mpz_class mpzChainOrigin;
mpz_class mpzOriginMinusOne;
mpz_class mpzOriginPlusOne;
mpz_class mpzN;
mpz_class mpzNMinusOne;
mpz_class mpzBase;
mpz_class mpzR;
mpz_class mpzR2;
mpz_class mpzE;
mpz_class mpzFrac;
// Values specific to a round
unsigned int nBits;
unsigned int nCandidateType;
// Results
unsigned int nChainLength;
CPrimalityTestParams()
{
nBits = 0;
nCandidateType = 0;
nChainLength = 0;
}
};
unsigned int TargetGetLength(unsigned int nBits);
unsigned int TargetGetFractional(unsigned int nBits);
std::string TargetToString(unsigned int nBits);
inline void mpz_set_uint256(mpz_t r, uint256& u)
{
mpz_import(r, 32 / sizeof(unsigned long), -1, sizeof(unsigned long), -1, 0, &u);
}
bool ProbablePrimeChainTestFast(const mpz_class& mpzPrimeChainOrigin, CPrimalityTestParams& testParams);
#endif /* PRIME_H_ */