Skip to content

Commit 486bad7

Browse files
author
Andrzej Kurek
committed
Change init and deinit macro to a function
1 parent 51f2ba2 commit 486bad7

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

atecc608a_se.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
#define ASSERT_SUCCESS(expression) ASSERT_STATUS(expression, ATCA_SUCCESS, \
5454
atecc608a_to_psa_error(ASSERT_result))
5555

56+
/** Does the same as the macro above, but without the error translation and for
57+
* the PSA return code - PSA_SUCCESS.*/
58+
#define ASSERT_SUCCESS_PSA(expression) ASSERT_STATUS(expression, PSA_SUCCESS, \
59+
ASSERT_result)
60+
5661
ATCAIfaceCfg atca_iface_config = {
5762
.iface_type = ATCA_I2C_IFACE,
5863
.devtype = ATECC608A,
@@ -115,6 +120,16 @@ psa_status_t atecc608a_to_psa_error(ATCA_STATUS ret)
115120
}
116121
}
117122

123+
psa_status_t atecc608a_init()
124+
{
125+
return atecc608a_to_psa_error(atcab_init(&atca_iface_config));
126+
}
127+
128+
psa_status_t atecc608a_deinit()
129+
{
130+
return atecc608a_to_psa_error(atcab_release());
131+
}
132+
118133
static psa_status_t atecc608a_export_public_key(psa_key_slot_number_t key,
119134
uint8_t *p_data, size_t data_size,
120135
size_t *p_data_length)
@@ -128,9 +143,9 @@ static psa_status_t atecc608a_export_public_key(psa_key_slot_number_t key,
128143
return PSA_ERROR_BUFFER_TOO_SMALL;
129144
}
130145

131-
ATCAB_INIT();
146+
ASSERT_SUCCESS_PSA(atecc608a_init());
132147

133-
/* atcab_get_pubkey returns concatenated x and y values, and the desired
148+
/* atcab_get_pubkey returns concatenated x and y values, and the desired
134149
format is 0x04 + x + y. We start at &p_data[1] and add a 0x04 at p_data[0]. */
135150
ASSERT_SUCCESS(atcab_get_pubkey(slot, &p_data[1]));
136151

@@ -143,7 +158,7 @@ static psa_status_t atecc608a_export_public_key(psa_key_slot_number_t key,
143158
#endif
144159

145160
exit:
146-
ATCAB_DEINIT();
161+
atecc608a_deinit();
147162
return status;
148163
}
149164

@@ -175,12 +190,12 @@ static psa_status_t atecc608a_asymmetric_sign(psa_key_slot_number_t key_slot,
175190
return PSA_ERROR_BUFFER_TOO_SMALL;
176191
}
177192

178-
ATCAB_INIT();
193+
ASSERT_SUCCESS_PSA(atecc608a_init());
179194

180195
/* Signature will be returned here. Format is R and S integers in
181196
* big-endian format. 64 bytes for P256 curve. */
182197
ASSERT_SUCCESS(atcab_sign(key_id, p_hash, p_signature));
183-
198+
184199
*p_signature_length = ATCA_SIG_SIZE;
185200

186201
#ifdef DEBUG_PRINT
@@ -189,7 +204,7 @@ static psa_status_t atecc608a_asymmetric_sign(psa_key_slot_number_t key_slot,
189204
#endif
190205

191206
exit:
192-
ATCAB_DEINIT();
207+
atecc608a_deinit();
193208
return status;
194209
}
195210

@@ -214,7 +229,7 @@ static psa_drv_se_key_management_t atecc608a_key_management =
214229
};
215230

216231
psa_drv_se_info_t atecc608a_drv_info =
217-
{
232+
{
218233
.lifetime = PSA_ATECC608A_LIFETIME,
219234
.p_key_management = &atecc608a_key_management,
220235
.p_mac = 0,

atecc608a_se.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,11 @@
2727
#include "atca_basic.h"
2828

2929
extern psa_drv_se_info_t atecc608a_drv_info;
30-
extern ATCAIfaceCfg atca_iface_config;
3130

3231
psa_status_t atecc608a_to_psa_error(ATCA_STATUS ret);
3332

34-
#define ATCAB_INIT() \
35-
do \
36-
{ \
37-
if (atcab_init(&atca_iface_config) != ATCA_SUCCESS) \
38-
{ \
39-
status = PSA_ERROR_HARDWARE_FAILURE; \
40-
goto exit; \
41-
} \
42-
} while(0)
43-
44-
/** `atcab_release()` might return `ATCA_BAD_PARAM` if there is no global device
45-
* initialized via `atcab_init()`. HAL might return an error if an i2c device
46-
* cannot be released, but in current implementations it always returns
47-
* `ATCA_SUCCESS` - therefore we are ignoring the return code. */
48-
#define ATCAB_DEINIT() \
49-
do \
50-
{ \
51-
atcab_release(); \
52-
} while(0)
53-
54-
33+
psa_status_t atecc608a_init();
34+
35+
psa_status_t atecc608a_deinit();
36+
5537
#endif /* ATECC608A_SE_H */

0 commit comments

Comments
 (0)