Commit 7bded8cb authored by yiwenshao's avatar yiwenshao

add simple version of ashe

parent 54c275b5
#include"crypto/ASHE.hh"
const unsigned long long ASHE::ASHE_MAX = 0xffffffffffffffff;
ASHE::ASHE(std::string s,int i):key(s),bf(s),IV(i){}
long ASHE::encrypt(unsigned long long plaintext){
return (plaintext - bf.encrypt(IV) + bf.encrypt(IV-1))%ASHE_MAX;
}
unsigned long long ASHE::decrypt(long ciphertext){
return (ciphertext + bf.encrypt(IV) - bf.encrypt(IV-1))%ASHE_MAX;
}
#pragma once
#include <string>
#include "crypto/blowfish.hh"
class ASHE{
static const unsigned long long ASHE_MAX;
std::string key;
blowfish bf;
int IV;
public:
ASHE(std::string s,int i);
long encrypt(unsigned long long plaintext);
int getIV();
unsigned long long decrypt(long ciphertext);
};
OBJDIRS += crypto
CRYPTOSRC := BasicCrypto.cc paillier.cc urandom.cc arc4.cc hgd.cc pbkdf2.cc \
ecjoin.cc ECJoin.cc search.cc skip32.cc ffx.cc online_ope.cc mont.cc \
prng.cc ope.cc SWPSearch.cc
prng.cc ope.cc SWPSearch.cc ASHE.cc
CRYPTOOBJ := $(patsubst %.cc,$(OBJDIR)/crypto/%.o,$(CRYPTOSRC))
all: $(OBJDIR)/libedbcrypto.a $(OBJDIR)/libedbcrypto.so
......@@ -14,13 +16,13 @@ $(OBJDIR)/libedbcrypto.a: $(CRYPTOOBJ)
$(AR) r $@ $(CRYPTOOBJ)
#all: $(OBJDIR)/crypto/x
$(OBJDIR)/crypto/x: $(OBJDIR)/crypto/x.o $(OBJDIR)/libedbcrypto.so
$(CXX) $< -o $@ $(LDFLAGS) $(LDRPATH) -ledbcrypto
#install: install_crypto
#.PHONY: install_crypto
#install_crypto: $(OBJDIR)/libedbcrypto.so
# install -m 644 $(OBJDIR)/libedbcrypto.so /usr/lib
install: install_crypto
# vim: set noexpandtab:
.PHONY: install_crypto
install_crypto: $(OBJDIR)/libedbcrypto.so
install -m 644 $(OBJDIR)/libedbcrypto.so /usr/lib
......@@ -2,6 +2,7 @@
#include <vector>
#include <stdint.h>
#include <string>/*why is this omitted?*/
#include <openssl/blowfish.h>
class blowfish {
......
#include <vector>
#include <iostream>
#include "crypto/ASHE.hh"
int main(){
std::vector<unsigned long long > plain{1u,2u,3u,4u,5u,6u,7u,8u,9u,10u};
std::vector<long> enc;
ASHE as("2222",1);
for(auto item:plain){
enc.push_back(as.encrypt(item));
}
std::cout<<"encs:plains"<<std::endl;
for(auto item:enc){
std::cout<<"enc:"<<item<<"dec:"<<as.decrypt(item)<<std::endl;
}
return 0;
}
#include <string>
#include <map>
#include <iostream>
#include <functional>
#include <cctype>
#include <locale>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <main/CryptoHandlers.hh>
#include <crypto/padding.hh>
#include <util/errstream.hh>
#include <util/cryptdb_log.hh>
#include <util/enum_text.hh>
#include <util/yield.hpp>
#include "util/onions.hh"
#include <vector>
#include <memory>
#include <iomanip>
#include <crypto/padding.hh>
#include <crypto/prng.hh>
#include <crypto/BasicCrypto.hh>
#include <crypto/blowfish.hh>
#include <crypto/SWPSearch.hh>
#include <crypto/BasicCrypto.hh>
#include <crypto/arc4.hh>
#include <crypto/cbc.hh>
#include <crypto/cmc.hh>
#include <util/util.hh>
#include <util/zz.hh>
#include <cmath>
#include <NTL/ZZ.h>
using namespace NTL;
using std::string;
......@@ -74,9 +58,6 @@ static string generateStringOfLen(int len){
return string(len,'a');
}
static void test_RNDstr(string ptext,int numOfTest){
string key="123456789";
string rawkey = prng_expand(key, 16);
......@@ -84,7 +65,6 @@ static void test_RNDstr(string ptext,int numOfTest){
const std::unique_ptr<const AES_KEY> deckey(get_AES_dec_key(rawkey));
uint64_t IV = 1234567;
uint64_t start = cur_usec();
// cout<<"ptext len = "<<ptext.size()<<" : "<<"key len = "<<rawkey.size()<<endl;
string enc,dec;
for(int i=1;i<=numOfTest;i++){
enc = encrypt_AES_CBC(ptext,enckey.get(),BytesFromInt(IV, SALT_LEN_BYTES),true);
......
find . | grep '\.c$\|\.cc$$\|\.h$\|\.hh$'| xargs ctags
find . | grep '\.c$\|\.cc$\|\.h$\|\.hh$'| xargs ctags
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