41 size_t pbits,
size_t qbits,
42 const std::vector<uint8_t>& seed_c,
45 if(!fips186_3_valid_size(pbits, qbits))
47 "FIPS 186-3 does not allow DSA domain parameters of " +
48 std::to_string(pbits) +
"/" + std::to_string(qbits) +
" bits long");
50 if(seed_c.size() * 8 < qbits)
52 "Generating a DSA parameter set with a " + std::to_string(qbits) +
53 " bit long q requires a seed at least as many bits long");
55 const std::string hash_name =
"SHA-" + std::to_string(qbits);
58 const size_t HASH_SIZE =
hash->output_length();
63 explicit Seed(
const std::vector<uint8_t>& s) : m_seed(s) {}
65 const std::vector<uint8_t>& value()
const {
return m_seed; }
69 for(
size_t j = m_seed.size(); j > 0; --j)
75 std::vector<uint8_t> m_seed;
87 const size_t n = (pbits-1) / (HASH_SIZE * 8),
88 b = (pbits-1) % (HASH_SIZE * 8);
91 std::vector<uint8_t> V(HASH_SIZE * (n+1));
95 for(
size_t j = 0; j != 4*pbits; ++j)
97 for(
size_t k = 0; k <= n; ++k)
100 hash->update(seed.value());
101 hash->final(&V[HASH_SIZE * (n-k)]);
106 X.binary_decode(&V[HASH_SIZE - 1 - b/8],
107 V.size() - (HASH_SIZE - 1 - b/8));
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)