#include <openssl/sha.h>
#include <openssl/bn.h>
#include <openssl/aes.h>
+#include <openssl/evp.h>
#include "para.h"
#include "error.h"
void hash_function(const char *data, unsigned long len, unsigned char *hash)
{
- SHA_CTX c;
- SHA1_Init(&c);
- SHA1_Update(&c, data, len);
- SHA1_Final(hash, &c);
+ EVP_MD_CTX *c = EVP_MD_CTX_new();
+ int ret = EVP_DigestInit_ex(c, EVP_sha1(), NULL);
+ assert(ret != 0);
+ ret = EVP_DigestUpdate(c, data, len);
+ assert(ret != 0);
+ ret = EVP_DigestFinal_ex(c, hash, NULL);
+ assert(ret != 0);
+ EVP_MD_CTX_free(c);
}
void hash2_function(const char *data, unsigned long len, unsigned char *hash)
{
- SHA256_CTX c;
- SHA256_Init(&c);
- SHA256_Update(&c, data, len);
- SHA256_Final(hash, &c);
+ EVP_MD_CTX *c = EVP_MD_CTX_new();
+ int ret = EVP_DigestInit_ex(c, EVP_sha256(), NULL);
+ assert(ret != 0);
+ ret = EVP_DigestUpdate(c, data, len);
+ assert(ret != 0);
+ ret = EVP_DigestFinal_ex(c, hash, NULL);
+ assert(ret != 0);
+ EVP_MD_CTX_free(c);
}