Botan 3.9.0
Crypto and TLS for C&
monty_exp.h
Go to the documentation of this file.
1/*
2* (C) 2018,2025 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_MONTY_EXP_H_
8#define BOTAN_MONTY_EXP_H_
9
10#include <botan/internal/monty.h>
11#include <memory>
12
13namespace Botan {
14
15class BigInt;
17class Montgomery_Exponentation_State;
18
19/*
20* Precompute for calculating values g^x mod p
21*/
22std::shared_ptr<const Montgomery_Exponentation_State> monty_precompute(const Montgomery_Params& params_p,
23 const BigInt& g,
24 size_t window_bits,
25 bool const_time = true);
26
27/*
28* Precompute for calculating values g^x mod p
29*/
30std::shared_ptr<const Montgomery_Exponentation_State> monty_precompute(const Montgomery_Int& g,
31 size_t window_bits,
32 bool const_time = true);
33
34/*
35* Return g^k mod p
36*/
37Montgomery_Int monty_execute(const Montgomery_Exponentation_State& precomputed_state,
38 const BigInt& k,
39 size_t max_k_bits);
40
41/*
42* Return g^k mod p taking variable time depending on k
43* @warning only use this if k is public
44*/
45Montgomery_Int monty_execute_vartime(const Montgomery_Exponentation_State& precomputed_state, const BigInt& k);
46
48 const BigInt& g,
49 const BigInt& k,
50 size_t max_k_bits) {
51 auto precomputed = monty_precompute(params_p, g, 4, true);
52 return monty_execute(*precomputed, k, max_k_bits);
53}
54
55inline Montgomery_Int monty_exp_vartime(const Montgomery_Params& params_p, const BigInt& g, const BigInt& k) {
56 auto precomputed = monty_precompute(params_p, g, 4, false);
57 return monty_execute_vartime(*precomputed, k);
58}
59
60/**
61* Return (x^z1 * y^z2) % p
62*/
63Montgomery_Int monty_multi_exp(
64 const Montgomery_Params& params_p, const BigInt& x, const BigInt& z1, const BigInt& y, const BigInt& z2);
65
66} // namespace Botan
67
68#endif
Montgomery_Int monty_exp_vartime(const Montgomery_Params &params_p, const BigInt &g, const BigInt &k)
Definition monty_exp.h:55
Montgomery_Int monty_execute_vartime(const Montgomery_Exponentation_State &precomputed_state, const BigInt &k)
Montgomery_Int monty_multi_exp(const Montgomery_Params &params_p, const BigInt &x_bn, const BigInt &z1, const BigInt &y_bn, const BigInt &z2)
Montgomery_Int monty_execute(const Montgomery_Exponentation_State &precomputed_state, const BigInt &k, size_t max_k_bits)
std::shared_ptr< const Montgomery_Exponentation_State > monty_precompute(const Montgomery_Int &g, size_t window_bits, bool const_time)
Montgomery_Int monty_exp(const Montgomery_Params &params_p, const BigInt &g, const BigInt &k, size_t max_k_bits)
Definition monty_exp.h:47