/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/word Division |
30 | | * @param x an integer |
31 | | * @param y a non-zero integer |
32 | | * @param q will be set to x / y |
33 | | * @param r will be set to x % y |
34 | | */ |
35 | | BOTAN_TEST_API |
36 | | void vartime_divide_word(const BigInt& x, |
37 | | word y, |
38 | | BigInt& q, |
39 | | BigInt& r); |
40 | | |
41 | | /** |
42 | | * BigInt division, const time variant |
43 | | * |
44 | | * This runs with control flow independent of the values of x/y. |
45 | | * Warning: the loop bounds still leak the sizes of x and y. |
46 | | * |
47 | | * @param x an integer |
48 | | * @param y a non-zero integer |
49 | | * @param q will be set to x / y |
50 | | * @param r will be set to x % y |
51 | | */ |
52 | | BOTAN_TEST_API |
53 | | void ct_divide(const BigInt& x, |
54 | | const BigInt& y, |
55 | | BigInt& q, |
56 | | BigInt& r); |
57 | | |
58 | | /** |
59 | | * BigInt division, const time variant |
60 | | * |
61 | | * This runs with control flow independent of the values of x/y. |
62 | | * Warning: the loop bounds still leak the sizes of x and y. |
63 | | * |
64 | | * @param x an integer |
65 | | * @param y a non-zero integer |
66 | | * @return x/y with remainder discarded |
67 | | */ |
68 | | inline BigInt ct_divide(const BigInt& x, const BigInt& y) |
69 | 28.2k | { |
70 | 28.2k | BigInt q, r; |
71 | 28.2k | ct_divide(x, y, q, r); |
72 | 28.2k | return q; |
73 | 28.2k | } |
74 | | |
75 | | /** |
76 | | * BigInt division, const time variant |
77 | | * |
78 | | * This runs with control flow independent of the values of x/y. |
79 | | * Warning: the loop bounds still leak the sizes of x and y. |
80 | | * |
81 | | * @param x an integer |
82 | | * @param y a non-zero integer |
83 | | * @param q will be set to x / y |
84 | | * @param r will be set to x % y |
85 | | */ |
86 | | BOTAN_TEST_API |
87 | | void ct_divide_u8(const BigInt& x, |
88 | | uint8_t y, |
89 | | BigInt& q, |
90 | | uint8_t& r); |
91 | | |
92 | | /** |
93 | | * BigInt modulo, const time variant |
94 | | * |
95 | | * Using this function is (slightly) cheaper than calling ct_divide and |
96 | | * using only the remainder. |
97 | | * |
98 | | * @param x a non-negative integer |
99 | | * @param modulo a positive integer |
100 | | * @return result x % modulo |
101 | | */ |
102 | | BOTAN_TEST_API |
103 | | BigInt ct_modulo(const BigInt& x, |
104 | | const BigInt& modulo); |
105 | | |
106 | | } |
107 | | |
108 | | #endif |