stm32_saes.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2022, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef STM32_SAES_H
  7. #define STM32_SAES_H
  8. #include <stdbool.h>
  9. #include <stddef.h>
  10. #include <stdint.h>
  11. #define DT_SAES_COMPAT "st,stm32-saes"
  12. struct stm32_saes_platdata {
  13. uintptr_t base;
  14. unsigned long clock_id;
  15. unsigned int reset_id;
  16. };
  17. enum stm32_saes_chaining_mode {
  18. STM32_SAES_MODE_ECB,
  19. STM32_SAES_MODE_CBC,
  20. STM32_SAES_MODE_CTR,
  21. STM32_SAES_MODE_GCM,
  22. STM32_SAES_MODE_CCM, /* Not use in TF-A */
  23. };
  24. enum stm32_saes_key_selection {
  25. STM32_SAES_KEY_SOFT,
  26. STM32_SAES_KEY_DHU, /* Derived HW unique key */
  27. STM32_SAES_KEY_BH, /* Boot HW key */
  28. STM32_SAES_KEY_BHU_XOR_BH, /* XOR of DHUK and BHK */
  29. STM32_SAES_KEY_WRAPPED
  30. };
  31. struct stm32_saes_context {
  32. uintptr_t base;
  33. uint32_t cr;
  34. uint32_t assoc_len;
  35. uint32_t load_len;
  36. uint32_t key[8]; /* In HW byte order */
  37. uint32_t iv[4]; /* In HW byte order */
  38. };
  39. int stm32_saes_driver_init(void);
  40. int stm32_saes_init(struct stm32_saes_context *ctx, bool is_decrypt,
  41. enum stm32_saes_chaining_mode ch_mode, enum stm32_saes_key_selection key_select,
  42. const void *key, size_t key_len, const void *iv, size_t iv_len);
  43. int stm32_saes_update(struct stm32_saes_context *ctx, bool last_block,
  44. uint8_t *data_in, uint8_t *data_out, size_t data_len);
  45. int stm32_saes_update_assodata(struct stm32_saes_context *ctx, bool last_block,
  46. uint8_t *data, size_t data_len);
  47. int stm32_saes_update_load(struct stm32_saes_context *ctx, bool last_block,
  48. uint8_t *data_in, uint8_t *data_out, size_t data_len);
  49. int stm32_saes_final(struct stm32_saes_context *ctx, uint8_t *tag, size_t tag_len);
  50. #endif