Commit cb985e53 authored by johan's avatar johan

More compilation warnings fix on windows

parent 1de281e2
......@@ -88,11 +88,11 @@ void gf_mulw_unsigned (gf_s *__restrict__ cs, const gf as, uint32_t b) {
accum0 += accum8 + c[8];
c[8] = accum0 & mask;
c[9] += accum0 >> 28;
c[9] += (uint32_t)(accum0 >> 28);
accum8 += c[0];
c[0] = accum8 & mask;
c[1] += accum8 >> 28;
c[1] += (uint32_t)(accum8 >> 28);
}
void gf_sqr (gf_s *__restrict__ cs, const gf as) {
......
......@@ -1273,7 +1273,7 @@ decaf_error_t decaf_x$(gf_shortname) (
else if (t == X_PRIVATE_BITS-1) sb = -1;
mask_t k_t = (sb>>(t%8)) & 1;
k_t = -k_t; /* set to all 0s or all 1s */
k_t = k_t?DECAF_MASK_ALL_SET:DECAF_MASK_ALL_UNSET; /* set to all 0s or all 1s */
swap ^= k_t;
gf_cond_swap(x2,x3,swap);
......@@ -1394,7 +1394,7 @@ void decaf_x$(gf_shortname)_derive_public_key (
memcpy(scalar2,scalar,sizeof(scalar2));
scalar2[0] &= -(uint8_t)COFACTOR;
scalar2[X_PRIVATE_BYTES-1] &= ~(-1u<<((X_PRIVATE_BITS+7)%8));
scalar2[X_PRIVATE_BYTES-1] &= ~(0xFF<<((X_PRIVATE_BITS+7)%8));
scalar2[X_PRIVATE_BYTES-1] |= 1<<((X_PRIVATE_BITS+7)%8);
scalar_t the_scalar;
......
......@@ -109,13 +109,13 @@ API_NS(invert_elligator_nonuniform) (
uint32_t hint_
) {
mask_t hint = hint_;
mask_t sgn_s = -(hint & 1),
sgn_altx = -(hint>>1 & 1),
sgn_r0 = -(hint>>2 & 1),
mask_t sgn_s = ((hint & 1)?DECAF_MASK_ALL_SET:DECAF_MASK_ALL_UNSET),
sgn_altx = ((hint>>1 & 1)?DECAF_MASK_ALL_SET:DECAF_MASK_ALL_UNSET),
sgn_r0 = ((hint>>2 & 1)?DECAF_MASK_ALL_SET:DECAF_MASK_ALL_UNSET),
/* FUTURE MAGIC: eventually if there's a curve which needs sgn_ed_T but not sgn_r0,
* change this mask extraction.
*/
sgn_ed_T = -(hint>>3 & 1);
sgn_ed_T = ((hint>>3 & 1)?DECAF_MASK_ALL_SET:DECAF_MASK_ALL_UNSET);
gf a,b,c;
API_NS(deisogenize)(a,b,c,p,sgn_s,sgn_altx,sgn_ed_T);
......
......@@ -37,15 +37,15 @@ static DECAF_NOINLINE void sc_subx(
unsigned int i;
for (i=0; i<SCALAR_LIMBS; i++) {
chain = (chain + accum[i]) - sub->limb[i];
out->limb[i] = chain;
out->limb[i] = (decaf_word_t)chain;
chain >>= WBITS;
}
decaf_word_t borrow = chain+extra; /* = 0 or -1 */
decaf_word_t borrow = (decaf_word_t)chain+extra; /* = 0 or -1 */
chain = 0;
for (i=0; i<SCALAR_LIMBS; i++) {
chain = (chain + out->limb[i]) + (p->limb[i] & borrow);
out->limb[i] = chain;
out->limb[i] = (decaf_word_t)chain;
chain >>= WBITS;
}
}
......@@ -66,22 +66,22 @@ static DECAF_NOINLINE void sc_montmul (
decaf_dword_t chain = 0;
for (j=0; j<SCALAR_LIMBS; j++) {
chain += ((decaf_dword_t)mand)*mier[j] + accum[j];
accum[j] = chain;
accum[j] = (decaf_word_t)chain;
chain >>= WBITS;
}
accum[j] = chain;
accum[j] = (decaf_word_t)chain;
mand = accum[0] * MONTGOMERY_FACTOR;
chain = 0;
mier = sc_p->limb;
for (j=0; j<SCALAR_LIMBS; j++) {
chain += (decaf_dword_t)mand*mier[j] + accum[j];
if (j) accum[j-1] = chain;
if (j) accum[j-1] = (decaf_word_t)chain;
chain >>= WBITS;
}
chain += accum[j];
chain += hi_carry;
accum[j-1] = chain;
accum[j-1] = (decaf_word_t)chain;
hi_carry = chain >> WBITS;
}
......@@ -179,10 +179,10 @@ void API_NS(scalar_add) (
unsigned int i;
for (i=0; i<SCALAR_LIMBS; i++) {
chain = (chain + a->limb[i]) + b->limb[i];
out->limb[i] = chain;
out->limb[i] = (decaf_word_t)chain;
chain >>= WBITS;
}
sc_subx(out, out->limb, sc_p, sc_p, chain);
sc_subx(out, out->limb, sc_p, sc_p, (decaf_word_t)chain);
}
void
......@@ -193,7 +193,7 @@ API_NS(scalar_set_unsigned) (
memset(out,0,sizeof(scalar_t));
unsigned int i = 0;
for (; i<sizeof(uint64_t)/sizeof(decaf_word_t); i++) {
out->limb[i] = w;
out->limb[i] = (decaf_word_t)w;
#if DECAF_WORD_BITS < 64
w >>= 8*sizeof(decaf_word_t);
#endif
......@@ -242,7 +242,7 @@ decaf_error_t API_NS(scalar_decode)(
API_NS(scalar_mul)(s,s,API_NS(scalar_one)); /* ham-handed reduce */
return decaf_succeed_if(~word_is_zero(accum));
return decaf_succeed_if(~word_is_zero((decaf_word_t)accum));
}
void API_NS(scalar_destroy) (
......@@ -314,17 +314,17 @@ void API_NS(scalar_halve) (
scalar_t out,
const scalar_t a
) {
decaf_word_t mask = -(a->limb[0] & 1);
decaf_word_t mask = (a->limb[0] & 1)?DECAF_WORD_ALL_SET:DECAF_WORD_ALL_UNSET;
decaf_dword_t chain = 0;
unsigned int i;
for (i=0; i<SCALAR_LIMBS; i++) {
chain = (chain + a->limb[i]) + (sc_p->limb[i] & mask);
out->limb[i] = chain;
out->limb[i] = (decaf_word_t)chain;
chain >>= DECAF_WORD_BITS;
}
for (i=0; i<SCALAR_LIMBS-1; i++) {
out->limb[i] = out->limb[i]>>1 | out->limb[i+1]<<(WBITS-1);
}
out->limb[i] = out->limb[i]>>1 | chain<<(WBITS-1);
out->limb[i] = out->limb[i]>>1 | (decaf_word_t)(chain<<(WBITS-1));
}
......@@ -95,11 +95,20 @@ typedef int64_t decaf_dsword_t; /**< Signed double-word size for internal co
/* MSCV compiler doesn't like the trick to have -1 assigned to an unsigned int to
* set it to all ones, so do it openly */
/** DECAF_TRUE = all ones so that DECAF_TRUE & x = x */
#if DECAF_WORD_BITS == 64
/** DECAF_TRUE = all ones so that DECAF_TRUE & x = x */
static const decaf_bool_t DECAF_TRUE = (decaf_bool_t)0xFFFFFFFFFFFFFFFF;
/** DECAF_WORD_ALL_SET : all ones */
static const decaf_word_t DECAF_WORD_ALL_SET = (decaf_word_t)0xFFFFFFFFFFFFFFFF;
/** DECAF_WORD_ALL_UNSET : all zeros */
static const decaf_word_t DECAF_WORD_ALL_UNSET = (decaf_word_t)0x0;
#elif DECAF_WORD_BITS == 32 /**< The number of bits in a word */
/** DECAF_TRUE = all ones so that DECAF_TRUE & x = x */
static const decaf_bool_t DECAF_TRUE = (decaf_bool_t)0xFFFFFFFF;
/** DECAF_WORD_ALL_SET : all ones */
static const decaf_word_t DECAF_WORD_ALL_SET = (decaf_word_t)0xFFFFFFFF;
/** DECAF_WORD_ALL_UNSET : all zeros */
static const decaf_word_t DECAF_WORD_ALL_UNSET = (decaf_word_t)0x0;
#else
#error "Only supporting DECAF_WORD_BITS = 32 or 64 for now"
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment