Strophe 0.13
XMPP client library
Data Structures | Macros | Functions
rand.c File Reference

Pseudo-random number generator. More...

Data Structures

struct  Hash_DRBG_CTX
 
struct  xmpp_rand_t
 

Macros

#define outlen   SHA1_DIGEST_SIZE
 
#define seedlen   (440 / 8)
 
#define reseed_interval   0x7fffffff
 
#define GENERATE_MAX   (outlen * 10)
 
#define ENTROPY_MAX   128
 
#define NONCE_MAX   8
 
#define RESEED_NEEDED   (-1)
 
#define round_up(x, y)   (((x) + (y)-1) / (y) * (y))
 
#define div_round_up(x, y)   (((x) + (y)-1) / (y))
 
#define ENTROPY_ACCUMULATE(ptr, last, type, arg)
 

Functions

static void arr_add (uint8_t *arr1, size_t arr1_len, uint8_t *arr2, size_t arr2_len)
 
static void store_be32 (uint32_t val, uint8_t be[4])
 
static void Hash_df (uint8_t *input_string, size_t input_string_len, uint8_t *output_string, size_t no_of_bytes_to_return)
 
static void Hash_DRBG_Instantiate (Hash_DRBG_CTX *ctx, uint8_t *entropy_input, size_t entropy_input_len, uint8_t *nonce, size_t nonce_len)
 
static void Hash_DRBG_Reseed (Hash_DRBG_CTX *ctx, uint8_t *entropy_input, size_t entropy_input_len)
 
static void Hashgen (uint8_t *V, uint8_t *output, size_t requested_number_of_bytes)
 
static int Hash_DRBG_Generate (Hash_DRBG_CTX *ctx, uint8_t *output, size_t requested_number_of_bytes)
 
static void xmpp_rand_reseed (xmpp_rand_t *rand)
 
xmpp_rand_t * xmpp_rand_new (xmpp_ctx_t *ctx)
 Create new xmpp_rand_t object.
 
void xmpp_rand_free (xmpp_ctx_t *ctx, xmpp_rand_t *rand)
 Destroy an xmpp_rand_t object.
 
void xmpp_rand_bytes (xmpp_rand_t *rand, unsigned char *output, size_t len)
 Generate random bytes.
 
int xmpp_rand (xmpp_rand_t *rand)
 Generate random integer.
 
static void rand_byte2hex (unsigned char byte, char *hex)
 
void xmpp_rand_nonce (xmpp_rand_t *rand, char *output, size_t len)
 Generate a nonce that is printable randomized string.
 

Detailed Description

Pseudo-random number generator.

Implemented Hash_DRBG mechanism according to NIST SP 800-90A. Hash function is SHA1.

Macro Definition Documentation

◆ outlen

#define outlen   SHA1_DIGEST_SIZE

◆ seedlen

#define seedlen   (440 / 8)

◆ reseed_interval

#define reseed_interval   0x7fffffff

◆ GENERATE_MAX

#define GENERATE_MAX   (outlen * 10)

◆ ENTROPY_MAX

#define ENTROPY_MAX   128

◆ NONCE_MAX

#define NONCE_MAX   8

◆ RESEED_NEEDED

#define RESEED_NEEDED   (-1)

◆ round_up

#define round_up (   x,
 
)    (((x) + (y)-1) / (y) * (y))

◆ div_round_up

#define div_round_up (   x,
 
)    (((x) + (y)-1) / (y))

◆ ENTROPY_ACCUMULATE

#define ENTROPY_ACCUMULATE (   ptr,
  last,
  type,
  arg 
)
Value:
do { \
type __arg = (type)(arg); \
if ((char *)ptr + sizeof(__arg) < (char *)last) { \
*(type *)ptr = __arg; \
ptr = (void *)((char *)ptr + sizeof(__arg)); \
} \
} while (0)

Function Documentation

◆ arr_add()

static void arr_add ( uint8_t *  arr1,
size_t  arr1_len,
uint8_t *  arr2,
size_t  arr2_len 
)
static

◆ store_be32()

static void store_be32 ( uint32_t  val,
uint8_t  be[4] 
)
static

◆ Hash_df()

static void Hash_df ( uint8_t *  input_string,
size_t  input_string_len,
uint8_t *  output_string,
size_t  no_of_bytes_to_return 
)
static

◆ Hash_DRBG_Instantiate()

static void Hash_DRBG_Instantiate ( Hash_DRBG_CTX *  ctx,
uint8_t *  entropy_input,
size_t  entropy_input_len,
uint8_t *  nonce,
size_t  nonce_len 
)
static

◆ Hash_DRBG_Reseed()

static void Hash_DRBG_Reseed ( Hash_DRBG_CTX *  ctx,
uint8_t *  entropy_input,
size_t  entropy_input_len 
)
static

◆ Hashgen()

static void Hashgen ( uint8_t *  V,
uint8_t *  output,
size_t  requested_number_of_bytes 
)
static

◆ Hash_DRBG_Generate()

static int Hash_DRBG_Generate ( Hash_DRBG_CTX *  ctx,
uint8_t *  output,
size_t  requested_number_of_bytes 
)
static

◆ xmpp_rand_reseed()

static void xmpp_rand_reseed ( xmpp_rand_t *  rand)
static

◆ rand_byte2hex()

static void rand_byte2hex ( unsigned char  byte,
char *  hex 
)
static