Skip to content

Commit

Permalink
Dynamic salt: Refactor to avoid variables with same name as typedefs
Browse files Browse the repository at this point in the history
This was made for combating a problem with -std=c99 on gcc 4.4.7,
but did not help.  Keeping it anyway for better readability.
  • Loading branch information
magnumripper committed Dec 2, 2024
1 parent 5059999 commit cb36a14
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/7z_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/axcrypt_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/dyna_salt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
}
18 changes: 9 additions & 9 deletions src/dyna_salt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
/*
Expand Down Expand Up @@ -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);

/*
Expand Down
2 changes: 1 addition & 1 deletion src/gpg_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/keepass_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/keystore_fmt_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/krb5_asrep_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/krb5_asrep_common_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/krb5_tgs_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/krb5_tgs_common_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/krb5_tgsrep_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/luks_fmt_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/opencl_argon2_fmt_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/opencl_oldoffice_fmt_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions src/pkzip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down

0 comments on commit cb36a14

Please sign in to comment.