Problem with OpenSSL: undefined reference to CRYPTO_gcm128_init

Here’s a minimal test case of the problem I encountered developing a trusted application that uses the OpenSSL provided with L4T/r32_Release_v4.2:

#include <openssl/evp.h>

int main(void)
{
    EVP_aes_256_gcm();
    return 0;
}

The error messages are:

.../trusty/trusty/lib/lib/openssl/crypto/evp/e_aes.c:1325: undefined reference to `CRYPTO_gcm128_init'

(A total of 9 functions.)

The test program can be built with upstream OpenSSL 1.0.2q, which is the OpenSSL version that the L4T one seems to be based on, both on Intel and AArch64. C definitions of the undefined functions seem to be present, and assember versions of related functions are added in the diff from upstream 1.0.2q, so it looks like some kind of configuration problem with the L4T OpenSSL.

Is this a known problem? Is there an easy work-around?

Edmund

I have not used this software, but was this error during link stage, or build? If build, then you might have to “#include” something, and if link, then you might need to install a supporting library. Make sure you have all prerequisite “dev” versions of packages installed (for header files), plus all necessary listed libraries to link against (perhaps you are missing some library package needed to link against).

If this were from kernel code while building the kernel or a module, then this would be a Kconfig missing the feature which provides the function.

It’s a linker error. I think the problem is internal to OpenSSH because the undefined function is in the OpenSSH source code and the function that is trying to call it is also in the OpenSSH source code. So I don’t think any other libraries are involved.

hello edmund.grimley-evans,

there’s definition by checking L4T sources,
for example,
$L4T_Sources/r32.4.2/Linux_for_Tegra/source/public/trusty/lib/lib/openssl/crypto/modes/modes.h
void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block);

could you please refer to README file, atf_and_trusty_README.txt,
it provides instructions for building and verifying the ARM Trusted Firmware (ATF) and Trusty.
thanks

Here is some further evidence for there being a problem within OpenSSL: if I replace EVP_aes_256_gcm in my test program with EVP_aes_256_ctr, there is no problem compiling and linking it. The problem is specific to a particular set of OpenSSL functions.

(In an earlier message I typed OpenSSH instead of OpenSSL. I keep doing that. Sorry!)

I will try with a newer release of the L4T sources, just in case that helps.

I’ve tried upgrading from 32.4.2 to 32.4.4. It make no difference. And it looks as though nothing relevant has changed between those versions.

Edmund

I think I’ve found a work-around. I’ll give some details in case in helps anyone.

The “undefined” function is defined in a file called gcm128.c, and there are 8 other .c files in the same directory. After building my application, are there corresponding .o files for any of them? Yes, 3 of them get compiled: cbc128.o, cfb128.o, ctr128.o. So I grepped the tree for any files that mention ctr128 but don’t mention gcm128, and it turns out that there are only 4 such files, of which 2 have x86-specific names.

My work-around is to modify the file Crypto-config-trusty.mk by duplicating the line that contains ctr128 and replacing ctr128 with gcm128 in the copy. (The file starts with # Auto-generated - DO NOT EDIT!, but re-auto-generating it is not part of the standard build process.)

My application can now be built. I am not yet able to test whether it runs correctly.

Edmund

hello edmund.grimley-evans,

actually,
I cannot reproduce the same error as yours.
I’ve create test.c to include the same code as you mentioned in bug description.
for example,
trusty/app/nvidia-sample/hwkey-agent/test.c

#include <openssl/evp.h>

int foo_evp(void)
{
    EVP_aes_256_gcm();
    return 0;
}

modify rules.mk to add this test code into makefile,
for example,
trusty/app/nvidia-sample/hwkey-agent/rules.mk

MODULE_SRCS += \
...
        $(LOCAL_DIR)/test.c

it’s compile successfully.
I did not meet the undefined reference error as you reported.

compiling app/nvidia-sample/hwkey-agent/test.c
linking t186ref/build-t186/user_tasks/nvidia-sample/hwkey-agent/app/nvidia-sample/hwkey-agent.mod.o
...
generating image: t186ref/build-t186/lk.bin

I think the reason you’re not getting an error is because you don’t have any linked file that uses foo_evp, so test.o is not being linked, and therefore there is no attempt to look for the symbol EVP_aes_256_gcm. Try inserting a call to foo_evp in main, or something like this in a file that gets linked:

int foo_evp(void);
static void *foo_evp_p = foo_evp;

Edmund

related github issues:

Maybe it would make sense to open an issue at the github openssl repository?