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

Commit ec83644f authored by Tommy Chiu's avatar Tommy Chiu
Browse files

Specify EcCurve when generating keys

EC_CURVE is a mandatory tag which is specified in the keymint HAL when
generating EC keys.

Bug: 232056693
Change-Id: Ibe2b85744d7e555b7c7b48aa9e57ce45bb19ef89
parent 0ba85312
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -142,6 +142,25 @@ class KeyMintBenchmarkTest {
        return Digest::NONE;
    }

    optional<EcCurve> getCurveFromLength(int keySize) {
        switch (keySize) {
            case 224:
                return EcCurve::P_224;
                break;
            case 256:
                return EcCurve::P_256;
                break;
            case 384:
                return EcCurve::P_384;
                break;
            case 521:
                return EcCurve::P_521;
                break;
            default:
                return {};
        }
    }

    bool GenerateKey(string transform, int keySize, bool sign = false) {
        if (transform == key_transform_) {
            return true;
@@ -184,6 +203,12 @@ class KeyMintBenchmarkTest {
        }
        if (algorithm == Algorithm::EC) {
            authSet.SetDefaultValidity();
            std::optional<EcCurve> curve = getCurveFromLength(keySize);
            if (!curve) {
                std::cerr << "Error: invalid EC-Curve from size " << keySize << std::endl;
                return false;
            }
            authSet.Authorization(TAG_EC_CURVE, curve.value());
        }
        error_ = GenerateKey(authSet);
        return error_ == ErrorCode::OK;