BN_DUMP(3)
๐ BN_DUMP(3) โ Library Functions Manual ๐
okay bestie, welcome to the BIGNUM backstage pass ๐ this is the Library Functions Manual entry for all the internal helper functions that make the big-number machine go brrr. โจ
๐ธ NAME ๐ธ
bn_mul_words, bn_mul_add_words, bn_sqr_words, bn_div_words, bn_add_words, bn_sub_words, bn_mul_comba4, bn_mul_comba8, bn_sqr_comba4, bn_sqr_comba8, bn_mul_normal, bn_expand, bn_wexpand โ BIGNUM library internal functions ๐ซถ
๐ฆ SYNOPSIS ๐ฆ
okay so hereโs the exact lineup, no cap:
#include bn_local.h
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);
void
bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num);
BN_ULONG
bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
BN_ULONG
bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp, int num);
BN_ULONG
bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp, int num);
void
bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b);
void
bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b);
void
bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a);
void
bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a);
void
bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb);
BIGNUM *
bn_expand(BIGNUM *a, int bits);
BIGNUM *
bn_wexpand(BIGNUM *a, int n);
๐ DESCRIPTION ๐
okay bestie, real talk: this page documents some internal functions used by the BIGNUM implementation. Theyโre described here to facilitate debugging and extending the library โ literally thatโs the whole vibe. ๐ ๏ธโจ
๐จ They are not to be used by applications. periodt. This is backstage-crew territory, not public-API main character energy. ๐
๐งธ The BIGNUM structure ๐งธ
typedef struct bignum_st BIGNUM;
struct bignum_st {
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 d, a malloc(3)'ed array of words (BN_ULONG), least significant word first ๐
BN_ULONG is a macro that expands to unsigned long (= uint64_t) on _LP64 platforms and unsigned int (= uint32_t) elsewhere. iykyk ๐
dmax 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 NULL and top == 0. ๐ซถ
flags is a bit field of flags which are defined in <openssl/bn.h>. The flags begin with BN_FLG_. The functions BN_set_flags(3) and BN_get_flags(3) enable or inspect flags. โจ
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 BN_CTX structure is used. This structure contains BN_CTX_NUM BIGNUMs; see BN_CTX_start(3). ๐
๐ฅ Low level arithmetic operations ๐ฅ
These functions are implemented in C and for several platforms in assembly language: ๐
bn_mul_words(rp, ap, num, w)โ operates on thenumword arraysrpandap. It computesap * w, places the result inrp, and returns the high word (carry). ๐งฎbn_mul_add_words(rp, ap, num, w)โ operates on thenumword arraysrpandap. It computesap * w + rp, places the result inrp, and returns the high word (carry). โจbn_sqr_words(rp, ap, num)โ operates on thenumword arrayapand the2*numword arrayap. It computesap * apword-wise, and places the low and high bytes of the result inrp. ๐ฆbn_div_words(h, l, d)โ divides the two word number(h, l)bydand returns the result. ๐bn_add_words(rp, ap, bp, num)โ operates on thenumword arraysap,bpandrp. It computesap + bp, places the result inrp, and returns the high word (carry). ๐bn_sub_words(rp, ap, bp, num)โ operates on thenumword arraysap,bpandrp. It computesap - bp, places the result inrp, and returns the carry (1ifbp โฉ ap,0otherwise). ๐ซถbn_mul_comba4(r, a, b)โ operates on the4word arraysaandband the8-wordarrayr. It computesa*band places the result inr. ๐bn_mul_comba8(r, a, b)โ operates on the8-wordarraysaandband the16-wordarrayr. It computesa*band places the result inr. โญbn_sqr_comba4(r, a, b)โ operates on the4-wordarraysaandband the8-wordarrayr. ๐bn_sqr_comba8(r, a, b)โ operates on the8-wordarraysaandband the16word arrayr. ๐ง
The following functions are implemented in C: ๐
bn_mul_normal(r, a, na, b, nb)โ operates on thenaword arraya, thenbword arrayband thena+nbword arrayr. It computesa*band places the result inr. ๐ฅ
BN_mul(3) calls bn_mul_comba4() if both factors are 4 words long, bn_mul_comba8() if both factors are 8 words long, or bn_mul_normal() otherwise. ๐
๐ Size changes ๐
bn_expand() ensures that b has enough space for a bits bit number. bn_wexpand() ensures that b has enough space for an n word number. They return 0 on error or 1 otherwise. โจ
๐ SEE ALSO ๐
BN_new(3) โ thatโs the whole see-also squad, bestie. ๐
xoxo, this page is from Debian, dated November 16, 2023, and itโs BN_DUMP(3) โ slay responsibly ๐ โจ
๐ฆ where this page comes from
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 ยท OpenSSL
- Copyright (c) 2000, 2003, 2006, 2009 The OpenSSL Project
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms