pike.git
/
src
/
post_modules
/
Nettle
/
nettle.cmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/post_modules/Nettle/nettle.cmod:1:
/* nettle.cmod -*- c -*- */
-
/*
$Id:
nettle.cmod,v 1.37 2005/12/11 18:01:46 nilsson Exp $
*/
+
/*
$Id$
*/
#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:484:
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 doesn't correspond to cipher block sizes.
pike.git/src/post_modules/Nettle/nettle.cmod:651:
*! *! 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:680:
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_constant_text("");
+
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:715:
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() *! *! Pad and de/encrypt any data left in the buffer. *! *! @seealso *! @[unpad()] */ PIKEFUN string pad() {