You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.3KB

  1. /*
  2. * This file is part of the TREZOR project, https://trezor.io/
  3. *
  4. * Copyright (c) SatoshiLabs
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __NORCOW_H__
  20. #define __NORCOW_H__
  21. #include <stdint.h>
  22. #include "secbool.h"
  23. /*
  24. * Storage parameters
  25. */
  26. #include "norcow_config.h"
  27. /*
  28. * Initialize storage
  29. */
  30. void norcow_init(uint32_t *norcow_version);
  31. /*
  32. * Wipe the storage
  33. */
  34. void norcow_wipe(void);
  35. /*
  36. * Looks for the given key, returns status of the operation
  37. */
  38. secbool norcow_get(uint16_t key, const void **val, uint16_t *len);
  39. /*
  40. * Reads the next entry in the storage starting at offset. Returns secfalse if there is none.
  41. */
  42. secbool norcow_get_next(uint32_t *offset, uint16_t *key, const void **val, uint16_t *len);
  43. /*
  44. * Sets the given key, returns status of the operation. If NULL is passed
  45. * as val, then norcow_set allocates a new key of size len. The value should
  46. * then be written using norcow_update_bytes().
  47. */
  48. secbool norcow_set(uint16_t key, const void *val, uint16_t len);
  49. secbool norcow_set_ex(uint16_t key, const void *val, uint16_t len, secbool *found);
  50. /*
  51. * Deletes the given key, returns status of the operation.
  52. */
  53. secbool norcow_delete(uint16_t key);
  54. /*
  55. * Update a word in flash in the given key at the given offset.
  56. * Note that you can only change bits from 1 to 0.
  57. */
  58. secbool norcow_update_word(uint16_t key, uint16_t offset, uint32_t value);
  59. /*
  60. * Update the value of the given key starting at the given offset.
  61. * Note that you can only change bits from 1 to 0.
  62. */
  63. secbool norcow_update_bytes(const uint16_t key, const uint16_t offset, const uint8_t *data, const uint16_t len);
  64. /*
  65. * Complete storage version upgrade
  66. */
  67. secbool norcow_upgrade_finish(void);
  68. #endif