/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 | | #include <botan/internal/scan_name.h> |
11 | | |
12 | | #if defined(BOTAN_HAS_SHAKE_XOF) |
13 | | #include <botan/internal/shake_xof.h> |
14 | | #endif |
15 | | |
16 | | #include <botan/exceptn.h> |
17 | | #include <botan/internal/fmt.h> |
18 | | |
19 | | namespace Botan { |
20 | | |
21 | | //static |
22 | 0 | std::unique_ptr<XOF> XOF::create(std::string_view algo_spec, std::string_view provider) { |
23 | 0 | const SCAN_Name req(algo_spec); |
24 | |
|
25 | 0 | if(!provider.empty() && provider != "base") { |
26 | 0 | return nullptr; // unknown provider |
27 | 0 | } |
28 | | |
29 | 0 | #if defined(BOTAN_HAS_SHAKE_XOF) |
30 | 0 | if(req.algo_name() == "SHAKE-128" && req.arg_count() == 0) { |
31 | 0 | return std::make_unique<SHAKE_128_XOF>(); |
32 | 0 | } |
33 | 0 | if(req.algo_name() == "SHAKE-256" && req.arg_count() == 0) { |
34 | 0 | return std::make_unique<SHAKE_256_XOF>(); |
35 | 0 | } |
36 | 0 | #endif |
37 | | |
38 | 0 | return nullptr; |
39 | 0 | } |
40 | | |
41 | | //static |
42 | 0 | std::unique_ptr<XOF> XOF::create_or_throw(std::string_view algo_spec, std::string_view provider) { |
43 | 0 | if(auto xof = XOF::create(algo_spec, provider)) { |
44 | 0 | return xof; |
45 | 0 | } |
46 | 0 | throw Lookup_Error("XOF", algo_spec, provider); |
47 | 0 | } |
48 | | |
49 | | // static |
50 | 0 | std::vector<std::string> XOF::providers(std::string_view algo_spec) { |
51 | 0 | return probe_providers_of<XOF>(algo_spec, {"base"}); |
52 | 0 | } |
53 | | |
54 | 0 | std::string XOF::provider() const { |
55 | 0 | return "base"; |
56 | 0 | } |
57 | | |
58 | 0 | void XOF::start(std::span<const uint8_t> salt, std::span<const uint8_t> key) { |
59 | 0 | if(!key_spec().valid_keylength(key.size())) { |
60 | 0 | throw Invalid_Key_Length(name(), key.size()); |
61 | 0 | } |
62 | | |
63 | 0 | if(!valid_salt_length(salt.size())) { |
64 | 0 | throw Invalid_Argument(fmt("{} cannot accept a salt length of {}", name(), salt.size())); |
65 | 0 | } |
66 | | |
67 | 0 | m_xof_started = true; |
68 | 0 | start_msg(salt, key); |
69 | 0 | } |
70 | | |
71 | 0 | void XOF::start_msg(std::span<const uint8_t> salt, std::span<const uint8_t> key) { |
72 | 0 | BOTAN_UNUSED(salt, key); |
73 | 0 | } |
74 | | |
75 | | } // namespace Botan |