From db3b7563b296d90b0da55549c27ddfe387327f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Vejpustek?= Date: Mon, 1 Apr 2024 21:07:36 +0200 Subject: [PATCH] fix(crypto): imporve handling of return value --- crypto/zkp_bip340.c | 8 +++++--- crypto/zkp_context.c | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crypto/zkp_bip340.c b/crypto/zkp_bip340.c index fd87086a2..607cfb565 100644 --- a/crypto/zkp_bip340.c +++ b/crypto/zkp_bip340.c @@ -294,9 +294,11 @@ int zkp_bip340_tweak_private_key(const uint8_t *internal_private_key, } secp256k1_keypair keypair = {0}; - if (secp256k1_keypair_create(context_writable, &keypair, - internal_private_key) != 1) { - result = -1; + if (result == 0) { + if (secp256k1_keypair_create(context_writable, &keypair, + internal_private_key) != 1) { + result = -1; + } } if (context_writable) { diff --git a/crypto/zkp_context.c b/crypto/zkp_context.c index 964140f06..5d4a139df 100644 --- a/crypto/zkp_context.c +++ b/crypto/zkp_context.c @@ -71,7 +71,10 @@ int zkp_context_init(void) { return 1; } - secp256k1_context_writable_randomize(context); + if (secp256k1_context_writable_randomize(context) != 0) { + zkp_context_destroy(); + return 1; + } atomic_flag_clear(&locked);