All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.jcajce.provider.ECUtil Maven / Gradle / Ivy

Go to download

The FIPS 140-3 Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms certified to FIPS 140-3 level 1. This jar contains JCE provider and low-level API for the BC-FJA version 2.0.0, FIPS Certificate #4743. Please see certificate for certified platform details.

There is a newer version: 2.0.0
Show newest version
package org.bouncycastle.jcajce.provider;

import java.security.spec.ECParameterSpec;
import java.security.spec.ECPoint;

import org.bouncycastle.crypto.asymmetric.ECDomainParameters;
import org.bouncycastle.crypto.asymmetric.ECImplicitDomainParameters;
import org.bouncycastle.jcajce.spec.ECDomainParameterSpec;
import org.bouncycastle.jcajce.spec.ECImplicitDomainParameterSpec;
import org.bouncycastle.math.ec.ECCurve;

class ECUtil
{
    public static ECParameterSpec convertToSpec(
        ECDomainParameters domainParameters)
    {
        if (domainParameters instanceof ECImplicitDomainParameters)
        {
            return new ECImplicitDomainParameterSpec((ECImplicitDomainParameters)domainParameters);
        }

        return new ECDomainParameterSpec(domainParameters);
    }

    public static ECDomainParameters convertFromSpec(
        ECParameterSpec ecSpec)
    {
        ECDomainParameters domainParameters;
        if (ecSpec instanceof ECDomainParameterSpec)
        {
            domainParameters = ((ECDomainParameterSpec)ecSpec).getDomainParameters();
        }
        else
        {
            domainParameters = new ECDomainParameterSpec(ecSpec).getDomainParameters();
        }

        if (ecSpec instanceof ECImplicitDomainParameterSpec)
        {
            return new ECImplicitDomainParameters(domainParameters);
        }

        return domainParameters;
    }

    public static org.bouncycastle.math.ec.ECPoint convertPoint(
        ECParameterSpec ecSpec,
        ECPoint point)
    {
        return convertPoint(convertFromSpec(ecSpec).getCurve(), point);
    }

    public static org.bouncycastle.math.ec.ECPoint convertPoint(
        ECCurve curve,
        ECPoint point)
    {
        return curve.validatePoint(point.getAffineX(), point.getAffineY());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy