[Botan-devel] Is Botan TrippleDES "TripleDES/ECB" thread safe?

Jack Lloyd lloyd at randombit.net
Wed Mar 21 10:50:35 EDT 2007


On Wed, Mar 21, 2007 at 02:34:21PM +0000, Brian Mitchell wrote:
> Hi,
> 
> 	Im using botan to perform Triple DES calculations in a tcpip server.
> Each new connection is run in a new thread. When I hit the server with 
> multiple simultainious connections, I'm sometimes getting this error.
> 
> "terminate called after throwing an instance of 
> 'Botan::Default_Mutex_Factory::make()::Default_Mutex::Mutex_State_Error'
>   what():  Botan: Internal error: Default_Mutex::lock: Mutex is already locked
> Aborted"
> 
> Does anyone know what it means, and do I need to put a mutex lock around my 
> triple des calculations?

No, not directly. This is being thrown by the default mutex stubs
(which don't actually perform any locking, since they are only
supposed to be used in single-threaded code, but do provide some error
checking, specifically to detect the cases where they should not be
used).

First, you have to have some other mutex factory set up with the
library. POSIX threads and Win32 critical sections are supported
already, in the mux_pthr and mux_win32 modules. Others are easy to add
from application code without requiring a library rebuild, if you're
using something exotic. You can check if any of the included ones are
enabled in your build by looking for the BOTAN_EXT_MUTEX_* macros in
<botan/build.h>

Then include 'thread_safe' in the string passed to LibraryInitializer, eg

  LibraryInitializer init("thread_safe <maybe_other_options_here>");

LibraryInitializer will throw an exception if you pass thread_safe and
it can't find a real/working mutex module.

The actual exception is coming from using shared state; the most
likely being the RNG or the memory allocator.

I should add that you do need explicit locking in your code if you
wanted to share a single TripleDES object between two threads (but I
wouldn't consider that a good idea).

-Jack


More information about the botan-devel mailing list