pike.git
/
src
/
post_modules
/
Nettle
/
hash.H
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/post_modules/Nettle/hash.H:67:
const struct nettle_hash *meta = THIS->meta = ((struct Nettle_Hash_struct *)parent_storage(2, Nettle_Hash_program))->meta; NO_WIDE_STRING(passwd); HMAC_SET_KEY(&THIS->ctx, meta, passwd->len, (const uint8_t *)passwd->str); } PIKEFUN string(8bit) `()(string(8bit) text) { struct cmod_CONCAT_EVAL(NETTLE_NAME, _ctx) state; int bytes = THIS->meta->digest_size; struct pike_string *dst = begin_shared_string(bytes);
+
NO_WIDE_STRING(text);
memcpy(&state, &THIS->ctx.inner, THIS->meta->context_size); THIS->meta->update(&state, text->len, (const uint8_t *)text->str); hmac_digest(&THIS->ctx.outer, &THIS->ctx.inner, &state, THIS->meta, THIS->meta->digest_size, (uint8_t *)dst->str); push_string(end_shared_string(dst)); } PIKEFUN object update(string(8bit) data) optflags OPT_SIDE_EFFECT; rawtype tFunc(tStr8, tObjImpl_NETTLE_HASH_STATE); {
-
+
NO_WIDE_STRING(data);
THIS->meta->update(&THIS->ctx.state, data->len, (const uint8_t *)data->str); push_object(this_object()); } PIKEFUN object init(string(8bit)|void data) optflags OPT_SIDE_EFFECT; rawtype tFunc(tOr(tVoid, tStr8), tObjImpl_NETTLE_HASH_STATE); { memcpy(&THIS->ctx.state, &THIS->ctx.inner, THIS->meta->context_size); if(data)
-
+
{
+
NO_WIDE_STRING(data);
THIS->meta->update(&THIS->ctx.state, data->len, (const uint8_t *)data->str);
-
+
}
push_object(this_object()); } PIKEFUN string(8bit) digest(int(0..)|void length) { int bytes = THIS->meta->digest_size; struct pike_string *dst; if(length) bytes = MINIMUM(bytes, length->u.integer); dst = begin_shared_string(bytes); hmac_digest(&THIS->ctx.outer, &THIS->ctx.inner, &THIS->ctx.state, THIS->meta, bytes, (uint8_t *)dst->str); push_string(end_shared_string(dst)); }
-
+
PIKEFUN string(8bit) digest_info(string(8bit) text)
+
{
+
struct external_variable_context loc;
+
apply_current(cmod_CONCAT_EVAL(f_Nettle_,PIKE_NAME,_cq__HMAC_State_update_fun_num),1);
+
+
/* Basically apply_external() with find_identifier() added. */
+
loc.o = Pike_fp->current_object;
+
loc.parent_identifier = Pike_fp->fun;
+
if (loc.o->prog) {
+
loc.inherit = INHERIT_FROM_INT(loc.o->prog, loc.parent_identifier);
+
find_external_context(&loc, 2);
+
int id = find_identifier("pkcs_digest", loc.o->prog);
+
if( id<0 )
+
Pike_error("Could not find pkcs_digest.\n");
+
apply_low(loc.o, id + loc.inherit->identifier_level, 1);
}
-
+
else
+
Pike_error("Apply on parent of destructed object.\n");
}
-
+
}
+
}
#endif DOCSTART() @class State *! *! State for PIKE_NAME hashing. *! DOCEND() PIKECLASS State program_flags PROGRAM_NEEDS_PARENT|PROGRAM_USES_PARENT; {