@@ -37,7 +37,8 @@ namespace electionguard
3737 // / <Summary>
3838 // / Make an elgamal keypair from a secret.
3939 // / </Summary>
40- static std::unique_ptr<ElGamalKeyPair> fromSecret (const ElementModQ &secretKey, bool isFixedBase = true );
40+ static std::unique_ptr<ElGamalKeyPair> fromSecret (const ElementModQ &secretKey,
41+ bool isFixedBase = true );
4142
4243 private:
4344 class Impl ;
@@ -131,23 +132,18 @@ namespace electionguard
131132 // / <returns>A ciphertext tuple.</returns>
132133 // / </summary>
133134 EG_API std::unique_ptr<ElGamalCiphertext>
134- elgamalEncrypt_with_precomputed (uint64_t m, ElementModP &gToRho ,
135- ElementModP &pubkeyToRho);
135+ elgamalEncrypt_with_precomputed (uint64_t m, ElementModP &gToRho , ElementModP &pubkeyToRho);
136136 // / <summary>
137137 // / Accumulate the ciphertexts by adding them together.
138138 // / </summary>
139139 EG_API std::unique_ptr<ElGamalCiphertext>
140140 elgamalAdd (const std::vector<std::reference_wrapper<ElGamalCiphertext>> &ciphertexts);
141141
142- #define HASHED_CIPHERTEXT_BLOCK_LENGTH 32U
143- #define _PAD_INDICATOR_SIZE sizeof (uint16_t )
142+ #define HASHED_CIPHERTEXT_BLOCK_LENGTH 32U
143+ #define _PAD_INDICATOR_SIZE sizeof (uint16_t )
144144
145145 typedef enum padded_data_size_e {
146146 NO_PADDING = 0 ,
147- BYTES_32 = 32 - _PAD_INDICATOR_SIZE,
148- BYTES_64 = 64 - _PAD_INDICATOR_SIZE,
149- BYTES_128 = 128 - _PAD_INDICATOR_SIZE,
150- BYTES_256 = 256 - _PAD_INDICATOR_SIZE,
151147 BYTES_512 = 512 - _PAD_INDICATOR_SIZE
152148 } padded_data_size_t ;
153149
@@ -159,7 +155,7 @@ namespace electionguard
159155 // / result. Create one with `hashedElgamalEncrypt`. Decrypt using one the
160156 // / 'decrypt' method.
161157 // / </summary>
162- class EG_API HashedElGamalCiphertext
158+ class EG_API HashedElGamalCiphertext : public CryptoHashable
163159 {
164160 public:
165161 HashedElGamalCiphertext (const HashedElGamalCiphertext &other);
@@ -207,14 +203,17 @@ namespace electionguard
207203 // / </Summary>
208204 std::vector<uint8_t > getMac () const ;
209205
206+ virtual std::unique_ptr<ElementModQ> crypto_hash () override ;
207+ virtual std::unique_ptr<ElementModQ> crypto_hash () const override ;
208+
210209 // / <summary>
211210 // / Decrypts ciphertext with the Auxiliary Encryption method (as specified in the
212211 // / ElectionGuard specification) given a random nonce, an ElGamal public key,
213212 // / and a description hash. The encrypt may be called to look for padding to
214213 // / verify and remove, in this case the plaintext will be smaller than
215214 // / the ciphertext, or not to look for padding in which case the
216- // / plaintext will be the same size as the ciphertext.
217- // /
215+ // / plaintext will be the same size as the ciphertext.
216+ // /
218217 // / <param name="nonce"> Randomly chosen nonce in [1,Q). </param>
219218 // / <param name="publicKey"> ElGamal public key. </param>
220219 // / <param name="descriptionHash"> Hash of the ballot description. </param>
@@ -232,7 +231,7 @@ namespace electionguard
232231 private:
233232 class Impl ;
234233#pragma warning(suppress : 4251)
235- std::unique_ptr<Impl> pimpl;
234+ std::unique_ptr<Impl> pimpl;
236235 };
237236
238237 // / <summary>
@@ -244,24 +243,32 @@ namespace electionguard
244243 // / This value indicates the maximum length of the plaintext that may be
245244 // / encrypted. The padding scheme applies two bytes for length of padding
246245 // / plus padding bytes. If padding is not to be applied then the
247- // / max_len parameter must be NO_PADDING and the plaintext must
246+ // / max_len parameter must be NO_PADDING. and the plaintext must
248247 // / be a multiple of the block length (32) and the ciphertext will be
249- // / the same size.
248+ // / the same size. If the max_len is set to something other than
249+ // / NO_PADDING and the allow_truncation parameter is set to
250+ // / true then if the message parameter data is longer than
251+ // / max_len then it will be truncated to max_len. If the max_len is set to
252+ // / something other than NO_PADDING and the allow_truncation parameter
253+ // / is set to false then if the message parameter data is longer than
254+ // / max_len then an exception will be thrown.
250255 // /
251- // / <param name="plaintext "> Message to hashed elgamal encrypt. </param>
256+ // / <param name="message "> Message to hashed elgamal encrypt. </param>
252257 // / <param name="nonce"> Randomly chosen nonce in [1,Q). </param>
253258 // / <param name="publicKey"> ElGamal public key. </param>
254259 // / <param name="descriptionHash"> Hash of the ballot description. </param>
255260 // / <param name="max_len"> If padding is to be applied then this indicates the
256261 // / maximum length of plaintext, must be one padded_data_size_t enumeration
257262 // / values. If padding is not to be applied then this parameter must use
258263 // / the NO_PADDING padded_data_size_t enumeration value.</param>
264+ // / <param name="allow_truncation"> Truncates data to the max_len if set to
265+ // / true. If max_len is set to NO_PADDING then this parameter is ignored. </param>
259266 // / <returns>A ciphertext triple.</returns>
260267 // / </summary>
261268 EG_API std::unique_ptr<HashedElGamalCiphertext>
262269 hashedElgamalEncrypt (std::vector<uint8_t > plaintext, const ElementModQ &nonce,
263270 const ElementModP &publicKey, const ElementModQ &descriptionHash,
264- padded_data_size_t max_len);
271+ padded_data_size_t max_len, bool allow_truncation );
265272
266273} // namespace electionguard
267274
0 commit comments