Botan  1.10.9
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 
13 namespace Botan {
14 
15 /*
16 * The size of the word type, in bits
17 */
18 const size_t MP_WORD_BITS = BOTAN_MP_WORD_BITS;
19 
20 extern "C" {
21 
22 /*
23 * Addition/Subtraction Operations
24 */
25 void bigint_add2(word x[], size_t x_size,
26  const word y[], size_t y_size);
27 
28 void bigint_add3(word z[],
29  const word x[], size_t x_size,
30  const word y[], size_t y_size);
31 
32 word bigint_add2_nc(word x[], size_t x_size, const word y[], size_t y_size);
33 
34 word bigint_add3_nc(word z[],
35  const word x[], size_t x_size,
36  const word y[], size_t y_size);
37 
38 word bigint_sub2(word x[], size_t x_size,
39  const word y[], size_t y_size);
40 
41 /**
42 * x = y - x; assumes y >= x
43 */
44 void bigint_sub2_rev(word x[], const word y[], size_t y_size);
45 
46 word bigint_sub3(word z[],
47  const word x[], size_t x_size,
48  const word y[], size_t y_size);
49 
50 /*
51 * Shift Operations
52 */
53 void bigint_shl1(word x[], size_t x_size,
54  size_t word_shift, size_t bit_shift);
55 
56 void bigint_shr1(word x[], size_t x_size,
57  size_t word_shift, size_t bit_shift);
58 
59 void bigint_shl2(word y[], const word x[], size_t x_size,
60  size_t word_shift, size_t bit_shift);
61 
62 void bigint_shr2(word y[], const word x[], size_t x_size,
63  size_t word_shift, size_t bit_shift);
64 
65 /*
66 * Simple O(N^2) Multiplication and Squaring
67 */
68 void bigint_simple_mul(word z[],
69  const word x[], size_t x_size,
70  const word y[], size_t y_size);
71 
72 void bigint_simple_sqr(word z[], const word x[], size_t x_size);
73 
74 /*
75 * Linear Multiply
76 */
77 void bigint_linmul2(word x[], size_t x_size, word y);
78 void bigint_linmul3(word z[], const word x[], size_t x_size, word y);
79 
80 /**
81 * Montgomery Reduction
82 * @param z integer to reduce (also output in first p_size+1 words)
83 * @param z_size size of z (should be >= 2*p_size+1)
84 * @param p modulus
85 * @param p_size size of p
86 * @param p_dash Montgomery value
87 * @param workspace array of at least 2*(p_size+1) words
88 */
89 void bigint_monty_redc(word z[], size_t z_size,
90  const word p[], size_t p_size, word p_dash,
91  word workspace[]);
92 
93 /*
94 * Montgomery Multiplication
95 */
96 void bigint_monty_mul(word z[], size_t z_size,
97  const word x[], size_t x_size, size_t x_sw,
98  const word y[], size_t y_size, size_t y_sw,
99  const word p[], size_t p_size, word p_dash,
100  word workspace[]);
101 
102 /*
103 * Montgomery Squaring
104 */
105 void bigint_monty_sqr(word z[], size_t z_size,
106  const word x[], size_t x_size, size_t x_sw,
107  const word p[], size_t p_size, word p_dash,
108  word workspace[]);
109 
110 /*
111 * Division operation
112 */
113 size_t bigint_divcore(word q, word y2, word y1,
114  word x3, word x2, word x1);
115 
116 /**
117 * Compare x and y
118 */
119 s32bit bigint_cmp(const word x[], size_t x_size,
120  const word y[], size_t y_size);
121 
122 /**
123 * Compute ((n1<<bits) + n0) / d
124 */
125 word bigint_divop(word n1, word n0, word d);
126 
127 /**
128 * Compute ((n1<<bits) + n0) % d
129 */
130 word bigint_modop(word n1, word n0, word d);
131 
132 /*
133 * Comba Multiplication / Squaring
134 */
135 void bigint_comba_mul4(word z[8], const word x[4], const word y[4]);
136 void bigint_comba_mul6(word z[12], const word x[6], const word y[6]);
137 void bigint_comba_mul8(word z[16], const word x[8], const word y[8]);
138 void bigint_comba_mul16(word z[32], const word x[16], const word y[16]);
139 
140 void bigint_comba_sqr4(word out[8], const word in[4]);
141 void bigint_comba_sqr6(word out[12], const word in[6]);
142 void bigint_comba_sqr8(word out[16], const word in[8]);
143 void bigint_comba_sqr16(word out[32], const word in[16]);
144 
145 }
146 
147 /*
148 * High Level Multiplication/Squaring Interfaces
149 */
150 void bigint_mul(word z[], size_t z_size, word workspace[],
151  const word x[], size_t x_size, size_t x_sw,
152  const word y[], size_t y_size, size_t y_sw);
153 
154 void bigint_sqr(word z[], size_t z_size, word workspace[],
155  const word x[], size_t x_size, size_t x_sw);
156 
157 }
158 
159 #endif
void bigint_shr1(word x[], size_t x_size, size_t word_shift, size_t bit_shift)
Definition: mp_shift.cpp:42
void bigint_sub2_rev(word x[], const word y[], size_t y_size)
Definition: mp_asm.cpp:108
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_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_sub2(word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_asm.cpp:87
void bigint_linmul2(word x[], size_t x_size, word y)
Definition: mp_asm.cpp:149
word bigint_add3_nc(word z[], const word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_asm.cpp:43
void bigint_comba_mul4(word z[8], const word x[4], const word y[4])
Definition: mp_comba.cpp:51
word bigint_sub3(word z[], const word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_asm.cpp:127
word bigint_divop(word n1, word n0, word d)
Definition: mp_misc.cpp:67
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
signed int s32bit
Definition: types.h:37
void bigint_linmul3(word z[], const word x[], size_t x_size, word y)
Definition: mp_asm.cpp:167
void bigint_comba_sqr16(word z[32], const word x[16])
Definition: mp_comba.cpp:387
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_sqr(word z[], size_t z_size, word workspace[], const word x[], size_t x_size, size_t x_sw)
Definition: mp_karat.cpp:303
word bigint_add2_nc(word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_asm.cpp:22
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_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
void bigint_shl1(word x[], size_t x_size, size_t word_shift, size_t bit_shift)
Definition: mp_shift.cpp:18
void bigint_comba_mul8(word z[16], const word x[8], const word y[8])
Definition: mp_comba.cpp:284
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:248
size_t bigint_divcore(word q, word y2, word y1, word x3, word x2, word x1)
Definition: mp_misc.cpp:18
void bigint_comba_sqr8(word z[16], const word x[8])
Definition: mp_comba.cpp:209
void bigint_add2(word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_asm.cpp:68
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
void bigint_simple_sqr(word z[], const word x[], size_t x_size)
Definition: mp_mulop.cpp:54
void bigint_comba_sqr4(word z[8], const word x[4])
Definition: mp_comba.cpp:18
void bigint_comba_sqr6(word z[12], const word x[6])
Definition: mp_comba.cpp:90
s32bit bigint_cmp(const word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_misc.cpp:41
void bigint_add3(word z[], const word x[], size_t x_size, const word y[], size_t y_size)
Definition: mp_asm.cpp:77
word bigint_modop(word n1, word n0, word d)
Definition: mp_misc.cpp:92
const size_t MP_WORD_BITS
Definition: mp_core.h:18