Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

Is it good to use a mouse movement as a 64-bit random seed for a Pseudorandom Generator like AES in Counter Mode?

Should I only need to get the X and Y coordinates of the mouse movement?

share|improve this question
1  
Why don't you just use the random number generator built into your operating system? –  CodesInChaos Jul 26 '12 at 11:01
2  
A 64 bit seed is far too small to be secure. And a single mouse position doesn't even have close to 64 bits of entropy. It doesn't even have 20 bits of entropy. –  CodesInChaos Jul 26 '12 at 11:03
1  
@goldroger, accepting answers is beneficial to you and to the person who wrote the answer. When you accept an answer, you get reputation points. Similarly, the person who wrote the answer you accept also gets reputation points. –  mikeazo Jul 26 '12 at 11:58
2  
@goldroger: Your accept rate is the percentage of your questions with an accepted answer, counting only non-closed questions which have at least one upvoted answer. It might be a good idea to look at the old questions to see if there is an acceptable answer, or, if there is none, add information to the question which might make it easier to answer. But don't feel obligated to accept answers if they actually are not helpful enough just to increase the accept rate. (Oops, ninja'ed.) –  Paŭlo Ebermann Jul 26 '12 at 11:58
4  
@woliveirajr: If you really feel a need to point someone to his accept rate, please try to do it in a a bit more friendly form, also giving some information like just by me and mikeazo, not just "improve your accept rate". We try to be a friendly and welcoming community here. –  Paŭlo Ebermann Jul 26 '12 at 12:03
show 3 more comments

2 Answers

up vote 3 down vote accepted

I suppose as far as entropy sources go, you could have chosen much, much worse. In fact a user properly moving his mouse while you collect a bunch of samples and hash them all together to obtain a seed is a pretty good random bit generator. Be conservative in your entropy estimates, for instance I would estimate no more than two bits of entropy per sample if you collect them intelligently (e.g. avoid continuous duplicates and keep a reasonably large sampling rate).

However obviously, a single mouse position is a terrible seed to use, since it doesn't even cover the whole 64-bit space. Your monitor is probably at best 1920x1080, which corresponds to about 2 million possible positions. WEAK.

But while this may be useful to keep in mind, it's probably best if you use an existing CSPRNG for your randomness needs, that way you don't bother the user, and you delegate security to someone else (which may be a good or a bad thing). You should always use the CSPRNG provided by your operating system as it is best placed to collect entropy, whether you like it or not. Under Windows, you can use CryptGenRandom() to access it.

It might seem counterproductive to use another RNG to seed your own, but entropy collection isn't exactly a trivial little thing that you just plug into a program. It has to be carefully and constantly monitored and tracked to keep a good estimate of the available entropy and ensure you don't lose any of it. Sure, making your own ultrafast PRNG using AES in counter mode for your specific needs might be worth it, but you need to consider the limits of your own random generator.

share|improve this answer
add comment

There are a few questions here.

  • Are mouse movements a good entropy source? In general no, but there are a number of programs that will ask the user to move the mouse randomly, sample the position at intervals, and use many samples as a source of entropy for random number generation.

  • Can you use mouse movement as the nonce in CTR mode? You shouldn't use a single mouse position as the nonce as there is not enough entropy. You could potentially use a process similar to what I describe in the first part of my answer to build up enough entropy to generate a good nonce, but since most all modern operating systems have a good random number generator built in, why not use that?

  • Is 64 bits enough? This totally depends on other factors of the system. For example, how often do you re-key. Repeating the same nonce with the same key will have devastating results. So, if you re-key every session, 64 bits is plenty. IPSEC ESP uses a 32 bit nonce for AES-CTR. Some of this also depends on how you combine the nonce with the counter. A large nonce concatenated with a small counter has it's benefits and disadvantages. You could use XOR or addition as other methods of combining the two.

  • Do you only need X and Y coordinates? I am not exactly sure what you are proposing here. If you are asking if X,Y coordinates are sufficient for securely generating a nonce, the answer is that it depends on how you do it exactly. Ideally, you should take many samples after requesting that the user move the mouse randomly. Modern PRNGs, however, use many entropy sources for security reasons. You'd be better off using modern PRNGs and specifically, not trying to reinvent the wheel when tried and tested solutions already exist.

share|improve this answer
    
do you think RNGCryptoServiceProvider Class is effective in generating a random value? –  goldroger Jul 26 '12 at 12:12
    
@goldroger, yes. –  mikeazo Jul 26 '12 at 12:15
    
is there any proof the RNGCryptoServiceProvider Class is generating a secured random value? –  goldroger Jul 26 '12 at 12:18
1  
@goldroger, I am not aware of a security proof. There are some CSPRNGs which are provably secure. I'd be surprised if this particular class uses one of those as they tend to be too slow. The only evidence we have that it is secure is that no one has published a break. This might not sound good enough, but it is the same as what we have for AES, SHA, and many other cryptographic functions available today. –  mikeazo Jul 26 '12 at 12:25
    
@goldroger RNGCryptoServiceProvider is far better than anything you might come up with on your own. (This isn't meant as disparagement: it's better than what I'd come up with too.) –  Gilles Jul 27 '12 at 13:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.