Current Path : /usr/opt/openssl11/share/doc/openssl/html/man3/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //usr/opt/openssl11/share/doc/openssl/html/man3/BN_div.html |
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>BN_add</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rev="made" href="mailto:root@hsxx.drive.ne.jp" /> </head> <body style="background-color: white"> <!-- INDEX BEGIN --> <div name="index"> <p><a name="__index__"></a></p> <ul> <li><a href="#name">NAME</a></li> <li><a href="#synopsis">SYNOPSIS</a></li> <li><a href="#description">DESCRIPTION</a></li> <li><a href="#return_values">RETURN VALUES</a></li> <li><a href="#see_also">SEE ALSO</a></li> <li><a href="#copyright">COPYRIGHT</a></li> </ul> <hr name="index" /> </div> <!-- INDEX END --> <p> </p> <hr /> <h1><a name="name">NAME</a></h1> <p>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_mod_sqrt, BN_exp, BN_mod_exp, BN_gcd - arithmetic operations on BIGNUMs</p> <p> </p> <hr /> <h1><a name="synopsis">SYNOPSIS</a></h1> <pre> #include <openssl/bn.h></pre> <pre> int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);</pre> <pre> int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);</pre> <pre> int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);</pre> <pre> int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);</pre> <pre> int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d, BN_CTX *ctx);</pre> <pre> int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);</pre> <pre> int BN_nnmod(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);</pre> <pre> int BN_mod_add(BIGNUM *r, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);</pre> <pre> int BN_mod_sub(BIGNUM *r, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);</pre> <pre> int BN_mod_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);</pre> <pre> int BN_mod_sqr(BIGNUM *r, BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);</pre> <pre> BIGNUM *BN_mod_sqrt(BIGNUM *in, BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);</pre> <pre> int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);</pre> <pre> int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx);</pre> <pre> int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);</pre> <p> </p> <hr /> <h1><a name="description">DESCRIPTION</a></h1> <p><code>BN_add()</code> adds <em>a</em> and <em>b</em> and places the result in <em>r</em> (<code>r=a+b</code>). <em>r</em> may be the same <strong>BIGNUM</strong> as <em>a</em> or <em>b</em>.</p> <p><code>BN_sub()</code> subtracts <em>b</em> from <em>a</em> and places the result in <em>r</em> (<code>r=a-b</code>). <em>r</em> may be the same <strong>BIGNUM</strong> as <em>a</em> or <em>b</em>.</p> <p><code>BN_mul()</code> multiplies <em>a</em> and <em>b</em> and places the result in <em>r</em> (<code>r=a*b</code>). <em>r</em> may be the same <strong>BIGNUM</strong> as <em>a</em> or <em>b</em>. For multiplication by powers of 2, use <em>BN_lshift(3)</em>.</p> <p><code>BN_sqr()</code> takes the square of <em>a</em> and places the result in <em>r</em> (<code>r=a^2</code>). <em>r</em> and <em>a</em> may be the same <strong>BIGNUM</strong>. This function is faster than BN_mul(r,a,a).</p> <p><code>BN_div()</code> divides <em>a</em> by <em>d</em> and places the result in <em>dv</em> and the remainder in <em>rem</em> (<code>dv=a/d, rem=a%d</code>). Either of <em>dv</em> and <em>rem</em> may be <strong>NULL</strong>, in which case the respective value is not returned. The result is rounded towards zero; thus if <em>a</em> is negative, the remainder will be zero or negative. For division by powers of 2, use <code>BN_rshift(3)</code>.</p> <p><code>BN_mod()</code> corresponds to <code>BN_div()</code> with <em>dv</em> set to <strong>NULL</strong>.</p> <p><code>BN_nnmod()</code> reduces <em>a</em> modulo <em>m</em> and places the nonnegative remainder in <em>r</em>.</p> <p><code>BN_mod_add()</code> adds <em>a</em> to <em>b</em> modulo <em>m</em> and places the nonnegative result in <em>r</em>.</p> <p><code>BN_mod_sub()</code> subtracts <em>b</em> from <em>a</em> modulo <em>m</em> and places the nonnegative result in <em>r</em>.</p> <p><code>BN_mod_mul()</code> multiplies <em>a</em> by <em>b</em> and finds the nonnegative remainder respective to modulus <em>m</em> (<code>r=(a*b) mod m</code>). <em>r</em> may be the same <strong>BIGNUM</strong> as <em>a</em> or <em>b</em>. For more efficient algorithms for repeated computations using the same modulus, see <em>BN_mod_mul_montgomery(3)</em> and <em>BN_mod_mul_reciprocal(3)</em>.</p> <p><code>BN_mod_sqr()</code> takes the square of <em>a</em> modulo <strong>m</strong> and places the result in <em>r</em>.</p> <p><code>BN_mod_sqrt()</code> returns the modular square root of <em>a</em> such that <code>in^2 = a (mod p)</code>. The modulus <em>p</em> must be a prime, otherwise an error or an incorrect "result" will be returned. The result is stored into <em>in</em> which can be NULL. The result will be newly allocated in that case.</p> <p><code>BN_exp()</code> raises <em>a</em> to the <em>p</em>-th power and places the result in <em>r</em> (<code>r=a^p</code>). This function is faster than repeated applications of <code>BN_mul()</code>.</p> <p><code>BN_mod_exp()</code> computes <em>a</em> to the <em>p</em>-th power modulo <em>m</em> (<code>r=a^p % m</code>). This function uses less time and space than <code>BN_exp()</code>. Do not call this function when <strong>m</strong> is even and any of the parameters have the <strong>BN_FLG_CONSTTIME</strong> flag set.</p> <p><code>BN_gcd()</code> computes the greatest common divisor of <em>a</em> and <em>b</em> and places the result in <em>r</em>. <em>r</em> may be the same <strong>BIGNUM</strong> as <em>a</em> or <em>b</em>.</p> <p>For all functions, <em>ctx</em> is a previously allocated <strong>BN_CTX</strong> used for temporary variables; see <em>BN_CTX_new(3)</em>.</p> <p>Unless noted otherwise, the result <strong>BIGNUM</strong> must be different from the arguments.</p> <p> </p> <hr /> <h1><a name="return_values">RETURN VALUES</a></h1> <p>The <code>BN_mod_sqrt()</code> returns the result (possibly incorrect if <em>p</em> is not a prime), or NULL.</p> <p>For all remaining functions, 1 is returned for success, 0 on error. The return value should always be checked (e.g., <code>if (!BN_add(r,a,b)) goto err;</code>). The error codes can be obtained by <em>ERR_get_error(3)</em>.</p> <p> </p> <hr /> <h1><a name="see_also">SEE ALSO</a></h1> <p><em>ERR_get_error(3)</em>, <em>BN_CTX_new(3)</em>, <em>BN_add_word(3)</em>, <em>BN_set_bit(3)</em></p> <p> </p> <hr /> <h1><a name="copyright">COPYRIGHT</a></h1> <p>Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.</p> <p>Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <a href="https://www.openssl.org/source/license.html">https://www.openssl.org/source/license.html</a>.</p> </body> </html>