Search in sources :

Example 1 with ECPublicKeyParameters

use of org.spongycastle.crypto.params.ECPublicKeyParameters in project aion by aionnetwork.

the class ECKeySecp256k1 method verify.

/**
 * <p>
 * Verifies the given ECDSA signature against the message bytes using the
 * public key bytes.
 * </p>
 *
 * <p>
 * When using native ECDSA verification, data must be 32 bytes, and no
 * element may be larger than 520 bytes.
 * </p>
 *
 * @param data
 *            Hash of the data to verify.
 * @param signature
 *            signature.
 * @param pub
 *            The public key bytes to use.
 *
 * @return -
 */
public boolean verify(byte[] data, ECDSASignature signature, byte[] pub) {
    ECDSASigner signer = new ECDSASigner();
    ECPublicKeyParameters params = new ECPublicKeyParameters(CURVE.getCurve().decodePoint(pub), CURVE);
    signer.init(false, params);
    try {
        return signer.verifySignature(data, signature.r, signature.s);
    } catch (NullPointerException npe) {
        // Bouncy Castle contains a bug that can cause NPEs given specially
        // crafted signatures.
        // Those signatures are inherently invalid/attack sigs so we just
        // fail them here rather than crash the thread.
        logger.error("Caught NPE inside bouncy castle", npe);
        return false;
    }
}
Also used : ECDSASigner(org.spongycastle.crypto.signers.ECDSASigner) ECPublicKeyParameters(org.spongycastle.crypto.params.ECPublicKeyParameters)

Example 2 with ECPublicKeyParameters

use of org.spongycastle.crypto.params.ECPublicKeyParameters in project AppCoins-ethereumj by AppStoreFoundation.

the class ECKey method verify.

/**
 * <p>Verifies the given ECDSA signature against the message bytes using the public key bytes.</p>
 *
 * <p>When using native ECDSA verification, data must be 32 bytes, and no element may be
 * larger than 520 bytes.</p>
 *
 * @param data Hash of the data to verify.
 * @param signature signature.
 * @param pub The public key bytes to use.
 *
 * @return -
 */
public static boolean verify(byte[] data, ECDSASignature signature, byte[] pub) {
    ECDSASigner signer = new ECDSASigner();
    ECPublicKeyParameters params = new ECPublicKeyParameters(CURVE.getCurve().decodePoint(pub), CURVE);
    signer.init(false, params);
    try {
        return signer.verifySignature(data, signature.r, signature.s);
    } catch (NullPointerException npe) {
        // logger.error("Caught NPE inside bouncy castle", npe);
        return false;
    }
}
Also used : ECDSASigner(org.spongycastle.crypto.signers.ECDSASigner) ECPublicKeyParameters(org.spongycastle.crypto.params.ECPublicKeyParameters)

Example 3 with ECPublicKeyParameters

use of org.spongycastle.crypto.params.ECPublicKeyParameters in project java-tron by tronprotocol.

the class ECKey method verify.

/**
 * <p>Verifies the given ECDSA signature against the message bytes using the public key bytes.</p>
 * <p> <p>When using native ECDSA verification, data must be 32 bytes, and no element may be
 * larger than 520 bytes.</p>
 *
 * @param data Hash of the data to verify.
 * @param signature signature.
 * @param pub The public key bytes to use.
 * @return -
 */
public static boolean verify(byte[] data, ECDSASignature signature, byte[] pub) {
    ECDSASigner signer = new ECDSASigner();
    ECPublicKeyParameters params = new ECPublicKeyParameters(CURVE.getCurve().decodePoint(pub), CURVE);
    signer.init(false, params);
    try {
        return signer.verifySignature(data, signature.r, signature.s);
    } catch (NullPointerException npe) {
        // Bouncy Castle contains a bug that can cause NPEs given
        // specially crafted signatures.
        // Those signatures are inherently invalid/attack sigs so we just
        // fail them here rather than crash the thread.
        logger.error("Caught NPE inside bouncy castle", npe);
        return false;
    }
}
Also used : ECDSASigner(org.spongycastle.crypto.signers.ECDSASigner) ECPublicKeyParameters(org.spongycastle.crypto.params.ECPublicKeyParameters)

Example 4 with ECPublicKeyParameters

use of org.spongycastle.crypto.params.ECPublicKeyParameters in project toshi-android-client by toshiapp.

the class ECKey method verify.

/**
 * <p>Verifies the given ECDSA signature against the message bytes using the public key bytes.</p>
 *
 * <p>When using native ECDSA verification, data must be 32 bytes, and no element may be
 * larger than 520 bytes.</p>
 *
 * @param data Hash of the data to verify.
 * @param signature signature.
 * @param pub The public key bytes to use.
 *
 * @return -
 */
public static boolean verify(byte[] data, ECDSASignature signature, byte[] pub) {
    ECDSASigner signer = new ECDSASigner();
    ECPublicKeyParameters params = new ECPublicKeyParameters(CURVE.getCurve().decodePoint(pub), CURVE);
    signer.init(false, params);
    try {
        return signer.verifySignature(data, signature.r, signature.s);
    } catch (NullPointerException npe) {
        return false;
    }
}
Also used : ECDSASigner(org.spongycastle.crypto.signers.ECDSASigner) ECPublicKeyParameters(org.spongycastle.crypto.params.ECPublicKeyParameters)

Aggregations

ECPublicKeyParameters (org.spongycastle.crypto.params.ECPublicKeyParameters)4 ECDSASigner (org.spongycastle.crypto.signers.ECDSASigner)4