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

randombit / botan / 13215274653

08 Feb 2025 11:38AM UTC coverage: 91.655% (-0.009%) from 91.664%
13215274653

Pull #4650

github

web-flow
Merge 107f31833 into bc555cd3c
Pull Request #4650: Reorganize code and reduce header dependencies

94836 of 103471 relevant lines covered (91.65%)

11230958.94 hits per line

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

87.5
/src/lib/block/gost_28147/gost_28147.h
1
/*
2
* GOST 28147-89
3
* (C) 1999-2009 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#ifndef BOTAN_GOST_28147_89_H_
9
#define BOTAN_GOST_28147_89_H_
10

11
#include <botan/block_cipher.h>
12
#include <botan/secmem.h>
13

14
namespace Botan {
15

16
/**
17
* The GOST 28147-89 block cipher uses a set of 4 bit Sboxes, however
18
* the standard does not actually define these Sboxes; they are
19
* considered a local configuration issue. Several different sets are
20
* used.
21
*/
22
class GOST_28147_89_Params final {
88✔
23
   public:
24
      /**
25
      * @param row the row
26
      * @param col the column
27
      * @return sbox entry at this row/column
28
      */
29
      uint8_t sbox_entry(size_t row, size_t col) const;
30

31
      /**
32
      * @return name of this parameter set
33
      */
34
      std::string param_name() const { return m_name; }
176✔
35

36
      /**
37
      * Return a representation used for building larger tables
38
      * For internal use
39
      */
40
      uint8_t sbox_pair(size_t row, size_t col) const;
41

42
      /**
43
      * Default GOST parameters are the ones given in GOST R 34.11 for
44
      * testing purposes; these sboxes are also used by Crypto++, and,
45
      * at least according to Wikipedia, the Central Bank of Russian
46
      * Federation
47
      * @param name of the parameter set
48
      */
49
      explicit GOST_28147_89_Params(std::string_view name = "R3411_94_TestParam");
50

51
   private:
52
      const uint8_t* m_sboxes;
53
      std::string m_name;
54
};
55

56
/**
57
* GOST 28147-89
58
*/
59
class GOST_28147_89 final : public Block_Cipher_Fixed_Params<8, 32> {
×
60
   public:
61
      void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
62
      void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
63

64
      void clear() override;
65

66
      std::string name() const override;
67

68
      std::unique_ptr<BlockCipher> new_object() const override {
28✔
69
         return std::make_unique<GOST_28147_89>(m_SBOX, m_name);
28✔
70
      }
71

72
      bool has_keying_material() const override;
73

74
      /**
75
      * @param params the sbox parameters to use
76
      */
77
      explicit GOST_28147_89(const GOST_28147_89_Params& params);
78

79
      explicit GOST_28147_89(std::string_view param_name) : GOST_28147_89(GOST_28147_89_Params(param_name)) {}
112✔
80

81
      explicit GOST_28147_89(const std::vector<uint32_t>& other_SBOX, std::string_view name) :
28✔
82
            m_SBOX(other_SBOX), m_EK(8), m_name(name) {}
56✔
83

84
   private:
85
      void key_schedule(std::span<const uint8_t> key) override;
86

87
      /*
88
      * The sbox is not secret, this is just a larger expansion of it
89
      * which we generate at runtime for faster execution
90
      */
91
      std::vector<uint32_t> m_SBOX;
92
      secure_vector<uint32_t> m_EK;
93
      std::string m_name;
94
};
95

96
}  // namespace Botan
97

98
#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