Skip to content

Commit

Permalink
Use unsigned types with UnsignedMin
Browse files Browse the repository at this point in the history
  • Loading branch information
noloader committed Jun 23, 2023
1 parent 0b04c12 commit 12c6a90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ida.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ size_t SecretSharing::Put2(const byte *begin, size_t length, int messageEnd, boo
if (!blocking)
throw BlockingInputOnly("SecretSharing");

SecByteBlock buf(UnsignedMin(256, length));
SecByteBlock buf(UnsignedMin(256u, length));
unsigned int threshold = m_ida.GetThreshold();
while (length > 0)
{
Expand Down
10 changes: 10 additions & 0 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "stdcpp.h"
#include "trap.h"

#if defined(CRYPTOPP_CXX11)
# include <type_traits>
#endif

#if !defined(CRYPTOPP_DOXYGEN_PROCESSING)

#if (CRYPTOPP_MSC_VERSION)
Expand Down Expand Up @@ -695,6 +699,12 @@ template <class T> inline const T& STDMAX(const T& a, const T& b)
template <class T1, class T2> inline const T1 UnsignedMin(const T1& a, const T2& b)
{
CRYPTOPP_COMPILE_ASSERT((sizeof(T1)<=sizeof(T2) && T2(-1)>0) || (sizeof(T1)>sizeof(T2) && T1(-1)>0));

#if defined(CRYPTOPP_CXX11)
CRYPTOPP_COMPILE_ASSERT(std::is_unsigned_v<T1> == true);
CRYPTOPP_COMPILE_ASSERT(std::is_unsigned_v<T2> == true);
#endif

if (sizeof(T1)<=sizeof(T2))
return b < (T2)a ? (T1)b : a;
else
Expand Down
2 changes: 1 addition & 1 deletion randpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void RandomPool::GenerateIntoBufferedTransformation(BufferedTransformation &targ
do
{
m_pCipher->ProcessBlock(m_seed);
size_t len = UnsignedMin(16, size);
size_t len = UnsignedMin(16u, size);
target.ChannelPut(channel, m_seed, len);
size -= len;
} while (size > 0);
Expand Down

0 comments on commit 12c6a90

Please sign in to comment.