diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index 341eeec2b8..3e358f52f7 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -367,9 +367,15 @@ True - + - + + + + + + + True diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index 84a7ea1820..15ca986ed7 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -43,8 +43,8 @@ {ED78E906-CE72-CDEF-3018-99E02603C37E} - - {398085D5-BDC7-D75C-2A1D-73395AC7A158} + + {80B5AA79-B513-6410-D468-472E3E393BAA} {FF9CBE50-56A0-7B59-C99F-C873605C844B} @@ -825,10 +825,19 @@ beast\crypto - - beast\crypto\impl + + beast\crypto\detail - + + beast\crypto\detail + + + beast\crypto\detail + + + beast\crypto + + beast\crypto diff --git a/src/beast/beast/crypto/sha512.h b/src/beast/beast/crypto/detail/mac_facade.h similarity index 66% rename from src/beast/beast/crypto/sha512.h rename to src/beast/beast/crypto/detail/mac_facade.h index e482ba6edd..8997048c38 100644 --- a/src/beast/beast/crypto/sha512.h +++ b/src/beast/beast/crypto/detail/mac_facade.h @@ -17,67 +17,42 @@ */ //============================================================================== -#ifndef BEAST_CRYPTO_SHA512_H_INCLUDED -#define BEAST_CRYPTO_SHA512_H_INCLUDED +#ifndef BEAST_CRYPTO_MAC_FACADE_H_INCLUDED +#define BEAST_CRYPTO_MAC_FACADE_H_INCLUDED +#include #include #include -#include +#include #include namespace beast { +namespace detail { -class sha512_hasher +// Message Authentication Code (MAC) facade +template +class mac_facade { -public: - static beast::endian const endian = - beast::endian::native; - - using result_type = - std::array; - - sha512_hasher() - { - detail::init(ctx_); - } - - void - operator()(void const* data, - std::size_t size) noexcept - { - detail::update(ctx_, data, size); - } - - explicit - operator result_type() noexcept - { - result_type digest; - finish(ctx_, &digest[0]); - return digest; - } - private: - detail::sha512_context ctx_; -}; + Context ctx_; -// secure version -class sha512_hasher_s -{ public: static beast::endian const endian = beast::endian::native; using result_type = - std::array; + std::array; - sha512_hasher_s() + mac_facade() noexcept { init(ctx_); } - ~sha512_hasher_s() + ~mac_facade() { - secure_erase(ctx_); + erase(std::integral_constant< + bool, Secure>{}); } void @@ -96,9 +71,21 @@ public: } private: - detail::sha512_context ctx_; + inline + void + erase (std::false_type) noexcept + { + } + + inline + void + erase (std::true_type) noexcept + { + secure_erase(&ctx_, sizeof(ctx_)); + } }; -} +} // detail +} // beast #endif diff --git a/src/beast/beast/crypto/detail/ripemd_context.h b/src/beast/beast/crypto/detail/ripemd_context.h new file mode 100644 index 0000000000..cc5f91fbb1 --- /dev/null +++ b/src/beast/beast/crypto/detail/ripemd_context.h @@ -0,0 +1,430 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_CRYPTO_RIPEMD_CONTEXT_H_INCLUDED +#define BEAST_CRYPTO_RIPEMD_CONTEXT_H_INCLUDED + +#include +#include +#include +#include + +namespace beast { +namespace detail { + +// Based on +// https://code.google.com/p/blockchain/source/browse/trunk/RIPEMD160.cpp +/* + Copyright (c) Katholieke Universiteit Leuven + 1996 All Rights Reserved + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ +// This implementation has been modified from the +// original. It has been updated for C++11. + +struct ripemd160_context +{ + static unsigned int const block_size = 64; + static unsigned int const digest_size = 20; + + unsigned int tot_len; + unsigned int len; + unsigned char block[256]; + std::uint32_t h[5]; +}; + +// ROL(x, n) cyclically rotates x over n bits to the left +// x must be of an unsigned 32 bits type and 0 <= n < 32. +#define BEAST_RIPEMD_ROL(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + +// the five basic functions F(), G() and H() +#define BEAST_RIPEMD_F(x, y, z) ((x) ^ (y) ^ (z)) +#define BEAST_RIPEMD_G(x, y, z) (((x) & (y)) | (~(x) & (z))) +#define BEAST_RIPEMD_H(x, y, z) (((x) | ~(y)) ^ (z)) +#define BEAST_RIPEMD_I(x, y, z) (((x) & (z)) | ((y) & ~(z))) +#define BEAST_RIPEMD_J(x, y, z) ((x) ^ ((y) | ~(z))) + +// the ten basic operations FF() through III() +#define BEAST_RIPEMD_FF(a, b, c, d, e, x, s) { \ + (a) += BEAST_RIPEMD_F((b), (c), (d)) + (x); \ + (a) = BEAST_RIPEMD_ROL((a), (s)) + (e); \ + (c) = BEAST_RIPEMD_ROL((c), 10); } +#define BEAST_RIPEMD_GG(a, b, c, d, e, x, s) { \ + (a) += BEAST_RIPEMD_G((b), (c), (d)) + (x) + 0x5a827999UL; \ + (a) = BEAST_RIPEMD_ROL((a), (s)) + (e); \ + (c) = BEAST_RIPEMD_ROL((c), 10); } +#define BEAST_RIPEMD_HH(a, b, c, d, e, x, s) { \ + (a) += BEAST_RIPEMD_H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\ + (a) = BEAST_RIPEMD_ROL((a), (s)) + (e); \ + (c) = BEAST_RIPEMD_ROL((c), 10); } +#define BEAST_RIPEMD_II(a, b, c, d, e, x, s) { \ + (a) += BEAST_RIPEMD_I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\ + (a) = BEAST_RIPEMD_ROL((a), (s)) + (e); \ + (c) = BEAST_RIPEMD_ROL((c), 10); } +#define BEAST_RIPEMD_JJ(a, b, c, d, e, x, s) { \ + (a) += BEAST_RIPEMD_J((b), (c), (d)) + (x) + 0xa953fd4eUL;\ + (a) = BEAST_RIPEMD_ROL((a), (s)) + (e); \ + (c) = BEAST_RIPEMD_ROL((c), 10); } +#define BEAST_RIPEMD_FFF(a, b, c, d, e, x, s) { \ + (a) += BEAST_RIPEMD_F((b), (c), (d)) + (x); \ + (a) = BEAST_RIPEMD_ROL((a), (s)) + (e); \ + (c) = BEAST_RIPEMD_ROL((c), 10); } +#define BEAST_RIPEMD_GGG(a, b, c, d, e, x, s) { \ + (a) += BEAST_RIPEMD_G((b), (c), (d)) + (x) + 0x7a6d76e9UL;\ + (a) = BEAST_RIPEMD_ROL((a), (s)) + (e); \ + (c) = BEAST_RIPEMD_ROL((c), 10); } +#define BEAST_RIPEMD_HHH(a, b, c, d, e, x, s) { \ + (a) += BEAST_RIPEMD_H((b), (c), (d)) + (x) + 0x6d703ef3UL;\ + (a) = BEAST_RIPEMD_ROL((a), (s)) + (e); \ + (c) = BEAST_RIPEMD_ROL((c), 10); } +#define BEAST_RIPEMD_III(a, b, c, d, e, x, s) { \ + (a) += BEAST_RIPEMD_I((b), (c), (d)) + (x) + 0x5c4dd124UL;\ + (a) = BEAST_RIPEMD_ROL((a), (s)) + (e); \ + (c) = BEAST_RIPEMD_ROL((c), 10); } +#define BEAST_RIPEMD_JJJ(a, b, c, d, e, x, s) { \ + (a) += BEAST_RIPEMD_J((b), (c), (d)) + (x) + 0x50a28be6UL;\ + (a) = BEAST_RIPEMD_ROL((a), (s)) + (e); \ + (c) = BEAST_RIPEMD_ROL((c), 10); } + +template +void ripemd_load (std::array& X, + unsigned char const* p) +{ + for(int i = 0; i < 16; ++i) + { + X[i] = + ((std::uint32_t) *((p)+3) << 24) | + ((std::uint32_t) *((p)+2) << 16) | + ((std::uint32_t) *((p)+1) << 8) | + ((std::uint32_t) * (p)); + p += 4; + } +} + +template +void ripemd_compress (ripemd160_context& ctx, + std::array& X) noexcept +{ + std::uint32_t aa = ctx.h[0]; + std::uint32_t bb = ctx.h[1]; + std::uint32_t cc = ctx.h[2]; + std::uint32_t dd = ctx.h[3]; + std::uint32_t ee = ctx.h[4]; + std::uint32_t aaa = ctx.h[0]; + std::uint32_t bbb = ctx.h[1]; + std::uint32_t ccc = ctx.h[2]; + std::uint32_t ddd = ctx.h[3]; + std::uint32_t eee = ctx.h[4]; + + // round 1 + BEAST_RIPEMD_FF(aa, bb, cc, dd, ee, X[ 0], 11); + BEAST_RIPEMD_FF(ee, aa, bb, cc, dd, X[ 1], 14); + BEAST_RIPEMD_FF(dd, ee, aa, bb, cc, X[ 2], 15); + BEAST_RIPEMD_FF(cc, dd, ee, aa, bb, X[ 3], 12); + BEAST_RIPEMD_FF(bb, cc, dd, ee, aa, X[ 4], 5); + BEAST_RIPEMD_FF(aa, bb, cc, dd, ee, X[ 5], 8); + BEAST_RIPEMD_FF(ee, aa, bb, cc, dd, X[ 6], 7); + BEAST_RIPEMD_FF(dd, ee, aa, bb, cc, X[ 7], 9); + BEAST_RIPEMD_FF(cc, dd, ee, aa, bb, X[ 8], 11); + BEAST_RIPEMD_FF(bb, cc, dd, ee, aa, X[ 9], 13); + BEAST_RIPEMD_FF(aa, bb, cc, dd, ee, X[10], 14); + BEAST_RIPEMD_FF(ee, aa, bb, cc, dd, X[11], 15); + BEAST_RIPEMD_FF(dd, ee, aa, bb, cc, X[12], 6); + BEAST_RIPEMD_FF(cc, dd, ee, aa, bb, X[13], 7); + BEAST_RIPEMD_FF(bb, cc, dd, ee, aa, X[14], 9); + BEAST_RIPEMD_FF(aa, bb, cc, dd, ee, X[15], 8); + + // round 2 + BEAST_RIPEMD_GG(ee, aa, bb, cc, dd, X[ 7], 7); + BEAST_RIPEMD_GG(dd, ee, aa, bb, cc, X[ 4], 6); + BEAST_RIPEMD_GG(cc, dd, ee, aa, bb, X[13], 8); + BEAST_RIPEMD_GG(bb, cc, dd, ee, aa, X[ 1], 13); + BEAST_RIPEMD_GG(aa, bb, cc, dd, ee, X[10], 11); + BEAST_RIPEMD_GG(ee, aa, bb, cc, dd, X[ 6], 9); + BEAST_RIPEMD_GG(dd, ee, aa, bb, cc, X[15], 7); + BEAST_RIPEMD_GG(cc, dd, ee, aa, bb, X[ 3], 15); + BEAST_RIPEMD_GG(bb, cc, dd, ee, aa, X[12], 7); + BEAST_RIPEMD_GG(aa, bb, cc, dd, ee, X[ 0], 12); + BEAST_RIPEMD_GG(ee, aa, bb, cc, dd, X[ 9], 15); + BEAST_RIPEMD_GG(dd, ee, aa, bb, cc, X[ 5], 9); + BEAST_RIPEMD_GG(cc, dd, ee, aa, bb, X[ 2], 11); + BEAST_RIPEMD_GG(bb, cc, dd, ee, aa, X[14], 7); + BEAST_RIPEMD_GG(aa, bb, cc, dd, ee, X[11], 13); + BEAST_RIPEMD_GG(ee, aa, bb, cc, dd, X[ 8], 12); + + // round 3 + BEAST_RIPEMD_HH(dd, ee, aa, bb, cc, X[ 3], 11); + BEAST_RIPEMD_HH(cc, dd, ee, aa, bb, X[10], 13); + BEAST_RIPEMD_HH(bb, cc, dd, ee, aa, X[14], 6); + BEAST_RIPEMD_HH(aa, bb, cc, dd, ee, X[ 4], 7); + BEAST_RIPEMD_HH(ee, aa, bb, cc, dd, X[ 9], 14); + BEAST_RIPEMD_HH(dd, ee, aa, bb, cc, X[15], 9); + BEAST_RIPEMD_HH(cc, dd, ee, aa, bb, X[ 8], 13); + BEAST_RIPEMD_HH(bb, cc, dd, ee, aa, X[ 1], 15); + BEAST_RIPEMD_HH(aa, bb, cc, dd, ee, X[ 2], 14); + BEAST_RIPEMD_HH(ee, aa, bb, cc, dd, X[ 7], 8); + BEAST_RIPEMD_HH(dd, ee, aa, bb, cc, X[ 0], 13); + BEAST_RIPEMD_HH(cc, dd, ee, aa, bb, X[ 6], 6); + BEAST_RIPEMD_HH(bb, cc, dd, ee, aa, X[13], 5); + BEAST_RIPEMD_HH(aa, bb, cc, dd, ee, X[11], 12); + BEAST_RIPEMD_HH(ee, aa, bb, cc, dd, X[ 5], 7); + BEAST_RIPEMD_HH(dd, ee, aa, bb, cc, X[12], 5); + + // round 4 + BEAST_RIPEMD_II(cc, dd, ee, aa, bb, X[ 1], 11); + BEAST_RIPEMD_II(bb, cc, dd, ee, aa, X[ 9], 12); + BEAST_RIPEMD_II(aa, bb, cc, dd, ee, X[11], 14); + BEAST_RIPEMD_II(ee, aa, bb, cc, dd, X[10], 15); + BEAST_RIPEMD_II(dd, ee, aa, bb, cc, X[ 0], 14); + BEAST_RIPEMD_II(cc, dd, ee, aa, bb, X[ 8], 15); + BEAST_RIPEMD_II(bb, cc, dd, ee, aa, X[12], 9); + BEAST_RIPEMD_II(aa, bb, cc, dd, ee, X[ 4], 8); + BEAST_RIPEMD_II(ee, aa, bb, cc, dd, X[13], 9); + BEAST_RIPEMD_II(dd, ee, aa, bb, cc, X[ 3], 14); + BEAST_RIPEMD_II(cc, dd, ee, aa, bb, X[ 7], 5); + BEAST_RIPEMD_II(bb, cc, dd, ee, aa, X[15], 6); + BEAST_RIPEMD_II(aa, bb, cc, dd, ee, X[14], 8); + BEAST_RIPEMD_II(ee, aa, bb, cc, dd, X[ 5], 6); + BEAST_RIPEMD_II(dd, ee, aa, bb, cc, X[ 6], 5); + BEAST_RIPEMD_II(cc, dd, ee, aa, bb, X[ 2], 12); + + // round 5 + BEAST_RIPEMD_JJ(bb, cc, dd, ee, aa, X[ 4], 9); + BEAST_RIPEMD_JJ(aa, bb, cc, dd, ee, X[ 0], 15); + BEAST_RIPEMD_JJ(ee, aa, bb, cc, dd, X[ 5], 5); + BEAST_RIPEMD_JJ(dd, ee, aa, bb, cc, X[ 9], 11); + BEAST_RIPEMD_JJ(cc, dd, ee, aa, bb, X[ 7], 6); + BEAST_RIPEMD_JJ(bb, cc, dd, ee, aa, X[12], 8); + BEAST_RIPEMD_JJ(aa, bb, cc, dd, ee, X[ 2], 13); + BEAST_RIPEMD_JJ(ee, aa, bb, cc, dd, X[10], 12); + BEAST_RIPEMD_JJ(dd, ee, aa, bb, cc, X[14], 5); + BEAST_RIPEMD_JJ(cc, dd, ee, aa, bb, X[ 1], 12); + BEAST_RIPEMD_JJ(bb, cc, dd, ee, aa, X[ 3], 13); + BEAST_RIPEMD_JJ(aa, bb, cc, dd, ee, X[ 8], 14); + BEAST_RIPEMD_JJ(ee, aa, bb, cc, dd, X[11], 11); + BEAST_RIPEMD_JJ(dd, ee, aa, bb, cc, X[ 6], 8); + BEAST_RIPEMD_JJ(cc, dd, ee, aa, bb, X[15], 5); + BEAST_RIPEMD_JJ(bb, cc, dd, ee, aa, X[13], 6); + + // parallel round 1 + BEAST_RIPEMD_JJJ(aaa, bbb, ccc, ddd, eee, X[ 5], 8); + BEAST_RIPEMD_JJJ(eee, aaa, bbb, ccc, ddd, X[14], 9); + BEAST_RIPEMD_JJJ(ddd, eee, aaa, bbb, ccc, X[ 7], 9); + BEAST_RIPEMD_JJJ(ccc, ddd, eee, aaa, bbb, X[ 0], 11); + BEAST_RIPEMD_JJJ(bbb, ccc, ddd, eee, aaa, X[ 9], 13); + BEAST_RIPEMD_JJJ(aaa, bbb, ccc, ddd, eee, X[ 2], 15); + BEAST_RIPEMD_JJJ(eee, aaa, bbb, ccc, ddd, X[11], 15); + BEAST_RIPEMD_JJJ(ddd, eee, aaa, bbb, ccc, X[ 4], 5); + BEAST_RIPEMD_JJJ(ccc, ddd, eee, aaa, bbb, X[13], 7); + BEAST_RIPEMD_JJJ(bbb, ccc, ddd, eee, aaa, X[ 6], 7); + BEAST_RIPEMD_JJJ(aaa, bbb, ccc, ddd, eee, X[15], 8); + BEAST_RIPEMD_JJJ(eee, aaa, bbb, ccc, ddd, X[ 8], 11); + BEAST_RIPEMD_JJJ(ddd, eee, aaa, bbb, ccc, X[ 1], 14); + BEAST_RIPEMD_JJJ(ccc, ddd, eee, aaa, bbb, X[10], 14); + BEAST_RIPEMD_JJJ(bbb, ccc, ddd, eee, aaa, X[ 3], 12); + BEAST_RIPEMD_JJJ(aaa, bbb, ccc, ddd, eee, X[12], 6); + + // parallel round 2 + BEAST_RIPEMD_III(eee, aaa, bbb, ccc, ddd, X[ 6], 9); + BEAST_RIPEMD_III(ddd, eee, aaa, bbb, ccc, X[11], 13); + BEAST_RIPEMD_III(ccc, ddd, eee, aaa, bbb, X[ 3], 15); + BEAST_RIPEMD_III(bbb, ccc, ddd, eee, aaa, X[ 7], 7); + BEAST_RIPEMD_III(aaa, bbb, ccc, ddd, eee, X[ 0], 12); + BEAST_RIPEMD_III(eee, aaa, bbb, ccc, ddd, X[13], 8); + BEAST_RIPEMD_III(ddd, eee, aaa, bbb, ccc, X[ 5], 9); + BEAST_RIPEMD_III(ccc, ddd, eee, aaa, bbb, X[10], 11); + BEAST_RIPEMD_III(bbb, ccc, ddd, eee, aaa, X[14], 7); + BEAST_RIPEMD_III(aaa, bbb, ccc, ddd, eee, X[15], 7); + BEAST_RIPEMD_III(eee, aaa, bbb, ccc, ddd, X[ 8], 12); + BEAST_RIPEMD_III(ddd, eee, aaa, bbb, ccc, X[12], 7); + BEAST_RIPEMD_III(ccc, ddd, eee, aaa, bbb, X[ 4], 6); + BEAST_RIPEMD_III(bbb, ccc, ddd, eee, aaa, X[ 9], 15); + BEAST_RIPEMD_III(aaa, bbb, ccc, ddd, eee, X[ 1], 13); + BEAST_RIPEMD_III(eee, aaa, bbb, ccc, ddd, X[ 2], 11); + + // parallel round 3 + BEAST_RIPEMD_HHH(ddd, eee, aaa, bbb, ccc, X[15], 9); + BEAST_RIPEMD_HHH(ccc, ddd, eee, aaa, bbb, X[ 5], 7); + BEAST_RIPEMD_HHH(bbb, ccc, ddd, eee, aaa, X[ 1], 15); + BEAST_RIPEMD_HHH(aaa, bbb, ccc, ddd, eee, X[ 3], 11); + BEAST_RIPEMD_HHH(eee, aaa, bbb, ccc, ddd, X[ 7], 8); + BEAST_RIPEMD_HHH(ddd, eee, aaa, bbb, ccc, X[14], 6); + BEAST_RIPEMD_HHH(ccc, ddd, eee, aaa, bbb, X[ 6], 6); + BEAST_RIPEMD_HHH(bbb, ccc, ddd, eee, aaa, X[ 9], 14); + BEAST_RIPEMD_HHH(aaa, bbb, ccc, ddd, eee, X[11], 12); + BEAST_RIPEMD_HHH(eee, aaa, bbb, ccc, ddd, X[ 8], 13); + BEAST_RIPEMD_HHH(ddd, eee, aaa, bbb, ccc, X[12], 5); + BEAST_RIPEMD_HHH(ccc, ddd, eee, aaa, bbb, X[ 2], 14); + BEAST_RIPEMD_HHH(bbb, ccc, ddd, eee, aaa, X[10], 13); + BEAST_RIPEMD_HHH(aaa, bbb, ccc, ddd, eee, X[ 0], 13); + BEAST_RIPEMD_HHH(eee, aaa, bbb, ccc, ddd, X[ 4], 7); + BEAST_RIPEMD_HHH(ddd, eee, aaa, bbb, ccc, X[13], 5); + + // parallel round 4 + BEAST_RIPEMD_GGG(ccc, ddd, eee, aaa, bbb, X[ 8], 15); + BEAST_RIPEMD_GGG(bbb, ccc, ddd, eee, aaa, X[ 6], 5); + BEAST_RIPEMD_GGG(aaa, bbb, ccc, ddd, eee, X[ 4], 8); + BEAST_RIPEMD_GGG(eee, aaa, bbb, ccc, ddd, X[ 1], 11); + BEAST_RIPEMD_GGG(ddd, eee, aaa, bbb, ccc, X[ 3], 14); + BEAST_RIPEMD_GGG(ccc, ddd, eee, aaa, bbb, X[11], 14); + BEAST_RIPEMD_GGG(bbb, ccc, ddd, eee, aaa, X[15], 6); + BEAST_RIPEMD_GGG(aaa, bbb, ccc, ddd, eee, X[ 0], 14); + BEAST_RIPEMD_GGG(eee, aaa, bbb, ccc, ddd, X[ 5], 6); + BEAST_RIPEMD_GGG(ddd, eee, aaa, bbb, ccc, X[12], 9); + BEAST_RIPEMD_GGG(ccc, ddd, eee, aaa, bbb, X[ 2], 12); + BEAST_RIPEMD_GGG(bbb, ccc, ddd, eee, aaa, X[13], 9); + BEAST_RIPEMD_GGG(aaa, bbb, ccc, ddd, eee, X[ 9], 12); + BEAST_RIPEMD_GGG(eee, aaa, bbb, ccc, ddd, X[ 7], 5); + BEAST_RIPEMD_GGG(ddd, eee, aaa, bbb, ccc, X[10], 15); + BEAST_RIPEMD_GGG(ccc, ddd, eee, aaa, bbb, X[14], 8); + + // parallel round 5 + BEAST_RIPEMD_FFF(bbb, ccc, ddd, eee, aaa, X[12] , 8); + BEAST_RIPEMD_FFF(aaa, bbb, ccc, ddd, eee, X[15] , 5); + BEAST_RIPEMD_FFF(eee, aaa, bbb, ccc, ddd, X[10] , 12); + BEAST_RIPEMD_FFF(ddd, eee, aaa, bbb, ccc, X[ 4] , 9); + BEAST_RIPEMD_FFF(ccc, ddd, eee, aaa, bbb, X[ 1] , 12); + BEAST_RIPEMD_FFF(bbb, ccc, ddd, eee, aaa, X[ 5] , 5); + BEAST_RIPEMD_FFF(aaa, bbb, ccc, ddd, eee, X[ 8] , 14); + BEAST_RIPEMD_FFF(eee, aaa, bbb, ccc, ddd, X[ 7] , 6); + BEAST_RIPEMD_FFF(ddd, eee, aaa, bbb, ccc, X[ 6] , 8); + BEAST_RIPEMD_FFF(ccc, ddd, eee, aaa, bbb, X[ 2] , 13); + BEAST_RIPEMD_FFF(bbb, ccc, ddd, eee, aaa, X[13] , 6); + BEAST_RIPEMD_FFF(aaa, bbb, ccc, ddd, eee, X[14] , 5); + BEAST_RIPEMD_FFF(eee, aaa, bbb, ccc, ddd, X[ 0] , 15); + BEAST_RIPEMD_FFF(ddd, eee, aaa, bbb, ccc, X[ 3] , 13); + BEAST_RIPEMD_FFF(ccc, ddd, eee, aaa, bbb, X[ 9] , 11); + BEAST_RIPEMD_FFF(bbb, ccc, ddd, eee, aaa, X[11] , 11); + + // combine results + ddd += cc + ctx.h[1]; // final result for h[0] + ctx.h[1] = ctx.h[2] + dd + eee; + ctx.h[2] = ctx.h[3] + ee + aaa; + ctx.h[3] = ctx.h[4] + aa + bbb; + ctx.h[4] = ctx.h[0] + bb + ccc; + ctx.h[0] = ddd; +} + +template +void init (ripemd160_context& ctx) noexcept +{ + ctx.len = 0; + ctx.tot_len = 0; + ctx.h[0] = 0x67452301UL; + ctx.h[1] = 0xefcdab89UL; + ctx.h[2] = 0x98badcfeUL; + ctx.h[3] = 0x10325476UL; + ctx.h[4] = 0xc3d2e1f0UL; +} + +template +void update (ripemd160_context& ctx, + void const* message, std::size_t size) noexcept +{ + auto const pm = reinterpret_cast< + unsigned char const*>(message); + unsigned int block_nb; + unsigned int new_len, rem_len, tmp_len; + const unsigned char *shifted_message; + tmp_len = ripemd160_context::block_size - ctx.len; + rem_len = size < tmp_len ? size : tmp_len; + std::memcpy(&ctx.block[ctx.len], pm, rem_len); + if (ctx.len + size < ripemd160_context::block_size) { + ctx.len += size; + return; + } + new_len = size - rem_len; + block_nb = new_len / ripemd160_context::block_size; + shifted_message = pm + rem_len; + std::array X; + ripemd_load(X, ctx.block); + ripemd_compress(ctx, X); + for (int i = 0; i < block_nb; ++i) + { + ripemd_load(X, shifted_message + + i * ripemd160_context::block_size); + ripemd_compress(ctx, X); + } + rem_len = new_len % ripemd160_context::block_size; + std::memcpy(ctx.block, &shifted_message[ + block_nb * ripemd160_context::block_size], + rem_len); + ctx.len = rem_len; + ctx.tot_len += (block_nb + 1) * + ripemd160_context::block_size; +} + +template +void finish (ripemd160_context& ctx, + void* digest) noexcept +{ + std::array X; + X.fill(0); + // put leftovers into X + auto p = &ctx.block[0]; + // uint8_t i goes into word X[i div 4] at pos. 8*(i mod 4) + for (int i = 0; i < ctx.len; ++i) + X[i >> 2] ^= (std::uint32_t) *p++ << (8 * (i & 3)); + ctx.tot_len += ctx.len; + // append the bit m_n == 1 + X[(ctx.tot_len>>2)&15] ^= + (uint32_t)1 << (8*(ctx.tot_len&3) + 7); + // length goes to next block? + if ((ctx.tot_len & 63) > 55) + { + ripemd_compress(ctx, X); + X.fill(0); + } + // append length in bits*/ + X[14] = ctx.tot_len << 3; + X[15] = (ctx.tot_len >> 29) | (0 << 3); + ripemd_compress(ctx, X); + + std::uint8_t* pd = reinterpret_cast< + std::uint8_t*>(digest); + for (std::uint32_t i = 0; i < 20; i += 4) + { + pd[i] = (std::uint8_t)(ctx.h[i>>2]); // implicit cast to uint8_t + pd[i+1] = (std::uint8_t)(ctx.h[i>>2] >> 8); // extracts the 8 least + pd[i+2] = (std::uint8_t)(ctx.h[i>>2] >> 16); // significant bits. + pd[i+3] = (std::uint8_t)(ctx.h[i>>2] >> 24); + } +} + +} // detail +} // beast + +#endif diff --git a/src/beast/beast/crypto/impl/sha512_context.h b/src/beast/beast/crypto/detail/sha2_context.h similarity index 59% rename from src/beast/beast/crypto/impl/sha512_context.h rename to src/beast/beast/crypto/detail/sha2_context.h index f5815932aa..1010349368 100644 --- a/src/beast/beast/crypto/impl/sha512_context.h +++ b/src/beast/beast/crypto/detail/sha2_context.h @@ -27,6 +27,10 @@ namespace beast { namespace detail { +// Based on https://github.com/ogay/sha2 +// This implementation has been modified from the +// original. It has been updated for C++11. + /* * Updated to C++, zedwood.com 2012 * Based on Olivier Gay's version @@ -64,6 +68,17 @@ namespace detail { * SUCH DAMAGE. */ +struct sha256_context +{ + static unsigned int const block_size = 64; + static unsigned int const digest_size = 32; + + unsigned int tot_len; + unsigned int len; + unsigned char block[2 * block_size]; + std::uint32_t h[8]; +}; + struct sha512_context { static unsigned int const block_size = 128; @@ -80,39 +95,184 @@ struct sha512_context #define BEAST_SHA2_ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) #define BEAST_SHA2_CH(x, y, z) ((x & y) ^ (~x & z)) #define BEAST_SHA2_MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) +#define BEAST_SHA256_F1(x) (BEAST_SHA2_ROTR(x, 2) ^ BEAST_SHA2_ROTR(x, 13) ^ BEAST_SHA2_ROTR(x, 22)) +#define BEAST_SHA256_F2(x) (BEAST_SHA2_ROTR(x, 6) ^ BEAST_SHA2_ROTR(x, 11) ^ BEAST_SHA2_ROTR(x, 25)) +#define BEAST_SHA256_F3(x) (BEAST_SHA2_ROTR(x, 7) ^ BEAST_SHA2_ROTR(x, 18) ^ BEAST_SHA2_SHFR(x, 3)) +#define BEAST_SHA256_F4(x) (BEAST_SHA2_ROTR(x, 17) ^ BEAST_SHA2_ROTR(x, 19) ^ BEAST_SHA2_SHFR(x, 10)) #define BEAST_SHA512_F1(x) (BEAST_SHA2_ROTR(x, 28) ^ BEAST_SHA2_ROTR(x, 34) ^ BEAST_SHA2_ROTR(x, 39)) #define BEAST_SHA512_F2(x) (BEAST_SHA2_ROTR(x, 14) ^ BEAST_SHA2_ROTR(x, 18) ^ BEAST_SHA2_ROTR(x, 41)) #define BEAST_SHA512_F3(x) (BEAST_SHA2_ROTR(x, 1) ^ BEAST_SHA2_ROTR(x, 8) ^ BEAST_SHA2_SHFR(x, 7)) #define BEAST_SHA512_F4(x) (BEAST_SHA2_ROTR(x, 19) ^ BEAST_SHA2_ROTR(x, 61) ^ BEAST_SHA2_SHFR(x, 6)) +#define BEAST_SHA2_PACK32(str, x) \ +{ \ + *(x) = \ + ((std::uint32_t) *((str) + 3) ) \ + | ((std::uint32_t) *((str) + 2) << 8) \ + | ((std::uint32_t) *((str) + 1) << 16) \ + | ((std::uint32_t) *((str) + 0) << 24); \ +} #define BEAST_SHA2_UNPACK32(x, str) \ { \ - *((str) + 3) = (std::uint8_t) ((x) ); \ - *((str) + 2) = (std::uint8_t) ((x) >> 8); \ - *((str) + 1) = (std::uint8_t) ((x) >> 16); \ - *((str) + 0) = (std::uint8_t) ((x) >> 24); \ -} -#define BEAST_SHA2_UNPACK64(x, str) \ -{ \ - *((str) + 7) = (std::uint8_t) ((x) ); \ - *((str) + 6) = (std::uint8_t) ((x) >> 8); \ - *((str) + 5) = (std::uint8_t) ((x) >> 16); \ - *((str) + 4) = (std::uint8_t) ((x) >> 24); \ - *((str) + 3) = (std::uint8_t) ((x) >> 32); \ - *((str) + 2) = (std::uint8_t) ((x) >> 40); \ - *((str) + 1) = (std::uint8_t) ((x) >> 48); \ - *((str) + 0) = (std::uint8_t) ((x) >> 56); \ + *((str) + 3) = (std::uint8_t) ((x) ); \ + *((str) + 2) = (std::uint8_t) ((x) >> 8); \ + *((str) + 1) = (std::uint8_t) ((x) >> 16); \ + *((str) + 0) = (std::uint8_t) ((x) >> 24); \ } #define BEAST_SHA2_PACK64(str, x) \ { \ - *(x) = ((std::uint64_t) *((str) + 7) ) \ - | ((std::uint64_t) *((str) + 6) << 8) \ - | ((std::uint64_t) *((str) + 5) << 16) \ - | ((std::uint64_t) *((str) + 4) << 24) \ - | ((std::uint64_t) *((str) + 3) << 32) \ - | ((std::uint64_t) *((str) + 2) << 40) \ - | ((std::uint64_t) *((str) + 1) << 48) \ - | ((std::uint64_t) *((str) + 0) << 56); \ + *(x) = \ + ((std::uint64_t) *((str) + 7) ) \ + | ((std::uint64_t) *((str) + 6) << 8) \ + | ((std::uint64_t) *((str) + 5) << 16) \ + | ((std::uint64_t) *((str) + 4) << 24) \ + | ((std::uint64_t) *((str) + 3) << 32) \ + | ((std::uint64_t) *((str) + 2) << 40) \ + | ((std::uint64_t) *((str) + 1) << 48) \ + | ((std::uint64_t) *((str) + 0) << 56); \ } +#define BEAST_SHA2_UNPACK64(x, str) \ +{ \ + *((str) + 7) = (std::uint8_t) ((x) ); \ + *((str) + 6) = (std::uint8_t) ((x) >> 8); \ + *((str) + 5) = (std::uint8_t) ((x) >> 16); \ + *((str) + 4) = (std::uint8_t) ((x) >> 24); \ + *((str) + 3) = (std::uint8_t) ((x) >> 32); \ + *((str) + 2) = (std::uint8_t) ((x) >> 40); \ + *((str) + 1) = (std::uint8_t) ((x) >> 48); \ + *((str) + 0) = (std::uint8_t) ((x) >> 56); \ +} + +//------------------------------------------------------------------------------ + +// SHA256 + +template +void sha256_transform (sha256_context& ctx, + unsigned char const* message, + unsigned int block_nb) noexcept +{ + static unsigned long long const K[64] = { + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, + 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, + 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, + 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, + 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 + }; + std::uint32_t w[64]; + std::uint32_t wv[8]; + std::uint32_t t1, t2; + unsigned char const* sub_block; + int i, j; + for (i = 0; i < (int) block_nb; i++) { + sub_block = message + (i << 6); + for (j = 0; j < 16; j++) + BEAST_SHA2_PACK32(&sub_block[j << 2], &w[j]); + for (j = 16; j < 64; j++) + w[j] = BEAST_SHA256_F4( + w[j - 2]) + w[j - 7] + + BEAST_SHA256_F3(w[j - 15]) + + w[j - 16]; + for (j = 0; j < 8; j++) + wv[j] = ctx.h[j]; + for (j = 0; j < 64; j++) { + t1 = wv[7] + BEAST_SHA256_F2(wv[4]) + + BEAST_SHA2_CH(wv[4], wv[5], wv[6]) + + K[j] + w[j]; + t2 = BEAST_SHA256_F1(wv[0]) + + BEAST_SHA2_MAJ(wv[0], wv[1], wv[2]); + wv[7] = wv[6]; + wv[6] = wv[5]; + wv[5] = wv[4]; + wv[4] = wv[3] + t1; + wv[3] = wv[2]; + wv[2] = wv[1]; + wv[1] = wv[0]; + wv[0] = t1 + t2; + } + for (j = 0; j < 8; j++) + ctx.h[j] += wv[j]; + } +} + +template +void init (sha256_context& ctx) noexcept +{ + ctx.len = 0; + ctx.tot_len = 0; + ctx.h[0] = 0x6a09e667; + ctx.h[1] = 0xbb67ae85; + ctx.h[2] = 0x3c6ef372; + ctx.h[3] = 0xa54ff53a; + ctx.h[4] = 0x510e527f; + ctx.h[5] = 0x9b05688c; + ctx.h[6] = 0x1f83d9ab; + ctx.h[7] = 0x5be0cd19; +} + +template +void update (sha256_context& ctx, + void const* message, std::size_t size) noexcept +{ + auto const pm = reinterpret_cast< + unsigned char const*>(message); + unsigned int block_nb; + unsigned int new_len, rem_len, tmp_len; + const unsigned char *shifted_message; + tmp_len = sha256_context::block_size - ctx.len; + rem_len = size < tmp_len ? size : tmp_len; + std::memcpy(&ctx.block[ctx.len], pm, rem_len); + if (ctx.len + size < sha256_context::block_size) { + ctx.len += size; + return; + } + new_len = size - rem_len; + block_nb = new_len / sha256_context::block_size; + shifted_message = pm + rem_len; + sha256_transform(ctx, ctx.block, 1); + sha256_transform(ctx, shifted_message, block_nb); + rem_len = new_len % sha256_context::block_size; + std::memcpy(ctx.block, &shifted_message[ + block_nb << 6], rem_len); + ctx.len = rem_len; + ctx.tot_len += (block_nb + 1) << 6; +} + +template +void finish (sha256_context& ctx, + void* digest) noexcept +{ + auto const pd = reinterpret_cast< + unsigned char*>(digest); + unsigned int block_nb; + unsigned int pm_len; + unsigned int len_b; + int i; + block_nb = (1 + ((sha256_context::block_size - 9) < + (ctx.len % sha256_context::block_size))); + len_b = (ctx.tot_len + ctx.len) << 3; + pm_len = block_nb << 6; + std::memset(ctx.block + ctx.len, 0, pm_len - ctx.len); + ctx.block[ctx.len] = 0x80; + BEAST_SHA2_UNPACK32(len_b, ctx.block + pm_len - 4); + sha256_transform(ctx, ctx.block, block_nb); + for (i = 0 ; i < 8; i++) + BEAST_SHA2_UNPACK32(ctx.h[i], &pd[i << 2]); +} + +//------------------------------------------------------------------------------ + +// SHA512 template void sha512_transform (sha512_context& ctx, @@ -183,8 +343,7 @@ void sha512_transform (sha512_context& ctx, BEAST_SHA2_CH(wv[4], wv[5], wv[6]) + K[j] + w[j]; t2 = BEAST_SHA512_F1(wv[0]) + - BEAST_SHA2_MAJ(wv[0], - wv[1], wv[2]); + BEAST_SHA2_MAJ(wv[0], wv[1], wv[2]); wv[7] = wv[6]; wv[6] = wv[5]; wv[5] = wv[4]; @@ -202,6 +361,8 @@ void sha512_transform (sha512_context& ctx, template void init (sha512_context& ctx) noexcept { + ctx.len = 0; + ctx.tot_len = 0; ctx.h[0] = 0x6a09e667f3bcc908ULL; ctx.h[1] = 0xbb67ae8584caa73bULL; ctx.h[2] = 0x3c6ef372fe94f82bULL; @@ -210,8 +371,6 @@ void init (sha512_context& ctx) noexcept ctx.h[5] = 0x9b05688c2b3e6c1fULL; ctx.h[6] = 0x1f83d9abfb41bd6bULL; ctx.h[7] = 0x5be0cd19137e2179ULL; - ctx.len = 0; - ctx.tot_len = 0; } template @@ -256,7 +415,7 @@ void finish (sha512_context& ctx, (ctx.len % sha512_context::block_size)); len_b = (ctx.tot_len + ctx.len) << 3; pm_len = block_nb << 7; - memset(ctx.block + ctx.len, 0, pm_len - ctx.len); + std::memset(ctx.block + ctx.len, 0, pm_len - ctx.len); ctx.block[ctx.len] = 0x80; BEAST_SHA2_UNPACK32(len_b, ctx.block + pm_len - 4); sha512_transform(ctx, ctx.block, block_nb); @@ -264,12 +423,6 @@ void finish (sha512_context& ctx, BEAST_SHA2_UNPACK64(ctx.h[i], &pd[i << 3]); } -template -void secure_erase (sha512_context& ctx) -{ - std::memset(ctx.block, 0, sizeof(ctx.block)); -} - } // detail } // beast diff --git a/src/beast/beast/crypto/ripemd.h b/src/beast/beast/crypto/ripemd.h new file mode 100644 index 0000000000..968ffecced --- /dev/null +++ b/src/beast/beast/crypto/ripemd.h @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_CRYPTO_RIPEMD_H_INCLUDED +#define BEAST_CRYPTO_RIPEMD_H_INCLUDED + +#include +#include + +namespace beast { + +using ripemd160_hasher = detail::mac_facade< + detail::ripemd160_context, false>; + +// secure version +using ripemd160_hasher_s = detail::mac_facade< + detail::ripemd160_context, true>; + +} + +#endif diff --git a/src/beast/beast/crypto/secure_erase.h b/src/beast/beast/crypto/secure_erase.h new file mode 100644 index 0000000000..48280108a7 --- /dev/null +++ b/src/beast/beast/crypto/secure_erase.h @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_CRYPTO_SECURE_ERASE_H_INCLUDED +#define BEAST_CRYPTO_SECURE_ERASE_H_INCLUDED + +#include +#include +#include + +namespace beast { + +namespace detail { + +class secure_erase_impl +{ +private: + struct base + { + virtual void operator()( + void* dest, std::size_t bytes) const = 0; + }; + + struct impl : base + { + void operator()( + void* dest, std::size_t bytes) const override + { + char volatile* volatile p = + const_cast( + reinterpret_cast(dest)); + if (bytes == 0) + return; + do + { + *p = 0; + } + while(*p++ == 0 && --bytes); + } + }; + + char buf_[sizeof(impl)]; + base& erase_; + +public: + secure_erase_impl() + : erase_(*new(buf_) impl) + { + } + + void operator()( + void* dest, std::size_t bytes) const + { + return erase_(dest, bytes); + } +}; + +} + +/** Guaranteed to fill memory with zeroes */ +template +void +secure_erase (void* dest, std::size_t bytes) +{ + static detail::secure_erase_impl const erase; + erase(dest, bytes); +} + +} + +#endif diff --git a/src/beast/beast/crypto/sha2.h b/src/beast/beast/crypto/sha2.h new file mode 100644 index 0000000000..203b5c3cfe --- /dev/null +++ b/src/beast/beast/crypto/sha2.h @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_CRYPTO_SHA2_H_INCLUDED +#define BEAST_CRYPTO_SHA2_H_INCLUDED + +#include +#include + +namespace beast { + +using sha256_hasher = detail::mac_facade< + detail::sha256_context, false>; + +// secure version +using sha256_hasher_s = detail::mac_facade< + detail::sha256_context, true>; + +using sha512_hasher = detail::mac_facade< + detail::sha512_context, false>; + +// secure version +using sha512_hasher_s = detail::mac_facade< + detail::sha512_context, true>; + +} + +#endif diff --git a/src/ripple/basics/SHA512Half.h b/src/ripple/basics/SHA512Half.h index affeb21547..ae282b938a 100644 --- a/src/ripple/basics/SHA512Half.h +++ b/src/ripple/basics/SHA512Half.h @@ -22,7 +22,7 @@ #include #include // needed by most callers -#include +#include #include #include //