Random number generation always depends on the PRNG
being seeded first.
The man page clearly mentions that.
Add RAND_seed() or RAND_add() with the required
entropy required before calling RAND_bytes(). In a
pseudorandom number generator the seed uniquely
determines the random sequence. So you might want to
vary the seed somehow using getpid() or gettimeofday()
or better, using /dev/random or /dev/urandom.
And random number generation has to be verified to
make sure that what you are getting is truly random.
All the best!
regards,
Girish
--- "Allan E. Johannesen" <[EMAIL PROTECTED]> wrote:
> >>>>> "ambarish_mitra" == Ambarish Mitra
> <[EMAIL PROTECTED]> writes:
>
> ambarish_mitra> Hi all, I am trying to generate
> random numbers using openssl. I
> ambarish_mitra> am not using the ENGINE API, but
> using only the rand functions.
>
> ambarish_mitra> Code snippet:
>
> You correctly identify the buffer as unsigned char,
> but then you deal with it
> as if it was a NUL terminated string.
>
> Perhaps:
>
> r = RAND_bytes(buf, strlen(buf));
> printf("random status: %d\n",r);
> printf("random number: [%s]\n",buf);
>
> Might be:
>
> r = RAND_bytes(buf, sizeof(buf));
> printf("random status: %d\n",r);
> printf("random number: ");
> for (r = 0; r < sizeof(buf); r++)
> {
> printf("%02x" buf[r]);
> };
> printf("\n");
>
> Note that strlen won't work on an undefined,
> unsigned char, probably giving 0,
> which is the beginning of the trouble.
>
______________________________________________________________________
> OpenSSL Project
> http://www.openssl.org
> User Support Mailing List
> [email protected]
> Automated List Manager
> [EMAIL PROTECTED]
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [EMAIL PROTECTED]