Branch: Tag:

2003-08-07

2003-08-07 20:32:37 by Martin Nilsson <mani@lysator.liu.se>

More doc. Made sure no one tries to give a larger entropy value than possible. Added min_seed_size method.

Rev: src/post_modules/Nettle/nettle.cmod:1.15

1:   /* nettle.cmod -*- c -*- */      #include "global.h" - RCSID("$Id: nettle.cmod,v 1.14 2003/08/06 10:00:33 grubba Exp $"); + RCSID("$Id: nettle.cmod,v 1.15 2003/08/07 20:32:37 nilsson Exp $");   #include "interpret.h"   #include "svalue.h"   /* For this_object() */
43:    CVAR struct yarrow256_ctx *ctx;    CVAR struct yarrow_source *sources;    +  /*! @decl void create(void|int sources) +  *! The number of entropy sources that will feed entropy to the +  *! random number generator is given as an argument to Yarrow +  *! during instantiation. +  *! @seealso +  *! @[update] +  */    PIKEFUN void create(void|int arg) {    INT32 num = 0;    THIS->sources = NULL;
67:    *! from @[get_seed].    *! @returns    *! Returns the called object. +  *! @seealso +  *! @[min_seed_size], @[get_seed], @[is_seeded]    */    PIKEFUN object seed(string data)    {
78:    RETURN this_object();    }    +  /*! @decl int(0..) min_seed_size() +  *! Returns the minimal number of characters that the @[seed] +  *! needs to properly seed the random number generator. +  *! @seealso +  *! @[seed] +  */ +  PIKEFUN int(0..) min_seed_size() +  { +  RETURN YARROW256_SEED_FILE_SIZE; +  } +     /*! @decl string get_seed()    *! Returns part of the internal state so that it can    *! be saved for later seeding. -  +  *! @seealso +  *! @[seed]    */    PIKEFUN string get_seed()    {
90:    /*! @decl int(0..1) is_seeded()    *! Returns 1 if the random generator is seeded and ready    *! to generator output. 0 otherwise. +  *! @seealso +  *! @[seed]    */    PIKEFUN int(0..1) is_seeded()    {    RETURN yarrow256_is_seeded(THIS->ctx);    }    -  +  /*! @decl void force_reseed() +  *! By calling this function entropy is moved from the slow +  *! pool to the fast pool. Read more about Yarrow before using +  *! this. +  */    PIKEFUN void force_reseed()    {    yarrow256_force_reseed(THIS->ctx);    }    -  +  /*! @decl int(0..1) update(string data, int source, int entropy) +  *! Inject additional entropy into the random number generator. +  *! +  *! @seealso +  *! @[create] +  */    PIKEFUN int(0..1) update(string data, int source, int entropy)    {    NO_WIDE_STRING(data);
110:    Pike_error("Invalid random source.\n");    if( entropy<0 )    Pike_error("Entropy must be positive.\n"); +  if( entropy>(data->len*8) ) +  Pike_error("Impossibly large entropy value.\n");    RETURN yarrow256_update(THIS->ctx, source, entropy, data->len, data->str);    }