I am using M2Crypto for generating PKCS#7 signatures. M2Crypto's example code includes a line to seed OpenSSL's PRNG from a file:
from M2Crypto import BIO, Rand, SMIME
def makebuf(text):
return BIO.MemoryBuffer(text)
# Make a MemoryBuffer of the message.
buf = makebuf('a sign of our times')
# Seed the PRNG.
Rand.load_file('randpool.dat', -1)
# Instantiate an SMIME object; set it up; sign the buffer.
s = SMIME.SMIME()
s.load_key('signer_key.pem', 'signer.pem')
p7 = s.sign(buf, SMIME.PKCS7_DETACHED)
My application is initializing an SMIME context and using it to sign multiple messages. From the above code, it is not clear how I should be seeding the PRNG.
- Should I seed once at application startup, or before each signature?
- What should I use as an entropy source?
OpenSSL's documentation indicates that:
On systems that provide /dev/urandom, the randomness device is used to seed the PRNG transparently.
But another documentation page states:
The
urandomdevice may lack sufficient entropy for your needs, and you might want to reseed it immediately from/dev/random.
There's also RAND_status(), which is supposed to indicate whether "the PRNG has been seeded with enough data", but it's not clear what this means for practical purposes.
Aucun commentaire:
Enregistrer un commentaire