From 1dea211bf76aed43cefa6d40ae339b9148fe09a9 Mon Sep 17 00:00:00 2001
From: yuanjm <yuanjianmin@espressif.com>
Date: Fri, 2 Aug 2019 18:03:03 +0800
Subject: [PATCH] feat(util): Add ARC4 for ESP8266 SoC

---
 .../mbedtls/port/esp8266/include/arc4_alt.h   | 46 +++++++++++++++++++
 .../port/esp8266/include/mbedtls/esp_config.h |  6 ++-
 2 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 components/ssl/mbedtls/port/esp8266/include/arc4_alt.h

diff --git a/components/ssl/mbedtls/port/esp8266/include/arc4_alt.h b/components/ssl/mbedtls/port/esp8266/include/arc4_alt.h
new file mode 100644
index 00000000..1fe52e57
--- /dev/null
+++ b/components/ssl/mbedtls/port/esp8266/include/arc4_alt.h
@@ -0,0 +1,46 @@
+/*
+ *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ *  SPDX-License-Identifier: Apache-2.0
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+#ifndef ARC4_ALT_H
+#define ARC4_ALT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(MBEDTLS_ARC4_ALT)
+#include "esp_arc4.h"
+
+typedef esp_arc4_context mbedtls_arc4_context;
+
+#define mbedtls_arc4_init(_ctx)                     { }
+
+#define mbedtls_arc4_free(_ctx)                     { }
+
+#define mbedtls_arc4_setup(_ctx, _s, _l)            esp_arc4_setup(_ctx, _s, _l)
+
+#define mbedtls_arc4_crypt(_ctx, _l, _i, _o)        esp_arc4_encrypt(_ctx, _l, _i, _o)
+
+#endif /* MBEDTLS_ARC4_ALT */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/components/ssl/mbedtls/port/esp8266/include/mbedtls/esp_config.h b/components/ssl/mbedtls/port/esp8266/include/mbedtls/esp_config.h
index 6243a73b..8a9af79b 100644
--- a/components/ssl/mbedtls/port/esp8266/include/mbedtls/esp_config.h
+++ b/components/ssl/mbedtls/port/esp8266/include/mbedtls/esp_config.h
@@ -275,7 +275,6 @@
  *            digests and ciphers instead.
  *
  */
-//#define MBEDTLS_ARC4_ALT
 //#define MBEDTLS_BLOWFISH_ALT
 //#define MBEDTLS_CAMELLIA_ALT
 //#define MBEDTLS_CCM_ALT
@@ -303,6 +302,11 @@
 #ifdef CONFIG_ESP_MD5
 #define MBEDTLS_MD5_ALT
 #endif
+
+#ifdef CONFIG_ESP_ARC4
+#define MBEDTLS_ARC4_ALT
+#endif
+
 /*
  * When replacing the elliptic curve module, pleace consider, that it is
  * implemented with two .c files: