Botan 1.10.17
mp_core.h
Go to the documentation of this file.
1/*
2* MPI Algorithms
3* (C) 1999-2010 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
6*/
7
8#ifndef BOTAN_MP_CORE_H__
9#define BOTAN_MP_CORE_H__
10
11#include <botan/mp_types.h>
12
13namespace Botan {
14
15/*
16* The size of the word type, in bits
17*/
18const size_t MP_WORD_BITS = BOTAN_MP_WORD_BITS;
19
20extern "C" {
21
22/*
23* If cond == 0, does nothing.
24* If cond > 0, swaps x[0:size] with y[0:size]
25* Runs in constant time
26*/
27void bigint_cnd_swap(word cnd, word x[], word y[], size_t size);
28
29/*
30* If cond > 0 adds x[0:size] to y[0:size] and returns carry
31* Runs in constant time
32*/
33word bigint_cnd_add(word cnd, word x[], const word y[], size_t size);
34
35/*
36* If cond > 0 subs x[0:size] to y[0:size] and returns borrow
37* Runs in constant time
38*/
39word bigint_cnd_sub(word cnd, word x[], const word y[], size_t size);
40
41/*
42* 2s complement absolute value
43* If cond > 0 sets x to ~x + 1
44* Runs in constant time
45*/
46void bigint_cnd_abs(word cnd, word x[], size_t size);
47
48/*
49* Addition/Subtraction Operations
50*/
51void bigint_add2(word x[], size_t x_size,
52 const word y[], size_t y_size);
53
54void bigint_add3(word z[],
55 const word x[], size_t x_size,
56 const word y[], size_t y_size);
57
58word bigint_add2_nc(word x[], size_t x_size, const word y[], size_t y_size);
59
60word bigint_add3_nc(word z[],
61 const word x[], size_t x_size,
62 const word y[], size_t y_size);
63
64word bigint_sub2(word x[], size_t x_size,
65 const word y[], size_t y_size);
66
67/**
68* x = y - x; assumes y >= x
69*/
70void bigint_sub2_rev(word x[], const word y[], size_t y_size);
71
72word bigint_sub3(word z[],
73 const word x[], size_t x_size,
74 const word y[], size_t y_size);
75
76/*
77* Shift Operations
78*/
79void bigint_shl1(word x[], size_t x_size,
80 size_t word_shift, size_t bit_shift);
81
82void bigint_shr1(word x[], size_t x_size,
83 size_t word_shift, size_t bit_shift);
84
85void bigint_shl2(word y[], const word x[], size_t x_size,
86 size_t word_shift, size_t bit_shift);
87
88void bigint_shr2(word y[], const word x[], size_t x_size,
89 size_t word_shift, size_t bit_shift);
90
91/*
92* Simple O(N^2) Multiplication and Squaring
93*/
94void bigint_simple_mul(word z[],
95 const word x[], size_t x_size,
96 const word y[], size_t y_size);
97
98void bigint_simple_sqr(word z[], const word x[], size_t x_size);
99
100/*
101* Linear Multiply
102*/
103void bigint_linmul2(word x[], size_t x_size, word y);
104void bigint_linmul3(word z[], const word x[], size_t x_size, word y);
105
106/**
107* Montgomery Reduction
108* @param z integer to reduce (also output in first p_size+1 words)
109* @param z_size size of z (should be >= 2*p_size+1)
110* @param p modulus
111* @param p_size size of p
112* @param p_dash Montgomery value
113* @param workspace array of at least 2*(p_size+1) words
114*/
115void bigint_monty_redc(word z[], size_t z_size,
116 const word p[], size_t p_size, word p_dash,
117 word workspace[]);
118
119/*
120* Montgomery Multiplication
121*/
122void bigint_monty_mul(word z[], size_t z_size,
123 const word x[], size_t x_size, size_t x_sw,
124 const word y[], size_t y_size, size_t y_sw,
125 const word p[], size_t p_size, word p_dash,
126 word workspace[]);
127
128/*
129* Montgomery Squaring
130*/
131void bigint_monty_sqr(word z[], size_t z_size,
132 const word x[], size_t x_size, size_t x_sw,
133 const word p[], size_t p_size, word p_dash,
134 word workspace[]);
135
136/*
137* Division operation
138*/
139size_t bigint_divcore(word q, word y2, word y1,
140 word x3, word x2, word x1);
141
142/**
143* Compare x and y
144*/
145s32bit bigint_cmp(const word x[], size_t x_size,
146 const word y[], size_t y_size);
147
148/**
149* Compute ((n1<<bits) + n0) / d
150*/
151word bigint_divop(word n1, word n0, word d);
152
153/**
154* Compute ((n1<<bits) + n0) % d
155*/
156word bigint_modop(word n1, word n0, word d);
157
158/*
159* Comba Multiplication / Squaring
160*/
161void bigint_comba_mul4(word z[8], const word x[4], const word y[4]);
162void bigint_comba_mul6(word z[12], const word x[6], const word y[6]);
163void bigint_comba_mul8(word z[16], const word x[8], const word y[8]);
164void bigint_comba_mul16(word z[32], const word x[16], const word y[16]);
165
166void bigint_comba_sqr4(word out[8], const word in[4]);
167void bigint_comba_sqr6(word out[12], const word in[6]);
168void bigint_comba_sqr8(word out[16], const word in[8]);
169void bigint_comba_sqr16(word out[32], const word in[16]);
170
171}
172
173/*
174* High Level Multiplication/Squaring Interfaces
175*/
176void bigint_mul(word z[], size_t z_size, word workspace[],
177 const word x[], size_t x_size, size_t x_sw,
178 const word y[], size_t y_size, size_t y_sw);
179
180void bigint_sqr(word z[], size_t z_size, word workspace[],
181 const word x[], size_t x_size, size_t x_sw);
182
183}
184
185#endif
word bigint_divop(word n1, word n0, word d)
Definition mp_misc.cpp:67
void bigint_sub2_rev(word x[], const word y[], size_t y_size)
Definition mp_asm.cpp:179
void bigint_shr1(word x[], size_t x_size, size_t word_shift, size_t bit_shift)
Definition mp_shift.cpp:42
void bigint_linmul3(word z[], const word x[], size_t x_size, word y)
Definition mp_asm.cpp:238
word bigint_sub2(word x[], size_t x_size, const word y[], size_t y_size)
Definition mp_asm.cpp:158
void bigint_comba_mul4(word z[8], const word x[4], const word y[4])
Definition mp_comba.cpp:51
void bigint_shl1(word x[], size_t x_size, size_t word_shift, size_t bit_shift)
Definition mp_shift.cpp:18
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:306
signed int s32bit
Definition types.h:37
void bigint_add3(word z[], const word x[], size_t x_size, const word y[], size_t y_size)
Definition mp_asm.cpp:148
void bigint_simple_mul(word z[], const word x[], size_t x_size, const word y[], size_t y_size)
Definition mp_mulop.cpp:20
void bigint_comba_sqr6(word z[12], const word x[6])
Definition mp_comba.cpp:90
void bigint_mul(word z[], size_t z_size, word workspace[], const word x[], size_t x_size, size_t x_sw, const word y[], size_t y_size, size_t y_sw)
Definition mp_karat.cpp:249
void bigint_comba_sqr16(word z[32], const word x[16])
Definition mp_comba.cpp:387
s32bit bigint_cmp(const word x[], size_t x_size, const word y[], size_t y_size)
Definition mp_misc.cpp:41
void bigint_simple_sqr(word z[], const word x[], size_t x_size)
Definition mp_mulop.cpp:54
void bigint_monty_redc(word z[], size_t z_size, const word p[], size_t p_size, word p_dash, word workspace[])
Definition mp_monty.cpp:21
void bigint_cnd_swap(word cnd, word x[], word y[], size_t size)
Definition mp_asm.cpp:25
void bigint_monty_sqr(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, const word p[], size_t p_size, word p_dash, word workspace[])
Definition mp_monty.cpp:84
word bigint_cnd_add(word cnd, word x[], const word y[], size_t size)
Definition mp_asm.cpp:42
void bigint_comba_mul8(word z[16], const word x[8], const word y[8])
Definition mp_comba.cpp:284
word bigint_cnd_sub(word cnd, word x[], const word y[], size_t size)
Definition mp_asm.cpp:64
void bigint_comba_sqr4(word z[8], const word x[4])
Definition mp_comba.cpp:18
const size_t MP_WORD_BITS
Definition mp_core.h:18
void bigint_shl2(word y[], const word x[], size_t x_size, size_t word_shift, size_t bit_shift)
Definition mp_shift.cpp:97
void bigint_add2(word x[], size_t x_size, const word y[], size_t y_size)
Definition mp_asm.cpp:139
word bigint_add2_nc(word x[], size_t x_size, const word y[], size_t y_size)
Definition mp_asm.cpp:93
void bigint_shr2(word y[], const word x[], size_t x_size, size_t word_shift, size_t bit_shift)
Definition mp_shift.cpp:117
word bigint_add3_nc(word z[], const word x[], size_t x_size, const word y[], size_t y_size)
Definition mp_asm.cpp:114
word bigint_modop(word n1, word n0, word d)
Definition mp_misc.cpp:92
void bigint_cnd_abs(word cnd, word x[], size_t size)
Definition mp_asm.cpp:78
void bigint_monty_mul(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, const word y[], size_t y_size, size_t y_sw, const word p[], size_t p_size, word p_dash, word workspace[])
Definition mp_monty.cpp:69
size_t bigint_divcore(word q, word y2, word y1, word x3, word x2, word x1)
Definition mp_misc.cpp:18
void bigint_linmul2(word x[], size_t x_size, word y)
Definition mp_asm.cpp:220
void bigint_comba_mul16(word z[32], const word x[16], const word y[16])
Definition mp_comba.cpp:594
void bigint_comba_mul6(word z[12], const word x[6], const word y[6])
Definition mp_comba.cpp:142
word bigint_sub3(word z[], const word x[], size_t x_size, const word y[], size_t y_size)
Definition mp_asm.cpp:198
void bigint_comba_sqr8(word z[16], const word x[8])
Definition mp_comba.cpp:209