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

version» Context lines:

pike.git/src/post_modules/Nettle/nettle.cmod:552:    RETURN this_object();    }       /*! @decl string crypt(string data)    *! Encrypt/decrypt @[data] and return the result. @[data] must    *! be an integral number of blocks.    */    PIKEFUN string crypt(string data) {    unsigned INT8 *result;    INT32 offset = 0; +  ONERROR uwp;       NO_WIDE_STRING(data);       if(data->len % THIS->block_size)    Pike_error("Data length not multiple of block size.\n"); -  if(!(result = alloca(data->len))) +  +  if(!(result = malloc(data->len)))    SIMPLE_OUT_OF_MEMORY_ERROR("crypt", data->len); -  +  SET_ONERROR (uwp, free, result);       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_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); -  +  +  CALL_AND_UNSET_ONERROR (uwp);    }   }      /*! @endclass    */      /*! @class Buffer    *! @belongs Crypto    *! Acts as a buffer so that data can be fed to a cipher in blocks    *! that don't correspond to cipher block sizes.
pike.git/src/post_modules/Nettle/nettle.cmod:725:    *!    *! Adds data to be encrypted to the buffer. If there's enough    *! data to en/decrypt a block, that will be done, and the result    *! returned. Any uncrypted data will be left in the buffer.    */    PIKEFUN string crypt(string data) {    unsigned char *result;    ptrdiff_t roffset = 0;    ptrdiff_t soffset = 0;    ptrdiff_t len; +  ONERROR uwp;    -  if (!(result = alloca(data->len + THIS->block_size))) +  if (!(result = malloc(data->len + THIS->block_size)))    SIMPLE_OUT_OF_MEMORY_ERROR("crypt", data->len + THIS->block_size); -  +  SET_ONERROR (uwp, free, result);       if (THIS->backlog_len) {    if (data->len >= (THIS->block_size - THIS->backlog_len)) {    MEMCPY(THIS->backlog + THIS->backlog_len, data->str,    (THIS->block_size - THIS->backlog_len));    soffset += (THIS->block_size - THIS->backlog_len);    THIS->backlog_len = 0;    push_string(make_shared_binary_string((char *)THIS->backlog,    THIS->block_size));    safe_apply(THIS->object, "crypt", 1);
pike.git/src/post_modules/Nettle/nettle.cmod:754:    MEMCPY(result, Pike_sp[-1].u.string->str, THIS->block_size);    roffset = THIS->block_size;    pop_stack();    MEMSET(THIS->backlog, 0, THIS->block_size);    } else {    MEMCPY(THIS->backlog + THIS->backlog_len,    data->str, data->len);    THIS->backlog_len += data->len;    pop_n_elems(args);    push_empty_string(); +  CALL_AND_UNSET_ONERROR (uwp);    return;    }    }       len = (Pike_sp[-1].u.string->len - soffset);    len -= len % THIS->block_size;       if (len) {    push_string(make_shared_binary_string(Pike_sp[-1].u.string->str +    soffset, len));
pike.git/src/post_modules/Nettle/nettle.cmod:789:    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);    THIS->backlog_len = Pike_sp[-1].u.string->len - soffset;    }       pop_n_elems(args);       push_string(make_shared_binary_string((char *)result, roffset + len));    MEMSET(result, 0, roffset + len); +  CALL_AND_UNSET_ONERROR (uwp);    }       /*! @decl string pad(void|int method)    *!    *! Pad and encrypt any data left in the buffer.    *!    *! @param method    *! The type of padding to apply to the buffer.    *! @int    *! @value Crypto.PAD_SSL