Java Code Examples for sun.security.util.ArrayUtil#reverse()
The following examples show how to use
sun.security.util.ArrayUtil#reverse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ECDHKeyAgreement.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static void validate(ECOperations ops, ECPublicKey key) { // ensure that integers are in proper range BigInteger x = key.getW().getAffineX(); BigInteger y = key.getW().getAffineY(); BigInteger p = ops.getField().getSize(); validateCoordinate(x, p); validateCoordinate(y, p); // ensure the point is on the curve EllipticCurve curve = key.getParams().getCurve(); BigInteger rhs = x.modPow(BigInteger.valueOf(3), p).add(curve.getA() .multiply(x)).add(curve.getB()).mod(p); BigInteger lhs = y.modPow(BigInteger.valueOf(2), p).mod(p); if (!rhs.equals(lhs)) { throw new ProviderException("point is not on curve"); } // check the order of the point ImmutableIntegerModuloP xElem = ops.getField().getElement(x); ImmutableIntegerModuloP yElem = ops.getField().getElement(y); AffinePoint affP = new AffinePoint(xElem, yElem); byte[] order = key.getParams().getOrder().toByteArray(); ArrayUtil.reverse(order); Point product = ops.multiply(affP, order); if (!ops.isNeutral(product)) { throw new ProviderException("point has incorrect order"); } }
Example 2
Source File: ECDHKeyAgreement.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void validate(ECOperations ops, ECPublicKey key) { // ensure that integers are in proper range BigInteger x = key.getW().getAffineX(); BigInteger y = key.getW().getAffineY(); BigInteger p = ops.getField().getSize(); validateCoordinate(x, p); validateCoordinate(y, p); // ensure the point is on the curve EllipticCurve curve = key.getParams().getCurve(); BigInteger rhs = x.modPow(BigInteger.valueOf(3), p).add(curve.getA() .multiply(x)).add(curve.getB()).mod(p); BigInteger lhs = y.modPow(BigInteger.valueOf(2), p).mod(p); if (!rhs.equals(lhs)) { throw new ProviderException("point is not on curve"); } // check the order of the point ImmutableIntegerModuloP xElem = ops.getField().getElement(x); ImmutableIntegerModuloP yElem = ops.getField().getElement(y); AffinePoint affP = new AffinePoint(xElem, yElem); byte[] order = key.getParams().getOrder().toByteArray(); ArrayUtil.reverse(order); Point product = ops.multiply(affP, order); if (!ops.isNeutral(product)) { throw new ProviderException("point has incorrect order"); } }
Example 3
Source File: ECDHKeyAgreement.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void validate(ECOperations ops, ECPublicKey key) { // ensure that integers are in proper range BigInteger x = key.getW().getAffineX(); BigInteger y = key.getW().getAffineY(); BigInteger p = ops.getField().getSize(); validateCoordinate(x, p); validateCoordinate(y, p); // ensure the point is on the curve EllipticCurve curve = key.getParams().getCurve(); BigInteger rhs = x.modPow(BigInteger.valueOf(3), p).add(curve.getA() .multiply(x)).add(curve.getB()).mod(p); BigInteger lhs = y.modPow(BigInteger.valueOf(2), p).mod(p); if (!rhs.equals(lhs)) { throw new ProviderException("point is not on curve"); } // check the order of the point ImmutableIntegerModuloP xElem = ops.getField().getElement(x); ImmutableIntegerModuloP yElem = ops.getField().getElement(y); AffinePoint affP = new AffinePoint(xElem, yElem); byte[] order = key.getParams().getOrder().toByteArray(); ArrayUtil.reverse(order); Point product = ops.multiply(affP, order); if (!ops.isNeutral(product)) { throw new ProviderException("point has incorrect order"); } }
Example 4
Source File: ECDHKeyAgreement.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static void validate(ECOperations ops, ECPublicKey key) { // ensure that integers are in proper range BigInteger x = key.getW().getAffineX(); BigInteger y = key.getW().getAffineY(); BigInteger p = ops.getField().getSize(); validateCoordinate(x, p); validateCoordinate(y, p); // ensure the point is on the curve EllipticCurve curve = key.getParams().getCurve(); BigInteger rhs = x.modPow(BigInteger.valueOf(3), p).add(curve.getA() .multiply(x)).add(curve.getB()).mod(p); BigInteger lhs = y.modPow(BigInteger.valueOf(2), p).mod(p); if (!rhs.equals(lhs)) { throw new ProviderException("point is not on curve"); } // check the order of the point ImmutableIntegerModuloP xElem = ops.getField().getElement(x); ImmutableIntegerModuloP yElem = ops.getField().getElement(y); AffinePoint affP = new AffinePoint(xElem, yElem); byte[] order = key.getParams().getOrder().toByteArray(); ArrayUtil.reverse(order); Point product = ops.multiply(affP, order); if (!ops.isNeutral(product)) { throw new ProviderException("point has incorrect order"); } }
Example 5
Source File: ECDHKeyAgreement.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
private static Optional<byte[]> deriveKeyImpl(ECPrivateKey priv, ECPublicKey pubKey) { ECParameterSpec ecSpec = priv.getParams(); EllipticCurve curve = ecSpec.getCurve(); Optional<ECOperations> opsOpt = ECOperations.forParameters(ecSpec); if (!opsOpt.isPresent()) { return Optional.empty(); } ECOperations ops = opsOpt.get(); if (! (priv instanceof ECPrivateKeyImpl)) { return Optional.empty(); } ECPrivateKeyImpl privImpl = (ECPrivateKeyImpl) priv; byte[] sArr = privImpl.getArrayS(); // to match the native implementation, validate the public key here // and throw ProviderException if it is invalid validate(ops, pubKey); IntegerFieldModuloP field = ops.getField(); // convert s array into field element and multiply by the cofactor MutableIntegerModuloP scalar = field.getElement(sArr).mutable(); SmallValue cofactor = field.getSmallValue(priv.getParams().getCofactor()); scalar.setProduct(cofactor); int keySize = (curve.getField().getFieldSize() + 7) / 8; byte[] privArr = scalar.asByteArray(keySize); ImmutableIntegerModuloP x = field.getElement(pubKey.getW().getAffineX()); ImmutableIntegerModuloP y = field.getElement(pubKey.getW().getAffineY()); AffinePoint affPub = new AffinePoint(x, y); Point product = ops.multiply(affPub, privArr); if (ops.isNeutral(product)) { throw new ProviderException("Product is zero"); } AffinePoint affProduct = product.asAffine(); byte[] result = affProduct.getX().asByteArray(keySize); ArrayUtil.reverse(result); return Optional.of(result); }
Example 6
Source File: ECDHKeyAgreement.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private static Optional<byte[]> deriveKeyImpl(ECPrivateKey priv, ECPublicKey pubKey) { ECParameterSpec ecSpec = priv.getParams(); EllipticCurve curve = ecSpec.getCurve(); Optional<ECOperations> opsOpt = ECOperations.forParameters(ecSpec); if (!opsOpt.isPresent()) { return Optional.empty(); } ECOperations ops = opsOpt.get(); if (! (priv instanceof ECPrivateKeyImpl)) { return Optional.empty(); } ECPrivateKeyImpl privImpl = (ECPrivateKeyImpl) priv; byte[] sArr = privImpl.getArrayS(); // to match the native implementation, validate the public key here // and throw ProviderException if it is invalid validate(ops, pubKey); IntegerFieldModuloP field = ops.getField(); // convert s array into field element and multiply by the cofactor MutableIntegerModuloP scalar = field.getElement(sArr).mutable(); SmallValue cofactor = field.getSmallValue(priv.getParams().getCofactor()); scalar.setProduct(cofactor); int keySize = (curve.getField().getFieldSize() + 7) / 8; byte[] privArr = scalar.asByteArray(keySize); ImmutableIntegerModuloP x = field.getElement(pubKey.getW().getAffineX()); ImmutableIntegerModuloP y = field.getElement(pubKey.getW().getAffineY()); AffinePoint affPub = new AffinePoint(x, y); Point product = ops.multiply(affPub, privArr); if (ops.isNeutral(product)) { throw new ProviderException("Product is zero"); } AffinePoint affProduct = product.asAffine(); byte[] result = affProduct.getX().asByteArray(keySize); ArrayUtil.reverse(result); return Optional.of(result); }
Example 7
Source File: ECDHKeyAgreement.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private static Optional<byte[]> deriveKeyImpl(ECPrivateKey priv, ECPublicKey pubKey) { ECParameterSpec ecSpec = priv.getParams(); EllipticCurve curve = ecSpec.getCurve(); Optional<ECOperations> opsOpt = ECOperations.forParameters(ecSpec); if (!opsOpt.isPresent()) { return Optional.empty(); } ECOperations ops = opsOpt.get(); if (! (priv instanceof ECPrivateKeyImpl)) { return Optional.empty(); } ECPrivateKeyImpl privImpl = (ECPrivateKeyImpl) priv; byte[] sArr = privImpl.getArrayS(); // to match the native implementation, validate the public key here // and throw ProviderException if it is invalid validate(ops, pubKey); IntegerFieldModuloP field = ops.getField(); // convert s array into field element and multiply by the cofactor MutableIntegerModuloP scalar = field.getElement(sArr).mutable(); SmallValue cofactor = field.getSmallValue(priv.getParams().getCofactor()); scalar.setProduct(cofactor); int keySize = (curve.getField().getFieldSize() + 7) / 8; byte[] privArr = scalar.asByteArray(keySize); ImmutableIntegerModuloP x = field.getElement(pubKey.getW().getAffineX()); ImmutableIntegerModuloP y = field.getElement(pubKey.getW().getAffineY()); AffinePoint affPub = new AffinePoint(x, y); Point product = ops.multiply(affPub, privArr); if (ops.isNeutral(product)) { throw new ProviderException("Product is zero"); } AffinePoint affProduct = product.asAffine(); byte[] result = affProduct.getX().asByteArray(keySize); ArrayUtil.reverse(result); return Optional.of(result); }
Example 8
Source File: ECDHKeyAgreement.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private static Optional<byte[]> deriveKeyImpl(ECPrivateKey priv, ECPublicKey pubKey) { ECParameterSpec ecSpec = priv.getParams(); EllipticCurve curve = ecSpec.getCurve(); Optional<ECOperations> opsOpt = ECOperations.forParameters(ecSpec); if (!opsOpt.isPresent()) { return Optional.empty(); } ECOperations ops = opsOpt.get(); if (! (priv instanceof ECPrivateKeyImpl)) { return Optional.empty(); } ECPrivateKeyImpl privImpl = (ECPrivateKeyImpl) priv; byte[] sArr = privImpl.getArrayS(); // to match the native implementation, validate the public key here // and throw ProviderException if it is invalid validate(ops, pubKey); IntegerFieldModuloP field = ops.getField(); // convert s array into field element and multiply by the cofactor MutableIntegerModuloP scalar = field.getElement(sArr).mutable(); SmallValue cofactor = field.getSmallValue(priv.getParams().getCofactor()); scalar.setProduct(cofactor); int keySize = (curve.getField().getFieldSize() + 7) / 8; byte[] privArr = scalar.asByteArray(keySize); ImmutableIntegerModuloP x = field.getElement(pubKey.getW().getAffineX()); ImmutableIntegerModuloP y = field.getElement(pubKey.getW().getAffineY()); AffinePoint affPub = new AffinePoint(x, y); Point product = ops.multiply(affPub, privArr); if (ops.isNeutral(product)) { throw new ProviderException("Product is zero"); } AffinePoint affProduct = product.asAffine(); byte[] result = affProduct.getX().asByteArray(keySize); ArrayUtil.reverse(result); return Optional.of(result); }