diff --git a/cryptoTools/Common/Timer.cpp b/cryptoTools/Common/Timer.cpp index a08cd6c..68750d9 100644 --- a/cryptoTools/Common/Timer.cpp +++ b/cryptoTools/Common/Timer.cpp @@ -10,8 +10,18 @@ namespace osuCrypto { const Timer::timeUnit& Timer::setTimePoint(const std::string& msg) { - mTimes.push_back(std::make_pair(timeUnit::clock::now(), msg)); - return mTimes.back().first; + if (mLocking) + { + std::lock_guard lock(mMtx); + mTimes.push_back(std::make_pair(timeUnit::clock::now(), msg)); + return mTimes.back().first; + } + else + { + mTimes.push_back(std::make_pair(timeUnit::clock::now(), msg)); + return mTimes.back().first; + + } } void Timer::reset() diff --git a/cryptoTools/Crypto/PRNG.h b/cryptoTools/Crypto/PRNG.h index e0fbd44..dc9e318 100644 --- a/cryptoTools/Crypto/PRNG.h +++ b/cryptoTools/Crypto/PRNG.h @@ -40,12 +40,26 @@ namespace osuCrypto const block getSeed() const; - struct AnyPOD + //template + //struct has_randomize_member_func : std::false_type + //{}; + + //template + //struct has_randomize_member_func < T, std::void_t< + + // // must have a randomize(PRNG&) member fn + // decltype(std::declval().randomize(std::declval())) + + // >> + // : std::true_type{}; + + + struct Any { PRNG& mPrng; template::value&& + std::is_standard_layout::value && std::is_trivial::value, T>::type> operator T() { @@ -54,7 +68,7 @@ namespace osuCrypto }; - AnyPOD get() + Any get() { return { *this }; } @@ -80,6 +94,7 @@ namespace osuCrypto return ret; } + // Templated function that fills the provided buffer // with random elements of the given type T. // Required: T must be a POD type. @@ -181,13 +196,4 @@ namespace osuCrypto return ret & 1; } - - template - typename std::enable_if< - std::is_standard_layout::value&& - std::is_trivial::value, PRNG&>::type operator<<(T& rhs, PRNG& lhs) - { - lhs.get(&rhs, 1); - } - }