Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
13 BOTAN_FUTURE_INTERNAL_HEADER(divide.h)
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_PUBLIC_API(2,0) 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 /**
46 * BigInt division, const time variant
47 *
48 * This runs with control flow independent of the values of x/y.
49 * Warning: the loop bounds still leak the sizes of x and y.
50 *
51 * @param x an integer
52 * @param y a non-zero integer
53 * @return x/y with remainder discarded
54 */
55 inline BigInt ct_divide(const BigInt& x, const BigInt& y)
56 {
57 BigInt q, r;
58 ct_divide(x, y, q, r);
59 return q;
60 }
61
62 /**
63 * BigInt division, const time variant
64 *
65 * This runs with control flow independent of the values of x/y.
66 * Warning: the loop bounds still leak the sizes of x and y.
67 *
68 * @param x an integer
69 * @param y a non-zero integer
70 * @param q will be set to x / y
71 * @param r will be set to x % y
72 */
73 void BOTAN_PUBLIC_API(2,9) ct_divide_u8(const BigInt& x,
74 uint8_t y,
75 BigInt& q,
76 uint8_t& r);
77
78 /**
79 * BigInt modulo, const time variant
80 *
81 * Using this function is (slightly) cheaper than calling ct_divide and
82 * using only the remainder.
83 *
84 * @param x a non-negative integer
85 * @param modulo a positive integer
86 * @return result x % modulo
87 */
88 BigInt BOTAN_PUBLIC_API(2,9) ct_modulo(const BigInt& x,
89 const BigInt& modulo);
90
91 }
92
93 #endif
Botan::BigInt
Definition: bigint.h:24
Botan::divide
void divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition: divide.cpp:159
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::ct_modulo
BigInt ct_modulo(const BigInt &x, const BigInt &y)
Definition: divide.cpp:118
Botan::ct_divide
BigInt ct_divide(const BigInt &x, const BigInt &y)
Definition: divide.h:55
Botan
Definition: alg_id.cpp:13
Botan::ct_divide_u8
void ct_divide_u8(const BigInt &x, uint8_t y, BigInt &q_out, uint8_t &r_out)
Definition: divide.cpp:82
BOTAN_FUTURE_INTERNAL_HEADER
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:139