protocomm_security.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <esp_err.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /**
  12. * @brief Protocomm Security 1 parameters: Proof Of Possession
  13. */
  14. typedef struct protocomm_security1_params {
  15. /**
  16. * Pointer to buffer containing the proof of possession data
  17. */
  18. const uint8_t *data;
  19. /**
  20. * Length (in bytes) of the proof of possession data
  21. */
  22. uint16_t len;
  23. } protocomm_security1_params_t;
  24. typedef protocomm_security1_params_t protocomm_security_pop_t __attribute__((deprecated("Use protocomm_security1_params_t instead")));
  25. /**
  26. * @brief Protocomm Security 2 parameters: Salt and Verifier
  27. *
  28. */
  29. typedef struct protocomm_security2_params {
  30. /**
  31. * Pointer to the buffer containing the salt
  32. */
  33. const char *salt;
  34. /**
  35. * Length (in bytes) of the salt
  36. */
  37. uint16_t salt_len;
  38. /**
  39. * Pointer to the buffer containing the verifier
  40. */
  41. const char *verifier;
  42. /**
  43. * Length (in bytes) of the verifier
  44. */
  45. uint16_t verifier_len;
  46. } protocomm_security2_params_t;
  47. typedef void * protocomm_security_handle_t;
  48. /**
  49. * @brief Protocomm security object structure.
  50. *
  51. * The member functions are used for implementing secure
  52. * protocomm sessions.
  53. *
  54. * @note This structure should not have any dynamic
  55. * members to allow re-entrancy
  56. */
  57. typedef struct protocomm_security {
  58. /**
  59. * Unique version number of security implementation
  60. */
  61. int ver;
  62. /**
  63. * Function for initializing/allocating security
  64. * infrastructure
  65. */
  66. esp_err_t (*init)(protocomm_security_handle_t *handle);
  67. /**
  68. * Function for deallocating security infrastructure
  69. */
  70. esp_err_t (*cleanup)(protocomm_security_handle_t handle);
  71. /**
  72. * Starts new secure transport session with specified ID
  73. */
  74. esp_err_t (*new_transport_session)(protocomm_security_handle_t handle,
  75. uint32_t session_id);
  76. /**
  77. * Closes a secure transport session with specified ID
  78. */
  79. esp_err_t (*close_transport_session)(protocomm_security_handle_t handle,
  80. uint32_t session_id);
  81. /**
  82. * Handler function for authenticating connection
  83. * request and establishing secure session
  84. */
  85. esp_err_t (*security_req_handler)(protocomm_security_handle_t handle,
  86. const void *sec_params,
  87. uint32_t session_id,
  88. const uint8_t *inbuf, ssize_t inlen,
  89. uint8_t **outbuf, ssize_t *outlen,
  90. void *priv_data);
  91. /**
  92. * Function which implements the encryption algorithm
  93. */
  94. esp_err_t (*encrypt)(protocomm_security_handle_t handle,
  95. uint32_t session_id,
  96. const uint8_t *inbuf, ssize_t inlen,
  97. uint8_t **outbuf, ssize_t *outlen);
  98. /**
  99. * Function which implements the decryption algorithm
  100. */
  101. esp_err_t (*decrypt)(protocomm_security_handle_t handle,
  102. uint32_t session_id,
  103. const uint8_t *inbuf, ssize_t inlen,
  104. uint8_t **outbuf, ssize_t *outlen);
  105. } protocomm_security_t;
  106. #ifdef __cplusplus
  107. }
  108. #endif