Getting openssl working with beaglebone black (BBB)

Today I needed to use MD5 in a C program on my BBB (running Angstrom) therefore I looked into openssl.
All seemed straight forward until I realised that my cross compiler tool chain did not include an arm version of the libssl library.

Note: Among other great tutorials, installing an ARM cross compiler chain is covered by Derek Molloy (see here).

After lots of searching, it seemed the only solution was to get hold of the openssl source and cross compile it myself.
Here’s how to do it:

wget http://www.openssl.org/source/openssl-1.0.0d.tar.gz
tar xvxf openssl-1.0.0d.tar.gz
cd openssl-1.0.0d
make CC=”arm-linux-gnueabi-gcc” AR=”arm-linux-gnueabi-ar r”

now you should have two new files called
libcrypto.a
libssl.a

Copy these to /usr/arm-linux/gnueabi/lib

now in Eclipse, view the project properties and under “GCC C++ Linker” section, click on “Libraries” and then in the “Libraries” display area, click on the add icon and type crypto. Once that is saved, compile the main program and all should go well.

If you want an MD5 test program, here is one:

#include <openssl/md5.h>
#include <unistd.h>

//---------------------------------------------------------------
int main(int ac, char **av)
//---------------------------------------------------------------
{
  int n;
  MD5_CTX c;
  char buf[512];
  ssize_t bytes;
  unsigned char out[MD5_DIGEST_LENGTH];

  bytes = sprintf(&buf[0], "this is a test");

  MD5_Init(&c);
  MD5_Update(&c, buf, bytes);
  MD5_Final(out, &c);

  for(n=0; n < MD5_DIGEST_LENGTH; n++)
  {
   fprintf(stdout, "%02x", out[n]);
  }

  fprintf(stdout, "\n");

  return 0;
}

You can run that on the bone to see the MD5 result which should be 54b0c58c7ce9f2a8b551351102ee0938

If you want to check it is right, you can do so in an ssh terminal using:

echo -n “this is a test” | md5sum

5 Responses to Getting openssl working with beaglebone black (BBB)

  • Thomas Cox says:

    I tried following your directions from the web site. At the make step, I get the error message make: *** No rule to make target `r”’. Stop.

    Could there be a typo here? Any help would be appreciated.

    • Martin says:

      Sorry, no, it should be as above. Try it with the ” double quotes replaced with single ‘ quotes.
      make CC=’arm-linux-gnueabi-gcc’ AR=’arm-linux-gnueabi-ar r’

    • Martin says:

      Further to my reply – the blog seems to be changing the quotes. Either type the line yourself or copy/paste it then replace the quotes yourself :-)
      Let me know if it now works for you…

  • Thomas Cox says:

    Single quotes worked. Thanks for the suggestion.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>