1 /* 2 * Streebog 3 * (C) 2017 Ribose Inc. 4 * 5 * Botan is released under the Simplified BSD License (see license.txt) 6 */ 7 8 #ifndef BOTAN_STREEBOG_H_ 9 #define BOTAN_STREEBOG_H_ 10 11 #include <botan/hash.h> 12 13 BOTAN_FUTURE_INTERNAL_HEADER(streebog.h) 14 15 namespace Botan { 16 17 /** 18 * Streebog (GOST R 34.11-2012) 19 * RFC 6986 20 */ 21 class BOTAN_PUBLIC_API(2,2) Streebog : public HashFunction 22 { 23 public: output_length()24 size_t output_length() const override { return m_output_bits / 8; } 25 clone()26 HashFunction* clone() const override { return new Streebog(m_output_bits); } 27 void clear() override; 28 std::string name() const override; hash_block_size()29 size_t hash_block_size() const override { return 64; } 30 31 std::unique_ptr<HashFunction> copy_state() const override; 32 33 explicit Streebog(size_t output_bits); 34 protected: 35 void add_data(const uint8_t input[], size_t length) override; 36 void final_result(uint8_t out[]) override; 37 38 void compress(const uint8_t input[], bool lastblock = false); 39 40 void compress_64(const uint64_t input[], bool lastblock = false); 41 42 private: 43 const size_t m_output_bits; 44 uint64_t m_count; 45 size_t m_position; 46 secure_vector<uint8_t> m_buffer; 47 secure_vector<uint64_t> m_h; 48 secure_vector<uint64_t> m_S; 49 }; 50 51 52 /** 53 * Streebog-256 54 */ 55 class BOTAN_PUBLIC_API(2,2) Streebog_256 final : public Streebog 56 { 57 public: Streebog_256()58 Streebog_256() : Streebog(256) {} 59 }; 60 61 /** 62 * Streebog-512 63 */ 64 class BOTAN_PUBLIC_API(2,2) Streebog_512 final : public Streebog 65 { 66 public: Streebog_512()67 Streebog_512() : Streebog(512) {} 68 }; 69 70 } 71 72 #endif 73