OpenSSL with gcc on OS X 10.7

I am using TextEdit and gcc for OS X 10.7 to build small terminal programs. I'm trying to learn how to program OpenSSL, but I have a compilation of dramas (due to a legacy issue - below). I've googled and searched on SO, but everything I've read is either up to 2011 (when the problem occurred), specific to iOS (I'm programming for OS X, but trying to be platform independent), or it talks about using XCode (which has I'm not here - I prefer TextEdit).

Can anyone point in the right direction with a simple step-by-step process for installing an OpenSSL program on OS X using gcc?

For the record, these are the exact steps I took:

  • OpenSSL installed via macports

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

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

  • I renamed to 'aes.c' and I use 'gcc -o aes aes.c'

  • I've tried the following flags (no result): -lcrypto, lssl, -Wno-error = debrecated-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)

      

+1


source to share


1 answer


Deprecation warnings are only warnings and can be ignored. The real problem is that the compiler doesn't see the declaration of a macro AES_BLOCK_SIZE

that is defined as aes.h

. Therefore you need to add #include <openssl/aes.h>

to your source code.



You also need to enable the linker flag -lcrypto

to link with the OpenSSL runtime library; otherwise you will get a bunch of "undefined reference" errors.

+2


source







All Articles