8 #include <botan/hash.h>
9 #include <botan/internal/commoncrypto.h>
10 #include <CommonCrypto/CommonCrypto.h>
11 #include <unordered_map>
18 class CommonCrypto_HashFunction
final :
public HashFunction
22 struct digest_config_t {
27 int (*
update)(CTX *,
const void *, CC_LONG len);
28 int (*
final)(
unsigned char *, CTX*);
34 throw CommonCrypto_Error(
"CC_" +
m_info.name +
"_Init");
37 std::string provider()
const override {
return "commoncrypto"; }
38 std::string
name()
const override {
return m_info.name; }
40 HashFunction* clone()
const override
42 return new CommonCrypto_HashFunction(
m_info);
45 std::unique_ptr<HashFunction> copy_state()
const override
47 return std::unique_ptr<CommonCrypto_HashFunction>(
51 size_t output_length()
const override
53 return m_info.digestLength;
56 size_t hash_block_size()
const override
61 CommonCrypto_HashFunction(
const digest_config_t& info) :
67 CommonCrypto_HashFunction(
const digest_config_t& info,
const CTX &ctx) :
71 void add_data(
const uint8_t input[],
size_t length)
override
74 throw CommonCrypto_Error(
"CC_" +
m_info.name +
"_Update");
77 void final_result(uint8_t output[])
override
80 throw CommonCrypto_Error(
"CC_" +
m_info.name +
"_Final");
89 std::unique_ptr<HashFunction>
92 #define MAKE_COMMONCRYPTO_HASH_3(name, hash, ctx) \
93 std::unique_ptr<HashFunction>( \
94 new CommonCrypto_HashFunction<CC_ ## ctx ## _CTX >({ \
96 CC_ ## hash ## _DIGEST_LENGTH, \
97 CC_ ## hash ## _BLOCK_BYTES, \
98 CC_ ## hash ## _Init, \
99 CC_ ## hash ## _Update, \
100 CC_ ## hash ## _Final \
103 #define MAKE_COMMONCRYPTO_HASH_2(name, id) \
104 MAKE_COMMONCRYPTO_HASH_3(name, id, id)
106 #define MAKE_COMMONCRYPTO_HASH_1(id) \
107 MAKE_COMMONCRYPTO_HASH_2(#id, id)
109 #if defined(BOTAN_HAS_SHA2_32)
110 if(name ==
"SHA-224")
112 if(name ==
"SHA-256")
115 #if defined(BOTAN_HAS_SHA2_64)
116 if(name ==
"SHA-384")
118 if(name ==
"SHA-512")
122 #if defined(BOTAN_HAS_SHA1)
123 if(name ==
"SHA-160" || name ==
"SHA-1" || name ==
"SHA1")
127 #if defined(BOTAN_HAS_MD5)
132 #if defined(BOTAN_HAS_MD4)
#define MAKE_COMMONCRYPTO_HASH_1(id)
int(* final)(unsigned char *, CTX *)
std::unique_ptr< HashFunction > make_commoncrypto_hash(const std::string &name)
#define MAKE_COMMONCRYPTO_HASH_2(name, id)
#define MAKE_COMMONCRYPTO_HASH_3(name, hash, ctx)
int(* update)(CTX *, const void *, CC_LONG len)