Skip to content

Commit

Permalink
mbedtls/aes: add mbedtls AES alt
Browse files Browse the repository at this point in the history
add mbedtls AES alt
  • Loading branch information
pillip8282 authored and an4967 committed Nov 25, 2021
1 parent 31ad265 commit 33746a9
Show file tree
Hide file tree
Showing 27 changed files with 1,395 additions and 309 deletions.
6 changes: 3 additions & 3 deletions apps/examples/performance/tls_handshake/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ ifneq ($(CONFIG_BUILD_KERNEL),y)
endif

ifeq ($(CONFIG_WINDOWS_NATIVE),y)
BIN = ..\..\..\libapps$(LIBEXT)
BIN = $(APPDIR)\libapps$(LIBEXT)
else
ifeq ($(WINTOOL),y)
BIN = ..\\..\\..\\libapps$(LIBEXT)
BIN = $(APPDIR)\\libapps$(LIBEXT)
else
BIN = ../../../libapps$(LIBEXT)
BIN = $(APPDIR)/libapps$(LIBEXT)
endif
endif

Expand Down
14 changes: 11 additions & 3 deletions apps/examples/performance/tls_handshake/README.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@

examples/tls_handshake
^^^^^^^^^^^^^^^^^^^^^
usage:
ex) tls_handshake
usage: tls_handshake mode
mode: server, client

server mode
TASH> tls_handshake -s

client mode
TASH> tls_handshake -c target_address
ex) tls_handshake -c 192.168.1.2

Configs (see the details on Kconfig):
Configs (see the details on Kconfig):
* CONFIG_EXAMPLES_TLS_HANDSHAKE

Depends on:
Expand Down
18 changes: 6 additions & 12 deletions apps/examples/performance/tls_handshake/tls_handshake_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,14 @@ extern int tls_handshake_client(char *ipaddr);

int tls_handshake_main(int argc, char **argv)
{
int ret = 0;
if (argc == 2) {
if ((ret = strncmp("-s", argv[1], 3)) != 0) {
printf("%s\n", TLS_HANDSHAKE_USAGE);
return -1;
}
if (argc == 2 && !strncmp("-s", argv[1], 3)) {
tls_handshake_server();
} else if (argc == 3) {
if ((ret = strncmp("-c", argv[1], 3)) != 0) {
printf("%s\n", TLS_HANDSHAKE_USAGE);
return -1;
}
return 0;
} else if (argc == 3 && !strncmp("-c", argv[1], 3)) {
tls_handshake_client(argv[2]);
return 0;
}

return 0;
printf("%s\n", TLS_HANDSHAKE_USAGE);
return -1;
}
23 changes: 23 additions & 0 deletions apps/examples/performance/tls_handshake/tls_handshake_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,29 @@ int tls_handshake_server(void)
len = ret;
mbedtls_printf(" %d bytes written\n\n%s\n", len, (char *)buf);

/* 7-1 write 1MiB */
unsigned int remain = 1024 * 1024;
memset(buf, 0x01, sizeof(buf));
while (remain) {
size_t buf_size = remain > sizeof(buf) ? sizeof(buf) : remain;
mbedtls_printf("[pkbuild] write %ld size\n", buf_size);
ret = mbedtls_ssl_write(&ssl, buf, buf_size);
if (ret == MBEDTLS_ERR_NET_CONN_RESET) {
mbedtls_printf(" failed\n ! peer closed the connection\n\n");
goto reset;
}
if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
continue;
}
if (ret < 0) {
mbedtls_printf(" failed\n ! mbedtls_ssl_write returned %d\n\n", ret);
goto reset;
}

mbedtls_printf(" %d bytes sent\n", ret);
remain -= ret;
}

mbedtls_printf(" . Closing the connection...");

while ((ret = mbedtls_ssl_close_notify(&ssl)) < 0) {
Expand Down
4 changes: 2 additions & 2 deletions apps/examples/performance/tls_handshake/tls_handshake_usage.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"example: tls_handshake -s\n"

#define TLS_HANDSHAKE_CLIENT_USAGE \
"\ntls_handshake -c target_address\n" \
"\ntls_handshake -c <target_address>\n" \
"example: tls_handshake -c 127.0.0.1\n"

#define TLS_HANDSHAKE_USAGE \
"usage: tls_handshake mode\n" \
"usage: tls_handshake <mode>\n" \
"mode : client, server\n" \
TLS_HANDSHAKE_CLIENT_USAGE \
TLS_HANDSHAKE_SERVER_USAGE
6 changes: 1 addition & 5 deletions apps/examples/security_test/seclink/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ CSRCS += \
sl_key_test.c \
sl_crypto_test.c \
sl_ss_test.c \
sl_mbed_test.c\
sl_test_utils.c

#CRYPTO
CSRCS += \
sl_crypto_aes_test.c\
sl_crypto_rsa_test.c

MAINSRC = sl_test_main.c

AOBJS = $(ASRCS:.S=$(OBJEXT))
Expand Down
1 change: 1 addition & 0 deletions apps/examples/security_test/seclink/sl_auth_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ void sl_handle_auth_remove_cert(sl_options *opt)
{
ST_SET_SMOKE(sl_auth, opt->count, 0, "Get certificate", get_certificate);
}

void sl_handle_auth(sl_options *opt)
{
ST_TC_SET_GLOBAL(sl_auth, sl_auth_global);
Expand Down
32 changes: 0 additions & 32 deletions apps/examples/security_test/seclink/sl_crypto_rsa_test.c

This file was deleted.

8 changes: 4 additions & 4 deletions apps/examples/security_test/seclink/sl_crypto_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
****************************************************************************/
// command, type, handler
SL_CRYPTO_TEST_POOL("aes_dec", SL_CRYPTO_TYPE_AES_DECRYPT, sl_handle_crypto_aes_dec)
SL_CRYPTO_TEST_POOL("aes_enc", SL_CRYPTO_TYPE_AES_ENCRYPT, sl_handle_crypto_aes_enc)
SL_CRYPTO_TEST_POOL("rsa_dec", SL_CRYPTO_TYPE_RSA_DECRYPT, sl_handle_crypto_rsa_dec)
SL_CRYPTO_TEST_POOL("rsa_enc", SL_CRYPTO_TYPE_RSA_ENCRYPT, sl_handle_crypto_rsa_enc)
SL_CRYPTO_TEST_POOL("aes_ecb", SL_CRYPTO_TYPE_AES_ECB, sl_handle_crypto_aes_ecb)
SL_CRYPTO_TEST_POOL("aes_cbc", SL_CRYPTO_TYPE_AES_CBC, sl_handle_crypto_aes_cbc)
SL_CRYPTO_TEST_POOL("aes_cfb128", SL_CRYPTO_TYPE_AES_CFB128, sl_handle_crypto_aes_cfb128)
SL_CRYPTO_TEST_POOL("aes_ctr", SL_CRYPTO_TYPE_AES_CTR, sl_handle_crypto_aes_ctr)
Loading

0 comments on commit 33746a9

Please sign in to comment.