14#ifndef OPENVPN_CRYPTO_OVPNHMAC_H
15#define OPENVPN_CRYPTO_OVPNHMAC_H
30template <
typename CRYPTO_API>
47 return ctx.is_initialized();
62 throw ovpn_hmac_context_digest_size();
69 const size_t out_size,
70 const unsigned char *in,
74 ctx.update(in, in_size);
81 const size_t data_size,
89 throw ovpn_hmac_context_bad_sizing();
94 const size_t data_size,
99 unsigned char local_hmac[CRYPTO_API::HMACContext::MAX_HMAC_SIZE];
102 ctx.final(local_hmac);
116 const size_t data_size,
121 const size_t lsum = l1 + l2 + l3;
122 if (lsum > data_size || l2 !=
ctx.size())
125 ctx.update(data + l1 + l2, l3);
126 ctx.update(data, l1);
127 ctx.update(data + lsum, data_size - lsum);
131 typename CRYPTO_API::HMACContext
ctx;
146 const size_t data_size,
149 const size_t l3) = 0;
152 const size_t data_size,
155 const size_t l3) = 0;
163 virtual size_t size()
const = 0;
178template <
typename CRYPTO_API>
198 const size_t data_size,
201 const size_t l3)
override
203 ovpn_hmac.ovpn_hmac_gen(data, data_size, l1, l2, l3);
207 const size_t data_size,
210 const size_t l3)
override
212 return ovpn_hmac.ovpn_hmac_cmp(data, data_size, l1, l2, l3);
220template <
typename CRYPTO_API>
243template <
typename CRYPTO_API>
OvpnHMACInstance::Ptr new_obj() override
CryptoOvpnHMACContext(const CryptoAlgs::Type digest_type)
size_t size() const override
OvpnHMACContext::Ptr new_obj(const CryptoAlgs::Type digest_type) override
bool ovpn_hmac_cmp(const unsigned char *data, const size_t data_size, const size_t l1, const size_t l2, const size_t l3) override
void ovpn_hmac_gen(unsigned char *data, const size_t data_size, const size_t l1, const size_t l2, const size_t l3) override
CryptoOvpnHMACInstance(const CryptoAlgs::Type digest_arg)
OvpnHMAC< CRYPTO_API > ovpn_hmac
void init(const StaticKey &key) override
size_t output_size() const override
virtual OvpnHMACInstance::Ptr new_obj()=0
virtual size_t size() const =0
virtual OvpnHMACContext::Ptr new_obj(const CryptoAlgs::Type digest_type)=0
virtual void ovpn_hmac_gen(unsigned char *data, const size_t data_size, const size_t l1, const size_t l2, const size_t l3)=0
virtual void init(const StaticKey &key)=0
virtual bool ovpn_hmac_cmp(const unsigned char *data, const size_t data_size, const size_t l1, const size_t l2, const size_t l3)=0
virtual size_t output_size() const =0
bool ovpn_hmac_pre(const unsigned char *data, const size_t data_size, const size_t l1, const size_t l2, const size_t l3)
void ovpn_hmac_gen(unsigned char *data, const size_t data_size, const size_t l1, const size_t l2, const size_t l3)
size_t output_size() const
OPENVPN_SIMPLE_EXCEPTION(ovpn_hmac_context_digest_size)
bool ovpn_hmac_cmp(const unsigned char *data, const size_t data_size, const size_t l1, const size_t l2, const size_t l3)
CRYPTO_API::HMACContext ctx
void init(const CryptoAlgs::Type digest, const StaticKey &key)
OvpnHMAC(const CryptoAlgs::Type digest, const StaticKey &key)
void hmac(unsigned char *out, const size_t out_size, const unsigned char *in, const size_t in_size)
OPENVPN_SIMPLE_EXCEPTION(ovpn_hmac_context_bad_sizing)
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
const unsigned char * data() const
const Alg & get(const Type type)
size_t size(const Type type)
bool memneq(const void *a, const void *b, size_t size)
static std::stringstream out