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.33 2004/02/14 07:33:57 nilsson Exp $"); + RCSID("$Id: nettle.cmod,v 1.34 2004/02/21 02:20:09 nilsson Exp $");   #include "interpret.h"   #include "svalue.h"   /* For this_object() */   #include "object.h"   #include "operators.h"   #include "module_support.h"   #include "threads.h"      #include "nettle_config.h"      #ifdef HAVE_LIBNETTLE      #include "nettle.h"      #include <nettle/yarrow.h> -  + #include <nettle/knuth-lfib.h>      #include <assert.h>   #include <stdio.h>   #include <stdarg.h>      DECLARATIONS      /*! @module Nettle    *! Low level crypto functions used by the @[Crypto] module. Unless    *! you are doing something very special, you would want to use the
pike.git/src/post_modules/Nettle/nettle.cmod:210:      char *crypt_md5(int pl, const char *pw, int sl, const char *salt);      /*! @decl string crypt_md5(string password, string salt)    *! Does the crypt_md5 abrakadabra (MD5 + snakeoil).    *! It is assumed that @[salt] does not contain "$".    */   PIKEFUN string crypt_md5(string pw, string salt)    optflags OPT_TRY_OPTIMIZE;   { +  char *hash;    NO_WIDE_STRING(pw);    NO_WIDE_STRING(salt);    THREADS_ALLOW(); -  push_text(crypt_md5(pw->len, pw->str,salt->len, salt->str)); +  hash = crypt_md5(pw->len, pw->str,salt->len, salt->str);    THREADS_DISALLOW(); -  +  push_text(hash);   }         static const char *crypto_functions[] = {    "block_size",    "key_size",    "set_encrypt_key",    "set_decrypt_key",    "crypt",    0
pike.git/src/post_modules/Nettle/nettle.cmod:782:    add_ref(str);    pop_stack();    push_string(make_shared_binary_string(str->str, len));    free_string(str);    }   }      /*! @endclass    */    + #if 0 +  + /* @class LFib +  * The Donald Knuth Lagged Fibonacci pseudo random number generator. +  * This is @b{not@} a source for cryptographic randomness. Use +  * @[Crypto.Yarrow] instead. +  */ + PIKECLASS LFib + { +  CVAR struct knuth_lfib_ctx *ctx; +  +  INIT { +  THIS->ctx = xalloc(sizeof(struct knuth_lfib_ctx)); +  } +  +  EXIT { +  free(THIS->ctx); +  } +  +  /* @decl void create(int seed) +  * The Lfib generator must be seeded with a number. +  */ +  PIKEFUN void create(int seed) { +  knuth_lfib_init(THIS->ctx, seed); +  } +  +  /* @decl this_program reseed(int s) +  * Reseed this object with seed @[s]. +  * @return +  * Returns the current object. +  */ +  PIKEFUN object reseed(int s) { +  knuth_lfib_init(THIS->ctx, s); +  RETURN this_object(); +  } +  +  /* Get one 32bit pseudorandom integer. +  */ +  PIKEFUN int get() { +  RETURN knuth_lfib_get(THIS->ctx); +  } +  +  /* Get a pseudorandom string of length @[len]. +  */ +  PIKEFUN string get_string(int len) { +  struct pike_string *s = begin_shared_string(len); +  knuth_lfib_random(THIS->ctx, len, s->str); +  push_string(end_shared_string(s)); +  } + } +  + /* @endclass +  */ +  + #endif +    /*! @endmodule    */            #endif /* HAVE_LIBNETTLE */      PIKE_MODULE_INIT   {   #ifdef __NT__