pike.git / src / post_modules / Nettle / nettle.cmod

version» Context lines:

pike.git/src/post_modules/Nettle/nettle.cmod:1:   /* nettle.cmod -*- c -*- */      #include "global.h" - RCSID("$Id: nettle.cmod,v 1.9 2003/08/05 18:05:13 nilsson Exp $"); + RCSID("$Id: nettle.cmod,v 1.10 2003/08/06 00:50:16 nilsson Exp $");   #include "interpret.h"   #include "svalue.h"   /* For this_object() */   #include "object.h"   #include "module_support.h"      #include "nettle_config.h"      #ifdef HAVE_LIBNETTLE   
pike.git/src/post_modules/Nettle/nettle.cmod:32:    *! Yarrow is a family of pseudo-randomness generators, designed for    *! cryptographic use, by John Kelsey, Bruce Schneier and Niels Ferguson.    *! Yarrow-160 is described in a paper at    *! @url{http://www.counterpane.com/yarrow.html@}, and it uses SHA1 and    *! triple-DES, and has a 160-bit internal state. Nettle implements    *! Yarrow-256, which is similar, but uses SHA256 and AES to get an    *! internal state of 256 bits.    */   PIKECLASS Yarrow   { -  CVAR const struct yarrow256_ctx *ctx; +  CVAR struct yarrow256_ctx *ctx; +  CVAR struct yarrow_source *sources;    -  PIKEFUN void create() { -  yarrow256_init(THIS->ctx, 0, NULL); +  PIKEFUN void create(void|int arg) { +  INT32 num = 0; +  THIS->sources = NULL; +  +  if(arg) { +  if (arg->type != PIKE_T_INT) +  Pike_error("Bad argument type.\n"); +  num = arg->u.integer; +  if(num < 0) +  Pike_error("Invalid number of sources.\n"); +  THIS->sources = xalloc(sizeof(struct yarrow_source)*num);    }    -  +  yarrow256_init(THIS->ctx, num, THIS->sources); +  } +     /*! @decl Yarrow seed(string data)    *! The random generator needs to be seeded before    *! it can be used. The seed must be at least 32    *! characters long. The seed could be stored from    *! a previous run by inserting the value returned    *! from @[get_seed].    *! @returns    *! Returns the called object.    */    PIKEFUN object seed(string data)    { -  /* FIXME: Take figure in error msg from define */ +     if(data->len < YARROW256_SEED_FILE_SIZE)    Pike_error( "Seed must be at least 32 characters.\n" );       NO_WIDE_STRING(data);    yarrow256_seed(THIS->ctx, data->len, data->str);    RETURN this_object();    }       /*! @decl string get_seed()    *! Returns part of the internal state so that it can
pike.git/src/post_modules/Nettle/nettle.cmod:104:    if( !yarrow256_is_seeded(THIS->ctx) )    Pike_error("Random generator not seeded.\n");    rnd = begin_shared_string(length);    yarrow256_random(THIS->ctx, length, rnd->str);    RETURN end_shared_string(rnd);    }       INIT    {    THIS->ctx = xalloc(sizeof(struct yarrow256_ctx)); +  THIS->ctx->nsources = 0;    }    EXIT    { -  +  if(THIS->ctx->nsources) free(THIS->sources);    free(THIS->ctx);    }   }      /*! @endclass    */      /*! @endmodule    */