Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ladnir/cryptotools
Browse files Browse the repository at this point in the history
  • Loading branch information
ladnir committed Jan 31, 2024
2 parents 2e0f348 + 139f4bd commit 1ffddc5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
14 changes: 12 additions & 2 deletions cryptoTools/Common/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> 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()
Expand Down
30 changes: 18 additions & 12 deletions cryptoTools/Crypto/PRNG.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,26 @@ namespace osuCrypto
const block getSeed() const;


struct AnyPOD
//template<typename T, typename = void>
//struct has_randomize_member_func : std::false_type
//{};

//template <typename T>
//struct has_randomize_member_func < T, std::void_t<

// // must have a randomize(PRNG&) member fn
// decltype(std::declval<T>().randomize(std::declval<PRNG&>()))

// >>
// : std::true_type{};


struct Any
{
PRNG& mPrng;

template<typename T, typename U = typename std::enable_if<
std::is_standard_layout<T>::value&&
std::is_standard_layout<T>::value &&
std::is_trivial<T>::value, T>::type>
operator T()
{
Expand All @@ -54,7 +68,7 @@ namespace osuCrypto

};

AnyPOD get()
Any get()
{
return { *this };
}
Expand All @@ -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.
Expand Down Expand Up @@ -181,13 +196,4 @@ namespace osuCrypto
return ret & 1;
}


template<typename T>
typename std::enable_if<
std::is_standard_layout<T>::value&&
std::is_trivial<T>::value, PRNG&>::type operator<<(T& rhs, PRNG& lhs)
{
lhs.get(&rhs, 1);
}

}

0 comments on commit 1ffddc5

Please sign in to comment.