/src/botan/build/include/botan/internal/ghash.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * (C) 2013 Jack Lloyd |
3 | | * (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity |
4 | | * |
5 | | * Botan is released under the Simplified BSD License (see license.txt) |
6 | | */ |
7 | | |
8 | | #ifndef BOTAN_GCM_GHASH_H_ |
9 | | #define BOTAN_GCM_GHASH_H_ |
10 | | |
11 | | #include <botan/sym_algo.h> |
12 | | |
13 | | namespace Botan { |
14 | | |
15 | | /** |
16 | | * GCM's GHASH |
17 | | */ |
18 | | class GHASH final : public SymmetricAlgorithm { |
19 | | public: |
20 | | void set_associated_data(const uint8_t ad[], size_t ad_len); |
21 | | |
22 | | void nonce_hash(secure_vector<uint8_t>& y0, const uint8_t nonce[], size_t len); |
23 | | |
24 | | void start(const uint8_t nonce[], size_t len); |
25 | | |
26 | | /* |
27 | | * Assumes input len is multiple of 16 |
28 | | */ |
29 | | void update(const uint8_t in[], size_t len); |
30 | | |
31 | | /* |
32 | | * Incremental update of associated data |
33 | | */ |
34 | | void update_associated_data(const uint8_t ad[], size_t len); |
35 | | |
36 | | void final(uint8_t out[], size_t out_len); |
37 | | |
38 | 973 | Key_Length_Specification key_spec() const override { return Key_Length_Specification(16); } |
39 | | |
40 | | bool has_keying_material() const override; |
41 | | |
42 | | void clear() override; |
43 | | |
44 | | void reset(); |
45 | | |
46 | 0 | std::string name() const override { return "GHASH"; } |
47 | | |
48 | | std::string provider() const; |
49 | | |
50 | | void ghash_update(secure_vector<uint8_t>& x, const uint8_t input[], size_t input_len); |
51 | | |
52 | | void add_final_block(secure_vector<uint8_t>& x, size_t ad_len, size_t pt_len); |
53 | | |
54 | | private: |
55 | | #if defined(BOTAN_HAS_GHASH_CLMUL_CPU) |
56 | | static void ghash_precompute_cpu(const uint8_t H[16], uint64_t H_pow[4 * 2]); |
57 | | |
58 | | static void ghash_multiply_cpu(uint8_t x[16], const uint64_t H_pow[4 * 2], const uint8_t input[], size_t blocks); |
59 | | #endif |
60 | | |
61 | | #if defined(BOTAN_HAS_GHASH_CLMUL_VPERM) |
62 | | static void ghash_multiply_vperm(uint8_t x[16], const uint64_t HM[256], const uint8_t input[], size_t blocks); |
63 | | #endif |
64 | | |
65 | | void key_schedule(std::span<const uint8_t> key) override; |
66 | | |
67 | | void ghash_multiply(secure_vector<uint8_t>& x, const uint8_t input[], size_t blocks); |
68 | | |
69 | | static const size_t GCM_BS = 16; |
70 | | |
71 | | secure_vector<uint8_t> m_H; |
72 | | secure_vector<uint8_t> m_H_ad; |
73 | | secure_vector<uint8_t> m_ghash; |
74 | | secure_vector<uint8_t> m_nonce; |
75 | | secure_vector<uint64_t> m_HM; |
76 | | secure_vector<uint64_t> m_H_pow; |
77 | | size_t m_ad_len = 0; |
78 | | size_t m_text_len = 0; |
79 | | }; |
80 | | |
81 | | } // namespace Botan |
82 | | |
83 | | #endif |