public String toString() { if (this.isInfinity()) { return "INF"; } StringBuffer sb = new StringBuffer(); sb.append('('); sb.append(getRawXCoord()); sb.append(','); sb.append(getRawYCoord()); for (int i = 0; i < zs.length; ++i) { sb.append(','); sb.append(zs[i]); } sb.append(')'); return sb.toString(); }
public String toString() { if (this.isInfinity()) { return "INF"; } StringBuffer sb = new StringBuffer(); sb.append('('); sb.append(getRawXCoord()); sb.append(','); sb.append(getRawYCoord()); for (int i = 0; i < zs.length; ++i) { sb.append(','); sb.append(zs[i]); } sb.append(')'); return sb.toString(); }
public static String getAddress(ECPoint key) { String publicKey = key.getRawXCoord().toString() + key.getRawYCoord().toString(); return getAddress(publicKey); }
private CustomECPoint toCustomECPoint(ECPublicKey key) { ECPoint q = key.getQ(); return new CustomECPoint(q.getRawXCoord().toBigInteger(), q.getRawYCoord().toBigInteger()); }
protected ECPoint createScaledPoint(ECFieldElement sx, ECFieldElement sy) { return this.getCurve().createRawPoint(getRawXCoord().multiply(sx), getRawYCoord().multiply(sy), this.withCompression); }
protected ECPoint createScaledPoint(ECFieldElement sx, ECFieldElement sy) { return this.getCurve().createRawPoint(getRawXCoord().multiply(sx), getRawYCoord().multiply(sy), this.withCompression); }
public ECPoint scaleY(ECFieldElement scale) { return isInfinity() ? this : getCurve().createRawPoint(getRawXCoord(), getRawYCoord().multiply(scale), getRawZCoords(), this.withCompression); }
public ECPoint scaleX(ECFieldElement scale) { return isInfinity() ? this : getCurve().createRawPoint(getRawXCoord().multiply(scale), getRawYCoord(), getRawZCoords(), this.withCompression); }
public ECPoint scaleX(ECFieldElement scale) { return isInfinity() ? this : getCurve().createRawPoint(getRawXCoord().multiply(scale), getRawYCoord(), getRawZCoords(), this.withCompression); }
public ECPoint scaleY(ECFieldElement scale) { return isInfinity() ? this : getCurve().createRawPoint(getRawXCoord(), getRawYCoord().multiply(scale), getRawZCoords(), this.withCompression); }
Nat256.copy(((SecP256R1FieldElement)p.getRawYCoord()).x, 0, table, pos); pos += FE_INTS;
Nat256.copy(((Curve25519FieldElement)p.getRawYCoord()).x, 0, table, pos); pos += FE_INTS;
Nat256.copy64(((SecT193FieldElement)p.getRawYCoord()).x, 0, table, pos); pos += FE_LONGS;
Nat192.copy64(((SecT163FieldElement)p.getRawYCoord()).x, 0, table, pos); pos += FE_LONGS;
public static CustomECPoint createClassicEcPublicKey(NamedGroup group, BigInteger privateKey) { if (!group.isStandardCurve()) { throw new IllegalArgumentException( "Cannot create ClassicEcPublicKey for group which is not a classic curve:" + group.name()); } ECDomainParameters ecDomainParameters = generateEcParameters(group); ECPoint ecPoint = ecDomainParameters.getG().multiply(privateKey); ecPoint = ecPoint.normalize(); if (ecPoint.isInfinity()) { // TODO ??? return new CustomECPoint(BigInteger.ZERO, BigInteger.ZERO); } return new CustomECPoint(ecPoint.getRawXCoord().toBigInteger(), ecPoint.getRawYCoord().toBigInteger()); }
private void adjustClientPublicKey(ECDHClientKeyExchangeMessage message) { byte[] serializedPoint = message.getPublicKey().getValue(); List<ECPointFormat> pointFormatList = tlsContext.getChooser().getServerSupportedPointFormats(); ECPointFormat[] formatArray = pointFormatList.toArray(new ECPointFormat[pointFormatList.size()]); NamedGroup usedGroup = tlsContext.getChooser().getSelectedNamedGroup(); ECDomainParameters ecParams = getDomainParameters(tlsContext.getChooser().getEcCurveType(), usedGroup); short[] pointFormats = ECCUtilsBCWrapper.convertPointFormats(formatArray); try { ECPublicKeyParameters clientPublicKey = TlsECCUtils.deserializeECPublicKey(pointFormats, ecParams, serializedPoint); tlsContext.setClientEcPublicKey(new CustomECPoint(clientPublicKey.getQ().getRawXCoord().toBigInteger(), clientPublicKey.getQ().getRawYCoord().toBigInteger())); } catch (IOException ex) { LOGGER.info("Could not deserialize EC point (it is possible that some of your modifications made " + "the EC point invalid)"); LOGGER.debug( "EC point that was attempted to be deserialized: " + ArrayConverter.bytesToHexString(serializedPoint), ex); } }
public static byte[] getSignature(Signature signature, ECPoint publicKey) { String publicKeyBytes = fillStr64(publicKey.getRawXCoord().toString()) + fillStr64(publicKey.getRawYCoord().toString()); return join(HexUtil.hexToBytes(signature.getSign()), HexUtil.hexToBytes(publicKeyBytes)); }
protected void setComputationPublicKey(T msg, boolean clientMode) { if (clientMode) { msg.getComputations().setPublicKey(chooser.getServerEcPublicKey().getX(), chooser.getServerEcPublicKey().getY()); } else { serializedPoint = msg.getPublicKey().getValue(); List<ECPointFormat> pointFormatList = chooser.getServerSupportedPointFormats(); ECPointFormat[] formatArray = pointFormatList.toArray(new ECPointFormat[pointFormatList.size()]); NamedGroup usedGroup = chooser.getSelectedNamedGroup(); ECDomainParameters ecParams = getDomainParameters(chooser.getEcCurveType(), usedGroup); short[] pointFormats = ECCUtilsBCWrapper.convertPointFormats(formatArray); try { ECPublicKeyParameters clientPublicKey = TlsECCUtils.deserializeECPublicKey(pointFormats, ecParams, serializedPoint); ECPoint q = clientPublicKey.getQ(); q = q.normalize(); msg.getComputations().setPublicKey(q.getRawXCoord().toBigInteger(), q.getRawYCoord().toBigInteger()); } catch (IOException ex) { throw new PreparationException("Could not deserialize EC Point: " + ArrayConverter.bytesToHexString(serializedPoint), ex); } } LOGGER.debug("Computation PublicKey: " + msg.getComputations().getPublicKey().toString()); }
@Override public void prepareAfterParse(boolean clientMode) { msg.prepareComputations(); prepareClientServerRandom(msg); NamedGroup usedGroup = chooser.getSelectedNamedGroup(); LOGGER.debug("Used Group: " + usedGroup.name()); setComputationPrivateKey(msg, clientMode); ECDomainParameters ecParams = getDomainParameters(chooser.getEcCurveType(), usedGroup); if (clientMode) { ECPoint clientPublicKey = ecParams.getG().multiply(msg.getComputations().getPrivateKey().getValue()); clientPublicKey = clientPublicKey.normalize(); if (clientPublicKey.getRawXCoord() != null && clientPublicKey.getRawYCoord() != null) { msg.getComputations().setComputedPublicKeyX(clientPublicKey.getRawXCoord().toBigInteger()); msg.getComputations().setComputedPublicKeyY(clientPublicKey.getRawYCoord().toBigInteger()); } else { LOGGER.warn("Could not compute correct public key. Using empty one instead"); msg.getComputations().setComputedPublicKeyX(BigInteger.ZERO); msg.getComputations().setComputedPublicKeyY(BigInteger.ZERO); } } setComputationPublicKey(msg, clientMode); LOGGER.debug("PublicKey used:" + msg.getComputations().getPublicKey().toString()); LOGGER.debug("PrivateKey used:" + msg.getComputations().getPrivateKey().getValue()); ECPoint publicKey = ecParams.getCurve().createPoint(msg.getComputations().getPublicKey().getX(), msg.getComputations().getPublicKey().getY()); publicKey = publicKey.normalize(); premasterSecret = computePremasterSecret(new ECPublicKeyParameters(publicKey, ecParams), new ECPrivateKeyParameters(msg.getComputations().getPrivateKey().getValue(), ecParams)); preparePremasterSecret(msg); }
protected void adjustECParameter(ECDHEServerKeyExchangeMessage message) { tlsContext.setSelectedGroup(NamedGroup.getNamedGroup(message.getNamedGroup().getValue())); // TODO avoid BC tool byte[] ecParams = ArrayConverter.concatenate(new byte[] { message.getGroupType().getValue() }, message .getNamedGroup().getValue(), ArrayConverter.intToBytes(message.getPublicKeyLength().getValue(), 1), message.getPublicKey().getValue()); InputStream is = new ByteArrayInputStream(ecParams); ECPublicKeyParameters publicKeyParameters = null; try { publicKeyParameters = ECCUtilsBCWrapper.readECParametersWithPublicKey(is); } catch (TlsFatalAlert alert) { throw new AdjustmentException("Problematic EC parameters, we dont support these yet", alert); } catch (IOException ex) { throw new AdjustmentException("EC public key parsing failed", ex); } CustomECPoint publicKey = new CustomECPoint(publicKeyParameters.getQ().getRawXCoord().toBigInteger(), publicKeyParameters.getQ().getRawYCoord().toBigInteger()); tlsContext.setServerEcPublicKey(publicKey); } }