HC-128 Cipher Generator¶
-
class randomgen.hc128.HC128(seed=
None, *, key=None)¶ 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, a new SeedSequence is created using entropy from the operating system.- 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.
- seed=
- lock¶
Lock instance that is shared so that the same bit 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 seed the generator. If seed is not a SeedSequence, one is created from it.
- 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.
HC128is the fastest software-only encryption-quality bit generator, and about 50% as fast asAESCounterwhen used with AESNI.HC128provides 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 aGeneratoror similar object that supports low-level access.See
AESCounterandChaChafor related PRNGs that uses a block cipher rather than a stream cipher.State and Seeding
The
HC128state 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.HC128is 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 to a SeedSequence, and the output of the SeedSequence is used as the initial state. Alternatively, the key can be set directly using a 256-bit integer.Parallel Features
HC128can 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
HC128makes 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 # randomReferences
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 |