Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Support for CentOS7 #18

Merged
merged 1 commit into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ if (UNIX)
string(APPEND COMPILER_FLAGS " -D__RTP_NO_CRYPTO__")
endif(DISABLE_CRYPTO)

# Check the getrandom() function exists
include(CheckCXXSymbolExists)
check_cxx_symbol_exists(getrandom sys/random.h HAVE_GETRANDOM)

if(HAVE_GETRANDOM)
add_compile_definitions(HAVE_GETRANDOM=1)
endif()

# if (NOT "${LIBRARY_PATHS}" STREQUAL "")
# add_custom_command(TARGET uvgrtp POST_BUILD
# COMMAND ar crsT ARGS libuvgrtp_thin.a libuvgrtp.a ${LIBRARY_PATHS}
Expand Down
17 changes: 17 additions & 0 deletions include/crypto.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#if __cplusplus >= 201703L
#if __has_include(<cryptopp/aes.h>) && \
__has_include(<cryptopp/base32.h>) && \
__has_include(<cryptopp/cryptlib.h>) && \
Expand All @@ -24,6 +25,22 @@
#include <cryptopp/crc.h>

#endif
#else // __cplusplus
#ifndef __RTP_NO_CRYPTO__
#define __RTP_CRYPTO__

#include <cryptopp/aes.h>
#include <cryptopp/base32.h>
#include <cryptopp/cryptlib.h>
#include <cryptopp/dh.h>
#include <cryptopp/hmac.h>
#include <cryptopp/modes.h>
#include <cryptopp/osrng.h>
#include <cryptopp/sha.h>
#include <cryptopp/crc.h>

#endif
#endif // __cplusplus

namespace uvgrtp {

Expand Down
30 changes: 27 additions & 3 deletions src/random.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
#include <winsock2.h>
#include <windows.h>
#include <wincrypt.h>
#else
#else // _WIN32
#ifdef HAVE_GETRANDOM
#include <sys/random.h>
#endif
#else // HAVE_GETRANDOM
#include <unistd.h>
#include <sys/syscall.h>
#endif // HAVE_GETRANDOM
#endif // _WIN32

#include <cstdlib>
#include <ctime>
Expand All @@ -25,8 +30,27 @@ rtp_error_t uvgrtp::random::init()
int uvgrtp::random::generate(void *buf, size_t n)
{
#ifdef __linux__
#ifdef HAVE_GETRANDOM
return getrandom(buf, n, 0);
#else
#else // HAVE_GETRANDOM

// Replace with the syscall
int read = syscall(SYS_getrandom, buf, n, 0);

// On error, return the same value as getrandom()
if (read == -EINTR || read == -ERESTART) {
errno = EINTR;
read = -1;
}

if (read < -1) {
errno = -read;
read = -1;
}

return read;
#endif // HAVE_GETRANDOM
#else // __linux__
HCRYPTPROV hCryptProv;
if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0) == TRUE) {
bool res = CryptGenRandom(hCryptProv, n, (BYTE *)buf);
Expand Down