| @@ -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) { | static INLINE mask_t bool_to_mask (decaf_bool_t m) { | ||||
| /* On most arches this will be optimized to a simple cast. */ | /* On most arches this will be optimized to a simple cast. */ | ||||
| mask_t ret = 0; | mask_t ret = 0; | ||||
| for (unsigned int i=0; i<1 || i<sizeof(decaf_bool_t)/sizeof(mask_t); i++) { | |||||
| unsigned int limit = sizeof(decaf_bool_t)/sizeof(mask_t); | |||||
| if (limit < 1) limit = 1; | |||||
| for (unsigned int i=0; i<limit; i++) { | |||||
| ret |= ~ word_is_zero(m >> (i*8*sizeof(word_t))); | ret |= ~ word_is_zero(m >> (i*8*sizeof(word_t))); | ||||
| } | } | ||||
| return ret; | return ret; | ||||
| @@ -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 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 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_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 | #endif | ||||
| /** DECAF_TRUE = -1 so that DECAF_TRUE & x = x */ | /** DECAF_TRUE = -1 so that DECAF_TRUE & x = x */ | ||||
| @@ -331,19 +331,24 @@ static void test_crypto() { | |||||
| SpongeRng rng(Block("test_decaf_crypto"),SpongeRng::DETERMINISTIC); | SpongeRng rng(Block("test_decaf_crypto"),SpongeRng::DETERMINISTIC); | ||||
| for (int i=0; i<NTESTS && test.passing_now; i++) { | for (int i=0; i<NTESTS && test.passing_now; i++) { | ||||
| PrivateKey<Group> priv1(rng), priv2(rng); | |||||
| PublicKey<Group> pub1(priv1), pub2(priv2); | |||||
| SecureBuffer message = rng.read(i); | |||||
| SecureBuffer sig(priv1.sign(message)); | |||||
| try { | |||||
| PrivateKey<Group> priv1(rng), priv2(rng); | |||||
| PublicKey<Group> 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(); | test.fail(); | ||||
| printf(" Shared secrets disagree on iteration %d.\n",i); | |||||
| printf(" Threw CryptoException.\n"); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||