Changeset - r28520:f9aebe299cae
[Not reviewed]
master
0 2 0
Patric Stout - 11 months ago 2024-01-18 23:17:58
truebrain@openttd.org
Codechange: MacOS already has MIN/MAX macros defined

This is caused because we use PreCompile Headers, and one of them
includes a system headers which defines MIN/MAX.
2 files changed with 13 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/3rdparty/monocypher/monocypher-ed25519.cpp
Show inline comments
 
@@ -62,13 +62,13 @@ namespace MONOCYPHER_CPP_NAMESPACE {
 
/////////////////
 
#define FOR(i, min, max)     for (size_t i = min; i < max; i++)
 
#define COPY(dst, src, size) FOR(_i_, 0, size) (dst)[_i_] = (src)[_i_]
 
#define ZERO(buf, size)      FOR(_i_, 0, size) (buf)[_i_] = 0
 
#define WIPE_CTX(ctx)        crypto_wipe(ctx   , sizeof(*(ctx)))
 
#define WIPE_BUFFER(buffer)  crypto_wipe(buffer, sizeof(buffer))
 
#define MIN(a, b)            ((a) <= (b) ? (a) : (b))
 
#define MC_MIN(a, b)         ((a) <= (b) ? (a) : (b))
 
typedef uint8_t u8;
 
typedef uint64_t u64;
 

	
 
// Returns the smallest positive integer y such that
 
// (x + y) % pow_2  == 0
 
// Basically, it's how many bytes we need to add to "align" x.
 
@@ -216,24 +216,24 @@ void crypto_sha512_update(crypto_sha512_
 
	if (message_size == 0) {
 
		return;
 
	}
 

	
 
	// Align ourselves with word boundaries
 
	if ((ctx->input_idx & 7) != 0) {
 
		size_t nb_bytes = MIN(align(ctx->input_idx, 8), message_size);
 
		size_t nb_bytes = MC_MIN(align(ctx->input_idx, 8), message_size);
 
		FOR (i, 0, nb_bytes) {
 
			sha512_set_input(ctx, message[i]);
 
			ctx->input_idx++;
 
		}
 
		message      += nb_bytes;
 
		message_size -= nb_bytes;
 
	}
 

	
 
	// Align ourselves with block boundaries
 
	if ((ctx->input_idx & 127) != 0) {
 
		size_t nb_words = MIN(align(ctx->input_idx, 128), message_size) >> 3;
 
		size_t nb_words = MC_MIN(align(ctx->input_idx, 128), message_size) >> 3;
 
		load64_be_buf(ctx->input + (ctx->input_idx >> 3), message, nb_words);
 
		ctx->input_idx += nb_words << 3;
 
		message        += nb_words << 3;
 
		message_size   -= nb_words << 3;
 
	}
 

	
 
@@ -369,13 +369,13 @@ void crypto_sha512_hkdf_expand(u8       
 
{
 
	int not_first = 0;
 
	u8 ctr = 1;
 
	u8 blk[64];
 

	
 
	while (okm_size > 0) {
 
		size_t out_size = MIN(okm_size, sizeof(blk));
 
		size_t out_size = MC_MIN(okm_size, sizeof(blk));
 

	
 
		crypto_sha512_hmac_ctx ctx;
 
		crypto_sha512_hmac_init(&ctx, prk , prk_size);
 
		if (not_first) {
 
			// For some reason HKDF uses some kind of CBC mode.
 
			// For some reason CTR mode alone wasn't enough.
src/3rdparty/monocypher/monocypher.cpp
Show inline comments
 
@@ -63,14 +63,14 @@ namespace MONOCYPHER_CPP_NAMESPACE {
 
#define FOR_T(type, i, start, end) for (type i = (start); i < (end); i++)
 
#define FOR(i, start, end)         FOR_T(size_t, i, start, end)
 
#define COPY(dst, src, size)       FOR(_i_, 0, size) (dst)[_i_] = (src)[_i_]
 
#define ZERO(buf, size)            FOR(_i_, 0, size) (buf)[_i_] = 0
 
#define WIPE_CTX(ctx)              crypto_wipe(ctx   , sizeof(*(ctx)))
 
#define WIPE_BUFFER(buffer)        crypto_wipe(buffer, sizeof(buffer))
 
#define MIN(a, b)                  ((a) <= (b) ? (a) : (b))
 
#define MAX(a, b)                  ((a) >= (b) ? (a) : (b))
 
#define MC_MIN(a, b)               ((a) <= (b) ? (a) : (b))
 
#define MC_MAX(a, b)               ((a) >= (b) ? (a) : (b))
 

	
 
typedef int8_t   i8;
 
typedef uint8_t  u8;
 
typedef int16_t  i16;
 
typedef uint32_t u32;
 
typedef int32_t  i32;
 
@@ -380,13 +380,13 @@ void crypto_poly1305_update(crypto_poly1
 
	// Avoid undefined NULL pointer increments with empty messages
 
	if (message_size == 0) {
 
		return;
 
	}
 

	
 
	// Align ourselves with block boundaries
 
	size_t aligned = MIN(gap(ctx->c_idx, 16), message_size);
 
	size_t aligned = MC_MIN(gap(ctx->c_idx, 16), message_size);
 
	FOR (i, 0, aligned) {
 
		ctx->c[ctx->c_idx] = *message;
 
		ctx->c_idx++;
 
		message++;
 
		message_size--;
 
	}
 
@@ -562,26 +562,26 @@ void crypto_blake2b_update(crypto_blake2
 
	if (message_size == 0) {
 
		return;
 
	}
 

	
 
	// Align with word boundaries
 
	if ((ctx->input_idx & 7) != 0) {
 
		size_t nb_bytes = MIN(gap(ctx->input_idx, 8), message_size);
 
		size_t nb_bytes = MC_MIN(gap(ctx->input_idx, 8), message_size);
 
		size_t word     = ctx->input_idx >> 3;
 
		size_t byte     = ctx->input_idx & 7;
 
		FOR (i, 0, nb_bytes) {
 
			ctx->input[word] |= (u64)message[i] << ((byte + i) << 3);
 
		}
 
		ctx->input_idx += nb_bytes;
 
		message        += nb_bytes;
 
		message_size   -= nb_bytes;
 
	}
 

	
 
	// Align with block boundaries (faster than byte by byte)
 
	if ((ctx->input_idx & 127) != 0) {
 
		size_t nb_words = MIN(gap(ctx->input_idx, 128), message_size) >> 3;
 
		size_t nb_words = MC_MIN(gap(ctx->input_idx, 128), message_size) >> 3;
 
		load64_le_buf(ctx->input + (ctx->input_idx >> 3), message, nb_words);
 
		ctx->input_idx += nb_words << 3;
 
		message        += nb_words << 3;
 
		message_size   -= nb_words << 3;
 
	}
 

	
 
@@ -623,13 +623,13 @@ void crypto_blake2b_update(crypto_blake2
 
	}
 
}
 

	
 
void crypto_blake2b_final(crypto_blake2b_ctx *ctx, u8 *hash)
 
{
 
	blake2b_compress(ctx, 1); // compress the last block
 
	size_t hash_size = MIN(ctx->hash_size, 64);
 
	size_t hash_size = MC_MIN(ctx->hash_size, 64);
 
	size_t nb_words  = hash_size >> 3;
 
	store64_le_buf(hash, ctx->hash, nb_words);
 
	FOR (i, nb_words << 3, hash_size) {
 
		hash[i] = (ctx->hash[i >> 3] >> (8 * (i & 7))) & 0xff;
 
	}
 
	WIPE_CTX(ctx);
 
@@ -684,13 +684,13 @@ static void  xor_block(blk *o,const blk*
 
// (One could use a stream cipher with a seed hash as the key, but
 
//  this would introduce another dependency —and point of failure.)
 
static void extended_hash(u8       *digest, u32 digest_size,
 
                          const u8 *input , u32 input_size)
 
{
 
	crypto_blake2b_ctx ctx;
 
	crypto_blake2b_init  (&ctx, MIN(digest_size, 64));
 
	crypto_blake2b_init  (&ctx, MC_MIN(digest_size, 64));
 
	blake_update_32      (&ctx, digest_size);
 
	crypto_blake2b_update(&ctx, input, input_size);
 
	crypto_blake2b_final (&ctx, digest);
 

	
 
	if (digest_size > 64) {
 
		// the conversion to u64 avoids integer overflow on
 
@@ -1939,13 +1939,13 @@ static int slide_step(slide_ctx *ctx, in
 
{
 
	if (i == ctx->next_check) {
 
		if (scalar_bit(scalar, i) == scalar_bit(scalar, i - 1)) {
 
			ctx->next_check--;
 
		} else {
 
			// compute digit of next window
 
			int w = MIN(width, i + 1);
 
			int w = MC_MIN(width, i + 1);
 
			int v = -(scalar_bit(scalar, i) << (w-1));
 
			FOR_T (int, j, 0, w-1) {
 
				v += scalar_bit(scalar, i-(w-1)+j) << j;
 
			}
 
			v += scalar_bit(scalar, i-w);
 
			int lsb = v & (~v + 1); // smallest bit of v
 
@@ -1998,13 +1998,13 @@ int crypto_eddsa_check_equation(const u8
 
	}
 

	
 
	// sum = [s]B - [h]A
 
	// Merged double and add ladder, fused with sliding
 
	slide_ctx h_slide;  slide_init(&h_slide, h);
 
	slide_ctx s_slide;  slide_init(&s_slide, s);
 
	int i = MAX(h_slide.next_check, s_slide.next_check);
 
	int i = MC_MAX(h_slide.next_check, s_slide.next_check);
 
	ge *sum = &minus_A; // reuse minus_A for the sum
 
	ge_zero(sum);
 
	while (i >= 0) {
 
		ge tmp;
 
		ge_double(sum, sum, &tmp);
 
		int h_digit = slide_step(&h_slide, P_W_WIDTH, i, h);
0 comments (0 inline, 0 general)