protocomm_security.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2018 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <esp_err.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /**
  20. * @brief Proof Of Possession for authenticating a secure session
  21. */
  22. typedef struct protocomm_security_pop {
  23. /**
  24. * Pointer to buffer containing the proof of possession data
  25. */
  26. const uint8_t *data;
  27. /**
  28. * Length (in bytes) of the proof of possession data
  29. */
  30. uint16_t len;
  31. } protocomm_security_pop_t;
  32. typedef void * protocomm_security_handle_t;
  33. /**
  34. * @brief Protocomm security object structure.
  35. *
  36. * The member functions are used for implementing secure
  37. * protocomm sessions.
  38. *
  39. * @note This structure should not have any dynamic
  40. * members to allow re-entrancy
  41. */
  42. typedef struct protocomm_security {
  43. /**
  44. * Unique version number of security implementation
  45. */
  46. int ver;
  47. /**
  48. * Function for initializing/allocating security
  49. * infrastructure
  50. */
  51. esp_err_t (*init)(protocomm_security_handle_t *handle);
  52. /**
  53. * Function for deallocating security infrastructure
  54. */
  55. esp_err_t (*cleanup)(protocomm_security_handle_t handle);
  56. /**
  57. * Starts new secure transport session with specified ID
  58. */
  59. esp_err_t (*new_transport_session)(protocomm_security_handle_t handle,
  60. uint32_t session_id);
  61. /**
  62. * Closes a secure transport session with specified ID
  63. */
  64. esp_err_t (*close_transport_session)(protocomm_security_handle_t handle,
  65. uint32_t session_id);
  66. /**
  67. * Handler function for authenticating connection
  68. * request and establishing secure session
  69. */
  70. esp_err_t (*security_req_handler)(protocomm_security_handle_t handle,
  71. const protocomm_security_pop_t *pop,
  72. uint32_t session_id,
  73. const uint8_t *inbuf, ssize_t inlen,
  74. uint8_t **outbuf, ssize_t *outlen,
  75. void *priv_data);
  76. /**
  77. * Function which implements the encryption algorithm
  78. */
  79. esp_err_t (*encrypt)(protocomm_security_handle_t handle,
  80. uint32_t session_id,
  81. const uint8_t *inbuf, ssize_t inlen,
  82. uint8_t *outbuf, ssize_t *outlen);
  83. /**
  84. * Function which implements the decryption algorithm
  85. */
  86. esp_err_t (*decrypt)(protocomm_security_handle_t handle,
  87. uint32_t session_id,
  88. const uint8_t *inbuf, ssize_t inlen,
  89. uint8_t *outbuf, ssize_t *outlen);
  90. } protocomm_security_t;
  91. #ifdef __cplusplus
  92. }
  93. #endif