Use unsigned types with UnsignedMin

This commit is contained in:
Jeffrey Walton 2023-06-23 16:51:05 -04:00
parent 0b04c12cbe
commit 12c6a9032b
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
3 changed files with 12 additions and 2 deletions

View File

@ -250,7 +250,7 @@ size_t SecretSharing::Put2(const byte *begin, size_t length, int messageEnd, boo
if (!blocking) if (!blocking)
throw BlockingInputOnly("SecretSharing"); throw BlockingInputOnly("SecretSharing");
SecByteBlock buf(UnsignedMin(256, length)); SecByteBlock buf(UnsignedMin(256u, length));
unsigned int threshold = m_ida.GetThreshold(); unsigned int threshold = m_ida.GetThreshold();
while (length > 0) while (length > 0)
{ {

10
misc.h
View File

@ -14,6 +14,10 @@
#include "stdcpp.h" #include "stdcpp.h"
#include "trap.h" #include "trap.h"
#if defined(CRYPTOPP_CXX11)
# include <type_traits>
#endif
#if !defined(CRYPTOPP_DOXYGEN_PROCESSING) #if !defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if (CRYPTOPP_MSC_VERSION) #if (CRYPTOPP_MSC_VERSION)
@ -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) 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)); 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)) if (sizeof(T1)<=sizeof(T2))
return b < (T2)a ? (T1)b : a; return b < (T2)a ? (T1)b : a;
else else

View File

@ -68,7 +68,7 @@ void RandomPool::GenerateIntoBufferedTransformation(BufferedTransformation &targ
do do
{ {
m_pCipher->ProcessBlock(m_seed); m_pCipher->ProcessBlock(m_seed);
size_t len = UnsignedMin(16, size); size_t len = UnsignedMin(16u, size);
target.ChannelPut(channel, m_seed, len); target.ChannelPut(channel, m_seed, len);
size -= len; size -= len;
} while (size > 0); } while (size > 0);