Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > PLEASE HELP - How do I include OpenSSL in my code?

Reply
Thread Tools

PLEASE HELP - How do I include OpenSSL in my code?

 
 
cpptutor2000@yahoo.com
Guest
Posts: n/a
 
      05-12-2006
Could some C guru please help me? I have a simple piece of code as:

#include <stdio.h>
#include <stdlib.h>
#include <openssl/rand.h>

int main(){
unsigned char temp[4];

RAND_bytes(temp, 4);
return 0;
}

If I type: whereis openssl
I get: openssl: /usr/bin/openssl /usr/include/openssl
/usr/share/man/man1/openssl.1ssl.gz

I compile this as:
gcc -g -o test test.c -I/usr/include/openssl -L/usr/bin/openssl

I get a linker error message as :
/tmp/cc4tQEqd.o(.text+0x1af0): In function `main':
/home/ecelrc/students/abanerj/cpp/test.c:6: undefined reference to
`RAND_bytes'

Could someone please point out what I am doing wrong? Any help would be
greatly
appreciated.

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      05-12-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) said:

> I get a linker error message as :
> /tmp/cc4tQEqd.o(.text+0x1af0): In function `main':
> /home/ecelrc/students/abanerj/cpp/test.c:6: undefined reference to
> `RAND_bytes'


You forgot to add -lssl to the end of your gcc line.

Strictly speaking, third party libs are off-topic in clc - but hey, I won't
tell if you don't.

Next time, though, try a Linux group, just to play safe. Here, we get all
antsy if it ain't ANSI.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      05-12-2006
(E-Mail Removed) wrote:
> Could some C guru please help me? I have a simple piece of code as:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <openssl/rand.h>


You're trying to get us into trouble, aren't you. Even if openssl were
on topic here, or if your implementation-specific question were on
topic, the language from the openssl site would scre me off:
> PLEASE REMEMBER THAT EXPORT/IMPORT AND/OR USE OF STRONG CRYPTOGRAPHY
> SOFTWARE, PROVIDING CRYPTOGRAPHY HOOKS OR EVEN JUST COMMUNICATING
> TECHNICAL DETAILS ABOUT CRYPTOGRAPHY SOFTWARE IS ILLEGAL IN SOME
> PARTS OF THE WORLD. SO, WHEN YOU IMPORT THIS PACKAGE TO YOUR COUNTRY,
> RE-DISTRIBUTE IT FROM THERE OR EVEN JUST EMAIL TECHNICAL SUGGESTIONS
> OR EVEN SOURCE PATCHES TO THE AUTHOR OR OTHER PEOPLE YOU ARE STRONGLY
> ADVISED TO PAY CLOSE ATTENTION TO ANY EXPORT/IMPORT AND/OR USE LAWS
> WHICH APPLY TO YOU. THE AUTHORS OF OPENSSL ARE NOT LIABLE FOR ANY
> VIOLATIONS YOU MAKE HERE. SO BE CAREFUL, IT IS YOUR RESPONSIBILITY.

 
Reply With Quote
 
Ben C
Guest
Posts: n/a
 
      05-12-2006
On 2006-05-12, (E-Mail Removed) <(E-Mail Removed)> wrote:
> Could some C guru please help me? I have a simple piece of code as:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <openssl/rand.h>
>
> int main(){
> unsigned char temp[4];
>
> RAND_bytes(temp, 4);
> return 0;
> }
>
> If I type: whereis openssl
> I get: openssl: /usr/bin/openssl /usr/include/openssl
> /usr/share/man/man1/openssl.1ssl.gz
>
> I compile this as:
> gcc -g -o test test.c -I/usr/include/openssl -L/usr/bin/openssl
>
> I get a linker error message as :
> /tmp/cc4tQEqd.o(.text+0x1af0): In function `main':
> /home/ecelrc/students/abanerj/cpp/test.c:6: undefined reference to
> `RAND_bytes'
>
> Could someone please point out what I am doing wrong? Any help would be
> greatly
> appreciated.


You need -l.

-L tells gcc where to look for libraries, -l tells it what libraries to
look in for symbols.

-lxxx means "look for a library called libxxx.a in the usual places".
You add places to "the usual places", if necessary, with -L.

The library you want is libssl.a and is quite likely in /usr/lib, where
gcc looks anyway, so -lssl with no -L option will probably do the trick:

$ gcc -g -o test test.c -I/usr/include/openssl -lssl

or also add -L/usr/lib/openssl (or something, depending on where
libssl.a is on your system) if you need it.

(gnu.gcc.help is the right NG for this by the way).
 
Reply With Quote
 
Andrew Poelstra
Guest
Posts: n/a
 
      05-13-2006
On 2006-05-12, Martin Ambuhl <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
>> Could some C guru please help me? I have a simple piece of code as:
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <openssl/rand.h>

>
> You're trying to get us into trouble, aren't you. Even if openssl were
> on topic here, or if your implementation-specific question were on
> topic, the language from the openssl site would scre me off:
>> [snipped]


It wouldn't scare me off, but seeing people posting solid walls of text
in all caps would.

My poor eyes...

Also, if you understood basic import/export cryptography laws, those
warnings would be warnings and you'd know how to avoid legal issues.
For example, there are no laws barring export between the US and
Canada that I know of, but to transfer cryposystems overseas you must
not use an electronic form.
 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      05-13-2006
Andrew Poelstra wrote:
> On 2006-05-12, Martin Ambuhl <(E-Mail Removed)> wrote:
>
>>(E-Mail Removed) wrote:
>>
>>>Could some C guru please help me? I have a simple piece of code as:
>>>
>>>#include <stdio.h>
>>>#include <stdlib.h>
>>>#include <openssl/rand.h>

>>
>>You're trying to get us into trouble, aren't you. Even if openssl were
>>on topic here, or if your implementation-specific question were on
>>topic, the language from the openssl site would scre me off:
>>
>>>[snipped]

>
>
> It wouldn't scare me off, but seeing people posting solid walls of text
> in all caps would.


On the other hand, changing the text from the openssl website to cater to

> My poor eyes...


would be dishonest. It is not the posting that is all caps, but the
quoted text.

> Also, if you understood basic import/export cryptography laws, those
> warnings would be warnings and you'd know how to avoid legal issues.


If you sufficiently understand these laws well enough to be sure of
avoiding problems (and the courts do not agree on what that
interpretation should be), then you should be getting the big bucks as a
corporate lawyer insted of programming.

> For example, there are no laws barring export between the US and
> Canada that I know of, but to transfer cryposystems overseas you must
> not use an electronic form.


Now you expect us to treat messages posted as somehow limited to the US
and Canada, and further to rely on your imperfect knowledge ("that I
know of"). Ephraim, you are a cake not turned.

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      05-13-2006
Andrew Poelstra said:

<snip>

> Also, if you understood basic import/export cryptography laws, those
> warnings would be warnings and you'd know how to avoid legal issues.
> For example, there are no laws barring export between the US and
> Canada that I know of, but to transfer cryposystems overseas you must
> not use an electronic form.


I've got news for you, folks - we already have strong crypto outside the
USA. We've had unbreakable crypto (albeit impractical for many purposes)
for almost a century, and almost-unbreakable public/private key for - well,
for just a few years longer than you.

And in any case, inventing a reasonably secure cryptosystem is, frankly,
trivial. The tricky bit is not the "technology" if that's the word, but the
usage - a great many ciphers are cracked not because they are inherently
weak but because they are misused.

The genie has been out of the bottle for a very long time.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      05-14-2006
In article <(E-Mail Removed)> ,
Andrew Poelstra <(E-Mail Removed)> wrote:
>Also, if you understood basic import/export cryptography laws, those
>warnings would be warnings and you'd know how to avoid legal issues.
>For example, there are no laws barring export between the US and
>Canada that I know of, but to transfer cryposystems overseas you must
>not use an electronic form.


There *are* laws controlling the export of cryptography from the US to
Canada. Those laws happen to say something on the order of, "providing
these conditions are met, no export permit is required" to export to
Canada, and that "providing these conditions are met, there is an
automatic export permit" to a small number of other countries. The
catch is in the "these conditions are met" portion.

For example, if a citizen of one of the six or so designated "hostile
countries" manages to legally reach the USA, then that citizen may
freely use strong cryptography *within the USA*, and that foreign
citizen may buy books, attend lectures, enter a cryptography PhD
program and so on -- as long as that foreign citizen does not -export-
the cryptographic programs.

I, a Canadian citizen, can buy and utilize US-originated strong
encryption programs within Canada (or to the USA or the other select
countries). However, the way the US export laws are written, if the
strong encryption program had been exported from the USA, then I [in
Canada] could not permit that same foreign citizen from using my copy
of the program, not even just to communicate within Canada between they
and I.


Now, it happens that some of our employees are from one of those
designated countries; and I am not permitted to discriminate against
any employee based upon country of origin, so my choice was effectively
to either be careful only to use cryptography that did not originate in
the USA, or else to not make cryptographic services routinely available
to any of our employees.

I did raise this point with our corporate security people at one point;
they believed that there was an exemption covering the situation, but
they did not have any justification available for such an exemption; I
gather that they casually asked someone who works for A Four Letter
Acronym {Three Letter Acronyms are for the USA } and were casually
told it wasn't a problem. (I preferred a stronger reassurance...)
--
All is vanity. -- Ecclesiastes
 
Reply With Quote
 
Andrew Poelstra
Guest
Posts: n/a
 
      05-14-2006
On 2006-05-13, Martin Ambuhl <(E-Mail Removed)> wrote:
> Andrew Poelstra wrote:
>> On 2006-05-12, Martin Ambuhl <(E-Mail Removed)> wrote:
>>
>>>(E-Mail Removed) wrote:
>>>
>>>>Could some C guru please help me? I have a simple piece of code as:
>>>>
>>>>#include <stdio.h>
>>>>#include <stdlib.h>
>>>>#include <openssl/rand.h>
>>>
>>>You're trying to get us into trouble, aren't you. Even if openssl were
>>>on topic here, or if your implementation-specific question were on
>>>topic, the language from the openssl site would scre me off:
>>>
>>>>[snipped]

>>
>>
>> It wouldn't scare me off, but seeing people posting solid walls of text
>> in all caps would.

>
> On the other hand, changing the text from the openssl website to cater to
>

He needed neither to change the text or to quote it at all.

>> My poor eyes...

>
> would be dishonest. It is not the posting that is all caps, but the
> quoted text.

I know; but on the site I can set stylesheets so that the colors aren't
so painful (slrn put the post in red on black).

>> Also, if you understood basic import/export cryptography laws, those
>> warnings would be warnings and you'd know how to avoid legal issues.

>
> If you sufficiently understand these laws well enough to be sure of
> avoiding problems (and the courts do not agree on what that
> interpretation should be), then you should be getting the big bucks as a
> corporate lawyer insted of programming.
>

See below.

>> For example, there are no laws barring export between the US and
>> Canada that I know of, but to transfer cryposystems overseas you must
>> not use an electronic form.

>
> Now you expect us to treat messages posted as somehow limited to the US
> and Canada, and further to rely on your imperfect knowledge ("that I
> know of"). Ephraim, you are a cake not turned.
>

"For example" does not mean "As applies to everyone here". US/Canada is
the border that concerns me personally the most, but I'm in no way
speaking for everyone.
 
Reply With Quote
 
Andrew Poelstra
Guest
Posts: n/a
 
      05-14-2006
On 2006-05-13, Richard Heathfield <(E-Mail Removed)> wrote:
> Andrew Poelstra said:
>
><snip>
>
>> Also, if you understood basic import/export cryptography laws, those
>> warnings would be warnings and you'd know how to avoid legal issues.
>> For example, there are no laws barring export between the US and
>> Canada that I know of, but to transfer cryposystems overseas you must
>> not use an electronic form.

>
> I've got news for you, folks - we already have strong crypto outside the
> USA. We've had unbreakable crypto (albeit impractical for many purposes)
> for almost a century, and almost-unbreakable public/private key for - well,
> for just a few years longer than you.
>

Yes, I'm well aware of that.

> And in any case, inventing a reasonably secure cryptosystem is, frankly,
> trivial. The tricky bit is not the "technology" if that's the word, but the
> usage - a great many ciphers are cracked not because they are inherently
> weak but because they are misused.
>

True; of course, most people who hear that believe that ciphertext[i] =
plaintext[i] ^ 5 is a "reasonably secure cryptosystem". I prefer to say
simply that only cryptographers can make decent ciphers. It saves me
from every having to debug a homebrew one.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Ruby and OpenSSL: no such file to load -- openssl (RuntimeError) Redd Vinylene Ruby 6 11-18-2008 08:51 AM
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
help please - openssl and ruby Chris Catton Ruby 2 12-31-2006 02:29 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments