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

version» Context lines:

pike.git/src/post_modules/Nettle/nettle.cmod:1:   /* nettle.cmod -*- c -*- */ - /* $Id: nettle.cmod,v 1.44 2008/05/29 22:50:20 nilsson Exp $ */ + /* $Id: nettle.cmod,v 1.45 2008/05/29 23:03:47 nilsson Exp $ */      #include "global.h"   #include "interpret.h"   #include "svalue.h"   /* For this_object() */   #include "object.h"   #include "operators.h"   #include "module_support.h"   #include "threads.h"   
pike.git/src/post_modules/Nettle/nettle.cmod:194:    rnd = begin_shared_string(length);    yarrow256_random(&THIS->ctx, length, (uint8_t *)rnd->str);    RETURN end_shared_string(rnd);    }       INIT    {    THIS->sources = NULL;    yarrow256_init(&THIS->ctx, 0, NULL);    } +     EXIT    gc_trivial;    { -  /* It's ok to call free(NULL); */ +  if( THIS->sources ) +  {    free(THIS->sources); -  +  THIS->sources = NULL;    }    } -  + }      /*! @endclass    */      /*! @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;
pike.git/src/post_modules/Nettle/nettle.cmod:309:    */   PIKECLASS CBC   {    CVAR struct object *object;    CVAR unsigned INT8 *iv;    CVAR INT32 block_size;    CVAR INT32 mode;       INIT    { -  THIS->object = 0; -  THIS->iv = 0; +  THIS->object = NULL; +  THIS->iv = NULL;    THIS->block_size = 0;    THIS->mode = 0;    }       EXIT    gc_trivial;    { -  if(THIS->object) free_object(THIS->object); +  if(THIS->object) { +  free_object(THIS->object); +  THIS->object = NULL; +  }    if(THIS->iv) {    MEMSET(THIS->iv, 0, THIS->block_size);    free(THIS->iv); -  +  THIS->iv = NULL;    } -  THIS->iv = 0; +     }       INLINE static void cbc_encrypt_step(const unsigned INT8 *const source,    unsigned INT8 *dest)    {    INT32 block_size = THIS->block_size;    INT32 i;       for(i=0; i < block_size; i++)    THIS->iv[i] ^= source[i];
pike.git/src/post_modules/Nettle/nettle.cmod:532:    *! Acts as a buffer so that data can be fed to a cipher in blocks    *! that doesn't correspond to cipher block sizes.    */   PIKECLASS Proxy {    CVAR struct object *object;    CVAR int block_size;    CVAR unsigned char *backlog;    CVAR int backlog_len;       INIT { -  THIS->object = 0; +  THIS->object = NULL;    THIS->block_size = 0; -  THIS->backlog = 0; +  THIS->backlog = NULL;    THIS->backlog_len = 0;    }       EXIT    gc_trivial;    {    if(THIS->backlog) {    MEMSET(THIS->backlog, 0, THIS->block_size);    free(THIS->backlog); -  +  THIS->backlog = NULL;    } -  if(THIS->object) +  if(THIS->object) {    free_object(THIS->object); -  +  THIS->object = NULL;    } -  +  }       /*! @decl void create(program|object|function cipher, mixed ... args)    *! Initialize the Proxy wrapper with a cipher algorithm. If it is a    *! program, an object will be instantiated with @[args] as arguments.    *! If it is an object that doesn't conform to the cipher API, but has    *! an @[LFUN::`()], that LFUN will be called. If it is a function,    *! that function will be called with @[args] as arguments.    */    PIKEFUN void create(program|object|function cipher, mixed ... more)    flags ID_STATIC;
pike.git/src/post_modules/Nettle/nettle.cmod:810:    CVAR struct knuth_lfib_ctx *ctx;       INIT {    THIS->ctx = xalloc(sizeof(struct knuth_lfib_ctx));    }       EXIT    gc_trivial;    {    free(THIS->ctx); +  THIS->ctx = NULL;    }       /* @decl void create(int seed)    * The Lfib generator must be seeded with a number.    */    PIKEFUN void create(int seed)    flags ID_STATIC;    {    knuth_lfib_init(THIS->ctx, seed);    }