1

I use TextEdit and gcc on OS X 10.7 to make small terminal programs. I'm trying to learn how to program OpenSSL, but I'm having dramas compiling (due to the deprecated issue - more below). I've Googled and searched on SO but everything I read is either pre-2011 (when the issue seemed to appear), specific to iOS (I'm programming for OS X but trying to be platform independent) or talks about using XCode (which I don't - I prefer TextEdit).

Can anyone please point in the right direction of a simple, step-by-step process for how to install an OpenSSL program on OS X using gcc?

For the record, this is the exact steps I have taken:

  • OpenSSL installed via macports

  • 'openssl version' returns "OpenSSL 1.0.1e 11 Feb 2013"

  • I'm trying to compile this file: http://saju.net.in/code/misc/openssl_aes.c.txt

  • I've renamed to 'aes.c' and I'm using 'gcc -o aes aes.c'

  • I've tried the following flags (for no result): -lcrypto, lssl, -Wno-error=deprecated-declarations

The specific output I get from gcc is the following:

Brads-MacBook-Air:Desktop brad$ gcc -o aes aes.c -lssl -lcrypto -Wno-error=deprecated-declarations
aes.c: In function ‘aes_init’:
aes.c:30: warning: ‘EVP_BytesToKey’ is deprecated (declared at /usr/include/openssl/evp.h:572)
aes.c:30: warning: ‘EVP_aes_256_cbc’ is deprecated (declared at /usr/include/openssl/evp.h:786)
aes.c:30: warning: ‘EVP_sha1’ is deprecated (declared at /usr/include/openssl/evp.h:666)
aes.c:36: warning: ‘EVP_CIPHER_CTX_init’ is deprecated (declared at /usr/include/openssl/evp.h:636)
aes.c:37: warning: ‘EVP_EncryptInit_ex’ is deprecated (declared at /usr/include/openssl/evp.h:581)
aes.c:37: warning: ‘EVP_aes_256_cbc’ is deprecated (declared at /usr/include/openssl/evp.h:786)
aes.c:38: warning: ‘EVP_CIPHER_CTX_init’ is deprecated (declared at /usr/include/openssl/evp.h:636)
aes.c:39: warning: ‘EVP_DecryptInit_ex’ is deprecated (declared at /usr/include/openssl/evp.h:590)
aes.c:39: warning: ‘EVP_aes_256_cbc’ is deprecated (declared at /usr/include/openssl/evp.h:786)
aes.c: In function ‘aes_encrypt’:
aes.c:51: error: ‘AES_BLOCK_SIZE’ undeclared (first use in this function)
aes.c:51: error: (Each undeclared identifier is reported only once
aes.c:51: error: for each function it appears in.)
aes.c:55: warning: ‘EVP_EncryptInit_ex’ is deprecated (declared at /usr/include/openssl/evp.h:581)
aes.c:59: warning: ‘EVP_EncryptUpdate’ is deprecated (declared at /usr/include/openssl/evp.h:583)
aes.c:62: warning: ‘EVP_EncryptFinal_ex’ is deprecated (declared at /usr/include/openssl/evp.h:584)
aes.c: In function ‘aes_decrypt’:
aes.c:75: error: ‘AES_BLOCK_SIZE’ undeclared (first use in this function)
aes.c:77: warning: ‘EVP_DecryptInit_ex’ is deprecated (declared at /usr/include/openssl/evp.h:590)
aes.c:78: warning: ‘EVP_DecryptUpdate’ is deprecated (declared at /usr/include/openssl/evp.h:592)
aes.c:79: warning: ‘EVP_DecryptFinal_ex’ is deprecated (declared at /usr/include/openssl/evp.h:594)
aes.c: In function ‘main’:
aes.c:136: warning: ‘EVP_CIPHER_CTX_cleanup’ is deprecated (declared at /usr/include/openssl/evp.h:637)
aes.c:137: warning: ‘EVP_CIPHER_CTX_cleanup’ is deprecated (declared at /usr/include/openssl/evp.h:637)
Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589
user3081739
  • 65
  • 1
  • 1
  • 7
  • Usually, you avoid Apple's 0.9.8 version of OpenSSL. It lacks TLS 1.1 and 1.2, it lacks full support of EC, etc. To build OpenSSL on OS X, see [Compilation and Installation](https://wiki.openssl.org/index.php/Compilation_and_Installation) on the OpenSSL wiki. I wrote the OS X instructions, so I know they work. – jww May 15 '15 at 20:48

1 Answers1

2

The deprecation warnings are just that, warnings, and can be ignored. The real problem is that the compiler can't see the declaration of the AES_BLOCK_SIZE macro, which is defined to aes.h. So you need to add a #include <openssl/aes.h> to your source code.

You'll also need to include the -lcrypto linker flag to link against the OpenSSL runtime library; otherwise, you'll get a bunch of "undefined reference" errors.

Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589
  • Thanks Adam - I've added the extra include and now the program compiles. When I run it though I get a segmentation fault... but at least it compiles... :) Thanks again! – user3081739 Jan 09 '14 at 05:36
  • With that compile line it is **not** using the macports version of the ssl library, but the OS supplied one. The OS supplied one is where the deprecation warnings are coming from – Anya Shenanigans Jan 09 '14 at 08:06
  • Hi Petesh - can you please expand on that? How do I get it to use the most current one? Thanks! – user3081739 Jan 10 '14 at 00:39