I am writing a secure instant messaging program in c++ using the libtomcrypt C library for its RSA and SPRNG functions. I got libtomcrypt compiled as a static library and I have been able to link to it and run the sprng functions and see and use the random data it is generating.
The problem I am having is trying to use the rsa_make_key() function which has dependencies to a linked math library to function.
In this case I am trying to use Tomsfastmath (tfm) which I am also trying to link as a static library. Both of these libraries reside in their own project folder one directory up from my project folder (ie ../libtomcrypt)
In my code when I try to access the tomsfast math descriptor "tfm_desc" I get the error
test_crypt.cpp:8:11: error: 'tfm_desc' was not declared in this scope. Which makes me think that tfm is not getting correctly linked into libtomcrypt. I have read the documentation for both of these things its not very clear.
I am at wits end here. What I am doing wrong?
Here is my 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
all: $(BINARY) $(COBJECTS) $(CPPOBJECTS)
$(CC) $(CFLAGS) -c $< -o [email protected]
$(CPP) $(CPPFLAGS) -c $< -o [email protected]
$(BINARY): $(COBJETS) $(CPPOBJECTS)
$(CPP) $(CPPFLAGS) $(COBJECTS) $(CPPOBJECTS) -o [email protected] $(LDFLAGS)
rm -rv $(BINARY) $(COBJECTS) $(CPPOBJECTS)
and here is my test_crypt function
using namespace std;
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
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
//sprng_read(entropy, size, &random_gen);
if((err = rsa_make_key(NULL, //PRNG state
rng_idx, //PRNG idx
1024/8, //Size of key
&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
-DTFM_DESC to your makefile's
CPPFLAGS variables so the headers will declare
tfm_desc as an
tfm_desc variable should then get pulled in from the library.
You need to include the relevant header in your test_crypt file.
I incorrectly stated that you would need to include
tfm.h earlier. You should
#include "tomcrypt.h" instead, as it should provide you with the constant you need.
To clarify what melpomene said, your issue is that you're not including the correct headers which is causing the compiler to - correctly - tell you that the identifier you are using is not declared.