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