14

I'm working on AES Encryption with PJSIP open source library. The library which is used for AES Encryption is not built-in library available in C Programming. So, I have gone with external library (Libmcrypt) for AES Encryption.

I followed this site for build the libmcrypt library into my machine(MAC OSX). https://coolestguidesontheplanet.com/install-mcrypt-php-mac-osx-10-10-yosemite-development-server/

https://gist.github.com/bricef/2436364

While building those library it created one dynamic library(libmcrypt.dylib) in /usr/local/lib/ path. when checking the architecture of that library using lipo -info libmcrypt.dylib command, it shows

Non-fat file: libmcrypt.dylib is architecture: x86_64

But I'm creating these applications for Android and IOS devices using PJSIP. Their architectures are armeabi(android) and armv7(IOS).

While Linking the libmcrypt.dylib(x86_64) into PJSIP library(armv7), it shows following errors.

Undefined symbols for architecture armv7:
  "_mcrypt_enc_get_block_size", referenced from:
      _encrypt_AES in libpjsip-armv7-apple-darwin_ios.a(aes.o)
      _decrypt_AES in libpjsip-armv7-apple-darwin_ios.a(aes.o)
  "_mcrypt_generic", referenced from:
      _encrypt_AES in libpjsip-armv7-apple-darwin_ios.a(aes.o)
  "_mcrypt_generic_deinit", referenced from:
      _encrypt_AES in libpjsip-armv7-apple-darwin_ios.a(aes.o)
      _decrypt_AES in libpjsip-armv7-apple-darwin_ios.a(aes.o)
  "_mcrypt_generic_init", referenced from:
      _encrypt_AES in libpjsip-armv7-apple-darwin_ios.a(aes.o)
      _decrypt_AES in libpjsip-armv7-apple-darwin_ios.a(aes.o)
  "_mcrypt_module_close", referenced from:
      _encrypt_AES in libpjsip-armv7-apple-darwin_ios.a(aes.o)
      _decrypt_AES in libpjsip-armv7-apple-darwin_ios.a(aes.o)
  "_mcrypt_module_open", referenced from:
      _encrypt_AES in libpjsip-armv7-apple-darwin_ios.a(aes.o)
      _decrypt_AES in libpjsip-armv7-apple-darwin_ios.a(aes.o)
  "_mdecrypt_generic", referenced from:
      _decrypt_AES in libpjsip-armv7-apple-darwin_ios.a(aes.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [../bin/pjsip-test-armv7-apple-darwin_ios] Error 1
make[1]: *** [pjsip-test-armv7-apple-darwin_ios] Error 2
make: *** [all] Error 1

I don't know a lot about these architectures. Is it possible to convert libmcrypt.dylib(x86_64) into libmcrypt.dylib(armv7). If Yes, then guide me how to convert it into armv7 architecture and if not then sorry for wasting your time.

Thanks in Advance!

Nandhakumar Kittusamy
  • 1,066
  • 12
  • 32
  • 3
    No, you cannot (easily) convert from x86_64 to armv7. You need to cross-compile it from source. – Ian Abbott Aug 17 '17 at 14:23
  • @lan if you don't mind, refer me how to cross compile x86_64 into armv7 architecture. – Nandhakumar Kittusamy Aug 17 '17 at 14:26
  • 3
    You don't cross compile the x86_64 binaries, you cross-compile the source code. The development kits you have installed for Android/iOS should include a cross-compiler that runs on your MAC OSX host and produces armv7 binaries for Android/iOS. You need to build mcrypt in the appropriate development environment. – Ian Abbott Aug 17 '17 at 14:33
  • I want to build libmcrypt library for armv7 architecture. Basically it is built for which machine you are building. Like if you built on mac os, it will resulting x86_64 architecture library. But I want to build armv7 architecture libmcrypt library. How to cross compile the libmcrypt library into armv7 architecture? Im using libmcrypt library from this link. [link](https://coolestguidesontheplanet.com/install-mcrypt-php-mac-osx-10-10-yosemite-development-server/) – Nandhakumar Kittusamy Aug 24 '17 at 12:58
  • 1
    Please note that the MCrypt library has not been [updated since 2007](https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/). It is [highly recommended](https://paragonie.com/blog/2015/05/if-you-re-typing-word-mcrypt-into-your-code-you-re-doing-it-wrong) you switch to OpenSSL or another maintained encryption project. – Tim Aug 25 '17 at 22:34
  • I think you're going in the wrong direction. Your instructions don't teach you how to cross-compile this library. You need to [seek some other instructions](https://landley.net/writing/docs/cross-compiling.html) and then work out how to vary what you have... – autistic Aug 28 '17 at 19:43
  • The answer to this question is technically yes, though I won't post that as an answer because it's just theory. Any turing machine (such as your arm machine) can emulate any other (such as your x86), so you just need to write an x86 interpreter or x86-to-arm translator for your arm, right? Wrong. Work on translating the source code directly to arm object code. Sincerely, */usr/local/lib/libmcrypt.so.4.4.8: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=de555800fad911f9423785f581ce11d708c40309, not stripped* – autistic Aug 28 '17 at 19:49

2 Answers2

8

Don't use mcrypt. The MCrypt library has not been updated since 2007. It is highly recommended you switch to OpenSSL or another maintained encryption project.

The PJSIP documentation has instructions on how to use OpenSSL for both IOS and Android devices:

Tim
  • 4,790
  • 4
  • 33
  • 41
  • 1
    Thank you very much...! I followed this link https://github.com/x2on/OpenSSL-for-iPhone . just downloading and compiling the iPhone GitHub project with openssl using build-lib. It gives both libraries libcrypto.a and libssl.a in all architectures(i386 armv7s armv7 x86_64 arm64). – Nandhakumar Kittusamy Aug 31 '17 at 12:55
3

Instead of using libmcrypt library, we can use below openssl(Github) projects for creating libraries on all architectures as Suggested by above answer. Thank you @Tim.

Use this project build-libssl.sh file for compiling for all architectures both on Android and IOS.

For Android,

https://github.com/ruslansalikhov/openssl-for-android

For IOS,

https://github.com/x2on/OpenSSL-for-iPhone

Just download and compile the project using build-libssl.sh file. It will creates all library for your platform. Either in Android or IOS.

Download the Project and go to the project directory using cmd/terminal.

cd OpenSSL-for-iPhone/

Compile the Project using following command,

./build-libssl.sh

NOTE: Machine must have gcc compiler and SDK installed(Android ndk and IOS).

After Successfull Compilation, go to you PROJECT_DIR(OpenSSL-for-iPhone)/lib folder. Check there is four libraries created for all architectures.

Use following command to check supported Architectures by the library file. Go to the lib path on cmd/terminal interface and check,

lipo -info libcrypto.a

It will show which architectures are supported by the library file.

Architectures in the fat file: libcrypto.a are: i386 armv7s armv7 x86_64 arm64

Nandhakumar Kittusamy
  • 1,066
  • 12
  • 32