0

I am trying to use the Keccak Code Package in a project, especially the SHAKE128 extendable ouput hash function. I have followed their instructions to compile the library, and I have obtained two folders, one is libkeccak.a and is full of .o files, the other is libkeccak.a.headers and is full of .h.

Now the structure of my project looks as follows:

Project 
 |
 + -- MakeFile
 |
 + -- Lamport 
 |     |
 |     + -- lamportOTS.cpp
 |     
 + --libkeccak.a
 |     |
 |     + -- *.o
 |
 + -- libkeccak.a.headers
 |     |
 |     + -- *.h

The function that I want to use is specified in libkeccak.a.headers/SimpleFIPS202.h. Therefore I have included the header file. However I can not find how to compile it properly. I have tried:

 g++ -c Lamport/lamportOTS.cpp 
 g++ lamportOTS.o libkeccak.a/SImpleFIPS202.o

It finds the SHAKE128 function, but fails to compile since the different .o files seem to be interdependent. Here is a sketch of lamportOTS.cpp

#include "../libkeccak.a.headers/SimpleFIPS202.h"

void sign(unsigned char* message, unsigned char* signature, unsigned char*** key){

    unsigned char randombits[2][256][32];

    ...

    /* Apply SHAKE128 to each value */
    for(int i = 0; i != 2; i++){
            for(int j = 0; j!= 256;j++){
                    SHAKE128(key[i][j],32, randombits[i][j], 32);
            }
    }

}

EDIT: Details about the compilation error have been asked in the comments. Running

g++ lamportOTS.o libkeccak.a/SimpleFIPS202.o

gives the following error

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: dans la fonction « _start »:
(.text+0x20): référence indéfinie vers « main »
libkeccak.a/SimpleFIPS202.o: dans la fonction « SHAKE128 »:
SimpleFIPS202.c:(.text+0x19): référence indéfinie vers « KeccakWidth1600_Sponge »
libkeccak.a/SimpleFIPS202.o: dans la fonction « SHAKE256 »:
SimpleFIPS202.c:(.text+0x49): référence indéfinie vers « KeccakWidth1600_Sponge »
libkeccak.a/SimpleFIPS202.o: dans la fonction « SHA3_224 »:
SimpleFIPS202.c:(.text+0x80): référence indéfinie vers « KeccakWidth1600_Sponge »
libkeccak.a/SimpleFIPS202.o: dans la fonction « SHA3_256 »:
SimpleFIPS202.c:(.text+0xb0): référence indéfinie vers « KeccakWidth1600_Sponge »
libkeccak.a/SimpleFIPS202.o: dans la fonction « SHA3_384 »:
SimpleFIPS202.c:(.text+0xe0): référence indéfinie vers « KeccakWidth1600_Sponge »
libkeccak.a/SimpleFIPS202.o:SimpleFIPS202.c:(.text+0x110): encore plus de références indéfinies suivent vers « KeccakWidth1600_Sponge »
lamportOTS.o: dans la fonction « sign(unsigned char*, unsigned char*, unsigned char***) »:
lamportOTS.cpp:(.text+0x140): référence indéfinie vers « SHAKE128(unsigned char*, unsigned long, unsigned char const*, unsigned long) »
collect2: error: ld returned 1 exit status
Raphael D.
  • 778
  • 2
  • 7
  • 18
  • Is there no ***file*** named `libkeccak.a`? Because it seems that the library is attempting to create an actual static library (which is what a file named `libkeccak.a` would be), and then you can link with the whole library instead of its separate object files. – Some programmer dude Mar 10 '18 at 12:28
  • I have cloned the [Keccak repo](https://github.com/gvanas/KeccakCodePackage) and followed the instructions, but it does not really mention how to use the library. There was also a `libkeccak.a.target` file, but it seems irrelevant. – Raphael D. Mar 10 '18 at 12:37
  • There is a reason why compilers print error messages instead of returning a simple pass/fail code. – n. m. could be an AI Mar 10 '18 at 12:39
  • When I run `g++ lamportOTS.o libkeccak.a/SimpleFIPS202.o` , I get `(.text+0x20): référence indéfinie vers « main » libkeccak.a/SimpleFIPS202.o: dans la fonction « SHAKE128 »: SimpleFIPS202.c:(.text+0x19): référence indéfinie vers « KeccakWidth1600_Sponge »` I could link `KeccakWidth1600_Sponge.o` as well but there are more than 30 files, I really don't want to get into that. – Raphael D. Mar 10 '18 at 12:46
  • If no actual static library is created (you have searched for it everywhere?) then you might want to do it yourself. Either by modifying the libraries makefile to automatically create the library as part of its build process, or manually (perhaps as part of *your* build process?). Either that, or link with every single object file needed. – Some programmer dude Mar 10 '18 at 12:55
  • @Someprogrammerdude After thorough search I have found a **libkeccak.a** file. How should I use it in the compilation ? – Raphael D. Mar 10 '18 at 13:50
  • Instead of using the object file, use the library file. – Some programmer dude Mar 10 '18 at 14:45

1 Answers1

0

It finally worked. Just for the record, here is what I had to do:

  • look for a .a file instead of a folder
  • wrap the include as follows, because the library is written in C extern "C" {#include "libkeccak.a.headers/SimpleFIPS202.h"}
  • run g++ Lamport/lamportOTS.cpp -o Lamport/lamportOTS -L[folder containing libkeccak.a] -lkeccak (the order seems to matter)
Raphael D.
  • 778
  • 2
  • 7
  • 18