X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilccrypt%2Fsilcrng.h;h=bf32fd8fcac2e9d9802613331b7559f03e86e49c;hb=e7b6c157b80152bf9fb9266e6bdd93f9fb0db776;hp=a5da3c348ad2f514be44cd6f1f18ef8ed9c05273;hpb=a818c5b5411bbc4436d1c5f011236985c96bb787;p=silc.git diff --git a/lib/silccrypt/silcrng.h b/lib/silccrypt/silcrng.h index a5da3c34..bf32fd8f 100644 --- a/lib/silccrypt/silcrng.h +++ b/lib/silccrypt/silcrng.h @@ -1,10 +1,10 @@ /* - silcrng.h + silcrng.h Author: Pekka Riikonen - Copyright (C) 1997 - 2002 Pekka Riikonen + Copyright (C) 1997 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ */ -/****h* silccrypt/SilcRNGAPI +/****h* silccrypt/SILC RNG Interface * * DESCRIPTION * @@ -39,7 +39,7 @@ /****s* silccrypt/SilcRNGAPI/SilcRng * * NAME - * + * * typedef struct SilcRngStruct *SilcRng; * * DESCRIPTION @@ -118,6 +118,27 @@ void silc_rng_init(SilcRng rng); ***/ SilcUInt8 silc_rng_get_byte(SilcRng rng); +/****f* silccrypt/SilcRNGAPI/silc_rng_get_byte_fast + * + * SYNOPSIS + * + * SilcUInt8 silc_rng_get_byte_fast(SilcRng rng); + * + * DESCRIPTION + * + * Returns one 8-bit random byte from the random number generator as + * fast as possible. + * + * NOTES + * + * This will read the data from /dev/urandom if it is available in the + * operating system, since this may be faster than retrieving a byte + * from the SILC RNG. If /dev/urandom is not available this will take + * the byte from SILC RNG and is effectively same as silc_rng_get_byte. + * + ***/ +SilcUInt8 silc_rng_get_byte_fast(SilcRng rng); + /****f* silccrypt/SilcRNGAPI/silc_rng_get_rn16 * * SYNOPSIS @@ -153,7 +174,8 @@ SilcUInt32 silc_rng_get_rn32(SilcRng rng); * DESCRIPTION * * Returns random string in HEX form of the length of `len' bytes. - * The caller must free returned data buffer. + * The caller must free returned data buffer. It is guaranteed the + * data string goes not include any zero (0x00) bytes. * ***/ unsigned char *silc_rng_get_rn_string(SilcRng rng, SilcUInt32 len); @@ -162,15 +184,18 @@ unsigned char *silc_rng_get_rn_string(SilcRng rng, SilcUInt32 len); * * SYNOPSIS * - * unsigned char *silc_rng_get_rn_data(SilcRng rng, SilcUInt32 len); + * SilcBool silc_rng_get_rn_data(SilcRng rng, SilcUInt32 len, + * unsigned char *buf, SilcUInt32 buf_size); * * DESCRIPTION * - * Returns random binary data of the length of `len' bytes. The - * caller must free returned data buffer. + * Returns random binary data of the length of `len' bytes to the `buf' + * of maximum size of `buf_size'. It is guaranteed the data buffer does + * not include any zero (0x00) bytes. * ***/ -unsigned char *silc_rng_get_rn_data(SilcRng rng, SilcUInt32 len); +SilcBool silc_rng_get_rn_data(SilcRng rng, SilcUInt32 len, + unsigned char *buf, SilcUInt32 buf_size); /****f* silccrypt/SilcRNGAPI/silc_rng_add_noise * @@ -180,7 +205,7 @@ unsigned char *silc_rng_get_rn_data(SilcRng rng, SilcUInt32 len); * * DESCRIPTION * - * Add the data buffer indicated by `buffer' of length of `len' bytes + * Add the data buffer indicated by `buffer' of length of `len' bytes * as noise to the random number generator. The random number generator * is restirred (reseeded) when this function is called. * @@ -191,7 +216,7 @@ void silc_rng_add_noise(SilcRng rng, unsigned char *buffer, SilcUInt32 len); * * SYNOPSIS * - * bool silc_rng_global_init(SilcRng rng); + * SilcBool silc_rng_global_init(SilcRng rng); * * DESCRIPTION * @@ -211,13 +236,13 @@ void silc_rng_add_noise(SilcRng rng, unsigned char *buffer, SilcUInt32 len); * the RNG as argument. * ***/ -bool silc_rng_global_init(SilcRng rng); +SilcBool silc_rng_global_init(SilcRng rng); /****f* silccrypt/SilcRNGAPI/silc_rng_global_uninit * * SYNOPSIS * - * bool silc_rng_global_uninit(void); + * SilcBool silc_rng_global_uninit(void); * * DESCRIPTION * @@ -225,7 +250,7 @@ bool silc_rng_global_init(SilcRng rng); * be called if silc_rng_global_init was called with non-NULL RNG. * ***/ -bool silc_rng_global_uninit(void); +SilcBool silc_rng_global_uninit(void); /****f* silccrypt/SilcRNGAPI/silc_rng_global_get_byte * @@ -296,7 +321,8 @@ SilcUInt32 silc_rng_global_get_rn32(void); * DESCRIPTION * * Returns random string in HEX form of the length of `len' bytes. - * The caller must free returned data buffer. + * The caller must free returned data buffer. It is guaranteed the + * data string goes not include any zero (0x00) bytes. * ***/ unsigned char *silc_rng_global_get_rn_string(SilcUInt32 len); @@ -305,15 +331,19 @@ unsigned char *silc_rng_global_get_rn_string(SilcUInt32 len); * * SYNOPSIS * - * unsigned char *silc_rng_global_get_rn_data(SilcUInt32 len); + * SilcBool silc_rng_global_get_rn_data(SilcRng rng, SilcUInt32 len, + * unsigned char *buf, + * SilcUInt32 buf_size); * * DESCRIPTION * - * Returns random binary data of the length of `len' bytes. The - * caller must free returned data buffer. + * Returns random binary data of the length of `len' bytes to the `buf' + * of maximum size of `buf_size'. It is guaranteed the data buffer does + * not include any zero (0x00) bytes. * ***/ -unsigned char *silc_rng_global_get_rn_data(SilcUInt32 len); +SilcBool silc_rng_global_get_rn_data(SilcRng rng, SilcUInt32 len, + unsigned char *buf, SilcUInt32 buf_size); /****f* silccrypt/SilcRNGAPI/silc_rng_global_add_noise * @@ -323,7 +353,7 @@ unsigned char *silc_rng_global_get_rn_data(SilcUInt32 len); * * DESCRIPTION * - * Add the data buffer indicated by `buffer' of length of `len' bytes + * Add the data buffer indicated by `buffer' of length of `len' bytes * as noise to the random number generator. The random number generator * is restirred (reseeded) when this function is called. *