X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilccrypt%2Fsilcrng.h;h=4348fb2ace77e6abfff0c402a25c7f32a89ffa39;hb=bd548b5771a325d3dc051887d3fd0225550d4418;hp=9a173ffb7cc8d7d3de327d46bcdbd6c9a22972ea;hpb=67ead87b5688a88f997ed02252625e1ebb882de4;p=crypto.git diff --git a/lib/silccrypt/silcrng.h b/lib/silccrypt/silcrng.h index 9a173ffb..4348fb2a 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 - 2008 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 @@ -36,10 +36,10 @@ #ifndef SILCRNG_H #define SILCRNG_H -/****s* silccrypt/SilcRNGAPI/SilcRng +/****s* silccrypt/SilcRng * * NAME - * + * * typedef struct SilcRngStruct *SilcRng; * * DESCRIPTION @@ -54,7 +54,7 @@ typedef struct SilcRngStruct *SilcRng; /* Prototypes */ -/****f* silccrypt/SilcRNGAPI/silc_rng_alloc +/****f* silccrypt/silc_rng_alloc * * SYNOPSIS * @@ -70,7 +70,7 @@ typedef struct SilcRngStruct *SilcRng; ***/ SilcRng silc_rng_alloc(void); -/****f* silccrypt/SilcRNGAPI/silc_rng_free +/****f* silccrypt/silc_rng_free * * SYNOPSIS * @@ -84,7 +84,7 @@ SilcRng silc_rng_alloc(void); ***/ void silc_rng_free(SilcRng rng); -/****f* silccrypt/SilcRNGAPI/silc_rng_init +/****f* silccrypt/silc_rng_init * * SYNOPSIS * @@ -105,7 +105,7 @@ void silc_rng_free(SilcRng rng); ***/ void silc_rng_init(SilcRng rng); -/****f* silccrypt/SilcRNGAPI/silc_rng_get_byte +/****f* silccrypt/silc_rng_get_byte * * SYNOPSIS * @@ -118,7 +118,28 @@ void silc_rng_init(SilcRng rng); ***/ SilcUInt8 silc_rng_get_byte(SilcRng rng); -/****f* silccrypt/SilcRNGAPI/silc_rng_get_rn16 +/****f* silccrypt/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/silc_rng_get_rn16 * * SYNOPSIS * @@ -131,7 +152,7 @@ SilcUInt8 silc_rng_get_byte(SilcRng rng); ***/ SilcUInt16 silc_rng_get_rn16(SilcRng rng); -/****f* silccrypt/SilcRNGAPI/silc_rng_get_rn32 +/****f* silccrypt/silc_rng_get_rn32 * * SYNOPSIS * @@ -144,7 +165,7 @@ SilcUInt16 silc_rng_get_rn16(SilcRng rng); ***/ SilcUInt32 silc_rng_get_rn32(SilcRng rng); -/****f* silccrypt/SilcRNGAPI/silc_rng_get_rn_string +/****f* silccrypt/silc_rng_get_rn_string * * SYNOPSIS * @@ -153,26 +174,30 @@ 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); -/****f* silccrypt/SilcRNGAPI/silc_rng_get_rn_data +/****f* silccrypt/silc_rng_get_rn_data * * 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 +/****f* silccrypt/silc_rng_add_noise * * SYNOPSIS * @@ -180,18 +205,18 @@ 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. * ***/ void silc_rng_add_noise(SilcRng rng, unsigned char *buffer, SilcUInt32 len); -/****f* silccrypt/SilcRNGAPI/silc_rng_global_init +/****f* silccrypt/silc_rng_global_init * * 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 +/****f* silccrypt/silc_rng_global_uninit * * SYNOPSIS * - * bool silc_rng_global_uninit(void); + * SilcBool silc_rng_global_uninit(void); * * DESCRIPTION * @@ -225,9 +250,9 @@ 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 +/****f* silccrypt/silc_rng_global_get_byte * * SYNOPSIS * @@ -240,7 +265,7 @@ bool silc_rng_global_uninit(void); ***/ SilcUInt8 silc_rng_global_get_byte(void); -/****f* silccrypt/SilcRNGAPI/silc_rng_global_get_byte_fast +/****f* silccrypt/silc_rng_global_get_byte_fast * * SYNOPSIS * @@ -261,7 +286,7 @@ SilcUInt8 silc_rng_global_get_byte(void); ***/ SilcUInt8 silc_rng_global_get_byte_fast(void); -/****f* silccrypt/SilcRNGAPI/silc_rng_global_get_rn16 +/****f* silccrypt/silc_rng_global_get_rn16 * * SYNOPSIS * @@ -274,7 +299,7 @@ SilcUInt8 silc_rng_global_get_byte_fast(void); ***/ SilcUInt16 silc_rng_global_get_rn16(void); -/****f* silccrypt/SilcRNGAPI/silc_rng_global_get_rn32 +/****f* silccrypt/silc_rng_global_get_rn32 * * SYNOPSIS * @@ -287,7 +312,7 @@ SilcUInt16 silc_rng_global_get_rn16(void); ***/ SilcUInt32 silc_rng_global_get_rn32(void); -/****f* silccrypt/SilcRNGAPI/silc_rng_global_get_rn_string +/****f* silccrypt/silc_rng_global_get_rn_string * * SYNOPSIS * @@ -296,26 +321,31 @@ 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); -/****f* silccrypt/SilcRNGAPI/silc_rng_global_get_rn_data +/****f* silccrypt/silc_rng_global_get_rn_data * * 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 +/****f* silccrypt/silc_rng_global_add_noise * * SYNOPSIS * @@ -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. *