|
RandX 1.4.3
基于 xoshiro/xoroshiro 算法族的纯头文件伪随机数生成器库
|
ChaCha20 密码学安全伪随机数生成器(CSPRNG),64 位输出,符合 RFC 8439。 更多...
#include <RandX.hpp>
Public 类型 | |
| using | result_type = std::uint64_t |
| 输出类型 | |
| using | result_type = std::uint64_t |
| 输出类型 | |
Public 成员函数 | |
| ChaCha20 (const ChaCha20 &)=delete | |
| ChaCha20 & | operator= (const ChaCha20 &)=delete |
| ChaCha20 (ChaCha20 &&other) noexcept | |
| ChaCha20 & | operator= (ChaCha20 &&other) noexcept |
| ~ChaCha20 () noexcept | |
| ChaCha20 () | |
| 构造方式 1:从 OS 熵自动播种(密码学安全,默认) | |
| ChaCha20 (std::uint64_t seed) | |
| 构造方式 2:以显式 64 位种子构造 | |
| ChaCha20 (const std::uint8_t *key, std::size_t keyLen, const std::uint8_t *nonce, std::size_t nonceLen, std::uint32_t counter=0) | |
| 构造方式 3:直接指定 key + nonce + counter(高级用法/测试复现) | |
| result_type | operator() () |
| 生成下一个 64 位随机数 | |
| void | discard (unsigned long long n) |
| 跳过 n 个输出 | |
| void | reseed () |
| 从 OS 熵重新播种 | |
| ChaCha20 (const ChaCha20 &)=delete | |
| ChaCha20 & | operator= (const ChaCha20 &)=delete |
| ChaCha20 (ChaCha20 &&other) noexcept | |
| ChaCha20 & | operator= (ChaCha20 &&other) noexcept |
| ~ChaCha20 () noexcept | |
| ChaCha20 () | |
| 构造方式 1:从 OS 熵自动播种(密码学安全,默认) | |
| RANDX_NODISCARD_CXX20 | ChaCha20 (std::uint64_t seed) |
| 构造方式 2:以显式 64 位种子构造 | |
| ChaCha20 (const std::uint8_t *key, std::size_t keyLen, const std::uint8_t *nonce, std::size_t nonceLen, std::uint32_t counter=0) | |
| 构造方式 3:直接指定 key + nonce + counter(高级用法/测试复现) | |
| result_type | operator() () |
| 生成下一个 64 位随机数 | |
| void | discard (unsigned long long n) |
| 跳过 n 个输出 | |
| void | reseed () |
| 从 OS 熵重新播种 | |
静态 Public 成员函数 | |
| static constexpr result_type | min () noexcept |
| 输出范围下界 | |
| static constexpr result_type | max () noexcept |
| 输出范围上界 | |
| static RANDX_NODISCARD_CXX20 constexpr result_type | min () noexcept |
| 输出范围下界 | |
| static RANDX_NODISCARD_CXX20 constexpr result_type | max () noexcept |
| 输出范围上界 | |
ChaCha20 密码学安全伪随机数生成器(CSPRNG),64 位输出,符合 RFC 8439。
状态为 key(256-bit) + counter(32-bit) + nonce(96-bit)。 每次 operator() 返回 8 字节,一个 block 服务 8 次调用。 默认从 OS 熵自动播种,并在输出 2^20 字节后自动 reseed 以提供前向安全。 满足 std::uniform_random_bit_generator 概念。
| using RandX::ChaCha20::result_type = std::uint64_t |
输出类型
|
delete |

|
noexcept |

|
noexcept |
| RandX::ChaCha20::ChaCha20 | ( | ) |
构造方式 1:从 OS 熵自动播种(密码学安全,默认)

|
explicit |
构造方式 2:以显式 64 位种子构造
| seed | 64 位种子值 |

| RandX::ChaCha20::ChaCha20 | ( | const std::uint8_t * | key, |
| std::size_t | keyLen, | ||
| const std::uint8_t * | nonce, | ||
| std::size_t | nonceLen, | ||
| std::uint32_t | counter = 0 ) |
构造方式 3:直接指定 key + nonce + counter(高级用法/测试复现)
| key | 密钥指针,须为 32 字节 |
| keyLen | 密钥长度(字节),须为 32,否则抛出 std::invalid_argument |
| nonce | 随机数指针,须为 12 字节 |
| nonceLen | 随机数长度(字节),须为 12,否则抛出 std::invalid_argument |
| counter | 32-bit block 计数器初值(默认 0;KAT 测试时显式传 1) |

| void RandX::ChaCha20::discard | ( | unsigned long long | n | ) |
跳过 n 个输出
| n | 跳过次数 |

|
inlinestaticconstexprnoexcept |
输出范围上界
|
inlinestaticconstexprnoexcept |
输出范围下界

| result_type RandX::ChaCha20::operator() | ( | ) |
| void RandX::ChaCha20::reseed | ( | ) |
从 OS 熵重新播种
