Thread: openssl/RAND_bytes

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    27

    openssl/RAND_bytes

    Im experimenting with openssl for homework and I need to generate a 1024 bit file. I know you can use RAND Bytes for this,but im not entirely sure how.

    As an example,
    int RAND_bytes(unsigned char *buf, int num);


    would all i need to do is put in 1024 or would more be needed?

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Do you know the difference between a Bit and a Byte?

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    27
    Quote Originally Posted by memcpy View Post
    Do you know the difference between a Bit and a Byte?
    I'm aware,what I mean is where I need to set any parameters into the rand bytes function,or just leave it alone? Yes,I'm aware I'm slow on the uptake where it comes to programming. But a straightforward answer would be most appreciated.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What does the documentation say about RAND_bytes?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Seriously, OP, first hit on Google for "RAND_bytes" (I didn't even bother to include OpenSSL in the search terms):

    OpenSSL: Documents, RAND_bytes(3)

    RAND_bytes(buf, num) "puts num cryptographically strong pseudo-random bytes into buf."

    If you want 1024 random BYTES, you'd use RAND_bytes(buf, 1024); with a suitable buffer (which would need to be AT LEAST 1024 bytes long before you started).

    I'd consider this a first strike at an obvious question with an even-more-obvious answer that's easily searchable. These sorts of posts just annoy people.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    27
    Quote Originally Posted by ledow View Post
    Seriously, OP, first hit on Google for "RAND_bytes" (I didn't even bother to include OpenSSL in the search terms):

    OpenSSL: Documents, RAND_bytes(3)

    RAND_bytes(buf, num) "puts num cryptographically strong pseudo-random bytes into buf."

    If you want 1024 random BYTES, you'd use RAND_bytes(buf, 1024); with a suitable buffer (which would need to be AT LEAST 1024 bytes long before you started).

    I'd consider this a first strike at an obvious question with an even-more-obvious answer that's easily searchable. These sorts of posts just annoy people.
    thanks dude
    Last edited by kakashi316; 03-21-2012 at 09:40 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Openssl Pipes with C Help?
    By Sundown G in forum C Programming
    Replies: 3
    Last Post: 02-13-2012, 06:38 PM
  2. Need help with OpenSSL
    By Ricardo_R5 in forum C Programming
    Replies: 0
    Last Post: 05-07-2007, 06:18 PM
  3. Using OpenSSL with Dev-C++
    By Smiley10 in forum C Programming
    Replies: 2
    Last Post: 07-08-2006, 10:27 AM
  4. OpenSSL and Win32 SSL API :: SSL/TLS
    By kuphryn in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-10-2004, 07:46 PM