Botan  2.11.0
Crypto and TLS for C++11
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 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 void BOTAN_PUBLIC_API(2,0) divide(const BigInt& x,
23  const BigInt& y,
24  BigInt& q,
25  BigInt& r);
26 
27 /**
28 * BigInt division, const time variant
29 *
30 * This runs with control flow independent of the values of x/y.
31 * Warning: the loop bounds still leak the sizes of x and y.
32 *
33 * @param x an integer
34 * @param y a non-zero integer
35 * @param q will be set to x / y
36 * @param r will be set to x % y
37 */
38 void BOTAN_PUBLIC_API(2,9) ct_divide(const BigInt& x,
39  const BigInt& y,
40  BigInt& q,
41  BigInt& r);
42 
43 /**
44 * BigInt division, const time variant
45 *
46 * This runs with control flow independent of the values of x/y.
47 * Warning: the loop bounds still leak the sizes of x and y.
48 *
49 * @param x an integer
50 * @param y a non-zero integer
51 * @return x/y with remainder discarded
52 */
53 inline BigInt ct_divide(const BigInt& x, const BigInt& y)
54  {
55  BigInt q, r;
56  ct_divide(x, y, q, r);
57  return q;
58  }
59 
60 /**
61 * BigInt division, const time variant
62 *
63 * This runs with control flow independent of the values of x/y.
64 * Warning: the loop bounds still leak the sizes of x and y.
65 *
66 * @param x an integer
67 * @param y a non-zero integer
68 * @param q will be set to x / y
69 * @param r will be set to x % y
70 */
71 void BOTAN_PUBLIC_API(2,9) ct_divide_u8(const BigInt& x,
72  uint8_t y,
73  BigInt& q,
74  uint8_t& r);
75 
76 /**
77 * BigInt modulo, const time variant
78 *
79 * Using this function is (slightly) cheaper than calling ct_divide and
80 * using only the remainder.
81 *
82 * @param x a non-negative integer
83 * @param modulo a positive integer
84 * @return result x % modulo
85 */
86 BigInt BOTAN_PUBLIC_API(2,9) ct_modulo(const BigInt& x,
87  const BigInt& modulo);
88 
89 }
90 
91 #endif
BigInt const BigInt & x
Definition: numthry.h:139
void divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition: divide.cpp:159
BigInt const BigInt & modulo
Definition: divide.h:87
void const BigInt BigInt BigInt & r
Definition: divide.h:23
BigInt ct_modulo(const BigInt &x, const BigInt &y)
Definition: divide.cpp:118
void ct_divide(const BigInt &x, const BigInt &y, BigInt &q_out, BigInt &r_out)
Definition: divide.cpp:52
Definition: alg_id.cpp:13
class BOTAN_PUBLIC_API(2, 0) AlgorithmIdentifier final bool BOTAN_PUBLIC_API(2, 0) operator
Name Constraints.
Definition: asn1_obj.h:66
void ct_divide_u8(const BigInt &x, uint8_t y, BigInt &q_out, uint8_t &r_out)
Definition: divide.cpp:82
const OctetString & y
Definition: symkey.h:126
void const BigInt BigInt & q
Definition: divide.h:23