Botan 3.11.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;
16class Montgomery_Exponentiation_State;
17
18/*
19* Precompute for calculating values g^x mod p
20*/
21std::shared_ptr<const Montgomery_Exponentiation_State> monty_precompute(const Montgomery_Params& params_p,
22 const BigInt& g,
23 size_t window_bits,
24 bool const_time = true);
25
26/*
27* Precompute for calculating values g^x mod p
28*/
29std::shared_ptr<const Montgomery_Exponentiation_State> monty_precompute(const Montgomery_Int& g,
30 size_t window_bits,
31 bool const_time = true);
32
33/*
34* Return g^k mod p
35*/
36Montgomery_Int monty_execute(const Montgomery_Exponentiation_State& precomputed_state,
37 const BigInt& k,
38 size_t max_k_bits);
39
40/*
41* Return g^k mod p taking variable time depending on k
42* @warning only use this if k is public
43*/
44Montgomery_Int monty_execute_vartime(const Montgomery_Exponentiation_State& precomputed_state, const BigInt& k);
45
47 const BigInt& g,
48 const BigInt& k,
49 size_t max_k_bits) {
50 auto precomputed = monty_precompute(params_p, g, 4, true);
51 return monty_execute(*precomputed, k, max_k_bits);
52}
53
54inline Montgomery_Int monty_exp_vartime(const Montgomery_Params& params_p, const BigInt& g, const BigInt& k) {
55 auto precomputed = monty_precompute(params_p, g, 4, false);
56 return monty_execute_vartime(*precomputed, k);
57}
58
59/**
60* Return (x^z1 * y^z2) % p
61*/
62Montgomery_Int monty_multi_exp(
63 const Montgomery_Params& params_p, const BigInt& x, const BigInt& z1, const BigInt& y, const BigInt& z2);
64
65} // namespace Botan
66
67#endif
Montgomery_Int monty_exp_vartime(const Montgomery_Params &params_p, const BigInt &g, const BigInt &k)
Definition monty_exp.h:54
std::shared_ptr< const Montgomery_Exponentiation_State > monty_precompute(const Montgomery_Int &g, size_t window_bits, bool const_time)
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_vartime(const Montgomery_Exponentiation_State &precomputed_state, const BigInt &k)
Montgomery_Int monty_execute(const Montgomery_Exponentiation_State &precomputed_state, const BigInt &k, size_t max_k_bits)
Montgomery_Int monty_exp(const Montgomery_Params &params_p, const BigInt &g, const BigInt &k, size_t max_k_bits)
Definition monty_exp.h:46