diff options
author | Jack Lloyd <[email protected]> | 2018-09-04 10:29:05 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-09-04 10:29:05 -0400 |
commit | 9cf8f1965e04a06419f5df60ae5f1520f6cda433 (patch) | |
tree | 389c04c023fc7921351a0799d12b629c9cfc9aa5 /src/lib | |
parent | b073b7430285d7a5079380a71e0be925250c50e5 (diff) |
Indent to match conventions.
Move CommonCrypto.h out of our commoncrypto.h since that header is
included around the library.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/prov/commoncrypto/commoncrypto.h | 2 | ||||
-rw-r--r-- | src/lib/prov/commoncrypto/commoncrypto_hash.cpp | 146 |
2 files changed, 73 insertions, 75 deletions
diff --git a/src/lib/prov/commoncrypto/commoncrypto.h b/src/lib/prov/commoncrypto/commoncrypto.h index da4adc8bf..34b2a3f35 100644 --- a/src/lib/prov/commoncrypto/commoncrypto.h +++ b/src/lib/prov/commoncrypto/commoncrypto.h @@ -14,8 +14,6 @@ #include <memory> #include <string> -#include <CommonCrypto/CommonCrypto.h> - namespace Botan { class HashFunction; diff --git a/src/lib/prov/commoncrypto/commoncrypto_hash.cpp b/src/lib/prov/commoncrypto/commoncrypto_hash.cpp index 81afa0e01..bb5a5debe 100644 --- a/src/lib/prov/commoncrypto/commoncrypto_hash.cpp +++ b/src/lib/prov/commoncrypto/commoncrypto_hash.cpp @@ -7,7 +7,7 @@ #include <botan/hash.h> #include <botan/internal/commoncrypto.h> - +#include <CommonCrypto/CommonCrypto.h> #include <unordered_map> namespace Botan { @@ -19,67 +19,67 @@ class CommonCrypto_HashFunction final : public HashFunction { public: - struct digest_config_t { - std::string name; - size_t digestLength; - size_t blockSize; - int (*init)(CTX *); - int (*update)(CTX *, const void *, CC_LONG len); - int (*final)(unsigned char *, CTX*); - }; - - void clear() override - { - if(m_info.init(&m_ctx) != 1) - throw CommonCrypto_Error("CC_" + m_info.name + "_Init"); - } - - std::string provider() const override { return "commoncrypto"; } - std::string name() const override { return m_info.name; } - - HashFunction* clone() const override - { - return new CommonCrypto_HashFunction(m_info); - } - - std::unique_ptr<HashFunction> copy_state() const override - { - return std::unique_ptr<CommonCrypto_HashFunction>( - new CommonCrypto_HashFunction(m_info, m_ctx)); - } - - size_t output_length() const override - { - return m_info.digestLength; - } - - size_t hash_block_size() const override - { - return m_info.blockSize; - } - - CommonCrypto_HashFunction(const digest_config_t& info) : - m_info(info) - { - clear(); - } - - CommonCrypto_HashFunction(const digest_config_t& info, const CTX &ctx) : - m_ctx(ctx), m_info(info) {} + struct digest_config_t { + std::string name; + size_t digestLength; + size_t blockSize; + int (*init)(CTX *); + int (*update)(CTX *, const void *, CC_LONG len); + int (*final)(unsigned char *, CTX*); + }; + + void clear() override + { + if(m_info.init(&m_ctx) != 1) + throw CommonCrypto_Error("CC_" + m_info.name + "_Init"); + } + + std::string provider() const override { return "commoncrypto"; } + std::string name() const override { return m_info.name; } + + HashFunction* clone() const override + { + return new CommonCrypto_HashFunction(m_info); + } + + std::unique_ptr<HashFunction> copy_state() const override + { + return std::unique_ptr<CommonCrypto_HashFunction>( + new CommonCrypto_HashFunction(m_info, m_ctx)); + } + + size_t output_length() const override + { + return m_info.digestLength; + } + + size_t hash_block_size() const override + { + return m_info.blockSize; + } + + CommonCrypto_HashFunction(const digest_config_t& info) : + m_info(info) + { + clear(); + } + + CommonCrypto_HashFunction(const digest_config_t& info, const CTX &ctx) : + m_ctx(ctx), m_info(info) {} private: void add_data(const uint8_t input[], size_t length) override - { - if(m_info.update(&m_ctx, input, length) != 1) + { + if(m_info.update(&m_ctx, input, length) != 1) throw CommonCrypto_Error("CC_" + m_info.name + "_Update"); - } + } void final_result(uint8_t output[]) override - { - if(m_info.final(output, &m_ctx) != 1) + { + if(m_info.final(output, &m_ctx) != 1) throw CommonCrypto_Error("CC_" + m_info.name + "_Final"); - clear(); - } + clear(); + } CTX m_ctx; digest_config_t m_info; @@ -89,28 +89,28 @@ class CommonCrypto_HashFunction final : public HashFunction std::unique_ptr<HashFunction> make_commoncrypto_hash(const std::string& name) { -#define MAKE_COMMONCRYPTO_HASH_3(name, hash, ctx) \ - std::unique_ptr<HashFunction>( \ - new CommonCrypto_HashFunction<CC_ ## ctx ## _CTX >({ \ - name, \ - CC_ ## hash ## _DIGEST_LENGTH, \ - CC_ ## hash ## _BLOCK_BYTES, \ - CC_ ## hash ## _Init, \ - CC_ ## hash ## _Update, \ - CC_ ## hash ## _Final \ - })); - -#define MAKE_COMMONCRYPTO_HASH_2(name, id) \ - MAKE_COMMONCRYPTO_HASH_3(name, id, id) - -#define MAKE_COMMONCRYPTO_HASH_1(id) \ - MAKE_COMMONCRYPTO_HASH_2(#id, id) +#define MAKE_COMMONCRYPTO_HASH_3(name, hash, ctx) \ + std::unique_ptr<HashFunction>( \ + new CommonCrypto_HashFunction<CC_ ## ctx ## _CTX >({ \ + name, \ + CC_ ## hash ## _DIGEST_LENGTH, \ + CC_ ## hash ## _BLOCK_BYTES, \ + CC_ ## hash ## _Init, \ + CC_ ## hash ## _Update, \ + CC_ ## hash ## _Final \ + })); + +#define MAKE_COMMONCRYPTO_HASH_2(name, id) \ + MAKE_COMMONCRYPTO_HASH_3(name, id, id) + +#define MAKE_COMMONCRYPTO_HASH_1(id) \ + MAKE_COMMONCRYPTO_HASH_2(#id, id) #if defined(BOTAN_HAS_SHA2_32) if(name == "SHA-224") return MAKE_COMMONCRYPTO_HASH_3(name, SHA224, SHA256); if(name == "SHA-256") - return MAKE_COMMONCRYPTO_HASH_2(name, SHA256); + return MAKE_COMMONCRYPTO_HASH_2(name, SHA256); #endif #if defined(BOTAN_HAS_SHA2_64) if(name == "SHA-384") @@ -127,7 +127,7 @@ make_commoncrypto_hash(const std::string& name) #if defined(BOTAN_HAS_MD5) if(name == "MD5") return MAKE_COMMONCRYPTO_HASH_1(MD5); - #endif +#endif #if defined(BOTAN_HAS_MD4) if(name == "MD4") |