psa_crypto_its.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /** \file psa_crypto_its.h
  2. * \brief Interface of trusted storage that crypto is built on.
  3. */
  4. /*
  5. * Copyright The Mbed TLS Contributors
  6. * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  7. */
  8. #ifndef PSA_CRYPTO_ITS_H
  9. #define PSA_CRYPTO_ITS_H
  10. #include <stddef.h>
  11. #include <stdint.h>
  12. #include <psa/crypto_types.h>
  13. #include <psa/crypto_values.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /** \brief Flags used when creating a data entry
  18. */
  19. typedef uint32_t psa_storage_create_flags_t;
  20. /** \brief A type for UIDs used for identifying data
  21. */
  22. typedef uint64_t psa_storage_uid_t;
  23. #define PSA_STORAGE_FLAG_NONE 0 /**< No flags to pass */
  24. #define PSA_STORAGE_FLAG_WRITE_ONCE (1 << 0) /**< The data associated with the uid will not be able to be modified or deleted. Intended to be used to set bits in `psa_storage_create_flags_t`*/
  25. /**
  26. * \brief A container for metadata associated with a specific uid
  27. */
  28. struct psa_storage_info_t {
  29. uint32_t size; /**< The size of the data associated with a uid **/
  30. psa_storage_create_flags_t flags; /**< The flags set when the uid was created **/
  31. };
  32. /** Flag indicating that \ref psa_storage_create and \ref psa_storage_set_extended are supported */
  33. #define PSA_STORAGE_SUPPORT_SET_EXTENDED (1 << 0)
  34. #define PSA_ITS_API_VERSION_MAJOR 1 /**< The major version number of the PSA ITS API. It will be incremented on significant updates that may include breaking changes */
  35. #define PSA_ITS_API_VERSION_MINOR 1 /**< The minor version number of the PSA ITS API. It will be incremented in small updates that are unlikely to include breaking changes */
  36. /**
  37. * \brief create a new or modify an existing uid/value pair
  38. *
  39. * \param[in] uid the identifier for the data
  40. * \param[in] data_length The size in bytes of the data in `p_data`
  41. * \param[in] p_data A buffer containing the data
  42. * \param[in] create_flags The flags that the data will be stored with
  43. *
  44. * \return A status indicating the success/failure of the operation
  45. *
  46. * \retval #PSA_SUCCESS The operation completed successfully
  47. * \retval #PSA_ERROR_NOT_PERMITTED The operation failed because the provided `uid` value was already created with PSA_STORAGE_FLAG_WRITE_ONCE
  48. * \retval #PSA_ERROR_NOT_SUPPORTED The operation failed because one or more of the flags provided in `create_flags` is not supported or is not valid
  49. * \retval #PSA_ERROR_INSUFFICIENT_STORAGE The operation failed because there was insufficient space on the storage medium
  50. * \retval #PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
  51. * \retval #PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_data`)
  52. * is invalid, for example is `NULL` or references memory the caller cannot access
  53. */
  54. psa_status_t psa_its_set(psa_storage_uid_t uid,
  55. uint32_t data_length,
  56. const void *p_data,
  57. psa_storage_create_flags_t create_flags);
  58. /**
  59. * \brief Retrieve the value associated with a provided uid
  60. *
  61. * \param[in] uid The uid value
  62. * \param[in] data_offset The starting offset of the data requested
  63. * \param[in] data_length the amount of data requested (and the minimum allocated size of the `p_data` buffer)
  64. * \param[out] p_data The buffer where the data will be placed upon successful completion
  65. * \param[out] p_data_length The amount of data returned in the p_data buffer
  66. *
  67. *
  68. * \return A status indicating the success/failure of the operation
  69. *
  70. * \retval #PSA_SUCCESS The operation completed successfully
  71. * \retval #PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided `uid` value was not found in the storage
  72. * \retval #PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
  73. * \retval #PSA_ERROR_DATA_CORRUPT The operation failed because stored data has been corrupted
  74. * \retval #PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_data`, `p_data_length`)
  75. * is invalid. For example is `NULL` or references memory the caller cannot access.
  76. * In addition, this can also happen if an invalid offset was provided.
  77. */
  78. psa_status_t psa_its_get(psa_storage_uid_t uid,
  79. uint32_t data_offset,
  80. uint32_t data_length,
  81. void *p_data,
  82. size_t *p_data_length);
  83. /**
  84. * \brief Retrieve the metadata about the provided uid
  85. *
  86. * \param[in] uid The uid value
  87. * \param[out] p_info A pointer to the `psa_storage_info_t` struct that will be populated with the metadata
  88. *
  89. * \return A status indicating the success/failure of the operation
  90. *
  91. * \retval #PSA_SUCCESS The operation completed successfully
  92. * \retval #PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided uid value was not found in the storage
  93. * \retval #PSA_ERROR_DATA_CORRUPT The operation failed because stored data has been corrupted
  94. * \retval #PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_info`)
  95. * is invalid, for example is `NULL` or references memory the caller cannot access
  96. */
  97. psa_status_t psa_its_get_info(psa_storage_uid_t uid,
  98. struct psa_storage_info_t *p_info);
  99. /**
  100. * \brief Remove the provided key and its associated data from the storage
  101. *
  102. * \param[in] uid The uid value
  103. *
  104. * \return A status indicating the success/failure of the operation
  105. *
  106. * \retval #PSA_SUCCESS The operation completed successfully
  107. * \retval #PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided key value was not found in the storage
  108. * \retval #PSA_ERROR_NOT_PERMITTED The operation failed because the provided key value was created with PSA_STORAGE_FLAG_WRITE_ONCE
  109. * \retval #PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
  110. */
  111. psa_status_t psa_its_remove(psa_storage_uid_t uid);
  112. #ifdef __cplusplus
  113. }
  114. #endif
  115. #endif /* PSA_CRYPTO_ITS_H */