RAND_load_file(..., -1) now means "read the complete file";
[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() substracts 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
44 BN_div() divides B<a> by B<d> and places the result in B<dv> and the
45 remainder in B<rem> (C<dv=a/d, rem=a%d>). Either of B<dv> and B<rem> may
46 be NULL, in which case the respective value is not returned.
47
48 BN_sqr() takes the square of B<a> and places the result in B<r>
49 (C<r=a^2>). B<r> and B<a> may be the same B<BIGNUM>.
50 This function is faster than BN_mul(r,a,a).
51
52 BN_mod() find the remainder of B<a> divided by B<m> and places it in
53 B<rem> (C<rem=a%m>).
54
55 BN_mod_mul() multiplies B<a> by B<b> and finds the remainder when
56 divided by B<m> (C<r=(a*b)%m>). B<r> may be the same B<BIGNUM> as B<a>
57 or B<b>. For a more efficient algorithm, see
58 L<BN_mod_mul_montgomery(3)>; for repeated computations using the same
59 modulus, see L<BN_mod_mul_reciprocal(3)>.
60
61 BN_exp() raises B<a> to the B<p>-th power and places the result in B<r>
62 (C<r=a^p>). This function is faster than repeated applications of
63 BN_mul().
64
65 BN_mod_exp() computes B<a> to the B<p>-th power modulo B<m> (C<r=a^p %
66 m>). This function uses less time and space than BN_exp().
67
68 BN_gcd() computes the greatest common divisor of B<a> and B<b> and
69 places the result in B<r>. B<r> may be the same B<BIGNUM> as B<a> or
70 B<b>.
71
72 For all functions, B<ctx> is a previously allocated B<BN_CTX> used for
73 temporary variables; see L<BN_CTX_new(3)>.
74
75 Unless noted otherwise, the result B<BIGNUM> must be different from
76 the arguments.
77
78 =head1 RETURN VALUES
79
80 For all functions, 1 is returned for success, 0 on error. The return
81 value should always be checked (e.g., C<if (!BN_add(r,a,b)) goto err;>).
82 The error codes can be obtained by ERR_get_error(3).
83
84 =head1 SEE ALSO
85
86 bn(3), err(3), BN_CTX_new(3), BN_add_word(3), BN_set_bit(3)
87
88 =head1 HISTORY
89
90 BN_add(), BN_sub(), BN_div(), BN_sqr(), BN_mod(), BN_mod_mul(),
91 BN_mod_exp() and BN_gcd() are available in all versions of SSLeay and
92 OpenSSL. The B<ctx> argument to BN_mul() was added in SSLeay
93 0.9.1b. BN_exp() appeared in SSLeay 0.9.0.
94
95 =cut