Botan 3.6.1
Crypto and TLS for C&
divide.h
Go to the documentation of this file.
1/*
2* Division
3* (C) 1999-2007 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_DIVISON_ALGORITHM_H_
9#define BOTAN_DIVISON_ALGORITHM_H_
10
11#include <botan/bigint.h>
12
13namespace Botan {
14
15/**
16* BigInt Division
17* @param x an integer
18* @param y a non-zero integer
19* @param q will be set to x / y
20* @param r will be set to x % y
21*/
23void vartime_divide(const BigInt& x, const BigInt& y, BigInt& q, BigInt& r);
24
25/**
26* BigInt division, const time variant
27*
28* This runs with control flow independent of the values of x/y.
29* Warning: the loop bounds still leak the sizes of x and y.
30*
31* @param x an integer
32* @param y a non-zero integer
33* @param q will be set to x / y
34* @param r will be set to x % y
35*/
37void ct_divide(const BigInt& x, const BigInt& y, BigInt& q, BigInt& r);
38
39/**
40* BigInt division, const time variant
41*
42* This runs with control flow independent of the values of x/y.
43* Warning: the loop bounds still leak the sizes of x and y.
44*
45* @param x an integer
46* @param y a non-zero integer
47* @return x/y with remainder discarded
48*/
49inline BigInt ct_divide(const BigInt& x, const BigInt& y) {
50 BigInt q, r;
51 ct_divide(x, y, q, r);
52 return q;
53}
54
55/**
56* BigInt division, const time variant
57*
58* This runs with control flow independent of the values of x/y.
59* Warning: the loop bounds still leaks the size of x.
60*
61* @param x an integer
62* @param y a non-zero integer
63* @param q will be set to x / y
64* @param r will be set to x % y
65*/
67void ct_divide_word(const BigInt& x, word y, BigInt& q, word& r);
68
69/**
70* BigInt modulo, const time variant
71*
72* Using this function is (slightly) cheaper than calling ct_divide and
73* using only the remainder.
74*
75* @param x a non-negative integer
76* @param modulo a positive integer
77* @return result x % modulo
78*/
80BigInt ct_modulo(const BigInt& x, const BigInt& modulo);
81
82} // namespace Botan
83
84#endif
#define BOTAN_TEST_API
Definition compiler.h:51
void vartime_divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition divide.cpp:155
BigInt ct_modulo(const BigInt &x, const BigInt &y)
Definition divide.cpp:117
void ct_divide(const BigInt &x, const BigInt &y, BigInt &q_out, BigInt &r_out)
Definition divide.cpp:48
void ct_divide_word(const BigInt &x, word y, BigInt &q_out, word &r_out)
Definition divide.cpp:80