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.57 2010/06/22 12:56:42 nilsson Exp $ */ + /* $Id: nettle.cmod,v 1.58 2010/06/22 14:30:13 grubba 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:588:    MEMSET(result, 0, offset);    }   }      /*! @endclass    */      /*! @class Buffer    *! @belongs Crypto    *! Acts as a buffer so that data can be fed to a cipher in blocks -  *! that doesn't correspond to cipher block sizes. +  *! that don'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 = NULL;    THIS->block_size = 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) {    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_PROTECTED;    { -  +  exit_Proxy_struct();    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) ||
pike.git/src/post_modules/Nettle/nettle.cmod:791:    }       pop_n_elems(args);       push_string(make_shared_binary_string((char *)result, roffset + len));    MEMSET(result, 0, roffset + len);    }       /*! @decl string pad(void|int method)    *! -  *! Pad and decrypt any data left in the buffer. +  *! Pad and encrypt any data left in the buffer.    *!    *! @param method -  *! What type of padding was applied to the original buffer. +  *! The type of padding to apply to the buffer.    *! @int    *! @value Crypto.PAD_SSL    *! @value Crypto.PAD_ISO_10126    *! @value Crypto.PAD_ANSI_X923    *! @value Crypto.PAD_PKCS7    *! @value Crypto.PAD_ZERO    *! @endint    *! Defaults to Crypto.PAD_SSL for compatibility reasons.    *!    *! @seealso
pike.git/src/post_modules/Nettle/nettle.cmod:870:    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, void|int method)    *! -  *! Encrypt and unpad a block of data. +  *! Decrypt and unpad a block of data.    *!    *! This performs the reverse operation of @[pad()].    *!    *! @param method -  *! What type of padding was applied to the original buffer. +  *! The type of padding that was applied to the original buffer.    *! @int    *! @value Crypto.PAD_SSL    *! @value Crypto.PAD_ISO_10126    *! @value Crypto.PAD_ANSI_X923    *! @value Crypto.PAD_PKCS7    *! @value Crypto.PAD_ZERO    *! @endint    *! Defaults to Crypto.PAD_SSL for compatibility reasons.    *!    *! @seealso
pike.git/src/post_modules/Nettle/nettle.cmod:941:    int c=THIS->block_size;    while( str->str[len-1]==0 && c>0 )    {    c--;    len--;    }    }    }       if (len < 0) -  Pike_error("String to short to unpad\n"); +  Pike_error("String too short to unpad\n");       add_ref(str);    pop_stack();    push_string(make_shared_binary_string(str->str, len));    free_string(str);    }   }      /*! @endclass    */