Example usage for org.bouncycastle.crypto.commitments HashCommitter HashCommitter

List of usage examples for org.bouncycastle.crypto.commitments HashCommitter HashCommitter

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.commitments HashCommitter HashCommitter.

Prototype

public HashCommitter(ExtendedDigest digest, SecureRandom random) 

Source Link

Document

Base Constructor.

Usage

From source file:com.vvote.verifierlibrary.utils.crypto.CryptoUtils.java

License:Open Source License

/**
 * Perform a verification on a hash commitment using bouncy castle. This
 * implementation uses the HashCommitter from bouncy castle and the
 * isRevealed function/*from www. ja va  2 s .  c  o m*/
 * 
 * @param commitment
 * @param witness
 * @param randomValue
 * @return whether the commitment check is successful
 * @throws CommitException
 */
private static boolean bouncyCastleVerifyHashCommitment(byte[] commitment, byte[] witness, byte[] randomValue)
        throws CommitException {

    logger.debug("Verifying hash commitment using Bouncy castle implementation");

    // initialise a hash committer
    HashCommitter hashCommitter = new HashCommitter(new SHA256Digest(), new SecureRandom(witness));

    MessageDigest md = null;

    try {
        logger.debug("Initialising message digest");
        // initialise the message digest
        md = MessageDigest.getInstance(CryptoConstants.Commitments.COMMITMENT_HASH_ALGORITHM);

        // ensure the random value is the correct length
        if (randomValue.length > CryptoConstants.Commitments.RANDOM_VALUE_MAXIMUM_LENGTH) {
            logger.debug("Hashing random value to the correct length");
            md.reset();
            randomValue = md.digest(randomValue);
        }

        // initialise a new Commitment
        Commitment comm = new Commitment(witness, commitment);

        // check whether the given random value opens the commitment
        if (!hashCommitter.isRevealed(comm, randomValue)) {
            logger.error("Bouncy castle hash commitment verification failed");
            return false;
        }

    } catch (NoSuchAlgorithmException e) {
        logger.error("Could not initialise the message digest with the specified algorithm: {}",
                CryptoConstants.Commitments.COMMITMENT_HASH_ALGORITHM, e);
        throw new CommitException("Could not initialise the message digest with the specified algorithm: "
                + CryptoConstants.Commitments.COMMITMENT_HASH_ALGORITHM, e);
    }

    return true;
}

From source file:org.cryptoworkshop.ximix.common.crypto.IndexCommitter.java

License:Apache License

/**
 * Constructor for generating commitments.
 *
 * @param digest the digest to base the HashCommitter on.
 * @param random the SecureRandom to use for generating witness values.
 *//*from   w w w . ja v  a2 s  .  com*/
public IndexCommitter(ExtendedDigest digest, SecureRandom random) {
    committer = new HashCommitter(digest, random);
}

From source file:org.cryptoworkshop.ximix.common.crypto.IndexCommitter.java

License:Apache License

/**
 * Constructor for verifying commitments.
 *
 * @param digest the digest to base the HashCommitter on.
 *///from  w  ww  .jav a2s.  c  o  m
public IndexCommitter(ExtendedDigest digest) {
    committer = new HashCommitter(digest, null);
}