1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-30 13:01:23 +03:00

crypto: Add evp hashing function.

This commit is contained in:
Andreas Schneider
2012-02-04 23:37:25 +01:00
parent fb6855a821
commit 216cb8b1aa
4 changed files with 40 additions and 0 deletions

View File

@@ -97,6 +97,34 @@ void sha1(unsigned char *digest, int len, unsigned char *hash) {
SHA1(digest, len, hash);
}
#ifdef HAVE_OPENSSL_ECC
static const EVP_MD *nid_to_evpmd(int nid)
{
switch (nid) {
case NID_X9_62_prime256v1:
return EVP_sha256();
case NID_secp384r1:
return EVP_sha384();
case NID_secp521r1:
return EVP_sha512();
default:
return NULL;
}
return NULL;
}
void evp(int nid, unsigned char *digest, int len, unsigned char *hash, unsigned int *hlen)
{
const EVP_MD *evp_md = nid_to_evpmd(nid);
EVP_MD_CTX md;
EVP_DigestInit(&md, evp_md);
EVP_DigestUpdate(&md, digest, len);
EVP_DigestFinal(&md, hash, hlen);
}
#endif
SHA256CTX sha256_init(void){
SHA256CTX c = malloc(sizeof(*c));
if (c == NULL) {