8 #include <botan/internal/openssl_engine.h> 9 #include <openssl/evp.h> 11 #if OPENSSL_VERSION_NUMBER >= 0x10100000 12 #error "OpenSSL 1.1 API not supported in Botan 1.10, upgrade to 2.x" 22 class EVP_HashFunction :
public HashFunction
26 std::string name()
const {
return algo_name; }
27 HashFunction* clone()
const;
29 size_t output_length()
const 31 return EVP_MD_size(EVP_MD_CTX_md(&md));
34 size_t hash_block_size()
const 36 return EVP_MD_block_size(EVP_MD_CTX_md(&md));
39 EVP_HashFunction(
const EVP_MD*,
const std::string&);
42 void add_data(
const byte[],
size_t);
43 void final_result(
byte[]);
46 std::string algo_name;
53 void EVP_HashFunction::add_data(
const byte input[],
size_t length)
55 EVP_DigestUpdate(&md, input, length);
61 void EVP_HashFunction::final_result(
byte output[])
63 EVP_DigestFinal_ex(&md, output, 0);
64 const EVP_MD* algo = EVP_MD_CTX_md(&md);
65 EVP_DigestInit_ex(&md, algo, 0);
71 void EVP_HashFunction::clear()
73 const EVP_MD* algo = EVP_MD_CTX_md(&md);
74 EVP_DigestInit_ex(&md, algo, 0);
80 HashFunction* EVP_HashFunction::clone()
const 82 const EVP_MD* algo = EVP_MD_CTX_md(&md);
83 return new EVP_HashFunction(algo, name());
89 EVP_HashFunction::EVP_HashFunction(
const EVP_MD* algo,
90 const std::string& name) :
94 EVP_DigestInit_ex(&md, algo, 0);
100 EVP_HashFunction::~EVP_HashFunction()
102 EVP_MD_CTX_cleanup(&md);
113 #if !defined(OPENSSL_NO_SHA) 115 return new EVP_HashFunction(EVP_sha1(),
"SHA-160");
118 #if !defined(OPENSSL_NO_SHA256) 120 return new EVP_HashFunction(EVP_sha224(),
"SHA-224");
122 return new EVP_HashFunction(EVP_sha256(),
"SHA-256");
125 #if !defined(OPENSSL_NO_SHA512) 127 return new EVP_HashFunction(EVP_sha384(),
"SHA-384");
129 return new EVP_HashFunction(EVP_sha512(),
"SHA-512");
132 #if !defined(OPENSSL_NO_MD2) 134 return new EVP_HashFunction(EVP_md2(),
"MD2");
137 #if !defined(OPENSSL_NO_MD4) 139 return new EVP_HashFunction(EVP_md4(),
"MD4");
142 #if !defined(OPENSSL_NO_MD5) 144 return new EVP_HashFunction(EVP_md5(),
"MD5");
147 #if !defined(OPENSSL_NO_RIPEMD) 149 return new EVP_HashFunction(EVP_ripemd160(),
"RIPEMD-160");
HashFunction * find_hash(const SCAN_Name &, Algorithm_Factory &) const
std::string algo_name() const