Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
bbs_rand.c File Reference
#include "bbs_rand.h"

Go to the source code of this file.

Defines

#define SEED   1
#define MODULUS   2

Functions

void bbs_srand (unsigned char *data, int len)
unsigned int bbs_rand (void)

Variables

static char * bbs_modulus = "28559EBA58C87447245ADD0651EDA507056A1129E3A3E16E903D64B437"
static int bbs_init = 0
static mp_int bbs_state
int bbs_seed_size = (sizeof(bbs_modulus) / 2)

Define Documentation

#define MODULUS   2

Definition at line 44 of file bbs_rand.c.

#define SEED   1

Definition at line 43 of file bbs_rand.c.


Function Documentation

unsigned int bbs_rand ( void  )

Definition at line 71 of file bbs_rand.c.

{
  static mp_int   modulus;
  unsigned int    result = 0, ix;

  if((bbs_init & MODULUS) == 0) {
    mp_init(&modulus);
    mp_read_radix(&modulus, bbs_modulus, 16);
    bbs_init |= MODULUS;
  }

  for(ix = 0; ix < sizeof(unsigned int); ix++) {
    mp_digit   d;

    mp_sqrmod(&bbs_state, &modulus, &bbs_state);
    d = DIGIT(&bbs_state, 0);

    result = (result << CHAR_BIT) | (d & UCHAR_MAX);
  }

  return result;

} /* end bbs_rand() */

Here is the call graph for this function:

void bbs_srand ( unsigned char *  data,
int  len 
)

Definition at line 60 of file bbs_rand.c.

{
  if((bbs_init & SEED) == 0) {
    mp_init(&bbs_state);
    bbs_init |= SEED;
  }

  mp_read_raw(&bbs_state, (char *)data, len);

} /* end bbs_srand() */

Here is the call graph for this function:


Variable Documentation

int bbs_init = 0 [static]

Definition at line 54 of file bbs_rand.c.

char* bbs_modulus = "28559EBA58C87447245ADD0651EDA507056A1129E3A3E16E903D64B437" [static]

Definition at line 48 of file bbs_rand.c.

int bbs_seed_size = (sizeof(bbs_modulus) / 2)

Definition at line 58 of file bbs_rand.c.

mp_int bbs_state [static]

Definition at line 55 of file bbs_rand.c.