MyWebUniversity.com Home Page
 



OpenSolaris man pages main menu


OpenSL                                     bninternal(3openssl)



NAME
     bnmulwords, bnmuladdwords, bnsqrwords, bndivwords,
     bnaddwords, bnsubwords, bnmulcomba4, bnmulcomba8,
     bnsqrcomba4, bnsqrcomba8, bncmpwords, bnmulnormal,
     bnmullownormal, bnmulrecursive, bnmulpartrecursive,
     bnmullowrecursive, bnmulhigh, bnsqrnormal,
     bnsqrrecursive, bnexpand, bnwexpand, bnexpand2,
     bnfixtop, bnchecktop, bnprint, bndump, bnsetmax,
     bnsethigh, bnsetlow - BIGNUM library internal functions

SYNOPSIS
      BNULONG bnmulwords(BNULONG *rp, BNULONG *ap, int num, BNULONG w);
      BNULONG bnmuladdwords(BNULONG *rp, BNULONG *ap, int num,
        BNULONG w);
      void     bnsqrwords(BNULONG *rp, BNULONG *ap, int num);
      BNULONG bndivwords(BNULONG h, BNULONG l, BNULONG d);
      BNULONG bnaddwords(BNULONG *rp, BNULONG *ap, BNULONG *bp,
        int num);
      BNULONG bnsubwords(BNULONG *rp, BNULONG *ap, BNULONG *bp,
        int num);

      void bnmulcomba4(BNULONG *r, BNULONG *a, BNULONG *b);
      void bnmulcomba8(BNULONG *r, BNULONG *a, BNULONG *b);
      void bnsqrcomba4(BNULONG *r, BNULONG *a);
      void bnsqrcomba8(BNULONG *r, BNULONG *a);

      int bncmpwords(BNULONG *a, BNULONG *b, int n);

      void bnmulnormal(BNULONG *r, BNULONG *a, int na, BNULONG *b,
        int nb);
      void bnmullownormal(BNULONG *r, BNULONG *a, BNULONG *b, int n);
      void bnmulrecursive(BNULONG *r, BNULONG *a, BNULONG *b, int n2,
        int dna,int dnb,BNULONG *tmp);
      void bnmulpartrecursive(BNULONG *r, BNULONG *a, BNULONG *b,
        int n, int tna,int tnb, BNULONG *tmp);
      void bnmullowrecursive(BNULONG *r, BNULONG *a, BNULONG *b,
        int n2, BNULONG *tmp);
      void bnmulhigh(BNULONG *r, BNULONG *a, BNULONG *b, BNULONG *l,
        int n2, BNULONG *tmp);

      void bnsqrnormal(BNULONG *r, BNULONG *a, int n, BNULONG *tmp);
      void bnsqrrecursive(BNULONG *r, BNULONG *a, int n2, BNULONG *tmp);

      void mul(BNULONG r, BNULONG a, BNULONG w, BNULONG c);
      void muladd(BNULONG r, BNULONG a, BNULONG w, BNULONG c);
      void sqr(BNULONG r0, BNULONG r1, BNULONG a);

      BIGNUM *bnexpand(BIGNUM *a, int bits);
      BIGNUM *bnwexpand(BIGNUM *a, int n);
      BIGNUM *bnexpand2(BIGNUM *a, int n);
      void bnfixtop(BIGNUM *a);




OpenSL-0.9.8       Last change: Oct 11 2005                    1






OpenSL                                     bninternal(3openssl)



      void bnchecktop(BIGNUM *a);
      void bnprint(BIGNUM *a);
      void bndump(BNULONG *d, int n);
      void bnsetmax(BIGNUM *a);
      void bnsethigh(BIGNUM *r, BIGNUM *a, int n);
      void bnsetlow(BIGNUM *r, BIGNUM *a, int n);

DESCRIPTION
     This page documents the internal functions used by the
     OpenSL BIGNUM implementation. They are described here to
     facilitate debugging and extending the library. They are not
     to be used by applications.

     The BIGNUM structure

      typedef struct bignumst
             {
             int top;      /* number of words used in d */
             BNULONG *d;  /* pointer to an array containing the integer value */
             int max;      /* size of the d array */
             int neg;      /* sign */
             } BIGNUM;

     The integer value is stored in d, a malloc()ed array of
     words (BNULONG), least significant word first. A BNULONG
     can be either 16, 32 or 64 bits in size, depending on the
     'number of bits' (BITS2) specified in openssl/bn.h.

     max is the size of the d array that has been allocated.  top
     is the number of words being used, so for a value of 4,
     bn.d[0]=4 and bn.top=1.  neg is 1 if the number is negative.
     When a BIGNUM is 0, the d field can be NUL and top == 0.

     Various routines in this library require the use of
     temporary BIGNUM variables during their execution.  Since
     dynamic memory allocation to create BIGNUMs is rather
     expensive when used in conjunction with repeated subroutine
     calls, the BNCTX structure is used.  This structure
     contains BNCTXNUM BIGNUMs, see BNCTXstart(3).

     Low-level arithmetic operations

     These functions are implemented in C and for several
     platforms in assembly language:

     bnmulwords(rp, ap, num, w) operates on the num word arrays
     rp and ap.  It computes ap * w, places the result in rp, and
     returns the high word (carry).

     bnmuladdwords(rp, ap, num, w) operates on the num word
     arrays rp and ap.  It computes ap * w ] rp, places the
     result in rp, and returns the high word (carry).



OpenSL-0.9.8       Last change: Oct 11 2005                    2






OpenSL                                     bninternal(3openssl)



     bnsqrwords(rp, ap, n) operates on the num word array ap
     and the 2*num word array ap.  It computes ap * ap word-wise,
     and places the low and high bytes of the result in rp.

     bndivwords(h, l, d) divides the two word number (h,l) by d
     and returns the result.

     bnaddwords(rp, ap, bp, num) operates on the num word
     arrays ap, bp and rp.  It computes ap ] bp, places the
     result in rp, and returns the high word (carry).

     bnsubwords(rp, ap, bp, num) operates on the num word
     arrays ap, bp and rp.  It computes ap - bp, places the
     result in rp, and returns the carry (1 if bp > ap, 0
     otherwise).

     bnmulcomba4(r, a, b) operates on the 4 word arrays a and b
     and the 8 word array r.  It computes a*b and places the
     result in r.

     bnmulcomba8(r, a, b) operates on the 8 word arrays a and b
     and the 16 word array r.  It computes a*b and places the
     result in r.

     bnsqrcomba4(r, a, b) operates on the 4 word arrays a and b
     and the 8 word array r.

     bnsqrcomba8(r, a, b) operates on the 8 word arrays a and b
     and the 16 word array r.

     The following functions are implemented in C:

     bncmpwords(a, b, n) operates on the n word arrays a and b.
     It returns 1, 0 and -1 if a is greater than, equal and less
     than b.

     bnmulnormal(r, a, na, b, nb) operates on the na word array
     a, the nb word array b and the na]nb word array r.  It
     computes a*b and places the result in r.

     bnmullownormal(r, a, b, n) operates on the n word arrays
     r, a and b.  It computes the n low words of a*b and places
     the result in r.

     bnmulrecursive(r, a, b, n2, dna, dnb, t) operates on the
     word arrays a and b of length n2]dna and n2]dnb (dna and dnb
     are currently allowed to be 0 or negative) and the 2*n2 word
     arrays r and t.  n2 must be a power of 2.  It computes a*b
     and places the result in r.

     bnmulpartrecursive(r, a, b, n, tna, tnb, tmp) operates on
     the word arrays a and b of length n]tna and n]tnb and the



OpenSL-0.9.8       Last change: Oct 11 2005                    3






OpenSL                                     bninternal(3openssl)



     4*n word arrays r and tmp.

     bnmullowrecursive(r, a, b, n2, tmp) operates on the n2
     word arrays r and tmp and the n2/2 word arrays a and b.

     bnmulhigh(r, a, b, l, n2, tmp) operates on the n2 word
     arrays r, a, b and l (?) and the 3*n2 word array tmp.

     BNmul() calls bnmulnormal(), or an optimized
     implementation if the factors have the same size:
     bnmulcomba8() is used if they are 8 words long,
     bnmulrecursive() if they are larger than
     BNMULSIZENORMAL and the size is an exact multiple of the
     word size, and bnmulpartrecursive() for others that are
     larger than BNMULSIZENORMAL.

     bnsqrnormal(r, a, n, tmp) operates on the n word array a
     and the 2*n word arrays tmp and r.

     The implementations use the following macros which,
     depending on the architecture, may use "long long" C
     operations or inline assembler.  They are defined in
     bnlcl.h.

     mul(r, a, w, c) computes w*a]c and places the low word of
     the result in r and the high word in c.

     muladd(r, a, w, c) computes w*a]r]c and places the low word
     of the result in r and the high word in c.

     sqr(r0, r1, a) computes a*a and places the low word of the
     result in r0 and the high word in r1.

     Size changes

     bnexpand() ensures that b has enough space for a bits bit
     number.  bnwexpand() ensures that b has enough space for an
     n word number.  If the number has to be expanded, both
     macros call bnexpand2(), which allocates a new d array and
     copies the data.  They return NUL on error, b otherwise.

     The bnfixtop() macro reduces a->top to point to the most
     significant non-zero word plus one when a has shrunk.

     Debugging

     bnchecktop() verifies that ((a)->top >= 0 && (a)->top <=
     (a)->max).  A violation will cause the program to abort.

     bnprint() prints a to stderr. bndump() prints n words at d
     (in reverse order, i.e. most significant word first) to
     stderr.



OpenSL-0.9.8       Last change: Oct 11 2005                    4






OpenSL                                     bninternal(3openssl)



     bnsetmax() makes a a static number with a max of its
     current size.  This is used by bnsetlow() and
     bnsethigh() to make r a read-only BIGNUM that contains the
     n low or high words of a.

     If BNDEBUG is not defined, bnchecktop(), bnprint(),
     bndump() and bnsetmax() are defined as empty macros.

SEE ALSO
     bn(3)













































OpenSL-0.9.8       Last change: Oct 11 2005                    5



OpenSolaris man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™