Ulf Möller | dd8dec6 | 2000-01-23 22:06:24 +0000 | [diff] [blame] | 1 | =pod |
| 2 | |
| 3 | =head1 NAME |
| 4 | |
Richard Levitte | e1b78bc | 2000-09-14 21:23:28 +0000 | [diff] [blame] | 5 | BN_mod_mul_reciprocal, BN_div_recp, BN_RECP_CTX_new, BN_RECP_CTX_init, |
Ulf Möller | 4d524e1 | 2000-02-24 11:55:57 +0000 | [diff] [blame] | 6 | BN_RECP_CTX_free, BN_RECP_CTX_set - modular multiplication using |
Ulf Möller | dd8dec6 | 2000-01-23 22:06:24 +0000 | [diff] [blame] | 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 | |
Ulf Möller | cae55bf | 2000-02-06 15:56:59 +0000 | [diff] [blame] | 19 | int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *a, BN_RECP_CTX *recp, |
| 20 | BN_CTX *ctx); |
| 21 | |
Ulf Möller | dd8dec6 | 2000-01-23 22:06:24 +0000 | [diff] [blame] | 22 | int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b, |
| 23 | BN_RECP_CTX *recp, BN_CTX *ctx); |
| 24 | |
| 25 | =head1 DESCRIPTION |
| 26 | |
| 27 | BN_mod_mul_reciprocal() can be used to perform an efficient |
Richard Levitte | bb075f8 | 2000-01-27 01:25:31 +0000 | [diff] [blame] | 28 | L<BN_mod_mul(3)|BN_mod_mul(3)> operation when the operation will be performed |
Ulf Möller | dd8dec6 | 2000-01-23 22:06:24 +0000 | [diff] [blame] | 29 | repeatedly with the same modulus. It computes B<r>=(B<a>*B<b>)%B<m> |
| 30 | using B<recp>=1/B<m>, which is set as described below. B<ctx> is a |
| 31 | previously allocated B<BN_CTX> used for temporary variables. |
| 32 | |
| 33 | BN_RECP_CTX_new() allocates and initializes a B<BN_RECP> structure. |
| 34 | BN_RECP_CTX_init() initializes an existing uninitialized B<BN_RECP>. |
| 35 | |
| 36 | BN_RECP_CTX_free() frees the components of the B<BN_RECP>, and, if it |
| 37 | was created by BN_RECP_CTX_new(), also the structure itself. |
| 38 | |
Ulf Möller | cae55bf | 2000-02-06 15:56:59 +0000 | [diff] [blame] | 39 | BN_RECP_CTX_set() stores B<m> in B<recp> and sets it up for computing |
| 40 | 1/B<m> and shifting it left by BN_num_bits(B<m>)+1 to make it an |
| 41 | integer. The result and the number of bits it was shifted left will |
| 42 | later be stored in B<recp>. |
| 43 | |
| 44 | BN_div_recp() divides B<a> by B<m> using B<recp>. It places the quotient |
| 45 | in B<dv> and the remainder in B<rem>. |
Ulf Möller | dd8dec6 | 2000-01-23 22:06:24 +0000 | [diff] [blame] | 46 | |
| 47 | The B<BN_RECP_CTX> structure is defined as follows: |
| 48 | |
| 49 | typedef struct bn_recp_ctx_st |
| 50 | { |
| 51 | BIGNUM N; /* the divisor */ |
| 52 | BIGNUM Nr; /* the reciprocal */ |
| 53 | int num_bits; |
| 54 | int shift; |
| 55 | int flags; |
| 56 | } BN_RECP_CTX; |
| 57 | |
| 58 | It cannot be shared between threads. |
| 59 | |
| 60 | =head1 RETURN VALUES |
| 61 | |
| 62 | BN_RECP_CTX_new() returns the newly allocated B<BN_RECP_CTX>, and NULL |
| 63 | on error. |
| 64 | |
| 65 | BN_RECP_CTX_init() and BN_RECP_CTX_free() have no return values. |
| 66 | |
| 67 | For the other functions, 1 is returned for success, 0 on error. |
Richard Levitte | bb075f8 | 2000-01-27 01:25:31 +0000 | [diff] [blame] | 68 | The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. |
Ulf Möller | dd8dec6 | 2000-01-23 22:06:24 +0000 | [diff] [blame] | 69 | |
| 70 | =head1 SEE ALSO |
| 71 | |
Richard Levitte | 6859cf7 | 2002-09-25 13:33:28 +0000 | [diff] [blame] | 72 | L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<BN_add(3)|BN_add(3)>, |
Richard Levitte | bb075f8 | 2000-01-27 01:25:31 +0000 | [diff] [blame] | 73 | L<BN_CTX_new(3)|BN_CTX_new(3)> |
Ulf Möller | dd8dec6 | 2000-01-23 22:06:24 +0000 | [diff] [blame] | 74 | |
| 75 | =head1 HISTORY |
| 76 | |
| 77 | B<BN_RECP_CTX> was added in SSLeay 0.9.0. Before that, the function |
| 78 | BN_reciprocal() was used instead, and the BN_mod_mul_reciprocal() |
Ulf Möller | e93f9a3 | 2000-01-27 01:50:42 +0000 | [diff] [blame] | 79 | arguments were different. |
Ulf Möller | dd8dec6 | 2000-01-23 22:06:24 +0000 | [diff] [blame] | 80 | |
| 81 | =cut |