/src/botan/build/include/botan/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 | | 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 | 98.1k | { |
57 | 98.1k | BigInt q, r; |
58 | 98.1k | ct_divide(x, y, q, r); |
59 | 98.1k | return q; |
60 | 98.1k | } |
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 |