/// <summary> /// Given an encrypted BallotContest, validates the encryption state against /// a specific encryption seed and public key /// by verifying the accumulated sum of selections match the proof. /// Calling this function expects that the object is in a well-formed encrypted state /// with the `ballot_selections` populated with valid encrypted ballot selections, /// the ElementModQ `description_hash`, the ElementModQ `crypto_hash`, /// and the ConstantChaumPedersenProof all populated. /// Specifically, the seed hash in this context is the hash of the ContestDescription, /// or whatever `ElementModQ` was used to populate the `description_hash` field. /// </summary> public unsafe bool IsValidEncryption( ElementModQ encryptionSeed, ElementModP elGamalPublicKey, ElementModQ cryptoExtendedBaseHash) { return(NativeInterface.CiphertextBallotContest.IsValidEncryption( Handle, encryptionSeed.Handle, elGamalPublicKey.Handle, cryptoExtendedBaseHash.Handle)); }
public unsafe CiphertextElectionContext(ulong numberOfGuardians, ulong quorum, ElementModP publicKey, ElementModQ commitmentHash, ElementModQ manifestHash) { var status = NativeInterface.CiphertextElectionContext.Make( numberOfGuardians, quorum, publicKey.Handle, commitmentHash.Handle, manifestHash.Handle, out Handle); if (status != Status.ELECTIONGUARD_STATUS_SUCCESS) { Console.WriteLine($"CiphertextElectionContext Error Status: {status}"); } }
/// <summary> /// Encrypts a message with a given random nonce and an ElGamal public key. /// /// <param name="plaintext"> Message to elgamal_encrypt; must be an integer in [0,Q). </param> /// <param name="nonce"> Randomly chosen nonce in [1,Q). </param> /// <param name="publicKey"> ElGamal public key. </param> /// <returns>A ciphertext tuple.</returns> /// </summary> unsafe public static ElGamalCiphertext Encrypt( ulong plaintext, ElementModQ nonce, ElementModP publicKey) { var status = NativeInterface.ElGamal.Encrypt( plaintext, nonce.Handle, publicKey.Handle, out NativeElGamalCiphertext ciphertext); if (status != Status.ELECTIONGUARD_STATUS_SUCCESS) { Console.WriteLine($"Encrypt Error Status: {status}"); return(null); } return(new ElGamalCiphertext(ciphertext)); }
protected override bool Free() { if (IsClosed) { return(true); } var status = ElementModP.Free(this); if (status != Status.ELECTIONGUARD_STATUS_SUCCESS) { Console.WriteLine($"ElementModP Error Free: {status}"); return(false); } return(true); }