8 #include <botan/internal/commoncrypto.h>
9 #include <botan/hash.h>
10 #include <unordered_map>
12 #include <CommonCrypto/CommonCrypto.h>
19 class CommonCrypto_HashFunction
final :
public HashFunction
23 struct digest_config_t {
28 int (*
update)(CTX *,
const void *, CC_LONG len);
29 int (*
final)(
unsigned char *, CTX*);
35 throw CommonCrypto_Error(
"CC_" +
m_info.name +
"_Init");
38 std::string provider()
const override {
return "commoncrypto"; }
39 std::string
name()
const override {
return m_info.name; }
41 HashFunction* clone()
const override
43 return new CommonCrypto_HashFunction(
m_info);
46 std::unique_ptr<HashFunction> copy_state()
const override
48 return std::unique_ptr<CommonCrypto_HashFunction>(
52 size_t output_length()
const override
54 return m_info.digestLength;
57 size_t hash_block_size()
const override
62 CommonCrypto_HashFunction(
const digest_config_t& info) :
68 CommonCrypto_HashFunction(
const digest_config_t& info,
const CTX &ctx) :
72 void add_data(
const uint8_t input[],
size_t length)
override
77 CC_LONG update_len = (length > 0xFFFFFFFFUL) ? 0xFFFFFFFFUL : static_cast<CC_LONG>(length);
84 void final_result(uint8_t output[])
override
87 throw CommonCrypto_Error(
"CC_" +
m_info.name +
"_Final");
96 std::unique_ptr<HashFunction>
99 #define MAKE_COMMONCRYPTO_HASH_3(name, hash, ctx) \
100 std::unique_ptr<HashFunction>( \
101 new CommonCrypto_HashFunction<CC_ ## ctx ## _CTX >({ \
103 CC_ ## hash ## _DIGEST_LENGTH, \
104 CC_ ## hash ## _BLOCK_BYTES, \
105 CC_ ## hash ## _Init, \
106 CC_ ## hash ## _Update, \
107 CC_ ## hash ## _Final \
110 #define MAKE_COMMONCRYPTO_HASH_2(name, id) \
111 MAKE_COMMONCRYPTO_HASH_3(name, id, id)
113 #define MAKE_COMMONCRYPTO_HASH_1(id) \
114 MAKE_COMMONCRYPTO_HASH_2(#id, id)
116 #if defined(BOTAN_HAS_SHA2_32)
117 if(name ==
"SHA-224")
119 if(name ==
"SHA-256")
122 #if defined(BOTAN_HAS_SHA2_64)
123 if(name ==
"SHA-384")
125 if(name ==
"SHA-512")
129 #if defined(BOTAN_HAS_SHA1)
130 if(name ==
"SHA-160" || name ==
"SHA-1" || name ==
"SHA1")
134 #if defined(BOTAN_HAS_MD5)
139 #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)