コード例 #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));
     }
 }
コード例 #2
0
ファイル: MediatorClient.cs プロジェクト: Unipisa/eligere
        public PublishedCiphertextTally Tally(CiphertextAcceptedBallot[] ballots, CiphertextElectionContext context, ElectionDescription description)
        {
            var ctxt = new StartTallyRequest()
            {
                ballots     = ballots,
                context     = context,
                description = description
            };

            return(PostRequest <PublishedCiphertextTally, StartTallyRequest>("/api/v1/tally", ctxt));
        }
コード例 #3
0
ファイル: MediatorClient.cs プロジェクト: Unipisa/eligere
        public CiphertextAcceptedBallot BallotSpoil(CiphertextBallot ballot, CiphertextElectionContext context, ElectionDescription description)
        {
            var ctxt = new AcceptBallotRequest()
            {
                ballot      = ballot,
                context     = context,
                description = description
            };

            return(PostRequest <CiphertextAcceptedBallot, AcceptBallotRequest>("/api/v1/ballot/spoil", ctxt));
        }
コード例 #4
0
        public DecryptBallotSharesResponse BallotDecryptShares(CiphertextElectionContext context, CiphertextAcceptedBallot[] encrypted_ballots, Guardian guardian)
        {
            var ctxt = new DecryptBallotSharesRequest()
            {
                context           = context,
                encrypted_ballots = encrypted_ballots,
                guardian          = guardian
            };

            return(PostRequest <DecryptBallotSharesResponse, DecryptBallotSharesRequest>("/api/v1/ballot/decrypt-shares", ctxt));
        }
コード例 #5
0
ファイル: MediatorClient.cs プロジェクト: Unipisa/eligere
        public PublishedPlaintextTally TallyDecrypt(CiphertextElectionContext context, ElectionDescription description, PublishedCiphertextTally encrypted_tally, Dictionary <string, TallyDecryptionShare> shares)
        {
            var ctxt = new DecryptTallyRequest()
            {
                context         = context,
                description     = description,
                encrypted_tally = encrypted_tally,
                shares          = shares
            };

            return(PostRequest <PublishedPlaintextTally, DecryptTallyRequest>("/api/v1/tally/decrypt", ctxt));
        }
コード例 #6
0
        public TallyDecryptionShare TallyDecryptShare(CiphertextElectionContext context, ElectionDescription description, PublishedCiphertextTally encrypted_tally, Guardian guardian)
        {
            var ctxt = new DecryptTallyShareRequest()
            {
                context         = context,
                description     = description,
                encrypted_tally = encrypted_tally,
                guardian        = guardian
            };

            return(PostRequest <TallyDecryptionShare, DecryptTallyShareRequest>("/api/v1/tally/decrypt-share", ctxt));
        }
コード例 #7
0
ファイル: MediatorClient.cs プロジェクト: Unipisa/eligere
        public EncryptBallotsResponse BallotEncrypt(PlaintextBallot[] ballots, CiphertextElectionContext context, ElectionDescription description, string nonce, string seed_hash)
        {
            var ctxt = new EncryptBallotsRequest()
            {
                ballots     = ballots,
                context     = context,
                description = description,
                nonce       = nonce,
                seed_hash   = seed_hash
            };

            return(PostRequest <EncryptBallotsResponse, EncryptBallotsRequest>("/api/v1/ballot/encrypt", ctxt));
        }
コード例 #8
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}");
            }
        }
コード例 #9
0
                protected override bool Free()
                {
                    if (IsClosed)
                    {
                        return(true);
                    }

                    var status = CiphertextElectionContext.Free(this);

                    if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
                    {
                        Console.WriteLine($"CiphertextElectionContext Error Free: {status}");
                        return(false);
                    }
                    return(true);
                }
コード例 #10
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));
        }
コード例 #11
0
ファイル: MediatorClient.cs プロジェクト: Unipisa/eligere
        public PublishedCiphertextTally TallyAppend(CiphertextAcceptedBallot[] ballots, CiphertextElectionContext context, ElectionDescription description, PublishedCiphertextTally encrypted_tally)
        {
            var ctxt = new AppendTallyRequest()
            {
                ballots         = ballots,
                context         = context,
                description     = description,
                encrypted_tally = encrypted_tally
            };

            return(PostRequest <PublishedCiphertextTally, AppendTallyRequest>("/api/v1/tally/append", ctxt));
        }
コード例 #12
0
ファイル: MediatorClient.cs プロジェクト: Unipisa/eligere
        public Dictionary <string, Dictionary <string, PlaintextTallyContest> > BallotDecrypt(CiphertextElectionContext context, CiphertextAcceptedBallot[] encrypted_ballots, Dictionary <string, BallotDecryptionShare[]> shares)
        {
            var ctxt = new DecryptBallotsRequest()
            {
                context           = context,
                encrypted_ballots = encrypted_ballots,
                shares            = shares
            };

            return(PostRequest <Dictionary <string, Dictionary <string, PlaintextTallyContest> >, DecryptBallotsRequest>("/api/v1/ballot/decrypt", ctxt));
        }
コード例 #13
0
ファイル: MediatorClient.cs プロジェクト: Unipisa/eligere
        public async Task <CiphertextAcceptedBallot> BallotSpoilAsync(CiphertextBallot ballot, CiphertextElectionContext context, ElectionDescription description)
        {
            var ctxt = new AcceptBallotRequest()
            {
                ballot      = ballot,
                context     = context,
                description = description
            };

            return(await PostRequestAsync <CiphertextAcceptedBallot, AcceptBallotRequest>("/api/v1/ballot/spoil", ctxt));
        }