Skip to content

Commit

Permalink
xtest: combine aes and hash into crypto_perf and add SM4 algorithm
Browse files Browse the repository at this point in the history
There is quite a bit of copy in these files.So, I cosolidate the
code to make it easier to maintain.In addition, SM4 algorithm is
added.

Signed-off-by: Zexi Yu <yuzexi@hisilicon.com>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
  • Loading branch information
yuzexiyzx committed Oct 16, 2023
1 parent f4dd113 commit 3225039
Show file tree
Hide file tree
Showing 27 changed files with 706 additions and 810 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
1 change: 1 addition & 0 deletions host/xtest/xtest_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void usage(char *program)
printf("\t--sha-perf [opts] Deprecated, same as --hash-perf\n");
printf("\t--hash-perf [opts] Hash performance testing tool (-h for usage)\n");
printf("\t--aes-perf [opts] AES performance testing tool (-h for usage)\n");
printf("\t--asym-cipher-perf [opts] Aysmmetric cipher performance testing tool (-h for usage)\n");
#ifdef CFG_SECSTOR_TA_MGMT_PTA
printf("\t--install-ta [directory or list of TAs]\n");
printf("\t Install TAs\n");
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

75 changes: 75 additions & 0 deletions ta/crypto_perf/include/ta_crypto_perf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* 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

#define TA_SM4_ECB 5
#define TA_SM4_CBC 6
#define TA_SM4_CTR 7
#define TA_SM4_XTS 8

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

#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

#endif /* TA_CRYPTO_PERF_H */
19 changes: 19 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,19 @@
/* 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_obj(void);
void cmd_clean_res(void);

#endif /* TA_CRYPTO_PERF_PRIV_H */
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* 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"

#define TA_UUID TA_HASH_PERF_UUID

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

#endif
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2015, Linaro Limited
*/

#ifndef USER_TA_HEADER_DEFINES_H
#define USER_TA_HEADER_DEFINES_H

#include "ta_crypto_perf.h"

#define TA_UUID TA_CRYPTO_PERF_UUID

#define TA_FLAGS 0

#define TA_STACK_SIZE (2 * 1024)
#define TA_DATA_SIZE (32 * 1024)

#endif
6 changes: 3 additions & 3 deletions 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
global-incdirs-y += include
srcs-y += ta_entry.c
srcs-y += ta_crypto_perf.c
Loading

0 comments on commit 3225039

Please sign in to comment.