rippled
mac_facade.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of Beast: https://github.com/vinniefalco/Beast
4  Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef BEAST_CRYPTO_MAC_FACADE_H_INCLUDED
21 #define BEAST_CRYPTO_MAC_FACADE_H_INCLUDED
22 
23 #include <ripple/beast/crypto/secure_erase.h>
24 #include <ripple/beast/hash/endian.h>
25 #include <type_traits>
26 #include <array>
27 
28 namespace beast {
29 namespace detail {
30 
31 // Message Authentication Code (MAC) facade
32 template <class Context, bool Secure>
34 {
35 private:
36  Context ctx_;
37 
38 public:
39  static beast::endian const endian =
41 
42  static std::size_t const digest_size =
43  Context::digest_size;
44 
45  using result_type =
47 
48  mac_facade() noexcept
49  {
50  init(ctx_);
51  }
52 
54  {
56  bool, Secure>{});
57  }
58 
59  void
60  operator()(void const* data,
61  std::size_t size) noexcept
62  {
63  update(ctx_, data, size);
64  }
65 
66  explicit
67  operator result_type() noexcept
68  {
69  result_type digest;
70  finish(ctx_, &digest[0]);
71  return digest;
72  }
73 
74 private:
75  inline
76  void
78  {
79  }
80 
81  inline
82  void
83  erase (std::true_type) noexcept
84  {
85  secure_erase(&ctx_, sizeof(ctx_));
86  }
87 };
88 
89 } // detail
90 } // beast
91 
92 #endif
std::integral_constant
beast::detail::update
void update(ripemd160_context &ctx, void const *message, std::size_t size) noexcept
Definition: ripemd_context.h:355
beast::detail::mac_facade::~mac_facade
~mac_facade()
Definition: mac_facade.h:53
beast::detail::mac_facade::digest_size
static const std::size_t digest_size
Definition: mac_facade.h:42
beast::detail::mac_facade::mac_facade
mac_facade() noexcept
Definition: mac_facade.h:48
beast::endian::native
@ native
array
beast::secure_erase
void secure_erase(void *dest, std::size_t bytes)
Guaranteed to fill memory with zeroes.
Definition: secure_erase.h:83
beast::detail::init
void init(ripemd160_context &ctx) noexcept
Definition: ripemd_context.h:343
beast::detail::finish
void finish(ripemd160_context &ctx, void *digest) noexcept
Definition: ripemd_context.h:392
beast::detail::mac_facade::erase
void erase(std::false_type) noexcept
Definition: mac_facade.h:77
beast::detail::mac_facade::result_type
std::array< std::uint8_t, digest_size > result_type
Definition: mac_facade.h:46
beast::detail::mac_facade::ctx_
Context ctx_
Definition: mac_facade.h:36
beast::detail::mac_facade
Definition: mac_facade.h:33
std::size_t
beast::detail::mac_facade::erase
void erase(std::true_type) noexcept
Definition: mac_facade.h:83
beast::detail::mac_facade::operator()
void operator()(void const *data, std::size_t size) noexcept
Definition: mac_facade.h:60
type_traits
beast::endian
endian
Definition: endian.h:30
beast
Definition: base_uint.h:582