OpenSL bn(3openssl)
NAME
bn - multiprecision integer arithmetics
SYNOPSIS
#include
BIGNUM *BNnew(void);
void BNfree(BIGNUM *a);
void BNinit(BIGNUM *);
void BNclear(BIGNUM *a);
void BNclearfree(BIGNUM *a);
BNCTX *BNCTXnew(void);
void BNCTXinit(BNCTX *c);
void BNCTXfree(BNCTX *c);
BIGNUM *BNcopy(BIGNUM *a, const BIGNUM *b);
BIGNUM *BNdup(const BIGNUM *a);
BIGNUM *BNswap(BIGNUM *a, BIGNUM *b);
int BNnumbytes(const BIGNUM *a);
int BNnumbits(const BIGNUM *a);
int BNnumbitsword(BNULONG w);
void BNsetnegative(BIGNUM *a, int n);
int BNisnegative(const BIGNUM *a);
int BNadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
int BNsub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
int BNmul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BNCTX *ctx);
int BNsqr(BIGNUM *r, BIGNUM *a, BNCTX *ctx);
int BNdiv(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
BNCTX *ctx);
int BNmod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BNCTX *ctx);
int BNnnmod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BNCTX *ctx);
int BNmodadd(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
BNCTX *ctx);
int BNmodsub(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
BNCTX *ctx);
int BNmodmul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
BNCTX *ctx);
int BNmodsqr(BIGNUM *ret, BIGNUM *a, const BIGNUM *m, BNCTX *ctx);
int BNexp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BNCTX *ctx);
int BNmodexp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BNCTX *ctx);
int BNgcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BNCTX *ctx);
OpenSL-0.9.8 Last change: Oct 11 2005 1
OpenSL bn(3openssl)
int BNaddword(BIGNUM *a, BNULONG w);
int BNsubword(BIGNUM *a, BNULONG w);
int BNmulword(BIGNUM *a, BNULONG w);
BNULONG BNdivword(BIGNUM *a, BNULONG w);
BNULONG BNmodword(const BIGNUM *a, BNULONG w);
int BNcmp(BIGNUM *a, BIGNUM *b);
int BNucmp(BIGNUM *a, BIGNUM *b);
int BNiszero(BIGNUM *a);
int BNisone(BIGNUM *a);
int BNisword(BIGNUM *a, BNULONG w);
int BNisodd(BIGNUM *a);
int BNzero(BIGNUM *a);
int BNone(BIGNUM *a);
const BIGNUM *BNvalueone(void);
int BNsetword(BIGNUM *a, unsigned long w);
unsigned long BNgetword(BIGNUM *a);
int BNrand(BIGNUM *rnd, int bits, int top, int bottom);
int BNpseudorand(BIGNUM *rnd, int bits, int top, int bottom);
int BNrandrange(BIGNUM *rnd, BIGNUM *range);
int BNpseudorandrange(BIGNUM *rnd, BIGNUM *range);
BIGNUM *BNgenerateprime(BIGNUM *ret, int bits,int safe, BIGNUM *add,
BIGNUM *rem, void (*callback)(int, int, void *), void *cbarg);
int BNisprime(const BIGNUM *p, int nchecks,
void (*callback)(int, int, void *), BNCTX *ctx, void *cbarg);
int BNsetbit(BIGNUM *a, int n);
int BNclearbit(BIGNUM *a, int n);
int BNisbitset(const BIGNUM *a, int n);
int BNmaskbits(BIGNUM *a, int n);
int BNlshift(BIGNUM *r, const BIGNUM *a, int n);
int BNlshift1(BIGNUM *r, BIGNUM *a);
int BNrshift(BIGNUM *r, BIGNUM *a, int n);
int BNrshift1(BIGNUM *r, BIGNUM *a);
int BNbn2bin(const BIGNUM *a, unsigned char *to);
BIGNUM *BNbin2bn(const unsigned char *s, int len, BIGNUM *ret);
char *BNbn2hex(const BIGNUM *a);
char *BNbn2dec(const BIGNUM *a);
int BNhex2bn(BIGNUM **a, const char *str);
int BNdec2bn(BIGNUM **a, const char *str);
int BNprint(BIO *fp, const BIGNUM *a);
int BNprintfp(FILE *fp, const BIGNUM *a);
int BNbn2mpi(const BIGNUM *a, unsigned char *to);
BIGNUM *BNmpi2bn(unsigned char *s, int len, BIGNUM *ret);
BIGNUM *BNmodinverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
BNCTX *ctx);
OpenSL-0.9.8 Last change: Oct 11 2005 2
OpenSL bn(3openssl)
BNRECPCTX *BNRECPCTXnew(void);
void BNRECPCTXinit(BNRECPCTX *recp);
void BNRECPCTXfree(BNRECPCTX *recp);
int BNRECPCTXset(BNRECPCTX *recp, const BIGNUM *m, BNCTX *ctx);
int BNmodmulreciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
BNRECPCTX *recp, BNCTX *ctx);
BNMONTCTX *BNMONTCTXnew(void);
void BNMONTCTXinit(BNMONTCTX *ctx);
void BNMONTCTXfree(BNMONTCTX *mont);
int BNMONTCTXset(BNMONTCTX *mont, const BIGNUM *m, BNCTX *ctx);
BNMONTCTX *BNMONTCTXcopy(BNMONTCTX *to, BNMONTCTX *from);
int BNmodmulmontgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
BNMONTCTX *mont, BNCTX *ctx);
int BNfrommontgomery(BIGNUM *r, BIGNUM *a, BNMONTCTX *mont,
BNCTX *ctx);
int BNtomontgomery(BIGNUM *r, BIGNUM *a, BNMONTCTX *mont,
BNCTX *ctx);
BNBLINDING *BNBLINDINGnew(const BIGNUM *A, const BIGNUM *Ai,
BIGNUM *mod);
void BNBLINDINGfree(BNBLINDING *b);
int BNBLINDINGupdate(BNBLINDING *b,BNCTX *ctx);
int BNBLINDINGconvert(BIGNUM *n, BNBLINDING *b, BNCTX *ctx);
int BNBLINDINGinvert(BIGNUM *n, BNBLINDING *b, BNCTX *ctx);
int BNBLINDINGconvertex(BIGNUM *n, BIGNUM *r, BNBLINDING *b,
BNCTX *ctx);
int BNBLINDINGinvertex(BIGNUM *n,const BIGNUM *r,BNBLINDING *b,
BNCTX *ctx);
unsigned long BNBLINDINGgetthreadid(const BNBLINDING *);
void BNBLINDINGsetthreadid(BNBLINDING *, unsigned long);
unsigned long BNBLINDINGgetflags(const BNBLINDING *);
void BNBLINDINGsetflags(BNBLINDING *, unsigned long);
BNBLINDING *BNBLINDINGcreateparam(BNBLINDING *b,
const BIGNUM *e, BIGNUM *m, BNCTX *ctx,
int (*bnmodexp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BNCTX *ctx, BNMONTCTX *mctx),
BNMONTCTX *mctx);
DESCRIPTION
This library performs arithmetic operations on integers of
arbitrary size. It was written for use in public key
cryptography, such as RSA and Diffie-Hellman.
It uses dynamic memory allocation for storing its data
structures. That means that there is no limit on the size
of the numbers manipulated by these functions, but return
values must always be checked in case a memory allocation
error has occurred.
The basic object in this library is a BIGNUM. It is used to
hold a single large integer. This type should be considered
OpenSL-0.9.8 Last change: Oct 11 2005 3
OpenSL bn(3openssl)
opaque and fields should not be modified or accessed
directly.
The creation of BIGNUM objects is described in BNnew(3);
BNadd(3) describes most of the arithmetic operations.
Comparison is described in BNcmp(3); BNzero(3) describes
certain assignments, BNrand(3) the generation of random
numbers, BNgenerateprime(3) deals with prime numbers and
BNsetbit(3) with bit operations. The conversion of BIGNUMs
to external formats is described in BNbn2bin(3).
SEE ALSO
bninternal(3), dh(3), err(3), rand(3), rsa(3), BNnew(3),
BNCTXnew(3), BNcopy(3), BNswap(3), BNnumbytes(3),
BNadd(3), BNaddword(3), BNcmp(3), BNzero(3),
BNrand(3), BNgenerateprime(3), BNsetbit(3),
BNbn2bin(3), BNmodinverse(3), BNmodmulreciprocal(3),
BNmodmulmontgomery(3), BNBLINDINGnew(3)
OpenSL-0.9.8 Last change: Oct 11 2005 4
|