#endif
-static void *md5_init(void)
+static void md5_init(void *sst)
{
- struct MD5Context *ctx;
+ struct MD5Context *ctx=sst;
- NEW(ctx);
MD5Init(ctx);
-
- return ctx;
}
static void md5_update(void *sst, const void *buf, int32_t len)
struct MD5Context *ctx=sst;
MD5Final(digest,ctx);
- free(ctx);
}
struct md5 {
void md5_module(dict_t *dict)
{
struct md5 *st;
- void *ctx;
cstring_t testinput="12345\n";
uint8_t expected[16]=
{0xd5,0x77,0x27,0x3f,0xf8,0x85,0xc3,0xf8,
st->cl.type=CL_HASH;
st->cl.apply=NULL;
st->cl.interface=&st->ops;
- st->ops.len=16;
+ st->ops.hlen=16;
+ st->ops.slen=sizeof(struct MD5Context);
st->ops.init=md5_init;
st->ops.update=md5_update;
st->ops.final=md5_final;
dict_add(dict,"md5",new_closure(&st->cl));
- ctx=md5_init();
+ uint8_t ctx[st->ops.slen];
+ md5_init(ctx);
md5_update(ctx,testinput,strlen(testinput));
md5_final(ctx,digest);
for (i=0; i<16; i++) {
static void rsa_sethash(struct rsacommon *c, struct hash_if *hash)
{
free(c->hashbuf);
- c->hashbuf=safe_malloc(hash->len, "generate_msg");
+ c->hashbuf=safe_malloc(hash->hlen, "generate_msg");
c->hashi=hash;
}
static void rsa_pub_sethash(void *sst, struct hash_if *hash)
}
static void rsa_hash(struct rsacommon *c, const uint8_t *buf, int32_t len)
{
- void *hst=c->hashi->init();
+ uint8_t hst[c->hashi->slen];
+ c->hashi->init(hst);
c->hashi->update(hst,buf,len);
c->hashi->final(hst,c->hashbuf);
}
rsa_hash(&st->common,data,datalen);
/* Construct the message representative. */
- emsa_pkcs1(&st->n, &a, st->common.hashbuf, st->common.hashi->len);
+ emsa_pkcs1(&st->n, &a, st->common.hashbuf, st->common.hashi->hlen);
/*
* Produce an RSA signature (a^d mod n) using the Chinese
mpz_init(&c);
rsa_hash(&st->common,data,datalen);
- emsa_pkcs1(&st->n, &a, st->common.hashbuf, st->common.hashi->len);
+ emsa_pkcs1(&st->n, &a, st->common.hashbuf, st->common.hashi->hlen);
/* Terminate signature with a '0' - already checked that this will fit */
int save = sig->sigstart[sig->siglen];
/* HASH interface */
-typedef void *hash_init_fn(void);
+typedef void hash_init_fn(void *st /* slen bytes alloc'd by caller */);
typedef void hash_update_fn(void *st, const void *buf, int32_t len);
-typedef void hash_final_fn(void *st, uint8_t *digest);
+typedef void hash_final_fn(void *st, uint8_t *digest /* hlen bytes */);
struct hash_if {
- int32_t len; /* Hash output length in bytes */
+ int32_t slen; /* State length in bytes */
+ int32_t hlen; /* Hash output length in bytes */
hash_init_fn *init;
hash_update_fn *update;
hash_final_fn *final;
/*************************************************************/
/* Everything below here is the interface to secnet */
-static void *sha1_init(void)
+static void sha1_init(void *sst)
{
- SHA1_CTX *ctx;
+ SHA1_CTX *ctx=sst;
- NEW(ctx);
SHA1Init(ctx);
-
- return ctx;
}
static void sha1_update(void *sst, const void *buf, int32_t len)
SHA1_CTX *ctx=sst;
SHA1Final(digest,ctx);
- free(ctx);
}
struct sha1 {
void sha1_module(dict_t *dict)
{
struct sha1 *st;
- void *ctx;
cstring_t testinput="abcdbcdecdefdefgefghfghigh"
"ijhijkijkljklmklmnlmnomnopnopq";
uint8_t expected[20]=
st->cl.type=CL_HASH;
st->cl.apply=NULL;
st->cl.interface=&st->ops;
- st->ops.len=20;
+ st->ops.hlen=20;
+ st->ops.slen=sizeof(SHA1_CTX);
st->ops.init=sha1_init;
st->ops.update=sha1_update;
st->ops.final=sha1_final;
dict_add(dict,"sha1",new_closure(&st->cl));
- ctx=sha1_init();
+ uint8_t ctx[st->ops.slen];
+ sha1_init(ctx);
sha1_update(ctx,testinput,strlen(testinput));
sha1_final(ctx,digest);
for (i=0; i<20; i++) {