ds_hal.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2015-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 "hal/systimer_hal.h"
  15. #include "hal/ds_hal.h"
  16. #include "hal/ds_ll.h"
  17. void ds_hal_start(void)
  18. {
  19. ds_ll_start();
  20. }
  21. void ds_hal_finish(void)
  22. {
  23. ds_ll_finish();
  24. }
  25. ds_key_check_t ds_hal_check_decryption_key(void)
  26. {
  27. uint64_t start_time = systimer_hal_get_time(SYSTIMER_COUNTER_0);
  28. while (ds_ll_busy() != 0) {
  29. if ((systimer_hal_get_time(SYSTIMER_COUNTER_0) - start_time) > SOC_DS_KEY_CHECK_MAX_WAIT_US) {
  30. return ds_ll_key_error_source();
  31. }
  32. }
  33. return DS_KEY_INPUT_OK;
  34. }
  35. void ds_hal_configure_iv(const uint32_t *iv)
  36. {
  37. ds_ll_configure_iv(iv);
  38. }
  39. void ds_hal_write_message(const uint8_t *msg, size_t size)
  40. {
  41. ds_ll_write_message(msg, size);
  42. }
  43. void ds_hal_write_private_key_params(const uint8_t *key_params)
  44. {
  45. ds_ll_write_private_key_params(key_params);
  46. }
  47. void ds_hal_start_sign(void)
  48. {
  49. ds_ll_start_sign();
  50. }
  51. bool ds_hal_busy(void)
  52. {
  53. return ds_ll_busy();
  54. }
  55. ds_signature_check_t ds_hal_read_result(uint8_t *result, size_t size)
  56. {
  57. ds_signature_check_t check_result = ds_ll_check_signature();
  58. if (check_result == DS_SIGNATURE_OK || check_result == DS_SIGNATURE_PADDING_FAIL) {
  59. ds_ll_read_result(result, size);
  60. }
  61. return check_result;
  62. }