protocomm_security.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /**
  17. * @brief Proof Of Possession for authenticating a secure session
  18. */
  19. typedef struct protocomm_security_pop {
  20. /**
  21. * Pointer to buffer containing the proof of possession data
  22. */
  23. const uint8_t *data;
  24. /**
  25. * Length (in bytes) of the proof of possession data
  26. */
  27. uint16_t len;
  28. } protocomm_security_pop_t;
  29. /**
  30. * @brief Protocomm security object structure.
  31. *
  32. * The member functions are used for implementing secure
  33. * protocomm sessions.
  34. *
  35. * @note This structure should not have any dynamic
  36. * members to allow re-entrancy
  37. */
  38. typedef struct protocomm_security {
  39. /**
  40. * Unique version number of security implmentation
  41. */
  42. int ver;
  43. /**
  44. * Function for initialising/allocating security
  45. * infrastructure
  46. */
  47. esp_err_t (*init)();
  48. /**
  49. * Function for deallocating security infrastructure
  50. */
  51. esp_err_t (*cleanup)();
  52. /**
  53. * Starts new secure transport session with specified ID
  54. */
  55. esp_err_t (*new_transport_session)(uint32_t session_id);
  56. /**
  57. * Closes a secure transport session with specified ID
  58. */
  59. esp_err_t (*close_transport_session)(uint32_t session_id);
  60. /**
  61. * Handler function for authenticating connection
  62. * request and establishing secure session
  63. */
  64. esp_err_t (*security_req_handler)(const protocomm_security_pop_t *pop,
  65. uint32_t session_id,
  66. const uint8_t *inbuf, ssize_t inlen,
  67. uint8_t **outbuf, ssize_t *outlen,
  68. void *priv_data);
  69. /**
  70. * Function which implements the encryption algorithm
  71. */
  72. esp_err_t (*encrypt)(uint32_t session_id,
  73. const uint8_t *inbuf, ssize_t inlen,
  74. uint8_t *outbuf, ssize_t *outlen);
  75. /**
  76. * Function which implements the decryption algorithm
  77. */
  78. esp_err_t (*decrypt)(uint32_t session_id,
  79. const uint8_t *inbuf, ssize_t inlen,
  80. uint8_t *outbuf, ssize_t *outlen);
  81. } protocomm_security_t;