Example usage for org.bouncycastle.crypto.ec ECFixedTransform ECFixedTransform

List of usage examples for org.bouncycastle.crypto.ec ECFixedTransform ECFixedTransform

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.ec ECFixedTransform ECFixedTransform.

Prototype

public ECFixedTransform(BigInteger k) 

Source Link

Usage

From source file:org.cryptoworkshop.ximix.client.verify.ECShuffledTranscriptVerifier.java

License:Apache License

/**
 * Verify that the transcripts are valid, throwing an exception if an issue is found.
 *
 * @throws TranscriptVerificationException on verification failure.
 *//* w  w w  .  ja v  a2  s  .com*/
public void verify() throws TranscriptVerificationException {
    // if we've been past streams we have to read the lot in one go.
    int batchSize = (initialTranscript instanceof InputStream) ? -1 : 2000; // TODO: make batch size configurable
    boolean moreWitnesses = true;

    while (moreWitnesses) {
        moreWitnesses = loadWitnesses(witnessTranscript, batchSize);

        if (witnesses.isEmpty()) {
            break;
        }

        if (initialTranscript instanceof InputStream) {
            loadCommitments((InputStream) initialTranscript, (InputStream) finalTranscript);
        } else {
            try {
                InputStream initTranscript = new BufferedInputStream(
                        new FileInputStream((File) initialTranscript));
                InputStream finTranscript = new BufferedInputStream(
                        new FileInputStream((File) finalTranscript));

                loadCommitments(initTranscript, finTranscript);

                initTranscript.close();
                finTranscript.close();
            } catch (IOException e) {
                throw new TranscriptVerificationException("Exception validating transcripts: " + e.getMessage(),
                        e);
            }
        }

        if (initialMap.size() != witnesses.size()) {
            throw new TranscriptVerificationException("Initial transcript incomplete "
                    + (witnesses.size() - initialMap.size()) + " messages missing.");
        }

        if (!finalIndexesOfInterest.isEmpty()) {
            throw new TranscriptVerificationException(
                    "Final transcript incomplete " + finalIndexesOfInterest.size() + " messages missing.");
        }

        try {
            for (Integer msgIndex : witnesses.keySet()) {
                PostedMessage initMsg = initialMap.get(msgIndex);
                MessageCommitment comMsg = witnesses.get(msgIndex);

                BigInteger kValue = new BigInteger(1, comMsg.getDetail());
                ECPairFactorTransform transform = new ECFixedTransform(kValue);

                transform.init(pubKey);

                PairSequence ecSeq = PairSequence.getInstance(ecCurve, initMsg.getMessage());
                ECPair[] ecInit = ecSeq.getECPairs();
                ECPair[] ecRes = new ECPair[ecSeq.size()];

                for (int i = 0; i != ecRes.length; i++) {
                    ecRes[i] = transform.transform(ecInit[i]);
                }

                PostedMessage finalMsg = finalMap.get(comMsg.getNewIndex());
                Commitment commitment = new Commitment(comMsg.getSecret(), finalMsg.getCommitment());

                if (commitChecker.isRevealed(commitment, comMsg.getNewIndex())) {
                    ECPair[] ecFin = PairSequence
                            .getInstance(pubKey.getParameters().getCurve(), finalMsg.getMessage()).getECPairs();

                    if (!Arrays.equals(ecFin, ecRes)) {
                        throw new TranscriptVerificationException(
                                "Transformed cipher text does not match for relationship " + initMsg.getIndex()
                                        + " -> " + comMsg.getNewIndex());
                    }
                } else {
                    throw new TranscriptVerificationException("Commitment check failed for relationship "
                            + initMsg.getIndex() + " -> " + comMsg.getNewIndex());
                }
            }
        } catch (TranscriptVerificationException e) {
            throw e;
        } catch (Exception e) {
            throw new TranscriptVerificationException("Exception validating transcripts: " + e.getMessage(), e);
        }

        witnesses.clear();
        initialMap.clear();
        finalMap.clear();
        finalIndexesOfInterest.clear();
    }
}

From source file:org.cryptoworkshop.ximix.node.mixnet.transform.MultiColumnRowTransform.java

License:Apache License

public void init(Object o) {
    this.parameters = (ECPublicKeyParameters) o;

    BigInteger kValue = generateK(parameters.getParameters().getN(), new SecureRandom()); // TODO: make configurable?

    transform = new ECFixedTransform(kValue);

    transform.init(parameters);/*from  w w  w .  j a  va  2 s.  c o m*/
}