Botan 3.7.1
Crypto and TLS for C&
dl_group.cpp
Go to the documentation of this file.
1/*
2* Discrete Logarithm Parameters
3* (C) 1999-2008,2015,2018 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/dl_group.h>
9
10#include <botan/ber_dec.h>
11#include <botan/der_enc.h>
12#include <botan/numthry.h>
13#include <botan/pem.h>
14#include <botan/reducer.h>
15#include <botan/internal/divide.h>
16#include <botan/internal/fmt.h>
17#include <botan/internal/mod_inv.h>
18#include <botan/internal/monty.h>
19#include <botan/internal/monty_exp.h>
20#include <botan/internal/primality.h>
21#include <botan/internal/workfactor.h>
22#include <string_view>
23
24namespace Botan {
25
26class DL_Group_Data final {
27 public:
28 DL_Group_Data(const BigInt& p, const BigInt& q, const BigInt& g, DL_Group_Source source) :
29 m_p(p),
30 m_q(q),
31 m_g(g),
32 m_mod_p(Modular_Reducer::for_public_modulus(p)),
33 m_mod_q(Modular_Reducer::for_public_modulus(q)),
34 m_monty_params(std::make_shared<Montgomery_Params>(m_p, m_mod_p)),
35 m_monty(monty_precompute(m_monty_params, m_g, /*window bits=*/4)),
36 m_p_bits(p.bits()),
37 m_q_bits(q.bits()),
38 m_estimated_strength(dl_work_factor(m_p_bits)),
39 m_exponent_bits(dl_exponent_size(m_p_bits)),
40 m_source(source) {}
41
42 DL_Group_Data(const BigInt& p, const BigInt& g, DL_Group_Source source) :
43 m_p(p),
44 m_g(g),
45 m_mod_p(Modular_Reducer::for_public_modulus(p)),
46 m_monty_params(std::make_shared<Montgomery_Params>(m_p, m_mod_p)),
47 m_monty(monty_precompute(m_monty_params, m_g, /*window bits=*/4)),
48 m_p_bits(p.bits()),
49 m_q_bits(0),
50 m_estimated_strength(dl_work_factor(m_p_bits)),
51 m_exponent_bits(dl_exponent_size(m_p_bits)),
52 m_source(source) {}
53
54 ~DL_Group_Data() = default;
55
56 DL_Group_Data(const DL_Group_Data& other) = delete;
57 DL_Group_Data(DL_Group_Data&& other) = delete;
58 DL_Group_Data& operator=(const DL_Group_Data& other) = delete;
59 DL_Group_Data& operator=(DL_Group_Data&& other) = delete;
60
61 const BigInt& p() const { return m_p; }
62
63 const BigInt& q() const { return m_q; }
64
65 const BigInt& g() const { return m_g; }
66
67 const Modular_Reducer& reducer_mod_p() const { return m_mod_p; }
68
69 const Modular_Reducer& reducer_mod_q() const {
70 BOTAN_STATE_CHECK(m_mod_q);
71 return *m_mod_q;
72 }
73
74 std::shared_ptr<const Montgomery_Params> monty_params_p() const { return m_monty_params; }
75
76 size_t p_bits() const { return m_p_bits; }
77
78 size_t q_bits() const { return m_q_bits; }
79
80 size_t p_bytes() const { return (m_p_bits + 7) / 8; }
81
82 size_t q_bytes() const { return (m_q_bits + 7) / 8; }
83
84 size_t estimated_strength() const { return m_estimated_strength; }
85
86 size_t exponent_bits() const { return m_exponent_bits; }
87
88 BigInt power_g_p(const BigInt& k, size_t max_k_bits) const {
89 return monty_execute(*m_monty, k, max_k_bits).value();
90 }
91
92 BigInt power_g_p_vartime(const BigInt& k) const { return monty_execute_vartime(*m_monty, k).value(); }
93
94 BigInt power_b_p(const BigInt& b, const BigInt& k, size_t max_k_bits) const {
95 return monty_exp(m_monty_params, b, k, max_k_bits).value();
96 }
97
98 BigInt power_b_p_vartime(const BigInt& b, const BigInt& k) const {
99 return monty_exp_vartime(m_monty_params, b, k).value();
100 }
101
102 bool q_is_set() const { return m_q_bits > 0; }
103
104 void assert_q_is_set(std::string_view function) const {
105 if(q_is_set() == false) {
106 throw Invalid_State(fmt("DL_Group::{}: q is not set for this group", function));
107 }
108 }
109
110 DL_Group_Source source() const { return m_source; }
111
112 private:
113 BigInt m_p;
114 BigInt m_q; // zero if no q set
115 BigInt m_g;
116 Modular_Reducer m_mod_p;
117 std::optional<Modular_Reducer> m_mod_q;
118 std::shared_ptr<const Montgomery_Params> m_monty_params;
119 std::shared_ptr<const Montgomery_Exponentation_State> m_monty;
120 size_t m_p_bits;
121 size_t m_q_bits;
122 size_t m_estimated_strength;
123 size_t m_exponent_bits;
124 DL_Group_Source m_source;
125};
126
127//static
128std::shared_ptr<DL_Group_Data> DL_Group::BER_decode_DL_group(const uint8_t data[],
129 size_t data_len,
130 DL_Group_Format format,
131 DL_Group_Source source) {
132 BER_Decoder decoder(data, data_len);
133 BER_Decoder ber = decoder.start_sequence();
134
135 if(format == DL_Group_Format::ANSI_X9_57) {
136 BigInt p, q, g;
137 ber.decode(p).decode(q).decode(g).verify_end();
138 return std::make_shared<DL_Group_Data>(p, q, g, source);
139 } else if(format == DL_Group_Format::ANSI_X9_42) {
140 BigInt p, g, q;
141 ber.decode(p).decode(g).decode(q).discard_remaining();
142 return std::make_shared<DL_Group_Data>(p, q, g, source);
143 } else if(format == DL_Group_Format::PKCS_3) {
144 BigInt p, g;
145 ber.decode(p).decode(g).discard_remaining();
146 return std::make_shared<DL_Group_Data>(p, g, source);
147 } else {
148 throw Invalid_Argument("Unknown DL_Group encoding");
149 }
150}
151
152//static
153std::shared_ptr<DL_Group_Data> DL_Group::load_DL_group_info(const char* p_str, const char* q_str, const char* g_str) {
154 const BigInt p(p_str);
155 const BigInt q(q_str);
156 const BigInt g(g_str);
157
158 if(q.is_zero()) {
159 return std::make_shared<DL_Group_Data>(p, g, DL_Group_Source::Builtin);
160 } else {
161 return std::make_shared<DL_Group_Data>(p, q, g, DL_Group_Source::Builtin);
162 }
163}
164
165//static
166std::shared_ptr<DL_Group_Data> DL_Group::load_DL_group_info(const char* p_str, const char* g_str) {
167 const BigInt p(p_str);
168 const BigInt q = (p - 1) / 2;
169 const BigInt g(g_str);
170
171 return std::make_shared<DL_Group_Data>(p, q, g, DL_Group_Source::Builtin);
172}
173
174namespace {
175
176DL_Group_Format pem_label_to_dl_format(std::string_view label) {
177 if(label == "DH PARAMETERS") {
179 } else if(label == "DSA PARAMETERS") {
181 } else if(label == "X942 DH PARAMETERS" || label == "X9.42 DH PARAMETERS") {
183 } else {
184 throw Decoding_Error(fmt("DL_Group: Unknown PEM label '{}'", label));
185 }
186}
187
188} // namespace
189
190/*
191* DL_Group Constructor
192*/
193DL_Group::DL_Group(std::string_view str) {
194 // Either a name or a PEM block, try name first
195 m_data = DL_group_info(str);
196
197 if(m_data == nullptr) {
198 try {
199 std::string label;
200 const std::vector<uint8_t> ber = unlock(PEM_Code::decode(str, label));
201 DL_Group_Format format = pem_label_to_dl_format(label);
202
203 m_data = BER_decode_DL_group(ber.data(), ber.size(), format, DL_Group_Source::ExternalSource);
204 } catch(...) {}
205 }
206
207 if(m_data == nullptr) {
208 throw Invalid_Argument(fmt("DL_Group: Unknown group '{}'", str));
209 }
210}
211
213 auto data = DL_group_info(name);
214
215 if(!data) {
216 throw Invalid_Argument(fmt("DL_Group: Unknown group '{}'", name));
217 }
218
219 return DL_Group(data);
220}
221
222//static
223DL_Group DL_Group::from_PEM(std::string_view pem) {
224 std::string label;
225 const std::vector<uint8_t> ber = unlock(PEM_Code::decode(pem, label));
226 DL_Group_Format format = pem_label_to_dl_format(label);
227 return DL_Group(ber, format);
228}
229
230namespace {
231
232/*
233* Create generator of the q-sized subgroup (DSA style generator)
234*/
235BigInt make_dsa_generator(const BigInt& p, const BigInt& q) {
236 BigInt e, r;
237 vartime_divide(p - 1, q, e, r);
238
239 if(e == 0 || r > 0) {
240 throw Invalid_Argument("make_dsa_generator q does not divide p-1");
241 }
242
243 for(size_t i = 0; i != PRIME_TABLE_SIZE; ++i) {
244 // TODO precompute!
245 BigInt g = power_mod(BigInt::from_word(PRIMES[i]), e, p);
246 if(g > 1) {
247 return g;
248 }
249 }
250
251 throw Internal_Error("DL_Group: Couldn't create a suitable generator");
252}
253
254} // namespace
255
256/*
257* DL_Group Constructor
258*/
259DL_Group::DL_Group(RandomNumberGenerator& rng, PrimeType type, size_t pbits, size_t qbits) {
260 if(pbits < 1024) {
261 throw Invalid_Argument(fmt("DL_Group: requested prime size {} is too small", pbits));
262 }
263
264 if(qbits >= pbits) {
265 throw Invalid_Argument(fmt("DL_Group: requested q size {} is too big for p {}", qbits, pbits));
266 }
267
268 if(type == Strong) {
269 if(qbits != 0 && qbits != pbits - 1) {
270 throw Invalid_Argument("Cannot create strong-prime DL_Group with specified q bits");
271 }
272
273 const BigInt p = random_safe_prime(rng, pbits);
274 const BigInt q = (p - 1) / 2;
275
276 /*
277 Always choose a generator that is quadratic reside mod p,
278 this forces g to be a generator of the subgroup of size q.
279 */
281 if(jacobi(g, p) != 1) {
282 // prime table does not contain 2
283 for(size_t i = 0; i < PRIME_TABLE_SIZE; ++i) {
285 if(jacobi(g, p) == 1) {
286 break;
287 }
288 }
289 }
290
291 m_data = std::make_shared<DL_Group_Data>(p, q, g, DL_Group_Source::RandomlyGenerated);
292 } else if(type == Prime_Subgroup) {
293 if(qbits == 0) {
294 qbits = dl_exponent_size(pbits);
295 }
296
297 const BigInt q = random_prime(rng, qbits);
298 auto mod_2q = Modular_Reducer::for_public_modulus(2 * q);
299 BigInt X;
300 BigInt p;
301 while(p.bits() != pbits || !is_prime(p, rng, 128, true)) {
302 X.randomize(rng, pbits);
303 p = X - mod_2q.reduce(X) + 1;
304 }
305
306 const BigInt g = make_dsa_generator(p, q);
307 m_data = std::make_shared<DL_Group_Data>(p, q, g, DL_Group_Source::RandomlyGenerated);
308 } else if(type == DSA_Kosherizer) {
309 if(qbits == 0) {
310 qbits = ((pbits <= 1024) ? 160 : 256);
311 }
312
313 BigInt p, q;
314 generate_dsa_primes(rng, p, q, pbits, qbits);
315 const BigInt g = make_dsa_generator(p, q);
316 m_data = std::make_shared<DL_Group_Data>(p, q, g, DL_Group_Source::RandomlyGenerated);
317 } else {
318 throw Invalid_Argument("DL_Group unknown PrimeType");
319 }
320}
321
322/*
323* DL_Group Constructor
324*/
325DL_Group::DL_Group(RandomNumberGenerator& rng, const std::vector<uint8_t>& seed, size_t pbits, size_t qbits) {
326 BigInt p, q;
327
328 if(!generate_dsa_primes(rng, p, q, pbits, qbits, seed)) {
329 throw Invalid_Argument("DL_Group: The seed given does not generate a DSA group");
330 }
331
332 BigInt g = make_dsa_generator(p, q);
333
334 m_data = std::make_shared<DL_Group_Data>(p, q, g, DL_Group_Source::RandomlyGenerated);
335}
336
337/*
338* DL_Group Constructor
339*/
340DL_Group::DL_Group(const BigInt& p, const BigInt& g) {
341 m_data = std::make_shared<DL_Group_Data>(p, g, DL_Group_Source::ExternalSource);
342}
343
344/*
345* DL_Group Constructor
346*/
347DL_Group::DL_Group(const BigInt& p, const BigInt& q, const BigInt& g) {
348 if(q.is_zero()) {
349 m_data = std::make_shared<DL_Group_Data>(p, g, DL_Group_Source::ExternalSource);
350 } else {
351 m_data = std::make_shared<DL_Group_Data>(p, q, g, DL_Group_Source::ExternalSource);
352 }
353}
354
355const DL_Group_Data& DL_Group::data() const {
356 if(m_data) {
357 return *m_data;
358 }
359
360 throw Invalid_State("DL_Group uninitialized");
361}
362
364 const BigInt& p = get_p();
365 const BigInt& q = get_q();
366
367 if(y <= 1 || y >= p) {
368 return false;
369 }
370
371 if(q.is_zero() == false) {
372 if(data().power_b_p_vartime(y, q) != 1) {
373 return false;
374 }
375 }
376
377 return true;
378}
379
381 const BigInt& p = get_p();
382 const BigInt& q = get_q();
383
384 if(x <= 1 || x >= p) {
385 return false;
386 }
387
388 if(q > 0 && x > q) {
389 return false;
390 }
391
392 return true;
393}
394
395bool DL_Group::verify_element_pair(const BigInt& y, const BigInt& x) const {
396 const BigInt& p = get_p();
397
398 if(y <= 1 || y >= p || x <= 1 || x >= p) {
399 return false;
400 }
401
402 if(y != this->power_g_p(x, x.bits())) {
403 return false;
404 }
405
406 return true;
407}
408
409/*
410* Verify the parameters
411*/
412bool DL_Group::verify_group(RandomNumberGenerator& rng, bool strong) const {
413 const bool from_builtin = (source() == DL_Group_Source::Builtin);
414
415 if(!strong && from_builtin) {
416 return true;
417 }
418
419 const BigInt& p = get_p();
420 const BigInt& q = get_q();
421 const BigInt& g = get_g();
422
423 if(g < 2 || p < 3 || q < 0) {
424 return false;
425 }
426
427 const size_t test_prob = 128;
428 const bool is_randomly_generated = (source() != DL_Group_Source::ExternalSource);
429
430 if(!is_prime(p, rng, test_prob, is_randomly_generated)) {
431 return false;
432 }
433
434 if(q != 0) {
435 if((p - 1) % q != 0) {
436 return false;
437 }
438 if(data().power_g_p_vartime(q) != 1) {
439 return false;
440 }
441 if(!is_prime(q, rng, test_prob, is_randomly_generated)) {
442 return false;
443 }
444 } else {
445 if(!from_builtin && !is_randomly_generated) {
446 // If we got this p,g from some unknown source, try to verify
447 // that the group order is not too absurdly small.
448
449 const size_t upper_bound = strong ? 1000 : 100;
450
451 for(size_t i = 2; i != upper_bound; ++i) {
452 if(data().power_g_p_vartime(BigInt::from_word(i)) == 1) {
453 return false;
454 }
455 }
456 }
457 }
458
459 return true;
460}
461
462/*
463* Return the prime
464*/
465const BigInt& DL_Group::get_p() const {
466 return data().p();
467}
468
469/*
470* Return the generator
471*/
472const BigInt& DL_Group::get_g() const {
473 return data().g();
474}
475
476/*
477* Return the subgroup
478*/
479const BigInt& DL_Group::get_q() const {
480 return data().q();
481}
482
483std::shared_ptr<const Montgomery_Params> DL_Group::monty_params_p() const {
484 return data().monty_params_p();
485}
486
487bool DL_Group::has_q() const {
488 return data().q_is_set();
489}
490
491size_t DL_Group::p_bits() const {
492 return data().p_bits();
493}
494
495size_t DL_Group::p_bytes() const {
496 return data().p_bytes();
497}
498
499size_t DL_Group::q_bits() const {
500 data().assert_q_is_set("q_bits");
501 return data().q_bits();
502}
503
504size_t DL_Group::q_bytes() const {
505 data().assert_q_is_set("q_bytes");
506 return data().q_bytes();
507}
508
510 return data().estimated_strength();
511}
512
514 return data().exponent_bits();
515}
516
518 // precompute??
519 return inverse_mod_public_prime(x, get_p());
520}
521
523 return data().reducer_mod_p().reduce(x);
524}
525
526BigInt DL_Group::multiply_mod_p(const BigInt& x, const BigInt& y) const {
527 return data().reducer_mod_p().multiply(x, y);
528}
529
531 return data().reducer_mod_p();
532}
533
535 data().assert_q_is_set("inverse_mod_q");
536 // precompute??
537 return inverse_mod_public_prime(x, get_q());
538}
539
541 data().assert_q_is_set("mod_q");
542 return data().reducer_mod_q().reduce(x);
543}
544
545BigInt DL_Group::multiply_mod_q(const BigInt& x, const BigInt& y) const {
546 data().assert_q_is_set("multiply_mod_q");
547 return data().reducer_mod_q().multiply(x, y);
548}
549
550BigInt DL_Group::multiply_mod_q(const BigInt& x, const BigInt& y, const BigInt& z) const {
551 data().assert_q_is_set("multiply_mod_q");
552 return this->multiply_mod_q(this->multiply_mod_q(x, y), z);
553}
554
556 data().assert_q_is_set("square_mod_q");
557 return data().reducer_mod_q().square(x);
558}
559
560BigInt DL_Group::multi_exponentiate(const BigInt& x, const BigInt& y, const BigInt& z) const {
561 return monty_multi_exp(data().monty_params_p(), get_g(), x, y, z).value();
562}
563
564BigInt DL_Group::power_g_p(const BigInt& x, size_t max_x_bits) const {
565 return data().power_g_p(x, max_x_bits);
566}
567
568BigInt DL_Group::power_b_p(const BigInt& b, const BigInt& x) const {
569 return this->power_b_p(b, x, data().p_bits());
570}
571
572BigInt DL_Group::power_b_p(const BigInt& b, const BigInt& x, size_t max_x_bits) const {
573 return data().power_b_p(b, x, max_x_bits);
574}
575
577 return data().source();
578}
579
580/*
581* DER encode the parameters
582*/
583std::vector<uint8_t> DL_Group::DER_encode(DL_Group_Format format) const {
584 if(get_q().is_zero() && (format != DL_Group_Format::PKCS_3)) {
585 throw Encoding_Error("Cannot encode DL_Group in ANSI formats when q param is missing");
586 }
587
588 std::vector<uint8_t> output;
589 DER_Encoder der(output);
590
591 if(format == DL_Group_Format::ANSI_X9_57) {
593 } else if(format == DL_Group_Format::ANSI_X9_42) {
595 } else if(format == DL_Group_Format::PKCS_3) {
597 } else {
598 throw Invalid_Argument("Unknown DL_Group encoding");
599 }
600
601 return output;
602}
603
604/*
605* PEM encode the parameters
606*/
607std::string DL_Group::PEM_encode(DL_Group_Format format) const {
608 const std::vector<uint8_t> encoding = DER_encode(format);
609
610 if(format == DL_Group_Format::PKCS_3) {
611 return PEM_Code::encode(encoding, "DH PARAMETERS");
612 } else if(format == DL_Group_Format::ANSI_X9_57) {
613 return PEM_Code::encode(encoding, "DSA PARAMETERS");
614 } else if(format == DL_Group_Format::ANSI_X9_42) {
615 return PEM_Code::encode(encoding, "X9.42 DH PARAMETERS");
616 } else {
617 throw Invalid_Argument("Unknown DL_Group encoding");
618 }
619}
620
621DL_Group::DL_Group(const uint8_t ber[], size_t ber_len, DL_Group_Format format) {
622 m_data = BER_decode_DL_group(ber, ber_len, format, DL_Group_Source::ExternalSource);
623}
624
625} // namespace Botan
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:41
size_t bits() const
Definition bigint.cpp:295
static BigInt from_word(word n)
Definition bigint.cpp:42
bool is_zero() const
Definition bigint.h:458
DER_Encoder & start_sequence()
Definition der_enc.h:64
DER_Encoder & end_cons()
Definition der_enc.cpp:171
DER_Encoder & encode(bool b)
Definition der_enc.cpp:250
bool verify_private_element(const BigInt &x) const
Definition dl_group.cpp:380
std::vector< uint8_t > DER_encode(DL_Group_Format format) const
Definition dl_group.cpp:583
BigInt power_g_p(const BigInt &x) const
Definition dl_group.h:262
static DL_Group from_PEM(std::string_view pem)
Definition dl_group.cpp:223
BigInt mod_p(const BigInt &x) const
Definition dl_group.cpp:522
BigInt multiply_mod_p(const BigInt &x, const BigInt &y) const
Definition dl_group.cpp:526
std::shared_ptr< const Montgomery_Params > monty_params_p() const
Definition dl_group.cpp:483
size_t p_bits() const
Definition dl_group.cpp:491
std::string PEM_encode(DL_Group_Format format) const
Definition dl_group.cpp:607
const BigInt & get_p() const
Definition dl_group.cpp:465
static DL_Group from_name(std::string_view name)
Definition dl_group.cpp:212
BigInt multi_exponentiate(const BigInt &x, const BigInt &y, const BigInt &z) const
Definition dl_group.cpp:560
bool verify_public_element(const BigInt &y) const
Definition dl_group.cpp:363
BigInt square_mod_q(const BigInt &x) const
Definition dl_group.cpp:555
const Modular_Reducer & _reducer_mod_p() const
Definition dl_group.cpp:530
BigInt inverse_mod_q(const BigInt &x) const
Definition dl_group.cpp:534
size_t p_bytes() const
Definition dl_group.cpp:495
bool verify_element_pair(const BigInt &y, const BigInt &x) const
Definition dl_group.cpp:395
size_t estimated_strength() const
Definition dl_group.cpp:509
size_t q_bytes() const
Definition dl_group.cpp:504
bool has_q() const
Definition dl_group.cpp:487
DL_Group_Source source() const
Definition dl_group.cpp:576
BigInt multiply_mod_q(const BigInt &x, const BigInt &y) const
Definition dl_group.cpp:545
BigInt inverse_mod_p(const BigInt &x) const
Definition dl_group.cpp:517
size_t q_bits() const
Definition dl_group.cpp:499
DL_Group()=default
BigInt power_b_p(const BigInt &b, const BigInt &x, size_t max_x_bits) const
Definition dl_group.cpp:572
size_t exponent_bits() const
Definition dl_group.cpp:513
BigInt mod_q(const BigInt &x) const
Definition dl_group.cpp:540
bool verify_group(RandomNumberGenerator &rng, bool strong=true) const
Definition dl_group.cpp:412
const BigInt & get_g() const
Definition dl_group.cpp:472
static std::shared_ptr< DL_Group_Data > DL_group_info(std::string_view name)
Definition dl_named.cpp:13
const BigInt & get_q() const
Definition dl_group.cpp:479
static Modular_Reducer for_public_modulus(const BigInt &m)
Definition reducer.cpp:43
BigInt value() const
Definition monty.cpp:335
std::string name
int(* final)(unsigned char *, CTX *)
FE_25519 X
Definition ge.cpp:25
std::string encode(const uint8_t der[], size_t length, std::string_view label, size_t width)
Definition pem.cpp:39
secure_vector< uint8_t > decode(DataSource &source, std::string &label)
Definition pem.cpp:62
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition numthry.cpp:284
void vartime_divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition divide.cpp:219
BigInt random_prime(RandomNumberGenerator &rng, size_t bits, const BigInt &coprime, size_t equiv, size_t modulo, size_t prob)
Definition make_prm.cpp:97
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
DL_Group_Format
Definition dl_group.h:29
const uint16_t PRIMES[]
Definition primes.cpp:12
const size_t PRIME_TABLE_SIZE
Definition numthry.h:174
Montgomery_Int monty_execute_vartime(const Montgomery_Exponentation_State &precomputed_state, const BigInt &k)
size_t dl_work_factor(size_t bits)
DL_Group_Source
Definition dl_group.h:20
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
Definition numthry.cpp:355
BigInt inverse_mod_public_prime(const BigInt &x, const BigInt &p)
Definition mod_inv.cpp:291
std::vector< T > unlock(const secure_vector< T > &in)
Definition secmem.h:75
Montgomery_Int monty_exp(const std::shared_ptr< const Montgomery_Params > &params_p, const BigInt &g, const BigInt &k, size_t max_k_bits)
Definition monty_exp.h:48
Montgomery_Int monty_exp_vartime(const std::shared_ptr< const Montgomery_Params > &params_p, const BigInt &g, const BigInt &k)
Definition monty_exp.h:56
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)
Definition dsa_gen.cpp:54
Montgomery_Int monty_execute(const Montgomery_Exponentation_State &precomputed_state, const BigInt &k, size_t max_k_bits)
size_t dl_exponent_size(size_t bits)
const SIMD_8x32 & b
std::shared_ptr< const Montgomery_Exponentation_State > monty_precompute(const Montgomery_Int &g, size_t window_bits, bool const_time)
int32_t jacobi(const BigInt &a, const BigInt &n)
Definition numthry.cpp:116
BigInt random_safe_prime(RandomNumberGenerator &rng, size_t bits)
Definition make_prm.cpp:294
Montgomery_Int monty_multi_exp(const std::shared_ptr< const Montgomery_Params > &params_p, const BigInt &x_bn, const BigInt &z1, const BigInt &y_bn, const BigInt &z2)