Sockets and Threads

From Crypto++ Wiki
Jump to: navigation, search

Early version of Crypto++ through Crypto++ 7.0 includes source files and classes that were removed from later versions of the library. The classes removed included ThreadLocalStorage, SocketSource, WindowsPipeSource, Socket, SocketSink, WindowsPipeSink. They were removed at Commit f2171cbe2f49. Also see Google Group discussion, which is empty but documents the action.

The details of why the files and classes were removed can be found at Issue 178 and Issue 208. The short of it is, the code added complexity but was less valuable since no one appeared to use the classes. They contributed to porting problems on lesser used platforms like AIX and Solaris, and added to compile failures for tooling like SunCC and IBM XLC. The classes and files also fell outside the core library mission of a cryptographic toolkit for academic, research and production systems. (Being outside of core isn't necessarily a bad thing).

If you need the files they are available below under Downloads. Be sure to visit Commit f2171cbe2f49 and recreate the preprocessor macros needed to activate them.

File List

The list of files removed at Commit f2171cbe2f49 is below.

  • network.cpp
  • network.h
  • socketft.cpp
  • socketft.h
  • trdlocal.cpp
  • trdlocal.h
  • wait.cpp
  • wait.h
  • winpipes.cpp
  • winpipes.h

Classes

The list of classes removed at Commit f2171cbe2f49 is below.

  • NonblockingSource
  • LimitedBandwidth
  • NetworkReceiver
  • NonblockingSink
  • NetworkSender
  • NetworkSource
  • NetworkSink
  • Socket
  • SocketsInitializer
  • SocketSender
  • SocketSource
  • SocketSink
  • ThreadLocalStorage
  • Tracer
  • CallStack
  • WaitObjectContainer
  • WindowsHandle
  • WindowsPipe
  • WindowsPipeReceiver
  • WindowsPipeSender
  • WindowsPipeSource
  • WindowsPipeSink

ThreadLocalStorage

Of all the classes removed ThreadLocalStorage was one of the more interesting ones. It was used in one place in fips140.cpp. A ThreadLocalStorage was used to track FIPS self-tests on a per-thread basis. If a self-test was started then the a boolean variable held a true value, and false otherwise.

Other than fips140.cpp the library does not concern itself with thread local storage. The library is thread safe at the class level, meaning there is no shared data among object instances. The user is responsible for locking when two threads access the same object.

After the removal of the classes the library uses a shared variable in place of the ThreadLocalStorage variable:

static bool s_inProgress = false;

bool PowerUpSelfTestInProgressOnThisThread()
{
#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
    return s_inProgress;
#endif
    return false;
}

void SetPowerUpSelfTestInProgressOnThisThread(bool inProgress)
{
#if CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2
    s_inProgress = inProgress;
#endif
}

Downloads

tls-socket.zip - Source files for classes ThreadLocalStorage, SocketSource, WindowsPipeSource, Socket, SocketSink, WindowsPipeSink removed at Commit f2171cbe2f49.