diff --git a/src/encauth/siv/siv.c b/src/encauth/siv/siv.c index bd6d5b45b..4de52d90b 100644 --- a/src/encauth/siv/siv.c +++ b/src/encauth/siv/siv.c @@ -161,7 +161,7 @@ static LTC_INLINE int s_siv_S2V_T(siv_omac_ctx_t *ctx, } else { s_siv_dbl(D); XMEMSET(&T, 0, sizeof(T)); - XMEMCPY(&T, in, inlen); + if (inlen != 0) XMEMCPY(&T, in, inlen); T.u.byte[inlen] = 0x80; s_siv_xor_buf(D, &T); diff --git a/src/misc/compare_testvector.c b/src/misc/compare_testvector.c index f13084960..fd8ae0c77 100644 --- a/src/misc/compare_testvector.c +++ b/src/misc/compare_testvector.c @@ -59,6 +59,8 @@ int ltc_compare_testvector(const void* is, const unsigned long is_len, const voi int res = 0; if(is_len != should_len) { res = is_len > should_len ? -1 : 1; + } else if (is_len == 0 && (!is || !should)) { + res = 0; } else { res = XMEMCMP(is, should, is_len); } diff --git a/src/pk/ec25519/tweetnacl.c b/src/pk/ec25519/tweetnacl.c index 48446ef9a..4fee24064 100644 --- a/src/pk/ec25519/tweetnacl.c +++ b/src/pk/ec25519/tweetnacl.c @@ -53,7 +53,7 @@ sv car25519(gf o) o[i]+=(1LL<<16); c=o[i]>>16; o[(i+1)*(i<15)]+=c-1+37*(c-1)*(i==15); - o[i]-=c<<16; + o[i]-=((i64)(((u64)(c))<<16)); } } @@ -366,7 +366,7 @@ sv modL(u8 *r,i64 x[64]) for (j = i - 32;j < i - 12;++j) { x[j] += carry - 16 * x[i] * L[j - (i - 32)]; carry = (x[j] + 128) >> 8; - x[j] -= carry << 8; + x[j] -= ((i64)(((u64)(carry)) << 8)); } x[j] += carry; x[i] = 0; diff --git a/src/pk/ec448/ec448_common.c b/src/pk/ec448/ec448_common.c index 65bb0f2bb..c8cb71600 100644 --- a/src/pk/ec448/ec448_common.c +++ b/src/pk/ec448/ec448_common.c @@ -96,13 +96,13 @@ static void s_gf448_carry(gf448 o) for (i = 0; i < 15; ++i) { c = o[i] >> 28; o[i+1] += c; - o[i] -= c << 28; + o[i] -= ((long64)(((ulong64)(c)) << 28)); } /* limb 15 overflow: 2^(28*16) = 2^448 == 2^224 + 1 */ c = o[15] >> 28; o[0] += c; /* + c * 1 */ o[8] += c; /* + c * 2^224 */ - o[15] -= c << 28; + o[15] -= ((long64)(((ulong64)(c)) << 28)); /* one more pass to settle the extra from limb 0 and 8 */ for (i = 0; i < 15; ++i) { c = o[i] >> 28; @@ -254,7 +254,7 @@ static void s_gf448_mul(gf448 o, const gf448 a, const gf448 b) for (i = 0; i < 30; ++i) { c = t[i] >> 28; t[i+1] += c; - t[i] -= c << 28; + t[i] -= ((long64)(((ulong64)(c)) << 28)); } t[14] += 2 * t[30]; t[6] += t[30];