From 6b2b4167187fee09365271cca182866ecb029af3 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 18 Mar 2024 14:56:16 +0000 Subject: [Rework] Remove some of the GLib types in lieu of standard ones This types have constant conflicts with the system ones especially on OSX. --- src/libcryptobox/chacha20/ref.c | 2 +- src/libcryptobox/cryptobox.c | 62 +++++++++++++++++++------------------- src/libcryptobox/cryptobox.h | 14 ++++----- src/libcryptobox/keypair.c | 4 +-- src/libcryptobox/keypair_private.h | 2 +- src/libcryptobox/keypairs_cache.c | 2 +- 6 files changed, 43 insertions(+), 43 deletions(-) (limited to 'src/libcryptobox') diff --git a/src/libcryptobox/chacha20/ref.c b/src/libcryptobox/chacha20/ref.c index ee646dbf3..b1b6c57fd 100644 --- a/src/libcryptobox/chacha20/ref.c +++ b/src/libcryptobox/chacha20/ref.c @@ -5,7 +5,7 @@ #if defined(HAVE_INT32) typedef uint32_t chacha_int32; #else -typedef guint32 chacha_int32; +typedef uint32_t chacha_int32; #endif /* interpret four 8 bit unsigned integers as a 32 bit unsigned integer in little endian */ diff --git a/src/libcryptobox/cryptobox.c b/src/libcryptobox/cryptobox.c index e118c4a73..4d3c1b43c 100644 --- a/src/libcryptobox/cryptobox.c +++ b/src/libcryptobox/cryptobox.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -72,7 +72,7 @@ static const guchar n0[16] = {0}; static void rspamd_cryptobox_cpuid(gint cpu[4], gint info) { - guint32 __attribute__((unused)) eax, __attribute__((unused)) ecx = 0, __attribute__((unused)) ebx = 0, __attribute__((unused)) edx = 0; + uint32_t __attribute__((unused)) eax, __attribute__((unused)) ecx = 0, __attribute__((unused)) ebx = 0, __attribute__((unused)) edx = 0; eax = info; #if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) @@ -111,7 +111,7 @@ static gboolean rspamd_cryptobox_test_instr(gint instr) { void (*old_handler)(int); - guint32 rd; + uint32_t rd; #if defined(__GNUC__) ok = 1; @@ -187,9 +187,9 @@ struct rspamd_cryptobox_library_ctx * rspamd_cryptobox_init(void) { gint cpu[4], nid; - const guint32 osxsave_mask = (1 << 27); - const guint32 fma_movbe_osxsave_mask = ((1 << 12) | (1 << 22) | (1 << 27)); - const guint32 avx2_bmi12_mask = (1 << 5) | (1 << 3) | (1 << 8); + const uint32_t osxsave_mask = (1 << 27); + const uint32_t fma_movbe_osxsave_mask = ((1 << 12) | (1 << 22) | (1 << 27)); + const uint32_t avx2_bmi12_mask = (1 << 5) | (1 << 3) | (1 << 8); gulong bit; static struct rspamd_cryptobox_library_ctx *ctx; GString *buf; @@ -207,32 +207,32 @@ rspamd_cryptobox_init(void) rspamd_cryptobox_cpuid(cpu, 1); if (nid > 1) { - if ((cpu[3] & ((guint32) 1 << 26))) { + if ((cpu[3] & ((uint32_t) 1 << 26))) { if (rspamd_cryptobox_test_instr(CPUID_SSE2)) { cpu_config |= CPUID_SSE2; } } - if ((cpu[2] & ((guint32) 1 << 0))) { + if ((cpu[2] & ((uint32_t) 1 << 0))) { if (rspamd_cryptobox_test_instr(CPUID_SSE3)) { cpu_config |= CPUID_SSE3; } } - if ((cpu[2] & ((guint32) 1 << 9))) { + if ((cpu[2] & ((uint32_t) 1 << 9))) { if (rspamd_cryptobox_test_instr(CPUID_SSSE3)) { cpu_config |= CPUID_SSSE3; } } - if ((cpu[2] & ((guint32) 1 << 19))) { + if ((cpu[2] & ((uint32_t) 1 << 19))) { if (rspamd_cryptobox_test_instr(CPUID_SSE41)) { cpu_config |= CPUID_SSE41; } } - if ((cpu[2] & ((guint32) 1 << 20))) { + if ((cpu[2] & ((uint32_t) 1 << 20))) { if (rspamd_cryptobox_test_instr(CPUID_SSE42)) { cpu_config |= CPUID_SSE42; } } - if ((cpu[2] & ((guint32) 1 << 30))) { + if ((cpu[2] & ((uint32_t) 1 << 30))) { if (rspamd_cryptobox_test_instr(CPUID_RDRAND)) { cpu_config |= CPUID_RDRAND; } @@ -240,7 +240,7 @@ rspamd_cryptobox_init(void) /* OSXSAVE */ if ((cpu[2] & osxsave_mask) == osxsave_mask) { - if ((cpu[2] & ((guint32) 1 << 28))) { + if ((cpu[2] & ((uint32_t) 1 << 28))) { if (rspamd_cryptobox_test_instr(CPUID_AVX)) { cpu_config |= CPUID_AVX; } @@ -1529,10 +1529,10 @@ G_STATIC_ASSERT(sizeof(struct XXH3_state_s) <= struct RSPAMD_ALIGNED(16) _mum_iuf { union { - gint64 ll; - unsigned char b[sizeof(guint64)]; + int64_t ll; + unsigned char b[sizeof(uint64_t)]; } buf; - gint64 h; + int64_t h; unsigned rem; }; @@ -1556,7 +1556,7 @@ void rspamd_cryptobox_fast_hash_free(rspamd_cryptobox_fast_hash_state_t *st) } void rspamd_cryptobox_fast_hash_init(rspamd_cryptobox_fast_hash_state_t *st, - guint64 seed) + uint64_t seed) { XXH3_state_t *xst = (XXH3_state_t *) st->opaque; st->type = RSPAMD_CRYPTOBOX_XXHASH3; @@ -1566,7 +1566,7 @@ void rspamd_cryptobox_fast_hash_init(rspamd_cryptobox_fast_hash_state_t *st, void rspamd_cryptobox_fast_hash_init_specific(rspamd_cryptobox_fast_hash_state_t *st, enum rspamd_cryptobox_fast_hash_type type, - guint64 seed) + uint64_t seed) { switch (type) { case RSPAMD_CRYPTOBOX_T1HA: @@ -1664,7 +1664,7 @@ void rspamd_cryptobox_fast_hash_update(rspamd_cryptobox_fast_hash_state_t *st, /* Leftover */ if (drem > 0) { - iuf->rem = sizeof(guint64) - drem; + iuf->rem = sizeof(uint64_t) - drem; iuf->buf.ll = 0; memcpy(iuf->buf.b, p, drem); } @@ -1681,10 +1681,10 @@ void rspamd_cryptobox_fast_hash_update(rspamd_cryptobox_fast_hash_state_t *st, } } -guint64 +uint64_t rspamd_cryptobox_fast_hash_final(rspamd_cryptobox_fast_hash_state_t *st) { - guint64 ret; + uint64_t ret; if (st->type == RSPAMD_CRYPTOBOX_T1HA) { t1ha_context_t *rst = (t1ha_context_t *) st->opaque; @@ -1731,32 +1731,32 @@ rspamd_cryptobox_fast_hash_final(rspamd_cryptobox_fast_hash_state_t *st) /** * One in all function */ -static inline guint64 +static inline uint64_t rspamd_cryptobox_fast_hash_machdep(const void *data, - gsize len, guint64 seed) + gsize len, uint64_t seed) { return XXH3_64bits_withSeed(data, len, seed); } -static inline guint64 +static inline uint64_t rspamd_cryptobox_fast_hash_indep(const void *data, - gsize len, guint64 seed) + gsize len, uint64_t seed) { return XXH3_64bits_withSeed(data, len, seed); } -guint64 +uint64_t rspamd_cryptobox_fast_hash(const void *data, - gsize len, guint64 seed) + gsize len, uint64_t seed) { return rspamd_cryptobox_fast_hash_machdep(data, len, seed); } -guint64 +uint64_t rspamd_cryptobox_fast_hash_specific( enum rspamd_cryptobox_fast_hash_type type, const void *data, - gsize len, guint64 seed) + gsize len, uint64_t seed) { switch (type) { case RSPAMD_CRYPTOBOX_XXHASH32: diff --git a/src/libcryptobox/cryptobox.h b/src/libcryptobox/cryptobox.h index 8cd79bbad..635fffefc 100644 --- a/src/libcryptobox/cryptobox.h +++ b/src/libcryptobox/cryptobox.h @@ -375,7 +375,7 @@ void rspamd_cryptobox_fast_hash_free(rspamd_cryptobox_fast_hash_state_t *st); * non-keyed hash is generated */ void rspamd_cryptobox_fast_hash_init(rspamd_cryptobox_fast_hash_state_t *st, - guint64 seed); + uint64_t seed); /** * Init cryptobox hash state using key if needed, `st` must point to the buffer @@ -384,7 +384,7 @@ void rspamd_cryptobox_fast_hash_init(rspamd_cryptobox_fast_hash_state_t *st, */ void rspamd_cryptobox_fast_hash_init_specific(rspamd_cryptobox_fast_hash_state_t *st, enum rspamd_cryptobox_fast_hash_type type, - guint64 seed); + uint64_t seed); /** * Update hash with data portion @@ -395,21 +395,21 @@ void rspamd_cryptobox_fast_hash_update(rspamd_cryptobox_fast_hash_state_t *st, /** * Output hash to the buffer of rspamd_cryptobox_HASHBYTES length */ -guint64 rspamd_cryptobox_fast_hash_final(rspamd_cryptobox_fast_hash_state_t *st); +uint64_t rspamd_cryptobox_fast_hash_final(rspamd_cryptobox_fast_hash_state_t *st); /** * One in all function */ -guint64 rspamd_cryptobox_fast_hash(const void *data, - gsize len, guint64 seed); +uint64_t rspamd_cryptobox_fast_hash(const void *data, + gsize len, uint64_t seed); /** * Platform independent version */ -guint64 rspamd_cryptobox_fast_hash_specific( +uint64_t rspamd_cryptobox_fast_hash_specific( enum rspamd_cryptobox_fast_hash_type type, const void *data, - gsize len, guint64 seed); + gsize len, uint64_t seed); /** * Decode base64 using platform optimized code diff --git a/src/libcryptobox/keypair.c b/src/libcryptobox/keypair.c index ec7490a56..671b752af 100644 --- a/src/libcryptobox/keypair.c +++ b/src/libcryptobox/keypair.c @@ -447,7 +447,7 @@ rspamd_pubkey_get_nm(struct rspamd_cryptobox_pubkey *p, g_assert(p != NULL); if (p->nm) { - if (memcmp(kp->id, (const guchar *) &p->nm->sk_id, sizeof(guint64)) == 0) { + if (memcmp(kp->id, (const guchar *) &p->nm->sk_id, sizeof(uint64_t)) == 0) { return p->nm->nm; } @@ -472,7 +472,7 @@ rspamd_pubkey_calculate_nm(struct rspamd_cryptobox_pubkey *p, abort(); } - memcpy(&p->nm->sk_id, kp->id, sizeof(guint64)); + memcpy(&p->nm->sk_id, kp->id, sizeof(uint64_t)); REF_INIT_RETAIN(p->nm, rspamd_cryptobox_nm_dtor); } diff --git a/src/libcryptobox/keypair_private.h b/src/libcryptobox/keypair_private.h index 16e17e0b2..89e3f0996 100644 --- a/src/libcryptobox/keypair_private.h +++ b/src/libcryptobox/keypair_private.h @@ -28,7 +28,7 @@ extern "C" { */ struct rspamd_cryptobox_nm { guchar nm[rspamd_cryptobox_MAX_NMBYTES]; - guint64 sk_id; /* Used to store secret key id */ + uint64_t sk_id; /* Used to store secret key id */ ref_entry_t ref; }; diff --git a/src/libcryptobox/keypairs_cache.c b/src/libcryptobox/keypairs_cache.c index 0616bb940..05712b25c 100644 --- a/src/libcryptobox/keypairs_cache.c +++ b/src/libcryptobox/keypairs_cache.c @@ -104,7 +104,7 @@ void rspamd_keypair_cache_process(struct rspamd_keypair_cache *c, memcpy(new->pair, rk->id, rspamd_cryptobox_HASHBYTES); memcpy(&new->pair[rspamd_cryptobox_HASHBYTES], lk->id, rspamd_cryptobox_HASHBYTES); - memcpy(&new->nm->sk_id, lk->id, sizeof(guint64)); + memcpy(&new->nm->sk_id, lk->id, sizeof(uint64_t)); if (rk->alg == RSPAMD_CRYPTOBOX_MODE_25519) { struct rspamd_cryptobox_pubkey_25519 *rk_25519 = -- cgit v1.2.3