From a2a5d119b94a6113655df026cfc4e4b41f29c008 Mon Sep 17 00:00:00 2001 From: Gabriel Valcazar Date: Fri, 16 Feb 2018 17:40:31 +0100 Subject: [PATCH] cryptochip: check if the device is configured before continuing RNG and encryption operations won't work unless the cryptochip is configured for TLS operations. Print a warning if the chip hasn't been configured yet. https://jira.digi.com/browse/DEL-5710 Signed-off-by: Gabriel Valcazar --- cryptochip-get-random/main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cryptochip-get-random/main.c b/cryptochip-get-random/main.c index c3e30c9..52b2857 100644 --- a/cryptochip-get-random/main.c +++ b/cryptochip-get-random/main.c @@ -22,9 +22,19 @@ int main(void) { uint8_t random_number[32]; + bool is_locked = false; atcab_init(&cfg_ateccx08a_i2c_default); + /* Check if config zone is locked */ + atcab_is_locked(LOCK_ZONE_CONFIG, &is_locked); + if (!is_locked) { + printf("**WARNING**: the cryptochip is currently not configured. Run " + "ecc-test-main at least once to be able to run this example.\n"); + atcab_release(); + return 1; + } + while (true) { atcab_random(random_number); write(STDOUT_FILENO, random_number, sizeof(random_number));