1 .\" Automatically generated by Pod::Man version 1.15
2 .\" Tue Jul 30 09:21:16 2002
5 .\" ======================================================================
6 .de Sh \" Subsection heading
14 .de Sp \" Vertical space (when we can't use .PP)
20 .ie \\n(.$>=3 .ne \\$3
24 .de Vb \" Begin verbatim text
29 .de Ve \" End verbatim text
34 .\" Set up some character translations and predefined strings. \*(-- will
35 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
36 .\" double quote, and \*(R" will give a right double quote. | will give a
37 .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used
38 .\" to do unbreakable dashes and therefore won't be available. \*(C` and
39 .\" \*(C' expand to `' in nroff, nothing in troff, for use with C<>
41 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
45 . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
46 . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
59 .\" If the F register is turned on, we'll generate index entries on stderr
60 .\" for titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and
61 .\" index entries marked with X<> in POD. Of course, you'll have to process
62 .\" the output yourself in some meaningful fashion.
65 . tm Index:\\$1\t\\n%\t"\\$2"
71 .\" For nroff, turn off justification. Always turn off hyphenation; it
72 .\" makes way too many mistakes in technical documents.
76 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
77 .\" Fear. Run. Save yourself. No user-serviceable parts.
79 . \" fudge factors for nroff and troff
88 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
94 . \" simple accents for nroff and troff
104 . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
105 . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
106 . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
107 . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
108 . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
109 . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
111 . \" troff and (daisy-wheel) nroff accents
112 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
113 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
114 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
115 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
116 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
117 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
118 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
119 .ds ae a\h'-(\w'a'u*4/10)'e
120 .ds Ae A\h'-(\w'A'u*4/10)'E
121 . \" corrections for vroff
122 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
123 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
124 . \" for low resolution devices (crt and lpr)
125 .if \n(.H>23 .if \n(.V>19 \
138 .\" ======================================================================
141 .TH BN_add 3 "0.9.6e" "2000-04-13" "OpenSSL"
144 BN_add, BN_sub, BN_mul, BN_div, BN_sqr, BN_mod, BN_mod_mul, BN_exp,
145 BN_mod_exp, BN_gcd \- arithmetic operations on BIGNUMs
147 .IX Header "SYNOPSIS"
149 \& #include <openssl/bn.h>
152 \& int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
155 \& int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
158 \& int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
161 \& int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
165 \& int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
168 \& int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
171 \& int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
175 \& int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
178 \& int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
179 \& const BIGNUM *m, BN_CTX *ctx);
182 \& int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
185 .IX Header "DESCRIPTION"
186 \&\fIBN_add()\fR adds \fBa\fR and \fBb\fR and places the result in \fBr\fR (\f(CW\*(C`r=a+b\*(C'\fR).
187 \&\fBr\fR may be the same \fB\s-1BIGNUM\s0\fR as \fBa\fR or \fBb\fR.
189 \&\fIBN_sub()\fR subtracts \fBb\fR from \fBa\fR and places the result in \fBr\fR (\f(CW\*(C`r=a\-b\*(C'\fR).
191 \&\fIBN_mul()\fR multiplies \fBa\fR and \fBb\fR and places the result in \fBr\fR (\f(CW\*(C`r=a*b\*(C'\fR).
192 \&\fBr\fR may be the same \fB\s-1BIGNUM\s0\fR as \fBa\fR or \fBb\fR.
193 For multiplication by powers of 2, use BN_lshift(3).
195 \&\fIBN_div()\fR divides \fBa\fR by \fBd\fR and places the result in \fBdv\fR and the
196 remainder in \fBrem\fR (\f(CW\*(C`dv=a/d, rem=a%d\*(C'\fR). Either of \fBdv\fR and \fBrem\fR may
197 be \s-1NULL\s0, in which case the respective value is not returned.
198 For division by powers of 2, use \fIBN_rshift\fR\|(3).
200 \&\fIBN_sqr()\fR takes the square of \fBa\fR and places the result in \fBr\fR
201 (\f(CW\*(C`r=a^2\*(C'\fR). \fBr\fR and \fBa\fR may be the same \fB\s-1BIGNUM\s0\fR.
202 This function is faster than BN_mul(r,a,a).
204 \&\fIBN_mod()\fR find the remainder of \fBa\fR divided by \fBm\fR and places it in
205 \&\fBrem\fR (\f(CW\*(C`rem=a%m\*(C'\fR).
207 \&\fIBN_mod_mul()\fR multiplies \fBa\fR by \fBb\fR and finds the remainder when
208 divided by \fBm\fR (\f(CW\*(C`r=(a*b)%m\*(C'\fR). \fBr\fR may be the same \fB\s-1BIGNUM\s0\fR as \fBa\fR
209 or \fBb\fR. For a more efficient algorithm, see
210 BN_mod_mul_montgomery(3); for repeated
211 computations using the same modulus, see BN_mod_mul_reciprocal(3).
213 \&\fIBN_exp()\fR raises \fBa\fR to the \fBp\fR\-th power and places the result in \fBr\fR
214 (\f(CW\*(C`r=a^p\*(C'\fR). This function is faster than repeated applications of
217 \&\fIBN_mod_exp()\fR computes \fBa\fR to the \fBp\fR\-th power modulo \fBm\fR (\f(CW\*(C`r=a^p %
218 m\*(C'\fR). This function uses less time and space than \fIBN_exp()\fR.
220 \&\fIBN_gcd()\fR computes the greatest common divisor of \fBa\fR and \fBb\fR and
221 places the result in \fBr\fR. \fBr\fR may be the same \fB\s-1BIGNUM\s0\fR as \fBa\fR or
224 For all functions, \fBctx\fR is a previously allocated \fB\s-1BN_CTX\s0\fR used for
225 temporary variables; see BN_CTX_new(3).
227 Unless noted otherwise, the result \fB\s-1BIGNUM\s0\fR must be different from
230 .IX Header "RETURN VALUES"
231 For all functions, 1 is returned for success, 0 on error. The return
232 value should always be checked (e.g., \f(CW\*(C`if (!BN_add(r,a,b)) goto err;\*(C'\fR).
233 The error codes can be obtained by ERR_get_error(3).
235 .IX Header "SEE ALSO"
236 bn(3), err(3), BN_CTX_new(3),
237 BN_add_word(3), BN_set_bit(3)
240 \&\fIBN_add()\fR, \fIBN_sub()\fR, \fIBN_div()\fR, \fIBN_sqr()\fR, \fIBN_mod()\fR, \fIBN_mod_mul()\fR,
241 \&\fIBN_mod_exp()\fR and \fIBN_gcd()\fR are available in all versions of SSLeay and
242 OpenSSL. The \fBctx\fR argument to \fIBN_mul()\fR was added in SSLeay
243 0.9.1b. \fIBN_exp()\fR appeared in SSLeay 0.9.0.