I would like to generate a key which would be good enough to be used for encryption with AES in a mobile environment. My idea is to use as a seed ''random attributes'' from a mobile device. Is hashing first this seed using HMAC construction (with some salt which is also random but public) and then use a HMAC-based Key Derivation function secure and efficient?
Asked
Active
Viewed 884 times
4
1 Answers
3
If you have plenty entropy in your "seed" then just use a KBKDF such as HKDF. If you have somewhat less, use a PBKDF such as PBKDF2. Both HKDF and PBKDF2 can take a salt as input parameter and are already using a HMAC internally.
There is no need to perform a HMAC beforehand. If you do, you would have to specify what data is used as key for the HMAC primitive.
If you just need a random key, use a well seeded CSPRNG (possibly just the one that the runtime supplies, the OS usually has most access to entropy sources).

Maarten Bodewes
- 92,551
- 13
- 161
- 313
/dev/urandom
) is providing you with high-entropy randomness, there's nothing further to do. If you only have access to a low-entropy RNG (e.g., Crand
), there may be nothing you can do; at absolute best, you can you use a key stretching algorithm like PBKDF2 or scrypt to linearly increase the effective cost of an attacker brute-forcing the key to simulate higher entropy. – Stephen Touset Jul 29 '14 at 00:54