Skip to content

Commit

Permalink
xtest: combine AES and hash into crypto_perf
Browse files Browse the repository at this point in the history
There is quite a bit of copy in these files.So, I cosonlidate the
code to make it easier to maintain.

Signed-off-by: Zexi Yu <[email protected]>
Acked-by: Jerome Forissier <[email protected]>
Acked-by: Etienne Carriere <[email protected]>
  • Loading branch information
yuzexiyzx committed Nov 9, 2023
1 parent f4dd113 commit aa7454b
Show file tree
Hide file tree
Showing 26 changed files with 305 additions and 454 deletions.
3 changes: 1 addition & 2 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ LOCAL_C_INCLUDES += $(LOCAL_PATH)/host/xtest \
$(LOCAL_PATH)/ta/storage_benchmark/include \
$(LOCAL_PATH)/ta/concurrent/include \
$(LOCAL_PATH)/ta/concurrent_large/include \
$(LOCAL_PATH)/ta/hash_perf/include \
$(LOCAL_PATH)/ta/aes_perf/include \
$(LOCAL_PATH)/ta/crypto_perf/include \
$(LOCAL_PATH)/ta/socket/include \
$(LOCAL_PATH)/ta/sdp_basic/include \
$(LOCAL_PATH)/ta/tpm_log_test/include \
Expand Down
3 changes: 1 addition & 2 deletions host/xtest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ CFLAGS += -I../../ta/sims_keepalive/include
CFLAGS += -I../../ta/storage_benchmark/include
CFLAGS += -I../../ta/concurrent/include
CFLAGS += -I../../ta/concurrent_large/include
CFLAGS += -I../../ta/hash_perf/include
CFLAGS += -I../../ta/aes_perf/include
CFLAGS += -I../../ta/crypto_perf/include
CFLAGS += -I../../ta/socket/include
CFLAGS += -I../../ta/sdp_basic/include
CFLAGS += -I../../ta/tpm_log_test/include
Expand Down
10 changes: 5 additions & 5 deletions host/xtest/aes_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <ta_aes_perf.h>
#include <ta_crypto_perf.h>
#include <tee_client_api.h>
#include <tee_client_api_extensions.h>
#include <time.h>
Expand Down Expand Up @@ -109,7 +109,7 @@ static void check_res(TEEC_Result res, const char *errmsg, uint32_t *orig)
static void open_ta(void)
{
TEEC_Result res = TEEC_ERROR_GENERIC;
TEEC_UUID uuid = TA_AES_PERF_UUID;
TEEC_UUID uuid = TA_CRYPTO_PERF_UUID;
uint32_t err_origin = 0;

res = TEEC_InitializeContext(NULL, &ctx);
Expand Down Expand Up @@ -354,7 +354,7 @@ static void prepare_key(int decrypt, int keysize, int mode)
TEEC_Result res = TEEC_ERROR_GENERIC;
uint32_t ret_origin = 0;
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
uint32_t cmd = TA_AES_PERF_CMD_PREPARE_KEY;
uint32_t cmd = TA_CRYPTO_PERF_CMD_CIPHER_PREPARE_KEY;

op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_VALUE_INPUT,
TEEC_NONE, TEEC_NONE);
Expand Down Expand Up @@ -432,8 +432,8 @@ void aes_perf_run_test(int mode, int keysize, int decrypt, size_t size, size_t u
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
int n0 = n;
double sd = 0;
uint32_t cmd = is_sdp_test ? TA_AES_PERF_CMD_PROCESS_SDP :
TA_AES_PERF_CMD_PROCESS;
uint32_t cmd = is_sdp_test ? TA_CRYPTO_PERF_CMD_CIPHER_PROCESS_SDP :
TA_CRYPTO_PERF_CMD_CIPHER_PROCESS;

if (input_buffer == BUFFER_UNSPECIFIED)
input_buffer = BUFFER_SHM_ALLOCATED;
Expand Down
4 changes: 1 addition & 3 deletions host/xtest/crypto_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
#ifndef XTEST_CRYPTO_COMMON_H
#define XTEST_CRYPTO_COMMON_H

#include "ta_aes_perf.h"
#include "ta_hash_perf.h"

#include "ta_crypto_perf.h"

#define AES_PERF_INPLACE 0

Expand Down
6 changes: 3 additions & 3 deletions host/xtest/hash_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void check_res(TEEC_Result res, const char *errmsg, uint32_t *orig)
static void open_ta(void)
{
TEEC_Result res = TEEC_ERROR_GENERIC;
TEEC_UUID uuid = TA_HASH_PERF_UUID;
TEEC_UUID uuid = TA_CRYPTO_PERF_UUID;
uint32_t err_origin = 0;

res = TEEC_InitializeContext(NULL, &ctx);
Expand Down Expand Up @@ -247,7 +247,7 @@ static uint64_t run_test_once(void *in, size_t size, int random_in,
read_random(in, size);

get_current_time(&t0);
res = TEEC_InvokeCommand(&sess, TA_HASH_PERF_CMD_PROCESS, op,
res = TEEC_InvokeCommand(&sess, TA_CRYPTO_PERF_CMD_HASH_PROCESS, op,
&ret_origin);
check_res(res, "TEEC_InvokeCommand", &ret_origin);
get_current_time(&t1);
Expand All @@ -264,7 +264,7 @@ static void prepare_op(int algo)
op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].value.a = algo;
res = TEEC_InvokeCommand(&sess, TA_HASH_PERF_CMD_PREPARE_OP, &op,
res = TEEC_InvokeCommand(&sess, TA_CRYPTO_PERF_CMD_HASH_PREPARE_OP, &op,
&ret_origin);
check_res(res, "TEEC_InvokeCommand", &ret_origin);
}
Expand Down
3 changes: 1 addition & 2 deletions ta/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ add_library(${PROJECT_NAME} INTERFACE)

target_include_directories(${PROJECT_NAME}
INTERFACE include
INTERFACE aes_perf/include
INTERFACE concurrent/include
INTERFACE concurrent_large/include
INTERFACE create_fail_test/include
INTERFACE crypt/include
INTERFACE crypto_perf/include
INTERFACE enc_fs/include
INTERFACE os_test/include
INTERFACE rpc_test/include
INTERFACE sdp_basic/include
INTERFACE hash_perf/include
INTERFACE sims/include
INTERFACE miss/include
INTERFACE sims_keepalive/include
Expand Down
3 changes: 1 addition & 2 deletions ta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ TA_DIRS := create_fail_test \
concurrent \
concurrent_large \
storage_benchmark \
hash_perf \
aes_perf \
crypto_perf \
socket \
supp_plugin \
large \
Expand Down
4 changes: 0 additions & 4 deletions ta/aes_perf/Makefile

This file was deleted.

38 changes: 0 additions & 38 deletions ta/aes_perf/include/ta_aes_perf.h

This file was deleted.

16 changes: 0 additions & 16 deletions ta/aes_perf/include/ta_aes_perf_priv.h

This file was deleted.

21 changes: 0 additions & 21 deletions ta/aes_perf/include/user_ta_header_defines.h

This file was deleted.

2 changes: 1 addition & 1 deletion ta/aes_perf/Android.mk → ta/crypto_perf/Android.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LOCAL_PATH := $(call my-dir)

local_module := e626662e-c0e2-485c-b8c8-09fbce6edf3d.ta
local_module := 02a42f43-d8b7-4a57-aa4d-87bd9b5587cb.ta
include $(BUILD_OPTEE_MK)
4 changes: 4 additions & 0 deletions ta/crypto_perf/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BINARY = 02a42f43-d8b7-4a57-aa4d-87bd9b5587cb

include ../ta_common.mk

56 changes: 56 additions & 0 deletions ta/crypto_perf/include/ta_crypto_perf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2015, Linaro Limited
*/

#ifndef TA_CRYPTO_PERF_H
#define TA_CRYPTO_PERF_H

#define TA_CRYPTO_PERF_UUID { 0x02a42f43, 0xd8b7, 0x4a57, \
{ 0xaa, 0x4d, 0x87, 0xbd, 0x9b, 0x55, 0x87, 0xcb } }

/*
* 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

/*
* Supported AES modes of operation
*/

#define TA_AES_ECB 0
#define TA_AES_CBC 1
#define TA_AES_CTR 2
#define TA_AES_XTS 3
#define TA_AES_GCM 4

/*
* AES key sizes
*/
#define AES_128 128
#define AES_192 192
#define AES_256 256

/*
* Supported hash algorithms
*/

#define TA_SHA_SHA1 0
#define TA_SHA_SHA224 1
#define TA_SHA_SHA256 2
#define TA_SHA_SHA384 3
#define TA_SHA_SHA512 4
#define TA_SM3 5
#define TA_HMAC_SHA1 6
#define TA_HMAC_SHA224 7
#define TA_HMAC_SHA256 8
#define TA_HMAC_SHA384 9
#define TA_HMAC_SHA512 10
#define TA_HMAC_SM3 11

#endif /* TA_CRYPTO_PERF_H */
18 changes: 18 additions & 0 deletions ta/crypto_perf/include/ta_crypto_perf_priv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2015, Linaro Limited
*/

#ifndef TA_CRYPTO_PERF_PRIV_H
#define TA_CRYPTO_PERF_PRIV_H

#include <tee_api.h>

TEE_Result cmd_cipher_prepare_key(uint32_t param_types, TEE_Param params[4]);
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]);
void cmd_clean_res(void);

#endif /* TA_CRYPTO_PERF_PRIV_H */
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2015, Linaro Limited
* All rights reserved.
*/

#ifndef USER_TA_HEADER_DEFINES_H
#define USER_TA_HEADER_DEFINES_H

#include "ta_hash_perf.h"
#include "ta_crypto_perf.h"

#define TA_UUID TA_HASH_PERF_UUID
#define TA_UUID TA_CRYPTO_PERF_UUID

#define TA_FLAGS 0

#define TA_FLAGS (TA_FLAG_USER_MODE | TA_FLAG_EXEC_DDR)
#define TA_STACK_SIZE (2 * 1024)
#define TA_DATA_SIZE (32 * 1024)

Expand Down
2 changes: 1 addition & 1 deletion ta/aes_perf/sub.mk → ta/crypto_perf/sub.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
global-incdirs-y += include
srcs-y += ta_entry.c
srcs-y += ta_aes_perf.c
srcs-y += ta_crypto_perf.c
Loading

0 comments on commit aa7454b

Please sign in to comment.