diff --git a/Filelist.txt b/Filelist.txt
index 6b0ffe3d..678291f8 100644
--- a/Filelist.txt
+++ b/Filelist.txt
@@ -202,8 +202,6 @@ naclite.h
nbtheory.cpp
nbtheory.h
neon-simd.cpp
-network.cpp
-network.h
nr.h
oaep.cpp
oaep.h
@@ -311,8 +309,6 @@ sm4.cpp
sm4-simd.cpp
sm4.h
smartptr.h
-socketft.cpp
-socketft.h
sosemanuk.cpp
sosemanuk.h
speck.cpp
@@ -336,8 +332,6 @@ threefish.h
tiger.cpp
tiger.h
tigertab.cpp
-trdlocal.cpp
-trdlocal.h
trunhash.h
ttmac.cpp
ttmac.h
@@ -360,14 +354,10 @@ validate.h
vmac.cpp
vmac.h
vs2005.zip
-wait.cpp
-wait.h
wake.cpp
wake.h
whrlpool.cpp
whrlpool.h
-winpipes.cpp
-winpipes.h
words.h
x64dll.asm
x64masm.asm
diff --git a/config.h b/config.h
index 57f1515d..c7d1ca3b 100644
--- a/config.h
+++ b/config.h
@@ -142,15 +142,6 @@
// see http://github.com/weidai11/cryptopp/issues/389.
// #define CRYPTOPP_NO_ASSIGN_TO_INTEGER
-// choose which style of sockets to wrap (mostly useful for MinGW which has both)
-#if !defined(NO_BERKELEY_STYLE_SOCKETS) && !defined(PREFER_BERKELEY_STYLE_SOCKETS)
-# define PREFER_BERKELEY_STYLE_SOCKETS
-#endif
-
-// #if !defined(NO_WINDOWS_STYLE_SOCKETS) && !defined(PREFER_WINDOWS_STYLE_SOCKETS)
-// # define PREFER_WINDOWS_STYLE_SOCKETS
-// #endif
-
// set the name of Rijndael cipher, was "Rijndael" before version 5.3
#define CRYPTOPP_RIJNDAEL_NAME "AES"
@@ -219,10 +210,6 @@ namespace CryptoPP { }
# endif
#endif
-#if defined(__CYGWIN__) && defined(PREFER_WINDOWS_STYLE_SOCKETS)
-# define __USE_W32_SOCKETS
-#endif
-
// Originally in global namespace to avoid ambiguity with other byte typedefs.
// Moved to Crypto++ namespace due to C++17, std::byte and potential compile problems. Also see
// http://www.cryptopp.com/wiki/std::byte and http://github.com/weidai11/cryptopp/issues/442
@@ -912,46 +899,10 @@ NAMESPACE_END
# endif
#endif
-#ifdef CRYPTOPP_UNIX_AVAILABLE
-# define HAS_BERKELEY_STYLE_SOCKETS
-# define SOCKETS_AVAILABLE
-#endif
-
-// Sockets are only available under Windows Runtime desktop partition apps (despite the MSDN literature)
-#ifdef CRYPTOPP_WIN32_AVAILABLE
-# define HAS_WINDOWS_STYLE_SOCKETS
-# if !defined(WINAPI_FAMILY)
-# define SOCKETS_AVAILABLE
-# elif defined(WINAPI_FAMILY)
-# if (WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
-# define SOCKETS_AVAILABLE
-# endif
-# endif
-#endif
-
-#if defined(HAS_WINDOWS_STYLE_SOCKETS) && (!defined(HAS_BERKELEY_STYLE_SOCKETS) || defined(PREFER_WINDOWS_STYLE_SOCKETS))
-# define USE_WINDOWS_STYLE_SOCKETS
-#else
-# define USE_BERKELEY_STYLE_SOCKETS
-#endif
-
-#if defined(CRYPTOPP_WIN32_AVAILABLE) && defined(SOCKETS_AVAILABLE) && !defined(USE_BERKELEY_STYLE_SOCKETS)
-# define WINDOWS_PIPES_AVAILABLE
-#endif
-
-
#if defined(CRYPTOPP_UNIX_AVAILABLE) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
# define NONBLOCKING_RNG_AVAILABLE
# define BLOCKING_RNG_AVAILABLE
# define OS_RNG_AVAILABLE
-# define HAS_PTHREADS
-# define THREADS_AVAILABLE
-#endif
-
-// Early IBM XL C on AIX fails to link due to missing pthread gear
-#if defined(_AIX) && defined(__xlC__)
-# undef HAS_PTHREADS
-# undef THREADS_AVAILABLE
#endif
// Cygwin/Newlib requires _XOPEN_SOURCE=600
@@ -961,14 +912,10 @@ NAMESPACE_END
#ifdef CRYPTOPP_WIN32_AVAILABLE
# if !defined(WINAPI_FAMILY)
-# define HAS_WINTHREADS
-# define THREADS_AVAILABLE
# define NONBLOCKING_RNG_AVAILABLE
# define OS_RNG_AVAILABLE
# elif defined(WINAPI_FAMILY)
# if (WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
-# define HAS_WINTHREADS
-# define THREADS_AVAILABLE
# define NONBLOCKING_RNG_AVAILABLE
# define OS_RNG_AVAILABLE
# elif !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
diff --git a/cryptdll.vcxproj b/cryptdll.vcxproj
index df5a4787..971cbb79 100644
--- a/cryptdll.vcxproj
+++ b/cryptdll.vcxproj
@@ -240,7 +240,6 @@
-
@@ -309,7 +308,6 @@
-
diff --git a/cryptest.nmake b/cryptest.nmake
index a0db6a29..e6a16fc4 100644
--- a/cryptest.nmake
+++ b/cryptest.nmake
@@ -45,11 +45,9 @@
###########################################################################################
-# If you use 'make sources' from Linux makefile, then add 'winpipes.cpp' to the list below.
+LIB_SRCS = cryptlib.cpp cpu.cpp integer.cpp 3way.cpp adler32.cpp algebra.cpp algparam.cpp arc4.cpp aria-simd.cpp aria.cpp ariatab.cpp asn.cpp authenc.cpp base32.cpp base64.cpp basecode.cpp bfinit.cpp blake2-simd.cpp blake2.cpp blowfish.cpp blumshub.cpp camellia.cpp cast.cpp casts.cpp cbcmac.cpp ccm.cpp chacha.cpp cham.cpp cham-simd.cpp channels.cpp cmac.cpp crc-simd.cpp crc.cpp default.cpp des.cpp dessp.cpp dh.cpp dh2.cpp dll.cpp dsa.cpp eax.cpp ec2n.cpp eccrypto.cpp ecp.cpp elgamal.cpp emsa2.cpp eprecomp.cpp esign.cpp files.cpp filters.cpp fips140.cpp fipstest.cpp gcm-simd.cpp gcm.cpp gf256.cpp gf2_32.cpp gf2n.cpp gfpcrypt.cpp gost.cpp gzip.cpp hc128.cpp hc256.cpp hex.cpp hight.cpp hmac.cpp hrtimer.cpp ida.cpp idea.cpp iterhash.cpp kalyna.cpp kalynatab.cpp keccak.cpp lea.cpp lea-simd.cpp luc.cpp mars.cpp marss.cpp md2.cpp md4.cpp md5.cpp misc.cpp modes.cpp mqueue.cpp mqv.cpp nbtheory.cpp neon-simd.cpp oaep.cpp osrng.cpp padlkrng.cpp panama.cpp pkcspad.cpp poly1305.cpp polynomi.cpp pssr.cpp pubkey.cpp queue.cpp rabin.cpp randpool.cpp rabbit.cpp rc2.cpp rc5.cpp rc6.cpp rdrand.cpp rdtables.cpp rijndael-simd.cpp rijndael.cpp ripemd.cpp rng.cpp rsa.cpp rw.cpp safer.cpp salsa.cpp scrypt.cpp seal.cpp seed.cpp serpent.cpp sha-simd.cpp sha.cpp sha3.cpp shacal2-simd.cpp shacal2.cpp shark.cpp sharkbox.cpp simeck-simd.cpp simeck.cpp simon.cpp simon64-simd.cpp simon128-simd.cpp skipjack.cpp sm3.cpp sm4.cpp sm4-simd.cpp sosemanuk.cpp speck.cpp speck64-simd.cpp speck128-simd.cpp square.cpp squaretb.cpp sse-simd.cpp strciphr.cpp tea.cpp tftables.cpp threefish.cpp tiger.cpp tigertab.cpp ttmac.cpp tweetnacl.cpp twofish.cpp vmac.cpp wake.cpp whrlpool.cp xtr.cpp xtrcrypt.cpp zdeflate.cpp zinflate.cpp zlib.cpp
-LIB_SRCS = cryptlib.cpp cpu.cpp integer.cpp 3way.cpp adler32.cpp algebra.cpp algparam.cpp arc4.cpp aria-simd.cpp aria.cpp ariatab.cpp asn.cpp authenc.cpp base32.cpp base64.cpp basecode.cpp bfinit.cpp blake2-simd.cpp blake2.cpp blowfish.cpp blumshub.cpp camellia.cpp cast.cpp casts.cpp cbcmac.cpp ccm.cpp chacha.cpp cham.cpp cham-simd.cpp channels.cpp cmac.cpp crc-simd.cpp crc.cpp default.cpp des.cpp dessp.cpp dh.cpp dh2.cpp dll.cpp dsa.cpp eax.cpp ec2n.cpp eccrypto.cpp ecp.cpp elgamal.cpp emsa2.cpp eprecomp.cpp esign.cpp files.cpp filters.cpp fips140.cpp fipstest.cpp gcm-simd.cpp gcm.cpp gf256.cpp gf2_32.cpp gf2n.cpp gfpcrypt.cpp gost.cpp gzip.cpp hc128.cpp hc256.cpp hex.cpp hight.cpp hmac.cpp hrtimer.cpp ida.cpp idea.cpp iterhash.cpp kalyna.cpp kalynatab.cpp keccak.cpp lea.cpp lea-simd.cpp luc.cpp mars.cpp marss.cpp md2.cpp md4.cpp md5.cpp misc.cpp modes.cpp mqueue.cpp mqv.cpp nbtheory.cpp neon-simd.cpp network.cpp oaep.cpp osrng.cpp padlkrng.cpp panama.cpp pkcspad.cpp poly1305.cpp polynomi.cpp pssr.cpp pubkey.cpp queue.cpp rabin.cpp randpool.cpp rabbit.cpp rc2.cpp rc5.cpp rc6.cpp rdrand.cpp rdtables.cpp rijndael-simd.cpp rijndael.cpp ripemd.cpp rng.cpp rsa.cpp rw.cpp safer.cpp salsa.cpp scrypt.cpp seal.cpp seed.cpp serpent.cpp sha-simd.cpp sha.cpp sha3.cpp shacal2-simd.cpp shacal2.cpp shark.cpp sharkbox.cpp simeck-simd.cpp simeck.cpp simon.cpp simon64-simd.cpp simon128-simd.cpp skipjack.cpp sm3.cpp sm4.cpp sm4-simd.cpp socketft.cpp sosemanuk.cpp speck.cpp speck64-simd.cpp speck128-simd.cpp square.cpp squaretb.cpp sse-simd.cpp strciphr.cpp tea.cpp tftables.cpp threefish.cpp tiger.cpp tigertab.cpp trdlocal.cpp ttmac.cpp tweetnacl.cpp twofish.cpp vmac.cpp wait.cpp wake.cpp whrlpool.cpp winpipes.cpp xtr.cpp xtrcrypt.cpp zdeflate.cpp zinflate.cpp zlib.cpp
-
-LIB_OBJS = cryptlib.obj cpu.obj integer.obj 3way.obj adler32.obj algebra.obj algparam.obj arc4.obj aria-simd.obj aria.obj ariatab.obj asn.obj authenc.obj base32.obj base64.obj basecode.obj bfinit.obj blake2-simd.obj blake2.obj blowfish.obj blumshub.obj camellia.obj cast.obj casts.obj cbcmac.obj ccm.obj chacha.obj cham.obj cham-simd.obj channels.obj cmac.obj crc-simd.obj crc.obj default.obj des.obj dessp.obj dh.obj dh2.obj dll.obj dsa.obj eax.obj ec2n.obj eccrypto.obj ecp.obj elgamal.obj emsa2.obj eprecomp.obj esign.obj files.obj filters.obj fips140.obj fipstest.obj gcm-simd.obj gcm.obj gf256.obj gf2_32.obj gf2n.obj gfpcrypt.obj gost.obj gzip.obj hc128.obj hc256.obj hex.obj hight.obj hmac.obj hrtimer.obj ida.obj idea.obj iterhash.obj kalyna.obj kalynatab.obj keccak.obj lea.obj lea-simd.obj luc.obj mars.obj marss.obj md2.obj md4.obj md5.obj misc.obj modes.obj mqueue.obj mqv.obj nbtheory.obj neon-simd.obj network.obj oaep.obj osrng.obj padlkrng.obj panama.obj pkcspad.obj poly1305.obj polynomi.obj pssr.obj pubkey.obj queue.obj rabin.obj randpool.obj rabbit.obj rc2.obj rc5.obj rc6.obj rdrand.obj rdtables.obj rijndael-simd.obj rijndael.obj ripemd.obj rng.obj rsa.obj rw.obj safer.obj salsa.obj scrypt.obj seal.obj seed.obj serpent.obj sha-simd.obj sha.obj sha3.obj shacal2-simd.obj shacal2.obj shark.obj sharkbox.obj simeck-simd.obj simeck.obj simon.obj simon64-simd.obj simon128-simd.obj skipjack.obj sm3.obj sm4.obj sm4-simd.obj socketft.obj sosemanuk.obj speck.obj speck64-simd.obj speck128-simd.obj square.obj squaretb.obj sse-simd.obj strciphr.obj tea.obj tftables.obj threefish.obj tiger.obj tigertab.obj trdlocal.obj ttmac.obj tweetnacl.obj twofish.obj vmac.obj wait.obj wake.obj whrlpool.obj winpipes.obj xtr.obj xtrcrypt.obj zdeflate.obj zinflate.obj zlib.obj
+LIB_OBJS = cryptlib.obj cpu.obj integer.obj 3way.obj adler32.obj algebra.obj algparam.obj arc4.obj aria-simd.obj aria.obj ariatab.obj asn.obj authenc.obj base32.obj base64.obj basecode.obj bfinit.obj blake2-simd.obj blake2.obj blowfish.obj blumshub.obj camellia.obj cast.obj casts.obj cbcmac.obj ccm.obj chacha.obj cham.obj cham-simd.obj channels.obj cmac.obj crc-simd.obj crc.obj default.obj des.obj dessp.obj dh.obj dh2.obj dll.obj dsa.obj eax.obj ec2n.obj eccrypto.obj ecp.obj elgamal.obj emsa2.obj eprecomp.obj esign.obj files.obj filters.obj fips140.obj fipstest.obj gcm-simd.obj gcm.obj gf256.obj gf2_32.obj gf2n.obj gfpcrypt.obj gost.obj gzip.obj hc128.obj hc256.obj hex.obj hight.obj hmac.obj hrtimer.obj ida.obj idea.obj iterhash.obj kalyna.obj kalynatab.obj keccak.obj lea.obj lea-simd.obj luc.obj mars.obj marss.obj md2.obj md4.obj md5.obj misc.obj modes.obj mqueue.obj mqv.obj nbtheory.obj neon-simd.obj oaep.obj osrng.obj padlkrng.obj panama.obj pkcspad.obj poly1305.obj polynomi.obj pssr.obj pubkey.obj queue.obj rabin.obj randpool.obj rabbit.obj rc2.obj rc5.obj rc6.obj rdrand.obj rdtables.obj rijndael-simd.obj rijndael.obj ripemd.obj rng.obj rsa.obj rw.obj safer.obj salsa.obj scrypt.obj seal.obj seed.obj serpent.obj sha-simd.obj sha.obj sha3.obj shacal2-simd.obj shacal2.obj shark.obj sharkbox.obj simeck-simd.obj simeck.obj simon.obj simon64-simd.obj simon128-simd.obj skipjack.obj sm3.obj sm4.obj sm4-simd.obj sosemanuk.obj speck.obj speck64-simd.obj speck128-simd.obj square.obj squaretb.obj sse-simd.obj strciphr.obj tea.obj tftables.obj threefish.obj tiger.obj tigertab.obj ttmac.obj tweetnacl.obj twofish.obj vmac.obj wake.obj whrlpool.obj xtr.obj xtrcrypt.obj zdeflate.obj zinflate.obj zlib.obj
TEST_SRCS = bench1.cpp bench2.cpp bench3.cpp test.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp validat4.cpp validat5.cpp validat6.cpp validat7.cpp validat8.cpp validat9.cpp validat10.cpp datatest.cpp regtest1.cpp regtest2.cpp regtest3.cpp regtest4.cpp fipsalgt.cpp dlltest.cpp fipstest.cpp
@@ -108,7 +106,7 @@ ASFLAGS = /nologo /D_M_X86 /W3 /Cx /Zi /safeseh
LIB_SRCS = $(LIB_SRCS) rdrand.cpp rdrand.asm
LIB_OBJS = $(LIB_OBJS) rdrand.obj rdrand-x86.obj
LDFLAGS = $(LDFLAGS) /MACHINE:X86
-LDLIBS = $(LDLIBS) ws2_32.lib kernel32.lib
+LDLIBS = $(LDLIBS) kernel32.lib
!ENDIF
# May need $(VCINSTALLDIR)\bin\amd64\ml64.exe
@@ -121,7 +119,7 @@ ASFLAGS = /nologo /D_M_X64 /W3 /Cx /Zi
LIB_SRCS = $(LIB_SRCS) rdrand.cpp rdrand.asm
LIB_OBJS = $(LIB_OBJS) rdrand.obj rdrand-x64.obj x64masm.obj x64dll.obj
LDFLAGS = $(LDFLAGS) /MACHINE:X64
-LDLIBS = $(LDLIBS) ws2_32.lib kernel32.lib
+LDLIBS = $(LDLIBS) kernel32.lib
!ENDIF
# We still don't know what we need for ARM64 on Windows. ARM64 and arm64 may be incorrect
@@ -131,7 +129,7 @@ CXXFLAGS = $(CXXFLAGS) /DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP
LIB_SRCS = $(LIB_SRCS) neon-simd.cpp
LIB_OBJS = $(LIB_OBJS) neon-simd.obj
# CXXFLAGS = $(CXXFLAGS) /DWINAPI_FAMILY=WINAPI_FAMILY_APP
-# LDLIBS = $(LDLIBS) ws2_32.lib
+# LDLIBS = $(LDLIBS)
!ENDIF
all: cryptest.exe
diff --git a/cryptlib.cpp b/cryptlib.cpp
index 8c1de4e2..81ff4b16 100644
--- a/cryptlib.cpp
+++ b/cryptlib.cpp
@@ -22,17 +22,11 @@
#include "fips140.h"
#include "argnames.h"
#include "fltrimpl.h"
-#include "trdlocal.h"
#include "osrng.h"
#include "secblock.h"
#include "smartptr.h"
#include "stdcpp.h"
-// http://www.cygwin.com/faq.html#faq.api.winsock
-#if (defined(__CYGWIN__) || defined(__CYGWIN32__)) && defined(PREFER_WINDOWS_STYLE_SOCKETS)
-# error Cygwin does not support Windows style sockets. See http://www.cygwin.com/faq.html#faq.api.winsock
-#endif
-
NAMESPACE_BEGIN(CryptoPP)
CRYPTOPP_COMPILE_ASSERT(sizeof(byte) == 1);
diff --git a/cryptlib.h b/cryptlib.h
index 722b8181..1b0c1791 100644
--- a/cryptlib.h
+++ b/cryptlib.h
@@ -48,9 +48,9 @@
Compression
Deflator, Inflator, Gzip, Gunzip, ZlibCompressor, ZlibDecompressor
Input Source Classes
- StringSource, ArraySource, FileSource, SocketSource, WindowsPipeSource, RandomNumberSource
+ StringSource, ArraySource, FileSource, RandomNumberSource
Output Sink Classes
- StringSinkTemplate, StringSink, ArraySink, FileSink, SocketSink, WindowsPipeSink, RandomNumberSink
+ StringSinkTemplate, StringSink, ArraySink, FileSink, RandomNumberSink
Filter Wrappers
StreamTransformationFilter, AuthenticatedEncryptionFilter, AuthenticatedDecryptionFilter, HashFilter,
HashVerificationFilter, SignerFilter, SignatureVerificationFilter
@@ -58,7 +58,7 @@
HexEncoder, HexDecoder, Base64Encoder, Base64Decoder, Base64URLEncoder, Base64URLDecoder, Base32Encoder,
Base32Decoder
Wrappers for OS features
- Timer, Socket, WindowsHandle, ThreadLocalStorage, ThreadUserTimer
+ Timer, ThreadUserTimer
diff --git a/cryptlib.vcxproj b/cryptlib.vcxproj
index 042fab7f..6115e9f0 100644
--- a/cryptlib.vcxproj
+++ b/cryptlib.vcxproj
@@ -257,7 +257,6 @@
-
@@ -308,7 +307,6 @@
-
@@ -322,15 +320,12 @@
-
-
-
@@ -460,7 +455,6 @@
-
@@ -507,7 +501,6 @@
-
@@ -517,16 +510,13 @@
-
-
-
diff --git a/cryptlib.vcxproj.filters b/cryptlib.vcxproj.filters
index 6d37edbd..5c178559 100644
--- a/cryptlib.vcxproj.filters
+++ b/cryptlib.vcxproj.filters
@@ -269,9 +269,6 @@
Source Files
-
- Source Files
-
Source Files
@@ -425,9 +422,6 @@
Source Files
-
- Source Files
-
Source Files
@@ -458,9 +452,6 @@
Source Files
-
- Source Files
-
Source Files
@@ -473,18 +464,12 @@
Source Files
-
- Source Files
-
Source Files
Source Files
-
- Source Files
-
Source Files
@@ -774,9 +759,6 @@
Header Files
-
- Header Files
-
Header Files
@@ -918,9 +900,6 @@
Header Files
-
- Header Files
-
Header Files
@@ -945,9 +924,6 @@
Header Files
-
- Header Files
-
Header Files
@@ -963,18 +939,12 @@
Header Files
-
- Header Files
-
Header Files
Header Files
-
- Header Files
-
Header Files
diff --git a/dll.h b/dll.h
index bbb2257a..f923026c 100644
--- a/dll.h
+++ b/dll.h
@@ -40,7 +40,6 @@
#include "rw.h"
#include "sha.h"
#include "skipjack.h"
-#include "trdlocal.h"
#ifdef CRYPTOPP_IMPORTS
diff --git a/fips140.cpp b/fips140.cpp
index f95f4005..1f911fc5 100644
--- a/fips140.cpp
+++ b/fips140.cpp
@@ -6,7 +6,6 @@
#include "fips140.h"
#include "misc.h"
-#include "trdlocal.h" // needs to be included last for cygwin
NAMESPACE_BEGIN(CryptoPP)
@@ -16,10 +15,6 @@ NAMESPACE_BEGIN(CryptoPP)
#define CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 0
#endif
-#if (CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 && !defined(THREADS_AVAILABLE))
-#error FIPS 140-2 compliance requires the availability of thread local storage.
-#endif
-
#if (CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2 && !defined(OS_RNG_AVAILABLE))
#error FIPS 140-2 compliance requires the availability of OS provided RNG.
#endif
@@ -41,29 +36,24 @@ PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus()
return g_powerUpSelfTestStatus;
}
-#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
-ThreadLocalStorage & AccessPowerUpSelfTestInProgress()
-{
- static ThreadLocalStorage selfTestInProgress;
- return selfTestInProgress;
-}
-#endif
+// One variable for all threads for compatibility. Previously this
+// was a ThreadLocalStorage variable, which is per-thread. Also see
+// https://github.com/weidai11/cryptopp/issues/208
+static bool s_inProgress = false;
bool PowerUpSelfTestInProgressOnThisThread()
{
#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
- return AccessPowerUpSelfTestInProgress().GetValue() != NULLPTR;
-#else
- CRYPTOPP_ASSERT(false); // should not be called
- return false;
+ return s_inProgress;
#endif
+ return false;
}
void SetPowerUpSelfTestInProgressOnThisThread(bool inProgress)
{
CRYPTOPP_UNUSED(inProgress);
#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
- AccessPowerUpSelfTestInProgress().SetValue((void *)inProgress);
+ s_inProgress = inProgress;
#endif
}
diff --git a/network.cpp b/network.cpp
deleted file mode 100644
index c7873d0e..00000000
--- a/network.cpp
+++ /dev/null
@@ -1,554 +0,0 @@
-// network.cpp - originally written and placed in the public domain by Wei Dai
-
-#include "pch.h"
-
-#include "network.h"
-
-#if !defined(NO_OS_DEPENDENCE) && defined(SOCKETS_AVAILABLE)
-
-#include "wait.h"
-
-#define CRYPTOPP_TRACE_NETWORK 0
-
-NAMESPACE_BEGIN(CryptoPP)
-
-lword LimitedBandwidth::ComputeCurrentTransceiveLimit()
-{
- if (!m_maxBytesPerSecond)
- return ULONG_MAX;
-
- const double curTime = GetCurTimeAndCleanUp();
- CRYPTOPP_UNUSED(curTime);
-
- lword total = 0;
- for (OpQueue::size_type i=0; i!=m_ops.size(); ++i)
- total += m_ops[i].second;
- return SaturatingSubtract(m_maxBytesPerSecond, total);
-}
-
-double LimitedBandwidth::TimeToNextTransceive()
-{
- if (!m_maxBytesPerSecond)
- return 0;
-
- if (!m_nextTransceiveTime)
- ComputeNextTransceiveTime();
-
- return SaturatingSubtract(m_nextTransceiveTime, m_timer.ElapsedTimeAsDouble());
-}
-
-void LimitedBandwidth::NoteTransceive(lword size)
-{
- if (m_maxBytesPerSecond)
- {
- double curTime = GetCurTimeAndCleanUp();
- m_ops.push_back(std::make_pair(curTime, size));
- m_nextTransceiveTime = 0;
- }
-}
-
-void LimitedBandwidth::ComputeNextTransceiveTime()
-{
- double curTime = GetCurTimeAndCleanUp();
- lword total = 0;
- for (unsigned int i=0; i!=m_ops.size(); ++i)
- total += m_ops[i].second;
- m_nextTransceiveTime =
- (total < m_maxBytesPerSecond) ? curTime : m_ops.front().first + 1000;
-}
-
-double LimitedBandwidth::GetCurTimeAndCleanUp()
-{
- if (!m_maxBytesPerSecond)
- return 0;
-
- double curTime = m_timer.ElapsedTimeAsDouble();
- while (m_ops.size() && (m_ops.front().first + 1000 < curTime))
- m_ops.pop_front();
- return curTime;
-}
-
-void LimitedBandwidth::GetWaitObjects(WaitObjectContainer &container, const CallStack &callStack)
-{
- double nextTransceiveTime = TimeToNextTransceive();
- if (nextTransceiveTime)
- container.ScheduleEvent(nextTransceiveTime, CallStack("LimitedBandwidth::GetWaitObjects()", &callStack));
-}
-
-// *************************************************************
-
-size_t NonblockingSource::GeneralPump2(
- lword& byteCount, bool blockingOutput,
- unsigned long maxTime, bool checkDelimiter, byte delimiter)
-{
- m_blockedBySpeedLimit = false;
-
- if (!GetMaxBytesPerSecond())
- {
- size_t ret = DoPump(byteCount, blockingOutput, maxTime, checkDelimiter, delimiter);
- m_doPumpBlocked = (ret != 0);
- return ret;
- }
-
- bool forever = (maxTime == INFINITE_TIME);
- unsigned long timeToGo = maxTime;
- Timer timer(Timer::MILLISECONDS, forever);
- lword maxSize = byteCount;
- byteCount = 0;
-
- timer.StartTimer();
-
- while (true)
- {
- lword curMaxSize = UnsignedMin(ComputeCurrentTransceiveLimit(), maxSize - byteCount);
-
- if (curMaxSize || m_doPumpBlocked)
- {
- if (!forever) timeToGo = SaturatingSubtract(maxTime, timer.ElapsedTime());
- size_t ret = DoPump(curMaxSize, blockingOutput, timeToGo, checkDelimiter, delimiter);
- m_doPumpBlocked = (ret != 0);
- if (curMaxSize)
- {
- NoteTransceive(curMaxSize);
- byteCount += curMaxSize;
- }
- if (ret)
- return ret;
- }
-
- if (maxSize != ULONG_MAX && byteCount >= maxSize)
- break;
-
- if (!forever)
- {
- timeToGo = SaturatingSubtract(maxTime, timer.ElapsedTime());
- if (!timeToGo)
- break;
- }
-
- double waitTime = TimeToNextTransceive();
- if (!forever && waitTime > timeToGo)
- {
- m_blockedBySpeedLimit = true;
- break;
- }
-
- WaitObjectContainer container;
- LimitedBandwidth::GetWaitObjects(container, CallStack("NonblockingSource::GeneralPump2() - speed limit", NULLPTR));
- container.Wait((unsigned long)waitTime);
- }
-
- return 0;
-}
-
-size_t NonblockingSource::PumpMessages2(unsigned int &messageCount, bool blocking)
-{
- if (messageCount == 0)
- return 0;
-
- messageCount = 0;
-
- lword byteCount;
- do {
- byteCount = LWORD_MAX;
- RETURN_IF_NONZERO(Pump2(byteCount, blocking));
- } while(byteCount == LWORD_MAX);
-
- if (!m_messageEndSent && SourceExhausted())
- {
- RETURN_IF_NONZERO(AttachedTransformation()->Put2(NULLPTR, 0, GetAutoSignalPropagation(), true));
- m_messageEndSent = true;
- messageCount = 1;
- }
- return 0;
-}
-
-lword NonblockingSink::TimedFlush(unsigned long maxTime, size_t targetSize)
-{
- m_blockedBySpeedLimit = false;
-
- size_t curBufSize = GetCurrentBufferSize();
- if (curBufSize <= targetSize && (targetSize || !EofPending()))
- return 0;
-
- if (!GetMaxBytesPerSecond())
- return DoFlush(maxTime, targetSize);
-
- bool forever = (maxTime == INFINITE_TIME);
- unsigned long timeToGo = maxTime;
- Timer timer(Timer::MILLISECONDS, forever);
- lword totalFlushed = 0;
-
- timer.StartTimer();
-
- while (true)
- {
- size_t flushSize = UnsignedMin(curBufSize - targetSize, ComputeCurrentTransceiveLimit());
- if (flushSize || EofPending())
- {
- if (!forever) timeToGo = SaturatingSubtract(maxTime, timer.ElapsedTime());
- size_t ret = (size_t)DoFlush(timeToGo, curBufSize - flushSize);
- if (ret)
- {
- NoteTransceive(ret);
- curBufSize -= ret;
- totalFlushed += ret;
- }
- }
-
- if (curBufSize <= targetSize && (targetSize || !EofPending()))
- break;
-
- if (!forever)
- {
- timeToGo = SaturatingSubtract(maxTime, timer.ElapsedTime());
- if (!timeToGo)
- break;
- }
-
- double waitTime = TimeToNextTransceive();
- if (!forever && waitTime > timeToGo)
- {
- m_blockedBySpeedLimit = true;
- break;
- }
-
- WaitObjectContainer container;
- LimitedBandwidth::GetWaitObjects(container, CallStack("NonblockingSink::TimedFlush() - speed limit", NULLPTR));
- container.Wait((unsigned long)waitTime);
- }
-
- return totalFlushed;
-}
-
-bool NonblockingSink::IsolatedFlush(bool hardFlush, bool blocking)
-{
- TimedFlush(blocking ? INFINITE_TIME : 0);
- return hardFlush && (!!GetCurrentBufferSize() || EofPending());
-}
-
-// *************************************************************
-
-NetworkSource::NetworkSource(BufferedTransformation *attachment)
- : NonblockingSource(attachment), m_buf(1024*16)
- , m_putSize(0), m_dataBegin(0), m_dataEnd(0)
- , m_waitingForResult(false), m_outputBlocked(false)
-{
-}
-
-unsigned int NetworkSource::GetMaxWaitObjectCount() const
-{
- return LimitedBandwidth::GetMaxWaitObjectCount()
- + GetReceiver().GetMaxWaitObjectCount()
- + AttachedTransformation()->GetMaxWaitObjectCount();
-}
-
-void NetworkSource::GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack)
-{
- if (BlockedBySpeedLimit())
- LimitedBandwidth::GetWaitObjects(container, CallStack("NetworkSource::GetWaitObjects() - speed limit", &callStack));
- else if (!m_outputBlocked)
- {
- if (m_dataBegin == m_dataEnd)
- AccessReceiver().GetWaitObjects(container, CallStack("NetworkSource::GetWaitObjects() - no data", &callStack));
- else
- container.SetNoWait(CallStack("NetworkSource::GetWaitObjects() - have data", &callStack));
- }
-
- AttachedTransformation()->GetWaitObjects(container, CallStack("NetworkSource::GetWaitObjects() - attachment", &callStack));
-}
-
-size_t NetworkSource::DoPump(lword &byteCount, bool blockingOutput, unsigned long maxTime, bool checkDelimiter, byte delimiter)
-{
- NetworkReceiver &receiver = AccessReceiver();
-
- lword maxSize = byteCount;
- byteCount = 0;
- bool forever = maxTime == INFINITE_TIME;
- Timer timer(Timer::MILLISECONDS, forever);
- BufferedTransformation *t = AttachedTransformation();
-
- if (m_outputBlocked)
- goto DoOutput;
-
- while (true)
- {
- if (m_dataBegin == m_dataEnd)
- {
- if (receiver.EofReceived())
- break;
-
- if (m_waitingForResult)
- {
- if (receiver.MustWaitForResult() &&
- !receiver.Wait(SaturatingSubtract(maxTime, timer.ElapsedTime()),
- CallStack("NetworkSource::DoPump() - wait receive result", NULLPTR)))
- break;
-
- unsigned int recvResult = receiver.GetReceiveResult();
-#if CRYPTOPP_TRACE_NETWORK
- OutputDebugStringA((IntToString((unsigned int)this) + ": Received " + IntToString(recvResult) + " bytes\n").c_str());
-#endif
- m_dataEnd += recvResult;
- m_waitingForResult = false;
-
- if (!receiver.MustWaitToReceive() && !receiver.EofReceived() && m_dataEnd != m_buf.size())
- goto ReceiveNoWait;
- }
- else
- {
- m_dataEnd = m_dataBegin = 0;
-
- if (receiver.MustWaitToReceive())
- {
- if (!receiver.Wait(SaturatingSubtract(maxTime, timer.ElapsedTime()),
- CallStack("NetworkSource::DoPump() - wait receive", NULLPTR)))
- break;
-
- receiver.Receive(m_buf+m_dataEnd, m_buf.size()-m_dataEnd);
- m_waitingForResult = true;
- }
- else
- {
-ReceiveNoWait:
- m_waitingForResult = true;
- // call Receive repeatedly as long as data is immediately available,
- // because some receivers tend to return data in small pieces
-#if CRYPTOPP_TRACE_NETWORK
- OutputDebugStringA((IntToString((unsigned int)this) + ": Receiving " + IntToString(m_buf.size()-m_dataEnd) + " bytes\n").c_str());
-#endif
- while (receiver.Receive(m_buf+m_dataEnd, m_buf.size()-m_dataEnd))
- {
- unsigned int recvResult = receiver.GetReceiveResult();
-#if CRYPTOPP_TRACE_NETWORK
- OutputDebugStringA((IntToString((unsigned int)this) + ": Received " + IntToString(recvResult) + " bytes\n").c_str());
-#endif
- m_dataEnd += recvResult;
- if (receiver.EofReceived() || m_dataEnd > m_buf.size() /2)
- {
- m_waitingForResult = false;
- break;
- }
- }
- }
- }
- }
- else
- {
- m_putSize = UnsignedMin(m_dataEnd - m_dataBegin, maxSize - byteCount);
-
- if (checkDelimiter)
- m_putSize = std::find(m_buf+m_dataBegin, m_buf+m_dataBegin+m_putSize, delimiter) - (m_buf+m_dataBegin);
-
-DoOutput:
- size_t result = t->PutModifiable2(m_buf+m_dataBegin, m_putSize, 0, forever || blockingOutput);
- if (result)
- {
- if (t->Wait(SaturatingSubtract(maxTime, timer.ElapsedTime()),
- CallStack("NetworkSource::DoPump() - wait attachment", NULLPTR)))
- goto DoOutput;
- else
- {
- m_outputBlocked = true;
- return result;
- }
- }
- m_outputBlocked = false;
-
- byteCount += m_putSize;
- m_dataBegin += m_putSize;
- if (checkDelimiter && m_dataBegin < m_dataEnd && m_buf[m_dataBegin] == delimiter)
- break;
- if (maxSize != ULONG_MAX && byteCount == maxSize)
- break;
- // once time limit is reached, return even if there is more data waiting
- // but make 0 a special case so caller can request a large amount of data to be
- // pumped as long as it is immediately available
- if (maxTime > 0 && timer.ElapsedTime() > maxTime)
- break;
- }
- }
-
- return 0;
-}
-
-// *************************************************************
-
-NetworkSink::NetworkSink(unsigned int maxBufferSize, unsigned int autoFlushBound)
- : m_maxBufferSize(maxBufferSize), m_autoFlushBound(autoFlushBound)
- , m_needSendResult(false), m_wasBlocked(false), m_eofState(EOF_NONE)
- , m_buffer(STDMIN(16U*1024U+256, maxBufferSize)), m_skipBytes(0)
- , m_speedTimer(Timer::MILLISECONDS), m_byteCountSinceLastTimerReset(0)
- , m_currentSpeed(0), m_maxObservedSpeed(0)
-{
-}
-
-float NetworkSink::ComputeCurrentSpeed()
-{
- if (m_speedTimer.ElapsedTime() > 1000)
- {
- m_currentSpeed = m_byteCountSinceLastTimerReset * 1000 / m_speedTimer.ElapsedTime();
- m_maxObservedSpeed = STDMAX(m_currentSpeed, m_maxObservedSpeed * 0.98f);
- m_byteCountSinceLastTimerReset = 0;
- m_speedTimer.StartTimer();
-// OutputDebugStringA(("max speed: " + IntToString((int)m_maxObservedSpeed) + " current speed: " + IntToString((int)m_currentSpeed) + "\n").c_str());
- }
- return m_currentSpeed;
-}
-
-float NetworkSink::GetMaxObservedSpeed() const
-{
- lword m = GetMaxBytesPerSecond();
- return m ? STDMIN(m_maxObservedSpeed, static_cast(m)) : m_maxObservedSpeed;
-}
-
-unsigned int NetworkSink::GetMaxWaitObjectCount() const
-{
- return LimitedBandwidth::GetMaxWaitObjectCount() + GetSender().GetMaxWaitObjectCount();
-}
-
-void NetworkSink::GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack)
-{
- if (BlockedBySpeedLimit())
- LimitedBandwidth::GetWaitObjects(container, CallStack("NetworkSink::GetWaitObjects() - speed limit", &callStack));
- else if (m_wasBlocked)
- AccessSender().GetWaitObjects(container, CallStack("NetworkSink::GetWaitObjects() - was blocked", &callStack));
- else if (!m_buffer.IsEmpty())
- AccessSender().GetWaitObjects(container, CallStack("NetworkSink::GetWaitObjects() - buffer not empty", &callStack));
- else if (EofPending())
- AccessSender().GetWaitObjects(container, CallStack("NetworkSink::GetWaitObjects() - EOF pending", &callStack));
-}
-
-size_t NetworkSink::Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
-{
- if (m_eofState == EOF_DONE)
- {
- if (length || messageEnd)
- throw Exception(Exception::OTHER_ERROR, "NetworkSink::Put2() being called after EOF had been sent");
-
- return 0;
- }
-
- if (m_eofState > EOF_NONE)
- goto EofSite;
-
- {
- if (m_skipBytes)
- {
- CRYPTOPP_ASSERT(length >= m_skipBytes);
- inString += m_skipBytes;
- length -= m_skipBytes;
- }
-
- m_buffer.Put(inString, length);
-
- if (!blocking || m_buffer.CurrentSize() > m_autoFlushBound)
- TimedFlush(0, 0);
-
- size_t targetSize = messageEnd ? 0 : m_maxBufferSize;
- if (blocking)
- TimedFlush(INFINITE_TIME, targetSize);
-
- if (m_buffer.CurrentSize() > targetSize)
- {
- CRYPTOPP_ASSERT(!blocking);
- m_wasBlocked = true;
- m_skipBytes += length;
- size_t blockedBytes = UnsignedMin(length, m_buffer.CurrentSize() - targetSize);
- return STDMAX(blockedBytes, 1);
- }
-
- m_wasBlocked = false;
- m_skipBytes = 0;
- }
-
- if (messageEnd)
- {
- m_eofState = EOF_PENDING_SEND;
-
- EofSite:
- TimedFlush(blocking ? INFINITE_TIME : 0, 0);
- if (m_eofState != EOF_DONE)
- return 1;
- }
-
- return 0;
-}
-
-lword NetworkSink::DoFlush(unsigned long maxTime, size_t targetSize)
-{
- NetworkSender &sender = AccessSender();
-
- bool forever = maxTime == INFINITE_TIME;
- Timer timer(Timer::MILLISECONDS, forever);
- unsigned int totalFlushSize = 0;
-
- while (true)
- {
- if (m_buffer.CurrentSize() <= targetSize)
- break;
-
- if (m_needSendResult)
- {
- if (sender.MustWaitForResult() &&
- !sender.Wait(SaturatingSubtract(maxTime, timer.ElapsedTime()),
- CallStack("NetworkSink::DoFlush() - wait send result", NULLPTR)))
- break;
-
- unsigned int sendResult = sender.GetSendResult();
-#if CRYPTOPP_TRACE_NETWORK
- OutputDebugStringA((IntToString((unsigned int)this) + ": Sent " + IntToString(sendResult) + " bytes\n").c_str());
-#endif
- m_buffer.Skip(sendResult);
- totalFlushSize += sendResult;
- m_needSendResult = false;
-
- if (!m_buffer.AnyRetrievable())
- break;
- }
-
- unsigned long timeOut = maxTime ? SaturatingSubtract(maxTime, timer.ElapsedTime()) : 0;
- if (sender.MustWaitToSend() && !sender.Wait(timeOut, CallStack("NetworkSink::DoFlush() - wait send", NULLPTR)))
- break;
-
- size_t contiguousSize = 0;
- const byte *block = m_buffer.Spy(contiguousSize);
-
-#if CRYPTOPP_TRACE_NETWORK
- OutputDebugStringA((IntToString((unsigned int)this) + ": Sending " + IntToString(contiguousSize) + " bytes\n").c_str());
-#endif
- sender.Send(block, contiguousSize);
- m_needSendResult = true;
-
- if (maxTime > 0 && timeOut == 0)
- break; // once time limit is reached, return even if there is more data waiting
- }
-
- m_byteCountSinceLastTimerReset += totalFlushSize;
- ComputeCurrentSpeed();
-
- if (m_buffer.IsEmpty() && !m_needSendResult)
- {
- if (m_eofState == EOF_PENDING_SEND)
- {
- sender.SendEof();
- m_eofState = sender.MustWaitForEof() ? EOF_PENDING_DELIVERY : EOF_DONE;
- }
-
- while (m_eofState == EOF_PENDING_DELIVERY)
- {
- unsigned long timeOut = maxTime ? SaturatingSubtract(maxTime, timer.ElapsedTime()) : 0;
- if (!sender.Wait(timeOut, CallStack("NetworkSink::DoFlush() - wait EOF", NULLPTR)))
- break;
-
- if (sender.EofSent())
- m_eofState = EOF_DONE;
- }
- }
-
- return totalFlushSize;
-}
-
-NAMESPACE_END
-
-#endif // #ifdef SOCKETS_AVAILABLE
diff --git a/network.h b/network.h
deleted file mode 100644
index 3ea90dee..00000000
--- a/network.h
+++ /dev/null
@@ -1,234 +0,0 @@
-#ifndef CRYPTOPP_NETWORK_H
-#define CRYPTOPP_NETWORK_H
-
-#include "config.h"
-
-#if !defined(NO_OS_DEPENDENCE) && defined(SOCKETS_AVAILABLE)
-
-#include "filters.h"
-#include "hrtimer.h"
-#include "stdcpp.h"
-
-NAMESPACE_BEGIN(CryptoPP)
-
-class LimitedBandwidth
-{
-public:
- LimitedBandwidth(lword maxBytesPerSecond = 0)
- : m_maxBytesPerSecond(maxBytesPerSecond), m_timer(Timer::MILLISECONDS)
- , m_nextTransceiveTime(0)
- { m_timer.StartTimer(); }
-
- lword GetMaxBytesPerSecond() const
- { return m_maxBytesPerSecond; }
-
- void SetMaxBytesPerSecond(lword v)
- { m_maxBytesPerSecond = v; }
-
- lword ComputeCurrentTransceiveLimit();
-
- double TimeToNextTransceive();
-
- void NoteTransceive(lword size);
-
-public:
- /*! GetWaitObjects() must be called despite the 0 return from GetMaxWaitObjectCount();
- the 0 is because the ScheduleEvent() method is used instead of adding a wait object */
- unsigned int GetMaxWaitObjectCount() const { return 0; }
- void GetWaitObjects(WaitObjectContainer &container, const CallStack &callStack);
-
-private:
- lword m_maxBytesPerSecond;
-
- typedef std::deque > OpQueue;
- OpQueue m_ops;
-
- Timer m_timer;
- double m_nextTransceiveTime;
-
- void ComputeNextTransceiveTime();
- double GetCurTimeAndCleanUp();
-};
-
-/// a Source class that can pump from a device for a specified amount of time.
-class CRYPTOPP_NO_VTABLE NonblockingSource : public AutoSignaling