本文介绍了通过NDK访问的OpenSSL AES_ENCRYPT函数时未定义引用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个使用OpenSSL开源库Android的加密/解密文件的包装。所以,我创建了一个NDK Android项目编译使用NDK库OpenSSL的。

下面是项目结构:

Android项目
    SRC
    JNI
        的OpenSSL 1.0.1e(文件夹包含OpenSSL的源$ C ​​$ C)
            加密(文件夹包含加密源$ C ​​$ C)
                Android.mk(Android的makefile文件来定义STATIC_LIBRARY)            包括
                OpenSSL的(文件夹包含头文件)        包装(文件夹包含包装源$ C ​​$ C,我在这里实现)
            aes_wrapper.c(我的包装实现)
            Android.mk(Android的makefile文件来定义SHARED_LIBRARY)        Android.mk(Android的生成文件调用的所有子机器人的makefile)
        Application.mk(应用程序生成文件,我用它来定义APP_ABI)

下面是在文件夹Android.mk内容JNI / OpenSSL的-1.0.1e /加密

LOCAL_PATH:= $(叫我-DIR)包括$(CLEAR_VARS)LOCAL_C_INCLUDES:= \\
    $(NDK_PROJECT_PATH)\\
    $(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto \\
    $(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto/asn1 \\
    $(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto/aes \\
    $(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto/evp \\
    $(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/include \\
    $(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/include/opensslLOCAL_SRC_FILES:=这里所有的源文件LOCAL_MODULE:=加密包括$(BUILD_STATIC_LIBRARY)

下面是在文件夹JNI /包装Android.mk内容

LOCAL_PATH:= $(叫我-DIR)包括$(CLEAR_VARS)LOCAL_C_INCLUDES:= \\
    $(NDK_PROJECT_PATH)\\
    $(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto \\
    $(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto/asn1 \\
    $(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto/aes \\
    $(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto/evp \\
    $(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/include \\
    $(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/include/opensslLOCAL_SRC_FILES:= aes_wrapper.cLOCAL_STATIC_LIBRARIES + =加密LOCAL_MODULE:= aes_wrapper包括$(BUILD_SHARED_LIBRARY)

下面是在文件夹JNI Android.mk内容

 包含$(调用所有子目录,makefile文件)

下面是在文件夹JNI Application.mk的含量

  APP_ABI:=所有

当我打电话NDK的构建我得到了一些未定义的引用的错误。我一直在试图解决一两天,但不幸的是我没有成功。谁能帮助我?任何帮助将AP preciated。

编辑:我有一堆像这样的错误

<$p$p><$c$c>/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/$p$pbuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe:
./obj/local/armeabi-v7a/objs/aes_wrapper/aes_wrapper.o:函数加密:JNI /包装/ aes_wrapper.c:21:错误:未定义引用AES_ENCRYPT


解决方案

It sounds like AES_encrypt is not you only error. For AES_encrypt, here's where its located:

$ grep -R AES_encrypt *
crypto/aes/aes.h:void AES_encrypt(const unsigned char *in, unsigned char *out,
...
crypto/aes/aes_core.c:void AES_encrypt(const unsigned char *in, unsigned char *out,
...

I don't use the NDK build system, so I'm not sure if aes_core.c is actually being compiled from your example.

However, you do have LOCAL_STATIC_LIBRARIES += crypto, and you can verify the function is present in the archive with the NDK's version of nm (I believe its arm-linux-androideabi-nm) as follows. You want to see an entry with a T (T is a definition in the Text section):

$ nm libcrypto.a | grep -i AES_encrypt
...
                 U AES_encrypt
0000000000000460 T AES_encrypt
0000000000000000 t _x86_64_AES_encrypt
00000000000001f0 t _x86_64_AES_encrypt_compact
...

If you are still having trouble, OpenSSL offers direction for building the library from the command line outside of the NDK build system. See FIPS Library and Android (and skip the FIPS part). From Build the FIPS Capable Library:

# From the 'root' directory
$ . ./setenv-android.sh
$ cd openssl-1.0.1e/

$ ./config shared no-ssl2 no-comp no-hw no-engine \
    --openssldir=/usr/local/ssl/$ANDROID_API

$ make depend
$ make all
$ sudo -E make install \
    CC=$ANDROID_TOOLCHAIN/arm-linux-androideabi-gcc \
    RANLIB=$ANDROID_TOOLCHAIN/arm-linux-androideabi-ranlib

In the recipe above, ANDROID_TOOLCHAIN is set by the setenv-android.sh script.

Also, you can usually find something prebuilt on Github. http://www.google.com/search?q=openssl+android+site:github.com

这篇关于通过NDK访问的OpenSSL AES_ENCRYPT函数时未定义引用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:48