/src/botan/build/include/botan/internal/divide.h
Line | Count | Source |
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 | | namespace 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 | | */ |
22 | | BOTAN_TEST_API |
23 | | void vartime_divide(const BigInt& x, |
24 | | const BigInt& y, |
25 | | BigInt& q, |
26 | | BigInt& r); |
27 | | |
28 | | /** |
29 | | * BigInt division, const time variant |
30 | | * |
31 | | * This runs with control flow independent of the values of x/y. |
32 | | * Warning: the loop bounds still leak the sizes of x and y. |
33 | | * |
34 | | * @param x an integer |
35 | | * @param y a non-zero integer |
36 | | * @param q will be set to x / y |
37 | | * @param r will be set to x % y |
38 | | */ |
39 | | BOTAN_TEST_API |
40 | | void 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 | 41.0k | { |
57 | 41.0k | BigInt q, r; |
58 | 41.0k | ct_divide(x, y, q, r); |
59 | 41.0k | return q; |
60 | 41.0k | } |
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 leaks the size of x. |
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 | | BOTAN_TEST_API |
74 | | void ct_divide_word(const BigInt& x, |
75 | | word y, |
76 | | BigInt& q, |
77 | | word& r); |
78 | | |
79 | | /** |
80 | | * BigInt modulo, const time variant |
81 | | * |
82 | | * Using this function is (slightly) cheaper than calling ct_divide and |
83 | | * using only the remainder. |
84 | | * |
85 | | * @param x a non-negative integer |
86 | | * @param modulo a positive integer |
87 | | * @return result x % modulo |
88 | | */ |
89 | | BOTAN_TEST_API |
90 | | BigInt ct_modulo(const BigInt& x, |
91 | | const BigInt& modulo); |
92 | | |
93 | | } |
94 | | |
95 | | #endif |