SHA512_Init(&s);
SHA512_Bytes(&s, p, len);
SHA512_Final(&s, output);
+ smemclr(&s, sizeof(s));
}
void SHA384_Simple(const void *p, int len, unsigned char *output) {
SHA384_Init(&s);
SHA512_Bytes(&s, p, len);
SHA384_Final(&s, output);
+ smemclr(&s, sizeof(s));
}
/*
return s;
}
-static void sha512_bytes(void *handle, void *p, int len)
+static void *sha512_copy(const void *vold)
+{
+ const SHA512_State *old = (const SHA512_State *)vold;
+ SHA512_State *s;
+
+ s = snew(SHA512_State);
+ *s = *old;
+ return s;
+}
+
+static void sha512_free(void *handle)
+{
+ SHA512_State *s = handle;
+
+ smemclr(s, sizeof(*s));
+ sfree(s);
+}
+
+static void sha512_bytes(void *handle, const void *p, int len)
{
SHA512_State *s = handle;
SHA512_State *s = handle;
SHA512_Final(s, output);
- sfree(s);
+ sha512_free(s);
}
const struct ssh_hash ssh_sha512 = {
- sha512_init, sha512_bytes, sha512_final, 64, "SHA-512"
+ sha512_init, sha512_copy, sha512_bytes, sha512_final, sha512_free,
+ 64, "SHA-512"
};
static void *sha384_init(void)
SHA512_State *s = handle;
SHA384_Final(s, output);
+ smemclr(s, sizeof(*s));
sfree(s);
}
const struct ssh_hash ssh_sha384 = {
- sha384_init, sha512_bytes, sha384_final, 48, "SHA-384"
+ sha384_init, sha512_copy, sha512_bytes, sha384_final, sha512_free,
+ 48, "SHA-384"
};
#ifdef TEST