Commit | Line | Data |
---|---|---|
5a44c043 | 1 | .\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) |
8b0cefbb JR |
2 | .\" |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
8b0cefbb | 5 | .de Sp \" Vertical space (when we can't use .PP) |
984263bc MD |
6 | .if t .sp .5v |
7 | .if n .sp | |
8 | .. | |
8b0cefbb | 9 | .de Vb \" Begin verbatim text |
984263bc MD |
10 | .ft CW |
11 | .nf | |
12 | .ne \\$1 | |
13 | .. | |
8b0cefbb | 14 | .de Ve \" End verbatim text |
984263bc | 15 | .ft R |
984263bc MD |
16 | .fi |
17 | .. | |
8b0cefbb JR |
18 | .\" Set up some character translations and predefined strings. \*(-- will |
19 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
e257b235 PA |
20 | .\" double quote, and \*(R" will give a right double quote. \*(C+ will |
21 | .\" give a nicer C++. Capital omega is used to do unbreakable dashes and | |
22 | .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, | |
23 | .\" nothing in troff, for use with C<>. | |
24 | .tr \(*W- | |
8b0cefbb | 25 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' |
984263bc | 26 | .ie n \{\ |
8b0cefbb JR |
27 | . ds -- \(*W- |
28 | . ds PI pi | |
29 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
30 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
31 | . ds L" "" | |
32 | . ds R" "" | |
33 | . ds C` "" | |
34 | . ds C' "" | |
984263bc MD |
35 | 'br\} |
36 | .el\{\ | |
8b0cefbb JR |
37 | . ds -- \|\(em\| |
38 | . ds PI \(*p | |
39 | . ds L" `` | |
40 | . ds R" '' | |
5a44c043 SW |
41 | . ds C` |
42 | . ds C' | |
984263bc | 43 | 'br\} |
8b0cefbb | 44 | .\" |
e257b235 PA |
45 | .\" Escape single quotes in literal strings from groff's Unicode transform. |
46 | .ie \n(.g .ds Aq \(aq | |
47 | .el .ds Aq ' | |
48 | .\" | |
8b0cefbb | 49 | .\" If the F register is turned on, we'll generate index entries on stderr for |
01185282 | 50 | .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
8b0cefbb JR |
51 | .\" entries marked with X<> in POD. Of course, you'll have to process the |
52 | .\" output yourself in some meaningful fashion. | |
5a44c043 SW |
53 | .\" |
54 | .\" Avoid warning from groff about undefined register 'F'. | |
55 | .de IX | |
984263bc | 56 | .. |
5a44c043 SW |
57 | .nr rF 0 |
58 | .if \n(.g .if rF .nr rF 1 | |
59 | .if (\n(rF:(\n(.g==0)) \{ | |
60 | . if \nF \{ | |
61 | . de IX | |
62 | . tm Index:\\$1\t\\n%\t"\\$2" | |
e257b235 | 63 | .. |
5a44c043 SW |
64 | . if !\nF==2 \{ |
65 | . nr % 0 | |
66 | . nr F 2 | |
67 | . \} | |
68 | . \} | |
e257b235 | 69 | .\} |
5a44c043 | 70 | .rr rF |
aac4ff6f | 71 | .\" |
8b0cefbb JR |
72 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). |
73 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
74 | . \" fudge factors for nroff and troff | |
984263bc | 75 | .if n \{\ |
8b0cefbb JR |
76 | . ds #H 0 |
77 | . ds #V .8m | |
78 | . ds #F .3m | |
79 | . ds #[ \f1 | |
80 | . ds #] \fP | |
984263bc MD |
81 | .\} |
82 | .if t \{\ | |
8b0cefbb JR |
83 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) |
84 | . ds #V .6m | |
85 | . ds #F 0 | |
86 | . ds #[ \& | |
87 | . ds #] \& | |
984263bc | 88 | .\} |
8b0cefbb | 89 | . \" simple accents for nroff and troff |
984263bc | 90 | .if n \{\ |
8b0cefbb JR |
91 | . ds ' \& |
92 | . ds ` \& | |
93 | . ds ^ \& | |
94 | . ds , \& | |
95 | . ds ~ ~ | |
96 | . ds / | |
984263bc MD |
97 | .\} |
98 | .if t \{\ | |
8b0cefbb JR |
99 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" |
100 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
101 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
102 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
103 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
104 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
984263bc | 105 | .\} |
8b0cefbb | 106 | . \" troff and (daisy-wheel) nroff accents |
984263bc MD |
107 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' |
108 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
109 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
110 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
111 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
112 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
113 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
114 | .ds ae a\h'-(\w'a'u*4/10)'e | |
115 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
8b0cefbb | 116 | . \" corrections for vroff |
984263bc MD |
117 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' |
118 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
8b0cefbb | 119 | . \" for low resolution devices (crt and lpr) |
984263bc MD |
120 | .if \n(.H>23 .if \n(.V>19 \ |
121 | \{\ | |
8b0cefbb JR |
122 | . ds : e |
123 | . ds 8 ss | |
124 | . ds o a | |
125 | . ds d- d\h'-1'\(ga | |
126 | . ds D- D\h'-1'\(hy | |
127 | . ds th \o'bp' | |
128 | . ds Th \o'LP' | |
129 | . ds ae ae | |
130 | . ds Ae AE | |
984263bc MD |
131 | .\} |
132 | .rm #[ #] #H #V #F C | |
8b0cefbb JR |
133 | .\" ======================================================================== |
134 | .\" | |
135 | .IX Title "bn_internal 3" | |
7dc78669 | 136 | .TH bn_internal 3 "2015-07-09" "1.0.1p" "OpenSSL" |
e257b235 PA |
137 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
138 | .\" way too many mistakes in technical documents. | |
139 | .if n .ad l | |
140 | .nh | |
984263bc MD |
141 | .SH "NAME" |
142 | bn_mul_words, bn_mul_add_words, bn_sqr_words, bn_div_words, | |
143 | bn_add_words, bn_sub_words, bn_mul_comba4, bn_mul_comba8, | |
144 | bn_sqr_comba4, bn_sqr_comba8, bn_cmp_words, bn_mul_normal, | |
145 | bn_mul_low_normal, bn_mul_recursive, bn_mul_part_recursive, | |
146 | bn_mul_low_recursive, bn_mul_high, bn_sqr_normal, bn_sqr_recursive, | |
147 | bn_expand, bn_wexpand, bn_expand2, bn_fix_top, bn_check_top, | |
74dab6c2 | 148 | bn_print, bn_dump, bn_set_max, bn_set_high, bn_set_low \- BIGNUM |
984263bc MD |
149 | library internal functions |
150 | .SH "SYNOPSIS" | |
8b0cefbb | 151 | .IX Header "SYNOPSIS" |
01185282 PA |
152 | .Vb 1 |
153 | \& #include <openssl/bn.h> | |
154 | \& | |
984263bc MD |
155 | \& BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); |
156 | \& BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, | |
157 | \& BN_ULONG w); | |
158 | \& void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num); | |
159 | \& BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d); | |
160 | \& BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp, | |
161 | \& int num); | |
162 | \& BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp, | |
163 | \& int num); | |
e257b235 | 164 | \& |
984263bc MD |
165 | \& void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b); |
166 | \& void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b); | |
167 | \& void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a); | |
168 | \& void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a); | |
e257b235 | 169 | \& |
984263bc | 170 | \& int bn_cmp_words(BN_ULONG *a, BN_ULONG *b, int n); |
e257b235 | 171 | \& |
984263bc MD |
172 | \& void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, |
173 | \& int nb); | |
174 | \& void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n); | |
175 | \& void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, | |
176 | \& int dna,int dnb,BN_ULONG *tmp); | |
177 | \& void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, | |
178 | \& int n, int tna,int tnb, BN_ULONG *tmp); | |
179 | \& void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, | |
180 | \& int n2, BN_ULONG *tmp); | |
181 | \& void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, | |
182 | \& int n2, BN_ULONG *tmp); | |
e257b235 | 183 | \& |
984263bc MD |
184 | \& void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp); |
185 | \& void bn_sqr_recursive(BN_ULONG *r, BN_ULONG *a, int n2, BN_ULONG *tmp); | |
e257b235 | 186 | \& |
984263bc MD |
187 | \& void mul(BN_ULONG r, BN_ULONG a, BN_ULONG w, BN_ULONG c); |
188 | \& void mul_add(BN_ULONG r, BN_ULONG a, BN_ULONG w, BN_ULONG c); | |
189 | \& void sqr(BN_ULONG r0, BN_ULONG r1, BN_ULONG a); | |
e257b235 | 190 | \& |
984263bc MD |
191 | \& BIGNUM *bn_expand(BIGNUM *a, int bits); |
192 | \& BIGNUM *bn_wexpand(BIGNUM *a, int n); | |
193 | \& BIGNUM *bn_expand2(BIGNUM *a, int n); | |
194 | \& void bn_fix_top(BIGNUM *a); | |
e257b235 | 195 | \& |
984263bc MD |
196 | \& void bn_check_top(BIGNUM *a); |
197 | \& void bn_print(BIGNUM *a); | |
198 | \& void bn_dump(BN_ULONG *d, int n); | |
199 | \& void bn_set_max(BIGNUM *a); | |
200 | \& void bn_set_high(BIGNUM *r, BIGNUM *a, int n); | |
201 | \& void bn_set_low(BIGNUM *r, BIGNUM *a, int n); | |
202 | .Ve | |
203 | .SH "DESCRIPTION" | |
8b0cefbb | 204 | .IX Header "DESCRIPTION" |
984263bc | 205 | This page documents the internal functions used by the OpenSSL |
8b0cefbb | 206 | \&\fB\s-1BIGNUM\s0\fR implementation. They are described here to facilitate |
984263bc MD |
207 | debugging and extending the library. They are \fInot\fR to be used by |
208 | applications. | |
01185282 | 209 | .SS "The \s-1BIGNUM\s0 structure" |
8b0cefbb | 210 | .IX Subsection "The BIGNUM structure" |
01185282 PA |
211 | .Vb 1 |
212 | \& typedef struct bignum_st BIGNUM; | |
213 | \& | |
214 | \& struct bignum_st | |
984263bc | 215 | \& { |
01185282 PA |
216 | \& BN_ULONG *d; /* Pointer to an array of \*(AqBN_BITS2\*(Aq bit chunks. */ |
217 | \& int top; /* Index of last used d +1. */ | |
218 | \& /* The next are internal book keeping for bn_expand. */ | |
219 | \& int dmax; /* Size of the d array. */ | |
220 | \& int neg; /* one if the number is negative */ | |
221 | \& int flags; | |
222 | \& }; | |
984263bc | 223 | .Ve |
8b0cefbb | 224 | .PP |
a561f9ff SS |
225 | The integer value is stored in \fBd\fR, a \fImalloc()\fRed array of words (\fB\s-1BN_ULONG\s0\fR), |
226 | least significant word first. A \fB\s-1BN_ULONG\s0\fR can be either 16, 32 or 64 bits | |
227 | in size, depending on the 'number of bits' (\fB\s-1BITS2\s0\fR) specified in | |
8b0cefbb | 228 | \&\f(CW\*(C`openssl/bn.h\*(C'\fR. |
984263bc | 229 | .PP |
01185282 | 230 | \&\fBdmax\fR is the size of the \fBd\fR array that has been allocated. \fBtop\fR |
a561f9ff | 231 | is the number of words being used, so for a value of 4, bn.d[0]=4 and |
984263bc | 232 | bn.top=1. \fBneg\fR is 1 if the number is negative. When a \fB\s-1BIGNUM\s0\fR is |
8b0cefbb | 233 | \&\fB0\fR, the \fBd\fR field can be \fB\s-1NULL\s0\fR and \fBtop\fR == \fB0\fR. |
984263bc | 234 | .PP |
01185282 PA |
235 | \&\fBflags\fR is a bit field of flags which are defined in \f(CW\*(C`openssl/bn.h\*(C'\fR. The |
236 | flags begin with \fB\s-1BN_FLG_\s0\fR. The macros BN_set_flags(b,n) and | |
237 | BN_get_flags(b,n) exist to enable or fetch flag(s) \fBn\fR from \fB\s-1BIGNUM\s0\fR | |
238 | structure \fBb\fR. | |
239 | .PP | |
984263bc | 240 | Various routines in this library require the use of temporary |
8b0cefbb | 241 | \&\fB\s-1BIGNUM\s0\fR variables during their execution. Since dynamic memory |
984263bc MD |
242 | allocation to create \fB\s-1BIGNUM\s0\fRs is rather expensive when used in |
243 | conjunction with repeated subroutine calls, the \fB\s-1BN_CTX\s0\fR structure is | |
244 | used. This structure contains \fB\s-1BN_CTX_NUM\s0\fR \fB\s-1BIGNUM\s0\fRs, see | |
8b0cefbb | 245 | \&\fIBN_CTX_start\fR\|(3). |
01185282 | 246 | .SS "Low-level arithmetic operations" |
8b0cefbb | 247 | .IX Subsection "Low-level arithmetic operations" |
984263bc MD |
248 | These functions are implemented in C and for several platforms in |
249 | assembly language: | |
250 | .PP | |
8b0cefbb | 251 | bn_mul_words(\fBrp\fR, \fBap\fR, \fBnum\fR, \fBw\fR) operates on the \fBnum\fR word |
984263bc MD |
252 | arrays \fBrp\fR and \fBap\fR. It computes \fBap\fR * \fBw\fR, places the result |
253 | in \fBrp\fR, and returns the high word (carry). | |
254 | .PP | |
8b0cefbb | 255 | bn_mul_add_words(\fBrp\fR, \fBap\fR, \fBnum\fR, \fBw\fR) operates on the \fBnum\fR |
984263bc MD |
256 | word arrays \fBrp\fR and \fBap\fR. It computes \fBap\fR * \fBw\fR + \fBrp\fR, places |
257 | the result in \fBrp\fR, and returns the high word (carry). | |
258 | .PP | |
8b0cefbb JR |
259 | bn_sqr_words(\fBrp\fR, \fBap\fR, \fBn\fR) operates on the \fBnum\fR word array |
260 | \&\fBap\fR and the 2*\fBnum\fR word array \fBap\fR. It computes \fBap\fR * \fBap\fR | |
e257b235 | 261 | word-wise, and places the low and high bytes of the result in \fBrp\fR. |
984263bc | 262 | .PP |
8b0cefbb | 263 | bn_div_words(\fBh\fR, \fBl\fR, \fBd\fR) divides the two word number (\fBh\fR,\fBl\fR) |
984263bc MD |
264 | by \fBd\fR and returns the result. |
265 | .PP | |
8b0cefbb | 266 | bn_add_words(\fBrp\fR, \fBap\fR, \fBbp\fR, \fBnum\fR) operates on the \fBnum\fR word |
984263bc MD |
267 | arrays \fBap\fR, \fBbp\fR and \fBrp\fR. It computes \fBap\fR + \fBbp\fR, places the |
268 | result in \fBrp\fR, and returns the high word (carry). | |
269 | .PP | |
8b0cefbb | 270 | bn_sub_words(\fBrp\fR, \fBap\fR, \fBbp\fR, \fBnum\fR) operates on the \fBnum\fR word |
984263bc MD |
271 | arrays \fBap\fR, \fBbp\fR and \fBrp\fR. It computes \fBap\fR \- \fBbp\fR, places the |
272 | result in \fBrp\fR, and returns the carry (1 if \fBbp\fR > \fBap\fR, 0 | |
273 | otherwise). | |
274 | .PP | |
8b0cefbb JR |
275 | bn_mul_comba4(\fBr\fR, \fBa\fR, \fBb\fR) operates on the 4 word arrays \fBa\fR and |
276 | \&\fBb\fR and the 8 word array \fBr\fR. It computes \fBa\fR*\fBb\fR and places the | |
984263bc MD |
277 | result in \fBr\fR. |
278 | .PP | |
8b0cefbb JR |
279 | bn_mul_comba8(\fBr\fR, \fBa\fR, \fBb\fR) operates on the 8 word arrays \fBa\fR and |
280 | \&\fBb\fR and the 16 word array \fBr\fR. It computes \fBa\fR*\fBb\fR and places the | |
984263bc MD |
281 | result in \fBr\fR. |
282 | .PP | |
8b0cefbb JR |
283 | bn_sqr_comba4(\fBr\fR, \fBa\fR, \fBb\fR) operates on the 4 word arrays \fBa\fR and |
284 | \&\fBb\fR and the 8 word array \fBr\fR. | |
984263bc | 285 | .PP |
8b0cefbb JR |
286 | bn_sqr_comba8(\fBr\fR, \fBa\fR, \fBb\fR) operates on the 8 word arrays \fBa\fR and |
287 | \&\fBb\fR and the 16 word array \fBr\fR. | |
984263bc MD |
288 | .PP |
289 | The following functions are implemented in C: | |
290 | .PP | |
8b0cefbb | 291 | bn_cmp_words(\fBa\fR, \fBb\fR, \fBn\fR) operates on the \fBn\fR word arrays \fBa\fR |
984263bc MD |
292 | and \fBb\fR. It returns 1, 0 and \-1 if \fBa\fR is greater than, equal and |
293 | less than \fBb\fR. | |
294 | .PP | |
8b0cefbb | 295 | bn_mul_normal(\fBr\fR, \fBa\fR, \fBna\fR, \fBb\fR, \fBnb\fR) operates on the \fBna\fR |
984263bc MD |
296 | word array \fBa\fR, the \fBnb\fR word array \fBb\fR and the \fBna\fR+\fBnb\fR word |
297 | array \fBr\fR. It computes \fBa\fR*\fBb\fR and places the result in \fBr\fR. | |
298 | .PP | |
8b0cefbb | 299 | bn_mul_low_normal(\fBr\fR, \fBa\fR, \fBb\fR, \fBn\fR) operates on the \fBn\fR word |
984263bc | 300 | arrays \fBr\fR, \fBa\fR and \fBb\fR. It computes the \fBn\fR low words of |
8b0cefbb | 301 | \&\fBa\fR*\fBb\fR and places the result in \fBr\fR. |
984263bc | 302 | .PP |
8b0cefbb | 303 | bn_mul_recursive(\fBr\fR, \fBa\fR, \fBb\fR, \fBn2\fR, \fBdna\fR, \fBdnb\fR, \fBt\fR) operates |
984263bc MD |
304 | on the word arrays \fBa\fR and \fBb\fR of length \fBn2\fR+\fBdna\fR and \fBn2\fR+\fBdnb\fR |
305 | (\fBdna\fR and \fBdnb\fR are currently allowed to be 0 or negative) and the 2*\fBn2\fR | |
306 | word arrays \fBr\fR and \fBt\fR. \fBn2\fR must be a power of 2. It computes | |
8b0cefbb | 307 | \&\fBa\fR*\fBb\fR and places the result in \fBr\fR. |
984263bc | 308 | .PP |
8b0cefbb | 309 | bn_mul_part_recursive(\fBr\fR, \fBa\fR, \fBb\fR, \fBn\fR, \fBtna\fR, \fBtnb\fR, \fBtmp\fR) |
984263bc | 310 | operates on the word arrays \fBa\fR and \fBb\fR of length \fBn\fR+\fBtna\fR and |
8b0cefbb | 311 | \&\fBn\fR+\fBtnb\fR and the 4*\fBn\fR word arrays \fBr\fR and \fBtmp\fR. |
984263bc | 312 | .PP |
8b0cefbb JR |
313 | bn_mul_low_recursive(\fBr\fR, \fBa\fR, \fBb\fR, \fBn2\fR, \fBtmp\fR) operates on the |
314 | \&\fBn2\fR word arrays \fBr\fR and \fBtmp\fR and the \fBn2\fR/2 word arrays \fBa\fR | |
984263bc MD |
315 | and \fBb\fR. |
316 | .PP | |
8b0cefbb JR |
317 | bn_mul_high(\fBr\fR, \fBa\fR, \fBb\fR, \fBl\fR, \fBn2\fR, \fBtmp\fR) operates on the |
318 | \&\fBn2\fR word arrays \fBr\fR, \fBa\fR, \fBb\fR and \fBl\fR (?) and the 3*\fBn2\fR word | |
984263bc MD |
319 | array \fBtmp\fR. |
320 | .PP | |
8b0cefbb | 321 | \&\fIBN_mul()\fR calls \fIbn_mul_normal()\fR, or an optimized implementation if the |
984263bc MD |
322 | factors have the same size: \fIbn_mul_comba8()\fR is used if they are 8 |
323 | words long, \fIbn_mul_recursive()\fR if they are larger than | |
8b0cefbb | 324 | \&\fB\s-1BN_MULL_SIZE_NORMAL\s0\fR and the size is an exact multiple of the word |
984263bc | 325 | size, and \fIbn_mul_part_recursive()\fR for others that are larger than |
8b0cefbb | 326 | \&\fB\s-1BN_MULL_SIZE_NORMAL\s0\fR. |
984263bc | 327 | .PP |
8b0cefbb JR |
328 | bn_sqr_normal(\fBr\fR, \fBa\fR, \fBn\fR, \fBtmp\fR) operates on the \fBn\fR word array |
329 | \&\fBa\fR and the 2*\fBn\fR word arrays \fBtmp\fR and \fBr\fR. | |
984263bc MD |
330 | .PP |
331 | The implementations use the following macros which, depending on the | |
332 | architecture, may use \*(L"long long\*(R" C operations or inline assembler. | |
8b0cefbb | 333 | They are defined in \f(CW\*(C`bn_lcl.h\*(C'\fR. |
984263bc | 334 | .PP |
8b0cefbb | 335 | mul(\fBr\fR, \fBa\fR, \fBw\fR, \fBc\fR) computes \fBw\fR*\fBa\fR+\fBc\fR and places the |
984263bc MD |
336 | low word of the result in \fBr\fR and the high word in \fBc\fR. |
337 | .PP | |
8b0cefbb | 338 | mul_add(\fBr\fR, \fBa\fR, \fBw\fR, \fBc\fR) computes \fBw\fR*\fBa\fR+\fBr\fR+\fBc\fR and |
984263bc MD |
339 | places the low word of the result in \fBr\fR and the high word in \fBc\fR. |
340 | .PP | |
8b0cefbb | 341 | sqr(\fBr0\fR, \fBr1\fR, \fBa\fR) computes \fBa\fR*\fBa\fR and places the low word |
984263bc | 342 | of the result in \fBr0\fR and the high word in \fBr1\fR. |
01185282 | 343 | .SS "Size changes" |
8b0cefbb JR |
344 | .IX Subsection "Size changes" |
345 | \&\fIbn_expand()\fR ensures that \fBb\fR has enough space for a \fBbits\fR bit | |
984263bc | 346 | number. \fIbn_wexpand()\fR ensures that \fBb\fR has enough space for an |
8b0cefbb | 347 | \&\fBn\fR word number. If the number has to be expanded, both macros |
984263bc MD |
348 | call \fIbn_expand2()\fR, which allocates a new \fBd\fR array and copies the |
349 | data. They return \fB\s-1NULL\s0\fR on error, \fBb\fR otherwise. | |
350 | .PP | |
8b0cefbb | 351 | The \fIbn_fix_top()\fR macro reduces \fBa\->top\fR to point to the most |
a561f9ff | 352 | significant non-zero word plus one when \fBa\fR has shrunk. |
01185282 | 353 | .SS "Debugging" |
8b0cefbb JR |
354 | .IX Subsection "Debugging" |
355 | \&\fIbn_check_top()\fR verifies that \f(CW\*(C`((a)\->top >= 0 && (a)\->top | |
01185282 | 356 | <= (a)\->dmax)\*(C'\fR. A violation will cause the program to abort. |
984263bc | 357 | .PP |
8b0cefbb | 358 | \&\fIbn_print()\fR prints \fBa\fR to stderr. \fIbn_dump()\fR prints \fBn\fR words at \fBd\fR |
984263bc MD |
359 | (in reverse order, i.e. most significant word first) to stderr. |
360 | .PP | |
01185282 | 361 | \&\fIbn_set_max()\fR makes \fBa\fR a static number with a \fBdmax\fR of its current size. |
984263bc | 362 | This is used by \fIbn_set_low()\fR and \fIbn_set_high()\fR to make \fBr\fR a read-only |
8b0cefbb | 363 | \&\fB\s-1BIGNUM\s0\fR that contains the \fBn\fR low or high words of \fBa\fR. |
984263bc MD |
364 | .PP |
365 | If \fB\s-1BN_DEBUG\s0\fR is not defined, \fIbn_check_top()\fR, \fIbn_print()\fR, \fIbn_dump()\fR | |
366 | and \fIbn_set_max()\fR are defined as empty macros. | |
367 | .SH "SEE ALSO" | |
74dab6c2 | 368 | .IX Header "SEE ALSO" |
8b0cefbb | 369 | \&\fIbn\fR\|(3) |