Coverage Report

Created: 2025-05-09 06:24

/src/botan/src/lib/xof/xof.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* Extendable Output Function Base Class
3
* (C) 2023 Jack Lloyd
4
*     2023 Fabian Albert, René Meusel - Rohde & Schwarz Cybersecurity
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
*/
8
9
#include <botan/xof.h>
10
11
#include <botan/assert.h>
12
#include <botan/internal/scan_name.h>
13
14
#if defined(BOTAN_HAS_SHAKE_XOF)
15
   #include <botan/internal/shake_xof.h>
16
#endif
17
18
#include <botan/exceptn.h>
19
#include <botan/internal/fmt.h>
20
21
namespace Botan {
22
23
//static
24
46
std::unique_ptr<XOF> XOF::create(std::string_view algo_spec, std::string_view provider) {
25
46
   const SCAN_Name req(algo_spec);
26
27
46
   if(!provider.empty() && provider != "base") {
28
0
      return nullptr;  // unknown provider
29
0
   }
30
31
46
#if defined(BOTAN_HAS_SHAKE_XOF)
32
46
   if(req.algo_name() == "SHAKE-128" && req.arg_count() == 0) {
33
23
      return std::make_unique<SHAKE_128_XOF>();
34
23
   }
35
23
   if(req.algo_name() == "SHAKE-256" && req.arg_count() == 0) {
36
23
      return std::make_unique<SHAKE_256_XOF>();
37
23
   }
38
0
#endif
39
40
0
   return nullptr;
41
23
}
42
43
//static
44
46
std::unique_ptr<XOF> XOF::create_or_throw(std::string_view algo_spec, std::string_view provider) {
45
46
   if(auto xof = XOF::create(algo_spec, provider)) {
46
46
      return xof;
47
46
   }
48
0
   throw Lookup_Error("XOF", algo_spec, provider);
49
46
}
50
51
// static
52
0
std::vector<std::string> XOF::providers(std::string_view algo_spec) {
53
0
   return probe_providers_of<XOF>(algo_spec, {"base"});
54
0
}
55
56
0
std::string XOF::provider() const {
57
0
   return "base";
58
0
}
59
60
148
void XOF::start(std::span<const uint8_t> salt, std::span<const uint8_t> key) {
61
148
   if(!key_spec().valid_keylength(key.size())) {
62
0
      throw Invalid_Key_Length(name(), key.size());
63
0
   }
64
65
148
   if(!valid_salt_length(salt.size())) {
66
0
      throw Invalid_Argument(fmt("{} cannot accept a salt length of {}", name(), salt.size()));
67
0
   }
68
69
148
   m_xof_started = true;
70
148
   start_msg(salt, key);
71
148
}
72
73
148
void XOF::start_msg(std::span<const uint8_t> salt, std::span<const uint8_t> key) {
74
148
   BOTAN_UNUSED(salt, key);
75
148
}
76
77
}  // namespace Botan