Search code examples
c++sslcrypto++diffie-hellman

Load/Export RandomNumber


In the frame of an home-made ECDHE application, both the client and the server have to send a randomly generated numbers (rng), in order to build later the MasterSecret during the handshake (TLS-like)...

With crypto++, it's easy to create these numbers, thanks to :

AutoSeededRandomPool rng;

My problem is 1) to export them to a string or equivalent, and 2) to load them from a string.

I must put these numbers within a frame, and nor the Class definition, nor the examples precise that.

On the web I haven't been able to find Save/Load examples (like the ones for RSA::PublicKeys).

Apparently I'm the first to want this, as their examples generate the client and the server in the same program, and thus don't need to transmit the numbers.

And, as part of this handshake, I also try to do the same with curvesID...


Solution

  • This question was a misunderstanding from my part, so I'll explain it, in case of anyone having the same interrogations. It's largely inspired from the crypto++ wiki...

    There are 2 distinct objects :

    AutoSeededRandomPool prng;
    
    prng.GenerateBlock( scratch, scratch.size() );
    

    AutoSeededRandomPool prng; is the generator of random numbers (that will be auto-seeded)

    prng.GenerateBlock is the command that will extract bits from this random number to build the std::string scratch of the desired length.

    And as the scratch is a string, we can do what we want with it, to use it anywhere... So please refer to the string import/export.