c++compilationkeccak

Using Keccak Library in a C++ project


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

Solution

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