BN_num_bits() -- SSLeay 0.9.0b -- January 1999

NAME

BN_num_bits, BN_set_bit, BN_clear_bit, BN_mask_bits, BN_lshift, BN_lshift1,
BN_rshift, BN_rshift1, BN_num_bytes -- BN bit-oriented routines

SYNOPSIS

#include "bn.h"

int BN_num_bits(BIGNUM *a)
BIGNUM *a;

int BN_set_bit(a, n)
BIGNUM *a;
int n;

int BN_clear_bit(a, n)
BIGNUM *a;
int n;

int BN_mask_bits(a, n)
BIGNUM *a;
int n;

int BN_lshift(r, a, n)
BIGNUM *r, *a;
int n;

int BN_lshift1(r, a)
BIGNUM *r, *a;

int BN_rshift(r, a, n)
BIGNUM *r, *a;
int n;

int BN_rshift1(r, a)
BIGNUM *r, *a;

DESCRIPTION

BN_num_bits returns the size of the value of a in bits.

BN_set_bit sets bit n to 1 in a, where the lsb is numbered 0. If a is shorter than n bits, it will be expanded as necessary. 1 is returned.

BN_clear_bit sets bit n to 0 in a, where the lsb is numbered 0. 1 is returned, or 0 on error (if a is shorter than n bits).

BN_mask_bits truncates a to be n bits long. It returns 1 on succes, or 0 on error (a is already shorter than n bits long).

BN_lshift(BIGNUM *r, BIGNUM *a, int n); shifts a left by n bits and places the result in r. This is r=a*(2^n). The function returns 1, or 0 on error.

BN_lshift1(BIGNUM *r, BIGNUM *a); shifts a left by 1 bit and places the result in r. The function returns 1, or 0 on error. This form is more efficient than BN_lshift(r,a,1). This is r=a*2.

BN_rshift(BIGNUM *r, BIGNUM *a, int n); shifts a right by n bits and places the result in r. This is r=int(a/(2^n)). The function returns 1, or 0 on error.

BN_rshift1(BIGNUM *r, BIGNUM *a); shifts a right by 1 bit and places the result in r. The function returns 1, or 0 on error. This form is more efficient than BN_rshift(r,a,1). This is r=int(a/2).

The following macros are provided for the convenience of the user:

#define BN_num_bytes(a)    ((BN_num_bits(a)+7)/8)

This will return the number of bytes used to hold the value of the BIGNUM.