1 #ifndef PKZIP_H 2 #define PKZIP_H 3 4 #include "dyna_salt.h" 5 #include "crc32.h" 6 7 typedef uint64_t u64; 8 typedef uint32_t u32; 9 typedef uint16_t u16; 10 typedef uint8_t u8; 11 typedef char c8; 12 13 u64 fget64LE(FILE *fp); 14 u32 fget32LE(FILE *fp); 15 u16 fget16LE(FILE *fp); 16 17 #define MAX_PKZ_FILES 3 18 19 // These came from the gladman headers 20 #define KEY_LENGTH(mode) (8 * ((mode) & 3) + 8) 21 #define SALT_LENGTH(mode) (4 * ((mode) & 3) + 4) 22 #define KEYING_ITERATIONS 1000 23 #define PASSWORD_VERIFIER 24 #ifdef PASSWORD_VERIFIER 25 #define PWD_VER_LENGTH 2 26 #else 27 #define PWD_VER_LENGTH 0 28 #endif 29 30 #if USE_PKZIP_MAGIC 31 typedef struct zip_magic_signatures_t { 32 u8 *magic_signature[8]; 33 u8 magic_sig_len[8]; 34 u8 magic_count; 35 u8 max_len; 36 } ZIP_SIGS; 37 #endif 38 39 typedef struct zip_hash_type_t { 40 u8 *h; // at getsalt time, we leave these null. Later in setsalt, we 'fix' them 41 u16 c; 42 u16 c2; 43 u64 datlen; 44 u8 magic; // This is used as 'magic' signature type. Also, 255 is 'generic text' 45 u8 full_zip; 46 u32 compType; // the type of compression 0 or 8 47 #if USE_PKZIP_MAGIC 48 ZIP_SIGS *pSig; 49 #endif 50 } ZIP_HASH; 51 52 typedef struct zip_salt_t { 53 dyna_salt dsalt; 54 char fname[1024]; // if the zip is too large, we open the file in cmp_exact read the 55 // data a small buffer at a time. If the zip blob is small enough 56 // (under 16k), then it simply read into H[x].h at init() time. 57 // and cmp_exact does not need fname to be used. 58 long offset; // this is the offset to zip data (if we have to read from the file). 59 ZIP_HASH H[MAX_PKZ_FILES]; 60 u32 full_zip_idx; // the index (0, 1, 2) which contains the 'full zip' data. 61 // start of the dyna zip 'compared' data. 62 u32 cnt; // number of hashes 63 u32 chk_bytes; // number of bytes valid in checksum (1 or 2) 64 u32 crc32; // if a 'full' file of encr data, then this is the CRC 65 u64 compLen; // length of compressed data (whether part or full) 66 u64 deCompLen; // length of decompressed data (if full). 67 u32 compType; // the type of compression 0 or 8 68 69 u8 zip_data[1]; // we 'move' the H[x].h data to here. Then we 'fix' it up when later setting the salt. 70 } PKZ_SALT; 71 72 typedef union MY_WORD { 73 u32 u; 74 u8 c[4]; 75 } MY_WORD; 76 77 /* Here is the 'common' code */ 78 #define WINZIP_BENCHMARK_COMMENT "" 79 #define WINZIP_BENCHMARK_LENGTH 0x107 80 #define WINZIP_BINARY_SIZE 10 81 #define WINZIP_FORMAT_TAG "$zip2$" 82 #define WINZIP_FORMAT_CLOSE_TAG "$/zip2$" 83 #define WINZIP_TAG_LENGTH 6 84 85 extern int winzip_common_valid(char *ciphertext, struct fmt_main *self); 86 extern char *winzip_common_split(char *ciphertext, int index, struct fmt_main *self); 87 extern void *winzip_common_binary(char *ciphertext); 88 89 extern struct fmt_tests winzip_common_tests[]; 90 91 #endif /* PKZIP_H */ 92