Remove indentation in the NAME section. There's really no need to
[openssl.git] / doc / crypto / BN_add.pod
1 =pod
2
3 =head1 NAME
4
5 BN_add, BN_sub, BN_mul, BN_div, BN_sqr, BN_mod, BN_mod_mul, BN_exp,
6 BN_mod_exp, BN_gcd - arithmetic operations on BIGNUMs
7
8 =head1 SYNOPSIS
9
10  #include <openssl/bn.h>
11
12  int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
13
14  int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
15
16  int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
17
18  int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
19          BN_CTX *ctx);
20
21  int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
22
23  int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
24
25  int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
26          BN_CTX *ctx);
27
28  int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
29
30  int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
31          const BIGNUM *m, BN_CTX *ctx);
32
33  int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
34
35 =head1 DESCRIPTION
36
37 BN_add() adds B<a> and B<b> and places the result in B<r> (C<r=a+b>).
38 B<r> may be the same B<BIGNUM> as B<a> or B<b>.
39
40 BN_sub() subtracts B<b> from B<a> and places the result in B<r> (C<r=a-b>).
41
42 BN_mul() multiplies B<a> and B<b> and places the result in B<r> (C<r=a*b>).
43 B<r> may be the same B<BIGNUM> as B<a> or B<b>.
44 For multiplication by powers of 2, use L<BN_lshift(3)|BN_lshift(3)>.
45
46 BN_div() divides B<a> by B<d> and places the result in B<dv> and the
47 remainder in B<rem> (C<dv=a/d, rem=a%d>). Either of B<dv> and B<rem> may
48 be NULL, in which case the respective value is not returned.
49 For division by powers of 2, use BN_rshift(3).
50
51 BN_sqr() takes the square of B<a> and places the result in B<r>
52 (C<r=a^2>). B<r> and B<a> may be the same B<BIGNUM>.
53 This function is faster than BN_mul(r,a,a).
54
55 BN_mod() find the remainder of B<a> divided by B<m> and places it in
56 B<rem> (C<rem=a%m>).
57
58 BN_mod_mul() multiplies B<a> by B<b> and finds the remainder when
59 divided by B<m> (C<r=(a*b)%m>). B<r> may be the same B<BIGNUM> as B<a>
60 or B<b>. For a more efficient algorithm, see
61 L<BN_mod_mul_montgomery(3)|BN_mod_mul_montgomery(3)>; for repeated
62 computations using the same modulus, see L<BN_mod_mul_reciprocal(3)|BN_mod_mul_reciprocal(3)>.
63
64 BN_exp() raises B<a> to the B<p>-th power and places the result in B<r>
65 (C<r=a^p>). This function is faster than repeated applications of
66 BN_mul().
67
68 BN_mod_exp() computes B<a> to the B<p>-th power modulo B<m> (C<r=a^p %
69 m>). This function uses less time and space than BN_exp().
70
71 BN_gcd() computes the greatest common divisor of B<a> and B<b> and
72 places the result in B<r>. B<r> may be the same B<BIGNUM> as B<a> or
73 B<b>.
74
75 For all functions, B<ctx> is a previously allocated B<BN_CTX> used for
76 temporary variables; see L<BN_CTX_new(3)|BN_CTX_new(3)>.
77
78 Unless noted otherwise, the result B<BIGNUM> must be different from
79 the arguments.
80
81 =head1 RETURN VALUES
82
83 For all functions, 1 is returned for success, 0 on error. The return
84 value should always be checked (e.g., C<if (!BN_add(r,a,b)) goto err;>).
85 The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
86
87 =head1 SEE ALSO
88
89 L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<BN_CTX_new(3)|BN_CTX_new(3)>,
90 L<BN_add_word(3)|BN_add_word(3)>, L<BN_set_bit(3)|BN_set_bit(3)>
91
92 =head1 HISTORY
93
94 BN_add(), BN_sub(), BN_div(), BN_sqr(), BN_mod(), BN_mod_mul(),
95 BN_mod_exp() and BN_gcd() are available in all versions of SSLeay and
96 OpenSSL. The B<ctx> argument to BN_mul() was added in SSLeay
97 0.9.1b. BN_exp() appeared in SSLeay 0.9.0.
98
99 =cut