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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user