From 7ac025ea149520a638e332f9fe8cb79d8dad6643 Mon Sep 17 00:00:00 2001 From: Flavio Santes Date: Wed, 16 Nov 2016 16:20:13 -0600 Subject: [PATCH] tests/tinycrypt: Fix dead code issue (1st) This commit fixes the dead code issue reported by Coverity. Coverity-CID: 151975 Change-Id: I449341d1f540abe149e8ad9197a64d52cd5722cd Signed-off-by: Flavio Santes --- tests/crypto/test_ecc_dsa/src/test_ecc_dsa.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/crypto/test_ecc_dsa/src/test_ecc_dsa.c b/tests/crypto/test_ecc_dsa/src/test_ecc_dsa.c index af75c011733..4905ff825db 100644 --- a/tests/crypto/test_ecc_dsa/src/test_ecc_dsa.c +++ b/tests/crypto/test_ecc_dsa/src/test_ecc_dsa.c @@ -68,6 +68,7 @@ int sign_vectors(TCSha256State_t hash, char **d_vec, char **k_vec, int rc = TC_FAIL; for (int i = 0; i < tests; i++) { + int hash_dwords; /* use keygen test to generate+validate pubkey */ rc = keygen_vectors(&point, d_vec+i, qx_vec+i, qy_vec+i, 1, @@ -99,11 +100,10 @@ int sign_vectors(TCSha256State_t hash, char **d_vec, char **k_vec, /* if digest larger than ECC scalar, drop the end * if digest smaller than ECC scalar, zero-pad front */ - int hash_dwords = TC_SHA256_DIGEST_SIZE / 4; - - if (hash_dwords > NUM_ECC_DIGITS) { - hash_dwords = NUM_ECC_DIGITS; - } + /* Note: here it is assumed that: + * NUM_ECC_DIGITS * 4 == TC_SHA256_DIGEST_SIZE + */ + hash_dwords = TC_SHA256_DIGEST_SIZE / 4; memset(dig32, 0, NUM_ECC_BYTES - 4 * hash_dwords); ecc_bytes2native(dig32+(NUM_ECC_DIGITS - hash_dwords), digest);