I am writing a secure instant messenger in C ++ using the libtomcrypt C library for my RSA and SPRNG functions. I got libtomcrypt compiled as a static library, and I was able to link to it and run the sprng functions, as well as view and use the arbitrary data that it generates.
The problem I am facing is trying to use the rsa_make_key () function, which has dependencies on the associated math library.
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 are in the folder of your project in one directory from my project folder (i.e. .. / 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 . This makes me think that tfm is not properly bound to libtomcrypt. I read the documentation about all these things, this is not very clear.
I am here. What am I 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 #COBJECTS=$(CSOURCES:.c=.o)libtfm.a libtomcrypt.a COBJECTS=$(CSOURCES:.c=.o) CPPOBJECTS=$(CPPSOURCES:.cpp=.o) BINARY=down_low all: $(BINARY) $(COBJECTS) $(CPPOBJECTS) .co: $(CC) $(CFLAGS) -c $< -o $@ .cpp.o: $(CPP) $(CPPFLAGS) -c $< -o $@ $(BINARY): $(COBJETS) $(CPPOBJECTS) $(CPP) $(CPPFLAGS) $(COBJECTS) $(CPPOBJECTS) -o $@ $(LDFLAGS) clean: rm -rv $(BINARY) $(COBJECTS) $(CPPOBJECTS)
and here is my test_crypt function
#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 }
source share