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.29 2004/01/29 23:16:03 nilsson Exp $"); + RCSID("$Id: nettle.cmod,v 1.30 2004/02/04 12:58:22 nilsson Exp $");   #include "interpret.h"   #include "svalue.h"   /* For this_object() */   #include "object.h"   #include "operators.h"   #include "module_support.h"      #include "nettle_config.h"      #ifdef HAVE_LIBNETTLE
pike.git/src/post_modules/Nettle/nettle.cmod:355:    DO_NOT_WARN((long)Pike_sp[-1].u.string->len));    }       for(i=0; i < block_size; i++)    dest[i] = THIS->iv[i] ^ Pike_sp[-1].u.string->str[i];       pop_stack();    MEMCPY(THIS->iv, source, block_size);    }    -  static void cbc_free_this_object() { -  if(THIS->object) free_object(THIS->object); -  } -  +     /*! @decl void create(program|object|function cipher, mixed ... args)    *! Initialize the CBC 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) { -  +  int old_block_size = THIS->block_size;    THIS->object = make_cipher_object(args);       safe_apply(THIS->object, "block_size", 0);       if(Pike_sp[-1].type != T_INT)    Pike_error("block_size() didn't return an int.\n"); -  +     THIS->block_size = Pike_sp[-1].u.integer;       pop_stack();       if ((!THIS->block_size) ||    (THIS->block_size > 4096))    Pike_error("Bad block size %d.\n", THIS->block_size);    -  +  if(THIS->iv) { +  MEMSET(THIS->iv, 0, old_block_size); +  free(THIS->iv); +  }    THIS->iv = (unsigned INT8 *)xalloc(THIS->block_size);    MEMSET(THIS->iv, 0, THIS->block_size);    }       /*! @decl string name()    *! Returns the string @expr{"CBC(x)"@} where x is the    *! encapsulated algorithm.    */    PIKEFUN string name() {    push_constant_text("CBC(");
pike.git/src/post_modules/Nettle/nettle.cmod:427:    safe_apply(THIS->object, "set_encrypt_key", args);    pop_stack();    RETURN this_object();    }       /*! @decl this_program set_decrypt_key(string key)    *! Prepare the cipher and the wrapper for decrypting    *! with the given @[key].    */    PIKEFUN object set_decrypt_key(string key) { -  f_CBC_set_encrypt_key(args); +  assert(THIS->block_size);    THIS->mode = 1; -  +  safe_apply(THIS->object, "set_decrypt_key", args); +  pop_stack(); +  RETURN this_object();    }       /*! @decl this_program set_iv(string iv)    *! Set the initialization vector to @[iv].    */    PIKEFUN object set_iv(string iv) {    assert(THIS->iv);    NO_WIDE_STRING(iv);    if(iv->len != THIS->block_size)    Pike_error("Argument incompatible with cipher block size.\n");
pike.git/src/post_modules/Nettle/nettle.cmod:467:       if(THIS->mode == 0) {    while (offset < data->len) {    cbc_encrypt_step((const unsigned INT8 *)data->str + offset,    result + offset);    offset += THIS->block_size;    }    }    else {    while (offset < data->len) { -  cbc_encrypt_step((const unsigned INT8 *)data->str + offset, +  cbc_decrypt_step((const unsigned INT8 *)data->str + offset,    result + offset);    offset += THIS->block_size;    }    }       pop_n_elems(args);    push_string(make_shared_binary_string((INT8 *)result, offset));    MEMSET(result, 0, offset);    }   }