Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

mp_core.h
Go to the documentation of this file.
1 /*
2 * MPI Algorithms
3 * (C) 1999-2010 Jack Lloyd
4 * 2006 Luca Piccarreta
5 * 2016 Matthias Gierlings
6 *
7 * Botan is released under the Simplified BSD License (see license.txt)
8 */
9
10 #ifndef BOTAN_MP_CORE_OPS_H__
11 #define BOTAN_MP_CORE_OPS_H__
12
13 #include <botan/bigint.h>
14 #include <botan/mp_types.h>
15
16 namespace Botan {
17
18 /*
19 * The size of the word type, in bits
20 */
21 const size_t MP_WORD_BITS = BOTAN_MP_WORD_BITS;
22
23 /*
24 * If cond == 0, does nothing.
25 * If cond > 0, swaps x[0:size] with y[0:size]
26 * Runs in constant time
27 */
28 BOTAN_DLL
29 void bigint_cnd_swap(word cnd, word x[], word y[], size_t size);
30
31 /*
32 * If cond > 0 adds x[0:size] to y[0:size] and returns carry
33 * Runs in constant time
34 */
35 BOTAN_DLL
36 word bigint_cnd_add(word cnd, word x[], const word y[], size_t size);
37
38 /*
39 * If cond > 0 subs x[0:size] to y[0:size] and returns borrow
40 * Runs in constant time
41 */
42 BOTAN_DLL
43 word bigint_cnd_sub(word cnd, word x[], const word y[], size_t size);
44
45 /*
46 * 2s complement absolute value
47 * If cond > 0 sets x to ~x + 1
48 * Runs in constant time
49 */
50 BOTAN_DLL
51 void bigint_cnd_abs(word cnd, word x[], size_t size);
52
53 /**
54 * Two operand addition
55 * @param x the first operand (and output)
56 * @param x_size size of x
57 * @param y the second operand
58 * @param y_size size of y (must be >= x_size)
59 */
60 void bigint_add2(word x[], size_t x_size,
61 const word y[], size_t y_size);
62
63 /**
64 * Three operand addition
65 */
66 void bigint_add3(word z[],
67 const word x[], size_t x_size,
68 const word y[], size_t y_size);
69
70 /**
71 * Two operand addition with carry out
72 */
73 word bigint_add2_nc(word x[], size_t x_size, const word y[], size_t y_size);
74
75 /**
76 * Three operand addition with carry out
77 */
78 word bigint_add3_nc(word z[],
79 const word x[], size_t x_size,
80 const word y[], size_t y_size);
81
82 /**
83 * Two operand subtraction
84 */
85 word bigint_sub2(word x[], size_t x_size,
86 const word y[], size_t y_size);
87
88 /**
89 * Two operand subtraction, x = y - x; assumes y >= x
90 */
91 void bigint_sub2_rev(word x[], const word y[], size_t y_size);
92
93 /**
94 * Three operand subtraction
95 */
96 word bigint_sub3(word z[],
97 const word x[], size_t x_size,
98 const word y[], size_t y_size);
99
100 /*
101 * Shift Operations
102 */
103 void bigint_shl1(word x[], size_t x_size,
104 size_t word_shift, size_t bit_shift);
105
106 void bigint_shr1(word x[], size_t x_size,
107 size_t word_shift, size_t bit_shift);
108
109 void bigint_shl2(word y[], const word x[], size_t x_size,
110 size_t word_shift, size_t bit_shift);
111
112 void bigint_shr2(word y[], const word x[], size_t x_size,
113 size_t word_shift, size_t bit_shift);
114
115 /*
116 * Linear Multiply
117 */
118 void bigint_linmul2(word x[], size_t x_size, word y);
119 void bigint_linmul3(word z[], const word x[], size_t x_size, word y);
120
121 /**
122 * Montgomery Reduction
123 * @param z integer to reduce, of size exactly 2*(p_size+1).
124 Output is in the first p_size+1 words, higher
125 words are set to zero.
126 * @param p modulus
127 * @param p_size size of p
128 * @param p_dash Montgomery value
129 * @param workspace array of at least 2*(p_size+1) words
130 */
131 void bigint_monty_redc(word z[],
132 const word p[], size_t p_size,
133 word p_dash,
134 word workspace[]);
135
136 /*
137 * Montgomery Multiplication
138 */
139 void bigint_monty_mul(BigInt& z, const BigInt& x, const BigInt& y,
140 const word p[], size_t p_size, word p_dash,
141 word workspace[]);
142
143 /*
144 * Montgomery Squaring
145 */
146 void bigint_monty_sqr(BigInt& z, const BigInt& x,
147 const word p[], size_t p_size, word p_dash,
148 word workspace[]);
149
150 /**
151 * Compare x and y
152 */
153 int32_t bigint_cmp(const word x[], size_t x_size,
154 const word y[], size_t y_size);
155
156 /**
157 * Compute ((n1<<bits) + n0) / d
158 */
159 word bigint_divop(word n1, word n0, word d);
160
161 /**
162 * Compute ((n1<<bits) + n0) % d
163 */
164 word bigint_modop(word n1, word n0, word d);
165
166 /*
167 * Comba Multiplication / Squaring
168 */
169 void bigint_comba_mul4(word z[8], const word x[4], const word y[4]);
170 void bigint_comba_mul6(word z[12], const word x[6], const word y[6]);
171 void bigint_comba_mul8(word z[16], const word x[8], const word y[8]);
172 void bigint_comba_mul9(word z[18], const word x[9], const word y[9]);
173 void bigint_comba_mul16(word z[32], const word x[16], const word y[16]);
174
175 void bigint_comba_sqr4(word out[8], const word in[4]);
176 void bigint_comba_sqr6(word out[12], const word in[6]);
177 void bigint_comba_sqr8(word out[16], const word in[8]);
178 void bigint_comba_sqr9(word out[18], const word in[9]);
179 void bigint_comba_sqr16(word out[32], const word in[16]);
180
181 /*
182 * High Level Multiplication/Squaring Interfaces
183 */
184 void bigint_mul(BigInt& z, const BigInt& x, const BigInt& y, word workspace[]);
185
186 void bigint_sqr(word z[], size_t z_size, word workspace[],
187 const word x[], size_t x_size, size_t x_sw);
188
189 }
190
191 #endif
Botan::bigint_shr1
void bigint_shr1(word x[], size_t x_size, size_t word_shift, size_t bit_shift)
Definition: mp_core.cpp:281
Botan::bigint_sub2_rev
void bigint_sub2_rev(word x[], const word y[], size_t y_size)
Definition: mp_core.cpp:180
Botan::BigInt
Definition: bigint.h:23
Botan::bigint_shr2
void bigint_shr2(word y[], const word x[], size_t x_size, size_t word_shift, size_t bit_shift)
Definition: mp_core.cpp:356
Botan::bigint_cmp
int32_t bigint_cmp(const word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_core.cpp:378
Botan::bigint_sub2
word bigint_sub2(word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_core.cpp:157
Botan::bigint_linmul2
void bigint_linmul2(word x[], size_t x_size, word y)
Definition: mp_core.cpp:222
Botan::bigint_add3_nc
word bigint_add3_nc(word z[], const word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_core.cpp:113
Botan::bigint_comba_mul4
void bigint_comba_mul4(word z[8], const word x[4], const word y[4])
Definition: mp_comba.cpp:50
Botan::bigint_sub3
word bigint_sub3(word z[], const word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_core.cpp:198
Botan::bigint_divop
word bigint_divop(word n1, word n0, word d)
Definition: mp_core.cpp:404
Botan::bigint_comba_mul9
void bigint_comba_mul9(word z[18], const word x[9], const word y[9])
Definition: mp_comba.cpp:474
Botan::bigint_cnd_sub
word bigint_cnd_sub(word cnd, word x[], const word y[], size_t size)
Definition: mp_core.cpp:61
Botan::bigint_linmul3
void bigint_linmul3(word z[], const word x[], size_t x_size, word y)
Definition: mp_core.cpp:240
Botan::bigint_comba_sqr16
void bigint_comba_sqr16(word z[32], const word x[16])
Definition: mp_comba.cpp:598
Botan::bigint_monty_sqr
void bigint_monty_sqr(BigInt &z, const BigInt &x, const word p[], size_t p_size, word p_dash, word workspace[])
Definition: mp_monty.cpp:109
Botan::bigint_sqr
void bigint_sqr(word z[], size_t z_size, word workspace[], const word x[], size_t x_size, size_t x_sw)
Definition: mp_karat.cpp:312
Botan::bigint_monty_mul
void bigint_monty_mul(BigInt &z, const BigInt &x, const BigInt &y, const word p[], size_t p_size, word p_dash, word workspace[])
Definition: mp_monty.cpp:97
Botan::bigint_cnd_add
word bigint_cnd_add(word cnd, word x[], const word y[], size_t size)
Definition: mp_core.cpp:39
Botan::bigint_add2_nc
word bigint_add2_nc(word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_core.cpp:90
Botan
Definition: alg_id.cpp:13
Botan::bigint_comba_sqr9
void bigint_comba_sqr9(word z[18], const word x[9])
Definition: mp_comba.cpp:386
Botan::bigint_cnd_abs
void bigint_cnd_abs(word cnd, word x[], size_t size)
Definition: mp_core.cpp:75
Botan::bigint_shl2
void bigint_shl2(word y[], const word x[], size_t x_size, size_t word_shift, size_t bit_shift)
Definition: mp_core.cpp:336
Botan::bigint_shl1
void bigint_shl1(word x[], size_t x_size, size_t word_shift, size_t bit_shift)
Definition: mp_core.cpp:258
Botan::bigint_comba_mul8
void bigint_comba_mul8(word z[16], const word x[8], const word y[8])
Definition: mp_comba.cpp:283
Botan::bigint_comba_sqr8
void bigint_comba_sqr8(word z[16], const word x[8])
Definition: mp_comba.cpp:208
Botan::bigint_add2
void bigint_add2(word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_core.cpp:138
Botan::bigint_comba_mul16
void bigint_comba_mul16(word z[32], const word x[16], const word y[16])
Definition: mp_comba.cpp:805
Botan::bigint_cnd_swap
void bigint_cnd_swap(word cnd, word x[], word y[], size_t size)
Definition: mp_core.cpp:22
Botan::bigint_mul
void bigint_mul(BigInt &z, const BigInt &x, const BigInt &y, word workspace[])
Definition: mp_karat.cpp:252
Botan::bigint_monty_redc
void bigint_monty_redc(word z[], const word p[], size_t p_size, word p_dash, word workspace[])
Definition: mp_monty.cpp:22
Botan::bigint_comba_mul6
void bigint_comba_mul6(word z[12], const word x[6], const word y[6])
Definition: mp_comba.cpp:141
Botan::bigint_comba_sqr4
void bigint_comba_sqr4(word z[8], const word x[4])
Definition: mp_comba.cpp:17
Botan::bigint_comba_sqr6
void bigint_comba_sqr6(word z[12], const word x[6])
Definition: mp_comba.cpp:89
Botan::bigint_add3
void bigint_add3(word z[], const word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_core.cpp:147
Botan::bigint_modop
word bigint_modop(word n1, word n0, word d)
Definition: mp_core.cpp:432
Botan::MP_WORD_BITS
const size_t MP_WORD_BITS
Definition: mp_core.h:21