hmac_hal.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2020 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. #include "stdio.h"
  15. #include "hal/hmac_hal.h"
  16. #include "hal/hmac_ll.h"
  17. void hmac_hal_start(void)
  18. {
  19. hmac_ll_wait_idle();
  20. hmac_ll_start();
  21. }
  22. uint32_t hmac_hal_configure(hmac_hal_output_t config, uint32_t key_id)
  23. {
  24. hmac_ll_wait_idle();
  25. hmac_ll_config_output(config);
  26. hmac_ll_config_hw_key_id(key_id);
  27. hmac_ll_config_finish();
  28. hmac_ll_wait_idle();
  29. uint32_t conf_error = hmac_ll_config_error();
  30. if (conf_error) {
  31. hmac_ll_calc_finish();
  32. return 1;
  33. } else if (config != HMAC_OUTPUT_USER) {
  34. // In "downstream" mode, this will be the last hmac operation. Make sure HMAC is ready for
  35. // the other peripheral.
  36. hmac_ll_wait_idle();
  37. }
  38. return 0;
  39. }
  40. void hmac_hal_write_one_block_512(const void *block)
  41. {
  42. hmac_ll_wait_idle();
  43. hmac_ll_write_block_512(block);
  44. hmac_ll_wait_idle();
  45. hmac_ll_msg_one_block();
  46. }
  47. void hmac_hal_write_block_512(const void *block)
  48. {
  49. hmac_ll_wait_idle();
  50. hmac_ll_write_block_512(block);
  51. }
  52. void hmac_hal_next_block_padding(void)
  53. {
  54. hmac_ll_wait_idle();
  55. hmac_ll_msg_padding();
  56. }
  57. void hmac_hal_next_block_normal(void)
  58. {
  59. hmac_ll_wait_idle();
  60. hmac_ll_msg_continue();
  61. }
  62. void hmac_hal_read_result_256(void *result)
  63. {
  64. hmac_ll_wait_idle();
  65. hmac_ll_read_result_256(result);
  66. hmac_ll_calc_finish();
  67. }
  68. void hmac_hal_clean(void)
  69. {
  70. hmac_ll_wait_idle();
  71. hmac_ll_clean();
  72. }