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 -*- */ #include "global.h"
-
RCSID("$Id: nettle.cmod,v 1.
21
2003/12/
05
07
:
00
:
23
nilsson Exp $");
+
RCSID("$Id: nettle.cmod,v 1.
22
2003/12/
06
10
:
45
:
25
nilsson Exp $");
#include "interpret.h" #include "svalue.h" /* For this_object() */ #include "object.h" #include "module_support.h" #include "nettle_config.h" #ifdef HAVE_LIBNETTLE
pike.git/src/post_modules/Nettle/nettle.cmod:199:
*! It is assumed that @[salt] does not contain "$". */ PIKEFUN string crypt_md5(string pw, string salt) { NO_WIDE_STRING(pw); NO_WIDE_STRING(salt); RETURN make_shared_string(crypt_md5(pw->len, pw->str, salt->len, salt->str)); }
-
/*! @class CBC
-
*! Implementation of the cipher block chaining mode (CBC).
-
*/
-
PIKECLASS CBC
-
{
-
CVAR struct object *object;
-
CVAR unsigned INT8 *iv;
-
CVAR INT32 block_size;
-
CVAR INT32 mode;
+
static const char *crypto_functions[] = { "block_size", "key_size", "set_encrypt_key", "set_decrypt_key", "crypt",
-
NULL
+
0
};
-
+
static char * assert_is_crypto_object(struct program *p,
+
const char **required) {
+
while (*required) {
+
if (find_identifier( (char *) *required, p) < 0)
+
return *required;
+
required++;
+
}
+
return 0;
+
}
-
+
+
/*! @class CBC
+
*! Implementation of the cipher block chaining mode (CBC).
+
*/
+
PIKECLASS CBC
+
{
+
CVAR struct object *object;
+
CVAR unsigned INT8 *iv;
+
CVAR INT32 block_size;
+
CVAR INT32 mode;
+
INIT { THIS->object = 0; THIS->iv = 0; THIS->block_size = 0; THIS->mode = 0; } EXIT { if(THIS->object) free_object(THIS->object); if(THIS->iv) { memset(THIS->iv, 0, THIS->block_size); free(THIS->iv); } THIS->iv = 0; }
-
INLINE static void assert_is_crypto_object(struct program *p,
-
const char **required) {
-
while (*required) {
-
if (find_identifier( (char *) *required, p) < 0) {
-
Pike_error("Object is missing identifier \"%s\"\n",
-
*required);
-
}
-
required++;
-
}
-
}
-
+
INLINE static void cbc_encrypt_step(const unsigned INT8 *source, unsigned INT8 *dest) { INT32 block_size = THIS->block_size; INT32 i; for(i=0; i < block_size; i++) THIS->iv[i] ^= source[i]; push_string(make_shared_binary_string((INT8 *)THIS->iv, block_size));
pike.git/src/post_modules/Nettle/nettle.cmod:300:
dest[i] = THIS->iv[i] ^ Pike_sp[-1].u.string->str[i]; pop_stack(); MEMCPY(THIS->iv, source, block_size); } /*! @decl void create(program|object|function algorithm, mixed ... args) */ PIKEFUN void create(program|object|function algorithm, mixed ... more) { ptrdiff_t fun;
+
char *missing;
switch(algorithm->type) { case T_PROGRAM: THIS->object = clone_object(algorithm->u.program, args-1); break; case T_FUNCTION: apply_svalue(Pike_sp - args, args-1); /* Check return value */ if(Pike_sp[-1].type != T_OBJECT) Pike_error("Returned value is not an object.\n"); add_ref(THIS->object = Pike_sp[-1].u.object); break; case T_OBJECT:
-
+
fun = -1;
+
missing = assert_is_crypto_object(algorithm->u.object->prog,
+
crypto_functions);
+
if(missing)
fun = FIND_LFUN(algorithm->u.object->prog, LFUN_CALL); if(fun!=-1) { apply_low(algorithm->u.object, fun, args-1); stack_swap(); pop_stack(); } else if(args!=1) Pike_error("Too many arguments.\n"); add_ref(THIS->object = algorithm->u.object); break; default: SIMPLE_BAD_ARG_ERROR("CBC->create", 1, "program|object|function"); } pop_stack(); /* Just one element left on the stack in all cases */
-
assert_is_crypto_object(THIS->object->prog, crypto_functions);
+
missing =
assert_is_crypto_object(THIS->object->prog, crypto_functions);
+
if(missing)
+
Pike_error("Object is missing identifier \"%s\"\n", missing);
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) ||