BN_DUMP(3)

๐Ÿ“ฆ version 4.1.0, in opensuse-leap 16.0

๐ŸŽ€ 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 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, num) โ€” 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_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(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