# Algorithm to generate ECDSA keys with random number generator

I have a certified random number generator (TRNG, it does not matter what it is for the question).

I would like to use it as a source to generate secp384r1 ECDSA keys. What is the algorithm I should use? Is it possible?

I know that it is generally not a good idea to implement one's own cryptographic algorithms, so is there any library that can be used for this? (something like Bouncy Castle?)

• This probably depends on how the TRNG interfaces with the host computer. Depending on the details a crypto library may technically be able to use it as an (additional) randomness source. – SEJPM Feb 6 '18 at 21:18

Many libraries allow you to specify your own random number generator. In BouncyCastle, for example, you can specify a SecureRandom in the initialize method of the KeyPairGenerator class; while in Go you can specify a io.Reader to the GenerateKey function.
Therefore, you would need to write a class that implements SecureRandom or io.Reader and reads the specified number of bytes from your TRNG, assuming your TRNG actually produces uniformly distributed random output. Be careful though, if you mess it up, the whole security of your system is compromised.
(A safer approach would be to make a program that reads from the TRNG and writes to /dev/random, mixing up the system PRNG, assuming it's Linux)
• Thank you. SecureRandom implementation with appropriate provider that can handle my TRNG is working. – user1563721 Feb 7 '18 at 16:40
Sure thing, you can use any NIST SP-800-90A compatible provider. There are a few available from Bouncy Castle in SP800SecureRandomBuilder. Depending on how you plan to retrieve the entropy from your TRNG, it may be required to implement an EntropySource and EntropySourceProvider, of course.