58 const std::vector<uint8_t>& seed_c,
60 if(!fips186_3_valid_size(pbits, qbits)) {
61 throw Invalid_Argument(
fmt(
"FIPS 186-3 does not allow DSA domain parameters of {}/{} bits long", pbits, qbits));
64 if(seed_c.size() * 8 < qbits) {
66 fmt(
"Generating a DSA parameter set with a {} bit long q requires a seed at least as many bits long", qbits));
69 const std::string hash_name = hash_function_for(qbits);
72 const size_t HASH_SIZE = hash->output_length();
76 explicit Seed(
const std::vector<uint8_t>& s) : m_seed(s) {}
78 const std::vector<uint8_t>& value()
const {
return m_seed; }
81 for(
size_t j = m_seed.size(); j > 0; --j) {
90 std::vector<uint8_t> m_seed;
103 const size_t n = (pbits - 1) / (HASH_SIZE * 8),
b = (pbits - 1) % (HASH_SIZE * 8);
106 std::vector<uint8_t> V(HASH_SIZE * (n + 1));
110 for(
size_t j = 0; j != 4 * pbits; ++j) {
111 for(
size_t k = 0; k <= n; ++k) {
113 hash->update(seed.value());
114 hash->final(&V[HASH_SIZE * (n - k)]);
118 X._assign_from_bytes(std::span{V}.subspan(HASH_SIZE - 1 -
b / 8));
119 X.set_bit(pbits - 1);
bool generate_dsa_primes(RandomNumberGenerator &rng, BigInt &p, BigInt &q, size_t pbits, size_t qbits, const std::vector< uint8_t > &seed_c, size_t offset)