Botan  2.19.1
Crypto and TLS for C++11
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 
14 
15 namespace Botan {
16 
17 /**
18 * BigInt Division
19 * @param x an integer
20 * @param y a non-zero integer
21 * @param q will be set to x / y
22 * @param r will be set to x % y
23 */
24 void BOTAN_UNSTABLE_API vartime_divide(const BigInt& x,
25  const BigInt& y,
26  BigInt& q,
27  BigInt& r);
28 
29 /**
30 * BigInt division, const time variant
31 *
32 * This runs with control flow independent of the values of x/y.
33 * Warning: the loop bounds still leak the sizes of x and y.
34 *
35 * @param x an integer
36 * @param y a non-zero integer
37 * @param q will be set to x / y
38 * @param r will be set to x % y
39 */
40 void BOTAN_PUBLIC_API(2,9) ct_divide(const BigInt& x,
41  const BigInt& y,
42  BigInt& q,
43  BigInt& r);
44 
45 inline void divide(const BigInt& x,
46  const BigInt& y,
47  BigInt& q,
48  BigInt& r)
49  {
50  ct_divide(x, y, q, r);
51  }
52 
53 /**
54 * BigInt division, const time variant
55 *
56 * This runs with control flow independent of the values of x/y.
57 * Warning: the loop bounds still leak the sizes of x and y.
58 *
59 * @param x an integer
60 * @param y a non-zero integer
61 * @return x/y with remainder discarded
62 */
63 inline BigInt ct_divide(const BigInt& x, const BigInt& y)
64  {
65  BigInt q, r;
66  ct_divide(x, y, q, r);
67  return q;
68  }
69 
70 /**
71 * BigInt division, const time variant
72 *
73 * This runs with control flow independent of the values of x/y.
74 * Warning: the loop bounds still leak the sizes of x and y.
75 *
76 * @param x an integer
77 * @param y a non-zero integer
78 * @param q will be set to x / y
79 * @param r will be set to x % y
80 */
81 void BOTAN_PUBLIC_API(2,9) ct_divide_u8(const BigInt& x,
82  uint8_t y,
83  BigInt& q,
84  uint8_t& r);
85 
86 /**
87 * BigInt modulo, const time variant
88 *
89 * Using this function is (slightly) cheaper than calling ct_divide and
90 * using only the remainder.
91 *
92 * @param x a non-negative integer
93 * @param modulo a positive integer
94 * @return result x % modulo
95 */
96 BigInt BOTAN_PUBLIC_API(2,9) ct_modulo(const BigInt& x,
97  const BigInt& modulo);
98 
99 }
100 
101 #endif
#define BOTAN_UNSTABLE_API
Definition: compiler.h:44
void vartime_divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition: divide.cpp:159
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
BigInt ct_modulo(const BigInt &x, const BigInt &y)
Definition: divide.cpp:118
BigInt ct_divide(const BigInt &x, const BigInt &y)
Definition: divide.h:63
Definition: alg_id.cpp:13
void ct_divide_u8(const BigInt &x, uint8_t y, BigInt &q_out, uint8_t &r_out)
Definition: divide.cpp:82
void divide(const BigInt &x, const BigInt &y, BigInt &q, BigInt &r)
Definition: divide.h:45
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:136