8 #include <botan/dl_group.h>
9 #include <botan/libstate.h>
10 #include <botan/parsing.h>
11 #include <botan/numthry.h>
12 #include <botan/der_enc.h>
13 #include <botan/ber_dec.h>
14 #include <botan/pipe.h>
15 #include <botan/pem.h>
16 #include <botan/internal/workfactor.h>
17 #include <botan/internal/assert.h>
36 if(grp_contents ==
"")
47 PrimeType type,
size_t pbits,
size_t qbits)
69 p = X - (X % (2*q) - 1);
72 g = make_dsa_generator(p, q);
76 qbits = qbits ? qbits : ((pbits <= 1024) ? 160 : 256);
83 g = make_dsa_generator(p, q);
97 p, q, pbits, qbits, seed))
99 "generate a DSA group");
101 g = make_dsa_generator(p, q);
111 initialize(p1, 0, g1);
119 initialize(p1, q1, g1);
129 if(g1 < 2 || g1 >= p1)
131 if(q1 < 0 || q1 >= p1)
144 void DL_Group::init_check()
const
147 throw Invalid_State(
"DLP group cannot be used uninitialized");
158 if(g < 2 || p < 3 || q < 0)
160 if((q != 0) && ((p - 1) % q != 0))
209 if((q == 0) && (format !=
PKCS_3))
210 throw Encoding_Error(
"The ANSI DL parameter formats require a subgroup");
266 BigInt new_p, new_q, new_g;
294 initialize(new_p, new_q, new_g);
305 if(label ==
"DH PARAMETERS")
307 else if(label ==
"DSA PARAMETERS")
309 else if(label ==
"X942 DH PARAMETERS")
320 BigInt g, e = (p - 1) / q;
322 BOTAN_ASSERT(e > 0,
"q does not divide p, invalid group");
331 throw Internal_Error(
"DL_Group: Couldn't create a suitable generator");
const size_t PRIME_TABLE_SIZE
SecureVector< byte > get_contents()
std::string PEM_encode(Format format) const
BER_Decoder & decode(bool &)
void PEM_decode(DataSource &src)
bool verify_group(RandomNumberGenerator &rng, bool strong) const
const BigInt & get_q() const
std::invalid_argument Invalid_Argument
const BigInt & get_p() const
void BER_decode(DataSource &src, Format format)
BER_Decoder start_cons(ASN1_Tag, ASN1_Tag=UNIVERSAL)
#define BOTAN_ASSERT(expr, msg)
SecureVector< byte > decode(DataSource &source, std::string &label)
DER_Encoder & encode(bool b)
RandomNumberGenerator * rng
void randomize(RandomNumberGenerator &rng, size_t bitsize=0)
const BigInt & get_g() const
Library_State & global_state()
SecureVector< byte > DER_encode(Format format) const
BER_Decoder & discard_remaining()
BigInt random_safe_prime(RandomNumberGenerator &rng, size_t bits)
std::string encode(const byte der[], size_t length, const std::string &label, size_t width)
BER_Decoder & verify_end()
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
std::string to_string(u64bit n, size_t min_len)
size_t dl_work_factor(size_t bits)
const u16bit BOTAN_DLL PRIMES[]
bool generate_dsa_primes(RandomNumberGenerator &rng, Algorithm_Factory &af, BigInt &p, BigInt &q, size_t pbits, size_t qbits, const MemoryRegion< byte > &seed_c)
std::string get(const std::string §ion, const std::string &key) const
BigInt random_prime(RandomNumberGenerator &rng, size_t bits, const BigInt &coprime, size_t equiv, size_t modulo)
bool check_prime(const BigInt &n, RandomNumberGenerator &rng)