Skip to content

Commit

Permalink
cpp 20 update
Browse files Browse the repository at this point in the history
  • Loading branch information
ladnir committed Apr 29, 2024
1 parent 0d5cb49 commit a604c4f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 33 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ if(NOT ENABLE_SSE AND ENABLE_AVX)
set(ENABLE_AVX OFF)
endif()


option(FETCH_AUTO "automatically download and build dependencies" OFF)

#option(FETCH_SPAN_LITE "download and build span" OFF))
EVAL(FETCH_SPAN_LITE_IMPL
(DEFINED FETCH_SPAN_LITE AND FETCH_SPAN_LITE) OR
((NOT DEFINED FETCH_SPAN_LITE) AND (FETCH_AUTO AND ENABLE_SPAN_LITE)))

if(CRYPTO_TOOLS_STD_VER EQUAL 14 OR CRYPTO_TOOLS_STD_VER EQUAL 17)
set(ENABLE_SPAN_LITE ON)
else()
set(ENABLE_SPAN_LITE OFF)
set(FETCH_SPAN_LITE_IMPL OFF)
endif()

#option(FETCH_SPAN_LITE "download and build span" OFF))
EVAL(FETCH_GMP_IMPL
(DEFINED FETCH_GMP AND FETCH_GMP) OR
Expand Down
5 changes: 3 additions & 2 deletions cmake/cryptoToolsDepHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ if (FETCH_SPAN_LITE_IMPL)
include("${CMAKE_CURRENT_LIST_DIR}/../thirdparty/getSpanLite.cmake")
endif()

FIND_SPAN(REQUIRED)

if(ENABLE_SPAN_LITE)
FIND_SPAN(REQUIRED)
endif()
## GMP
###########################################################################

Expand Down
6 changes: 4 additions & 2 deletions cryptoTools/Common/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ namespace osuCrypto

template<typename T,
typename Enable = typename std::enable_if<
std::is_pod<T>::value &&
std::is_standard_layout<T>::value&&
std::is_trivial<T>::value &&
(sizeof(T) <= 16) &&
(16 % sizeof(T) == 0)
>::type>
Expand Down Expand Up @@ -176,7 +177,8 @@ namespace osuCrypto
// For integer types, this will be specialized with SSE futher down.
template<typename T>
OC_FORCEINLINE static typename std::enable_if<
std::is_pod<T>::value &&
std::is_standard_layout<T>::value&&
std::is_trivial<T>::value &&
(sizeof(T) <= 16) &&
(16 % sizeof(T) == 0),
block>::type allSame(T val)
Expand Down
12 changes: 10 additions & 2 deletions cryptoTools/Crypto/Blake2.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ namespace osuCrypto {

// Add length bytes pointed to by dataIn to the internal Blake2 state.
template<typename T>
typename std::enable_if<std::is_pod<T>::value>::type Update(const T* dataIn, u64 length)
typename std::enable_if<
std::is_standard_layout<T>::value&&
std::is_trivial<T>::value
>::type Update(const T* dataIn, u64 length)
{
blake2b_update(&state, dataIn, length * sizeof(T));
}
Expand All @@ -77,7 +80,12 @@ namespace osuCrypto {
// Finalize the Blake2 hash and output the result to out.
// Only sizeof(T) bytes of the output are written.
template<typename T>
typename std::enable_if<std::is_pod<T>::value && sizeof(T) <= MaxHashSize && std::is_pointer<T>::value == false>::type
typename std::enable_if<
std::is_standard_layout<T>::value&&
std::is_trivial<T>::value &&
sizeof(T) <= MaxHashSize &&
std::is_pointer<T>::value == false
>::type
Final(T& out)
{
if (sizeof(T) != outputLength())
Expand Down
6 changes: 5 additions & 1 deletion cryptoTools/Crypto/Hashable.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ namespace osuCrypto {
struct Hashable : std::false_type {};

template<typename T>
struct Hashable<T, typename std::enable_if<std::is_pod<T>::value>::type> : std::true_type
struct Hashable<T,
typename std::enable_if<
std::is_standard_layout<T>::value&&
std::is_trivial<T>::value>::type
> : std::true_type
{
template<typename Hasher>
static void hash(const T& t, Hasher& hasher)
Expand Down
44 changes: 22 additions & 22 deletions cryptoTools/Network/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ namespace osuCrypto {
// Sends length number of T pointed to by src over the network. The type T
// must be POD. Returns once all the data has been sent.
template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
send(const T* src, u64 length);

// Sends the data in buf over the network. The type Container must meet the
// requirements defined in IoBuffer.h. Returns once all the data has been sent.
template <class T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
send(const T& buf);

// Sends the data in buf over the network. The type Container must meet the
Expand All @@ -80,7 +80,7 @@ namespace osuCrypto {
// Returns before the data has been sent. The life time of the data must be
// managed externally to ensure it lives longer than the async operations.
template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
asyncSend(const T* data, u64 length);

// Sends the data in buf over the network. The type Container must meet the
Expand All @@ -107,7 +107,7 @@ namespace osuCrypto {
// Returns before the data has been sent. The life time of the data must be
// managed externally to ensure it lives longer than the async operations.
template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
asyncSend(const T& data);

// Sends the data in buf over the network. The type T must be POD.
Expand Down Expand Up @@ -140,20 +140,20 @@ namespace osuCrypto {
// Returns before the data has been sent. The life time of the data must be
// managed externally to ensure it lives longer than the async operations.
template<typename T>
typename std::enable_if<std::is_pod<T>::value, std::future<void>>::type
typename std::enable_if<std::is_trivial<T>::value, std::future<void>>::type
asyncSendFuture(const T* data, u64 length);


// Performs a data copy and then sends the data in buf over the network.
// The type T must be POD. Returns before the data has been sent.
template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
asyncSendCopy(const T& buff);

// Performs a data copy and then sends the data in buf over the network.
// The type T must be POD. Returns before the data has been sent.
template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
asyncSendCopy(const T* bufferPtr, u64 length);

// Performs a data copy and then sends the data in buf over the network.
Expand Down Expand Up @@ -193,34 +193,34 @@ namespace osuCrypto {
// Receive data over the network. The function returns once all the data
// has been received.
template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
recv(T* dest, u64 length);

// Receive data over the network. The function returns once all the data
// has been received.
template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
recv(T& dest) { recv(&dest, 1); }

// Receive data over the network asynchronously. The function returns right away,
// before the data has been received. When all the data has benn received the
// future is set.
template<typename T>
typename std::enable_if<std::is_pod<T>::value, std::future<void>>::type
typename std::enable_if<std::is_trivial<T>::value, std::future<void>>::type
asyncRecv(T* dest, u64 length);

// Receive data over the network asynchronously. The function returns right away,
// before the data has been received. When all the data has benn received the
// future is set and the callback fn is called.
template<typename T>
typename std::enable_if<std::is_pod<T>::value, std::future<void>>::type
typename std::enable_if<std::is_trivial<T>::value, std::future<void>>::type
asyncRecv(T* dest, u64 length, std::function<void()> fn);

// Receive data over the network asynchronously. The function returns right away,
// before the data has been received. When all the data has benn received the
// future is set.
template<typename T>
typename std::enable_if<std::is_pod<T>::value, std::future<void>>::type
typename std::enable_if<std::is_trivial<T>::value, std::future<void>>::type
asyncRecv(T& dest) { return asyncRecv(&dest, 1); }

// Receive data over the network asynchronously. The function returns right away,
Expand Down Expand Up @@ -759,15 +759,15 @@ namespace osuCrypto {


template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
Channel::send(const T* buffT, u64 sizeT)
{
asyncSendFuture(buffT, sizeT).get();
}


template<typename T>
typename std::enable_if<std::is_pod<T>::value, std::future<void>>::type
typename std::enable_if<std::is_trivial<T>::value, std::future<void>>::type
Channel::asyncSendFuture(const T* buffT, u64 sizeT)
{
u8* buff = (u8*)buffT;
Expand Down Expand Up @@ -796,14 +796,14 @@ namespace osuCrypto {


template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
Channel::send(const T& buffT)
{
send(&buffT, 1);
}

template<typename T>
typename std::enable_if<std::is_pod<T>::value, std::future<void>>::type
typename std::enable_if<std::is_trivial<T>::value, std::future<void>>::type
Channel::asyncRecv(T* buffT, u64 sizeT)
{
u8* buff = (u8*)buffT;
Expand All @@ -830,7 +830,7 @@ namespace osuCrypto {
}

template<typename T>
typename std::enable_if<std::is_pod<T>::value, std::future<void>>::type
typename std::enable_if<std::is_trivial<T>::value, std::future<void>>::type
Channel::asyncRecv(T* buffT, u64 sizeT, std::function<void()> fn)
{
u8* buff = (u8*)buffT;
Expand Down Expand Up @@ -858,7 +858,7 @@ namespace osuCrypto {
}

template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
Channel::asyncSend(const T* buffT, u64 sizeT)
{
u8* buff = (u8*)buffT;
Expand All @@ -880,7 +880,7 @@ namespace osuCrypto {


template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
Channel::asyncSend(const T& v)
{
asyncSend(&v, 1);
Expand Down Expand Up @@ -938,14 +938,14 @@ namespace osuCrypto {


template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
Channel::recv(T* buff, u64 size)
{
asyncRecv(buff, size).get();
}

template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
Channel::asyncSendCopy(const T* bufferPtr, u64 length)
{
std::vector<u8> bs((u8*)bufferPtr, (u8*)bufferPtr + length * sizeof(T));
Expand All @@ -954,7 +954,7 @@ namespace osuCrypto {


template<typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
typename std::enable_if<std::is_trivial<T>::value, void>::type
Channel::asyncSendCopy(const T& buf)
{
asyncSendCopy(&buf, 1);
Expand Down
6 changes: 4 additions & 2 deletions cryptoTools/Network/IoBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ namespace osuCrypto

#define _SILENCE_CXX20_IS_POD_DEPRECATION_WARNING



/// type trait that defines what is considered a STL like Container
///
/// Must have the following member types: pointer, size_type, value_type
Expand All @@ -127,8 +129,8 @@ namespace osuCrypto
std::is_convertible<
typename Container::size_type,
decltype(std::declval<Container>().size())>::value&&
std::is_pod<typename Container::value_type>::value&&
std::is_pod<Container>::value == false>::type
std::is_trivial<typename Container::value_type>::value&&
std::is_trivial<Container>::value == false>::type
,
void>;

Expand Down
4 changes: 2 additions & 2 deletions thirdparty/getCoproto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(USER_NAME )
set(TOKEN )
set(GIT_REPOSITORY "https://github.com/Visa-Research/coproto.git")
set(GIT_TAG "fd097b1f2498b73140dd6e2e3d0ee5c5e3c60cd2" )
set(GIT_TAG "22c98abba47dbfacd421e3dcd90702fff74de6f3" )

set(CLONE_DIR "${OC_THIRDPARTY_CLONE_DIR}/coproto")
set(BUILD_DIR "${CLONE_DIR}/out/build/${OC_CONFIG}")
Expand All @@ -25,7 +25,7 @@ if(NOT coproto_FOUND)
-DCOPROTO_NO_SYSTEM_PATH=${NO_SYSTEM_PATH}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DVERBOSE_FETCH=true
-DCOPROTO_FETCH_SPAN=ON
-DCOPROTO_FETCH_SPAN=OFF
-DCOPROTO_FETCH_FUNCTION2=ON
-DCOPROTO_FETCH_MACORO=ON
-DCOPROTO_FETCH_BOOST=${LOCAL_COPROTO_FETCH_BOOST}
Expand Down

0 comments on commit a604c4f

Please sign in to comment.