Topic: AES GCM Streaming linker error

Hello,

I have integrated the wolfssl library version "4_8_0_stable" into my application and configured the wolfssl with the option as "./configure --enable-aesgcm-stream". After configuring, i could notice that the macro "WOLFSSL_AESGCM_STREAM" is defined in  "wolfssl\options.h" file. I'm trying to build the wolfssl into my application using the "CMakeLists.txt". As part of the build, "wolfcrypt/test/test.c" file is getting compiled and ends with the below linker error.

wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10130: undefined reference to `wc_AesGcmEncryptInit'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10133: undefined reference to `wc_AesGcmEncryptUpdate'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10136: undefined reference to `wc_AesGcmEncryptFinal'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10145: undefined reference to `wc_AesGcmDecryptInit'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10148: undefined reference to `wc_AesGcmDecryptUpdate'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10151: undefined reference to `wc_AesGcmDecryptFinal'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10160: undefined reference to `wc_AesGcmEncryptInit'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10168: undefined reference to `wc_AesGcmEncryptUpdate'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10176: undefined reference to `wc_AesGcmEncryptUpdate'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10181: undefined reference to `wc_AesGcmEncryptFinal'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10192: undefined reference to `wc_AesGcmDecryptInit'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10200: undefined reference to `wc_AesGcmDecryptUpdate'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10208: undefined reference to `wc_AesGcmDecryptUpdate'
external/wolfssl_4_8_0_stable/wolfcrypt/test/test.c:10213: undefined reference to `wc_AesGcmDecryptFinal'

Have attached the file "wolfssl\options.h" for reference. Someone could please help me in resolving this error.

Thank you!

Share

Re: AES GCM Streaming linker error

Hi Raghu,

This sounds like a build configuration issue. If building with ./configure it generates a wolfssl/options.h with settings. It looks like our CMakeLists.txt also does this. Assuming you have `HAVE_AESGCM` and `WOLFSSL_AESGCM_STREAM` in the generated options.h, the next item to check is the include at the top of wolfcrypt/test/test.c is including wolfssl/options.h, which it does if WOLFSSL_USER_SETTINGS is not defined.

I don't see your options.h attached, so I am unable to confirm.

Thanks,
David Garske, wolfSSL

Share

Re: AES GCM Streaming linker error

Hello David,

If "HAVE_AESGCM" and "WOLFSSL_AESGCM_STREAM" is not defined then we might end up with declaration error. I checked in my application that "WOLFSSL_USER_SETTINGS" is not defined anywhere, so the "wolfssl/options.h" should be included in wolfcrypt/test/test.c. I have attached the wolfssl/options.h file again and I hope you can able to see it.

As i don't know where to enable AES GCM stream in "CMakeLists.txt", i tried the below workaround.
1. Configured the wolfssl with the option as "./configure --enable-aesgcm-stream
2. Replace the "wolfssl\options.h" and "cyassl\options.h" in my application with the above configured one.
3. If we try to build via "CMakeLists.txt" in my application, then the "wolfssl\options.h" will be overwritten. To avoid overwriting, i have commented out the "# Generate user options header" in CMakeLists.txt (line no: 1353 to 1414).

In addition, after configuration, i have removed the "WOLFSSL_BASE64_ENCODE" and "HAVE_WC_INTROSPECTION" in "wolfssl\options.h" as i was getting the below linker error.

external/wolfssl_4_8_0_stable/CMakeFiles/unit_test.dir/examples/server/server.c.o: In function `server_test':
external/wolfssl_4_8_0_stable/examples/server/server.c:1828: undefined reference to `wolfSSL_configure_args'
external/wolfssl_4_8_0_stable/examples/server/server.c:1845: undefined reference to `wolfSSL_global_cflags'
external/wolfssl_4_8_0_stable/CMakeFiles/unit_test.dir/examples/client/client.c.o: In function `client_test':
external/wolfssl_4_8_0_stable/examples/client/client.c:2299: undefined reference to `wolfSSL_configure_args'
external/wolfssl_4_8_0_stable/examples/client/client.c:2316: undefined reference to `wolfSSL_global_cflags'

Does the above workaround will have any impacts?

Thank you!

Post's attachments

options.h 2.37 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Share

Re: AES GCM Streaming linker error

Hi Raghu,

What you've discovered here is actually a defect in our CMake build. Thanks for pointing it out! With the autotools build, we parse the environment variables CPPFLAGS and CFLAGS for defines supplied by the user and add anything we find to options.h. The equivalent variable for CMake, CMAKE_C_FLAGS, wasn't being parsed for defines to add to options.h. However, I've just fixed this in this PR: https://github.com/wolfSSL/wolfssl/pull/4368

Could you try applying that PR as a patch to your copy of wolfSSL? Then, you should be able to supply arbitrary defines to the compiler that'll also be reflected in options.h by doing:

cmake -DCMAKE_C_FLAGS="-DYOUR_DEFINE_GOES_HERE" ..

The ".." at the end assumes you're in the directory wolfssl/build/ and the CMakeLists.txt is at wolfssl/CMakeLists.txt.

Thanks,

Hayden

Share

Re: AES GCM Streaming linker error

Hello Hayden,

Thanks for the fix. I have integrated your PR patch into my application. Then i added the below lines in my application CMakeLists.txt.

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_AESGCM_STREAM")

After that, I could notice that "WOLFSSL_AESGCM_STREAM" is defined in "wolfssl/options.h". But now it ends up with the below error.

Now the question is do we need to configure explicitly some other macros to eliminate the error? Also attached the generated "wolfssl/options.h"

[build] lib/libwolfssl.a(aes.c.o):external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6864: more undefined references to `GHASH_ONE_BLOCK' follow
[build] lib/libwolfssl.a(aes.c.o): In function `GHASH_FINAL':
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6867: undefined reference to `FlattenSzInBits'
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6867: undefined reference to `FlattenSzInBits'
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6867: undefined reference to `GHASH_ONE_BLOCK'
[build] collect2: error: ld returned 1 exit status
[build] [56/67] Linking C executable external/wolfssl_4_8_0_stable/examples/benchmark/tls_bench
[build] FAILED: external/wolfssl_4_8_0_stable/examples/benchmark/tls_bench
[build] : && ccache
[build] lib/libwolfssl.a(aes.c.o): In function `GHASH_INIT':
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6736: undefined reference to `GHASH_INIT_EXTRA'
[build] lib/libwolfssl.a(aes.c.o): In function `GHASH_UPDATE':
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6769: undefined reference to `GHASH_ONE_BLOCK'
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6783: undefined reference to `GHASH_ONE_BLOCK'
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6798: undefined reference to `GHASH_ONE_BLOCK'
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6818: undefined reference to `GHASH_ONE_BLOCK'
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6832: undefined reference to `GHASH_ONE_BLOCK'
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6864: more undefined references to `GHASH_ONE_BLOCK' follow
[build] lib/libwolfssl.a(aes.c.o): In function `GHASH_FINAL':
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6867: undefined reference to `FlattenSzInBits'
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6867: undefined reference to `FlattenSzInBits'
external/wolfssl_4_8_0_stable/wolfcrypt/src/aes.c:6867: undefined reference to `GHASH_ONE_BLOCK'
[build] collect2: error: ld returned 1 exit status

Thank you!

Post's attachments

options.h 2.11 kb, 2 downloads since 2021-09-03 

You don't have the permssions to download the attachments of this post.

Share

Re: AES GCM Streaming linker error

Hi raghu,

I also had that issue at first. Make sure you've pulled that branch and reconfigured your cmake. You might even need to delete wolfssl/options.h.

git fetch origin pull/4368/head:cmake_cflags
git checkout cmake_cflags
rm wolfssl/options.h
rm -rf build
mkdir build
cd build
cmake -DCMAKE_C_FLAGS="-DWOLFSSL_AESGCM_STREAM" ..
make

Let us know if that does not help.

Thanks,
David Garske, wolfSSL

Share

Re: AES GCM Streaming linker error

Hello David,

Thanks for the hint. I have check out the master branch and then i could able to test the AES GCM streaming algorithm successfully.

Thank you!

Share

Re: AES GCM Streaming linker error

Hi Raghu,

I made an error in that last CMake PR I linked you to. I've fixed it with this new PR: https://github.com/wolfSSL/wolfssl/pull/4379 You'll probably want to pull that change in, too.

Thanks,

Hayden

Share