proxygen
folly::ssl::OpenSSLHash::Hmac Class Reference

#include <OpenSSLHash.h>

Public Member Functions

 Hmac ()
 
void hash_init (const EVP_MD *md, ByteRange key)
 
void hash_update (ByteRange data)
 
void hash_update (const IOBuf &data)
 
void hash_final (MutableByteRange out)
 

Private Attributes

const EVP_MD * md_ = nullptr
 
HmacCtxUniquePtr ctx_ {nullptr}
 

Detailed Description

Definition at line 101 of file OpenSSLHash.h.

Constructor & Destructor Documentation

folly::ssl::OpenSSLHash::Hmac::Hmac ( )
inline

Definition at line 103 of file OpenSSLHash.h.

103 : ctx_(HMAC_CTX_new()) {}
HMAC_CTX * HMAC_CTX_new()
Definition: OpenSSL.cpp:337

Member Function Documentation

void folly::ssl::OpenSSLHash::Hmac::hash_final ( MutableByteRange  out)
inline

Definition at line 119 of file OpenSSLHash.h.

References folly::ssl::OpenSSLHash::check_libssl_result(), folly::ssl::OpenSSLHash::check_out_size(), folly::ssl::OpenSSLHash::Digest::ctx_, folly::Range< Iter >::data(), folly::ssl::OpenSSLHash::Digest::md_, and folly::size().

Referenced by folly::ssl::OpenSSLHash::hmac().

119  {
120  const auto size = EVP_MD_size(md_);
121  check_out_size(size_t(size), out);
122  unsigned int len = 0;
123  check_libssl_result(1, HMAC_Final(ctx_.get(), out.data(), &len));
124  check_libssl_result(size, int(len));
125  md_ = nullptr;
126  }
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
static void check_libssl_result(int expected, int result)
Definition: OpenSSLHash.h:176
static void check_out_size(size_t size, MutableByteRange out)
Definition: OpenSSLHash.h:166
void folly::ssl::OpenSSLHash::Hmac::hash_init ( const EVP_MD *  md,
ByteRange  key 
)
inline

Definition at line 105 of file OpenSSLHash.h.

References folly::ssl::OpenSSLHash::check_libssl_result(), folly::ssl::OpenSSLHash::Digest::ctx_, folly::Range< Iter >::data(), folly::ssl::OpenSSLHash::Digest::md_, and folly::Range< Iter >::size().

Referenced by folly::ssl::OpenSSLHash::hmac().

105  {
106  md_ = md;
108  1,
109  HMAC_Init_ex(ctx_.get(), key.data(), int(key.size()), md_, nullptr));
110  }
static void check_libssl_result(int expected, int result)
Definition: OpenSSLHash.h:176
void folly::ssl::OpenSSLHash::Hmac::hash_update ( ByteRange  data)
inline

Definition at line 111 of file OpenSSLHash.h.

References folly::ssl::OpenSSLHash::check_libssl_result(), folly::ssl::OpenSSLHash::Digest::ctx_, folly::Range< Iter >::data(), and folly::Range< Iter >::size().

Referenced by folly::ssl::OpenSSLHash::hmac().

111  {
112  check_libssl_result(1, HMAC_Update(ctx_.get(), data.data(), data.size()));
113  }
static void check_libssl_result(int expected, int result)
Definition: OpenSSLHash.h:176
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
void folly::ssl::OpenSSLHash::Hmac::hash_update ( const IOBuf data)
inline

Definition at line 114 of file OpenSSLHash.h.

References folly::ssl::OpenSSLHash::Digest::hash_update().

114  {
115  for (auto r : data) {
116  hash_update(r);
117  }
118  }
void hash_update(ByteRange data)
Definition: OpenSSLHash.h:111
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71

Member Data Documentation

HmacCtxUniquePtr folly::ssl::OpenSSLHash::Hmac::ctx_ {nullptr}
private

Definition at line 130 of file OpenSSLHash.h.

const EVP_MD* folly::ssl::OpenSSLHash::Hmac::md_ = nullptr
private

Definition at line 129 of file OpenSSLHash.h.


The documentation for this class was generated from the following file: