This worked..Thanks a million. :-)

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Allan E. Johannesen
Sent: Monday, April 24, 2006 6:32 PM
To: openssl-users@openssl.org
Subject: Random Number Generation in openssl


>>>>> "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                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to