SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
data_packer.h
Go to the documentation of this file.
1 /*
2 SeComLib
3 Copyright 2012-2013 TU Delft, Information Security & Privacy Lab (http://isplab.tudelft.nl/)
4 
5 Contributors:
6 Inald Lagendijk (R.L.Lagendijk@TUDelft.nl)
7 Mihai Todor (todormihai@gmail.com)
8 Thijs Veugen (P.J.M.Veugen@tudelft.nl)
9 Zekeriya Erkin (z.erkin@tudelft.nl)
10 
11 Licensed under the Apache License, Version 2.0 (the "License");
12 you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at
14 
15 http://www.apache.org/licenses/LICENSE-2.0
16 
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22 */
29 #ifndef DATA_PACKER_HEADER_GUARD
30 #define DATA_PACKER_HEADER_GUARD
31 
32 #include "utils/config.h"
33 
34 //include C++ headers
35 #include <deque>
36 #include <stdexcept>
37 
38 namespace SeComLib {
39 namespace Core {
45  template <typename T_CryptoProvider>
46  class DataPacker {
47  public:
48 
52  struct DataBucket {
53  public:
55  BigInteger frontPadding;
56 
58  BigInteger data;
59 
61  BigInteger backPadding;
62  };
63 
65  typedef std::deque<typename DataPacker<T_CryptoProvider>::DataBucket> UnpackedData;
66 
68  typedef std::deque<typename T_CryptoProvider::Ciphertext> PackedData;
69 
71  DataPacker (const T_CryptoProvider &cryptoProvider, const size_t dataSize, const size_t frontPaddingSize = 0, const size_t backPaddingSize = 0);
72 
75 
77  PackedData Pack (const UnpackedData &input) const;
78 
80  UnpackedData Unpack (const PackedData &input, const size_t totalBucketCount) const;
81 
83  PackedData HomomorphicAdd (const PackedData &lhs, const PackedData &rhs);
84 
86  PackedData HomomorphicMultiply (const PackedData &lhs, const BigInteger &rhs);
87 
88  private:
90  const T_CryptoProvider &cryptoProvider;
91 
94 
97 
99  size_t dataSize;
100 
102  BigInteger dataMessageSpace;
103 
106 
109 
111  size_t bucketSize;
112 
115 
117  void initialize ();
118 
120  DataPacker (DataPacker const &);
121 
124  };
125 }//namespace Core
126 }//namespace SeComLib
127 
128 //Separate the implementation from the declaration of template methods
129 #include "data_packer.hpp"
130 
131 #endif//DATA_PACKER_HEADER_GUARD
BigInteger backPadding
The back padding ( )
Definition: data_packer.h:61
Container for data buckets.
Definition: data_packer.h:52
PackedData Pack(const UnpackedData &input) const
Pack data.
Definition: data_packer.hpp:59
const T_CryptoProvider & cryptoProvider
Reference to the Crypto Provider.
Definition: data_packer.h:90
BigInteger data
The data ( )
Definition: data_packer.h:58
size_t bucketSize
The size (in bits) of each bucket (computed in the constructor)
Definition: data_packer.h:111
Definition of class Config.
BigInteger backPaddingMessageSpace
The maximum value that can be stored in DataBucket.backPadding.
Definition: data_packer.h:108
UnpackedData Unpack(const PackedData &input, const size_t totalBucketCount) const
Unpack data.
size_t bucketsPerEncryption
The maximum number of buckets that can pe packet in a single encryption.
Definition: data_packer.h:114
std::deque< typename DataPacker< T_CryptoProvider >::DataBucket > UnpackedData
Define a vector template specialization for vectors of unpacked data.
Definition: data_packer.h:65
void initialize()
Initialize class members.
BigInteger frontPaddingMessageSpace
The maximum value that can be stored in DataBucket.frontPadding.
Definition: data_packer.h:96
Template class which implements the data packing functionality.
Definition: data_packer.h:46
BigInteger dataMessageSpace
The maximum value that can be stored in DataBucket.data.
Definition: data_packer.h:102
BigInteger frontPadding
The front padding ( )
Definition: data_packer.h:55
DataPacker(const T_CryptoProvider &cryptoProvider, const size_t dataSize, const size_t frontPaddingSize=0, const size_t backPaddingSize=0)
Constructor with custom data sizes.
Definition: data_packer.hpp:44
size_t backPaddingSize
The size (in bits) of the back padding (defaults to 0)
Definition: data_packer.h:105
size_t dataSize
The size (in bits) of the data.
Definition: data_packer.h:99
Implementation of template class DataPacker. To be included in data_packer.h.
DataPacker operator=(DataPacker const &)
Copy assignment operator - not implemented.
PackedData HomomorphicAdd(const PackedData &lhs, const PackedData &rhs)
Add two vectors of packed data.
std::deque< typename T_CryptoProvider::Ciphertext > PackedData
Define a vector template specialization for vectors of packed data.
Definition: data_packer.h:68
size_t frontPaddingSize
The size (in bits) of the front padding (defaults to 0)
Definition: data_packer.h:93
PackedData HomomorphicMultiply(const PackedData &lhs, const BigInteger &rhs)
Multiply a vector of packed data with a constant plaintext term.
~DataPacker()
Destructor.
Definition: data_packer.h:74