These functions are implemented in C and for several platforms in assembly language:
bn_mul_words(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).
bn_mul_add_words(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).
bn_sqr_words(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.
bn_div_words(h, l, d) divides the two word number (h,l) by d and returns the result.
bn_add_words(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).
bn_sub_words(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).
bn_mul_comba4(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.
bn_mul_comba8(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.
bn_sqr_comba4(r, a, b) operates on the 4 word arrays a and b and the 8 word array r.
bn_sqr_comba8(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:
bn_cmp_words(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.
bn_mul_normal(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.
bn_mul_low_normal(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.
bn_mul_recursive(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.
bn_mul_part_recursive(r, a, b, n, tna, tnb, tmp) operates on the word arrays a and b of length n+tna and n+tnb and the 4*n word arrays r and tmp.
bn_mul_low_recursive(r, a, b, n2, tmp) operates on the n2 word arrays r and tmp and the n2/2 word arrays a and b.
bn_mul_high(r, a, b, l, n2, tmp) operates on the n2 word arrays r, a, b and l (?) and the 3*n2 word array tmp.
BN_mul() calls bn_mul_normal(), or an optimized implementation if the factors have the same size: bn_mul_comba8() is used if they are 8 words long, bn_mul_recursive() if they are larger than BN_MULL_SIZE_NORMAL and the size is an exact multiple of the word size, and bn_mul_part_recursive() for others that are larger than BN_MULL_SIZE_NORMAL.
bn_sqr_normal(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 "bn_lcl.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.
mul_add(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.