From c7a3efd496103dbe9be25e2e910a3970512c865b Mon Sep 17 00:00:00 2001 From: Michael Hamburg Date: Tue, 26 Jan 2016 11:41:47 -0800 Subject: [PATCH] fix typo in 32-bit code --- src/decaf.c | 4 +++- src/public_include/decaf/common.h | 2 +- test/test_decaf.cxx | 27 ++++++++++++++++----------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/decaf.c b/src/decaf.c index 04b7134..b9af62c 100644 --- a/src/decaf.c +++ b/src/decaf.c @@ -82,7 +82,9 @@ static INLINE decaf_bool_t mask_to_bool (mask_t m) { static INLINE mask_t bool_to_mask (decaf_bool_t m) { /* On most arches this will be optimized to a simple cast. */ mask_t ret = 0; - for (unsigned int i=0; i<1 || i> (i*8*sizeof(word_t))); } return ret; diff --git a/src/public_include/decaf/common.h b/src/public_include/decaf/common.h index d415c5d..d8db2b2 100644 --- a/src/public_include/decaf/common.h +++ b/src/public_include/decaf/common.h @@ -59,7 +59,7 @@ typedef uint32_t decaf_word_t; /**< Word size for internal computations */ typedef int32_t decaf_sword_t; /**< Signed word size for internal computations */ typedef uint32_t decaf_bool_t; /**< "Boolean" type, will be set to all-zero or all-one (i.e. -1u) */ typedef uint64_t decaf_dword_t; /**< Double-word size for internal computations */ -typedef uint64_t decaf_dsword_t; /**< Signed double-word size for internal computations */ +typedef int64_t decaf_dsword_t; /**< Signed double-word size for internal computations */ #endif /** DECAF_TRUE = -1 so that DECAF_TRUE & x = x */ diff --git a/test/test_decaf.cxx b/test/test_decaf.cxx index 34c9f8e..3a0a714 100644 --- a/test/test_decaf.cxx +++ b/test/test_decaf.cxx @@ -331,19 +331,24 @@ static void test_crypto() { SpongeRng rng(Block("test_decaf_crypto"),SpongeRng::DETERMINISTIC); for (int i=0; i priv1(rng), priv2(rng); - PublicKey pub1(priv1), pub2(priv2); - - SecureBuffer message = rng.read(i); - SecureBuffer sig(priv1.sign(message)); + try { + PrivateKey priv1(rng), priv2(rng); + PublicKey pub1(priv1), pub2(priv2); + + SecureBuffer message = rng.read(i); + SecureBuffer sig(priv1.sign(message)); - pub1.verify(message, sig); - - SecureBuffer s1(priv1.sharedSecret(pub2,32,true)); - SecureBuffer s2(priv2.sharedSecret(pub1,32,false)); - if (!memeq(s1,s2)) { + pub1.verify(message, sig); + + SecureBuffer s1(priv1.sharedSecret(pub2,32,true)); + SecureBuffer s2(priv2.sharedSecret(pub1,32,false)); + if (!memeq(s1,s2)) { + test.fail(); + printf(" Shared secrets disagree on iteration %d.\n",i); + } + } catch (CryptoException) { test.fail(); - printf(" Shared secrets disagree on iteration %d.\n",i); + printf(" Threw CryptoException.\n"); } } }