10#include <botan/exceptn.h>
11#include <botan/internal/algorithm_spec.h>
12#include <botan/internal/ct_utils.h>
13#include <botan/internal/probe_providers.h>
15#if defined(BOTAN_HAS_CMAC)
16 #include <botan/internal/cmac.h>
19#if defined(BOTAN_HAS_GMAC)
20 #include <botan/block_cipher.h>
21 #include <botan/internal/gmac.h>
24#if defined(BOTAN_HAS_HMAC)
25 #include <botan/hash.h>
26 #include <botan/internal/hmac.h>
29#if defined(BOTAN_HAS_POLY1305)
30 #include <botan/internal/poly1305.h>
33#if defined(BOTAN_HAS_SIPHASH)
34 #include <botan/internal/siphash.h>
37#if defined(BOTAN_HAS_ANSI_X919_MAC)
38 #include <botan/internal/x919_mac.h>
41#if defined(BOTAN_HAS_BLAKE2BMAC)
42 #include <botan/internal/blake2bmac.h>
45#if defined(BOTAN_HAS_KMAC)
46 #include <botan/internal/kmac.h>
55#if defined(BOTAN_HAS_BLAKE2BMAC)
56 if(
auto m = req.
match(
"BLAKE2b|Blake2b({bits:int=512})")) {
58 return std::make_unique<BLAKE2bMAC>(m->integer(
"bits"));
63#if defined(BOTAN_HAS_GMAC)
64 if(
auto m = req.
match(
"GMAC({cipher})")) {
67 return std::make_unique<GMAC>(std::move(bc));
73#if defined(BOTAN_HAS_HMAC)
74 if(
auto m = req.
match(
"HMAC({hash})")) {
77 return std::make_unique<HMAC>(std::move(hash));
83#if defined(BOTAN_HAS_POLY1305)
86 return std::make_unique<Poly1305>();
91#if defined(BOTAN_HAS_SIPHASH)
92 if(
auto m = req.
match(
"SipHash({c:int=2},{d:int=4})")) {
94 return std::make_unique<SipHash>(m->integer(
"c"), m->integer(
"d"));
99#if defined(BOTAN_HAS_CMAC)
100 if(
auto m = req.
match(
"CMAC|OMAC({cipher})")) {
103 return std::make_unique<CMAC>(std::move(bc));
109#if defined(BOTAN_HAS_ANSI_X919_MAC)
112 return std::make_unique<ANSI_X919_MAC>();
117#if defined(BOTAN_HAS_KMAC)
118 if(
auto m = req.
match(
"KMAC-128({bits:int})")) {
120 return std::make_unique<KMAC128>(m->integer(
"bits"));
124 if(
auto m = req.
match(
"KMAC-256({bits:int})")) {
126 return std::make_unique<KMAC256>(m->integer(
"bits"));
156 if(our_mac.size() != mac.size()) {
160 return CT::is_equal(our_mac.data(), mac.data(), mac.size()).as_bool();
bool matches(const AlgorithmPattern &pattern) const
std::optional< AlgorithmMatch > match(const AlgorithmPattern &pattern) const &
static std::unique_ptr< BlockCipher > create(std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
virtual bool verify_mac_result(std::span< const uint8_t > in)
static std::unique_ptr< MessageAuthenticationCode > create_or_throw(std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< MessageAuthenticationCode > create(std::string_view algo_spec, std::string_view provider="")
virtual std::string provider() const
static std::vector< std::string > providers(std::string_view algo_spec)
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
std::vector< std::string > probe_providers_of(std::string_view algo_spec, const std::vector< std::string > &possible={"base"})
std::vector< T, secure_allocator< T > > secure_vector