HC-128 Cipher Generator¶
-
class randomgen.hc128.HC128(seed=
None
, *, key=None
, mode='sequence'
)¶ Container for the HC-128 cipher-based pseudo-random number generator
- Parameters:¶
- seed=
None
¶ Random seed initializing the pseudo-random number generator. Can be an integer in [0, 2**64), array of integers in [0, 2**64), a SeedSequence instance or
None
(the default). If seed isNone
, then data is read from/dev/urandom
(or the Windows analog) if available. If unavailable, a hash of the time and process ID is used.- key=
None
¶ Key for HC128. The key is a 256-bit integer that contains both the key (lower 128 bits) and initial values (upper 128-bits) for the HC-128 cipher. key and seed cannot both be used.
- mode=
'sequence'
¶ Deprecated parameter. Do not use.
- seed=
- lock¶
Lock instance that is shared so that the same bit git generator can be used in multiple Generators without corrupting the state. Code that generates values from a bit generator should hold the bit generator’s lock.
- Type:¶
- seed_seq¶
The SeedSequence instance used to initialize the generator if mode is “sequence” or is seed is a SeedSequence.
- Type:¶
{None, SeedSequence}
Notes
HC-128 was developer by Hongjun Wu and is an eSTREAM finalist ([1], [2]). It is a cryptographic quality random number generator that produces a keystream is suitable for encryption. The average cycle length is expected to be 2**(1024*32+10-1) = 2**32777.
HC128
is the fastest software-only encryption-quality bit generator, and about 50% as fast asAESCounter
when used with AESNI.HC128
provides a capsule containing function pointers that produce doubles, and unsigned 32 and 64- bit integers. These are not directly consumable in Python and must be consumed by aGenerator
or similar object that supports low-level access.See
AESCounter
andChaCha
for related PRNGs that uses a block cipher rather than a stream cipher.State and Seeding
The
HC128
state vector consists of a 2 512-element arrays of 32-bit unsigned integers (p and q) and an integer in [0, 1024). In addition, the state contains a 16-element array that buffers values and a buffer index.HC128
is seeded using either a single 256-bit unsigned integer or a vector of 64-bit unsigned integers. In either case, the seed is used as an input for another simple random number generator, SplitMix64, and the output of this PRNG function is used as the initial state. Alternatively, the key can be set directly using a 256-bit integer.Parallel Features
HC128
can be used in parallel applications by using distinct keys>>> from numpy.random import Generator >>> from randomgen import HC128 >>> rg = [Generator(HC128(key=1234 + i)) for i in range(10)]
Compatibility Guarantee
HC128
makes a guarantee that a fixed seed will always produce the same random integer stream.Examples
>>> from numpy.random import Generator >>> from randomgen import HC128 >>> rg = Generator(HC128(1234)) >>> rg.standard_normal() 0.123 # random
References
Seeding and State¶
|
Seed the generator |
Get or set the PRNG state |
Extending¶
CFFI interface |
|
ctypes interface |
Testing¶
|
Return randoms as generated by the underlying BitGenerator |