PDA

View Full Version : The unique key



igor.alexandrov
15th January 2008, 22:24
Hello all :) Sorry for my English, i am from Russia :))
I have got a problem. I need a crossplaform method to generate some unique per machine key. I will use it in my RC4 crypt algorithm as a crypt key.
In Windows, I know, there is something like WinId, but what to do in Linux and Mac?
Thanks :)

marcel
15th January 2008, 22:29
WinId is the platform window handle id, and it most certainly will not be unique between sessions.

For your need QUuid is more suitable.

igor.alexandrov
15th January 2008, 22:39
I know about QUuid, but i also keno that it is not cryptographic-quality random number generator.

marcel
15th January 2008, 22:45
I know about QUuid, but i also keno that it is not cryptographic-quality random number generator.
And how is WinId better than a GUID?

If you want to use "cryptographic-quality random number generator" then take a look at libgcrypt at http://www.gnupg.org/

igor.alexandrov
15th January 2008, 22:51
No, no, I really don't think that WinId is better then QUuid. It was just an example :) About GnuPG, thanks, I forget about it.

wysota
16th January 2008, 09:50
Just generate a large random number and test it for being prime. You don't need Qt for that.

Thomas
25th January 2008, 21:45
I know it is a bit late, but...

If it is just about a random number, Linux has a two very nice devices which provide you with entropy based rand numbers. Check the man page (man urandom). If it is about random uuids, read the (publicly readable) file /proc/sys/kernel/random/uuid. This file creates on every read access a new random uuid.

Cheers,
Thomas

wysota
26th January 2008, 00:51
I just read the original question again. You are using RC4, so your large number doesn't even have to be prime. If you want a custom random number generator, you can find some in "Numerical Recipes in C".

Thomas
26th January 2008, 00:57
I just read the original question again. You are using RC4, so your large number doesn't even have to be prime. If you want a custom random number generator, you can find some in "Numerical Recipes in C".

But the code in Numerical Recipies is not free, so it limits the usage pretty much. For instance the project I am working for cannot use those code snippets because our software is GPL.

wysota
26th January 2008, 01:27
Who said you should take the code? The algorithm is what is important, the code can be written from scratch. Once you get a grip of how random number generators work (that they are shift registers with feedback), you can design (and implement) your own.