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.30 2004/02/04 12:58:22 nilsson Exp $"); + RCSID("$Id: nettle.cmod,v 1.31 2004/02/04 21:36:29 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:487:       pop_n_elems(args);    push_string(make_shared_binary_string((INT8 *)result, offset));    MEMSET(result, 0, offset);    }   }      /*! @endclass    */    - /*! @class Proxy + /*! @class Buffer    *! 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 {
pike.git/src/post_modules/Nettle/nettle.cmod:653:    len -= len % THIS->block_size;       if (len) {    push_string(make_shared_binary_string(Pike_sp[-1].u.string->str +    soffset, len));    soffset += len;       safe_apply(THIS->object, "crypt", 1);       if (Pike_sp[-1].type != T_STRING) -  Pike_error("crypt() did not return string\n"); +  Pike_error("crypt() did not return string.\n");    if (Pike_sp[-1].u.string->len != len) -  Pike_error("crypt() Unexpected string length %ld\n", +  Pike_error("crypt() Unexpected string length %ld.\n",    DO_NOT_WARN((long)Pike_sp[-1].u.string->len));       MEMCPY(result + roffset, Pike_sp[-1].u.string->str, len);       pop_stack();    }       if (soffset < Pike_sp[-1].u.string->len) {    MEMCPY(THIS->backlog, Pike_sp[-1].u.string->str + soffset,    Pike_sp[-1].u.string->len - soffset);
pike.git/src/post_modules/Nettle/nettle.cmod:689:    *! @seealso    *! @[unpad()]    */    PIKEFUN string pad() {    ptrdiff_t i;       for (i = THIS->backlog_len; i < THIS->block_size - 1; i++)    THIS->backlog[i] = DO_NOT_WARN((unsigned char)(my_rand() & 0xff));       THIS->backlog[THIS->block_size - 1] = -  DO_NOT_WARN((unsigned char)(7 - THIS->backlog_len)); +  DO_NOT_WARN((unsigned char)(THIS->block_size - THIS->backlog_len - 1));       push_string(make_shared_binary_string((const char *)THIS->backlog,    THIS->block_size));       MEMSET(THIS->backlog, 0, THIS->block_size);    THIS->backlog_len = 0;       safe_apply(THIS->object, "crypt", 1);    }       /*! @decl string unpad(string data)    *!    *! De/encrypt and unpad a block of data.    *!    *! This performs the reverse operation of @[pad()].    *!    *! @seealso    *! @[pad()]    */ -  PIKEFUN string unpad(string data) { +  PIKEFUN string unpad(string str) {    ptrdiff_t len; -  struct pike_string *str; +     -  str = Pike_sp[-1].u.string; +     len = str->len;    -  +  if( len % THIS->block_size) +  Pike_error("String must be integral numbers of blocks.\n"); +  safe_apply(THIS->object, "crypt", 1); +  if (Pike_sp[-1].type != T_STRING) +  Pike_error("crypt() did not return string.\n"); +  if (Pike_sp[-1].u.string->len != len) +  Pike_error("crypt() Unexpected string length %ld.\n", +  DO_NOT_WARN((long)Pike_sp[-1].u.string->len)); +  str = Pike_sp[-1].u.string; +     if (str->str[len - 1] > (THIS->block_size - 1)) -  Pike_error("Invalid padding\n"); +  Pike_error("Invalid padding (%d > %d)\n", +  str->str[len-1], THIS->block_size-1);       len -= (str->str[len - 1] + 1);       if (len < 0)    Pike_error("String to short to unpad\n");       add_ref(str);    pop_stack();    push_string(make_shared_binary_string(str->str, len));    free_string(str);