From 0c22a0264151b7c279e92f403652de7834a1520b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Tue, 12 Jul 2022 12:48:27 +0200 Subject: [PATCH] [beken-72xx] Use mbedTLS MD5 implementation --- arduino/beken-72xx/libraries/MD5/MD5Impl.h | 5 ++++ arduino/libretuya/libraries/MD5/MD5.h | 3 ++ .../libraries/MD5/MD5MbedTLSImpl.cpp | 28 +++++++++++++++++++ .../libretuya/libraries/MD5/MD5MbedTLSImpl.h | 14 ++++++++++ builder/frameworks/beken-72xx-arduino.py | 1 + 5 files changed, 51 insertions(+) create mode 100644 arduino/beken-72xx/libraries/MD5/MD5Impl.h create mode 100644 arduino/libretuya/libraries/MD5/MD5MbedTLSImpl.cpp create mode 100644 arduino/libretuya/libraries/MD5/MD5MbedTLSImpl.h diff --git a/arduino/beken-72xx/libraries/MD5/MD5Impl.h b/arduino/beken-72xx/libraries/MD5/MD5Impl.h new file mode 100644 index 0000000..c93f9d7 --- /dev/null +++ b/arduino/beken-72xx/libraries/MD5/MD5Impl.h @@ -0,0 +1,5 @@ +/* Copyright (c) Kuba Szczodrzyński 2022-07-11. */ + +#pragma once + +#define LT_MD5_USE_MBEDTLS 1 diff --git a/arduino/libretuya/libraries/MD5/MD5.h b/arduino/libretuya/libraries/MD5/MD5.h index 4aae25e..5423ad2 100644 --- a/arduino/libretuya/libraries/MD5/MD5.h +++ b/arduino/libretuya/libraries/MD5/MD5.h @@ -9,6 +9,9 @@ #if LT_MD5_USE_POLARSSL #include "MD5PolarSSLImpl.h" #endif +#if LT_MD5_USE_MBEDTLS +#include "MD5MbedTLSImpl.h" +#endif // common API #ifdef __cplusplus diff --git a/arduino/libretuya/libraries/MD5/MD5MbedTLSImpl.cpp b/arduino/libretuya/libraries/MD5/MD5MbedTLSImpl.cpp new file mode 100644 index 0000000..2db16c0 --- /dev/null +++ b/arduino/libretuya/libraries/MD5/MD5MbedTLSImpl.cpp @@ -0,0 +1,28 @@ +/* Copyright (c) Kuba Szczodrzyński 2022-07-11. */ + +#if LT_ARD_HAS_MD5 + +#include "MD5.h" + +#if LT_MD5_USE_MBEDTLS + +extern "C" { + +void MD5Init(LT_MD5_CTX_T *context) { + mbedtls_md5_init(context); + mbedtls_md5_starts(context); +} + +void MD5Update(LT_MD5_CTX_T *context, const unsigned char *buf, unsigned len) { + mbedtls_md5_update(context, buf, len); +} + +void MD5Final(unsigned char digest[16], LT_MD5_CTX_T *context) { + mbedtls_md5_finish(context, digest); +} + +} // extern "C" + +#endif // LT_MD5_USE_MBEDTLS + +#endif // LT_ARD_HAS_MD5 diff --git a/arduino/libretuya/libraries/MD5/MD5MbedTLSImpl.h b/arduino/libretuya/libraries/MD5/MD5MbedTLSImpl.h new file mode 100644 index 0000000..68fcd48 --- /dev/null +++ b/arduino/libretuya/libraries/MD5/MD5MbedTLSImpl.h @@ -0,0 +1,14 @@ +/* Copyright (c) Kuba Szczodrzyński 2022-07-11. */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#define LT_MD5_CTX_T mbedtls_md5_context + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/builder/frameworks/beken-72xx-arduino.py b/builder/frameworks/beken-72xx-arduino.py index 68068fe..285e4cb 100644 --- a/builder/frameworks/beken-72xx-arduino.py +++ b/builder/frameworks/beken-72xx-arduino.py @@ -26,6 +26,7 @@ env.Append( CPPDEFINES=[ # LibreTuya configuration ("LT_ARD_HAS_WIFI", "1"), + ("LT_ARD_HAS_MD5", "1"), # macros # mbedtls_net_set_nonblock is commented out in tls_net.c ("mbedtls_net_set_nonblock", "net_set_nonblock"),