diff options
Diffstat (limited to 'src/lib/hash/skein')
-rw-r--r-- | src/lib/hash/skein/skein_512.cpp | 72 | ||||
-rw-r--r-- | src/lib/hash/skein/skein_512.h | 12 |
2 files changed, 42 insertions, 42 deletions
diff --git a/src/lib/hash/skein/skein_512.cpp b/src/lib/hash/skein/skein_512.cpp index fe95dd7a5..ad0817da7 100644 --- a/src/lib/hash/skein/skein_512.cpp +++ b/src/lib/hash/skein/skein_512.cpp @@ -19,12 +19,12 @@ Skein_512* Skein_512::make(const Spec& spec) Skein_512::Skein_512(size_t arg_output_bits, const std::string& arg_personalization) : - personalization(arg_personalization), - output_bits(arg_output_bits), + m_personalization(arg_personalization), + m_output_bits(arg_output_bits), m_threefish(new Threefish_512), - T(2), buffer(64), buf_pos(0) + m_T(2), m_buffer(64), m_buf_pos(0) { - if(output_bits == 0 || output_bits % 8 != 0 || output_bits > 512) + if(m_output_bits == 0 || m_output_bits % 8 != 0 || m_output_bits > 512) throw Invalid_Argument("Bad output bits size for Skein-512"); initial_block(); @@ -32,30 +32,30 @@ Skein_512::Skein_512(size_t arg_output_bits, std::string Skein_512::name() const { - if(personalization != "") - return "Skein-512(" + std::to_string(output_bits) + "," + - personalization + ")"; - return "Skein-512(" + std::to_string(output_bits) + ")"; + if(m_personalization != "") + return "Skein-512(" + std::to_string(m_output_bits) + "," + + m_personalization + ")"; + return "Skein-512(" + std::to_string(m_output_bits) + ")"; } HashFunction* Skein_512::clone() const { - return new Skein_512(output_bits, personalization); + return new Skein_512(m_output_bits, m_personalization); } void Skein_512::clear() { - zeroise(buffer); - buf_pos = 0; + zeroise(m_buffer); + m_buf_pos = 0; initial_block(); } void Skein_512::reset_tweak(type_code type, bool final) { - T[0] = 0; + m_T[0] = 0; - T[1] = (static_cast<u64bit>(type) << 56) | + m_T[1] = (static_cast<u64bit>(type) << 56) | (static_cast<u64bit>(1) << 62) | (static_cast<u64bit>(final) << 63); } @@ -68,24 +68,24 @@ void Skein_512::initial_block() // ASCII("SHA3") followed by version (0x0001) code byte config_str[32] = { 0x53, 0x48, 0x41, 0x33, 0x01, 0x00, 0 }; - store_le(u32bit(output_bits), config_str + 8); + store_le(u32bit(m_output_bits), config_str + 8); reset_tweak(SKEIN_CONFIG, true); ubi_512(config_str, sizeof(config_str)); - if(personalization != "") + if(m_personalization != "") { /* This is a limitation of this implementation, and not of the algorithm specification. Could be fixed relatively easily, but doesn't seem worth the trouble. */ - if(personalization.length() > 64) + if(m_personalization.length() > 64) throw Invalid_Argument("Skein personalization must be less than 64 bytes"); - const byte* bits = reinterpret_cast<const byte*>(personalization.data()); + const byte* bits = reinterpret_cast<const byte*>(m_personalization.data()); reset_tweak(SKEIN_PERSONALIZATION, true); - ubi_512(bits, personalization.length()); + ubi_512(bits, m_personalization.length()); } reset_tweak(SKEIN_MSG, false); @@ -98,7 +98,7 @@ void Skein_512::ubi_512(const byte msg[], size_t msg_len) do { const size_t to_proc = std::min<size_t>(msg_len, 64); - T[0] += to_proc; + m_T[0] += to_proc; load_le(M.data(), msg, to_proc / 8); @@ -108,10 +108,10 @@ void Skein_512::ubi_512(const byte msg[], size_t msg_len) M[to_proc/8] |= static_cast<u64bit>(msg[8*(to_proc/8)+j]) << (8*j); } - m_threefish->skein_feedfwd(M, T); + m_threefish->skein_feedfwd(M, m_T); // clear first flag if set - T[1] &= ~(static_cast<u64bit>(1) << 62); + m_T[1] &= ~(static_cast<u64bit>(1) << 62); msg_len -= to_proc; msg += to_proc; @@ -123,16 +123,16 @@ void Skein_512::add_data(const byte input[], size_t length) if(length == 0) return; - if(buf_pos) + if(m_buf_pos) { - buffer_insert(buffer, buf_pos, input, length); - if(buf_pos + length > 64) + buffer_insert(m_buffer, m_buf_pos, input, length); + if(m_buf_pos + length > 64) { - ubi_512(buffer.data(), buffer.size()); + ubi_512(m_buffer.data(), m_buffer.size()); - input += (64 - buf_pos); - length -= (64 - buf_pos); - buf_pos = 0; + input += (64 - m_buf_pos); + length -= (64 - m_buf_pos); + m_buf_pos = 0; } } @@ -143,27 +143,27 @@ void Skein_512::add_data(const byte input[], size_t length) length -= full_blocks * 64; - buffer_insert(buffer, buf_pos, input + full_blocks * 64, length); - buf_pos += length; + buffer_insert(m_buffer, m_buf_pos, input + full_blocks * 64, length); + m_buf_pos += length; } void Skein_512::final_result(byte out[]) { - T[1] |= (static_cast<u64bit>(1) << 63); // final block flag + m_T[1] |= (static_cast<u64bit>(1) << 63); // final block flag - for(size_t i = buf_pos; i != buffer.size(); ++i) - buffer[i] = 0; + for(size_t i = m_buf_pos; i != m_buffer.size(); ++i) + m_buffer[i] = 0; - ubi_512(buffer.data(), buf_pos); + ubi_512(m_buffer.data(), m_buf_pos); const byte counter[8] = { 0 }; reset_tweak(SKEIN_OUTPUT, true); ubi_512(counter, sizeof(counter)); - copy_out_vec_le(out, output_bits / 8, m_threefish->m_K); + copy_out_vec_le(out, m_output_bits / 8, m_threefish->m_K); - buf_pos = 0; + m_buf_pos = 0; initial_block(); } diff --git a/src/lib/hash/skein/skein_512.h b/src/lib/hash/skein/skein_512.h index dceb34854..9d3c69fb2 100644 --- a/src/lib/hash/skein/skein_512.h +++ b/src/lib/hash/skein/skein_512.h @@ -30,7 +30,7 @@ class BOTAN_DLL Skein_512 : public HashFunction const std::string& personalization = ""); size_t hash_block_size() const override { return 64; } - size_t output_length() const override { return output_bits / 8; } + size_t output_length() const override { return m_output_bits / 8; } static Skein_512* make(const Spec& spec); @@ -57,13 +57,13 @@ class BOTAN_DLL Skein_512 : public HashFunction void initial_block(); void reset_tweak(type_code type, bool final); - std::string personalization; - size_t output_bits; + std::string m_personalization; + size_t m_output_bits; std::unique_ptr<Threefish_512> m_threefish; - secure_vector<u64bit> T; - secure_vector<byte> buffer; - size_t buf_pos; + secure_vector<u64bit> m_T; + secure_vector<byte> m_buffer; + size_t m_buf_pos; }; } |