From affeb8d1a8726286248f28eba467bcfbb250f83d Mon Sep 17 00:00:00 2001 From: Anjan Roy Date: Tue, 28 Jan 2025 22:31:05 +0400 Subject: [PATCH] Encode customization string bit-length instead of byte length, for Ascon-CXOF128 See https://github.com/itzmeanjan/ascon/issues/27 Signed-off-by: Anjan Roy --- include/ascon/hashes/ascon_cxof128.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/ascon/hashes/ascon_cxof128.hpp b/include/ascon/hashes/ascon_cxof128.hpp index 4079586..e5a6d89 100644 --- a/include/ascon/hashes/ascon_cxof128.hpp +++ b/include/ascon/hashes/ascon_cxof128.hpp @@ -53,10 +53,12 @@ struct ascon_cxof128_t forceinline constexpr bool customize(std::span cust_str) { if (!has_customized && (cust_str.size() <= CUSTOMIZATION_STRING_MAX_BYTE_LEN)) [[likely]] { - std::array cust_str_len_as_bytes{}; - ascon_common_utils::to_le_bytes(cust_str.size(), cust_str_len_as_bytes); + const size_t cust_str_bit_len = cust_str.size() * std::numeric_limits::digits; - ascon_sponge_mode::absorb(state, offset, cust_str_len_as_bytes); + std::array cust_str_bit_len_as_bytes{}; + ascon_common_utils::to_le_bytes(cust_str_bit_len, cust_str_bit_len_as_bytes); + + ascon_sponge_mode::absorb(state, offset, cust_str_bit_len_as_bytes); ascon_sponge_mode::absorb(state, offset, cust_str); ascon_sponge_mode::finalize(state, offset);