├── 0_Hardware └── jlcEDA │ ├── esp12f.zip │ └── esp32.zip ├── 1_Firmware ├── 1_arduino_esp8266 │ └── FANtest │ │ ├── ESPbutton.h │ │ ├── FANtest.ino │ │ ├── my_accessory.c │ │ └── wifi_info.h └── 2_platformio_esp8266 │ ├── .gitignore │ ├── .vscode │ ├── extensions.json │ └── settings.json │ ├── include │ ├── ESPbutton.h │ ├── README │ └── wifi_info.h │ ├── lib │ ├── HomeKit-ESP8266 │ │ ├── LICENSE │ │ ├── README.md │ │ ├── examples │ │ │ ├── Example01_TemperatureSensor │ │ │ │ ├── my_accessory.c │ │ │ │ ├── temperature_sensor.ino │ │ │ │ └── wifi_info.h │ │ │ ├── Example02_Switch │ │ │ │ ├── my_accessory.c │ │ │ │ ├── switch.ino │ │ │ │ └── wifi_info.h │ │ │ ├── Example03_StatelessProgrammableSwitch │ │ │ │ ├── ESPButton.h │ │ │ │ ├── my_accessory.c │ │ │ │ ├── stateless_programmable_switch.ino │ │ │ │ └── wifi_info.h │ │ │ ├── Example04_MultipleAccessories │ │ │ │ ├── multiple_accessories.ino │ │ │ │ ├── my_accessory.c │ │ │ │ └── wifi_info.h │ │ │ └── legacy │ │ │ │ ├── simple_led │ │ │ │ ├── ButtonDebounce.h │ │ │ │ ├── ButtonHandler.h │ │ │ │ ├── simple_led.ino │ │ │ │ └── simple_led_accessory.c │ │ │ │ └── simplest_led │ │ │ │ ├── simplest_led.ino │ │ │ │ └── simplest_led_accessory.c │ │ ├── extras │ │ │ ├── ESP8266WiFi_nossl_noleak │ │ │ │ └── src │ │ │ │ │ ├── ESP8266WiFi.cpp │ │ │ │ │ ├── ESP8266WiFi.h │ │ │ │ │ ├── ESP8266WiFiAP.cpp │ │ │ │ │ ├── ESP8266WiFiAP.h │ │ │ │ │ ├── ESP8266WiFiGeneric.cpp │ │ │ │ │ ├── ESP8266WiFiGeneric.h │ │ │ │ │ ├── ESP8266WiFiMulti.cpp │ │ │ │ │ ├── ESP8266WiFiMulti.h │ │ │ │ │ ├── ESP8266WiFiSTA.cpp │ │ │ │ │ ├── ESP8266WiFiSTA.h │ │ │ │ │ ├── ESP8266WiFiScan.cpp │ │ │ │ │ ├── ESP8266WiFiScan.h │ │ │ │ │ ├── ESP8266WiFiType.h │ │ │ │ │ ├── WiFiClient.cpp │ │ │ │ │ ├── WiFiClient.h │ │ │ │ │ ├── WiFiServer.cpp │ │ │ │ │ ├── WiFiServer.h │ │ │ │ │ ├── WiFiUdp.cpp │ │ │ │ │ ├── WiFiUdp.h │ │ │ │ │ └── include │ │ │ │ │ ├── ClientContext.h │ │ │ │ │ ├── DataSource.h │ │ │ │ │ ├── SSLContext.h │ │ │ │ │ ├── UdpContext.h │ │ │ │ │ ├── WiFiState.h │ │ │ │ │ ├── slist.h │ │ │ │ │ ├── ssl.h │ │ │ │ │ └── wl_definitions.h │ │ │ ├── example_serial_output.txt │ │ │ ├── example_serial_output_v1.1.0.txt │ │ │ └── preview.jpg │ │ ├── library.json │ │ ├── library.properties │ │ ├── src │ │ │ ├── accessories.c │ │ │ ├── arduino_homekit_server.cpp │ │ │ ├── arduino_homekit_server.h │ │ │ ├── base64.c │ │ │ ├── base64.h │ │ │ ├── cJSON.c │ │ │ ├── cJSON.h │ │ │ ├── cQueue.c │ │ │ ├── cQueue.h │ │ │ ├── constants.h │ │ │ ├── crypto.c │ │ │ ├── crypto.h │ │ │ ├── esp_xpgm.h │ │ │ ├── homekit │ │ │ │ ├── characteristics.h │ │ │ │ ├── homekit.h │ │ │ │ ├── tlv.h │ │ │ │ └── types.h │ │ │ ├── homekit_debug.c │ │ │ ├── homekit_debug.h │ │ │ ├── http_parser.c │ │ │ ├── http_parser.h │ │ │ ├── json.c │ │ │ ├── json.h │ │ │ ├── pairing.h │ │ │ ├── port.c │ │ │ ├── port.h │ │ │ ├── query_params.c │ │ │ ├── query_params.h │ │ │ ├── storage.c │ │ │ ├── storage.h │ │ │ ├── tlv.c │ │ │ ├── types.c │ │ │ ├── user_settings.h │ │ │ ├── watchdog.c │ │ │ ├── watchdog.h │ │ │ ├── wolfcrypt │ │ │ │ └── src │ │ │ │ │ ├── chacha.c │ │ │ │ │ ├── chacha20_poly1305.c │ │ │ │ │ ├── curve25519.c │ │ │ │ │ ├── ed25519.c │ │ │ │ │ ├── error.c │ │ │ │ │ ├── fe_low_mem.c │ │ │ │ │ ├── fe_operations.c │ │ │ │ │ ├── ge_low_mem.c │ │ │ │ │ ├── ge_operations.c │ │ │ │ │ ├── hash.c │ │ │ │ │ ├── hmac.c │ │ │ │ │ ├── integer.c │ │ │ │ │ ├── misc.c │ │ │ │ │ ├── poly1305.c │ │ │ │ │ ├── random.c │ │ │ │ │ ├── sha.c │ │ │ │ │ ├── sha256.c │ │ │ │ │ ├── sha512.c │ │ │ │ │ ├── srp.c │ │ │ │ │ └── wolfmath.c │ │ │ └── wolfssl │ │ │ │ └── wolfcrypt │ │ │ │ ├── aes.h │ │ │ │ ├── arc4.h │ │ │ │ ├── asn.h │ │ │ │ ├── asn_public.h │ │ │ │ ├── blake2-impl.h │ │ │ │ ├── blake2-int.h │ │ │ │ ├── blake2.h │ │ │ │ ├── camellia.h │ │ │ │ ├── chacha.h │ │ │ │ ├── chacha20_poly1305.h │ │ │ │ ├── cmac.h │ │ │ │ ├── coding.h │ │ │ │ ├── compress.h │ │ │ │ ├── cpuid.h │ │ │ │ ├── curve25519.h │ │ │ │ ├── des3.h │ │ │ │ ├── dh.h │ │ │ │ ├── dsa.h │ │ │ │ ├── ecc.h │ │ │ │ ├── ed25519.h │ │ │ │ ├── error-crypt.h │ │ │ │ ├── fe_operations.h │ │ │ │ ├── fips_test.h │ │ │ │ ├── ge_operations.h │ │ │ │ ├── hash.h │ │ │ │ ├── hc128.h │ │ │ │ ├── hmac.h │ │ │ │ ├── idea.h │ │ │ │ ├── integer.h │ │ │ │ ├── logging.h │ │ │ │ ├── md2.h │ │ │ │ ├── md4.h │ │ │ │ ├── md5.h │ │ │ │ ├── mem_track.h │ │ │ │ ├── memory.h │ │ │ │ ├── misc.h │ │ │ │ ├── mpi_class.h │ │ │ │ ├── mpi_superclass.h │ │ │ │ ├── pkcs12.h │ │ │ │ ├── pkcs7.h │ │ │ │ ├── poly1305.h │ │ │ │ ├── pwdbased.h │ │ │ │ ├── rabbit.h │ │ │ │ ├── random.h │ │ │ │ ├── ripemd.h │ │ │ │ ├── rsa.h │ │ │ │ ├── settings.h │ │ │ │ ├── sha.h │ │ │ │ ├── sha256.h │ │ │ │ ├── sha3.h │ │ │ │ ├── sha512.h │ │ │ │ ├── signature.h │ │ │ │ ├── sp.h │ │ │ │ ├── srp.h │ │ │ │ ├── tfm.h │ │ │ │ ├── types.h │ │ │ │ ├── visibility.h │ │ │ │ ├── wc_encrypt.h │ │ │ │ ├── wc_port.h │ │ │ │ ├── wolfevent.h │ │ │ │ └── wolfmath.h │ │ └── translations │ │ │ └── README-ptbr.md │ └── README │ ├── platformio.ini │ ├── src │ ├── main.cpp │ └── my_accessory.c │ └── test │ └── README ├── 2_Lib ├── Arduino-HomeKit-ESP32 │ ├── .gitattributes │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── examples │ │ └── ESP32_homekit_wolfssl_4_3_0 │ │ │ ├── ESP32_homekit.ino │ │ │ ├── ESPButton.h │ │ │ └── builtin_led_accessory.c │ ├── library.json │ ├── library.properties │ └── src │ │ ├── accessories.c │ │ ├── arduino_homekit_server.h │ │ ├── arduino_homekit_server_esp32.cpp │ │ ├── arduino_homekit_server_esp8266.cpp │ │ ├── base64.c │ │ ├── base64.h │ │ ├── cJSON.c │ │ ├── cJSON.h │ │ ├── cQueue.c │ │ ├── cQueue.h │ │ ├── constants.h │ │ ├── crypto.c │ │ ├── crypto.h │ │ ├── esp_xpgm.h │ │ ├── homekit │ │ ├── characteristics.h │ │ ├── homekit.h │ │ ├── tlv.h │ │ └── types.h │ │ ├── homekit_debug.c │ │ ├── homekit_debug.h │ │ ├── http_parser.c │ │ ├── http_parser.h │ │ ├── json.c │ │ ├── json.h │ │ ├── pairing.h │ │ ├── port.c │ │ ├── port.h │ │ ├── query_params.c │ │ ├── query_params.h │ │ ├── storage.c │ │ ├── storage.h │ │ ├── tlv.c │ │ ├── types.c │ │ ├── user_settings.h │ │ ├── watchdog.c │ │ ├── watchdog.h │ │ ├── wolfcrypt │ │ └── src │ │ │ ├── aes.c │ │ │ ├── arc4.c │ │ │ ├── asm.c │ │ │ ├── asn.c │ │ │ ├── blake2b.c │ │ │ ├── blake2s.c │ │ │ ├── camellia.c │ │ │ ├── chacha.c │ │ │ ├── chacha20_poly1305.c │ │ │ ├── cmac.c │ │ │ ├── coding.c │ │ │ ├── compress.c │ │ │ ├── cpuid.c │ │ │ ├── cryptocb.c │ │ │ ├── curve25519.c │ │ │ ├── des3.c │ │ │ ├── dh.c │ │ │ ├── dsa.c │ │ │ ├── ecc.c │ │ │ ├── ecc_fp.c │ │ │ ├── ed25519.c │ │ │ ├── error.c │ │ │ ├── evp.c │ │ │ ├── fe_low_mem.c │ │ │ ├── fe_operations.c │ │ │ ├── ge_low_mem.c │ │ │ ├── ge_operations.c │ │ │ ├── hash.c │ │ │ ├── hc128.c │ │ │ ├── hmac.c │ │ │ ├── idea.c │ │ │ ├── integer.c │ │ │ ├── logging.c │ │ │ ├── md2.c │ │ │ ├── md4.c │ │ │ ├── md5.c │ │ │ ├── memory.c │ │ │ ├── misc.c │ │ │ ├── pkcs12.c │ │ │ ├── pkcs7.c │ │ │ ├── poly1305.c │ │ │ ├── port │ │ │ └── Espressif │ │ │ │ ├── README.md │ │ │ │ ├── esp32_aes.c │ │ │ │ ├── esp32_mp.c │ │ │ │ ├── esp32_sha.c │ │ │ │ └── esp32_util.c │ │ │ ├── pwdbased.c.unused │ │ │ ├── rabbit.c │ │ │ ├── random.c │ │ │ ├── ripemd.c │ │ │ ├── rsa.c │ │ │ ├── sha.c │ │ │ ├── sha256.c │ │ │ ├── sha3.c │ │ │ ├── sha512.c │ │ │ ├── signature.c │ │ │ ├── sp_arm32.c │ │ │ ├── sp_arm64.c │ │ │ ├── sp_armthumb.c │ │ │ ├── sp_c32.c │ │ │ ├── sp_c64.c │ │ │ ├── sp_cortexm.c │ │ │ ├── sp_int.c │ │ │ ├── sp_x86_64.c │ │ │ ├── srp.c │ │ │ ├── tfm.c │ │ │ ├── wc_encrypt.c │ │ │ ├── wc_pkcs11.c │ │ │ ├── wc_port.c │ │ │ ├── wolfevent.c │ │ │ └── wolfmath.c │ │ └── wolfssl │ │ ├── version.h │ │ └── wolfcrypt │ │ ├── aes.h │ │ ├── arc4.h │ │ ├── asn.h │ │ ├── asn_public.h │ │ ├── blake2-impl.h │ │ ├── blake2-int.h │ │ ├── blake2.h │ │ ├── camellia.h │ │ ├── chacha.h │ │ ├── chacha20_poly1305.h │ │ ├── cmac.h │ │ ├── coding.h │ │ ├── compress.h │ │ ├── cpuid.h │ │ ├── cryptocb.h │ │ ├── curve25519.h │ │ ├── des3.h │ │ ├── dh.h │ │ ├── dsa.h │ │ ├── ecc.h │ │ ├── ed25519.h │ │ ├── error-crypt.h │ │ ├── fe_operations.h │ │ ├── fips_test.h │ │ ├── ge_operations.h │ │ ├── hash.h │ │ ├── hc128.h │ │ ├── hmac.h │ │ ├── idea.h │ │ ├── integer.h │ │ ├── logging.h │ │ ├── md2.h │ │ ├── md4.h │ │ ├── md5.h │ │ ├── mem_track.h │ │ ├── memory.h │ │ ├── misc.h │ │ ├── mpi_class.h │ │ ├── mpi_superclass.h │ │ ├── pkcs11.h │ │ ├── pkcs12.h │ │ ├── pkcs7.h │ │ ├── poly1305.h │ │ ├── port │ │ └── Espressif │ │ │ └── esp32-crypt.h │ │ ├── pwdbased.h │ │ ├── rabbit.h │ │ ├── random.h │ │ ├── ripemd.h │ │ ├── rsa.h │ │ ├── selftest.h │ │ ├── settings.h │ │ ├── sha.h │ │ ├── sha256.h │ │ ├── sha3.h │ │ ├── sha512.h │ │ ├── signature.h │ │ ├── sp.h │ │ ├── sp_int.h │ │ ├── srp.h │ │ ├── tfm.h │ │ ├── types.h │ │ ├── visibility.h │ │ ├── wc_encrypt.h │ │ ├── wc_pkcs11.h │ │ ├── wc_port.h │ │ ├── wolfevent.h │ │ └── wolfmath.h └── HomeKit-ESP8266 │ ├── LICENSE │ ├── README.md │ ├── examples │ ├── Example01_TemperatureSensor │ │ ├── my_accessory.c │ │ ├── temperature_sensor.ino │ │ └── wifi_info.h │ ├── Example02_Switch │ │ ├── my_accessory.c │ │ ├── switch.ino │ │ └── wifi_info.h │ ├── Example03_StatelessProgrammableSwitch │ │ ├── ESPButton.h │ │ ├── my_accessory.c │ │ ├── stateless_programmable_switch.ino │ │ └── wifi_info.h │ ├── Example04_MultipleAccessories │ │ ├── multiple_accessories.ino │ │ ├── my_accessory.c │ │ └── wifi_info.h │ └── legacy │ │ ├── simple_led │ │ ├── ButtonDebounce.h │ │ ├── ButtonHandler.h │ │ ├── simple_led.ino │ │ └── simple_led_accessory.c │ │ └── simplest_led │ │ ├── simplest_led.ino │ │ └── simplest_led_accessory.c │ ├── extras │ ├── ESP8266WiFi_nossl_noleak │ │ └── src │ │ │ ├── ESP8266WiFi.cpp │ │ │ ├── ESP8266WiFi.h │ │ │ ├── ESP8266WiFiAP.cpp │ │ │ ├── ESP8266WiFiAP.h │ │ │ ├── ESP8266WiFiGeneric.cpp │ │ │ ├── ESP8266WiFiGeneric.h │ │ │ ├── ESP8266WiFiMulti.cpp │ │ │ ├── ESP8266WiFiMulti.h │ │ │ ├── ESP8266WiFiSTA.cpp │ │ │ ├── ESP8266WiFiSTA.h │ │ │ ├── ESP8266WiFiScan.cpp │ │ │ ├── ESP8266WiFiScan.h │ │ │ ├── ESP8266WiFiType.h │ │ │ ├── WiFiClient.cpp │ │ │ ├── WiFiClient.h │ │ │ ├── WiFiServer.cpp │ │ │ ├── WiFiServer.h │ │ │ ├── WiFiUdp.cpp │ │ │ ├── WiFiUdp.h │ │ │ └── include │ │ │ ├── ClientContext.h │ │ │ ├── DataSource.h │ │ │ ├── SSLContext.h │ │ │ ├── UdpContext.h │ │ │ ├── WiFiState.h │ │ │ ├── slist.h │ │ │ ├── ssl.h │ │ │ └── wl_definitions.h │ ├── example_serial_output.txt │ ├── example_serial_output_v1.1.0.txt │ └── preview.jpg │ ├── library.json │ ├── library.properties │ ├── src │ ├── accessories.c │ ├── arduino_homekit_server.cpp │ ├── arduino_homekit_server.h │ ├── base64.c │ ├── base64.h │ ├── cJSON.c │ ├── cJSON.h │ ├── cQueue.c │ ├── cQueue.h │ ├── constants.h │ ├── crypto.c │ ├── crypto.h │ ├── esp_xpgm.h │ ├── homekit │ │ ├── characteristics.h │ │ ├── homekit.h │ │ ├── tlv.h │ │ └── types.h │ ├── homekit_debug.c │ ├── homekit_debug.h │ ├── http_parser.c │ ├── http_parser.h │ ├── json.c │ ├── json.h │ ├── pairing.h │ ├── port.c │ ├── port.h │ ├── query_params.c │ ├── query_params.h │ ├── storage.c │ ├── storage.h │ ├── tlv.c │ ├── types.c │ ├── user_settings.h │ ├── watchdog.c │ ├── watchdog.h │ ├── wolfcrypt │ │ └── src │ │ │ ├── chacha.c │ │ │ ├── chacha20_poly1305.c │ │ │ ├── curve25519.c │ │ │ ├── ed25519.c │ │ │ ├── error.c │ │ │ ├── fe_low_mem.c │ │ │ ├── fe_operations.c │ │ │ ├── ge_low_mem.c │ │ │ ├── ge_operations.c │ │ │ ├── hash.c │ │ │ ├── hmac.c │ │ │ ├── integer.c │ │ │ ├── misc.c │ │ │ ├── poly1305.c │ │ │ ├── random.c │ │ │ ├── sha.c │ │ │ ├── sha256.c │ │ │ ├── sha512.c │ │ │ ├── srp.c │ │ │ └── wolfmath.c │ └── wolfssl │ │ └── wolfcrypt │ │ ├── aes.h │ │ ├── arc4.h │ │ ├── asn.h │ │ ├── asn_public.h │ │ ├── blake2-impl.h │ │ ├── blake2-int.h │ │ ├── blake2.h │ │ ├── camellia.h │ │ ├── chacha.h │ │ ├── chacha20_poly1305.h │ │ ├── cmac.h │ │ ├── coding.h │ │ ├── compress.h │ │ ├── cpuid.h │ │ ├── curve25519.h │ │ ├── des3.h │ │ ├── dh.h │ │ ├── dsa.h │ │ ├── ecc.h │ │ ├── ed25519.h │ │ ├── error-crypt.h │ │ ├── fe_operations.h │ │ ├── fips_test.h │ │ ├── ge_operations.h │ │ ├── hash.h │ │ ├── hc128.h │ │ ├── hmac.h │ │ ├── idea.h │ │ ├── integer.h │ │ ├── logging.h │ │ ├── md2.h │ │ ├── md4.h │ │ ├── md5.h │ │ ├── mem_track.h │ │ ├── memory.h │ │ ├── misc.h │ │ ├── mpi_class.h │ │ ├── mpi_superclass.h │ │ ├── pkcs12.h │ │ ├── pkcs7.h │ │ ├── poly1305.h │ │ ├── pwdbased.h │ │ ├── rabbit.h │ │ ├── random.h │ │ ├── ripemd.h │ │ ├── rsa.h │ │ ├── settings.h │ │ ├── sha.h │ │ ├── sha256.h │ │ ├── sha3.h │ │ ├── sha512.h │ │ ├── signature.h │ │ ├── sp.h │ │ ├── srp.h │ │ ├── tfm.h │ │ ├── types.h │ │ ├── visibility.h │ │ ├── wc_encrypt.h │ │ ├── wc_port.h │ │ ├── wolfevent.h │ │ └── wolfmath.h │ └── translations │ └── README-ptbr.md ├── 4_Docs ├── ESP-12E.PDF ├── ESP-12F(ESP8266MOD).PDF ├── ESP8266 CH340原理图.jpg ├── HAP-Specification-Non-Commercial-Version.pdf ├── esp32.pdf ├── esp32wroom.png └── esp8266引脚图.png └── README.md /0_Hardware/jlcEDA/esp12f.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycraft/homekit_fan/785c88693364ca0e70091744fb3954c50de9ec84/0_Hardware/jlcEDA/esp12f.zip -------------------------------------------------------------------------------- /0_Hardware/jlcEDA/esp32.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycraft/homekit_fan/785c88693364ca0e70091744fb3954c50de9ec84/0_Hardware/jlcEDA/esp32.zip -------------------------------------------------------------------------------- /1_Firmware/1_arduino_esp8266/FANtest/my_accessory.c: -------------------------------------------------------------------------------- 1 | /* 2 | my_accessory.c 3 | Define the accessory in C language using the Macro in characteristics.h 4 | 5 | Created on: 07-04-2021 6 | Author: KUNAL VERMA 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | void my_accessory_identify(homekit_value_t _value) { 13 | printf("accessory identify\n"); 14 | } 15 | 16 | // Fan (HAP section 8.13) 17 | // required: Active 18 | // optional: ROTATION_SPEED 19 | // ROTATION_DIRECTION 20 | // NAME 21 | 22 | //一个电风扇总开关 23 | homekit_characteristic_t fan_on = HOMEKIT_CHARACTERISTIC_(ON, false); 24 | //一个控制LED 25 | homekit_characteristic_t cha_switch_on0 = HOMEKIT_CHARACTERISTIC_(ON, false); 26 | 27 | //三档调节风扇速度 28 | homekit_characteristic_t rotation_speed = HOMEKIT_CHARACTERISTIC_(ROTATION_SPEED, per_send); 29 | // format: string; HAP section 9.62; max length 64 30 | homekit_characteristic_t cha_name0 = HOMEKIT_CHARACTERISTIC_(NAME, "LED"); 31 | 32 | homekit_accessory_t *accessories[] = { 33 | HOMEKIT_ACCESSORY(.id = 1, .category = homekit_accessory_category_fan, .services = (homekit_service_t*[]) { //.id后边的数字代表带几个设备,>1就是作为桥连接 34 | HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics = (homekit_characteristic_t*[]) { 35 | HOMEKIT_CHARACTERISTIC(NAME, "FANtest"), 36 | HOMEKIT_CHARACTERISTIC(MANUFACTURER, "lycraft_Person"), 37 | HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "666666"), 38 | HOMEKIT_CHARACTERISTIC(MODEL, "ESP8266"), 39 | HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "1.0"), 40 | HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify), 41 | NULL 42 | }), 43 | HOMEKIT_SERVICE(FAN, .primary = true, .characteristics = (homekit_characteristic_t*[]) { //建一个FAN类型服务 44 | &fan_on, 45 | &rotation_speed, 46 | NULL 47 | }), 48 | HOMEKIT_SERVICE(SWITCH, .characteristics=(homekit_characteristic_t*[]){ //新建一个服务 switch类型 49 | &cha_switch_on0, 50 | &cha_name0, 51 | NULL 52 | }), 53 | NULL 54 | }), 55 | NULL 56 | }; 57 | 58 | homekit_server_config_t config = { 59 | .accessories = accessories, 60 | .password = "111-11-111" 61 | }; 62 | 63 | -------------------------------------------------------------------------------- /1_Firmware/1_arduino_esp8266/FANtest/wifi_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wifi_info.h 3 | * 4 | * Created on: 07-04-2021 5 | * Author: KUNAL VERMA 6 | */ 7 | 8 | #ifndef WIFI_INFO_H_ 9 | #define WIFI_INFO_H_ 10 | 11 | #if defined(ESP8266) 12 | #include 13 | #elif defined(ESP32) 14 | #include 15 | #endif 16 | 17 | const char *ssid = "HUAWEI-7A0A1D"; 18 | const char *password = "l12345678"; 19 | 20 | void wifi_connect() { 21 | WiFi.persistent(false); 22 | WiFi.mode(WIFI_STA); 23 | WiFi.setAutoReconnect(true); 24 | WiFi.begin(ssid, password); 25 | Serial.println("WiFi connecting..."); 26 | while (!WiFi.isConnected()) { 27 | delay(100); 28 | Serial.print("."); 29 | } 30 | Serial.print("\n"); 31 | Serial.printf("WiFi connected, IP: %s\n", WiFi.localIP().toString().c_str()); 32 | } 33 | 34 | #endif /* WIFI_INFO_H_ */ 35 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ], 7 | "unwantedRecommendations": [ 8 | "ms-vscode.cpptools-extension-pack" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.errorSquiggles": "Disabled" 3 | } -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/include/wifi_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wifi_info.h 3 | * 4 | * Created on: 07-04-2021 5 | * Author: KUNAL VERMA 6 | */ 7 | 8 | #ifndef WIFI_INFO_H_ 9 | #define WIFI_INFO_H_ 10 | 11 | #if defined(ESP8266) 12 | #include 13 | #elif defined(ESP32) 14 | #include 15 | #endif 16 | 17 | const char *ssid = "HUAWEI-7A0A1D"; 18 | const char *password = "password"; 19 | 20 | void wifi_connect() { 21 | WiFi.persistent(false); 22 | WiFi.mode(WIFI_STA); 23 | WiFi.setAutoReconnect(true); 24 | WiFi.begin(ssid, password); 25 | Serial.println("WiFi connecting..."); 26 | while (!WiFi.isConnected()) { 27 | delay(100); 28 | Serial.print("."); 29 | } 30 | Serial.print("\n"); 31 | Serial.printf("WiFi connected, IP: %s\n", WiFi.localIP().toString().c_str()); 32 | } 33 | 34 | #endif /* WIFI_INFO_H_ */ 35 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Mixiaoxiao(谜小小) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/examples/Example01_TemperatureSensor/wifi_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wifi_info.h 3 | * 4 | * Created on: 2020-05-15 5 | * Author: Mixiaoxiao (Wang Bin) 6 | */ 7 | 8 | #ifndef WIFI_INFO_H_ 9 | #define WIFI_INFO_H_ 10 | 11 | #if defined(ESP8266) 12 | #include 13 | #elif defined(ESP32) 14 | #include 15 | #endif 16 | 17 | const char *ssid = "your-ssid"; 18 | const char *password = "your-password"; 19 | 20 | void wifi_connect() { 21 | WiFi.persistent(false); 22 | WiFi.mode(WIFI_STA); 23 | WiFi.setAutoReconnect(true); 24 | WiFi.begin(ssid, password); 25 | Serial.println("WiFi connecting..."); 26 | while (!WiFi.isConnected()) { 27 | delay(100); 28 | Serial.print("."); 29 | } 30 | Serial.print("\n"); 31 | Serial.printf("WiFi connected, IP: %s\n", WiFi.localIP().toString().c_str()); 32 | } 33 | 34 | #endif /* WIFI_INFO_H_ */ 35 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/examples/Example02_Switch/my_accessory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * my_accessory.c 3 | * Define the accessory in C language using the Macro in characteristics.h 4 | * 5 | * Created on: 2020-05-15 6 | * Author: Mixiaoxiao (Wang Bin) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | void my_accessory_identify(homekit_value_t _value) { 13 | printf("accessory identify\n"); 14 | } 15 | 16 | // Switch (HAP section 8.38) 17 | // required: ON 18 | // optional: NAME 19 | 20 | // format: bool; HAP section 9.70; write the .setter function to get the switch-event sent from iOS Home APP. 21 | homekit_characteristic_t cha_switch_on = HOMEKIT_CHARACTERISTIC_(ON, false); 22 | 23 | // format: string; HAP section 9.62; max length 64 24 | homekit_characteristic_t cha_name = HOMEKIT_CHARACTERISTIC_(NAME, "Switch"); 25 | 26 | homekit_accessory_t *accessories[] = { 27 | HOMEKIT_ACCESSORY(.id=1, .category=homekit_accessory_category_switch, .services=(homekit_service_t*[]) { 28 | HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]) { 29 | HOMEKIT_CHARACTERISTIC(NAME, "Switch"), 30 | HOMEKIT_CHARACTERISTIC(MANUFACTURER, "Arduino HomeKit"), 31 | HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "0123456"), 32 | HOMEKIT_CHARACTERISTIC(MODEL, "ESP8266/ESP32"), 33 | HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "1.0"), 34 | HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify), 35 | NULL 36 | }), 37 | HOMEKIT_SERVICE(SWITCH, .primary=true, .characteristics=(homekit_characteristic_t*[]){ 38 | &cha_switch_on, 39 | &cha_name, 40 | NULL 41 | }), 42 | NULL 43 | }), 44 | NULL 45 | }; 46 | 47 | homekit_server_config_t config = { 48 | .accessories = accessories, 49 | .password = "111-11-111" 50 | }; 51 | 52 | 53 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/examples/Example02_Switch/wifi_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wifi_info.h 3 | * 4 | * Created on: 2020-05-15 5 | * Author: Mixiaoxiao (Wang Bin) 6 | */ 7 | 8 | #ifndef WIFI_INFO_H_ 9 | #define WIFI_INFO_H_ 10 | 11 | #if defined(ESP8266) 12 | #include 13 | #elif defined(ESP32) 14 | #include 15 | #endif 16 | 17 | const char *ssid = "your-ssid"; 18 | const char *password = "your-password"; 19 | 20 | void wifi_connect() { 21 | WiFi.persistent(false); 22 | WiFi.mode(WIFI_STA); 23 | WiFi.setAutoReconnect(true); 24 | WiFi.begin(ssid, password); 25 | Serial.println("WiFi connecting..."); 26 | while (!WiFi.isConnected()) { 27 | delay(100); 28 | Serial.print("."); 29 | } 30 | Serial.print("\n"); 31 | Serial.printf("WiFi connected, IP: %s\n", WiFi.localIP().toString().c_str()); 32 | } 33 | 34 | #endif /* WIFI_INFO_H_ */ 35 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/examples/Example03_StatelessProgrammableSwitch/my_accessory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * my_accessory.c 3 | * Define the accessory in C language using the Macro in characteristics.h 4 | * 5 | * Created on: 2020-05-16 6 | * Author: Mixiaoxiao (Wang Bin) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | void my_accessory_identify(homekit_value_t _value) { 13 | printf("accessory identify\n"); 14 | } 15 | 16 | // Stateless Programmable Switch (HAP section 8.37) 17 | // required: PROGRAMMABLE_SWITCH_EVENT 18 | // optional: NAME, SERVICE_LABEL_INDEX 19 | 20 | // format: uint8; HAP section 9.75; write the .getter function and always return "null" for reading 21 | homekit_characteristic_t cha_programmable_switch_event = HOMEKIT_CHARACTERISTIC_(PROGRAMMABLE_SWITCH_EVENT, 0); 22 | 23 | homekit_accessory_t *accessories[] = { 24 | HOMEKIT_ACCESSORY(.id=1, .category=homekit_accessory_category_switch, .services=(homekit_service_t*[]) { 25 | HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]) { 26 | HOMEKIT_CHARACTERISTIC(NAME, "Stateless Programmable Switch"), 27 | HOMEKIT_CHARACTERISTIC(MANUFACTURER, "Arduino HomeKit"), 28 | HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "0123456"), 29 | HOMEKIT_CHARACTERISTIC(MODEL, "ESP8266/ESP32"), 30 | HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "1.0"), 31 | HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify), 32 | NULL 33 | }), 34 | HOMEKIT_SERVICE(STATELESS_PROGRAMMABLE_SWITCH, .primary=true, .characteristics=(homekit_characteristic_t*[]){ 35 | HOMEKIT_CHARACTERISTIC(NAME, "Stateless Programmable Switch"), 36 | &cha_programmable_switch_event, 37 | NULL 38 | }), 39 | NULL 40 | }), 41 | NULL 42 | }; 43 | 44 | homekit_server_config_t config = { 45 | .accessories = accessories, 46 | .password = "111-11-111" 47 | }; 48 | 49 | 50 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/examples/Example03_StatelessProgrammableSwitch/wifi_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wifi_info.h 3 | * 4 | * Created on: 2020-05-15 5 | * Author: Mixiaoxiao (Wang Bin) 6 | */ 7 | 8 | #ifndef WIFI_INFO_H_ 9 | #define WIFI_INFO_H_ 10 | 11 | #if defined(ESP8266) 12 | #include 13 | #elif defined(ESP32) 14 | #include 15 | #endif 16 | 17 | const char *ssid = "your-ssid"; 18 | const char *password = "your-password"; 19 | 20 | void wifi_connect() { 21 | WiFi.persistent(false); 22 | WiFi.mode(WIFI_STA); 23 | WiFi.setAutoReconnect(true); 24 | WiFi.begin(ssid, password); 25 | Serial.println("WiFi connecting..."); 26 | while (!WiFi.isConnected()) { 27 | delay(100); 28 | Serial.print("."); 29 | } 30 | Serial.print("\n"); 31 | Serial.printf("WiFi connected, IP: %s\n", WiFi.localIP().toString().c_str()); 32 | } 33 | 34 | #endif /* WIFI_INFO_H_ */ 35 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/examples/Example04_MultipleAccessories/wifi_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wifi_info.h 3 | * 4 | * Created on: 2020-05-15 5 | * Author: Mixiaoxiao (Wang Bin) 6 | */ 7 | 8 | #ifndef WIFI_INFO_H_ 9 | #define WIFI_INFO_H_ 10 | 11 | #if defined(ESP8266) 12 | #include 13 | #elif defined(ESP32) 14 | #include 15 | #endif 16 | 17 | const char *ssid = "your-ssid"; 18 | const char *password = "your-password"; 19 | 20 | void wifi_connect() { 21 | WiFi.persistent(false); 22 | WiFi.mode(WIFI_STA); 23 | WiFi.setAutoReconnect(true); 24 | WiFi.begin(ssid, password); 25 | Serial.println("WiFi connecting..."); 26 | while (!WiFi.isConnected()) { 27 | delay(100); 28 | Serial.print("."); 29 | } 30 | Serial.print("\n"); 31 | Serial.printf("WiFi connected, IP: %s\n", WiFi.localIP().toString().c_str()); 32 | } 33 | 34 | #endif /* WIFI_INFO_H_ */ 35 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/extras/ESP8266WiFi_nossl_noleak/src/ESP8266WiFiAP.h: -------------------------------------------------------------------------------- 1 | /* 2 | ESP8266WiFiAP.h - esp8266 Wifi support. 3 | Based on WiFi.h from Arduino WiFi shield library. 4 | Copyright (c) 2011-2014 Arduino. All right reserved. 5 | Modified by Ivan Grokhotkov, December 2014 6 | Reworked by Markus Sattler, December 2015 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #ifndef ESP8266WIFIAP_H_ 24 | #define ESP8266WIFIAP_H_ 25 | 26 | 27 | #include "ESP8266WiFiType.h" 28 | #include "ESP8266WiFiGeneric.h" 29 | 30 | 31 | class ESP8266WiFiAPClass { 32 | 33 | // ---------------------------------------------------------------------------------------------- 34 | // ----------------------------------------- AP function ---------------------------------------- 35 | // ---------------------------------------------------------------------------------------------- 36 | 37 | public: 38 | 39 | bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4); 40 | bool softAP(const String& ssid,const String& passphrase = emptyString,int channel = 1,int ssid_hidden = 0,int max_connection = 4); 41 | bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet); 42 | bool softAPdisconnect(bool wifioff = false); 43 | 44 | uint8_t softAPgetStationNum(); 45 | 46 | IPAddress softAPIP(); 47 | 48 | uint8_t* softAPmacAddress(uint8_t* mac); 49 | String softAPmacAddress(void); 50 | 51 | String softAPSSID() const; 52 | String softAPPSK() const; 53 | 54 | protected: 55 | 56 | }; 57 | 58 | #endif /* ESP8266WIFIAP_H_*/ 59 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/extras/ESP8266WiFi_nossl_noleak/src/ESP8266WiFiMulti.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file ESP8266WiFiMulti.h 4 | * @date 16.05.2015 5 | * @author Markus Sattler 6 | * 7 | * Copyright (c) 2015 Markus Sattler. All rights reserved. 8 | * This file is part of the esp8266 core for Arduino environment. 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | * 24 | */ 25 | 26 | 27 | #ifndef WIFICLIENTMULTI_H_ 28 | #define WIFICLIENTMULTI_H_ 29 | 30 | #include "ESP8266WiFi.h" 31 | #include 32 | 33 | #ifdef DEBUG_ESP_WIFI 34 | #ifdef DEBUG_ESP_PORT 35 | #define DEBUG_WIFI_MULTI(fmt, ...) DEBUG_ESP_PORT.printf_P( (PGM_P)PSTR(fmt), ##__VA_ARGS__ ) 36 | #endif 37 | #endif 38 | 39 | #ifndef DEBUG_WIFI_MULTI 40 | #define DEBUG_WIFI_MULTI(...) do { (void)0; } while (0) 41 | #endif 42 | 43 | struct WifiAPEntry { 44 | char * ssid; 45 | char * passphrase; 46 | }; 47 | 48 | typedef std::vector WifiAPlist; 49 | 50 | class ESP8266WiFiMulti { 51 | public: 52 | ESP8266WiFiMulti(); 53 | ~ESP8266WiFiMulti(); 54 | 55 | bool addAP(const char* ssid, const char *passphrase = NULL); 56 | bool existsAP(const char* ssid, const char *passphrase = NULL); 57 | 58 | wl_status_t run(void); 59 | 60 | void cleanAPlist(void); 61 | 62 | private: 63 | WifiAPlist APlist; 64 | bool APlistAdd(const char* ssid, const char *passphrase = NULL); 65 | bool APlistExists(const char* ssid, const char *passphrase = NULL); 66 | void APlistClean(void); 67 | 68 | }; 69 | 70 | #endif /* WIFICLIENTMULTI_H_ */ 71 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/extras/ESP8266WiFi_nossl_noleak/src/WiFiServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiServer.h - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino LLC. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified by Ivan Grokhotkov, December 2014 - esp8266 support 20 | */ 21 | 22 | #ifndef wifiserver_h 23 | #define wifiserver_h 24 | 25 | extern "C" { 26 | #include "include/wl_definitions.h" 27 | 28 | struct tcp_pcb; 29 | } 30 | 31 | #include "Server.h" 32 | #include "IPAddress.h" 33 | 34 | class ClientContext; 35 | class WiFiClient; 36 | 37 | class WiFiServer : public Server { 38 | // Secure server needs access to all the private entries here 39 | protected: 40 | uint16_t _port; 41 | IPAddress _addr; 42 | tcp_pcb* _pcb; 43 | 44 | ClientContext* _unclaimed; 45 | ClientContext* _discarded; 46 | enum { _ndDefault, _ndFalse, _ndTrue } _noDelay = _ndDefault; 47 | 48 | public: 49 | WiFiServer(const IPAddress& addr, uint16_t port); 50 | WiFiServer(uint16_t port); 51 | virtual ~WiFiServer() {} 52 | WiFiClient available(uint8_t* status = NULL); 53 | bool hasClient(); 54 | void begin(); 55 | void begin(uint16_t port); 56 | void setNoDelay(bool nodelay); 57 | bool getNoDelay(); 58 | virtual size_t write(uint8_t); 59 | virtual size_t write(const uint8_t *buf, size_t size); 60 | uint8_t status(); 61 | void close(); 62 | void stop(); 63 | 64 | using Print::write; 65 | using ClientType = WiFiClient; 66 | 67 | protected: 68 | long _accept(tcp_pcb* newpcb, long err); 69 | void _discard(ClientContext* client); 70 | 71 | static long _s_accept(void *arg, tcp_pcb* newpcb, long err); 72 | static void _s_discard(void* server, ClientContext* ctx); 73 | }; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/extras/ESP8266WiFi_nossl_noleak/src/include/WiFiState.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef WIFISTATE_H_ 3 | #define WIFISTATE_H_ 4 | 5 | #include 6 | #include 7 | 8 | struct WiFiState 9 | { 10 | uint32_t crc; 11 | struct 12 | { 13 | station_config fwconfig; 14 | ip_info ip; 15 | ip_addr_t dns[2]; 16 | ip_addr_t ntp[2]; 17 | WiFiMode_t mode; 18 | uint8_t channel; 19 | bool persistent; 20 | } state; 21 | }; 22 | 23 | #endif // WIFISTATE_H_ 24 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/extras/ESP8266WiFi_nossl_noleak/src/include/slist.h: -------------------------------------------------------------------------------- 1 | #ifndef SLIST_H 2 | #define SLIST_H 3 | 4 | template 5 | class SList { 6 | public: 7 | SList() : _next(0) { } 8 | 9 | protected: 10 | 11 | static void _add(T* self) { 12 | T* tmp = _s_first; 13 | _s_first = self; 14 | self->_next = tmp; 15 | } 16 | 17 | static void _remove(T* self) { 18 | if (_s_first == self) { 19 | _s_first = self->_next; 20 | self->_next = 0; 21 | return; 22 | } 23 | 24 | for (T* prev = _s_first; prev->_next; prev = prev->_next) { 25 | if (prev->_next == self) { 26 | prev->_next = self->_next; 27 | self->_next = 0; 28 | return; 29 | } 30 | } 31 | } 32 | 33 | static T* _s_first; 34 | T* _next; 35 | }; 36 | 37 | 38 | #endif //SLIST_H 39 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/extras/preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycraft/homekit_fan/785c88693364ca0e70091744fb3954c50de9ec84/1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/extras/preview.jpg -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"HomeKit-ESP8266", 3 | "description":"Apple HomeKit accessory server library for the ESP8266 Arduino core.", 4 | "keywords":"homekit,esp8266,esp32,apple homekit", 5 | "authors": 6 | { 7 | "name": "Mixiaoxiao (Wang Bin)", 8 | "maintainer": true 9 | }, 10 | "repository": 11 | { 12 | "type": "git", 13 | "url": "https://github.com/Mixiaoxiao/Arduino-HomeKit-ESP8266.git" 14 | }, 15 | "version": "1.2.0", 16 | "license": "MIT", 17 | "frameworks": "arduino", 18 | "platforms": "espressif8266", 19 | "build": { 20 | "libCompatMode": 2 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/library.properties: -------------------------------------------------------------------------------- 1 | name=HomeKit-ESP8266 2 | version=1.2.0 3 | author=Mixiaoxiao 4 | maintainer=Mixiaoxiao 5 | sentence=Native Apple HomeKit accessory implementation for the ESP8266 Arduino core. 6 | paragraph=Native Apple HomeKit Accessory Implementation for the ESP8266 Arduino core. 7 | category=Communication 8 | url=https://github.com/Mixiaoxiao/Arduino-HomeKit-ESP8266.git 9 | architectures=esp8266 10 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/base64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | 10 | size_t base64_encoded_size(const unsigned char* data, size_t size); 11 | size_t base64_decoded_size(const unsigned char* encoded_data, size_t encoded_size); 12 | //multiple definition of `base64_decode'; 13 | int base64_encode_(const unsigned char* data, size_t data_size, unsigned char *encoded_data); 14 | int base64_decode_(const unsigned char* encoded_data, size_t encoded_size, unsigned char *data); 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/constants.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define DEVICE_ID_SIZE 36 4 | #define ACCESSORY_ID_SIZE 17 5 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/esp_xpgm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * xpgm.h 3 | * 4 | * Created on: 2020-03-08 5 | * Author: Wang Bin 6 | */ 7 | 8 | #ifndef ESP_XPGM_H_ 9 | #define ESP_XPGM_H_ 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | //see "osapi.h" 20 | /* 21 | This function works only after Serial.setDebugOutput(true); ? 22 | otherwise Serial prints nothing. 23 | #define esp_printf(fmt, ...) do { \ 24 | static const char flash_str[] ICACHE_RODATA_ATTR STORE_ATTR = fmt; \ 25 | os_printf_plus(flash_str, ##__VA_ARGS__); \ 26 | } while(0)*/ 27 | 28 | #define XPGM_PRINTF(fmt, ...) printf_P(PSTR(fmt) , ##__VA_ARGS__); 29 | 30 | #define XPGM_VAR(v0, v1) v0##v1 31 | 32 | // pgm_ptr --> ram_ptr 33 | #define XPGM_CPY(ram_ptr, pgm_ptr, size) memcpy_P(ram_ptr, pgm_ptr, size) 34 | 35 | #define XPGM_BUFFCPY(buff_type, buff_name, pgm_ptr, size) size_t XPGM_VAR(buff_name, _size) = size; \ 36 | buff_type buff_name[XPGM_VAR(buff_name, _size)]; \ 37 | XPGM_CPY(buff_name, pgm_ptr, XPGM_VAR(buff_name, _size)); 38 | 39 | #define XPGM_BUFFCPY_ARRAY(buff_type, buff_name, pgm_array) XPGM_BUFFCPY(buff_type, buff_name, pgm_array, sizeof(pgm_array)) 40 | 41 | #define XPGM_BUFFCPY_STRING(buff_type, buff_name, pgm_string) XPGM_BUFFCPY(buff_type, buff_name, pgm_string, strlen_P(pgm_string) + 1) 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* ESP_XPGM_H_ */ 48 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/homekit/tlv.h: -------------------------------------------------------------------------------- 1 | #ifndef __TLV_H__ 2 | #define __TLV_H__ 3 | 4 | #define __need_size_t 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | typedef unsigned char byte; 15 | 16 | typedef struct _tlv { 17 | struct _tlv *next; 18 | byte type; 19 | byte *value; 20 | size_t size; 21 | } tlv_t; 22 | 23 | 24 | typedef struct { 25 | tlv_t *head; 26 | } tlv_values_t; 27 | 28 | 29 | tlv_values_t *tlv_new(); 30 | 31 | void tlv_free(tlv_values_t *values); 32 | 33 | int tlv_add_value(tlv_values_t *values, byte type, const byte *value, size_t size); 34 | int tlv_add_string_value(tlv_values_t *values, byte type, const char *value); 35 | int tlv_add_integer_value(tlv_values_t *values, byte type, size_t size, int value); 36 | int tlv_add_tlv_value(tlv_values_t *values, byte type, tlv_values_t *value); 37 | 38 | tlv_t *tlv_get_value(const tlv_values_t *values, byte type); 39 | int tlv_get_integer_value(const tlv_values_t *values, byte type, int def); 40 | tlv_values_t *tlv_get_tlv_value(const tlv_values_t *values, byte type); 41 | 42 | int tlv_format(const tlv_values_t *values, byte *buffer, size_t *size); 43 | 44 | int tlv_parse(const byte *buffer, size_t length, tlv_values_t *values); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif // __TLV_H__ 51 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/homekit_debug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "homekit_debug.h" 5 | 6 | 7 | char *binary_to_string(const byte *data, size_t size) { 8 | int i; 9 | 10 | size_t buffer_size = 1; // 1 char for eos 11 | for (i=0; i= 32 && data[i] < 128) ? 1 : 4); 13 | 14 | char *buffer = malloc(buffer_size); 15 | 16 | int pos = 0; 17 | for (i=0; i= 128) { 22 | size_t printed = snprintf(&buffer[pos], buffer_size - pos, "\\x%02X", data[i]); 23 | if (printed > 0) { 24 | pos += printed; 25 | } 26 | } else { 27 | buffer[pos++] = data[i]; 28 | } 29 | } 30 | buffer[pos] = 0; 31 | 32 | return buffer; 33 | } 34 | 35 | 36 | void print_binary(const char *prompt, const byte *data, size_t size) { 37 | #ifdef HOMEKIT_DEBUG 38 | char *buffer = binary_to_string(data, size); 39 | printf("%s (%d bytes): \"%s\"\n", prompt, (int)size, buffer); 40 | free(buffer); 41 | #endif 42 | } 43 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/homekit_debug.h: -------------------------------------------------------------------------------- 1 | #ifndef __HOMEKIT_DEBUG_H__ 2 | #define __HOMEKIT_DEBUG_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include "Arduino.h" 11 | #include 12 | #include 13 | 14 | typedef unsigned char byte; 15 | 16 | //#define HOMEKIT_DEBUG 17 | 18 | #define HOMEKIT_PRINTF XPGM_PRINTF 19 | 20 | #ifdef HOMEKIT_DEBUG 21 | 22 | #define DEBUG(message, ...) HOMEKIT_PRINTF(">>> %s: " message "\n", __func__, ##__VA_ARGS__) 23 | static uint32_t start_time = 0; 24 | #define DEBUG_TIME_BEGIN() start_time=millis(); 25 | #define DEBUG_TIME_END(func_name) HOMEKIT_PRINTF("### [%7d] %s took %6dms\n", millis(), func_name, (millis() - start_time)); 26 | 27 | #else 28 | 29 | #define DEBUG(message, ...) 30 | #define DEBUG_TIME_BEGIN() 31 | #define DEBUG_TIME_END(func_name) 32 | 33 | #endif 34 | 35 | #define INFO(message, ...) HOMEKIT_PRINTF(">>> [%7d] HomeKit: " message "\n", millis(), ##__VA_ARGS__) 36 | #define ERROR(message, ...) HOMEKIT_PRINTF("!!! [%7d] HomeKit: " message "\n", millis(), ##__VA_ARGS__) 37 | #define INFO_HEAP() INFO("Free heap: %d", system_get_free_heap_size()); 38 | #define DEBUG_HEAP() DEBUG("Free heap: %d", system_get_free_heap_size()); 39 | 40 | char *binary_to_string(const byte *data, size_t size); 41 | void print_binary(const char *prompt, const byte *data, size_t size); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif // __HOMEKIT_DEBUG_H__ 48 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/json.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | struct json_stream; 10 | typedef struct json_stream json_stream; 11 | 12 | typedef void (*json_flush_callback)(uint8_t *buffer, size_t size, void *context); 13 | 14 | json_stream *json_new(size_t buffer_size, json_flush_callback on_flush, void *context); 15 | void json_free(json_stream *json); 16 | 17 | void json_flush(json_stream *json); 18 | 19 | void json_object_start(json_stream *json); 20 | void json_object_end(json_stream *json); 21 | 22 | void json_array_start(json_stream *json); 23 | void json_array_end(json_stream *json); 24 | 25 | void json_integer(json_stream *json, int x); 26 | void json_uint8(json_stream *json, uint8_t x); 27 | void json_uint16(json_stream *json, uint16_t x); 28 | void json_uint32(json_stream *json, uint32_t x); 29 | void json_uint64(json_stream *json, uint64_t x); 30 | void json_float(json_stream *json, float x); 31 | void json_string(json_stream *json, const char *x); 32 | void json_boolean(json_stream *json, bool x); 33 | void json_null(json_stream *json); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/pairing.h: -------------------------------------------------------------------------------- 1 | #ifndef __PAIRING_H__ 2 | #define __PAIRING_H__ 3 | 4 | #include "constants.h" 5 | #include "crypto.h" 6 | 7 | 8 | typedef enum { 9 | pairing_permissions_admin = (1 << 0), 10 | } pairing_permissions_t; 11 | 12 | typedef struct { 13 | int id; 14 | char device_id[DEVICE_ID_SIZE + 1]; 15 | ed25519_key device_key; 16 | pairing_permissions_t permissions; 17 | } pairing_t; 18 | 19 | #endif // __PAIRING_H__ 20 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/port.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | uint32_t homekit_random(); 10 | void homekit_random_fill(uint8_t *data, size_t size); 11 | 12 | void homekit_system_restart(); 13 | void homekit_overclock_start(); 14 | void homekit_overclock_end(); 15 | 16 | #ifdef ESP_OPEN_RTOS 17 | #include 18 | #define ESP_OK 0 19 | #endif 20 | 21 | //#ifdef ESP_IDF 22 | //#include 23 | //#include 24 | 25 | #ifdef ARDUINO_ARCH_ESP8266 26 | #include "Arduino.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | #define ESP_OK SPI_FLASH_RESULT_OK //0 34 | 35 | #define SPI_FLASH_SECTOR_SIZE SPI_FLASH_SEC_SIZE 36 | #define spiflash_read(addr, buffer, size) (spi_flash_read((addr), (buffer), (size)) == ESP_OK) 37 | #define spiflash_write(addr, data, size) (spi_flash_write((addr), (data), (size)) == ESP_OK) 38 | #define spiflash_erase_sector(addr) (spi_flash_erase_sector((addr) / SPI_FLASH_SECTOR_SIZE) == ESP_OK) 39 | #endif 40 | 41 | 42 | #ifdef ESP_IDF 43 | #define SERVER_TASK_STACK 12288 44 | #else 45 | #define SERVER_TASK_STACK 2048 46 | #endif 47 | 48 | 49 | //void homekit_mdns_init(); 50 | //void homekit_mdns_configure_init(const char *instance_name, int port); 51 | //void homekit_mdns_add_txt(const char *key, const char *format, ...); 52 | //void homekit_mdns_configure_finalize(); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/query_params.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "query_params.h" 4 | 5 | 6 | query_param_t *query_params_parse(const char *s) { 7 | query_param_t *params = NULL; 8 | 9 | int i = 0; 10 | while (1) { 11 | int pos = i; 12 | while (s[i] && s[i] != '=' && s[i] != '&' && s[i] != '#') i++; 13 | if (i == pos) { 14 | i++; 15 | continue; 16 | } 17 | 18 | query_param_t *param = malloc(sizeof(query_param_t)); 19 | param->name = strndup(s+pos, i-pos); 20 | param->value = NULL; 21 | param->next = params; 22 | params = param; 23 | 24 | if (s[i] == '=') { 25 | i++; 26 | pos = i; 27 | while (s[i] && s[i] != '&' && s[i] != '#') i++; 28 | if (i != pos) { 29 | param->value = strndup(s+pos, i-pos); 30 | } 31 | } 32 | 33 | if (!s[i] || s[i] == '#') 34 | break; 35 | } 36 | 37 | return params; 38 | } 39 | 40 | 41 | query_param_t *query_params_find(query_param_t *params, const char *name) { 42 | while (params) { 43 | if (!strcmp(params->name, name)) 44 | return params; 45 | params = params->next; 46 | } 47 | 48 | return NULL; 49 | } 50 | 51 | 52 | void query_params_free(query_param_t *params) { 53 | while (params) { 54 | query_param_t *next = params->next; 55 | if (params->name) 56 | free(params->name); 57 | if (params->value) 58 | free(params->value); 59 | free(params); 60 | 61 | params = next; 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/query_params.h: -------------------------------------------------------------------------------- 1 | #ifndef __HOMEKIT_QUERY_PARAMS__ 2 | #define __HOMEKIT_QUERY_PARAMS__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef struct _query_param { 9 | char *name; 10 | char *value; 11 | 12 | struct _query_param *next; 13 | } query_param_t; 14 | 15 | query_param_t *query_params_parse(const char *s); 16 | query_param_t *query_params_find(query_param_t *params, const char *name); 17 | void query_params_free(query_param_t *params); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif // __HOMEKIT_QUERY_PARAMS__ 24 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/storage.h: -------------------------------------------------------------------------------- 1 | #ifndef __STORAGE_H__ 2 | #define __STORAGE_H__ 3 | 4 | //#include "EEPROM.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #include "pairing.h" 11 | 12 | int homekit_storage_reset(); 13 | 14 | int homekit_storage_init(); 15 | 16 | void homekit_storage_save_accessory_id(const char *accessory_id); 17 | int homekit_storage_load_accessory_id(char *data); 18 | 19 | void homekit_storage_save_accessory_key(const ed25519_key *key); 20 | int homekit_storage_load_accessory_key(ed25519_key *key); 21 | 22 | bool homekit_storage_can_add_pairing(); 23 | int homekit_storage_add_pairing(const char *device_id, const ed25519_key *device_key, byte permissions); 24 | int homekit_storage_update_pairing(const char *device_id, byte permissions); 25 | int homekit_storage_remove_pairing(const char *device_id); 26 | int homekit_storage_find_pairing(const char *device_id, pairing_t *pairing); 27 | 28 | typedef struct { 29 | int idx; 30 | } pairing_iterator_t; 31 | 32 | 33 | void homekit_storage_pairing_iterator_init(pairing_iterator_t *it); 34 | int homekit_storage_next_pairing(pairing_iterator_t *it, pairing_t *pairing); 35 | void homekit_storage_pairing_iterator_done(pairing_iterator_t *iterator); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | #endif // __STORAGE_H__ 41 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/user_settings.h: -------------------------------------------------------------------------------- 1 | #ifndef wolfcrypt_user_settings_h 2 | #define wolfcrypt_user_settings_h 3 | 4 | #define WOLFSSL_USER_SETTINGS 5 | 6 | //#define ARDUINO_HOMEKIT_LOWROM 7 | 8 | //skip ed25519_verify, see crypto_ed25519_verify in crypto.c 9 | //Pair Verify Step 2/2: skip=35ms, not-skip=794ms 10 | //#define ARDUINO_HOMEKIT_SKIP_ED25519_VERIFY 11 | 12 | #include "stdint.h" 13 | #include "stddef.h" 14 | #include "stdlib.h" 15 | #include "osapi.h" 16 | #include "homekit_debug.h" 17 | 18 | static inline int hwrand_generate_block(uint8_t *buf, size_t len) { 19 | os_get_random(buf, len); 20 | return 0; 21 | } 22 | 23 | #define WC_NO_HARDEN 24 | #define NO_WOLFSSL_DIR 25 | #define SINGLE_THREADED 26 | #define WOLFSSL_LWIP 27 | #define NO_INLINE 28 | 29 | #define NO_WOLFSSL_MEMORY 30 | #define MP_LOW_MEM 31 | 32 | #define CUSTOM_RAND_GENERATE_BLOCK hwrand_generate_block 33 | 34 | //========== 35 | // added 36 | //========== 37 | #define WOLFCRYPT_ONLY 38 | 39 | #define NO_ASN 40 | #define NO_AES 41 | #define NO_RC4 42 | #define NO_RSA 43 | #define NO_SHA256 44 | #define NO_DH 45 | #define NO_DSA 46 | #define NO_CODING 47 | #define NO_SHA 48 | #define NO_MD5 49 | 50 | #define HAVE_CURVE25519 51 | #define HAVE_CHACHA 52 | #define HAVE_POLY1305 53 | #define HAVE_ED25519 54 | #define WOLFSSL_SHA512 55 | #define WOLFCRYPT_HAVE_SRP 56 | #define HAVE_HKDF 57 | 58 | #define WC_NO_HASHDRBG 59 | 60 | #define WOLFSSL_BASE64_ENCODE 61 | 62 | //see integer.c 63 | //default winsize=5(MP_LOW_MEM), but ram(heap) is not sufficient! 64 | //winsize of {2,3,4,5} are same performance 65 | //lower winsize, lower ram required 66 | #define ESP_INTEGER_WINSIZE 2 67 | //winsize=3 & mp_exptmod_fast : ram(heap) is not sufficient 68 | //force use s_mp_exptmod (lower memory), and smiller performance with mp_exptmod_fast 69 | #define ESP_FORCE_S_MP_EXPTMOD 70 | //winsize = 5 & mp_exptmod_fast 最快,Pair Verify Step 2/2 = 10s左右 71 | //winsize = 6 heap不够 72 | 73 | 74 | #define MP_16BIT //faster than 32bit in ESP8266 75 | 76 | #if defined(ARDUINO_HOMEKIT_LOWROM) 77 | 78 | #define CURVE25519_SMALL 79 | #define ED25519_SMALL //关联ED25519,关闭这个之后编译dram会超(stack mem太大) 80 | //`.bss' is not within region `dram0_0_seg' 81 | 82 | #else 83 | // crypto.c crypto_ed25519_verify 84 | // No sufficient ram to run ge_double_scalarmult_vartime in ge_operations.c 85 | // Run the ge_double_scalarmult_vartime in ge_low_mem 86 | #define ESP_GE_DOUBLE_SCALARMULT_VARTIME_LOWMEM 87 | 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/watchdog.c: -------------------------------------------------------------------------------- 1 | // Base on esp_hw_wdt in github 2 | /* 3 | * Copyright (c) 2014-2017 Cesanta Software Limited 4 | * All rights reserved 5 | * Changed: 6 | * 2017 Alexander Epstine (a@epstine.com) 7 | */ 8 | 9 | #include "watchdog.h" 10 | #include "Arduino.h" 11 | #include "stdint.h" 12 | #include "user_interface.h" 13 | #include "homekit_debug.h" 14 | 15 | #define REG_WDT_BASE 0x60000900 16 | 17 | #define WDT_CTL (REG_WDT_BASE + 0x0) 18 | #define WDT_CTL_ENABLE (BIT(0)) 19 | #define WDT_RESET (REG_WDT_BASE + 0x14) 20 | #define WDT_RESET_VALUE 0x73 21 | 22 | void esp_hw_wdt_enable() { 23 | SET_PERI_REG_MASK(WDT_CTL, WDT_CTL_ENABLE); 24 | } 25 | 26 | void esp_hw_wdt_disable() { 27 | CLEAR_PERI_REG_MASK(WDT_CTL, WDT_CTL_ENABLE); 28 | } 29 | 30 | void esp_hw_wdt_feed() { 31 | WRITE_PERI_REG(WDT_RESET, WDT_RESET_VALUE); 32 | } 33 | 34 | void watchdog_disable_all() { 35 | system_soft_wdt_stop(); 36 | esp_hw_wdt_disable(); 37 | } 38 | 39 | void watchdog_enable_all() { 40 | esp_hw_wdt_enable(); 41 | system_soft_wdt_restart(); 42 | } 43 | 44 | #ifdef HOMEKIT_DEBUG 45 | 46 | static uint32_t wdt_checkpoint; 47 | 48 | void watchdog_check_begin() { 49 | wdt_checkpoint = millis(); 50 | } 51 | 52 | void watchdog_check_end(const char *message) { 53 | uint32_t d = millis() - wdt_checkpoint; 54 | printf("[WatchDog] Function %s took: %dms\n", message, d); 55 | } 56 | 57 | #else 58 | 59 | void watchdog_check_begin() { 60 | } 61 | void watchdog_check_end(const char *message) { 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/watchdog.h: -------------------------------------------------------------------------------- 1 | #ifndef WATCHDOG_H_ 2 | #define WATCHDOG_H_ 3 | 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | void watchdog_disable_all(); 10 | 11 | void watchdog_enable_all(); 12 | 13 | void watchdog_check_begin(); 14 | 15 | void watchdog_check_end(const char* message); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | 22 | #endif /* WATCHDOG_H_ */ 23 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/arc4.h: -------------------------------------------------------------------------------- 1 | /* arc4.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | #ifndef WOLF_CRYPT_ARC4_H 25 | #define WOLF_CRYPT_ARC4_H 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #ifdef WOLFSSL_ASYNC_CRYPT 34 | #include 35 | #endif 36 | 37 | enum { 38 | ARC4_ENC_TYPE = 4, /* cipher unique type */ 39 | ARC4_STATE_SIZE = 256 40 | }; 41 | 42 | /* ARC4 encryption and decryption */ 43 | typedef struct Arc4 { 44 | byte x; 45 | byte y; 46 | byte state[ARC4_STATE_SIZE]; 47 | #ifdef WOLFSSL_ASYNC_CRYPT 48 | WC_ASYNC_DEV asyncDev; 49 | #endif 50 | void* heap; 51 | } Arc4; 52 | 53 | WOLFSSL_API int wc_Arc4Process(Arc4*, byte*, const byte*, word32); 54 | WOLFSSL_API int wc_Arc4SetKey(Arc4*, const byte*, word32); 55 | 56 | WOLFSSL_API int wc_Arc4Init(Arc4*, void*, int); 57 | WOLFSSL_API void wc_Arc4Free(Arc4*); 58 | 59 | #ifdef __cplusplus 60 | } /* extern "C" */ 61 | #endif 62 | 63 | 64 | #endif /* WOLF_CRYPT_ARC4_H */ 65 | 66 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/blake2.h: -------------------------------------------------------------------------------- 1 | /* blake2.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | 25 | #ifndef WOLF_CRYPT_BLAKE2_H 26 | #define WOLF_CRYPT_BLAKE2_H 27 | 28 | #include 29 | 30 | #ifdef HAVE_BLAKE2 31 | 32 | #include 33 | 34 | /* call old functions if using fips for the sake of hmac @wc_fips */ 35 | #ifdef HAVE_FIPS 36 | /* Since hmac can call blake functions provide original calls */ 37 | #define wc_InitBlake2b InitBlake2b 38 | #define wc_Blake2bUpdate Blake2bUpdate 39 | #define wc_Blake2bFinal Blake2bFinal 40 | #endif 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* in bytes, variable digest size up to 512 bits (64 bytes) */ 47 | enum { 48 | BLAKE2B_ID = 7, /* hash type unique */ 49 | BLAKE2B_256 = 32 /* 256 bit type, SSL default */ 50 | }; 51 | 52 | 53 | /* BLAKE2b digest */ 54 | typedef struct Blake2b { 55 | blake2b_state S[1]; /* our state */ 56 | word32 digestSz; /* digest size used on init */ 57 | } Blake2b; 58 | 59 | 60 | WOLFSSL_API int wc_InitBlake2b(Blake2b*, word32); 61 | WOLFSSL_API int wc_Blake2bUpdate(Blake2b*, const byte*, word32); 62 | WOLFSSL_API int wc_Blake2bFinal(Blake2b*, byte*, word32); 63 | 64 | 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* HAVE_BLAKE2 */ 71 | #endif /* WOLF_CRYPT_BLAKE2_H */ 72 | 73 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/chacha.h: -------------------------------------------------------------------------------- 1 | /* chacha.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_CHACHA_H 24 | #define WOLF_CRYPT_CHACHA_H 25 | 26 | #include 27 | 28 | #ifdef HAVE_CHACHA 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* Size of the IV */ 35 | #define CHACHA_IV_WORDS 3 36 | #define CHACHA_IV_BYTES (CHACHA_IV_WORDS * sizeof(word32)) 37 | 38 | /* Size of ChaCha chunks */ 39 | #define CHACHA_CHUNK_WORDS 16 40 | #define CHACHA_CHUNK_BYTES (CHACHA_CHUNK_WORDS * sizeof(word32)) 41 | 42 | enum { 43 | CHACHA_ENC_TYPE = 7 /* cipher unique type */ 44 | }; 45 | 46 | typedef struct ChaCha { 47 | word32 X[CHACHA_CHUNK_WORDS]; /* state of cipher */ 48 | } ChaCha; 49 | 50 | /** 51 | * IV(nonce) changes with each record 52 | * counter is for what value the block counter should start ... usually 0 53 | */ 54 | WOLFSSL_API int wc_Chacha_SetIV(ChaCha* ctx, const byte* inIv, word32 counter); 55 | 56 | WOLFSSL_API int wc_Chacha_Process(ChaCha* ctx, byte* cipher, const byte* plain, 57 | word32 msglen); 58 | WOLFSSL_API int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz); 59 | 60 | #ifdef __cplusplus 61 | } /* extern "C" */ 62 | #endif 63 | 64 | #endif /* HAVE_CHACHA */ 65 | #endif /* WOLF_CRYPT_CHACHA_H */ 66 | 67 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/cmac.h: -------------------------------------------------------------------------------- 1 | /* cmac.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_CMAC_H 24 | #define WOLF_CRYPT_CMAC_H 25 | 26 | #include 27 | #include 28 | 29 | #if !defined(NO_AES) && defined(WOLFSSL_CMAC) 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | typedef struct Cmac { 36 | Aes aes; 37 | byte buffer[AES_BLOCK_SIZE]; /* partially stored block */ 38 | byte digest[AES_BLOCK_SIZE]; /* running digest */ 39 | byte k1[AES_BLOCK_SIZE]; 40 | byte k2[AES_BLOCK_SIZE]; 41 | word32 bufferSz; 42 | word32 totalSz; 43 | } Cmac; 44 | 45 | 46 | typedef enum CmacType { 47 | WC_CMAC_AES = 1 48 | } CmacType; 49 | 50 | 51 | WOLFSSL_API 52 | int wc_InitCmac(Cmac* cmac, 53 | const byte* key, word32 keySz, 54 | int type, void* unused); 55 | WOLFSSL_API 56 | int wc_CmacUpdate(Cmac* cmac, 57 | const byte* in, word32 inSz); 58 | WOLFSSL_API 59 | int wc_CmacFinal(Cmac* cmac, 60 | byte* out, word32* outSz); 61 | 62 | WOLFSSL_API 63 | int wc_AesCmacGenerate(byte* out, word32* outSz, 64 | const byte* in, word32 inSz, 65 | const byte* key, word32 keySz); 66 | 67 | WOLFSSL_API 68 | int wc_AesCmacVerify(const byte* check, word32 checkSz, 69 | const byte* in, word32 inSz, 70 | const byte* key, word32 keySz); 71 | 72 | #ifdef __cplusplus 73 | } /* extern "C" */ 74 | #endif 75 | 76 | 77 | #endif /* NO_AES && WOLFSSL_CMAC */ 78 | #endif /* WOLF_CRYPT_CMAC_H */ 79 | 80 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/compress.h: -------------------------------------------------------------------------------- 1 | /* compress.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_COMPRESS_H 24 | #define WOLF_CRYPT_COMPRESS_H 25 | 26 | #include 27 | 28 | #ifdef HAVE_LIBZ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | 35 | #define COMPRESS_FIXED 1 36 | 37 | 38 | WOLFSSL_API int wc_Compress(byte*, word32, const byte*, word32, word32); 39 | WOLFSSL_API int wc_DeCompress(byte*, word32, const byte*, word32); 40 | 41 | 42 | #ifdef __cplusplus 43 | } /* extern "C" */ 44 | #endif 45 | 46 | 47 | #endif /* HAVE_LIBZ */ 48 | #endif /* WOLF_CRYPT_COMPRESS_H */ 49 | 50 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/cpuid.h: -------------------------------------------------------------------------------- 1 | /* cpuid.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | #ifndef WOLF_CRYPT_CPUID_H 25 | #define WOLF_CRYPT_CPUID_H 26 | 27 | 28 | #include 29 | 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #if defined(WOLFSSL_X86_64_BUILD) || defined(USE_INTEL_SPEEDUP) || \ 36 | defined(WOLFSSL_AESNI) 37 | #define CPUID_AVX1 0x0001 38 | #define CPUID_AVX2 0x0002 39 | #define CPUID_RDRAND 0x0004 40 | #define CPUID_RDSEED 0x0008 41 | #define CPUID_BMI2 0x0010 /* MULX, RORX */ 42 | #define CPUID_AESNI 0x0020 43 | #define CPUID_ADX 0x0040 /* ADCX, ADOX */ 44 | 45 | #define IS_INTEL_AVX1(f) ((f) & CPUID_AVX1) 46 | #define IS_INTEL_AVX2(f) ((f) & CPUID_AVX2) 47 | #define IS_INTEL_RDRAND(f) ((f) & CPUID_RDRAND) 48 | #define IS_INTEL_RDSEED(f) ((f) & CPUID_RDSEED) 49 | #define IS_INTEL_BMI2(f) ((f) & CPUID_BMI2) 50 | #define IS_INTEL_AESNI(f) ((f) & CPUID_AESNI) 51 | #define IS_INTEL_ADX(f) ((f) & CPUID_ADX) 52 | 53 | void cpuid_set_flags(void); 54 | word32 cpuid_get_flags(void); 55 | #endif 56 | 57 | #ifdef __cplusplus 58 | } /* extern "C" */ 59 | #endif 60 | 61 | 62 | #endif /* WOLF_CRYPT_CPUID_H */ 63 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/fips_test.h: -------------------------------------------------------------------------------- 1 | /* fips_test.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | #ifndef WOLF_CRYPT_FIPS_TEST_H 25 | #define WOLF_CRYPT_FIPS_TEST_H 26 | 27 | #include 28 | 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* Known Answer Test string inputs are hex, internal */ 35 | CYASSL_LOCAL int DoKnownAnswerTests(char*, int); 36 | 37 | 38 | /* FIPS failure callback */ 39 | typedef void(*wolfCrypt_fips_cb)(int ok, int err, const char* hash); 40 | 41 | /* Public set function */ 42 | CYASSL_API int wolfCrypt_SetCb_fips(wolfCrypt_fips_cb cbf); 43 | 44 | /* Public get status functions */ 45 | CYASSL_API int wolfCrypt_GetStatus_fips(void); 46 | CYASSL_API const char* wolfCrypt_GetCoreHash_fips(void); 47 | 48 | #ifdef HAVE_FORCE_FIPS_FAILURE 49 | /* Public function to force failure mode for operational testing */ 50 | CYASSL_API int wolfCrypt_SetStatus_fips(int); 51 | #endif 52 | 53 | 54 | #ifdef __cplusplus 55 | } /* extern "C" */ 56 | #endif 57 | 58 | #endif /* WOLF_CRYPT_FIPS_TEST_H */ 59 | 60 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/hc128.h: -------------------------------------------------------------------------------- 1 | /* hc128.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_HC128_H 24 | #define WOLF_CRYPT_HC128_H 25 | 26 | #include 27 | 28 | #ifndef NO_HC128 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | enum { 35 | HC128_ENC_TYPE = 6 /* cipher unique type */ 36 | }; 37 | 38 | /* HC-128 stream cipher */ 39 | typedef struct HC128 { 40 | word32 T[1024]; /* P[i] = T[i]; Q[i] = T[1024 + i ]; */ 41 | word32 X[16]; 42 | word32 Y[16]; 43 | word32 counter1024; /* counter1024 = i mod 1024 at the ith step */ 44 | word32 key[8]; 45 | word32 iv[8]; 46 | #ifdef XSTREAM_ALIGN 47 | void* heap; /* heap hint, currently XMALLOC only used with aligning */ 48 | #endif 49 | } HC128; 50 | 51 | 52 | WOLFSSL_API int wc_Hc128_Process(HC128*, byte*, const byte*, word32); 53 | WOLFSSL_API int wc_Hc128_SetKey(HC128*, const byte* key, const byte* iv); 54 | 55 | WOLFSSL_LOCAL int wc_Hc128_SetHeap(HC128* ctx, void* heap); 56 | 57 | #ifdef __cplusplus 58 | } /* extern "C" */ 59 | #endif 60 | 61 | #endif /* HAVE_HC128 */ 62 | #endif /* WOLF_CRYPT_HC128_H */ 63 | 64 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/idea.h: -------------------------------------------------------------------------------- 1 | /* idea.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_IDEA_H 24 | #define WOLF_CRYPT_IDEA_H 25 | 26 | #include 27 | 28 | #ifdef HAVE_IDEA 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | enum { 35 | IDEA_MODULO = 0x10001, /* 2^16+1 */ 36 | IDEA_2EXP16 = 0x10000, /* 2^16 */ 37 | IDEA_MASK = 0xFFFF, /* 16 bits set to one */ 38 | IDEA_ROUNDS = 8, /* number of rounds for IDEA */ 39 | IDEA_SK_NUM = (6*IDEA_ROUNDS + 4), /* number of subkeys */ 40 | IDEA_KEY_SIZE = 16, /* size of key in bytes */ 41 | IDEA_BLOCK_SIZE = 8, /* size of IDEA blocks in bytes */ 42 | IDEA_IV_SIZE = 8, /* size of IDEA IV in bytes */ 43 | IDEA_ENCRYPTION = 0, 44 | IDEA_DECRYPTION = 1 45 | }; 46 | 47 | /* IDEA encryption and decryption */ 48 | typedef struct Idea { 49 | word32 reg[IDEA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ 50 | word32 tmp[IDEA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ 51 | word16 skey[IDEA_SK_NUM]; /* 832 bits expanded key */ 52 | } Idea; 53 | 54 | WOLFSSL_API int wc_IdeaSetKey(Idea *idea, const byte* key, word16 keySz, 55 | const byte *iv, int dir); 56 | WOLFSSL_API int wc_IdeaSetIV(Idea *idea, const byte* iv); 57 | WOLFSSL_API int wc_IdeaCipher(Idea *idea, byte* out, const byte* in); 58 | WOLFSSL_API int wc_IdeaCbcEncrypt(Idea *idea, byte* out, 59 | const byte* in, word32 len); 60 | WOLFSSL_API int wc_IdeaCbcDecrypt(Idea *idea, byte* out, 61 | const byte* in, word32 len); 62 | #ifdef __cplusplus 63 | } /* extern "C" */ 64 | #endif 65 | 66 | #endif /* HAVE_IDEA */ 67 | #endif /* WOLF_CRYPT_IDEA_H */ 68 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/md2.h: -------------------------------------------------------------------------------- 1 | /* md2.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_MD2_H 24 | #define WOLF_CRYPT_MD2_H 25 | 26 | #include 27 | 28 | #ifdef WOLFSSL_MD2 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* in bytes */ 35 | enum { 36 | MD2 = 6, /* hash type unique */ 37 | MD2_BLOCK_SIZE = 16, 38 | MD2_DIGEST_SIZE = 16, 39 | MD2_PAD_SIZE = 16, 40 | MD2_X_SIZE = 48 41 | }; 42 | 43 | 44 | /* Md2 digest */ 45 | typedef struct Md2 { 46 | word32 count; /* bytes % PAD_SIZE */ 47 | byte X[MD2_X_SIZE]; 48 | byte C[MD2_BLOCK_SIZE]; 49 | byte buffer[MD2_BLOCK_SIZE]; 50 | } Md2; 51 | 52 | 53 | WOLFSSL_API void wc_InitMd2(Md2*); 54 | WOLFSSL_API void wc_Md2Update(Md2*, const byte*, word32); 55 | WOLFSSL_API void wc_Md2Final(Md2*, byte*); 56 | WOLFSSL_API int wc_Md2Hash(const byte*, word32, byte*); 57 | 58 | 59 | #ifdef __cplusplus 60 | } /* extern "C" */ 61 | #endif 62 | 63 | #endif /* WOLFSSL_MD2 */ 64 | #endif /* WOLF_CRYPT_MD2_H */ 65 | 66 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/md4.h: -------------------------------------------------------------------------------- 1 | /* md4.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_MD4_H 24 | #define WOLF_CRYPT_MD4_H 25 | 26 | #include 27 | 28 | #ifndef NO_MD4 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* in bytes */ 35 | enum { 36 | MD4_BLOCK_SIZE = 64, 37 | MD4_DIGEST_SIZE = 16, 38 | MD4_PAD_SIZE = 56 39 | }; 40 | 41 | 42 | /* MD4 digest */ 43 | typedef struct Md4 { 44 | word32 buffLen; /* in bytes */ 45 | word32 loLen; /* length in bytes */ 46 | word32 hiLen; /* length in bytes */ 47 | word32 digest[MD4_DIGEST_SIZE / sizeof(word32)]; 48 | word32 buffer[MD4_BLOCK_SIZE / sizeof(word32)]; 49 | } Md4; 50 | 51 | 52 | WOLFSSL_API void wc_InitMd4(Md4*); 53 | WOLFSSL_API void wc_Md4Update(Md4*, const byte*, word32); 54 | WOLFSSL_API void wc_Md4Final(Md4*, byte*); 55 | 56 | 57 | #ifdef __cplusplus 58 | } /* extern "C" */ 59 | #endif 60 | 61 | #endif /* NO_MD4 */ 62 | #endif /* WOLF_CRYPT_MD4_H */ 63 | 64 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/pkcs12.h: -------------------------------------------------------------------------------- 1 | /* pkcs12.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_PKCS12_H 24 | #define WOLF_CRYPT_PKCS12_H 25 | 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #ifndef WOLFSSL_TYPES_DEFINED /* do not redeclare from ssl.h */ 33 | typedef struct WC_PKCS12 WC_PKCS12; 34 | #endif 35 | 36 | typedef struct WC_DerCertList { /* dereferenced in ssl.c */ 37 | byte* buffer; 38 | word32 bufferSz; 39 | struct WC_DerCertList* next; 40 | } WC_DerCertList; 41 | 42 | 43 | 44 | WOLFSSL_API WC_PKCS12* wc_PKCS12_new(void); 45 | WOLFSSL_API void wc_PKCS12_free(WC_PKCS12* pkcs12); 46 | WOLFSSL_API int wc_d2i_PKCS12(const byte* der, word32 derSz, WC_PKCS12* pkcs12); 47 | WOLFSSL_API int wc_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw, 48 | byte** pkey, word32* pkeySz, byte** cert, word32* certSz, 49 | WC_DerCertList** ca); 50 | 51 | WOLFSSL_LOCAL int wc_PKCS12_SetHeap(WC_PKCS12* pkcs12, void* heap); 52 | WOLFSSL_LOCAL void* wc_PKCS12_GetHeap(WC_PKCS12* pkcs12); 53 | 54 | 55 | #ifdef __cplusplus 56 | } /* extern "C" */ 57 | #endif 58 | 59 | #endif /* WOLF_CRYPT_PKCS12_H */ 60 | 61 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/rabbit.h: -------------------------------------------------------------------------------- 1 | /* rabbit.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_RABBIT_H 24 | #define WOLF_CRYPT_RABBIT_H 25 | 26 | #include 27 | 28 | #ifndef NO_RABBIT 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | 35 | enum { 36 | RABBIT_ENC_TYPE = 5 /* cipher unique type */ 37 | }; 38 | 39 | 40 | /* Rabbit Context */ 41 | typedef struct RabbitCtx { 42 | word32 x[8]; 43 | word32 c[8]; 44 | word32 carry; 45 | } RabbitCtx; 46 | 47 | 48 | /* Rabbit stream cipher */ 49 | typedef struct Rabbit { 50 | RabbitCtx masterCtx; 51 | RabbitCtx workCtx; 52 | #ifdef XSTREAM_ALIGN 53 | void* heap; /* heap hint, currently XMALLOC only used with aligning */ 54 | #endif 55 | } Rabbit; 56 | 57 | 58 | WOLFSSL_API int wc_RabbitProcess(Rabbit*, byte*, const byte*, word32); 59 | WOLFSSL_API int wc_RabbitSetKey(Rabbit*, const byte* key, const byte* iv); 60 | 61 | WOLFSSL_LOCAL int wc_Rabbit_SetHeap(Rabbit* ctx, void* heap); 62 | 63 | #ifdef __cplusplus 64 | } /* extern "C" */ 65 | #endif 66 | 67 | #endif /* NO_RABBIT */ 68 | #endif /* WOLF_CRYPT_RABBIT_H */ 69 | 70 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/ripemd.h: -------------------------------------------------------------------------------- 1 | /* ripemd.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_RIPEMD_H 24 | #define WOLF_CRYPT_RIPEMD_H 25 | 26 | #include 27 | 28 | #ifdef WOLFSSL_RIPEMD 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | 35 | /* in bytes */ 36 | enum { 37 | RIPEMD = 3, /* hash type unique */ 38 | RIPEMD_BLOCK_SIZE = 64, 39 | RIPEMD_DIGEST_SIZE = 20, 40 | RIPEMD_PAD_SIZE = 56 41 | }; 42 | 43 | 44 | /* RipeMd 160 digest */ 45 | typedef struct RipeMd { 46 | word32 buffLen; /* in bytes */ 47 | word32 loLen; /* length in bytes */ 48 | word32 hiLen; /* length in bytes */ 49 | word32 digest[RIPEMD_DIGEST_SIZE / sizeof(word32)]; 50 | word32 buffer[RIPEMD_BLOCK_SIZE / sizeof(word32)]; 51 | } RipeMd; 52 | 53 | 54 | WOLFSSL_API int wc_InitRipeMd(RipeMd*); 55 | WOLFSSL_API int wc_RipeMdUpdate(RipeMd*, const byte*, word32); 56 | WOLFSSL_API int wc_RipeMdFinal(RipeMd*, byte*); 57 | 58 | 59 | #ifdef __cplusplus 60 | } /* extern "C" */ 61 | #endif 62 | 63 | #endif /* WOLFSSL_RIPEMD */ 64 | #endif /* WOLF_CRYPT_RIPEMD_H */ 65 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/signature.h: -------------------------------------------------------------------------------- 1 | /* signature.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_SIGNATURE_H 24 | #define WOLF_CRYPT_SIGNATURE_H 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | enum wc_SignatureType { 35 | WC_SIGNATURE_TYPE_NONE = 0, 36 | WC_SIGNATURE_TYPE_ECC = 1, 37 | WC_SIGNATURE_TYPE_RSA = 2, 38 | WC_SIGNATURE_TYPE_RSA_W_ENC = 3, /* Adds DER header via wc_EncodeSignature */ 39 | }; 40 | 41 | WOLFSSL_API int wc_SignatureGetSize(enum wc_SignatureType sig_type, 42 | const void* key, word32 key_len); 43 | 44 | WOLFSSL_API int wc_SignatureVerify( 45 | enum wc_HashType hash_type, enum wc_SignatureType sig_type, 46 | const byte* data, word32 data_len, 47 | const byte* sig, word32 sig_len, 48 | const void* key, word32 key_len); 49 | 50 | WOLFSSL_API int wc_SignatureGenerate( 51 | enum wc_HashType hash_type, enum wc_SignatureType sig_type, 52 | const byte* data, word32 data_len, 53 | byte* sig, word32 *sig_len, 54 | const void* key, word32 key_len, 55 | WC_RNG* rng); 56 | 57 | #ifdef __cplusplus 58 | } /* extern "C" */ 59 | #endif 60 | 61 | #endif /* WOLF_CRYPT_SIGNATURE_H */ 62 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/wc_encrypt.h: -------------------------------------------------------------------------------- 1 | /* wc_encrypt.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | #ifndef WOLF_CRYPT_ENCRYPT_H 25 | #define WOLF_CRYPT_ENCRYPT_H 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #ifndef NO_AES 34 | WOLFSSL_API int wc_AesCbcEncryptWithKey(byte* out, const byte* in, word32 inSz, 35 | const byte* key, word32 keySz, 36 | const byte* iv); 37 | WOLFSSL_API int wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz, 38 | const byte* key, word32 keySz, 39 | const byte* iv); 40 | #endif /* !NO_AES */ 41 | 42 | 43 | #ifndef NO_DES3 44 | WOLFSSL_API int wc_Des_CbcDecryptWithKey(byte* out, 45 | const byte* in, word32 sz, 46 | const byte* key, const byte* iv); 47 | WOLFSSL_API int wc_Des_CbcEncryptWithKey(byte* out, 48 | const byte* in, word32 sz, 49 | const byte* key, const byte* iv); 50 | WOLFSSL_API int wc_Des3_CbcEncryptWithKey(byte* out, 51 | const byte* in, word32 sz, 52 | const byte* key, const byte* iv); 53 | WOLFSSL_API int wc_Des3_CbcDecryptWithKey(byte* out, 54 | const byte* in, word32 sz, 55 | const byte* key, const byte* iv); 56 | #endif /* !NO_DES3 */ 57 | 58 | #ifdef __cplusplus 59 | } /* extern "C" */ 60 | #endif 61 | 62 | #endif /* WOLF_CRYPT_ENCRYPT_H */ 63 | 64 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/wolfmath.h: -------------------------------------------------------------------------------- 1 | /* wolfmath.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | #if defined(HAVE_WOLF_BIGINT) && !defined(WOLF_BIGINT_DEFINED) 23 | /* raw big integer */ 24 | typedef struct WC_BIGINT { 25 | byte* buf; 26 | word32 len; 27 | void* heap; 28 | } WC_BIGINT; 29 | 30 | #define WOLF_BIGINT_DEFINED 31 | #endif 32 | 33 | 34 | /* only define functions if mp_int has been declared */ 35 | #ifdef MP_INT_DEFINED 36 | 37 | #ifndef __WOLFMATH_H__ 38 | #define __WOLFMATH_H__ 39 | 40 | /* timing resistance array */ 41 | #if !defined(WC_NO_CACHE_RESISTANT) && \ 42 | ((defined(HAVE_ECC) && defined(ECC_TIMING_RESISTANT)) || \ 43 | (defined(USE_FAST_MATH) && defined(TFM_TIMING_RESISTANT))) 44 | 45 | extern const wolfssl_word wc_off_on_addr[2]; 46 | #endif 47 | 48 | /* common math functions */ 49 | int get_digit_count(mp_int* a); 50 | mp_digit get_digit(mp_int* a, int n); 51 | int get_rand_digit(WC_RNG* rng, mp_digit* d); 52 | int mp_rand(mp_int* a, int digits, WC_RNG* rng); 53 | 54 | 55 | #ifdef HAVE_WOLF_BIGINT 56 | void wc_bigint_init(WC_BIGINT* a); 57 | int wc_bigint_alloc(WC_BIGINT* a, word32 sz); 58 | int wc_bigint_from_unsigned_bin(WC_BIGINT* a, const byte* in, word32 inlen); 59 | int wc_bigint_to_unsigned_bin(WC_BIGINT* a, byte* out, word32* outlen); 60 | void wc_bigint_zero(WC_BIGINT* a); 61 | void wc_bigint_free(WC_BIGINT* a); 62 | 63 | int wc_mp_to_bigint(mp_int* src, WC_BIGINT* dst); 64 | int wc_bigint_to_mp(WC_BIGINT* src, mp_int* dst); 65 | #endif /* HAVE_WOLF_BIGINT */ 66 | 67 | #endif /* __WOLFMATH_H__ */ 68 | 69 | #endif /* MP_INT_DEFINED */ 70 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:esp12e] 12 | platform = espressif8266 13 | board = esp12e 14 | framework = arduino 15 | monitor_speed = 115200 16 | 17 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/src/my_accessory.c: -------------------------------------------------------------------------------- 1 | /* 2 | my_accessory.c 3 | Define the accessory in C language using the Macro in characteristics.h 4 | 5 | Created on: 07-04-2021 6 | Author: KUNAL VERMA 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | void my_accessory_identify(homekit_value_t _value) { 13 | printf("accessory identify\n"); 14 | } 15 | 16 | // Fan (HAP section 8.13) 17 | // required: Active 18 | // optional: ROTATION_SPEED 19 | // ROTATION_DIRECTION 20 | // NAME 21 | 22 | //一个电风扇总开关 23 | homekit_characteristic_t fan_on = HOMEKIT_CHARACTERISTIC_(ON, false); 24 | //一个控制LED 25 | homekit_characteristic_t cha_switch_on0 = HOMEKIT_CHARACTERISTIC_(ON, false); 26 | 27 | //三档调节风扇速度 28 | homekit_characteristic_t rotation_speed = HOMEKIT_CHARACTERISTIC_(ROTATION_SPEED, per_send); 29 | // format: string; HAP section 9.62; max length 64 30 | homekit_characteristic_t cha_name0 = HOMEKIT_CHARACTERISTIC_(NAME, "LED"); 31 | 32 | homekit_accessory_t *accessories[] = { 33 | HOMEKIT_ACCESSORY(.id = 1, .category = homekit_accessory_category_fan, .services = (homekit_service_t*[]) { //.id后边的数字代表带几个设备,>1就是作为桥连接 34 | HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics = (homekit_characteristic_t*[]) { 35 | HOMEKIT_CHARACTERISTIC(NAME, "ESP12F"), 36 | HOMEKIT_CHARACTERISTIC(MANUFACTURER, "lycraft_Person"), 37 | HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "123456"), 38 | HOMEKIT_CHARACTERISTIC(MODEL, "ESP8266"), 39 | HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "1.0"), 40 | HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify), 41 | NULL 42 | }), 43 | HOMEKIT_SERVICE(FAN, .primary = true, .characteristics = (homekit_characteristic_t*[]) { //建一个FAN类型服务 44 | &fan_on, 45 | &rotation_speed, 46 | NULL 47 | }), 48 | HOMEKIT_SERVICE(SWITCH, .characteristics=(homekit_characteristic_t*[]){ //新建一个服务 switch类型 49 | &cha_switch_on0, 50 | &cha_name0, 51 | NULL 52 | }), 53 | NULL 54 | }), 55 | NULL 56 | }; 57 | 58 | homekit_server_config_t config = { 59 | .accessories = accessories, 60 | .password = "111-22-333" 61 | }; 62 | 63 | -------------------------------------------------------------------------------- /1_Firmware/2_platformio_esp8266/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PlatformIO Test Runner and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PlatformIO Unit Testing: 11 | - https://docs.platformio.org/en/latest/advanced/unit-testing/index.html 12 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # Others 35 | .DS_STORE 36 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Mixiaoxiao(谜小小) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/README.md: -------------------------------------------------------------------------------- 1 | # Arduino-HomeKit-ESP32 2 | **[Deprecated]** Native Apple HomeKit accessory implementation for the ESP32 Arduino core. 3 | 4 | This Arduino library is a native Apple HomeKit accessory implementation for the [ESP32 Arduino core](https://github.com/espressif/arduino-esp32), and works without any additional bridges. 5 | 6 | This library is the ESP32 version of [Arduino-HomeKit-ESP8266](https://github.com/Mixiaoxiao/Arduino-HomeKit-ESP8266), and **will no longer be maintained**, since Espressif has published the official HomeKit library for ESP32, available on Espressif's GitHub repository [esp-apple-homekit-adk](https://github.com/espressif/esp-apple-homekit-adk). 7 | 8 | ## Notes 9 | 10 | * This is a "only-can-work" version for ESP32, remains something to be optimized. 11 | 12 | * The `WolfSSL` used for ESP32 is based on `4.3.0-stable` version with **Hardware Acceleration Support** (enabled by default). 13 | 14 | * The HomeKit running on ESP32 has a **GREAT PERFORMANCE** which Pair-Setup can be done in ~1.2s and Pair-Verify in < 0.1s (10x faster than ESP8266). 15 | 16 | * The HomeKit storage on ESP32 is based on `nvs`. 17 | 18 | ## Performance WITH Hardware Acceleration on ESP32 19 | 20 | * Preinit: ~0.53s 21 | * Pair Setup Step 1/3: ~0s (The heavy crypto computation is done in Preinit) 22 | * Pair Setup Step 2/3: ~0.53s 23 | * Pair Setup Step 3/3: ~0.20s 24 | * Pair Verify Step 1/2: ~0.05s 25 | * Pair Verify Step 2/2: ~0.02s 26 | 27 | ## Performance WITHOUT Hardware Acceleration on ESP32 28 | 29 | * Preinit: ~2.2s 30 | * Pair Setup Step 1/3: ~0s (The heavy crypto computation is done in Preinit) 31 | * Pair Setup Step 2/3: ~2.5s 32 | * Pair Setup Step 3/3: ~0.1s 33 | * Pair Verify Step 1/2: ~0.06s 34 | * Pair Verify Step 2/2: ~0.03s 35 | 36 | ## Setup code of the example sketch 37 | 38 | ``111-11-111`` 39 | 40 | ## Manual Installation 41 | 42 | Refer to the official guide: [Manual installation](https://www.arduino.cc/en/guide/libraries#toc5) 43 | Note: this library will not publish the release version for Arduino IDE. 44 | 45 | 46 | #### Manual Installation for Windows 47 | 48 | 1. Click on _"Clone or Download"_ button, then click _"[Download ZIP](https://github.com/Mixiaoxiao/Arduino-HomeKit-ESP32/archive/master.zip)"_ on the page. 49 | 1. Extract the contents of the downloaded zip file. 50 | 1. Rename the extracted folder to _"Arduino-HomeKit-ESP32"_. 51 | 1. Move this folder to your libraries directory. (under windows: `C:\Users\\Documents\Arduino\libraries\`) 52 | 1. Restart your Arduino IDE. 53 | 1. Check out the examples. 54 | 55 | 56 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/examples/ESP32_homekit_wolfssl_4_3_0/ESP32_homekit.ino: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "WiFi.h" 3 | #include "arduino_homekit_server.h" 4 | #include "ESPButton.h" 5 | 6 | extern "C" homekit_server_config_t config; 7 | extern "C" homekit_characteristic_t name; 8 | extern "C" char ACCESSORY_NAME[32]; 9 | extern "C" void led_toggle(); 10 | extern "C" void accessory_init(); 11 | 12 | #define PIN_BTN 0 13 | 14 | const char *ssid = "your-ssid"; 15 | const char *password = "your-password"; 16 | 17 | void setup() { 18 | Serial.begin(115200); 19 | 20 | WiFi.mode(WIFI_STA); 21 | WiFi.persistent(false); 22 | WiFi.disconnect(false); 23 | WiFi.setAutoReconnect(true); 24 | WiFi.begin(ssid, password); 25 | 26 | printf("\n"); 27 | printf("SketchSize: %d B\n", ESP.getSketchSize()); 28 | printf("FreeSketchSpace: %d B\n", ESP.getFreeSketchSpace()); 29 | printf("FlashChipSize: %d B\n", ESP.getFlashChipSize()); 30 | //printf("FlashChipRealSize: %d B\n", ESP.getFlashChipRealSize()); 31 | printf("FlashChipSpeed: %d\n", ESP.getFlashChipSpeed()); 32 | printf("SdkVersion: %s\n", ESP.getSdkVersion()); 33 | //printf("FullVersion: %s\n", ESP.getFullVersion().c_str()); 34 | //printf("CpuFreq: %dMHz\n", ESP.getCpuFreqMHz()); 35 | printf("FreeHeap: %d B\n", ESP.getFreeHeap()); 36 | //printf("ResetInfo: %s\n", ESP.getResetInfo().c_str()); 37 | //printf("ResetReason: %s\n", ESP.getResetReason().c_str()); 38 | DEBUG_HEAP(); 39 | 40 | //Init Button 41 | pinMode(PIN_BTN, INPUT_PULLUP); 42 | ESPButton.add(0, PIN_BTN, LOW, false, true); 43 | ESPButton.setCallback([](uint8_t id, ESPButtonEvent event) { 44 | printf("ButtonEvent: %s\n", ESPButton.getButtonEventDescription(event)); 45 | if (event == ESPBUTTONEVENT_SINGLECLICK) { 46 | led_toggle(); 47 | } else if (event == ESPBUTTONEVENT_DOUBLECLICK) { 48 | 49 | } else if (event == ESPBUTTONEVENT_LONGCLICK) { 50 | homekit_storage_reset(); 51 | esp_restart(); 52 | } 53 | }); 54 | ESPButton.begin(); 55 | homekit_setup(); 56 | } 57 | 58 | void loop() { 59 | ESPButton.loop(); 60 | uint32_t time = millis(); 61 | static uint32_t next_heap_millis = 0; 62 | if (time > next_heap_millis) { 63 | INFO("heap: %u, sockets: %d", ESP.getFreeHeap(), arduino_homekit_connected_clients_count()); 64 | next_heap_millis = time + 5000; 65 | } 66 | delay(5); 67 | } 68 | 69 | void homekit_setup() { 70 | accessory_init(); 71 | // We create one FreeRTOS-task for HomeKit 72 | // No need to call arduino_homekit_loop 73 | arduino_homekit_setup(&config); 74 | } 75 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"HomeKit-ESP32", 3 | "description":"Apple HomeKit accessory server library for the ESP32 Arduino core.", 4 | "keywords":"homekit,esp32,apple homekit", 5 | "authors": 6 | { 7 | "name": "Mixiaoxiao (Wang Bin)", 8 | "maintainer": true 9 | }, 10 | "repository": 11 | { 12 | "type": "git", 13 | "url": "https://github.com/Mixiaoxiao/Arduino-HomeKit-ESP32.git" 14 | }, 15 | "version": "1.0.0", 16 | "license": "MIT", 17 | "frameworks": "arduino", 18 | "platforms": "espressif32", 19 | "build": { 20 | "libCompatMode": 2 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/library.properties: -------------------------------------------------------------------------------- 1 | name=HomeKit-ESP32 2 | version=1.0.0 3 | author=Mixiaoxiao 4 | maintainer=Mixiaoxiao 5 | sentence=Native Apple HomeKit accessory implementation for the ESP32 Arduino core. 6 | paragraph=Native Apple HomeKit Accessory Implementation for the ESP32 Arduino core. 7 | category=Communication 8 | url=https://github.com/Mixiaoxiao/Arduino-HomeKit-ESP32.git 9 | architectures=esp32 10 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/base64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | 10 | size_t base64_encoded_size(const unsigned char* data, size_t size); 11 | size_t base64_decoded_size(const unsigned char* encoded_data, size_t encoded_size); 12 | //multiple definition of `base64_decode'; 13 | int base64_encode_(const unsigned char* data, size_t data_size, unsigned char *encoded_data); 14 | int base64_decode_(const unsigned char* encoded_data, size_t encoded_size, unsigned char *data); 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/constants.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define DEVICE_ID_SIZE 36 4 | #define ACCESSORY_ID_SIZE 17 5 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/esp_xpgm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * xpgm.h 3 | * 4 | * Created on: 2020-03-08 5 | * Author: Wang Bin 6 | */ 7 | 8 | #ifndef ESP_XPGM_H_ 9 | #define ESP_XPGM_H_ 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | //see "osapi.h" 20 | /* 21 | This function works only after Serial.setDebugOutput(true); ? 22 | otherwise Serial prints nothing. 23 | #define esp_printf(fmt, ...) do { \ 24 | static const char flash_str[] ICACHE_RODATA_ATTR STORE_ATTR = fmt; \ 25 | os_printf_plus(flash_str, ##__VA_ARGS__); \ 26 | } while(0)*/ 27 | 28 | #define XPGM_PRINTF(fmt, ...) printf_P(PSTR(fmt) , ##__VA_ARGS__); 29 | 30 | #define XPGM_VAR(v0, v1) v0##v1 31 | 32 | // pgm_ptr --> ram_ptr 33 | #define XPGM_CPY(ram_ptr, pgm_ptr, size) memcpy_P(ram_ptr, pgm_ptr, size) 34 | 35 | #define XPGM_BUFFCPY(buff_type, buff_name, pgm_ptr, size) size_t XPGM_VAR(buff_name, _size) = size; \ 36 | buff_type buff_name[XPGM_VAR(buff_name, _size)]; \ 37 | XPGM_CPY(buff_name, pgm_ptr, XPGM_VAR(buff_name, _size)); 38 | 39 | #define XPGM_BUFFCPY_ARRAY(buff_type, buff_name, pgm_array) XPGM_BUFFCPY(buff_type, buff_name, pgm_array, sizeof(pgm_array)) 40 | 41 | #define XPGM_BUFFCPY_STRING(buff_type, buff_name, pgm_string) XPGM_BUFFCPY(buff_type, buff_name, pgm_string, strlen_P(pgm_string) + 1) 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* ESP_XPGM_H_ */ 48 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/homekit/tlv.h: -------------------------------------------------------------------------------- 1 | #ifndef __TLV_H__ 2 | #define __TLV_H__ 3 | 4 | #define __need_size_t 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | typedef unsigned char byte; 15 | 16 | typedef struct _tlv { 17 | struct _tlv *next; 18 | byte type; 19 | byte *value; 20 | size_t size; 21 | } tlv_t; 22 | 23 | 24 | typedef struct { 25 | tlv_t *head; 26 | } tlv_values_t; 27 | 28 | 29 | tlv_values_t *tlv_new(); 30 | 31 | void tlv_free(tlv_values_t *values); 32 | 33 | int tlv_add_value(tlv_values_t *values, byte type, const byte *value, size_t size); 34 | int tlv_add_string_value(tlv_values_t *values, byte type, const char *value); 35 | int tlv_add_integer_value(tlv_values_t *values, byte type, size_t size, int value); 36 | int tlv_add_tlv_value(tlv_values_t *values, byte type, tlv_values_t *value); 37 | 38 | tlv_t *tlv_get_value(const tlv_values_t *values, byte type); 39 | int tlv_get_integer_value(const tlv_values_t *values, byte type, int def); 40 | tlv_values_t *tlv_get_tlv_value(const tlv_values_t *values, byte type); 41 | 42 | int tlv_format(const tlv_values_t *values, byte *buffer, size_t *size); 43 | 44 | int tlv_parse(const byte *buffer, size_t length, tlv_values_t *values); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif // __TLV_H__ 51 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/homekit_debug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "homekit_debug.h" 5 | 6 | 7 | char *binary_to_string(const byte *data, size_t size) { 8 | int i; 9 | 10 | size_t buffer_size = 1; // 1 char for eos 11 | for (i=0; i= 32 && data[i] < 128) ? 1 : 4); 13 | 14 | char *buffer = malloc(buffer_size); 15 | 16 | int pos = 0; 17 | for (i=0; i= 128) { 22 | size_t printed = snprintf(&buffer[pos], buffer_size - pos, "\\x%02X", data[i]); 23 | if (printed > 0) { 24 | pos += printed; 25 | } 26 | } else { 27 | buffer[pos++] = data[i]; 28 | } 29 | } 30 | buffer[pos] = 0; 31 | 32 | return buffer; 33 | } 34 | 35 | 36 | void print_binary(const char *prompt, const byte *data, size_t size) { 37 | #ifdef HOMEKIT_DEBUG 38 | char *buffer = binary_to_string(data, size); 39 | printf("%s (%d bytes): \"%s\"\n", prompt, (int)size, buffer); 40 | free(buffer); 41 | #endif 42 | } 43 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/homekit_debug.h: -------------------------------------------------------------------------------- 1 | #ifndef __HOMEKIT_DEBUG_H__ 2 | #define __HOMEKIT_DEBUG_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include "Arduino.h" 11 | #include 12 | #include 13 | 14 | typedef unsigned char byte; 15 | 16 | //#define HOMEKIT_DEBUG 17 | 18 | #define HOMEKIT_PRINTF XPGM_PRINTF 19 | #if defined(ARDUINO_ARCH_ESP8266) 20 | #define MILLIS_FMT "%7u" 21 | #elif defined(ARDUINO_ARCH_ESP32) 22 | #define MILLIS_FMT "%7lu" 23 | #endif 24 | 25 | #ifdef HOMEKIT_DEBUG 26 | 27 | #define DEBUG(message, ...) HOMEKIT_PRINTF(">>> %s: " message "\n", __func__, ##__VA_ARGS__) 28 | static uint32_t start_time = 0; 29 | #define DEBUG_TIME_BEGIN() start_time=millis(); 30 | #define DEBUG_TIME_END(func_name) HOMEKIT_PRINTF("### [" MILLIS_FMT "] %s took %6dms\n", millis(), func_name, (millis() - start_time)); 31 | 32 | #else 33 | 34 | #define DEBUG(message, ...) 35 | 36 | #endif 37 | 38 | #define INFO(message, ...) HOMEKIT_PRINTF(">>> [" MILLIS_FMT "] HomeKit: " message "\n", millis(), ##__VA_ARGS__) 39 | #define ERROR(message, ...) HOMEKIT_PRINTF("!!! [" MILLIS_FMT "] HomeKit: " message "\n", millis(), ##__VA_ARGS__) 40 | #define INFO_HEAP() INFO("Free heap: %u", system_get_free_heap_size()); 41 | #define DEBUG_HEAP() DEBUG("Free heap: %u", system_get_free_heap_size()); 42 | static unsigned long start_time = 0; 43 | #define DEBUG_TIME_BEGIN() start_time=millis(); 44 | #define DEBUG_TIME_END(func_name) HOMEKIT_PRINTF("### [" MILLIS_FMT "] %s took " MILLIS_FMT "ms\n", millis(), func_name, (millis() - start_time)); 45 | 46 | 47 | char *binary_to_string(const byte *data, size_t size); 48 | void print_binary(const char *prompt, const byte *data, size_t size); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif // __HOMEKIT_DEBUG_H__ 55 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/json.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | struct json_stream; 10 | typedef struct json_stream json_stream; 11 | 12 | typedef void (*json_flush_callback)(uint8_t *buffer, size_t size, void *context); 13 | 14 | json_stream *json_new(size_t buffer_size, json_flush_callback on_flush, void *context); 15 | void json_free(json_stream *json); 16 | 17 | void json_flush(json_stream *json); 18 | 19 | void json_object_start(json_stream *json); 20 | void json_object_end(json_stream *json); 21 | 22 | void json_array_start(json_stream *json); 23 | void json_array_end(json_stream *json); 24 | 25 | void json_integer(json_stream *json, int x); 26 | void json_uint8(json_stream *json, uint8_t x); 27 | void json_uint16(json_stream *json, uint16_t x); 28 | void json_uint32(json_stream *json, uint32_t x); 29 | void json_uint64(json_stream *json, uint64_t x); 30 | void json_float(json_stream *json, float x); 31 | void json_string(json_stream *json, const char *x); 32 | void json_boolean(json_stream *json, bool x); 33 | void json_null(json_stream *json); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/pairing.h: -------------------------------------------------------------------------------- 1 | #ifndef __PAIRING_H__ 2 | #define __PAIRING_H__ 3 | 4 | #include "constants.h" 5 | #include "crypto.h" 6 | 7 | 8 | typedef enum { 9 | pairing_permissions_admin = (1 << 0), 10 | } pairing_permissions_t; 11 | 12 | typedef struct { 13 | int id; 14 | char device_id[DEVICE_ID_SIZE + 1]; 15 | ed25519_key device_key; 16 | pairing_permissions_t permissions; 17 | } pairing_t; 18 | 19 | #endif // __PAIRING_H__ 20 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/port.h: -------------------------------------------------------------------------------- 1 | #ifndef __HOMEKIT_PORT_H_ 2 | #define __HOMEKIT_PORT_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include "homekit_debug.h" 10 | 11 | uint32_t homekit_random(); 12 | void homekit_random_fill(uint8_t *data, size_t size); 13 | 14 | void homekit_system_restart(); 15 | void homekit_overclock_start(); 16 | void homekit_overclock_end(); 17 | 18 | #ifdef ESP_OPEN_RTOS 19 | #include 20 | #define ESP_OK 0 21 | #endif 22 | 23 | //#ifdef ESP_IDF 24 | //#include 25 | //#include 26 | 27 | #if defined(ARDUINO_ARCH_ESP8266) 28 | #include "Arduino.h" 29 | #include 30 | #include 31 | #include 32 | #include 33 | #define ESP_OK SPI_FLASH_RESULT_OK //0 34 | 35 | #define SPI_FLASH_SECTOR_SIZE SPI_FLASH_SEC_SIZE 36 | #define spiflash_read(addr, buffer, size) (spi_flash_read((addr), (buffer), (size)) == ESP_OK) 37 | #define spiflash_write(addr, data, size) (spi_flash_write((addr), (data), (size)) == ESP_OK) 38 | #define spiflash_erase_sector(addr) (spi_flash_erase_sector((addr) / SPI_FLASH_SECTOR_SIZE) == ESP_OK) 39 | 40 | #endif 41 | 42 | //#ifdef ESP_IDF 43 | #ifdef ARDUINO_ARCH_ESP32 44 | #define SERVER_TASK_STACK 10240//12288// USE_FAST_MATH requires a lot of memory!!! 45 | #else 46 | #define SERVER_TASK_STACK 2048 47 | #endif 48 | 49 | #if defined(ARDUINO_ARCH_ESP32) 50 | #include 51 | #include 52 | #define SPI_FLASH_SECTOR_SIZE SPI_FLASH_SEC_SIZE 53 | 54 | // Use nvs of ESP32, See EEPROM.cpp for example 55 | 56 | // 1536 is enough, but require 4096 in compact_data() (for compatibility) 57 | #define HOMEKIT_STORAGE_SIZE SPI_FLASH_SECTOR_SIZE 58 | #define HOMEKIT_STORAGE_NVS_NAME "homekit" 59 | 60 | bool spiflash_init(); 61 | bool spiflash_erase_sector(size_t sector); 62 | bool spiflash_write(size_t dest_addr, const void *src, size_t size); 63 | bool spiflash_read(size_t src_addr, void *dest, size_t size); 64 | 65 | #endif 66 | 67 | //void homekit_mdns_init(); 68 | //void homekit_mdns_configure_init(const char *instance_name, int port); 69 | //void homekit_mdns_add_txt(const char *key, const char *format, ...); 70 | //void homekit_mdns_configure_finalize(); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif /* __HOMEKIT_PORT_H_ */ 77 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/query_params.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "query_params.h" 4 | 5 | 6 | query_param_t *query_params_parse(const char *s) { 7 | query_param_t *params = NULL; 8 | 9 | int i = 0; 10 | while (1) { 11 | int pos = i; 12 | while (s[i] && s[i] != '=' && s[i] != '&' && s[i] != '#') i++; 13 | if (i == pos) { 14 | i++; 15 | continue; 16 | } 17 | 18 | query_param_t *param = malloc(sizeof(query_param_t)); 19 | param->name = strndup(s+pos, i-pos); 20 | param->value = NULL; 21 | param->next = params; 22 | params = param; 23 | 24 | if (s[i] == '=') { 25 | i++; 26 | pos = i; 27 | while (s[i] && s[i] != '&' && s[i] != '#') i++; 28 | if (i != pos) { 29 | param->value = strndup(s+pos, i-pos); 30 | } 31 | } 32 | 33 | if (!s[i] || s[i] == '#') 34 | break; 35 | } 36 | 37 | return params; 38 | } 39 | 40 | 41 | query_param_t *query_params_find(query_param_t *params, const char *name) { 42 | while (params) { 43 | if (!strcmp(params->name, name)) 44 | return params; 45 | params = params->next; 46 | } 47 | 48 | return NULL; 49 | } 50 | 51 | 52 | void query_params_free(query_param_t *params) { 53 | while (params) { 54 | query_param_t *next = params->next; 55 | if (params->name) 56 | free(params->name); 57 | if (params->value) 58 | free(params->value); 59 | free(params); 60 | 61 | params = next; 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/query_params.h: -------------------------------------------------------------------------------- 1 | #ifndef __HOMEKIT_QUERY_PARAMS__ 2 | #define __HOMEKIT_QUERY_PARAMS__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef struct _query_param { 9 | char *name; 10 | char *value; 11 | 12 | struct _query_param *next; 13 | } query_param_t; 14 | 15 | query_param_t *query_params_parse(const char *s); 16 | query_param_t *query_params_find(query_param_t *params, const char *name); 17 | void query_params_free(query_param_t *params); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif // __HOMEKIT_QUERY_PARAMS__ 24 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/storage.h: -------------------------------------------------------------------------------- 1 | #ifndef __STORAGE_H__ 2 | #define __STORAGE_H__ 3 | 4 | //#include "EEPROM.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #include "pairing.h" 11 | 12 | int homekit_storage_reset(); 13 | 14 | int homekit_storage_init(); 15 | 16 | void homekit_storage_save_accessory_id(const char *accessory_id); 17 | int homekit_storage_load_accessory_id(char *data); 18 | 19 | void homekit_storage_save_accessory_key(const ed25519_key *key); 20 | int homekit_storage_load_accessory_key(ed25519_key *key); 21 | 22 | bool homekit_storage_can_add_pairing(); 23 | int homekit_storage_add_pairing(const char *device_id, const ed25519_key *device_key, byte permissions); 24 | int homekit_storage_update_pairing(const char *device_id, byte permissions); 25 | int homekit_storage_remove_pairing(const char *device_id); 26 | int homekit_storage_find_pairing(const char *device_id, pairing_t *pairing); 27 | 28 | typedef struct { 29 | int idx; 30 | } pairing_iterator_t; 31 | 32 | 33 | void homekit_storage_pairing_iterator_init(pairing_iterator_t *it); 34 | int homekit_storage_next_pairing(pairing_iterator_t *it, pairing_t *pairing); 35 | void homekit_storage_pairing_iterator_done(pairing_iterator_t *iterator); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | #endif // __STORAGE_H__ 41 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/watchdog.c: -------------------------------------------------------------------------------- 1 | // Base on esp_hw_wdt in github 2 | /* 3 | * Copyright (c) 2014-2017 Cesanta Software Limited 4 | * All rights reserved 5 | * Changed: 6 | * 2017 Alexander Epstine (a@epstine.com) 7 | */ 8 | 9 | #include "watchdog.h" 10 | #include "Arduino.h" 11 | #include "stdint.h" 12 | #include "homekit_debug.h" 13 | 14 | #define REG_WDT_BASE 0x60000900 15 | 16 | #define WDT_CTL (REG_WDT_BASE + 0x0) 17 | #define WDT_CTL_ENABLE (BIT(0)) 18 | #define WDT_RESET (REG_WDT_BASE + 0x14) 19 | #define WDT_RESET_VALUE 0x73 20 | 21 | void esp_hw_wdt_enable() { 22 | SET_PERI_REG_MASK(WDT_CTL, WDT_CTL_ENABLE); 23 | } 24 | 25 | void esp_hw_wdt_disable() { 26 | CLEAR_PERI_REG_MASK(WDT_CTL, WDT_CTL_ENABLE); 27 | } 28 | 29 | void esp_hw_wdt_feed() { 30 | WRITE_PERI_REG(WDT_RESET, WDT_RESET_VALUE); 31 | } 32 | 33 | #if defined(ESP8266) 34 | #include "user_interface.h" 35 | void watchdog_disable_all() { 36 | system_soft_wdt_stop(); 37 | esp_hw_wdt_disable(); 38 | } 39 | 40 | void watchdog_enable_all() { 41 | esp_hw_wdt_enable(); 42 | system_soft_wdt_restart(); 43 | } 44 | 45 | #else 46 | 47 | #endif 48 | 49 | #ifdef HOMEKIT_DEBUG 50 | 51 | static uint32_t wdt_checkpoint; 52 | 53 | void watchdog_check_begin() { 54 | wdt_checkpoint = millis(); 55 | } 56 | 57 | void watchdog_check_end(const char *message) { 58 | uint32_t d = millis() - wdt_checkpoint; 59 | printf("[WatchDog] Function %s took: %dms\n", message, d); 60 | } 61 | 62 | #else 63 | void watchdog_disable_all() { 64 | } 65 | 66 | void watchdog_enable_all() { 67 | } 68 | 69 | void watchdog_check_begin() { 70 | } 71 | 72 | void watchdog_check_end(const char *message) { 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/watchdog.h: -------------------------------------------------------------------------------- 1 | #ifndef WATCHDOG_H_ 2 | #define WATCHDOG_H_ 3 | 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | void watchdog_disable_all(); 10 | 11 | void watchdog_enable_all(); 12 | 13 | void watchdog_check_begin(); 14 | 15 | void watchdog_check_end(const char* message); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | 22 | #endif /* WATCHDOG_H_ */ 23 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfcrypt/src/ecc_fp.c: -------------------------------------------------------------------------------- 1 | /* dummy ecc_fp.c for dist */ 2 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfcrypt/src/port/Espressif/esp32_util.c: -------------------------------------------------------------------------------- 1 | /* esp32_util.c 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | #include 22 | 23 | #if defined(WOLFSSL_ESP32WROOM32_CRYPT) && \ 24 | (!defined(NO_AES) || !defined(NO_SHA) || !defined(NO_SHA256) ||\ 25 | defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)) 26 | 27 | #include 28 | #include 29 | 30 | int esp_CryptHwMutexInit(wolfSSL_Mutex* mutex) { 31 | return wc_InitMutex(mutex); 32 | } 33 | 34 | int esp_CryptHwMutexLock(wolfSSL_Mutex* mutex, TickType_t xBlockTime) { 35 | #ifdef SINGLE_THREADED 36 | return wc_LockMutex(mutex); 37 | #else 38 | return ((xSemaphoreTake( *mutex, xBlockTime ) == pdTRUE) ? 0 : BAD_MUTEX_E); 39 | #endif 40 | } 41 | 42 | int esp_CryptHwMutexUnLock(wolfSSL_Mutex* mutex) { 43 | return wc_UnLockMutex(mutex); 44 | } 45 | 46 | #endif 47 | 48 | #ifdef WOLFSSL_ESP32WROOM32_CRYPT_DEBUG 49 | 50 | #include "esp_timer.h" 51 | #include "esp_log.h" 52 | 53 | static uint64_t startTime = 0; 54 | 55 | 56 | void wc_esp32TimerStart() 57 | { 58 | startTime = esp_timer_get_time(); 59 | } 60 | 61 | uint64_t wc_esp32elapsedTime() 62 | { 63 | /* return elapsed time since wc_esp32AesTimeStart() is called in us */ 64 | return esp_timer_get_time() - startTime; 65 | } 66 | 67 | #endif /*WOLFSSL_ESP32WROOM32_CRYPT_DEBUG */ 68 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/version.h: -------------------------------------------------------------------------------- 1 | /* wolfssl_version.h.in 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLFSSL_VERSION_H 24 | #define WOLFSSL_VERSION_H 25 | 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #define LIBWOLFSSL_VERSION_STRING "4.3.0" 32 | #define LIBWOLFSSL_VERSION_HEX 0x04003000 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | 39 | #endif /* WOLFSSL_VERSION_H */ 40 | 41 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/wolfcrypt/arc4.h: -------------------------------------------------------------------------------- 1 | /* arc4.h 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | /*! 23 | \file wolfssl/wolfcrypt/arc4.h 24 | */ 25 | 26 | #ifndef WOLF_CRYPT_ARC4_H 27 | #define WOLF_CRYPT_ARC4_H 28 | 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #ifdef WOLFSSL_ASYNC_CRYPT 36 | #include 37 | #endif 38 | 39 | enum { 40 | ARC4_ENC_TYPE = 4, /* cipher unique type */ 41 | ARC4_STATE_SIZE = 256, 42 | RC4_KEY_SIZE = 16, /* always 128bit */ 43 | }; 44 | 45 | /* ARC4 encryption and decryption */ 46 | typedef struct Arc4 { 47 | byte x; 48 | byte y; 49 | byte state[ARC4_STATE_SIZE]; 50 | #ifdef WOLFSSL_ASYNC_CRYPT 51 | WC_ASYNC_DEV asyncDev; 52 | #endif 53 | void* heap; 54 | } Arc4; 55 | 56 | WOLFSSL_API int wc_Arc4Process(Arc4*, byte*, const byte*, word32); 57 | WOLFSSL_API int wc_Arc4SetKey(Arc4*, const byte*, word32); 58 | 59 | WOLFSSL_API int wc_Arc4Init(Arc4*, void*, int); 60 | WOLFSSL_API void wc_Arc4Free(Arc4*); 61 | 62 | #ifdef __cplusplus 63 | } /* extern "C" */ 64 | #endif 65 | 66 | 67 | #endif /* WOLF_CRYPT_ARC4_H */ 68 | 69 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/wolfcrypt/chacha.h: -------------------------------------------------------------------------------- 1 | /* chacha.h 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | /*! 23 | \file wolfssl/wolfcrypt/chacha.h 24 | */ 25 | 26 | 27 | #ifndef WOLF_CRYPT_CHACHA_H 28 | #define WOLF_CRYPT_CHACHA_H 29 | 30 | #include 31 | 32 | #ifdef HAVE_CHACHA 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /* Size of the IV */ 39 | #define CHACHA_IV_WORDS 3 40 | #define CHACHA_IV_BYTES (CHACHA_IV_WORDS * sizeof(word32)) 41 | 42 | /* Size of ChaCha chunks */ 43 | #define CHACHA_CHUNK_WORDS 16 44 | #define CHACHA_CHUNK_BYTES (CHACHA_CHUNK_WORDS * sizeof(word32)) 45 | 46 | #ifdef WOLFSSL_X86_64_BUILD 47 | #if defined(USE_INTEL_SPEEDUP) && !defined(NO_CHACHA_ASM) 48 | #define USE_INTEL_CHACHA_SPEEDUP 49 | #define HAVE_INTEL_AVX1 50 | #endif 51 | #endif 52 | 53 | enum { 54 | CHACHA_ENC_TYPE = WC_CIPHER_CHACHA, /* cipher unique type */ 55 | CHACHA_MAX_KEY_SZ = 32, 56 | }; 57 | 58 | typedef struct ChaCha { 59 | word32 X[CHACHA_CHUNK_WORDS]; /* state of cipher */ 60 | #ifdef HAVE_INTEL_AVX1 61 | /* vpshufd reads 16 bytes but we only use bottom 4. */ 62 | byte extra[12]; 63 | #endif 64 | } ChaCha; 65 | 66 | /** 67 | * IV(nonce) changes with each record 68 | * counter is for what value the block counter should start ... usually 0 69 | */ 70 | WOLFSSL_API int wc_Chacha_SetIV(ChaCha* ctx, const byte* inIv, word32 counter); 71 | 72 | WOLFSSL_API int wc_Chacha_Process(ChaCha* ctx, byte* cipher, const byte* plain, 73 | word32 msglen); 74 | WOLFSSL_API int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz); 75 | 76 | #ifdef __cplusplus 77 | } /* extern "C" */ 78 | #endif 79 | 80 | #endif /* HAVE_CHACHA */ 81 | #endif /* WOLF_CRYPT_CHACHA_H */ 82 | 83 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/wolfcrypt/compress.h: -------------------------------------------------------------------------------- 1 | /* compress.h 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | /*! 23 | \file wolfssl/wolfcrypt/compress.h 24 | */ 25 | 26 | 27 | #ifndef WOLF_CRYPT_COMPRESS_H 28 | #define WOLF_CRYPT_COMPRESS_H 29 | 30 | #include 31 | 32 | #ifdef HAVE_LIBZ 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | 39 | #define COMPRESS_FIXED 1 40 | 41 | #define LIBZ_WINBITS_GZIP 16 42 | 43 | 44 | WOLFSSL_API int wc_Compress(byte*, word32, const byte*, word32, word32); 45 | WOLFSSL_API int wc_Compress_ex(byte* out, word32 outSz, const byte* in, 46 | word32 inSz, word32 flags, word32 windowBits); 47 | WOLFSSL_API int wc_DeCompress(byte*, word32, const byte*, word32); 48 | WOLFSSL_API int wc_DeCompress_ex(byte* out, word32 outSz, const byte* in, 49 | word32 inSz, int windowBits); 50 | 51 | #ifdef __cplusplus 52 | } /* extern "C" */ 53 | #endif 54 | 55 | 56 | #endif /* HAVE_LIBZ */ 57 | #endif /* WOLF_CRYPT_COMPRESS_H */ 58 | 59 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/wolfcrypt/cpuid.h: -------------------------------------------------------------------------------- 1 | /* cpuid.h 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | #ifndef WOLF_CRYPT_CPUID_H 25 | #define WOLF_CRYPT_CPUID_H 26 | 27 | 28 | #include 29 | 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #if defined(WOLFSSL_X86_64_BUILD) || defined(USE_INTEL_SPEEDUP) || \ 36 | defined(WOLFSSL_AESNI) 37 | #define CPUID_AVX1 0x0001 38 | #define CPUID_AVX2 0x0002 39 | #define CPUID_RDRAND 0x0004 40 | #define CPUID_RDSEED 0x0008 41 | #define CPUID_BMI2 0x0010 /* MULX, RORX */ 42 | #define CPUID_AESNI 0x0020 43 | #define CPUID_ADX 0x0040 /* ADCX, ADOX */ 44 | 45 | #define IS_INTEL_AVX1(f) ((f) & CPUID_AVX1) 46 | #define IS_INTEL_AVX2(f) ((f) & CPUID_AVX2) 47 | #define IS_INTEL_RDRAND(f) ((f) & CPUID_RDRAND) 48 | #define IS_INTEL_RDSEED(f) ((f) & CPUID_RDSEED) 49 | #define IS_INTEL_BMI2(f) ((f) & CPUID_BMI2) 50 | #define IS_INTEL_AESNI(f) ((f) & CPUID_AESNI) 51 | #define IS_INTEL_ADX(f) ((f) & CPUID_ADX) 52 | 53 | void cpuid_set_flags(void); 54 | word32 cpuid_get_flags(void); 55 | #endif 56 | 57 | #ifdef __cplusplus 58 | } /* extern "C" */ 59 | #endif 60 | 61 | 62 | #endif /* WOLF_CRYPT_CPUID_H */ 63 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/wolfcrypt/fips_test.h: -------------------------------------------------------------------------------- 1 | /* fips_test.h 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | #ifndef WOLF_CRYPT_FIPS_TEST_H 25 | #define WOLF_CRYPT_FIPS_TEST_H 26 | 27 | #include 28 | 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* Known Answer Test string inputs are hex, internal */ 35 | WOLFSSL_LOCAL int DoKnownAnswerTests(char*, int); 36 | 37 | 38 | /* FIPS failure callback */ 39 | typedef void(*wolfCrypt_fips_cb)(int ok, int err, const char* hash); 40 | 41 | /* Public set function */ 42 | WOLFSSL_API int wolfCrypt_SetCb_fips(wolfCrypt_fips_cb cbf); 43 | 44 | /* Public get status functions */ 45 | WOLFSSL_API int wolfCrypt_GetStatus_fips(void); 46 | WOLFSSL_API const char* wolfCrypt_GetCoreHash_fips(void); 47 | 48 | #ifdef HAVE_FORCE_FIPS_FAILURE 49 | /* Public function to force failure mode for operational testing */ 50 | WOLFSSL_API int wolfCrypt_SetStatus_fips(int); 51 | #endif 52 | 53 | 54 | #ifdef __cplusplus 55 | } /* extern "C" */ 56 | #endif 57 | 58 | #endif /* WOLF_CRYPT_FIPS_TEST_H */ 59 | 60 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/wolfcrypt/hc128.h: -------------------------------------------------------------------------------- 1 | /* hc128.h 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | /*! 23 | \file wolfssl/wolfcrypt/hc128.h 24 | */ 25 | 26 | 27 | #ifndef WOLF_CRYPT_HC128_H 28 | #define WOLF_CRYPT_HC128_H 29 | 30 | #include 31 | 32 | #ifndef NO_HC128 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | enum { 39 | HC128_ENC_TYPE = WC_CIPHER_HC128, /* cipher unique type */ 40 | }; 41 | 42 | /* HC-128 stream cipher */ 43 | typedef struct HC128 { 44 | word32 T[1024]; /* P[i] = T[i]; Q[i] = T[1024 + i ]; */ 45 | word32 X[16]; 46 | word32 Y[16]; 47 | word32 counter1024; /* counter1024 = i mod 1024 at the ith step */ 48 | word32 key[8]; 49 | word32 iv[8]; 50 | #ifdef XSTREAM_ALIGN 51 | void* heap; /* heap hint, currently XMALLOC only used with aligning */ 52 | #endif 53 | } HC128; 54 | 55 | 56 | WOLFSSL_API int wc_Hc128_Process(HC128*, byte*, const byte*, word32); 57 | WOLFSSL_API int wc_Hc128_SetKey(HC128*, const byte* key, const byte* iv); 58 | 59 | WOLFSSL_LOCAL int wc_Hc128_SetHeap(HC128* ctx, void* heap); 60 | 61 | #ifdef __cplusplus 62 | } /* extern "C" */ 63 | #endif 64 | 65 | #endif /* HAVE_HC128 */ 66 | #endif /* WOLF_CRYPT_HC128_H */ 67 | 68 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/wolfcrypt/md2.h: -------------------------------------------------------------------------------- 1 | /* md2.h 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | /*! 23 | \file wolfssl/wolfcrypt/md2.h 24 | */ 25 | 26 | 27 | #ifndef WOLF_CRYPT_MD2_H 28 | #define WOLF_CRYPT_MD2_H 29 | 30 | #include 31 | 32 | #ifdef WOLFSSL_MD2 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /* in bytes */ 39 | enum { 40 | MD2 = WC_HASH_TYPE_MD2, 41 | MD2_BLOCK_SIZE = 16, 42 | MD2_DIGEST_SIZE = 16, 43 | MD2_PAD_SIZE = 16, 44 | MD2_X_SIZE = 48 45 | }; 46 | 47 | 48 | /* Md2 digest */ 49 | typedef struct Md2 { 50 | word32 count; /* bytes % PAD_SIZE */ 51 | byte X[MD2_X_SIZE]; 52 | byte C[MD2_BLOCK_SIZE]; 53 | byte buffer[MD2_BLOCK_SIZE]; 54 | } Md2; 55 | 56 | 57 | WOLFSSL_API void wc_InitMd2(Md2*); 58 | WOLFSSL_API void wc_Md2Update(Md2*, const byte*, word32); 59 | WOLFSSL_API void wc_Md2Final(Md2*, byte*); 60 | WOLFSSL_API int wc_Md2Hash(const byte*, word32, byte*); 61 | 62 | 63 | #ifdef __cplusplus 64 | } /* extern "C" */ 65 | #endif 66 | 67 | #endif /* WOLFSSL_MD2 */ 68 | #endif /* WOLF_CRYPT_MD2_H */ 69 | 70 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/wolfcrypt/md4.h: -------------------------------------------------------------------------------- 1 | /* md4.h 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | /*! 23 | \file wolfssl/wolfcrypt/md4.h 24 | */ 25 | 26 | #ifndef WOLF_CRYPT_MD4_H 27 | #define WOLF_CRYPT_MD4_H 28 | 29 | #include 30 | 31 | #ifndef NO_MD4 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* in bytes */ 38 | enum { 39 | MD4 = WC_HASH_TYPE_MD4, 40 | MD4_BLOCK_SIZE = 64, 41 | MD4_DIGEST_SIZE = 16, 42 | MD4_PAD_SIZE = 56 43 | }; 44 | 45 | 46 | /* MD4 digest */ 47 | typedef struct Md4 { 48 | word32 buffLen; /* in bytes */ 49 | word32 loLen; /* length in bytes */ 50 | word32 hiLen; /* length in bytes */ 51 | word32 digest[MD4_DIGEST_SIZE / sizeof(word32)]; 52 | word32 buffer[MD4_BLOCK_SIZE / sizeof(word32)]; 53 | } Md4; 54 | 55 | 56 | WOLFSSL_API void wc_InitMd4(Md4*); 57 | WOLFSSL_API void wc_Md4Update(Md4*, const byte*, word32); 58 | WOLFSSL_API void wc_Md4Final(Md4*, byte*); 59 | 60 | 61 | #ifdef __cplusplus 62 | } /* extern "C" */ 63 | #endif 64 | 65 | #endif /* NO_MD4 */ 66 | #endif /* WOLF_CRYPT_MD4_H */ 67 | 68 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/wolfcrypt/pkcs12.h: -------------------------------------------------------------------------------- 1 | /* pkcs12.h 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_PKCS12_H 24 | #define WOLF_CRYPT_PKCS12_H 25 | 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #ifndef WOLFSSL_TYPES_DEFINED /* do not redeclare from ssl.h */ 33 | typedef struct WC_PKCS12 WC_PKCS12; 34 | #endif 35 | 36 | typedef struct WC_DerCertList { /* dereferenced in ssl.c */ 37 | byte* buffer; 38 | word32 bufferSz; 39 | struct WC_DerCertList* next; 40 | } WC_DerCertList; 41 | 42 | /* default values for creating PKCS12 */ 43 | enum { 44 | WC_PKCS12_ITT_DEFAULT = 2048, 45 | WC_PKCS12_VERSION_DEFAULT = 3, 46 | WC_PKCS12_MAC_DEFAULT = 1, 47 | }; 48 | 49 | WOLFSSL_API WC_PKCS12* wc_PKCS12_new(void); 50 | WOLFSSL_API void wc_PKCS12_free(WC_PKCS12* pkcs12); 51 | WOLFSSL_API int wc_d2i_PKCS12(const byte* der, word32 derSz, WC_PKCS12* pkcs12); 52 | WOLFSSL_API int wc_i2d_PKCS12(WC_PKCS12* pkcs12, byte** der, int* derSz); 53 | WOLFSSL_API int wc_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw, 54 | byte** pkey, word32* pkeySz, byte** cert, word32* certSz, 55 | WC_DerCertList** ca); 56 | WOLFSSL_API WC_PKCS12* wc_PKCS12_create(char* pass, word32 passSz, 57 | char* name, byte* key, word32 keySz, byte* cert, word32 certSz, 58 | WC_DerCertList* ca, int nidKey, int nidCert, int iter, int macIter, 59 | int keyType, void* heap); 60 | 61 | 62 | WOLFSSL_LOCAL int wc_PKCS12_SetHeap(WC_PKCS12* pkcs12, void* heap); 63 | WOLFSSL_LOCAL void* wc_PKCS12_GetHeap(WC_PKCS12* pkcs12); 64 | 65 | WOLFSSL_LOCAL void wc_FreeCertList(WC_DerCertList* list, void* heap); 66 | 67 | #ifdef __cplusplus 68 | } /* extern "C" */ 69 | #endif 70 | 71 | #endif /* WOLF_CRYPT_PKCS12_H */ 72 | 73 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/wolfcrypt/rabbit.h: -------------------------------------------------------------------------------- 1 | /* rabbit.h 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | /*! 23 | \file wolfssl/wolfcrypt/rabbit.h 24 | */ 25 | 26 | 27 | #ifndef WOLF_CRYPT_RABBIT_H 28 | #define WOLF_CRYPT_RABBIT_H 29 | 30 | #include 31 | 32 | #ifndef NO_RABBIT 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | 39 | enum { 40 | RABBIT_ENC_TYPE = 5 /* cipher unique type */ 41 | }; 42 | 43 | 44 | /* Rabbit Context */ 45 | typedef struct RabbitCtx { 46 | word32 x[8]; 47 | word32 c[8]; 48 | word32 carry; 49 | } RabbitCtx; 50 | 51 | 52 | /* Rabbit stream cipher */ 53 | typedef struct Rabbit { 54 | RabbitCtx masterCtx; 55 | RabbitCtx workCtx; 56 | #ifdef XSTREAM_ALIGN 57 | void* heap; /* heap hint, currently XMALLOC only used with aligning */ 58 | #endif 59 | } Rabbit; 60 | 61 | 62 | WOLFSSL_API int wc_RabbitProcess(Rabbit*, byte*, const byte*, word32); 63 | WOLFSSL_API int wc_RabbitSetKey(Rabbit*, const byte* key, const byte* iv); 64 | 65 | WOLFSSL_LOCAL int wc_Rabbit_SetHeap(Rabbit* ctx, void* heap); 66 | 67 | #ifdef __cplusplus 68 | } /* extern "C" */ 69 | #endif 70 | 71 | #endif /* NO_RABBIT */ 72 | #endif /* WOLF_CRYPT_RABBIT_H */ 73 | 74 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/wolfcrypt/ripemd.h: -------------------------------------------------------------------------------- 1 | /* ripemd.h 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | /*! 23 | \file wolfssl/wolfcrypt/ripemd.h 24 | */ 25 | 26 | #ifndef WOLF_CRYPT_RIPEMD_H 27 | #define WOLF_CRYPT_RIPEMD_H 28 | 29 | #include 30 | 31 | #ifdef WOLFSSL_RIPEMD 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | 38 | /* in bytes */ 39 | enum { 40 | RIPEMD = 3, /* hash type unique */ 41 | RIPEMD_BLOCK_SIZE = 64, 42 | RIPEMD_DIGEST_SIZE = 20, 43 | RIPEMD_PAD_SIZE = 56 44 | }; 45 | 46 | 47 | /* RipeMd 160 digest */ 48 | typedef struct RipeMd { 49 | word32 buffLen; /* in bytes */ 50 | word32 loLen; /* length in bytes */ 51 | word32 hiLen; /* length in bytes */ 52 | word32 digest[RIPEMD_DIGEST_SIZE / sizeof(word32)]; 53 | word32 buffer[RIPEMD_BLOCK_SIZE / sizeof(word32)]; 54 | } RipeMd; 55 | 56 | 57 | WOLFSSL_API int wc_InitRipeMd(RipeMd*); 58 | WOLFSSL_API int wc_RipeMdUpdate(RipeMd*, const byte*, word32); 59 | WOLFSSL_API int wc_RipeMdFinal(RipeMd*, byte*); 60 | 61 | 62 | #ifdef __cplusplus 63 | } /* extern "C" */ 64 | #endif 65 | 66 | #endif /* WOLFSSL_RIPEMD */ 67 | #endif /* WOLF_CRYPT_RIPEMD_H */ 68 | -------------------------------------------------------------------------------- /2_Lib/Arduino-HomeKit-ESP32/src/wolfssl/wolfcrypt/selftest.h: -------------------------------------------------------------------------------- 1 | /* selftest.h 2 | * 3 | * Copyright (C) 2006-2019 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | #ifndef WOLFCRYPT_SELF_TEST_H 25 | #define WOLFCRYPT_SELF_TEST_H 26 | 27 | #include 28 | 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #ifdef HAVE_SELFTEST 35 | /* Get wolfCrypt CAVP version */ 36 | WOLFSSL_API const char* wolfCrypt_GetVersion_CAVP_selftest(void); 37 | 38 | /* wolfCrypt self test, runs CAVP KATs */ 39 | WOLFSSL_API int wolfCrypt_SelfTest(void); 40 | #endif 41 | 42 | #ifdef __cplusplus 43 | } /* extern "C" */ 44 | #endif 45 | 46 | #endif /* WOLFCRYPT_SELF_TEST_H */ 47 | 48 | 49 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Mixiaoxiao(谜小小) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/examples/Example01_TemperatureSensor/wifi_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wifi_info.h 3 | * 4 | * Created on: 2020-05-15 5 | * Author: Mixiaoxiao (Wang Bin) 6 | */ 7 | 8 | #ifndef WIFI_INFO_H_ 9 | #define WIFI_INFO_H_ 10 | 11 | #if defined(ESP8266) 12 | #include 13 | #elif defined(ESP32) 14 | #include 15 | #endif 16 | 17 | const char *ssid = "your-ssid"; 18 | const char *password = "your-password"; 19 | 20 | void wifi_connect() { 21 | WiFi.persistent(false); 22 | WiFi.mode(WIFI_STA); 23 | WiFi.setAutoReconnect(true); 24 | WiFi.begin(ssid, password); 25 | Serial.println("WiFi connecting..."); 26 | while (!WiFi.isConnected()) { 27 | delay(100); 28 | Serial.print("."); 29 | } 30 | Serial.print("\n"); 31 | Serial.printf("WiFi connected, IP: %s\n", WiFi.localIP().toString().c_str()); 32 | } 33 | 34 | #endif /* WIFI_INFO_H_ */ 35 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/examples/Example02_Switch/my_accessory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * my_accessory.c 3 | * Define the accessory in C language using the Macro in characteristics.h 4 | * 5 | * Created on: 2020-05-15 6 | * Author: Mixiaoxiao (Wang Bin) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | void my_accessory_identify(homekit_value_t _value) { 13 | printf("accessory identify\n"); 14 | } 15 | 16 | // Switch (HAP section 8.38) 17 | // required: ON 18 | // optional: NAME 19 | 20 | // format: bool; HAP section 9.70; write the .setter function to get the switch-event sent from iOS Home APP. 21 | homekit_characteristic_t cha_switch_on = HOMEKIT_CHARACTERISTIC_(ON, false); 22 | 23 | // format: string; HAP section 9.62; max length 64 24 | homekit_characteristic_t cha_name = HOMEKIT_CHARACTERISTIC_(NAME, "Switch"); 25 | 26 | homekit_accessory_t *accessories[] = { 27 | HOMEKIT_ACCESSORY(.id=1, .category=homekit_accessory_category_switch, .services=(homekit_service_t*[]) { 28 | HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]) { 29 | HOMEKIT_CHARACTERISTIC(NAME, "Switch"), 30 | HOMEKIT_CHARACTERISTIC(MANUFACTURER, "Arduino HomeKit"), 31 | HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "0123456"), 32 | HOMEKIT_CHARACTERISTIC(MODEL, "ESP8266/ESP32"), 33 | HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "1.0"), 34 | HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify), 35 | NULL 36 | }), 37 | HOMEKIT_SERVICE(SWITCH, .primary=true, .characteristics=(homekit_characteristic_t*[]){ 38 | &cha_switch_on, 39 | &cha_name, 40 | NULL 41 | }), 42 | NULL 43 | }), 44 | NULL 45 | }; 46 | 47 | homekit_server_config_t config = { 48 | .accessories = accessories, 49 | .password = "111-11-111" 50 | }; 51 | 52 | 53 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/examples/Example02_Switch/wifi_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wifi_info.h 3 | * 4 | * Created on: 2020-05-15 5 | * Author: Mixiaoxiao (Wang Bin) 6 | */ 7 | 8 | #ifndef WIFI_INFO_H_ 9 | #define WIFI_INFO_H_ 10 | 11 | #if defined(ESP8266) 12 | #include 13 | #elif defined(ESP32) 14 | #include 15 | #endif 16 | 17 | const char *ssid = "your-ssid"; 18 | const char *password = "your-password"; 19 | 20 | void wifi_connect() { 21 | WiFi.persistent(false); 22 | WiFi.mode(WIFI_STA); 23 | WiFi.setAutoReconnect(true); 24 | WiFi.begin(ssid, password); 25 | Serial.println("WiFi connecting..."); 26 | while (!WiFi.isConnected()) { 27 | delay(100); 28 | Serial.print("."); 29 | } 30 | Serial.print("\n"); 31 | Serial.printf("WiFi connected, IP: %s\n", WiFi.localIP().toString().c_str()); 32 | } 33 | 34 | #endif /* WIFI_INFO_H_ */ 35 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/examples/Example03_StatelessProgrammableSwitch/my_accessory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * my_accessory.c 3 | * Define the accessory in C language using the Macro in characteristics.h 4 | * 5 | * Created on: 2020-05-16 6 | * Author: Mixiaoxiao (Wang Bin) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | void my_accessory_identify(homekit_value_t _value) { 13 | printf("accessory identify\n"); 14 | } 15 | 16 | // Stateless Programmable Switch (HAP section 8.37) 17 | // required: PROGRAMMABLE_SWITCH_EVENT 18 | // optional: NAME, SERVICE_LABEL_INDEX 19 | 20 | // format: uint8; HAP section 9.75; write the .getter function and always return "null" for reading 21 | homekit_characteristic_t cha_programmable_switch_event = HOMEKIT_CHARACTERISTIC_(PROGRAMMABLE_SWITCH_EVENT, 0); 22 | 23 | homekit_accessory_t *accessories[] = { 24 | HOMEKIT_ACCESSORY(.id=1, .category=homekit_accessory_category_switch, .services=(homekit_service_t*[]) { 25 | HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]) { 26 | HOMEKIT_CHARACTERISTIC(NAME, "Stateless Programmable Switch"), 27 | HOMEKIT_CHARACTERISTIC(MANUFACTURER, "Arduino HomeKit"), 28 | HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "0123456"), 29 | HOMEKIT_CHARACTERISTIC(MODEL, "ESP8266/ESP32"), 30 | HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "1.0"), 31 | HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify), 32 | NULL 33 | }), 34 | HOMEKIT_SERVICE(STATELESS_PROGRAMMABLE_SWITCH, .primary=true, .characteristics=(homekit_characteristic_t*[]){ 35 | HOMEKIT_CHARACTERISTIC(NAME, "Stateless Programmable Switch"), 36 | &cha_programmable_switch_event, 37 | NULL 38 | }), 39 | NULL 40 | }), 41 | NULL 42 | }; 43 | 44 | homekit_server_config_t config = { 45 | .accessories = accessories, 46 | .password = "111-11-111" 47 | }; 48 | 49 | 50 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/examples/Example03_StatelessProgrammableSwitch/wifi_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wifi_info.h 3 | * 4 | * Created on: 2020-05-15 5 | * Author: Mixiaoxiao (Wang Bin) 6 | */ 7 | 8 | #ifndef WIFI_INFO_H_ 9 | #define WIFI_INFO_H_ 10 | 11 | #if defined(ESP8266) 12 | #include 13 | #elif defined(ESP32) 14 | #include 15 | #endif 16 | 17 | const char *ssid = "your-ssid"; 18 | const char *password = "your-password"; 19 | 20 | void wifi_connect() { 21 | WiFi.persistent(false); 22 | WiFi.mode(WIFI_STA); 23 | WiFi.setAutoReconnect(true); 24 | WiFi.begin(ssid, password); 25 | Serial.println("WiFi connecting..."); 26 | while (!WiFi.isConnected()) { 27 | delay(100); 28 | Serial.print("."); 29 | } 30 | Serial.print("\n"); 31 | Serial.printf("WiFi connected, IP: %s\n", WiFi.localIP().toString().c_str()); 32 | } 33 | 34 | #endif /* WIFI_INFO_H_ */ 35 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/examples/Example04_MultipleAccessories/wifi_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wifi_info.h 3 | * 4 | * Created on: 2020-05-15 5 | * Author: Mixiaoxiao (Wang Bin) 6 | */ 7 | 8 | #ifndef WIFI_INFO_H_ 9 | #define WIFI_INFO_H_ 10 | 11 | #if defined(ESP8266) 12 | #include 13 | #elif defined(ESP32) 14 | #include 15 | #endif 16 | 17 | const char *ssid = "your-ssid"; 18 | const char *password = "your-password"; 19 | 20 | void wifi_connect() { 21 | WiFi.persistent(false); 22 | WiFi.mode(WIFI_STA); 23 | WiFi.setAutoReconnect(true); 24 | WiFi.begin(ssid, password); 25 | Serial.println("WiFi connecting..."); 26 | while (!WiFi.isConnected()) { 27 | delay(100); 28 | Serial.print("."); 29 | } 30 | Serial.print("\n"); 31 | Serial.printf("WiFi connected, IP: %s\n", WiFi.localIP().toString().c_str()); 32 | } 33 | 34 | #endif /* WIFI_INFO_H_ */ 35 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/extras/ESP8266WiFi_nossl_noleak/src/ESP8266WiFiAP.h: -------------------------------------------------------------------------------- 1 | /* 2 | ESP8266WiFiAP.h - esp8266 Wifi support. 3 | Based on WiFi.h from Arduino WiFi shield library. 4 | Copyright (c) 2011-2014 Arduino. All right reserved. 5 | Modified by Ivan Grokhotkov, December 2014 6 | Reworked by Markus Sattler, December 2015 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #ifndef ESP8266WIFIAP_H_ 24 | #define ESP8266WIFIAP_H_ 25 | 26 | 27 | #include "ESP8266WiFiType.h" 28 | #include "ESP8266WiFiGeneric.h" 29 | 30 | 31 | class ESP8266WiFiAPClass { 32 | 33 | // ---------------------------------------------------------------------------------------------- 34 | // ----------------------------------------- AP function ---------------------------------------- 35 | // ---------------------------------------------------------------------------------------------- 36 | 37 | public: 38 | 39 | bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4); 40 | bool softAP(const String& ssid,const String& passphrase = emptyString,int channel = 1,int ssid_hidden = 0,int max_connection = 4); 41 | bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet); 42 | bool softAPdisconnect(bool wifioff = false); 43 | 44 | uint8_t softAPgetStationNum(); 45 | 46 | IPAddress softAPIP(); 47 | 48 | uint8_t* softAPmacAddress(uint8_t* mac); 49 | String softAPmacAddress(void); 50 | 51 | String softAPSSID() const; 52 | String softAPPSK() const; 53 | 54 | protected: 55 | 56 | }; 57 | 58 | #endif /* ESP8266WIFIAP_H_*/ 59 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/extras/ESP8266WiFi_nossl_noleak/src/ESP8266WiFiMulti.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @file ESP8266WiFiMulti.h 4 | * @date 16.05.2015 5 | * @author Markus Sattler 6 | * 7 | * Copyright (c) 2015 Markus Sattler. All rights reserved. 8 | * This file is part of the esp8266 core for Arduino environment. 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | * 24 | */ 25 | 26 | 27 | #ifndef WIFICLIENTMULTI_H_ 28 | #define WIFICLIENTMULTI_H_ 29 | 30 | #include "ESP8266WiFi.h" 31 | #include 32 | 33 | #ifdef DEBUG_ESP_WIFI 34 | #ifdef DEBUG_ESP_PORT 35 | #define DEBUG_WIFI_MULTI(fmt, ...) DEBUG_ESP_PORT.printf_P( (PGM_P)PSTR(fmt), ##__VA_ARGS__ ) 36 | #endif 37 | #endif 38 | 39 | #ifndef DEBUG_WIFI_MULTI 40 | #define DEBUG_WIFI_MULTI(...) do { (void)0; } while (0) 41 | #endif 42 | 43 | struct WifiAPEntry { 44 | char * ssid; 45 | char * passphrase; 46 | }; 47 | 48 | typedef std::vector WifiAPlist; 49 | 50 | class ESP8266WiFiMulti { 51 | public: 52 | ESP8266WiFiMulti(); 53 | ~ESP8266WiFiMulti(); 54 | 55 | bool addAP(const char* ssid, const char *passphrase = NULL); 56 | bool existsAP(const char* ssid, const char *passphrase = NULL); 57 | 58 | wl_status_t run(void); 59 | 60 | void cleanAPlist(void); 61 | 62 | private: 63 | WifiAPlist APlist; 64 | bool APlistAdd(const char* ssid, const char *passphrase = NULL); 65 | bool APlistExists(const char* ssid, const char *passphrase = NULL); 66 | void APlistClean(void); 67 | 68 | }; 69 | 70 | #endif /* WIFICLIENTMULTI_H_ */ 71 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/extras/ESP8266WiFi_nossl_noleak/src/WiFiServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiServer.h - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino LLC. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified by Ivan Grokhotkov, December 2014 - esp8266 support 20 | */ 21 | 22 | #ifndef wifiserver_h 23 | #define wifiserver_h 24 | 25 | extern "C" { 26 | #include "include/wl_definitions.h" 27 | 28 | struct tcp_pcb; 29 | } 30 | 31 | #include "Server.h" 32 | #include "IPAddress.h" 33 | 34 | class ClientContext; 35 | class WiFiClient; 36 | 37 | class WiFiServer : public Server { 38 | // Secure server needs access to all the private entries here 39 | protected: 40 | uint16_t _port; 41 | IPAddress _addr; 42 | tcp_pcb* _pcb; 43 | 44 | ClientContext* _unclaimed; 45 | ClientContext* _discarded; 46 | enum { _ndDefault, _ndFalse, _ndTrue } _noDelay = _ndDefault; 47 | 48 | public: 49 | WiFiServer(const IPAddress& addr, uint16_t port); 50 | WiFiServer(uint16_t port); 51 | virtual ~WiFiServer() {} 52 | WiFiClient available(uint8_t* status = NULL); 53 | bool hasClient(); 54 | void begin(); 55 | void begin(uint16_t port); 56 | void setNoDelay(bool nodelay); 57 | bool getNoDelay(); 58 | virtual size_t write(uint8_t); 59 | virtual size_t write(const uint8_t *buf, size_t size); 60 | uint8_t status(); 61 | void close(); 62 | void stop(); 63 | 64 | using Print::write; 65 | using ClientType = WiFiClient; 66 | 67 | protected: 68 | long _accept(tcp_pcb* newpcb, long err); 69 | void _discard(ClientContext* client); 70 | 71 | static long _s_accept(void *arg, tcp_pcb* newpcb, long err); 72 | static void _s_discard(void* server, ClientContext* ctx); 73 | }; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/extras/ESP8266WiFi_nossl_noleak/src/include/WiFiState.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef WIFISTATE_H_ 3 | #define WIFISTATE_H_ 4 | 5 | #include 6 | #include 7 | 8 | struct WiFiState 9 | { 10 | uint32_t crc; 11 | struct 12 | { 13 | station_config fwconfig; 14 | ip_info ip; 15 | ip_addr_t dns[2]; 16 | ip_addr_t ntp[2]; 17 | WiFiMode_t mode; 18 | uint8_t channel; 19 | bool persistent; 20 | } state; 21 | }; 22 | 23 | #endif // WIFISTATE_H_ 24 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/extras/ESP8266WiFi_nossl_noleak/src/include/slist.h: -------------------------------------------------------------------------------- 1 | #ifndef SLIST_H 2 | #define SLIST_H 3 | 4 | template 5 | class SList { 6 | public: 7 | SList() : _next(0) { } 8 | 9 | protected: 10 | 11 | static void _add(T* self) { 12 | T* tmp = _s_first; 13 | _s_first = self; 14 | self->_next = tmp; 15 | } 16 | 17 | static void _remove(T* self) { 18 | if (_s_first == self) { 19 | _s_first = self->_next; 20 | self->_next = 0; 21 | return; 22 | } 23 | 24 | for (T* prev = _s_first; prev->_next; prev = prev->_next) { 25 | if (prev->_next == self) { 26 | prev->_next = self->_next; 27 | self->_next = 0; 28 | return; 29 | } 30 | } 31 | } 32 | 33 | static T* _s_first; 34 | T* _next; 35 | }; 36 | 37 | 38 | #endif //SLIST_H 39 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/extras/preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycraft/homekit_fan/785c88693364ca0e70091744fb3954c50de9ec84/2_Lib/HomeKit-ESP8266/extras/preview.jpg -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"HomeKit-ESP8266", 3 | "description":"Apple HomeKit accessory server library for the ESP8266 Arduino core.", 4 | "keywords":"homekit,esp8266,esp32,apple homekit", 5 | "authors": 6 | { 7 | "name": "Mixiaoxiao (Wang Bin)", 8 | "maintainer": true 9 | }, 10 | "repository": 11 | { 12 | "type": "git", 13 | "url": "https://github.com/Mixiaoxiao/Arduino-HomeKit-ESP8266.git" 14 | }, 15 | "version": "1.2.0", 16 | "license": "MIT", 17 | "frameworks": "arduino", 18 | "platforms": "espressif8266", 19 | "build": { 20 | "libCompatMode": 2 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/library.properties: -------------------------------------------------------------------------------- 1 | name=HomeKit-ESP8266 2 | version=1.2.0 3 | author=Mixiaoxiao 4 | maintainer=Mixiaoxiao 5 | sentence=Native Apple HomeKit accessory implementation for the ESP8266 Arduino core. 6 | paragraph=Native Apple HomeKit Accessory Implementation for the ESP8266 Arduino core. 7 | category=Communication 8 | url=https://github.com/Mixiaoxiao/Arduino-HomeKit-ESP8266.git 9 | architectures=esp8266 10 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/base64.c: -------------------------------------------------------------------------------- 1 | #include "base64.h" 2 | 3 | static unsigned char base64_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 4 | 5 | unsigned char base64_encode_char(unsigned char c) { 6 | return base64_chars[c]; 7 | } 8 | 9 | unsigned char base64_decode_char(unsigned char c) { 10 | if (c >= 'A' && c <= 'Z') 11 | return c - 'A'; 12 | if (c >= 'a' && c <= 'z') 13 | return c - 'a' + 26; 14 | if (c >= '0' && c <= '9') 15 | return c - '0' + 52; 16 | if (c == '+') 17 | return 62; 18 | if (c == '/') 19 | return 63; 20 | if (c == '=') 21 | return 64; 22 | 23 | return 0; 24 | } 25 | 26 | size_t base64_encoded_size(const unsigned char *data, size_t size) { 27 | return (size + 2)/3*4; 28 | } 29 | 30 | size_t base64_decoded_size(const unsigned char *encoded_data, size_t encoded_size) { 31 | size_t size = (encoded_size + 3)/4*3; 32 | if (encoded_data[encoded_size-1] == '=') 33 | size--; 34 | if (encoded_data[encoded_size-2] == '=') 35 | size--; 36 | return size; 37 | } 38 | 39 | int base64_encode_(const unsigned char* data, size_t size, unsigned char *encoded_data) { 40 | size_t i=0, j=0, size1=size - size%3; 41 | for (; i>2); 43 | encoded_data[j+1] = base64_encode_char(((data[i+0]&0x3)<<4) + (data[i+1]>>4)); 44 | encoded_data[j+2] = base64_encode_char(((data[i+1]&0xF)<<2) + (data[i+2]>>6)); 45 | encoded_data[j+3] = base64_encode_char(data[i+2]&0x3F); 46 | } 47 | 48 | if (size % 3 == 1) { 49 | encoded_data[j+0] = base64_encode_char(data[i+0]>>2); 50 | encoded_data[j+1] = base64_encode_char((data[i+0]&0x3)<<4); 51 | encoded_data[j+2] = encoded_data[j+3] = '='; 52 | j += 4; 53 | } else if (size % 3 == 2) { 54 | encoded_data[j+0] = base64_encode_char(data[i+0]>>2); 55 | encoded_data[j+1] = base64_encode_char(((data[i+0]&0x3)<<4) + (data[i+1]>>4)); 56 | encoded_data[j+2] = base64_encode_char(((data[i+1]&0xF)<<2)); 57 | encoded_data[j+3] = '='; 58 | j += 4; 59 | } 60 | 61 | return j; 62 | } 63 | 64 | int base64_decode_(const unsigned char* encoded_data, size_t encoded_size, unsigned char *data) { 65 | if (encoded_size % 4 != 0) 66 | return -1; 67 | 68 | size_t i=0, j=0; 69 | for (; i>4); 75 | if (block[2] == 64) 76 | break; 77 | 78 | data[j++] = ((block[1]&0xF)<<4) + (block[2]>>2); 79 | if (block[3] == 64) 80 | break; 81 | 82 | data[j++] = ((block[2]&0x3)<<6) + block[3]; 83 | } 84 | 85 | return j; 86 | } 87 | 88 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/base64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | 10 | size_t base64_encoded_size(const unsigned char* data, size_t size); 11 | size_t base64_decoded_size(const unsigned char* encoded_data, size_t encoded_size); 12 | //multiple definition of `base64_decode'; 13 | int base64_encode_(const unsigned char* data, size_t data_size, unsigned char *encoded_data); 14 | int base64_decode_(const unsigned char* encoded_data, size_t encoded_size, unsigned char *data); 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/constants.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define DEVICE_ID_SIZE 36 4 | #define ACCESSORY_ID_SIZE 17 5 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/esp_xpgm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * xpgm.h 3 | * 4 | * Created on: 2020-03-08 5 | * Author: Wang Bin 6 | */ 7 | 8 | #ifndef ESP_XPGM_H_ 9 | #define ESP_XPGM_H_ 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | //see "osapi.h" 20 | /* 21 | This function works only after Serial.setDebugOutput(true); ? 22 | otherwise Serial prints nothing. 23 | #define esp_printf(fmt, ...) do { \ 24 | static const char flash_str[] ICACHE_RODATA_ATTR STORE_ATTR = fmt; \ 25 | os_printf_plus(flash_str, ##__VA_ARGS__); \ 26 | } while(0)*/ 27 | 28 | #define XPGM_PRINTF(fmt, ...) printf_P(PSTR(fmt) , ##__VA_ARGS__); 29 | 30 | #define XPGM_VAR(v0, v1) v0##v1 31 | 32 | // pgm_ptr --> ram_ptr 33 | #define XPGM_CPY(ram_ptr, pgm_ptr, size) memcpy_P(ram_ptr, pgm_ptr, size) 34 | 35 | #define XPGM_BUFFCPY(buff_type, buff_name, pgm_ptr, size) size_t XPGM_VAR(buff_name, _size) = size; \ 36 | buff_type buff_name[XPGM_VAR(buff_name, _size)]; \ 37 | XPGM_CPY(buff_name, pgm_ptr, XPGM_VAR(buff_name, _size)); 38 | 39 | #define XPGM_BUFFCPY_ARRAY(buff_type, buff_name, pgm_array) XPGM_BUFFCPY(buff_type, buff_name, pgm_array, sizeof(pgm_array)) 40 | 41 | #define XPGM_BUFFCPY_STRING(buff_type, buff_name, pgm_string) XPGM_BUFFCPY(buff_type, buff_name, pgm_string, strlen_P(pgm_string) + 1) 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* ESP_XPGM_H_ */ 48 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/homekit/tlv.h: -------------------------------------------------------------------------------- 1 | #ifndef __TLV_H__ 2 | #define __TLV_H__ 3 | 4 | #define __need_size_t 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | typedef unsigned char byte; 15 | 16 | typedef struct _tlv { 17 | struct _tlv *next; 18 | byte type; 19 | byte *value; 20 | size_t size; 21 | } tlv_t; 22 | 23 | 24 | typedef struct { 25 | tlv_t *head; 26 | } tlv_values_t; 27 | 28 | 29 | tlv_values_t *tlv_new(); 30 | 31 | void tlv_free(tlv_values_t *values); 32 | 33 | int tlv_add_value(tlv_values_t *values, byte type, const byte *value, size_t size); 34 | int tlv_add_string_value(tlv_values_t *values, byte type, const char *value); 35 | int tlv_add_integer_value(tlv_values_t *values, byte type, size_t size, int value); 36 | int tlv_add_tlv_value(tlv_values_t *values, byte type, tlv_values_t *value); 37 | 38 | tlv_t *tlv_get_value(const tlv_values_t *values, byte type); 39 | int tlv_get_integer_value(const tlv_values_t *values, byte type, int def); 40 | tlv_values_t *tlv_get_tlv_value(const tlv_values_t *values, byte type); 41 | 42 | int tlv_format(const tlv_values_t *values, byte *buffer, size_t *size); 43 | 44 | int tlv_parse(const byte *buffer, size_t length, tlv_values_t *values); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif // __TLV_H__ 51 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/homekit_debug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "homekit_debug.h" 5 | 6 | 7 | char *binary_to_string(const byte *data, size_t size) { 8 | int i; 9 | 10 | size_t buffer_size = 1; // 1 char for eos 11 | for (i=0; i= 32 && data[i] < 128) ? 1 : 4); 13 | 14 | char *buffer = malloc(buffer_size); 15 | 16 | int pos = 0; 17 | for (i=0; i= 128) { 22 | size_t printed = snprintf(&buffer[pos], buffer_size - pos, "\\x%02X", data[i]); 23 | if (printed > 0) { 24 | pos += printed; 25 | } 26 | } else { 27 | buffer[pos++] = data[i]; 28 | } 29 | } 30 | buffer[pos] = 0; 31 | 32 | return buffer; 33 | } 34 | 35 | 36 | void print_binary(const char *prompt, const byte *data, size_t size) { 37 | #ifdef HOMEKIT_DEBUG 38 | char *buffer = binary_to_string(data, size); 39 | printf("%s (%d bytes): \"%s\"\n", prompt, (int)size, buffer); 40 | free(buffer); 41 | #endif 42 | } 43 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/homekit_debug.h: -------------------------------------------------------------------------------- 1 | #ifndef __HOMEKIT_DEBUG_H__ 2 | #define __HOMEKIT_DEBUG_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include "Arduino.h" 11 | #include 12 | #include 13 | 14 | typedef unsigned char byte; 15 | 16 | //#define HOMEKIT_DEBUG 17 | 18 | #define HOMEKIT_PRINTF XPGM_PRINTF 19 | 20 | #ifdef HOMEKIT_DEBUG 21 | 22 | #define DEBUG(message, ...) HOMEKIT_PRINTF(">>> %s: " message "\n", __func__, ##__VA_ARGS__) 23 | static uint32_t start_time = 0; 24 | #define DEBUG_TIME_BEGIN() start_time=millis(); 25 | #define DEBUG_TIME_END(func_name) HOMEKIT_PRINTF("### [%7d] %s took %6dms\n", millis(), func_name, (millis() - start_time)); 26 | 27 | #else 28 | 29 | #define DEBUG(message, ...) 30 | #define DEBUG_TIME_BEGIN() 31 | #define DEBUG_TIME_END(func_name) 32 | 33 | #endif 34 | 35 | #define INFO(message, ...) HOMEKIT_PRINTF(">>> [%7d] HomeKit: " message "\n", millis(), ##__VA_ARGS__) 36 | #define ERROR(message, ...) HOMEKIT_PRINTF("!!! [%7d] HomeKit: " message "\n", millis(), ##__VA_ARGS__) 37 | #define INFO_HEAP() INFO("Free heap: %d", system_get_free_heap_size()); 38 | #define DEBUG_HEAP() DEBUG("Free heap: %d", system_get_free_heap_size()); 39 | 40 | char *binary_to_string(const byte *data, size_t size); 41 | void print_binary(const char *prompt, const byte *data, size_t size); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif // __HOMEKIT_DEBUG_H__ 48 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/json.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | struct json_stream; 10 | typedef struct json_stream json_stream; 11 | 12 | typedef void (*json_flush_callback)(uint8_t *buffer, size_t size, void *context); 13 | 14 | json_stream *json_new(size_t buffer_size, json_flush_callback on_flush, void *context); 15 | void json_free(json_stream *json); 16 | 17 | void json_flush(json_stream *json); 18 | 19 | void json_object_start(json_stream *json); 20 | void json_object_end(json_stream *json); 21 | 22 | void json_array_start(json_stream *json); 23 | void json_array_end(json_stream *json); 24 | 25 | void json_integer(json_stream *json, int x); 26 | void json_uint8(json_stream *json, uint8_t x); 27 | void json_uint16(json_stream *json, uint16_t x); 28 | void json_uint32(json_stream *json, uint32_t x); 29 | void json_uint64(json_stream *json, uint64_t x); 30 | void json_float(json_stream *json, float x); 31 | void json_string(json_stream *json, const char *x); 32 | void json_boolean(json_stream *json, bool x); 33 | void json_null(json_stream *json); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/pairing.h: -------------------------------------------------------------------------------- 1 | #ifndef __PAIRING_H__ 2 | #define __PAIRING_H__ 3 | 4 | #include "constants.h" 5 | #include "crypto.h" 6 | 7 | 8 | typedef enum { 9 | pairing_permissions_admin = (1 << 0), 10 | } pairing_permissions_t; 11 | 12 | typedef struct { 13 | int id; 14 | char device_id[DEVICE_ID_SIZE + 1]; 15 | ed25519_key device_key; 16 | pairing_permissions_t permissions; 17 | } pairing_t; 18 | 19 | #endif // __PAIRING_H__ 20 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/port.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | 9 | uint32_t homekit_random(); 10 | void homekit_random_fill(uint8_t *data, size_t size); 11 | 12 | void homekit_system_restart(); 13 | void homekit_overclock_start(); 14 | void homekit_overclock_end(); 15 | 16 | #ifdef ESP_OPEN_RTOS 17 | #include 18 | #define ESP_OK 0 19 | #endif 20 | 21 | //#ifdef ESP_IDF 22 | //#include 23 | //#include 24 | 25 | #ifdef ARDUINO_ARCH_ESP8266 26 | #include "Arduino.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | #define ESP_OK SPI_FLASH_RESULT_OK //0 34 | 35 | #define SPI_FLASH_SECTOR_SIZE SPI_FLASH_SEC_SIZE 36 | #define spiflash_read(addr, buffer, size) (spi_flash_read((addr), (buffer), (size)) == ESP_OK) 37 | #define spiflash_write(addr, data, size) (spi_flash_write((addr), (data), (size)) == ESP_OK) 38 | #define spiflash_erase_sector(addr) (spi_flash_erase_sector((addr) / SPI_FLASH_SECTOR_SIZE) == ESP_OK) 39 | #endif 40 | 41 | 42 | #ifdef ESP_IDF 43 | #define SERVER_TASK_STACK 12288 44 | #else 45 | #define SERVER_TASK_STACK 2048 46 | #endif 47 | 48 | 49 | //void homekit_mdns_init(); 50 | //void homekit_mdns_configure_init(const char *instance_name, int port); 51 | //void homekit_mdns_add_txt(const char *key, const char *format, ...); 52 | //void homekit_mdns_configure_finalize(); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/query_params.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "query_params.h" 4 | 5 | 6 | query_param_t *query_params_parse(const char *s) { 7 | query_param_t *params = NULL; 8 | 9 | int i = 0; 10 | while (1) { 11 | int pos = i; 12 | while (s[i] && s[i] != '=' && s[i] != '&' && s[i] != '#') i++; 13 | if (i == pos) { 14 | i++; 15 | continue; 16 | } 17 | 18 | query_param_t *param = malloc(sizeof(query_param_t)); 19 | param->name = strndup(s+pos, i-pos); 20 | param->value = NULL; 21 | param->next = params; 22 | params = param; 23 | 24 | if (s[i] == '=') { 25 | i++; 26 | pos = i; 27 | while (s[i] && s[i] != '&' && s[i] != '#') i++; 28 | if (i != pos) { 29 | param->value = strndup(s+pos, i-pos); 30 | } 31 | } 32 | 33 | if (!s[i] || s[i] == '#') 34 | break; 35 | } 36 | 37 | return params; 38 | } 39 | 40 | 41 | query_param_t *query_params_find(query_param_t *params, const char *name) { 42 | while (params) { 43 | if (!strcmp(params->name, name)) 44 | return params; 45 | params = params->next; 46 | } 47 | 48 | return NULL; 49 | } 50 | 51 | 52 | void query_params_free(query_param_t *params) { 53 | while (params) { 54 | query_param_t *next = params->next; 55 | if (params->name) 56 | free(params->name); 57 | if (params->value) 58 | free(params->value); 59 | free(params); 60 | 61 | params = next; 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/query_params.h: -------------------------------------------------------------------------------- 1 | #ifndef __HOMEKIT_QUERY_PARAMS__ 2 | #define __HOMEKIT_QUERY_PARAMS__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef struct _query_param { 9 | char *name; 10 | char *value; 11 | 12 | struct _query_param *next; 13 | } query_param_t; 14 | 15 | query_param_t *query_params_parse(const char *s); 16 | query_param_t *query_params_find(query_param_t *params, const char *name); 17 | void query_params_free(query_param_t *params); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif // __HOMEKIT_QUERY_PARAMS__ 24 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/storage.h: -------------------------------------------------------------------------------- 1 | #ifndef __STORAGE_H__ 2 | #define __STORAGE_H__ 3 | 4 | //#include "EEPROM.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #include "pairing.h" 11 | 12 | int homekit_storage_reset(); 13 | 14 | int homekit_storage_init(); 15 | 16 | void homekit_storage_save_accessory_id(const char *accessory_id); 17 | int homekit_storage_load_accessory_id(char *data); 18 | 19 | void homekit_storage_save_accessory_key(const ed25519_key *key); 20 | int homekit_storage_load_accessory_key(ed25519_key *key); 21 | 22 | bool homekit_storage_can_add_pairing(); 23 | int homekit_storage_add_pairing(const char *device_id, const ed25519_key *device_key, byte permissions); 24 | int homekit_storage_update_pairing(const char *device_id, byte permissions); 25 | int homekit_storage_remove_pairing(const char *device_id); 26 | int homekit_storage_find_pairing(const char *device_id, pairing_t *pairing); 27 | 28 | typedef struct { 29 | int idx; 30 | } pairing_iterator_t; 31 | 32 | 33 | void homekit_storage_pairing_iterator_init(pairing_iterator_t *it); 34 | int homekit_storage_next_pairing(pairing_iterator_t *it, pairing_t *pairing); 35 | void homekit_storage_pairing_iterator_done(pairing_iterator_t *iterator); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | #endif // __STORAGE_H__ 41 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/user_settings.h: -------------------------------------------------------------------------------- 1 | #ifndef wolfcrypt_user_settings_h 2 | #define wolfcrypt_user_settings_h 3 | 4 | #define WOLFSSL_USER_SETTINGS 5 | 6 | //#define ARDUINO_HOMEKIT_LOWROM 7 | 8 | //skip ed25519_verify, see crypto_ed25519_verify in crypto.c 9 | //Pair Verify Step 2/2: skip=35ms, not-skip=794ms 10 | //#define ARDUINO_HOMEKIT_SKIP_ED25519_VERIFY 11 | 12 | #include "stdint.h" 13 | #include "stddef.h" 14 | #include "stdlib.h" 15 | #include "osapi.h" 16 | #include "homekit_debug.h" 17 | 18 | static inline int hwrand_generate_block(uint8_t *buf, size_t len) { 19 | os_get_random(buf, len); 20 | return 0; 21 | } 22 | 23 | #define WC_NO_HARDEN 24 | #define NO_WOLFSSL_DIR 25 | #define SINGLE_THREADED 26 | #define WOLFSSL_LWIP 27 | #define NO_INLINE 28 | 29 | #define NO_WOLFSSL_MEMORY 30 | #define MP_LOW_MEM 31 | 32 | #define CUSTOM_RAND_GENERATE_BLOCK hwrand_generate_block 33 | 34 | //========== 35 | // added 36 | //========== 37 | #define WOLFCRYPT_ONLY 38 | 39 | #define NO_ASN 40 | #define NO_AES 41 | #define NO_RC4 42 | #define NO_RSA 43 | #define NO_SHA256 44 | #define NO_DH 45 | #define NO_DSA 46 | #define NO_CODING 47 | #define NO_SHA 48 | #define NO_MD5 49 | 50 | #define HAVE_CURVE25519 51 | #define HAVE_CHACHA 52 | #define HAVE_POLY1305 53 | #define HAVE_ED25519 54 | #define WOLFSSL_SHA512 55 | #define WOLFCRYPT_HAVE_SRP 56 | #define HAVE_HKDF 57 | 58 | #define WC_NO_HASHDRBG 59 | 60 | #define WOLFSSL_BASE64_ENCODE 61 | 62 | //see integer.c 63 | //default winsize=5(MP_LOW_MEM), but ram(heap) is not sufficient! 64 | //winsize of {2,3,4,5} are same performance 65 | //lower winsize, lower ram required 66 | #define ESP_INTEGER_WINSIZE 2 67 | //winsize=3 & mp_exptmod_fast : ram(heap) is not sufficient 68 | //force use s_mp_exptmod (lower memory), and smiller performance with mp_exptmod_fast 69 | #define ESP_FORCE_S_MP_EXPTMOD 70 | //winsize = 5 & mp_exptmod_fast 最快,Pair Verify Step 2/2 = 10s左右 71 | //winsize = 6 heap不够 72 | 73 | 74 | #define MP_16BIT //faster than 32bit in ESP8266 75 | 76 | #if defined(ARDUINO_HOMEKIT_LOWROM) 77 | 78 | #define CURVE25519_SMALL 79 | #define ED25519_SMALL //关联ED25519,关闭这个之后编译dram会超(stack mem太大) 80 | //`.bss' is not within region `dram0_0_seg' 81 | 82 | #else 83 | // crypto.c crypto_ed25519_verify 84 | // No sufficient ram to run ge_double_scalarmult_vartime in ge_operations.c 85 | // Run the ge_double_scalarmult_vartime in ge_low_mem 86 | #define ESP_GE_DOUBLE_SCALARMULT_VARTIME_LOWMEM 87 | 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/watchdog.c: -------------------------------------------------------------------------------- 1 | // Base on esp_hw_wdt in github 2 | /* 3 | * Copyright (c) 2014-2017 Cesanta Software Limited 4 | * All rights reserved 5 | * Changed: 6 | * 2017 Alexander Epstine (a@epstine.com) 7 | */ 8 | 9 | #include "watchdog.h" 10 | #include "Arduino.h" 11 | #include "stdint.h" 12 | #include "user_interface.h" 13 | #include "homekit_debug.h" 14 | 15 | #define REG_WDT_BASE 0x60000900 16 | 17 | #define WDT_CTL (REG_WDT_BASE + 0x0) 18 | #define WDT_CTL_ENABLE (BIT(0)) 19 | #define WDT_RESET (REG_WDT_BASE + 0x14) 20 | #define WDT_RESET_VALUE 0x73 21 | 22 | void esp_hw_wdt_enable() { 23 | SET_PERI_REG_MASK(WDT_CTL, WDT_CTL_ENABLE); 24 | } 25 | 26 | void esp_hw_wdt_disable() { 27 | CLEAR_PERI_REG_MASK(WDT_CTL, WDT_CTL_ENABLE); 28 | } 29 | 30 | void esp_hw_wdt_feed() { 31 | WRITE_PERI_REG(WDT_RESET, WDT_RESET_VALUE); 32 | } 33 | 34 | void watchdog_disable_all() { 35 | system_soft_wdt_stop(); 36 | esp_hw_wdt_disable(); 37 | } 38 | 39 | void watchdog_enable_all() { 40 | esp_hw_wdt_enable(); 41 | system_soft_wdt_restart(); 42 | } 43 | 44 | #ifdef HOMEKIT_DEBUG 45 | 46 | static uint32_t wdt_checkpoint; 47 | 48 | void watchdog_check_begin() { 49 | wdt_checkpoint = millis(); 50 | } 51 | 52 | void watchdog_check_end(const char *message) { 53 | uint32_t d = millis() - wdt_checkpoint; 54 | printf("[WatchDog] Function %s took: %dms\n", message, d); 55 | } 56 | 57 | #else 58 | 59 | void watchdog_check_begin() { 60 | } 61 | void watchdog_check_end(const char *message) { 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/watchdog.h: -------------------------------------------------------------------------------- 1 | #ifndef WATCHDOG_H_ 2 | #define WATCHDOG_H_ 3 | 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | void watchdog_disable_all(); 10 | 11 | void watchdog_enable_all(); 12 | 13 | void watchdog_check_begin(); 14 | 15 | void watchdog_check_end(const char* message); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | 22 | #endif /* WATCHDOG_H_ */ 23 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/arc4.h: -------------------------------------------------------------------------------- 1 | /* arc4.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | #ifndef WOLF_CRYPT_ARC4_H 25 | #define WOLF_CRYPT_ARC4_H 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #ifdef WOLFSSL_ASYNC_CRYPT 34 | #include 35 | #endif 36 | 37 | enum { 38 | ARC4_ENC_TYPE = 4, /* cipher unique type */ 39 | ARC4_STATE_SIZE = 256 40 | }; 41 | 42 | /* ARC4 encryption and decryption */ 43 | typedef struct Arc4 { 44 | byte x; 45 | byte y; 46 | byte state[ARC4_STATE_SIZE]; 47 | #ifdef WOLFSSL_ASYNC_CRYPT 48 | WC_ASYNC_DEV asyncDev; 49 | #endif 50 | void* heap; 51 | } Arc4; 52 | 53 | WOLFSSL_API int wc_Arc4Process(Arc4*, byte*, const byte*, word32); 54 | WOLFSSL_API int wc_Arc4SetKey(Arc4*, const byte*, word32); 55 | 56 | WOLFSSL_API int wc_Arc4Init(Arc4*, void*, int); 57 | WOLFSSL_API void wc_Arc4Free(Arc4*); 58 | 59 | #ifdef __cplusplus 60 | } /* extern "C" */ 61 | #endif 62 | 63 | 64 | #endif /* WOLF_CRYPT_ARC4_H */ 65 | 66 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/blake2.h: -------------------------------------------------------------------------------- 1 | /* blake2.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | 25 | #ifndef WOLF_CRYPT_BLAKE2_H 26 | #define WOLF_CRYPT_BLAKE2_H 27 | 28 | #include 29 | 30 | #ifdef HAVE_BLAKE2 31 | 32 | #include 33 | 34 | /* call old functions if using fips for the sake of hmac @wc_fips */ 35 | #ifdef HAVE_FIPS 36 | /* Since hmac can call blake functions provide original calls */ 37 | #define wc_InitBlake2b InitBlake2b 38 | #define wc_Blake2bUpdate Blake2bUpdate 39 | #define wc_Blake2bFinal Blake2bFinal 40 | #endif 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* in bytes, variable digest size up to 512 bits (64 bytes) */ 47 | enum { 48 | BLAKE2B_ID = 7, /* hash type unique */ 49 | BLAKE2B_256 = 32 /* 256 bit type, SSL default */ 50 | }; 51 | 52 | 53 | /* BLAKE2b digest */ 54 | typedef struct Blake2b { 55 | blake2b_state S[1]; /* our state */ 56 | word32 digestSz; /* digest size used on init */ 57 | } Blake2b; 58 | 59 | 60 | WOLFSSL_API int wc_InitBlake2b(Blake2b*, word32); 61 | WOLFSSL_API int wc_Blake2bUpdate(Blake2b*, const byte*, word32); 62 | WOLFSSL_API int wc_Blake2bFinal(Blake2b*, byte*, word32); 63 | 64 | 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* HAVE_BLAKE2 */ 71 | #endif /* WOLF_CRYPT_BLAKE2_H */ 72 | 73 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/chacha.h: -------------------------------------------------------------------------------- 1 | /* chacha.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_CHACHA_H 24 | #define WOLF_CRYPT_CHACHA_H 25 | 26 | #include 27 | 28 | #ifdef HAVE_CHACHA 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* Size of the IV */ 35 | #define CHACHA_IV_WORDS 3 36 | #define CHACHA_IV_BYTES (CHACHA_IV_WORDS * sizeof(word32)) 37 | 38 | /* Size of ChaCha chunks */ 39 | #define CHACHA_CHUNK_WORDS 16 40 | #define CHACHA_CHUNK_BYTES (CHACHA_CHUNK_WORDS * sizeof(word32)) 41 | 42 | enum { 43 | CHACHA_ENC_TYPE = 7 /* cipher unique type */ 44 | }; 45 | 46 | typedef struct ChaCha { 47 | word32 X[CHACHA_CHUNK_WORDS]; /* state of cipher */ 48 | } ChaCha; 49 | 50 | /** 51 | * IV(nonce) changes with each record 52 | * counter is for what value the block counter should start ... usually 0 53 | */ 54 | WOLFSSL_API int wc_Chacha_SetIV(ChaCha* ctx, const byte* inIv, word32 counter); 55 | 56 | WOLFSSL_API int wc_Chacha_Process(ChaCha* ctx, byte* cipher, const byte* plain, 57 | word32 msglen); 58 | WOLFSSL_API int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz); 59 | 60 | #ifdef __cplusplus 61 | } /* extern "C" */ 62 | #endif 63 | 64 | #endif /* HAVE_CHACHA */ 65 | #endif /* WOLF_CRYPT_CHACHA_H */ 66 | 67 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/cmac.h: -------------------------------------------------------------------------------- 1 | /* cmac.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_CMAC_H 24 | #define WOLF_CRYPT_CMAC_H 25 | 26 | #include 27 | #include 28 | 29 | #if !defined(NO_AES) && defined(WOLFSSL_CMAC) 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | typedef struct Cmac { 36 | Aes aes; 37 | byte buffer[AES_BLOCK_SIZE]; /* partially stored block */ 38 | byte digest[AES_BLOCK_SIZE]; /* running digest */ 39 | byte k1[AES_BLOCK_SIZE]; 40 | byte k2[AES_BLOCK_SIZE]; 41 | word32 bufferSz; 42 | word32 totalSz; 43 | } Cmac; 44 | 45 | 46 | typedef enum CmacType { 47 | WC_CMAC_AES = 1 48 | } CmacType; 49 | 50 | 51 | WOLFSSL_API 52 | int wc_InitCmac(Cmac* cmac, 53 | const byte* key, word32 keySz, 54 | int type, void* unused); 55 | WOLFSSL_API 56 | int wc_CmacUpdate(Cmac* cmac, 57 | const byte* in, word32 inSz); 58 | WOLFSSL_API 59 | int wc_CmacFinal(Cmac* cmac, 60 | byte* out, word32* outSz); 61 | 62 | WOLFSSL_API 63 | int wc_AesCmacGenerate(byte* out, word32* outSz, 64 | const byte* in, word32 inSz, 65 | const byte* key, word32 keySz); 66 | 67 | WOLFSSL_API 68 | int wc_AesCmacVerify(const byte* check, word32 checkSz, 69 | const byte* in, word32 inSz, 70 | const byte* key, word32 keySz); 71 | 72 | #ifdef __cplusplus 73 | } /* extern "C" */ 74 | #endif 75 | 76 | 77 | #endif /* NO_AES && WOLFSSL_CMAC */ 78 | #endif /* WOLF_CRYPT_CMAC_H */ 79 | 80 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/compress.h: -------------------------------------------------------------------------------- 1 | /* compress.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_COMPRESS_H 24 | #define WOLF_CRYPT_COMPRESS_H 25 | 26 | #include 27 | 28 | #ifdef HAVE_LIBZ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | 35 | #define COMPRESS_FIXED 1 36 | 37 | 38 | WOLFSSL_API int wc_Compress(byte*, word32, const byte*, word32, word32); 39 | WOLFSSL_API int wc_DeCompress(byte*, word32, const byte*, word32); 40 | 41 | 42 | #ifdef __cplusplus 43 | } /* extern "C" */ 44 | #endif 45 | 46 | 47 | #endif /* HAVE_LIBZ */ 48 | #endif /* WOLF_CRYPT_COMPRESS_H */ 49 | 50 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/cpuid.h: -------------------------------------------------------------------------------- 1 | /* cpuid.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | #ifndef WOLF_CRYPT_CPUID_H 25 | #define WOLF_CRYPT_CPUID_H 26 | 27 | 28 | #include 29 | 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #if defined(WOLFSSL_X86_64_BUILD) || defined(USE_INTEL_SPEEDUP) || \ 36 | defined(WOLFSSL_AESNI) 37 | #define CPUID_AVX1 0x0001 38 | #define CPUID_AVX2 0x0002 39 | #define CPUID_RDRAND 0x0004 40 | #define CPUID_RDSEED 0x0008 41 | #define CPUID_BMI2 0x0010 /* MULX, RORX */ 42 | #define CPUID_AESNI 0x0020 43 | #define CPUID_ADX 0x0040 /* ADCX, ADOX */ 44 | 45 | #define IS_INTEL_AVX1(f) ((f) & CPUID_AVX1) 46 | #define IS_INTEL_AVX2(f) ((f) & CPUID_AVX2) 47 | #define IS_INTEL_RDRAND(f) ((f) & CPUID_RDRAND) 48 | #define IS_INTEL_RDSEED(f) ((f) & CPUID_RDSEED) 49 | #define IS_INTEL_BMI2(f) ((f) & CPUID_BMI2) 50 | #define IS_INTEL_AESNI(f) ((f) & CPUID_AESNI) 51 | #define IS_INTEL_ADX(f) ((f) & CPUID_ADX) 52 | 53 | void cpuid_set_flags(void); 54 | word32 cpuid_get_flags(void); 55 | #endif 56 | 57 | #ifdef __cplusplus 58 | } /* extern "C" */ 59 | #endif 60 | 61 | 62 | #endif /* WOLF_CRYPT_CPUID_H */ 63 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/fips_test.h: -------------------------------------------------------------------------------- 1 | /* fips_test.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | #ifndef WOLF_CRYPT_FIPS_TEST_H 25 | #define WOLF_CRYPT_FIPS_TEST_H 26 | 27 | #include 28 | 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* Known Answer Test string inputs are hex, internal */ 35 | CYASSL_LOCAL int DoKnownAnswerTests(char*, int); 36 | 37 | 38 | /* FIPS failure callback */ 39 | typedef void(*wolfCrypt_fips_cb)(int ok, int err, const char* hash); 40 | 41 | /* Public set function */ 42 | CYASSL_API int wolfCrypt_SetCb_fips(wolfCrypt_fips_cb cbf); 43 | 44 | /* Public get status functions */ 45 | CYASSL_API int wolfCrypt_GetStatus_fips(void); 46 | CYASSL_API const char* wolfCrypt_GetCoreHash_fips(void); 47 | 48 | #ifdef HAVE_FORCE_FIPS_FAILURE 49 | /* Public function to force failure mode for operational testing */ 50 | CYASSL_API int wolfCrypt_SetStatus_fips(int); 51 | #endif 52 | 53 | 54 | #ifdef __cplusplus 55 | } /* extern "C" */ 56 | #endif 57 | 58 | #endif /* WOLF_CRYPT_FIPS_TEST_H */ 59 | 60 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/hc128.h: -------------------------------------------------------------------------------- 1 | /* hc128.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_HC128_H 24 | #define WOLF_CRYPT_HC128_H 25 | 26 | #include 27 | 28 | #ifndef NO_HC128 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | enum { 35 | HC128_ENC_TYPE = 6 /* cipher unique type */ 36 | }; 37 | 38 | /* HC-128 stream cipher */ 39 | typedef struct HC128 { 40 | word32 T[1024]; /* P[i] = T[i]; Q[i] = T[1024 + i ]; */ 41 | word32 X[16]; 42 | word32 Y[16]; 43 | word32 counter1024; /* counter1024 = i mod 1024 at the ith step */ 44 | word32 key[8]; 45 | word32 iv[8]; 46 | #ifdef XSTREAM_ALIGN 47 | void* heap; /* heap hint, currently XMALLOC only used with aligning */ 48 | #endif 49 | } HC128; 50 | 51 | 52 | WOLFSSL_API int wc_Hc128_Process(HC128*, byte*, const byte*, word32); 53 | WOLFSSL_API int wc_Hc128_SetKey(HC128*, const byte* key, const byte* iv); 54 | 55 | WOLFSSL_LOCAL int wc_Hc128_SetHeap(HC128* ctx, void* heap); 56 | 57 | #ifdef __cplusplus 58 | } /* extern "C" */ 59 | #endif 60 | 61 | #endif /* HAVE_HC128 */ 62 | #endif /* WOLF_CRYPT_HC128_H */ 63 | 64 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/idea.h: -------------------------------------------------------------------------------- 1 | /* idea.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_IDEA_H 24 | #define WOLF_CRYPT_IDEA_H 25 | 26 | #include 27 | 28 | #ifdef HAVE_IDEA 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | enum { 35 | IDEA_MODULO = 0x10001, /* 2^16+1 */ 36 | IDEA_2EXP16 = 0x10000, /* 2^16 */ 37 | IDEA_MASK = 0xFFFF, /* 16 bits set to one */ 38 | IDEA_ROUNDS = 8, /* number of rounds for IDEA */ 39 | IDEA_SK_NUM = (6*IDEA_ROUNDS + 4), /* number of subkeys */ 40 | IDEA_KEY_SIZE = 16, /* size of key in bytes */ 41 | IDEA_BLOCK_SIZE = 8, /* size of IDEA blocks in bytes */ 42 | IDEA_IV_SIZE = 8, /* size of IDEA IV in bytes */ 43 | IDEA_ENCRYPTION = 0, 44 | IDEA_DECRYPTION = 1 45 | }; 46 | 47 | /* IDEA encryption and decryption */ 48 | typedef struct Idea { 49 | word32 reg[IDEA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ 50 | word32 tmp[IDEA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ 51 | word16 skey[IDEA_SK_NUM]; /* 832 bits expanded key */ 52 | } Idea; 53 | 54 | WOLFSSL_API int wc_IdeaSetKey(Idea *idea, const byte* key, word16 keySz, 55 | const byte *iv, int dir); 56 | WOLFSSL_API int wc_IdeaSetIV(Idea *idea, const byte* iv); 57 | WOLFSSL_API int wc_IdeaCipher(Idea *idea, byte* out, const byte* in); 58 | WOLFSSL_API int wc_IdeaCbcEncrypt(Idea *idea, byte* out, 59 | const byte* in, word32 len); 60 | WOLFSSL_API int wc_IdeaCbcDecrypt(Idea *idea, byte* out, 61 | const byte* in, word32 len); 62 | #ifdef __cplusplus 63 | } /* extern "C" */ 64 | #endif 65 | 66 | #endif /* HAVE_IDEA */ 67 | #endif /* WOLF_CRYPT_IDEA_H */ 68 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/md2.h: -------------------------------------------------------------------------------- 1 | /* md2.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_MD2_H 24 | #define WOLF_CRYPT_MD2_H 25 | 26 | #include 27 | 28 | #ifdef WOLFSSL_MD2 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* in bytes */ 35 | enum { 36 | MD2 = 6, /* hash type unique */ 37 | MD2_BLOCK_SIZE = 16, 38 | MD2_DIGEST_SIZE = 16, 39 | MD2_PAD_SIZE = 16, 40 | MD2_X_SIZE = 48 41 | }; 42 | 43 | 44 | /* Md2 digest */ 45 | typedef struct Md2 { 46 | word32 count; /* bytes % PAD_SIZE */ 47 | byte X[MD2_X_SIZE]; 48 | byte C[MD2_BLOCK_SIZE]; 49 | byte buffer[MD2_BLOCK_SIZE]; 50 | } Md2; 51 | 52 | 53 | WOLFSSL_API void wc_InitMd2(Md2*); 54 | WOLFSSL_API void wc_Md2Update(Md2*, const byte*, word32); 55 | WOLFSSL_API void wc_Md2Final(Md2*, byte*); 56 | WOLFSSL_API int wc_Md2Hash(const byte*, word32, byte*); 57 | 58 | 59 | #ifdef __cplusplus 60 | } /* extern "C" */ 61 | #endif 62 | 63 | #endif /* WOLFSSL_MD2 */ 64 | #endif /* WOLF_CRYPT_MD2_H */ 65 | 66 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/md4.h: -------------------------------------------------------------------------------- 1 | /* md4.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_MD4_H 24 | #define WOLF_CRYPT_MD4_H 25 | 26 | #include 27 | 28 | #ifndef NO_MD4 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* in bytes */ 35 | enum { 36 | MD4_BLOCK_SIZE = 64, 37 | MD4_DIGEST_SIZE = 16, 38 | MD4_PAD_SIZE = 56 39 | }; 40 | 41 | 42 | /* MD4 digest */ 43 | typedef struct Md4 { 44 | word32 buffLen; /* in bytes */ 45 | word32 loLen; /* length in bytes */ 46 | word32 hiLen; /* length in bytes */ 47 | word32 digest[MD4_DIGEST_SIZE / sizeof(word32)]; 48 | word32 buffer[MD4_BLOCK_SIZE / sizeof(word32)]; 49 | } Md4; 50 | 51 | 52 | WOLFSSL_API void wc_InitMd4(Md4*); 53 | WOLFSSL_API void wc_Md4Update(Md4*, const byte*, word32); 54 | WOLFSSL_API void wc_Md4Final(Md4*, byte*); 55 | 56 | 57 | #ifdef __cplusplus 58 | } /* extern "C" */ 59 | #endif 60 | 61 | #endif /* NO_MD4 */ 62 | #endif /* WOLF_CRYPT_MD4_H */ 63 | 64 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/pkcs12.h: -------------------------------------------------------------------------------- 1 | /* pkcs12.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_PKCS12_H 24 | #define WOLF_CRYPT_PKCS12_H 25 | 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #ifndef WOLFSSL_TYPES_DEFINED /* do not redeclare from ssl.h */ 33 | typedef struct WC_PKCS12 WC_PKCS12; 34 | #endif 35 | 36 | typedef struct WC_DerCertList { /* dereferenced in ssl.c */ 37 | byte* buffer; 38 | word32 bufferSz; 39 | struct WC_DerCertList* next; 40 | } WC_DerCertList; 41 | 42 | 43 | 44 | WOLFSSL_API WC_PKCS12* wc_PKCS12_new(void); 45 | WOLFSSL_API void wc_PKCS12_free(WC_PKCS12* pkcs12); 46 | WOLFSSL_API int wc_d2i_PKCS12(const byte* der, word32 derSz, WC_PKCS12* pkcs12); 47 | WOLFSSL_API int wc_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw, 48 | byte** pkey, word32* pkeySz, byte** cert, word32* certSz, 49 | WC_DerCertList** ca); 50 | 51 | WOLFSSL_LOCAL int wc_PKCS12_SetHeap(WC_PKCS12* pkcs12, void* heap); 52 | WOLFSSL_LOCAL void* wc_PKCS12_GetHeap(WC_PKCS12* pkcs12); 53 | 54 | 55 | #ifdef __cplusplus 56 | } /* extern "C" */ 57 | #endif 58 | 59 | #endif /* WOLF_CRYPT_PKCS12_H */ 60 | 61 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/rabbit.h: -------------------------------------------------------------------------------- 1 | /* rabbit.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_RABBIT_H 24 | #define WOLF_CRYPT_RABBIT_H 25 | 26 | #include 27 | 28 | #ifndef NO_RABBIT 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | 35 | enum { 36 | RABBIT_ENC_TYPE = 5 /* cipher unique type */ 37 | }; 38 | 39 | 40 | /* Rabbit Context */ 41 | typedef struct RabbitCtx { 42 | word32 x[8]; 43 | word32 c[8]; 44 | word32 carry; 45 | } RabbitCtx; 46 | 47 | 48 | /* Rabbit stream cipher */ 49 | typedef struct Rabbit { 50 | RabbitCtx masterCtx; 51 | RabbitCtx workCtx; 52 | #ifdef XSTREAM_ALIGN 53 | void* heap; /* heap hint, currently XMALLOC only used with aligning */ 54 | #endif 55 | } Rabbit; 56 | 57 | 58 | WOLFSSL_API int wc_RabbitProcess(Rabbit*, byte*, const byte*, word32); 59 | WOLFSSL_API int wc_RabbitSetKey(Rabbit*, const byte* key, const byte* iv); 60 | 61 | WOLFSSL_LOCAL int wc_Rabbit_SetHeap(Rabbit* ctx, void* heap); 62 | 63 | #ifdef __cplusplus 64 | } /* extern "C" */ 65 | #endif 66 | 67 | #endif /* NO_RABBIT */ 68 | #endif /* WOLF_CRYPT_RABBIT_H */ 69 | 70 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/ripemd.h: -------------------------------------------------------------------------------- 1 | /* ripemd.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_RIPEMD_H 24 | #define WOLF_CRYPT_RIPEMD_H 25 | 26 | #include 27 | 28 | #ifdef WOLFSSL_RIPEMD 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | 35 | /* in bytes */ 36 | enum { 37 | RIPEMD = 3, /* hash type unique */ 38 | RIPEMD_BLOCK_SIZE = 64, 39 | RIPEMD_DIGEST_SIZE = 20, 40 | RIPEMD_PAD_SIZE = 56 41 | }; 42 | 43 | 44 | /* RipeMd 160 digest */ 45 | typedef struct RipeMd { 46 | word32 buffLen; /* in bytes */ 47 | word32 loLen; /* length in bytes */ 48 | word32 hiLen; /* length in bytes */ 49 | word32 digest[RIPEMD_DIGEST_SIZE / sizeof(word32)]; 50 | word32 buffer[RIPEMD_BLOCK_SIZE / sizeof(word32)]; 51 | } RipeMd; 52 | 53 | 54 | WOLFSSL_API int wc_InitRipeMd(RipeMd*); 55 | WOLFSSL_API int wc_RipeMdUpdate(RipeMd*, const byte*, word32); 56 | WOLFSSL_API int wc_RipeMdFinal(RipeMd*, byte*); 57 | 58 | 59 | #ifdef __cplusplus 60 | } /* extern "C" */ 61 | #endif 62 | 63 | #endif /* WOLFSSL_RIPEMD */ 64 | #endif /* WOLF_CRYPT_RIPEMD_H */ 65 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/signature.h: -------------------------------------------------------------------------------- 1 | /* signature.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | #ifndef WOLF_CRYPT_SIGNATURE_H 24 | #define WOLF_CRYPT_SIGNATURE_H 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | enum wc_SignatureType { 35 | WC_SIGNATURE_TYPE_NONE = 0, 36 | WC_SIGNATURE_TYPE_ECC = 1, 37 | WC_SIGNATURE_TYPE_RSA = 2, 38 | WC_SIGNATURE_TYPE_RSA_W_ENC = 3, /* Adds DER header via wc_EncodeSignature */ 39 | }; 40 | 41 | WOLFSSL_API int wc_SignatureGetSize(enum wc_SignatureType sig_type, 42 | const void* key, word32 key_len); 43 | 44 | WOLFSSL_API int wc_SignatureVerify( 45 | enum wc_HashType hash_type, enum wc_SignatureType sig_type, 46 | const byte* data, word32 data_len, 47 | const byte* sig, word32 sig_len, 48 | const void* key, word32 key_len); 49 | 50 | WOLFSSL_API int wc_SignatureGenerate( 51 | enum wc_HashType hash_type, enum wc_SignatureType sig_type, 52 | const byte* data, word32 data_len, 53 | byte* sig, word32 *sig_len, 54 | const void* key, word32 key_len, 55 | WC_RNG* rng); 56 | 57 | #ifdef __cplusplus 58 | } /* extern "C" */ 59 | #endif 60 | 61 | #endif /* WOLF_CRYPT_SIGNATURE_H */ 62 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/wc_encrypt.h: -------------------------------------------------------------------------------- 1 | /* wc_encrypt.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | 23 | 24 | #ifndef WOLF_CRYPT_ENCRYPT_H 25 | #define WOLF_CRYPT_ENCRYPT_H 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #ifndef NO_AES 34 | WOLFSSL_API int wc_AesCbcEncryptWithKey(byte* out, const byte* in, word32 inSz, 35 | const byte* key, word32 keySz, 36 | const byte* iv); 37 | WOLFSSL_API int wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz, 38 | const byte* key, word32 keySz, 39 | const byte* iv); 40 | #endif /* !NO_AES */ 41 | 42 | 43 | #ifndef NO_DES3 44 | WOLFSSL_API int wc_Des_CbcDecryptWithKey(byte* out, 45 | const byte* in, word32 sz, 46 | const byte* key, const byte* iv); 47 | WOLFSSL_API int wc_Des_CbcEncryptWithKey(byte* out, 48 | const byte* in, word32 sz, 49 | const byte* key, const byte* iv); 50 | WOLFSSL_API int wc_Des3_CbcEncryptWithKey(byte* out, 51 | const byte* in, word32 sz, 52 | const byte* key, const byte* iv); 53 | WOLFSSL_API int wc_Des3_CbcDecryptWithKey(byte* out, 54 | const byte* in, word32 sz, 55 | const byte* key, const byte* iv); 56 | #endif /* !NO_DES3 */ 57 | 58 | #ifdef __cplusplus 59 | } /* extern "C" */ 60 | #endif 61 | 62 | #endif /* WOLF_CRYPT_ENCRYPT_H */ 63 | 64 | -------------------------------------------------------------------------------- /2_Lib/HomeKit-ESP8266/src/wolfssl/wolfcrypt/wolfmath.h: -------------------------------------------------------------------------------- 1 | /* wolfmath.h 2 | * 3 | * Copyright (C) 2006-2017 wolfSSL Inc. 4 | * 5 | * This file is part of wolfSSL. 6 | * 7 | * wolfSSL is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * wolfSSL is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 | */ 21 | 22 | #if defined(HAVE_WOLF_BIGINT) && !defined(WOLF_BIGINT_DEFINED) 23 | /* raw big integer */ 24 | typedef struct WC_BIGINT { 25 | byte* buf; 26 | word32 len; 27 | void* heap; 28 | } WC_BIGINT; 29 | 30 | #define WOLF_BIGINT_DEFINED 31 | #endif 32 | 33 | 34 | /* only define functions if mp_int has been declared */ 35 | #ifdef MP_INT_DEFINED 36 | 37 | #ifndef __WOLFMATH_H__ 38 | #define __WOLFMATH_H__ 39 | 40 | /* timing resistance array */ 41 | #if !defined(WC_NO_CACHE_RESISTANT) && \ 42 | ((defined(HAVE_ECC) && defined(ECC_TIMING_RESISTANT)) || \ 43 | (defined(USE_FAST_MATH) && defined(TFM_TIMING_RESISTANT))) 44 | 45 | extern const wolfssl_word wc_off_on_addr[2]; 46 | #endif 47 | 48 | /* common math functions */ 49 | int get_digit_count(mp_int* a); 50 | mp_digit get_digit(mp_int* a, int n); 51 | int get_rand_digit(WC_RNG* rng, mp_digit* d); 52 | int mp_rand(mp_int* a, int digits, WC_RNG* rng); 53 | 54 | 55 | #ifdef HAVE_WOLF_BIGINT 56 | void wc_bigint_init(WC_BIGINT* a); 57 | int wc_bigint_alloc(WC_BIGINT* a, word32 sz); 58 | int wc_bigint_from_unsigned_bin(WC_BIGINT* a, const byte* in, word32 inlen); 59 | int wc_bigint_to_unsigned_bin(WC_BIGINT* a, byte* out, word32* outlen); 60 | void wc_bigint_zero(WC_BIGINT* a); 61 | void wc_bigint_free(WC_BIGINT* a); 62 | 63 | int wc_mp_to_bigint(mp_int* src, WC_BIGINT* dst); 64 | int wc_bigint_to_mp(WC_BIGINT* src, mp_int* dst); 65 | #endif /* HAVE_WOLF_BIGINT */ 66 | 67 | #endif /* __WOLFMATH_H__ */ 68 | 69 | #endif /* MP_INT_DEFINED */ 70 | -------------------------------------------------------------------------------- /4_Docs/ESP-12E.PDF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycraft/homekit_fan/785c88693364ca0e70091744fb3954c50de9ec84/4_Docs/ESP-12E.PDF -------------------------------------------------------------------------------- /4_Docs/ESP-12F(ESP8266MOD).PDF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycraft/homekit_fan/785c88693364ca0e70091744fb3954c50de9ec84/4_Docs/ESP-12F(ESP8266MOD).PDF -------------------------------------------------------------------------------- /4_Docs/ESP8266 CH340原理图.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycraft/homekit_fan/785c88693364ca0e70091744fb3954c50de9ec84/4_Docs/ESP8266 CH340原理图.jpg -------------------------------------------------------------------------------- /4_Docs/HAP-Specification-Non-Commercial-Version.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycraft/homekit_fan/785c88693364ca0e70091744fb3954c50de9ec84/4_Docs/HAP-Specification-Non-Commercial-Version.pdf -------------------------------------------------------------------------------- /4_Docs/esp32.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycraft/homekit_fan/785c88693364ca0e70091744fb3954c50de9ec84/4_Docs/esp32.pdf -------------------------------------------------------------------------------- /4_Docs/esp32wroom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycraft/homekit_fan/785c88693364ca0e70091744fb3954c50de9ec84/4_Docs/esp32wroom.png -------------------------------------------------------------------------------- /4_Docs/esp8266引脚图.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lycraft/homekit_fan/785c88693364ca0e70091744fb3954c50de9ec84/4_Docs/esp8266引脚图.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## homekit_fan 2 | 3 | ESP8266方案基于[arduino-homekit-esp](https://gitee.com/mirrors_Mixiaoxiao/Arduino-HomeKit-ESP8266?_from=gitee_search)库 4 | 5 | #### 引脚对应 6 | 7 | | ESP_GPIO | ESP_Char | Use | BOOT | 8 | | -------- | -------- | -------------- | ---- | 9 | | GPIO16 | D0 | LED | 高 | 10 | | GPIO5 | D1 | 继电器(总开关) | | 11 | | GPIO4 | D2 | 继电器(低速) | | 12 | | GPIO0 | D3 | 按键总开关 | N低 | 13 | | GPIO2 | D4 | 按键低速 | 高 | 14 | | GPIO14 | D5 | 继电器(中速) | | 15 | | GPIO12 | D6 | 继电器(高速) | | 16 | | GPIO13 | D7 | 按键中速 | | 17 | | GPIO15 | D8 | 按键高速 | N高 | 18 | | ADC | A0 | | | 19 | 20 | #### 怎么使用? 21 | 22 | * 在vscode中搜索platformio插件并下载。 23 | * 打开firmware文件夹中的platformio工程 24 | * 根据WiFi信息修改wifi_info.h文件中的ssid和password 25 | * 编译下载进esp8266 26 | * 苹果手机的家庭APP右上角配对,配对码为11122333 27 | 28 | --- 29 | 30 | 完成esp32版本的开发会回来好好写文档的 --------------------------------------------------------------------------------