This is an implementation of the private database query system described in
"Private Database Queries Using Somewhat Homomorphic Encryption," by D. Boneh,
C. Gentry, S. Halevi, F. Wang, and D. Wu in ACNS 2013. This implementation
leverages Brakerski's somewhat homomorphic encryption system. We use our
implementation of this system, available here: https://github.com/dwu4/fhe-si.

Please contact me if you have any questions:
  Email: dwu4@cs.stanford.edu
  Website: http://cs.stanford.edu/~dwu4/

To compile and run a simple demo on toy data, use the provided script
  ./runDemo.sh
  
To run tests using the FHE system, run tests/TestProxy:
  ./tests/TestProxy datafile queryfile [mod_reduction] [outputfile] [output]
The parameters are explained below:
 - datafile is the database file (can be generated using the included 
   python script, scripts/generateData.py, described below 
 - queryfile is the list of queries to perform on the encrypted database 
   (first line consists of the number of queries, each subsequent line 
   contains a query (consists of the number of records in the query (n), 
   followed by n tag ids) 
 - OPTIONAL: mod_reduction [default: 0] specifies whether to use the 
   modular reduction optimization (0: no modular reduction, 1: modular 
   reduction and key switching, 2: modular reduction without key switching) 
 - OPTIONAL: outputfile [default: ""] specifies a location to write the 
   computation result to disk (used to measure bandwidth) 
 - OPTIONAL: output [default: true] is a boolean flag specifying whether 
   information should be written to standard out 

To run tests using the Paillier system, run tests/TestPaillier:
  ./tests/TestPaillier datafile queryfile [outputfile]
Parameters are as in the FHE system above.

There are two included python scripts that are useful for creating toy 
databases and verifying results. 

To generate a database, run
  python scripts/generateData.py filename num_records num_tags 
                                 min_records max_records max_inter 

The parameters are as follows:
  filename: output file for the database
  num_records: total number of records in database
  num_tags: number of tags to generate
  min_records: minimum number of records in each tag
  max_records: maximum number of records in each tag
  max_inter: maximum number of records in the intersection of all records

To run a query against a database (useful for checking correctness), run
  python scripts/queryDatabase.py datafile
Specify the database file as the datafile parameter. Then enter queries 
over standard in (tag ids delimited by spaces).
