2021-05-04 03:39:43 -04:00
|
|
|
package dh
|
|
|
|
|
2021-07-03 03:58:06 -04:00
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
)
|
|
|
|
|
2021-05-04 03:39:43 -04:00
|
|
|
const (
|
|
|
|
// QSizeMinimum Specifies the number of the most significant bit (0 to M).
|
|
|
|
// WARNING: internally, usually 1 to N.
|
|
|
|
QSizeMinimum = 511
|
|
|
|
|
|
|
|
// Prime sieving constants
|
|
|
|
// Assuming 8 bit bytes and 32 bit words.
|
2021-07-03 03:58:06 -04:00
|
|
|
ShiftBit = 3
|
|
|
|
ShiftByte = 2
|
|
|
|
ShiftWord = ShiftBit + ShiftByte
|
2021-05-04 03:39:43 -04:00
|
|
|
ShiftMegabyte = 20
|
|
|
|
ShiftMegaWord = ShiftMegabyte - ShiftBit
|
|
|
|
|
|
|
|
// Memory limits.
|
|
|
|
// LargeMinimum is 8 megabytes
|
|
|
|
LargeMinimum = uint32(8) // Originally an 8UL in moduli.c
|
|
|
|
// LargeMaximum is 127MB.
|
|
|
|
LargeMaximum = uint32(127)
|
|
|
|
// The largest sieve prime has to be < 2**32 on 32-bit systems.
|
|
|
|
SmallMaximum = uint32(0xffffffff) // 4294967295
|
|
|
|
// Can sieve all primes less than 2**32, as 65537**2 > 2**32-1.
|
|
|
|
TinyNumber = uint32(1) << 16
|
|
|
|
// Ensure enough bit space for testing 2*q.
|
|
|
|
TestMaximum = uint32(1) << 16
|
|
|
|
TestMinimum = QSizeMinimum + 1 // (uint32(1) << (ShiftWord - TestPower))
|
2021-07-03 03:58:06 -04:00
|
|
|
TestPower = 3 // 2**n, n < ShiftWord
|
|
|
|
// Minimum number of primality tests to perform
|
|
|
|
TrialMinimum = 4
|
2021-05-04 03:39:43 -04:00
|
|
|
)
|
|
|
|
|
2021-07-03 03:58:06 -04:00
|
|
|
type (
|
|
|
|
|
|
|
|
/*
|
|
|
|
Sieving data (XXX - move to struct)
|
|
|
|
*/
|
|
|
|
|
|
|
|
// sieve 2**16
|
|
|
|
TinySieve *uint32
|
|
|
|
tinybits uint32
|
|
|
|
|
|
|
|
// sieve 2**30 in 2**16 parts
|
|
|
|
SmallSieve *uint32
|
|
|
|
smallbits uint32
|
|
|
|
smallbase uint32
|
|
|
|
|
|
|
|
// sieve relative to the initial value
|
|
|
|
LargeSieve *uint32
|
|
|
|
largewords uint32
|
|
|
|
largetries uint32
|
|
|
|
largenumbers uint32
|
|
|
|
largebits uint32 // Megabytes..
|
|
|
|
largememory uint32 // ""
|
|
|
|
|
|
|
|
largebase big.Int
|
2021-05-04 03:39:43 -04:00
|
|
|
)
|