• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 6057704243

02 Sep 2023 10:05AM UTC coverage: 91.729% (+0.01%) from 91.718%
6057704243

Pull #3680

github

web-flow
Merge fc59ca615 into 2c2ff3c71
Pull Request #3680: Kuznyechik block cipher

78780 of 85883 relevant lines covered (91.73%)

8435879.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/lib/hash/trunc_hash/trunc_hash.h
1
/**
2
 * Wrapper for truncated hashes
3
 * (C) 2023 Jack Lloyd
4
 *     2023 René Meusel - Rohde & Schwarz Cybersecurity
5
 *
6
 * Botan is released under the Simplified BSD License (see license.txt)
7
 */
8

9
#ifndef BOTAN_TRUNCATED_HASH_H_
10
#define BOTAN_TRUNCATED_HASH_H_
11

12
#include <botan/hash.h>
13

14
namespace Botan {
15

16
/**
17
 * Wrapper class to truncate underlying hash function output to a given number
18
 * of bits. The leading bits are retained. Since the HashFunction interface is
19
 * defined to return bytes, if the desired truncation length is not a multiple
20
 * of 8, then the final byte of the output will have some number of trailing
21
 * bits always set to zero.
22
 */
23
class Truncated_Hash final : public HashFunction {
×
24
   public:
25
      void clear() override;
26
      std::string name() const override;
27
      std::unique_ptr<HashFunction> new_object() const override;
28
      std::unique_ptr<HashFunction> copy_state() const override;
29

30
      size_t output_length() const override;
31

32
      /**
33
      * @param hash   the underlying hash function whose output shall be truncated
34
      * @param length the number of bits the hash shall be truncated to
35
      */
36
      Truncated_Hash(std::unique_ptr<HashFunction> hash, size_t length);
37

38
   private:
39
      void add_data(const uint8_t[], size_t) override;
40
      void final_result(uint8_t[]) override;
41

42
      std::unique_ptr<HashFunction> m_hash;
43
      size_t m_output_bits;
44

45
      secure_vector<uint8_t> m_buffer;
46
};
47

48
}  // namespace Botan
49

50
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc