BN_mod_mul_reciprocal(3) OpenSSL BN_mod_mul_reciprocal(3) NNAAMMEE BN_mod_mul_reciprocal, BN_div_recp, BN_RECP_CTX_new, BN_RECP_CTX_init, BN_RECP_CTX_free, BN_RECP_CTX_set - modular multiplication using recip- rocal SSYYNNOOPPSSIISS #include BN_RECP_CTX *BN_RECP_CTX_new(void); void BN_RECP_CTX_init(BN_RECP_CTX *recp); void BN_RECP_CTX_free(BN_RECP_CTX *recp); int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx); int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *a, BN_RECP_CTX *recp, BN_CTX *ctx); int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_RECP_CTX *recp, BN_CTX *ctx); DDEESSCCRRIIPPTTIIOONN _B_N___m_o_d___m_u_l___r_e_c_i_p_r_o_c_a_l_(_) can be used to perform an efficient _B_N___m_o_d___m_u_l(3) operation when the operation will be performed repeatedly with the same modulus. It computes rr=(aa*bb)%mm using rreeccpp=1/mm, which is set as described below. ccttxx is a previously allocated BBNN__CCTTXX used for temporary variables. _B_N___R_E_C_P___C_T_X___n_e_w_(_) allocates and initializes a BBNN__RREECCPP structure. _B_N___R_E_C_P___C_T_X___i_n_i_t_(_) initializes an existing uninitialized BBNN__RREECCPP. _B_N___R_E_C_P___C_T_X___f_r_e_e_(_) frees the components of the BBNN__RREECCPP, and, if it was created by _B_N___R_E_C_P___C_T_X___n_e_w_(_), also the structure itself. _B_N___R_E_C_P___C_T_X___s_e_t_(_) stores mm in rreeccpp and sets it up for computing 1/mm and shifting it left by BN_num_bits(mm)+1 to make it an integer. The result and the number of bits it was shifted left will later be stored in rreeccpp. _B_N___d_i_v___r_e_c_p_(_) divides aa by mm using rreeccpp. It places the quotient in ddvv and the remainder in rreemm. The BBNN__RREECCPP__CCTTXX structure is defined as follows: typedef struct bn_recp_ctx_st { BIGNUM N; /* the divisor */ BIGNUM Nr; /* the reciprocal */ int num_bits; int shift; int flags; } BN_RECP_CTX; It cannot be shared between threads. RREETTUURRNN VVAALLUUEESS _B_N___R_E_C_P___C_T_X___n_e_w_(_) returns the newly allocated BBNN__RREECCPP__CCTTXX, and NULL on error. _B_N___R_E_C_P___C_T_X___i_n_i_t_(_) and _B_N___R_E_C_P___C_T_X___f_r_e_e_(_) have no return values. For the other functions, 1 is returned for success, 0 on error. The error codes can be obtained by _E_R_R___g_e_t___e_r_r_o_r(3). SSEEEE AALLSSOO _b_n(3), _E_R_R___g_e_t___e_r_r_o_r(3), _B_N___a_d_d(3), _B_N___C_T_X___n_e_w(3) HHIISSTTOORRYY BBNN__RREECCPP__CCTTXX was added in SSLeay 0.9.0. Before that, the function _B_N___r_e_c_i_p_r_o_c_a_l_(_) was used instead, and the _B_N___m_o_d___m_u_l___r_e_c_i_p_r_o_c_a_l_(_) argu- ments were different. 1.0.2u 2019-12-20 BN_mod_mul_reciprocal(3)