From 0aefb278cdab7b8cfcaf7e4b651857f6b981f0d1 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Tue, 7 Jun 2022 21:59:27 +0200 Subject: [PATCH] Berry optimization of crypto module --- lib/libesp32/berry/default/be_modtab.c | 8 ++++---- lib/libesp32/berry/generate/be_fixed_crypto.h | 18 +++++++++++++++++ .../berry_tasmota/src/be_crypto_lib.c | 20 ++++++------------- 3 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 lib/libesp32/berry/generate/be_fixed_crypto.h diff --git a/lib/libesp32/berry/default/be_modtab.c b/lib/libesp32/berry/default/be_modtab.c index 8f7addd94..a3bfbf5f7 100644 --- a/lib/libesp32/berry/default/be_modtab.c +++ b/lib/libesp32/berry/default/be_modtab.c @@ -48,6 +48,7 @@ be_extern_native_module(uuid); be_extern_native_module(animate); be_extern_native_module(partition_core); be_extern_native_module(crc); +be_extern_native_module(crypto); #ifdef USE_ZIGBEE be_extern_native_module(zigbee); #endif // USE_ZIGBEE @@ -156,6 +157,9 @@ BERRY_LOCAL const bntvmodule* const be_module_table[] = { &be_native_module(flash), &be_native_module(partition_core), &be_native_module(crc), +#ifdef USE_ALEXA_AVS + &be_native_module(crypto), +#endif /* user-defined modules register end */ NULL /* do not remove */ @@ -276,7 +280,6 @@ BERRY_LOCAL bclass_array be_class_table = { NULL, /* do not remove */ }; -extern void be_load_crypto_lib(bvm *vm); extern void be_load_ctypes_energy_definitions_lib(bvm *vm); /* this code loads the native class definitions */ @@ -288,9 +291,6 @@ BERRY_API void be_load_custom_libs(bvm *vm) #if !BE_USE_PRECOMPILED_OBJECT /* be_load_xxxlib(vm); */ #endif -#ifdef USE_ALEXA_AVS - be_load_crypto_lib(vm); // sub-module -#endif #ifdef USE_ENERGY_SENSOR be_load_ctypes_energy_definitions_lib(vm); // ctype class #endif // USE_ENERGY_SENSOR diff --git a/lib/libesp32/berry/generate/be_fixed_crypto.h b/lib/libesp32/berry/generate/be_fixed_crypto.h new file mode 100644 index 000000000..a59056a8b --- /dev/null +++ b/lib/libesp32/berry/generate/be_fixed_crypto.h @@ -0,0 +1,18 @@ +#include "be_constobj.h" + +static be_define_const_map_slots(m_libcrypto_map) { + { be_const_key_weak(AES_GCM, -1), be_const_class(be_class_aes_gcm) }, + { be_const_key_weak(EC_C25519, -1), be_const_class(be_class_ec_c25519) }, +}; + +static be_define_const_map( + m_libcrypto_map, + 2 +); + +static be_define_const_module( + m_libcrypto, + "crypto" +); + +BE_EXPORT_VARIABLE be_define_const_native_module(crypto); diff --git a/lib/libesp32/berry_tasmota/src/be_crypto_lib.c b/lib/libesp32/berry_tasmota/src/be_crypto_lib.c index f09913511..4108fd16a 100644 --- a/lib/libesp32/berry_tasmota/src/be_crypto_lib.c +++ b/lib/libesp32/berry_tasmota/src/be_crypto_lib.c @@ -19,21 +19,8 @@ extern int m_ec_c25519_sharedkey(bvm *vm); #include "be_fixed_be_class_aes_gcm.h" #include "be_fixed_be_class_ec_c25519.h" +#include "be_fixed_crypto.h" -void be_load_crypto_lib(bvm *vm) { - // insert the class GCM in module AES - be_newmodule(vm); - be_setname(vm, -1, "crypto"); - be_setglobal(vm, "crypto"); - - be_pushntvclass(vm, &be_class_aes_gcm); - be_setmember(vm, -2, "AES_GCM"); - be_pop(vm, 1); - - be_pushntvclass(vm, &be_class_ec_c25519); - be_setmember(vm, -2, "EC_C25519"); - be_pop(vm, 2); -} /* @const_object_info_begin class be_class_aes_gcm (scope: global, name: AES_GCM, strings: weak) { @@ -51,6 +38,11 @@ class be_class_ec_c25519 (scope: global, name: EC_C25519, strings: weak) { shared_key, func(m_ec_c25519_sharedkey) } +module crypto (scope: global, strings: weak) { + AES_GCM, class(be_class_aes_gcm) + EC_C25519, class(be_class_ec_c25519) +} + @const_object_info_end */ #endif // USE_ALEXA_AVS