hash: class decleration style

This commit is contained in:
Danny Robson 2016-06-17 15:57:09 +10:00
parent 51487cd34e
commit ef17f9c7d1
5 changed files with 109 additions and 119 deletions

View File

@ -21,32 +21,30 @@
#include <cstdint> #include <cstdint>
namespace util { namespace util { namespace hash {
namespace hash { class MD2 {
class MD2 { public:
public: typedef std::array<uint8_t,16> digest_t;
typedef std::array<uint8_t,16> digest_t;
public: public:
MD2 (); MD2 ();
void update (const uint8_t *data, size_t len); void update (const uint8_t *data, size_t len);
void update (const void *data, size_t len); void update (const void *data, size_t len);
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
void finish (void); void finish (void);
digest_t digest (void) const; digest_t digest (void) const;
void reset (void); void reset (void);
private: private:
void transform (void); void transform (void);
uint64_t m_total; uint64_t m_total;
uint8_t C[16]; uint8_t C[16];
uint8_t X[48]; uint8_t X[48];
}; };
} } }
}
#endif #endif

View File

@ -20,35 +20,33 @@
#include <array> #include <array>
#include <cstdint> #include <cstdint>
namespace util { namespace util { namespace hash {
namespace hash { class MD4 {
class MD4 { public:
public: typedef std::array<uint8_t,16> digest_t;
typedef std::array<uint8_t,16> digest_t;
public: public:
MD4(); MD4();
void update (const void *data, size_t len); void update (const void *data, size_t len);
void update (const uint8_t *data, size_t len); void update (const uint8_t *data, size_t len);
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
void finish (void); void finish (void);
digest_t digest (void) const; digest_t digest (void) const;
void reset (void); void reset (void);
private:
void transform (void);
uint64_t m_total; private:
void transform (void);
std::array<uint32_t,4> ABCD; uint64_t m_total;
union {
uint32_t X [16]; std::array<uint32_t,4> ABCD;
uint8_t Xb[64]; union {
}; uint32_t X [16];
uint8_t Xb[64];
}; };
} };
} } }
#endif #endif

View File

@ -21,40 +21,38 @@
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
namespace util { namespace util { namespace hash {
namespace hash { class MD5 {
class MD5 { public:
public: typedef std::array<uint8_t,16> digest_t;
typedef std::array<uint8_t,16> digest_t; static const size_t BLOCK_SIZE = 64;
static const size_t BLOCK_SIZE = 64; static const size_t DIGEST_SIZE = 16;
static const size_t DIGEST_SIZE = 16;
public: public:
MD5(); MD5();
void update (const void *data, size_t len); void update (const void *data, size_t len);
void update (const uint8_t *data, size_t len); void update (const uint8_t *data, size_t len);
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
void finish (void); void finish (void);
digest_t digest (void) const; digest_t digest (void) const;
void reset (void); void reset (void);
private: private:
void transform (void); void transform (void);
uint64_t m_total; uint64_t m_total;
std::array<uint32_t, 4> ABCD; std::array<uint32_t, 4> ABCD;
union { union {
uint32_t X [16]; uint32_t X [16];
uint8_t Xb[64]; uint8_t Xb[64];
};
}; };
} };
typedef uint8_t md5_t; typedef uint8_t md5_t;
md5_t md5 (const void *restrict data, size_t len); md5_t md5 (const void *restrict data, size_t len);
} } }
#endif #endif

View File

@ -20,39 +20,37 @@
#include <array> #include <array>
namespace util { namespace util { namespace hash {
namespace hash { class RIPEMD {
class RIPEMD { public:
public: typedef std::array<uint8_t,20> digest_t;
typedef std::array<uint8_t,20> digest_t;
public: public:
RIPEMD(); RIPEMD();
void update (const uint8_t*, size_t); void update (const uint8_t*, size_t);
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
digest_t digest (void) const; digest_t digest (void) const;
void finish (void); void finish (void);
void reset (void); void reset (void);
protected: protected:
void transform (); void transform ();
bool m_finished; bool m_finished;
uint32_t m_state[5]; uint32_t m_state[5];
uint64_t m_length; uint64_t m_length;
struct { struct {
union { union {
uint32_t d32[16]; uint32_t d32[16];
uint8_t d08[64]; uint8_t d08[64];
}; };
size_t size; size_t size;
} m_buffer; } m_buffer;
}; };
} } }
}
#endif #endif

View File

@ -21,35 +21,33 @@
#include <array> #include <array>
#include <cstdint> #include <cstdint>
namespace util { namespace util { namespace hash {
namespace hash { class SHA256 {
class SHA256 { public:
public: typedef std::array<uint8_t,32> digest_t;
typedef std::array<uint8_t,32> digest_t;
public: public:
SHA256(); SHA256();
void update (const uint8_t *, size_t); void update (const uint8_t *, size_t);
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
void finish (void); void finish (void);
digest_t digest (void) const; digest_t digest (void) const;
void reset (void); void reset (void);
private: private:
void process (void); void process (void);
uint64_t m_total; uint64_t m_total;
std::array<uint32_t, 8> H; std::array<uint32_t, 8> H;
union { union {
std::array<uint32_t, 16> M; std::array<uint32_t, 16> M;
std::array<uint8_t, 64> C; std::array<uint8_t, 64> C;
};
}; };
} };
} } }
#endif #endif