From bb63a50c1d9503d82c3e1df591971293d34c8351 Mon Sep 17 00:00:00 2001 From: Matheus Lima Date: Wed, 26 Mar 2025 15:54:06 -0300 Subject: [PATCH 1/3] fix: try to fix build on ubuntu --- .../algorithm/detail/kupyna_provider.hpp | 337 +++++++++--------- 1 file changed, 169 insertions(+), 168 deletions(-) diff --git a/VCMP-LUA/modules/crypto/include/algorithm/detail/kupyna_provider.hpp b/VCMP-LUA/modules/crypto/include/algorithm/detail/kupyna_provider.hpp index cec5eb0..30ed4b8 100644 --- a/VCMP-LUA/modules/crypto/include/algorithm/detail/kupyna_provider.hpp +++ b/VCMP-LUA/modules/crypto/include/algorithm/detail/kupyna_provider.hpp @@ -10,186 +10,187 @@ This code is written by kerukuro and released into public domain. #include "../../detail/validate_hash_size.hpp" #include "constants/kupyna_constants.hpp" #include +#include namespace digestpp { -namespace detail -{ - -namespace kupyna_functions -{ - template - static inline void G(uint64_t* x, uint64_t* y) - { - for (int c = 0; c != R; ++c) - y[c] = kupyna_constants::T[0][static_cast(x[(c + R) % R])] - ^ kupyna_constants::T[1][static_cast(x[(c + R - 1) % R] >> 8)] - ^ kupyna_constants::T[2][static_cast(x[(c + R - 2) % R] >> 16)] - ^ kupyna_constants::T[3][static_cast(x[(c + R - 3) % R] >> 24)] - ^ kupyna_constants::T[4][static_cast(x[(c + R - 4) % R] >> 32)] - ^ kupyna_constants::T[5][static_cast(x[(c + R - 5) % R] >> 40)] - ^ kupyna_constants::T[6][static_cast(x[(c + R - 6) % R] >> 48)] - ^ kupyna_constants::T[7][static_cast(x[(c + R - (R == 16 ? 11 : 7)) % R] >> 56)]; - } - - template - static inline void roundP(uint64_t* x, uint64_t* y, uint64_t i) - { - for (int idx = 0; idx < R; idx++) - x[idx] ^= (static_cast(idx) << 4) ^ i; - - G(x, y); - } - - template - static inline void roundQ(uint64_t* x, uint64_t* y, uint64_t i) + namespace detail { - for (int j = 0; j < R; ++j) - x[j] += (0x00F0F0F0F0F0F0F3ULL - ^ ((static_cast(((R - 1 - j) * 0x10) ^ static_cast(i))) << 56)); - G(x, y); - } - - template - static inline void transform(uint64_t* h, const uint64_t* m) - { - uint64_t AQ1[R], AQ2[R], AP1[R], AP2[R]; - - for (int column = 0; column < R; column++) + namespace kupyna_functions { - AP1[column] = h[column] ^ m[column]; - AQ1[column] = m[column]; - } + template + static inline void G(uint64_t* x, uint64_t* y) + { + for (int c = 0; c != R; ++c) + y[c] = kupyna_constants::T[0][static_cast(x[(c + R) % R])] + ^ kupyna_constants::T[1][static_cast(x[(c + R - 1) % R] >> 8)] + ^ kupyna_constants::T[2][static_cast(x[(c + R - 2) % R] >> 16)] + ^ kupyna_constants::T[3][static_cast(x[(c + R - 3) % R] >> 24)] + ^ kupyna_constants::T[4][static_cast(x[(c + R - 4) % R] >> 32)] + ^ kupyna_constants::T[5][static_cast(x[(c + R - 5) % R] >> 40)] + ^ kupyna_constants::T[6][static_cast(x[(c + R - 6) % R] >> 48)] + ^ kupyna_constants::T[7][static_cast(x[(c + R - (R == 16 ? 11 : 7)) % R] >> 56)]; + } + + template + static inline void roundP(uint64_t* x, uint64_t* y, uint64_t i) + { + for (int idx = 0; idx < R; idx++) + x[idx] ^= (static_cast(idx) << 4) ^ i; + + G(x, y); + } + + template + static inline void roundQ(uint64_t* x, uint64_t* y, uint64_t i) + { + for (int j = 0; j < R; ++j) + x[j] += (0x00F0F0F0F0F0F0F3ULL + ^ ((static_cast(((R - 1 - j) * 0x10) ^ static_cast(i))) << 56)); + + G(x, y); + } + + template + static inline void transform(uint64_t* h, const uint64_t* m) + { + uint64_t AQ1[R], AQ2[R], AP1[R], AP2[R]; + + for (int column = 0; column < R; column++) + { + AP1[column] = h[column] ^ m[column]; + AQ1[column] = m[column]; + } + + for (uint64_t r = 0; r < (R == 16 ? 14 : 10); r += 2) + { + roundP(AP1, AP2, r); + roundP(AP2, AP1, r + 1); + roundQ(AQ1, AQ2, r); + roundQ(AQ2, AQ1, r + 1); + } + + for (int column = 0; column < R; column++) + { + h[column] = AP1[column] ^ AQ1[column] ^ h[column]; + } + } + + template + static inline void outputTransform(uint64_t* h) + { + uint64_t t1[R]; + uint64_t t2[R]; + + for (int column = 0; column < R; column++) { + t1[column] = h[column]; + } + + for (uint64_t r = 0; r < (R == 16 ? 14 : 10); r += 2) { + roundP(t1, t2, r); + roundP(t2, t1, r + 1); + } + + for (int column = 0; column < R; column++) { + h[column] ^= t1[column]; + } + } - for (uint64_t r = 0; r < (R == 16 ? 14 : 10); r += 2) - { - roundP(AP1, AP2, r); - roundP(AP2, AP1, r + 1); - roundQ(AQ1, AQ2, r); - roundQ(AQ2, AQ1, r + 1); } - for (int column = 0; column < R; column++) + class kupyna_provider { - h[column] = AP1[column] ^ AQ1[column] ^ h[column]; - } - } - - template - static inline void outputTransform(uint64_t* h) - { - uint64_t t1[R]; - uint64_t t2[R]; - - for (int column = 0; column < R; column++) { - t1[column] = h[column]; - } - - for (uint64_t r = 0; r < (R == 16 ? 14 : 10); r += 2) { - roundP(t1, t2, r); - roundP(t2, t1, r+1); - } - - for (int column = 0; column < R; column++) { - h[column] ^= t1[column]; - } - } - -} - -class kupyna_provider -{ -public: - static const bool is_xof = false; - - kupyna_provider(size_t hashsize) - : hs(hashsize) - { - validate_hash_size(hashsize, { 256, 512 }); - } - - ~kupyna_provider() - { - clear(); - } - - inline void init() - { - pos = 0; - total = 0; - memset(&h[0], 0, sizeof(uint64_t)*16); - h[0] = block_bytes(); // state in bytes - } - - inline void update(const unsigned char* data, size_t len) - { - detail::absorb_bytes(data, len, block_bytes(), block_bytes(), m.data(), pos, total, - [this](const unsigned char* data, size_t len) { transform(data, len); }); - } - - inline void final(unsigned char* hash) - { - total += pos * 8; - m[pos++] = 0x80; - size_t limit = block_bytes(); - if (pos > limit - 12) - { - if (limit != pos) + public: + static const bool is_xof = false; + + kupyna_provider(size_t hashsize) + : hs(hashsize) + { + validate_hash_size(hashsize, { 256, 512 }); + } + + ~kupyna_provider() + { + clear(); + } + + inline void init() + { + pos = 0; + total = 0; + memset(&h[0], 0, sizeof(uint64_t) * 16); + h[0] = block_bytes(); // state in bytes + } + + inline void update(const unsigned char* data, size_t len) + { + detail::absorb_bytes(data, len, block_bytes(), block_bytes(), m.data(), pos, total, + [this](const unsigned char* data, size_t len) { transform(data, len); }); + } + + inline void final(unsigned char* hash) + { + total += pos * 8; + m[pos++] = 0x80; + size_t limit = block_bytes(); + if (pos > limit - 12) + { + if (limit != pos) + memset(&m[pos], 0, limit - pos); + transform(m.data(), 1); + pos = 0; + } memset(&m[pos], 0, limit - pos); - transform(m.data(), 1); - pos = 0; - } - memset(&m[pos], 0, limit - pos); - memcpy(&m[limit - 12], &total, sizeof(uint64_t)); - memset(&m[limit - 4], 0, 4); - - transform(m.data(), 1); - outputTransform(); - - memcpy(hash, reinterpret_cast(h.data()) + limit - hash_size() / 8, hash_size() / 8); - } - - inline void clear() - { - zero_memory(h); - zero_memory(m); - } - - inline size_t hash_size() const { return hs; } - -private: - inline size_t block_bytes() const { return hs > 256 ? 128 : 64; } - - inline void outputTransform() - { - if (hs > 256) - kupyna_functions::outputTransform<16>(&h[0]); - else - kupyna_functions::outputTransform<8>(&h[0]); - } - - inline void transform(const unsigned char* mp, size_t num_blks) - { - for (size_t blk = 0; blk < num_blks; blk++) - { - if (hs > 256) - kupyna_functions::transform<16>(&h[0], reinterpret_cast(mp + block_bytes() * blk)); - else - kupyna_functions::transform<8>(&h[0], reinterpret_cast(mp + block_bytes() * blk)); - } - } - - std::array h; - std::array m; - size_t hs; - size_t pos; - uint64_t total; - -}; - -} // namespace detail + memcpy(&m[limit - 12], &total, sizeof(uint64_t)); + memset(&m[limit - 4], 0, 4); + + transform(m.data(), 1); + outputTransform(); + + memcpy(hash, reinterpret_cast(h.data()) + limit - hash_size() / 8, hash_size() / 8); + } + + inline void clear() + { + zero_memory(h); + zero_memory(m); + } + + inline size_t hash_size() const { return hs; } + + private: + inline size_t block_bytes() const { return hs > 256 ? 128 : 64; } + + inline void outputTransform() + { + if (hs > 256) + kupyna_functions::outputTransform<16>(&h[0]); + else + kupyna_functions::outputTransform<8>(&h[0]); + } + + inline void transform(const unsigned char* mp, size_t num_blks) + { + for (size_t blk = 0; blk < num_blks; blk++) + { + if (hs > 256) + kupyna_functions::transform<16>(&h[0], reinterpret_cast(mp + block_bytes() * blk)); + else + kupyna_functions::transform<8>(&h[0], reinterpret_cast(mp + block_bytes() * blk)); + } + } + + std::array h; + std::array m; + size_t hs; + size_t pos; + uint64_t total; + + }; + + } // namespace detail } // namespace digestpp From bd1d4bc8ea30ff898202963a1df65a984ebcadae Mon Sep 17 00:00:00 2001 From: Matheus Lima Date: Wed, 26 Mar 2025 16:01:39 -0300 Subject: [PATCH 2/3] Revert "fix: try to fix build on ubuntu" This reverts commit bb63a50c1d9503d82c3e1df591971293d34c8351. --- .../algorithm/detail/kupyna_provider.hpp | 337 +++++++++--------- 1 file changed, 168 insertions(+), 169 deletions(-) diff --git a/VCMP-LUA/modules/crypto/include/algorithm/detail/kupyna_provider.hpp b/VCMP-LUA/modules/crypto/include/algorithm/detail/kupyna_provider.hpp index 30ed4b8..cec5eb0 100644 --- a/VCMP-LUA/modules/crypto/include/algorithm/detail/kupyna_provider.hpp +++ b/VCMP-LUA/modules/crypto/include/algorithm/detail/kupyna_provider.hpp @@ -10,187 +10,186 @@ This code is written by kerukuro and released into public domain. #include "../../detail/validate_hash_size.hpp" #include "constants/kupyna_constants.hpp" #include -#include namespace digestpp { - namespace detail +namespace detail +{ + +namespace kupyna_functions +{ + template + static inline void G(uint64_t* x, uint64_t* y) + { + for (int c = 0; c != R; ++c) + y[c] = kupyna_constants::T[0][static_cast(x[(c + R) % R])] + ^ kupyna_constants::T[1][static_cast(x[(c + R - 1) % R] >> 8)] + ^ kupyna_constants::T[2][static_cast(x[(c + R - 2) % R] >> 16)] + ^ kupyna_constants::T[3][static_cast(x[(c + R - 3) % R] >> 24)] + ^ kupyna_constants::T[4][static_cast(x[(c + R - 4) % R] >> 32)] + ^ kupyna_constants::T[5][static_cast(x[(c + R - 5) % R] >> 40)] + ^ kupyna_constants::T[6][static_cast(x[(c + R - 6) % R] >> 48)] + ^ kupyna_constants::T[7][static_cast(x[(c + R - (R == 16 ? 11 : 7)) % R] >> 56)]; + } + + template + static inline void roundP(uint64_t* x, uint64_t* y, uint64_t i) + { + for (int idx = 0; idx < R; idx++) + x[idx] ^= (static_cast(idx) << 4) ^ i; + + G(x, y); + } + + template + static inline void roundQ(uint64_t* x, uint64_t* y, uint64_t i) { + for (int j = 0; j < R; ++j) + x[j] += (0x00F0F0F0F0F0F0F3ULL + ^ ((static_cast(((R - 1 - j) * 0x10) ^ static_cast(i))) << 56)); - namespace kupyna_functions + G(x, y); + } + + template + static inline void transform(uint64_t* h, const uint64_t* m) + { + uint64_t AQ1[R], AQ2[R], AP1[R], AP2[R]; + + for (int column = 0; column < R; column++) { - template - static inline void G(uint64_t* x, uint64_t* y) - { - for (int c = 0; c != R; ++c) - y[c] = kupyna_constants::T[0][static_cast(x[(c + R) % R])] - ^ kupyna_constants::T[1][static_cast(x[(c + R - 1) % R] >> 8)] - ^ kupyna_constants::T[2][static_cast(x[(c + R - 2) % R] >> 16)] - ^ kupyna_constants::T[3][static_cast(x[(c + R - 3) % R] >> 24)] - ^ kupyna_constants::T[4][static_cast(x[(c + R - 4) % R] >> 32)] - ^ kupyna_constants::T[5][static_cast(x[(c + R - 5) % R] >> 40)] - ^ kupyna_constants::T[6][static_cast(x[(c + R - 6) % R] >> 48)] - ^ kupyna_constants::T[7][static_cast(x[(c + R - (R == 16 ? 11 : 7)) % R] >> 56)]; - } - - template - static inline void roundP(uint64_t* x, uint64_t* y, uint64_t i) - { - for (int idx = 0; idx < R; idx++) - x[idx] ^= (static_cast(idx) << 4) ^ i; - - G(x, y); - } - - template - static inline void roundQ(uint64_t* x, uint64_t* y, uint64_t i) - { - for (int j = 0; j < R; ++j) - x[j] += (0x00F0F0F0F0F0F0F3ULL - ^ ((static_cast(((R - 1 - j) * 0x10) ^ static_cast(i))) << 56)); - - G(x, y); - } - - template - static inline void transform(uint64_t* h, const uint64_t* m) - { - uint64_t AQ1[R], AQ2[R], AP1[R], AP2[R]; - - for (int column = 0; column < R; column++) - { - AP1[column] = h[column] ^ m[column]; - AQ1[column] = m[column]; - } - - for (uint64_t r = 0; r < (R == 16 ? 14 : 10); r += 2) - { - roundP(AP1, AP2, r); - roundP(AP2, AP1, r + 1); - roundQ(AQ1, AQ2, r); - roundQ(AQ2, AQ1, r + 1); - } - - for (int column = 0; column < R; column++) - { - h[column] = AP1[column] ^ AQ1[column] ^ h[column]; - } - } - - template - static inline void outputTransform(uint64_t* h) - { - uint64_t t1[R]; - uint64_t t2[R]; - - for (int column = 0; column < R; column++) { - t1[column] = h[column]; - } - - for (uint64_t r = 0; r < (R == 16 ? 14 : 10); r += 2) { - roundP(t1, t2, r); - roundP(t2, t1, r + 1); - } - - for (int column = 0; column < R; column++) { - h[column] ^= t1[column]; - } - } + AP1[column] = h[column] ^ m[column]; + AQ1[column] = m[column]; + } + for (uint64_t r = 0; r < (R == 16 ? 14 : 10); r += 2) + { + roundP(AP1, AP2, r); + roundP(AP2, AP1, r + 1); + roundQ(AQ1, AQ2, r); + roundQ(AQ2, AQ1, r + 1); } - class kupyna_provider + for (int column = 0; column < R; column++) { - public: - static const bool is_xof = false; - - kupyna_provider(size_t hashsize) - : hs(hashsize) - { - validate_hash_size(hashsize, { 256, 512 }); - } - - ~kupyna_provider() - { - clear(); - } - - inline void init() - { - pos = 0; - total = 0; - memset(&h[0], 0, sizeof(uint64_t) * 16); - h[0] = block_bytes(); // state in bytes - } - - inline void update(const unsigned char* data, size_t len) - { - detail::absorb_bytes(data, len, block_bytes(), block_bytes(), m.data(), pos, total, - [this](const unsigned char* data, size_t len) { transform(data, len); }); - } - - inline void final(unsigned char* hash) - { - total += pos * 8; - m[pos++] = 0x80; - size_t limit = block_bytes(); - if (pos > limit - 12) - { - if (limit != pos) - memset(&m[pos], 0, limit - pos); - transform(m.data(), 1); - pos = 0; - } + h[column] = AP1[column] ^ AQ1[column] ^ h[column]; + } + } + + template + static inline void outputTransform(uint64_t* h) + { + uint64_t t1[R]; + uint64_t t2[R]; + + for (int column = 0; column < R; column++) { + t1[column] = h[column]; + } + + for (uint64_t r = 0; r < (R == 16 ? 14 : 10); r += 2) { + roundP(t1, t2, r); + roundP(t2, t1, r+1); + } + + for (int column = 0; column < R; column++) { + h[column] ^= t1[column]; + } + } + +} + +class kupyna_provider +{ +public: + static const bool is_xof = false; + + kupyna_provider(size_t hashsize) + : hs(hashsize) + { + validate_hash_size(hashsize, { 256, 512 }); + } + + ~kupyna_provider() + { + clear(); + } + + inline void init() + { + pos = 0; + total = 0; + memset(&h[0], 0, sizeof(uint64_t)*16); + h[0] = block_bytes(); // state in bytes + } + + inline void update(const unsigned char* data, size_t len) + { + detail::absorb_bytes(data, len, block_bytes(), block_bytes(), m.data(), pos, total, + [this](const unsigned char* data, size_t len) { transform(data, len); }); + } + + inline void final(unsigned char* hash) + { + total += pos * 8; + m[pos++] = 0x80; + size_t limit = block_bytes(); + if (pos > limit - 12) + { + if (limit != pos) memset(&m[pos], 0, limit - pos); - memcpy(&m[limit - 12], &total, sizeof(uint64_t)); - memset(&m[limit - 4], 0, 4); - - transform(m.data(), 1); - outputTransform(); - - memcpy(hash, reinterpret_cast(h.data()) + limit - hash_size() / 8, hash_size() / 8); - } - - inline void clear() - { - zero_memory(h); - zero_memory(m); - } - - inline size_t hash_size() const { return hs; } - - private: - inline size_t block_bytes() const { return hs > 256 ? 128 : 64; } - - inline void outputTransform() - { - if (hs > 256) - kupyna_functions::outputTransform<16>(&h[0]); - else - kupyna_functions::outputTransform<8>(&h[0]); - } - - inline void transform(const unsigned char* mp, size_t num_blks) - { - for (size_t blk = 0; blk < num_blks; blk++) - { - if (hs > 256) - kupyna_functions::transform<16>(&h[0], reinterpret_cast(mp + block_bytes() * blk)); - else - kupyna_functions::transform<8>(&h[0], reinterpret_cast(mp + block_bytes() * blk)); - } - } - - std::array h; - std::array m; - size_t hs; - size_t pos; - uint64_t total; - - }; - - } // namespace detail + transform(m.data(), 1); + pos = 0; + } + memset(&m[pos], 0, limit - pos); + memcpy(&m[limit - 12], &total, sizeof(uint64_t)); + memset(&m[limit - 4], 0, 4); + + transform(m.data(), 1); + outputTransform(); + + memcpy(hash, reinterpret_cast(h.data()) + limit - hash_size() / 8, hash_size() / 8); + } + + inline void clear() + { + zero_memory(h); + zero_memory(m); + } + + inline size_t hash_size() const { return hs; } + +private: + inline size_t block_bytes() const { return hs > 256 ? 128 : 64; } + + inline void outputTransform() + { + if (hs > 256) + kupyna_functions::outputTransform<16>(&h[0]); + else + kupyna_functions::outputTransform<8>(&h[0]); + } + + inline void transform(const unsigned char* mp, size_t num_blks) + { + for (size_t blk = 0; blk < num_blks; blk++) + { + if (hs > 256) + kupyna_functions::transform<16>(&h[0], reinterpret_cast(mp + block_bytes() * blk)); + else + kupyna_functions::transform<8>(&h[0], reinterpret_cast(mp + block_bytes() * blk)); + } + } + + std::array h; + std::array m; + size_t hs; + size_t pos; + uint64_t total; + +}; + +} // namespace detail } // namespace digestpp From 4af86cb50b6a13fee9de0f7c7f26a28aaf2eac3a Mon Sep 17 00:00:00 2001 From: Matheus Lima Date: Wed, 26 Mar 2025 16:09:24 -0300 Subject: [PATCH 3/3] Update functions.hpp --- VCMP-LUA/modules/crypto/include/detail/functions.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/VCMP-LUA/modules/crypto/include/detail/functions.hpp b/VCMP-LUA/modules/crypto/include/detail/functions.hpp index 9bedd24..b48ffd4 100644 --- a/VCMP-LUA/modules/crypto/include/detail/functions.hpp +++ b/VCMP-LUA/modules/crypto/include/detail/functions.hpp @@ -5,6 +5,10 @@ This code is written by kerukuro and released into public domain. #ifndef DIGESTPP_DETAIL_FUNCTIONS_HPP #define DIGESTPP_DETAIL_FUNCTIONS_HPP +#include +#include +#include + namespace digestpp { namespace detail