Browse Source

update: independent impl namespace

master
Dnomd343 6 months ago
parent
commit
cf2c055ac4
  1. 8
      src/impl/algorithm.inc
  2. 4
      src/impl/constexpr.inc
  3. 14
      src/impl/core.cc
  4. 4
      src/impl/inline.inc
  5. 4
      src/impl/wrapper.cc
  6. 10
      src/md5.h

8
src/impl/algorithm.inc

@ -35,7 +35,7 @@
#include "sine.inc" #include "sine.inc"
namespace md5 { namespace md5::impl {
/// Hexadecimal character mapping table. /// Hexadecimal character mapping table.
constexpr char HexTable[] = { constexpr char HexTable[] = {
@ -77,8 +77,8 @@ consteval int S(int i) {
/// MD5 T-table constant, input between 0 and 63. /// MD5 T-table constant, input between 0 and 63.
consteval uint32_t T(int i) { consteval uint32_t T(int i) {
auto val = math::sin(i + 1); auto val = ::md5::math::sin(i + 1);
return static_cast<uint32_t>(std::abs(val) * 0x100000000); return static_cast<uint32_t>(::std::abs(val) * 0x100000000);
} }
} // namespace md5 } // namespace md5::impl

4
src/impl/constexpr.inc

@ -2,7 +2,7 @@
#include <array> #include <array>
namespace md5 { namespace md5::impl {
struct md5_ctx_ce { struct md5_ctx_ce {
uint32_t A = MD5_A; uint32_t A = MD5_A;
@ -74,4 +74,4 @@ constexpr std::array<char, 32> MD5::HashCE(const char *data, uint64_t len) {
return DigestCE({ctx.A, ctx.B, ctx.C, ctx.D}); return DigestCE({ctx.A, ctx.B, ctx.C, ctx.D});
} }
} // namespace md5 } // namespace md5::impl

14
src/impl/core.cc

@ -2,7 +2,7 @@
#include "md5.h" #include "md5.h"
namespace md5 { using ::md5::impl::MD5;
static constexpr unsigned char Padding[64] { 0x80, /* 0x00, ... */ }; static constexpr unsigned char Padding[64] { 0x80, /* 0x00, ... */ };
@ -43,18 +43,16 @@ void MD5::FinalImpl(const void *data, uint64_t len) {
} }
unsigned char buffer[128]; // 2 blocks unsigned char buffer[128]; // 2 blocks
std::memcpy(buffer, data, len); ::std::memcpy(buffer, data, len);
uint64_t total = (ctx_.size + len) << 3; // total number in bit uint64_t total = (ctx_.size + len) << 3; // total number in bit
if (len < 56) { // len -> [0, 56) if (len < 56) { // len -> [0, 56)
std::memcpy(buffer + len, Padding, 56 - len); ::std::memcpy(buffer + len, Padding, 56 - len);
std::memcpy(buffer + 56, &total, 8); ::std::memcpy(buffer + 56, &total, 8);
UpdateImpl(buffer, 64); // update 1 block UpdateImpl(buffer, 64); // update 1 block
} else { // len -> [56, 64 + 56) } else { // len -> [56, 64 + 56)
std::memcpy(buffer + len, Padding, 120 - len); ::std::memcpy(buffer + len, Padding, 120 - len);
std::memcpy(buffer + 120, &total, 8); ::std::memcpy(buffer + 120, &total, 8);
UpdateImpl(buffer, 128); // update 2 blocks UpdateImpl(buffer, 128); // update 2 blocks
} }
} }
} // namespace md5

4
src/impl/inline.inc

@ -1,6 +1,6 @@
#pragma once #pragma once
namespace md5 { namespace md5::impl {
inline MD5& MD5::Reset() { inline MD5& MD5::Reset() {
ctx_.A = MD5_A; ctx_.A = MD5_A;
@ -35,4 +35,4 @@ constexpr std::array<char, 32> MD5::HashCE(const std::string_view &data) {
return HashCE(data.data(), data.size()); return HashCE(data.data(), data.size());
} }
} // namespace md5 } // namespace md5::impl

4
src/impl/wrapper.cc

@ -2,7 +2,7 @@
#include "md5.h" #include "md5.h"
namespace md5 { using ::md5::impl::MD5;
std::string MD5::Digest() const { std::string MD5::Digest() const {
std::string result {}; std::string result {};
@ -39,5 +39,3 @@ MD5& MD5::Update(const void *data, uint64_t len) {
} }
return *this; return *this;
} }
} // namespace md5

10
src/md5.h

@ -12,7 +12,7 @@ static_assert(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__,
#include "impl/algorithm.inc" #include "impl/algorithm.inc"
namespace md5 { namespace md5::impl {
class MD5 { class MD5 {
public: public:
@ -58,7 +58,13 @@ private:
void FinalImpl(const void *data, uint64_t len); void FinalImpl(const void *data, uint64_t len);
}; };
} // namespace md5 } // namespace md5::impl
#include "impl/inline.inc" #include "impl/inline.inc"
#include "impl/constexpr.inc" #include "impl/constexpr.inc"
namespace md5 {
using MD5 = ::md5::impl::MD5;
} // namespace md5

Loading…
Cancel
Save