Coverage Report

Created: 2026-12-01 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Botan-3.13.0/build/include/internal/botan/internal/sm3.h
Line
Count
Source
1
/*
2
* SM3
3
* (C) 2017 Ribose Inc.
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_SM3_H_
9
#define BOTAN_SM3_H_
10
11
#include <botan/internal/mdx_hash.h>
12
13
namespace Botan {
14
15
/**
16
* SM3
17
*/
18
class SM3 final : public HashFunction {
19
   public:
20
      using digest_type = secure_vector<uint32_t>;
21
22
      static constexpr MD_Endian byte_endianness = MD_Endian::Big;
23
      static constexpr MD_Endian bit_endianness = MD_Endian::Big;
24
      static constexpr size_t block_bytes = 64;
25
      static constexpr size_t output_bytes = 32;
26
      static constexpr size_t ctr_bytes = 8;
27
28
      static void compress_n(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
29
      static void init(digest_type& digest);
30
31
   public:
32
4.87k
      std::string name() const override { return "SM3"; }
33
34
      std::string provider() const override;
35
36
99.1k
      size_t output_length() const override { return output_bytes; }
37
38
0
      size_t hash_block_size() const override { return block_bytes; }
39
40
      std::unique_ptr<HashFunction> new_object() const override;
41
42
      std::unique_ptr<HashFunction> copy_state() const override;
43
44
0
      void clear() override { m_md.clear(); }
45
46
   private:
47
      void add_data(std::span<const uint8_t> input) override;
48
49
      void final_result(std::span<uint8_t> output) override;
50
51
#if defined(BOTAN_HAS_SM3_X86_AVX2_BMI2)
52
      static void compress_digest_x86_avx2(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
53
#endif
54
55
#if defined(BOTAN_HAS_SM3_ARMV8)
56
      static void compress_digest_armv8(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
57
#endif
58
59
#if defined(BOTAN_HAS_SM3_X86)
60
      static void compress_digest_x86(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
61
#endif
62
63
   private:
64
      MerkleDamgard_Hash<SM3> m_md;
65
};
66
67
}  // namespace Botan
68
69
#endif