88064b | 2011-12-20 | Henrik Grubbström (Grubba) | |
|
86a727 | 2013-10-05 | Henrik Grubbström (Grubba) | | DOCSTART() @class PIKE_NAME
*!
*! Implementation of the PIKE_NAME hash algorithm.
|
88064b | 2011-12-20 | Henrik Grubbström (Grubba) | | *!
DOCEND()
|
86a727 | 2013-10-05 | Henrik Grubbström (Grubba) | | PIKECLASS PIKE_NAME
|
88064b | 2011-12-20 | Henrik Grubbström (Grubba) | | {
|
86a727 | 2013-10-05 | Henrik Grubbström (Grubba) | | DOCSTART() @decl inherit Hash
DOCEND()
|
895c72 | 2014-03-29 | Henrik Grubbström (Grubba) | | INHERIT Nettle_Hash;
|
86a727 | 2013-10-05 | Henrik Grubbström (Grubba) | |
|
88064b | 2011-12-20 | Henrik Grubbström (Grubba) | | INIT
{
|
895c72 | 2014-03-29 | Henrik Grubbström (Grubba) | | struct Nettle_Hash_struct *hash;
ASSIGN_CURRENT_STORAGE(hash, struct Nettle_Hash_struct, 1,
Nettle_Hash_program);
|
86a727 | 2013-10-05 | Henrik Grubbström (Grubba) | |
werror(cmod_STRFY_EVAL(PIKE_NAME) "->INIT\n");
|
69e263 | 2013-10-20 | Henrik Grubbström (Grubba) | | hash->meta = &cmod_CONCAT_EVAL(nettle_, NETTLE_NAME);
|
88064b | 2011-12-20 | Henrik Grubbström (Grubba) | | }
|
5a1e2e | 2017-07-19 | Martin Nilsson | | #ifdef SPECIAL_PBKDF2
PIKEFUN string pbkdf2(string(8bit) password, string(8bit) salt,
int rounds, int bytes)
{
struct pike_string *dst = begin_shared_string(bytes);
NO_WIDE_STRING(password);
NO_WIDE_STRING(salt);
cmod_CONCAT_EVAL(pbkdf2_hmac_,NETTLE_NAME)(password->len,
(const uint8_t *)password->str,
rounds,
salt->len,
(const uint8_t *)salt->str,
bytes,
(uint8_t *)dst->str);
push_string(end_shared_string(dst));
}
#endif
|
d19e9c | 2017-08-01 | Martin Nilsson | | #ifdef HAVE_NETTLE_HMAC_H
PIKECLASS _HMAC
flags ID_PROTECTED;
{
EXTRA
{
inherit_internal_class(MK_STRING("_HMAC"));
}
PIKECLASS State
{
CVAR struct HMAC_CTX(struct cmod_CONCAT_EVAL(NETTLE_NAME, _ctx)) ctx;
CVAR const struct nettle_hash *meta;
EXTRA
{
inherit_internal_class(MK_STRING("State"));
}
PIKEFUN void create(string(8bit) passwd, void|int b)
{
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);
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);
{
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)
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));
}
}
}
#endif
|
86a727 | 2013-10-05 | Henrik Grubbström (Grubba) | | DOCSTART() @class State
*!
*! State for PIKE_NAME hashing.
*!
DOCEND()
PIKECLASS State
program_flags PROGRAM_NEEDS_PARENT|PROGRAM_USES_PARENT;
{
|
4561b6 | 2013-10-05 | Henrik Grubbström (Grubba) | | DOCSTART() @decl inherit Hash::State
DOCEND()
|
86a727 | 2013-10-05 | Henrik Grubbström (Grubba) | | EXTRA
{
|
0bb0ef | 2013-10-19 | Henrik Grubbström (Grubba) | | |
86a727 | 2013-10-05 | Henrik Grubbström (Grubba) | | */
|
b715e5 | 2017-07-31 | Martin Nilsson | | inherit_internal_class(MK_STRING("State"));
|
86a727 | 2013-10-05 | Henrik Grubbström (Grubba) | | }
|
88064b | 2011-12-20 | Henrik Grubbström (Grubba) | |
CVAR struct cmod_CONCAT_EVAL(NETTLE_NAME, _ctx) NETTLE_NAME;
INIT
{
|
895c72 | 2014-03-29 | Henrik Grubbström (Grubba) | | struct Nettle_Hash_State_struct *instance;
ASSIGN_CURRENT_STORAGE(instance, struct Nettle_Hash_State_struct, 1,
Nettle_Hash_State_program);
|
88064b | 2011-12-20 | Henrik Grubbström (Grubba) | |
|
69e263 | 2013-10-20 | Henrik Grubbström (Grubba) | | werror(cmod_STRFY_EVAL(PIKE_NAME) ".State->INIT\n");
|
88064b | 2011-12-20 | Henrik Grubbström (Grubba) | |
cmod_CONCAT_EVAL(NETTLE_NAME, _init)(&THIS->NETTLE_NAME);
instance->ctx = &THIS->NETTLE_NAME;
}
|
86a727 | 2013-10-05 | Henrik Grubbström (Grubba) | | }
DOCSTART() @endclass State
DOCEND()
|
88064b | 2011-12-20 | Henrik Grubbström (Grubba) | | }
|
86a727 | 2013-10-05 | Henrik Grubbström (Grubba) | | DOCSTART() @endclass PIKE_NAME
|
88064b | 2011-12-20 | Henrik Grubbström (Grubba) | | DOCEND()
|
86a727 | 2013-10-05 | Henrik Grubbström (Grubba) | |
|