Example usage for org.bouncycastle.asn1 DERSequence DERSequence

List of usage examples for org.bouncycastle.asn1 DERSequence DERSequence

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 DERSequence DERSequence.

Prototype

public DERSequence(ASN1Encodable[] elements) 

Source Link

Document

Create a sequence containing an array of objects.

Usage

From source file:org.cryptoworkshop.ximix.client.connection.signing.ECDSASigningService.java

License:Apache License

public MessageReply generateSig(SignatureCreateMessage ecdsaCreate)
        throws ServiceConnectionException, IOException {
    Participant[] participants = new Participant[ecdsaCreate.getNodesToUse().size()];
    int index = 0;

    for (String name : ecdsaCreate.getNodesToUse()) {
        MessageReply seqRep = sendMessage(name, Type.FETCH_SEQUENCE_NO,
                new KeyIDMessage(ecdsaCreate.getKeyID()));
        // TODO: need to drop out people who don't reply.
        participants[index] = new Participant(
                BigIntegerMessage.getInstance(seqRep.getPayload()).getValue().intValue(), name);
        index++;//from  w w w .j a va  2 s. c om
    }

    FetchPublicKeyMessage fetchMessage = new FetchPublicKeyMessage(ecdsaCreate.getKeyID());

    MessageReply reply = connection.sendMessage(ClientMessage.Type.FETCH_PUBLIC_KEY, fetchMessage);

    ECDomainParameters domainParams = ((ECPublicKeyParameters) PublicKeyFactory
            .createKey(SubjectPublicKeyInfo.getInstance(reply.getPayload()))).getParameters();
    BigInteger n = domainParams.getN();
    BigInteger e = calculateE(n, ecdsaCreate.getMessage());
    // TODO: need to take into account node failure during startup.

    reply = sendMessage(participants[0].getName(), Type.FETCH_SIG_ID, DERNull.INSTANCE);

    SigID sigID = new SigID(IDMessage.getInstance(reply.getPayload()).getID());

    BigInteger r, s;
    do // generate s
    {
        ECDSAInitialiseMessage initialiseMessage = new ECDSAInitialiseMessage(sigID.getID(),
                ecdsaCreate.getKeyID(), ecdsaCreate.getThreshold(), domainParams.getN(), participants);

        sendInitialiseMessage(Type.INIT_K_AND_P, initialiseMessage);
        sendInitialiseMessage(Type.INIT_A, initialiseMessage);
        sendInitialiseMessage(Type.INIT_B, initialiseMessage);
        sendInitialiseMessage(Type.INIT_C, initialiseMessage);
        sendInitialiseMessage(Type.INIT_R, initialiseMessage);
        sendInitialiseMessage(Type.INIT_MU, initialiseMessage);

        MessageReply seqRep = sendMessage(participants[0].getName(), Type.FETCH_R,
                new IDMessage(sigID.getID()));

        r = BigIntegerMessage.getInstance(seqRep.getPayload()).getValue();

        s = accumulateBigInteger(participants, Type.PRIVATE_KEY_SIGN,
                new ECDSAPartialCreateMessage(sigID.getID(), ecdsaCreate.getKeyID(), e, participants), n);
    } while (s.equals(BigInteger.ZERO));

    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new ASN1Integer(r));
    v.add(new ASN1Integer(s));

    return new MessageReply(MessageReply.Type.OKAY, new DERSequence(v));
}

From source file:org.cryptoworkshop.ximix.client.connection.signing.message.BLSPartialCreateMessage.java

License:Apache License

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new DERUTF8String(keyID));
    v.add(h);/*from  ww w .  j  a v a2  s .com*/
    v.add(MessageUtils.toASN1Sequence(nodesToUse));

    return new DERSequence(v);
}

From source file:org.cryptoworkshop.ximix.client.connection.signing.message.ECDSAFetchMessage.java

License:Apache License

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new DERUTF8String(sigID));
    v.add(new DERUTF8String(keyID));
    v.add(MessageUtils.toASN1Sequence(nodesToUse));

    return new DERSequence(v);
}

From source file:org.cryptoworkshop.ximix.client.connection.signing.message.ECDSAInitialiseMessage.java

License:Apache License

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new DERUTF8String(sigID));
    v.add(new DERUTF8String(keyID));
    v.add(new ASN1Integer(threshold));
    v.add(new ASN1Integer(n));
    v.add(MessageUtils.toASN1Sequence(nodesToUse));

    return new DERSequence(v);
}

From source file:org.cryptoworkshop.ximix.client.connection.signing.message.ECDSAPartialCreateMessage.java

License:Apache License

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new DERUTF8String(sigID));
    v.add(new DERUTF8String(keyID));
    v.add(new ASN1Integer(e));
    v.add(MessageUtils.toASN1Sequence(nodesToUse));

    return new DERSequence(v);
}

From source file:org.cryptoworkshop.ximix.client.connection.signing.message.ECDSAPointMessage.java

License:Apache License

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new DERUTF8String(keyID));
    v.add(new DEROctetString(point));

    return new DERSequence(v);
}

From source file:org.cryptoworkshop.ximix.common.asn1.board.Pair.java

License:Apache License

/**
 * <pre>/*from   w  ww. j  ava 2 s  . c o m*/
 *     Pair ::= SEQUENCE {
 *         x OCTET STRING,
 *         y OCTET STRING
 *     }
 * </pre>
 *
 * @return an encoding of an ASN.1 sequence
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new DEROctetString(ecPair.getX().getEncoded()));
    v.add(new DEROctetString(ecPair.getY().getEncoded()));

    return new DERSequence(v);
}

From source file:org.cryptoworkshop.ximix.common.asn1.board.PairSequence.java

License:Apache License

/**
 * <pre>/*from w w  w  .  j  a  v a  2s .c o  m*/
 *     PairSequence ::= SEQUENCE OF Pair
 * </pre>
 *
 * @return an encoding of an ASN.1 sequence
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    for (ECPair pair : ecPairs) {
        v.add(new Pair(pair));
    }

    return new DERSequence(v);
}

From source file:org.cryptoworkshop.ximix.common.asn1.board.PairSequenceWithProofs.java

License:Apache License

/**
 * <pre>/*from  w ww  .j ava 2 s .  c om*/
 *     PairSequence ::= SEQUENCE OF Pair
 * </pre>
 *
 * @return an encoding of an ASN.1 sequence
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector tot = new ASN1EncodableVector();
    ASN1EncodableVector v = new ASN1EncodableVector();

    for (ECPair pair : ecPairs) {
        v.add(new Pair(pair));
    }

    tot.add(new DERSequence(v));

    v = new ASN1EncodableVector();
    for (ECDecryptionProof proof : ecProofs) {
        ASN1EncodableVector proofV = new ASN1EncodableVector();

        proofV.add(new DEROctetString(proof.getA().getEncoded(true)));
        proofV.add(new DEROctetString(proof.getB().getEncoded(true)));
        proofV.add(new ASN1Integer(proof.getR()));

        v.add(new DERSequence(proofV));
    }

    tot.add(new DERSequence(v));

    return new DERSequence(tot);
}

From source file:org.cryptoworkshop.ximix.common.asn1.board.PointSequence.java

License:Apache License

/**
 * <pre>/*from  ww  w . j  ava 2 s .  c  om*/
 *     PointSequence ::= SEQUENCE OF Point
 * </pre>
 *
 * @return an encoding of an ASN.1 sequence
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    for (ECPoint point : ecPoints) {
        v.add(new DEROctetString(point.getEncoded()));
    }

    return new DERSequence(v);
}