SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
el_gamal_ciphertext.cpp
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 */
30 #include "el_gamal_ciphertext.h"
31 
32 namespace SeComLib {
33 namespace Core {
38  }
39 
44  ElGamalCiphertext::Data::Data (const BigInteger &x, const BigInteger &y) : x(x), y(y) {
45  }
46 
51  }
52 
57  ElGamalCiphertext::ElGamalCiphertext (const std::shared_ptr<BigInteger> &encryptionModulus) : encryptionModulus(encryptionModulus) {
58  }
59 
66  ElGamalCiphertext::ElGamalCiphertext (const BigInteger &x, const BigInteger &y, const std::shared_ptr<BigInteger> &encryptionModulus) : data(Data(x, y)), encryptionModulus(encryptionModulus) {
67  }
68 
74  if (!this->encryptionModulus) {
75  throw std::runtime_error("This operation requires the encryption modulus.");
76  }
77 
78  ElGamalCiphertext output(this->data.x.GetInverseModN(*this->encryptionModulus), this->data.y.GetInverseModN(*this->encryptionModulus), this->encryptionModulus);
79 
80  return output;
81  }
82 
89  if (!this->encryptionModulus) {
90  throw std::runtime_error("This operation requires the encryption modulus.");
91  }
92 
93  ElGamalCiphertext output((this->data.x * input.data.x) % (*this->encryptionModulus), (this->data.y * input.data.y) % (*this->encryptionModulus), this->encryptionModulus);
94 
95  return output;
96  }
97 
104  if (!this->encryptionModulus) {
105  throw std::runtime_error("This operation requires the encryption modulus.");
106  }
107 
108  ElGamalCiphertext output((this->data.x * input.data.x.GetInverseModN(*this->encryptionModulus)) % (*this->encryptionModulus), (this->data.y * input.data.y.GetInverseModN(*this->encryptionModulus)) % (*this->encryptionModulus), this->encryptionModulus);
109 
110  return output;
111  }
112 }//namespace Core
113 }//namespace SeComLib
Data data
Cipertext container.
ElGamalCiphertext()
Default constructor.
ElGamalCiphertext operator+(const ElGamalCiphertext &input) const
Homomorphic addition binary operator.
ElGamalCiphertext operator-() const
Homomorphic negation unary operator.
std::shared_ptr< BigInteger > encryptionModulus
The encryption modulus.
Definition of class ElGamalCiphertext.
ElGamal cipertext container structure.