Exemplo n.º 1
0
 /// <summary>
 /// Encrypt a specific `Ballot` in the context of a specific `CiphertextElectionContext`
 ///
 /// This method accepts a ballot representation that only includes `True` selections.
 /// It will fill missing selections for a contest with `False` values, and generate `placeholder`
 /// selections to represent the number of seats available for a given contest.  By adding `placeholder`
 /// votes
 ///
 /// This method also allows for ballots to exclude passing contests for which the voter made no selections.
 /// It will fill missing contests with `False` selections and generate `placeholder` selections that are marked `True`.
 ///
 /// <param name="ballot">the selection in the valid input form</param>
 /// <param name="internalManifest">the `InternalManifest` which defines this ballot's structure</param>
 /// <param name="context">all the cryptographic context for the election</param>
 /// <param name="ballotCodeSeed">Hash from previous ballot or hash from device</param>
 /// <param name="nonce">an optional value used to seed the `Nonce` generated for this ballot
 ///                     if this value is not provided, the secret generating mechanism of the OS provides its own</param>
 /// <param name="shouldVerifyProofs">specify if the proofs should be verified prior to returning (default True)</param>
 /// <returns>A `CiphertextBallot`</returns>
 /// </summary>
 public static unsafe CiphertextBallot Ballot(
     PlaintextBallot ballot,
     InternalManifest internalManifest,
     CiphertextElectionContext context,
     ElementModQ ballotCodeSeed,
     ElementModQ nonce       = null,
     bool shouldVerifyProofs = true)
 {
     if (nonce == null)
     {
         var status = NativeInterface.Encrypt.Ballot(
             ballot.Handle, internalManifest.Handle, context.Handle,
             ballotCodeSeed.Handle, shouldVerifyProofs,
             out NativeCiphertextBallot ciphertext);
         if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
         {
             Console.WriteLine($"Encrypt Ballot Error Status: {status}");
         }
         return(new CiphertextBallot(ciphertext));
     }
     else
     {
         var status = NativeInterface.Encrypt.Ballot(
             ballot.Handle, internalManifest.Handle, context.Handle,
             ballotCodeSeed.Handle, nonce.Handle, shouldVerifyProofs,
             out NativeCiphertextBallot ciphertext);
         if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
         {
             Console.WriteLine($"EncryptWithNonce Ballot Error Status: {status}");
         }
         return(new CiphertextBallot(ciphertext));
     }
 }
Exemplo n.º 2
0
        public unsafe EncryptionMediator(
            InternalManifest manifest,
            CiphertextElectionContext context,
            EncryptionDevice device)
        {
            var status = NativeInterface.EncryptionMediator.New(
                manifest.Handle, context.Handle, device.Handle, out Handle);

            if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
            {
                Console.WriteLine($"EncryptionMediator New Error Status: {status}");
            }
        }
                protected override bool Free()
                {
                    if (IsClosed)
                    {
                        return(true);
                    }

                    var status = InternalManifest.Free(this);

                    if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
                    {
                        Console.WriteLine($"InternalManifest Error Free: {status}");
                        return(false);
                    }
                    return(true);
                }
Exemplo n.º 4
0
        /// <summary>
        /// Encrypt a specific `Ballot` in the context of a specific `CiphertextElectionContext`
        ///
        /// This method accepts a ballot representation that only includes `True` selections.
        /// It will fill missing selections for a contest with `False` values, and generate `placeholder`
        /// selections to represent the number of seats available for a given contest.  By adding `placeholder`
        /// votes
        ///
        /// This method also allows for ballots to exclude passing contests for which the voter made no selections.
        /// It will fill missing contests with `False` selections and generate `placeholder` selections that are marked `True`.
        ///
        /// This version of the encrypt method returns a `compact` version of the ballot that includes a minimal representation
        /// of the plaintext ballot along with the crypto parameters that are required to expand the ballot
        ///
        /// <param name="ballot">the selection in the valid input form</param>
        /// <param name="internalManifest">the `InternalManifest` which defines this ballot's structure</param>
        /// <param name="context">all the cryptographic context for the election</param>
        /// <param name="ballotCodeSeed">Hash from previous ballot or hash from device</param>
        /// <param name="nonceSeed">an optional value used to seed the `Nonce` generated for this ballot
        ///                     if this value is not provided, the secret generating mechanism of the OS provides its own</param>
        /// <param name="shouldVerifyProofs">specify if the proofs should be verified prior to returning (default True)</param>
        /// <returns>A `CiphertextBallot`</returns>
        /// </summary>
        public static unsafe CompactCiphertextBallot CompactBallot(
            PlaintextBallot ballot,
            InternalManifest internalManifest,
            CiphertextElectionContext context,
            ElementModQ ballotCodeSeed,
            bool verifyProofs = true)
        {
            var status = NativeInterface.Encrypt.CompactBallot(
                ballot.Handle, internalManifest.Handle, context.Handle,
                ballotCodeSeed.Handle, verifyProofs,
                out NativeCompactCiphertextBallot ciphertext);

            if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
            {
                Console.WriteLine($"Encrypt CompactBallot Error Status: {status}");
            }
            return(new CompactCiphertextBallot(ciphertext));
        }