GNU General Public License for more details.
*/
+/* $Id$ */
/*
* Created: Sun Mar 9 00:09:18 1997
*
*/
/* XXX: Some operations block resulting slow initialization.
* XXX: I have some pending changes to make this better. */
-/*
- * $Id$
- * $Log$
- * Revision 1.1.1.1 2000/06/27 11:36:55 priikone
- * Importet from internal CVS/Added Log headers.
- *
- *
- */
#include "silcincludes.h"
SILC_LOG_DEBUG(("Allocating new RNG object"));
new = silc_calloc(1, sizeof(*new));
- if (!new) {
- SILC_LOG_ERROR(("Could not allocate new RNG object"));
- return NULL;
- }
memset(new->pool, 0, sizeof(new->pool));
memset(new->key, 0, sizeof(new->key));
SILC_LOG_DEBUG(("Initializing RNG object"));
/* Initialize the states for the RNG. */
- rng->state = silc_malloc(sizeof(*rng->state));
+ rng->state = silc_calloc(1, sizeof(*rng->state));
rng->state->low = 0;
rng->state->pos = 8;
rng->state->next = NULL;
first = rng->state;
for (i = SILC_RNG_STATE_NUM - 1; i >= 1; i--) {
- next = silc_malloc(sizeof(*rng->state));
+ next = silc_calloc(1, sizeof(*rng->state));
next->low =
(i * (sizeof(rng->pool) / SILC_RNG_STATE_NUM));
next->pos =
(i * (sizeof(rng->pool) / SILC_RNG_STATE_NUM)) + 8;
-#if 0
- next->pos = sizeof(rng->pool) -
- ((i * (sizeof(rng->pool) / SILC_RNG_STATE_NUM))) + 8;
-#endif
next->next = rng->state;
rng->state = next;
}
unsigned char *string;
string = silc_calloc((len * 2 + 1), sizeof(unsigned char));
- if (string == NULL)
- return NULL;
for (i = 0; i < len; i++)
sprintf(string + 2 * i, "%02x", silc_rng_get_byte(rng));
return string;
}
+
+/* Returns random number binary data. */
+
+unsigned char *silc_rng_get_rn_data(SilcRng rng, unsigned int len)
+{
+ int i;
+ unsigned char *data;
+
+ data = silc_calloc(len + 1, sizeof(*data));
+
+ for (i = 0; i < len; i++)
+ data[i] = silc_rng_get_byte(rng);
+
+ return data;
+}