From 067ba4a39729f1e33b41c60c826274a4c4c38b8d Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 8 Oct 2016 22:15:26 +0200 Subject: Lib-ify --- .gitignore | 2 +- Makefile | 16 ++--- main.cpp | 240 ------------------------------------------------------------- 3 files changed, 8 insertions(+), 250 deletions(-) delete mode 100644 main.cpp diff --git a/.gitignore b/.gitignore index 89805cd..cdd3cd9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ *.o *.dSYM -main +cryptolib.a *.txt diff --git a/Makefile b/Makefile index 5778290..87bf616 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,26 @@ CXX = g++ CXXFLAGS = -Wall -Wextra -std=c++0x -fwrapv -LDFLAGS = ifneq ($(DEBUG),) CXXFLAGS += -g else CXXFLAGS += -O2 endif -ifeq ($(shell uname),Linux) - LDFLAGS += -lbsd -endif -BIN = main + +LIBNAME = cryptolib.a + .PHONY: all clean remake -all: $(BIN) +all: $(LIBNAME) clean: - rm -rf $(BIN) *.o *.dSYM + rm -rf $(LIBNAME) *.o remake: clean all -$(BIN): $(patsubst %.cpp,%.o,$(wildcard *.cpp)) - $(CXX) -o $@ $^ $(LDFLAGS) +$(LIBNAME): $(patsubst %.cpp,%.o,$(wildcard *.cpp)) + ar -cr $@ $^ %.o: %.cpp $(wildcard *.h) $(CXX) $(CXXFLAGS) -c -o $@ $< diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 2385da8..0000000 --- a/main.cpp +++ /dev/null @@ -1,240 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "aes.h" -#include "base64.h" -#include "bigint.h" -#include "envelope.h" -#include "numalgo.h" -#include "primes.h" -#include "rng.h" -#include "rsa.h" - -using namespace std; - -class eof_error : public runtime_error{ -public: - eof_error() - :runtime_error("EOF"){} -}; - -int64_t rand64(){ - return ((int64_t)rand()<<32)+(((int64_t)rand()%2)<<31)+rand(); -} - -Bigint readevalexpr(istream &is){ - Bigint a; - is>>a; - if(is.eof())throw eof_error(); - // cerr<<"Read "<>s; - assert(!is.fail()); - a=readevalexpr(is); - Bigint b=readevalexpr(is); - //cerr<<"Operation "<>bi; - assert(bi==Bigint(n)); - } - } -#endif - -#if 1 - { - string s="4405994068155852661780322209877856931246944549396705884037139443014164958640201650440984581318995014"; - istringstream iss(s); - Bigint bi; - iss>>bi; - uint32_t digs[11]={1752788038,953502834,2175607868,1627159508,1754291416,1207689192,3196357285,3165170272,3313904421,3194703103,2062}; - for(int i=0;i<11;i++)assert(bi._digit(i)==digs[i]); - ostringstream oss; - oss<=1); - for(int i=0;i<1000;i++){ - Bigint n(rand64()); - for(int j=1;jn); - } -} - -void performrsa(){ - RSA::PrivateKey privkey; - Bigint p(1000000007),q(3000000019U); - privkey.pub.mod=(int64_t)3000000040000000133LL; - privkey.pub.exp=65537; - { - Bigint x; - egcd((p-Bigint::one)*(q-Bigint::one),privkey.pub.exp,x,privkey.pexp); - } - cout<<"d = "<>d; - // cout<