diff --git a/ta/crypto_perf/include/ta_crypto_perf.h b/ta/crypto_perf/include/ta_crypto_perf.h index ba47efa5c..e67b3caf5 100644 --- a/ta/crypto_perf/include/ta_crypto_perf.h +++ b/ta/crypto_perf/include/ta_crypto_perf.h @@ -13,11 +13,19 @@ * Commands implemented by the TA */ -#define TA_CRYPTO_PERF_CMD_CIPHER_PREPARE_KEY 0 -#define TA_CRYPTO_PERF_CMD_CIPHER_PROCESS 1 -#define TA_CRYPTO_PERF_CMD_CIPHER_PROCESS_SDP 2 -#define TA_CRYPTO_PERF_CMD_HASH_PREPARE_OP 3 -#define TA_CRYPTO_PERF_CMD_HASH_PROCESS 4 +#define TA_CRYPTO_PERF_CMD_CIPHER_PREPARE_KEY 0 +#define TA_CRYPTO_PERF_CMD_CIPHER_PROCESS 1 +#define TA_CRYPTO_PERF_CMD_CIPHER_PROCESS_SDP 2 +#define TA_CRYPTO_PERF_CMD_HASH_PREPARE_OP 3 +#define TA_CRYPTO_PERF_CMD_HASH_PROCESS 4 +#define TA_CRYPTO_PERF_CMD_ASYM_PREPARE_OBJ 5 +#define TA_CRYPTO_PERF_CMD_ASYM_PREPARE_HASH 6 +#define TA_CRYPTO_PERF_CMD_ASYM_PREPARE_KEYPAIR 7 +#define TA_CRYPTO_PERF_CMD_ASYM_PREPARE_ENC_SIGN 8 +#define TA_CRYPTO_PERF_CMD_ASYM_PREPARE_ATTRS 9 +#define TA_CRYPTO_PERF_CMD_ASYM_PROCESS_GEN_KEYPAIR 10 +#define TA_CRYPTO_PERF_CMD_ASYM_PROCESS 11 +#define TA_CRYPTO_PERF_CMD_ASYM_FREE_ATTRS 12 /* * Supported AES modes of operation @@ -53,4 +61,70 @@ #define TA_HMAC_SHA512 10 #define TA_HMAC_SM3 11 +/* + * Asymmetric cryptographic algorithms + */ +#define PKCS_V1_5_MIN 11 +#define BITS_TO_BYTES(len) (((len) + 7) / 8) +#define OAEP_HASH_LEN(hsz) ((hsz) * 2) +#define OAEP_OTHER_LEN 2 +#define PSS_OTHER_LEN 2 + +#define DERCODE_SHA1_LEN 15 +#define DERCODE_SHA_LEN 19 +#define SHA1_LEN 20 +#define SHA224_LEN 28 +#define SHA256_LEN 32 +#define SHA384_LEN 48 +#define SHA512_LEN 64 + +#define WIDTH_BITS_25519 256 + +#define ECC_CURVE_192 192 +#define ECC_CURVE_224 224 +#define ECC_CURVE_256 256 +#define ECC_CURVE_384 384 +#define ECC_CURVE_521 521 + +#define TEE_MAX_OUT_SIZE 4096 + +#define DH_MAX_SIZE 4096 +#define DH_G_SIZE 1 + +enum asym_algorithm { + ALGO_DH = 1, + ALGO_RSA = 2, + ALGO_ECDSA = 3, + ALGO_ECDH = 4, + ALGO_X25519 = 5, +}; + +enum asym_cipher_mode { + MODE_ENCRYPT = 0, + MODE_DECRYPT = 1, + MODE_SIGN = 2, + MODE_VERIFY = 3, + MODE_GENKEYPAIR = 4, +}; + +enum rsa_mode { + RSA_NOPAD = 0, + RSAES_PKCS1_V1_5 = 1, + RSAES_PKCS1_OAEP_SHA1 = 2, + RSAES_PKCS1_OAEP_SHA224 = 3, + RSAES_PKCS1_OAEP_SHA256 = 4, + RSAES_PKCS1_OAEP_SHA384 = 5, + RSAES_PKCS1_OAEP_SHA512 = 6, + RSASSA_PKCS1_V1_5_SHA1 = 7, + RSASSA_PKCS1_V1_5_SHA224 = 8, + RSASSA_PKCS1_V1_5_SHA256 = 9, + RSASSA_PKCS1_V1_5_SHA384 = 10, + RSASSA_PKCS1_V1_5_SHA512 = 11, + RSASSA_PKCS1_PSS_MGF1_SHA1 = 12, + RSASSA_PKCS1_PSS_MGF1_SHA224 = 13, + RSASSA_PKCS1_PSS_MGF1_SHA256 = 14, + RSASSA_PKCS1_PSS_MGF1_SHA384 = 15, + RSASSA_PKCS1_PSS_MGF1_SHA512 = 16, +}; + #endif /* TA_CRYPTO_PERF_H */ diff --git a/ta/crypto_perf/include/ta_crypto_perf_priv.h b/ta/crypto_perf/include/ta_crypto_perf_priv.h index c8595377d..5959cc278 100644 --- a/ta/crypto_perf/include/ta_crypto_perf_priv.h +++ b/ta/crypto_perf/include/ta_crypto_perf_priv.h @@ -13,6 +13,15 @@ TEE_Result cmd_cipher_process(uint32_t param_types, TEE_Param params[4], bool sdp); TEE_Result cmd_hash_prepare_op(uint32_t param_types, TEE_Param params[4]); TEE_Result cmd_hash_process(uint32_t param_types, TEE_Param params[4]); +TEE_Result cmd_asym_process_keypair(uint32_t param_types, TEE_Param params[4]); +TEE_Result cmd_asym_process_rsa_ecc(uint32_t param_types, TEE_Param params[4]); +TEE_Result cmd_asym_prepare_obj(uint32_t param_types, TEE_Param params[4]); +TEE_Result cmd_asym_prepare_keypair(uint32_t param_types, TEE_Param params[4]); +TEE_Result cmd_asym_prepare_hash(uint32_t param_types, TEE_Param params[4]); +TEE_Result cmd_asym_prepare_enc_sign(uint32_t param_types, TEE_Param params[4]); +TEE_Result cmd_asym_prepare_attrs(uint32_t param_types, TEE_Param params[4]); +TEE_Result cmd_asym_free_attrs(uint32_t param_types, TEE_Param params[4]); +void cmd_clean_obj(void); void cmd_clean_res(void); #endif /* TA_CRYPTO_PERF_PRIV_H */ diff --git a/ta/crypto_perf/ta_crypto_perf.c b/ta/crypto_perf/ta_crypto_perf.c index 6f60eb93b..6d01b7fd9 100644 --- a/ta/crypto_perf/ta_crypto_perf.c +++ b/ta/crypto_perf/ta_crypto_perf.c @@ -29,6 +29,11 @@ static int use_iv; static TEE_OperationHandle crypto_op; static uint32_t algo; +static TEE_OperationHandle crypto_op_enc_sign = TEE_HANDLE_NULL; +static TEE_ObjectHandle crypto_obj = TEE_HANDLE_NULL; +static TEE_Attribute *asym_perf_attrs; +static uint32_t asym_perf_attr_count; +static uint8_t *crypto_buf; static bool is_inbuf_a_secure_memref(TEE_Param *param) { @@ -465,8 +470,504 @@ TEE_Result cmd_hash_prepare_op(uint32_t param_types, TEE_Param params[4]) return TEE_SUCCESS; } +struct attr_packed { + uint32_t id; + uint32_t a; + uint32_t b; +}; + +static TEE_Result unpack_attrs(const uint8_t *buf, size_t blen, + TEE_Attribute **attrs, uint32_t *attr_count) +{ + TEE_Result res = TEE_SUCCESS; + TEE_Attribute *a = NULL; + const struct attr_packed *ap = NULL; + size_t num_attrs = 0; + const size_t num_attrs_size = sizeof(uint32_t); + + if (blen == 0) + goto out; + + if (!IS_ALIGNED_WITH_TYPE(buf, uint32_t) || blen < num_attrs_size) + return TEE_ERROR_BAD_PARAMETERS; + num_attrs = *(uint32_t *)(void *)buf; + if ((blen - num_attrs_size) < (num_attrs * sizeof(*ap))) + return TEE_ERROR_BAD_PARAMETERS; + ap = (const struct attr_packed *)(const void *)(buf + num_attrs_size); + + if (num_attrs > 0) { + size_t n = 0; + + a = TEE_Malloc(num_attrs * sizeof(TEE_Attribute), 0); + if (!a) + return TEE_ERROR_OUT_OF_MEMORY; + for (n = 0; n < num_attrs; n++) { + uintptr_t p = 0; + + a[n].attributeID = ap[n].id; + if (ap[n].id & TEE_ATTR_FLAG_VALUE) { + a[n].content.value.a = ap[n].a; + a[n].content.value.b = ap[n].b; + continue; + } + + a[n].content.ref.length = ap[n].b; + p = (uintptr_t)ap[n].a; + if (p) { + if ((p + a[n].content.ref.length) > blen) { + res = TEE_ERROR_BAD_PARAMETERS; + goto out; + } + p += (uintptr_t)buf; + } + a[n].content.ref.buffer = (void *)p; + } + } + +out: + if (res == TEE_SUCCESS) { + *attrs = a; + *attr_count = num_attrs; + } else { + TEE_Free(a); + } + return res; +} + +static TEE_Result get_rsa_cipher_algo(uint32_t algo_type) +{ + switch (algo_type) { + case RSA_NOPAD: + algo = TEE_ALG_RSA_NOPAD; + break; + case RSAES_PKCS1_V1_5: + algo = TEE_ALG_RSAES_PKCS1_V1_5; + break; + case RSAES_PKCS1_OAEP_SHA1: + algo = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1; + break; + case RSAES_PKCS1_OAEP_SHA224: + algo = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA224; + break; + case RSAES_PKCS1_OAEP_SHA256: + algo = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA256; + break; + case RSAES_PKCS1_OAEP_SHA384: + algo = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA384; + break; + case RSAES_PKCS1_OAEP_SHA512: + algo = TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA512; + break; + default: + EMSG("RSA enc or dec error algo_type"); + return TEE_ERROR_BAD_PARAMETERS; + } + + return TEE_SUCCESS; +} + +static TEE_Result get_rsa_hash_algo(uint32_t algo_type) +{ + switch (algo_type) { + case RSASSA_PKCS1_V1_5_SHA1: + algo = TEE_ALG_RSASSA_PKCS1_V1_5_SHA1; + break; + case RSASSA_PKCS1_V1_5_SHA224: + algo = TEE_ALG_RSASSA_PKCS1_V1_5_SHA224; + break; + case RSASSA_PKCS1_V1_5_SHA256: + algo = TEE_ALG_RSASSA_PKCS1_V1_5_SHA256; + break; + case RSASSA_PKCS1_V1_5_SHA384: + algo = TEE_ALG_RSASSA_PKCS1_V1_5_SHA384; + break; + case RSASSA_PKCS1_V1_5_SHA512: + algo = TEE_ALG_RSASSA_PKCS1_V1_5_SHA512; + break; + case RSASSA_PKCS1_PSS_MGF1_SHA1: + algo = TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA1; + break; + case RSASSA_PKCS1_PSS_MGF1_SHA224: + algo = TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA224; + break; + case RSASSA_PKCS1_PSS_MGF1_SHA256: + algo = TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256; + break; + case RSASSA_PKCS1_PSS_MGF1_SHA384: + algo = TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA384; + break; + case RSASSA_PKCS1_PSS_MGF1_SHA512: + algo = TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA512; + break; + default: + EMSG("RSA sign or verify error algo_type"); + return TEE_ERROR_BAD_PARAMETERS; + } + + return TEE_SUCCESS; +} + +static TEE_Result get_ecdsa_hash_algo(uint32_t width_bits) +{ + switch (width_bits) { + case ECC_CURVE_192: + algo = __OPTEE_ALG_ECDSA_P192; + break; + case ECC_CURVE_224: + algo = __OPTEE_ALG_ECDSA_P224; + break; + case ECC_CURVE_256: + algo = __OPTEE_ALG_ECDSA_P256; + break; + case ECC_CURVE_384: + algo = __OPTEE_ALG_ECDSA_P384; + break; + case ECC_CURVE_521: + algo = __OPTEE_ALG_ECDSA_P521; + break; + default: + EMSG("ECDSA sign or verify error width_bits"); + return TEE_ERROR_BAD_PARAMETERS; + } + + return TEE_SUCCESS; +} + +static TEE_Result get_algo(uint32_t tee_type, uint32_t mode, + uint32_t width_bits, uint32_t algo_type) +{ + TEE_Result res = TEE_SUCCESS; + + if (tee_type == ALGO_RSA) { + if (mode == MODE_ENCRYPT || mode == MODE_DECRYPT) { + res = get_rsa_cipher_algo(algo_type); + } else if (mode == MODE_SIGN || mode == MODE_VERIFY) { + res = get_rsa_hash_algo(algo_type); + } else { + EMSG("RSA error mode"); + res = TEE_ERROR_BAD_PARAMETERS; + } + } else if (tee_type == ALGO_ECDSA) { + if (mode == MODE_SIGN || mode == MODE_VERIFY) { + res = get_ecdsa_hash_algo(width_bits); + } else { + EMSG("ECDSA error mode"); + res = TEE_ERROR_BAD_PARAMETERS; + } + } else { + res = TEE_ERROR_BAD_PARAMETERS; + } + + return res; +} + +static uint32_t get_keypair_type(uint32_t value) +{ + switch (value) { + case ALGO_DH: + return TEE_TYPE_DH_KEYPAIR; + case ALGO_RSA: + return TEE_TYPE_RSA_KEYPAIR; + case ALGO_ECDSA: + return TEE_TYPE_ECDSA_KEYPAIR; + case ALGO_ECDH: + return TEE_TYPE_ECDH_KEYPAIR; + case ALGO_X25519: + return TEE_TYPE_X25519_KEYPAIR; + default: + EMSG("The algo[%"PRIu32"] is not valid", value); + return TEE_TYPE_ILLEGAL_VALUE; + } +} + +TEE_Result cmd_asym_prepare_attrs(uint32_t param_types, + TEE_Param params[TEE_NUM_PARAMS]) +{ + uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INOUT, + TEE_PARAM_TYPE_NONE, + TEE_PARAM_TYPE_NONE, + TEE_PARAM_TYPE_NONE); + + if (param_types != exp_param_types) + return TEE_ERROR_BAD_PARAMETERS; + + crypto_buf = TEE_Malloc(params[0].memref.size, 0); + memcpy(crypto_buf, params[0].memref.buffer, params[0].memref.size); + + return unpack_attrs(crypto_buf, params[0].memref.size, + &asym_perf_attrs, &asym_perf_attr_count); +} + +TEE_Result cmd_asym_free_attrs(uint32_t param_types, + TEE_Param params[TEE_NUM_PARAMS]) +{ + uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_NONE, + TEE_PARAM_TYPE_NONE, + TEE_PARAM_TYPE_NONE, + TEE_PARAM_TYPE_NONE); + + if (param_types != exp_param_types) + return TEE_ERROR_BAD_PARAMETERS; + + TEE_Free(asym_perf_attrs); + asym_perf_attrs = NULL; + TEE_Free(crypto_buf); + crypto_buf = NULL; + + return TEE_SUCCESS; +} + +TEE_Result cmd_asym_process_keypair(uint32_t param_types, + TEE_Param params[TEE_NUM_PARAMS]) +{ + TEE_Result res = TEE_ERROR_GENERIC; + int width_bits = 0; + int n = 0; + uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT, + TEE_PARAM_TYPE_NONE, + TEE_PARAM_TYPE_NONE, + TEE_PARAM_TYPE_NONE); + + if (param_types != exp_param_types) + return TEE_ERROR_BAD_PARAMETERS; + + width_bits = params[0].value.a; + n = params[0].value.b; + + while (n--) { + res = TEE_GenerateKey(crypto_obj, width_bits, asym_perf_attrs, asym_perf_attr_count); + CHECK(res, "TEE_GenerateKey()", goto out;); + TEE_ResetTransientObject(crypto_obj); + } + +out: + return res; +} + +TEE_Result cmd_asym_process_rsa_ecc(uint32_t param_types, + TEE_Param params[TEE_NUM_PARAMS]) +{ + TEE_Result res = TEE_ERROR_GENERIC; + int n = 0; + uint32_t mode = 0; + uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT, + TEE_PARAM_TYPE_MEMREF_INPUT, + TEE_PARAM_TYPE_MEMREF_OUTPUT, + TEE_PARAM_TYPE_NONE); + size_t dummy_size = params[2].memref.size; + TEE_Result (*do_asym)(TEE_OperationHandle, const TEE_Attribute *, + uint32_t, const void *, uint32_t, void *, + uint32_t *) = NULL; + + if (param_types != exp_param_types) + return TEE_ERROR_BAD_PARAMETERS; + + n = params[0].value.a; + mode = params[0].value.b; + + if (mode == MODE_ENCRYPT) + do_asym = TEE_AsymmetricEncrypt; + else if (mode == MODE_DECRYPT) + do_asym = TEE_AsymmetricDecrypt; + else if (mode == MODE_SIGN) + do_asym = TEE_AsymmetricSignDigest; + + if (mode == MODE_VERIFY) { + while (n--) { + res = TEE_AsymmetricVerifyDigest(crypto_op, asym_perf_attrs, asym_perf_attr_count, + params[1].memref.buffer, params[1].memref.size, + params[2].memref.buffer, dummy_size); + + CHECK(res, "TEE processing failed", goto out;); + } + } else { + while (n--) { + res = do_asym(crypto_op, asym_perf_attrs, asym_perf_attr_count, + params[1].memref.buffer, params[1].memref.size, + params[2].memref.buffer, &dummy_size); + + CHECK(res, "TEE processing failed", goto out;); + } + } + +out: + return res; +} + +TEE_Result cmd_asym_prepare_obj(uint32_t param_types, + TEE_Param params[TEE_NUM_PARAMS]) +{ + TEE_Result res = TEE_ERROR_GENERIC; + uint32_t tee_type = TEE_TYPE_ILLEGAL_VALUE; + uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT, + TEE_PARAM_TYPE_NONE, + TEE_PARAM_TYPE_NONE, + TEE_PARAM_TYPE_NONE); + + if (param_types != exp_param_types) + return TEE_ERROR_BAD_PARAMETERS; + + tee_type = get_keypair_type(params[0].value.a); + if (tee_type == TEE_TYPE_ILLEGAL_VALUE) + return TEE_ERROR_BAD_PARAMETERS; + + cmd_clean_obj(); + res = TEE_AllocateTransientObject(tee_type, params[0].value.b, + &crypto_obj); + CHECK(res, "TEE_AllocateTransientObject()", return res;); + + return TEE_SUCCESS; +} + +TEE_Result cmd_asym_prepare_keypair(uint32_t param_types, + TEE_Param params[TEE_NUM_PARAMS]) +{ + TEE_Result res = TEE_ERROR_GENERIC; + TEE_Attribute *attrs = NULL; + uint32_t attr_count = 0; + uint32_t width_bits = 0; + uint32_t algo_type = 0; + uint32_t tee_type = 0; + uint32_t mode = 0; + uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT, + TEE_PARAM_TYPE_VALUE_INPUT, + TEE_PARAM_TYPE_MEMREF_INPUT, + TEE_PARAM_TYPE_NONE); + + if (param_types != exp_param_types) + return TEE_ERROR_BAD_PARAMETERS; + + mode = params[0].value.b; + width_bits = params[0].value.a; + tee_type = params[1].value.a; + algo_type = params[1].value.b; + + if (get_algo(tee_type, mode, width_bits, algo_type)) + return TEE_ERROR_BAD_PARAMETERS; + + res = unpack_attrs(params[2].memref.buffer, params[2].memref.size, + &attrs, &attr_count); + if (res != TEE_SUCCESS) + return res; + + res = TEE_GenerateKey(crypto_obj, width_bits, attrs, attr_count); + CHECK(res, "TEE_GenerateKey()", goto out;); + + cmd_clean_res(); + res = TEE_AllocateOperation(&crypto_op, algo, mode, width_bits); + CHECK(res, "TEE_AllocateOperation()", goto out;); + + res = TEE_SetOperationKey(crypto_op, crypto_obj); + CHECK(res, "TEE_SetOperationKey()", goto out;); + + if (mode == MODE_DECRYPT) { + res = TEE_AllocateOperation(&crypto_op_enc_sign, algo, + MODE_ENCRYPT, width_bits); + CHECK(res, "TEE_AllocateOperation()", goto out;); + + res = TEE_SetOperationKey(crypto_op_enc_sign, crypto_obj); + CHECK(res, "TEE_SetOperationKey()", goto out;); + } else if (mode == MODE_VERIFY) { + res = TEE_AllocateOperation(&crypto_op_enc_sign, algo, + MODE_SIGN, width_bits); + CHECK(res, "TEE_AllocateOperation()", goto out;); + + res = TEE_SetOperationKey(crypto_op_enc_sign, crypto_obj); + CHECK(res, "TEE_SetOperationKey()", goto out;); + } + +out: + TEE_Free(attrs); + + return res; +} + +TEE_Result cmd_asym_prepare_hash(uint32_t param_types, + TEE_Param params[TEE_NUM_PARAMS]) +{ + TEE_Result res = TEE_ERROR_GENERIC; + TEE_OperationHandle hash_op = NULL; + uint32_t hash_algo = 0; + uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT, + TEE_PARAM_TYPE_MEMREF_INPUT, + TEE_PARAM_TYPE_MEMREF_INOUT, + TEE_PARAM_TYPE_NONE); + + if (param_types != exp_param_types) + return TEE_ERROR_BAD_PARAMETERS; + + if (params[0].value.a == ALGO_ECDSA) + hash_algo = TEE_ALG_SHA1; + else + hash_algo = TEE_ALG_HASH_ALGO(TEE_ALG_GET_DIGEST_HASH(algo)); + + res = TEE_AllocateOperation(&hash_op, hash_algo, TEE_MODE_DIGEST, 0); + CHECK(res, "TEE_AllocateOperation()", return res;); + + res = TEE_DigestDoFinal(hash_op, params[1].memref.buffer, + params[1].memref.size, params[2].memref.buffer, + ¶ms[2].memref.size); + TEE_FreeOperation(hash_op); + CHECK(res, "TEE_DigestDoFinal()", return res;); + + return TEE_SUCCESS; +} + +TEE_Result cmd_asym_prepare_enc_sign(uint32_t param_types, + TEE_Param params[TEE_NUM_PARAMS]) +{ + TEE_Result res = TEE_ERROR_GENERIC; + TEE_Attribute *attrs = NULL; + uint32_t attr_count = 0; + uint32_t mode = 0; + uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT, + TEE_PARAM_TYPE_MEMREF_OUTPUT, + TEE_PARAM_TYPE_VALUE_INPUT, + TEE_PARAM_TYPE_MEMREF_INPUT); + + if (param_types != exp_param_types) + return TEE_ERROR_BAD_PARAMETERS; + + mode = params[2].value.a; + res = unpack_attrs(params[3].memref.buffer, params[3].memref.size, + &attrs, &attr_count); + if (res != TEE_SUCCESS) + return res; + + if (mode == MODE_DECRYPT) + res = TEE_AsymmetricEncrypt(crypto_op_enc_sign, NULL, 0, + params[0].memref.buffer, params[0].memref.size, + params[1].memref.buffer, ¶ms[1].memref.size); + else + res = TEE_AsymmetricSignDigest(crypto_op_enc_sign, attrs, + attr_count, + params[0].memref.buffer, + params[0].memref.size, + params[1].memref.buffer, + ¶ms[1].memref.size); + + TEE_Free(attrs); + if (mode == MODE_DECRYPT) + CHECK(res, "TEE_AsymmetricEncrypt", return res;); + else + CHECK(res, "TEE_AsymmetricSignDigest", return res;); + + return TEE_SUCCESS; +} + +void cmd_clean_obj(void) +{ + if (crypto_obj) + TEE_FreeTransientObject(crypto_obj); + crypto_obj = TEE_HANDLE_NULL; +} + void cmd_clean_res(void) { if (crypto_op) TEE_FreeOperation(crypto_op); + if (crypto_op_enc_sign) { + TEE_FreeOperation(crypto_op_enc_sign); + crypto_op_enc_sign = NULL; + } } diff --git a/ta/crypto_perf/ta_entry.c b/ta/crypto_perf/ta_entry.c index 6cdb8d8ba..9c268738c 100644 --- a/ta/crypto_perf/ta_entry.c +++ b/ta/crypto_perf/ta_entry.c @@ -42,6 +42,7 @@ void TA_CloseSessionEntryPoint(void *pSessionContext) (void)pSessionContext; cmd_clean_res(); + cmd_clean_obj(); } /* Called when a command is invoked */ @@ -54,7 +55,6 @@ TEE_Result TA_InvokeCommandEntryPoint(void *pSessionContext, switch (nCommandID) { case TA_CRYPTO_PERF_CMD_CIPHER_PREPARE_KEY: return cmd_cipher_prepare_key(nParamTypes, pParams); - case TA_CRYPTO_PERF_CMD_CIPHER_PROCESS: return cmd_cipher_process(nParamTypes, pParams, false); case TA_CRYPTO_PERF_CMD_CIPHER_PROCESS_SDP: @@ -68,6 +68,22 @@ TEE_Result TA_InvokeCommandEntryPoint(void *pSessionContext, return cmd_hash_prepare_op(nParamTypes, pParams); case TA_CRYPTO_PERF_CMD_HASH_PROCESS: return cmd_hash_process(nParamTypes, pParams); + case TA_CRYPTO_PERF_CMD_ASYM_PROCESS_GEN_KEYPAIR: + return cmd_asym_process_keypair(nParamTypes, pParams); + case TA_CRYPTO_PERF_CMD_ASYM_PREPARE_ATTRS: + return cmd_asym_prepare_attrs(nParamTypes, pParams); + case TA_CRYPTO_PERF_CMD_ASYM_PROCESS: + return cmd_asym_process_rsa_ecc(nParamTypes, pParams); + case TA_CRYPTO_PERF_CMD_ASYM_PREPARE_KEYPAIR: + return cmd_asym_prepare_keypair(nParamTypes, pParams); + case TA_CRYPTO_PERF_CMD_ASYM_PREPARE_HASH: + return cmd_asym_prepare_hash(nParamTypes, pParams); + case TA_CRYPTO_PERF_CMD_ASYM_PREPARE_OBJ: + return cmd_asym_prepare_obj(nParamTypes, pParams); + case TA_CRYPTO_PERF_CMD_ASYM_PREPARE_ENC_SIGN: + return cmd_asym_prepare_enc_sign(nParamTypes, pParams); + case TA_CRYPTO_PERF_CMD_ASYM_FREE_ATTRS: + return cmd_asym_free_attrs(nParamTypes, pParams); default: return TEE_ERROR_BAD_PARAMETERS;