BN_add(3) OpenSSL BN_add(3) NNAAMMEE BN_add, BN_sub, BN_mul, BN_sqr, BN_div, BN_mod, BN_nnmod, BN_mod_add, BN_mod_sub, BN_mod_mul, BN_mod_sqr, BN_exp, BN_mod_exp, BN_gcd - arith- metic operations on BIGNUMs SSYYNNOOPPSSIISS #include int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx); int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx); int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d, BN_CTX *ctx); int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); int BN_nnmod(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); int BN_mod_add(BIGNUM *r, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); int BN_mod_sub(BIGNUM *r, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); int BN_mod_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); int BN_mod_sqr(BIGNUM *r, BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx); int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx); int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx); DDEESSCCRRIIPPTTIIOONN _B_N___a_d_d_(_) adds _a and _b and places the result in _r ("r=a+b"). _r may be the same BBIIGGNNUUMM as _a or _b. _B_N___s_u_b_(_) subtracts _b from _a and places the result in _r ("r=a-b"). _B_N___m_u_l_(_) multiplies _a and _b and places the result in _r ("r=a*b"). _r may be the same BBIIGGNNUUMM as _a or _b. For multiplication by powers of 2, use _B_N___l_s_h_i_f_t(3). _B_N___s_q_r_(_) takes the square of _a and places the result in _r ("r=a^2"). _r and _a may be the same BBIIGGNNUUMM. This function is faster than BN_mul(r,a,a). _B_N___d_i_v_(_) divides _a by _d and places the result in _d_v and the remainder in _r_e_m ("dv=a/d, rem=a%d"). Either of _d_v and _r_e_m may be NNUULLLL, in which case the respective value is not returned. The result is rounded towards zero; thus if _a is negative, the remainder will be zero or neg- ative. For division by powers of 2, use _B_N___r_s_h_i_f_t(3). _B_N___m_o_d_(_) corresponds to _B_N___d_i_v_(_) with _d_v set to NNUULLLL. _B_N___n_n_m_o_d_(_) reduces _a modulo _m and places the non-negative remainder in _r. _B_N___m_o_d___a_d_d_(_) adds _a to _b modulo _m and places the non-negative result in _r. _B_N___m_o_d___s_u_b_(_) subtracts _b from _a modulo _m and places the non-negative result in _r. _B_N___m_o_d___m_u_l_(_) multiplies _a by _b and finds the non-negative remainder respective to modulus _m ("r=(a*b) mod m"). _r may be the same BBIIGGNNUUMM as _a or _b. For more efficient algorithms for repeated computations using the same modulus, see _B_N___m_o_d___m_u_l___m_o_n_t_g_o_m_e_r_y(3) and _B_N___m_o_d___m_u_l___r_e_c_i_p_r_o_- _c_a_l(3). _B_N___m_o_d___s_q_r_(_) takes the square of _a modulo mm and places the result in _r. _B_N___e_x_p_(_) raises _a to the _p-th power and places the result in _r ("r=a^p"). This function is faster than repeated applications of _B_N___m_u_l_(_). _B_N___m_o_d___e_x_p_(_) computes _a to the _p-th power modulo _m ("r=a^p % m"). This function uses less time and space than _B_N___e_x_p_(_). Do not call this func- tion when mm is even and any of the parameters have the BBNN__FFLLGG__CCOONNSSTTTTIIMMEE flag set. _B_N___g_c_d_(_) computes the greatest common divisor of _a and _b and places the result in _r. _r may be the same BBIIGGNNUUMM as _a or _b. For all functions, _c_t_x is a previously allocated BBNN__CCTTXX used for tempo- rary variables; see _B_N___C_T_X___n_e_w(3). Unless noted otherwise, the result BBIIGGNNUUMM must be different from the arguments. RREETTUURRNN VVAALLUUEESS For all functions, 1 is returned for success, 0 on error. The return value should always be checked (e.g., "if (!BN_add(r,a,b)) goto err;"). 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___C_T_X___n_e_w(3), _B_N___a_d_d___w_o_r_d(3), _B_N___s_e_t___b_i_t(3) HHIISSTTOORRYY _B_N___a_d_d_(_), _B_N___s_u_b_(_), _B_N___s_q_r_(_), _B_N___d_i_v_(_), _B_N___m_o_d_(_), _B_N___m_o_d___m_u_l_(_), _B_N___m_o_d___e_x_p_(_) and _B_N___g_c_d_(_) are available in all versions of SSLeay and OpenSSL. The _c_t_x argument to _B_N___m_u_l_(_) was added in SSLeay 0.9.1b. _B_N___e_x_p_(_) appeared in SSLeay 0.9.0. _B_N___n_n_m_o_d_(_), _B_N___m_o_d___a_d_d_(_), _B_N___m_o_d___s_u_b_(_), and _B_N___m_o_d___s_q_r_(_) were added in OpenSSL 0.9.7. 1.0.2u 2019-12-20 BN_add(3)