0

I'm having a weird problem with mbedtls security library. I've downloaded the newest version of it (link to download the .tar.gz) on my Ubuntu machine, then compiled it and copied the header files to /usr/include and the shared library files to the /usr/lib.

When I'm compiling my C++ program which calls the function mbedtls_cipher_cmac_starts from mbedtls/cmac.h, I get the undefined reference error Security.cpp:599: undefined reference to 'mbedtls_cipher_cmac_starts'. However, I have included and linked the libraries correctly (At least I think so, this is not an ordering problem, right?). The problem seems to be in the mbedtls library itself, as when I nm -D libmbedcrypto.so, I can't find the needed function. I also checked the libmbedtls.so but also no luck from there.

0000000000020206 T mbedtls_cipher_auth_decrypt
0000000000020128 T mbedtls_cipher_auth_encrypt
000000000001ff17 T mbedtls_cipher_check_tag
0000000000020022 T mbedtls_cipher_crypt
0000000000264960 D mbedtls_cipher_definitions
000000000001fb49 T mbedtls_cipher_finish

Although it seems to be in the library makefile when compiling the library. Also, it is weird that the header file (cmac.h) can be referenced from code, but it just won't compile because of the undefined references.

Jussi Hietanen
  • 181
  • 1
  • 1
  • 12
  • _Also, it is weird that the header file (cmac.h) can be referenced from code, but it just won't compile because of the undefined references._ It sounds like there's a mismatch between header version and your `.a` file. What is the question you want answered here? – pingul Jul 25 '17 at 11:48
  • 1
    Don't know the library in question, but: **(a)** Library ordering could be an issue: if the library _providing_ that function occurs on the command-line before the library _using_ that function, it likely won't work. Also, **(b)** are there any conditional compilation options for turning on/off parts of the library (such as "cmac")? – TripeHound Jul 25 '17 at 12:12
  • @pingul I'm using (and compiling) shared libraries, so they are `.so` files. Compile time it does not say that anything is wrong. There are also some test files for cmac testing in the library provided, and compiling the library doesn't get stuck at those files. @TripleHound , I tried to read through the whole library README, but there was just the specific command to output `.so` -library for the shared use. I will look further, and email the library developer if I can't sort this issue myself. I think the library ordering is not the issue, as other functions from the same library do work. – Jussi Hietanen Jul 25 '17 at 12:33

1 Answers1

2

Which config.h did you use when building (have a look at configs/ folder)? Make sure MBEDTLS_CMAC_C is defined when building mbedtls, the default one does not define it (as of the date of this posting).

kursancew
  • 351
  • 3
  • 7