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>
namespace util {
namespace hash {
class MD2 {
public:
typedef std::array<uint8_t,16> digest_t;
namespace util { namespace hash {
class MD2 {
public:
typedef std::array<uint8_t,16> digest_t;
public:
MD2 ();
public:
MD2 ();
void update (const uint8_t *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 *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 finish (void);
digest_t digest (void) const;
void reset (void);
void finish (void);
digest_t digest (void) const;
void reset (void);
private:
void transform (void);
private:
void transform (void);
uint64_t m_total;
uint64_t m_total;
uint8_t C[16];
uint8_t X[48];
};
}
}
uint8_t C[16];
uint8_t X[48];
};
} }
#endif

View File

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

View File

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

View File

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

View File

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