Skip to content

Commit

Permalink
add MSDOS via DJGPP support
Browse files Browse the repository at this point in the history
  • Loading branch information
Neo-Desktop committed Feb 21, 2024
1 parent 843d74c commit 715ebca
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
4 changes: 3 additions & 1 deletion config_align.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@
// IBM XL C/C++ alignment modifier per Optimization Guide, pp. 19-20.
// __IBM_ATTRIBUTES per XLC 12.1 AIX Compiler Manual, p. 473.
// CRYPTOPP_ALIGN_DATA may not be reliable on AIX.
#if defined(CRYPTOPP_CXX11_ALIGNAS)
#if defined(CRYPTOPP_CXX11_ALIGNAS) && !defined(__DJGPP__)
#define CRYPTOPP_ALIGN_DATA(x) alignas(x)
#elif defined(__DJGPP__)
#define CRYPTOPP_ALIGN_DATA(x)
#elif defined(CRYPTOPP_MSC_VERSION)
#define CRYPTOPP_ALIGN_DATA(x) __declspec(align(x))
#elif defined(__GNUC__) || defined(__clang__) || (__SUNPRO_CC >= 0x5100)
Expand Down
5 changes: 5 additions & 0 deletions config_asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
# define CRYPTOPP_DISABLE_ASM 1
#endif

// DJGPP is designed to support legacy intel processors, SSE2 is certainly not available
#if defined(__DJGPP__)
# define CRYPTOPP_DISABLE_ASM 1
#endif

// Sun Studio 12.1 provides GCC inline assembly
// http://blogs.oracle.com/x86be/entry/gcc_style_asm_inlining_support
#if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5100)
Expand Down
9 changes: 7 additions & 2 deletions config_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
#define CRYPTOPP_BSD_AVAILABLE
#endif

// MSDOS via DJGPP
#if defined(__DJGPP__)
#define CRYPTOPP_DJGPP_AVAILABLE
#endif

// Microsoft compilers
#if defined(CRYPTOPP_MSC_VERSION) || defined(__fastcall)
#define CRYPTOPP_FASTCALL __fastcall
Expand Down Expand Up @@ -121,7 +126,7 @@
# endif
#endif // CRYPTOPP_INIT_PRIORITY, NO_OS_DEPENDENCE, Apple, Sun

#if defined(CRYPTOPP_WIN32_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE)
#if defined(CRYPTOPP_WIN32_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE) || defined(CRYPTOPP_DJGPP_AVAILABLE)
# define HIGHRES_TIMER_AVAILABLE
#endif

Expand All @@ -135,7 +140,7 @@
# endif
#endif

#if defined(CRYPTOPP_UNIX_AVAILABLE) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
#if defined(CRYPTOPP_UNIX_AVAILABLE) || defined(CRYPTOPP_DOXYGEN_PROCESSING) || defined(CRYPTOPP_DJGPP_AVAILABLE)
# define NONBLOCKING_RNG_AVAILABLE
# define BLOCKING_RNG_AVAILABLE
# define OS_RNG_AVAILABLE
Expand Down
8 changes: 8 additions & 0 deletions hrtimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ TimerWord Timer::GetCurrentTimerValue()
timeval now;
gettimeofday(&now, NULLPTR);
return (TimerWord)now.tv_sec * 1000000 + now.tv_usec;
#elif defined(CRYPTOPP_DJGPP_AVAILABLE)
return uclock();
#else
// clock_t now;
return clock();
Expand All @@ -111,6 +113,8 @@ TimerWord Timer::TicksPerSecond()
return PerformanceCounterFrequency();
#elif defined(CRYPTOPP_UNIX_AVAILABLE)
return 1000000;
#elif defined(CRYPTOPP_DJGPP_AVAILABLE)
return UCLOCKS_PER_SEC;
#else
return CLOCKS_PER_SEC;
#endif
Expand Down Expand Up @@ -151,6 +155,8 @@ TimerWord ThreadUserTimer::GetCurrentTimerValue()
tms now;
times(&now);
return now.tms_utime;
#elif defined(CRYPTOPP_DJGPP_AVAILABLE)
return uclock();
#else
return clock();
#endif
Expand All @@ -166,6 +172,8 @@ TimerWord ThreadUserTimer::TicksPerSecond()
#elif defined(CRYPTOPP_UNIX_AVAILABLE)
static const long ticksPerSecond = sysconf(_SC_CLK_TCK);
return ticksPerSecond;
#elif defined(CRYPTOPP_DJGPP_AVAILABLE)
return UCLOCKS_PER_SEC;
#else
return CLOCKS_PER_SEC;
#endif
Expand Down
14 changes: 12 additions & 2 deletions osrng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,17 @@ NonblockingRng::NonblockingRng()
const int flags = O_RDONLY;
# endif

m_fd = open("/dev/urandom", flags);
# ifndef CRYPTOPP_NONBLOCKING_RNG_FILENAME
# if !defined(CRYPTOPP_DJGPP_AVAILABLE)
# define CRYPTOPP_NONBLOCKING_RNG_FILENAME "/dev/urandom"
# else
# define CRYPTOPP_NONBLOCKING_RNG_FILENAME "/dev/urandom\x24"
# endif
# endif

m_fd = open(CRYPTOPP_NONBLOCKING_RNG_FILENAME, flags);
if (m_fd == -1)
throw OS_RNG_Err("open /dev/urandom");
throw OS_RNG_Err("open " CRYPTOPP_NONBLOCKING_RNG_FILENAME);

#endif
}
Expand Down Expand Up @@ -250,6 +258,8 @@ void NonblockingRng::GenerateBlock(byte *output, size_t size)
#ifndef CRYPTOPP_BLOCKING_RNG_FILENAME
# ifdef __OpenBSD__
# define CRYPTOPP_BLOCKING_RNG_FILENAME "/dev/srandom"
# elif defined(CRYPTOPP_DJGPP_AVAILABLE)
# define CRYPTOPP_BLOCKING_RNG_FILENAME "/dev/random\x24"
# else
# define CRYPTOPP_BLOCKING_RNG_FILENAME "/dev/random"
# endif
Expand Down

0 comments on commit 715ebca

Please sign in to comment.