|
1 |
| -#include "hmac.h" |
2 |
| - |
3 |
| -struct hmac_data { |
4 |
| - bool fired; |
5 |
| - returncode_t ret; |
6 |
| -}; |
| 1 | +#include <libtock/defer.h> |
7 | 2 |
|
8 |
| -static struct hmac_data result = {.fired = false}; |
9 |
| - |
10 |
| -static void hmac_cb_hmac(returncode_t ret) { |
11 |
| - result.fired = true; |
12 |
| - result.ret = ret; |
13 |
| -} |
| 3 | +#include "hmac.h" |
14 | 4 |
|
15 | 5 | returncode_t libtocksync_hmac_simple(libtock_hmac_algorithm_t hmac_type,
|
16 | 6 | uint8_t* key_buffer, uint32_t key_length,
|
17 | 7 | uint8_t* input_buffer, uint32_t input_length,
|
18 | 8 | uint8_t* hmac_buffer, uint32_t hmac_length) {
|
19 | 9 | returncode_t ret;
|
20 | 10 |
|
21 |
| - result.fired = false; |
22 |
| - |
23 |
| - ret = libtock_hmac_simple(hmac_type, key_buffer, key_length, input_buffer, input_length, hmac_buffer, hmac_length, |
24 |
| - hmac_cb_hmac); |
| 11 | + ret = libtock_hmac_command_set_algorithm((uint32_t) hmac_type); |
25 | 12 | if (ret != RETURNCODE_SUCCESS) return ret;
|
26 | 13 |
|
27 |
| - // Wait for the callback. |
28 |
| - yield_for(&result.fired); |
29 |
| - if (result.ret != RETURNCODE_SUCCESS) return result.ret; |
| 14 | + ret = libtock_hmac_set_readonly_allow_key_buffer(key_buffer, key_length); |
| 15 | + if (ret != RETURNCODE_SUCCESS) return ret; |
| 16 | + defer { libtock_hmac_set_readonly_allow_key_buffer(NULL, 0); |
| 17 | + }; |
30 | 18 |
|
31 |
| - ret = libtock_hmac_set_readonly_allow_key_buffer(NULL, 0); |
| 19 | + ret = libtock_hmac_set_readonly_allow_data_buffer(input_buffer, input_length); |
32 | 20 | if (ret != RETURNCODE_SUCCESS) return ret;
|
| 21 | + defer { libtock_hmac_set_readonly_allow_data_buffer(NULL, 0); |
| 22 | + }; |
33 | 23 |
|
34 |
| - ret = libtock_hmac_set_readonly_allow_data_buffer(NULL, 0); |
| 24 | + ret = libtock_hmac_set_readwrite_allow_destination_buffer(hmac_buffer, hmac_length); |
35 | 25 | if (ret != RETURNCODE_SUCCESS) return ret;
|
| 26 | + defer { libtock_hmac_set_readwrite_allow_destination_buffer(NULL, 0); |
| 27 | + }; |
36 | 28 |
|
37 |
| - ret = libtock_hmac_set_readwrite_allow_destination_buffer(NULL, 0); |
| 29 | + ret = libtock_hmac_command_run(); |
38 | 30 | if (ret != RETURNCODE_SUCCESS) return ret;
|
39 | 31 |
|
40 |
| - return RETURNCODE_SUCCESS; |
| 32 | + // Wait for the operation. |
| 33 | + ret = libtocksync_hmac_yield_wait_for(); |
| 34 | + |
| 35 | + return ret; |
41 | 36 | }
|
0 commit comments