Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MyCryptoESP32.cpp 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * The MySensors Arduino library handles the wireless radio link and protocol
  3. * between your home built sensors/actuators and HA controller of choice.
  4. * The sensors forms a self healing radio network with optional repeaters. Each
  5. * repeater and gateway builds a routing tables in EEPROM which keeps track of the
  6. * network topology allowing messages to be routed to nodes.
  7. *
  8. * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
  9. * Copyright (C) 2013-2018 Sensnology AB
  10. * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
  11. *
  12. * Documentation: http://www.mysensors.org
  13. * Support Forum: http://forum.mysensors.org
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * version 2 as published by the Free Software Foundation.
  18. */
  19. #include "MyCryptoESP32.h"
  20. // ESP32 SHA256
  21. void SHA256(uint8_t *dest, const uint8_t *data, size_t dataLength)
  22. {
  23. mbedtls_md_context_t ctx;
  24. mbedtls_md_init(&ctx);
  25. mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 0);
  26. mbedtls_md_starts(&ctx);
  27. mbedtls_md_update(&ctx, (const unsigned char *)data, dataLength);
  28. mbedtls_md_finish(&ctx, dest);
  29. }
  30. // ESP32 SHA256HMAC
  31. void SHA256HMAC(uint8_t *dest, const uint8_t *key, size_t keyLength, const uint8_t *data,
  32. size_t dataLength)
  33. {
  34. mbedtls_md_context_t ctx;
  35. mbedtls_md_init(&ctx);
  36. mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 1);
  37. mbedtls_md_starts(&ctx);
  38. mbedtls_md_hmac_starts(&ctx, (const unsigned char *)key, keyLength);
  39. mbedtls_md_hmac_update(&ctx, (const unsigned char *)data, dataLength);
  40. mbedtls_md_hmac_finish(&ctx, dest);
  41. }
  42. /* not tested yet
  43. // ESP32 AES128 CBC
  44. esp_aes_context aes_ctx;
  45. void AES128CBCInit(const uint8_t *key)
  46. {
  47. esp_aes_init(&aes_ctx);
  48. (void)esp_aes_setkey(&aes_ctx, key, 128);
  49. }
  50. void AES128CBCEncrypt(uint8_t *dest, const uint8_t *data, size_t dataLength)
  51. {
  52. uint8_t iv[16] = { 0 };
  53. esp_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_ENCRYPT, dataLength, iv, (const unsigned char *)data, (unsigned char *)dest);
  54. }
  55. void AES128CBCDecrypt(uint8_t *dest, const uint8_t *data, size_t dataLength)
  56. {
  57. uint8_t iv[16] = { 0 };
  58. esp_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_DECRYPT, dataLength, iv, (const unsigned char *)data, (unsigned char *)dest);
  59. }
  60. void AES128CBCFree(void)
  61. {
  62. esp_aes_free(&aes_ctx);
  63. }
  64. */