proxygen
folly::ssl::OpenSSLHash Class Reference

#include <OpenSSLHash.h>

Classes

class  Digest
 
class  Hmac
 

Static Public Member Functions

static void hash (MutableByteRange out, const EVP_MD *md, ByteRange data)
 
static void hash (MutableByteRange out, const EVP_MD *md, const IOBuf &data)
 
static void sha1 (MutableByteRange out, ByteRange data)
 
static void sha1 (MutableByteRange out, const IOBuf &data)
 
static void sha256 (MutableByteRange out, ByteRange data)
 
static void sha256 (MutableByteRange out, const IOBuf &data)
 
static void hmac (MutableByteRange out, const EVP_MD *md, ByteRange key, ByteRange data)
 
static void hmac (MutableByteRange out, const EVP_MD *md, ByteRange key, const IOBuf &data)
 
static void hmac_sha1 (MutableByteRange out, ByteRange key, ByteRange data)
 
static void hmac_sha1 (MutableByteRange out, ByteRange key, const IOBuf &data)
 
static void hmac_sha256 (MutableByteRange out, ByteRange key, ByteRange data)
 
static void hmac_sha256 (MutableByteRange out, ByteRange key, const IOBuf &data)
 

Static Private Member Functions

static void check_out_size (size_t size, MutableByteRange out)
 
static void check_out_size_throw (size_t size, MutableByteRange out)
 
static void check_libssl_result (int expected, int result)
 

Detailed Description

Warning: These functions are not thread-safe unless you initialize OpenSSL.

Definition at line 29 of file OpenSSLHash.h.

Member Function Documentation

static void folly::ssl::OpenSSLHash::check_libssl_result ( int  expected,
int  result 
)
inlinestaticprivate

Definition at line 176 of file OpenSSLHash.h.

References LIKELY.

Referenced by folly::ssl::OpenSSLHash::Digest::Digest(), folly::ssl::OpenSSLHash::Digest::hash_final(), folly::ssl::OpenSSLHash::Hmac::hash_final(), folly::ssl::OpenSSLHash::Digest::hash_init(), folly::ssl::OpenSSLHash::Hmac::hash_init(), folly::ssl::OpenSSLHash::Digest::hash_update(), and folly::ssl::OpenSSLHash::Hmac::hash_update().

176  {
177  if (LIKELY(result == expected)) {
178  return;
179  }
180  throw_exception<std::runtime_error>("openssl crypto function failed");
181  }
#define LIKELY(x)
Definition: Likely.h:47
static void folly::ssl::OpenSSLHash::check_out_size ( size_t  size,
MutableByteRange  out 
)
inlinestaticprivate

Definition at line 166 of file OpenSSLHash.h.

References check_out_size_throw(), LIKELY, folly::size(), and folly::Range< Iter >::size().

Referenced by folly::ssl::OpenSSLHash::Digest::hash_final(), and folly::ssl::OpenSSLHash::Hmac::hash_final().

166  {
167  if (LIKELY(size == out.size())) {
168  return;
169  }
171  }
static void check_out_size_throw(size_t size, MutableByteRange out)
Definition: OpenSSLHash.cpp:24
#define LIKELY(x)
Definition: Likely.h:47
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
void folly::ssl::OpenSSLHash::check_out_size_throw ( size_t  size,
MutableByteRange  out 
)
staticprivate

Definition at line 24 of file OpenSSLHash.cpp.

References folly::sformat(), and folly::Range< Iter >::size().

Referenced by check_out_size().

26  {
27  throw std::invalid_argument(folly::sformat(
28  "expected out of size {} but was of size {}", size, out.size()));
29 }
std::string sformat(StringPiece fmt, Args &&...args)
Definition: Format.h:280
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
static void folly::ssl::OpenSSLHash::hash ( MutableByteRange  out,
const EVP_MD *  md,
ByteRange  data 
)
inlinestatic

Definition at line 76 of file OpenSSLHash.h.

References folly::ssl::OpenSSLHash::Digest::hash_final(), folly::ssl::OpenSSLHash::Digest::hash_init(), and folly::ssl::OpenSSLHash::Digest::hash_update().

Referenced by fizz::Sha< T >::hash(), hash(), sha1(), and sha256().

76  {
77  Digest hash;
78  hash.hash_init(md);
79  hash.hash_update(data);
80  hash.hash_final(out);
81  }
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static void hash(MutableByteRange out, const EVP_MD *md, ByteRange data)
Definition: OpenSSLHash.h:76
static void folly::ssl::OpenSSLHash::hash ( MutableByteRange  out,
const EVP_MD *  md,
const IOBuf data 
)
inlinestatic

Definition at line 82 of file OpenSSLHash.h.

References hash(), folly::ssl::OpenSSLHash::Digest::hash_final(), folly::ssl::OpenSSLHash::Digest::hash_init(), and folly::ssl::OpenSSLHash::Digest::hash_update().

82  {
83  Digest hash;
84  hash.hash_init(md);
85  hash.hash_update(data);
86  hash.hash_final(out);
87  }
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static void hash(MutableByteRange out, const EVP_MD *md, ByteRange data)
Definition: OpenSSLHash.h:76
static void folly::ssl::OpenSSLHash::hmac ( MutableByteRange  out,
const EVP_MD *  md,
ByteRange  key,
ByteRange  data 
)
inlinestatic

Definition at line 134 of file OpenSSLHash.h.

References folly::ssl::OpenSSLHash::Hmac::hash_final(), folly::ssl::OpenSSLHash::Hmac::hash_init(), and folly::ssl::OpenSSLHash::Hmac::hash_update().

Referenced by fizz::Sha< T >::hmac(), hmac(), hmac_sha1(), and hmac_sha256().

134  {
135  Hmac hmac;
136  hmac.hash_init(md, key);
137  hmac.hash_update(data);
138  hmac.hash_final(out);
139  }
static void hmac(MutableByteRange out, const EVP_MD *md, ByteRange key, ByteRange data)
Definition: OpenSSLHash.h:134
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static void folly::ssl::OpenSSLHash::hmac ( MutableByteRange  out,
const EVP_MD *  md,
ByteRange  key,
const IOBuf data 
)
inlinestatic

Definition at line 140 of file OpenSSLHash.h.

References folly::ssl::OpenSSLHash::Hmac::hash_final(), folly::ssl::OpenSSLHash::Hmac::hash_init(), folly::ssl::OpenSSLHash::Hmac::hash_update(), and hmac().

144  {
145  Hmac hmac;
146  hmac.hash_init(md, key);
147  hmac.hash_update(data);
148  hmac.hash_final(out);
149  }
static void hmac(MutableByteRange out, const EVP_MD *md, ByteRange key, ByteRange data)
Definition: OpenSSLHash.h:134
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static void folly::ssl::OpenSSLHash::hmac_sha1 ( MutableByteRange  out,
ByteRange  key,
ByteRange  data 
)
inlinestatic

Definition at line 150 of file OpenSSLHash.h.

References hmac().

150  {
151  hmac(out, EVP_sha1(), key, data);
152  }
static void hmac(MutableByteRange out, const EVP_MD *md, ByteRange key, ByteRange data)
Definition: OpenSSLHash.h:134
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static void folly::ssl::OpenSSLHash::hmac_sha1 ( MutableByteRange  out,
ByteRange  key,
const IOBuf data 
)
inlinestatic

Definition at line 154 of file OpenSSLHash.h.

References hmac().

154  {
155  hmac(out, EVP_sha1(), key, data);
156  }
static void hmac(MutableByteRange out, const EVP_MD *md, ByteRange key, ByteRange data)
Definition: OpenSSLHash.h:134
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static void folly::ssl::OpenSSLHash::hmac_sha256 ( MutableByteRange  out,
ByteRange  key,
ByteRange  data 
)
inlinestatic

Definition at line 157 of file OpenSSLHash.h.

References hmac().

157  {
158  hmac(out, EVP_sha256(), key, data);
159  }
static void hmac(MutableByteRange out, const EVP_MD *md, ByteRange key, ByteRange data)
Definition: OpenSSLHash.h:134
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static void folly::ssl::OpenSSLHash::hmac_sha256 ( MutableByteRange  out,
ByteRange  key,
const IOBuf data 
)
inlinestatic

Definition at line 161 of file OpenSSLHash.h.

References hmac().

161  {
162  hmac(out, EVP_sha256(), key, data);
163  }
static void hmac(MutableByteRange out, const EVP_MD *md, ByteRange key, ByteRange data)
Definition: OpenSSLHash.h:134
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static void folly::ssl::OpenSSLHash::sha1 ( MutableByteRange  out,
ByteRange  data 
)
inlinestatic

Definition at line 88 of file OpenSSLHash.h.

References hash().

88  {
89  hash(out, EVP_sha1(), data);
90  }
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static void hash(MutableByteRange out, const EVP_MD *md, ByteRange data)
Definition: OpenSSLHash.h:76
static void folly::ssl::OpenSSLHash::sha1 ( MutableByteRange  out,
const IOBuf data 
)
inlinestatic

Definition at line 91 of file OpenSSLHash.h.

References hash().

91  {
92  hash(out, EVP_sha1(), data);
93  }
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static void hash(MutableByteRange out, const EVP_MD *md, ByteRange data)
Definition: OpenSSLHash.h:76
static void folly::ssl::OpenSSLHash::sha256 ( MutableByteRange  out,
ByteRange  data 
)
inlinestatic

Definition at line 94 of file OpenSSLHash.h.

References hash().

94  {
95  hash(out, EVP_sha256(), data);
96  }
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static void hash(MutableByteRange out, const EVP_MD *md, ByteRange data)
Definition: OpenSSLHash.h:76
static void folly::ssl::OpenSSLHash::sha256 ( MutableByteRange  out,
const IOBuf data 
)
inlinestatic

Definition at line 97 of file OpenSSLHash.h.

References hash().

97  {
98  hash(out, EVP_sha256(), data);
99  }
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static void hash(MutableByteRange out, const EVP_MD *md, ByteRange data)
Definition: OpenSSLHash.h:76

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