├── .gitignore ├── INSTALL.sh ├── LICENSE ├── Makefile ├── README.md ├── cdbclient.sh ├── cdbserver.sh ├── crypto ├── BasicCrypto.cc ├── BasicCrypto.hh ├── ECJoin.cc ├── ECJoin.hh ├── Makefrag ├── SWPSearch.cc ├── SWPSearch.hh ├── aes.hh ├── all ├── arc4.cc ├── arc4.hh ├── blowfish.hh ├── bn.hh ├── cbc.hh ├── cbcmac.hh ├── cmc.hh ├── dj.hh ├── ec.hh ├── ecjoin.cc ├── ecjoin.hh ├── ffx.cc ├── ffx.hh ├── gfe.hh ├── hgd.cc ├── hgd.hh ├── hmac.hh ├── mont.cc ├── mont.hh ├── online_ope.cc ├── online_ope.hh ├── ope-exp.cc ├── ope.cc ├── ope.hh ├── padding.hh ├── paillier.cc ├── paillier.hh ├── pbkdf2.cc ├── pbkdf2.hh ├── prng.cc ├── prng.hh ├── search.cc ├── search.hh ├── sha.hh ├── skip32.cc ├── skip32.hh └── urandom.cc ├── debug ├── Makefrag ├── hello.cc ├── local_client.cc ├── test_createHandler.cc ├── test_insertHandler.cc ├── test_load_schema.cc └── test_proxy.cc ├── insert.sh ├── main ├── Analysis.cc ├── Analysis.hh ├── Connect.cc ├── Connect.hh ├── CryptoHandlers.cc ├── CryptoHandlers.hh ├── Makefrag ├── Translator.cc ├── Translator.hh ├── alter_sub_handler.cc ├── alter_sub_handler.hh ├── big_proxy.cc ├── big_proxy.hh ├── cdb_test.cc ├── change_test.cc ├── dbobject.hh ├── ddl_handler.cc ├── ddl_handler.hh ├── dispatcher.cc ├── dispatcher.hh ├── dml_handler.cc ├── dml_handler.hh ├── error.cc ├── error.hh ├── load_and_store.cc ├── macro_util.hh ├── metadata_tables.cc ├── metadata_tables.hh ├── rewrite_const.cc ├── rewrite_ds.cc ├── rewrite_ds.hh ├── rewrite_field.cc ├── rewrite_func.cc ├── rewrite_main.cc ├── rewrite_main.hh ├── rewrite_sum.cc ├── rewrite_util.cc ├── rewrite_util.hh ├── schema.cc ├── schema.hh ├── serializers.hh ├── sql_handler.cc ├── sql_handler.hh ├── stored_procedures.cc ├── stored_procedures.hh ├── test_layer.cc ├── test_proxy.cc └── test_schema.cc ├── mbk.cc ├── mergedep.pl ├── metadata.data ├── mysql-proxy.cnf ├── mysqlproxy ├── ConnectWrapper.cc └── Makefrag ├── packages ├── bison_2.7.1.dfsg-1_amd64.deb ├── libbison-dev_2.7.1.dfsg-1_amd64.deb ├── mysql-proxy-0.8.5.tar.gz ├── mysql-src.tar.gz └── tls │ ├── buildtags.sh │ ├── essential.sh │ ├── gdbs │ ├── int.sh │ ├── intnormal.sh │ ├── myback │ ├── mydumper │ ├── .bzrignore │ ├── CMakeCache.txt │ ├── CMakeFiles │ │ ├── 3.5.1 │ │ │ ├── CMakeCCompiler.cmake │ │ │ ├── CMakeCXXCompiler.cmake │ │ │ ├── CMakeDetermineCompilerABI_C.bin │ │ │ ├── CMakeDetermineCompilerABI_CXX.bin │ │ │ ├── CMakeSystem.cmake │ │ │ ├── CompilerIdC │ │ │ │ ├── CMakeCCompilerId.c │ │ │ │ └── a.out │ │ │ └── CompilerIdCXX │ │ │ │ ├── CMakeCXXCompilerId.cpp │ │ │ │ └── a.out │ │ ├── CMakeDirectoryInformation.cmake │ │ ├── CMakeOutput.log │ │ ├── CMakeRuleHashes.txt │ │ ├── Makefile.cmake │ │ ├── Makefile2 │ │ ├── TargetDirectories.txt │ │ ├── cmake.check_cache │ │ ├── dist.dir │ │ │ ├── DependInfo.cmake │ │ │ ├── build.make │ │ │ ├── cmake_clean.cmake │ │ │ └── progress.make │ │ ├── feature_tests.bin │ │ ├── feature_tests.c │ │ ├── feature_tests.cxx │ │ ├── mydumper.dir │ │ │ ├── C.includecache │ │ │ ├── DependInfo.cmake │ │ │ ├── build.make │ │ │ ├── cmake_clean.cmake │ │ │ ├── depend.internal │ │ │ ├── depend.make │ │ │ ├── flags.make │ │ │ ├── link.txt │ │ │ └── progress.make │ │ ├── myloader.dir │ │ │ ├── C.includecache │ │ │ ├── DependInfo.cmake │ │ │ ├── build.make │ │ │ ├── cmake_clean.cmake │ │ │ ├── depend.internal │ │ │ ├── depend.make │ │ │ ├── flags.make │ │ │ ├── link.txt │ │ │ └── progress.make │ │ └── progress.marks │ ├── CMakeLists.txt │ ├── Makefile │ ├── README │ ├── binlog.c │ ├── binlog.h │ ├── cmake │ │ └── modules │ │ │ ├── CppcheckTargets.cmake │ │ │ ├── FindGLIB2.cmake │ │ │ ├── FindMySQL.cmake │ │ │ ├── FindPCRE.cmake │ │ │ ├── FindSphinx.cmake │ │ │ ├── Findcppcheck.cmake │ │ │ └── Findcppcheck.cpp │ ├── cmake_install.cmake │ ├── common.h │ ├── config.h │ ├── config.h.in │ ├── dest │ │ ├── metadata │ │ ├── tdb3-schema-create.sql │ │ ├── tdb3.student-schema.sql │ │ └── tdb3.student.sql │ ├── docs │ │ ├── CMakeFiles │ │ │ ├── CMakeDirectoryInformation.cmake │ │ │ └── progress.marks │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── _build │ │ │ ├── conf.py.in │ │ │ └── sources.cmake.in │ │ ├── authors.rst │ │ ├── cmake_install.cmake │ │ ├── compiling.rst │ │ ├── examples.rst │ │ ├── files.rst │ │ ├── index.rst │ │ ├── mydumper_usage.rst │ │ └── myloader_usage.rst │ ├── g_unix_signal.c │ ├── g_unix_signal.h │ ├── mydumper │ ├── mydumper.c │ ├── mydumper.h │ ├── myloader │ ├── myloader.c │ ├── myloader.h │ ├── server_detect.c │ └── server_detect.h │ ├── mysqlWrapper │ ├── Makefile │ ├── analysis.cc │ ├── backFieldsToFiles.cc │ ├── createSelect.cc │ ├── inmain │ ├── main.cc │ └── mysqllib │ │ ├── MyConnect.cc │ │ ├── MyConnect.h │ │ ├── utilities.cc │ │ └── utilities.h │ ├── shell │ ├── a │ ├── count.sh │ └── insert.sh │ ├── stopgdbs │ ├── str.sh │ ├── strnormal.sh │ └── tpcc-mysql │ ├── Dockerfile │ ├── README.md │ ├── a │ ├── add_fkey_idx.sql │ ├── count.sql │ ├── create_table.sql │ ├── cryptbenchmark.sh │ ├── drop_cons.sql │ ├── load.sh │ ├── load_multi_schema.sh │ ├── normalbenchmark.sh │ ├── schema2 │ ├── add_fkey_idx.sql │ ├── count.sql │ ├── create_table.sql │ └── drop_cons.sql │ ├── scripts │ ├── 2instances │ │ └── run.sh │ ├── analyze.full.sh │ ├── analyze.sh │ ├── analyzeR.sh │ ├── analyze_checkpoint.sh │ ├── analyze_checkpoint_xtradb.sh │ ├── analyze_checkpoint_xtradb1.sh │ ├── analyze_dirty.sh │ ├── analyze_evicted.sh │ ├── analyze_flushed.sh │ ├── analyze_flushed_innodb.sh │ ├── analyze_min.sh │ ├── analyze_modified.sh │ ├── flashcache_stat.sh │ ├── innodb_stat.sh │ ├── memlock │ ├── memlock.c │ ├── multi-instances │ │ └── runX.sh │ ├── parse_trx.py │ ├── remote │ │ └── runX.sh │ ├── run.sh │ ├── runX.sh │ ├── run_no_backup.sh │ └── virident_stat.sh │ ├── src │ ├── Makefile │ ├── delivery.c │ ├── delivery.o │ ├── driver.c │ ├── driver.o │ ├── load.c │ ├── load.o │ ├── main.c │ ├── main.o │ ├── neword.c │ ├── neword.o │ ├── ordstat.c │ ├── ordstat.o │ ├── parse_port.h │ ├── payment.c │ ├── payment.o │ ├── rthist.c │ ├── rthist.h │ ├── rthist.o │ ├── sb_percentile.c │ ├── sb_percentile.h │ ├── sb_percentile.o │ ├── sequence.c │ ├── sequence.h │ ├── sequence.o │ ├── slev.c │ ├── slev.o │ ├── spt_proc.c │ ├── spt_proc.h │ ├── spt_proc.o │ ├── support.c │ ├── support.o │ ├── tpc.h │ └── trans_if.h │ ├── tpcc_load │ └── tpcc_start ├── parser ├── Makefrag ├── README ├── embedmysql.cc ├── embedmysql.hh ├── lex_util.cc ├── lex_util.hh ├── mysql_type_metadata.cc ├── mysql_type_metadata.hh ├── mysqld-filler.cc ├── sql_utils.cc ├── sql_utils.hh └── stringify.hh ├── reset.sh ├── results ├── setup.sh ├── tutorial-basic.lua ├── udf ├── Makefrag ├── create.sql └── edb.cc ├── util ├── Makefrag ├── cleanup.hh ├── coroutine.hpp ├── cryptdb_log.cc ├── cryptdb_log.hh ├── ctr.cc ├── ctr.hh ├── enum_text.hh ├── errstream.hh ├── hello.cc ├── onions.cc ├── onions.hh ├── params.hh ├── rob.hh ├── scoped_lock.hh ├── scopedperf.hh ├── timer.hh ├── unyield.hpp ├── util.cc ├── util.hh ├── version.hh ├── yield.hpp └── zz.hh ├── verify.sh └── wrapper.lua /.gitignore: -------------------------------------------------------------------------------- 1 | mysql-src/ 2 | normal.sh 3 | obj/ 4 | tags 5 | shadow/ 6 | core 7 | curMysql 8 | reset.sql 9 | test 10 | cscope.files 11 | cscope.out 12 | cscope.files 13 | cscope.out 14 | tags 15 | readFile 16 | writeFile 17 | *CMakeFiles* 18 | *all* 19 | *back1.sql 20 | *back.sql 21 | *load.sql 22 | data 23 | mtl 24 | -------------------------------------------------------------------------------- /INSTALL.sh: -------------------------------------------------------------------------------- 1 | sudo apt update -y 2 | sudo apt remove bison libbison-dev -y 3 | sudo apt upgrade -y 4 | sudo apt install g++-4.7 gawk liblua5.1-0-dev libntl-dev libmysqlclient-dev libssl-dev libbsd-dev libevent-dev libglib2.0-dev libgmp-dev mysql-server libaio-dev automake gtk-doc-tools flex cmake libncurses5-dev make ruby lua5.1 libmysqld-dev exuberant-ctags cscope -y 5 | cd packages;sudo dpkg -i libbison-dev_2.7.1.dfsg-1_amd64.deb;sudo dpkg -i bison_2.7.1.dfsg-1_amd64.deb;cd .. 6 | 7 | 8 | echo =============COMPILE MYSQL================================ 9 | 10 | rm -rf mysql-src 11 | tar -xvf packages/mysql-src.tar.gz 12 | export CXX=g++-4.7 13 | cd mysql-src;mkdir build;cd build;cmake -DWITH_EMBEDDED_SERVER=on -DENABLE_DTRACE=off .. ; make;cd ../..; 14 | 15 | echo ===============OK======================================== 16 | 17 | 18 | echo =============INSTALL MYSQL-proxy========================= 19 | 20 | tar -xvf packages/mysql-proxy-0.8.5.tar.gz -C mysql-src/ 21 | 22 | binpath=`pwd`/mysql-src/mysql-proxy-0.8.5/bin 23 | 24 | echo " " >> ~/.bashrc 25 | echo PATH='$'PATH:${binpath} >> ~/.bashrc 26 | source ~/.bashrc 27 | 28 | echo =============INSTALL Cryptdb============================= 29 | 30 | make 31 | sudo make install 32 | chmod 0660 mysql-proxy.cnf 33 | 34 | echo ============Enjoy it!!!===================================== 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The source code for CryptDB is licensed under the terms of the GPL v3 2 | license, unless otherwise noted (such as in the case of third-party 3 | components and libraries): 4 | 5 | CryptDB is free software: you can redistribute it and/or modify it 6 | under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | CryptDB is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | A copy of the GNU General Public License is included with CryptDB, 16 | under doc/gpl-3.txt. Alternatively, see . 17 | 18 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | MYSRC := $(shell pwd)/mysql-src 2 | MYBUILD := $(MYSRC)/build 3 | RPATH := 1 4 | 5 | CXX := g++-4.7 6 | MYSQL_PLUGIN_DIR := /usr/lib/mysql/plugin 7 | 8 | 9 | OBJDIR := obj 10 | TOP := $(shell echo $${PWD-`pwd`}) 11 | #CXX := g++ 12 | AR := ar 13 | ## -g -O0 -> -O2 14 | CXXFLAGS := -g -O0 -fno-strict-aliasing -fno-rtti -fwrapv -fPIC \ 15 | -Wall -Werror -Wpointer-arith -Wendif-labels -Wformat=2 \ 16 | -Wextra -Wmissing-noreturn -Wwrite-strings -Wno-unused-parameter \ 17 | -Wno-deprecated \ 18 | -Wmissing-declarations -Woverloaded-virtual \ 19 | -Wunreachable-code -D_GNU_SOURCE -std=c++0x -I$(TOP) 20 | LDFLAGS := -L$(TOP)/$(OBJDIR) -Wl,--no-undefined 21 | 22 | 23 | ## Use RPATH only for debug builds; set RPATH=1 in config.mk. 24 | ifeq ($(RPATH),1) 25 | LDRPATH := -Wl,-rpath=$(TOP)/$(OBJDIR) -Wl,-rpath=$(TOP) 26 | endif 27 | 28 | CXXFLAGS += -I$(MYBUILD)/include \ 29 | -I$(MYSRC)/include \ 30 | -I$(MYSRC)/sql \ 31 | -I$(MYSRC)/regex \ 32 | -I$(MYBUILD)/sql \ 33 | -DHAVE_CONFIG_H -DMYSQL_SERVER -DEMBEDDED_LIBRARY -DDBUG_OFF \ 34 | -DMYSQL_BUILD_DIR=\"$(MYBUILD)\" 35 | LDFLAGS += -lpthread -lrt -ldl -lcrypt -lreadline 36 | 37 | ## To be populated by Makefrag files 38 | 39 | OBJDIRS := 40 | 41 | .PHONY: all 42 | all: 43 | 44 | .PHONY: install 45 | install: 46 | 47 | .PHONY: clean 48 | clean: 49 | rm -rf $(OBJDIR) mtl 50 | 51 | .PHONY: doc 52 | doc: 53 | doxygen CryptDBdoxgen 54 | 55 | .PHONY: whitespace 56 | whitespace: 57 | find . -name '*.cc' -o -name '*.hh' -type f -exec sed -i 's/ *$//' '{}' ';' 58 | 59 | .PHONY: always 60 | always: 61 | 62 | # Eliminate default suffix rules 63 | .SUFFIXES: 64 | 65 | # Delete target files if there is an error (or make is interrupted) 66 | .DELETE_ON_ERROR: 67 | 68 | # make it so that no intermediate .o files are ever deleted 69 | .PRECIOUS: %.o 70 | 71 | $(OBJDIR)/%.o: %.cc 72 | @mkdir -p $(@D) 73 | $(CXX) -MD $(CXXFLAGS) -c $< -o $@ 74 | 75 | $(OBJDIR)/%.o: $(OBJDIR)/%.cc 76 | @mkdir -p $(@D) 77 | $(CXX) -MD $(CXXFLAGS) -c $< -o $@ 78 | 79 | mtl/%:$(OBJDIR)/debug/%.o 80 | @mkdir -p $(@D) 81 | $(CXX) -g -o $@ $^ $(CXXFLAGS) $(LDFLAGS) -L/$(MYBUILD)/libmysqld -lmysqld -laio -lz -ldl -lm -lcrypt -lpthread -lcryptdb -ledbcrypto -ledbutil -ledbparser -lntl -lcrypto 82 | 83 | 84 | 85 | 86 | include crypto/Makefrag 87 | include parser/Makefrag 88 | include main/Makefrag 89 | include util/Makefrag 90 | include udf/Makefrag 91 | include mysqlproxy/Makefrag 92 | include debug/Makefrag 93 | 94 | 95 | $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d)) 96 | @mkdir -p $(@D) 97 | perl mergedep.pl $@ $^ 98 | echo "after merge" 99 | -include $(OBJDIR)/.deps 100 | 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Make cryptdb Practical 2 | 3 | Cryptdb originated from MIT. This is a modified version. In this project, we try to add new features, fix bugs we meet in our environment, and rewrite the code and comments to make the source code easy to understand. Introduction to the features will be posted at yiwenshao.github.io. Also, analysis of the source code will be posted there so that you do not need so much effort contributing to this project. 4 | 5 | To deploy this version, you need follow the following steps. 6 | 7 | + have ubuntu 16.04 installed 8 | + install mysql-server 5.5 or higher, with the root password 'letmein' 9 | To verify this, you can use the command mysql -uroot -pletmein to log in 10 | + ./INSTALL.sh 11 | + source ~/.bashrc 12 | + source setup.sh 13 | + run ./cdbserver.sh 14 | + run ./cdbclient.sh 15 | + enjoy it! 16 | 17 | 18 | 19 | If you meet any problems installing it, or if you meet bugs or need new features that if not yet supported, post issues or contact me via shaoyiwenetATgmailDotcom. 20 | 21 | 22 | 23 | New features added 24 | 25 | + foreign key constraint 26 | 27 | ``` 28 | create table student (id integer primary key); 29 | create table choose (sid integer, foreign key fk(sid) references student(id)); 30 | insert into student values(1); 31 | insert into choose values(1); 32 | 33 | ``` 34 | 35 | + set user variable 36 | + timestamp 37 | + show create table 38 | + cdb_test for simple curd 39 | 40 | obselete functions deleted 41 | 42 | + annotation 43 | + dbobject.tt 44 | 45 | ### features to be added 46 | 47 | + extended-insert 48 | + QUOTE 49 | + Search 50 | -------------------------------------------------------------------------------- /cdbclient.sh: -------------------------------------------------------------------------------- 1 | `pwd`/mysql-src/build/client/mysql -uroot -pletmein -h 127.0.0.1 -P3399 2 | -------------------------------------------------------------------------------- /cdbserver.sh: -------------------------------------------------------------------------------- 1 | mkdir shadow 2 | mysql-proxy --defaults-file=./mysql-proxy.cnf --proxy-lua-script=`pwd`/wrapper.lua 3 | 4 | -------------------------------------------------------------------------------- /crypto/ECJoin.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * ECJoin.h 5 | * 6 | * Implements CryptDB's adjustable join encryption scheme. 7 | * It is based on the elliptic-curve DDH assumption. 8 | * 9 | * Currently, it is using the NIST curve denoted NID_X9_62_prime192v1 believed to satisfy ECDDH 10 | * To use a different NIST curve, simply modify the NID field below. 11 | * 12 | * 13 | * Public parameters: 14 | * G: elliptic curve group of prime order 15 | * P: a random point on the elliptic curve 16 | * order: the order of G 17 | * 18 | * To encrypt v, we compute E_k[v] := PRF_k(v) * k * P \in G, where 19 | * k: secret key 20 | * 21 | * To adjust encryption of v under k1, to encryption under k2, we perform: 22 | * \delta k = k2 * k1^{-1} mod order 23 | * E_k2[v] = E_k1[v]*\delta k \in G 24 | * 25 | * TODO: may speed up by: 26 | * - passing BN_CTX * to some functions (and CTX for point, group, if any) 27 | * - using ssl's preprocessing functions 28 | * - use NIST curves with less bits representation, e.g., NID_secp160r1; there are even shorter 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | 38 | struct ECJoinSK{ 39 | const AES_KEY * aesKey; 40 | BIGNUM * k; //secret key 41 | EC_POINT * kP; 42 | }; 43 | 44 | struct ECDeltaSK { 45 | BIGNUM * deltaK; 46 | EC_GROUP * group; 47 | BIGNUM * ZeroBN; 48 | }; 49 | 50 | class ECJoin 51 | { 52 | public: 53 | //setups the elliptic curve and systems parameters 54 | ECJoin(); 55 | 56 | ECJoinSK * getSKey(const AES_KEY * baseKey, const std::string & columnKey); 57 | 58 | //returns secret key needed to adjust from encryption with key 1 to encryption with key 2 59 | ECDeltaSK * getDeltaKey(const ECJoinSK * key1, const ECJoinSK * key2); 60 | 61 | std::string encrypt(const ECJoinSK * sk, const std::string & ptext); 62 | static std::string adjust(const ECDeltaSK * deltaSK, const std::string & ctext); 63 | 64 | virtual 65 | ~ECJoin(); 66 | 67 | private: 68 | //setup parameters 69 | EC_GROUP * group; 70 | EC_POINT * P; 71 | 72 | 73 | //helper parameters 74 | BIGNUM * order; //order of the group 75 | EC_POINT * Infty; 76 | BIGNUM * ZeroBN; 77 | BN_CTX * bn_ctx; 78 | 79 | 80 | //using curve of 160 bits prime field \n"; 81 | static const int NID = NID_X9_62_prime192v1; 82 | static const unsigned int bytesLong = 24; 83 | static const unsigned int MAX_BUF = 256; 84 | 85 | /*** Helper Functions ***/ 86 | 87 | //returns a random point on the EC 88 | EC_POINT * randomPoint(); 89 | // a PRF with 128 bits security, but bytesLong output 90 | static std::string PRFForEC(const AES_KEY * sk, const std::string & ptext); 91 | static std::string point2Str(const EC_GROUP * group, const EC_POINT * point); 92 | }; 93 | -------------------------------------------------------------------------------- /crypto/Makefrag: -------------------------------------------------------------------------------- 1 | OBJDIRS += crypto 2 | CRYPTOSRC := BasicCrypto.cc paillier.cc urandom.cc arc4.cc hgd.cc pbkdf2.cc \ 3 | ecjoin.cc ECJoin.cc search.cc skip32.cc ffx.cc online_ope.cc mont.cc \ 4 | prng.cc ope.cc SWPSearch.cc 5 | CRYPTOOBJ := $(patsubst %.cc,$(OBJDIR)/crypto/%.o,$(CRYPTOSRC)) 6 | 7 | all: $(OBJDIR)/libedbcrypto.a $(OBJDIR)/libedbcrypto.so 8 | 9 | $(OBJDIR)/libedbcrypto.so: $(CRYPTOOBJ) $(OBJDIR)/libedbutil.so 10 | $(CXX) -fPIC -shared -o $@ $(CRYPTOOBJ) $(LDFLAGS) $(LDRPATH) \ 11 | -ledbutil -lcrypto -lntl 12 | 13 | $(OBJDIR)/libedbcrypto.a: $(CRYPTOOBJ) 14 | $(AR) r $@ $(CRYPTOOBJ) 15 | 16 | #all: $(OBJDIR)/crypto/x 17 | $(OBJDIR)/crypto/x: $(OBJDIR)/crypto/x.o $(OBJDIR)/libedbcrypto.so 18 | $(CXX) $< -o $@ $(LDFLAGS) $(LDRPATH) -ledbcrypto 19 | 20 | #install: install_crypto 21 | 22 | #.PHONY: install_crypto 23 | #install_crypto: $(OBJDIR)/libedbcrypto.so 24 | # install -m 644 $(OBJDIR)/libedbcrypto.so /usr/lib 25 | 26 | # vim: set noexpandtab: 27 | -------------------------------------------------------------------------------- /crypto/aes.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | class AES { 11 | public: 12 | AES(const std::string &key) { 13 | throw_c(key.size() == 16 || key.size() == 24 || key.size() == 32); 14 | AES_set_encrypt_key((const uint8_t*) key.data(), key.size() * 8, &enc); 15 | AES_set_decrypt_key((const uint8_t*) key.data(), key.size() * 8, &dec); 16 | } 17 | 18 | void block_encrypt(const void *ptext, void *ctext) const { 19 | AES_encrypt((const uint8_t*) ptext, (uint8_t*) ctext, &enc); 20 | } 21 | 22 | void block_decrypt(const void *ctext, void *ptext) const { 23 | AES_decrypt((const uint8_t*) ctext, (uint8_t*) ptext, &dec); 24 | } 25 | 26 | static const size_t blocksize = 16; 27 | 28 | private: 29 | AES_KEY enc; 30 | AES_KEY dec; 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /crypto/all: -------------------------------------------------------------------------------- 1 | BasicCrypto.cc 2 | paillier.cc 3 | urandom.cc 4 | arc4.cc 5 | hgd.cc 6 | pbkdf2.cc 7 | ecjoin.cc 8 | ECJoin.cc 9 | search.cc 10 | skip32.cc 11 | ffx.cc 12 | online_ope.cc 13 | mont.cc 14 | prng.cc 15 | ope.cc 16 | SWPSearch.cc 17 | -------------------------------------------------------------------------------- /crypto/arc4.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | arc4::arc4(const std::string &key) 6 | { 7 | reset(); 8 | for (size_t n = 0; n < key.size(); n += 128) 9 | addkey((const uint8_t *) &key[n], min((size_t) 128, key.size() - n)); 10 | j = i; 11 | 12 | /* discard first bytes */ 13 | for (int n = 0; n < 4096; n++) 14 | getbyte(); 15 | } 16 | 17 | void 18 | arc4::reset() 19 | { 20 | i = 0xff; 21 | j = 0; 22 | for (int n = 0; n < 0x100; n++) 23 | s[n] = n; 24 | } 25 | 26 | void 27 | arc4::addkey(const uint8_t *key, size_t keylen) 28 | { 29 | size_t n, keypos; 30 | uint8_t si; 31 | for (n = 0, keypos = 0; n < 256; n++, keypos++) { 32 | if (keypos >= keylen) 33 | keypos = 0; 34 | i = (i + 1) & 0xff; 35 | si = s[i]; 36 | j = (j + si + key[keypos]) & 0xff; 37 | s[i] = s[j]; 38 | s[j] = si; 39 | } 40 | } 41 | 42 | uint8_t 43 | arc4::getbyte() 44 | { 45 | uint8_t si, sj; 46 | i = (i + 1) & 0xff; 47 | si = s[i]; 48 | j = (j + si) & 0xff; 49 | sj = s[j]; 50 | s[i] = sj; 51 | s[j] = si; 52 | return s[(si + sj) & 0xff]; 53 | } 54 | -------------------------------------------------------------------------------- /crypto/arc4.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class arc4 { 6 | public: 7 | arc4(const std::string &key); 8 | uint8_t getbyte(); 9 | 10 | private: 11 | arc4(const arc4 &); 12 | 13 | void reset(); 14 | void addkey(const uint8_t *key, size_t keylen); 15 | 16 | uint8_t i; 17 | uint8_t j; 18 | uint8_t s[256]; 19 | }; 20 | -------------------------------------------------------------------------------- /crypto/blowfish.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class blowfish { 8 | public: 9 | blowfish(const std::string &key) { 10 | BF_set_key(&k, key.size(), (const uint8_t*) key.data()); 11 | } 12 | 13 | void block_encrypt(const void *ptext, void *ctext) const { 14 | BF_ecb_encrypt((const uint8_t*) ptext, (uint8_t*) ctext, &k, BF_ENCRYPT); 15 | } 16 | 17 | void block_decrypt(const void *ctext, void *ptext) const { 18 | BF_ecb_encrypt((const uint8_t*) ctext, (uint8_t*) ptext, &k, BF_DECRYPT); 19 | } 20 | 21 | uint64_t encrypt(uint64_t pt) const { 22 | uint64_t ct; 23 | block_encrypt(&pt, &ct); 24 | return ct; 25 | } 26 | 27 | uint64_t decrypt(uint64_t ct) const { 28 | uint64_t pt; 29 | block_decrypt(&ct, &pt); 30 | return pt; 31 | } 32 | 33 | static const size_t blocksize = 8; 34 | 35 | private: 36 | BF_KEY k; 37 | }; 38 | -------------------------------------------------------------------------------- /crypto/bn.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | class _bignum_ctx { 11 | public: 12 | _bignum_ctx() { c = BN_CTX_new(); } 13 | ~_bignum_ctx() { BN_CTX_free(c); } 14 | BN_CTX *ctx() { return c; } 15 | 16 | static BN_CTX *the_ctx() { 17 | static _bignum_ctx cx; 18 | return cx.ctx(); 19 | } 20 | 21 | private: 22 | BN_CTX *c; 23 | }; 24 | 25 | class bignum { 26 | public: 27 | bignum() { 28 | BN_init(&b); 29 | } 30 | 31 | bignum(unsigned long v) { 32 | BN_init(&b); 33 | BN_set_word(&b, v); 34 | } 35 | 36 | bignum(const bignum &other) { 37 | BN_init(&b); 38 | throw_c(BN_copy(&b, other.bn())); 39 | } 40 | 41 | bignum(const uint8_t *buf, size_t nbytes) { 42 | BN_init(&b); 43 | throw_c(BN_bin2bn(buf, nbytes, &b)); 44 | } 45 | 46 | bignum(const std::string &v) { 47 | BN_init(&b); 48 | throw_c(BN_bin2bn((uint8_t*) v.data(), v.size(), &b)); 49 | } 50 | 51 | ~bignum() { BN_free(&b); } 52 | 53 | BIGNUM *bn() { return &b; } 54 | const BIGNUM *bn() const { return &b; } 55 | unsigned long word() const { 56 | unsigned long v = BN_get_word(&b); 57 | if (v == 0xffffffffL) 58 | throw std::runtime_error("out of range"); 59 | return v; 60 | } 61 | 62 | #define op(opname, func, args...) \ 63 | bignum opname(const bignum &mod) { \ 64 | bignum res; \ 65 | throw_c(1 == func(res.bn(), &b, mod.bn(), ##args)); \ 66 | return res; \ 67 | } 68 | 69 | op(operator+, BN_add) 70 | op(operator-, BN_sub) 71 | op(operator%, BN_mod, _bignum_ctx::the_ctx()) 72 | op(operator*, BN_mul, _bignum_ctx::the_ctx()) 73 | #undef op 74 | 75 | #define pred(predname, cmp) \ 76 | bool predname(const bignum &other) { \ 77 | return BN_cmp(&b, other.bn()) cmp; \ 78 | } 79 | 80 | pred(operator<, < 0) 81 | pred(operator<=, <= 0) 82 | pred(operator>, > 0) 83 | pred(operator>=, >= 0) 84 | pred(operator==, == 0) 85 | #undef pred 86 | 87 | bignum invmod(const bignum &mod) { 88 | bignum r; 89 | throw_c(BN_mod_inverse(r.bn(), &b, mod.bn(), _bignum_ctx::the_ctx())); 90 | return r; 91 | } 92 | 93 | private: 94 | BIGNUM b; 95 | }; 96 | 97 | static inline std::ostream& 98 | operator<<(std::ostream &out, const bignum &bn) 99 | { 100 | char *s = BN_bn2dec(bn.bn()); 101 | out << s; 102 | OPENSSL_free(s); 103 | return out; 104 | } 105 | -------------------------------------------------------------------------------- /crypto/cbcmac.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | template 7 | class cbcmac { 8 | public: 9 | cbcmac(const BlockCipher *cx) { 10 | c = cx; 11 | memset(v, 0, BlockCipher::blocksize); 12 | mbytes = 0; 13 | } 14 | 15 | cbcmac(const BlockCipher *cx, void *iv) { 16 | c = cx; 17 | memcpy(v, iv, BlockCipher::blocksize); 18 | mbytes = 0; 19 | } 20 | 21 | void update(const void *data, size_t len) { 22 | const uint8_t *d = static_cast (data); 23 | 24 | if (mbytes) { 25 | size_t ncopy = std::min(len, BlockCipher::blocksize - mbytes); 26 | memcpy(&m[mbytes], d, ncopy); 27 | d += ncopy; 28 | len -= ncopy; 29 | mbytes += ncopy; 30 | } 31 | 32 | if (mbytes == BlockCipher::blocksize) { 33 | do_block(m); 34 | mbytes = 0; 35 | } 36 | 37 | while (len >= BlockCipher::blocksize) { 38 | do_block(d); 39 | d += BlockCipher::blocksize; 40 | len -= BlockCipher::blocksize; 41 | } 42 | 43 | if (len) { 44 | memcpy(m, d, len); 45 | mbytes = len; 46 | } 47 | } 48 | 49 | void update(const std::string &v) { 50 | update(v.data(), v.size()); 51 | } 52 | 53 | void final(uint8_t *buf) { 54 | if (mbytes) { 55 | memset(&m[mbytes], 0, BlockCipher::blocksize - mbytes); 56 | do_block(m); 57 | } 58 | 59 | memcpy(buf, v, BlockCipher::blocksize); 60 | } 61 | 62 | std::string final() { 63 | std::string f; 64 | f.resize(BlockCipher::blocksize); 65 | final((uint8_t*) f.data()); 66 | return f; 67 | } 68 | 69 | static const size_t blocksize = BlockCipher::blocksize; 70 | 71 | private: 72 | void do_block(const uint8_t *p) { 73 | uint8_t x[BlockCipher::blocksize]; 74 | for (size_t i = 0; i < BlockCipher::blocksize; i++) 75 | x[i] = v[i] ^ p[i]; 76 | c->block_encrypt(x, v); 77 | } 78 | 79 | uint8_t v[BlockCipher::blocksize]; 80 | uint8_t m[BlockCipher::blocksize]; 81 | uint8_t mbytes; 82 | 83 | const BlockCipher *c; 84 | }; 85 | -------------------------------------------------------------------------------- /crypto/dj.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Damgard-Jurik (a generalization of Paillier) provides a ciphertext 3 | * size that is asymptotically close to the plaintext size, rather 4 | * than a factor of 2 larger in standard Paillier. 5 | * 6 | * This may be especially useful in applications where ciphertext space 7 | * is the bottleneck, where in combination with packing, this should 8 | * provide almost no ciphertext storage overheads (except for spacing 9 | * for aggregate overflow). 10 | * 11 | * "A Generalisation, a Simplification and some Applications of 12 | * Paillier's Probabilistic Public-Key System", by Damgard and Jurik. 13 | * 14 | */ 15 | 16 | -------------------------------------------------------------------------------- /crypto/ec.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class ec_point { 8 | public: 9 | ec_point(const EC_GROUP *group) { 10 | gr = group; 11 | pt = EC_POINT_new(gr); 12 | } 13 | 14 | ec_point(const ec_point &other) { 15 | gr = other.gr; 16 | pt = EC_POINT_dup(other.pt, gr); 17 | } 18 | 19 | ~ec_point() { 20 | EC_POINT_free(pt); 21 | } 22 | 23 | ec_point operator*(const bignum &n) const { 24 | bignum zero(0); 25 | ec_point res(gr); 26 | throw_c(EC_POINT_mul(gr, res.p(), zero.bn(), 27 | pt, n.bn(), _bignum_ctx::the_ctx())); 28 | return res; 29 | } 30 | 31 | bool operator==(const ec_point &other) const { 32 | return EC_POINT_cmp(gr, pt, other.pt, _bignum_ctx::the_ctx()) == 0; 33 | } 34 | 35 | bool operator!=(const ec_point &other) const { 36 | return EC_POINT_cmp(gr, pt, other.pt, _bignum_ctx::the_ctx()) != 0; 37 | } 38 | 39 | std::string to_string(point_conversion_form_t form = 40 | POINT_CONVERSION_UNCOMPRESSED) const { 41 | char *s = EC_POINT_point2hex(gr, pt, form, _bignum_ctx::the_ctx()); 42 | std::string r(s); 43 | free(s); 44 | return r; 45 | } 46 | 47 | EC_POINT *p() { return pt; } 48 | 49 | private: 50 | EC_POINT *pt; 51 | const EC_GROUP *gr; 52 | }; 53 | 54 | static inline std::ostream& 55 | operator<<(std::ostream &out, const ec_point &p) 56 | { 57 | return out << p.to_string(); 58 | } 59 | -------------------------------------------------------------------------------- /crypto/ecjoin.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | ecjoin::ecjoin(int curve_id) 7 | { 8 | group = EC_GROUP_new_by_curve_name(curve_id); 9 | throw_c(group); 10 | 11 | throw_c(EC_GROUP_get_order(group, order.bn(), _bignum_ctx::the_ctx())); 12 | } 13 | 14 | ecjoin::~ecjoin() 15 | { 16 | EC_GROUP_free(group); 17 | } 18 | 19 | ec_point 20 | ecjoin::adjust(const ec_point &p, const bignum &delta_k) 21 | { 22 | return p * delta_k; 23 | } 24 | 25 | 26 | ecjoin_priv::ecjoin_priv(const std::string &base_key, int curve_id) 27 | : ecjoin(curve_id), base(sha256::hash(base_key)), basept(group) 28 | { 29 | streamrng r(base_key); 30 | 31 | for (;;) { 32 | bignum x = r.rand_bn_mod(order); 33 | if (!EC_POINT_set_compressed_coordinates_GFp(group, basept.p(), 34 | x.bn(), 1, 35 | _bignum_ctx::the_ctx())) 36 | continue; 37 | 38 | bignum y; 39 | throw_c(EC_POINT_get_affine_coordinates_GFp(group, basept.p(), 40 | x.bn(), y.bn(), 41 | _bignum_ctx::the_ctx())); 42 | if (x == 0 || y == 0) 43 | continue; 44 | 45 | if (EC_POINT_is_on_curve(group, basept.p(), _bignum_ctx::the_ctx())) 46 | break; 47 | } 48 | } 49 | 50 | ec_point 51 | ecjoin_priv::hash(const std::string &ptext, const std::string &k) 52 | { 53 | auto hash = sha1::hash(ptext); 54 | throw_c(hash.size() >= base.blocksize); 55 | hash.resize(base.blocksize); 56 | 57 | std::string enc; 58 | enc.resize(base.blocksize); 59 | base.block_encrypt(&hash[0], &enc[0]); 60 | 61 | bignum kn(sha256::hash(k)); 62 | bignum enc_bn(enc); 63 | 64 | return basept * (kn % order) * (enc_bn % order); 65 | } 66 | 67 | bignum 68 | ecjoin_priv::delta(const std::string &k0, const std::string &k1) 69 | { 70 | bignum kn0(sha256::hash(k0)); 71 | bignum kn1(sha256::hash(k1)); 72 | 73 | return ((kn1 % order) * kn0.invmod(order)) % order; 74 | } 75 | -------------------------------------------------------------------------------- /crypto/ecjoin.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static int ecjoin_default_curve = NID_X9_62_prime192v1; 10 | 11 | class ecjoin { 12 | public: 13 | ecjoin(int curve_id = ecjoin_default_curve); 14 | ~ecjoin(); 15 | 16 | static ec_point adjust(const ec_point &p, const bignum &delta_k); 17 | 18 | protected: 19 | EC_GROUP *group; 20 | bignum order; 21 | }; 22 | 23 | class ecjoin_priv : public ecjoin { 24 | public: 25 | ecjoin_priv(const std::string &base_key, 26 | int curve_id = ecjoin_default_curve); 27 | 28 | ec_point hash(const std::string &ptext, const std::string &k); 29 | bignum delta(const std::string &k0, const std::string &k1); 30 | 31 | private: 32 | AES base; 33 | ec_point basept; 34 | }; 35 | -------------------------------------------------------------------------------- /crypto/ffx.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ffx_mem_to_u64(const uint8_t *p, 4 | uint64_t *a, uint64_t *b, 5 | uint abits, uint bbits) 6 | { 7 | throw_c(abits <= 64 && bbits <= 64); 8 | 9 | *a = 0; 10 | *b = 0; 11 | 12 | while (abits >= 8) { 13 | *a = *a << 8 | *p; 14 | p++; 15 | abits -= 8; 16 | } 17 | 18 | if (abits) { 19 | *a = *a << abits | *p >> (8 - abits); 20 | uint8_t pleft = *p & ((1 << (8 - abits)) - 1); 21 | if (bbits < 8 - abits) { 22 | *b = pleft >> (8 - bbits); 23 | bbits = 0; 24 | } else { 25 | *b = pleft; 26 | bbits -= 8 - abits; 27 | } 28 | p++; 29 | } 30 | 31 | while (bbits >= 8) { 32 | *b = *b << 8 | *p; 33 | p++; 34 | bbits -= 8; 35 | } 36 | 37 | if (bbits) 38 | *b = *b << bbits | *p >> (8 - bbits); 39 | } 40 | 41 | void ffx_u64_to_mem(uint64_t a, uint64_t b, 42 | uint64_t abits, uint64_t bbits, 43 | uint8_t *p) 44 | { 45 | throw_c(abits <= 64 && bbits <= 64); 46 | 47 | while (abits >= 8) { 48 | *p = a >> (abits - 8); 49 | p++; 50 | abits -= 8; 51 | } 52 | 53 | if (abits) { 54 | *p = a & ((1 << abits) - 1); 55 | if (bbits < 8 - abits) { 56 | *p = (*p << bbits | (b & ((1 << bbits) - 1))) << (8 - abits - bbits); 57 | bbits = 0; 58 | } else { 59 | *p = *p << (8 - abits) | b >> (bbits - (8 - abits)); 60 | bbits -= (8 - abits); 61 | } 62 | p++; 63 | } 64 | 65 | while (bbits >= 8) { 66 | *p = b >> (bbits - 8); 67 | p++; 68 | bbits -= 8; 69 | } 70 | 71 | if (bbits) 72 | *p = b << (8 - bbits); 73 | } 74 | -------------------------------------------------------------------------------- /crypto/hgd.hh: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | * KK is the number of elements drawn from an urn where there are NN1 white 6 | * balls and NN2 black balls; the result is the number of white balls in 7 | * the KK sample. 8 | * 9 | * The implementation is based on an adaptation of the H2PEC alg for large 10 | * numbers; see hgd.cc for details 11 | */ 12 | NTL::ZZ HGD(const NTL::ZZ &KK, 13 | const NTL::ZZ &NN1, 14 | const NTL::ZZ &NN2, 15 | PRNG *prng); 16 | -------------------------------------------------------------------------------- /crypto/hmac.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | template 6 | class hmac { 7 | public: 8 | hmac(const void *keydata, size_t keylen) { 9 | static_assert(Hash::blocksize >= Hash::hashsize, 10 | "Hack::blocksize should be >= Hash::hashsize"); 11 | 12 | uint8_t k[Hash::blocksize]; 13 | memset(k, 0, sizeof(k)); 14 | if (keylen <= Hash::blocksize) { 15 | memcpy(k, keydata, keylen); 16 | } else { 17 | Hash kh; 18 | kh.update(keydata, keylen); 19 | kh.final(k); 20 | } 21 | 22 | for (size_t i = 0; i < Hash::blocksize; i++) { 23 | opad[i] = k[i] ^ 0x5c; 24 | ipad[i] = k[i] ^ 0x36; 25 | } 26 | 27 | h.update(ipad, sizeof(ipad)); 28 | } 29 | 30 | void update(const void *data, size_t len) { 31 | h.update(data, len); 32 | } 33 | 34 | void final(uint8_t *buf) { 35 | uint8_t inner[Hash::hashsize]; 36 | h.final(inner); 37 | 38 | Hash outer; 39 | outer.update(opad, sizeof(opad)); 40 | outer.update(inner, sizeof(inner)); 41 | outer.final(buf); 42 | } 43 | 44 | std::string final() { 45 | std::string v; 46 | v.resize(Hash::hashsize); 47 | final((uint8_t*) v.data()); 48 | return v; 49 | } 50 | 51 | static std::string mac(const std::string &v, const std::string &key) { 52 | hmac x(&key[0], key.size()); 53 | x.update(&v[0], v.size()); 54 | return x.final(); 55 | } 56 | 57 | private: 58 | uint8_t opad[Hash::blocksize]; 59 | uint8_t ipad[Hash::blocksize]; 60 | Hash h; 61 | }; 62 | -------------------------------------------------------------------------------- /crypto/mont.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | using namespace std; 7 | using namespace NTL; 8 | 9 | ZZ 10 | montgomery::to_mont(const ZZ &a) 11 | { 12 | return MulMod(a, _r, _m); 13 | } 14 | 15 | ZZ 16 | montgomery::from_mont(const ZZ &a) 17 | { 18 | return MulMod(a, _rinv, _m); 19 | } 20 | 21 | #define SIZE(p) (((long *) (p))[1]) 22 | #define DATA(p) ((mp_limb_t *) (((long *) (p)) + 2)) 23 | 24 | ZZ 25 | montgomery::mmul(const ZZ &a, const ZZ &b) 26 | { 27 | static_assert(sizeof(mp_limb_t) == sizeof(long), "mp_limb_t not long"); 28 | ZZ ab = a * b; 29 | if (ab == 0) return ab; // to avoid testing in loop 30 | 31 | for (uint i = 0; i < _mbits; i += sizeof(long) * 8) { 32 | uint thisbits = std::min((uint) sizeof(long) * 8, _mbits - i); 33 | mp_limb_t* abdata = DATA(ab.rep); 34 | long l = abdata[0]; 35 | long c = _minusm_inv_modr * l; 36 | if (thisbits < sizeof(long) * 8) 37 | c &= (((long)1) << thisbits) - 1; 38 | ab += _m * c; 39 | 40 | // throw_c(trunc_long(ab, thisbits) == 0); 41 | ab >>= thisbits; 42 | } 43 | 44 | while (ab >= _m) 45 | ab = ab - _m; 46 | return ab; 47 | } 48 | -------------------------------------------------------------------------------- /crypto/mont.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class montgomery { 6 | private: 7 | NTL::ZZ _m; 8 | uint _mbits; 9 | NTL::ZZ _r; 10 | NTL::ZZ _rinv; 11 | long _minusm_inv_modr; 12 | 13 | public: 14 | montgomery(const NTL::ZZ &m) 15 | : _m(m), _mbits(NumBits(m)), _r(NTL::to_ZZ(1) << _mbits), 16 | _rinv(InvMod(_r % _m, _m)), 17 | _minusm_inv_modr(trunc_long(InvMod(_r-_m, _r), sizeof(long) * 8)) {} 18 | 19 | NTL::ZZ to_mont(const NTL::ZZ &a); 20 | NTL::ZZ from_mont(const NTL::ZZ &a); 21 | NTL::ZZ mmul(const NTL::ZZ &a, const NTL::ZZ &b); 22 | }; 23 | -------------------------------------------------------------------------------- /crypto/ope.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | using namespace NTL; 11 | 12 | /* 13 | * A gap is represented by the next integer value _above_ the gap. 14 | */ 15 | static ZZ 16 | domain_gap(const ZZ &ndomain, const ZZ &nrange, const ZZ &rgap, PRNG *prng) 17 | { 18 | return HGD(rgap, ndomain, nrange-ndomain, prng); 19 | } 20 | 21 | template 22 | ope_domain_range 23 | OPE::lazy_sample(const ZZ &d_lo, const ZZ &d_hi, 24 | const ZZ &r_lo, const ZZ &r_hi, 25 | CB go_low, blockrng *prng) 26 | { 27 | ZZ ndomain = d_hi - d_lo + 1; 28 | ZZ nrange = r_hi - r_lo + 1; 29 | throw_c(nrange >= ndomain); 30 | 31 | if (ndomain == 1) 32 | return ope_domain_range(d_lo, r_lo, r_hi); 33 | 34 | /* 35 | * Deterministically reset the PRNG counter, regardless of 36 | * whether we had to use it for HGD or not in previous round. 37 | */ 38 | auto v = hmac::mac(StringFromZZ(d_lo) + "/" + 39 | StringFromZZ(d_hi) + "/" + 40 | StringFromZZ(r_lo) + "/" + 41 | StringFromZZ(r_hi), key); 42 | v.resize(AES::blocksize); 43 | prng->set_ctr(v); 44 | 45 | ZZ rgap = nrange/2; 46 | ZZ dgap; 47 | 48 | auto ci = dgap_cache.find(r_lo + rgap); 49 | if (ci == dgap_cache.end()) { 50 | dgap = domain_gap(ndomain, nrange, nrange / 2, prng); 51 | dgap_cache[r_lo + rgap] = dgap; 52 | } else { 53 | dgap = ci->second; 54 | } 55 | 56 | if (go_low(d_lo + dgap, r_lo + rgap)) 57 | return lazy_sample(d_lo, d_lo + dgap - 1, r_lo, r_lo + rgap - 1, go_low, prng); 58 | else 59 | return lazy_sample(d_lo + dgap, d_hi, r_lo + rgap, r_hi, go_low, prng); 60 | } 61 | 62 | template 63 | ope_domain_range 64 | OPE::search(CB go_low) 65 | { 66 | blockrng r(aesk); 67 | 68 | return lazy_sample(to_ZZ(0), to_ZZ(1) << pbits, 69 | to_ZZ(0), to_ZZ(1) << cbits, 70 | go_low, &r); 71 | } 72 | 73 | ZZ 74 | OPE::encrypt(const ZZ &ptext) 75 | { 76 | ope_domain_range dr = 77 | search([&ptext](const ZZ &d, const ZZ &) { return ptext < d; }); 78 | 79 | auto v = sha256::hash(StringFromZZ(ptext)); 80 | v.resize(16); 81 | 82 | blockrng aesrand(aesk); 83 | aesrand.set_ctr(v); 84 | 85 | ZZ nrange = dr.r_hi - dr.r_lo + 1; 86 | return dr.r_lo + aesrand.rand_zz_mod(nrange); 87 | } 88 | 89 | ZZ 90 | OPE::decrypt(const ZZ &ctext) 91 | { 92 | ope_domain_range dr = 93 | search([&ctext](const ZZ &, const ZZ &r) { return ctext < r; }); 94 | return dr.d; 95 | } 96 | -------------------------------------------------------------------------------- /crypto/ope.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class ope_domain_range { 11 | public: 12 | ope_domain_range(const NTL::ZZ &d_arg, 13 | const NTL::ZZ &r_lo_arg, 14 | const NTL::ZZ &r_hi_arg) 15 | : d(d_arg), r_lo(r_lo_arg), r_hi(r_hi_arg) {} 16 | NTL::ZZ d, r_lo, r_hi; 17 | }; 18 | 19 | class OPE { 20 | public: 21 | OPE(const std::string &keyarg, size_t plainbits, size_t cipherbits) 22 | : key(keyarg), pbits(plainbits), cbits(cipherbits), aesk(aeskey(key)) {} 23 | 24 | NTL::ZZ encrypt(const NTL::ZZ &ptext); 25 | NTL::ZZ decrypt(const NTL::ZZ &ctext); 26 | 27 | private: 28 | static std::string aeskey(const std::string &key) { 29 | auto v = sha256::hash(key); 30 | v.resize(16); 31 | return v; 32 | } 33 | 34 | std::string key; 35 | size_t pbits, cbits; 36 | 37 | AES aesk; 38 | std::map dgap_cache; 39 | 40 | template 41 | ope_domain_range search(CB go_low); 42 | 43 | template 44 | ope_domain_range lazy_sample(const NTL::ZZ &d_lo, const NTL::ZZ &d_hi, 45 | const NTL::ZZ &r_lo, const NTL::ZZ &r_hi, 46 | CB go_low, blockrng *prng); 47 | }; 48 | -------------------------------------------------------------------------------- /crypto/padding.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | static inline void 4 | pad_blocksize(std::string *ptext, size_t blocksize) 5 | { 6 | size_t plen = ptext->size(); 7 | uint8_t pad = blocksize - (plen % blocksize); 8 | ptext->resize(plen + pad); 9 | (*ptext)[plen + pad - 1] = pad; 10 | } 11 | 12 | static inline void 13 | unpad_blocksize(std::string *ptext, size_t blocksize) 14 | { 15 | size_t flen = ptext->size(); 16 | uint8_t pad = (*ptext)[flen - 1]; 17 | ptext->resize(flen - pad); 18 | } 19 | -------------------------------------------------------------------------------- /crypto/pbkdf2.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | std::string pbkdf2(const std::string &pass, const std::string &salt, 6 | uint key_len, uint rounds); 7 | 8 | -------------------------------------------------------------------------------- /crypto/prng.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace NTL; 4 | 5 | ZZ 6 | PRNG::rand_zz_nbits(size_t nbits) 7 | { 8 | if (nbits == 0) 9 | return to_ZZ(0); 10 | 11 | uint8_t buf[(nbits + 7) / 8]; 12 | rand_bytes(sizeof(buf), buf); 13 | 14 | ZZ r = ZZFromBytes(buf, sizeof(buf)); 15 | SetBit(r, nbits - 1); 16 | return r; 17 | } 18 | 19 | ZZ 20 | PRNG::rand_zz_prime(size_t nbits) 21 | { 22 | for (;;) { 23 | ZZ r = rand_zz_nbits(nbits); 24 | SetBit(r, 0); 25 | 26 | // XXX assume ProbPrime is perfect 27 | if (ProbPrime(r, 10)) 28 | return r; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /crypto/search.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | static string 10 | xor_pad(const string &word_key, size_t csize) 11 | { 12 | auto v = sha256::hash(word_key); 13 | throw_c(v.size() >= csize); 14 | v.resize(csize); 15 | return v; 16 | } 17 | 18 | bool 19 | search::match(const string &ctext, 20 | const string &word_key) 21 | { 22 | throw_c(ctext.size() == csize); 23 | string cx; 24 | 25 | auto xorpad = xor_pad(word_key, csize); 26 | for (size_t i = 0; i < csize; i++) 27 | cx.push_back(ctext[i] ^ xorpad[i]); 28 | 29 | string salt = cx; 30 | salt.resize(csize/2); 31 | 32 | string cf(cx.begin() + csize/2, cx.end()); 33 | auto f = hmac::mac(salt, word_key); 34 | f.resize((csize + 1) / 2); 35 | 36 | return (f == cf); 37 | } 38 | 39 | bool 40 | search::match(const vector &ctexts, const string &word_key) 41 | { 42 | for (auto &c: ctexts) 43 | if (match(c, word_key)) 44 | return true; 45 | return false; 46 | } 47 | 48 | string 49 | search_priv::transform(const string &word) 50 | { 51 | auto word_key = wordkey(word); 52 | 53 | urandom r; 54 | auto salt = r.rand_string(csize / 2); 55 | 56 | auto f = hmac::mac(salt, word_key); 57 | f.resize((csize + 1) / 2); 58 | 59 | string x; 60 | x.insert(x.end(), salt.begin(), salt.end()); 61 | x.insert(x.end(), f.begin(), f.end()); 62 | 63 | auto xorpad = xor_pad(word_key, csize); 64 | for (size_t i = 0; i < csize; i++) 65 | x[i] ^= xorpad[i]; 66 | 67 | return x; 68 | } 69 | 70 | vector 71 | search_priv::transform(const vector &words) 72 | { 73 | vector res; 74 | for (auto &w: words) 75 | res.push_back(transform(w)); 76 | sort(res.begin(), res.end()); 77 | return res; 78 | } 79 | 80 | string 81 | search_priv::wordkey(const string &word) 82 | { 83 | return hmac::mac(word, master_key); 84 | } 85 | -------------------------------------------------------------------------------- /crypto/search.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class search { 7 | public: 8 | static const size_t defsize = 16; 9 | search(size_t csize_arg = defsize) : csize(csize_arg) {} 10 | 11 | bool match(const std::vector &ctext, 12 | const std::string &wordkey); 13 | 14 | protected: 15 | bool match(const std::string &ctext, 16 | const std::string &wordkey); 17 | size_t csize; 18 | }; 19 | 20 | class search_priv : public search { 21 | public: 22 | search_priv(const std::string &key, size_t csize_arg = defsize) 23 | : search(csize_arg), master_key(key) {} 24 | 25 | std::vector 26 | transform(const std::vector &words); 27 | std::string 28 | wordkey(const std::string &word); 29 | 30 | private: 31 | std::string 32 | transform(const std::string &word); 33 | std::string master_key; 34 | }; 35 | -------------------------------------------------------------------------------- /crypto/sha.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | template 12 | class sha { 13 | public: 14 | sha() { Init(&s); } 15 | void update(const void *data, size_t len) { Update(&s, data, len); } 16 | 17 | void final(uint8_t *buf) { 18 | Final(buf, &s); 19 | } 20 | 21 | std::string final() { 22 | std::string v; 23 | v.resize(hashsize); 24 | final((uint8_t*) v.data()); 25 | return v; 26 | } 27 | 28 | static std::string hash(const std::string &s) { 29 | sha x; 30 | x.update(s.data(), s.length()); 31 | return x.final(); 32 | } 33 | 34 | static const size_t hashsize = OutBytes; 35 | static const size_t blocksize = BlockBytes; 36 | 37 | private: 38 | State s; 39 | }; 40 | 41 | typedef sha sha1; 42 | typedef sha sha224; 43 | typedef sha sha256; 44 | typedef sha sha384; 45 | typedef sha sha512; 46 | -------------------------------------------------------------------------------- /crypto/skip32.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | class skip32 { 10 | public: 11 | skip32(const std::vector &k) { 12 | throw_c(k.size() == 10); 13 | key = k; 14 | } 15 | 16 | void block_encrypt(const void *ptext, void *ctext) const { 17 | memcpy(ctext, ptext, 4); 18 | process((uint8_t*) ctext, 1); 19 | } 20 | 21 | void block_decrypt(const void *ctext, void *ptext) const { 22 | memcpy(ptext, ctext, 4); 23 | process((uint8_t*) ptext, 0); 24 | } 25 | 26 | static const size_t blocksize = 4; 27 | 28 | private: 29 | void process(uint8_t *data, int encrypt) const; 30 | 31 | std::vector key; 32 | }; 33 | -------------------------------------------------------------------------------- /crypto/urandom.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | urandom::urandom() 9 | : f("/dev/urandom") 10 | { 11 | throw_c(false == f.fail(), 12 | "cannot open /dev/urandom: " + std::string(strerror(errno))); 13 | } 14 | 15 | void 16 | urandom::rand_bytes(size_t nbytes, uint8_t *buf) 17 | { 18 | f.read((char *) buf, nbytes); 19 | } 20 | 21 | void 22 | urandom::seed_bytes(size_t nbytes, uint8_t *buf) 23 | { 24 | f.write((char *) buf, nbytes); 25 | } 26 | -------------------------------------------------------------------------------- /debug/Makefrag: -------------------------------------------------------------------------------- 1 | OBJDIRS += debug 2 | 3 | ##note that xx=*.cc will not expand. wildcard *.cc will include files from other directories. 4 | ##%.o will include testall 5 | TESTALL_OBJS := $(patsubst %.cc,$(OBJDIR)/%.o,$(wildcard debug/*.cc)) 6 | TESTALL_EXES := $(patsubst debug/%.cc,mtl/%,$(wildcard debug/*.cc)) 7 | 8 | all: $(TESTALL_OBJS) $(TESTALL_EXES) 9 | -------------------------------------------------------------------------------- /debug/hello.cc: -------------------------------------------------------------------------------- 1 | int main(){ 2 | 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /debug/local_client.cc: -------------------------------------------------------------------------------- 1 | #include "main/big_proxy.hh" 2 | #include 3 | using std::string; 4 | using std::vector; 5 | int 6 | main(int argc,char ** argv) { 7 | big_proxy b; 8 | std::string query; 9 | std::getline(std::cin,query); 10 | while(query!="quit"){ 11 | b.go(query); 12 | std::getline(std::cin,query); 13 | } 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /debug/test_proxy.cc: -------------------------------------------------------------------------------- 1 | #include "main/big_proxy.hh" 2 | #include 3 | using std::string; 4 | using std::vector; 5 | int 6 | main(int argc,char ** argv) { 7 | big_proxy b; 8 | vectorqueries={ 9 | "show databases;", 10 | "create database tdb;", 11 | "use tdb;", 12 | "create table student(id integer,name varchar(20));", 13 | "insert into student values(1,'zhang');", 14 | "select * from student;" 15 | }; 16 | std::string query; 17 | for(auto query:queries) 18 | b.go(query); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /insert.sh: -------------------------------------------------------------------------------- 1 | files=`find ~/Insert/ -type f` 2 | arrayfiles=($files) 3 | #IFS=' ' read -r -a arrayfiles <<< "$files" 4 | 5 | 6 | for data in ${arrayfiles[@]} 7 | do 8 | ss="cdb_test tpcc1000 < $data" 9 | eval $ss 10 | echo $ss 11 | done 12 | 13 | -------------------------------------------------------------------------------- /main/Connect.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * Connect.h 5 | * 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | typedef MYSQL_RES DBResult_native; 17 | 18 | extern "C" void *create_embedded_thd(int client_flag); 19 | 20 | class DBResult { 21 | public: 22 | DBResult(DBResult_native *const n, bool success, 23 | uint64_t affected_rows, uint64_t insert_id) 24 | : n(n), success(success), affected_rows(affected_rows), 25 | insert_id(insert_id) {} 26 | 27 | ~DBResult(); 28 | DBResult_native *const n; 29 | 30 | //returns data from this db result 31 | ResType unpack(); 32 | 33 | static DBResult *store(MYSQL *const mysql); 34 | 35 | bool getSuccess() const {return success;} 36 | 37 | private: 38 | const bool success; 39 | const uint64_t affected_rows; 40 | const uint64_t insert_id; 41 | }; 42 | 43 | class Connect { 44 | public: 45 | Connect(const std::string &server, const std::string &user, 46 | const std::string &passwd, uint port = 0); 47 | 48 | Connect(MYSQL *const _conn) : conn(_conn), close_on_destroy(true) { } 49 | 50 | //returns Connect for the embedded server 51 | static Connect *getEmbedded(const std::string &embed_dir); 52 | 53 | // returns true if execution was ok; caller must delete DBResult 54 | bool execute(const std::string &query, std::unique_ptr *res, 55 | bool multiple_resultsets=false); 56 | bool execute(const std::string &query, bool multiple_resultsets=false); 57 | 58 | // returns error message if a query caused error 59 | std::string getError(); 60 | 61 | my_ulonglong last_insert_id(); 62 | 63 | unsigned long long get_thread_id(); 64 | unsigned long real_escape_string(char *const to, 65 | const char *const from, 66 | unsigned long length); 67 | unsigned int get_mysql_errno(); 68 | 69 | uint64_t get_affected_rows(); 70 | 71 | ~Connect(); 72 | 73 | private: 74 | MYSQL *conn; 75 | 76 | void do_connect(const std::string &server, const std::string &user, 77 | const std::string &passwd, uint port); 78 | 79 | bool close_on_destroy; 80 | }; 81 | 82 | bool strictMode(Connect *const c); 83 | 84 | -------------------------------------------------------------------------------- /main/Makefrag: -------------------------------------------------------------------------------- 1 | OBJDIRS += main 2 | 3 | CRYPTDB_SRCS := schema.cc Translator.cc Connect.cc \ 4 | Analysis.cc CryptoHandlers.cc rewrite_util.cc \ 5 | rewrite_field.cc dispatcher.cc sql_handler.cc dml_handler.cc \ 6 | ddl_handler.cc alter_sub_handler.cc rewrite_const.cc \ 7 | rewrite_func.cc rewrite_sum.cc metadata_tables.cc \ 8 | error.cc stored_procedures.cc rewrite_ds.cc rewrite_main.cc big_proxy.cc 9 | 10 | CRYPTDB_PROGS:= cdb_test load_and_store test_layer test_schema test_proxy change_test 11 | 12 | 13 | CRYPTDBPROGOBJS := $(patsubst %,$(OBJDIR)/main/%,$(CRYPTDB_PROGS)) 14 | 15 | all: $(CRYPTDBPROGOBJS) $(OBJDIR)/libcryptdb.so 16 | 17 | CRYPTDB_OBJS := $(patsubst %.cc,$(OBJDIR)/main/%.o,$(CRYPTDB_SRCS)) 18 | 19 | $(CRYPTDBPROGOBJS): %: %.o $(OBJDIR)/libedbparser.so \ 20 | $(OBJDIR)/libedbutil.so \ 21 | $(OBJDIR)/libcryptdb.so \ 22 | $(OBJDIR)/libedbcrypto.so 23 | $(CXX) $< -o $@ -ledbparser $(LDFLAGS) $(LDRPATH) \ 24 | -ledbutil -ledbcrypto -lcryptdb 25 | 26 | $(OBJDIR)/libcryptdb.so: $(CRYPTDB_OBJS) \ 27 | $(OBJDIR)/libedbcrypto.so \ 28 | $(OBJDIR)/libedbutil.so \ 29 | $(OBJDIR)/libedbparser.so 30 | $(CXX) -shared -g -o $@ $(CRYPTDB_OBJS) $(LDFLAGS) $(LDRPATH) \ 31 | -ledbcrypto -ledbutil -ledbparser -lntl -lcrypto 32 | 33 | 34 | 35 | #install: install_main 36 | 37 | #.PHONY: install_main 38 | #install_main: $(OBJDIR)/libcryptdb.so 39 | # install -m 644 $(OBJDIR)/libcryptdb.so /usr/lib 40 | 41 | # vim: set noexpandtab: 42 | -------------------------------------------------------------------------------- /main/Translator.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Translator.cpp 3 | * 4 | * Created on: Aug 13, 2010 5 | * Author: raluca 6 | */ 7 | 8 | #include
9 | #include 10 | 11 | #include 12 | #include 13 | 14 | // TODO: Make length longer. 15 | // TODO: Ensure some level of collision resistance. 16 | std::string 17 | getpRandomName(){ 18 | // FIXME: Not using numbers because. 19 | // 'CREATE TABLE a (2e integer); <---- succeeds 20 | // 'CREATE TABLE b (2e5 integer); <--- fails 21 | static const char valids[] = 22 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 23 | static int out_length = 10; 24 | char output[out_length + 1]; 25 | std::function wrap_srand =[](){srand(time(NULL)); return true;}; 26 | std::function do_nothing = [] (bool b) {return;}; 27 | static bool danger_will_robinson = wrap_srand(); 28 | do_nothing(danger_will_robinson); 29 | 30 | for (int i = 0; i < out_length; ++i) { 31 | output[i] = valids[rand() % strlen(valids)]; 32 | } 33 | output[out_length] = 0; 34 | return std::string(output); 35 | } 36 | 37 | std::string 38 | nextAutoInc(std::map & autoInc, 39 | std::string fullname){ 40 | std::string val; 41 | if (autoInc.find(fullname) == autoInc.end()) { 42 | val = "1"; 43 | autoInc[fullname] = 1; 44 | } else { 45 | autoInc[fullname] += 1; 46 | val = strFromVal(autoInc[fullname]); 47 | } 48 | 49 | return val; 50 | } 51 | 52 | std::string 53 | getTableSalt(std::string anonTableName) { 54 | return BASE_SALT_NAME + "_t_" + anonTableName; 55 | } 56 | 57 | std::string 58 | getTableOfSalt(std::string salt_name) { 59 | return salt_name.substr(BASE_SALT_NAME.length() + 3, salt_name.length() - 3 - BASE_SALT_NAME.length()); 60 | } 61 | 62 | 63 | 64 | std::string 65 | getFieldsItSelect(std::list & words, 66 | std::list::iterator & it) { 67 | it = words.begin(); 68 | it++; 69 | std::string res = "SELECT "; 70 | 71 | if (equalsIgnoreCase(*it, "distinct")) { 72 | LOG(edb_v) << "has distinct!"; 73 | it++; 74 | res += "DISTINCT "; 75 | } 76 | return res; 77 | } 78 | 79 | -------------------------------------------------------------------------------- /main/Translator.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * Translator.h 5 | * 6 | * Created on: Aug 13, 2010 7 | * Author: raluca 8 | * 9 | * Logic of translation between unencrypted and encrypted fields and 10 | * manipulations of fields and tables. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include
21 | #include 22 | 23 | bool isCommand(std::string str); 24 | 25 | //it is made to point to the first field after select and distinct if they 26 | // exist 27 | std::string getFieldsItSelect(std::list & words, std::list::iterator & it); 28 | 29 | bool isNested(const std::string &query); 30 | 31 | //returns true if token is of the form 'string.string" 32 | 33 | bool isField(std::string token); 34 | 35 | //returns true if "id" is the name of salt; isTableSalt set to true if it is 36 | std::string 37 | getTableSalt(std::string anonTableName); 38 | //returns the anonymized name of the table with this salt 39 | std::string getTableOfSalt(std::string salt_name); 40 | 41 | //returns the name of the given field as it should appear in the query result 42 | // table, field are unanonymized names 43 | //should allow * 44 | //does not consider field aliases 45 | std::string fieldNameForResponse(std::string table, std::string field, 46 | std::string origName, QueryMeta & qm, 47 | bool isAgg = false); 48 | 49 | // fetches the next auto increment value for fullname and updates autoInc 50 | std::string nextAutoInc(std::map & autoInc, 51 | std::string fullname); 52 | 53 | std::string getpRandomName(); 54 | -------------------------------------------------------------------------------- /main/alter_sub_handler.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include
6 | #include
7 | 8 | #include 9 | 10 | class AlterSubHandler { 11 | public: 12 | virtual LEX * 13 | transformLex(Analysis &a, LEX *lex) const; 14 | virtual ~AlterSubHandler() {;} 15 | 16 | private: 17 | virtual LEX *rewriteAndUpdate(Analysis &a, LEX *lex, 18 | const Preamble &preamble) const = 0; 19 | 20 | protected: 21 | AlterSubHandler() {;} 22 | }; 23 | 24 | 25 | class AddIndexSubHandler : public AlterSubHandler { 26 | virtual LEX * 27 | rewriteAndUpdate(Analysis &a, LEX *lex, const Preamble &preamble)const; 28 | 29 | }; 30 | 31 | class ForeignKeySubHandler : public AlterSubHandler{ 32 | virtual LEX * 33 | rewriteAndUpdate(Analysis &a, LEX *lex, const Preamble &preamble)const; 34 | }; 35 | 36 | 37 | 38 | class AlterDispatcher; 39 | 40 | AlterDispatcher *buildAlterSubDispatcher(); 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /main/big_proxy.hh: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | 48 | //My WrapperState. 49 | class WrapperState { 50 | WrapperState(const WrapperState &other); 51 | WrapperState &operator=(const WrapperState &rhs); 52 | KillZone kill_zone; 53 | public: 54 | std::string last_query; 55 | std::string default_db; 56 | 57 | WrapperState() {} 58 | ~WrapperState() {} 59 | const std::unique_ptr &getQueryRewrite() const { 60 | assert(this->qr); 61 | return this->qr; 62 | } 63 | void setQueryRewrite(std::unique_ptr &&in_qr) { 64 | this->qr = std::move(in_qr); 65 | } 66 | void selfKill(KillZone::Where where) { 67 | kill_zone.die(where); 68 | } 69 | void setKillZone(const KillZone &kz) { 70 | kill_zone = kz; 71 | } 72 | 73 | std::unique_ptr ps; 74 | std::vector schema_info_refs; 75 | 76 | private: 77 | std::unique_ptr qr; 78 | }; 79 | 80 | 81 | 82 | struct big_proxy{ 83 | Connect *globalConn; 84 | std::map clients; 85 | std::string curQuery; 86 | std::string targetDb; 87 | unsigned long long _thread_id; 88 | std::string client; 89 | std::string embeddedDir="/t/cryt/shadow"; 90 | 91 | big_proxy(std::string db = "tdb"); 92 | void myNext(std::string client,bool isFirst,ResType inRes); 93 | void batchTogether(std::string client, std::string curQuery,unsigned long long _thread_id); 94 | bool myRewrite(std::string curQuery,unsigned long long _thread_id,std::string client); 95 | void go(std::string query); 96 | }; 97 | -------------------------------------------------------------------------------- /main/change_test.cc: -------------------------------------------------------------------------------- 1 | #include "big_proxy.hh" 2 | #include 3 | using std::string; 4 | using std::vector; 5 | 6 | vector queries{ 7 | "show databases;", 8 | "create database if not exists tdb2;", 9 | "use tdb2;", 10 | "create table if not exists student(id integer, name varchar(50));", 11 | "insert into student values(1,'shao'),(2,'xiaocai'),(3,'nans'),(4,'hehe'),(5,'oo');", 12 | "select * from student;", 13 | "select id from student;", 14 | "select name from student;", 15 | "select sum(id) from student;" 16 | }; 17 | 18 | int 19 | main(int argc,char ** argv) { 20 | big_proxy b; 21 | for(auto query:queries){ 22 | b.go(query); 23 | std::cout< 4 | 5 | #include
6 | #include
7 | #include
8 | 9 | #include 10 | 11 | class DDLQueryExecutor : public AbstractQueryExecutor { 12 | 13 | 14 | 15 | AssignOnce ddl_res; 16 | AssignOnce embedded_completion_id; 17 | 18 | public: 19 | const std::string new_query; 20 | DDLQueryExecutor(const LEX &new_lex, 21 | std::vector > &&deltas) 22 | : new_query(lexToQuery(new_lex)), deltas(std::move(deltas)) {} 23 | ~DDLQueryExecutor() {} 24 | std::pair 25 | nextImpl(const ResType &res, const NextParams &nparams); 26 | 27 | private: 28 | const std::vector > deltas; 29 | bool stales() const {return true;} 30 | bool usesEmbedded() const {return true;} 31 | }; 32 | 33 | // Abstract base class for command handler. 34 | class DDLHandler : public SQLHandler { 35 | public: 36 | virtual AbstractQueryExecutor *transformLex(Analysis &analysis, LEX *lex) 37 | const; 38 | 39 | private: 40 | virtual AbstractQueryExecutor * 41 | rewriteAndUpdate(Analysis &a, LEX *lex, const Preamble &pre) const = 0; 42 | protected: 43 | DDLHandler() {;} 44 | virtual ~DDLHandler() {;} 45 | }; 46 | 47 | 48 | class CreateTableHandler : public DDLHandler { 49 | //must rewrite the header here or we get pure virtual function 50 | virtual AbstractQueryExecutor * 51 | rewriteAndUpdate(Analysis &a, LEX *lex, const Preamble &pre) const; 52 | }; 53 | 54 | 55 | 56 | 57 | SQLDispatcher *buildDDLDispatcher(); 58 | 59 | -------------------------------------------------------------------------------- /main/dispatcher.cc: -------------------------------------------------------------------------------- 1 | #include
2 | 3 | /* 4 | This file contains functions for SQLDispatcher and 5 | AlterDispatcher 6 | */ 7 | //########################SQLDispatcher######################### 8 | bool 9 | SQLDispatcher::canDo(LEX *const lex) const 10 | { 11 | return handlers.end() != handlers.find(extract(lex)); 12 | } 13 | 14 | const SQLHandler & 15 | SQLDispatcher::dispatch(LEX *const lex) const 16 | { 17 | auto it = handlers.find(extract(lex)); 18 | assert(handlers.end() != it); 19 | 20 | assert(it->second); 21 | return *it->second; 22 | } 23 | 24 | long long 25 | SQLDispatcher::extract(LEX *const lex) const 26 | { 27 | return lex->sql_command; 28 | } 29 | 30 | 31 | 32 | //#####################AlterDispatcher########################## 33 | bool 34 | AlterDispatcher::canDo(LEX *const lex) const 35 | { 36 | // there must be a command for us to do 37 | if (0 == lex->alter_info.flags) { 38 | return false; 39 | } 40 | 41 | long long flags = lex->alter_info.flags; 42 | for (const auto &it : handlers) { 43 | flags -= lex->alter_info.flags & it.first; 44 | } 45 | 46 | return 0 == flags; 47 | } 48 | 49 | std::vector 50 | AlterDispatcher::dispatch(LEX *const lex) const 51 | { 52 | std::vector out; 53 | for (const auto &it : handlers) { 54 | const long long extract = lex->alter_info.flags & it.first; 55 | if (extract) { 56 | auto it_handler = handlers.find(extract); 57 | assert(handlers.end() != it_handler && it_handler->second); 58 | out.push_back(it_handler->second.get()); 59 | } 60 | } 61 | 62 | return out; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /main/dispatcher.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include
6 | #include
7 | #include
8 | 9 | #include 10 | 11 | template 12 | class Dispatcher { 13 | public: 14 | virtual ~Dispatcher() {} 15 | 16 | bool addHandler(long long cmd, FetchMe *const h) { 17 | if (NULL == h) { 18 | return false; 19 | } 20 | 21 | auto it = handlers.find(cmd); 22 | if (handlers.end() != it) { 23 | return false; 24 | } 25 | 26 | handlers[cmd] = std::unique_ptr(h); 27 | return true; 28 | } 29 | 30 | virtual bool canDo(LEX *const lex) const = 0; 31 | 32 | protected: 33 | std::map> handlers; 34 | }; 35 | 36 | class SQLDispatcher : public Dispatcher { 37 | public: 38 | bool canDo(LEX *const lex) const; 39 | const SQLHandler &dispatch(LEX *const lex) const; 40 | 41 | private: 42 | virtual long long extract(LEX *const lex) const; 43 | }; 44 | 45 | class AlterDispatcher : public Dispatcher { 46 | public: 47 | std::vector dispatch(LEX *const lex) const; 48 | bool canDo(LEX *const lex) const; 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /main/error.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include
4 | #include
5 | #include 6 | #include 7 | 8 | std::ostream &operator<<(std::ostream &out, 9 | const AbstractException &abstract_error) 10 | { 11 | out << abstract_error.to_string(); 12 | return out; 13 | } 14 | 15 | std::string AbstractException::to_string() const 16 | { 17 | return "FILE: " + file_name + "\n" 18 | "LINE: " + std::to_string(line_number) + "\n"; 19 | } 20 | 21 | // FIXME: Format the output. 22 | std::string BadItemArgumentCount::to_string() const 23 | { 24 | return "Item has bad argument count\n" + 25 | AbstractException::to_string() + 26 | // FIXME: Use TypeText. 27 | "ITEM TYPE: " + std::to_string(type) + "\n" + 28 | "EXPECTED COUNT: " + std::to_string(expected) + "\n" + 29 | "ACTUAL COUNT: " + std::to_string(actual) + "\n"; 30 | } 31 | 32 | // FIXME: Format the output. 33 | std::string UnexpectedSecurityLevel::to_string() const 34 | { 35 | return "Unexpected security level for onion\n" + 36 | AbstractException::to_string() + 37 | "ONION TYPE: " + TypeText::toText(o) + "\n" + 38 | "EXPECTED LEVEL: " + TypeText::toText(expected)+"\n" + 39 | "ACTUAL LEVEL: " + TypeText::toText(actual) + "\n"; 40 | } 41 | 42 | // FIXME: Format the output. 43 | // FIXME: Children EncSet would be nice. 44 | std::string NoAvailableEncSet::to_string() const 45 | { 46 | std::stringstream s; 47 | s << 48 | "Current crypto schemes do not support this query" << std::endl 49 | << AbstractException::to_string() 50 | // << "ITEM TYPE " + TypeText<>::toText(); 51 | << "ITEM TYPE: " << std::to_string(type) << std::endl 52 | << "OPERATION: " << why << std::endl 53 | << "REQUIRED ENCSET: " << req_enc_set << std::endl 54 | << "***** CHILDREN REASONS *****" << std::endl; 55 | for (auto it = childr_rp.begin(); it != childr_rp.end(); it++) { 56 | s << "[" << std::to_string(std::distance(childr_rp.begin(), it)) 57 | << "] " 58 | << (*it)->getReason() << std::endl; 59 | } 60 | 61 | return s.str(); 62 | } 63 | 64 | std::string TextMessageError::to_string() const 65 | { 66 | return "Error: " + message + "\n" 67 | + AbstractException::to_string(); 68 | } 69 | 70 | std::string 71 | IdentifierNotFound::to_string() const 72 | { 73 | return "Identifier not found: '" + this->identifier_name + "'\n" 74 | + AbstractException::to_string(); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /main/metadata_tables.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include
7 | 8 | //这个在embedded的表中也是定义好的query最大的长度, 在程序中检查不能超过这个长度. 9 | #define STORED_QUERY_LENGTH 10000 10 | 11 | namespace MetaData { 12 | bool initialize(const std::unique_ptr &conn, 13 | const std::unique_ptr &e_conn, 14 | const std::string &prefix); 15 | 16 | namespace Table { 17 | std::string metaObject(); 18 | std::string bleedingMetaObject(); 19 | std::string embeddedQueryCompletion(); 20 | std::string staleness(); 21 | std::string showDirective(); 22 | std::string remoteQueryCompletion(); 23 | }; 24 | 25 | namespace Proc { 26 | std::string activeTransactionP(); 27 | }; 28 | 29 | namespace DB { 30 | std::string embeddedDB(); 31 | std::string remoteDB(); 32 | }; 33 | 34 | namespace Internal { 35 | void initPrefix(const std::string &prefix); 36 | const std::string &getPrefix(); 37 | const std::string &lowLevelPrefix(const char *const p); 38 | }; 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /main/rewrite_ds.cc: -------------------------------------------------------------------------------- 1 | #include
2 | #include
3 | 4 | RewritePlanWithAnalysis::~RewritePlanWithAnalysis() 5 | {} 6 | -------------------------------------------------------------------------------- /main/serializers.hh: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | //简单的字符串序列化方法, 长度_str 6 | inline std::string 7 | serialize_string(std::string str) 8 | { 9 | return std::string(std::to_string(str.length()) + "_" + str); 10 | } 11 | 12 | // TESTME. 13 | // Must perserve order. 14 | inline std::vector 15 | unserialize_string(std::string serial) 16 | { 17 | std::vector output; 18 | std::size_t start = 0; 19 | std::size_t under_pos = serial.find_first_of("_"); 20 | while (under_pos != std::string::npos) { 21 | const std::size_t length = 22 | atoi(serial.substr(start, under_pos-start).c_str()); 23 | output.push_back(serial.substr(under_pos+1, length)); 24 | start = under_pos + 1 + length; 25 | under_pos = serial.find_first_of("_", start); 26 | } 27 | 28 | // TODO: Sanity check no leftover characters. 29 | 30 | return output; 31 | } 32 | 33 | inline std::string 34 | unserialize_one_string(std::string serial) 35 | { 36 | auto vec = unserialize_string(serial); 37 | return vec[0]; 38 | } 39 | 40 | inline unsigned int 41 | serial_to_uint(std::string serial) 42 | { 43 | return atoi(unserialize_one_string(serial).c_str()); 44 | } 45 | -------------------------------------------------------------------------------- /main/sql_handler.cc: -------------------------------------------------------------------------------- 1 | #include
2 | #include 3 | 4 | AbstractAnything::~AbstractAnything() {} 5 | 6 | AbstractQueryExecutor::~AbstractQueryExecutor() {} 7 | 8 | std::pair 9 | AbstractQueryExecutor:: 10 | next(const ResType &res, const NextParams &nparams) 11 | { 12 | genericPreamble(nparams); 13 | return this->nextImpl(res, nparams); 14 | } 15 | 16 | void AbstractQueryExecutor:: 17 | genericPreamble(const NextParams &nparams) 18 | { 19 | // We handle before any queries because a failed query 20 | // may stale the database during recovery and then 21 | // we'd have to handle there as well. 22 | 23 | //首先根据stales来设置这个executor会不会让当前在shared中的cache变成stale,对于simple来说, 继承的是默认的情况, 所以 24 | //不会设置cache为stale, 也就是下次进入rewrite的时候, 不需要重新load. 25 | try { 26 | nparams.ps.getSchemaCache().updateStaleness( 27 | nparams.ps.getEConn(), this->stales()); 28 | } catch (const SchemaFailure &e) { 29 | FAIL_GenericPacketException("failed updating staleness"); 30 | } 31 | 32 | if (this->usesEmbedded()) { 33 | TEST_ErrPkt( 34 | lowLevelSetCurrentDatabase(nparams.ps.getEConn(), nparams.default_db), 35 | "failed to set the embedded database to " + nparams.default_db + ";" 36 | " your client may be in an unrecoverable bad loop" 37 | " so consider restarting just the _client_. this can happen" 38 | " if you tell your client to connect to a database that exists" 39 | " but was not created through cryptdb."); 40 | } 41 | 42 | return; 43 | } 44 | 45 | std::pair SimpleExecutor:: 46 | nextImpl(const ResType &res, const NextParams &nparams) 47 | { 48 | reenter(this->corot) { 49 | yield return CR_QUERY_RESULTS(nparams.original_query); 50 | } 51 | 52 | assert(false); 53 | } 54 | 55 | std::pair NoOpExecutor:: 56 | nextImpl(const ResType &res, const NextParams &nparams) 57 | { 58 | reenter(this->corot) { 59 | yield return CR_QUERY_RESULTS("DO 0;"); 60 | } 61 | 62 | assert(false); 63 | } 64 | 65 | 66 | -------------------------------------------------------------------------------- /main/stored_procedures.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include
4 | #include
5 | #include
6 | 7 | std::vector 8 | getStoredProcedures() 9 | { 10 | const std::vector &add_procs{ 11 | " CREATE PROCEDURE " + MetaData::Proc::activeTransactionP() + "()\n" 12 | " BEGIN\n" 13 | " DECLARE eat_result BIGINT;\n" 14 | " DECLARE trx_count BIGINT;\n\n" 15 | 16 | // force transaction propagation 17 | " SELECT 1 FROM remote_db.generic_prefix_remoteQueryCompletion\n" 18 | " LIMIT 1\n" 19 | " INTO eat_result;\n\n" 20 | 21 | " SELECT COUNT(trx_id) INTO trx_count\n" 22 | " FROM INFORMATION_SCHEMA.INNODB_TRX\n" 23 | " WHERE INFORMATION_SCHEMA.INNODB_TRX.TRX_MYSQL_THREAD_ID =\n" 24 | " (SELECT CONNECTION_ID())\n" 25 | " AND INFORMATION_SCHEMA.INNODB_TRX.TRX_STATE =\n" 26 | " 'RUNNING';\n\n" 27 | 28 | " SELECT NOT 0 = trx_count AS ACTIVE_TRX;\n" 29 | " END\n"}; 30 | 31 | return add_procs; 32 | } 33 | 34 | static bool 35 | addStoredProcedures(const std::unique_ptr &conn) 36 | { 37 | auto procs = getStoredProcedures(); 38 | for (auto it : procs) { 39 | RETURN_FALSE_IF_FALSE(conn->execute(it)); 40 | } 41 | 42 | return true; 43 | } 44 | 45 | static bool 46 | dropStoredProcedures(const std::unique_ptr &conn) 47 | { 48 | const std::vector 49 | drop_procs{MetaData::Proc::activeTransactionP()}; 50 | 51 | for (auto it : drop_procs) { 52 | RETURN_FALSE_IF_FALSE(conn->execute("DROP PROCEDURE IF EXISTS " + it)); 53 | } 54 | 55 | return true; 56 | } 57 | 58 | bool 59 | loadStoredProcedures(const std::unique_ptr &conn) 60 | { 61 | RETURN_FALSE_IF_FALSE(dropStoredProcedures(conn)); 62 | RETURN_FALSE_IF_FALSE(addStoredProcedures(conn)); 63 | 64 | return true; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /main/stored_procedures.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include
6 | 7 | bool 8 | loadStoredProcedures(const std::unique_ptr &conn); 9 | 10 | std::vector 11 | getStoredProcedures(); 12 | 13 | -------------------------------------------------------------------------------- /main/test_proxy.cc: -------------------------------------------------------------------------------- 1 | #include "big_proxy.hh" 2 | using std::string; 3 | int 4 | main(int argc,char ** argv) { 5 | big_proxy b; 6 | std::string query; 7 | std::getline(std::cin,query); 8 | while(query != "quit"){ 9 | b.go(query); 10 | std::getline(std::cin,query); 11 | } 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /mergedep.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # Copyright 2003 Bryan Ford 3 | # Distributed under the GNU General Public License. 4 | # 5 | # Usage: mergedep [ ...] 6 | # 7 | # This script merges the contents of all specified 8 | # on the command line into the single file , 9 | # which may or may not previously exist. 10 | # Dependencies in the will override 11 | # any existing dependencies for the same targets in . 12 | # The are deleted after is updated. 13 | # 14 | # The are typically generated by GCC with the -MD option, 15 | # and the is typically included from a Makefile, 16 | # as shown here for GNU 'make': 17 | # 18 | # .deps: $(wildcard *.d) 19 | # perl mergedep $@ $^ 20 | # -include .deps 21 | # 22 | # This script properly handles multiple dependencies per , 23 | # including dependencies having no target, 24 | # so it is compatible with GCC3's -MP option. 25 | # 26 | 27 | sub readdeps { 28 | my $filename = shift; 29 | 30 | open(DEPFILE, $filename) or return 0; 31 | while () { 32 | if (/([^:]*):([^\\:]*)([\\]?)$/) { 33 | my $target = $1; 34 | my $deplines = $2; 35 | my $slash = $3; 36 | while ($slash ne '') { 37 | $_ = ; 38 | defined($_) or die 39 | "Unterminated dependency in $filename"; 40 | /(^[ \t][^\\]*)([\\]?)$/ or die 41 | "Bad continuation line in $filename"; 42 | $deplines = "$deplines\\\n$1"; 43 | $slash = $2; 44 | } 45 | #print "DEPENDENCY [[$target]]: [[$deplines]]\n"; 46 | $dephash{$target} = $deplines; 47 | } elsif (/^[#]?[ \t]*$/) { 48 | # ignore blank lines and comments 49 | } else { 50 | die "Bad dependency line in $filename: $_"; 51 | } 52 | } 53 | close DEPFILE; 54 | return 1; 55 | } 56 | 57 | 58 | if ($#ARGV < 0) { 59 | print "Usage: mergedep [ ..]\n"; 60 | exit(1); 61 | } 62 | 63 | %dephash = (); 64 | 65 | # Read the main dependency file 66 | $maindeps = $ARGV[0]; 67 | readdeps($maindeps); 68 | 69 | # Read and merge in the new dependency files 70 | foreach $i (1 .. $#ARGV) { 71 | readdeps($ARGV[$i]) or die "Can't open $ARGV[$i]"; 72 | } 73 | 74 | # Update the main dependency file 75 | open(DEPFILE, ">$maindeps.tmp") or die "Can't open output file $maindeps.tmp"; 76 | foreach $target (keys %dephash) { 77 | print DEPFILE "$target:$dephash{$target}"; 78 | } 79 | close DEPFILE; 80 | rename("$maindeps.tmp", "$maindeps") or die "Can't overwrite $maindeps"; 81 | 82 | # Finally, delete the new dependency files 83 | foreach $i (1 .. $#ARGV) { 84 | unlink($ARGV[$i]) or print "Error removing $ARGV[$i]\n"; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /metadata.data: -------------------------------------------------------------------------------- 1 | database:tdb 2 | table:student 3 | num_of_fields:4 4 | field_types:N N S N 5 | field_lengths:20 8 64 8 6 | field_names:PFMDHKUBAToEq cdb_saltXZMEYJFFMA GEKBROFQEOoEq cdb_saltTNTIQAULBW 7 | choosen_onions:0 0 8 | -------------------------------------------------------------------------------- /mysql-proxy.cnf: -------------------------------------------------------------------------------- 1 | [mysql-proxy] 2 | plugins = proxy 3 | event-threads = 4 4 | proxy-address = 127.0.0.1:3399 5 | proxy-backen-addresses = 127.0.0.1:3306 6 | -------------------------------------------------------------------------------- /mysqlproxy/Makefrag: -------------------------------------------------------------------------------- 1 | OBJDIRS += mysqlproxy 2 | 3 | PROXY_SRCS := ConnectWrapper.cc 4 | PROXY_OBJS := $(patsubst %.cc,$(OBJDIR)/mysqlproxy/%.o,$(PROXY_SRCS)) 5 | 6 | all: $(OBJDIR)/libexecute.so 7 | 8 | $(OBJDIR)/libexecute.so: $(PROXY_OBJS) \ 9 | $(OBJDIR)/libedbcrypto.so \ 10 | $(OBJDIR)/libcryptdb.so \ 11 | $(OBJDIR)/libedbparser.so \ 12 | $(OBJDIR)/libedbutil.so 13 | $(CXX) -shared -o $@ $(PROXY_OBJS) $(LDFLAGS) $(LDRPATH) \ 14 | -ledbcrypto -lcryptdb -ledbutil -ledbparser -llua5.1 15 | 16 | # vim: set noexpandtab: 17 | -------------------------------------------------------------------------------- /packages/bison_2.7.1.dfsg-1_amd64.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/bison_2.7.1.dfsg-1_amd64.deb -------------------------------------------------------------------------------- /packages/libbison-dev_2.7.1.dfsg-1_amd64.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/libbison-dev_2.7.1.dfsg-1_amd64.deb -------------------------------------------------------------------------------- /packages/mysql-proxy-0.8.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/mysql-proxy-0.8.5.tar.gz -------------------------------------------------------------------------------- /packages/mysql-src.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/mysql-src.tar.gz -------------------------------------------------------------------------------- /packages/tls/buildtags.sh: -------------------------------------------------------------------------------- 1 | cd ../.. 2 | find . | grep '\.cc$\|\.c$\|\.h$\|\.hh$' | xargs ctags 3 | rm cscope* 4 | find . | grep '\.cc$\|\.c$\|\.h$\|\.hh$' > cscope.files 5 | cscope -R -b -i cscope.files 6 | -------------------------------------------------------------------------------- /packages/tls/essential.sh: -------------------------------------------------------------------------------- 1 | sudo apt install vim git 2 | -------------------------------------------------------------------------------- /packages/tls/gdbs: -------------------------------------------------------------------------------- 1 | ###start gdb 2 | sudo gdb `which mysql-proxy` `ps aux | grep 'mysql-proxy.cnf' |grep -v grep | awk '{print $2}'` 3 | -------------------------------------------------------------------------------- /packages/tls/int.sh: -------------------------------------------------------------------------------- 1 | if [ $# = 0 ];then 2 | echo "arg1 num in pipe, arg2 num of pipe" 3 | exit 4 | fi 5 | 6 | function inittable { 7 | mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "drop database if exists tpcc1000" 8 | mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "create database tpcc1000" 9 | mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "use tpcc1000; drop table if exists student" 10 | len=$[$1+16] 11 | #not supported 12 | mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "use tpcc1000; create table if not exists student2(name integer)" 13 | } 14 | 15 | 16 | #generate load.sql 17 | 18 | head='INSERT INTO student2 VALUES ' 19 | 20 | cur=1234567 21 | 22 | multi="" 23 | function getMultipleFields { 24 | num=$1 25 | cur=`date +%s` 26 | multi=\($cur\) 27 | for((i=1;i<$num;i++))do 28 | multi=${multi}\,\($cur\) 29 | done 30 | } 31 | getMultipleFields $1 32 | 33 | rm -rf load.sql 34 | 35 | 36 | echo "start to get multiple inserts!!!!" 37 | 38 | for((i=0;i<$2;i++))do 39 | echo $head$multi\; >> load.sql 40 | done 41 | 42 | inittable 43 | 44 | mysql -uroot -pletmein -h127.0.0.1 -P3399 tpcc1000 < load.sql 45 | 46 | mysqldump --skip-extended-insert -uroot -pletmein -h127.0.0.1 --hex-blob --compact tpcc1000 > back.sql 47 | 48 | 49 | -------------------------------------------------------------------------------- /packages/tls/intnormal.sh: -------------------------------------------------------------------------------- 1 | if [ $# = 0 ];then 2 | echo "arg1 num in pipe, arg2 num of pipe" 3 | exit 4 | fi 5 | 6 | function inittable { 7 | mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tpcc1000" 8 | mysql -uroot -pletmein -h127.0.0.1 -e "create database tpcc1000" 9 | mysql -uroot -pletmein -h127.0.0.1 -e "use tpcc1000; drop table if exists student" 10 | len=$[$1+16] 11 | #not supported 12 | mysql -uroot -pletmein -h127.0.0.1 -e "use tpcc1000; create table if not exists student2(name integer)" 13 | } 14 | 15 | 16 | #generate load.sql 17 | 18 | head='INSERT INTO student2 VALUES ' 19 | 20 | cur=1234567 21 | 22 | multi="" 23 | function getMultipleFields { 24 | num=$1 25 | multi=\($cur\) 26 | for((i=1;i<$num;i++))do 27 | multi=${multi}\,\($cur\) 28 | done 29 | } 30 | getMultipleFields $1 31 | 32 | rm -rf load.sql 33 | 34 | 35 | echo "start to get multiple inserts!!!!" 36 | 37 | for((i=0;i<$2;i++))do 38 | echo $head$multi\; >> load.sql 39 | done 40 | 41 | inittable 42 | 43 | mysql -uroot -pletmein -h127.0.0.1 tpcc1000 < load.sql 44 | 45 | mysqldump --skip-extended-insert -uroot -pletmein -h127.0.0.1 --hex-blob --compact tpcc1000 > back.sql 46 | 47 | 48 | -------------------------------------------------------------------------------- /packages/tls/mydumper/.bzrignore: -------------------------------------------------------------------------------- 1 | mydumper 2 | myloader 3 | *~ 4 | *.dSYM 5 | export 6 | CMakeCache.txt 7 | CMakeFiles/ 8 | Makefile 9 | cmake_install.cmake 10 | config.h 11 | docs/CMakeFiles/ 12 | docs/Makefile 13 | docs/_doctrees/ 14 | docs/_sources/ 15 | docs/cmake_install.cmake 16 | docs/html/ 17 | docs/man/ 18 | docs/_build/conf.py 19 | docs/_build/sources.cmake 20 | .project 21 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/3.5.1/CMakeCCompiler.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_C_COMPILER "/usr/bin/cc") 2 | set(CMAKE_C_COMPILER_ARG1 "") 3 | set(CMAKE_C_COMPILER_ID "GNU") 4 | set(CMAKE_C_COMPILER_VERSION "5.4.0") 5 | set(CMAKE_C_COMPILER_WRAPPER "") 6 | set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "11") 7 | set(CMAKE_C_COMPILE_FEATURES "c_function_prototypes;c_restrict;c_variadic_macros;c_static_assert") 8 | set(CMAKE_C90_COMPILE_FEATURES "c_function_prototypes") 9 | set(CMAKE_C99_COMPILE_FEATURES "c_restrict;c_variadic_macros") 10 | set(CMAKE_C11_COMPILE_FEATURES "c_static_assert") 11 | 12 | set(CMAKE_C_PLATFORM_ID "Linux") 13 | set(CMAKE_C_SIMULATE_ID "") 14 | set(CMAKE_C_SIMULATE_VERSION "") 15 | 16 | set(CMAKE_AR "/usr/bin/ar") 17 | set(CMAKE_RANLIB "/usr/bin/ranlib") 18 | set(CMAKE_LINKER "/usr/bin/ld") 19 | set(CMAKE_COMPILER_IS_GNUCC 1) 20 | set(CMAKE_C_COMPILER_LOADED 1) 21 | set(CMAKE_C_COMPILER_WORKS TRUE) 22 | set(CMAKE_C_ABI_COMPILED TRUE) 23 | set(CMAKE_COMPILER_IS_MINGW ) 24 | set(CMAKE_COMPILER_IS_CYGWIN ) 25 | if(CMAKE_COMPILER_IS_CYGWIN) 26 | set(CYGWIN 1) 27 | set(UNIX 1) 28 | endif() 29 | 30 | set(CMAKE_C_COMPILER_ENV_VAR "CC") 31 | 32 | if(CMAKE_COMPILER_IS_MINGW) 33 | set(MINGW 1) 34 | endif() 35 | set(CMAKE_C_COMPILER_ID_RUN 1) 36 | set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m) 37 | set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) 38 | set(CMAKE_C_LINKER_PREFERENCE 10) 39 | 40 | # Save compiler ABI information. 41 | set(CMAKE_C_SIZEOF_DATA_PTR "8") 42 | set(CMAKE_C_COMPILER_ABI "ELF") 43 | set(CMAKE_C_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") 44 | 45 | if(CMAKE_C_SIZEOF_DATA_PTR) 46 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}") 47 | endif() 48 | 49 | if(CMAKE_C_COMPILER_ABI) 50 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}") 51 | endif() 52 | 53 | if(CMAKE_C_LIBRARY_ARCHITECTURE) 54 | set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu") 55 | endif() 56 | 57 | set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "") 58 | if(CMAKE_C_CL_SHOWINCLUDES_PREFIX) 59 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}") 60 | endif() 61 | 62 | 63 | 64 | 65 | set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "c") 66 | set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/5;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib") 67 | set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") 68 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/3.5.1/CMakeDetermineCompilerABI_C.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/mydumper/CMakeFiles/3.5.1/CMakeDetermineCompilerABI_C.bin -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/3.5.1/CMakeDetermineCompilerABI_CXX.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/mydumper/CMakeFiles/3.5.1/CMakeDetermineCompilerABI_CXX.bin -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/3.5.1/CMakeSystem.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_HOST_SYSTEM "Linux-4.4.0-81-generic") 2 | set(CMAKE_HOST_SYSTEM_NAME "Linux") 3 | set(CMAKE_HOST_SYSTEM_VERSION "4.4.0-81-generic") 4 | set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64") 5 | 6 | 7 | 8 | set(CMAKE_SYSTEM "Linux-4.4.0-81-generic") 9 | set(CMAKE_SYSTEM_NAME "Linux") 10 | set(CMAKE_SYSTEM_VERSION "4.4.0-81-generic") 11 | set(CMAKE_SYSTEM_PROCESSOR "x86_64") 12 | 13 | set(CMAKE_CROSSCOMPILING "FALSE") 14 | 15 | set(CMAKE_SYSTEM_LOADED 1) 16 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/3.5.1/CompilerIdC/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/mydumper/CMakeFiles/3.5.1/CompilerIdC/a.out -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/3.5.1/CompilerIdCXX/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/mydumper/CMakeFiles/3.5.1/CompilerIdCXX/a.out -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/CMakeDirectoryInformation.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.5 3 | 4 | # Relative path conversion top directories. 5 | set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/casualet/github/Practical-Cryptdb/packages/tls/mydumper") 6 | set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/casualet/github/Practical-Cryptdb/packages/tls/mydumper") 7 | 8 | # Force unix paths in dependencies. 9 | set(CMAKE_FORCE_UNIX_PATHS 1) 10 | 11 | 12 | # The C and CXX include file regular expressions for this directory. 13 | set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") 14 | set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") 15 | set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) 16 | set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) 17 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/CMakeRuleHashes.txt: -------------------------------------------------------------------------------- 1 | # Hashes of file build rules. 2 | 2ca33b18fb9c1a0258c7782ae1fa698e CMakeFiles/dist 3 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/TargetDirectories.txt: -------------------------------------------------------------------------------- 1 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/install.dir 2 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/list_install_components.dir 3 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/rebuild_cache.dir 4 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/edit_cache.dir 5 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/mydumper.dir 6 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/dist.dir 7 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/myloader.dir 8 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/install/local.dir 9 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/install/strip.dir 10 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/docs/CMakeFiles/install.dir 11 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/docs/CMakeFiles/list_install_components.dir 12 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/docs/CMakeFiles/install/strip.dir 13 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/docs/CMakeFiles/install/local.dir 14 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/docs/CMakeFiles/rebuild_cache.dir 15 | /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/docs/CMakeFiles/edit_cache.dir 16 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/cmake.check_cache: -------------------------------------------------------------------------------- 1 | # This file is generated by cmake for dependency checking of the CMakeCache.txt file 2 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/dist.dir/DependInfo.cmake: -------------------------------------------------------------------------------- 1 | # The set of languages for which implicit dependencies are needed: 2 | set(CMAKE_DEPENDS_LANGUAGES 3 | ) 4 | # The set of files for implicit dependencies of each language: 5 | 6 | # Targets to which this target links. 7 | set(CMAKE_TARGET_LINKED_INFO_FILES 8 | ) 9 | 10 | # Fortran module output directory. 11 | set(CMAKE_Fortran_TARGET_MODULE_DIR "") 12 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/dist.dir/build.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.5 3 | 4 | # Delete rule output on recipe failure. 5 | .DELETE_ON_ERROR: 6 | 7 | 8 | #============================================================================= 9 | # Special targets provided by cmake. 10 | 11 | # Disable implicit rules so canonical targets will work. 12 | .SUFFIXES: 13 | 14 | 15 | # Remove some rules from gmake that .SUFFIXES does not remove. 16 | SUFFIXES = 17 | 18 | .SUFFIXES: .hpux_make_needs_suffix_list 19 | 20 | 21 | # Suppress display of executed commands. 22 | $(VERBOSE).SILENT: 23 | 24 | 25 | # A target that is always out of date. 26 | cmake_force: 27 | 28 | .PHONY : cmake_force 29 | 30 | #============================================================================= 31 | # Set environment variables for the build. 32 | 33 | # The shell in which to execute make rules. 34 | SHELL = /bin/sh 35 | 36 | # The CMake executable. 37 | CMAKE_COMMAND = /usr/bin/cmake 38 | 39 | # The command to remove a file. 40 | RM = /usr/bin/cmake -E remove -f 41 | 42 | # Escaping for special characters. 43 | EQUALS = = 44 | 45 | # The top-level source directory on which CMake was run. 46 | CMAKE_SOURCE_DIR = /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper 47 | 48 | # The top-level build directory on which CMake was run. 49 | CMAKE_BINARY_DIR = /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper 50 | 51 | # Utility rule file for dist. 52 | 53 | # Include the progress variables for this target. 54 | include CMakeFiles/dist.dir/progress.make 55 | 56 | CMakeFiles/dist: 57 | bzr export --root=mydumper-0.9.2 /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/mydumper-0.9.2.tar.gz 58 | 59 | dist: CMakeFiles/dist 60 | dist: CMakeFiles/dist.dir/build.make 61 | 62 | .PHONY : dist 63 | 64 | # Rule to build all files generated by this target. 65 | CMakeFiles/dist.dir/build: dist 66 | 67 | .PHONY : CMakeFiles/dist.dir/build 68 | 69 | CMakeFiles/dist.dir/clean: 70 | $(CMAKE_COMMAND) -P CMakeFiles/dist.dir/cmake_clean.cmake 71 | .PHONY : CMakeFiles/dist.dir/clean 72 | 73 | CMakeFiles/dist.dir/depend: 74 | cd /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper && $(CMAKE_COMMAND) -E cmake_depends "Unix Makefiles" /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/dist.dir/DependInfo.cmake --color=$(COLOR) 75 | .PHONY : CMakeFiles/dist.dir/depend 76 | 77 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/dist.dir/cmake_clean.cmake: -------------------------------------------------------------------------------- 1 | file(REMOVE_RECURSE 2 | "CMakeFiles/dist" 3 | ) 4 | 5 | # Per-language clean rules from dependency scanning. 6 | foreach(lang ) 7 | include(CMakeFiles/dist.dir/cmake_clean_${lang}.cmake OPTIONAL) 8 | endforeach() 9 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/dist.dir/progress.make: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/feature_tests.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/mydumper/CMakeFiles/feature_tests.bin -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/feature_tests.c: -------------------------------------------------------------------------------- 1 | 2 | const char features[] = {"\n" 3 | "C_FEATURE:" 4 | #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 404 5 | "1" 6 | #else 7 | "0" 8 | #endif 9 | "c_function_prototypes\n" 10 | "C_FEATURE:" 11 | #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 404 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 12 | "1" 13 | #else 14 | "0" 15 | #endif 16 | "c_restrict\n" 17 | "C_FEATURE:" 18 | #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201000L 19 | "1" 20 | #else 21 | "0" 22 | #endif 23 | "c_static_assert\n" 24 | "C_FEATURE:" 25 | #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 404 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 26 | "1" 27 | #else 28 | "0" 29 | #endif 30 | "c_variadic_macros\n" 31 | 32 | }; 33 | 34 | int main(int argc, char** argv) { (void)argv; return features[argc]; } 35 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/mydumper.dir/DependInfo.cmake: -------------------------------------------------------------------------------- 1 | # The set of languages for which implicit dependencies are needed: 2 | set(CMAKE_DEPENDS_LANGUAGES 3 | "C" 4 | ) 5 | # The set of files for implicit dependencies of each language: 6 | set(CMAKE_DEPENDS_CHECK_C 7 | "/home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/g_unix_signal.c" "/home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/mydumper.dir/g_unix_signal.c.o" 8 | "/home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/mydumper.c" "/home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/mydumper.dir/mydumper.c.o" 9 | "/home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/server_detect.c" "/home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/mydumper.dir/server_detect.c.o" 10 | ) 11 | set(CMAKE_C_COMPILER_ID "GNU") 12 | 13 | # The include file search paths: 14 | set(CMAKE_C_TARGET_INCLUDE_PATH 15 | "/usr/include/mysql" 16 | "/usr/include/glib-2.0" 17 | "/usr/lib/x86_64-linux-gnu/glib-2.0/include" 18 | ) 19 | 20 | # Targets to which this target links. 21 | set(CMAKE_TARGET_LINKED_INFO_FILES 22 | ) 23 | 24 | # Fortran module output directory. 25 | set(CMAKE_Fortran_TARGET_MODULE_DIR "") 26 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/mydumper.dir/cmake_clean.cmake: -------------------------------------------------------------------------------- 1 | file(REMOVE_RECURSE 2 | "CMakeFiles/mydumper.dir/mydumper.c.o" 3 | "CMakeFiles/mydumper.dir/server_detect.c.o" 4 | "CMakeFiles/mydumper.dir/g_unix_signal.c.o" 5 | "mydumper.pdb" 6 | "mydumper" 7 | ) 8 | 9 | # Per-language clean rules from dependency scanning. 10 | foreach(lang C) 11 | include(CMakeFiles/mydumper.dir/cmake_clean_${lang}.cmake OPTIONAL) 12 | endforeach() 13 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/mydumper.dir/flags.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.5 3 | 4 | # compile C with /usr/bin/cc 5 | C_FLAGS = -Wall -Wno-deprecated-declarations -Wunused -Wwrite-strings -Wno-strict-aliasing -Wextra -Wshadow -Werror -O3 -g -I/usr/include/mysql 6 | 7 | C_DEFINES = 8 | 9 | C_INCLUDES = -I/usr/include/mysql -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include 10 | 11 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/mydumper.dir/link.txt: -------------------------------------------------------------------------------- 1 | /usr/bin/cc -Wall -Wno-deprecated-declarations -Wunused -Wwrite-strings -Wno-strict-aliasing -Wextra -Wshadow -Werror -O3 -g -I/usr/include/mysql CMakeFiles/mydumper.dir/mydumper.c.o CMakeFiles/mydumper.dir/server_detect.c.o CMakeFiles/mydumper.dir/g_unix_signal.c.o -o mydumper -rdynamic -lmysqlclient -lpthread -lz -lm -lrt -ldl -lglib-2.0 -lgthread-2.0 -lpcre -lz -lm -lrt -ldl -lglib-2.0 -lgthread-2.0 -lpcre 2 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/mydumper.dir/progress.make: -------------------------------------------------------------------------------- 1 | CMAKE_PROGRESS_1 = 1 2 | CMAKE_PROGRESS_2 = 2 3 | CMAKE_PROGRESS_3 = 3 4 | CMAKE_PROGRESS_4 = 4 5 | 6 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/myloader.dir/DependInfo.cmake: -------------------------------------------------------------------------------- 1 | # The set of languages for which implicit dependencies are needed: 2 | set(CMAKE_DEPENDS_LANGUAGES 3 | "C" 4 | ) 5 | # The set of files for implicit dependencies of each language: 6 | set(CMAKE_DEPENDS_CHECK_C 7 | "/home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/myloader.c" "/home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/CMakeFiles/myloader.dir/myloader.c.o" 8 | ) 9 | set(CMAKE_C_COMPILER_ID "GNU") 10 | 11 | # The include file search paths: 12 | set(CMAKE_C_TARGET_INCLUDE_PATH 13 | "/usr/include/mysql" 14 | "/usr/include/glib-2.0" 15 | "/usr/lib/x86_64-linux-gnu/glib-2.0/include" 16 | ) 17 | 18 | # Targets to which this target links. 19 | set(CMAKE_TARGET_LINKED_INFO_FILES 20 | ) 21 | 22 | # Fortran module output directory. 23 | set(CMAKE_Fortran_TARGET_MODULE_DIR "") 24 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/myloader.dir/cmake_clean.cmake: -------------------------------------------------------------------------------- 1 | file(REMOVE_RECURSE 2 | "CMakeFiles/myloader.dir/myloader.c.o" 3 | "myloader.pdb" 4 | "myloader" 5 | ) 6 | 7 | # Per-language clean rules from dependency scanning. 8 | foreach(lang C) 9 | include(CMakeFiles/myloader.dir/cmake_clean_${lang}.cmake OPTIONAL) 10 | endforeach() 11 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/myloader.dir/flags.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.5 3 | 4 | # compile C with /usr/bin/cc 5 | C_FLAGS = -Wall -Wno-deprecated-declarations -Wunused -Wwrite-strings -Wno-strict-aliasing -Wextra -Wshadow -Werror -O3 -g -I/usr/include/mysql 6 | 7 | C_DEFINES = 8 | 9 | C_INCLUDES = -I/usr/include/mysql -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include 10 | 11 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/myloader.dir/link.txt: -------------------------------------------------------------------------------- 1 | /usr/bin/cc -Wall -Wno-deprecated-declarations -Wunused -Wwrite-strings -Wno-strict-aliasing -Wextra -Wshadow -Werror -O3 -g -I/usr/include/mysql CMakeFiles/myloader.dir/myloader.c.o -o myloader -rdynamic -lmysqlclient -lpthread -lz -lm -lrt -ldl -lglib-2.0 -lgthread-2.0 -lpcre -lz -lm -lrt -ldl -lglib-2.0 -lgthread-2.0 -lpcre 2 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/myloader.dir/progress.make: -------------------------------------------------------------------------------- 1 | CMAKE_PROGRESS_1 = 5 2 | CMAKE_PROGRESS_2 = 6 3 | 4 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeFiles/progress.marks: -------------------------------------------------------------------------------- 1 | 6 2 | -------------------------------------------------------------------------------- /packages/tls/mydumper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | project(mydumper) 3 | set(VERSION 0.9.2) 4 | set(ARCHIVE_NAME "${CMAKE_PROJECT_NAME}-${VERSION}") 5 | 6 | #Required packages 7 | set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) 8 | find_package(MySQL) 9 | find_package(ZLIB) 10 | find_package(GLIB2) 11 | find_package(PCRE) 12 | 13 | option(BUILD_DOCS "Build the documentation" ON) 14 | 15 | if (BUILD_DOCS) 16 | add_subdirectory(docs) 17 | endif (BUILD_DOCS) 18 | 19 | option(WITH_BINLOG "Build binlog dump options" OFF) 20 | 21 | set(CMAKE_C_FLAGS "-Wall -Wno-deprecated-declarations -Wunused -Wwrite-strings -Wno-strict-aliasing -Wextra -Wshadow -Werror -O3 -g ${MYSQL_CFLAGS}") 22 | 23 | include_directories(${MYDUMPER_SOURCE_DIR} ${MYSQL_INCLUDE_DIR} ${GLIB2_INCLUDE_DIR} ${PCRE_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS}) 24 | 25 | if (NOT CMAKE_INSTALL_PREFIX) 26 | SET(CMAKE_INSTALL_PREFIX "/usr/local" CACHE STRING "Install path" FORCE) 27 | endif (NOT CMAKE_INSTALL_PREFIX) 28 | MARK_AS_ADVANCED(CMAKE) 29 | 30 | CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h) 31 | 32 | 33 | if (WITH_BINLOG) 34 | add_executable(mydumper mydumper.c binlog.c server_detect.c g_unix_signal.c) 35 | else (WITH_BINLOG) 36 | add_executable(mydumper mydumper.c server_detect.c g_unix_signal.c) 37 | endif (WITH_BINLOG) 38 | target_link_libraries(mydumper ${MYSQL_LIBRARIES} ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARIES} ${PCRE_PCRE_LIBRARY} ${ZLIB_LIBRARIES}) 39 | 40 | 41 | add_executable(myloader myloader.c) 42 | target_link_libraries(myloader ${MYSQL_LIBRARIES} ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARIES} ${PCRE_PCRE_LIBRARY} ${ZLIB_LIBRARIES}) 43 | 44 | INSTALL(TARGETS mydumper myloader 45 | RUNTIME DESTINATION bin 46 | ) 47 | 48 | add_custom_target(dist 49 | COMMAND bzr export --root=${ARCHIVE_NAME} 50 | ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.gz 51 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) 52 | 53 | OPTION(RUN_CPPCHECK "Run cppcheck" OFF) 54 | 55 | IF(RUN_CPPCHECK) 56 | include(CppcheckTargets) 57 | add_cppcheck(mydumper) 58 | add_cppcheck(myloader) 59 | ENDIF(RUN_CPPCHECK) 60 | 61 | 62 | MESSAGE(STATUS "------------------------------------------------") 63 | MESSAGE(STATUS "MYSQL_CONFIG = ${MYSQL_CONFIG}") 64 | MESSAGE(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}") 65 | MESSAGE(STATUS "BUILD_DOCS = ${BUILD_DOCS}") 66 | MESSAGE(STATUS "WITH_BINLOG = ${WITH_BINLOG}") 67 | MESSAGE(STATUS "RUN_CPPCHECK = ${RUN_CPPCHECK}") 68 | MESSAGE(STATUS "Change a values with: cmake -D=") 69 | MESSAGE(STATUS "------------------------------------------------") 70 | MESSAGE(STATUS) 71 | 72 | -------------------------------------------------------------------------------- /packages/tls/mydumper/README: -------------------------------------------------------------------------------- 1 | == What is mydumper? Why? == 2 | 3 | * Parallelism (hence, speed) and performance (avoids expensive character set conversion routines, efficient code overall) 4 | * Easier to manage output (separate files for tables, dump metadata, etc, easy to view/parse data) 5 | * Consistency - maintains snapshot across all threads, provides accurate master and slave log positions, etc 6 | * Manageability - supports PCRE for specifying database and tables inclusions and exclusions 7 | 8 | == How to build it? == 9 | 10 | Run: 11 | cmake . 12 | make 13 | 14 | One needs to install development versions of required libaries (MySQL, GLib, ZLib, PCRE): 15 | NOTE: you must use the correspondent mysql devel package. 16 | 17 | * Ubuntu or Debian: apt-get install libglib2.0-dev libmysqlclient15-dev zlib1g-dev libpcre3-dev libssl-dev 18 | * Fedora, RedHat and CentOS: yum install glib2-devel mysql-devel zlib-devel pcre-devel openssl-devel 19 | * openSUSE: zypper install glib2-devel libmysqlclient-devel pcre-devel zlib-devel 20 | * MacOSX: port install glib2 mysql5 pcre pkgconfig cmake 21 | (You may want to run 'port select mysql mysql5' afterwards) 22 | 23 | One has to make sure, that pkg-config, mysql_config, pcre-config are all in $PATH 24 | 25 | Binlog dump is disabled by default to compile with it you need to add -DWITH_BINLOG=ON to cmake options 26 | 27 | == How does consistent snapshot work? == 28 | 29 | This is all done following best MySQL practices and traditions: 30 | 31 | * As a precaution, slow running queries on the server either abort the dump, or get killed 32 | * Global write lock is acquired ("FLUSH TABLES WITH READ LOCK") 33 | * Various metadata is read ("SHOW SLAVE STATUS","SHOW MASTER STATUS") 34 | * Other threads connect and establish snapshots ("START TRANSACTION WITH CONSISTENT SNAPSHOT") 35 | ** On pre-4.1.8 it creates dummy InnoDB table, and reads from it. 36 | * Once all worker threads announce the snapshot establishment, master executes "UNLOCK TABLES" and starts queueing jobs. 37 | 38 | This for now does not provide consistent snapshots for non-transactional engines - support for that is expected in 0.2 :) 39 | 40 | == How to exclude (or include) databases? == 41 | 42 | Once can use --regex functionality, for example not to dump mysql and test databases: 43 | 44 | mydumper --regex '^(?!(mysql|test))' 45 | 46 | Of course, regex functionality can be used to describe pretty much any list of tables. 47 | 48 | 49 | -------------------------------------------------------------------------------- /packages/tls/mydumper/binlog.h: -------------------------------------------------------------------------------- 1 | /* 2 | This program is free software: you can redistribute it and/or modify 3 | it under the terms of the GNU General Public License as published by 4 | the Free Software Foundation, either version 3 of the License, or 5 | (at your option) any later version. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program. If not, see . 14 | 15 | Authors: Domas Mituzas, Facebook ( domas at fb dot com ) 16 | Mark Leith, Oracle Corporation (mark dot leith at oracle dot com) 17 | Andrew Hutchings, SkySQL (andrew at skysql dot com) 18 | 19 | */ 20 | 21 | #ifndef _binlog_h 22 | #define _binlog_h 23 | #include "mydumper.h" 24 | 25 | void get_binlogs(MYSQL *conn, struct configuration *conf); 26 | void get_binlog_file(MYSQL *conn, char *binlog_file, const char *binlog_directory, guint64 start_position, guint64 stop_position, gboolean continuous); 27 | unsigned int get_event(const char *buf, unsigned int len); 28 | void write_binlog(FILE* file, const char* data, guint64 len); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /packages/tls/mydumper/cmake/modules/FindGLIB2.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find the GLIB2 libraries 2 | 3 | if(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES AND GTHREAD2_LIBRARIES) 4 | # Already in cache, be silent 5 | set(GLIB2_FIND_QUIETLY TRUE) 6 | endif(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES AND GTHREAD2_LIBRARIES) 7 | 8 | if (NOT WIN32) 9 | include(FindPkgConfig) 10 | pkg_search_module(PC_GLIB2 REQUIRED glib-2.0) 11 | pkg_search_module(PC_GTHREAD2 REQUIRED gthread-2.0) 12 | endif(NOT WIN32) 13 | 14 | set(GLIB2_INCLUDE_DIR ${PC_GLIB2_INCLUDE_DIRS}) 15 | 16 | find_library(GLIB2_LIBRARIES NAMES glib-2.0 HINTS ${PC_GLIB2_LIBDIR} ${PC_GLIB2_LIBRARY_DIRS}) 17 | 18 | find_library(GTHREAD2_LIBRARIES NAMES gthread-2.0 HINTS ${PC_GTHREAD2_LIBDIR} ${PC_GTHREAD2_LIBRARY_DIRS}) 19 | 20 | 21 | mark_as_advanced(GLIB2_INCLUDE_DIR GLIB2_LIBRARIES GTHREAD2_LIBRARIES) 22 | 23 | -------------------------------------------------------------------------------- /packages/tls/mydumper/cmake/modules/FindPCRE.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find the PCRE regular expression library 2 | # Once done this will define 3 | # 4 | # PCRE_FOUND - system has the PCRE library 5 | # PCRE_INCLUDE_DIR - the PCRE include directory 6 | # PCRE_LIBRARIES - The libraries needed to use PCRE 7 | 8 | # Copyright (c) 2006, Alexander Neundorf, 9 | # 10 | # Redistribution and use is allowed according to the terms of the BSD license. 11 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 12 | 13 | 14 | if (PCRE_INCLUDE_DIR AND PCRE_PCREPOSIX_LIBRARY AND PCRE_PCRE_LIBRARY) 15 | # Already in cache, be silent 16 | set(PCRE_FIND_QUIETLY TRUE) 17 | endif (PCRE_INCLUDE_DIR AND PCRE_PCREPOSIX_LIBRARY AND PCRE_PCRE_LIBRARY) 18 | 19 | 20 | if (NOT WIN32) 21 | # use pkg-config to get the directories and then use these values 22 | # in the FIND_PATH() and FIND_LIBRARY() calls 23 | find_package(PkgConfig) 24 | 25 | pkg_check_modules(PC_PCRE REQUIRED libpcre) 26 | 27 | set(PCRE_DEFINITIONS ${PC_PCRE_CFLAGS_OTHER}) 28 | 29 | endif (NOT WIN32) 30 | 31 | find_path(PCRE_INCLUDE_DIR pcre.h 32 | HINTS ${PC_PCRE_INCLUDEDIR} ${PC_PCRE_INCLUDE_DIRS} 33 | PATH_SUFFIXES pcre) 34 | 35 | find_library(PCRE_PCRE_LIBRARY NAMES pcre HINTS ${PC_PCRE_LIBDIR} ${PC_PCRE_LIBRARY_DIRS}) 36 | 37 | find_library(PCRE_PCREPOSIX_LIBRARY NAMES pcreposix HINTS ${PC_PCRE_LIBDIR} ${PC_PCRE_LIBRARY_DIRS}) 38 | 39 | include(FindPackageHandleStandardArgs) 40 | find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_INCLUDE_DIR PCRE_PCRE_LIBRARY PCRE_PCREPOSIX_LIBRARY ) 41 | 42 | set(PCRE_LIBRARIES ${PCRE_PCRE_LIBRARY} ${PCRE_PCREPOSIX_LIBRARY}) 43 | 44 | mark_as_advanced(PCRE_INCLUDE_DIR PCRE_LIBRARIES PCRE_PCREPOSIX_LIBRARY PCRE_PCRE_LIBRARY) 45 | 46 | -------------------------------------------------------------------------------- /packages/tls/mydumper/cmake/modules/FindSphinx.cmake: -------------------------------------------------------------------------------- 1 | # - This module looks for Sphinx 2 | # Find the Sphinx documentation generator 3 | # 4 | # This modules defines 5 | # SPHINX_EXECUTABLE 6 | # SPHINX_FOUND 7 | # SPHINX_MAJOR_VERSION 8 | # SPHINX_MINOR_VERSION 9 | # SPHINX_VERSION 10 | 11 | #============================================================================= 12 | # Copyright 2002-2009 Kitware, Inc. 13 | # Copyright 2009-2011 Peter Colberg 14 | # 15 | # Distributed under the OSI-approved BSD License (the "License"); 16 | # see accompanying file COPYING-CMAKE-SCRIPTS for details. 17 | # 18 | # This software is distributed WITHOUT ANY WARRANTY; without even the 19 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20 | # See the License for more information. 21 | #============================================================================= 22 | # (To distribute this file outside of CMake, substitute the full 23 | # License text for the above reference.) 24 | 25 | find_program(SPHINX_EXECUTABLE NAMES sphinx-build 26 | HINTS 27 | $ENV{SPHINX_DIR} 28 | PATH_SUFFIXES bin 29 | DOC "Sphinx documentation generator" 30 | ) 31 | 32 | include(FindPackageHandleStandardArgs) 33 | 34 | find_package_handle_standard_args(Sphinx DEFAULT_MSG 35 | SPHINX_EXECUTABLE 36 | ) 37 | 38 | if (SPHINX_EXECUTABLE) 39 | execute_process ( 40 | COMMAND "${SPHINX_EXECUTABLE}" -h 41 | OUTPUT_VARIABLE _SPHINX_VERSION_OUTPUT 42 | ERROR_VARIABLE _SPHINX_VERSION_OUTPUT 43 | ) 44 | if (_SPHINX_VERSION_OUTPUT MATCHES "Sphinx v([0-9]+\\.[0-9]+\\.[0-9]+)") 45 | set (SPHINX_VERSION "${CMAKE_MATCH_1}") 46 | string (REPLACE "." ";" _SPHINX_VERSION_LIST "${SPHINX_VERSION}") 47 | list (GET _SPHINX_VERSION_LIST 0 SPHINX_MAJOR_VERSION) 48 | list (GET _SPHINX_VERSION_LIST 1 SPHINX_MINOR_VERSION) 49 | # patch version meh :) 50 | endif() 51 | endif() 52 | 53 | message("${SPHINX_MAJOR_VERSION}") 54 | 55 | mark_as_advanced( 56 | SPHINX_EXECUTABLE 57 | ) 58 | -------------------------------------------------------------------------------- /packages/tls/mydumper/cmake/modules/Findcppcheck.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * \file Findcppcheck.cpp 3 | * \brief Dummy C++ source file used by CMake module Findcppcheck.cmake 4 | * 5 | * \author 6 | * Ryan Pavlik, 2009-2010 7 | * 8 | * http://academic.cleardefinition.com/ 9 | * 10 | */ 11 | 12 | 13 | 14 | int main(int argc, char* argv[]) { 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /packages/tls/mydumper/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | This program is free software: you can redistribute it and/or modify 3 | it under the terms of the GNU General Public License as published by 4 | the Free Software Foundation, either version 3 of the License, or 5 | (at your option) any later version. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program. If not, see . 14 | 15 | Authors: Andrew Hutchings, SkySQL (andrew at skysql dot com) 16 | */ 17 | #ifndef _common_h 18 | #define _common_h 19 | 20 | char *hostname=NULL; 21 | char *username=NULL; 22 | char *password=NULL; 23 | char *socket_path=NULL; 24 | char *db=NULL; 25 | char *defaults_file=NULL; 26 | guint port=3306; 27 | guint num_threads= 1; 28 | guint verbose=2; 29 | gboolean compress_protocol= FALSE; 30 | gboolean program_version= FALSE; 31 | 32 | GOptionEntry common_entries[] = 33 | { 34 | { "host", 'h', 0, G_OPTION_ARG_STRING, &hostname, "The host to connect to", NULL }, 35 | { "user", 'u', 0, G_OPTION_ARG_STRING, &username, "Username with the necessary privileges", NULL }, 36 | { "password", 'p', 0, G_OPTION_ARG_STRING, &password, "User password", NULL }, 37 | { "port", 'P', 0, G_OPTION_ARG_INT, &port, "TCP/IP port to connect to", NULL }, 38 | { "socket", 'S', 0, G_OPTION_ARG_STRING, &socket_path, "UNIX domain socket file to use for connection", NULL }, 39 | { "threads", 't', 0, G_OPTION_ARG_INT, &num_threads, "Number of threads to use, default 4", NULL }, 40 | { "compress-protocol", 'C', 0, G_OPTION_ARG_NONE, &compress_protocol, "Use compression on the MySQL connection", NULL }, 41 | { "version", 'V', 0, G_OPTION_ARG_NONE, &program_version, "Show the program version and exit", NULL }, 42 | { "verbose", 'v', 0, G_OPTION_ARG_INT, &verbose, "Verbosity of output, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2", NULL }, 43 | { "defaults-file", 0, 0, G_OPTION_ARG_FILENAME, &defaults_file, "Use a specific defaults file", NULL }, 44 | { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /packages/tls/mydumper/config.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | 4 | #define VERSION "0.9.2" 5 | /* #undef WITH_BINLOG */ 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /packages/tls/mydumper/config.h.in: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | 4 | #cmakedefine VERSION "@VERSION@" 5 | #cmakedefine WITH_BINLOG 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /packages/tls/mydumper/dest/metadata: -------------------------------------------------------------------------------- 1 | Started dump at: 2017-07-09 14:29:23 2 | Finished dump at: 2017-07-09 14:29:23 3 | -------------------------------------------------------------------------------- /packages/tls/mydumper/dest/tdb3-schema-create.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE `tdb3` /*!40100 DEFAULT CHARACTER SET latin1 */; 2 | -------------------------------------------------------------------------------- /packages/tls/mydumper/dest/tdb3.student-schema.sql: -------------------------------------------------------------------------------- 1 | /*!40101 SET NAMES binary*/; 2 | /*!40014 SET FOREIGN_KEY_CHECKS=0*/; 3 | 4 | CREATE TABLE `student` ( 5 | `id` int(11) DEFAULT NULL, 6 | `name` varchar(20) DEFAULT NULL 7 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 8 | -------------------------------------------------------------------------------- /packages/tls/mydumper/dest/tdb3.student.sql: -------------------------------------------------------------------------------- 1 | /*!40101 SET NAMES binary*/; 2 | /*!40014 SET FOREIGN_KEY_CHECKS=0*/; 3 | /*!40103 SET TIME_ZONE='+00:00' */; 4 | INSERT INTO `student` VALUES 5 | (1,"ZHANGFEI"), 6 | (2,"\n\n"), 7 | (3,"\'"), 8 | (4,""), 9 | (1,"\n;"); 10 | -------------------------------------------------------------------------------- /packages/tls/mydumper/docs/CMakeFiles/CMakeDirectoryInformation.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.5 3 | 4 | # Relative path conversion top directories. 5 | set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/casualet/github/Practical-Cryptdb/packages/tls/mydumper") 6 | set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/casualet/github/Practical-Cryptdb/packages/tls/mydumper") 7 | 8 | # Force unix paths in dependencies. 9 | set(CMAKE_FORCE_UNIX_PATHS 1) 10 | 11 | 12 | # The C and CXX include file regular expressions for this directory. 13 | set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") 14 | set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") 15 | set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) 16 | set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) 17 | -------------------------------------------------------------------------------- /packages/tls/mydumper/docs/CMakeFiles/progress.marks: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /packages/tls/mydumper/docs/_build/sources.cmake.in: -------------------------------------------------------------------------------- 1 | # This script recursively copies all ReST documents from the source directory to 2 | # the binary directory. CMAKE_CURRENT_SOURCE_DIR and SOURCES_DIR are substituted 3 | # upon the cmake stage. The script is executed upon the make stage to ensure 4 | # that the binary sources directory is always up to date. 5 | 6 | file(GLOB SOURCES 7 | RELATIVE "@CMAKE_CURRENT_SOURCE_DIR@" 8 | "@CMAKE_CURRENT_SOURCE_DIR@/*.rst" 9 | ) 10 | foreach(source ${SOURCES}) 11 | configure_file( 12 | "@CMAKE_CURRENT_SOURCE_DIR@/${source}" 13 | "@SOURCES_DIR@/${source}" 14 | COPYONLY 15 | ) 16 | endforeach(source) 17 | -------------------------------------------------------------------------------- /packages/tls/mydumper/docs/authors.rst: -------------------------------------------------------------------------------- 1 | Authors 2 | ======= 3 | 4 | The code for mydumper has been written by the following people: 5 | 6 | * `Domas Mituzas `_, Facebook ( domas at fb dot com ) 7 | * `Andrew Hutchings `_, SkySQL ( andrew at skysql dot com ) 8 | * `Mark Leith `_, Oracle Corporation ( mark dot leith at oracle dot com ) 9 | * `Max Bubenick `_, Percona RDBA ( max dot bubenick at percona dot com ) 10 | -------------------------------------------------------------------------------- /packages/tls/mydumper/docs/cmake_install.cmake: -------------------------------------------------------------------------------- 1 | # Install script for directory: /home/casualet/github/Practical-Cryptdb/packages/tls/mydumper/docs 2 | 3 | # Set the install prefix 4 | if(NOT DEFINED CMAKE_INSTALL_PREFIX) 5 | set(CMAKE_INSTALL_PREFIX "/usr/local") 6 | endif() 7 | string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") 8 | 9 | # Set the install configuration name. 10 | if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) 11 | if(BUILD_TYPE) 12 | string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" 13 | CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") 14 | else() 15 | set(CMAKE_INSTALL_CONFIG_NAME "") 16 | endif() 17 | message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") 18 | endif() 19 | 20 | # Set the component getting installed. 21 | if(NOT CMAKE_INSTALL_COMPONENT) 22 | if(COMPONENT) 23 | message(STATUS "Install component: \"${COMPONENT}\"") 24 | set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") 25 | else() 26 | set(CMAKE_INSTALL_COMPONENT) 27 | endif() 28 | endif() 29 | 30 | # Install shared libraries without execute permission? 31 | if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) 32 | set(CMAKE_INSTALL_SO_NO_EXE "1") 33 | endif() 34 | 35 | -------------------------------------------------------------------------------- /packages/tls/mydumper/docs/compiling.rst: -------------------------------------------------------------------------------- 1 | Compiling 2 | ========= 3 | 4 | Requirements 5 | ------------ 6 | 7 | mydumper requires the following before it can be compiled: 8 | 9 | * `CMake `_ 10 | * `Glib2 `_ (with development packages) 11 | * `PCRE `_ (with development packages) 12 | * `MySQL `_ client libraries (with development packages) 13 | 14 | Additionally the following packages are optional: 15 | 16 | * `python-sphinx `_ (for documentation) 17 | 18 | Ubuntu/Debian 19 | ^^^^^^^^^^^^^ 20 | 21 | .. code-block:: bash 22 | 23 | apt-get install libglib2.0-dev libmysqlclient15-dev zlib1g-dev libpcre3-dev 24 | 25 | Fedora/Redhat/CentOS 26 | ^^^^^^^^^^^^^^^^^^^^ 27 | 28 | .. code-block:: bash 29 | 30 | yum install glib2-devel mysql-devel zlib-devel pcre-devel 31 | 32 | OpenSUSE 33 | ^^^^^^^^ 34 | 35 | .. code-block:: bash 36 | 37 | zypper install glib2-devel libmysqlclient-devel pcre-devel zlib-devel 38 | 39 | Mac OSX 40 | ^^^^^^^ 41 | 42 | .. code-block:: bash 43 | 44 | port install glib2 mysql5 pcre 45 | 46 | CMake 47 | ----- 48 | 49 | CMake is used for mydumper's build system and is executed as follows:: 50 | 51 | cmake . 52 | make 53 | 54 | You can optionally provide parameters for CMake, the possible options are: 55 | 56 | * ``-DMYSQL_CONFIG=/path/to/mysql_config`` - The path and filename for the mysql_config executable 57 | * ``-DCMAKE_INSTALL_PREFIX=/install/path`` - The path where mydumper should be installed 58 | 59 | Documentation 60 | ------------- 61 | 62 | If you wish to just compile the documentation you can do so with:: 63 | 64 | cmake . 65 | make doc_html 66 | 67 | or for a man page output:: 68 | 69 | cmake . 70 | make doc_man 71 | -------------------------------------------------------------------------------- /packages/tls/mydumper/docs/examples.rst: -------------------------------------------------------------------------------- 1 | Examples 2 | ======== 3 | 4 | Simple Usage 5 | ------------ 6 | Just running :program:`mydumper` without any options will try to connect to a 7 | server using the default socket path. It will then dump the tables from all 8 | databases using 4 worker threads. 9 | 10 | Regex 11 | ----- 12 | To use :program:`mydumper`'s regex feature simply use the 13 | :option:`--regex ` option. In the following example mydumper 14 | will ignore the ``test`` and ``mysql`` databases:: 15 | 16 | mydumper --regex '^(?!(mysql|test))' 17 | 18 | Restoring a dump 19 | ---------------- 20 | Mydumper now include myloader which is a multi-threaded restoration tool. To 21 | use myloader with a mydumper dump you simply need to pass it the directory of 22 | the dump along with a user capable of restoring the schemas and data. As an 23 | example the following will restore a dump overwriting any existing tables:: 24 | 25 | myloader --directory=export-20110614-094953 --overwrite-tables --user=root 26 | 27 | Daemon mode 28 | ----------- 29 | Mydumper has a daemon mode which will snapshot the dump data every so often 30 | whilst continuously retreiving the binary log files. This gives a continuous 31 | consistent backup right up to the point where the database server fails. To use 32 | this you simply need to use the :option:`--daemon ` option. 33 | 34 | In the following example mydumper will use daemon mode, creating a snapshot 35 | every half an hour and log to an output file:: 36 | 37 | mydumper --daemon --snapshot-interval=30 --logfile=dump.log 38 | -------------------------------------------------------------------------------- /packages/tls/mydumper/docs/files.rst: -------------------------------------------------------------------------------- 1 | Output Files 2 | ============ 3 | 4 | mydumper generates several files during the generation of the dump. Many of 5 | these are for the table data itself since every table has at least one file. 6 | 7 | Metadata 8 | -------- 9 | When a dump is executed a file called ``metadata.partial`` is created in the output 10 | directory and is renamed to ``metadata`` when mydumper finish without error. 11 | This contains the start and end time of the dump as well as the 12 | master binary log positions if applicable. 13 | 14 | This is an example of the content of this file:: 15 | 16 | Started dump at: 2011-05-05 13:57:17 17 | SHOW MASTER STATUS: 18 | Log: linuxjedi-laptop-bin.000001 19 | Pos: 106 20 | 21 | Finished dump at: 2011-05-05 13:57:17 22 | 23 | Table Data 24 | ---------- 25 | The data from every table is written into a separate file, also if the 26 | :option:`--rows ` option is used then each chunk of table will 27 | be in a separate file. The file names for this are in the format:: 28 | 29 | database.table.sql(.gz) 30 | 31 | or if chunked:: 32 | 33 | database.table.chunk.sql(.gz) 34 | 35 | Where 'chunk' is a number padded with up to 5 zeros. 36 | 37 | Table Schemas 38 | ------------- 39 | When the :option:`--schemas ` option is used mydumper will 40 | create a file for the schema of every table it is writing data for. The files 41 | for this are in the following format:: 42 | 43 | database.table-schema.sql(.gz) 44 | 45 | Binary Logs 46 | ----------- 47 | Binary logs are retrieved when :option:`--binlogs ` option 48 | has been set. This will store them in the ``binlog_snapshot/`` sub-directory 49 | inside the dump directory. 50 | 51 | The binary log files have the same filename as the MySQL server that supplies them and will also have a .gz on the end if they are compressed. 52 | 53 | Daemon mode 54 | ----------- 55 | Daemon mode does things a little differently. There are the directories ``0`` 56 | and ``1`` inside the dump directory. These alternate when dumping so that if 57 | mydumper fails for any reason there is still a good snapshot. When a snapshot 58 | dump is complete the ``last_dump`` symlink is updated to point to that dump. 59 | 60 | If binary logging is enabled mydumper will connect as if it is a slave server 61 | and constantly retreives the binary logs into the ``binlogs`` subdirectory. 62 | -------------------------------------------------------------------------------- /packages/tls/mydumper/docs/index.rst: -------------------------------------------------------------------------------- 1 | .. MySQL Data Dumper documentation master file 2 | You can adapt this file completely to your liking, but it should at least 3 | contain the root `toctree` directive. 4 | 5 | Welcome to MySQL Data Dumper's documentation! 6 | ============================================= 7 | 8 | Contents: 9 | 10 | .. toctree:: 11 | :maxdepth: 2 12 | 13 | authors 14 | compiling 15 | mydumper_usage 16 | myloader_usage 17 | files 18 | examples 19 | 20 | Indices and tables 21 | ================== 22 | 23 | * :ref:`genindex` 24 | * :ref:`search` 25 | 26 | -------------------------------------------------------------------------------- /packages/tls/mydumper/docs/myloader_usage.rst: -------------------------------------------------------------------------------- 1 | Myloader Usage 2 | ============== 3 | 4 | Synopsis 5 | -------- 6 | 7 | :program:`myloader` :option:`--directory ` = /path/to/mydumper/backup [:ref:`OPTIONS `] 8 | 9 | Description 10 | ----------- 11 | 12 | :program:`myloader` is a tool used for multi-threaded restoration of mydumper 13 | backups. 14 | 15 | .. _myloader-options-label: 16 | 17 | Options 18 | ------- 19 | 20 | The :program:`myloader` tool has several available options: 21 | 22 | .. program:: myloader 23 | 24 | .. option:: --help, -? 25 | 26 | Show help text 27 | 28 | .. option:: --defaults-file 29 | 30 | Use the given option file. If the file does not exist or is otherwise inaccessible, no failure occurs 31 | 32 | .. option:: --host, -h 33 | 34 | Hostname of MySQL server to connect to (default localhost) 35 | 36 | .. option:: --user, -u 37 | 38 | MySQL username with the correct privileges to execute the restoration 39 | 40 | .. option:: --password, -p 41 | 42 | The corresponding password for the MySQL user 43 | 44 | .. option:: --port, -P 45 | 46 | The port for the MySQL connection. 47 | 48 | .. note:: 49 | 50 | For localhost TCP connections use 127.0.0.1 for :option:`--host`. 51 | 52 | .. option:: --socket, -S 53 | 54 | The UNIX domain socket file to use for the connection 55 | 56 | .. option:: --threads, -t 57 | 58 | The number of threads to use for restoring data, default is 4 59 | 60 | .. option:: --version, -V 61 | 62 | Show the program version and exit 63 | 64 | .. option:: --compress-protocol, -C 65 | 66 | Use client protocol compression for connections to the MySQL server 67 | 68 | .. option:: --directory, -d 69 | 70 | The directory of the mydumper backup to restore 71 | 72 | .. option:: --database, -B 73 | 74 | An alternative database to load the dump into 75 | 76 | .. note:: 77 | 78 | For use with single database dumps. When using with multi-database dumps 79 | that have duplicate table names in more than one database it may cause 80 | errors. Alternatively this scenario may give unpredictable results with 81 | :option:`--overwrite-tables`. 82 | 83 | .. option:: --source-db, -s 84 | 85 | Database to restore, useful in combination with --database 86 | 87 | .. option:: --queries-per-transaction, -q 88 | 89 | Number of INSERT queries to execute per transaction during restore, default 90 | is 1000. 91 | 92 | .. option:: --overwrite-tables, -o 93 | 94 | Drop any existing tables when restoring schemas 95 | 96 | .. option:: --enable-binlog, -e 97 | 98 | Log the data loading in the MySQL binary log if enabled (off by default) 99 | 100 | .. option:: --verbose, -v 101 | 102 | The verbosity of messages. 0 = silent, 1 = errors, 2 = warnings, 3 = info. 103 | Default is 2. 104 | -------------------------------------------------------------------------------- /packages/tls/mydumper/g_unix_signal.h: -------------------------------------------------------------------------------- 1 | #ifndef G_UNIX_SIGNAL_H 2 | #define G_UNIX_SIGNAL_H 3 | 4 | #include 5 | 6 | GSource *g_unix_signal_source_new(gint signum); 7 | guint g_unix_signal_add(gint signum, GSourceFunc function, gpointer data); 8 | guint g_unix_signal_add_full(gint priority, gint signum, GSourceFunc function, gpointer data, GDestroyNotify notify); 9 | 10 | #endif /* G_UNIX_SIGNAL_H */ 11 | -------------------------------------------------------------------------------- /packages/tls/mydumper/mydumper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/mydumper/mydumper -------------------------------------------------------------------------------- /packages/tls/mydumper/mydumper.h: -------------------------------------------------------------------------------- 1 | /* 2 | This program is free software: you can redistribute it and/or modify 3 | it under the terms of the GNU General Public License as published by 4 | the Free Software Foundation, either version 3 of the License, or 5 | (at your option) any later version. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program. If not, see . 14 | 15 | Authors: Domas Mituzas, Facebook ( domas at fb dot com ) 16 | Mark Leith, Oracle Corporation (mark dot leith at oracle dot com) 17 | Andrew Hutchings, SkySQL (andrew at skysql dot com) 18 | Max Bubenick, Percona RDBA (max dot bubenick at percona dot com) 19 | 20 | */ 21 | 22 | #ifndef _mydumper_h 23 | #define _mydumper_h 24 | 25 | enum job_type { JOB_SHUTDOWN, JOB_RESTORE, JOB_DUMP, JOB_DUMP_NON_INNODB, JOB_SCHEMA, JOB_VIEW, JOB_TRIGGERS, JOB_SCHEMA_POST, JOB_BINLOG, JOB_LOCK_DUMP_NON_INNODB }; 26 | 27 | struct configuration { 28 | char use_any_index; 29 | GAsyncQueue* queue; 30 | GAsyncQueue* queue_less_locking; 31 | GAsyncQueue* ready; 32 | GAsyncQueue* ready_less_locking; 33 | GAsyncQueue* unlock_tables; 34 | GMutex* mutex; 35 | int done; 36 | }; 37 | 38 | struct thread_data { 39 | struct configuration *conf; 40 | guint thread_id; 41 | }; 42 | 43 | struct job { 44 | enum job_type type; 45 | void *job_data; 46 | struct configuration *conf; 47 | }; 48 | 49 | struct table_job { 50 | char *database; 51 | char *table; 52 | char *filename; 53 | char *where; 54 | }; 55 | 56 | struct tables_job { 57 | GList* table_job_list; 58 | }; 59 | 60 | struct schema_job { 61 | char *database; 62 | char *table; 63 | char *filename; 64 | }; 65 | 66 | struct view_job { 67 | char *database; 68 | char *table; 69 | char *filename; 70 | char *filename2; 71 | }; 72 | 73 | struct schema_post_job { 74 | char *database; 75 | char *filename; 76 | }; 77 | 78 | struct restore_job { 79 | char *database; 80 | char *table; 81 | char *filename; 82 | }; 83 | 84 | struct binlog_job { 85 | char *filename; 86 | guint64 start_position; 87 | guint64 stop_position; 88 | }; 89 | 90 | struct db_table { 91 | char* database; 92 | char* table; 93 | guint64 datalength; 94 | }; 95 | 96 | struct schema_post { 97 | char* database; 98 | }; 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /packages/tls/mydumper/myloader: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/mydumper/myloader -------------------------------------------------------------------------------- /packages/tls/mydumper/myloader.h: -------------------------------------------------------------------------------- 1 | /* 2 | This program is free software: you can redistribute it and/or modify 3 | it under the terms of the GNU General Public License as published by 4 | the Free Software Foundation, either version 3 of the License, or 5 | (at your option) any later version. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program. If not, see . 14 | 15 | Authors: Domas Mituzas, Facebook ( domas at fb dot com ) 16 | Mark Leith, Oracle Corporation (mark dot leith at oracle dot com) 17 | Andrew Hutchings, SkySQL (andrew at skysql dot com) 18 | 19 | */ 20 | 21 | #ifndef _myloader_h 22 | #define _myloader_h 23 | 24 | enum job_type { JOB_SHUTDOWN, JOB_RESTORE }; 25 | 26 | struct configuration { 27 | GAsyncQueue* queue; 28 | GAsyncQueue* ready; 29 | GMutex* mutex; 30 | int done; 31 | }; 32 | 33 | struct thread_data { 34 | struct configuration *conf; 35 | guint thread_id; 36 | }; 37 | 38 | struct job { 39 | enum job_type type; 40 | void *job_data; 41 | struct configuration *conf; 42 | }; 43 | 44 | struct restore_job { 45 | char *database; 46 | char *table; 47 | char *filename; 48 | guint part; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /packages/tls/mydumper/server_detect.c: -------------------------------------------------------------------------------- 1 | /* 2 | This program is free software: you can redistribute it and/or modify 3 | it under the terms of the GNU General Public License as published by 4 | the Free Software Foundation, either version 3 of the License, or 5 | (at your option) any later version. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program. If not, see . 14 | 15 | Authors: Andrew Hutchings, SkySQL (andrew at skysql dot com) 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include "server_detect.h" 22 | 23 | int detect_server(MYSQL *conn) { 24 | pcre *re= NULL; 25 | const char *error; 26 | int erroroffset; 27 | int ovector[9]= {0}; 28 | int rc; 29 | const char* db_version= mysql_get_server_info(conn); 30 | 31 | re= pcre_compile(DETECT_MYSQL_REGEX, 0, &error, &erroroffset, NULL); 32 | if (!re) { 33 | g_critical("Regular expression fail: %s", error); 34 | exit(EXIT_FAILURE); 35 | } 36 | 37 | rc = pcre_exec(re, NULL, db_version, strlen(db_version), 0, 0, ovector, 9); 38 | pcre_free(re); 39 | 40 | if (rc > 0) { 41 | return SERVER_TYPE_MYSQL; 42 | } 43 | 44 | re= pcre_compile(DETECT_DRIZZLE_REGEX, 0, &error, &erroroffset, NULL); 45 | if (!re) { 46 | g_critical("Regular expression fail: %s", error); 47 | exit(EXIT_FAILURE); 48 | } 49 | 50 | rc = pcre_exec(re, NULL, db_version, strlen(db_version), 0, 0, ovector, 9); 51 | pcre_free(re); 52 | 53 | if (rc > 0) { 54 | return SERVER_TYPE_DRIZZLE; 55 | } 56 | 57 | re= pcre_compile(DETECT_MARIADB_REGEX, 0, &error, &erroroffset, NULL); 58 | if (!re) { 59 | g_critical("Regular expression fail: %s", error); 60 | exit(EXIT_FAILURE); 61 | } 62 | 63 | rc = pcre_exec(re, NULL, db_version, strlen(db_version), 0, 0, ovector, 9); 64 | pcre_free(re); 65 | 66 | if (rc > 0) { 67 | return SERVER_TYPE_MYSQL; 68 | } 69 | 70 | return SERVER_TYPE_UNKNOWN; 71 | } 72 | -------------------------------------------------------------------------------- /packages/tls/mydumper/server_detect.h: -------------------------------------------------------------------------------- 1 | /* 2 | This program is free software: you can redistribute it and/or modify 3 | it under the terms of the GNU General Public License as published by 4 | the Free Software Foundation, either version 3 of the License, or 5 | (at your option) any later version. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program. If not, see . 14 | 15 | Authors: Andrew Hutchings, SkySQL (andrew at skysql dot com) 16 | */ 17 | #ifndef _server_detect_h 18 | #define _server_detect_h 19 | 20 | #include 21 | 22 | #define DETECT_MYSQL_REGEX "^([3-9]\\.[0-9]+\\.[0-9]+)" 23 | #define DETECT_DRIZZLE_REGEX "^(20[0-9]{2}\\.(0[1-9]|1[012])\\.[0-9]+)" 24 | #define DETECT_MARIADB_REGEX "^([0-9]{1,2}\\.[0-9]+\\.[0-9]+)" 25 | 26 | enum server_type { SERVER_TYPE_UNKNOWN, SERVER_TYPE_MYSQL, SERVER_TYPE_DRIZZLE }; 27 | int detect_server(MYSQL *conn); 28 | #endif 29 | -------------------------------------------------------------------------------- /packages/tls/mysqlWrapper/Makefile: -------------------------------------------------------------------------------- 1 | SRCFILES=$(wildcard mysqllib/*.cc) 2 | OBJFILES=$(patsubst mysqllib/%.cc,obj/%.o,$(SRCFILES)) 3 | CXXFLAGS=-I/usr/include/mysql -fabi-version=2 -fno-omit-frame-pointer -std=c++11 4 | LDFLAGS=-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl 5 | CXX=g++ 6 | 7 | 8 | .PHONY: all 9 | 10 | 11 | executables:=main createSelect backFieldsToFiles analysis 12 | 13 | all: $(executables) 14 | 15 | createSelect: obj/createSelect.o $(OBJFILES) 16 | $(CXX) -o createSelect $^ $(LDFLAGS) 17 | 18 | main: obj/main.o $(OBJFILES) 19 | $(CXX) -o main $^ $(LDFLAGS) 20 | 21 | backFieldsToFiles: obj/backFieldsToFiles.o $(OBJFILES) 22 | $(CXX) -o backFieldsToFiles $^ $(LDFLAGS) 23 | 24 | analysis: obj/analysis.o $(OBJFILES) 25 | $(CXX) -o analysis $^ $(LDFLAGS) 26 | 27 | .PHONY:clean 28 | 29 | 30 | #since we only have xx.cc instead of obj/xx.cc, and we use %.cc, so we have to use obj/%.o instead of %.o here 31 | obj/%.o:%.cc 32 | @mkdir -p $(@D) 33 | $(CXX) -MMD $(CXXFLAGS) -g -c $< -o $@ 34 | 35 | 36 | obj/%.o:mysqllib/%.cc 37 | @mkdir -p $(@D) 38 | $(CXX) -MMD $(CXXFLAGS) -g -c $< -o $@ 39 | 40 | clean: 41 | -rm -rf obj $(executables) 42 | -------------------------------------------------------------------------------- /packages/tls/mysqlWrapper/analysis.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mysqllib/utilities.h" 4 | #include "mysqllib/MyConnect.h" 5 | #include 6 | #include 7 | using namespace std; 8 | extern Connect *con; 9 | 10 | void createSelect(string database,string table){ 11 | auto dbresult = con->execute(string("SELECT * FROM `")+database+"`.`"+string(table)+"` LIMIT 1;"); 12 | DBResult * result = dbresult.get(); 13 | vector> rows = result->getRows(); 14 | vector types = result->getTypes(); 15 | vector fields = result->getFields(); 16 | } 17 | 18 | int main(int argc,char**argv){ 19 | system("rm -rf allTables"); 20 | system("mkdir allTables"); 21 | if(argc!=3){ 22 | cout<<"db, table"< 3 | #include 4 | extern const std::string BOLD_BEGIN = "\033[1m"; 5 | extern const std::string RED_BEGIN = "\033[1;31m"; 6 | extern const std::string GREEN_BEGIN = "\033[1;92m"; 7 | extern const std::string COLOR_END = "\033[0m"; 8 | 9 | void current_time::get_time(){ 10 | const time_t t = time(NULL); 11 | struct tm* cur_time = localtime(&t); 12 | year = cur_time->tm_year+1900; 13 | month = cur_time->tm_mon+1; 14 | day = cur_time->tm_mday; 15 | } 16 | 17 | /* 18 | function to show the time 19 | */ 20 | void current_time::show_time(){ 21 | std::cout<<"current year is: "< 4 | 5 | //With color in cpp 6 | extern const std::string BOLD_BEGIN; 7 | extern const std::string RED_BEGIN; 8 | extern const std::string GREEN_BEGIN; 9 | extern const std::string COLOR_END; 10 | 11 | 12 | //get current time in the form year, month, day 13 | struct current_time{ 14 | int year; 15 | int month; 16 | int day; 17 | void get_time(); 18 | void show_time(); 19 | }; 20 | 21 | 22 | 23 | #endif // UTILITIES_H_INCLUDED 24 | -------------------------------------------------------------------------------- /packages/tls/shell/a: -------------------------------------------------------------------------------- 1 | customer,total_count 30000 2 | district,total_count 10 3 | history,total_count 30000 4 | item,total_count 100000 5 | new_orders,total_count 9000 6 | order_line,total_count 299810 7 | orders,total_count 30000 8 | stock,total_count 100000 9 | warehouse,total_count 1 10 | -------------------------------------------------------------------------------- /packages/tls/shell/count.sh: -------------------------------------------------------------------------------- 1 | ## specify the database name, and get the total count of all the tables in that database 2 | function mysql_command(){ 3 | cmd=\'$1\' 4 | #single quoted ${cmd} is not recognised 5 | final="mysql -uroot -pletmein -h127.0.0.1 -e ${cmd}" 6 | #eval can not be ommited here, can not just use $final only for this command 7 | res=`eval $final` 8 | echo $res 9 | } 10 | 11 | function show_table_counts(){ 12 | db=$1 13 | raw=`mysql -uroot -pletmein -h127.0.0.1 -e "use $db;show tables;"| awk '{print $1}'` 14 | arr=($raw) 15 | len=${#arr[@]} 16 | for((i=1;i<$len;i++)) 17 | do 18 | res=`mysql_command "SELECT COUNT(*) AS total_count FROM $1.${arr[$i]}"` 19 | echo ${arr[$i]},$res 20 | done 21 | } 22 | 23 | show_table_counts $1 24 | 25 | #res=`mysql_command 'show databases'` 26 | #echo $res 27 | ##only support numeric return value 28 | #echo $? 29 | -------------------------------------------------------------------------------- /packages/tls/shell/insert.sh: -------------------------------------------------------------------------------- 1 | files=`ls| grep '\.sql$'` 2 | arrayfiles=($files) 3 | #IFS=' ' read -r -a arrayfiles <<< "$files" 4 | 5 | 6 | for data in ${arrayfiles[@]} 7 | do 8 | ss="mysql -uroot -pletmein -h127.0.0.1 tpcc1000 < $data" 9 | eval $ss 10 | done 11 | 12 | -------------------------------------------------------------------------------- /packages/tls/stopgdbs: -------------------------------------------------------------------------------- 1 | ###stop gdb 2 | ps aux|grep gdb|grep -v grep|awk '{print $2}'| while read line;do sudo kill -9 $line;done 3 | -------------------------------------------------------------------------------- /packages/tls/str.sh: -------------------------------------------------------------------------------- 1 | if [ $# = 0 ];then 2 | echo "arg1: len of field, arg2 num in pipe, arg3 num of pipe" 3 | exit 4 | fi 5 | 6 | function inittable { 7 | mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "drop database if exists tpcc1000" 8 | mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "create database tpcc1000" 9 | mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "use tpcc1000; drop table if exists student" 10 | len=$[$1+0] 11 | #not supported 12 | #mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "create table if not exists tpcc1000.student(name varchar(${len}))" 13 | mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "use tpcc1000; create table if not exists student(name varchar(${len}))" 14 | echo "create table if not exists tpcc1000.student(name varchar(${len}))" 15 | } 16 | 17 | 18 | #generate load.sql 19 | 20 | head='INSERT INTO student VALUES ' 21 | 22 | cur="" 23 | 24 | function getField { 25 | num=$1 26 | for((i=0;i<$num;i++))do 27 | cur=${cur}a 28 | done 29 | cur=\'$cur\' 30 | } 31 | getField $1 32 | multi="" 33 | function getMultipleFields { 34 | num=$1 35 | multi=\($cur\) 36 | for((i=1;i<$num;i++))do 37 | multi=${multi}\,\($cur\) 38 | done 39 | } 40 | getMultipleFields $2 41 | 42 | rm -rf load.sql 43 | 44 | 45 | echo "start to get multiple inserts!!!!" 46 | 47 | for((i=0;i<$3;i++))do 48 | echo $head$multi\; >> load.sql 49 | done 50 | 51 | 52 | inittable $1 53 | mysql -uroot -pletmein -h127.0.0.1 -P3399 tpcc1000 < load.sql 54 | mysqldump --skip-extended-insert -uroot -pletmein -h127.0.0.1 --hex-blob --compact tpcc1000 > back.sql 55 | 56 | 57 | -------------------------------------------------------------------------------- /packages/tls/strnormal.sh: -------------------------------------------------------------------------------- 1 | if [ $# = 0 ];then 2 | echo "arg1: len of field, arg2 num in pipe, arg3 num of pipe" 3 | exit 4 | fi 5 | 6 | function inittable { 7 | mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tpcc1000" 8 | mysql -uroot -pletmein -h127.0.0.1 -e "create database tpcc1000" 9 | mysql -uroot -pletmein -h127.0.0.1 -e "use tpcc1000; drop table if exists student" 10 | len=$[$1+0] 11 | #not supported 12 | #mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "create table if not exists tpcc1000.student(name varchar(${len}))" 13 | mysql -uroot -pletmein -h127.0.0.1 -e "use tpcc1000; create table if not exists student(name varchar(${len}))" 14 | echo "create table if not exists tpcc1000.student(name varchar(${len}))" 15 | } 16 | 17 | 18 | #generate load.sql 19 | 20 | head='INSERT INTO student VALUES ' 21 | 22 | cur="" 23 | 24 | function getField { 25 | num=$1 26 | for((i=0;i<$num;i++))do 27 | cur=${cur}a 28 | done 29 | cur=\'$cur\' 30 | } 31 | getField $1 32 | multi="" 33 | function getMultipleFields { 34 | num=$1 35 | multi=\($cur\) 36 | for((i=1;i<$num;i++))do 37 | multi=${multi}\,\($cur\) 38 | done 39 | } 40 | getMultipleFields $2 41 | 42 | rm -rf load.sql 43 | 44 | 45 | echo "start to get multiple inserts!!!!" 46 | 47 | for((i=0;i<$3;i++))do 48 | echo $head$multi\; >> load.sql 49 | done 50 | 51 | 52 | inittable $1 53 | mysql -uroot -pletmein -h127.0.0.1 tpcc1000 < load.sql 54 | mysqldump --skip-extended-insert -uroot -pletmein -h127.0.0.1 --hex-blob --compact tpcc1000 > back.sql 55 | 56 | 57 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | RUN apt-get update && apt-get install -y gcc libc6-dev zlib1g-dev make libmysqlclient-dev 4 | 5 | ADD . /tpcc-mysql 6 | ENV PATH /tpcc-mysql:$PATH 7 | WORKDIR /tpcc-mysql 8 | RUN cd src && make 9 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/README.md: -------------------------------------------------------------------------------- 1 | 1. Build binaries 2 | * `cd src ; make` 3 | ( you should have mysql_config available in $PATH) 4 | 5 | 2. Load data 6 | * create database 7 | `mysqladmin create tpcc1000` 8 | * create tables 9 | `mysql tpcc1000 < create_table.sql` 10 | * create indexes and FK ( this step can be done after loading data) 11 | `mysql tpcc1000 < add_fkey_idx.sql` 12 | * populate data 13 | - simple step 14 | `tpcc_load -h127.0.0.1 -d tpcc1000 -u root -p "" -w 1000` 15 | |hostname:port| |dbname| |user| |password| |WAREHOUSES| 16 | ref. tpcc_load --help for all options 17 | - load data in parallel 18 | check load.sh script 19 | 20 | 3. Start benchmark 21 | * `./tpcc_start -h127.0.0.1 -P3306 -dtpcc1000 -uroot -w1000 -c32 -r10 -l10800` 22 | * |hostname| |port| |dbname| |user| |WAREHOUSES| |CONNECTIONS| |WARMUP TIME| |BENCHMARK TIME| 23 | * ref. tpcc_start --help for all options 24 | 25 | Output 26 | =================================== 27 | 28 | With the defined interval (-i option), the tool will produce the following output: 29 | ``` 30 | 10, trx: 12920, 95%: 9.483, 99%: 18.738, max_rt: 213.169, 12919|98.778, 1292|101.096, 1293|443.955, 1293|670.842 31 | 20, trx: 12666, 95%: 7.074, 99%: 15.578, max_rt: 53.733, 12668|50.420, 1267|35.846, 1266|58.292, 1267|37.421 32 | 30, trx: 13269, 95%: 6.806, 99%: 13.126, max_rt: 41.425, 13267|27.968, 1327|32.242, 1327|40.529, 1327|29.580 33 | 40, trx: 12721, 95%: 7.265, 99%: 15.223, max_rt: 60.368, 12721|42.837, 1271|34.567, 1272|64.284, 1272|22.947 34 | 50, trx: 12573, 95%: 7.185, 99%: 14.624, max_rt: 48.607, 12573|45.345, 1258|41.104, 1258|54.022, 1257|26.626 35 | ``` 36 | 37 | Where: 38 | * 10 - the seconds from the start of the benchmark 39 | * trx: 12920 - New Order transactions executed during the gived interval (in this case, for the previous 10 sec). Basically this is the throughput per interval. The more the better 40 | * 95%: 9.483: - The 95% Response time of New Order transactions per given interval. In this case it is 9.483 sec 41 | * 99%: 18.738: - The 99% Response time of New Order transactions per given interval. In this case it is 18.738 sec 42 | * max_rt: 213.169: - The Max Response time of New Order transactions per given interval. In this case it is 213.169 sec 43 | * the rest: `12919|98.778, 1292|101.096, 1293|443.955, 1293|670.842` is throughput and max response time for the other kind of transactions and can be ignored 44 | 45 | 46 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/a: -------------------------------------------------------------------------------- 1 | 123 2 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/add_fkey_idx.sql: -------------------------------------------------------------------------------- 1 | SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; 2 | SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; 3 | 4 | 5 | CREATE INDEX idx_customer ON customer (c_w_id,c_d_id,c_last,c_first); 6 | CREATE INDEX idx_orders ON orders (o_w_id,o_d_id,o_c_id,o_id); 7 | CREATE INDEX fkey_stock_2 ON stock (s_i_id); 8 | CREATE INDEX fkey_order_line_2 ON order_line (ol_supply_w_id,ol_i_id); 9 | 10 | ALTER TABLE district ADD CONSTRAINT fkey_district_1 FOREIGN KEY(d_w_id) REFERENCES warehouse(w_id); 11 | ALTER TABLE customer ADD CONSTRAINT fkey_customer_1 FOREIGN KEY(c_w_id,c_d_id) REFERENCES district(d_w_id,d_id); 12 | ALTER TABLE history ADD CONSTRAINT fkey_history_1 FOREIGN KEY(h_c_w_id,h_c_d_id,h_c_id) REFERENCES customer(c_w_id,c_d_id,c_id); 13 | ALTER TABLE history ADD CONSTRAINT fkey_history_2 FOREIGN KEY(h_w_id,h_d_id) REFERENCES district(d_w_id,d_id); 14 | ALTER TABLE new_orders ADD CONSTRAINT fkey_new_orders_1 FOREIGN KEY(no_w_id,no_d_id,no_o_id) REFERENCES orders(o_w_id,o_d_id,o_id); 15 | ALTER TABLE orders ADD CONSTRAINT fkey_orders_1 FOREIGN KEY(o_w_id,o_d_id,o_c_id) REFERENCES customer(c_w_id,c_d_id,c_id); 16 | ALTER TABLE order_line ADD CONSTRAINT fkey_order_line_1 FOREIGN KEY(ol_w_id,ol_d_id,ol_o_id) REFERENCES orders(o_w_id,o_d_id,o_id); 17 | ALTER TABLE order_line ADD CONSTRAINT fkey_order_line_2 FOREIGN KEY(ol_supply_w_id,ol_i_id) REFERENCES stock(s_w_id,s_i_id); 18 | ALTER TABLE stock ADD CONSTRAINT fkey_stock_1 FOREIGN KEY(s_w_id) REFERENCES warehouse(w_id); 19 | ALTER TABLE stock ADD CONSTRAINT fkey_stock_2 FOREIGN KEY(s_i_id) REFERENCES item(i_id); 20 | 21 | 22 | 23 | SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; 24 | SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; 25 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/count.sql: -------------------------------------------------------------------------------- 1 | select count(w_id) from warehouse; 2 | select count(d_w_id) from district; 3 | select count(c_w_id) from customer; 4 | select count(h_c_id) from history; 5 | select count(no_w_id) from new_orders; 6 | select count(o_w_id) from orders; 7 | select count(ol_w_id) from order_line; 8 | select count(i_id) from item; 9 | select count(s_w_id) from stock; 10 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/cryptbenchmark.sh: -------------------------------------------------------------------------------- 1 | echo "=============================================CREATE DATABASE=====================================================" 2 | mysql -uroot -pletmein -h127.0.0.1 -P3399 -e "create database tpcc1000" 3 | echo "=============================================CREATE TABLE=====================================================" 4 | #mysql -uroot -pletmein -h127.0.0.1 -P3399 tpcc1000 < create_table.sql 5 | echo "=============================================LOAD DATA=====================================================" 6 | mysql -uroot -pletmein -h127.0.0.1 -P3399 tpcc1000 < all$1.sql 7 | echo "=============================================DUMP DATABASE=====================================================" 8 | mysqldump --skip-extended-insert -uroot -pletmein -h127.0.0.1 --hex-blob tpcc1000 > back$1.sql 9 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/drop_cons.sql: -------------------------------------------------------------------------------- 1 | SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; 2 | SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; 3 | 4 | ALTER TABLE district DROP FOREIGN KEY fkey_district_1; 5 | ALTER TABLE customer DROP FOREIGN KEY fkey_customer_1; 6 | ALTER TABLE history DROP FOREIGN KEY fkey_history_1; 7 | ALTER TABLE history DROP FOREIGN KEY fkey_history_2; 8 | ALTER TABLE new_orders DROP FOREIGN KEY fkey_new_orders_1; 9 | ALTER TABLE orders DROP FOREIGN KEY fkey_orders_1; 10 | ALTER TABLE order_line DROP FOREIGN KEY fkey_order_line_1; 11 | ALTER TABLE order_line DROP FOREIGN KEY fkey_order_line_2; 12 | ALTER TABLE stock DROP FOREIGN KEY fkey_stock_1; 13 | ALTER TABLE stock DROP FOREIGN KEY fkey_stock_2; 14 | 15 | SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; 16 | SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; 17 | 18 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/load.sh: -------------------------------------------------------------------------------- 1 | export LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql/ 2 | DBNAME=$1 3 | WH=$2 4 | HOST=127.0.0.1 5 | STEP=100 6 | 7 | ./tpcc_load -h $HOST -d $DBNAME -u root -p "" -w $WH -l 1 -m 1 -n $WH >> 1.out & 8 | 9 | x=1 10 | 11 | while [ $x -le $WH ] 12 | do 13 | echo $x $(( $x + $STEP - 1 )) 14 | ./tpcc_load -h $HOST -d $DBNAME -u root -p "" -w $WH -l 2 -m $x -n $(( $x + $STEP - 1 )) >> 2_$x.out & 15 | ./tpcc_load -h $HOST -d $DBNAME -u root -p "" -w $WH -l 3 -m $x -n $(( $x + $STEP - 1 )) >> 3_$x.out & 16 | ./tpcc_load -h $HOST -d $DBNAME -u root -p "" -w $WH -l 4 -m $x -n $(( $x + $STEP - 1 )) >> 4_$x.out & 17 | x=$(( $x + $STEP )) 18 | done 19 | 20 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/load_multi_schema.sh: -------------------------------------------------------------------------------- 1 | export LD_LIBRARY_PATH=/data/opt/bin/mysql-5.7.11-linux-glibc2.5-x86_64/lib/ 2 | DBNAME=$1 3 | WH=$2 4 | NSCHEMA=$3 5 | HOST=127.0.0.1 6 | STEP=5 7 | 8 | schema=0 9 | 10 | while [ $schema -lt $NSCHEMA ] 11 | do 12 | DBFULLNAME=${DBNAME}_${schema} 13 | echo "Creating schema $DBFULLNAME" 14 | mysqladmin -h $HOST -f drop $DBFULLNAME 15 | mysqladmin -h $HOST create $DBFULLNAME 16 | mysql -h $HOST $DBFULLNAME < create_table.sql 17 | mysql -h $HOST $DBFULLNAME < add_fkey_idx.sql 18 | mkdir -p out 19 | 20 | ./tpcc_load -h $HOST -d $DBFULLNAME -u root -p "" -w $WH -l 1 -m 1 -n $WH >> out/1_$DBFULLNAME.out & 21 | 22 | x=1 23 | 24 | while [ $x -le $WH ] 25 | do 26 | echo $x $(( $x + $STEP - 1 )) 27 | ./tpcc_load -h $HOST -d $DBFULLNAME -u root -p "" -w $WH -l 2 -m $x -n $(( $x + $STEP - 1 )) >> out/2_$DBFULLNAME.$x.out & 28 | ./tpcc_load -h $HOST -d $DBFULLNAME -u root -p "" -w $WH -l 3 -m $x -n $(( $x + $STEP - 1 )) >> out/3_$DBFULLNAME.$x.out & 29 | ./tpcc_load -h $HOST -d $DBFULLNAME -u root -p "" -w $WH -l 4 -m $x -n $(( $x + $STEP - 1 )) >> out/4_$DBFULLNAME.$x.out & 30 | x=$(( $x + $STEP )) 31 | done 32 | 33 | for job in `jobs -p` 34 | do 35 | echo $job 36 | wait $job 37 | done 38 | 39 | schema=$(( $schema + 1 )) 40 | 41 | done 42 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/normalbenchmark.sh: -------------------------------------------------------------------------------- 1 | 2 | # load data and dump all.sql 3 | mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tpcc1000" 4 | mysql -uroot -pletmein -h127.0.0.1 -e "create database tpcc1000" 5 | mysql -uroot -pletmein -h127.0.0.1 tpcc1000 < create_table.sql 6 | 7 | ./tpcc_load -h127.0.0.1 -uroot -pletmein -d tpcc1000 -w $1 8 | # mysqldump --skip-extended-insert -uroot -pletmein -h127.0.0.1 --no-create-info --hex-blob --compact tpcc1000 > all$1.sql 9 | 10 | #mysqldump -uroot -pletmein -h127.0.0.1 --hex-blob --no-create-info --compact tpcc1000 --compact > all$1.sql 11 | 12 | #mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tpcc1000" 13 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/schema2/add_fkey_idx.sql: -------------------------------------------------------------------------------- 1 | SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; 2 | SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; 3 | 4 | 5 | ALTER TABLE district ADD CONSTRAINT fkey_district_1 FOREIGN KEY(d_w_id) REFERENCES warehouse(w_id); 6 | ALTER TABLE customer ADD CONSTRAINT fkey_customer_1 FOREIGN KEY(c_d_id, c_w_id) REFERENCES district(d_id, d_w_id); 7 | ALTER TABLE history ADD CONSTRAINT fkey_history_1 FOREIGN KEY(h_c_id, h_c_d_id, h_c_w_id) REFERENCES customer(c_id, c_d_id, c_w_id); 8 | ALTER TABLE history ADD CONSTRAINT fkey_history_2 FOREIGN KEY(h_d_id, h_w_id) REFERENCES district(d_id, d_w_id); 9 | ALTER TABLE new_orders ADD CONSTRAINT fkey_new_orders_1 FOREIGN KEY(no_o_id,no_d_id,no_w_id) REFERENCES orders(o_id, o_d_id, o_w_id); 10 | ALTER TABLE orders ADD CONSTRAINT fkey_orders_1 FOREIGN KEY(o_c_id,o_d_id,o_w_id) REFERENCES customer(c_id,c_d_id,c_w_id); 11 | ALTER TABLE order_line ADD CONSTRAINT fkey_order_line_1 FOREIGN KEY(ol_o_id,ol_d_id,ol_w_id) REFERENCES orders(o_id, o_d_id, o_w_id); 12 | ALTER TABLE order_line ADD CONSTRAINT fkey_order_line_2 FOREIGN KEY(ol_i_id,ol_supply_w_id) REFERENCES stock(s_i_id,s_w_id); 13 | ALTER TABLE stock ADD CONSTRAINT fkey_stock_1 FOREIGN KEY(s_w_id) REFERENCES warehouse(w_id); 14 | ALTER TABLE stock ADD CONSTRAINT fkey_stock_2 FOREIGN KEY(s_i_id) REFERENCES item(i_id); 15 | 16 | 17 | CREATE INDEX idx_customer ON customer (c_w_id,c_d_id,c_last,c_first); 18 | CREATE INDEX idx_orders ON orders (o_w_id,o_d_id,o_c_id,o_id); 19 | 20 | 21 | SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; 22 | SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; 23 | 24 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/schema2/count.sql: -------------------------------------------------------------------------------- 1 | select count(w_id) from warehouse; 2 | select count(d_w_id) from district; 3 | select count(c_w_id) from customer; 4 | select count(h_c_id) from history; 5 | select count(no_w_id) from new_orders; 6 | select count(o_w_id) from orders; 7 | select count(ol_w_id) from order_line; 8 | select count(i_id) from item; 9 | select count(s_w_id) from stock; 10 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/schema2/drop_cons.sql: -------------------------------------------------------------------------------- 1 | SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; 2 | SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; 3 | 4 | ALTER TABLE district DROP FOREIGN KEY fkey_district_1; 5 | ALTER TABLE customer DROP FOREIGN KEY fkey_customer_1; 6 | ALTER TABLE history DROP FOREIGN KEY fkey_history_1; 7 | ALTER TABLE history DROP FOREIGN KEY fkey_history_2; 8 | ALTER TABLE new_orders DROP FOREIGN KEY fkey_new_orders_1; 9 | ALTER TABLE orders DROP FOREIGN KEY fkey_orders_1; 10 | ALTER TABLE order_line DROP FOREIGN KEY fkey_order_line_1; 11 | ALTER TABLE order_line DROP FOREIGN KEY fkey_order_line_2; 12 | ALTER TABLE stock DROP FOREIGN KEY fkey_stock_1; 13 | ALTER TABLE stock DROP FOREIGN KEY fkey_stock_2; 14 | 15 | SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; 16 | SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; 17 | 18 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/analyze.full.sh: -------------------------------------------------------------------------------- 1 | cat $1 | grep LSN_ratio_expected | awk ' BEGIN {s=0} { print s,$4; s++ } ' > /tmp/1.rr 2 | cat $1 | grep -P "LSN_ratio[\s]" | awk ' BEGIN {s=0} { print s,$4; s++ } ' > /tmp/2.rr 3 | cat $1 | grep Innodb_log_write_sleeps | awk ' BEGIN {s=0;i=0} { print i,$4-s; s=$4;i++ } ' > /tmp/3.rr 4 | cat $1 | grep -P "Innodb_log_write_sleep_prob" | awk ' BEGIN {s=0} { print s,$4; s++ } ' > /tmp/4.rr 5 | cat $1 | grep -P "Innodb_break_ratio" | awk ' BEGIN {s=0} { print s,$4; s++ } ' > /tmp/5.rr 6 | cat $1 | grep -P "Innodb_break_value" | awk ' BEGIN {s=0} { print s,$4; s++ } ' > /tmp/6.rr 7 | cat $1 | grep -P "Innodb_tacts_to_flush_dirty" | awk ' BEGIN {s=0} { print s,$4; s++ } ' > /tmp/7.rr 8 | cat $1 | grep -P "Innodb_tacts_to_fill_target" | awk ' BEGIN {s=0} { print s,$4; s++ } ' > /tmp/8.rr 9 | cat $1 | grep -P "Innodb_EMA_lsn_grow" | awk ' BEGIN {s=0} { print s,$4; s++ } ' > /tmp/9.rr 10 | cat $1 | grep -P "Innodb_EMA_ckpt_lsn_grow" | awk ' BEGIN {s=0} { print s,$4; s++ } ' > /tmp/10.rr 11 | cat $1 | grep -P "Innodb_buffer_pool_pages_flushed[\s]" | awk ' BEGIN {s=0;i=0} { print i,$4-s; s=$4;i++ } ' > /tmp/11.rr 12 | cat $1 | grep -P "Innodb_buffer_pool_pages_flushed_neighbors[\s]" | awk ' BEGIN {s=0;i=0} { print i,$4-s; s=$4;i++ } ' > /tmp/12.rr 13 | cat $2 | awk ' BEGIN {i=0;sp=0 } /Last checkpoint at/ { st=$4 ; print i, (st)/1024/1024,(st-sp)/1024/1024; i++; sp=st } ' > /tmp/13.rr 14 | 15 | join /tmp/1.rr /tmp/2.rr > /tmp/a2.rr 16 | join /tmp/a2.rr /tmp/3.rr > /tmp/a3.rr 17 | join /tmp/a3.rr /tmp/4.rr > /tmp/a4.rr 18 | join /tmp/a4.rr /tmp/5.rr > /tmp/a5.rr 19 | join /tmp/a5.rr /tmp/6.rr > /tmp/a6.rr 20 | join /tmp/a6.rr /tmp/7.rr > /tmp/a7.rr 21 | join /tmp/a7.rr /tmp/8.rr > /tmp/a8.rr 22 | join /tmp/a8.rr /tmp/9.rr > /tmp/a9.rr 23 | join /tmp/a9.rr /tmp/10.rr > /tmp/a10.rr 24 | join /tmp/a10.rr /tmp/11.rr > /tmp/a11.rr 25 | join /tmp/a11.rr /tmp/12.rr > /tmp/a12.rr 26 | join /tmp/a12.rr /tmp/13.rr > /tmp/a13.rr 27 | echo "time LSN_ratio_expected LSN_ratio sleeps sleep_prob break_ratio break_value tacts_to_flush_dirty tacts_to_fill_target EMA_lsn EMA_ckpt_lsn flushed flushed_neighbors checkpoint checkpoint_delta" 28 | cat /tmp/a13.rr 29 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/analyze.sh: -------------------------------------------------------------------------------- 1 | TIMESLOT=1 2 | 3 | if [ -n "$2" ] 4 | then 5 | TIMESLOT=$2 6 | echo "Defined $2" 7 | fi 8 | 9 | cat $1 | grep -v HY000 | grep -v payment | grep -v neword | awk -v timeslot=$TIMESLOT ' BEGIN { FS="[,():]"; s=0; cntr=0; aggr=0 } /MEASURING START/ { s=1} /STOPPING THREADS/ {s=0} /0/ { if (s==1) { cntr++; aggr+=$2; } if ( cntr==timeslot ) { printf ("%d %3f\n",aggr,$5) ; cntr=0; aggr=0 } } ' 10 | 11 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/analyzeR.sh: -------------------------------------------------------------------------------- 1 | TIMESLOT=1 2 | 3 | if [ -n "$2" ] 4 | then 5 | TIMESLOT=$2 6 | echo "Defined $2" 7 | fi 8 | 9 | 10 | for i in 1 2 4 8 16 32 64 11 | do 12 | cat tpcc.par$i.log4G.trx2..out | grep -v HY000 | grep -v payment | grep -v neword | awk -v timeslot=$TIMESLOT -v thr=$i ' BEGIN { FS="[,():]"; s=0; cntr=0; aggr=0 } /MEASURING START/ { s=1} /STOPPING THREADS/ {s=0} /0/ { if (s==1) { cntr++; aggr+=$2; } if ( cntr==timeslot ) { printf ("%d %d %d %3f innodb\n",thr,$1,aggr,$5) ; cntr=0; aggr=0 } } ' 13 | done 14 | 15 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/analyze_checkpoint.sh: -------------------------------------------------------------------------------- 1 | cat $1 | awk ' BEGIN { } /Log sequence number/ {st=$4 } /Last checkpoint at/ { ed=$4; print (st-ed)/1024/1024 } ' 2 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/analyze_checkpoint_xtradb.sh: -------------------------------------------------------------------------------- 1 | cat $1 | awk ' BEGIN { } /Checkpoint age / {st=$3 ; print (st)/1024/1024 } ' 2 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/analyze_checkpoint_xtradb1.sh: -------------------------------------------------------------------------------- 1 | #cat $1 | awk ' BEGIN { } /Log sequence number/ {st=$4 ; print (st)/1024/1024 } ' 2 | cat $1 | awk ' BEGIN { } /Last checkpoint at/ {st=$4 ; print (st)/1024/1024 } ' 3 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/analyze_dirty.sh: -------------------------------------------------------------------------------- 1 | cat $1 | awk ' BEGIN { dt=-1;dr=-1;df=-1 } /Innodb_buffer_pool_pages_data/ { if (dt==-1) { dt=$4} else { dt+=$4 } } /Innodb_buffer_pool_pages_dirty/ { if (dr==-1) { dr=$4} else { dr+=$4 } } /Innodb_buffer_pool_pages_free/ { if (df==-1) { df=$4} else { df+=$4 } ; print (100*dr)/(1+dt+df) } ' 2 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/analyze_evicted.sh: -------------------------------------------------------------------------------- 1 | cat $1 | awk ' BEGIN { df=0 ; dl=0; } /Innodb_buffer_pool_read_ahead_evicted/ { df=$4 } /Innodb_buffer_pool_pages_LRU_flushed/ { dl=$4; print df,dl } ' 2 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/analyze_flushed.sh: -------------------------------------------------------------------------------- 1 | cat $1 | awk ' BEGIN { df=0 ; dl=0; } /Innodb_buffer_pool_pages_flushed[\s]/ { df=$4 } /Innodb_buffer_pool_pages_LRU_flushed/ { dl=$4; print df,dl } ' 2 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/analyze_flushed_innodb.sh: -------------------------------------------------------------------------------- 1 | cat $1 | awk ' BEGIN { df=0 ; dl=0; } /Innodb_buffer_pool_pages_flushed/ { df=$4 ; print df } ' 2 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/analyze_min.sh: -------------------------------------------------------------------------------- 1 | cat $1 | grep -v HY000 | grep -v payment | grep -v neword | awk ' BEGIN { FS="[,(]"; s=0; cntr=0; aggr=0 } /MEASURING START/ { s=1} /STOPPING THREADS/ {s=0} /0/ { if (s==1) { cntr++; aggr+=$2; } if ( cntr==6 ) { printf ("%d\n",aggr) ; cntr=0; aggr=0 } } ' 2 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/analyze_modified.sh: -------------------------------------------------------------------------------- 1 | cat $1 | awk ' BEGIN { } /Log sequence number/ {st=$4 } /Log flushed up to/ { ed=$5; print (st-ed) } ' 2 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/flashcache_stat.sh: -------------------------------------------------------------------------------- 1 | sysctl -w dev.flashcache.zero_stats=1 2 | 3 | while [ true ] 4 | do 5 | 6 | dmsetup status flashcache 7 | sleep 10 8 | 9 | done 10 | 11 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/innodb_stat.sh: -------------------------------------------------------------------------------- 1 | x=1 2 | end=$1 3 | 4 | while [ [ $x -le $end ] ] 5 | do 6 | 7 | mysql -e "SHOW ENGINE INNODB STATUS\G" 8 | sleep 10 9 | x=$(( $x + 10 )) 10 | 11 | done 12 | 13 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/memlock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/scripts/memlock -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/memlock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | char * 7 | alloc_workbuf(size_t size) 8 | { 9 | char *ptr; 10 | 11 | /* allocate some memory */ 12 | ptr = malloc(size); 13 | 14 | /* return NULL on failure */ 15 | if (ptr == NULL) 16 | return NULL; 17 | 18 | /* lock this buffer into RAM */ 19 | if (mlock(ptr, size)) { 20 | free(ptr); 21 | return NULL; 22 | } 23 | return ptr; 24 | } 25 | 26 | void 27 | free_workbuf(char *ptr, size_t size) 28 | { 29 | /* unlock the address range */ 30 | munlock(ptr, size); 31 | 32 | /* free the memory */ 33 | free(ptr); 34 | } 35 | 36 | int main() 37 | { 38 | 39 | char *area; 40 | size_t allocz=306535006208LLU; 41 | 42 | area=alloc_workbuf(allocz); 43 | 44 | while(1) 45 | { 46 | sleep(10); 47 | } 48 | 49 | free_workbuf(area,allocz); 50 | 51 | return 0; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -u 3 | set -x 4 | set -e 5 | 6 | export LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql/ 7 | 8 | DR="/mnt/fio320/bench" 9 | BD="/data/back/fio320/bench" 10 | 11 | WT=10 12 | RT=10800 13 | 14 | ROWS=80000000 15 | 16 | #log2="/data/log/" 17 | log2="$DR/" 18 | 19 | # restore from backup 20 | 21 | rm -fr $DR/* 22 | 23 | echo $log2 24 | #for nm in ibdata1 ib_logfile0 ib_logfile1 25 | for nm in ibdata1 26 | do 27 | rm -f $log2/$nm 28 | pagecache-management.sh cp $BD/$nm $log2 29 | done 30 | 31 | 32 | cp -r $BD/mysql $DR 33 | pagecache-management.sh cp -r $BD/tpcc $DR 34 | 35 | sync 36 | echo 3 > /proc/sys/vm/drop_caches 37 | 38 | chown mysql.mysql -R $DR 39 | chown mysql.mysql -R $log2 40 | 41 | 42 | function waitm { 43 | 44 | while [ true ] 45 | do 46 | 47 | mysql -e "set global innodb_max_dirty_pages_pct=0" mysql 48 | 49 | wt=`mysql -e "SHOW ENGINE INNODB STATUS\G" | grep "Modified db pages" | sort -u | awk '{print $4}'` 50 | if [[ "$wt" -lt 100 ]] ; 51 | then 52 | mysql -e "set global innodb_max_dirty_pages_pct=90" mysql 53 | break 54 | fi 55 | 56 | echo "mysql pages $wt" 57 | sleep 10 58 | done 59 | 60 | } 61 | 62 | #for par in 1 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 43 63 | for par in 16 64 | do 65 | 66 | /usr/local/mysql/libexec/mysqld --defaults-file=/etc/my.cnf --datadir=$DR --innodb_data_home_dir=$log2 --innodb_log_group_home_dir=$log2 --innodb_thread_concurrency=0 & 67 | set +e 68 | 69 | while true; 70 | do 71 | mysql -Bse "SELECT 1" mysql 72 | 73 | if [ "$?" -eq 0 ] 74 | then 75 | break 76 | fi 77 | 78 | sleep 30 79 | 80 | echo -n "." 81 | done 82 | set -e 83 | 84 | 85 | ./tpcc_start localhost tpcc root "" 1000 $par 10 7200 | tee -a tpcc.threads${par}.out 86 | 87 | 88 | waitm 89 | 90 | 91 | mysqladmin shutdown 92 | 93 | done 94 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/run_no_backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -u 3 | set -x 4 | set -e 5 | 6 | #export LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql/ 7 | export LD_LIBRARY_PATH=/usr/local/Percona-Server/lib/mysql/ 8 | 9 | ulimit -c unlimited 10 | 11 | #DR="/mnt/fio320" 12 | BD=/mnt/tachion/tpc1000w 13 | #DR=/data/db/bench 14 | DR="/mnt/fio320/tpc1000w" 15 | 16 | WT=10 17 | RT=10800 18 | 19 | ROWS=80000000 20 | 21 | #log2="/data/log/" 22 | log2="$DR/" 23 | 24 | # restore from backup 25 | 26 | 27 | function waitm { 28 | 29 | while [ true ] 30 | do 31 | 32 | mysql -e "set global innodb_max_dirty_pages_pct=0" mysql 33 | 34 | wt=`mysql -e "SHOW ENGINE INNODB STATUS\G" | grep "Modified db pages" | sort -u | awk '{print $4}'` 35 | if [[ "$wt" -lt 100 ]] ; 36 | then 37 | mysql -e "set global innodb_max_dirty_pages_pct=90" mysql 38 | break 39 | fi 40 | 41 | echo "mysql pages $wt" 42 | sleep 10 43 | done 44 | 45 | } 46 | 47 | 48 | 49 | # Determine run number for selecting an output directory 50 | RUN_NUMBER=-1 51 | 52 | if [ -f ".run_number" ]; then 53 | read RUN_NUMBER < .run_number 54 | fi 55 | 56 | if [ $RUN_NUMBER -eq -1 ]; then 57 | RUN_NUMBER=0 58 | fi 59 | 60 | OUTDIR=res$RUN_NUMBER 61 | mkdir -p $OUTDIR 62 | 63 | RUN_NUMBER=`expr $RUN_NUMBER + 1` 64 | echo $RUN_NUMBER > .run_number 65 | 66 | #for par in 1 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 43 67 | for par in 13 26 39 52 65 78 68 | #for par in 24 69 | do 70 | export OS_FILE_LOG_BLOCK_SIZE=4096 71 | /usr/local/mysql/libexec/mysqld --defaults-file=/etc/my.cnf --datadir=$DR --innodb_log_group_home_dir=$log2 --innodb_thread_concurrency=0 --innodb-buffer-pool-size=${par}GB & 72 | 73 | 74 | set +e 75 | 76 | while true; 77 | do 78 | mysql -Bse "SELECT 1" mysql 79 | 80 | if [ "$?" -eq 0 ] 81 | then 82 | break 83 | fi 84 | 85 | sleep 30 86 | 87 | echo -n "." 88 | done 89 | set -e 90 | 91 | 92 | 93 | 94 | iostat -dx 5 2000 >> $OUTDIR/iostat.${par}res & 95 | PID=$! 96 | vmstat 5 2000 >> $OUTDIR/vmstat.${par}res & 97 | PIDV=$! 98 | ./tpcc_start localhost tpcc1000 root "" 1000 24 10 3600 | tee -a $OUTDIR/tpcc.${par}.out 99 | kill -9 $PID 100 | kill -9 $PIDV 101 | 102 | waitm 103 | 104 | 105 | mysqladmin shutdown 106 | rm -fr /mnt/fio320/tpc1000w ; cp -r /mnt/tachion/back/tpc1000w /mnt/fio320/ 107 | sync 108 | 109 | done 110 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/scripts/virident_stat.sh: -------------------------------------------------------------------------------- 1 | echo 0 > /proc/driver/virident/vgcdrivea0/bdev 2 | 3 | while [ true ] 4 | do 5 | 6 | cat /proc/driver/virident/vgcdrivea0/bdev 7 | cat /proc/driver/virident/vgcdrivea0/gc 8 | sleep 10 9 | 10 | done 11 | 12 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # "make all" to build necessary executables. 3 | # 4 | 5 | 6 | 7 | LIBS= `mysql_config --libs_r` -lrt 8 | 9 | INC= -I. `mysql_config --include` 10 | 11 | #DEFS= -DDEBUG 12 | 13 | CFLAGS= -w -O3 -g 14 | 15 | TRANSACTIONS= neword.o payment.o ordstat.o delivery.o slev.o 16 | OBJS= main.o spt_proc.o driver.o support.o sequence.o rthist.o sb_percentile.o $(TRANSACTIONS) 17 | 18 | .SUFFIXES: 19 | .SUFFIXES: .o .c 20 | 21 | .c.o: 22 | $(CC) $(CFLAGS) $(INC) $(DEFS) -c $*.c 23 | 24 | all: ../tpcc_load ../tpcc_start 25 | 26 | ../tpcc_load : load.o support.o 27 | $(CC) load.o support.o $(LIBS) -o ../tpcc_load 28 | 29 | ../tpcc_start : $(OBJS) 30 | $(CC) $(OBJS) $(LIBS) -o ../tpcc_start 31 | 32 | clean : 33 | rm -f *.o 34 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/delivery.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/delivery.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/driver.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/driver.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/load.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/load.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/main.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/neword.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/neword.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/ordstat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/ordstat.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/parse_port.h: -------------------------------------------------------------------------------- 1 | inline void parse_host(char* host, const char* from) 2 | { 3 | const char* port= rindex(from,':'); 4 | size_t length; 5 | if(NULL == port) 6 | length= strlen(from); 7 | else 8 | length= (port - from); 9 | memcpy(host,from, length); 10 | host[length] = '\0'; 11 | } 12 | inline int parse_port(const char* from) 13 | { 14 | const char* port= rindex(from,':'); 15 | if(NULL == port) 16 | return 3306; 17 | else 18 | { 19 | const char* end= NULL; 20 | int result= strtol(port+1,&end,10); 21 | if( (0 == *end) && (0 <= result) && (result <= 0xFFFF) ) 22 | return result; 23 | else 24 | { 25 | printf(stderr,"Incorrect port value: %s\n",end); 26 | exit(-1); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/payment.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/payment.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/rthist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rthist.h 3 | */ 4 | 5 | void hist_init(); 6 | void hist_inc( int transaction, double rtclk ); 7 | double hist_ckp( int transaction ); 8 | void hist_report(); 9 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/rthist.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/rthist.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/sb_percentile.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Alexey Kopytov. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; either version 2 of the License, or 6 | (at your option) any later version. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with this program; if not, write to the Free Software 15 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | */ 17 | 18 | #ifndef SB_PERCENTILE_H 19 | #define SB_PERCENTILE_H 20 | 21 | #ifdef HAVE_PTHREAD_H 22 | # include 23 | #endif 24 | 25 | typedef struct { 26 | unsigned long long *values; 27 | unsigned long long *tmp; 28 | unsigned long long total; 29 | unsigned int size; 30 | double range_min; 31 | double range_max; 32 | double range_deduct; 33 | double range_mult; 34 | pthread_mutex_t mutex; 35 | } sb_percentile_t; 36 | 37 | int sb_percentile_init(sb_percentile_t *percentile, 38 | unsigned int size, double range_min, double range_max); 39 | 40 | void sb_percentile_update(sb_percentile_t *percentile, double value); 41 | 42 | double sb_percentile_calculate(sb_percentile_t *percentile, double percent); 43 | 44 | void sb_percentile_reset(sb_percentile_t *percentile); 45 | 46 | void sb_percentile_done(sb_percentile_t *percentile); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/sb_percentile.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/sb_percentile.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/sequence.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sequence.c 3 | * manage sequence shared by threads 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | /* weight */ 11 | static int no; 12 | static int py; 13 | static int os; 14 | static int dl; 15 | static int sl; 16 | static int total; 17 | 18 | static pthread_mutex_t mutex; 19 | static int *seq; 20 | static int next_num; 21 | 22 | static void shuffle() 23 | { 24 | int i,j,rnd,tmp; 25 | 26 | for( i=0, j=0; i < no ; i++, j++ ){ 27 | seq[j]=0; 28 | } 29 | for( i=0; i < py ; i++, j++){ 30 | seq[j]=1; 31 | } 32 | for( i=0; i < os ; i++, j++){ 33 | seq[j]=2; 34 | } 35 | for( i=0; i < dl ; i++, j++){ 36 | seq[j]=3; 37 | } 38 | for( i=0; i < sl ; i++, j++){ 39 | seq[j]=4; 40 | } 41 | for( i=0, j = total - 1; j>0; i++, j--){ 42 | rnd = rand()%(j+1); 43 | tmp = seq[rnd+i]; 44 | seq[rnd+i] = seq[i]; 45 | seq[i] = tmp; 46 | } 47 | } 48 | 49 | void seq_init( int n, int p, int o, int d, int s ) 50 | { 51 | pthread_mutex_init( &mutex, NULL ); 52 | no = n; 53 | py = p; 54 | os = o; 55 | dl = d; 56 | sl = s; 57 | total = n + p + o + d + s; 58 | seq = malloc( sizeof(int) * total ); 59 | shuffle(); 60 | next_num = 0; 61 | } 62 | 63 | 64 | int seq_get() 65 | { 66 | int retval; 67 | 68 | pthread_mutex_lock( &mutex ); 69 | 70 | if(next_num >= total){ 71 | shuffle(); 72 | next_num = 0; 73 | } 74 | 75 | retval = seq[next_num]; 76 | ++next_num; 77 | 78 | pthread_mutex_unlock( &mutex ); 79 | 80 | return(retval); 81 | } 82 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/sequence.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sequence.h 3 | */ 4 | 5 | void seq_init( int n, int p, int o, int d, int s ); 6 | int seq_get(); 7 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/sequence.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/sequence.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/slev.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/slev.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/spt_proc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * spt_proc.pc 3 | * support routines for the proc tpcc implementation 4 | */ 5 | 6 | #include 7 | 8 | #include 9 | 10 | /* 11 | * report error 12 | */ 13 | int error( 14 | MYSQL *mysql, 15 | MYSQL_STMT *mysql_stmt 16 | ) 17 | { 18 | /* 19 | if(mysql_stmt) { 20 | printf("\n%d, %s, %s", mysql_stmt_errno(mysql_stmt), 21 | mysql_stmt_sqlstate(mysql_stmt), mysql_stmt_error(mysql_stmt) ); 22 | } 23 | */ 24 | if(mysql){ 25 | fprintf(stderr, "%d, %s, %s\n", mysql_errno(mysql), mysql_sqlstate(mysql), mysql_error(mysql) ); 26 | } 27 | return (0); 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/spt_proc.h: -------------------------------------------------------------------------------- 1 | int error(MYSQL *mysql, MYSQL_STMT *mysql_stmt); 2 | 3 | #define TIMESTAMP_LEN 80 4 | #define STRFTIME_FORMAT "%Y-%m-%d %H:%M:%S" 5 | 6 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/spt_proc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/spt_proc.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/support.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/src/support.o -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/tpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tpc.h 3 | * definitions for tpcc loading program && transactions 4 | */ 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * correct values 12 | */ 13 | #define MAXITEMS 100000 14 | #define CUST_PER_DIST 3000 15 | #define DIST_PER_WARE 10 16 | #define ORD_PER_DIST 3000 17 | /* 18 | */ 19 | 20 | /* 21 | * small values 22 | 23 | #define MAXITEMS 1000 24 | #define CUST_PER_DIST 30 25 | #define DIST_PER_WARE 3 26 | #define ORD_PER_DIST 30 27 | 28 | */ 29 | 30 | /* definitions for new order transaction */ 31 | #define MAX_NUM_ITEMS 15 32 | #define MAX_ITEM_LEN 24 33 | 34 | #define swap_int(a,b) {int tmp; tmp=a; a=b; b=tmp;} 35 | 36 | /* 37 | * hack MakeAddress() into a macro so that we can pass Oracle 38 | * VARCHARs instead of char *s 39 | */ 40 | #define MakeAddressMacro(str1,str2,city,state,zip) \ 41 | {int tmp; \ 42 | tmp = MakeAlphaString(10,20,str1.arr); \ 43 | str1.len = tmp; \ 44 | tmp = MakeAlphaString(10,20,str2.arr); \ 45 | str2.len = tmp; \ 46 | tmp = MakeAlphaString(10,20,city.arr); \ 47 | city.len = tmp; \ 48 | tmp = MakeAlphaString(2,2,state.arr); \ 49 | state.len = tmp; \ 50 | tmp = MakeNumberString(9,9,zip.arr); \ 51 | zip.len = tmp;} 52 | 53 | /* 54 | * while we're at it, wrap MakeAlphaString() and MakeNumberString() 55 | * in a similar way 56 | */ 57 | #define MakeAlphaStringMacro(x,y,str) \ 58 | {int tmp; tmp = MakeAlphaString(x,y,str.arr); str.len = tmp;} 59 | #define MakeNumberStringMacro(x,y,str) \ 60 | {int tmp; tmp = MakeNumberString(x,y,str.arr); str.len = tmp;} 61 | 62 | /* 63 | * likewise, for Lastname() 64 | * counts on Lastname() producing null-terminated strings 65 | */ 66 | #define LastnameMacro(num,str) \ 67 | {Lastname(num, str.arr); str.len = strlen(str.arr);} 68 | 69 | extern long count_ware; 70 | 71 | /* Functions */ 72 | 73 | void LoadItems(); 74 | void LoadWare(); 75 | void LoadCust(); 76 | void LoadOrd(); 77 | void LoadNewOrd(); 78 | int Stock(); 79 | int District(); 80 | void Customer(); 81 | void Orders(); 82 | void New_Orders(); 83 | void MakeAddress(); 84 | void Error(); 85 | 86 | #ifdef __STDC__ 87 | void SetSeed (int seed); 88 | int RandomNumber (int min, int max); 89 | int NURand (unsigned A, unsigned x, unsigned y); 90 | int MakeAlphaString (int x, int y, char str[]); 91 | int MakeNumberString (int x, int y, char str[]); 92 | void gettimestamp (char str[], char *format, size_t n); 93 | void InitPermutation (void); 94 | int GetPermutation (void); 95 | void Lastname(int num, char* name); 96 | 97 | #endif /* __STDC__ */ 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/src/trans_if.h: -------------------------------------------------------------------------------- 1 | /* 2 | * trans_if.h 3 | * 4 | * prototypes for the transaction interface calls 5 | */ 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | int driver (int t_num); 12 | int neword (int t_num, int w_id_arg, int d_id_arg, int c_id_arg, 13 | int o_ol_cnt_arg, int o_all_local_arg, int itemid[], 14 | int supware[], int qty[]); 15 | int payment (int t_num, int w_id_arg, int d_id_arg, int byname, 16 | int c_w_id_arg, int c_d_id_arg, 17 | int c_id_arg, char c_last_arg[], float h_amount_arg); 18 | int ordstat (int t_num, int w_id, int d_id, int byname, int c_id, 19 | char c_last[]); 20 | int slev (int t_num, int w_id, int d_id, int level); 21 | int delivery (int t_num, int w_id_arg, int o_carrier_id_arg); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/tpcc_load: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/tpcc_load -------------------------------------------------------------------------------- /packages/tls/tpcc-mysql/tpcc_start: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/packages/tls/tpcc-mysql/tpcc_start -------------------------------------------------------------------------------- /parser/Makefrag: -------------------------------------------------------------------------------- 1 | OBJDIRS += parser 2 | 3 | PARSERSRC := sql_utils.cc lex_util.cc embedmysql.cc \ 4 | mysqld-filler.cc mysql_type_metadata.cc 5 | 6 | all: $(OBJDIR)/libedbparser.so 7 | 8 | EDBPARSER_OBJS := $(patsubst %.cc,$(OBJDIR)/parser/%.o,$(PARSERSRC)) 9 | 10 | $(OBJDIR)/libedbparser.so: $(EDBPARSER_OBJS) \ 11 | $(OBJDIR)/libedbutil.so \ 12 | $(OBJDIR)/libedbcrypto.so 13 | $(CXX) -shared -o $@ $(EDBPARSER_OBJS) $(LDFLAGS) $(LDRPATH) \ 14 | -ledbutil -ledbcrypto \ 15 | -Wl,--whole-archive -L$(MYBUILD)/libmysqld -lmysqld \ 16 | -Wl,--no-whole-archive -laio -lz -ldl -lrt -lcrypt 17 | # vim: set noexpandtab: 18 | -------------------------------------------------------------------------------- /parser/README: -------------------------------------------------------------------------------- 1 | 2 | note: to debug the embedded server, 3 | % cmake -DWITH_EMBEDDED_SERVER=ON -DCMAKE_BUILD_TYPE=Debug -DWITH_DEBUG=1 .. 4 | 5 | note: when changing the mysql grammar, it's necessary to re-run cmake, 6 | which runs the equivalent of lex and yacc on sql_yacc.yy. It's easiest 7 | to just "rm -r build; mkdir build; cd build; cmake ... etc". 8 | 9 | Some notes about Item processing: 10 | Item::transform, Item::compile, and Item::traverse_cond could be useful 11 | 12 | -------------------------------------------------------------------------------- /parser/embedmysql.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class query_parse { 12 | public: 13 | query_parse(const std::string &db, const std::string &q); 14 | virtual ~query_parse(); 15 | LEX *lex(); 16 | private: 17 | void cleanup(); 18 | THD *t; 19 | Parser_state ps; /*这里包含了词法分析和语法分析时候, 使用的内部状态*/ 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /parser/mysqld-filler.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | * We need to convert libmysqld.a into a shared library. 6 | * Unfortunately, it has some dangling references that 7 | * do not normally get exposed when performing static 8 | * linking (because not all parts of mysql's source code 9 | * are archived into libmysqld.a). 10 | * 11 | * Fill in these missing functions with dummy placeholders. 12 | */ 13 | 14 | void __attribute__((noreturn)) 15 | Slave_reporting_capability::report(loglevel, int, char const*, ...) const 16 | { 17 | abort(); 18 | } 19 | 20 | void __attribute__((noreturn)) 21 | Relay_log_info::slave_close_thread_tables(THD*) 22 | { 23 | abort(); 24 | } 25 | 26 | /* 27 | * This is actually Relay_log_info::Relay_log_info(bool), 28 | * but defining it as a real constructor makes the compiler 29 | * want to initialize member fields, which leads to calls 30 | * to more functions that aren't defined in libmysqld.a. 31 | * Cut our losses by just defining the mangled symbol. 32 | */ 33 | extern "C" void _ZN14Relay_log_infoC1Eb() __attribute__((noreturn)); 34 | 35 | void 36 | _ZN14Relay_log_infoC1Eb() 37 | { 38 | abort(); 39 | } 40 | -------------------------------------------------------------------------------- /parser/sql_utils.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | 10 | using namespace std; 11 | 12 | static bool lib_initialized = false; 13 | 14 | void 15 | init_mysql(const string &embed_db){ 16 | // FIXME: can still get a weird case where something calls 17 | // init_mysql(...) and lib_initialized is true so it continues on to 18 | // execute a query against the embedded database; but the thread 19 | // initializing the embedded database still hasn't completed 20 | if (!__sync_bool_compare_and_swap(&lib_initialized, false, true)) { 21 | return; 22 | } 23 | 24 | char dir_arg[1024]; 25 | snprintf(dir_arg, sizeof(dir_arg), "--datadir=%s", embed_db.c_str()); 26 | 27 | const char *mysql_av[] = 28 | { "progname", 29 | "--skip-grant-tables", 30 | dir_arg, 31 | /* "--skip-innodb", */ 32 | /* "--default-storage-engine=MEMORY", */ 33 | "--character-set-server=utf8", 34 | "--language=" MYSQL_BUILD_DIR "/sql/share/" 35 | }; 36 | 37 | assert(0 == mysql_library_init(sizeof(mysql_av)/sizeof(mysql_av[0]), 38 | (char**) mysql_av, 0)); 39 | assert(0 == mysql_thread_init()); 40 | } 41 | 42 | char * 43 | make_thd_string(const string &s, size_t *lenp){ 44 | THD *thd = current_thd; 45 | assert(thd); 46 | if (lenp) 47 | *lenp = s.size(); 48 | return thd->strmake(s.data(), s.size()); 49 | } 50 | 51 | string 52 | ItemToString(const Item &i) { 53 | if (RiboldMYSQL::is_null(i)) { 54 | return std::string("NULL"); 55 | } 56 | 57 | bool is_null; 58 | const std::string &s0 = RiboldMYSQL::val_str(i, &is_null); 59 | assert(false == is_null); 60 | 61 | return s0; 62 | } 63 | 64 | std::string 65 | printItemToString(const Item &i){ 66 | std::ostringstream o; 67 | o << i; 68 | return o.str(); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /parser/sql_utils.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | // must be called before we can use any MySQL AP 15 | void 16 | init_mysql(const std::string & embed_db); 17 | 18 | class ResType { 19 | public: 20 | const bool ok; // query executed successfully 21 | const uint64_t affected_rows; 22 | const uint64_t insert_id; 23 | const std::vector names; 24 | const std::vector types; 25 | const std::vector > rows; 26 | 27 | ResType(bool okflag, uint64_t affected_rows, uint64_t insert_id, 28 | const std::vector &&names = std::vector(), 29 | std::vector &&types = 30 | std::vector(), 31 | std::vector > &&rows = 32 | std::vector >()) 33 | : ok(okflag), affected_rows(affected_rows), 34 | insert_id(std::move(insert_id)), names(std::move(names)), 35 | types(std::move(types)), rows(rows) {} 36 | 37 | ResType(const ResType &res, const std::vector > &rows) 38 | : ok(res.ok), affected_rows(res.affected_rows), insert_id(res.insert_id), 39 | names(res.names), types(res.types), rows(rows) {} 40 | 41 | bool success() const {return this->ok;} 42 | }; 43 | 44 | char * make_thd_string(const std::string &s, size_t *lenp = 0); 45 | 46 | std::string ItemToString(const Item &i); 47 | std::string printItemToString(const Item &i); 48 | 49 | -------------------------------------------------------------------------------- /reset.sh: -------------------------------------------------------------------------------- 1 | mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tpcc1000" 2 | mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tdb" 3 | mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tdb2" 4 | mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tdb3" 5 | rm -rf ./shadow/* 6 | -------------------------------------------------------------------------------- /results: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/results -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | cur=$(pwd) 2 | export LD_LIBRARY_PATH=${cur}/obj 3 | -------------------------------------------------------------------------------- /udf/Makefrag: -------------------------------------------------------------------------------- 1 | OBJDIRS += udf 2 | 3 | all: udf 4 | 5 | udf: $(OBJDIR)/udf/edb.so 6 | 7 | $(OBJDIR)/udf/edb.so: $(OBJDIR)/udf/edb.o \ 8 | $(OBJDIR)/libedbcrypto.a \ 9 | $(OBJDIR)/libedbutil.a \ 10 | $(OBJDIR)/../udf/edb.cc 11 | $(CXX) -shared -o $@ $< $(LDFLAGS) \ 12 | $(OBJDIR)/libedbcrypto.a \ 13 | $(OBJDIR)/libedbutil.a \ 14 | -lcrypto -lntl -lgmp 15 | 16 | install: install_udf 17 | 18 | .PHONY: install_udf 19 | install_udf: $(OBJDIR)/udf/edb.so 20 | install -m 644 -g mysql -o mysql $(OBJDIR)/udf/edb.so $(MYSQL_PLUGIN_DIR) 21 | 22 | # vim: set noexpandtab: 23 | -------------------------------------------------------------------------------- /udf/create.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE remote_db.generic_prefix_currentTransactionID 2 | (OUT out_id VARCHAR(20)) 3 | BEGIN 4 | SELECT trx_id INTO out_id FROM INFORMATION_SCHEMA.INNODB_TRX 5 | WHERE INFORMATION_SCHEMA.INNODB_TRX.TRX_MYSQL_THREAD_ID = 6 | (SELECT CONNECTION_ID()) 7 | AND INFORMATION_SCHEMA.INNODB_TRX.TRX_STATE = 8 | 'RUNNING'; 9 | END 10 | 11 | CREATE PROCEDURE remote_db.generic_prefix_homAdditionTransaction 12 | (IN delete_query VARBINARY(50000), 13 | IN insert_query VARBINARY(50000)) 14 | BEGIN 15 | DECLARE old_transaction_id VARCHAR(20); 16 | 17 | CALL remote_db.generic_prefix_currentTransactionID (old_transaction_id); 18 | 19 | IF old_transaction_id IS NULL THEN 20 | START TRANSACTION; 21 | END IF; 22 | 23 | SET @query = delete_query; 24 | PREPARE dq FROM @query; 25 | EXECUTE dq; 26 | 27 | SET @query = insert_query; 28 | PREPARE iq FROM @query; 29 | EXECUTE iq; 30 | 31 | IF old_transaction_id IS NULL THEN 32 | COMMIT; 33 | 34 | END IF; 35 | END 36 | 37 | 38 | CREATE PROCEDURE remote_db.generic_prefix_adjustOnion 39 | (IN completion_id INTEGER, 40 | IN adjust_query0 VARBINARY(500), 41 | IN adjust_query1 VARBINARY(500)) 42 | BEGIN 43 | DECLARE old_transaction_id VARCHAR(20); 44 | DECLARE b_reissue BOOLEAN; 45 | 46 | CALL remote_db.generic_prefix_currentTransactionID(old_transaction_id); 47 | 48 | IF old_transaction_id IS NULL THEN 49 | SET b_reissue = TRUE; 50 | ELSE 51 | SET b_reissue = FALSE; 52 | END IF; 53 | 54 | ROLLBACK; 55 | 56 | START TRANSACTION; 57 | 58 | SET @query = adjust_query0; 59 | PREPARE aq0 FROM @query; 60 | EXECUTE aq0; 61 | 62 | SET @query = adjust_query1; 63 | PREPARE aq1 FROM @query; 64 | EXECUTE aq1; 65 | 66 | INSERT INTO remote_db.generic_prefix_remoteQueryCompletion 67 | (begin, complete, embedded_completion_id, reissue) VALUES 68 | (TRUE, TRUE, completion_id, b_reissue); 69 | 70 | COMMIT; 71 | END 72 | 73 | CREATE FUNCTION cryptdb_decrypt_int_sem RETURNS INTEGER SONAME 'edb.so'; 74 | CREATE FUNCTION cryptdb_decrypt_text_sem RETURNS STRING SONAME 'edb.so'; 75 | CREATE FUNCTION cryptdb_decrypt_int_det RETURNS INTEGER SONAME 'edb.so'; 76 | CREATE FUNCTION cryptdb_decrypt_text_det RETURNS STRING SONAME 'edb.so'; 77 | CREATE FUNCTION cryptdb_func_add_set RETURNS STRING SONAME 'edb.so'; 78 | CREATE AGGREGATE FUNCTION cryptdb_agg RETURNS STRING SONAME 'edb.so'; 79 | CREATE FUNCTION cryptdb_searchSWP RETURNS INTEGER SONAME 'edb.so'; 80 | CREATE FUNCTION cryptdb_version RETURNS STRING SONAME 'edb.so'; 81 | -------------------------------------------------------------------------------- /util/Makefrag: -------------------------------------------------------------------------------- 1 | OBJDIRS += util 2 | UTILSRC := onions.cc cryptdb_log.cc ctr.cc util.cc version.cc 3 | 4 | all: $(OBJDIR)/libedbutil.so $(OBJDIR)/libedbutil.a 5 | 6 | $(OBJDIR)/libedbutil.so: $(patsubst %.cc,$(OBJDIR)/util/%.o,$(UTILSRC)) 7 | $(CXX) -fPIC -shared -o $@ $^ $(LDFLAGS) -lntl -lcrypto -lgmp 8 | 9 | $(OBJDIR)/libedbutil.a: $(patsubst %.cc,$(OBJDIR)/util/%.o,$(UTILSRC)) 10 | $(AR) r $@ $^ 11 | 12 | #install: install_util 13 | 14 | #.PHONY: install_util 15 | #install_util: $(OBJDIR)/libedbutil.so 16 | # install -m 644 $(OBJDIR)/libedbutil.so /usr/lib 17 | 18 | $(OBJDIR)/util/version.cc: always 19 | @mkdir -p $(@D) 20 | echo "#include " > $@.tmp 21 | ( REL="$$(git describe --always --long --dirty=+dirty)" ; \ 22 | echo "const char* cryptdb_version_string = \"$$REL\";" >> $@.tmp ) 23 | cmp -s $@.tmp $@ || mv $@.tmp $@ 24 | 25 | # vim: set noexpandtab: 26 | -------------------------------------------------------------------------------- /util/cleanup.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * ANON generates a unique identifier, useful in cases when the 5 | * name of some object or class doesn't matter. 6 | */ 7 | 8 | #include "string.h" 9 | 10 | #define ANON_CONCAT2(a, b) a ## b 11 | #define ANON_CONCAT(a, b) ANON_CONCAT2(a, b) 12 | #define ANON_NAME(name) ANON_CONCAT(name, __COUNTER__) 13 | 14 | /* 15 | * Cleanup handler object: invokes the supplied function in its 16 | * destructor. 17 | */ 18 | template 19 | class cleanup_caller { 20 | public: 21 | cleanup_caller(T a) : action(a) {} 22 | ~cleanup_caller() { action(); } 23 | 24 | private: 25 | T action; 26 | }; 27 | 28 | template 29 | cleanup_caller 30 | cleanup(T a) 31 | { 32 | return cleanup_caller(a); 33 | } 34 | -------------------------------------------------------------------------------- /util/coroutine.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // coroutine.hpp 3 | // ~~~~~~~~~~~~~ 4 | // 5 | // Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 | // 7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 | // 10 | 11 | #ifndef COROUTINE_HPP 12 | #define COROUTINE_HPP 13 | 14 | class coroutine 15 | { 16 | public: 17 | coroutine() : value_(0) {} 18 | bool is_child() const { return value_ < 0; } 19 | bool is_parent() const { return !is_child(); } 20 | bool is_complete() const { return value_ == -1; } 21 | private: 22 | friend class coroutine_ref; 23 | int value_; 24 | }; 25 | 26 | class coroutine_ref 27 | { 28 | public: 29 | coroutine_ref(coroutine& c) : value_(c.value_), modified_(false) {} 30 | coroutine_ref(coroutine* c) : value_(c->value_), modified_(false) {} 31 | ~coroutine_ref() { if (!modified_) value_ = -1; } 32 | operator int() const { return value_; } 33 | int& operator=(int v) { modified_ = true; return value_ = v; } 34 | private: 35 | void operator=(const coroutine_ref&); 36 | int& value_; 37 | bool modified_; 38 | }; 39 | 40 | #define CORO_REENTER(c) \ 41 | switch (coroutine_ref _coro_value = c) \ 42 | case -1: if (_coro_value) \ 43 | { \ 44 | goto terminate_coroutine; \ 45 | terminate_coroutine: \ 46 | _coro_value = -1; \ 47 | goto bail_out_of_coroutine; \ 48 | bail_out_of_coroutine: \ 49 | break; \ 50 | } \ 51 | else case 0: 52 | 53 | #define CORO_YIELD_IMPL(n) \ 54 | for (_coro_value = (n);;) \ 55 | if (_coro_value == 0) \ 56 | { \ 57 | case (n): ; \ 58 | break; \ 59 | } \ 60 | else \ 61 | switch (_coro_value ? 0 : 1) \ 62 | for (;;) \ 63 | case -1: if (_coro_value) \ 64 | goto terminate_coroutine; \ 65 | else for (;;) \ 66 | case 1: if (_coro_value) \ 67 | goto bail_out_of_coroutine; \ 68 | else case 0: 69 | 70 | #define CORO_FORK_IMPL(n) \ 71 | for (_coro_value = -(n);; _coro_value = (n)) \ 72 | if (_coro_value == (n)) \ 73 | { \ 74 | case -(n): ; \ 75 | break; \ 76 | } \ 77 | else 78 | 79 | #if defined(_MSC_VER) 80 | # define CORO_YIELD CORO_YIELD_IMPL(__COUNTER__ + 1) 81 | # define CORO_FORK CORO_FORK_IMPL(__COUNTER__ + 1) 82 | #else // defined(_MSC_VER) 83 | # define CORO_YIELD CORO_YIELD_IMPL(__LINE__) 84 | # define CORO_FORK CORO_FORK_IMPL(__LINE__) 85 | #endif // defined(_MSC_VER) 86 | 87 | #endif // COROUTINE_HPP 88 | -------------------------------------------------------------------------------- /util/cryptdb_log.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | uint64_t cryptdb_logger::enable_mask = cryptdb_logger::mask(log_group::log_warn); 4 | 5 | -------------------------------------------------------------------------------- /util/cryptdb_log.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define LOG_GROUPS(m) \ 9 | m(warn) \ 10 | m(debug) \ 11 | m(cdb_v) \ 12 | m(crypto) \ 13 | m(crypto_v) \ 14 | m(crypto_data) \ 15 | m(edb) \ 16 | m(edb_v) \ 17 | m(edb_query) \ 18 | m(edb_query_plain) \ 19 | m(edb_perf) \ 20 | m(encl) \ 21 | m(test) \ 22 | m(am) \ 23 | m(am_v) \ 24 | m(mp) \ 25 | m(wrapper) \ 26 | m(all) 27 | 28 | enum class log_group { 29 | #define __temp_m(n) log_ ## n, 30 | LOG_GROUPS(__temp_m) 31 | #undef __temp_m 32 | }; 33 | 34 | static 35 | std::map log_name_to_group = { 36 | #define __temp_m(n) { #n, log_group::log_ ## n }, 37 | LOG_GROUPS(__temp_m) 38 | #undef __temp_m 39 | }; 40 | 41 | class cryptdb_logger : public std::stringstream { 42 | public: 43 | cryptdb_logger(log_group g, const char *filearg, uint linearg, const char *fnarg) 44 | : m(mask(g)), file(filearg), line(linearg), func(fnarg) 45 | { 46 | } 47 | 48 | ~cryptdb_logger() 49 | { 50 | if (enable_mask & m) 51 | std::cerr << file << ":" << line 52 | << " (" << func << "): " 53 | << str() << std::endl; 54 | } 55 | 56 | static void 57 | enable(log_group g) 58 | { 59 | if (g == log_group::log_all) 60 | enable_mask = ~0ULL; 61 | else 62 | enable_mask |= mask(g); 63 | } 64 | 65 | static void 66 | disable(log_group g) 67 | { 68 | if (g == log_group::log_all) 69 | enable_mask = 0; 70 | else 71 | enable_mask &= ~mask(g); 72 | } 73 | 74 | static bool 75 | enabled(log_group g) 76 | { 77 | return enable_mask & mask(g); 78 | } 79 | 80 | static uint64_t 81 | mask(log_group g) 82 | { 83 | return 1ULL << ((int) g); 84 | } 85 | 86 | static std::string 87 | getConf() 88 | { 89 | std::stringstream ss; 90 | ss << enable_mask; 91 | return ss.str(); 92 | } 93 | 94 | static void 95 | setConf(std::string conf) 96 | { 97 | std::stringstream ss(conf); 98 | ss >> enable_mask; 99 | } 100 | 101 | private: 102 | uint64_t m; 103 | const char *file; 104 | uint line; 105 | const char *func; 106 | 107 | static uint64_t enable_mask; 108 | 109 | }; 110 | 111 | #define LOG(g) \ 112 | (cryptdb_logger(log_group::log_ ## g, __FILE__, __LINE__, __func__)) 113 | 114 | -------------------------------------------------------------------------------- /util/ctr.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static tsc_ctr tsc; 4 | decltype(perf_cg) perf_cg = ctrgroup(&tsc); 5 | 6 | -------------------------------------------------------------------------------- /util/ctr.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | extern ctrgroup_chain perf_cg; 6 | 7 | -------------------------------------------------------------------------------- /util/errstream.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | class CryptDBError { 9 | public: 10 | CryptDBError(const std::string &m) : msg(m) {} 11 | std::string msg; 12 | }; 13 | 14 | class CryptoError : public CryptDBError { 15 | public: 16 | CryptoError(const std::string &m) : CryptDBError(m) {} 17 | }; 18 | 19 | inline void 20 | throw_c(bool test, const std::string &msg = "crypto fail") 21 | { 22 | if (false == test) { 23 | throw CryptoError(msg); 24 | } 25 | 26 | return; 27 | } 28 | 29 | class err_stream { 30 | public: 31 | virtual ~err_stream() noexcept(false) {} 32 | 33 | template 34 | std::ostream &operator<<(T &s) { 35 | stream << s; 36 | return stream; 37 | } 38 | 39 | protected: 40 | std::stringstream stream; 41 | }; 42 | 43 | 44 | class fatal : public err_stream { 45 | public: 46 | ~fatal() noexcept(false) __attribute__((noreturn)) { 47 | std::cerr << stream.str() << std::endl; 48 | exit(-1); 49 | } 50 | }; 51 | 52 | class thrower : public err_stream { 53 | public: 54 | ~thrower() noexcept(false) __attribute__((noreturn)) { 55 | throw CryptDBError(stream.str()); 56 | } 57 | }; 58 | 59 | -------------------------------------------------------------------------------- /util/hello.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void help(){ 4 | printf("help\n"); 5 | } 6 | 7 | -------------------------------------------------------------------------------- /util/onions.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiwenshao/Practical-Cryptdb/f61f3307546142a2b5c0cfc102719ce0980a174a/util/onions.cc -------------------------------------------------------------------------------- /util/onions.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | typedef enum onion { 11 | oDET, 12 | oOPE, 13 | oAGG, 14 | oSWP, 15 | oPLAIN, 16 | oBESTEFFORT, 17 | oINVALID, 18 | } onion; 19 | 20 | //Sec levels ordered such that 21 | // if a is less secure than b. 22 | // a appears before b 23 | // (note, this is not "iff") 24 | 25 | enum class SECLEVEL { 26 | INVALID, 27 | PLAINVAL, 28 | OPEFOREIGN, 29 | OPE, 30 | DETJOIN, 31 | DET, 32 | SEARCH, 33 | HOM, 34 | RND, 35 | }; 36 | 37 | //Onion layouts - initial structure of onions 38 | typedef std::map > onionlayout; 39 | 40 | static onionlayout PLAIN_ONION_LAYOUT = { 41 | {oPLAIN, std::vector({SECLEVEL::PLAINVAL})} 42 | }; 43 | 44 | static onionlayout NUM_ONION_LAYOUT = { 45 | {oDET, std::vector({SECLEVEL::DETJOIN, SECLEVEL::DET, 46 | SECLEVEL::RND})}, 47 | {oOPE, std::vector({SECLEVEL::OPEFOREIGN,SECLEVEL::OPE, SECLEVEL::RND})}, 48 | {oAGG, std::vector({SECLEVEL::HOM})} 49 | }; 50 | 51 | static onionlayout BEST_EFFORT_NUM_ONION_LAYOUT = { 52 | {oDET, std::vector({SECLEVEL::DETJOIN, SECLEVEL::DET, 53 | SECLEVEL::RND})}, 54 | {oOPE, std::vector({SECLEVEL::OPEFOREIGN,SECLEVEL::OPE, SECLEVEL::RND})}, 55 | {oAGG, std::vector({SECLEVEL::HOM})}, 56 | // Requires SECLEVEL::DET, otherwise you will have to implement 57 | // encoding for negative numbers in SECLEVEL::RND. 58 | {oPLAIN, std::vector({SECLEVEL::PLAINVAL, SECLEVEL::DET, 59 | SECLEVEL::RND})} 60 | }; 61 | 62 | static onionlayout STR_ONION_LAYOUT = { 63 | {oDET, std::vector({SECLEVEL::DETJOIN, SECLEVEL::DET, 64 | SECLEVEL::RND})}, 65 | {oOPE, std::vector({SECLEVEL::OPEFOREIGN,SECLEVEL::OPE, SECLEVEL::RND})}, 66 | // {oSWP, std::vector({SECLEVEL::SEARCH})} 67 | // {oSWP, std::vector({SECLEVEL::PLAINVAL, SECLEVEL::DET, 68 | // SECLEVEL::RND})} 69 | }; 70 | 71 | static onionlayout BEST_EFFORT_STR_ONION_LAYOUT = { 72 | {oDET, std::vector({SECLEVEL::DETJOIN, SECLEVEL::DET, 73 | SECLEVEL::RND})}, 74 | {oOPE, std::vector({SECLEVEL::OPEFOREIGN,SECLEVEL::OPE, SECLEVEL::RND})}, 75 | // {oSWP, std::vector({SECLEVEL::SEARCH})}, 76 | // {oSWP, std::vector({SECLEVEL::PLAINVAL, SECLEVEL::DET, 77 | // SECLEVEL::RND})}, 78 | // HACK: RND_str expects the data to be a multiple of 16, so we use 79 | // DET (it supports decryption UDF) to handle the padding for us. 80 | {oPLAIN, std::vector({SECLEVEL::PLAINVAL, SECLEVEL::DET, 81 | SECLEVEL::RND})} 82 | }; 83 | 84 | //这个会用到么? 85 | typedef std::map OnionLevelMap; 86 | 87 | enum class SECURITY_RATING {PLAIN, BEST_EFFORT, SENSITIVE}; 88 | -------------------------------------------------------------------------------- /util/params.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * config.h 5 | * 6 | * Configuration parameters. 7 | * 8 | */ 9 | 10 | // if this bit is set, we are working with MySQL, else we are working with 11 | // Postgres 12 | #define MYSQL_S 1 13 | 14 | /************* EVAL/DEBUGGING FLAGS ************/ 15 | 16 | //Flags for evaluation of different scenarios: 17 | #define PARSING 0 18 | //strawman where values are decrypted on the fly before being used 19 | #define DECRYPTFIRST 0 20 | 21 | #define ASSERTS_ON true 22 | 23 | 24 | /******* VERBOSITY ****************/ 25 | 26 | //flag for debugging, particularly verbose 27 | const bool VERBOSE_G = false; 28 | 29 | const bool VERBOSE_KEYACCESS = true; 30 | const bool VERBOSE_EDBProxy = true; 31 | const bool VERBOSE_EDBProxy_VERY = true; 32 | -------------------------------------------------------------------------------- /util/rob.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | * The rob template below is sufficient to trick gcc to access private 5 | * or protected members, bypassing the expected access checking rules. 6 | * However, the code below isn't strictly allowed by the C++ spec; 7 | * e.g., clang rejects it. 8 | * 9 | * It is possible to access private or protected members in a way that 10 | * is well-specified and legal, by exploiting the following rule from 11 | * C++ specification section 14.7.2, "Explicit instantiation": 12 | * 13 | * http://www.lcdf.org/c++/clause14.html#s14.7.2 14 | * 15 | * The usual access checking rules do not apply to names used to 16 | * specify explicit instantiations. 17 | * 18 | * A standard-compliant (and more complex) version of the rob template, 19 | * which exploits the above rule, is available here: 20 | * 21 | * http://bloglitb.blogspot.com/2010/07/access-to-private-members-thats-easy.html 22 | */ 23 | 24 | template 25 | struct rob { 26 | static FieldType Victim::*ptr() { return p; } 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /util/scoped_lock.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class scoped_lock { 6 | public: 7 | scoped_lock(pthread_mutex_t *muarg) : mu(muarg) { 8 | pthread_mutex_lock(mu); 9 | } 10 | 11 | ~scoped_lock() { 12 | pthread_mutex_unlock(mu); 13 | } 14 | 15 | private: 16 | pthread_mutex_t *mu; 17 | }; 18 | -------------------------------------------------------------------------------- /util/timer.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class timer { 6 | private: 7 | timer(const timer &t); /* no reason to copy timer objects */ 8 | 9 | public: 10 | timer() { lap(); } 11 | 12 | uint64_t lap() { /* returns microseconds */ 13 | uint64_t t0 = start; 14 | uint64_t t1 = cur_usec(); 15 | start = t1; 16 | return t1 - t0; 17 | } 18 | 19 | private: 20 | static uint64_t cur_usec() { 21 | struct timeval tv; 22 | gettimeofday(&tv, 0); 23 | return ((uint64_t)tv.tv_sec) * 1000000 + tv.tv_usec; 24 | } 25 | 26 | uint64_t start; 27 | }; 28 | -------------------------------------------------------------------------------- /util/unyield.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // unyield.hpp 3 | // ~~~~~~~~~~~ 4 | // 5 | // Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 | // 7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 | // 10 | 11 | #ifdef reenter 12 | # undef reenter 13 | #endif 14 | 15 | #ifdef yield 16 | # undef yield 17 | #endif 18 | 19 | #ifdef fork 20 | # undef fork 21 | #endif 22 | -------------------------------------------------------------------------------- /util/version.hh: -------------------------------------------------------------------------------- 1 | extern const char* cryptdb_version_string; 2 | -------------------------------------------------------------------------------- /util/yield.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // yield.hpp 3 | // ~~~~~~~~~ 4 | // 5 | // Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 | // 7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 | // 10 | 11 | #include "coroutine.hpp" 12 | 13 | #ifndef reenter 14 | # define reenter(c) CORO_REENTER(c) 15 | #endif 16 | 17 | #ifndef yield 18 | # define yield CORO_YIELD 19 | #endif 20 | 21 | #ifndef fork 22 | # define fork CORO_FORK 23 | #endif 24 | -------------------------------------------------------------------------------- /util/zz.hh: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | inline std::string 6 | StringFromZZ(const NTL::ZZ &x) 7 | { 8 | std::string s; 9 | s.resize(NumBytes(x), 0); 10 | NTL::BytesFromZZ((uint8_t*) &s[0], x, s.length()); 11 | return s; 12 | } 13 | 14 | // returns ZZ from a string representing the ZZ in base 256 15 | inline NTL::ZZ 16 | ZZFromString(const std::string &s) 17 | { 18 | return NTL::ZZFromBytes((const uint8_t *) s.data(), s.length()); 19 | } 20 | 21 | 22 | // converts ZZ to and from a string representing the number in decimal 23 | 24 | inline std::string 25 | DecStringFromZZ(const NTL::ZZ & x) { 26 | std::stringstream ss; 27 | ss << x; 28 | return ss.str(); 29 | } 30 | 31 | inline NTL::ZZ 32 | ZZFromDecString(const std::string &s) { 33 | NTL::ZZ v; 34 | std::stringstream ss(s); 35 | ss >> v; 36 | return v; 37 | } 38 | -------------------------------------------------------------------------------- /verify.sh: -------------------------------------------------------------------------------- 1 | mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tpcc1000" 2 | mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tdb" 3 | mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tdb2" 4 | mysql -uroot -pletmein -h127.0.0.1 -e "drop database if exists tdb3" 5 | rm -rf ./shadow/* 6 | 7 | ##running this twice will caurse troubles because of the metadata mismatch 8 | ./obj/main/change_test 9 | --------------------------------------------------------------------------------