/src/botan/src/lib/xof/xof.cpp
Line | Count | Source |
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 | | #if defined(BOTAN_HAS_ASCON_XOF128) |
19 | | #include <botan/internal/ascon_xof128.h> |
20 | | #endif |
21 | | |
22 | | #include <botan/exceptn.h> |
23 | | #include <botan/internal/fmt.h> |
24 | | |
25 | | namespace Botan { |
26 | | |
27 | | //static |
28 | 312 | std::unique_ptr<XOF> XOF::create(std::string_view algo_spec, std::string_view provider) { |
29 | 312 | const SCAN_Name req(algo_spec); |
30 | | |
31 | 312 | if(!provider.empty() && provider != "base") { |
32 | 0 | return nullptr; // unknown provider |
33 | 0 | } |
34 | | |
35 | 312 | #if defined(BOTAN_HAS_SHAKE_XOF) |
36 | 312 | if(req.algo_name() == "SHAKE-128" && req.arg_count() == 0) { |
37 | 156 | return std::make_unique<SHAKE_128_XOF>(); |
38 | 156 | } |
39 | 156 | if(req.algo_name() == "SHAKE-256" && req.arg_count() == 0) { |
40 | 156 | return std::make_unique<SHAKE_256_XOF>(); |
41 | 156 | } |
42 | 0 | #endif |
43 | | |
44 | 0 | #if defined(BOTAN_HAS_ASCON_XOF128) |
45 | 0 | if(req.algo_name() == "Ascon-XOF128" && req.arg_count() == 0) { |
46 | 0 | return std::make_unique<Ascon_XOF128>(); |
47 | 0 | } |
48 | 0 | #endif |
49 | | |
50 | 0 | return nullptr; |
51 | 0 | } |
52 | | |
53 | | //static |
54 | 312 | std::unique_ptr<XOF> XOF::create_or_throw(std::string_view algo_spec, std::string_view provider) { |
55 | 312 | if(auto xof = XOF::create(algo_spec, provider)) { |
56 | 312 | return xof; |
57 | 312 | } |
58 | 0 | throw Lookup_Error("XOF", algo_spec, provider); |
59 | 312 | } |
60 | | |
61 | | // static |
62 | 0 | std::vector<std::string> XOF::providers(std::string_view algo_spec) { |
63 | 0 | return probe_providers_of<XOF>(algo_spec, {"base"}); |
64 | 0 | } |
65 | | |
66 | 0 | std::string XOF::provider() const { |
67 | 0 | return "base"; |
68 | 0 | } |
69 | | |
70 | 6.08k | void XOF::start(std::span<const uint8_t> salt, std::span<const uint8_t> key) { |
71 | 6.08k | if(!key_spec().valid_keylength(key.size())) { |
72 | 0 | throw Invalid_Key_Length(name(), key.size()); |
73 | 0 | } |
74 | | |
75 | 6.08k | if(!valid_salt_length(salt.size())) { |
76 | 0 | throw Invalid_Argument(fmt("{} cannot accept a salt length of {}", name(), salt.size())); |
77 | 0 | } |
78 | | |
79 | 6.08k | m_xof_started = true; |
80 | 6.08k | start_msg(salt, key); |
81 | 6.08k | } |
82 | | |
83 | 6.08k | void XOF::start_msg(std::span<const uint8_t> salt, std::span<const uint8_t> key) { |
84 | 6.08k | BOTAN_UNUSED(salt, key); |
85 | 6.08k | } |
86 | | |
87 | | } // namespace Botan |