1 /* 2 * This software was written by Jim Fougeron jfoug AT cox dot net 3 * in 2014. No copyright is claimed, and the software is hereby 4 * placed in the public domain. In case this attempt to disclaim 5 * copyright and place the software in the public domain is deemed 6 * null and void, then the software is Copyright (c) 2014 Jim Fougeron 7 * and it is hereby released to the general public under the following 8 * terms: 9 * 10 * This software may be modified, redistributed, and used for any 11 * purpose, in source and binary forms, with or without modification. 12 */ 13 14 /* 15 * This is a dynamic salt structure. In a hash that has salts which 16 * vary in size. To make a local salt structure usable by dyna_salt 17 * code in John, simply place an instance of a dyna_salt structure as 18 * the FIRST member of your salt structure, and then properly fill in 19 * the members of that structure. This will make your structure 'look' 20 * just like a dyna_salt_john_core structure. That is the structure 21 * that john core code uses, so john core can access your structure, 22 * without having to know its full internal structure. Then define the 23 * rest of the salt structure to be the 'real' salt structure you need 24 * for the runtime of your hash. In your format structure, set the salt_size 25 * to be sizeof(dyna_salt*) and set the FMT_DYNA_SALT format flag. See 26 * zip format for an example of how to properly use dyna_salt's. 27 */ 28 29 #if !defined (_DYNA_SALT_H__) 30 #define _DYNA_SALT_H__ 31 32 #include <stddef.h> 33 #include <stdint.h> 34 35 //#define DYNA_SALT_DEBUG 36 37 /************************************************************************ 38 * NOTE if changing this struct, also copy the changes to opencl_misc.h * 39 ************************************************************************/ 40 typedef struct dyna_salt_t { 41 size_t salt_cmp_size; 42 struct { /* bit field stealing one bit of the size_t */ 43 size_t salt_alloc_needs_free : 1; /* 1 if if malloc/calloc used */ 44 size_t salt_cmp_offset : (sizeof(size_t) * 8 - 1); 45 }; 46 } dyna_salt; 47 48 /* this IS the signature that is required for ALL formats 49 * which use dyna_salt to have 50 */ 51 typedef struct dyna_salt_john_core_t { 52 dyna_salt dyna_salt; 53 } dyna_salt_john_core; 54 55 // call with SALT_CMP_SIZE(struct, first comp. member, blob member, extra_bytes) 56 #define SALT_CMP_SIZE(a,b,c,d) (offsetof(a,c)-offsetof(a,b)+d) 57 // call with SALT_CMP_OFF(struct, member) 58 #define SALT_CMP_OFF(a,b) (offsetof(a,b)) 59 60 /* 61 * MUST be called prior to other functions, and reset 62 * each time a format change happens, during self test 63 * and loading. There are times where other functions 64 * are called, where we do not have a format structure. 65 * Returns the format previously set (may be NULL) 66 */ 67 struct fmt_main; 68 struct fmt_main *dyna_salt_init(struct fmt_main *format); 69 70 /* 71 * NOTE, will compare dyna and non-dyna salts. 72 */ 73 int dyna_salt_cmp(void *p1, void *p2, int comp_size); 74 75 /* 76 * NOTE, will do the MD5 salt hashing for either non or dyna-salts. 77 */ 78 void dyna_salt_md5(struct db_salt *p, int comp_size); 79 80 //#define DYNA_SALT_DEBUG 81 82 #ifdef DYNA_SALT_DEBUG 83 void dyna_salt_created_fp(void *a, char *fname, int line); 84 #define dyna_salt_create(a) dyna_salt_created_fp(a,__FILE__,__LINE__) 85 void dyna_salt_remove_fp(void *a, char *fname, int line); 86 #define dyna_salt_remove(a) dyna_salt_remove_fp(a,__FILE__,__LINE__) 87 #else 88 #define dyna_salt_create(a) do {} while (0) 89 void dyna_salt_remove_fp(void *a); 90 #define dyna_salt_remove(a) dyna_salt_remove_fp(a) 91 #endif 92 93 //#undef DYNA_SALT_DEBUG 94 95 /* These 2 used in self test code. Put here to hide the ugly details */ 96 void dyna_salt_smash(void *p, char c); 97 int dyna_salt_smash_check(void *p, unsigned char c); 98 99 #endif // _DYNA_SALT_H__ 100