Use GP 1.1.0 ECDH algorithm names 47/297247/3
authorDongsun Lee <ds73.lee@samsung.com>
Wed, 16 Aug 2023 01:01:41 +0000 (10:01 +0900)
committerDongsun Lee <ds73.lee@samsung.com>
Wed, 16 Aug 2023 08:26:38 +0000 (17:26 +0900)
- Use TEE_ALG_ECDH_PXXX(1.1.0) instead of TEE_ALG_ECDH_DERIVE_SHARED_SECRET(v1.1.1)

Change-Id: If196a4a967e3d95444c59d48dca89b6141c50d03

ta/src/cmd_exec.c

index 9ed0ece6410183054d04731911e709ca2b0b3856..f4eb5d94a9e8c152a2dab622ce9135ed33d75fab 100644 (file)
@@ -303,6 +303,17 @@ static TEE_Result KM_ToTeeEccCurve(uint32_t curve, uint32_t *id)
        return TEE_SUCCESS;
 }
 
+static TEE_Result KM_ToTeeEcdhAlgo(uint32_t curve, uint32_t *algo)
+{
+       switch(curve) {
+       case EC_NIST_P192: *algo = TEE_ALG_ECDH_P192; break;
+       case EC_NIST_P256: *algo = TEE_ALG_ECDH_P256; break;
+       case EC_NIST_P384: *algo = TEE_ALG_ECDH_P384; break;
+       default: return TEE_ERROR_BAD_PARAMETERS;
+       }
+       return TEE_SUCCESS;
+}
+
 static TEE_Result KM_ToKeyBitSize(uint32_t curve, uint32_t *bitsize)
 {
        switch(curve) {
@@ -998,6 +1009,7 @@ static TEE_Result KM_DeriveEcdhSecret(const TEE_ObjectHandle prv_key,
        TEE_ObjectHandle tmp_secret_handl = TEE_HANDLE_NULL;
        TEE_Attribute ecdhParams[2];
        uint32_t priv_curve = 0, pub_curve = 0, b = 0;
+       uint32_t ecdh_algo = 0;
        uint32_t maxKeySizeBits = 0;
 
        TEE_GetObjectInfo(prv_key, &info);
@@ -1024,6 +1036,12 @@ static TEE_Result KM_DeriveEcdhSecret(const TEE_ObjectHandle prv_key,
                return TEE_ERROR_BAD_PARAMETERS;
        }
 
+       ret = KM_ToTeeEcdhAlgo(curve, &ecdh_algo);
+       if (ret) {
+               LOG("Failed to convert curve to ecdh_algo, input = %d", curve);
+               return TEE_ERROR_BAD_PARAMETERS;
+       }
+
        ret = TEE_AllocateTransientObject(TEE_TYPE_GENERIC_SECRET, maxKeySizeBits, &tmp_secret_handl);
        if (TEE_SUCCESS != ret) {
                LOG("TEE_AllocateTransientObject has failed with=%x. key_type = %x max_key_bits_size = %u",
@@ -1048,7 +1066,7 @@ static TEE_Result KM_DeriveEcdhSecret(const TEE_ObjectHandle prv_key,
                ecdh_key = prv_key;
        }
 
-       ret = KM_CreateOperation(ecdh_key, TEE_ALG_ECDH_DERIVE_SHARED_SECRET, TEE_MODE_DERIVE, &operation);
+       ret = KM_CreateOperation(ecdh_key, ecdh_algo, TEE_MODE_DERIVE, &operation);
        if (TEE_SUCCESS != ret) {
                LOG("KM_CreateOperation() has failed with=%x", ret);
                goto clean;