Run ispell.
[openssl.git] / doc / crypto / BN_mod_mul_reciprocal.pod
1 =pod
2
3 =head1 NAME
4
5 BN_mod_mul_reciprocal, BN_RECP_CTX_new, BN_RECP_CTX_init,
6 BN_RECP_CTX_free, BN_RECP_CTX_set - Modular multiplication using
7 reciprocal
8
9 =head1 SYNOPSIS
10
11  #include <openssl/bn.h>
12
13  BN_RECP_CTX *BN_RECP_CTX_new(void);
14  void BN_RECP_CTX_init(BN_RECP_CTX *recp);
15  void BN_RECP_CTX_free(BN_RECP_CTX *recp);
16
17  int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
18
19  int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
20         BN_RECP_CTX *recp, BN_CTX *ctx);
21
22 =head1 DESCRIPTION
23
24 BN_mod_mul_reciprocal() can be used to perform an efficient
25 L<BN_mod_mul(3)|BN_mod_mul(3)> operation when the operation will be performed
26 repeatedly with the same modulus. It computes B<r>=(B<a>*B<b>)%B<m>
27 using B<recp>=1/B<m>, which is set as described below.  B<ctx> is a
28 previously allocated B<BN_CTX> used for temporary variables.
29
30 BN_RECP_CTX_new() allocates and initializes a B<BN_RECP> structure.
31 BN_RECP_CTX_init() initializes an existing uninitialized B<BN_RECP>.
32
33 BN_RECP_CTX_free() frees the components of the B<BN_RECP>, and, if it
34 was created by BN_RECP_CTX_new(), also the structure itself.
35
36 BN_RECP_CTX_set() computes 1/B<m> and shifts it left by
37 BN_num_bits(B<m>)+1 to make it an integer. The result and the
38 number of bits it was shifted left are stored in B<recp>.
39
40 The B<BN_RECP_CTX> structure is defined as follows:
41
42  typedef struct bn_recp_ctx_st
43         {
44         BIGNUM N;       /* the divisor */
45         BIGNUM Nr;      /* the reciprocal */
46         int num_bits;
47         int shift;
48         int flags;
49         } BN_RECP_CTX;
50
51 It cannot be shared between threads.
52
53 =head1 RETURN VALUES
54
55 BN_RECP_CTX_new() returns the newly allocated B<BN_RECP_CTX>, and NULL
56 on error.
57
58 BN_RECP_CTX_init() and BN_RECP_CTX_free() have no return values.
59
60 For the other functions, 1 is returned for success, 0 on error.
61 The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
62
63 =head1 SEE ALSO
64
65 L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<BN_add(3)|BN_add(3)>,
66 L<BN_CTX_new(3)|BN_CTX_new(3)>
67
68 =head1 HISTORY
69
70 B<BN_RECP_CTX> was added in SSLeay 0.9.0. Before that, the function
71 BN_reciprocal() was used instead, and the BN_mod_mul_reciprocal()
72 arguments were different.
73
74 =cut