X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=doc%2Fcrypto%2Fbn_internal.pod;h=91840b0f0d63cec7fb409c975c375ccf521e3b53;hp=4263c1897fdbdf7f1ab15b4c5fc42b3f57a25960;hb=93b83d0626e73bb09559ce85aefa418ac7318d59;hpb=5ee6cc11626114223fbcae1e51bc9302652406d2 diff --git a/doc/crypto/bn_internal.pod b/doc/crypto/bn_internal.pod index 4263c1897f..91840b0f0d 100644 --- a/doc/crypto/bn_internal.pod +++ b/doc/crypto/bn_internal.pod @@ -13,6 +13,8 @@ library internal functions =head1 SYNOPSIS + #include + BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); @@ -34,9 +36,9 @@ library internal functions int nb); void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n); void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, - BN_ULONG *tmp); + int dna,int dnb,BN_ULONG *tmp); void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, - int tn, int n, BN_ULONG *tmp); + int n, int tna,int tnb, BN_ULONG *tmp); void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, BN_ULONG *tmp); void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, @@ -70,40 +72,40 @@ applications. =head2 The BIGNUM structure - typedef struct bignum_st + typedef struct bignum_st BIGNUM; + + struct bignum_st { - int top; /* index of last used d (most significant word) */ - BN_ULONG *d; /* pointer to an array of 'BITS2' bit chunks */ - int max; /* size of the d array */ - int neg; /* sign */ - } BIGNUM; - -The big number is stored in B, a malloc()ed array of Bs, -least significant first. A B can be either 16, 32 or 64 bits -in size (B), depending on the 'number of bits' specified in + BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ + int top; /* Index of last used d +1. */ + /* The next are internal book keeping for bn_expand. */ + int dmax; /* Size of the d array. */ + int neg; /* one if the number is negative */ + int flags; + }; + + +The integer value is stored in B, a malloc()ed array of words (B), +least significant word first. A B can be either 16, 32 or 64 bits +in size, depending on the 'number of bits' (B) specified in C. -B is the size of the B array that has been allocated. B -is the 'last' entry being used, so for a value of 4, bn.d[0]=4 and +B is the size of the B array that has been allocated. B +is the number of words being used, so for a value of 4, bn.d[0]=4 and bn.top=1. B is 1 if the number is negative. When a B is B<0>, the B field can be B and B == B<0>. +B is a bit field of flags which are defined in C. The +flags begin with B. The macros BN_set_flags(b,n) and +BN_get_flags(b,n) exist to enable or fetch flag(s) B from B +structure B. + Various routines in this library require the use of temporary B variables during their execution. Since dynamic memory allocation to create Bs is rather expensive when used in conjunction with repeated subroutine calls, the B structure is -used. This structure contains B Bs. -B is the maximum number of temporary Bs any -publicly exported function will use. - - #define BN_CTX_NUM 12 - typedef struct bignum_ctx - { - int tos; /* top of stack */ - BIGNUM *bn[BN_CTX_NUM]; /* The variables */ - } BN_CTX; - -B is the index of the first unused B in the B array. +used. This structure contains B Bs, see +L. =head2 Low-level arithmetic operations @@ -159,17 +161,18 @@ word array B, the B word array B and the B+B word array B. It computes B*B and places the result in B. bn_mul_low_normal(B, B, B, B) operates on the B word -arrays B, B und B. It computes the B low words of +arrays B, B and B. It computes the B low words of B*B and places the result in B. -bn_mul_recursive(B, B, B, B, B) operates on the B -word arrays B and B and the 2*B word arrays B and B. -B must be a power of 2. It computes B*B and places the -result in B. +bn_mul_recursive(B, B, B, B, B, B, B) operates +on the word arrays B and B of length B+B and B+B +(B and B are currently allowed to be 0 or negative) and the 2*B +word arrays B and B. B must be a power of 2. It computes +B*B and places the result in B. -bn_mul_part_recursive(B, B, B, B, B, B) operates -on the B+B word arrays B and B and the 4*B word arrays -B and B. +bn_mul_part_recursive(B, B, B, B, B, B, B) +operates on the word arrays B and B of length B+B and +B+B and the 4*B word arrays B and B. bn_mul_low_recursive(B, B, B, B, B) operates on the B word arrays B and B and the B/2 word arrays B @@ -210,20 +213,20 @@ B word number. If the number has to be expanded, both macros call bn_expand2(), which allocates a new B array and copies the data. They return B on error, B otherwise. -The bn_fix_top() macro reduces Btop> to most significant -non-zero word when B has shrunk. +The bn_fix_top() macro reduces Btop> to point to the most +significant non-zero word plus one when B has shrunk. =head2 Debugging -bn_check_top() verifies that C<((a)->top E= 0 && (a)-Etop -E= (a)-Emax)>. A violation will cause the program to abort. +bn_check_top() verifies that C<((a)-Etop E= 0 && (a)-Etop +E= (a)-Edmax)>. A violation will cause the program to abort. bn_print() prints B to stderr. bn_dump() prints B words at B (in reverse order, i.e. most significant word first) to stderr. -bn_set_max() makes B a static number with a B of its current size. +bn_set_max() makes B a static number with a B of its current size. This is used by bn_set_low() and bn_set_high() to make B a read-only -B that contains the B lower or higher words of B. +B that contains the B low or high words of B. If B is not defined, bn_check_top(), bn_print(), bn_dump() and bn_set_max() are defined as empty macros.