8#include <botan/numthry.h>
10#include <botan/reducer.h>
20bool fips186_3_valid_size(
size_t pbits,
size_t qbits)
23 return (pbits == 1024);
26 return (pbits == 2048);
29 return (pbits == 2048 || pbits == 3072);
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 " +
50 if(seed_c.size() * 8 < qbits)
53 " bit long q requires a seed at least as many bits long");
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));
124 size_t pbits,
size_t qbits)
128 std::vector<uint8_t> seed(qbits / 8);
void binary_decode(const uint8_t buf[], size_t length)
static std::unique_ptr< HashFunction > create_or_throw(const std::string &algo_spec, const std::string &provider="")
BigInt reduce(const BigInt &x) const
virtual void randomize(uint8_t output[], size_t length)=0
int(* final)(unsigned char *, CTX *)
std::string to_string(const BER_Object &obj)
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
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)