Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 33454dd5 authored by Alex Klyubin's avatar Alex Klyubin
Browse files

No need to specify EC curve name in EcIesParameterSpec.

EC curve parameters will be obtained from the provided EC key.

Bug: 18088752
Change-Id: Ic99353a6566c8d4ce2b6b73d0309edaa40f84fa6
parent d1af38a4
Loading
Loading
Loading
Loading
+2 −25
Original line number Original line Diff line number Diff line
@@ -85,11 +85,10 @@ public class EcIesParameterSpec implements AlgorithmParameterSpec {
    }
    }


    /**
    /**
     * Default parameter spec: NIST P-256 curve (aka secp256r1 aka prime256v1), compressed point
     * Default parameter spec: compressed point format, {@code HKDFwithSHA256}, DEM uses 128-bit AES
     * format, {@code HKDFwithSHA256}, DEM uses 128-bit AES GCM.
     * GCM.
     */
     */
    public static final EcIesParameterSpec DEFAULT = new EcIesParameterSpec(
    public static final EcIesParameterSpec DEFAULT = new EcIesParameterSpec(
            "P-256",
            PointFormat.COMPRESSED,
            PointFormat.COMPRESSED,
            "HKDFwithSHA256",
            "HKDFwithSHA256",
            "AES/GCM/NoPadding",
            "AES/GCM/NoPadding",
@@ -97,7 +96,6 @@ public class EcIesParameterSpec implements AlgorithmParameterSpec {
            null,
            null,
            0);
            0);


    private final String mKemCurveName;
    private final @PointFormatEnum int mKemPointFormat;
    private final @PointFormatEnum int mKemPointFormat;
    private final String mKemKdfAlgorithm;
    private final String mKemKdfAlgorithm;
    private final String mDemCipherTransformation;
    private final String mDemCipherTransformation;
@@ -106,14 +104,12 @@ public class EcIesParameterSpec implements AlgorithmParameterSpec {
    private final int mDemMacKeySize;
    private final int mDemMacKeySize;


    private EcIesParameterSpec(
    private EcIesParameterSpec(
            String kemCurveName,
            @PointFormatEnum int kemPointFormat,
            @PointFormatEnum int kemPointFormat,
            String kemKdfAlgorithm,
            String kemKdfAlgorithm,
            String demCipherTransformation,
            String demCipherTransformation,
            int demCipherKeySize,
            int demCipherKeySize,
            String demMacAlgorithm,
            String demMacAlgorithm,
            int demMacKeySize) {
            int demMacKeySize) {
        mKemCurveName = kemCurveName;
        mKemPointFormat = kemPointFormat;
        mKemPointFormat = kemPointFormat;
        mKemKdfAlgorithm = kemKdfAlgorithm;
        mKemKdfAlgorithm = kemKdfAlgorithm;
        mDemCipherTransformation = demCipherTransformation;
        mDemCipherTransformation = demCipherTransformation;
@@ -122,13 +118,6 @@ public class EcIesParameterSpec implements AlgorithmParameterSpec {
        mDemMacKeySize = demMacKeySize;
        mDemMacKeySize = demMacKeySize;
    }
    }


    /**
     * Returns KEM EC curve name (e.g., {@code secp256r1}) or {@code null} if not specified.
     */
    public String getKemCurveName() {
        return mKemCurveName;
    }

    /**
    /**
     * Returns KEM EC point wire format or {@link PointFormat#UNSPECIFIED} if not specified.
     * Returns KEM EC point wire format or {@link PointFormat#UNSPECIFIED} if not specified.
     */
     */
@@ -188,7 +177,6 @@ public class EcIesParameterSpec implements AlgorithmParameterSpec {
     * Builder of {@link EcIesParameterSpec}.
     * Builder of {@link EcIesParameterSpec}.
     */
     */
    public static class Builder {
    public static class Builder {
        private String mKemCurveName;
        private @PointFormatEnum int mKemPointFormat = PointFormat.UNSPECIFIED;
        private @PointFormatEnum int mKemPointFormat = PointFormat.UNSPECIFIED;
        private String mKemKdfAlgorithm;
        private String mKemKdfAlgorithm;
        private String mDemCipherTransformation;
        private String mDemCipherTransformation;
@@ -196,16 +184,6 @@ public class EcIesParameterSpec implements AlgorithmParameterSpec {
        private String mDemMacAlgorithm;
        private String mDemMacAlgorithm;
        private int mDemMacKeySize = -1;
        private int mDemMacKeySize = -1;


        /**
         * Sets KEM EC curve name. For example, {@code P-256} or {@code secp256r1}.
         *
         * <p>NOTE: Only curves with cofactor of {@code 1} are supported.
         */
        public Builder setKemCurveName(String name) {
            mKemCurveName = name;
            return this;
        }

        /**
        /**
         * Sets KEM EC point wire format.
         * Sets KEM EC point wire format.
         */
         */
@@ -274,7 +252,6 @@ public class EcIesParameterSpec implements AlgorithmParameterSpec {
        public EcIesParameterSpec build() {
        public EcIesParameterSpec build() {
            int demMacKeySize = (mDemMacKeySize != -1) ? mDemMacKeySize : mDemCipherKeySize;
            int demMacKeySize = (mDemMacKeySize != -1) ? mDemMacKeySize : mDemCipherKeySize;
            return new EcIesParameterSpec(
            return new EcIesParameterSpec(
                    mKemCurveName,
                    mKemPointFormat,
                    mKemPointFormat,
                    mKemKdfAlgorithm,
                    mKemKdfAlgorithm,
                    mDemCipherTransformation,
                    mDemCipherTransformation,