Commit 8e9efedf authored by yiwenshao's avatar yiwenshao

add test_crypto

parent a2673803
...@@ -108,6 +108,10 @@ mtl/tools/%:$(OBJDIR)/tools/%.o $(OBJDIR)/libredisbio.so $(OBJDIR)/libwrapper.so ...@@ -108,6 +108,10 @@ mtl/tools/%:$(OBJDIR)/tools/%.o $(OBJDIR)/libredisbio.so $(OBJDIR)/libwrapper.so
@mkdir -p $(@D) @mkdir -p $(@D)
$(CXX) -g -o $@ $< $(CXXFLAGS) $(LDFLAGS) -L/$(MYBUILD)/libmysqld -lmysqld -laio -lz -ldl -lm -lcrypt -lpthread -lwrapper -lcryptdb -ledbcrypto -ledbutil -ledbparser -lntl -lcrypto -lredisbio $(CXX) -g -o $@ $< $(CXXFLAGS) $(LDFLAGS) -L/$(MYBUILD)/libmysqld -lmysqld -laio -lz -ldl -lm -lcrypt -lpthread -lwrapper -lcryptdb -ledbcrypto -ledbutil -ledbparser -lntl -lcrypto -lredisbio
mtl/test_crypto_exe/%:$(OBJDIR)/test_crypto/%.o
@mkdir -p $(@D)
$(CXX) -g -o $@ $^ $(CXXFLAGS) $(LDFLAGS) -L/$(MYBUILD)/libmysqld -lmysqld -laio -lz -ldl -lm -lcrypt -lpthread -ledbutil -lntl -ledbcrypto -lcrypto
include crypto/Makefrag include crypto/Makefrag
include parser/Makefrag include parser/Makefrag
...@@ -125,6 +129,7 @@ include test_parser_helper/Makefrag ...@@ -125,6 +129,7 @@ include test_parser_helper/Makefrag
include redisbio/Makefrag include redisbio/Makefrag
include test_redisbio/Makefrag include test_redisbio/Makefrag
include tools/Makefrag include tools/Makefrag
include test_crypto/Makefrag
$(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d)) $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d))
@mkdir -p $(@D) @mkdir -p $(@D)
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <iomanip> #include <iomanip>
#include <crypto/padding.hh> #include <crypto/padding.hh>
#include <crypto/prng.hh> #include <crypto/prng.hh>
#include <crypto/BasicCrypto.hh> #include <crypto/BasicCrypto.hh>
......
OBJDIRS += test_crypto
##note that xx=*.cc will not expand. wildcard *.cc will include files from other directories.
##%.o will include testall
TESTALL_OBJS := $(patsubst %.cc,$(OBJDIR)/%.o,$(wildcard test_crypto/*.cc))
TESTALL_EXES := $(patsubst test_crypto/%.cc,mtl/test_crypto_exe/%,$(wildcard test_crypto/*.cc))
all: $(TESTALL_OBJS) $(TESTALL_EXES)
int
main() {
return 0;
}
#include <string>
#include <map>
#include <iostream>
#include <memory>
#include <iomanip>
#include <crypto/padding.hh>
#include <crypto/prng.hh>
#include <crypto/BasicCrypto.hh>
#include <crypto/blowfish.hh>
#include <crypto/arc4.hh>
#include <crypto/cbc.hh>
#include <crypto/ope.hh>
#include <util/util.hh>
#include <NTL/ZZ.h>
using namespace NTL;
static std::string prng_expand(const std::string &seed_key, uint key_bytes){
streamrng<arc4> prng(seed_key);
return prng.rand_string(key_bytes);
}
static
void test_OPEint() {
std::string key = "12345798797";
std::string rawkey = prng_expand(key, 16);
const size_t plain_size = 4;
const size_t ciph_size = 8;
OPE ope(rawkey,8*plain_size,8*ciph_size);
uint64_t plaintext = 123456789;
NTL::ZZ enc,dec;
uint64_t enc64,dec64;
enc = ope.encrypt(ZZFromUint64(plaintext));
enc64 = uint64FromZZ(enc);
dec = ope.decrypt(ZZFromUint64(enc64));
dec64 = uint64FromZZ(dec);
std::cout<<"enc: "<<enc<<"dec: "<<dec<<std::endl;
std::cout<<"enc64: "<<enc64<<"dec64:"<<dec64<<std::endl;
}
int
main(){
test_OPEint();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment