All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.openchvote.electionauthority.writein.PublicData Maven / Gradle / Ivy

/*
 * Copyright (C) 2024 Berner Fachhochschule https://e-voting.bfh.ch
 *
 *  - This program is free software: you can redistribute it and/or modify                           -
 *  - it under the terms of the GNU Affero General Public License as published by                    -
 *  - the Free Software Foundation, either version 3 of the License, or                              -
 *  - (at your option) any later version.                                                            -
 *  -                                                                                                -
 *  - This program is distributed in the hope that it will be useful,                                -
 *  - but WITHOUT ANY WARRANTY; without even the implied warranty of                                 -
 *  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                                   -
 *  - GNU General Public License for more details.                                                   -
 *  -                                                                                                -
 *  - You should have received a copy of the GNU Affero General Public License                       -
 *  - along with this program. If not, see .                           -
 */
package ch.openchvote.electionauthority.writein;

import ch.openchvote.algorithms.protocols.common.model.*;
import ch.openchvote.algorithms.protocols.writein.model.*;
import ch.openchvote.framework.party.EventData;
import ch.openchvote.protocol.protocols.writein.content.message.*;
import ch.openchvote.utilities.sequence.ByteArray;
import ch.openchvote.utilities.sequence.Matrix;
import ch.openchvote.utilities.sequence.Vector;
import ch.openchvote.utilities.tuples.Tuple;
import ch.openchvote.utilities.tuples.viguple.SexViguple;

import java.math.BigInteger;

/**
 * Instances of this class represent the election authority's public data. The class inherits from the generic {@link Tuple}
 * subclass, that matches with the number of {@link EventData.Data} and {@link EventData.DataMap} objects to store. 
 * Convenience methods for accessing the fields with names as specified by the CHVote protocol are provided.
 */
@SuppressWarnings("MissingJavadoc")
public final class PublicData extends SexViguple<
        // event setup and election parameters
        EventData.Data, // ES
        EventData.Data, // EP
        // public keys
        EventData.DataMap, // bold_pk
        EventData.DataMap>, // bold_PK_prime
        EventData.Data, // pk
        EventData.Data>, // bold_pk_prime
        EventData.DataMap, // bold_pi
        // polynomials
        EventData.Data>, // bold_a_j
        EventData.Data>, // bold_P_j
        // public credentials
        EventData.DataMap>, // bold_X_hat
        EventData.DataMap>, // bold_Y_hat
        EventData.DataMap>, // bold_Z_hat
        EventData.DataMap, // bold_pi_hat
        EventData.Data>, // bold_x_hat
        EventData.Data>, // bold_y_hat
        EventData.Data>, // bold_z_hat
        // ballots, confirmations, finalizations
        EventData.DataMap, // B_j
        EventData.DataMap, // C_j
        EventData.DataMap, // F_j
        // shuffle
        EventData.DataMap>, // bold_E_tilde
        EventData.DataMap, // bold_pi_tilde
        // decryption
        EventData.DataMap>, // bold_C
        EventData.DataMap>, // arrow_bold_D
        EventData.DataMap, // bold_pi_prime
        EventData.Data>, // bold_c
        EventData.Data>> // bold_D
        implements EventData {

    public PublicData() {
        this(new Data<>(), new Data<>(), new DataMap<>(), new DataMap<>(), new Data<>(), new Data<>(), new DataMap<>(), new Data<>(), new Data<>(), new DataMap<>(), new DataMap<>(), new DataMap<>(), new DataMap<>(), new Data<>(), new Data<>(), new Data<>(), new DataMap<>(), new DataMap<>(), new DataMap<>(), new DataMap<>(), new DataMap<>(), new DataMap<>(), new DataMap<>(), new DataMap<>(), new Data<>(), new Data<>());
    }

    // private constructor for initializing all fields
    private PublicData(Data ES, Data EP, DataMap bold_pk, DataMap> bold_PK_prime, Data pk, Data> bold_pk_prime, DataMap bold_pi, Data> bold_a_j, Data> bold_P_j, DataMap> bold_X_hat, DataMap> bold_Y_hat, DataMap> bold_Z_hat, DataMap bold_pi_hat, Data> bold_x_hat, Data> bold_y_hat, Data> bold_z_hat, DataMap B_j, DataMap C_j, DataMap F_j, DataMap> bold_E_tilde, DataMap bold_pi_tilde, DataMap> bold_C, DataMap> arrow_bold_D, DataMap bold_pi_prime, Data> bold_c, Data> bold_D) {
        super(ES, EP, bold_pk, bold_PK_prime, pk, bold_pk_prime, bold_pi, bold_a_j, bold_P_j, bold_X_hat, bold_Y_hat, bold_Z_hat, bold_pi_hat, bold_x_hat, bold_y_hat, bold_z_hat, B_j, C_j, F_j, bold_E_tilde, bold_pi_tilde, bold_C, arrow_bold_D, bold_pi_prime, bold_c, bold_D);
    }

    // private copy constructor
    @SuppressWarnings("unused")
    private PublicData(PublicData publicData) {
        this(publicData.get_ES(), publicData.get_EP(), publicData.get_bold_pk(), publicData.get_bold_PK_prime(), publicData.get_pk(), publicData.get_bold_pk_prime(), publicData.get_bold_pi(), publicData.get_bold_a_j(), publicData.get_bold_P_j(), publicData.get_bold_X_hat(), publicData.get_bold_Y_hat(), publicData.get_bold_Z_hat(), publicData.get_bold_pi_hat(), publicData.get_bold_x_hat(), publicData.get_bold_y_hat(), publicData.get_bold_z_hat(), publicData.get_B_j(), publicData.get_C_j(), publicData.get_F_j(), publicData.get_bold_E_tilde(), publicData.get_bold_pi_tilde(), publicData.get_bold_C(), publicData.get_arrow_bold_D(), publicData.get_bold_pi_prime(), publicData.get_bold_c(), publicData.get_bold_D());
    }

    public Data get_ES() {
        return this.getFirst();
    }

    public Data get_EP() {
        return this.getSecond();
    }

    public DataMap get_bold_pk() {
        return this.getThird();
    }

    public DataMap> get_bold_PK_prime() {
        return this.getFourth();
    }

    public Data get_pk() {
        return this.getFifth();
    }

    public Data> get_bold_pk_prime() {
        return this.getSixth();
    }

    public DataMap get_bold_pi() {
        return this.getSeventh();
    }

    public Data> get_bold_a_j() {
        return this.getEighth();
    }

    public Data> get_bold_P_j() {
        return this.getNinth();
    }

    public DataMap> get_bold_X_hat() {
        return this.getTenth();
    }

    public DataMap> get_bold_Y_hat() {
        return this.getEleventh();
    }

    public DataMap> get_bold_Z_hat() {
        return this.getTwelfth();
    }

    public DataMap get_bold_pi_hat() {
        return this.getThirteenth();
    }

    public Data> get_bold_x_hat() {
        return this.getFourteenth();
    }

    public Data> get_bold_y_hat() {
        return this.getFifteenth();
    }

    public Data> get_bold_z_hat() {
        return this.getSixteenth();
    }

    public DataMap get_B_j() {
        return this.getSeventeenth();
    }

    public DataMap get_C_j() {
        return this.getEighteenth();
    }

    public DataMap get_F_j() {
        return this.getNineteenth();
    }

    public DataMap> get_bold_E_tilde() {
        return this.getTwentieth();
    }

    public DataMap get_bold_pi_tilde() {
        return this.getTwentyFirst();
    }

    public DataMap> get_bold_C() {
        return this.getTwentySecond();
    }

    public DataMap> get_arrow_bold_D() {
        return this.getTwentyThird();
    }

    public DataMap get_bold_pi_prime() {
        return this.getTwentyFourth();
    }

    public Data> get_bold_c() {
        return this.getTwentyFifth();
    }

    public Data> get_bold_D() {
        return this.getTwentySixth();
    }

    /**
     * Calling this method stores the given content of type {@link MEE1} into the election authority's public data.
     *
     * @param index   The index of the received content
     * @param content The given content
     */
    public void setContent(int index, MEE1 content) {
        this.get_bold_pk().set(index, content.get_pk());
        this.get_bold_PK_prime().set(index, content.get_bold_pk_prime());
        this.get_bold_pi().set(index, content.get_pi());
    }

    /**
     * Calling this method stores the given content of type {@link MEE2} into the election authority's public data.
     *
     * @param index   The index of the received content
     * @param content The given content
     */
    public void setContent(int index, MEE2 content) {
        this.get_bold_X_hat().set(index, content.get_bold_x_hat());
        this.get_bold_Y_hat().set(index, content.get_bold_y_hat());
        this.get_bold_Z_hat().set(index, content.get_bold_z_hat());
        this.get_bold_pi_hat().set(index, content.get_pi_hat());
    }

    /**
     * Calling this method stores the given content of type {@link MEE3} into the election authority's public data.
     *
     * @param index   The index of the received content
     * @param content The given content
     */
    public void setContent(int index, MEE3 content) {
        this.get_bold_E_tilde().set(index, content.get_bold_e_tilde());
        this.get_bold_pi_tilde().set(index, content.get_pi_tilde());
    }

    /**
     * Calling this method stores the given content of type {@link MEE4} into the election authority's public data.
     *
     * @param index   The index of the received content
     * @param content The given content
     */
    public void setContent(int index, MEE4 content) {
        this.get_bold_C().set(index, content.get_bold_c());
        this.get_arrow_bold_D().set(index, content.get_bold_D());
        this.get_bold_pi_prime().set(index, content.get_pi_prime());
    }

    /**
     * Calling this method stores the given content of type {@link MAE1} into the election authority's public data.
     *
     * @param content The given content
     */
    public void setContent(MAE1 content) {
        this.get_ES().set(content.get_ES());
        this.get_EP().set(content.get_EP());
    }

    /**
     * Calling this method stores the given content of type {@link MAE2} into the election authority's public data.
     *
     * @param content The given content
     */
    public void setContent(MAE2 content) {
        this.get_bold_pk().set(0, content.get_pk());
        this.get_bold_PK_prime().set(0, content.get_bold_pk_prime());
        this.get_bold_pi().set(0, content.get_pi());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy