2012-12-08 13 views
6

Sto scrivendo un programma di messaggistica istantanea sicuro in C++ utilizzando la libreria C libtomcrypt per le sue funzioni RSA e SPRNG. Ho ottenuto libtomcrypt compilato come libreria statica e sono stato in grado di collegarlo ad esso ed eseguire le funzioni sprng e vedere e utilizzare i dati casuali che sta generando.Impossibile collegare tomsfastmath in libtomcrypt

Il problema che sto riscontrando è quello di provare a utilizzare la funzione rsa_make_key() che ha funzioni di dipendenza da una libreria matematica collegata.

In questo caso sto cercando di utilizzare Tomsfastmath (tfm) che sto anche cercando di collegare come libreria statica. Entrambe queste librerie risiedono nella loro cartella di progetto una directory dalla cartella del mio progetto (ie ../libtomcrypt)

Nel mio codice quando provo ad accedere al tomsfast descrittore di matematica "tfm_desc" ottengo l'errore test_crypt.cpp:8:11: error: 'tfm_desc' was not declared in this scope. Il che mi fa pensare che tfm non viene collegato correttamente in libtomcrypt. Ho letto la documentazione per entrambe queste cose non è molto chiara.

Sono qui a fine di intelligenza. Cosa sto facendo di sbagliato?

Ecco il mio make file

CC:=gcC#C Compiler 
CFLAGS:=-std=c99 -O0 -I/home/k3rb3ros/csci484-CMU-/libtomcrypt-1.17/src/headers -g -  Wall -Wextra#C Compiler flags 
CPP:=g++ #C++ Compiler 
CPPFLAGS:=-std=gnu++0x -O0 -I/home/k3rb3ros/csci484/csci484-CMU-/libtomcrypt- 1.17/src/headers -L. -g -Wall -Wextra#C++ Compiler flags 
#CPPFLAGS:=-std=gnu++0x -O0 -g -Wall -Wextra #C++ Compiler flags 
LDFLAGS:= -lSDL -lSDL_net -ltfm -ltomcrypt 
CSOURCES= #C files used in this program 
CPPSOURCES=connection.cpp chat.cpp test_crypt.cpp #CPP files used in this prgram 
#COBJECTS=$(CSOURCES:.c=.o)libtfm.a libtomcrypt.a 
COBJECTS=$(CSOURCES:.c=.o) 
CPPOBJECTS=$(CPPSOURCES:.cpp=.o) 
BINARY=down_low 

all: $(BINARY) $(COBJECTS) $(CPPOBJECTS) 
.c.o: 
     $(CC) $(CFLAGS) -c $< -o [email protected] 

.cpp.o: 
     $(CPP) $(CPPFLAGS) -c $< -o [email protected] 

    $(BINARY): $(COBJETS) $(CPPOBJECTS) 
     $(CPP) $(CPPFLAGS) $(COBJECTS) $(CPPOBJECTS) -o [email protected] $(LDFLAGS) 

    clean: 
    rm -rv $(BINARY) $(COBJECTS) $(CPPOBJECTS) 

e qui è la mia funzione test_crypt

#include "headers/test_crypt.h" 
using namespace std; 

void test_crypt() 
{ 
    int err = 0; 
    int rng_idx = -1; //rng index, not sure if I need this 
    ltc_mp = tfm_desc; //tell tomcrypt to use toms fast math 
    rsa_key pub_key; 
    prng_state random_gen; 

    if((err = sprng_start(&random_gen)) != CRYPT_OK) //start the rng and check for errors 
    { 
     cout << "start error " << error_to_string(err) << endl; 
    } 

    rng_idx = find_prng("sprng"); 
    if((err = sprng_ready(&random_gen)) != CRYPT_OK) 
    { 
     cout << "Ready error " << error_to_string(err) << endl; 
    } 

    //test toms fast math present and working 
    //fp_int test; 
    //fp_init(&test); 

    //sprng_read(entropy, size, &random_gen); 

    /* 
    if((err = rsa_make_key(NULL,   //PRNG state 
          rng_idx,  //PRNG idx 
          1024/8,   //Size of key 
          65537,   //e 
          &pub_key)  //RSA key 
          ) != CRYPT_OK) //if conditon test 
    { 
     cout << "RSA Key Generation error " << error_to_string(err) << endl; 
    } 
    rsa_free(&pub_key); //free the key when we are done with it; 
    */ 
    sprng_done(&random_gen); //done generating random numbers 
} 
+1

Questo è un errore del compilatore, non un errore del linker. – melpomene

risposta

0

Aggiungi -DTFM_DESC al CFLAGS e CPPFLAGS variabili di makefile in modo che le intestazioni dichiareranno tfm_desc come variabile extern.

La variabile tfm_desc deve quindi essere richiamata dalla libreria.

+0

Come nota a margine, potresti voler rinominare 'CPPFLAGS' in' CXXFLAGS'. 'CPPFLAGS' è spesso usato per configurare le opzioni per il preprocessore C; 'CXXFLAGS' è spesso usato per C++. –

+0

Sono riuscito a compilare il mio codice aggiungendo -DTFM_DESC a CPP (dovrebbero essere i flag CXX) e fissando il -L puntando alla cartella sbagliata. Grazie per l'aiuto. Normalmente i Makefile sono fantastici ma questo progetto è sfuggito di mano. – K3rb3ros

0

È necessario includere l'intestazione corrispondente nel file test_crypt.

In modo errato affermavo che sarebbe necessario includere tfm.h in precedenza. Devi invece #include "tomcrypt.h", in quanto dovrebbe fornirti la costante di cui hai bisogno.

Per chiarire che cosa diceva melpomene, il problema è che non si includono le intestazioni corrette che stanno causando al compilatore di - correttamente - dirti che l'identificatore che stai usando non è dichiarato.

+0

è incluso nel file myheader. Vorrei che la soluzione fosse facile, ma qualcos'altro sta succedendo qui. – K3rb3ros

Problemi correlati