[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8. Random Numbers


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.1 Quality of random numbers

Libgcypt offers random numbers of different quality levels:

Data type: gcry_random_level_t

The constants for the random quality levels are of this enum type.

GCRY_WEAK_RANDOM

For all functions, except for gcry_mpi_randomize, this level maps to GCRY_STRONG_RANDOM. If you do not want this, consider using gcry_create_nonce.

GCRY_STRONG_RANDOM

Use this level for session keys and similar purposes.

GCRY_VERY_STRONG_RANDOM

Use this level for long term key material.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.2 Retrieving random numbers

Function: void gcry_randomize (unsigned char *buffer, size_t length, enum gcry_random_level level)

Fill buffer with length random bytes using a random quality as defined by level.

Function: void * gcry_random_bytes (size_t nbytes, enum gcry_random_level level)

Convenience function to allocate a memory block consisting of nbytes fresh random bytes using a random quality as defined by level.

Function: void * gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level)

Convenience function to allocate a memory block consisting of nbytes fresh random bytes using a random quality as defined by level. This function differs from gcry_random_bytes in that the returned buffer is allocated in a "secure" area of the memory.

Function: void gcry_create_nonce (unsigned char *buffer, size_t length)

Fill buffer with length unpredictable bytes. This is commonly called a nonce and may also be used for initialization vectors and padding. This is an extra function nearly independent of the other random function for 3 reasons: It better protects the regular random generator's internal state, provides better performance and does not drain the precious entropy pool.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated on January, 20 2010 using texi2html 1.76.