diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/third_party/botan/src/lib/hash/keccak | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/third_party/botan/src/lib/hash/keccak')
-rw-r--r-- | comm/third_party/botan/src/lib/hash/keccak/info.txt | 7 | ||||
-rw-r--r-- | comm/third_party/botan/src/lib/hash/keccak/keccak.cpp | 68 | ||||
-rw-r--r-- | comm/third_party/botan/src/lib/hash/keccak/keccak.h | 51 |
3 files changed, 126 insertions, 0 deletions
diff --git a/comm/third_party/botan/src/lib/hash/keccak/info.txt b/comm/third_party/botan/src/lib/hash/keccak/info.txt new file mode 100644 index 0000000000..6f7345af87 --- /dev/null +++ b/comm/third_party/botan/src/lib/hash/keccak/info.txt @@ -0,0 +1,7 @@ +<defines> +KECCAK -> 20131128 +</defines> + +<requires> +sha3 +</requires> diff --git a/comm/third_party/botan/src/lib/hash/keccak/keccak.cpp b/comm/third_party/botan/src/lib/hash/keccak/keccak.cpp new file mode 100644 index 0000000000..b8196495c6 --- /dev/null +++ b/comm/third_party/botan/src/lib/hash/keccak/keccak.cpp @@ -0,0 +1,68 @@ +/* +* Keccak +* (C) 2010,2016 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include <botan/keccak.h> +#include <botan/sha3.h> +#include <botan/exceptn.h> +#include <botan/loadstor.h> + +namespace Botan { + +std::unique_ptr<HashFunction> Keccak_1600::copy_state() const + { + return std::unique_ptr<HashFunction>(new Keccak_1600(*this)); + } + +Keccak_1600::Keccak_1600(size_t output_bits) : + m_output_bits(output_bits), + m_bitrate(1600 - 2*output_bits), + m_S(25), + m_S_pos(0) + { + // We only support the parameters for the SHA-3 proposal + + if(output_bits != 224 && output_bits != 256 && + output_bits != 384 && output_bits != 512) + throw Invalid_Argument("Keccak_1600: Invalid output length " + + std::to_string(output_bits)); + } + +std::string Keccak_1600::name() const + { + return "Keccak-1600(" + std::to_string(m_output_bits) + ")"; + } + +HashFunction* Keccak_1600::clone() const + { + return new Keccak_1600(m_output_bits); + } + +void Keccak_1600::clear() + { + zeroise(m_S); + m_S_pos = 0; + } + +void Keccak_1600::add_data(const uint8_t input[], size_t length) + { + m_S_pos = SHA_3::absorb(m_bitrate, m_S, m_S_pos, input, length); + } + +void Keccak_1600::final_result(uint8_t output[]) + { + SHA_3::finish(m_bitrate, m_S, m_S_pos, 0x01, 0x80); + + /* + * We never have to run the permutation again because we only support + * limited output lengths + */ + copy_out_vec_le(output, m_output_bits/8, m_S); + + clear(); + } + +} diff --git a/comm/third_party/botan/src/lib/hash/keccak/keccak.h b/comm/third_party/botan/src/lib/hash/keccak/keccak.h new file mode 100644 index 0000000000..083d7fc5a6 --- /dev/null +++ b/comm/third_party/botan/src/lib/hash/keccak/keccak.h @@ -0,0 +1,51 @@ +/* +* Keccak +* (C) 2010 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_KECCAK_H_ +#define BOTAN_KECCAK_H_ + +#include <botan/hash.h> +#include <botan/secmem.h> +#include <string> + +namespace Botan { + +BOTAN_FUTURE_INTERNAL_HEADER(keccak.h) + +/** +* Keccak[1600], a SHA-3 candidate +*/ +class BOTAN_PUBLIC_API(2,0) Keccak_1600 final : public HashFunction + { + public: + + /** + * @param output_bits the size of the hash output; must be one of + * 224, 256, 384, or 512 + */ + explicit Keccak_1600(size_t output_bits = 512); + + size_t hash_block_size() const override { return m_bitrate / 8; } + size_t output_length() const override { return m_output_bits / 8; } + + HashFunction* clone() const override; + std::unique_ptr<HashFunction> copy_state() const override; + std::string name() const override; + void clear() override; + + private: + void add_data(const uint8_t input[], size_t length) override; + void final_result(uint8_t out[]) override; + + size_t m_output_bits, m_bitrate; + secure_vector<uint64_t> m_S; + size_t m_S_pos; + }; + +} + +#endif |