aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/hash/shake/shake.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/hash/shake/shake.h')
-rw-r--r--src/lib/hash/shake/shake.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/lib/hash/shake/shake.h b/src/lib/hash/shake/shake.h
new file mode 100644
index 000000000..96c171323
--- /dev/null
+++ b/src/lib/hash/shake/shake.h
@@ -0,0 +1,81 @@
+/*
+* SHAKE hash functions
+* (C) 2010,2016 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#ifndef BOTAN_SHAKE_HASH_H__
+#define BOTAN_SHAKE_HASH_H__
+
+#include <botan/hash.h>
+#include <botan/secmem.h>
+#include <string>
+
+namespace Botan {
+
+/**
+* SHAKE-128
+*/
+class BOTAN_DLL SHAKE_128 : public HashFunction
+ {
+ public:
+
+ /**
+ * @param output_bits the desired output size in bits
+ * must be a multiple of 8
+ */
+ SHAKE_128(size_t output_bits);
+
+ size_t hash_block_size() const override { return SHAKE_128_BITRATE / 8; }
+ size_t output_length() const override { return m_output_bits / 8; }
+
+ HashFunction* clone() const override;
+ std::string name() const override;
+ void clear() override;
+
+ private:
+ void add_data(const byte input[], size_t length) override;
+ void final_result(byte out[]) override;
+
+ static const size_t SHAKE_128_BITRATE = 1600 - 256;
+
+ size_t m_output_bits;
+ secure_vector<u64bit> m_S;
+ size_t m_S_pos;
+ };
+
+/**
+* SHAKE-256
+*/
+class BOTAN_DLL SHAKE_256 : public HashFunction
+ {
+ public:
+
+ /**
+ * @param output_bits the desired output size in bits
+ * must be a multiple of 8
+ */
+ SHAKE_256(size_t output_bits);
+
+ size_t hash_block_size() const override { return SHAKE_256_BITRATE / 8; }
+ size_t output_length() const override { return m_output_bits / 8; }
+
+ HashFunction* clone() const override;
+ std::string name() const override;
+ void clear() override;
+
+ private:
+ void add_data(const byte input[], size_t length) override;
+ void final_result(byte out[]) override;
+
+ static const size_t SHAKE_256_BITRATE = 1600 - 512;
+
+ size_t m_output_bits;
+ secure_vector<u64bit> m_S;
+ size_t m_S_pos;
+ };
+
+}
+
+#endif