/src/Botan-3.4.0/build/include/internal/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, 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 | | */ |
36 | | BOTAN_TEST_API |
37 | | void 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 | | */ |
49 | 75.4k | inline BigInt ct_divide(const BigInt& x, const BigInt& y) { |
50 | 75.4k | BigInt q, r; |
51 | 75.4k | ct_divide(x, y, q, r); |
52 | 75.4k | return q; |
53 | 75.4k | } |
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 | | */ |
66 | | BOTAN_TEST_API |
67 | | void 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 | | */ |
79 | | BOTAN_TEST_API |
80 | | BigInt ct_modulo(const BigInt& x, const BigInt& modulo); |
81 | | |
82 | | } // namespace Botan |
83 | | |
84 | | #endif |