List of usage examples for org.bouncycastle.crypto.params ECDomainParameters getN
public BigInteger getN()
From source file:com.licel.jcardsim.crypto.ECKeyImpl.java
License:Apache License
/** * Set/*from ww w . ja v a 2 s.c o m*/ * <code>ECDomainParameters</code> for EC curve * * @param parameters * @see ECDomainParameters */ final void setDomainParameters(ECDomainParameters parameters) { a.setBigInteger(parameters.getCurve().getA().toBigInteger()); b.setBigInteger(parameters.getCurve().getB().toBigInteger()); // generator g.setBytes(parameters.getG().getEncoded()); // order r.setBigInteger(parameters.getN()); // cofactor setK(parameters.getH().shortValue()); if (parameters.getCurve() instanceof ECCurve.Fp) { ECCurve.Fp ecfp = (ECCurve.Fp) parameters.getCurve(); fp.setBigInteger(ecfp.getQ()); } else { ECCurve.F2m ecf2m = (ECCurve.F2m) parameters.getCurve(); setFieldF2M((short) ecf2m.getK1(), (short) ecf2m.getK2(), (short) ecf2m.getK3()); } }
From source file:dorkbox.util.crypto.CryptoECC.java
License:Apache License
public static boolean compare(ECPrivateKeyParameters privateA, ECPrivateKeyParameters privateB) { ECDomainParameters parametersA = privateA.getParameters(); ECDomainParameters parametersB = privateB.getParameters(); // is it the same curve? boolean equals = parametersA.getCurve().equals(parametersB.getCurve()); if (!equals) { return false; }/* w w w . ja v a2s . c om*/ equals = parametersA.getG().equals(parametersB.getG()); if (!equals) { return false; } equals = parametersA.getH().equals(parametersB.getH()); if (!equals) { return false; } equals = parametersA.getN().equals(parametersB.getN()); if (!equals) { return false; } equals = privateA.getD().equals(privateB.getD()); return equals; }
From source file:dorkbox.util.crypto.CryptoECC.java
License:Apache License
/** * @return true if publicA and publicB are NOT NULL, and are both equal to eachother *//*from www .j a va 2 s . c o m*/ @SuppressWarnings({ "RedundantIfStatement", "SpellCheckingInspection" }) public static boolean compare(ECPublicKeyParameters publicA, ECPublicKeyParameters publicB) { if (publicA == null || publicB == null) { return false; } ECDomainParameters parametersA = publicA.getParameters(); ECDomainParameters parametersB = publicB.getParameters(); // is it the same curve? boolean equals = parametersA.getCurve().equals(parametersB.getCurve()); if (!equals) { return false; } equals = parametersA.getG().equals(parametersB.getG()); if (!equals) { return false; } equals = parametersA.getH().equals(parametersB.getH()); if (!equals) { return false; } equals = parametersA.getN().equals(parametersB.getN()); if (!equals) { return false; } ECPoint normalizeA = publicA.getQ().normalize(); ECPoint normalizeB = publicB.getQ().normalize(); ECFieldElement xCoordA = normalizeA.getXCoord(); ECFieldElement xCoordB = normalizeB.getXCoord(); equals = xCoordA.equals(xCoordB); if (!equals) { return false; } ECFieldElement yCoordA = normalizeA.getYCoord(); ECFieldElement yCoordB = normalizeB.getYCoord(); equals = yCoordA.equals(yCoordB); if (!equals) { return false; } return true; }
From source file:dorkbox.util.serialization.EccPrivateKeySerializer.java
License:Apache License
public static void write(Output output, ECPrivateKeyParameters key) throws KryoException { byte[] bytes; int length;/*from www .ja v a 2s . co m*/ ECDomainParameters parameters = key.getParameters(); ECCurve curve = parameters.getCurve(); EccPrivateKeySerializer.serializeCurve(output, curve); ///////////// BigInteger n = parameters.getN(); ECPoint g = parameters.getG(); ///////////// bytes = n.toByteArray(); length = bytes.length; output.writeInt(length, true); output.writeBytes(bytes, 0, length); serializeECPoint(g, output); ///////////// bytes = key.getD().toByteArray(); length = bytes.length; output.writeInt(length, true); output.writeBytes(bytes, 0, length); }
From source file:dorkbox.util.serialization.EccPublicKeySerializer.java
License:Apache License
public static void write(Output output, ECPublicKeyParameters key) throws KryoException { byte[] bytes; int length;/*from w w w.j a v a2 s.c o m*/ ECDomainParameters parameters = key.getParameters(); ECCurve curve = parameters.getCurve(); EccPrivateKeySerializer.serializeCurve(output, curve); ///////////// BigInteger n = parameters.getN(); ECPoint g = parameters.getG(); ///////////// bytes = n.toByteArray(); length = bytes.length; output.writeInt(length, true); output.writeBytes(bytes, 0, length); EccPrivateKeySerializer.serializeECPoint(g, output); EccPrivateKeySerializer.serializeECPoint(key.getQ(), output); }
From source file:org.cryptacular.adapter.AbstractWrappedECKey.java
License:Open Source License
/** @return EC domain parameters. */ public ECParameterSpec getParams() { final ECDomainParameters params = delegate.getParameters(); return new ECParameterSpec(EC5Util.convertCurve(params.getCurve(), params.getSeed()), new ECPoint(params.getG().normalize().getXCoord().toBigInteger(), params.getG().normalize().getYCoord().toBigInteger()), params.getN(), params.getH().intValue()); }
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++;/* w w w. j a v a 2s . com*/ } 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.verify.ECDecryptionChallengeVerifier.java
License:Apache License
private boolean isSameParameters(ECDomainParameters a, ECDomainParameters b) { return a.getCurve().equals(b.getCurve()) && a.getG().equals(b.getG()) && a.getH().equals(b.getH()) && a.getN().equals(b.getN()); }
From source file:org.cryptoworkshop.ximix.common.crypto.threshold.ECNewDKGSecretSplitter.java
License:Apache License
/** * creates an instance over the specified EC domain parameters * to share secrets among the specified number of peers * * @param numberOfPeers the number of peers among which the secret is shared * @param threshold number of peers that must be available for secret reconstruction, * @param h value to calculate commitment polynomial against. * @param domainParams domain parameters for the EC group to use. * @param random a source of randomness, *//*w ww . j av a 2 s .c o m*/ public ECNewDKGSecretSplitter(int numberOfPeers, int threshold, ECPoint h, ECDomainParameters domainParams, SecureRandom random) { if (numberOfPeers < threshold) { throw new IllegalArgumentException("numberOfPeers must at least be as big as the threshold value."); } this.k = threshold; this.h = h; this.domainParams = domainParams; this.secretSplitter = new ShamirSecretSplitter(numberOfPeers, threshold, domainParams.getN(), random); this.random = random; }
From source file:org.cryptoworkshop.ximix.demo.admin.Main.java
License:Apache License
private static ECPoint generatePoint(ECDomainParameters params, SecureRandom rand) { return params.getG().multiply(getRandomInteger(params.getN(), rand)); }