/** * Multiplies this <code>ECPoint</code> by the given number. * @param k The multiplicator. * @return <code>k * this</code>. */ public ECPoint multiply(BigInteger k) { return this.getCurve().getMultiplier().multiply(this, k); }
/** * Multiplies this <code>ECPoint</code> by the given number. * @param k The multiplicator. * @return <code>k * this</code>. */ public ECPoint multiply(BigInteger k) { return this.getCurve().getMultiplier().multiply(this, k); }
private BigInteger getScalarMultipleXCoord(ECPoint p, BigInteger s) { return _fixedPointMultiplier.multiply(p, s).normalize().getAffineXCoord().toBigInteger(); } }
private BigInteger getScalarMultipleXCoord(ECPoint p, BigInteger s) { return _fixedPointMultiplier.multiply(p, s).normalize().getAffineXCoord().toBigInteger(); } }
ECPoint p = basePointMultiplier.multiply(ecParams.getG(), k).normalize();
ECPoint Q = createBasePointMultiplier().multiply(params.getG(), d);
/** * Given the domain parameters this routine generates an EC key * pair in accordance with X9.62 section 5.2.1 pages 26, 27. */ public AsymmetricCipherKeyPair generateKeyPair() { BigInteger n = params.getN(); int nBitLength = n.bitLength(); int minWeight = nBitLength >>> 2; BigInteger d; for (;;) { d = BigIntegers.createRandomBigInteger(nBitLength, random); if (d.compareTo(TWO) < 0 || (d.compareTo(n) >= 0)) { continue; } if (WNafUtil.getNafWeight(d) < minWeight) { continue; } break; } ECPoint Q = createBasePointMultiplier().multiply(params.getG(), d); return new AsymmetricCipherKeyPair( new ECPublicKeyParameters(Q, params), new ECPrivateKeyParameters(d, params)); }
Fe = basePointMultiplier.multiply(ec.getG(), e).normalize().getAffineXCoord();
Fe = basePointMultiplier.multiply(ec.getG(), e).normalize().getAffineXCoord();
basePointMultiplier.multiply(ecParams.getG(), r), ecPubKey.getQ().multiply(rPrime) };
basePointMultiplier.multiply(ecParams.getG(), r), ecPubKey.getQ().multiply(rPrime) };
/** * 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]); }
/** * 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]); }
/** * 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]); }
/** * 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]); }
/** * 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]); }
/** * 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 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]); }
private byte[] encrypt(byte[] in, int inOff, int inLen) throws InvalidCipherTextException { byte[] c2 = new byte[inLen]; System.arraycopy(in, inOff, c2, 0, c2.length); ECMultiplier multiplier = createBasePointMultiplier(); byte[] c1; ECPoint kPB; do { BigInteger k = nextK(); ECPoint c1P = multiplier.multiply(ecParams.getG(), k).normalize(); c1 = c1P.getEncoded(false); kPB = ((ECPublicKeyParameters)ecKey).getQ().multiply(k).normalize(); kdf(digest, kPB, c2); } while (notEncrypted(c2, in, inOff)); byte[] c3 = new byte[digest.getDigestSize()]; addFieldElement(digest, kPB.getAffineXCoord()); digest.update(in, inOff, inLen); addFieldElement(digest, kPB.getAffineYCoord()); digest.doFinal(c3, 0); return Arrays.concatenate(c1, c2, c3); }
/** * 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]); }