[botan-devel] Exception when doing multithreaded signing

Jack Lloyd lloyd at randombit.net
Tue Jun 7 10:19:08 EDT 2011


On Tue, Jun 07, 2011 at 10:02:33AM -0400, Jack Lloyd wrote:

> 
> Can you send me a copy of the source? Offlist is fine.

I tried to replicate (attempt attached), but no luck so far.
-------------- next part --------------
#include <thread>
#include <botan/botan.h>
#include <botan/pubkey.h>
#include <botan/rsa.h>
#include <iostream>

using namespace Botan;

void sign()
   {
   try
      {
      AutoSeeded_RNG rng;
      RSA_PrivateKey key(rng, 1024);

      PK_Signer signer(key, "EMSA3(Raw)");
      PK_Verifier verify(key, "EMSA3(Raw)");

      for(size_t i = 0; i != 10000; ++i)
         {
         byte hash[20];
         rng.randomize(hash, sizeof(hash));

         SecureVector<byte> sig = signer.sign_message(hash, sizeof(hash), rng);

         bool ok = verify.verify_message(hash, sizeof(hash),
                                         &sig[0], sig.size());

         if(!ok)
            std::cout << "FAIL\n";
         }
      }
   catch(std::exception& e)
      {
      std::cout << e.what() << "\n";
      }
   }

int main()
   {
   try
      {
      LibraryInitializer init("thread_safe=true");

      std::vector<std::thread> threads;
      for(size_t i = 0; i != 8; ++i)
         {
         std::thread t(sign);
         threads.push_back(std::move(t));
         }

      for(size_t i = 0; i != threads.size(); ++i)
         threads[i].join();
      }
   catch(std::exception& e)
      {
      std::cout << e.what() << "\n";
      }
   }


More information about the botan-devel mailing list