Skip to content

Commit 7b50eb7

Browse files
author
Andrzej Kurek
committed
Change init and deinit macro to a function
1 parent 19724e9 commit 7b50eb7

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

atecc608a_utils.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,30 @@ psa_status_t atecc608a_get_serial_number(uint8_t* buffer,
3434
return PSA_ERROR_BUFFER_TOO_SMALL;
3535
}
3636

37-
ATCAB_INIT();
37+
ASSERT_SUCCESS_PSA(atecc608a_init());
3838

3939
ASSERT_SUCCESS(atcab_read_serial_number(buffer));
4040
*buffer_length = ATCA_SERIAL_NUM_SIZE;
4141

4242
exit:
43-
ATCAB_DEINIT();
43+
atecc608a_deinit();
4444
return status;
4545
}
4646

4747
psa_status_t atecc608a_check_config_locked()
4848
{
4949
bool config_locked;
5050
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
51-
52-
ATCAB_INIT();
51+
52+
ASSERT_SUCCESS_PSA(atecc608a_init());
5353

5454
ASSERT_SUCCESS(atcab_is_locked(LOCK_ZONE_CONFIG, &config_locked));
5555

5656
exit:
57-
ATCAB_DEINIT();
57+
atecc608a_deinit();
5858
if (status == PSA_SUCCESS)
5959
{
6060
status = config_locked? PSA_SUCCESS : PSA_ERROR_HARDWARE_FAILURE;
6161
}
62-
return status;
63-
}
62+
return status;
63+
}

atecc608a_utils.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* See the License for the specific language governing permissions and
2020
* limitations under the License.
2121
*/
22-
22+
2323
#ifndef ATECC608A_UTILS_H
2424
#define ATECC608A_UTILS_H
2525

@@ -58,6 +58,7 @@
5858

5959
psa_status_t atecc608a_get_serial_number(uint8_t* buffer, size_t buffer_size,
6060
size_t *buffer_length);
61+
6162
psa_status_t atecc608a_check_config_locked();
6263

63-
#endif /* ATECC608A_SE_H */
64+
#endif /* ATECC608A_SE_H */

main.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ psa_status_t atecc608a_hash_sha256(const uint8_t *input, size_t input_size,
5555
atcab_printbin_label("Input: ", (uint8_t *)input, input_size);
5656
atcab_printbin_label("Expected Hash: ", (uint8_t *)expected_hash,
5757
expected_hash_size);
58-
ATCAB_INIT();
58+
ASSERT_SUCCESS_PSA(atecc608a_init());
5959
ASSERT_SUCCESS(atcab_hw_sha2_256(input, input_size, actual_hash));
6060
atcab_printbin_label("Actual Hash: ", actual_hash, ATCA_SHA_DIGEST_SIZE);
6161
ASSERT_STATUS(memcmp(actual_hash, expected_hash, sizeof(actual_hash)), 0,
6262
PSA_ERROR_HARDWARE_FAILURE);
6363
printf("Success!\n\n");
6464

6565
exit:
66-
ATCAB_DEINIT();
66+
atecc608a_deinit();
6767
return status;
6868
}
6969

@@ -72,7 +72,7 @@ psa_status_t atecc608a_print_locked_zones()
7272
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
7373
bool locked;
7474
printf("--- Device locks information ---\n");
75-
ATCAB_INIT();
75+
ASSERT_SUCCESS_PSA(atecc608a_init());
7676
ASSERT_SUCCESS(atcab_is_locked(LOCK_ZONE_CONFIG, &locked));
7777
printf(" - Config locked: %d\n", locked);
7878
ASSERT_SUCCESS(atcab_is_locked(LOCK_ZONE_DATA, &locked));
@@ -83,9 +83,9 @@ psa_status_t atecc608a_print_locked_zones()
8383
printf(" - Slot %d locked: %d\n", i, locked);
8484
}
8585
printf("--------------------------------\n");
86-
86+
8787
exit:
88-
ATCAB_DEINIT();
88+
atecc608a_deinit();
8989
return status;
9090
}
9191

@@ -150,12 +150,12 @@ int main(void)
150150
/* Verify that the device has a locked config before doing anything */
151151
ASSERT_SUCCESS_PSA(atecc608a_check_config_locked());
152152

153-
ASSERT_SUCCESS_PSA((*atecc608a_drv_info.p_key_management->p_export)
154-
(atecc608a_key_slot_device, pubkey, sizeof(pubkey),
153+
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_key_management->p_export(
154+
atecc608a_key_slot_device, pubkey, sizeof(pubkey),
155155
&pubkey_len));
156156

157-
ASSERT_SUCCESS_PSA((*atecc608a_drv_info.p_asym->p_sign)
158-
(atecc608a_key_slot_device, alg, hash, sizeof(hash),
157+
ASSERT_SUCCESS_PSA(atecc608a_drv_info.p_asym->p_sign(
158+
atecc608a_key_slot_device, alg, hash, sizeof(hash),
159159
signature, sizeof(signature), &signature_length));
160160

161161
/*

0 commit comments

Comments
 (0)