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

NAME

BN_num_bits_word, BN_set_word, BN_get_word, BN_add_word, BN_sub_word,
BN_mul_word, BN_div_word, BN_mod_word -- BN word-based routines

SYNOPSIS

#include "bn.h"

int BN_num_bits_word(w)
BN_ULONG w;

int BN_set_word(a, w)
BIGNUM *a;
unsigned long w;

unsigned long BN_get_word(a)
BIGNUM *a;

int BN_add_word(a, w)
BIGNUM *a;
unsigned long w;

int BN_sub_word(a, w)
BIGNUM *a;
unsigned long w;

int BN_mul_word(a, w)
BIGNUM *a;
unsigned long w;

BN_ULONG BN_div_word(a, w)
BIGNUM *a;
unsigned long w;

BN_ULONG BN_mod_word(a, w)
BIGNUM *a;
unsigned long w;

DESCRIPTION

BN_num_bits_word returns the number of bits needed to hold the value in l. Needless to say, negative values are not considered here.

This routine is called by BN_num_bits().

BN_set_word sets the value of the BIGNUM a to be w. a must have been previously allocated to be big enough to hold the value. 1 is returned.

Needless to say, negative values are not considered here; w is an unsigned long, after all.

BN_get_word returns the value of a in an unsigned long. Not remarkably, often a will be bigger than a word, in which case 0xffffffffL is returned.

Word Operations These functions are much more efficient that the normal bignum arithmetic operations.

BN_add_word adds the value of w to a. Negative values in a are handled properly. 1 is returned, or 0 on error.

BN_sub_word subtracts the value of w from a. Negative values in a are handled properly. 1 is returned, or 0 on error.

BN_mul_word multiplies a by the value of w. Negative values in a are handled properly. 0 is always returned (oops!)

BN_div_word divides a by the value of w. Negative values in a are handled properly. The remainder (a BN_ULONG) is returned, or 0 on error.

BN_mod_word returns the remainder of a divided by the value of w. Negative values in a are handled properly.

The following marcos are defined for the connience of the user:

#define BN_one(a)       (BN_set_word((a),1))
#define BN_zero(a)      (BN_set_word((a),0))

BN_one sets its argument to hold the value 1.

BN_zero sets its argument to hold the value 0.