1 (edited by ykuz 2020-10-22 12:49:38)

Topic: Linker error: adding custom crypto functions to WolfSSL

Hello everyone,
I am trying to add custom crypto algorithms in wolfssl for my project, however I have a couple problems and I am not sure why.

The setup is as follows:

1. In the wolfssl/wolfcrypt/src directory I added a new file, PQ.c, where new functions wc_InitPQKey(),
wc_FreePQKey(), wc_GeneratePQKeyPair() etc. are implemented. The corresponding header is in wolfssl/wolfssl/wolfcrypt/PQ.h.

2. I defined a new WolfSSL configuration: --enable-pq.
- For that, I added the following into wolfssl/configure.ac:

    ...
    enable_pq=yes
    ...
    # PQ
    AC_ARG_ENABLE([pq],
        [AS_HELP_STRING([--enable-pq],[Enable wolfSSL PQ support (default: disabled)])],
        [ ENABLED_PQ=$enableval ],
        [ ENABLED_PQ=no ]
        )

    if test "$ENABLED_PQ" = "yes"
    then
        AM_CFLAGS="$AM_CFLAGS -DHAVE_PQ"
    fi
    ...
    AM_CONDITIONAL([BUILD_PQ],[test "x$ENABLED_PQ" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
    ...
    echo "   * PQ:                      $ENABLED_PQ"
    ...

- in the wolfssl/src/include.am I added:

    ...
    if BUILD_PQ
    src_libwolfssl_la_SOURCES += wolfcrypt/src/PQ.c
    endif
    ...

- in the wolfssl/wolfssl/wolfcrypt/include.am:

    ...
    nobase_include_HEADERS+= \
                         wolfssl/wolfcrypt/aes.h \
                         ...
                         wolfssl/wolfcrypt/PQ.h \
                         ...
    ...
    if BUILD_PQ
    nobase_include_HEADERS+= wolfssl/wolfcrypt/PQ.h
    endif

3. To build the library, I do:

    ./configure --enable-pq
    make
    sudo make install

4. In my test project file I include <wolfssl/options.h>, <wolfssl/wolfcrypt/PQ.h>, <wolfssl/wolfcrypt/settings.h> etc. and call my functions
wc_InitPQKey(), wc_FreePQKey(), wc_GeneratePQKeyPair().


However, when I am trying to compile the project I get the following:

make
gcc -Wall   -c -o main.o main.c
gcc -o myprog main.o -lwolfssl
/usr/bin/ld: main.o: in function `main':
main.c:(.text+0x12d): undefined reference to `wc_InitPQKey'
/usr/bin/ld: main.c:(.text+0x14a): undefined reference to `wc_InitPQKey'
/usr/bin/ld: main.c:(.text+0x1ce): undefined reference to `wc_GeneratePQKeyPair'
...

Am I missing something?
Thank your very much for your help!

Share

Re: Linker error: adding custom crypto functions to WolfSSL

Hi ykuz,

Make sure you add "WOLFSSL_API" to the header definition of the API, so it is available. Let me know if that doesn't help.

Thanks,
David Garske, wolfSSL

Share

3 (edited by ykuz 2020-10-23 02:29:14)

Re: Linker error: adding custom crypto functions to WolfSSL

Hi David,

Thanks for you response, I added WOLFSSL_API to the header definitions, but unfortunately it did not help.
I then checked if my functions are built in the library by running

nm -g /usr/local/lib/libwolfssl.so | grep PQ

and it turned out, they are not.

In the output of readelf the functions are LOCAL instead of GLOBAL, so maybe that's why they cannot be seen by the linker?

 readelf -sW /usr/local/lib/libwolfssl.so | grep PQ
   414: 0000000000029b90    59 FUNC    LOCAL  DEFAULT   14 wc_FreePQKey
   453: 0000000000029bd0    30 FUNC    LOCAL  DEFAULT   14 wc_GeneratePQKeyPair
   715: 0000000000029b30    88 FUNC    LOCAL  DEFAULT   14 wc_InitPQKey

The library object src_libwolfssl_la-PQ.lo is present in the /wolfssl/wolfcrypt/src directory.

Could you give me an advice how to fix it? Thanks!

Share

Re: Linker error: adding custom crypto functions to WolfSSL

Hi ykuz,

It would help if you could point me to or share your code with me.

Make sure your header includes "#include <wolfssl/wolfcrypt/types.h>" which includes visibility.h. Take a look at wolfssl/wolfcrypt/visilbility.h and make sure you define BUILDING_WOLFSSL and HAVE_VISIBILITY.

Thanks,
David Garske, wolfSSL

Share