From 0f231c70d3ab31d7ced77d83479cfdf0eaa9c6f4 Mon Sep 17 00:00:00 2001 From: Flavio Santes Date: Wed, 16 Nov 2016 16:26:10 -0600 Subject: [PATCH] tests/tinycrypt: Fix dead code issue (2nd) This commit fixes the dead code issue reported by Coverity. Coverity-CID: 151977 Change-Id: Iaa31c032456f48e1af1d1c9d722f051ac5519ccf Signed-off-by: Flavio Santes --- tests/crypto/test_ecc_dsa/src/test_ecc_dsa.c | 11 ++++++----- 1 file changed, 6 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 4905ff825db..776fe4aad4b 100644 --- a/tests/crypto/test_ecc_dsa/src/test_ecc_dsa.c +++ b/tests/crypto/test_ecc_dsa/src/test_ecc_dsa.c @@ -334,6 +334,8 @@ int verify_vectors(TCSha256State_t hash, char **msg_vec, char **qx_vec, int rc = TC_FAIL; for (int i = 0; i < tests; i++) { + int hash_dwords; + str_to_scalar(pub.x, NUM_ECC_DIGITS, qx_vec[i]); str_to_scalar(pub.y, NUM_ECC_DIGITS, qy_vec[i]); str_to_scalar(r, NUM_ECC_DIGITS, r_vec[i]); @@ -358,11 +360,10 @@ int verify_vectors(TCSha256State_t hash, char **msg_vec, char **qx_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),