protocomm_security.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. /**
  33. * @brief Protocomm security object structure.
  34. *
  35. * The member functions are used for implementing secure
  36. * protocomm sessions.
  37. *
  38. * @note This structure should not have any dynamic
  39. * members to allow re-entrancy
  40. */
  41. typedef struct protocomm_security {
  42. /**
  43. * Unique version number of security implementation
  44. */
  45. int ver;
  46. /**
  47. * Function for initializing/allocating security
  48. * infrastructure
  49. */
  50. esp_err_t (*init)();
  51. /**
  52. * Function for deallocating security infrastructure
  53. */
  54. esp_err_t (*cleanup)();
  55. /**
  56. * Starts new secure transport session with specified ID
  57. */
  58. esp_err_t (*new_transport_session)(uint32_t session_id);
  59. /**
  60. * Closes a secure transport session with specified ID
  61. */
  62. esp_err_t (*close_transport_session)(uint32_t session_id);
  63. /**
  64. * Handler function for authenticating connection
  65. * request and establishing secure session
  66. */
  67. esp_err_t (*security_req_handler)(const protocomm_security_pop_t *pop,
  68. uint32_t session_id,
  69. const uint8_t *inbuf, ssize_t inlen,
  70. uint8_t **outbuf, ssize_t *outlen,
  71. void *priv_data);
  72. /**
  73. * Function which implements the encryption algorithm
  74. */
  75. esp_err_t (*encrypt)(uint32_t session_id,
  76. const uint8_t *inbuf, ssize_t inlen,
  77. uint8_t *outbuf, ssize_t *outlen);
  78. /**
  79. * Function which implements the decryption algorithm
  80. */
  81. esp_err_t (*decrypt)(uint32_t session_id,
  82. const uint8_t *inbuf, ssize_t inlen,
  83. uint8_t *outbuf, ssize_t *outlen);
  84. } protocomm_security_t;
  85. #ifdef __cplusplus
  86. }
  87. #endif