Steps for Porting OpenSSL For Android

Steps for porting the OpenSSL For Android


1) Android NDK (latest is recommended)
2) Cygwin with shell support for windows


1) Download the latest open ssl code from the
2) Unzip the file and configure for the android by executing the Configure command

./Configure android-armv7 -DL_ENDIAN  (or)
./Configure android-x86 -DL_ENDIAN    (or)
./Configure android -DL_ENDIAN

You can remove the modules which you want by adding those directives in the Configure command 

./Configure linux-generic32 no-idea no-bf no-cast no-seed no-md2 -DL_ENDIAN

3) Create an updated file which contains the CFLAG and DEPFLAG of the makefile in the root (first) folder. Make sure to add all the -D flags to  LOCAL_CFLAGS, except -DTERMIO; include -DOPENSSL_NO_HW in addition to these. Anyway its better to include all the -DOPENSSL_NO_xxx flags as well, but it not important as those will be replicated in the file crypto/opensslconf.h when ./Configure is executed.

4) Copy the new LICENSE file from OpenSSL distribution as NOTICE.
   Create an empty MODULE_LICENSE_BSD_LIKE file

5)You may delete the following directories along with their contents,
   since we won't use these (any more):

     MacOS Netware VMS apps/demoCA apps/set bugs certs crypto/bf crypto/cast  \
     crypto/cms crypto/idea crypto/md2 crypto/rc5 crypto/seed demos doc \
     engines ms os2 perl shlib test times tools util

   Also you may delete the following files:

     CHANGES CHANGES.SSLeay ChangeLog.0_9_7-stable_not-in-head                \
     ChangeLog.0_9_7-stable_not-in-head_FIPS Configure FAQ INSTALL            \
     INSTALL.W32 INSTALL.W64 INSTALL.WCE LICENSE Makefile Makefile.bak        \ Makefile.shared NEWS PROBLEMS README README.ASN1            \
     README.ENGINE apps/ config crypto/opensslconf.h.bak             \ openssl.doxy openssl.spec

If any modules is required for your project specific purpose retain those folders.

6) Go to include/openssl.  There's a bunch of symlinks here.  Since symlinks
   can be a special case for version control, replace them by regular files:

      for l in *.h; do cp $l copy_$l; rm $l; mv copy_$l $l; done

   Some symlinks will remain, pointing to files that don't exit
   (you deleted those in step d).  Delete the symlinks.

7) Create files based on those you find in the previous OpenSSL port:


   For the latter three, merge in any substantial changes between the
   corresponding Makefiles in the OpenSSL distribution (apps/Makefile,
   crypto/Makefile, crypto/*/Makefile, ssl/Makefile).
   Don't forget to update the directory name for OpenSSL in these files
   and whereever else it is used.

Check the makefiles and add if we have any missed files. Don't add all the missed files as it may cause redefinition error during linking.
Don't blindly copy the makefiles from the existing android ported code. Some files need to be added if missing from the new makefiles.

8) Generate the asm files for your particular architecture type using the perl scripts which are already present in the asm folders of the OpenSSL.
Ex:   # Generate asm
  perl crypto/aes/asm/         > crypto/aes/asm/aes-armv4.S
  perl crypto/bn/asm/         > crypto/bn/asm/armv4-mont.S
  perl crypto/sha/asm/  > crypto/sha/asm/sha1-armv4-large.S
  perl crypto/sha/asm/      > crypto/sha/asm/sha256-armv4.S
  perl crypto/sha/asm/      > crypto/sha/asm/sha512-armv4.S

9) During facing compilation issue, we may have to
 a) Change the include path of the header files in the source (.c or .cpp) files.
 b) Disable some of the mains for the removed modules of those #defines are not properly enabled
     Ex: #if 0 /* ANDROID */
         For removing the ts_main in the ..../openssl/apps/progs.h
  c) May face some of the undefined reference errors, search in the source files for the definition where it is present and include in compilation if required or else if that module has been removed then comment it.

10) If compilation is gone through you will find the .so files got generated.

Happy porting :).

Ported Code:

References: (Courtesy)

Credit to the below guy


Colm Malone said...

Thanks for the invaluable port! It's been a life-saver for many of our projects.
FYI the github link at the bottom of the article has a typo (one too many S's) it should be:

Suman said...

Thanks for the comments :). Corrected the github link.

Ahmed said...

I have downloaded OpenSSL1.0.1cForAndroid-master from your git and I am using Ubuntu 12.10. Could you please tell how to compile it finally? Which environment variables must be set? $CROSS_COMPILE ? What else? And than just type make in the OpenSSL1.0.1cForAndroid-master/ssl directory?

Bogdan Chifor said...

I downloaded your project from github but I have a question.Why does not have the CMS feature and how can I add it?
Thank you.

Bogdan Chifor said...

I downloaded your openssl 1.0.1c from github but I doesn't have CMS support.Why and how can I add this?
Thank you.

Suman said...

I am not sure, I was requiring only SSL (Open SSL) sockets. So, I targeted for the same and I followed the instruction mentioned in the above page (