Example usage for org.bouncycastle.math.ec ECPoint toString

List of usage examples for org.bouncycastle.math.ec ECPoint toString

Introduction

In this page you can find the example usage for org.bouncycastle.math.ec ECPoint toString.

Prototype

public String toString() 

Source Link

Usage

From source file:com.vvote.verifier.component.ComponentVerifier.java

License:Open Source License

/**
 * Verify that the base encrypted ids are actually the plaintext ids
 * encrypted with a fixed randomness value of 1
 * /* w  ww.jav a  2s.  c  o m*/
 * @return true if the plaintext ids and base encryped candidate ids match
 */
public boolean verifyBaseCandidateIds() {

    logger.info("Starting Verification of the base candidate ids");

    if (this.getDataStore().getPlaintextIds() == null || this.getDataStore().getBaseEncryptedIds() == null) {
        logger.error("Check that both the plaintext ids and base encrypted candidate ids are present");
        resultsLogger.error("Check that both the plaintext ids and base encrypted candidate ids are present");
        return false;
    }

    // check that the number of ids (plaintext/base encrypted) match
    if (this.getDataStore().getPlaintextIds().size() != this.getDataStore().getBaseEncryptedIds().size()) {
        logger.error("The size of the lists of plaintext ids and base encrypted candidate ids do not match");
        resultsLogger
                .error("The size of the lists of plaintext ids and base encrypted candidate ids do not match");
        return false;
    }

    final ECPoint publicKey = this.getDataStore().getPublicKey();

    ECPoint currentPlaintextId = null;
    ElGamalECPoint encryptedId = null;
    ElGamalECPoint currentBaseEncryptedId = null;

    // Encrypt each plaintext id with fixed randomness value of 1 and get a
    // candidate encrypted id to compare to the stored base encrypted
    // ciphers
    for (int i = 0; i < this.getDataStore().getPlaintextIds().size(); i++) {

        currentPlaintextId = this.getDataStore().getPlaintextIds().get(i);
        currentBaseEncryptedId = this.getDataStore().getBaseEncryptedIds().get(i);
        encryptedId = ECUtils.encrypt(currentPlaintextId, publicKey, BigInteger.ONE);

        // compare the two ElGamalECPoints
        if (!encryptedId.equals(currentBaseEncryptedId)) {
            logger.error(
                    "Plaintext ids and base candidate ids do not match at index: {}, (plaintext id: {}, base encrypted id: {})",
                    i, currentPlaintextId.toString(), currentBaseEncryptedId.toString());
            resultsLogger.error(
                    "Plaintext ids and base candidate ids do not match at index: {}, (plaintext id: {}, base encrypted id: {})",
                    i, currentPlaintextId.toString(), currentBaseEncryptedId.toString());
            return false;
        }
    }

    logger.debug("Successfully verified that the plaintext ids and base candidate ids match");
    resultsLogger.info("Successfully verified that the plaintext ids and base candidate ids match");

    return true;
}