From 64333239503d7a75517d652df6e03046b0b4627a Mon Sep 17 00:00:00 2001 From: magnum Date: Mon, 2 Dec 2024 05:41:16 +0100 Subject: [PATCH] Dynamic salt: Refactor to avoid typedefs with same name as variables "dyna_salt_t" was used as struct name, which is backwards. Then "dyna_salt" was used as typedef name, member name and variable name which was very confusing. Now using dyna_salt_s, dyna_salt_t and dyna_salt. --- src/7z_common.h | 2 +- src/axcrypt_common.h | 2 +- src/dyna_salt.c | 18 +++++++++--------- src/dyna_salt.h | 18 +++++++++--------- src/formats.c | 12 ++++++------ src/formats.h | 4 ++-- src/gpg_common.h | 2 +- src/keepass_common.h | 2 +- src/keystore_fmt_plug.c | 4 ++-- src/krb5_asrep_common.h | 2 +- src/krb5_asrep_common_plug.c | 2 +- src/krb5_tgs_common.h | 2 +- src/krb5_tgs_common_plug.c | 2 +- src/krb5_tgsrep_common.h | 2 +- src/luks_fmt_plug.c | 2 +- src/opencl_argon2_fmt_plug.c | 2 +- src/opencl_oldoffice_fmt_plug.c | 4 ++-- src/pkzip.h | 4 ++-- 18 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/7z_common.h b/src/7z_common.h index b1cd5a906e8..1a6971d0e9f 100644 --- a/src/7z_common.h +++ b/src/7z_common.h @@ -32,7 +32,7 @@ #define SALT_ALIGN sizeof(sevenzip_salt_t*) typedef struct sevenzip_salt_s { - dyna_salt dsalt; + dyna_salt_t dsalt; size_t aes_length; /* AES length (even blocks) */ size_t packed_size; /* Deflated length */ size_t crc_len; /* Inflated length */ diff --git a/src/axcrypt_common.h b/src/axcrypt_common.h index 41ea1e82454..240e08303c7 100644 --- a/src/axcrypt_common.h +++ b/src/axcrypt_common.h @@ -11,7 +11,7 @@ #define FORMAT_TAG_LEN (sizeof(FORMAT_TAG)-1) struct custom_salt { - dyna_salt dsalt; + dyna_salt_t dsalt; int version; uint32_t key_wrapping_rounds; uint32_t deriv_salt_length; diff --git a/src/dyna_salt.c b/src/dyna_salt.c index 19795beb525..8dbe8ef222a 100644 --- a/src/dyna_salt.c +++ b/src/dyna_salt.c @@ -14,15 +14,15 @@ /* * This is a dynamic salt structure. In a hash that has salts which * vary in size. To make a local salt structure usable by dyna_salt - * code in John, simply place an instance of a dyna_salt structure as + * code in John, simply place an instance of a dyna_salt_t structure as * the FIRST member of your salt structure, and then properly fill in * the members of that structure. This will make your structure 'look' - * just like a dyna_salt_john_core structure. That is the structure + * just like a dyna_salt_john_core_t structure. That is the structure * that john core code uses, so john core can access your structure, * without having to know its full internal structure. Then define the * rest of the salt structure to be the 'real' salt structure you need * for the runtime of your hash. In your format structure, set the salt_size - * to be sizeof(dyna_salt*) and set the FMT_DYNA_SALT format flag. See + * to be sizeof(dyna_salt_t*) and set the FMT_DYNA_SALT format flag. See * zip format for an example of how to properly use dyna_salt's. */ @@ -52,7 +52,7 @@ void dyna_salt_remove_fp(void *p) { if (p && (!format || /* get_salt() for dynamic format called from within valid() */ (format->params.flags & FMT_DYNA_SALT) == FMT_DYNA_SALT)) { - dyna_salt_john_core *p1 = *((dyna_salt_john_core**)p); + dyna_salt_john_core_t *p1 = *((dyna_salt_john_core_t**)p); if (p1 && p1->dyna_salt.salt_alloc_needs_free == 1) { #ifdef DYNA_SALT_DEBUG printf("-- Freeing a salt #%d from: %s line %d\n", --salt_count, fname, line); @@ -72,8 +72,8 @@ void dyna_salt_created_fp(void *p, char *fname, int line) { int dyna_salt_cmp(void *_p1, void *_p2, int comp_size) { if ((format->params.flags & FMT_DYNA_SALT) == FMT_DYNA_SALT) { - dyna_salt_john_core *p1 = *((dyna_salt_john_core**)_p1); - dyna_salt_john_core *p2 = *((dyna_salt_john_core**)_p2); + dyna_salt_john_core_t *p1 = *((dyna_salt_john_core_t**)_p1); + dyna_salt_john_core_t *p2 = *((dyna_salt_john_core_t**)_p2); #ifdef DYNA_SALT_DEBUG dump_stuff_msg("dyna_salt_cmp\np1", &((unsigned char*)p1)[p1->dyna_salt.salt_cmp_offset], p1->dyna_salt.salt_cmp_size>48?48:p1->dyna_salt.salt_cmp_size); dump_stuff_msg("p2", &((unsigned char*)p2)[p2->dyna_salt.salt_cmp_offset], p2->dyna_salt.salt_cmp_size>48?48:p2->dyna_salt.salt_cmp_size); @@ -99,7 +99,7 @@ void dyna_salt_md5(struct db_salt *p, int comp_size) { MD5_Init(&ctx); if ((format->params.flags & FMT_DYNA_SALT) == FMT_DYNA_SALT) { - dyna_salt_john_core *ds = *((dyna_salt_john_core**)p->salt); + dyna_salt_john_core_t *ds = *((dyna_salt_john_core_t**)p->salt); MD5_Update(&ctx, &((unsigned char*)ds)[ds->dyna_salt.salt_cmp_offset], ds->dyna_salt.salt_cmp_size); } else @@ -108,10 +108,10 @@ void dyna_salt_md5(struct db_salt *p, int comp_size) { } void dyna_salt_smash(void *p, char c) { - dyna_salt_john_core *p1 = *((dyna_salt_john_core**)p); + dyna_salt_john_core_t *p1 = *((dyna_salt_john_core_t**)p); memset(&((unsigned char*)p1)[p1->dyna_salt.salt_cmp_offset], 0xAF, p1->dyna_salt.salt_cmp_size); } int dyna_salt_smash_check(void *p, unsigned char c) { - dyna_salt_john_core *p1 = *((dyna_salt_john_core**)p); + dyna_salt_john_core_t *p1 = *((dyna_salt_john_core_t**)p); return (((unsigned char*)p1)[p1->dyna_salt.salt_cmp_offset+p1->dyna_salt.salt_cmp_size-1] == c); } diff --git a/src/dyna_salt.h b/src/dyna_salt.h index e09211765c5..d847c9e22a4 100644 --- a/src/dyna_salt.h +++ b/src/dyna_salt.h @@ -14,15 +14,15 @@ /* * This is a dynamic salt structure. In a hash that has salts which * vary in size. To make a local salt structure usable by dyna_salt - * code in John, simply place an instance of a dyna_salt structure as + * code in John, simply place an instance of a dyna_salt_t structure as * the FIRST member of your salt structure, and then properly fill in * the members of that structure. This will make your structure 'look' - * just like a dyna_salt_john_core structure. That is the structure + * just like a dyna_salt_john_core_t structure. That is the structure * that john core code uses, so john core can access your structure, * without having to know its full internal structure. Then define the * rest of the salt structure to be the 'real' salt structure you need * for the runtime of your hash. In your format structure, set the salt_size - * to be sizeof(dyna_salt*) and set the FMT_DYNA_SALT format flag. See + * to be sizeof(dyna_salt_t*) and set the FMT_DYNA_SALT format flag. See * zip format for an example of how to properly use dyna_salt's. */ @@ -37,20 +37,20 @@ /************************************************************************ * NOTE if changing this struct, also copy the changes to opencl_misc.h * ************************************************************************/ -typedef struct dyna_salt_t { +typedef struct dyna_salt_s { size_t salt_cmp_size; struct { /* bit field stealing one bit of the size_t */ size_t salt_alloc_needs_free : 1; /* 1 if if malloc/calloc used */ size_t salt_cmp_offset : (sizeof(size_t) * 8 - 1); }; -} dyna_salt; +} dyna_salt_t; /* this IS the signature that is required for ALL formats - * which use dyna_salt to have + * which use dyna_salt_t to have */ -typedef struct dyna_salt_john_core_t { - dyna_salt dyna_salt; -} dyna_salt_john_core; +typedef struct dyna_salt_john_core_s { + dyna_salt_t dyna_salt; +} dyna_salt_john_core_t; // call with SALT_CMP_SIZE(struct, first comp. member, blob member, extra_bytes) #define SALT_CMP_SIZE(a,b,c,d) (offsetof(a,c)-offsetof(a,b)+d) diff --git a/src/formats.c b/src/formats.c index 350ffea48d6..6d9ab581da5 100644 --- a/src/formats.c +++ b/src/formats.c @@ -1136,18 +1136,18 @@ static char *fmt_self_test_body(struct fmt_main *format, /* validate that salt() returns cleaned buffer */ if (extra_tests && !salt_cleaned_warned && format->params.salt_size) { if ((format->params.flags & FMT_DYNA_SALT) == FMT_DYNA_SALT) { - dyna_salt *p1, *p2=0, *p3=0; - p1 = *((dyna_salt**)salt); + dyna_salt_t *p1, *p2=0, *p3=0; + p1 = *((dyna_salt_t**)salt); dyna_salt_smash(salt, 0xAF); salt = format->methods.salt(ciphertext); dyna_salt_create(salt); - p2 = *((dyna_salt**)salt); + p2 = *((dyna_salt_t**)salt); if (dyna_salt_smash_check(salt, 0xAF)) { dyna_salt_smash(salt, 0xC3); salt = format->methods.salt(ciphertext); dyna_salt_create(salt); - p3 = *((dyna_salt**)salt); + p3 = *((dyna_salt_t**)salt); if (dyna_salt_smash_check(salt, 0xC3)) { /* possibly did not clean the salt. */ puts("Warning: salt() not pre-cleaning buffer"); @@ -2136,8 +2136,8 @@ int fmt_default_salt_hash(void *salt) int fmt_default_dyna_salt_hash(void *salt) { - /* if the hash is a dyna_salt type hash, it can simply use this function */ - dyna_salt_john_core *mysalt = *(dyna_salt_john_core **)salt; + /* if the hash is a dyna_salt_t type hash, it can simply use this function */ + dyna_salt_john_core_t *mysalt = *(dyna_salt_john_core_t **)salt; unsigned v; int i; unsigned char *p; diff --git a/src/formats.h b/src/formats.h index db6e3724d8e..eb43eef659a 100644 --- a/src/formats.h +++ b/src/formats.h @@ -91,7 +91,7 @@ struct db_salt; #define FMT_NOT_EXACT 0x00000100 /* * This format uses a dynamic sized salt, and its salt structure - * 'derives' from the dyna_salt type defined in dyna_salt.h + * 'derives' from the dyna_salt_t type defined in dyna_salt.h */ #define FMT_DYNA_SALT 0x00000200 /* @@ -514,7 +514,7 @@ extern int fmt_default_salt_hash(void *salt); extern void fmt_default_set_salt(void *salt); extern void fmt_default_clear_keys(void); extern int fmt_default_get_hash(int index); -/* this is a salt_hash default specifically for dyna_salt type formats */ +/* this is a salt_hash default specifically for dyna_salt_t type formats */ extern int fmt_default_dyna_salt_hash(void *salt); /* diff --git a/src/gpg_common.h b/src/gpg_common.h index 5714c5e1c3b..871fac84f44 100644 --- a/src/gpg_common.h +++ b/src/gpg_common.h @@ -82,7 +82,7 @@ enum { #endif struct gpg_common_custom_salt { - dyna_salt dsalt; + dyna_salt_t dsalt; int datalen; char spec; char pk_algorithm; diff --git a/src/keepass_common.h b/src/keepass_common.h index 4f0fb494a7c..fc9838945bc 100644 --- a/src/keepass_common.h +++ b/src/keepass_common.h @@ -31,7 +31,7 @@ #define ARGON2_SALT_SIZE 64 typedef struct { - dyna_salt dsalt; + dyna_salt_t dsalt; uint32_t t_cost, m_cost, lanes; uint32_t hash_size; uint32_t salt_length; diff --git a/src/keystore_fmt_plug.c b/src/keystore_fmt_plug.c index 9eedcec141e..b8ad37dc911 100644 --- a/src/keystore_fmt_plug.c +++ b/src/keystore_fmt_plug.c @@ -100,7 +100,7 @@ static preload *cursimd; // set_salt points this to the current salt. #endif typedef struct keystore_salt_t { - dyna_salt dsalt; + dyna_salt_t dsalt; int target; int data_length; int count; @@ -299,7 +299,7 @@ static void *get_salt(char *ciphertext) + atoi16[ARCH_INDEX(p[i * 2 + 1])]; MEM_FREE(keeptr); - // setup the dyna_salt stuff. + // setup the dyna_salt_t stuff. cs.dsalt.salt_cmp_offset = SALT_CMP_OFF(keystore_salt, data_length); cs.dsalt.salt_cmp_size = SALT_CMP_SIZE(keystore_salt, data_length, data, 0); cs.dsalt.salt_alloc_needs_free = 0; diff --git a/src/krb5_asrep_common.h b/src/krb5_asrep_common.h index b4ee4acaf8b..f5e65959882 100644 --- a/src/krb5_asrep_common.h +++ b/src/krb5_asrep_common.h @@ -19,7 +19,7 @@ #define SALT_ALIGN sizeof(struct custom_salt*) struct custom_salt { - dyna_salt dsalt; + dyna_salt_t dsalt; unsigned char edata1[16]; char salt[256]; unsigned char etype; diff --git a/src/krb5_asrep_common_plug.c b/src/krb5_asrep_common_plug.c index f11a69b4e57..b0aa32140dc 100644 --- a/src/krb5_asrep_common_plug.c +++ b/src/krb5_asrep_common_plug.c @@ -198,7 +198,7 @@ void *krb5_asrep_get_salt(char *ciphertext) MEM_FREE(keeptr); - /* following is used to fool dyna_salt stuff */ + /* following is used to fool dyna_salt_t stuff */ cs.dsalt.salt_cmp_offset = SALT_CMP_OFF(struct custom_salt, edata1); cs.dsalt.salt_cmp_size = SALT_CMP_SIZE(struct custom_salt, edata1, edata2len, 0); cs.dsalt.salt_alloc_needs_free = 0; diff --git a/src/krb5_tgs_common.h b/src/krb5_tgs_common.h index f700f02b854..b154141a4a1 100644 --- a/src/krb5_tgs_common.h +++ b/src/krb5_tgs_common.h @@ -18,7 +18,7 @@ #define SALT_ALIGN sizeof(struct custom_salt *) typedef struct { - dyna_salt dsalt; + dyna_salt_t dsalt; unsigned char edata1[16]; uint32_t edata2len; unsigned char edata2[1]; diff --git a/src/krb5_tgs_common_plug.c b/src/krb5_tgs_common_plug.c index d864e3833d9..a4ff608218f 100644 --- a/src/krb5_tgs_common_plug.c +++ b/src/krb5_tgs_common_plug.c @@ -170,7 +170,7 @@ void *krb5tgs_get_salt(char *ciphertext) } MEM_FREE(keeptr); - /* Set the JtR core linkage stuff for this dyna_salt */ + /* Set the JtR core linkage stuff for this dyna_salt_t */ psalt->dsalt.salt_cmp_offset = SALT_CMP_OFF(krb5tgs_salt, edata1); psalt->dsalt.salt_cmp_size = SALT_CMP_SIZE(krb5tgs_salt, edata1, edata2len, psalt->edata2len); psalt->dsalt.salt_alloc_needs_free = 1; diff --git a/src/krb5_tgsrep_common.h b/src/krb5_tgsrep_common.h index 7be0b026994..10aa0de6d5b 100644 --- a/src/krb5_tgsrep_common.h +++ b/src/krb5_tgsrep_common.h @@ -21,7 +21,7 @@ #define SALT_ALIGN sizeof(krb5tgsrep_salt*) typedef struct { - dyna_salt dsalt; + dyna_salt_t dsalt; int etype; char salt[256]; /* (...)$User$realm$(...) --> REALMUser */ unsigned char edata1[12]; /* hmac-sha1 stripped to 12 bytes */ diff --git a/src/luks_fmt_plug.c b/src/luks_fmt_plug.c index 17d0421ce06..8c65abadd09 100644 --- a/src/luks_fmt_plug.c +++ b/src/luks_fmt_plug.c @@ -121,7 +121,7 @@ struct luks_phdr { }; static struct custom_salt_LUKS { - dyna_salt dsalt; + dyna_salt_t dsalt; char path[8192]; int loaded; struct luks_phdr myphdr; diff --git a/src/opencl_argon2_fmt_plug.c b/src/opencl_argon2_fmt_plug.c index 1dbb9b04ad3..2490b80c338 100644 --- a/src/opencl_argon2_fmt_plug.c +++ b/src/opencl_argon2_fmt_plug.c @@ -985,7 +985,7 @@ static void kp_set_salt(void *salt) keepass_salt = *((keepass_salt_t**)salt); // The KeePass salt is dynamic size, but starts off with a plain - // Argon2 salt after the dyna_salt header + // Argon2 salt after the dyna_salt_t header memcpy(&saved_salt, &keepass_salt->t_cost, sizeof(struct argon2_salt)); if (sizeof(keepass_salt_t) + keepass_salt->content_size - 1 > keepass_saltsize) { diff --git a/src/opencl_oldoffice_fmt_plug.c b/src/opencl_oldoffice_fmt_plug.c index efd6011cb80..ce1ce30524f 100644 --- a/src/opencl_oldoffice_fmt_plug.c +++ b/src/opencl_oldoffice_fmt_plug.c @@ -39,7 +39,7 @@ john_register_one(&FORMAT_STRUCT); #define PLAINTEXT_LENGTH 24 //* 19 is leanest, 24, 28, 31, max. 51 */ #define BINARY_SIZE 0 #define BINARY_ALIGN MEM_ALIGN_NONE -#define SALT_SIZE sizeof(dyna_salt*) +#define SALT_SIZE sizeof(dyna_salt_t*) #define SALT_ALIGN MEM_ALIGN_WORD #define MIN_KEYS_PER_CRYPT 1 @@ -80,7 +80,7 @@ static struct fmt_tests oo_tests[] = { }; typedef struct { - dyna_salt dsalt; + dyna_salt_t dsalt; int type; unsigned char salt[16]; unsigned char verifier[16]; /* or encryptedVerifier */ diff --git a/src/pkzip.h b/src/pkzip.h index f8be7fae2e9..330e940c2f0 100644 --- a/src/pkzip.h +++ b/src/pkzip.h @@ -58,7 +58,7 @@ typedef struct zip_hash_type_t { } ZIP_HASH; typedef struct winzip_salt_t { - dyna_salt dsalt; + dyna_salt_t dsalt; uint64_t comp_len; struct { uint16_t type : 4; @@ -70,7 +70,7 @@ typedef struct winzip_salt_t { } winzip_salt; typedef struct zip_salt_t { - dyna_salt dsalt; + dyna_salt_t dsalt; char fname[1024]; // if the zip is too large, we open the file in cmp_exact read the // data a small buffer at a time. If the zip blob is small enough // (under 16k), then it simply read into H[x].h at init() time.