Przeglądaj źródła

fix typo in 32-bit code

master
Michael Hamburg 8 lat temu
rodzic
commit
c7a3efd496
3 zmienionych plików z 20 dodań i 13 usunięć
  1. +3
    -1
      src/decaf.c
  2. +1
    -1
      src/public_include/decaf/common.h
  3. +16
    -11
      test/test_decaf.cxx

+ 3
- 1
src/decaf.c Wyświetl plik

@@ -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<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)));
}
return ret;


+ 1
- 1
src/public_include/decaf/common.h Wyświetl plik

@@ -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 */


+ 16
- 11
test/test_decaf.cxx Wyświetl plik

@@ -331,19 +331,24 @@ static void test_crypto() {
SpongeRng rng(Block("test_decaf_crypto"),SpongeRng::DETERMINISTIC);

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();
printf(" Shared secrets disagree on iteration %d.\n",i);
printf(" Threw CryptoException.\n");
}
}
}


Ładowanie…
Anuluj
Zapisz