/** * TODO want to figure out why BouncyCastle does not work. * @return The initialized curve25519 parameter spec */ public static AlgorithmParameterSpec getCurve25519Params() { X9ECParameters ecP = CustomNamedCurves.getByName("curve25519"); return new ECParameterSpec(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed()); } }
public boolean equals(Object other) { return other instanceof ECPair ? equals((ECPair)other) : false; }
/** * Transform an existing cipher test pair using the ElGamal algorithm. Note: it is assumed this * transform has been initialised with the same public key that was used to create the original * cipher text. * * @param cipherText the EC point to process. * @return returns a new ECPair representing the result of the process. */ public ECPair transform(ECPair cipherText) { if (key == null) { throw new IllegalStateException("ECNewRandomnessTransform not initialised"); } ECDomainParameters ec = key.getParameters(); BigInteger n = ec.getN(); ECMultiplier basePointMultiplier = createBasePointMultiplier(); BigInteger k = ECUtil.generateK(n, random); ECPoint[] gamma_phi = new ECPoint[]{ basePointMultiplier.multiply(ec.getG(), k).add(cipherText.getX()), key.getQ().multiply(k).add(cipherText.getY()) }; ec.getCurve().normalizeAll(gamma_phi); lastK = k; return new ECPair(gamma_phi[0], gamma_phi[1]); }
/** * Transform an existing cipher text pair using the ElGamal algorithm. Note: the input cipherText will * need to be preserved in order to complete the transformation to the new public key. * * @param cipherText the EC point to process. * @return returns a new ECPair representing the result of the process. */ public ECPair transform(ECPair cipherText) { if (key == null) { throw new IllegalStateException("ECNewPublicKeyTransform not initialised"); } ECDomainParameters ec = key.getParameters(); BigInteger n = ec.getN(); ECMultiplier basePointMultiplier = createBasePointMultiplier(); BigInteger k = ECUtil.generateK(n, random); ECPoint[] gamma_phi = new ECPoint[]{ basePointMultiplier.multiply(ec.getG(), k), key.getQ().multiply(k).add(cipherText.getY()) }; ec.getCurve().normalizeAll(gamma_phi); return new ECPair(gamma_phi[0], gamma_phi[1]); }
/** * Transform an existing cipher text pair using the ElGamal algorithm. Note: it is assumed this * transform has been initialised with the same public key that was used to create the original * cipher text. * * @param cipherText the EC point to process. * @return returns a new ECPair representing the result of the process. */ public ECPair transform(ECPair cipherText) { if (key == null) { throw new IllegalStateException("ECFixedTransform not initialised"); } ECDomainParameters ec = key.getParameters(); BigInteger n = ec.getN(); ECMultiplier basePointMultiplier = createBasePointMultiplier(); BigInteger k = this.k.mod(n); ECPoint[] gamma_phi = new ECPoint[]{ basePointMultiplier.multiply(ec.getG(), k).add(cipherText.getX()), key.getQ().multiply(k).add(cipherText.getY()) }; ec.getCurve().normalizeAll(gamma_phi); return new ECPair(gamma_phi[0], gamma_phi[1]); }
/** * Process a single EC point using the basic ElGamal algorithm. * * @param point the EC point to process. * @return the result of the Elgamal process. */ public ECPair encrypt(ECPoint point) { if (key == null) { throw new IllegalStateException("ECElGamalEncryptor not initialised"); } ECDomainParameters ec = key.getParameters(); BigInteger k = ECUtil.generateK(ec.getN(), random); ECMultiplier basePointMultiplier = createBasePointMultiplier(); ECPoint[] gamma_phi = new ECPoint[]{ basePointMultiplier.multiply(ec.getG(), k), key.getQ().multiply(k).add(point) }; ec.getCurve().normalizeAll(gamma_phi); return new ECPair(gamma_phi[0], gamma_phi[1]); }
public static X9ECParameters getNamedCurveByOid( ASN1ObjectIdentifier oid) { X9ECParameters params = CustomNamedCurves.getByOID(oid); if (params == null) { params = ECNamedCurveTable.getByOID(oid); } return params; }
/** * Transform an existing cipher test pair using the ElGamal algorithm. Note: it is assumed this * transform has been initialised with the same public key that was used to create the original * cipher text. * * @param cipherText the EC point to process. * @return returns a new ECPair representing the result of the process. */ public ECPair transform(ECPair cipherText) { if (key == null) { throw new IllegalStateException("ECNewRandomnessTransform not initialised"); } ECDomainParameters ec = key.getParameters(); BigInteger n = ec.getN(); ECMultiplier basePointMultiplier = createBasePointMultiplier(); BigInteger k = ECUtil.generateK(n, random); ECPoint[] gamma_phi = new ECPoint[]{ basePointMultiplier.multiply(ec.getG(), k).add(ECAlgorithms.cleanPoint(ec.getCurve(), cipherText.getX())), key.getQ().multiply(k).add(ECAlgorithms.cleanPoint(ec.getCurve(), cipherText.getY())) }; ec.getCurve().normalizeAll(gamma_phi); lastK = k; return new ECPair(gamma_phi[0], gamma_phi[1]); }
/** * Transform an existing cipher text pair using the ElGamal algorithm. Note: the input cipherText will * need to be preserved in order to complete the transformation to the new public key. * * @param cipherText the EC point to process. * @return returns a new ECPair representing the result of the process. */ public ECPair transform(ECPair cipherText) { if (key == null) { throw new IllegalStateException("ECNewPublicKeyTransform not initialised"); } ECDomainParameters ec = key.getParameters(); BigInteger n = ec.getN(); ECMultiplier basePointMultiplier = createBasePointMultiplier(); BigInteger k = ECUtil.generateK(n, random); ECPoint[] gamma_phi = new ECPoint[]{ basePointMultiplier.multiply(ec.getG(), k), key.getQ().multiply(k).add(ECAlgorithms.cleanPoint(ec.getCurve(), cipherText.getY())) }; ec.getCurve().normalizeAll(gamma_phi); return new ECPair(gamma_phi[0], gamma_phi[1]); }
/** * Transform an existing cipher text pair using the ElGamal algorithm. Note: it is assumed this * transform has been initialised with the same public key that was used to create the original * cipher text. * * @param cipherText the EC point to process. * @return returns a new ECPair representing the result of the process. */ public ECPair transform(ECPair cipherText) { if (key == null) { throw new IllegalStateException("ECFixedTransform not initialised"); } ECDomainParameters ec = key.getParameters(); BigInteger n = ec.getN(); ECMultiplier basePointMultiplier = createBasePointMultiplier(); BigInteger k = this.k.mod(n); ECPoint[] gamma_phi = new ECPoint[]{ basePointMultiplier.multiply(ec.getG(), k).add(ECAlgorithms.cleanPoint(ec.getCurve(), cipherText.getX())), key.getQ().multiply(k).add(ECAlgorithms.cleanPoint(ec.getCurve(), cipherText.getY())) }; ec.getCurve().normalizeAll(gamma_phi); return new ECPair(gamma_phi[0], gamma_phi[1]); }
/** * Process a single EC point using the basic ElGamal algorithm. * * @param point the EC point to process. * @return the result of the Elgamal process. */ public ECPair encrypt(ECPoint point) { if (key == null) { throw new IllegalStateException("ECElGamalEncryptor not initialised"); } ECDomainParameters ec = key.getParameters(); BigInteger k = ECUtil.generateK(ec.getN(), random); ECMultiplier basePointMultiplier = createBasePointMultiplier(); ECPoint[] gamma_phi = new ECPoint[]{ basePointMultiplier.multiply(ec.getG(), k), key.getQ().multiply(k).add(ECAlgorithms.cleanPoint(ec.getCurve(), point)) }; ec.getCurve().normalizeAll(gamma_phi); return new ECPair(gamma_phi[0], gamma_phi[1]); }
public static X9ECParameters getNamedCurveByName( String curveName) { X9ECParameters params = CustomNamedCurves.getByName(curveName); if (params == null) { params = ECNamedCurveTable.getByName(curveName); } return params; }
public boolean equals(Object other) { return other instanceof ECPair ? equals((ECPair)other) : false; }
/** * Decrypt an EC pair producing the original EC point. * * @param pair the EC point pair to process. * @return the result of the Elgamal process. */ public ECPoint decrypt(ECPair pair) { if (key == null) { throw new IllegalStateException("ECElGamalDecryptor not initialised"); } ECPoint tmp = pair.getX().multiply(key.getD()); return pair.getY().subtract(tmp).normalize(); } }
/** * TODO want to figure out why BouncyCastle does not work. * @return The initialized curve25519 parameter spec */ public static AlgorithmParameterSpec getCurve25519Params() { X9ECParameters ecP = CustomNamedCurves.getByName("curve25519"); return new ECParameterSpec(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed()); } }
/** * Decrypt an EC pair producing the original EC point. * * @param pair the EC point pair to process. * @return the result of the Elgamal process. */ public ECPoint decrypt(ECPair pair) { if (key == null) { throw new IllegalStateException("ECElGamalDecryptor not initialised"); } ECCurve curve = key.getParameters().getCurve(); ECPoint tmp = ECAlgorithms.cleanPoint(curve, pair.getX()).multiply(key.getD()); return ECAlgorithms.cleanPoint(curve, pair.getY()).subtract(tmp).normalize(); } }
public static ECDomainParameters getParametersForNamedCurve(int namedCurve) { String curveName = getNameOfNamedCurve(namedCurve); if (curveName == null) { return null; } // Parameters are lazily created the first time a particular curve is accessed X9ECParameters ecP = CustomNamedCurves.getByName(curveName); if (ecP == null) { ecP = ECNamedCurveTable.getByName(curveName); if (ecP == null) { return null; } } // It's a bit inefficient to do this conversion every time return new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed()); }
public static ECDomainParameters getParametersForNamedCurve(int namedCurve) { String curveName = getNameOfNamedCurve(namedCurve); if (curveName == null) { return null; } // Parameters are lazily created the first time a particular curve is accessed X9ECParameters ecP = CustomNamedCurves.getByName(curveName); if (ecP == null) { ecP = ECNamedCurveTable.getByName(curveName); if (ecP == null) { return null; } } // It's a bit inefficient to do this conversion every time return new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed()); }