@@ -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,19 @@ 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 HASHED_BLOCK_LENGTH_IN_BITS 256U
144+ #define _PAD_INDICATOR_SIZE sizeof (uint16_t )
144145
145146 typedef enum padded_data_size_e {
146147 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,
151148 BYTES_512 = 512 - _PAD_INDICATOR_SIZE
152149 } padded_data_size_t ;
153150
@@ -159,7 +156,7 @@ namespace electionguard
159156 // / result. Create one with `hashedElgamalEncrypt`. Decrypt using one the
160157 // / 'decrypt' method.
161158 // / </summary>
162- class EG_API HashedElGamalCiphertext
159+ class EG_API HashedElGamalCiphertext : public CryptoHashable
163160 {
164161 public:
165162 HashedElGamalCiphertext (const HashedElGamalCiphertext &other);
@@ -207,14 +204,17 @@ namespace electionguard
207204 // / </Summary>
208205 std::vector<uint8_t > getMac () const ;
209206
207+ virtual std::unique_ptr<ElementModQ> crypto_hash () override ;
208+ virtual std::unique_ptr<ElementModQ> crypto_hash () const override ;
209+
210210 // / <summary>
211211 // / Decrypts ciphertext with the Auxiliary Encryption method (as specified in the
212212 // / ElectionGuard specification) given a random nonce, an ElGamal public key,
213213 // / and a description hash. The encrypt may be called to look for padding to
214214 // / verify and remove, in this case the plaintext will be smaller than
215215 // / the ciphertext, or not to look for padding in which case the
216- // / plaintext will be the same size as the ciphertext.
217- // /
216+ // / plaintext will be the same size as the ciphertext.
217+ // /
218218 // / <param name="nonce"> Randomly chosen nonce in [1,Q). </param>
219219 // / <param name="publicKey"> ElGamal public key. </param>
220220 // / <param name="descriptionHash"> Hash of the ballot description. </param>
@@ -232,7 +232,7 @@ namespace electionguard
232232 private:
233233 class Impl ;
234234#pragma warning(suppress : 4251)
235- std::unique_ptr<Impl> pimpl;
235+ std::unique_ptr<Impl> pimpl;
236236 };
237237
238238 // / <summary>
@@ -244,24 +244,32 @@ namespace electionguard
244244 // / This value indicates the maximum length of the plaintext that may be
245245 // / encrypted. The padding scheme applies two bytes for length of padding
246246 // / plus padding bytes. If padding is not to be applied then the
247- // / max_len parameter must be NO_PADDING and the plaintext must
247+ // / max_len parameter must be NO_PADDING. and the plaintext must
248248 // / be a multiple of the block length (32) and the ciphertext will be
249- // / the same size.
249+ // / the same size. If the max_len is set to something other than
250+ // / NO_PADDING and the allow_truncation parameter is set to
251+ // / true then if the message parameter data is longer than
252+ // / max_len then it will be truncated to max_len. If the max_len is set to
253+ // / something other than NO_PADDING and the allow_truncation parameter
254+ // / is set to false then if the message parameter data is longer than
255+ // / max_len then an exception will be thrown.
250256 // /
251- // / <param name="plaintext "> Message to hashed elgamal encrypt. </param>
257+ // / <param name="message "> Message to hashed elgamal encrypt. </param>
252258 // / <param name="nonce"> Randomly chosen nonce in [1,Q). </param>
253259 // / <param name="publicKey"> ElGamal public key. </param>
254260 // / <param name="descriptionHash"> Hash of the ballot description. </param>
255261 // / <param name="max_len"> If padding is to be applied then this indicates the
256262 // / maximum length of plaintext, must be one padded_data_size_t enumeration
257263 // / values. If padding is not to be applied then this parameter must use
258264 // / the NO_PADDING padded_data_size_t enumeration value.</param>
265+ // / <param name="allow_truncation"> Truncates data to the max_len if set to
266+ // / true. If max_len is set to NO_PADDING then this parameter is ignored. </param>
259267 // / <returns>A ciphertext triple.</returns>
260268 // / </summary>
261269 EG_API std::unique_ptr<HashedElGamalCiphertext>
262270 hashedElgamalEncrypt (std::vector<uint8_t > plaintext, const ElementModQ &nonce,
263271 const ElementModP &publicKey, const ElementModQ &descriptionHash,
264- padded_data_size_t max_len);
272+ padded_data_size_t max_len, bool allow_truncation );
265273
266274} // namespace electionguard
267275
0 commit comments