1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimBN_mod_mul_reciprocal, BN_div_recp, BN_RECP_CTX_new, 6e71b7053SJung-uk KimBN_RECP_CTX_free, BN_RECP_CTX_set - modular multiplication using 7e71b7053SJung-uk Kimreciprocal 8e71b7053SJung-uk Kim 9e71b7053SJung-uk Kim=head1 SYNOPSIS 10e71b7053SJung-uk Kim 11e71b7053SJung-uk Kim #include <openssl/bn.h> 12e71b7053SJung-uk Kim 13e71b7053SJung-uk Kim BN_RECP_CTX *BN_RECP_CTX_new(void); 14e71b7053SJung-uk Kim void BN_RECP_CTX_free(BN_RECP_CTX *recp); 15e71b7053SJung-uk Kim 16e71b7053SJung-uk Kim int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx); 17e71b7053SJung-uk Kim 18*b077aed3SPierre Pronchery int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, BN_RECP_CTX *recp, 19e71b7053SJung-uk Kim BN_CTX *ctx); 20e71b7053SJung-uk Kim 21*b077aed3SPierre Pronchery int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, 22e71b7053SJung-uk Kim BN_RECP_CTX *recp, BN_CTX *ctx); 23e71b7053SJung-uk Kim 24e71b7053SJung-uk Kim=head1 DESCRIPTION 25e71b7053SJung-uk Kim 26e71b7053SJung-uk KimBN_mod_mul_reciprocal() can be used to perform an efficient 27e71b7053SJung-uk KimL<BN_mod_mul(3)> operation when the operation will be performed 28e71b7053SJung-uk Kimrepeatedly with the same modulus. It computes B<r>=(B<a>*B<b>)%B<m> 29e71b7053SJung-uk Kimusing B<recp>=1/B<m>, which is set as described below. B<ctx> is a 30e71b7053SJung-uk Kimpreviously allocated B<BN_CTX> used for temporary variables. 31e71b7053SJung-uk Kim 32e71b7053SJung-uk KimBN_RECP_CTX_new() allocates and initializes a B<BN_RECP> structure. 33e71b7053SJung-uk Kim 34e71b7053SJung-uk KimBN_RECP_CTX_free() frees the components of the B<BN_RECP>, and, if it 35e71b7053SJung-uk Kimwas created by BN_RECP_CTX_new(), also the structure itself. 36e71b7053SJung-uk KimIf B<recp> is NULL, nothing is done. 37e71b7053SJung-uk Kim 38e71b7053SJung-uk KimBN_RECP_CTX_set() stores B<m> in B<recp> and sets it up for computing 39e71b7053SJung-uk Kim1/B<m> and shifting it left by BN_num_bits(B<m>)+1 to make it an 40e71b7053SJung-uk Kiminteger. The result and the number of bits it was shifted left will 41e71b7053SJung-uk Kimlater be stored in B<recp>. 42e71b7053SJung-uk Kim 43e71b7053SJung-uk KimBN_div_recp() divides B<a> by B<m> using B<recp>. It places the quotient 44e71b7053SJung-uk Kimin B<dv> and the remainder in B<rem>. 45e71b7053SJung-uk Kim 46e71b7053SJung-uk KimThe B<BN_RECP_CTX> structure cannot be shared between threads. 47e71b7053SJung-uk Kim 48e71b7053SJung-uk Kim=head1 RETURN VALUES 49e71b7053SJung-uk Kim 50e71b7053SJung-uk KimBN_RECP_CTX_new() returns the newly allocated B<BN_RECP_CTX>, and NULL 51e71b7053SJung-uk Kimon error. 52e71b7053SJung-uk Kim 53e71b7053SJung-uk KimBN_RECP_CTX_free() has no return value. 54e71b7053SJung-uk Kim 55e71b7053SJung-uk KimFor the other functions, 1 is returned for success, 0 on error. 56e71b7053SJung-uk KimThe error codes can be obtained by L<ERR_get_error(3)>. 57e71b7053SJung-uk Kim 58e71b7053SJung-uk Kim=head1 SEE ALSO 59e71b7053SJung-uk Kim 60e71b7053SJung-uk KimL<ERR_get_error(3)>, L<BN_add(3)>, 61e71b7053SJung-uk KimL<BN_CTX_new(3)> 62e71b7053SJung-uk Kim 63e71b7053SJung-uk Kim=head1 HISTORY 64e71b7053SJung-uk Kim 65e71b7053SJung-uk KimBN_RECP_CTX_init() was removed in OpenSSL 1.1.0 66e71b7053SJung-uk Kim 67e71b7053SJung-uk Kim=head1 COPYRIGHT 68e71b7053SJung-uk Kim 69*b077aed3SPierre ProncheryCopyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. 70e71b7053SJung-uk Kim 71*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 72e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 73e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 74e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 75e71b7053SJung-uk Kim 76e71b7053SJung-uk Kim=cut 77