Botan 3.0.0
Crypto and TLS for C&
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
13namespace 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*/
23void 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*/
40void 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*/
55inline BigInt ct_divide(const BigInt& x, const BigInt& y)
56 {
57 BigInt q, r;
58 ct_divide(x, y, q, r);
59 return q;
60 }
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*/
74void 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*/
90BigInt ct_modulo(const BigInt& x,
91 const BigInt& modulo);
92
93}
94
95#endif
static SIMD_4x64 y
#define BOTAN_TEST_API
Definition: compiler.h:51
Definition: alg_id.cpp:12
void vartime_divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition: divide.cpp:165
BigInt ct_modulo(const BigInt &x, const BigInt &y)
Definition: divide.cpp:124
void ct_divide(const BigInt &x, const BigInt &y, BigInt &q_out, BigInt &r_out)
Definition: divide.cpp:51
void ct_divide_word(const BigInt &x, word y, BigInt &q_out, word &r_out)
Definition: divide.cpp:84