0

I am trying to compile and create executable for the dilithium2 algorithm which is a Quantum Cryptography Project. I am getting into trouble with using macro defined functions in my compiling process. I am getting error undefined reference even if the functions are defined with macro. Could you please help me what is the trick of using macro functions.

You can achieve open source file from National Institute of Standards and Technology. Link : Open Source Codes from NIST Official Site. You can download CRYSTAL-DILITHIUM.

Here are my details:

Compile Outputs and Related Errors:

====================[ Build | dilithium_test_speed | Debug ]====================
/opt/clion-2023.1.4/bin/cmake/linux/x64/bin/cmake --build /projectDirectory/cmake-build-debug --target dilithium_test_speed -j 10
[2/2] Linking C executable dilithium_test_speed
FAILED: dilithium_test_speed 
: && /usr/bin/cc -g  CMakeFiles/dilithium_test_speed.dir/test/cpucycles.c.o CMakeFiles/dilithium_test_speed.dir/test/speed_print.c.o CMakeFiles/dilithium_test_speed.dir/test/test_dilithium.c.o CMakeFiles/dilithium_test_speed.dir/randombytes.c.o CMakeFiles/dilithium_test_speed.dir/sign.c.o CMakeFiles/dilithium_test_speed.dir/poly.c.o CMakeFiles/dilithium_test_speed.dir/polyvec.c.o -o dilithium_test_speed  -lcrypto  -lssl && :
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/sign.c.o: in function `pqcrystals_dilithium2_ref_keypair':
/projectDirectory/sign.c:33: undefined reference to `pqcrystals_fips202_ref_shake256'
/usr/bin/ld: /projectDirectory/sign.c:58: undefined reference to `pqcrystals_dilithium2_ref_pack_pk'
/usr/bin/ld: /projectDirectory/sign.c:61: undefined reference to `pqcrystals_fips202_ref_shake256'
/usr/bin/ld: /projectDirectory/sign.c:62: undefined reference to `pqcrystals_dilithium2_ref_pack_sk'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/sign.c.o: in function `pqcrystals_dilithium2_ref_signature':
/projectDirectory/sign.c:100: undefined reference to `pqcrystals_dilithium2_ref_upack_sk'
/usr/bin/ld: /projectDirectory/sign.c:103: undefined reference to `pqcrystals_fips202_ref_shake256_init'
/usr/bin/ld: /projectDirectory/sign.c:104: undefined reference to `pqcrystals_fips202_ref_shake256_absorb'
/usr/bin/ld: /projectDirectory/sign.c:105: undefined reference to `pqcrystals_fips202_ref_shake256_absorb'
/usr/bin/ld: /projectDirectory/sign.c:106: undefined reference to `pqcrystals_fips202_ref_shake256_finalize'
/usr/bin/ld: /projectDirectory/sign.c:107: undefined reference to `pqcrystals_fips202_ref_shake256_squeeze'
/usr/bin/ld: /projectDirectory/sign.c:112: undefined reference to `pqcrystals_fips202_ref_shake256'
/usr/bin/ld: /projectDirectory/sign.c:137: undefined reference to `pqcrystals_fips202_ref_shake256_init'
/usr/bin/ld: /projectDirectory/sign.c:138: undefined reference to `pqcrystals_fips202_ref_shake256_absorb'
/usr/bin/ld: /projectDirectory/sign.c:139: undefined reference to `pqcrystals_fips202_ref_shake256_absorb'
/usr/bin/ld: /projectDirectory/sign.c:140: undefined reference to `pqcrystals_fips202_ref_shake256_finalize'
/usr/bin/ld: /projectDirectory/sign.c:141: undefined reference to `pqcrystals_fips202_ref_shake256_squeeze'
/usr/bin/ld: /projectDirectory/sign.c:176: undefined reference to `pqcrystals_dilithium2_ref_pack_sig'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/sign.c.o: in function `pqcrystals_dilithium2_ref_verify':
/projectDirectory/sign.c:245: undefined reference to `pqcrystals_dilithium2_ref_unpack_pk'
/usr/bin/ld: /projectDirectory/sign.c:246: undefined reference to `pqcrystals_dilithium2_ref_unpack_sig'
/usr/bin/ld: /projectDirectory/sign.c:252: undefined reference to `pqcrystals_fips202_ref_shake256'
/usr/bin/ld: /projectDirectory/sign.c:253: undefined reference to `pqcrystals_fips202_ref_shake256_init'
/usr/bin/ld: /projectDirectory/sign.c:254: undefined reference to `pqcrystals_fips202_ref_shake256_absorb'
/usr/bin/ld: /projectDirectory/sign.c:255: undefined reference to `pqcrystals_fips202_ref_shake256_absorb'
/usr/bin/ld: /projectDirectory/sign.c:256: undefined reference to `pqcrystals_fips202_ref_shake256_finalize'
/usr/bin/ld: /projectDirectory/sign.c:257: undefined reference to `pqcrystals_fips202_ref_shake256_squeeze'
/usr/bin/ld: /projectDirectory/sign.c:281: undefined reference to `pqcrystals_fips202_ref_shake256_init'
/usr/bin/ld: /projectDirectory/sign.c:282: undefined reference to `pqcrystals_fips202_ref_shake256_absorb'
/usr/bin/ld: /projectDirectory/sign.c:283: undefined reference to `pqcrystals_fips202_ref_shake256_absorb'
/usr/bin/ld: /projectDirectory/sign.c:284: undefined reference to `pqcrystals_fips202_ref_shake256_finalize'
/usr/bin/ld: /projectDirectory/sign.c:285: undefined reference to `pqcrystals_fips202_ref_shake256_squeeze'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_reduce':
/projectDirectory/poly.c:33: undefined reference to `pqcrystals_dilithium2_ref_reduce32'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_caddq':
/projectDirectory/poly.c:51: undefined reference to `pqcrystals_dilithium2_ref_caddq'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_freeze':
/projectDirectory/poly.c:69: undefined reference to `pqcrystals_dilithium2_ref_freeze'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_ntt':
/projectDirectory/poly.c:143: undefined reference to `pqcrystals_dilithium2_ref_ntt'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_invntt_tomont':
/projectDirectory/poly.c:160: undefined reference to `pqcrystals_dilithium2_ref_invntt_tomont'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_pointwise_montgomery':
/projectDirectory/poly.c:181: undefined reference to `pqcrystals_dilithium2_ref_montgomery_reduce'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_power2round':
/projectDirectory/poly.c:203: undefined reference to `pqcrystals_dilithium2_ref_power2round'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_decompose':
/projectDirectory/poly.c:226: undefined reference to `pqcrystals_dilithium2_ref_decompose'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_make_hint':
/projectDirectory/poly.c:249: undefined reference to `pqcrystals_dilithium2_ref_make_hint'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_use_hint':
/projectDirectory/poly.c:271: undefined reference to `pqcrystals_dilithium2_ref_use_hint'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_uniform':
/projectDirectory/poly.c:372: undefined reference to `pqcrystals_dilithium2_ref_dilithium_shake128_stream_init'
/usr/bin/ld: /projectDirectory/poly.c:373: undefined reference to `pqcrystals_fips202_ref_shake128_squeezeblocks'
/usr/bin/ld: /projectDirectory/poly.c:382: undefined reference to `pqcrystals_fips202_ref_shake128_squeezeblocks'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_uniform_eta':
/projectDirectory/poly.c:462: undefined reference to `pqcrystals_dilithium2_ref_dilithium_shake128_stream_init'
/usr/bin/ld: /projectDirectory/poly.c:463: undefined reference to `pqcrystals_fips202_ref_shake128_squeezeblocks'
/usr/bin/ld: /projectDirectory/poly.c:468: undefined reference to `pqcrystals_fips202_ref_shake128_squeezeblocks'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_uniform_gamma1':
/projectDirectory/poly.c:496: undefined reference to `pqcrystals_dilithium2_ref_dilithium_shake256_stream_init'
/usr/bin/ld: /projectDirectory/poly.c:497: undefined reference to `pqcrystals_fips202_ref_shake256_squeezeblocks'
/usr/bin/ld: CMakeFiles/dilithium_test_speed.dir/poly.c.o: in function `pqcrystals_dilithium2_ref_poly_challenge':
/projectDirectory/poly.c:517: undefined reference to `pqcrystals_fips202_ref_shake256_init'
/usr/bin/ld: /projectDirectory/poly.c:518: undefined reference to `pqcrystals_fips202_ref_shake256_absorb'
/usr/bin/ld: /projectDirectory/poly.c:519: undefined reference to `pqcrystals_fips202_ref_shake256_finalize'
/usr/bin/ld: /projectDirectory/poly.c:520: undefined reference to `pqcrystals_fips202_ref_shake256_squeezeblocks'
/usr/bin/ld: /projectDirectory/poly.c:532: undefined reference to `pqcrystals_fips202_ref_shake256_squeezeblocks'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

File Structure:

  ├── test
  │     ├── cpucycles.c
  │     ├── cpucycles.h
  │     ├── speed_print.c
  │     ├── speed_print.h
  │     ├── test_dilithium.c
  │     ├── test_mul.c
  │     ├── test_speed.c
  │     └── test_vectors.c
  ├── aes256ctr.c
  ├── aes256ctr.h
  ├── api.h
  ├── config.h
  ├── fips202.c
  ├── fips202.h
  ├── ntt.c
  ├── ntt.h
  ├── packing.c
  ├── packing.h
  ├── params.h
  ├── poly.c
  ├── poly.h
  ├── polyvec.c
  ├── PQCgenKAT_sign.c
  ├── randombytes.c
  ├── randombytes.h
  ├── reduce.c
  ├── reduce.h
  ├── rng.c
  ├── rng.h
  ├── rounding.c
  ├── rounding.h
  ├── sign.c
  ├── sign.h
  ├── symmetric.h
  ├── symmetric-aes.c
  ├── symmetric-shake.c
  ├── Makefile
  ├── CMakelists.txt

CMakeLists.txt :

cmake_minimum_required(VERSION 3.12)
project(dilithium2 C)

set(CMAKE_C_STANDARD 11)

# Add your source files here
set(SOURCES
    aes256ctr.c
    fips202.c
    ntt.c
    packing.c
    poly.c
    polyvec.c
    PQCgenKAT_sign.c
    randombytes.c
    reduce.c
    rng.c
    rounding.c
    sign.c
    symmetric-aes.c
    symmetric-shake.c
)

# Add your test source files here
set(TEST_SOURCES
    test/cpucycles.c
    test/speed_print.c
    test/test_dilithium.c
    sign.c
    poly.c
    polyvec.c
)

# Add include directories
include_directories(
    .
    test
)

add_executable(dilithium_test_speed ${TEST_SOURCES})

# Link any necessary libraries (e.g., -lcrypto -lssl)
target_link_libraries(dilithium_test_speed crypto ssl)
jps
  • 20,041
  • 15
  • 75
  • 79
  • The errors you're getting are all linker errors. If you studied C you should know that building a C program is done in multiple steps. One step is compiling the source file and all its included header files into an object file (this is the [*translation unit*](https://en.wikipedia.org/wiki/Translation_unit_(programming)) that the compiler works with). Then the linker takes all object files and all libraries to create the final executable program file. Macros are compile-time features, they don't exist in the object files. So the problem you're having is not related to macros. – Some programmer dude Aug 20 '23 at 08:43
  • More likely the problem is you missing object files, or not linking with the required libraries. – Some programmer dude Aug 20 '23 at 08:43
  • 1
    One of two things is happening: Either (1) You aren't linking with the file(s) that define your missing functions, or (2) The file that you intended to define those function is not actually defining them. So, pick one. Look for `pqcrystals_fips202_ref_shake256`. What file defines it? Confirm it: Is it in the `.o` file? If not, then you've found your problem. Or if it is defined, then you forgot to include it when linking your executable, so just add it. – Tom Karzes Aug 20 '23 at 09:41
  • @Someprogrammerdude Thank you so much for your informative feedbacks diagnosis is strong match. – Kanije Ashine Shie Shuai Aug 20 '23 at 11:37
  • It is strongly match with your diagnosis @TomKarzes. Thank you so much. – Kanije Ashine Shie Shuai Aug 20 '23 at 11:38
  • Do you know specific order is required or not for HEADER and SOURCES file? I just create executable with CMakeLists. But it is failing when I tried with Makefile with the same source and header files. The only differences is header files including hierarchy. I am able to add in CMake with this line : # Add include directories include_directories( . test ) I don't know which order included headers due to "." dot factor. But I am using below for Makefile: – Kanije Ashine Shie Shuai Aug 20 '23 at 11:58
  • SOURCES_TEST_SPEED := test/cpucycles.c test/speed_print.c test/test_speed.c HEADER_TEST_SPEED := test/cpucycles.h test/speed_print.h – Kanije Ashine Shie Shuai Aug 20 '23 at 12:00
  • SOURCES_TEST_SPEED2 := randombytes.c\ sign.c\ poly.c\ polyvec.c\ fips202.c\ reduce.c\ rounding.c\ ntt.c\ packing.c\ symmetric-shake.c\ symmetric-aes.c\ aes256ctr.c – Kanije Ashine Shie Shuai Aug 20 '23 at 12:01
  • HEADER_TEST_SPEED2 := randombytes.h\ sign.h\ poly.h\ polyvec.h\ fips202.h\ reduce.h\ rounding.h\ ntt.h\ packing.h\ aes256ctr.h\ params.h\ symmetric.h\ config.h\ api.h – Kanije Ashine Shie Shuai Aug 20 '23 at 12:01
  • Doesn't the source package contain build instructions? And its own makefile, autotooling, or CMake-based build system? You should not need to create your own. – John Bollinger Aug 20 '23 at 12:22
  • There is a Makefile but it is not autocreated and it is not serve to create executable. It is also rises erros. @JohnBollinger – Kanije Ashine Shie Shuai Aug 20 '23 at 12:28

0 Answers0