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

io.gatling.recorder.internal.bouncycastle.crypto.constraints.ConstraintUtils Maven / Gradle / Ivy

There is a newer version: 1.78.1
Show newest version
package io.gatling.recorder.internal.bouncycastle.crypto.constraints;

import java.math.BigInteger;

import io.gatling.recorder.internal.bouncycastle.math.ec.ECCurve;

public class ConstraintUtils
{
    /**
     * Return the bits of security for the passed in RSA modulus or DH/DSA group value.
     *
     * @param p a modulus or group value
     * @return the security strength in bits.
     */
    public static int bitsOfSecurityFor(BigInteger p)
    {
        return bitsOfSecurityForFF(p.bitLength());
    }

    /**
     * Return the bits of security for the passed in Elliptic Curve.
     *
     * @param curve the ECCurve of interest.
     * @return the security strength in bits.
     */
    public static int bitsOfSecurityFor(ECCurve curve)
    {
        int sBits = (curve.getFieldSize() + 1) / 2;

        return (sBits > 256) ? 256 : sBits;
    }

    public static int bitsOfSecurityForFF(int strength)
    {
        if (strength >= 2048)
        {
            return (strength >= 3072) ?
                        ((strength >= 7680) ?
                            ((strength >= 15360) ? 256
                            : 192)
                        : 128)
                   : 112;
        }

        return (strength >= 1024) ? 80 : 20;      // TODO: possibly a bit harsh...
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy