From 3dc77ced14f16dfd0cfba5cc059a68f264c52d43 Mon Sep 17 00:00:00 2001 From: jsteube Date: Tue, 6 Sep 2016 11:49:26 +0200 Subject: [PATCH] More preparation for easier integration of: * https://github.com/hashcat/hashcat/pull/485 * https://github.com/hashcat/hashcat/pull/486 --- include/convert.h | 43 + include/cpu_aes.h | 2 + include/data.h | 254 + include/interface.h | 1834 +++++ include/shared.h | 1326 +--- include/types.h | 1040 +-- src/Makefile | 10 +- src/convert.c | 428 ++ src/cpu_aes.c | 44 + src/data.c | 17 + src/hashcat.c | 25 + src/interface.c | 15846 ++++++++++++++++++++++++++++++++++++++++ src/shared.c | 16290 +----------------------------------------- 13 files changed, 18636 insertions(+), 18523 deletions(-) create mode 100644 include/convert.h create mode 100644 include/data.h create mode 100644 include/interface.h create mode 100644 src/convert.c create mode 100644 src/data.c create mode 100644 src/interface.c diff --git a/include/convert.h b/include/convert.h new file mode 100644 index 000000000..2cf05d39c --- /dev/null +++ b/include/convert.h @@ -0,0 +1,43 @@ +/** + * Author......: Jens Steube + * License.....: MIT + */ + +#pragma once + +#include + +int is_valid_hex_char (const u8 c); + +u8 hex_convert (const u8 c); + +u8 hex_to_u8 (const u8 hex[2]); +u32 hex_to_u32 (const u8 hex[8]); +u64 hex_to_u64 (const u8 hex[16]); + +void bin_to_hex_lower (const u32 v, u8 hex[8]); + +u8 int_to_base32 (const u8 c); +u8 base32_to_int (const u8 c); +u8 int_to_base64 (const u8 c); +u8 base64_to_int (const u8 c); + +u8 int_to_itoa32 (const u8 c); +u8 itoa32_to_int (const u8 c); +u8 int_to_itoa64 (const u8 c); +u8 itoa64_to_int (const u8 c); + +u8 int_to_bf64 (const u8 c); +u8 bf64_to_int (const u8 c); + +u8 int_to_lotus64 (const u8 c); +u8 lotus64_to_int (const u8 c); + +int base32_decode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf); +int base32_encode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf); + +int base64_decode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf); +int base64_encode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf); + +void lowercase (u8 *buf, int len); +void uppercase (u8 *buf, int len); diff --git a/include/cpu_aes.h b/include/cpu_aes.h index 36690b001..97a6497a1 100644 --- a/include/cpu_aes.h +++ b/include/cpu_aes.h @@ -709,3 +709,5 @@ void AES_set_encrypt_key (const u8 *key, int keysize, AES_KEY *aes_key); void AES_set_decrypt_key (const u8 *key, int keysize, AES_KEY *aes_key); void AES_encrypt (AES_KEY *aes_key, const u8 *input, u8 *output); void AES_decrypt (AES_KEY *aes_key, const u8 *input, u8 *output); + +void AES128_decrypt_cbc (const u32 key[4], const u32 iv[4], const u32 in[16], u32 out[16]); diff --git a/include/data.h b/include/data.h new file mode 100644 index 000000000..699fbf76c --- /dev/null +++ b/include/data.h @@ -0,0 +1,254 @@ +/** + * Author......: Jens Steube + * License.....: MIT + */ + +#pragma once + +typedef struct +{ + /** + * threads + */ + + uint devices_status; + uint devices_cnt; + uint devices_active; + + hc_device_param_t *devices_param; + + uint shutdown_inner; + uint shutdown_outer; + + /** + * workload specific + */ + + uint hardware_power_all; + uint kernel_power_all; + u64 kernel_power_final; // we save that so that all divisions are done from the same base + + /** + * attack specific + */ + + uint wordlist_mode; + uint hashlist_mode; + uint hashlist_format; + + uint attack_mode; + uint attack_kern; + uint attack_exec; + + uint kernel_rules_cnt; + + kernel_rule_t *kernel_rules_buf; + + uint combs_mode; + uint combs_cnt; + + uint bfs_cnt; + + uint css_cnt; + cs_t *css_buf; + + cs_t *root_css_buf; + cs_t *markov_css_buf; + + char *rule_buf_l; + char *rule_buf_r; + int rule_len_l; + int rule_len_r; + + /** + * opencl library stuff + */ + + void *ocl; + + /** + * hardware watchdog + */ + + #ifdef HAVE_HWMON + void *hm_adl; + void *hm_nvml; + void *hm_nvapi; + void *hm_xnvctrl; + hm_attrs_t hm_device[DEVICES_MAX]; + #endif + + /** + * hashes + */ + + uint digests_cnt; + uint digests_done; + uint digests_saved; + + void *digests_buf; + uint *digests_shown; + uint *digests_shown_tmp; + + uint salts_cnt; + uint salts_done; + + salt_t *salts_buf; + uint *salts_shown; + + void *esalts_buf; + + uint scrypt_tmp_size; + uint scrypt_tmto_final; + + /** + * logging + */ + + uint logfile_disable; + char *logfile; + char *topid; + char *subid; + + /** + * crack-per-time + */ + + cpt_t cpt_buf[CPT_BUF]; + int cpt_pos; + time_t cpt_start; + u64 cpt_total; + + /** + * user + */ + + char *dictfile; + char *dictfile2; + char *mask; + uint maskcnt; + uint maskpos; + char *session; + char separator; + char *hashfile; + char *homedir; + char *install_dir; + char *profile_dir; + char *session_dir; + char *shared_dir; + char *outfile; + uint outfile_format; + uint outfile_autohex; + uint outfile_check_timer; + char *eff_restore_file; + char *new_restore_file; + char *induction_directory; + char *outfile_check_directory; + uint loopback; + char *loopback_file; + uint restore; + uint restore_timer; + uint restore_disable; + uint status; + uint status_timer; + uint machine_readable; + uint quiet; + uint force; + uint benchmark; + uint runtime; + uint remove; + uint remove_timer; + uint debug_mode; + char *debug_file; + uint hex_charset; + uint hex_salt; + uint hex_wordlist; + uint pw_min; + uint pw_max; + uint powertune_enable; + uint scrypt_tmto; + uint segment_size; + char *truecrypt_keyfiles; + char *veracrypt_keyfiles; + uint veracrypt_pim; + uint workload_profile; + char *custom_charset_1; + char *custom_charset_2; + char *custom_charset_3; + char *custom_charset_4; + + uint hash_mode; + uint hash_type; + uint kern_type; + uint opts_type; + uint salt_type; + uint esalt_size; + uint isSalted; + uint dgst_size; + uint opti_type; + uint dgst_pos0; + uint dgst_pos1; + uint dgst_pos2; + uint dgst_pos3; + + #ifdef HAVE_HWMON + uint gpu_temp_disable; + uint gpu_temp_abort; + uint gpu_temp_retain; + #endif + + char **rp_files; + uint rp_files_cnt; + uint rp_gen; + uint rp_gen_seed; + + FILE *pot_fp; + + /** + * used for restore + */ + + u64 skip; + u64 limit; + + restore_data_t *rd; + + u64 checkpoint_cur_words; // used for the "stop at next checkpoint" feature + + /** + * status, timer + */ + + time_t runtime_start; + time_t runtime_stop; + + time_t prepare_time; + + time_t proc_start; + time_t proc_stop; + + u64 words_cnt; + u64 words_cur; + u64 words_base; + + u64 *words_progress_done; // progress number of words done per salt + u64 *words_progress_rejected; // progress number of words rejected per salt + u64 *words_progress_restored; // progress number of words restored per salt + + hc_timer_t timer_running; // timer on current dict + hc_timer_t timer_paused; // timer on current dict + + double ms_paused; // timer on current dict + + /** + * hash_info and username + */ + + hashinfo_t **hash_info; + uint username; + + int (*sort_by_digest) (const void *, const void *); + + int (*parse_func) (char *, uint, hash_t *); + +} hc_global_data_t; diff --git a/include/interface.h b/include/interface.h new file mode 100644 index 000000000..e1be9d1c6 --- /dev/null +++ b/include/interface.h @@ -0,0 +1,1834 @@ +/** + * Authors.....: Jens Steube + * License.....: MIT + */ + +#pragma once + +#include +#include +#include +#include + +/** + * types + */ + +typedef struct +{ + uint iv[4]; + +} rar5_t; + +typedef struct +{ + int V; + int R; + int P; + + int enc_md; + + uint id_buf[8]; + uint u_buf[32]; + uint o_buf[32]; + + int id_len; + int o_len; + int u_len; + + uint rc4key[2]; + uint rc4data[2]; + +} pdf_t; + +typedef struct +{ + uint pke[25]; + uint eapol[64]; + int eapol_size; + int keyver; + u8 orig_mac1[6]; + u8 orig_mac2[6]; + u8 orig_nonce1[32]; + u8 orig_nonce2[32]; + +} wpa_t; + +typedef struct +{ + uint cry_master_buf[64]; + uint ckey_buf[64]; + uint public_key_buf[64]; + + uint cry_master_len; + uint ckey_len; + uint public_key_len; + +} bitcoin_wallet_t; + +typedef struct +{ + uint salt_buf[30]; + uint salt_len; + + uint esalt_buf[38]; + uint esalt_len; + +} sip_t; + +typedef struct +{ + uint data[384]; + +} androidfde_t; + +typedef struct +{ + uint nr_buf[16]; + uint nr_len; + + uint msg_buf[128]; + uint msg_len; + +} ikepsk_t; + +typedef struct +{ + uint user_len; + uint domain_len; + uint srvchall_len; + uint clichall_len; + + uint userdomain_buf[64]; + uint chall_buf[256]; + +} netntlm_t; + +typedef struct +{ + uint user[16]; + uint realm[16]; + uint salt[32]; + uint timestamp[16]; + uint checksum[4]; + +} krb5pa_t; + +typedef struct +{ + uint account_info[512]; + uint checksum[4]; + uint edata2[2560]; + uint edata2_len; + +} krb5tgs_t; + +typedef struct +{ + u32 version; + u32 algorithm; + + /* key-file handling */ + u32 keyfile_len; + u32 keyfile[8]; + + u32 final_random_seed[8]; + u32 transf_random_seed[8]; + u32 enc_iv[4]; + u32 contents_hash[8]; + + /* specific to version 1 */ + u32 contents_len; + u32 contents[75000]; + + /* specific to version 2 */ + u32 expected_bytes[8]; + +} keepass_t; + +typedef struct +{ + uint salt_buf[16]; + uint data_buf[112]; + uint keyfile_buf[16]; + uint signature; + +} tc_t; + +typedef struct +{ + uint salt_buf[16]; + +} pbkdf2_md5_t; + +typedef struct +{ + uint salt_buf[16]; + +} pbkdf2_sha1_t; + +typedef struct +{ + uint salt_buf[16]; + +} pbkdf2_sha256_t; + +typedef struct +{ + uint salt_buf[32]; + +} pbkdf2_sha512_t; + +typedef struct +{ + u8 cipher[1040]; + +} agilekey_t; + +typedef struct +{ + uint salt_buf[128]; + uint salt_len; + +} rakp_t; + +typedef struct +{ + uint data_len; + uint data_buf[512]; + +} cloudkey_t; + +typedef struct +{ + uint encryptedVerifier[4]; + uint encryptedVerifierHash[5]; + + uint keySize; + +} office2007_t; + +typedef struct +{ + uint encryptedVerifier[4]; + uint encryptedVerifierHash[8]; + +} office2010_t; + +typedef struct +{ + uint encryptedVerifier[4]; + uint encryptedVerifierHash[8]; + +} office2013_t; + +typedef struct +{ + uint version; + uint encryptedVerifier[4]; + uint encryptedVerifierHash[4]; + uint rc4key[2]; + +} oldoffice01_t; + +typedef struct +{ + uint version; + uint encryptedVerifier[4]; + uint encryptedVerifierHash[5]; + uint rc4key[2]; + +} oldoffice34_t; + +typedef struct +{ + u32 salt_buf[128]; + u32 salt_len; + + u32 pc_digest[5]; + u32 pc_offset; + +} pstoken_t; + +typedef struct +{ + u32 type; + u32 mode; + u32 magic; + u32 salt_len; + u32 salt_buf[4]; + u32 verify_bytes; + u32 compress_length; + u32 data_len; + u32 data_buf[2048]; + u32 auth_len; + u32 auth_buf[4]; + +} zip2_t; + +typedef struct +{ + uint salt_buf[32]; + +} win8phone_t; + +typedef struct +{ + char signature[4]; + u32 salt_buf[8]; + u32 iterations; + u32 hash_buf[8]; + +} psafe3_t; + +typedef struct +{ + uint digest[4]; + uint out[4]; + +} pdf14_tmp_t; + +typedef struct +{ + union + { + uint dgst32[16]; + u64 dgst64[8]; + } d; + + uint dgst_len; + uint W_len; + +} pdf17l8_tmp_t; + +typedef struct +{ + uint digest_buf[4]; + +} phpass_tmp_t; + +typedef struct +{ + uint digest_buf[4]; + +} md5crypt_tmp_t; + +typedef struct +{ + u64 l_alt_result[8]; + + u64 l_p_bytes[2]; + u64 l_s_bytes[2]; + +} sha512crypt_tmp_t; + +typedef struct +{ + uint alt_result[8]; + + uint p_bytes[4]; + uint s_bytes[4]; + +} sha256crypt_tmp_t; + +typedef struct +{ + uint ipad[5]; + uint opad[5]; + + uint dgst[10]; + uint out[10]; + +} wpa_tmp_t; + +typedef struct +{ + u64 dgst[8]; + +} bitcoin_wallet_tmp_t; + +typedef struct +{ + uint ipad[5]; + uint opad[5]; + + uint dgst[5]; + uint out[4]; + +} dcc2_tmp_t; + +typedef struct +{ + uint E[18]; + + uint P[18]; + + uint S0[256]; + uint S1[256]; + uint S2[256]; + uint S3[256]; + +} bcrypt_tmp_t; + +typedef struct +{ + uint digest[2]; + + uint P[18]; + + uint S0[256]; + uint S1[256]; + uint S2[256]; + uint S3[256]; + +} pwsafe2_tmp_t; + +typedef struct +{ + uint digest_buf[8]; + +} pwsafe3_tmp_t; + +typedef struct +{ + uint digest_buf[5]; + +} androidpin_tmp_t; + +typedef struct +{ + uint ipad[5]; + uint opad[5]; + + uint dgst[10]; + uint out[10]; + +} androidfde_tmp_t; + +typedef struct +{ + uint ipad[16]; + uint opad[16]; + + uint dgst[64]; + uint out[64]; + +} tc_tmp_t; + +typedef struct +{ + u64 ipad[8]; + u64 opad[8]; + + u64 dgst[32]; + u64 out[32]; + +} tc64_tmp_t; + +typedef struct +{ + uint ipad[5]; + uint opad[5]; + + uint dgst[5]; + uint out[5]; + +} agilekey_tmp_t; + +typedef struct +{ + uint ipad[5]; + uint opad[5]; + + uint dgst1[5]; + uint out1[5]; + + uint dgst2[5]; + uint out2[5]; + +} mywallet_tmp_t; + +typedef struct +{ + uint ipad[5]; + uint opad[5]; + + uint dgst[5]; + uint out[5]; + +} sha1aix_tmp_t; + +typedef struct +{ + uint ipad[8]; + uint opad[8]; + + uint dgst[8]; + uint out[8]; + +} sha256aix_tmp_t; + +typedef struct +{ + u64 ipad[8]; + u64 opad[8]; + + u64 dgst[8]; + u64 out[8]; + +} sha512aix_tmp_t; + +typedef struct +{ + uint ipad[8]; + uint opad[8]; + + uint dgst[8]; + uint out[8]; + +} lastpass_tmp_t; + +typedef struct +{ + u64 digest_buf[8]; + +} drupal7_tmp_t; + +typedef struct +{ + uint ipad[5]; + uint opad[5]; + + uint dgst[5]; + uint out[5]; + +} lotus8_tmp_t; + +typedef struct +{ + uint out[5]; + +} office2007_tmp_t; + +typedef struct +{ + uint out[5]; + +} office2010_tmp_t; + +typedef struct +{ + u64 out[8]; + +} office2013_tmp_t; + +typedef struct +{ + uint digest_buf[5]; + +} saph_sha1_tmp_t; + +typedef struct +{ + u32 ipad[4]; + u32 opad[4]; + + u32 dgst[32]; + u32 out[32]; + +} pbkdf2_md5_tmp_t; + +typedef struct +{ + u32 ipad[5]; + u32 opad[5]; + + u32 dgst[32]; + u32 out[32]; + +} pbkdf2_sha1_tmp_t; + +typedef struct +{ + u32 ipad[8]; + u32 opad[8]; + + u32 dgst[32]; + u32 out[32]; + +} pbkdf2_sha256_tmp_t; + +typedef struct +{ + u64 ipad[8]; + u64 opad[8]; + + u64 dgst[16]; + u64 out[16]; + +} pbkdf2_sha512_tmp_t; + +typedef struct +{ + u64 out[8]; + +} ecryptfs_tmp_t; + +typedef struct +{ + u64 ipad[8]; + u64 opad[8]; + + u64 dgst[16]; + u64 out[16]; + +} oraclet_tmp_t; + +typedef struct +{ + uint block[16]; + + uint dgst[8]; + + uint block_len; + uint final_len; + +} seven_zip_tmp_t; + +typedef struct +{ + uint Kc[16]; + uint Kd[16]; + + uint iv[2]; + +} bsdicrypt_tmp_t; + +typedef struct +{ + uint dgst[17][5]; + +} rar3_tmp_t; + +typedef struct +{ + uint user[16]; + +} cram_md5_t; + +typedef struct +{ + uint iv_buf[4]; + uint iv_len; + + uint salt_buf[4]; + uint salt_len; + + uint crc; + + uint data_buf[96]; + uint data_len; + + uint unpack_size; + +} seven_zip_t; + +typedef struct +{ + u32 KEK[4]; + u32 lsb[4]; + u32 cipher[4]; + +} axcrypt_tmp_t; + +typedef struct +{ + u32 tmp_digest[8]; + +} keepass_tmp_t; + +typedef struct +{ + u32 random[2]; + u32 hash[5]; + u32 salt[5]; // unused, but makes better valid check + u32 iv[2]; // unused, but makes better valid check + +} psafe2_hdr; + +typedef struct +{ + char essid[36]; + + u8 mac1[6]; + u8 mac2[6]; + u8 nonce1[32]; + u8 nonce2[32]; + + u8 eapol[256]; + int eapol_size; + + int keyver; + u8 keymic[16]; + +} hccap_t; + +/** + * parser + */ + +static const char PA_000[] = "OK"; +static const char PA_001[] = "Ignored due to comment"; +static const char PA_002[] = "Ignored due to zero length"; +static const char PA_003[] = "Line-length exception"; +static const char PA_004[] = "Hash-length exception"; +static const char PA_005[] = "Hash-value exception"; +static const char PA_006[] = "Salt-length exception"; +static const char PA_007[] = "Salt-value exception"; +static const char PA_008[] = "Salt-iteration count exception"; +static const char PA_009[] = "Separator unmatched"; +static const char PA_010[] = "Signature unmatched"; +static const char PA_011[] = "Invalid hccap filesize"; +static const char PA_012[] = "Invalid eapol size"; +static const char PA_013[] = "Invalid psafe2 filesize"; +static const char PA_014[] = "Invalid psafe3 filesize"; +static const char PA_015[] = "Invalid truecrypt filesize"; +static const char PA_016[] = "Invalid veracrypt filesize"; +static const char PA_017[] = "Invalid SIP directive, only MD5 is supported"; +static const char PA_255[] = "Unknown error"; + +typedef enum parser_rc +{ + PARSER_OK = 0, + PARSER_COMMENT = -1, + PARSER_GLOBAL_ZERO = -2, + PARSER_GLOBAL_LENGTH = -3, + PARSER_HASH_LENGTH = -4, + PARSER_HASH_VALUE = -5, + PARSER_SALT_LENGTH = -6, + PARSER_SALT_VALUE = -7, + PARSER_SALT_ITERATION = -8, + PARSER_SEPARATOR_UNMATCHED = -9, + PARSER_SIGNATURE_UNMATCHED = -10, + PARSER_HCCAP_FILE_SIZE = -11, + PARSER_HCCAP_EAPOL_SIZE = -12, + PARSER_PSAFE2_FILE_SIZE = -13, + PARSER_PSAFE3_FILE_SIZE = -14, + PARSER_TC_FILE_SIZE = -15, + PARSER_VC_FILE_SIZE = -16, + PARSER_SIP_AUTH_DIRECTIVE = -17, + PARSER_UNKNOWN_ERROR = -255 + +} parser_rc_t; + +/** + * hashtypes cleartext + */ + +static const char HT_00000[] = "MD5"; +static const char HT_00010[] = "md5($pass.$salt)"; +static const char HT_00020[] = "md5($salt.$pass)"; +static const char HT_00030[] = "md5(unicode($pass).$salt)"; +static const char HT_00040[] = "md5($salt.unicode($pass))"; +static const char HT_00050[] = "HMAC-MD5 (key = $pass)"; +static const char HT_00060[] = "HMAC-MD5 (key = $salt)"; +static const char HT_00100[] = "SHA1"; +static const char HT_00110[] = "sha1($pass.$salt)"; +static const char HT_00120[] = "sha1($salt.$pass)"; +static const char HT_00130[] = "sha1(unicode($pass).$salt)"; +static const char HT_00140[] = "sha1($salt.unicode($pass))"; +static const char HT_00150[] = "HMAC-SHA1 (key = $pass)"; +static const char HT_00160[] = "HMAC-SHA1 (key = $salt)"; +static const char HT_00200[] = "MySQL323"; +static const char HT_00300[] = "MySQL4.1/MySQL5"; +static const char HT_00400[] = "phpass, MD5(Wordpress), MD5(phpBB3), MD5(Joomla)"; +static const char HT_00500[] = "md5crypt, MD5(Unix), FreeBSD MD5, Cisco-IOS MD5"; +static const char HT_00501[] = "Juniper IVE"; +static const char HT_00900[] = "MD4"; +static const char HT_00910[] = "md4($pass.$salt)"; +static const char HT_01000[] = "NTLM"; +static const char HT_01100[] = "Domain Cached Credentials (DCC), MS Cache"; +static const char HT_01400[] = "SHA256"; +static const char HT_01410[] = "sha256($pass.$salt)"; +static const char HT_01420[] = "sha256($salt.$pass)"; +static const char HT_01430[] = "sha256(unicode($pass).$salt)"; +static const char HT_01440[] = "sha256($salt.$pass)"; +static const char HT_01450[] = "HMAC-SHA256 (key = $pass)"; +static const char HT_01460[] = "HMAC-SHA256 (key = $salt)"; +static const char HT_01500[] = "descrypt, DES(Unix), Traditional DES"; +static const char HT_01600[] = "md5apr1, MD5(APR), Apache MD5"; +static const char HT_01700[] = "SHA512"; +static const char HT_01710[] = "sha512($pass.$salt)"; +static const char HT_01720[] = "sha512($salt.$pass)"; +static const char HT_01730[] = "sha512(unicode($pass).$salt)"; +static const char HT_01740[] = "sha512($salt.unicode($pass))"; +static const char HT_01750[] = "HMAC-SHA512 (key = $pass)"; +static const char HT_01760[] = "HMAC-SHA512 (key = $salt)"; +static const char HT_01800[] = "sha512crypt, SHA512(Unix)"; +static const char HT_02100[] = "Domain Cached Credentials 2 (DCC2), MS Cache 2"; +static const char HT_02400[] = "Cisco-PIX MD5"; +static const char HT_02410[] = "Cisco-ASA MD5"; +static const char HT_02500[] = "WPA/WPA2"; +static const char HT_02600[] = "Double MD5"; +static const char HT_03000[] = "LM"; +static const char HT_03100[] = "Oracle H: Type (Oracle 7+)"; +static const char HT_03200[] = "bcrypt, Blowfish(OpenBSD)"; +static const char HT_03710[] = "md5($salt.md5($pass))"; +static const char HT_03711[] = "Mediawiki B type"; +static const char HT_03800[] = "md5($salt.$pass.$salt)"; +static const char HT_04300[] = "md5(strtoupper(md5($pass)))"; +static const char HT_04400[] = "md5(sha1($pass))"; +static const char HT_04500[] = "Double SHA1"; +static const char HT_04700[] = "sha1(md5($pass))"; +static const char HT_04800[] = "MD5(Chap), iSCSI CHAP authentication"; +static const char HT_04900[] = "sha1($salt.$pass.$salt)"; +static const char HT_05000[] = "SHA-3(Keccak)"; +static const char HT_05100[] = "Half MD5"; +static const char HT_05200[] = "Password Safe v3"; +static const char HT_05300[] = "IKE-PSK MD5"; +static const char HT_05400[] = "IKE-PSK SHA1"; +static const char HT_05500[] = "NetNTLMv1-VANILLA / NetNTLMv1+ESS"; +static const char HT_05600[] = "NetNTLMv2"; +static const char HT_05700[] = "Cisco-IOS SHA256"; +static const char HT_05800[] = "Android PIN"; +static const char HT_06000[] = "RipeMD160"; +static const char HT_06100[] = "Whirlpool"; +static const char HT_06300[] = "AIX {smd5}"; +static const char HT_06400[] = "AIX {ssha256}"; +static const char HT_06500[] = "AIX {ssha512}"; +static const char HT_06600[] = "1Password, agilekeychain"; +static const char HT_06700[] = "AIX {ssha1}"; +static const char HT_06800[] = "Lastpass"; +static const char HT_06900[] = "GOST R 34.11-94"; +static const char HT_07100[] = "OSX v10.8+"; +static const char HT_07200[] = "GRUB 2"; +static const char HT_07300[] = "IPMI2 RAKP HMAC-SHA1"; +static const char HT_07400[] = "sha256crypt, SHA256(Unix)"; +static const char HT_07500[] = "Kerberos 5 AS-REQ Pre-Auth etype 23"; +static const char HT_07600[] = "Redmine Project Management Web App"; +static const char HT_07700[] = "SAP CODVN B (BCODE)"; +static const char HT_07800[] = "SAP CODVN F/G (PASSCODE)"; +static const char HT_07900[] = "Drupal7"; +static const char HT_08000[] = "Sybase ASE"; +static const char HT_08100[] = "Citrix NetScaler"; +static const char HT_08200[] = "1Password, cloudkeychain"; +static const char HT_08300[] = "DNSSEC (NSEC3)"; +static const char HT_08400[] = "WBB3, Woltlab Burning Board 3"; +static const char HT_08500[] = "RACF"; +static const char HT_08600[] = "Lotus Notes/Domino 5"; +static const char HT_08700[] = "Lotus Notes/Domino 6"; +static const char HT_08800[] = "Android FDE <= 4.3"; +static const char HT_08900[] = "scrypt"; +static const char HT_09000[] = "Password Safe v2"; +static const char HT_09100[] = "Lotus Notes/Domino 8"; +static const char HT_09200[] = "Cisco $8$"; +static const char HT_09300[] = "Cisco $9$"; +static const char HT_09400[] = "Office 2007"; +static const char HT_09500[] = "Office 2010"; +static const char HT_09600[] = "Office 2013"; +static const char HT_09700[] = "MS Office <= 2003 MD5 + RC4, oldoffice$0, oldoffice$1"; +static const char HT_09710[] = "MS Office <= 2003 MD5 + RC4, collision-mode #1"; +static const char HT_09720[] = "MS Office <= 2003 MD5 + RC4, collision-mode #2"; +static const char HT_09800[] = "MS Office <= 2003 SHA1 + RC4, oldoffice$3, oldoffice$4"; +static const char HT_09810[] = "MS Office <= 2003 SHA1 + RC4, collision-mode #1"; +static const char HT_09820[] = "MS Office <= 2003 SHA1 + RC4, collision-mode #2"; +static const char HT_09900[] = "Radmin2"; +static const char HT_10000[] = "Django (PBKDF2-SHA256)"; +static const char HT_10100[] = "SipHash"; +static const char HT_10200[] = "Cram MD5"; +static const char HT_10300[] = "SAP CODVN H (PWDSALTEDHASH) iSSHA-1"; +static const char HT_10400[] = "PDF 1.1 - 1.3 (Acrobat 2 - 4)"; +static const char HT_10410[] = "PDF 1.1 - 1.3 (Acrobat 2 - 4) + collider-mode #1"; +static const char HT_10420[] = "PDF 1.1 - 1.3 (Acrobat 2 - 4) + collider-mode #2"; +static const char HT_10500[] = "PDF 1.4 - 1.6 (Acrobat 5 - 8)"; +static const char HT_10600[] = "PDF 1.7 Level 3 (Acrobat 9)"; +static const char HT_10700[] = "PDF 1.7 Level 8 (Acrobat 10 - 11)"; +static const char HT_10800[] = "SHA384"; +static const char HT_10900[] = "PBKDF2-HMAC-SHA256"; +static const char HT_11000[] = "PrestaShop"; +static const char HT_11100[] = "PostgreSQL Challenge-Response Authentication (MD5)"; +static const char HT_11200[] = "MySQL Challenge-Response Authentication (SHA1)"; +static const char HT_11300[] = "Bitcoin/Litecoin wallet.dat"; +static const char HT_11400[] = "SIP digest authentication (MD5)"; +static const char HT_11500[] = "CRC32"; +static const char HT_11600[] = "7-Zip"; +static const char HT_11700[] = "GOST R 34.11-2012 (Streebog) 256-bit"; +static const char HT_11800[] = "GOST R 34.11-2012 (Streebog) 512-bit"; +static const char HT_11900[] = "PBKDF2-HMAC-MD5"; +static const char HT_12000[] = "PBKDF2-HMAC-SHA1"; +static const char HT_12100[] = "PBKDF2-HMAC-SHA512"; +static const char HT_12200[] = "eCryptfs"; +static const char HT_12300[] = "Oracle T: Type (Oracle 12+)"; +static const char HT_12400[] = "BSDiCrypt, Extended DES"; +static const char HT_12500[] = "RAR3-hp"; +static const char HT_12600[] = "ColdFusion 10+"; +static const char HT_12700[] = "Blockchain, My Wallet"; +static const char HT_12800[] = "MS-AzureSync PBKDF2-HMAC-SHA256"; +static const char HT_12900[] = "Android FDE (Samsung DEK)"; +static const char HT_13000[] = "RAR5"; +static const char HT_13100[] = "Kerberos 5 TGS-REP etype 23"; +static const char HT_13200[] = "AxCrypt"; +static const char HT_13300[] = "AxCrypt in memory SHA1"; +static const char HT_13400[] = "Keepass 1 (AES/Twofish) and Keepass 2 (AES)"; +static const char HT_13500[] = "PeopleSoft PS_TOKEN"; +static const char HT_13600[] = "WinZip"; +static const char HT_13800[] = "Windows 8+ phone PIN/Password"; +static const char HT_13900[] = "OpenCart"; +static const char HT_14000[] = "DES (PT = $salt, key = $pass)"; +static const char HT_14100[] = "3DES (PT = $salt, key = $pass)"; + +static const char HT_00011[] = "Joomla < 2.5.18"; +static const char HT_00012[] = "PostgreSQL"; +static const char HT_00021[] = "osCommerce, xt:Commerce"; +static const char HT_00022[] = "Juniper Netscreen/SSG (ScreenOS)"; +static const char HT_00023[] = "Skype"; +static const char HT_00101[] = "SHA-1(Base64), nsldap, Netscape LDAP SHA"; +static const char HT_00111[] = "SSHA-1(Base64), nsldaps, Netscape LDAP SSHA"; +static const char HT_00112[] = "Oracle S: Type (Oracle 11+)"; +static const char HT_00121[] = "SMF > v1.1"; +static const char HT_00122[] = "OSX v10.4, v10.5, v10.6"; +static const char HT_00124[] = "Django (SHA-1)"; +static const char HT_00125[] = "ArubaOS"; +static const char HT_00131[] = "MSSQL(2000)"; +static const char HT_00132[] = "MSSQL(2005)"; +static const char HT_00133[] = "PeopleSoft"; +static const char HT_00141[] = "EPiServer 6.x < v4"; +static const char HT_01421[] = "hMailServer"; +static const char HT_01441[] = "EPiServer 6.x > v4"; +static const char HT_01711[] = "SSHA-512(Base64), LDAP {SSHA512}"; +static const char HT_01722[] = "OSX v10.7"; +static const char HT_01731[] = "MSSQL(2012)"; +static const char HT_02611[] = "vBulletin < v3.8.5"; +static const char HT_02612[] = "PHPS"; +static const char HT_02711[] = "vBulletin > v3.8.5"; +static const char HT_02811[] = "IPB2+, MyBB1.2+"; +static const char HT_06211[] = "TrueCrypt PBKDF2-HMAC-RipeMD160 + XTS 512 bit"; +static const char HT_06212[] = "TrueCrypt PBKDF2-HMAC-RipeMD160 + XTS 1024 bit"; +static const char HT_06213[] = "TrueCrypt PBKDF2-HMAC-RipeMD160 + XTS 1536 bit"; +static const char HT_06221[] = "TrueCrypt PBKDF2-HMAC-SHA512 + XTS 512 bit"; +static const char HT_06222[] = "TrueCrypt PBKDF2-HMAC-SHA512 + XTS 1024 bit"; +static const char HT_06223[] = "TrueCrypt PBKDF2-HMAC-SHA512 + XTS 1536 bit"; +static const char HT_06231[] = "TrueCrypt PBKDF2-HMAC-Whirlpool + XTS 512 bit"; +static const char HT_06232[] = "TrueCrypt PBKDF2-HMAC-Whirlpool + XTS 1024 bit"; +static const char HT_06233[] = "TrueCrypt PBKDF2-HMAC-Whirlpool + XTS 1536 bit"; +static const char HT_06241[] = "TrueCrypt PBKDF2-HMAC-RipeMD160 + XTS 512 bit + boot-mode"; +static const char HT_06242[] = "TrueCrypt PBKDF2-HMAC-RipeMD160 + XTS 1024 bit + boot-mode"; +static const char HT_06243[] = "TrueCrypt PBKDF2-HMAC-RipeMD160 + XTS 1536 bit + boot-mode"; +static const char HT_13711[] = "VeraCrypt PBKDF2-HMAC-RipeMD160 + XTS 512 bit"; +static const char HT_13712[] = "VeraCrypt PBKDF2-HMAC-RipeMD160 + XTS 1024 bit"; +static const char HT_13713[] = "VeraCrypt PBKDF2-HMAC-RipeMD160 + XTS 1536 bit"; +static const char HT_13721[] = "VeraCrypt PBKDF2-HMAC-SHA512 + XTS 512 bit"; +static const char HT_13722[] = "VeraCrypt PBKDF2-HMAC-SHA512 + XTS 1024 bit"; +static const char HT_13723[] = "VeraCrypt PBKDF2-HMAC-SHA512 + XTS 1536 bit"; +static const char HT_13731[] = "VeraCrypt PBKDF2-HMAC-Whirlpool + XTS 512 bit"; +static const char HT_13732[] = "VeraCrypt PBKDF2-HMAC-Whirlpool + XTS 1024 bit"; +static const char HT_13733[] = "VeraCrypt PBKDF2-HMAC-Whirlpool + XTS 1536 bit"; +static const char HT_13741[] = "VeraCrypt PBKDF2-HMAC-RipeMD160 + XTS 512 bit + boot-mode"; +static const char HT_13742[] = "VeraCrypt PBKDF2-HMAC-RipeMD160 + XTS 1024 bit + boot-mode"; +static const char HT_13743[] = "VeraCrypt PBKDF2-HMAC-RipeMD160 + XTS 1536 bit + boot-mode"; +static const char HT_13751[] = "VeraCrypt PBKDF2-HMAC-SHA256 + XTS 512 bit"; +static const char HT_13752[] = "VeraCrypt PBKDF2-HMAC-SHA256 + XTS 1024 bit"; +static const char HT_13753[] = "VeraCrypt PBKDF2-HMAC-SHA256 + XTS 1536 bit"; +static const char HT_13761[] = "VeraCrypt PBKDF2-HMAC-SHA256 + XTS 512 bit + boot-mode"; +static const char HT_13762[] = "VeraCrypt PBKDF2-HMAC-SHA256 + XTS 1024 bit + boot-mode"; +static const char HT_13763[] = "VeraCrypt PBKDF2-HMAC-SHA256 + XTS 1536 bit + boot-mode"; + +typedef enum display_len +{ + DISPLAY_LEN_MIN_0 = 32, + DISPLAY_LEN_MAX_0 = 32, + DISPLAY_LEN_MIN_10 = 32 + 1 + 0, + DISPLAY_LEN_MAX_10 = 32 + 1 + 51, + DISPLAY_LEN_MIN_10H = 32 + 1 + 0, + DISPLAY_LEN_MAX_10H = 32 + 1 + 102, + DISPLAY_LEN_MIN_20 = 32 + 1 + 0, + DISPLAY_LEN_MAX_20 = 32 + 1 + 31, + DISPLAY_LEN_MIN_20H = 32 + 1 + 0, + DISPLAY_LEN_MAX_20H = 32 + 1 + 62, + DISPLAY_LEN_MIN_50 = 32 + 1 + 0, + DISPLAY_LEN_MAX_50 = 32 + 1 + 51, + DISPLAY_LEN_MIN_50H = 32 + 1 + 0, + DISPLAY_LEN_MAX_50H = 32 + 1 + 102, + DISPLAY_LEN_MIN_100 = 40, + DISPLAY_LEN_MAX_100 = 40, + DISPLAY_LEN_MIN_110 = 40 + 1 + 0, + DISPLAY_LEN_MAX_110 = 40 + 1 + 51, + DISPLAY_LEN_MIN_110H = 40 + 1 + 0, + DISPLAY_LEN_MAX_110H = 40 + 1 + 102, + DISPLAY_LEN_MIN_120 = 40 + 1 + 0, + DISPLAY_LEN_MAX_120 = 40 + 1 + 31, + DISPLAY_LEN_MIN_120H = 40 + 1 + 0, + DISPLAY_LEN_MAX_120H = 40 + 1 + 62, + DISPLAY_LEN_MIN_150 = 40 + 1 + 0, + DISPLAY_LEN_MAX_150 = 40 + 1 + 51, + DISPLAY_LEN_MIN_150H = 40 + 1 + 0, + DISPLAY_LEN_MAX_150H = 40 + 1 + 102, + DISPLAY_LEN_MIN_200 = 16, + DISPLAY_LEN_MAX_200 = 16, + DISPLAY_LEN_MIN_300 = 40, + DISPLAY_LEN_MAX_300 = 40, + DISPLAY_LEN_MIN_400 = 34, + DISPLAY_LEN_MAX_400 = 34, + DISPLAY_LEN_MIN_500 = 3 + 1 + 0 + 22, + DISPLAY_LEN_MIN_501 = 104, + DISPLAY_LEN_MAX_500 = 3 + 1 + 8 + 22, + DISPLAY_LEN_MAX_501 = 104, + DISPLAY_LEN_MIN_900 = 32, + DISPLAY_LEN_MAX_900 = 32, + DISPLAY_LEN_MIN_910 = 32 + 1 + 0, + DISPLAY_LEN_MAX_910 = 32 + 1 + 51, + DISPLAY_LEN_MIN_910H = 32 + 1 + 0, + DISPLAY_LEN_MAX_910H = 32 + 1 + 102, + DISPLAY_LEN_MIN_1000 = 32, + DISPLAY_LEN_MAX_1000 = 32, + DISPLAY_LEN_MIN_1100 = 32 + 1 + 0, + DISPLAY_LEN_MAX_1100 = 32 + 1 + 19, + DISPLAY_LEN_MIN_1100H = 32 + 1 + 0, + DISPLAY_LEN_MAX_1100H = 32 + 1 + 38, + DISPLAY_LEN_MIN_1400 = 64, + DISPLAY_LEN_MAX_1400 = 64, + DISPLAY_LEN_MIN_1410 = 64 + 1 + 0, + DISPLAY_LEN_MAX_1410 = 64 + 1 + 51, + DISPLAY_LEN_MIN_1410H = 64 + 1 + 0, + DISPLAY_LEN_MAX_1410H = 64 + 1 + 102, + DISPLAY_LEN_MIN_1420 = 64 + 1 + 0, + DISPLAY_LEN_MAX_1420 = 64 + 1 + 16, + DISPLAY_LEN_MIN_1420H = 64 + 1 + 0, + DISPLAY_LEN_MAX_1420H = 64 + 1 + 32, + DISPLAY_LEN_MIN_1421 = 70, + DISPLAY_LEN_MAX_1421 = 70, + DISPLAY_LEN_MIN_1450 = 64 + 1 + 0, + DISPLAY_LEN_MAX_1450 = 64 + 1 + 51, + DISPLAY_LEN_MIN_1450H = 64 + 1 + 0, + DISPLAY_LEN_MAX_1450H = 64 + 1 + 102, + DISPLAY_LEN_MIN_1500 = 13, + DISPLAY_LEN_MAX_1500 = 13, + DISPLAY_LEN_MIN_1600 = 29 + 0, + DISPLAY_LEN_MAX_1600 = 29 + 8, + DISPLAY_LEN_MIN_1700 = 128, + DISPLAY_LEN_MAX_1700 = 128, + DISPLAY_LEN_MIN_1710 = 128 + 1 + 0, + DISPLAY_LEN_MAX_1710 = 128 + 1 + 51, + DISPLAY_LEN_MIN_1710H = 128 + 1 + 0, + DISPLAY_LEN_MAX_1710H = 128 + 1 + 102, + DISPLAY_LEN_MIN_1720 = 128 + 1 + 0, + DISPLAY_LEN_MAX_1720 = 128 + 1 + 16, + DISPLAY_LEN_MIN_1720H = 128 + 1 + 0, + DISPLAY_LEN_MAX_1720H = 128 + 1 + 32, + DISPLAY_LEN_MIN_1730 = 128 + 1 + 0, + DISPLAY_LEN_MAX_1730 = 128 + 1 + 16, + DISPLAY_LEN_MIN_1731 = 128 + 6 + 0, + DISPLAY_LEN_MAX_1731 = 128 + 6 + 16, + DISPLAY_LEN_MIN_1740 = 128 + 1 + 0, + DISPLAY_LEN_MAX_1740 = 128 + 1 + 16, + DISPLAY_LEN_MIN_1750 = 128 + 1 + 0, + DISPLAY_LEN_MAX_1750 = 128 + 1 + 51, + DISPLAY_LEN_MIN_1750H = 128 + 1 + 0, + DISPLAY_LEN_MAX_1750H = 128 + 1 + 102, + DISPLAY_LEN_MIN_1800 = 90 + 0, + DISPLAY_LEN_MAX_1800 = 90 + 16, + DISPLAY_LEN_MIN_2100 = 6 + 1 + 1 + 32 + 1 + 0, + DISPLAY_LEN_MAX_2100 = 6 + 5 + 1 + 32 + 1 + 19, + DISPLAY_LEN_MIN_2100H = 6 + 1 + 1 + 32 + 1 + 0, + DISPLAY_LEN_MAX_2100H = 6 + 5 + 1 + 32 + 1 + 38, + DISPLAY_LEN_MIN_2400 = 16, + DISPLAY_LEN_MAX_2400 = 16, + DISPLAY_LEN_MIN_2410 = 16 + 1 + 0, + DISPLAY_LEN_MAX_2410 = 16 + 1 + 16, + DISPLAY_LEN_MIN_2410H = 16 + 1 + 0, + DISPLAY_LEN_MAX_2410H = 16 + 1 + 32, + DISPLAY_LEN_MIN_2500 = 64 + 1 + 0, + DISPLAY_LEN_MAX_2500 = 64 + 1 + 15, + DISPLAY_LEN_MIN_2600 = 32, + DISPLAY_LEN_MAX_2600 = 32, + DISPLAY_LEN_MIN_3000 = 16, + DISPLAY_LEN_MAX_3000 = 16, + DISPLAY_LEN_MIN_3100 = 16 + 1 + 0, + DISPLAY_LEN_MAX_3100 = 16 + 1 + 30, + DISPLAY_LEN_MIN_3100H = 16 + 1 + 0, + DISPLAY_LEN_MAX_3100H = 16 + 1 + 60, + DISPLAY_LEN_MIN_3200 = 60, + DISPLAY_LEN_MAX_3200 = 60, + DISPLAY_LEN_MIN_3711 = 3 + 0 + 1 + 32, + DISPLAY_LEN_MAX_3711 = 3 + 31 + 1 + 32, + DISPLAY_LEN_MIN_4300 = 32, + DISPLAY_LEN_MAX_4300 = 32, + DISPLAY_LEN_MIN_4800 = 32 + 1 + 32 + 1 + 2, + DISPLAY_LEN_MAX_4800 = 32 + 1 + 32 + 1 + 2, + DISPLAY_LEN_MIN_5000 = 16, + DISPLAY_LEN_MAX_5000 = 400, + DISPLAY_LEN_MIN_5100 = 16, + DISPLAY_LEN_MAX_5100 = 16, + DISPLAY_LEN_MIN_5300 = 48, + DISPLAY_LEN_MAX_5300 = 1024, + DISPLAY_LEN_MIN_5400 = 56, + DISPLAY_LEN_MAX_5400 = 1024, + DISPLAY_LEN_MIN_5500 = 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 48 + 1 + 16, + DISPLAY_LEN_MAX_5500 = 60 + 1 + 0 + 1 + 45 + 1 + 48 + 1 + 48 + 1 + 16, + DISPLAY_LEN_MIN_5600 = 1 + 1 + 0 + 1 + 1 + 1 + 16 + 1 + 32 + 1 + 1, + DISPLAY_LEN_MAX_5600 = 60 + 1 + 0 + 1 + 45 + 1 + 16 + 1 + 32 + 1 + 1024, + DISPLAY_LEN_MIN_5700 = 43, + DISPLAY_LEN_MAX_5700 = 43, + DISPLAY_LEN_MIN_5800 = 40 + 1 + 1, + DISPLAY_LEN_MAX_5800 = 40 + 1 + 16, + DISPLAY_LEN_MIN_6000 = 40, + DISPLAY_LEN_MAX_6000 = 40, + DISPLAY_LEN_MIN_6100 = 128, + DISPLAY_LEN_MAX_6100 = 128, + DISPLAY_LEN_MIN_6300 = 6 + 1 + 8 + 22, + DISPLAY_LEN_MAX_6300 = 6 + 1 + 48 + 22, + DISPLAY_LEN_MIN_6400 = 9 + 2 + 1 + 16 + 1 + 43, + DISPLAY_LEN_MAX_6400 = 9 + 2 + 1 + 48 + 1 + 43, + DISPLAY_LEN_MIN_6500 = 9 + 2 + 1 + 16 + 1 + 86, + DISPLAY_LEN_MAX_6500 = 9 + 2 + 1 + 48 + 1 + 86, + DISPLAY_LEN_MIN_6600 = 1 + 1 + 16 + 1 + 2080, + DISPLAY_LEN_MAX_6600 = 6 + 1 + 16 + 1 + 2080, + DISPLAY_LEN_MIN_6700 = 7 + 2 + 1 + 16 + 1 + 27, + DISPLAY_LEN_MAX_6700 = 7 + 2 + 1 + 48 + 1 + 27, + DISPLAY_LEN_MIN_6800 = 32 + 1 + 1 + 1 + 0, + DISPLAY_LEN_MAX_6800 = 32 + 1 + 5 + 1 + 32, + DISPLAY_LEN_MIN_6900 = 64, + DISPLAY_LEN_MAX_6900 = 64, + DISPLAY_LEN_MIN_7100 = 4 + 2 + 1 + 64 + 1 + 128, + DISPLAY_LEN_MAX_7100 = 4 + 5 + 1 + 64 + 1 + 128, + DISPLAY_LEN_MIN_7200 = 19 + 1 + 1 + 1 + 128, + DISPLAY_LEN_MAX_7200 = 19 + 5 + 1 + 224 + 128, + DISPLAY_LEN_MIN_7300 = 64 + 1 + 40, + DISPLAY_LEN_MAX_7300 = 512 + 1 + 40, + DISPLAY_LEN_MIN_7400 = 47 + 0, + DISPLAY_LEN_MAX_7400 = 47 + 16, + DISPLAY_LEN_MIN_7500 = 1 + 6 + 1 + 2 + 1 + 0 + 1 + 0 + 1 + 0 + 1 + 72 + 32, + DISPLAY_LEN_MAX_7500 = 1 + 6 + 1 + 2 + 1 + 64 + 1 + 64 + 1 + 128 + 1 + 72 + 32, + DISPLAY_LEN_MIN_7700 = 1 + 1 + 16, + DISPLAY_LEN_MAX_7700 = 40 + 1 + 16, + DISPLAY_LEN_MIN_7800 = 1 + 1 + 40, + DISPLAY_LEN_MAX_7800 = 40 + 1 + 40, + DISPLAY_LEN_MIN_7900 = 3 + 1 + 8 + 43, + DISPLAY_LEN_MAX_7900 = 3 + 1 + 8 + 43, + DISPLAY_LEN_MIN_8000 = 2 + 4 + 16 + 64, + DISPLAY_LEN_MAX_8000 = 2 + 4 + 16 + 64, + DISPLAY_LEN_MIN_8100 = 1 + 8 + 40, + DISPLAY_LEN_MAX_8100 = 1 + 8 + 40, + DISPLAY_LEN_MIN_8200 = 64 + 1 + 32 + 1 + 1 + 1 + 1, + DISPLAY_LEN_MAX_8200 = 64 + 1 + 32 + 1 + 8 + 1 + 2048, + DISPLAY_LEN_MIN_8300 = 32 + 1 + 1 + 1 + 1 + 1 + 1, + DISPLAY_LEN_MAX_8300 = 32 + 1 + 32 + 1 + 32 + 1 + 5, + DISPLAY_LEN_MIN_8400 = 40 + 1 + 40, + DISPLAY_LEN_MAX_8400 = 40 + 1 + 40, + DISPLAY_LEN_MIN_8500 = 6 + 1 + 1 + 1 + 1, + DISPLAY_LEN_MAX_8500 = 6 + 1 + 8 + 1 + 16, + DISPLAY_LEN_MIN_8600 = 32, + DISPLAY_LEN_MAX_8600 = 32, + DISPLAY_LEN_MIN_8700 = 22, + DISPLAY_LEN_MAX_8700 = 22, + DISPLAY_LEN_MIN_8800 = 1 + 3 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 32 + 1 + 3072, + DISPLAY_LEN_MAX_8800 = 1 + 3 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 32 + 1 + 3072, + DISPLAY_LEN_MIN_8900 = 6 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 44, + DISPLAY_LEN_MAX_8900 = 6 + 1 + 6 + 1 + 2 + 1 + 2 + 1 + 45 + 1 + 44, + DISPLAY_LEN_MIN_9100 = 51, + DISPLAY_LEN_MAX_9100 = 51, + DISPLAY_LEN_MIN_9200 = 3 + 14 + 1 + 43, + DISPLAY_LEN_MAX_9200 = 3 + 14 + 1 + 43, + DISPLAY_LEN_MIN_9300 = 3 + 14 + 1 + 43, + DISPLAY_LEN_MAX_9300 = 3 + 14 + 1 + 43, + DISPLAY_LEN_MIN_9400 = 8 + 1 + 4 + 1 + 2 + 1 + 3 + 1 + 2 + 1 + 32 + 1 + 32 + 1 + 40, + DISPLAY_LEN_MAX_9400 = 8 + 1 + 4 + 1 + 2 + 1 + 3 + 1 + 2 + 1 + 32 + 1 + 32 + 1 + 40, + DISPLAY_LEN_MIN_9500 = 8 + 1 + 4 + 1 + 6 + 1 + 3 + 1 + 2 + 1 + 32 + 1 + 32 + 1 + 64, + DISPLAY_LEN_MAX_9500 = 8 + 1 + 4 + 1 + 6 + 1 + 3 + 1 + 2 + 1 + 32 + 1 + 32 + 1 + 64, + DISPLAY_LEN_MIN_9600 = 8 + 1 + 4 + 1 + 6 + 1 + 3 + 1 + 2 + 1 + 32 + 1 + 32 + 1 + 64, + DISPLAY_LEN_MAX_9600 = 8 + 1 + 4 + 1 + 6 + 1 + 3 + 1 + 2 + 1 + 32 + 1 + 32 + 1 + 64, + DISPLAY_LEN_MIN_9700 = 12 + 1 + 32 + 1 + 32 + 1 + 32, + DISPLAY_LEN_MAX_9700 = 12 + 1 + 32 + 1 + 32 + 1 + 32, + DISPLAY_LEN_MIN_9720 = 12 + 1 + 32 + 1 + 32 + 1 + 32 + 1 + 10, + DISPLAY_LEN_MAX_9720 = 12 + 1 + 32 + 1 + 32 + 1 + 32 + 1 + 10, + DISPLAY_LEN_MIN_9800 = 12 + 1 + 32 + 1 + 32 + 1 + 40, + DISPLAY_LEN_MAX_9800 = 12 + 1 + 32 + 1 + 32 + 1 + 40, + DISPLAY_LEN_MIN_9820 = 12 + 1 + 32 + 1 + 32 + 1 + 40 + 1 + 10, + DISPLAY_LEN_MAX_9820 = 12 + 1 + 32 + 1 + 32 + 1 + 40 + 1 + 10, + DISPLAY_LEN_MIN_9900 = 32, + DISPLAY_LEN_MAX_9900 = 32, + DISPLAY_LEN_MIN_10000 = 13 + 1 + 1 + 1 + 0 + 44, + DISPLAY_LEN_MAX_10000 = 13 + 1 + 6 + 1 + 15 + 44, + DISPLAY_LEN_MIN_10100 = 16 + 1 + 1 + 1 + 1 + 1 + 32, + DISPLAY_LEN_MAX_10100 = 16 + 1 + 1 + 1 + 1 + 1 + 32, + DISPLAY_LEN_MIN_10200 = 10 + 12 + 1 + 44, + DISPLAY_LEN_MAX_10200 = 10 + 76 + 1 + 132, + DISPLAY_LEN_MIN_10300 = 10 + 1 + 1 + 33, + DISPLAY_LEN_MAX_10300 = 10 + 5 + 1 + 49, + DISPLAY_LEN_MIN_10400 = 5 + 1 + 1 + 1 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64, + DISPLAY_LEN_MAX_10400 = 5 + 1 + 1 + 1 + 1 + 2 + 1 + 5 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64, + DISPLAY_LEN_MIN_10410 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64, + DISPLAY_LEN_MAX_10410 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 5 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64, + DISPLAY_LEN_MIN_10420 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64 + 1 + 10, + DISPLAY_LEN_MAX_10420 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 5 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64 + 1 + 10, + DISPLAY_LEN_MIN_10500 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64, + DISPLAY_LEN_MAX_10500 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 5 + 1 + 1 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64, + DISPLAY_LEN_MIN_10600 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 1, + DISPLAY_LEN_MAX_10600 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 5 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 1000, + DISPLAY_LEN_MIN_10700 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 1, + DISPLAY_LEN_MAX_10700 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 5 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 1000, + DISPLAY_LEN_MIN_10800 = 96, + DISPLAY_LEN_MAX_10800 = 96, + DISPLAY_LEN_MIN_10900 = 7 + 1 + 1 + 0 + 1 + 24, + DISPLAY_LEN_MAX_10900 = 7 + 6 + 1 + 64 + 1 + 88, + DISPLAY_LEN_MIN_11000 = 32 + 1 + 56, + DISPLAY_LEN_MAX_11000 = 32 + 1 + 56, + DISPLAY_LEN_MIN_11100 = 10 + 0 + 1 + 8 + 1 + 32, + DISPLAY_LEN_MAX_11100 = 10 + 32 + 1 + 8 + 1 + 32, + DISPLAY_LEN_MIN_11200 = 9 + 40 + 1 + 40, + DISPLAY_LEN_MAX_11200 = 9 + 40 + 1 + 40, + DISPLAY_LEN_MIN_11300 = 1 + 7 + 1 + 2 + 1 + 96 + 1 + 2 + 1 + 16 + 1 + 1 + 1 + 2 + 1 + 96 + 1 + 1 + 1 + 2, + DISPLAY_LEN_MAX_11300 = 1 + 7 + 1 + 2 + 1 + 96 + 1 + 2 + 1 + 16 + 1 + 6 + 1 + 2 + 1 + 96 + 1 + 3 + 1 + 512, + DISPLAY_LEN_MIN_11400 = 6 + 0 + 1 + 0 + 1 + 0 + 1 + 0 + 1 + 0 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 0 + 1 + 0 + 1 + 3 + 1 + 32, + DISPLAY_LEN_MAX_11400 = 6 + 512 + 1 + 512 + 1 + 116 + 1 + 116 + 1 + 246 + 1 + 245 + 1 + 246 + 1 + 245 + 1 + 50 + 1 + 50 + 1 + 50 + 1 + 50 + 1 + 3 + 1 + 32, + DISPLAY_LEN_MIN_11500 = 8 + 1 + 8, + DISPLAY_LEN_MAX_11500 = 8 + 1 + 8, + DISPLAY_LEN_MIN_11600 = 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 32 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 2, + DISPLAY_LEN_MAX_11600 = 1 + 2 + 1 + 1 + 1 + 2 + 1 + 1 + 1 + 64 + 1 + 1 + 1 + 32 + 1 + 10 + 1 + 3 + 1 + 3 + 1 + 768, + DISPLAY_LEN_MIN_11700 = 64, + DISPLAY_LEN_MAX_11700 = 64, + DISPLAY_LEN_MIN_11800 = 128, + DISPLAY_LEN_MAX_11800 = 128, + DISPLAY_LEN_MIN_11900 = 3 + 1 + 1 + 0 + 1 + 12, + DISPLAY_LEN_MAX_11900 = 3 + 6 + 1 + 64 + 1 + 88, + DISPLAY_LEN_MIN_12000 = 4 + 1 + 1 + 0 + 1 + 16, + DISPLAY_LEN_MAX_12000 = 4 + 6 + 1 + 64 + 1 + 88, + DISPLAY_LEN_MIN_12100 = 6 + 1 + 1 + 0 + 1 + 16, + DISPLAY_LEN_MAX_12100 = 6 + 6 + 1 + 64 + 1 + 88, + DISPLAY_LEN_MIN_12200 = 1 + 8 + 1 + 1 + 1 + 1 + 1 + 16 + 1 + 16, + DISPLAY_LEN_MAX_12200 = 1 + 8 + 1 + 1 + 1 + 1 + 1 + 16 + 1 + 16, + DISPLAY_LEN_MIN_12300 = 160, + DISPLAY_LEN_MAX_12300 = 160, + DISPLAY_LEN_MIN_12400 = 1 + 4 + 4 + 11, + DISPLAY_LEN_MAX_12400 = 1 + 4 + 4 + 11, + DISPLAY_LEN_MIN_12500 = 6 + 1 + 1 + 1 + 16 + 1 + 32, + DISPLAY_LEN_MAX_12500 = 6 + 1 + 1 + 1 + 16 + 1 + 32, + DISPLAY_LEN_MIN_12600 = 64 + 1 + 64, + DISPLAY_LEN_MAX_12600 = 64 + 1 + 64, + DISPLAY_LEN_MIN_12700 = 1 + 10 + 1 + 1 + 1 + 64, + DISPLAY_LEN_MAX_12700 = 1 + 10 + 1 + 5 + 1 + 20000, + DISPLAY_LEN_MIN_12800 = 11 + 1 + 20 + 1 + 1 + 1 + 64, + DISPLAY_LEN_MAX_12800 = 11 + 1 + 20 + 1 + 5 + 1 + 64, + DISPLAY_LEN_MIN_12900 = 64 + 64 + 32, + DISPLAY_LEN_MAX_12900 = 64 + 64 + 32, + DISPLAY_LEN_MIN_13000 = 1 + 4 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 32 + 1 + 1 + 1 + 16, + DISPLAY_LEN_MAX_13000 = 1 + 4 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 32 + 1 + 1 + 1 + 16, + DISPLAY_LEN_MIN_13100 = 1 + 7 + 1 + 2 + 1 + 0 + 0 + 32 + 1 + 64, + DISPLAY_LEN_MAX_13100 = 1 + 7 + 1 + 2 + 1 + 2 + 512 + 1 + 32 + 1 + 20480, + DISPLAY_LEN_MIN_13200 = 1 + 7 + 1 + 1 + 1 + 1 + 1 + 1 + 32 + 1 + 48, + DISPLAY_LEN_MAX_13200 = 1 + 7 + 1 + 1 + 1 + 1 + 50 + 1 + 32 + 1 + 48 + 1 + 20480, + DISPLAY_LEN_MIN_13300 = 1 + 12 + 1 + 32, + DISPLAY_LEN_MAX_13300 = 1 + 12 + 1 + 40, + DISPLAY_LEN_MIN_13400 = 1 + 7 + 1 + 1 + 1 + 1 + 1 + 1 + 32 + 1 + 64 + 1 + 32 + 1 + 64 + 1 + 1 + 1 + 1, + DISPLAY_LEN_MAX_13400 = 1 + 7 + 1 + 1 + 10 + 1 + 3 + 1 + 64 + 1 + 64 + 1 + 32 + 1 + 64 + 1 + 4 + 1 + 600000 + 1 + 2 + 1 + 64, + DISPLAY_LEN_MIN_13500 = 40 + 1 + 32, + DISPLAY_LEN_MAX_13500 = 40 + 1 + 1024, + DISPLAY_LEN_MIN_13600 = 6 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 16 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 20 + 1 + 7, + DISPLAY_LEN_MAX_13600 = 6 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 32 + 1 + 4 + 1 + 4 + 1 + 8192 + 1 + 20 + 1 + 7, + DISPLAY_LEN_MIN_13800 = 64 + 1 + 256, + DISPLAY_LEN_MAX_13800 = 64 + 1 + 256, + DISPLAY_LEN_MIN_13900 = 40 + 1 + 9, + DISPLAY_LEN_MAX_13900 = 40 + 1 + 9, + DISPLAY_LEN_MIN_14000 = 16 + 1 + 16, + DISPLAY_LEN_MAX_14000 = 16 + 1 + 16, + DISPLAY_LEN_MIN_14100 = 16 + 1 + 16, + DISPLAY_LEN_MAX_14100 = 16 + 1 + 16, + + DISPLAY_LEN_MIN_11 = 32 + 1 + 16, + DISPLAY_LEN_MAX_11 = 32 + 1 + 32, + DISPLAY_LEN_MIN_11H = 32 + 1 + 32, + DISPLAY_LEN_MAX_11H = 32 + 1 + 64, + DISPLAY_LEN_MIN_12 = 32 + 1 + 1, + DISPLAY_LEN_MAX_12 = 32 + 1 + 32, + DISPLAY_LEN_MIN_12H = 32 + 1 + 2, + DISPLAY_LEN_MAX_12H = 32 + 1 + 64, + DISPLAY_LEN_MIN_21 = 32 + 1 + 1, + DISPLAY_LEN_MAX_21 = 32 + 1 + 15, + DISPLAY_LEN_MIN_21H = 32 + 1 + 2, + DISPLAY_LEN_MAX_21H = 32 + 1 + 30, + DISPLAY_LEN_MIN_22 = 30 + 1 + 1, + DISPLAY_LEN_MAX_22 = 30 + 1 + 28, + DISPLAY_LEN_MIN_22H = 30 + 1 + 2, + DISPLAY_LEN_MAX_22H = 30 + 1 + 56, + DISPLAY_LEN_MIN_23 = 32 + 1 + 0, + DISPLAY_LEN_MAX_23 = 32 + 1 + 23, + DISPLAY_LEN_MIN_101 = 5 + 28, + DISPLAY_LEN_MAX_101 = 5 + 28, + DISPLAY_LEN_MIN_111 = 6 + 28 + 0, + DISPLAY_LEN_MAX_111 = 6 + 28 + 40, + DISPLAY_LEN_MIN_112 = 40 + 1 + 20, + DISPLAY_LEN_MAX_112 = 40 + 1 + 20, + DISPLAY_LEN_MIN_121 = 40 + 1 + 1, + DISPLAY_LEN_MAX_121 = 40 + 1 + 32, + DISPLAY_LEN_MIN_121H = 40 + 1 + 2, + DISPLAY_LEN_MAX_121H = 40 + 1 + 64, + DISPLAY_LEN_MIN_122 = 8 + 40, + DISPLAY_LEN_MAX_122 = 8 + 40, + DISPLAY_LEN_MIN_124 = 4 + 1 + 0 + 1 + 40, + DISPLAY_LEN_MAX_124 = 4 + 1 + 32 + 1 + 40, + DISPLAY_LEN_MIN_125 = 10 + 40, + DISPLAY_LEN_MAX_125 = 10 + 40, + DISPLAY_LEN_MIN_131 = 6 + 8 + 80, + DISPLAY_LEN_MAX_131 = 6 + 8 + 80, + DISPLAY_LEN_MIN_132 = 6 + 8 + 40, + DISPLAY_LEN_MAX_132 = 6 + 8 + 40, + DISPLAY_LEN_MIN_133 = 28, + DISPLAY_LEN_MAX_133 = 28, + DISPLAY_LEN_MIN_141 = 14 + 0 + 1 + 28, + DISPLAY_LEN_MAX_141 = 14 + 44 + 1 + 28, + DISPLAY_LEN_MIN_1441 = 14 + 0 + 1 + 43, + DISPLAY_LEN_MAX_1441 = 14 + 24 + 1 + 43, + DISPLAY_LEN_MIN_1711 = 9 + 86 + 0, + DISPLAY_LEN_MAX_1711 = 9 + 86 + 68, + DISPLAY_LEN_MIN_1722 = 8 + 128, + DISPLAY_LEN_MAX_1722 = 8 + 128, + DISPLAY_LEN_MIN_2611 = 32 + 1 + 0, + DISPLAY_LEN_MAX_2611 = 32 + 1 + 23, + DISPLAY_LEN_MIN_2611H = 32 + 1 + 0, + DISPLAY_LEN_MIN_2612 = 6 + 0 + 1 + 32, + DISPLAY_LEN_MAX_2611H = 32 + 1 + 46, + DISPLAY_LEN_MAX_2612 = 6 + 46 + 1 + 32, + DISPLAY_LEN_MIN_2711 = 32 + 1 + 23, + DISPLAY_LEN_MAX_2711 = 32 + 1 + 31, + DISPLAY_LEN_MIN_2711H = 32 + 1 + 46, + DISPLAY_LEN_MAX_2711H = 32 + 1 + 62, + DISPLAY_LEN_MIN_2811 = 32 + 1 + 0, + DISPLAY_LEN_MAX_2811 = 32 + 1 + 31, + DISPLAY_LEN_MIN_2811H = 32 + 1 + 0, + DISPLAY_LEN_MAX_2811H = 32 + 1 + 62, + DISPLAY_LEN_MIN_7600 = 40 + 1 + 32, + DISPLAY_LEN_MAX_7600 = 40 + 1 + 32, + +} display_len_t; + +typedef enum hash_type +{ + HASH_TYPE_MD4 = 1, + HASH_TYPE_MD5 = 2, + HASH_TYPE_MD5H = 3, + HASH_TYPE_SHA1 = 4, + HASH_TYPE_SHA256 = 5, + HASH_TYPE_SHA384 = 6, + HASH_TYPE_SHA512 = 7, + HASH_TYPE_DCC2 = 8, + HASH_TYPE_WPA = 9, + HASH_TYPE_LM = 10, + HASH_TYPE_DESCRYPT = 11, + HASH_TYPE_ORACLEH = 12, + HASH_TYPE_DESRACF = 13, + HASH_TYPE_BCRYPT = 14, + HASH_TYPE_KECCAK = 15, + HASH_TYPE_NETNTLM = 16, + HASH_TYPE_RIPEMD160 = 17, + HASH_TYPE_WHIRLPOOL = 18, + HASH_TYPE_AES = 19, + HASH_TYPE_GOST = 20, + HASH_TYPE_KRB5PA = 21, + HASH_TYPE_SAPB = 22, + HASH_TYPE_SAPG = 23, + HASH_TYPE_MYSQL = 24, + HASH_TYPE_LOTUS5 = 25, + HASH_TYPE_LOTUS6 = 26, + HASH_TYPE_ANDROIDFDE = 27, + HASH_TYPE_SCRYPT = 28, + HASH_TYPE_LOTUS8 = 29, + HASH_TYPE_OFFICE2007 = 30, + HASH_TYPE_OFFICE2010 = 31, + HASH_TYPE_OFFICE2013 = 32, + HASH_TYPE_OLDOFFICE01 = 33, + HASH_TYPE_OLDOFFICE34 = 34, + HASH_TYPE_SIPHASH = 35, + HASH_TYPE_PDFU16 = 36, + HASH_TYPE_PDFU32 = 37, + HASH_TYPE_PBKDF2_SHA256 = 38, + HASH_TYPE_BITCOIN_WALLET = 39, + HASH_TYPE_CRC32 = 40, + HASH_TYPE_GOST_2012SBOG_256 = 41, + HASH_TYPE_GOST_2012SBOG_512 = 42, + HASH_TYPE_PBKDF2_MD5 = 43, + HASH_TYPE_PBKDF2_SHA1 = 44, + HASH_TYPE_PBKDF2_SHA512 = 45, + HASH_TYPE_ECRYPTFS = 46, + HASH_TYPE_ORACLET = 47, + HASH_TYPE_BSDICRYPT = 48, + HASH_TYPE_RAR3HP = 49, + HASH_TYPE_KRB5TGS = 50, + HASH_TYPE_STDOUT = 51, + HASH_TYPE_DES = 52 + +} hash_type_t; + +typedef enum kern_type +{ + KERN_TYPE_MD5 = 0, + KERN_TYPE_MD5_PWSLT = 10, + KERN_TYPE_MD5_SLTPW = 20, + KERN_TYPE_MD5_PWUSLT = 30, + KERN_TYPE_MD5_SLTPWU = 40, + KERN_TYPE_HMACMD5_PW = 50, + KERN_TYPE_HMACMD5_SLT = 60, + KERN_TYPE_SHA1 = 100, + KERN_TYPE_SHA1_PWSLT = 110, + KERN_TYPE_SHA1_SLTPW = 120, + KERN_TYPE_SHA1_PWUSLT = 130, + KERN_TYPE_SHA1_SLTPWU = 140, + KERN_TYPE_HMACSHA1_PW = 150, + KERN_TYPE_HMACSHA1_SLT = 160, + KERN_TYPE_MYSQL = 200, + KERN_TYPE_MYSQL41 = 300, + KERN_TYPE_PHPASS = 400, + KERN_TYPE_MD5CRYPT = 500, + KERN_TYPE_MD4 = 900, + KERN_TYPE_MD4_PWU = 1000, + KERN_TYPE_MD44_PWUSLT = 1100, + KERN_TYPE_SHA256 = 1400, + KERN_TYPE_SHA256_PWSLT = 1410, + KERN_TYPE_SHA256_SLTPW = 1420, + KERN_TYPE_SHA256_PWUSLT = 1430, + KERN_TYPE_SHA256_SLTPWU = 1440, + KERN_TYPE_HMACSHA256_PW = 1450, + KERN_TYPE_HMACSHA256_SLT = 1460, + KERN_TYPE_DESCRYPT = 1500, + KERN_TYPE_APR1CRYPT = 1600, + KERN_TYPE_SHA512 = 1700, + KERN_TYPE_SHA512_PWSLT = 1710, + KERN_TYPE_SHA512_SLTPW = 1720, + KERN_TYPE_SHA512_PWSLTU = 1730, + KERN_TYPE_SHA512_SLTPWU = 1740, + KERN_TYPE_HMACSHA512_PW = 1750, + KERN_TYPE_HMACSHA512_SLT = 1760, + KERN_TYPE_SHA512CRYPT = 1800, + KERN_TYPE_STDOUT = 2000, + KERN_TYPE_DCC2 = 2100, + KERN_TYPE_MD5PIX = 2400, + KERN_TYPE_MD5ASA = 2410, + KERN_TYPE_WPA = 2500, + KERN_TYPE_MD55 = 2600, + KERN_TYPE_MD55_PWSLT1 = 2610, + KERN_TYPE_MD55_PWSLT2 = 2710, + KERN_TYPE_MD55_SLTPW = 2810, + KERN_TYPE_LM = 3000, + KERN_TYPE_ORACLEH = 3100, + KERN_TYPE_BCRYPT = 3200, + KERN_TYPE_MD5_SLT_MD5_PW = 3710, + KERN_TYPE_MD5_SLT_PW_SLT = 3800, + KERN_TYPE_MD5U5 = 4300, + KERN_TYPE_MD5U5_PWSLT1 = 4310, + KERN_TYPE_MD5_SHA1 = 4400, + KERN_TYPE_SHA11 = 4500, + KERN_TYPE_SHA1_MD5 = 4700, + KERN_TYPE_MD5_CHAP = 4800, + KERN_TYPE_SHA1_SLT_PW_SLT = 4900, + KERN_TYPE_KECCAK = 5000, + KERN_TYPE_MD5H = 5100, + KERN_TYPE_PSAFE3 = 5200, + KERN_TYPE_IKEPSK_MD5 = 5300, + KERN_TYPE_IKEPSK_SHA1 = 5400, + KERN_TYPE_NETNTLMv1 = 5500, + KERN_TYPE_NETNTLMv2 = 5600, + KERN_TYPE_ANDROIDPIN = 5800, + KERN_TYPE_RIPEMD160 = 6000, + KERN_TYPE_WHIRLPOOL = 6100, + KERN_TYPE_TCRIPEMD160_XTS512 = 6211, + KERN_TYPE_TCRIPEMD160_XTS1024 = 6212, + KERN_TYPE_TCRIPEMD160_XTS1536 = 6213, + KERN_TYPE_TCSHA512_XTS512 = 6221, + KERN_TYPE_TCSHA512_XTS1024 = 6222, + KERN_TYPE_TCSHA512_XTS1536 = 6223, + KERN_TYPE_TCWHIRLPOOL_XTS512 = 6231, + KERN_TYPE_TCWHIRLPOOL_XTS1024 = 6232, + KERN_TYPE_TCWHIRLPOOL_XTS1536 = 6233, + KERN_TYPE_VCSHA256_XTS512 = 13751, + KERN_TYPE_VCSHA256_XTS1024 = 13752, + KERN_TYPE_VCSHA256_XTS1536 = 13753, + KERN_TYPE_MD5AIX = 6300, + KERN_TYPE_SHA256AIX = 6400, + KERN_TYPE_SHA512AIX = 6500, + KERN_TYPE_AGILEKEY = 6600, + KERN_TYPE_SHA1AIX = 6700, + KERN_TYPE_LASTPASS = 6800, + KERN_TYPE_GOST = 6900, + KERN_TYPE_PBKDF2_SHA512 = 7100, + KERN_TYPE_RAKP = 7300, + KERN_TYPE_SHA256CRYPT = 7400, + KERN_TYPE_KRB5PA = 7500, + KERN_TYPE_SHA1_SLT_SHA1_PW = 7600, + KERN_TYPE_SAPB = 7700, + KERN_TYPE_SAPG = 7800, + KERN_TYPE_DRUPAL7 = 7900, + KERN_TYPE_SYBASEASE = 8000, + KERN_TYPE_NETSCALER = 8100, + KERN_TYPE_CLOUDKEY = 8200, + KERN_TYPE_NSEC3 = 8300, + KERN_TYPE_WBB3 = 8400, + KERN_TYPE_RACF = 8500, + KERN_TYPE_LOTUS5 = 8600, + KERN_TYPE_LOTUS6 = 8700, + KERN_TYPE_ANDROIDFDE = 8800, + KERN_TYPE_SCRYPT = 8900, + KERN_TYPE_PSAFE2 = 9000, + KERN_TYPE_LOTUS8 = 9100, + KERN_TYPE_OFFICE2007 = 9400, + KERN_TYPE_OFFICE2010 = 9500, + KERN_TYPE_OFFICE2013 = 9600, + KERN_TYPE_OLDOFFICE01 = 9700, + KERN_TYPE_OLDOFFICE01CM1 = 9710, + KERN_TYPE_OLDOFFICE01CM2 = 9720, + KERN_TYPE_OLDOFFICE34 = 9800, + KERN_TYPE_OLDOFFICE34CM1 = 9810, + KERN_TYPE_OLDOFFICE34CM2 = 9820, + KERN_TYPE_RADMIN2 = 9900, + KERN_TYPE_SIPHASH = 10100, + KERN_TYPE_SAPH_SHA1 = 10300, + KERN_TYPE_PDF11 = 10400, + KERN_TYPE_PDF11CM1 = 10410, + KERN_TYPE_PDF11CM2 = 10420, + KERN_TYPE_PDF14 = 10500, + KERN_TYPE_PDF17L8 = 10700, + KERN_TYPE_SHA384 = 10800, + KERN_TYPE_PBKDF2_SHA256 = 10900, + KERN_TYPE_PRESTASHOP = 11000, + KERN_TYPE_POSTGRESQL_AUTH = 11100, + KERN_TYPE_MYSQL_AUTH = 11200, + KERN_TYPE_BITCOIN_WALLET = 11300, + KERN_TYPE_SIP_AUTH = 11400, + KERN_TYPE_CRC32 = 11500, + KERN_TYPE_SEVEN_ZIP = 11600, + KERN_TYPE_GOST_2012SBOG_256 = 11700, + KERN_TYPE_GOST_2012SBOG_512 = 11800, + KERN_TYPE_PBKDF2_MD5 = 11900, + KERN_TYPE_PBKDF2_SHA1 = 12000, + KERN_TYPE_ECRYPTFS = 12200, + KERN_TYPE_ORACLET = 12300, + KERN_TYPE_BSDICRYPT = 12400, + KERN_TYPE_RAR3 = 12500, + KERN_TYPE_CF10 = 12600, + KERN_TYPE_MYWALLET = 12700, + KERN_TYPE_MS_DRSR = 12800, + KERN_TYPE_ANDROIDFDE_SAMSUNG = 12900, + KERN_TYPE_RAR5 = 13000, + KERN_TYPE_KRB5TGS = 13100, + KERN_TYPE_AXCRYPT = 13200, + KERN_TYPE_SHA1_AXCRYPT = 13300, + KERN_TYPE_KEEPASS = 13400, + KERN_TYPE_PSTOKEN = 13500, + KERN_TYPE_ZIP2 = 13600, + KERN_TYPE_WIN8PHONE = 13800, + KERN_TYPE_OPENCART = 13900, + KERN_TYPE_DES = 14000, + KERN_TYPE_3DES = 14100 + +} kern_type_t; + +/** + * Signatures + */ + +static const char SIGNATURE_ANDROIDFDE[] = "$fde$"; +static const char SIGNATURE_AXCRYPT[] = "$axcrypt$*1"; +static const char SIGNATURE_AXCRYPT_SHA1[] = "$axcrypt_sha1"; +static const char SIGNATURE_BCRYPT1[] = "$2a$"; +static const char SIGNATURE_BCRYPT2[] = "$2b$"; +static const char SIGNATURE_BCRYPT3[] = "$2x$"; +static const char SIGNATURE_BCRYPT4[] = "$2y$"; +static const char SIGNATURE_BITCOIN_WALLET[] = "$bitcoin$"; +static const char SIGNATURE_BSDICRYPT[] = "_"; +static const char SIGNATURE_CISCO8[] = "$8$"; +static const char SIGNATURE_CISCO9[] = "$9$"; +static const char SIGNATURE_CRAM_MD5[] = "$cram_md5$"; +static const char SIGNATURE_DCC2[] = "$DCC2$"; +static const char SIGNATURE_DJANGOPBKDF2[] = "pbkdf2_sha256$"; +static const char SIGNATURE_DJANGOSHA1[] = "sha1$"; +static const char SIGNATURE_DRUPAL7[] = "$S$"; +static const char SIGNATURE_ECRYPTFS[] = "$ecryptfs$"; +static const char SIGNATURE_EPISERVER4[] = "$episerver$*1*"; +static const char SIGNATURE_EPISERVER[] = "$episerver$*0*"; +static const char SIGNATURE_KEEPASS[] = "$keepass$"; +static const char SIGNATURE_KRB5PA[] = "$krb5pa$23"; +static const char SIGNATURE_KRB5TGS[] = "$krb5tgs$23"; +static const char SIGNATURE_MD5AIX[] = "{smd5}"; +static const char SIGNATURE_MD5APR1[] = "$apr1$"; +static const char SIGNATURE_MD5CRYPT[] = "$1$"; +static const char SIGNATURE_MEDIAWIKI_B[] = "$B$"; +static const char SIGNATURE_MS_DRSR[] = "v1;PPH1_MD4"; +static const char SIGNATURE_MSSQL[] = "0x0100"; +static const char SIGNATURE_MSSQL2012[] = "0x0200"; +static const char SIGNATURE_MYSQL_AUTH[] = "$mysqlna$"; +static const char SIGNATURE_MYWALLET[] = "$blockchain$"; +static const char SIGNATURE_NETSCALER[] = "1"; +static const char SIGNATURE_OFFICE2007[] = "$office$"; +static const char SIGNATURE_OFFICE2010[] = "$office$"; +static const char SIGNATURE_OFFICE2013[] = "$office$"; +static const char SIGNATURE_OLDOFFICE0[] = "$oldoffice$0"; +static const char SIGNATURE_OLDOFFICE1[] = "$oldoffice$1"; +static const char SIGNATURE_OLDOFFICE3[] = "$oldoffice$3"; +static const char SIGNATURE_OLDOFFICE4[] = "$oldoffice$4"; +static const char SIGNATURE_PBKDF2_MD5[] = "md5:"; +static const char SIGNATURE_PBKDF2_SHA1[] = "sha1:"; +static const char SIGNATURE_PBKDF2_SHA256[] = "sha256:"; +static const char SIGNATURE_PBKDF2_SHA512[] = "sha512:"; +static const char SIGNATURE_PDF[] = "$pdf$"; +static const char SIGNATURE_PHPASS1[] = "$P$"; +static const char SIGNATURE_PHPASS2[] = "$H$"; +static const char SIGNATURE_PHPS[] = "$PHPS$"; +static const char SIGNATURE_POSTGRESQL_AUTH[] = "$postgres$"; +static const char SIGNATURE_PSAFE3[] = "PWS3"; +static const char SIGNATURE_RACF[] = "$racf$"; +static const char SIGNATURE_RAR3[] = "$RAR3$"; +static const char SIGNATURE_RAR5[] = "$rar5$"; +static const char SIGNATURE_SAPH_SHA1[] = "{x-issha, "; +static const char SIGNATURE_SCRYPT[] = "SCRYPT"; +static const char SIGNATURE_SEVEN_ZIP[] = "$7z$"; +static const char SIGNATURE_SHA1AIX[] = "{ssha1}"; +static const char SIGNATURE_SHA1B64[] = "{SHA}"; +static const char SIGNATURE_SHA256AIX[] = "{ssha256}"; +static const char SIGNATURE_SHA256CRYPT[] = "$5$"; +static const char SIGNATURE_SHA512AIX[] = "{ssha512}"; +static const char SIGNATURE_SHA512B64S[] = "{SSHA512}"; +static const char SIGNATURE_SHA512CRYPT[] = "$6$"; +static const char SIGNATURE_SHA512GRUB[] = "grub.pbkdf2.sha512."; +static const char SIGNATURE_SHA512OSX[] = "$ml$"; +static const char SIGNATURE_SIP_AUTH[] = "$sip$*"; +static const char SIGNATURE_SSHA1B64_lower[] = "{ssha}"; +static const char SIGNATURE_SSHA1B64_upper[] = "{SSHA}"; +static const char SIGNATURE_SYBASEASE[] = "0xc007"; +static const char SIGNATURE_TRUECRYPT[] = "TRUE"; +static const char SIGNATURE_ZIP2_START[] = "$zip2$"; +static const char SIGNATURE_ZIP2_STOP[] = "$/zip2$"; + +/** + * Default iteration numbers + */ + +typedef enum rounds_count +{ + ROUNDS_PHPASS = (1 << 11), // $P$B + ROUNDS_DCC2 = 10240, + ROUNDS_WPA2 = 4096, + ROUNDS_BCRYPT = (1 << 5), + ROUNDS_PSAFE3 = 2048, + ROUNDS_ANDROIDPIN = 1024, + ROUNDS_TRUECRYPT_1K = 1000, + ROUNDS_TRUECRYPT_2K = 2000, + ROUNDS_VERACRYPT_200000 = 200000, + ROUNDS_VERACRYPT_500000 = 500000, + ROUNDS_VERACRYPT_327661 = 327661, + ROUNDS_VERACRYPT_655331 = 655331, + ROUNDS_SHA1AIX = (1 << 6), + ROUNDS_SHA256AIX = (1 << 6), + ROUNDS_SHA512AIX = (1 << 6), + ROUNDS_MD5CRYPT = 1000, + ROUNDS_SHA256CRYPT = 5000, + ROUNDS_SHA512CRYPT = 5000, + ROUNDS_GRUB = 10000, + ROUNDS_SHA512OSX = 35000, + ROUNDS_AGILEKEY = 1000, + ROUNDS_LASTPASS = 500, + ROUNDS_DRUPAL7 = (1 << 14), // $S$C + ROUNDS_CLOUDKEY = 40000, + ROUNDS_NSEC3 = 1, + ROUNDS_ANDROIDFDE = 2000, + ROUNDS_PSAFE2 = 1000, + ROUNDS_LOTUS8 = 5000, + ROUNDS_CISCO8 = 20000, + ROUNDS_OFFICE2007 = 50000, + ROUNDS_OFFICE2010 = 100000, + ROUNDS_OFFICE2013 = 100000, + ROUNDS_DJANGOPBKDF2 = 20000, + ROUNDS_SAPH_SHA1 = 1024, + ROUNDS_PDF14 = (50 + 20), + ROUNDS_PDF17L8 = 64, + ROUNDS_PBKDF2_SHA256 = 1000, + ROUNDS_BITCOIN_WALLET = 200000, + ROUNDS_SEVEN_ZIP = (1 << 19), + ROUNDS_PBKDF2_MD5 = 1000, + ROUNDS_PBKDF2_SHA1 = 1000, + ROUNDS_PBKDF2_SHA512 = 1000, + ROUNDS_ECRYPTFS = 65536, + ROUNDS_ORACLET = 4096, + ROUNDS_BSDICRYPT = 2900, + ROUNDS_RAR3 = 262144, + ROUNDS_MYWALLET = 10, + ROUNDS_MS_DRSR = 100, + ROUNDS_ANDROIDFDE_SAMSUNG = 4096, + ROUNDS_RAR5 = (1 << 15), + ROUNDS_AXCRYPT = 10000, + ROUNDS_KEEPASS = 6000, + ROUNDS_ZIP2 = 1000, + ROUNDS_STDOUT = 0 + +} rounds_count_t; + +/** + * input functions + */ + +int bcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int cisco4_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int dcc_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int dcc2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int descrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int des_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int episerver_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int ipb2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int joomla_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int postgresql_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int netscreen_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int keccak_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int lm_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int md4_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int md4s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int md5s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int md5half_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int md5md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int md5pix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int md5asa_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int md5apr1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int md5crypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int mssql2000_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int mssql2005_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int netntlmv1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int netntlmv2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int oracleh_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int oracles_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int oraclet_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int osc_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int arubaos_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int osx1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int osx512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int phpass_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha1b64_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha1b64s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha1s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha256s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha384_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha512s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha512crypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int smf_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int vb3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int vb30_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int wpa_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int psafe2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int psafe3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int ikepsk_md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int ikepsk_sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int androidpin_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int ripemd160_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int whirlpool_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int truecrypt_parse_hash_1k (char *input_buf, uint input_len, hash_t *hash_buf); +int truecrypt_parse_hash_2k (char *input_buf, uint input_len, hash_t *hash_buf); +int md5aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha256aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha512aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int agilekey_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha1aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int lastpass_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int gost_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha256crypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int mssql2012_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha512osx_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int episerver4_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha512grub_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha512b64s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int hmacsha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int hmacsha256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int hmacsha512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int hmacmd5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int krb5pa_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int krb5tgs_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sapb_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sapg_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int drupal7_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sybasease_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int mysql323_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int rakp_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int netscaler_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int chap_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int cloudkey_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int nsec3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int wbb3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int racf_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int lotus5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int lotus6_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int lotus8_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int hmailserver_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int phps_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int mediawiki_b_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int peoplesoft_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int skype_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int androidfde_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int scrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int juniper_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int cisco8_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int cisco9_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int office2007_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int office2010_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int office2013_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int oldoffice01_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int oldoffice01cm1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int oldoffice01cm2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int oldoffice34_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int oldoffice34cm1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int oldoffice34cm2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int radmin2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int djangosha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int djangopbkdf2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int siphash_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int crammd5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int saph_sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int redmine_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int pdf11_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int pdf11cm1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int pdf11cm2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int pdf14_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int pdf17l3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int pdf17l8_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int pbkdf2_sha256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int prestashop_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int postgresql_auth_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int mysql_auth_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int bitcoin_wallet_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sip_auth_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int crc32_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int seven_zip_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int gost2012sbog_256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int gost2012sbog_512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int pbkdf2_md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int pbkdf2_sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int pbkdf2_sha512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int ecryptfs_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int bsdicrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int rar3hp_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int rar5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int cf10_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int mywallet_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int ms_drsr_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int androidfde_samsung_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int axcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int sha1axcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int keepass_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int pstoken_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int zip2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int veracrypt_parse_hash_200000 (char *input_buf, uint input_len, hash_t *hash_buf); +int veracrypt_parse_hash_500000 (char *input_buf, uint input_len, hash_t *hash_buf); +int veracrypt_parse_hash_327661 (char *input_buf, uint input_len, hash_t *hash_buf); +int veracrypt_parse_hash_655331 (char *input_buf, uint input_len, hash_t *hash_buf); +int win8phone_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); +int opencart_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); + +/** + * output functions + */ + +char *strhashtype (const uint hash_mode); +char *strparser (const uint parser_status); + +void to_hccap_t (hccap_t *hccap, uint salt_pos, uint digest_pos); + +void truecrypt_crc32 (const char *filename, u8 keytab[64]); + +void ascii_digest (char *out_buf, uint salt_pos, uint digest_pos); diff --git a/include/shared.h b/include/shared.h index e60a8c089..ab54f4077 100644 --- a/include/shared.h +++ b/include/shared.h @@ -9,15 +9,11 @@ #pragma once #include -#include -#include #include #include #include #include -#include #include -#include /** * OS specific includes @@ -104,1003 +100,6 @@ extern const char *PROMPT; extern hc_thread_mutex_t mux_display; -/** - * Strings - */ - -static const char HT_00000[] = "MD5"; -static const char HT_00010[] = "md5($pass.$salt)"; -static const char HT_00020[] = "md5($salt.$pass)"; -static const char HT_00030[] = "md5(unicode($pass).$salt)"; -static const char HT_00040[] = "md5($salt.unicode($pass))"; -static const char HT_00050[] = "HMAC-MD5 (key = $pass)"; -static const char HT_00060[] = "HMAC-MD5 (key = $salt)"; -static const char HT_00100[] = "SHA1"; -static const char HT_00110[] = "sha1($pass.$salt)"; -static const char HT_00120[] = "sha1($salt.$pass)"; -static const char HT_00130[] = "sha1(unicode($pass).$salt)"; -static const char HT_00140[] = "sha1($salt.unicode($pass))"; -static const char HT_00150[] = "HMAC-SHA1 (key = $pass)"; -static const char HT_00160[] = "HMAC-SHA1 (key = $salt)"; -static const char HT_00200[] = "MySQL323"; -static const char HT_00300[] = "MySQL4.1/MySQL5"; -static const char HT_00400[] = "phpass, MD5(Wordpress), MD5(phpBB3), MD5(Joomla)"; -static const char HT_00500[] = "md5crypt, MD5(Unix), FreeBSD MD5, Cisco-IOS MD5"; -static const char HT_00501[] = "Juniper IVE"; -static const char HT_00900[] = "MD4"; -static const char HT_00910[] = "md4($pass.$salt)"; -static const char HT_01000[] = "NTLM"; -static const char HT_01100[] = "Domain Cached Credentials (DCC), MS Cache"; -static const char HT_01400[] = "SHA256"; -static const char HT_01410[] = "sha256($pass.$salt)"; -static const char HT_01420[] = "sha256($salt.$pass)"; -static const char HT_01430[] = "sha256(unicode($pass).$salt)"; -static const char HT_01440[] = "sha256($salt.$pass)"; -static const char HT_01450[] = "HMAC-SHA256 (key = $pass)"; -static const char HT_01460[] = "HMAC-SHA256 (key = $salt)"; -static const char HT_01500[] = "descrypt, DES(Unix), Traditional DES"; -static const char HT_01600[] = "md5apr1, MD5(APR), Apache MD5"; -static const char HT_01700[] = "SHA512"; -static const char HT_01710[] = "sha512($pass.$salt)"; -static const char HT_01720[] = "sha512($salt.$pass)"; -static const char HT_01730[] = "sha512(unicode($pass).$salt)"; -static const char HT_01740[] = "sha512($salt.unicode($pass))"; -static const char HT_01750[] = "HMAC-SHA512 (key = $pass)"; -static const char HT_01760[] = "HMAC-SHA512 (key = $salt)"; -static const char HT_01800[] = "sha512crypt, SHA512(Unix)"; -static const char HT_02100[] = "Domain Cached Credentials 2 (DCC2), MS Cache 2"; -static const char HT_02400[] = "Cisco-PIX MD5"; -static const char HT_02410[] = "Cisco-ASA MD5"; -static const char HT_02500[] = "WPA/WPA2"; -static const char HT_02600[] = "Double MD5"; -static const char HT_03000[] = "LM"; -static const char HT_03100[] = "Oracle H: Type (Oracle 7+)"; -static const char HT_03200[] = "bcrypt, Blowfish(OpenBSD)"; -static const char HT_03710[] = "md5($salt.md5($pass))"; -static const char HT_03711[] = "Mediawiki B type"; -static const char HT_03800[] = "md5($salt.$pass.$salt)"; -static const char HT_04300[] = "md5(strtoupper(md5($pass)))"; -static const char HT_04400[] = "md5(sha1($pass))"; -static const char HT_04500[] = "Double SHA1"; -static const char HT_04700[] = "sha1(md5($pass))"; -static const char HT_04800[] = "MD5(Chap), iSCSI CHAP authentication"; -static const char HT_04900[] = "sha1($salt.$pass.$salt)"; -static const char HT_05000[] = "SHA-3(Keccak)"; -static const char HT_05100[] = "Half MD5"; -static const char HT_05200[] = "Password Safe v3"; -static const char HT_05300[] = "IKE-PSK MD5"; -static const char HT_05400[] = "IKE-PSK SHA1"; -static const char HT_05500[] = "NetNTLMv1-VANILLA / NetNTLMv1+ESS"; -static const char HT_05600[] = "NetNTLMv2"; -static const char HT_05700[] = "Cisco-IOS SHA256"; -static const char HT_05800[] = "Android PIN"; -static const char HT_06000[] = "RipeMD160"; -static const char HT_06100[] = "Whirlpool"; -static const char HT_06300[] = "AIX {smd5}"; -static const char HT_06400[] = "AIX {ssha256}"; -static const char HT_06500[] = "AIX {ssha512}"; -static const char HT_06600[] = "1Password, agilekeychain"; -static const char HT_06700[] = "AIX {ssha1}"; -static const char HT_06800[] = "Lastpass"; -static const char HT_06900[] = "GOST R 34.11-94"; -static const char HT_07100[] = "OSX v10.8+"; -static const char HT_07200[] = "GRUB 2"; -static const char HT_07300[] = "IPMI2 RAKP HMAC-SHA1"; -static const char HT_07400[] = "sha256crypt, SHA256(Unix)"; -static const char HT_07500[] = "Kerberos 5 AS-REQ Pre-Auth etype 23"; -static const char HT_07600[] = "Redmine Project Management Web App"; -static const char HT_07700[] = "SAP CODVN B (BCODE)"; -static const char HT_07800[] = "SAP CODVN F/G (PASSCODE)"; -static const char HT_07900[] = "Drupal7"; -static const char HT_08000[] = "Sybase ASE"; -static const char HT_08100[] = "Citrix NetScaler"; -static const char HT_08200[] = "1Password, cloudkeychain"; -static const char HT_08300[] = "DNSSEC (NSEC3)"; -static const char HT_08400[] = "WBB3, Woltlab Burning Board 3"; -static const char HT_08500[] = "RACF"; -static const char HT_08600[] = "Lotus Notes/Domino 5"; -static const char HT_08700[] = "Lotus Notes/Domino 6"; -static const char HT_08800[] = "Android FDE <= 4.3"; -static const char HT_08900[] = "scrypt"; -static const char HT_09000[] = "Password Safe v2"; -static const char HT_09100[] = "Lotus Notes/Domino 8"; -static const char HT_09200[] = "Cisco $8$"; -static const char HT_09300[] = "Cisco $9$"; -static const char HT_09400[] = "Office 2007"; -static const char HT_09500[] = "Office 2010"; -static const char HT_09600[] = "Office 2013"; -static const char HT_09700[] = "MS Office <= 2003 MD5 + RC4, oldoffice$0, oldoffice$1"; -static const char HT_09710[] = "MS Office <= 2003 MD5 + RC4, collision-mode #1"; -static const char HT_09720[] = "MS Office <= 2003 MD5 + RC4, collision-mode #2"; -static const char HT_09800[] = "MS Office <= 2003 SHA1 + RC4, oldoffice$3, oldoffice$4"; -static const char HT_09810[] = "MS Office <= 2003 SHA1 + RC4, collision-mode #1"; -static const char HT_09820[] = "MS Office <= 2003 SHA1 + RC4, collision-mode #2"; -static const char HT_09900[] = "Radmin2"; -static const char HT_10000[] = "Django (PBKDF2-SHA256)"; -static const char HT_10100[] = "SipHash"; -static const char HT_10200[] = "Cram MD5"; -static const char HT_10300[] = "SAP CODVN H (PWDSALTEDHASH) iSSHA-1"; -static const char HT_10400[] = "PDF 1.1 - 1.3 (Acrobat 2 - 4)"; -static const char HT_10410[] = "PDF 1.1 - 1.3 (Acrobat 2 - 4) + collider-mode #1"; -static const char HT_10420[] = "PDF 1.1 - 1.3 (Acrobat 2 - 4) + collider-mode #2"; -static const char HT_10500[] = "PDF 1.4 - 1.6 (Acrobat 5 - 8)"; -static const char HT_10600[] = "PDF 1.7 Level 3 (Acrobat 9)"; -static const char HT_10700[] = "PDF 1.7 Level 8 (Acrobat 10 - 11)"; -static const char HT_10800[] = "SHA384"; -static const char HT_10900[] = "PBKDF2-HMAC-SHA256"; -static const char HT_11000[] = "PrestaShop"; -static const char HT_11100[] = "PostgreSQL Challenge-Response Authentication (MD5)"; -static const char HT_11200[] = "MySQL Challenge-Response Authentication (SHA1)"; -static const char HT_11300[] = "Bitcoin/Litecoin wallet.dat"; -static const char HT_11400[] = "SIP digest authentication (MD5)"; -static const char HT_11500[] = "CRC32"; -static const char HT_11600[] = "7-Zip"; -static const char HT_11700[] = "GOST R 34.11-2012 (Streebog) 256-bit"; -static const char HT_11800[] = "GOST R 34.11-2012 (Streebog) 512-bit"; -static const char HT_11900[] = "PBKDF2-HMAC-MD5"; -static const char HT_12000[] = "PBKDF2-HMAC-SHA1"; -static const char HT_12100[] = "PBKDF2-HMAC-SHA512"; -static const char HT_12200[] = "eCryptfs"; -static const char HT_12300[] = "Oracle T: Type (Oracle 12+)"; -static const char HT_12400[] = "BSDiCrypt, Extended DES"; -static const char HT_12500[] = "RAR3-hp"; -static const char HT_12600[] = "ColdFusion 10+"; -static const char HT_12700[] = "Blockchain, My Wallet"; -static const char HT_12800[] = "MS-AzureSync PBKDF2-HMAC-SHA256"; -static const char HT_12900[] = "Android FDE (Samsung DEK)"; -static const char HT_13000[] = "RAR5"; -static const char HT_13100[] = "Kerberos 5 TGS-REP etype 23"; -static const char HT_13200[] = "AxCrypt"; -static const char HT_13300[] = "AxCrypt in memory SHA1"; -static const char HT_13400[] = "Keepass 1 (AES/Twofish) and Keepass 2 (AES)"; -static const char HT_13500[] = "PeopleSoft PS_TOKEN"; -static const char HT_13600[] = "WinZip"; -static const char HT_13800[] = "Windows 8+ phone PIN/Password"; -static const char HT_13900[] = "OpenCart"; -static const char HT_14000[] = "DES (PT = $salt, key = $pass)"; -static const char HT_14100[] = "3DES (PT = $salt, key = $pass)"; - -static const char HT_00011[] = "Joomla < 2.5.18"; -static const char HT_00012[] = "PostgreSQL"; -static const char HT_00021[] = "osCommerce, xt:Commerce"; -static const char HT_00022[] = "Juniper Netscreen/SSG (ScreenOS)"; -static const char HT_00023[] = "Skype"; -static const char HT_00101[] = "SHA-1(Base64), nsldap, Netscape LDAP SHA"; -static const char HT_00111[] = "SSHA-1(Base64), nsldaps, Netscape LDAP SSHA"; -static const char HT_00112[] = "Oracle S: Type (Oracle 11+)"; -static const char HT_00121[] = "SMF > v1.1"; -static const char HT_00122[] = "OSX v10.4, v10.5, v10.6"; -static const char HT_00124[] = "Django (SHA-1)"; -static const char HT_00125[] = "ArubaOS"; -static const char HT_00131[] = "MSSQL(2000)"; -static const char HT_00132[] = "MSSQL(2005)"; -static const char HT_00133[] = "PeopleSoft"; -static const char HT_00141[] = "EPiServer 6.x < v4"; -static const char HT_01421[] = "hMailServer"; -static const char HT_01441[] = "EPiServer 6.x > v4"; -static const char HT_01711[] = "SSHA-512(Base64), LDAP {SSHA512}"; -static const char HT_01722[] = "OSX v10.7"; -static const char HT_01731[] = "MSSQL(2012)"; -static const char HT_02611[] = "vBulletin < v3.8.5"; -static const char HT_02612[] = "PHPS"; -static const char HT_02711[] = "vBulletin > v3.8.5"; -static const char HT_02811[] = "IPB2+, MyBB1.2+"; -static const char HT_06211[] = "TrueCrypt PBKDF2-HMAC-RipeMD160 + XTS 512 bit"; -static const char HT_06212[] = "TrueCrypt PBKDF2-HMAC-RipeMD160 + XTS 1024 bit"; -static const char HT_06213[] = "TrueCrypt PBKDF2-HMAC-RipeMD160 + XTS 1536 bit"; -static const char HT_06221[] = "TrueCrypt PBKDF2-HMAC-SHA512 + XTS 512 bit"; -static const char HT_06222[] = "TrueCrypt PBKDF2-HMAC-SHA512 + XTS 1024 bit"; -static const char HT_06223[] = "TrueCrypt PBKDF2-HMAC-SHA512 + XTS 1536 bit"; -static const char HT_06231[] = "TrueCrypt PBKDF2-HMAC-Whirlpool + XTS 512 bit"; -static const char HT_06232[] = "TrueCrypt PBKDF2-HMAC-Whirlpool + XTS 1024 bit"; -static const char HT_06233[] = "TrueCrypt PBKDF2-HMAC-Whirlpool + XTS 1536 bit"; -static const char HT_06241[] = "TrueCrypt PBKDF2-HMAC-RipeMD160 + XTS 512 bit + boot-mode"; -static const char HT_06242[] = "TrueCrypt PBKDF2-HMAC-RipeMD160 + XTS 1024 bit + boot-mode"; -static const char HT_06243[] = "TrueCrypt PBKDF2-HMAC-RipeMD160 + XTS 1536 bit + boot-mode"; -static const char HT_13711[] = "VeraCrypt PBKDF2-HMAC-RipeMD160 + XTS 512 bit"; -static const char HT_13712[] = "VeraCrypt PBKDF2-HMAC-RipeMD160 + XTS 1024 bit"; -static const char HT_13713[] = "VeraCrypt PBKDF2-HMAC-RipeMD160 + XTS 1536 bit"; -static const char HT_13721[] = "VeraCrypt PBKDF2-HMAC-SHA512 + XTS 512 bit"; -static const char HT_13722[] = "VeraCrypt PBKDF2-HMAC-SHA512 + XTS 1024 bit"; -static const char HT_13723[] = "VeraCrypt PBKDF2-HMAC-SHA512 + XTS 1536 bit"; -static const char HT_13731[] = "VeraCrypt PBKDF2-HMAC-Whirlpool + XTS 512 bit"; -static const char HT_13732[] = "VeraCrypt PBKDF2-HMAC-Whirlpool + XTS 1024 bit"; -static const char HT_13733[] = "VeraCrypt PBKDF2-HMAC-Whirlpool + XTS 1536 bit"; -static const char HT_13741[] = "VeraCrypt PBKDF2-HMAC-RipeMD160 + XTS 512 bit + boot-mode"; -static const char HT_13742[] = "VeraCrypt PBKDF2-HMAC-RipeMD160 + XTS 1024 bit + boot-mode"; -static const char HT_13743[] = "VeraCrypt PBKDF2-HMAC-RipeMD160 + XTS 1536 bit + boot-mode"; -static const char HT_13751[] = "VeraCrypt PBKDF2-HMAC-SHA256 + XTS 512 bit"; -static const char HT_13752[] = "VeraCrypt PBKDF2-HMAC-SHA256 + XTS 1024 bit"; -static const char HT_13753[] = "VeraCrypt PBKDF2-HMAC-SHA256 + XTS 1536 bit"; -static const char HT_13761[] = "VeraCrypt PBKDF2-HMAC-SHA256 + XTS 512 bit + boot-mode"; -static const char HT_13762[] = "VeraCrypt PBKDF2-HMAC-SHA256 + XTS 1024 bit + boot-mode"; -static const char HT_13763[] = "VeraCrypt PBKDF2-HMAC-SHA256 + XTS 1536 bit + boot-mode"; - -/** - * Outfile formats - */ - -typedef enum outfile_fmt -{ - OUTFILE_FMT_HASH = (1 << 0), - OUTFILE_FMT_PLAIN = (1 << 1), - OUTFILE_FMT_HEXPLAIN = (1 << 2), - OUTFILE_FMT_CRACKPOS = (1 << 3) - -} outfile_fmt_t; - -/** - * algo specific - */ - -typedef enum display_len -{ - DISPLAY_LEN_MIN_0 = 32, - DISPLAY_LEN_MAX_0 = 32, - DISPLAY_LEN_MIN_10 = 32 + 1 + 0, - DISPLAY_LEN_MAX_10 = 32 + 1 + 51, - DISPLAY_LEN_MIN_10H = 32 + 1 + 0, - DISPLAY_LEN_MAX_10H = 32 + 1 + 102, - DISPLAY_LEN_MIN_20 = 32 + 1 + 0, - DISPLAY_LEN_MAX_20 = 32 + 1 + 31, - DISPLAY_LEN_MIN_20H = 32 + 1 + 0, - DISPLAY_LEN_MAX_20H = 32 + 1 + 62, - DISPLAY_LEN_MIN_50 = 32 + 1 + 0, - DISPLAY_LEN_MAX_50 = 32 + 1 + 51, - DISPLAY_LEN_MIN_50H = 32 + 1 + 0, - DISPLAY_LEN_MAX_50H = 32 + 1 + 102, - DISPLAY_LEN_MIN_100 = 40, - DISPLAY_LEN_MAX_100 = 40, - DISPLAY_LEN_MIN_110 = 40 + 1 + 0, - DISPLAY_LEN_MAX_110 = 40 + 1 + 51, - DISPLAY_LEN_MIN_110H = 40 + 1 + 0, - DISPLAY_LEN_MAX_110H = 40 + 1 + 102, - DISPLAY_LEN_MIN_120 = 40 + 1 + 0, - DISPLAY_LEN_MAX_120 = 40 + 1 + 31, - DISPLAY_LEN_MIN_120H = 40 + 1 + 0, - DISPLAY_LEN_MAX_120H = 40 + 1 + 62, - DISPLAY_LEN_MIN_150 = 40 + 1 + 0, - DISPLAY_LEN_MAX_150 = 40 + 1 + 51, - DISPLAY_LEN_MIN_150H = 40 + 1 + 0, - DISPLAY_LEN_MAX_150H = 40 + 1 + 102, - DISPLAY_LEN_MIN_200 = 16, - DISPLAY_LEN_MAX_200 = 16, - DISPLAY_LEN_MIN_300 = 40, - DISPLAY_LEN_MAX_300 = 40, - DISPLAY_LEN_MIN_400 = 34, - DISPLAY_LEN_MAX_400 = 34, - DISPLAY_LEN_MIN_500 = 3 + 1 + 0 + 22, - DISPLAY_LEN_MIN_501 = 104, - DISPLAY_LEN_MAX_500 = 3 + 1 + 8 + 22, - DISPLAY_LEN_MAX_501 = 104, - DISPLAY_LEN_MIN_900 = 32, - DISPLAY_LEN_MAX_900 = 32, - DISPLAY_LEN_MIN_910 = 32 + 1 + 0, - DISPLAY_LEN_MAX_910 = 32 + 1 + 51, - DISPLAY_LEN_MIN_910H = 32 + 1 + 0, - DISPLAY_LEN_MAX_910H = 32 + 1 + 102, - DISPLAY_LEN_MIN_1000 = 32, - DISPLAY_LEN_MAX_1000 = 32, - DISPLAY_LEN_MIN_1100 = 32 + 1 + 0, - DISPLAY_LEN_MAX_1100 = 32 + 1 + 19, - DISPLAY_LEN_MIN_1100H = 32 + 1 + 0, - DISPLAY_LEN_MAX_1100H = 32 + 1 + 38, - DISPLAY_LEN_MIN_1400 = 64, - DISPLAY_LEN_MAX_1400 = 64, - DISPLAY_LEN_MIN_1410 = 64 + 1 + 0, - DISPLAY_LEN_MAX_1410 = 64 + 1 + 51, - DISPLAY_LEN_MIN_1410H = 64 + 1 + 0, - DISPLAY_LEN_MAX_1410H = 64 + 1 + 102, - DISPLAY_LEN_MIN_1420 = 64 + 1 + 0, - DISPLAY_LEN_MAX_1420 = 64 + 1 + 16, - DISPLAY_LEN_MIN_1420H = 64 + 1 + 0, - DISPLAY_LEN_MAX_1420H = 64 + 1 + 32, - DISPLAY_LEN_MIN_1421 = 70, - DISPLAY_LEN_MAX_1421 = 70, - DISPLAY_LEN_MIN_1450 = 64 + 1 + 0, - DISPLAY_LEN_MAX_1450 = 64 + 1 + 51, - DISPLAY_LEN_MIN_1450H = 64 + 1 + 0, - DISPLAY_LEN_MAX_1450H = 64 + 1 + 102, - DISPLAY_LEN_MIN_1500 = 13, - DISPLAY_LEN_MAX_1500 = 13, - DISPLAY_LEN_MIN_1600 = 29 + 0, - DISPLAY_LEN_MAX_1600 = 29 + 8, - DISPLAY_LEN_MIN_1700 = 128, - DISPLAY_LEN_MAX_1700 = 128, - DISPLAY_LEN_MIN_1710 = 128 + 1 + 0, - DISPLAY_LEN_MAX_1710 = 128 + 1 + 51, - DISPLAY_LEN_MIN_1710H = 128 + 1 + 0, - DISPLAY_LEN_MAX_1710H = 128 + 1 + 102, - DISPLAY_LEN_MIN_1720 = 128 + 1 + 0, - DISPLAY_LEN_MAX_1720 = 128 + 1 + 16, - DISPLAY_LEN_MIN_1720H = 128 + 1 + 0, - DISPLAY_LEN_MAX_1720H = 128 + 1 + 32, - DISPLAY_LEN_MIN_1730 = 128 + 1 + 0, - DISPLAY_LEN_MAX_1730 = 128 + 1 + 16, - DISPLAY_LEN_MIN_1731 = 128 + 6 + 0, - DISPLAY_LEN_MAX_1731 = 128 + 6 + 16, - DISPLAY_LEN_MIN_1740 = 128 + 1 + 0, - DISPLAY_LEN_MAX_1740 = 128 + 1 + 16, - DISPLAY_LEN_MIN_1750 = 128 + 1 + 0, - DISPLAY_LEN_MAX_1750 = 128 + 1 + 51, - DISPLAY_LEN_MIN_1750H = 128 + 1 + 0, - DISPLAY_LEN_MAX_1750H = 128 + 1 + 102, - DISPLAY_LEN_MIN_1800 = 90 + 0, - DISPLAY_LEN_MAX_1800 = 90 + 16, - DISPLAY_LEN_MIN_2100 = 6 + 1 + 1 + 32 + 1 + 0, - DISPLAY_LEN_MAX_2100 = 6 + 5 + 1 + 32 + 1 + 19, - DISPLAY_LEN_MIN_2100H = 6 + 1 + 1 + 32 + 1 + 0, - DISPLAY_LEN_MAX_2100H = 6 + 5 + 1 + 32 + 1 + 38, - DISPLAY_LEN_MIN_2400 = 16, - DISPLAY_LEN_MAX_2400 = 16, - DISPLAY_LEN_MIN_2410 = 16 + 1 + 0, - DISPLAY_LEN_MAX_2410 = 16 + 1 + 16, - DISPLAY_LEN_MIN_2410H = 16 + 1 + 0, - DISPLAY_LEN_MAX_2410H = 16 + 1 + 32, - DISPLAY_LEN_MIN_2500 = 64 + 1 + 0, - DISPLAY_LEN_MAX_2500 = 64 + 1 + 15, - DISPLAY_LEN_MIN_2600 = 32, - DISPLAY_LEN_MAX_2600 = 32, - DISPLAY_LEN_MIN_3000 = 16, - DISPLAY_LEN_MAX_3000 = 16, - DISPLAY_LEN_MIN_3100 = 16 + 1 + 0, - DISPLAY_LEN_MAX_3100 = 16 + 1 + 30, - DISPLAY_LEN_MIN_3100H = 16 + 1 + 0, - DISPLAY_LEN_MAX_3100H = 16 + 1 + 60, - DISPLAY_LEN_MIN_3200 = 60, - DISPLAY_LEN_MAX_3200 = 60, - DISPLAY_LEN_MIN_3711 = 3 + 0 + 1 + 32, - DISPLAY_LEN_MAX_3711 = 3 + 31 + 1 + 32, - DISPLAY_LEN_MIN_4300 = 32, - DISPLAY_LEN_MAX_4300 = 32, - DISPLAY_LEN_MIN_4800 = 32 + 1 + 32 + 1 + 2, - DISPLAY_LEN_MAX_4800 = 32 + 1 + 32 + 1 + 2, - DISPLAY_LEN_MIN_5000 = 16, - DISPLAY_LEN_MAX_5000 = 400, - DISPLAY_LEN_MIN_5100 = 16, - DISPLAY_LEN_MAX_5100 = 16, - DISPLAY_LEN_MIN_5300 = 48, - DISPLAY_LEN_MAX_5300 = 1024, - DISPLAY_LEN_MIN_5400 = 56, - DISPLAY_LEN_MAX_5400 = 1024, - DISPLAY_LEN_MIN_5500 = 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 48 + 1 + 16, - DISPLAY_LEN_MAX_5500 = 60 + 1 + 0 + 1 + 45 + 1 + 48 + 1 + 48 + 1 + 16, - DISPLAY_LEN_MIN_5600 = 1 + 1 + 0 + 1 + 1 + 1 + 16 + 1 + 32 + 1 + 1, - DISPLAY_LEN_MAX_5600 = 60 + 1 + 0 + 1 + 45 + 1 + 16 + 1 + 32 + 1 + 1024, - DISPLAY_LEN_MIN_5700 = 43, - DISPLAY_LEN_MAX_5700 = 43, - DISPLAY_LEN_MIN_5800 = 40 + 1 + 1, - DISPLAY_LEN_MAX_5800 = 40 + 1 + 16, - DISPLAY_LEN_MIN_6000 = 40, - DISPLAY_LEN_MAX_6000 = 40, - DISPLAY_LEN_MIN_6100 = 128, - DISPLAY_LEN_MAX_6100 = 128, - DISPLAY_LEN_MIN_6300 = 6 + 1 + 8 + 22, - DISPLAY_LEN_MAX_6300 = 6 + 1 + 48 + 22, - DISPLAY_LEN_MIN_6400 = 9 + 2 + 1 + 16 + 1 + 43, - DISPLAY_LEN_MAX_6400 = 9 + 2 + 1 + 48 + 1 + 43, - DISPLAY_LEN_MIN_6500 = 9 + 2 + 1 + 16 + 1 + 86, - DISPLAY_LEN_MAX_6500 = 9 + 2 + 1 + 48 + 1 + 86, - DISPLAY_LEN_MIN_6600 = 1 + 1 + 16 + 1 + 2080, - DISPLAY_LEN_MAX_6600 = 6 + 1 + 16 + 1 + 2080, - DISPLAY_LEN_MIN_6700 = 7 + 2 + 1 + 16 + 1 + 27, - DISPLAY_LEN_MAX_6700 = 7 + 2 + 1 + 48 + 1 + 27, - DISPLAY_LEN_MIN_6800 = 32 + 1 + 1 + 1 + 0, - DISPLAY_LEN_MAX_6800 = 32 + 1 + 5 + 1 + 32, - DISPLAY_LEN_MIN_6900 = 64, - DISPLAY_LEN_MAX_6900 = 64, - DISPLAY_LEN_MIN_7100 = 4 + 2 + 1 + 64 + 1 + 128, - DISPLAY_LEN_MAX_7100 = 4 + 5 + 1 + 64 + 1 + 128, - DISPLAY_LEN_MIN_7200 = 19 + 1 + 1 + 1 + 128, - DISPLAY_LEN_MAX_7200 = 19 + 5 + 1 + 224 + 128, - DISPLAY_LEN_MIN_7300 = 64 + 1 + 40, - DISPLAY_LEN_MAX_7300 = 512 + 1 + 40, - DISPLAY_LEN_MIN_7400 = 47 + 0, - DISPLAY_LEN_MAX_7400 = 47 + 16, - DISPLAY_LEN_MIN_7500 = 1 + 6 + 1 + 2 + 1 + 0 + 1 + 0 + 1 + 0 + 1 + 72 + 32, - DISPLAY_LEN_MAX_7500 = 1 + 6 + 1 + 2 + 1 + 64 + 1 + 64 + 1 + 128 + 1 + 72 + 32, - DISPLAY_LEN_MIN_7700 = 1 + 1 + 16, - DISPLAY_LEN_MAX_7700 = 40 + 1 + 16, - DISPLAY_LEN_MIN_7800 = 1 + 1 + 40, - DISPLAY_LEN_MAX_7800 = 40 + 1 + 40, - DISPLAY_LEN_MIN_7900 = 3 + 1 + 8 + 43, - DISPLAY_LEN_MAX_7900 = 3 + 1 + 8 + 43, - DISPLAY_LEN_MIN_8000 = 2 + 4 + 16 + 64, - DISPLAY_LEN_MAX_8000 = 2 + 4 + 16 + 64, - DISPLAY_LEN_MIN_8100 = 1 + 8 + 40, - DISPLAY_LEN_MAX_8100 = 1 + 8 + 40, - DISPLAY_LEN_MIN_8200 = 64 + 1 + 32 + 1 + 1 + 1 + 1, - DISPLAY_LEN_MAX_8200 = 64 + 1 + 32 + 1 + 8 + 1 + 2048, - DISPLAY_LEN_MIN_8300 = 32 + 1 + 1 + 1 + 1 + 1 + 1, - DISPLAY_LEN_MAX_8300 = 32 + 1 + 32 + 1 + 32 + 1 + 5, - DISPLAY_LEN_MIN_8400 = 40 + 1 + 40, - DISPLAY_LEN_MAX_8400 = 40 + 1 + 40, - DISPLAY_LEN_MIN_8500 = 6 + 1 + 1 + 1 + 1, - DISPLAY_LEN_MAX_8500 = 6 + 1 + 8 + 1 + 16, - DISPLAY_LEN_MIN_8600 = 32, - DISPLAY_LEN_MAX_8600 = 32, - DISPLAY_LEN_MIN_8700 = 22, - DISPLAY_LEN_MAX_8700 = 22, - DISPLAY_LEN_MIN_8800 = 1 + 3 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 32 + 1 + 3072, - DISPLAY_LEN_MAX_8800 = 1 + 3 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 32 + 1 + 3072, - DISPLAY_LEN_MIN_8900 = 6 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 44, - DISPLAY_LEN_MAX_8900 = 6 + 1 + 6 + 1 + 2 + 1 + 2 + 1 + 45 + 1 + 44, - DISPLAY_LEN_MIN_9100 = 51, - DISPLAY_LEN_MAX_9100 = 51, - DISPLAY_LEN_MIN_9200 = 3 + 14 + 1 + 43, - DISPLAY_LEN_MAX_9200 = 3 + 14 + 1 + 43, - DISPLAY_LEN_MIN_9300 = 3 + 14 + 1 + 43, - DISPLAY_LEN_MAX_9300 = 3 + 14 + 1 + 43, - DISPLAY_LEN_MIN_9400 = 8 + 1 + 4 + 1 + 2 + 1 + 3 + 1 + 2 + 1 + 32 + 1 + 32 + 1 + 40, - DISPLAY_LEN_MAX_9400 = 8 + 1 + 4 + 1 + 2 + 1 + 3 + 1 + 2 + 1 + 32 + 1 + 32 + 1 + 40, - DISPLAY_LEN_MIN_9500 = 8 + 1 + 4 + 1 + 6 + 1 + 3 + 1 + 2 + 1 + 32 + 1 + 32 + 1 + 64, - DISPLAY_LEN_MAX_9500 = 8 + 1 + 4 + 1 + 6 + 1 + 3 + 1 + 2 + 1 + 32 + 1 + 32 + 1 + 64, - DISPLAY_LEN_MIN_9600 = 8 + 1 + 4 + 1 + 6 + 1 + 3 + 1 + 2 + 1 + 32 + 1 + 32 + 1 + 64, - DISPLAY_LEN_MAX_9600 = 8 + 1 + 4 + 1 + 6 + 1 + 3 + 1 + 2 + 1 + 32 + 1 + 32 + 1 + 64, - DISPLAY_LEN_MIN_9700 = 12 + 1 + 32 + 1 + 32 + 1 + 32, - DISPLAY_LEN_MAX_9700 = 12 + 1 + 32 + 1 + 32 + 1 + 32, - DISPLAY_LEN_MIN_9720 = 12 + 1 + 32 + 1 + 32 + 1 + 32 + 1 + 10, - DISPLAY_LEN_MAX_9720 = 12 + 1 + 32 + 1 + 32 + 1 + 32 + 1 + 10, - DISPLAY_LEN_MIN_9800 = 12 + 1 + 32 + 1 + 32 + 1 + 40, - DISPLAY_LEN_MAX_9800 = 12 + 1 + 32 + 1 + 32 + 1 + 40, - DISPLAY_LEN_MIN_9820 = 12 + 1 + 32 + 1 + 32 + 1 + 40 + 1 + 10, - DISPLAY_LEN_MAX_9820 = 12 + 1 + 32 + 1 + 32 + 1 + 40 + 1 + 10, - DISPLAY_LEN_MIN_9900 = 32, - DISPLAY_LEN_MAX_9900 = 32, - DISPLAY_LEN_MIN_10000 = 13 + 1 + 1 + 1 + 0 + 44, - DISPLAY_LEN_MAX_10000 = 13 + 1 + 6 + 1 + 15 + 44, - DISPLAY_LEN_MIN_10100 = 16 + 1 + 1 + 1 + 1 + 1 + 32, - DISPLAY_LEN_MAX_10100 = 16 + 1 + 1 + 1 + 1 + 1 + 32, - DISPLAY_LEN_MIN_10200 = 10 + 12 + 1 + 44, - DISPLAY_LEN_MAX_10200 = 10 + 76 + 1 + 132, - DISPLAY_LEN_MIN_10300 = 10 + 1 + 1 + 33, - DISPLAY_LEN_MAX_10300 = 10 + 5 + 1 + 49, - DISPLAY_LEN_MIN_10400 = 5 + 1 + 1 + 1 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64, - DISPLAY_LEN_MAX_10400 = 5 + 1 + 1 + 1 + 1 + 2 + 1 + 5 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64, - DISPLAY_LEN_MIN_10410 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64, - DISPLAY_LEN_MAX_10410 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 5 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64, - DISPLAY_LEN_MIN_10420 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64 + 1 + 10, - DISPLAY_LEN_MAX_10420 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 5 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64 + 1 + 10, - DISPLAY_LEN_MIN_10500 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64, - DISPLAY_LEN_MAX_10500 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 5 + 1 + 1 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64 + 1 + 2 + 1 + 64, - DISPLAY_LEN_MIN_10600 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 1, - DISPLAY_LEN_MAX_10600 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 5 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 1000, - DISPLAY_LEN_MIN_10700 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 1, - DISPLAY_LEN_MAX_10700 = 5 + 1 + 1 + 1 + 1 + 3 + 1 + 5 + 1 + 1 + 1 + 2 + 1 + 32 + 1 + 1000, - DISPLAY_LEN_MIN_10800 = 96, - DISPLAY_LEN_MAX_10800 = 96, - DISPLAY_LEN_MIN_10900 = 7 + 1 + 1 + 0 + 1 + 24, - DISPLAY_LEN_MAX_10900 = 7 + 6 + 1 + 64 + 1 + 88, - DISPLAY_LEN_MIN_11000 = 32 + 1 + 56, - DISPLAY_LEN_MAX_11000 = 32 + 1 + 56, - DISPLAY_LEN_MIN_11100 = 10 + 0 + 1 + 8 + 1 + 32, - DISPLAY_LEN_MAX_11100 = 10 + 32 + 1 + 8 + 1 + 32, - DISPLAY_LEN_MIN_11200 = 9 + 40 + 1 + 40, - DISPLAY_LEN_MAX_11200 = 9 + 40 + 1 + 40, - DISPLAY_LEN_MIN_11300 = 1 + 7 + 1 + 2 + 1 + 96 + 1 + 2 + 1 + 16 + 1 + 1 + 1 + 2 + 1 + 96 + 1 + 1 + 1 + 2, - DISPLAY_LEN_MAX_11300 = 1 + 7 + 1 + 2 + 1 + 96 + 1 + 2 + 1 + 16 + 1 + 6 + 1 + 2 + 1 + 96 + 1 + 3 + 1 + 512, - DISPLAY_LEN_MIN_11400 = 6 + 0 + 1 + 0 + 1 + 0 + 1 + 0 + 1 + 0 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 0 + 1 + 0 + 1 + 3 + 1 + 32, - DISPLAY_LEN_MAX_11400 = 6 + 512 + 1 + 512 + 1 + 116 + 1 + 116 + 1 + 246 + 1 + 245 + 1 + 246 + 1 + 245 + 1 + 50 + 1 + 50 + 1 + 50 + 1 + 50 + 1 + 3 + 1 + 32, - DISPLAY_LEN_MIN_11500 = 8 + 1 + 8, - DISPLAY_LEN_MAX_11500 = 8 + 1 + 8, - DISPLAY_LEN_MIN_11600 = 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 32 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 2, - DISPLAY_LEN_MAX_11600 = 1 + 2 + 1 + 1 + 1 + 2 + 1 + 1 + 1 + 64 + 1 + 1 + 1 + 32 + 1 + 10 + 1 + 3 + 1 + 3 + 1 + 768, - DISPLAY_LEN_MIN_11700 = 64, - DISPLAY_LEN_MAX_11700 = 64, - DISPLAY_LEN_MIN_11800 = 128, - DISPLAY_LEN_MAX_11800 = 128, - DISPLAY_LEN_MIN_11900 = 3 + 1 + 1 + 0 + 1 + 12, - DISPLAY_LEN_MAX_11900 = 3 + 6 + 1 + 64 + 1 + 88, - DISPLAY_LEN_MIN_12000 = 4 + 1 + 1 + 0 + 1 + 16, - DISPLAY_LEN_MAX_12000 = 4 + 6 + 1 + 64 + 1 + 88, - DISPLAY_LEN_MIN_12100 = 6 + 1 + 1 + 0 + 1 + 16, - DISPLAY_LEN_MAX_12100 = 6 + 6 + 1 + 64 + 1 + 88, - DISPLAY_LEN_MIN_12200 = 1 + 8 + 1 + 1 + 1 + 1 + 1 + 16 + 1 + 16, - DISPLAY_LEN_MAX_12200 = 1 + 8 + 1 + 1 + 1 + 1 + 1 + 16 + 1 + 16, - DISPLAY_LEN_MIN_12300 = 160, - DISPLAY_LEN_MAX_12300 = 160, - DISPLAY_LEN_MIN_12400 = 1 + 4 + 4 + 11, - DISPLAY_LEN_MAX_12400 = 1 + 4 + 4 + 11, - DISPLAY_LEN_MIN_12500 = 6 + 1 + 1 + 1 + 16 + 1 + 32, - DISPLAY_LEN_MAX_12500 = 6 + 1 + 1 + 1 + 16 + 1 + 32, - DISPLAY_LEN_MIN_12600 = 64 + 1 + 64, - DISPLAY_LEN_MAX_12600 = 64 + 1 + 64, - DISPLAY_LEN_MIN_12700 = 1 + 10 + 1 + 1 + 1 + 64, - DISPLAY_LEN_MAX_12700 = 1 + 10 + 1 + 5 + 1 + 20000, - DISPLAY_LEN_MIN_12800 = 11 + 1 + 20 + 1 + 1 + 1 + 64, - DISPLAY_LEN_MAX_12800 = 11 + 1 + 20 + 1 + 5 + 1 + 64, - DISPLAY_LEN_MIN_12900 = 64 + 64 + 32, - DISPLAY_LEN_MAX_12900 = 64 + 64 + 32, - DISPLAY_LEN_MIN_13000 = 1 + 4 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 32 + 1 + 1 + 1 + 16, - DISPLAY_LEN_MAX_13000 = 1 + 4 + 1 + 2 + 1 + 32 + 1 + 2 + 1 + 32 + 1 + 1 + 1 + 16, - DISPLAY_LEN_MIN_13100 = 1 + 7 + 1 + 2 + 1 + 0 + 0 + 32 + 1 + 64, - DISPLAY_LEN_MAX_13100 = 1 + 7 + 1 + 2 + 1 + 2 + 512 + 1 + 32 + 1 + 20480, - DISPLAY_LEN_MIN_13200 = 1 + 7 + 1 + 1 + 1 + 1 + 1 + 1 + 32 + 1 + 48, - DISPLAY_LEN_MAX_13200 = 1 + 7 + 1 + 1 + 1 + 1 + 50 + 1 + 32 + 1 + 48 + 1 + 20480, - DISPLAY_LEN_MIN_13300 = 1 + 12 + 1 + 32, - DISPLAY_LEN_MAX_13300 = 1 + 12 + 1 + 40, - DISPLAY_LEN_MIN_13400 = 1 + 7 + 1 + 1 + 1 + 1 + 1 + 1 + 32 + 1 + 64 + 1 + 32 + 1 + 64 + 1 + 1 + 1 + 1, - DISPLAY_LEN_MAX_13400 = 1 + 7 + 1 + 1 + 10 + 1 + 3 + 1 + 64 + 1 + 64 + 1 + 32 + 1 + 64 + 1 + 4 + 1 + 600000 + 1 + 2 + 1 + 64, - DISPLAY_LEN_MIN_13500 = 40 + 1 + 32, - DISPLAY_LEN_MAX_13500 = 40 + 1 + 1024, - DISPLAY_LEN_MIN_13600 = 6 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 16 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 20 + 1 + 7, - DISPLAY_LEN_MAX_13600 = 6 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 32 + 1 + 4 + 1 + 4 + 1 + 8192 + 1 + 20 + 1 + 7, - DISPLAY_LEN_MIN_13800 = 64 + 1 + 256, - DISPLAY_LEN_MAX_13800 = 64 + 1 + 256, - DISPLAY_LEN_MIN_13900 = 40 + 1 + 9, - DISPLAY_LEN_MAX_13900 = 40 + 1 + 9, - DISPLAY_LEN_MIN_14000 = 16 + 1 + 16, - DISPLAY_LEN_MAX_14000 = 16 + 1 + 16, - DISPLAY_LEN_MIN_14100 = 16 + 1 + 16, - DISPLAY_LEN_MAX_14100 = 16 + 1 + 16, - - DISPLAY_LEN_MIN_11 = 32 + 1 + 16, - DISPLAY_LEN_MAX_11 = 32 + 1 + 32, - DISPLAY_LEN_MIN_11H = 32 + 1 + 32, - DISPLAY_LEN_MAX_11H = 32 + 1 + 64, - DISPLAY_LEN_MIN_12 = 32 + 1 + 1, - DISPLAY_LEN_MAX_12 = 32 + 1 + 32, - DISPLAY_LEN_MIN_12H = 32 + 1 + 2, - DISPLAY_LEN_MAX_12H = 32 + 1 + 64, - DISPLAY_LEN_MIN_21 = 32 + 1 + 1, - DISPLAY_LEN_MAX_21 = 32 + 1 + 15, - DISPLAY_LEN_MIN_21H = 32 + 1 + 2, - DISPLAY_LEN_MAX_21H = 32 + 1 + 30, - DISPLAY_LEN_MIN_22 = 30 + 1 + 1, - DISPLAY_LEN_MAX_22 = 30 + 1 + 28, - DISPLAY_LEN_MIN_22H = 30 + 1 + 2, - DISPLAY_LEN_MAX_22H = 30 + 1 + 56, - DISPLAY_LEN_MIN_23 = 32 + 1 + 0, - DISPLAY_LEN_MAX_23 = 32 + 1 + 23, - DISPLAY_LEN_MIN_101 = 5 + 28, - DISPLAY_LEN_MAX_101 = 5 + 28, - DISPLAY_LEN_MIN_111 = 6 + 28 + 0, - DISPLAY_LEN_MAX_111 = 6 + 28 + 40, - DISPLAY_LEN_MIN_112 = 40 + 1 + 20, - DISPLAY_LEN_MAX_112 = 40 + 1 + 20, - DISPLAY_LEN_MIN_121 = 40 + 1 + 1, - DISPLAY_LEN_MAX_121 = 40 + 1 + 32, - DISPLAY_LEN_MIN_121H = 40 + 1 + 2, - DISPLAY_LEN_MAX_121H = 40 + 1 + 64, - DISPLAY_LEN_MIN_122 = 8 + 40, - DISPLAY_LEN_MAX_122 = 8 + 40, - DISPLAY_LEN_MIN_124 = 4 + 1 + 0 + 1 + 40, - DISPLAY_LEN_MAX_124 = 4 + 1 + 32 + 1 + 40, - DISPLAY_LEN_MIN_125 = 10 + 40, - DISPLAY_LEN_MAX_125 = 10 + 40, - DISPLAY_LEN_MIN_131 = 6 + 8 + 80, - DISPLAY_LEN_MAX_131 = 6 + 8 + 80, - DISPLAY_LEN_MIN_132 = 6 + 8 + 40, - DISPLAY_LEN_MAX_132 = 6 + 8 + 40, - DISPLAY_LEN_MIN_133 = 28, - DISPLAY_LEN_MAX_133 = 28, - DISPLAY_LEN_MIN_141 = 14 + 0 + 1 + 28, - DISPLAY_LEN_MAX_141 = 14 + 44 + 1 + 28, - DISPLAY_LEN_MIN_1441 = 14 + 0 + 1 + 43, - DISPLAY_LEN_MAX_1441 = 14 + 24 + 1 + 43, - DISPLAY_LEN_MIN_1711 = 9 + 86 + 0, - DISPLAY_LEN_MAX_1711 = 9 + 86 + 68, - DISPLAY_LEN_MIN_1722 = 8 + 128, - DISPLAY_LEN_MAX_1722 = 8 + 128, - DISPLAY_LEN_MIN_2611 = 32 + 1 + 0, - DISPLAY_LEN_MAX_2611 = 32 + 1 + 23, - DISPLAY_LEN_MIN_2611H = 32 + 1 + 0, - DISPLAY_LEN_MIN_2612 = 6 + 0 + 1 + 32, - DISPLAY_LEN_MAX_2611H = 32 + 1 + 46, - DISPLAY_LEN_MAX_2612 = 6 + 46 + 1 + 32, - DISPLAY_LEN_MIN_2711 = 32 + 1 + 23, - DISPLAY_LEN_MAX_2711 = 32 + 1 + 31, - DISPLAY_LEN_MIN_2711H = 32 + 1 + 46, - DISPLAY_LEN_MAX_2711H = 32 + 1 + 62, - DISPLAY_LEN_MIN_2811 = 32 + 1 + 0, - DISPLAY_LEN_MAX_2811 = 32 + 1 + 31, - DISPLAY_LEN_MIN_2811H = 32 + 1 + 0, - DISPLAY_LEN_MAX_2811H = 32 + 1 + 62, - DISPLAY_LEN_MIN_7600 = 40 + 1 + 32, - DISPLAY_LEN_MAX_7600 = 40 + 1 + 32, - -} display_len_t; - -typedef enum hash_type -{ - HASH_TYPE_MD4 = 1, - HASH_TYPE_MD5 = 2, - HASH_TYPE_MD5H = 3, - HASH_TYPE_SHA1 = 4, - HASH_TYPE_SHA256 = 5, - HASH_TYPE_SHA384 = 6, - HASH_TYPE_SHA512 = 7, - HASH_TYPE_DCC2 = 8, - HASH_TYPE_WPA = 9, - HASH_TYPE_LM = 10, - HASH_TYPE_DESCRYPT = 11, - HASH_TYPE_ORACLEH = 12, - HASH_TYPE_DESRACF = 13, - HASH_TYPE_BCRYPT = 14, - HASH_TYPE_KECCAK = 15, - HASH_TYPE_NETNTLM = 16, - HASH_TYPE_RIPEMD160 = 17, - HASH_TYPE_WHIRLPOOL = 18, - HASH_TYPE_AES = 19, - HASH_TYPE_GOST = 20, - HASH_TYPE_KRB5PA = 21, - HASH_TYPE_SAPB = 22, - HASH_TYPE_SAPG = 23, - HASH_TYPE_MYSQL = 24, - HASH_TYPE_LOTUS5 = 25, - HASH_TYPE_LOTUS6 = 26, - HASH_TYPE_ANDROIDFDE = 27, - HASH_TYPE_SCRYPT = 28, - HASH_TYPE_LOTUS8 = 29, - HASH_TYPE_OFFICE2007 = 30, - HASH_TYPE_OFFICE2010 = 31, - HASH_TYPE_OFFICE2013 = 32, - HASH_TYPE_OLDOFFICE01 = 33, - HASH_TYPE_OLDOFFICE34 = 34, - HASH_TYPE_SIPHASH = 35, - HASH_TYPE_PDFU16 = 36, - HASH_TYPE_PDFU32 = 37, - HASH_TYPE_PBKDF2_SHA256 = 38, - HASH_TYPE_BITCOIN_WALLET = 39, - HASH_TYPE_CRC32 = 40, - HASH_TYPE_GOST_2012SBOG_256 = 41, - HASH_TYPE_GOST_2012SBOG_512 = 42, - HASH_TYPE_PBKDF2_MD5 = 43, - HASH_TYPE_PBKDF2_SHA1 = 44, - HASH_TYPE_PBKDF2_SHA512 = 45, - HASH_TYPE_ECRYPTFS = 46, - HASH_TYPE_ORACLET = 47, - HASH_TYPE_BSDICRYPT = 48, - HASH_TYPE_RAR3HP = 49, - HASH_TYPE_KRB5TGS = 50, - HASH_TYPE_STDOUT = 51, - HASH_TYPE_DES = 52 - -} hash_type_t; - -typedef enum kern_type -{ - KERN_TYPE_MD5 = 0, - KERN_TYPE_MD5_PWSLT = 10, - KERN_TYPE_MD5_SLTPW = 20, - KERN_TYPE_MD5_PWUSLT = 30, - KERN_TYPE_MD5_SLTPWU = 40, - KERN_TYPE_HMACMD5_PW = 50, - KERN_TYPE_HMACMD5_SLT = 60, - KERN_TYPE_SHA1 = 100, - KERN_TYPE_SHA1_PWSLT = 110, - KERN_TYPE_SHA1_SLTPW = 120, - KERN_TYPE_SHA1_PWUSLT = 130, - KERN_TYPE_SHA1_SLTPWU = 140, - KERN_TYPE_HMACSHA1_PW = 150, - KERN_TYPE_HMACSHA1_SLT = 160, - KERN_TYPE_MYSQL = 200, - KERN_TYPE_MYSQL41 = 300, - KERN_TYPE_PHPASS = 400, - KERN_TYPE_MD5CRYPT = 500, - KERN_TYPE_MD4 = 900, - KERN_TYPE_MD4_PWU = 1000, - KERN_TYPE_MD44_PWUSLT = 1100, - KERN_TYPE_SHA256 = 1400, - KERN_TYPE_SHA256_PWSLT = 1410, - KERN_TYPE_SHA256_SLTPW = 1420, - KERN_TYPE_SHA256_PWUSLT = 1430, - KERN_TYPE_SHA256_SLTPWU = 1440, - KERN_TYPE_HMACSHA256_PW = 1450, - KERN_TYPE_HMACSHA256_SLT = 1460, - KERN_TYPE_DESCRYPT = 1500, - KERN_TYPE_APR1CRYPT = 1600, - KERN_TYPE_SHA512 = 1700, - KERN_TYPE_SHA512_PWSLT = 1710, - KERN_TYPE_SHA512_SLTPW = 1720, - KERN_TYPE_SHA512_PWSLTU = 1730, - KERN_TYPE_SHA512_SLTPWU = 1740, - KERN_TYPE_HMACSHA512_PW = 1750, - KERN_TYPE_HMACSHA512_SLT = 1760, - KERN_TYPE_SHA512CRYPT = 1800, - KERN_TYPE_STDOUT = 2000, - KERN_TYPE_DCC2 = 2100, - KERN_TYPE_MD5PIX = 2400, - KERN_TYPE_MD5ASA = 2410, - KERN_TYPE_WPA = 2500, - KERN_TYPE_MD55 = 2600, - KERN_TYPE_MD55_PWSLT1 = 2610, - KERN_TYPE_MD55_PWSLT2 = 2710, - KERN_TYPE_MD55_SLTPW = 2810, - KERN_TYPE_LM = 3000, - KERN_TYPE_ORACLEH = 3100, - KERN_TYPE_BCRYPT = 3200, - KERN_TYPE_MD5_SLT_MD5_PW = 3710, - KERN_TYPE_MD5_SLT_PW_SLT = 3800, - KERN_TYPE_MD5U5 = 4300, - KERN_TYPE_MD5U5_PWSLT1 = 4310, - KERN_TYPE_MD5_SHA1 = 4400, - KERN_TYPE_SHA11 = 4500, - KERN_TYPE_SHA1_MD5 = 4700, - KERN_TYPE_MD5_CHAP = 4800, - KERN_TYPE_SHA1_SLT_PW_SLT = 4900, - KERN_TYPE_KECCAK = 5000, - KERN_TYPE_MD5H = 5100, - KERN_TYPE_PSAFE3 = 5200, - KERN_TYPE_IKEPSK_MD5 = 5300, - KERN_TYPE_IKEPSK_SHA1 = 5400, - KERN_TYPE_NETNTLMv1 = 5500, - KERN_TYPE_NETNTLMv2 = 5600, - KERN_TYPE_ANDROIDPIN = 5800, - KERN_TYPE_RIPEMD160 = 6000, - KERN_TYPE_WHIRLPOOL = 6100, - KERN_TYPE_TCRIPEMD160_XTS512 = 6211, - KERN_TYPE_TCRIPEMD160_XTS1024 = 6212, - KERN_TYPE_TCRIPEMD160_XTS1536 = 6213, - KERN_TYPE_TCSHA512_XTS512 = 6221, - KERN_TYPE_TCSHA512_XTS1024 = 6222, - KERN_TYPE_TCSHA512_XTS1536 = 6223, - KERN_TYPE_TCWHIRLPOOL_XTS512 = 6231, - KERN_TYPE_TCWHIRLPOOL_XTS1024 = 6232, - KERN_TYPE_TCWHIRLPOOL_XTS1536 = 6233, - KERN_TYPE_VCSHA256_XTS512 = 13751, - KERN_TYPE_VCSHA256_XTS1024 = 13752, - KERN_TYPE_VCSHA256_XTS1536 = 13753, - KERN_TYPE_MD5AIX = 6300, - KERN_TYPE_SHA256AIX = 6400, - KERN_TYPE_SHA512AIX = 6500, - KERN_TYPE_AGILEKEY = 6600, - KERN_TYPE_SHA1AIX = 6700, - KERN_TYPE_LASTPASS = 6800, - KERN_TYPE_GOST = 6900, - KERN_TYPE_PBKDF2_SHA512 = 7100, - KERN_TYPE_RAKP = 7300, - KERN_TYPE_SHA256CRYPT = 7400, - KERN_TYPE_KRB5PA = 7500, - KERN_TYPE_SHA1_SLT_SHA1_PW = 7600, - KERN_TYPE_SAPB = 7700, - KERN_TYPE_SAPG = 7800, - KERN_TYPE_DRUPAL7 = 7900, - KERN_TYPE_SYBASEASE = 8000, - KERN_TYPE_NETSCALER = 8100, - KERN_TYPE_CLOUDKEY = 8200, - KERN_TYPE_NSEC3 = 8300, - KERN_TYPE_WBB3 = 8400, - KERN_TYPE_RACF = 8500, - KERN_TYPE_LOTUS5 = 8600, - KERN_TYPE_LOTUS6 = 8700, - KERN_TYPE_ANDROIDFDE = 8800, - KERN_TYPE_SCRYPT = 8900, - KERN_TYPE_PSAFE2 = 9000, - KERN_TYPE_LOTUS8 = 9100, - KERN_TYPE_OFFICE2007 = 9400, - KERN_TYPE_OFFICE2010 = 9500, - KERN_TYPE_OFFICE2013 = 9600, - KERN_TYPE_OLDOFFICE01 = 9700, - KERN_TYPE_OLDOFFICE01CM1 = 9710, - KERN_TYPE_OLDOFFICE01CM2 = 9720, - KERN_TYPE_OLDOFFICE34 = 9800, - KERN_TYPE_OLDOFFICE34CM1 = 9810, - KERN_TYPE_OLDOFFICE34CM2 = 9820, - KERN_TYPE_RADMIN2 = 9900, - KERN_TYPE_SIPHASH = 10100, - KERN_TYPE_SAPH_SHA1 = 10300, - KERN_TYPE_PDF11 = 10400, - KERN_TYPE_PDF11CM1 = 10410, - KERN_TYPE_PDF11CM2 = 10420, - KERN_TYPE_PDF14 = 10500, - KERN_TYPE_PDF17L8 = 10700, - KERN_TYPE_SHA384 = 10800, - KERN_TYPE_PBKDF2_SHA256 = 10900, - KERN_TYPE_PRESTASHOP = 11000, - KERN_TYPE_POSTGRESQL_AUTH = 11100, - KERN_TYPE_MYSQL_AUTH = 11200, - KERN_TYPE_BITCOIN_WALLET = 11300, - KERN_TYPE_SIP_AUTH = 11400, - KERN_TYPE_CRC32 = 11500, - KERN_TYPE_SEVEN_ZIP = 11600, - KERN_TYPE_GOST_2012SBOG_256 = 11700, - KERN_TYPE_GOST_2012SBOG_512 = 11800, - KERN_TYPE_PBKDF2_MD5 = 11900, - KERN_TYPE_PBKDF2_SHA1 = 12000, - KERN_TYPE_ECRYPTFS = 12200, - KERN_TYPE_ORACLET = 12300, - KERN_TYPE_BSDICRYPT = 12400, - KERN_TYPE_RAR3 = 12500, - KERN_TYPE_CF10 = 12600, - KERN_TYPE_MYWALLET = 12700, - KERN_TYPE_MS_DRSR = 12800, - KERN_TYPE_ANDROIDFDE_SAMSUNG = 12900, - KERN_TYPE_RAR5 = 13000, - KERN_TYPE_KRB5TGS = 13100, - KERN_TYPE_AXCRYPT = 13200, - KERN_TYPE_SHA1_AXCRYPT = 13300, - KERN_TYPE_KEEPASS = 13400, - KERN_TYPE_PSTOKEN = 13500, - KERN_TYPE_ZIP2 = 13600, - KERN_TYPE_WIN8PHONE = 13800, - KERN_TYPE_OPENCART = 13900, - KERN_TYPE_DES = 14000, - KERN_TYPE_3DES = 14100 - -} kern_type_t; - -/** - * signatures - */ - -static const char SIGNATURE_ANDROIDFDE[] = "$fde$"; -static const char SIGNATURE_AXCRYPT[] = "$axcrypt$*1"; -static const char SIGNATURE_AXCRYPT_SHA1[] = "$axcrypt_sha1"; -static const char SIGNATURE_BCRYPT1[] = "$2a$"; -static const char SIGNATURE_BCRYPT2[] = "$2b$"; -static const char SIGNATURE_BCRYPT3[] = "$2x$"; -static const char SIGNATURE_BCRYPT4[] = "$2y$"; -static const char SIGNATURE_BITCOIN_WALLET[] = "$bitcoin$"; -static const char SIGNATURE_BSDICRYPT[] = "_"; -static const char SIGNATURE_CISCO8[] = "$8$"; -static const char SIGNATURE_CISCO9[] = "$9$"; -static const char SIGNATURE_CRAM_MD5[] = "$cram_md5$"; -static const char SIGNATURE_DCC2[] = "$DCC2$"; -static const char SIGNATURE_DJANGOPBKDF2[] = "pbkdf2_sha256$"; -static const char SIGNATURE_DJANGOSHA1[] = "sha1$"; -static const char SIGNATURE_DRUPAL7[] = "$S$"; -static const char SIGNATURE_ECRYPTFS[] = "$ecryptfs$"; -static const char SIGNATURE_EPISERVER4[] = "$episerver$*1*"; -static const char SIGNATURE_EPISERVER[] = "$episerver$*0*"; -static const char SIGNATURE_KEEPASS[] = "$keepass$"; -static const char SIGNATURE_KRB5PA[] = "$krb5pa$23"; -static const char SIGNATURE_KRB5TGS[] = "$krb5tgs$23"; -static const char SIGNATURE_MD5AIX[] = "{smd5}"; -static const char SIGNATURE_MD5APR1[] = "$apr1$"; -static const char SIGNATURE_MD5CRYPT[] = "$1$"; -static const char SIGNATURE_MEDIAWIKI_B[] = "$B$"; -static const char SIGNATURE_MS_DRSR[] = "v1;PPH1_MD4"; -static const char SIGNATURE_MSSQL[] = "0x0100"; -static const char SIGNATURE_MSSQL2012[] = "0x0200"; -static const char SIGNATURE_MYSQL_AUTH[] = "$mysqlna$"; -static const char SIGNATURE_MYWALLET[] = "$blockchain$"; -static const char SIGNATURE_NETSCALER[] = "1"; -static const char SIGNATURE_OFFICE2007[] = "$office$"; -static const char SIGNATURE_OFFICE2010[] = "$office$"; -static const char SIGNATURE_OFFICE2013[] = "$office$"; -static const char SIGNATURE_OLDOFFICE0[] = "$oldoffice$0"; -static const char SIGNATURE_OLDOFFICE1[] = "$oldoffice$1"; -static const char SIGNATURE_OLDOFFICE3[] = "$oldoffice$3"; -static const char SIGNATURE_OLDOFFICE4[] = "$oldoffice$4"; -static const char SIGNATURE_PBKDF2_MD5[] = "md5:"; -static const char SIGNATURE_PBKDF2_SHA1[] = "sha1:"; -static const char SIGNATURE_PBKDF2_SHA256[] = "sha256:"; -static const char SIGNATURE_PBKDF2_SHA512[] = "sha512:"; -static const char SIGNATURE_PDF[] = "$pdf$"; -static const char SIGNATURE_PHPASS1[] = "$P$"; -static const char SIGNATURE_PHPASS2[] = "$H$"; -static const char SIGNATURE_PHPS[] = "$PHPS$"; -static const char SIGNATURE_POSTGRESQL_AUTH[] = "$postgres$"; -static const char SIGNATURE_PSAFE3[] = "PWS3"; -static const char SIGNATURE_RACF[] = "$racf$"; -static const char SIGNATURE_RAR3[] = "$RAR3$"; -static const char SIGNATURE_RAR5[] = "$rar5$"; -static const char SIGNATURE_SAPH_SHA1[] = "{x-issha, "; -static const char SIGNATURE_SCRYPT[] = "SCRYPT"; -static const char SIGNATURE_SEVEN_ZIP[] = "$7z$"; -static const char SIGNATURE_SHA1AIX[] = "{ssha1}"; -static const char SIGNATURE_SHA1B64[] = "{SHA}"; -static const char SIGNATURE_SHA256AIX[] = "{ssha256}"; -static const char SIGNATURE_SHA256CRYPT[] = "$5$"; -static const char SIGNATURE_SHA512AIX[] = "{ssha512}"; -static const char SIGNATURE_SHA512B64S[] = "{SSHA512}"; -static const char SIGNATURE_SHA512CRYPT[] = "$6$"; -static const char SIGNATURE_SHA512GRUB[] = "grub.pbkdf2.sha512."; -static const char SIGNATURE_SHA512OSX[] = "$ml$"; -static const char SIGNATURE_SIP_AUTH[] = "$sip$*"; -static const char SIGNATURE_SSHA1B64_lower[] = "{ssha}"; -static const char SIGNATURE_SSHA1B64_upper[] = "{SSHA}"; -static const char SIGNATURE_SYBASEASE[] = "0xc007"; -static const char SIGNATURE_TRUECRYPT[] = "TRUE"; -static const char SIGNATURE_ZIP2_START[] = "$zip2$"; -static const char SIGNATURE_ZIP2_STOP[] = "$/zip2$"; - -/** - * Default iteration numbers - */ - -typedef enum rounds_count -{ - ROUNDS_PHPASS = (1 << 11), // $P$B - ROUNDS_DCC2 = 10240, - ROUNDS_WPA2 = 4096, - ROUNDS_BCRYPT = (1 << 5), - ROUNDS_PSAFE3 = 2048, - ROUNDS_ANDROIDPIN = 1024, - ROUNDS_TRUECRYPT_1K = 1000, - ROUNDS_TRUECRYPT_2K = 2000, - ROUNDS_VERACRYPT_200000 = 200000, - ROUNDS_VERACRYPT_500000 = 500000, - ROUNDS_VERACRYPT_327661 = 327661, - ROUNDS_VERACRYPT_655331 = 655331, - ROUNDS_SHA1AIX = (1 << 6), - ROUNDS_SHA256AIX = (1 << 6), - ROUNDS_SHA512AIX = (1 << 6), - ROUNDS_MD5CRYPT = 1000, - ROUNDS_SHA256CRYPT = 5000, - ROUNDS_SHA512CRYPT = 5000, - ROUNDS_GRUB = 10000, - ROUNDS_SHA512OSX = 35000, - ROUNDS_AGILEKEY = 1000, - ROUNDS_LASTPASS = 500, - ROUNDS_DRUPAL7 = (1 << 14), // $S$C - ROUNDS_CLOUDKEY = 40000, - ROUNDS_NSEC3 = 1, - ROUNDS_ANDROIDFDE = 2000, - ROUNDS_PSAFE2 = 1000, - ROUNDS_LOTUS8 = 5000, - ROUNDS_CISCO8 = 20000, - ROUNDS_OFFICE2007 = 50000, - ROUNDS_OFFICE2010 = 100000, - ROUNDS_OFFICE2013 = 100000, - ROUNDS_DJANGOPBKDF2 = 20000, - ROUNDS_SAPH_SHA1 = 1024, - ROUNDS_PDF14 = (50 + 20), - ROUNDS_PDF17L8 = 64, - ROUNDS_PBKDF2_SHA256 = 1000, - ROUNDS_BITCOIN_WALLET = 200000, - ROUNDS_SEVEN_ZIP = (1 << 19), - ROUNDS_PBKDF2_MD5 = 1000, - ROUNDS_PBKDF2_SHA1 = 1000, - ROUNDS_PBKDF2_SHA512 = 1000, - ROUNDS_ECRYPTFS = 65536, - ROUNDS_ORACLET = 4096, - ROUNDS_BSDICRYPT = 2900, - ROUNDS_RAR3 = 262144, - ROUNDS_MYWALLET = 10, - ROUNDS_MS_DRSR = 100, - ROUNDS_ANDROIDFDE_SAMSUNG = 4096, - ROUNDS_RAR5 = (1 << 15), - ROUNDS_AXCRYPT = 10000, - ROUNDS_KEEPASS = 6000, - ROUNDS_ZIP2 = 1000, - ROUNDS_STDOUT = 0 - -} rounds_count_t; - -/** - * salt types - */ - -typedef enum salt_type -{ - SALT_TYPE_NONE = 1, - SALT_TYPE_EMBEDDED = 2, - SALT_TYPE_INTERN = 3, - SALT_TYPE_EXTERN = 4, - SALT_TYPE_VIRTUAL = 5 - -} salt_type_t; - -/** - * optimizer options - */ - -typedef enum opti_type -{ - OPTI_TYPE_ZERO_BYTE = (1 << 1), - OPTI_TYPE_PRECOMPUTE_INIT = (1 << 2), - OPTI_TYPE_PRECOMPUTE_MERKLE = (1 << 3), - OPTI_TYPE_PRECOMPUTE_PERMUT = (1 << 4), - OPTI_TYPE_MEET_IN_MIDDLE = (1 << 5), - OPTI_TYPE_EARLY_SKIP = (1 << 6), - OPTI_TYPE_NOT_SALTED = (1 << 7), - OPTI_TYPE_NOT_ITERATED = (1 << 8), - OPTI_TYPE_PREPENDED_SALT = (1 << 9), - OPTI_TYPE_APPENDED_SALT = (1 << 10), - OPTI_TYPE_SINGLE_HASH = (1 << 11), - OPTI_TYPE_SINGLE_SALT = (1 << 12), - OPTI_TYPE_BRUTE_FORCE = (1 << 13), - OPTI_TYPE_RAW_HASH = (1 << 14), - OPTI_TYPE_SLOW_HASH_SIMD = (1 << 15), - OPTI_TYPE_USES_BITS_8 = (1 << 16), - OPTI_TYPE_USES_BITS_16 = (1 << 17), - OPTI_TYPE_USES_BITS_32 = (1 << 18), - OPTI_TYPE_USES_BITS_64 = (1 << 19) - -} opti_type_t; - static const char OPTI_STR_ZERO_BYTE[] = "Zero-Byte"; static const char OPTI_STR_PRECOMPUTE_INIT[] = "Precompute-Init"; static const char OPTI_STR_PRECOMPUTE_MERKLE[] = "Precompute-Merkle-Demgard"; @@ -1121,130 +120,6 @@ static const char OPTI_STR_USES_BITS_16[] = "Uses-16-Bit"; static const char OPTI_STR_USES_BITS_32[] = "Uses-32-Bit"; static const char OPTI_STR_USES_BITS_64[] = "Uses-64-Bit"; -/** - * hash options - */ - -typedef enum opts_type -{ - OPTS_TYPE_PT_UNICODE = (1 << 0), - OPTS_TYPE_PT_UPPER = (1 << 1), - OPTS_TYPE_PT_LOWER = (1 << 2), - OPTS_TYPE_PT_ADD01 = (1 << 3), - OPTS_TYPE_PT_ADD02 = (1 << 4), - OPTS_TYPE_PT_ADD80 = (1 << 5), - OPTS_TYPE_PT_ADDBITS14 = (1 << 6), - OPTS_TYPE_PT_ADDBITS15 = (1 << 7), - OPTS_TYPE_PT_GENERATE_LE = (1 << 8), - OPTS_TYPE_PT_GENERATE_BE = (1 << 9), - OPTS_TYPE_PT_NEVERCRACK = (1 << 10), // if we want all possible results - OPTS_TYPE_PT_BITSLICE = (1 << 11), - OPTS_TYPE_ST_UNICODE = (1 << 12), - OPTS_TYPE_ST_UPPER = (1 << 13), - OPTS_TYPE_ST_LOWER = (1 << 14), - OPTS_TYPE_ST_ADD01 = (1 << 15), - OPTS_TYPE_ST_ADD02 = (1 << 16), - OPTS_TYPE_ST_ADD80 = (1 << 17), - OPTS_TYPE_ST_ADDBITS14 = (1 << 18), - OPTS_TYPE_ST_ADDBITS15 = (1 << 19), - OPTS_TYPE_ST_GENERATE_LE = (1 << 20), - OPTS_TYPE_ST_GENERATE_BE = (1 << 21), - OPTS_TYPE_ST_HEX = (1 << 22), - OPTS_TYPE_ST_BASE64 = (1 << 23), - OPTS_TYPE_HASH_COPY = (1 << 24), - OPTS_TYPE_HOOK12 = (1 << 25), - OPTS_TYPE_HOOK23 = (1 << 26) - -} opts_type_t; - -/** - * digests - */ - -typedef enum dgst_size -{ - DGST_SIZE_4_2 = (2 * sizeof (uint)), // 8 - DGST_SIZE_4_4 = (4 * sizeof (uint)), // 16 - DGST_SIZE_4_5 = (5 * sizeof (uint)), // 20 - DGST_SIZE_4_6 = (6 * sizeof (uint)), // 24 - DGST_SIZE_4_8 = (8 * sizeof (uint)), // 32 - DGST_SIZE_4_16 = (16 * sizeof (uint)), // 64 !!! - DGST_SIZE_4_32 = (32 * sizeof (uint)), // 128 !!! - DGST_SIZE_4_64 = (64 * sizeof (uint)), // 256 - DGST_SIZE_8_8 = (8 * sizeof (u64)), // 64 !!! - DGST_SIZE_8_16 = (16 * sizeof (u64)), // 128 !!! - DGST_SIZE_8_25 = (25 * sizeof (u64)) // 200 - -} dgst_size_t; - -/** - * parser - */ - -typedef enum parser_rc -{ - PARSER_OK = 0, - PARSER_COMMENT = -1, - PARSER_GLOBAL_ZERO = -2, - PARSER_GLOBAL_LENGTH = -3, - PARSER_HASH_LENGTH = -4, - PARSER_HASH_VALUE = -5, - PARSER_SALT_LENGTH = -6, - PARSER_SALT_VALUE = -7, - PARSER_SALT_ITERATION = -8, - PARSER_SEPARATOR_UNMATCHED = -9, - PARSER_SIGNATURE_UNMATCHED = -10, - PARSER_HCCAP_FILE_SIZE = -11, - PARSER_HCCAP_EAPOL_SIZE = -12, - PARSER_PSAFE2_FILE_SIZE = -13, - PARSER_PSAFE3_FILE_SIZE = -14, - PARSER_TC_FILE_SIZE = -15, - PARSER_VC_FILE_SIZE = -16, - PARSER_SIP_AUTH_DIRECTIVE = -17, - PARSER_UNKNOWN_ERROR = -255 - -} parser_rc_t; - -static const char PA_000[] = "OK"; -static const char PA_001[] = "Ignored due to comment"; -static const char PA_002[] = "Ignored due to zero length"; -static const char PA_003[] = "Line-length exception"; -static const char PA_004[] = "Hash-length exception"; -static const char PA_005[] = "Hash-value exception"; -static const char PA_006[] = "Salt-length exception"; -static const char PA_007[] = "Salt-value exception"; -static const char PA_008[] = "Salt-iteration count exception"; -static const char PA_009[] = "Separator unmatched"; -static const char PA_010[] = "Signature unmatched"; -static const char PA_011[] = "Invalid hccap filesize"; -static const char PA_012[] = "Invalid eapol size"; -static const char PA_013[] = "Invalid psafe2 filesize"; -static const char PA_014[] = "Invalid psafe3 filesize"; -static const char PA_015[] = "Invalid truecrypt filesize"; -static const char PA_016[] = "Invalid veracrypt filesize"; -static const char PA_017[] = "Invalid SIP directive, only MD5 is supported"; -static const char PA_255[] = "Unknown error"; - -/** - * status - */ - -typedef enum status_rc -{ - STATUS_STARTING = 0, - STATUS_INIT = 1, - STATUS_RUNNING = 2, - STATUS_PAUSED = 3, - STATUS_EXHAUSTED = 4, - STATUS_CRACKED = 5, - STATUS_ABORTED = 6, - STATUS_QUIT = 7, - STATUS_BYPASS = 8, - STATUS_STOP_AT_CHECKPOINT = 9, - STATUS_AUTOTUNE = 10 - -} status_rc_t; - static const char ST_0000[] = "Initializing"; static const char ST_0001[] = "Starting"; static const char ST_0002[] = "Running"; @@ -1257,41 +132,11 @@ static const char ST_0008[] = "Bypass"; static const char ST_0009[] = "Running (stop at checkpoint)"; static const char ST_0010[] = "Autotuning"; -/** - * kernel types - */ - -typedef enum kern_run -{ - KERN_RUN_1 = 1000, - KERN_RUN_12 = 1500, - KERN_RUN_2 = 2000, - KERN_RUN_23 = 2500, - KERN_RUN_3 = 3000 - -} kern_run_t; - -typedef enum kern_run_mp -{ - KERN_RUN_MP = 101, - KERN_RUN_MP_L = 102, - KERN_RUN_MP_R = 103 - -} kern_run_mp_t; /* * functions */ -u8 hex_convert (const u8 c); -u8 hex_to_u8 (const u8 hex[2]); -u32 hex_to_u32 (const u8 hex[8]); -u64 hex_to_u64 (const u8 hex[16]); - -void dump_hex (const u8 *s, const int sz); - -void truecrypt_crc32 (const char *filename, u8 keytab[64]); - char *get_exec_path (void); char *get_install_dir (const char *progname); char *get_profile_dir (const char *homedir); @@ -1347,20 +192,14 @@ u32 get_random_num (const u32 min, const u32 max); u32 mydivc32 (const u32 dividend, const u32 divisor); u64 mydivc64 (const u64 dividend, const u64 divisor); -void ascii_digest (char *out_buf, uint salt_pos, uint digest_pos); -void to_hccap_t (hccap_t *hccap, uint salt_pos, uint digest_pos); - void format_speed_display (double val, char *buf, size_t len); void format_timer_display (struct tm *tm, char *buf, size_t len); -void lowercase (u8 *buf, int len); -void uppercase (u8 *buf, int len); int fgetl (FILE *fp, char *line_buf); int in_superchop (char *buf); char **scan_directory (const char *path); int count_dictionaries (char **dictionary_files); -char *strparser (const uint parser_status); + char *stroptitype (const uint opti_type); -char *strhashtype (const uint hash_mode); char *strstatus (const uint threads_status); void status (); @@ -1429,15 +268,15 @@ void mp_css_to_uniq_tbl (uint css_cnt, cs_t *css, uint uniq_tbls[SP_PW_MAX][CHAR void mp_cut_at (char *mask, uint max); void mp_exec (u64 val, char *buf, cs_t *css, int css_cnt); cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, uint *css_cnt); -u64 mp_get_sum (uint css_cnt, cs_t *css); +u64 mp_get_sum (uint css_cnt, cs_t *css); void mp_setup_sys (cs_t *mp_sys); void mp_setup_usr (cs_t *mp_sys, cs_t *mp_usr, char *buf, uint index); void mp_reset_usr (cs_t *mp_usr, uint index); char *mp_get_truncated_mask (char *mask_buf, size_t mask_len, uint len); -u64 sp_get_sum (uint start, uint stop, cs_t *root_css_buf); +u64 sp_get_sum (uint start, uint stop, cs_t *root_css_buf); void sp_exec (u64 ctx, char *pw_buf, cs_t *root_css_buf, cs_t *markov_css_buf, uint start, uint stop); -int sp_comp_val (const void *p1, const void *p2); +int sp_comp_val (const void *p1, const void *p2); void sp_setup_tbl (const char *install_dir, char *hcstat, uint disable, uint classic, hcstat_table_t *root_table_buf, hcstat_table_t *markov_table_buf); void sp_tbl_to_css (hcstat_table_t *root_table_buf, hcstat_table_t *markov_table_buf, cs_t *root_css_buf, cs_t *markov_css_buf, uint threshold, uint uniq_tbls[SP_PW_MAX][CHARSIZ]); void sp_stretch_markov (hcstat_table_t *in, hcstat_table_t *out); @@ -1448,163 +287,6 @@ tuning_db_t *tuning_db_alloc (FILE *fp); tuning_db_t *tuning_db_init (const char *tuning_db_file); tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, hc_device_param_t *device_param, int attack_mode, int hash_type); -int bcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int cisco4_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int dcc_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int dcc2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int descrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int des_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int episerver_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int ipb2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int joomla_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int postgresql_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int netscreen_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int keccak_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int lm_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int md4_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int md4s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int md5s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int md5half_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int md5md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int md5pix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int md5asa_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int md5apr1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int md5crypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int mssql2000_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int mssql2005_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int netntlmv1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int netntlmv2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int oracleh_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int oracles_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int oraclet_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int osc_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int arubaos_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int osx1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int osx512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int phpass_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha1b64_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha1b64s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha1s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha256s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha384_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha512s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha512crypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int smf_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int vb3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int vb30_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int wpa_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int psafe2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int psafe3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int ikepsk_md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int ikepsk_sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int androidpin_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int ripemd160_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int whirlpool_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int truecrypt_parse_hash_1k (char *input_buf, uint input_len, hash_t *hash_buf); -int truecrypt_parse_hash_2k (char *input_buf, uint input_len, hash_t *hash_buf); -int md5aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha256aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha512aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int agilekey_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha1aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int lastpass_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int gost_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha256crypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int mssql2012_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha512osx_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int episerver4_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha512grub_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha512b64s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int hmacsha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int hmacsha256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int hmacsha512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int hmacmd5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int krb5pa_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int krb5tgs_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sapb_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sapg_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int drupal7_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sybasease_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int mysql323_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int rakp_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int netscaler_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int chap_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int cloudkey_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int nsec3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int wbb3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int racf_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int lotus5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int lotus6_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int lotus8_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int hmailserver_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int phps_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int mediawiki_b_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int peoplesoft_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int skype_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int androidfde_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int scrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int juniper_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int cisco8_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int cisco9_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int office2007_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int office2010_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int office2013_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int oldoffice01_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int oldoffice01cm1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int oldoffice01cm2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int oldoffice34_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int oldoffice34cm1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int oldoffice34cm2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int radmin2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int djangosha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int djangopbkdf2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int siphash_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int crammd5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int saph_sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int redmine_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int pdf11_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int pdf11cm1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int pdf11cm2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int pdf14_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int pdf17l3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int pdf17l8_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int pbkdf2_sha256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int prestashop_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int postgresql_auth_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int mysql_auth_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int bitcoin_wallet_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sip_auth_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int crc32_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int seven_zip_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int gost2012sbog_256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int gost2012sbog_512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int pbkdf2_md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int pbkdf2_sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int pbkdf2_sha512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int ecryptfs_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int bsdicrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int rar3hp_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int rar5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int cf10_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int mywallet_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int ms_drsr_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int androidfde_samsung_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int axcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int sha1axcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int keepass_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int pstoken_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int zip2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int veracrypt_parse_hash_200000 (char *input_buf, uint input_len, hash_t *hash_buf); -int veracrypt_parse_hash_500000 (char *input_buf, uint input_len, hash_t *hash_buf); -int veracrypt_parse_hash_327661 (char *input_buf, uint input_len, hash_t *hash_buf); -int veracrypt_parse_hash_655331 (char *input_buf, uint input_len, hash_t *hash_buf); -int win8phone_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); -int opencart_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf); - void naive_replace (char *s, const u8 key_char, const u8 replace_char); void naive_escape (char *s, size_t s_max, const u8 key_char, const u8 escape_char); void load_kernel (const char *kernel_file, int num_devices, size_t *kernel_lengths, const u8 **kernel_sources); diff --git a/include/types.h b/include/types.h index 6cf56f897..fc9e124c1 100644 --- a/include/types.h +++ b/include/types.h @@ -15,6 +15,137 @@ #define EOL "\n" #endif +/** + * Outfile formats + */ + +typedef enum outfile_fmt +{ + OUTFILE_FMT_HASH = (1 << 0), + OUTFILE_FMT_PLAIN = (1 << 1), + OUTFILE_FMT_HEXPLAIN = (1 << 2), + OUTFILE_FMT_CRACKPOS = (1 << 3) + +} outfile_fmt_t; + +/** + * salt types + */ + +typedef enum salt_type +{ + SALT_TYPE_NONE = 1, + SALT_TYPE_EMBEDDED = 2, + SALT_TYPE_INTERN = 3, + SALT_TYPE_EXTERN = 4, + SALT_TYPE_VIRTUAL = 5 + +} salt_type_t; + +/** + * optimizer options + */ + +typedef enum opti_type +{ + OPTI_TYPE_ZERO_BYTE = (1 << 1), + OPTI_TYPE_PRECOMPUTE_INIT = (1 << 2), + OPTI_TYPE_PRECOMPUTE_MERKLE = (1 << 3), + OPTI_TYPE_PRECOMPUTE_PERMUT = (1 << 4), + OPTI_TYPE_MEET_IN_MIDDLE = (1 << 5), + OPTI_TYPE_EARLY_SKIP = (1 << 6), + OPTI_TYPE_NOT_SALTED = (1 << 7), + OPTI_TYPE_NOT_ITERATED = (1 << 8), + OPTI_TYPE_PREPENDED_SALT = (1 << 9), + OPTI_TYPE_APPENDED_SALT = (1 << 10), + OPTI_TYPE_SINGLE_HASH = (1 << 11), + OPTI_TYPE_SINGLE_SALT = (1 << 12), + OPTI_TYPE_BRUTE_FORCE = (1 << 13), + OPTI_TYPE_RAW_HASH = (1 << 14), + OPTI_TYPE_SLOW_HASH_SIMD = (1 << 15), + OPTI_TYPE_USES_BITS_8 = (1 << 16), + OPTI_TYPE_USES_BITS_16 = (1 << 17), + OPTI_TYPE_USES_BITS_32 = (1 << 18), + OPTI_TYPE_USES_BITS_64 = (1 << 19) + +} opti_type_t; + +/** + * hash options + */ + +typedef enum opts_type +{ + OPTS_TYPE_PT_UNICODE = (1 << 0), + OPTS_TYPE_PT_UPPER = (1 << 1), + OPTS_TYPE_PT_LOWER = (1 << 2), + OPTS_TYPE_PT_ADD01 = (1 << 3), + OPTS_TYPE_PT_ADD02 = (1 << 4), + OPTS_TYPE_PT_ADD80 = (1 << 5), + OPTS_TYPE_PT_ADDBITS14 = (1 << 6), + OPTS_TYPE_PT_ADDBITS15 = (1 << 7), + OPTS_TYPE_PT_GENERATE_LE = (1 << 8), + OPTS_TYPE_PT_GENERATE_BE = (1 << 9), + OPTS_TYPE_PT_NEVERCRACK = (1 << 10), // if we want all possible results + OPTS_TYPE_PT_BITSLICE = (1 << 11), + OPTS_TYPE_ST_UNICODE = (1 << 12), + OPTS_TYPE_ST_UPPER = (1 << 13), + OPTS_TYPE_ST_LOWER = (1 << 14), + OPTS_TYPE_ST_ADD01 = (1 << 15), + OPTS_TYPE_ST_ADD02 = (1 << 16), + OPTS_TYPE_ST_ADD80 = (1 << 17), + OPTS_TYPE_ST_ADDBITS14 = (1 << 18), + OPTS_TYPE_ST_ADDBITS15 = (1 << 19), + OPTS_TYPE_ST_GENERATE_LE = (1 << 20), + OPTS_TYPE_ST_GENERATE_BE = (1 << 21), + OPTS_TYPE_ST_HEX = (1 << 22), + OPTS_TYPE_ST_BASE64 = (1 << 23), + OPTS_TYPE_HASH_COPY = (1 << 24), + OPTS_TYPE_HOOK12 = (1 << 25), + OPTS_TYPE_HOOK23 = (1 << 26) + +} opts_type_t; + +/** + * digests + */ + +typedef enum dgst_size +{ + DGST_SIZE_4_2 = (2 * sizeof (uint)), // 8 + DGST_SIZE_4_4 = (4 * sizeof (uint)), // 16 + DGST_SIZE_4_5 = (5 * sizeof (uint)), // 20 + DGST_SIZE_4_6 = (6 * sizeof (uint)), // 24 + DGST_SIZE_4_8 = (8 * sizeof (uint)), // 32 + DGST_SIZE_4_16 = (16 * sizeof (uint)), // 64 !!! + DGST_SIZE_4_32 = (32 * sizeof (uint)), // 128 !!! + DGST_SIZE_4_64 = (64 * sizeof (uint)), // 256 + DGST_SIZE_8_8 = (8 * sizeof (u64)), // 64 !!! + DGST_SIZE_8_16 = (16 * sizeof (u64)), // 128 !!! + DGST_SIZE_8_25 = (25 * sizeof (u64)) // 200 + +} dgst_size_t; + +/** + * status + */ + +typedef enum status_rc +{ + STATUS_STARTING = 0, + STATUS_INIT = 1, + STATUS_RUNNING = 2, + STATUS_PAUSED = 3, + STATUS_EXHAUSTED = 4, + STATUS_CRACKED = 5, + STATUS_ABORTED = 6, + STATUS_QUIT = 7, + STATUS_BYPASS = 8, + STATUS_STOP_AT_CHECKPOINT = 9, + STATUS_AUTOTUNE = 10 + +} status_rc_t; + typedef struct { uint salt_buf[16]; @@ -38,639 +169,6 @@ typedef struct } salt_t; -typedef struct -{ - uint iv[4]; - -} rar5_t; - -typedef struct -{ - int V; - int R; - int P; - - int enc_md; - - uint id_buf[8]; - uint u_buf[32]; - uint o_buf[32]; - - int id_len; - int o_len; - int u_len; - - uint rc4key[2]; - uint rc4data[2]; - -} pdf_t; - -typedef struct -{ - uint pke[25]; - uint eapol[64]; - int eapol_size; - int keyver; - u8 orig_mac1[6]; - u8 orig_mac2[6]; - u8 orig_nonce1[32]; - u8 orig_nonce2[32]; - -} wpa_t; - -typedef struct -{ - uint cry_master_buf[64]; - uint ckey_buf[64]; - uint public_key_buf[64]; - - uint cry_master_len; - uint ckey_len; - uint public_key_len; - -} bitcoin_wallet_t; - -typedef struct -{ - uint salt_buf[30]; - uint salt_len; - - uint esalt_buf[38]; - uint esalt_len; - -} sip_t; - -typedef struct -{ - uint data[384]; - -} androidfde_t; - -typedef struct -{ - uint nr_buf[16]; - uint nr_len; - - uint msg_buf[128]; - uint msg_len; - -} ikepsk_t; - -typedef struct -{ - uint user_len; - uint domain_len; - uint srvchall_len; - uint clichall_len; - - uint userdomain_buf[64]; - uint chall_buf[256]; - -} netntlm_t; - -typedef struct -{ - uint user[16]; - uint realm[16]; - uint salt[32]; - uint timestamp[16]; - uint checksum[4]; - -} krb5pa_t; - -typedef struct -{ - uint account_info[512]; - uint checksum[4]; - uint edata2[2560]; - uint edata2_len; - -} krb5tgs_t; - -typedef struct -{ - u32 version; - u32 algorithm; - - /* key-file handling */ - u32 keyfile_len; - u32 keyfile[8]; - - u32 final_random_seed[8]; - u32 transf_random_seed[8]; - u32 enc_iv[4]; - u32 contents_hash[8]; - - /* specific to version 1 */ - u32 contents_len; - u32 contents[75000]; - - /* specific to version 2 */ - u32 expected_bytes[8]; - -} keepass_t; - -typedef struct -{ - uint salt_buf[16]; - uint data_buf[112]; - uint keyfile_buf[16]; - uint signature; - -} tc_t; - -typedef struct -{ - uint salt_buf[16]; - -} pbkdf2_md5_t; - -typedef struct -{ - uint salt_buf[16]; - -} pbkdf2_sha1_t; - -typedef struct -{ - uint salt_buf[16]; - -} pbkdf2_sha256_t; - -typedef struct -{ - uint salt_buf[32]; - -} pbkdf2_sha512_t; - -typedef struct -{ - u8 cipher[1040]; - -} agilekey_t; - -typedef struct -{ - uint salt_buf[128]; - uint salt_len; - -} rakp_t; - -typedef struct -{ - uint data_len; - uint data_buf[512]; - -} cloudkey_t; - -typedef struct -{ - uint encryptedVerifier[4]; - uint encryptedVerifierHash[5]; - - uint keySize; - -} office2007_t; - -typedef struct -{ - uint encryptedVerifier[4]; - uint encryptedVerifierHash[8]; - -} office2010_t; - -typedef struct -{ - uint encryptedVerifier[4]; - uint encryptedVerifierHash[8]; - -} office2013_t; - -typedef struct -{ - uint version; - uint encryptedVerifier[4]; - uint encryptedVerifierHash[4]; - uint rc4key[2]; - -} oldoffice01_t; - -typedef struct -{ - uint version; - uint encryptedVerifier[4]; - uint encryptedVerifierHash[5]; - uint rc4key[2]; - -} oldoffice34_t; - -typedef struct -{ - u32 salt_buf[128]; - u32 salt_len; - - u32 pc_digest[5]; - u32 pc_offset; - -} pstoken_t; - -typedef struct -{ - u32 type; - u32 mode; - u32 magic; - u32 salt_len; - u32 salt_buf[4]; - u32 verify_bytes; - u32 compress_length; - u32 data_len; - u32 data_buf[2048]; - u32 auth_len; - u32 auth_buf[4]; - -} zip2_t; - -typedef struct -{ - uint salt_buf[32]; - -} win8phone_t; - -typedef struct -{ - uint digest[4]; - uint out[4]; - -} pdf14_tmp_t; - -typedef struct -{ - union - { - uint dgst32[16]; - u64 dgst64[8]; - } d; - - uint dgst_len; - uint W_len; - -} pdf17l8_tmp_t; - -typedef struct -{ - uint digest_buf[4]; - -} phpass_tmp_t; - -typedef struct -{ - uint digest_buf[4]; - -} md5crypt_tmp_t; - -typedef struct -{ - u64 l_alt_result[8]; - - u64 l_p_bytes[2]; - u64 l_s_bytes[2]; - -} sha512crypt_tmp_t; - -typedef struct -{ - uint alt_result[8]; - - uint p_bytes[4]; - uint s_bytes[4]; - -} sha256crypt_tmp_t; - -typedef struct -{ - uint ipad[5]; - uint opad[5]; - - uint dgst[10]; - uint out[10]; - -} wpa_tmp_t; - -typedef struct -{ - u64 dgst[8]; - -} bitcoin_wallet_tmp_t; - -typedef struct -{ - uint ipad[5]; - uint opad[5]; - - uint dgst[5]; - uint out[4]; - -} dcc2_tmp_t; - -typedef struct -{ - uint E[18]; - - uint P[18]; - - uint S0[256]; - uint S1[256]; - uint S2[256]; - uint S3[256]; - -} bcrypt_tmp_t; - -typedef struct -{ - uint digest[2]; - - uint P[18]; - - uint S0[256]; - uint S1[256]; - uint S2[256]; - uint S3[256]; - -} pwsafe2_tmp_t; - -typedef struct -{ - uint digest_buf[8]; - -} pwsafe3_tmp_t; - -typedef struct -{ - uint digest_buf[5]; - -} androidpin_tmp_t; - -typedef struct -{ - uint ipad[5]; - uint opad[5]; - - uint dgst[10]; - uint out[10]; - -} androidfde_tmp_t; - -typedef struct -{ - uint ipad[16]; - uint opad[16]; - - uint dgst[64]; - uint out[64]; - -} tc_tmp_t; - -typedef struct -{ - u64 ipad[8]; - u64 opad[8]; - - u64 dgst[32]; - u64 out[32]; - -} tc64_tmp_t; - -typedef struct -{ - uint ipad[5]; - uint opad[5]; - - uint dgst[5]; - uint out[5]; - -} agilekey_tmp_t; - -typedef struct -{ - uint ipad[5]; - uint opad[5]; - - uint dgst1[5]; - uint out1[5]; - - uint dgst2[5]; - uint out2[5]; - -} mywallet_tmp_t; - -typedef struct -{ - uint ipad[5]; - uint opad[5]; - - uint dgst[5]; - uint out[5]; - -} sha1aix_tmp_t; - -typedef struct -{ - uint ipad[8]; - uint opad[8]; - - uint dgst[8]; - uint out[8]; - -} sha256aix_tmp_t; - -typedef struct -{ - u64 ipad[8]; - u64 opad[8]; - - u64 dgst[8]; - u64 out[8]; - -} sha512aix_tmp_t; - -typedef struct -{ - uint ipad[8]; - uint opad[8]; - - uint dgst[8]; - uint out[8]; - -} lastpass_tmp_t; - -typedef struct -{ - u64 digest_buf[8]; - -} drupal7_tmp_t; - -typedef struct -{ - uint ipad[5]; - uint opad[5]; - - uint dgst[5]; - uint out[5]; - -} lotus8_tmp_t; - -typedef struct -{ - uint out[5]; - -} office2007_tmp_t; - -typedef struct -{ - uint out[5]; - -} office2010_tmp_t; - -typedef struct -{ - u64 out[8]; - -} office2013_tmp_t; - -typedef struct -{ - uint digest_buf[5]; - -} saph_sha1_tmp_t; - -typedef struct -{ - u32 ipad[4]; - u32 opad[4]; - - u32 dgst[32]; - u32 out[32]; - -} pbkdf2_md5_tmp_t; - -typedef struct -{ - u32 ipad[5]; - u32 opad[5]; - - u32 dgst[32]; - u32 out[32]; - -} pbkdf2_sha1_tmp_t; - -typedef struct -{ - u32 ipad[8]; - u32 opad[8]; - - u32 dgst[32]; - u32 out[32]; - -} pbkdf2_sha256_tmp_t; - -typedef struct -{ - u64 ipad[8]; - u64 opad[8]; - - u64 dgst[16]; - u64 out[16]; - -} pbkdf2_sha512_tmp_t; - -typedef struct -{ - u64 out[8]; - -} ecryptfs_tmp_t; - -typedef struct -{ - u64 ipad[8]; - u64 opad[8]; - - u64 dgst[16]; - u64 out[16]; - -} oraclet_tmp_t; - -typedef struct -{ - uint block[16]; - - uint dgst[8]; - - uint block_len; - uint final_len; - -} seven_zip_tmp_t; - -typedef struct -{ - uint Kc[16]; - uint Kd[16]; - - uint iv[2]; - -} bsdicrypt_tmp_t; - -typedef struct -{ - uint dgst[17][5]; - -} rar3_tmp_t; - -typedef struct -{ - uint user[16]; - -} cram_md5_t; - -typedef struct -{ - uint iv_buf[4]; - uint iv_len; - - uint salt_buf[4]; - uint salt_len; - - uint crc; - - uint data_buf[96]; - uint data_len; - - uint unpack_size; - -} seven_zip_t; - -typedef struct -{ - u32 KEK[4]; - u32 lsb[4]; - u32 cipher[4]; - -} axcrypt_tmp_t; - -typedef struct -{ - u32 tmp_digest[8]; - -} keepass_tmp_t; - -typedef struct -{ - u32 random[2]; - u32 hash[5]; - u32 salt[5]; // unused, but makes better valid check - u32 iv[2]; // unused, but makes better valid check - -} psafe2_hdr; - typedef struct { char *user_name; @@ -709,32 +207,6 @@ typedef struct } cs_t; -typedef struct -{ - char essid[36]; - - u8 mac1[6]; - u8 mac2[6]; - u8 nonce1[32]; - u8 nonce2[32]; - - u8 eapol[256]; - int eapol_size; - - int keyver; - u8 keymic[16]; - -} hccap_t; - -typedef struct -{ - char signature[4]; - u32 salt_buf[8]; - u32 iterations; - u32 hash_buf[8]; - -} psafe3_t; - typedef struct { char plain_buf[256]; @@ -1116,253 +588,3 @@ typedef struct } hm_attrs_t; #endif // HAVE_HWMON - -typedef struct -{ - /** - * threads - */ - - uint devices_status; - uint devices_cnt; - uint devices_active; - - hc_device_param_t *devices_param; - - uint shutdown_inner; - uint shutdown_outer; - - /** - * workload specific - */ - - uint hardware_power_all; - uint kernel_power_all; - u64 kernel_power_final; // we save that so that all divisions are done from the same base - - /** - * attack specific - */ - - uint wordlist_mode; - uint hashlist_mode; - uint hashlist_format; - - uint attack_mode; - uint attack_kern; - uint attack_exec; - - uint kernel_rules_cnt; - - kernel_rule_t *kernel_rules_buf; - - uint combs_mode; - uint combs_cnt; - - uint bfs_cnt; - - uint css_cnt; - cs_t *css_buf; - - cs_t *root_css_buf; - cs_t *markov_css_buf; - - char *rule_buf_l; - char *rule_buf_r; - int rule_len_l; - int rule_len_r; - - /** - * opencl library stuff - */ - - void *ocl; - - /** - * hardware watchdog - */ - - #ifdef HAVE_HWMON - void *hm_adl; - void *hm_nvml; - void *hm_nvapi; - void *hm_xnvctrl; - hm_attrs_t hm_device[DEVICES_MAX]; - #endif - - /** - * hashes - */ - - uint digests_cnt; - uint digests_done; - uint digests_saved; - - void *digests_buf; - uint *digests_shown; - uint *digests_shown_tmp; - - uint salts_cnt; - uint salts_done; - - salt_t *salts_buf; - uint *salts_shown; - - void *esalts_buf; - - uint scrypt_tmp_size; - uint scrypt_tmto_final; - - /** - * logging - */ - - uint logfile_disable; - char *logfile; - char *topid; - char *subid; - - /** - * crack-per-time - */ - - cpt_t cpt_buf[CPT_BUF]; - int cpt_pos; - time_t cpt_start; - u64 cpt_total; - - /** - * user - */ - - char *dictfile; - char *dictfile2; - char *mask; - uint maskcnt; - uint maskpos; - char *session; - char separator; - char *hashfile; - char *homedir; - char *install_dir; - char *profile_dir; - char *session_dir; - char *shared_dir; - char *outfile; - uint outfile_format; - uint outfile_autohex; - uint outfile_check_timer; - char *eff_restore_file; - char *new_restore_file; - char *induction_directory; - char *outfile_check_directory; - uint loopback; - char *loopback_file; - uint restore; - uint restore_timer; - uint restore_disable; - uint status; - uint status_timer; - uint machine_readable; - uint quiet; - uint force; - uint benchmark; - uint runtime; - uint remove; - uint remove_timer; - uint debug_mode; - char *debug_file; - uint hex_charset; - uint hex_salt; - uint hex_wordlist; - uint pw_min; - uint pw_max; - uint powertune_enable; - uint scrypt_tmto; - uint segment_size; - char *truecrypt_keyfiles; - char *veracrypt_keyfiles; - uint veracrypt_pim; - uint workload_profile; - char *custom_charset_1; - char *custom_charset_2; - char *custom_charset_3; - char *custom_charset_4; - - uint hash_mode; - uint hash_type; - uint kern_type; - uint opts_type; - uint salt_type; - uint esalt_size; - uint isSalted; - uint dgst_size; - uint opti_type; - uint dgst_pos0; - uint dgst_pos1; - uint dgst_pos2; - uint dgst_pos3; - - #ifdef HAVE_HWMON - uint gpu_temp_disable; - uint gpu_temp_abort; - uint gpu_temp_retain; - #endif - - char **rp_files; - uint rp_files_cnt; - uint rp_gen; - uint rp_gen_seed; - - FILE *pot_fp; - - /** - * used for restore - */ - - u64 skip; - u64 limit; - - restore_data_t *rd; - - u64 checkpoint_cur_words; // used for the "stop at next checkpoint" feature - - /** - * status, timer - */ - - time_t runtime_start; - time_t runtime_stop; - - time_t prepare_time; - - time_t proc_start; - time_t proc_stop; - - u64 words_cnt; - u64 words_cur; - u64 words_base; - - u64 *words_progress_done; // progress number of words done per salt - u64 *words_progress_rejected; // progress number of words rejected per salt - u64 *words_progress_restored; // progress number of words restored per salt - - hc_timer_t timer_running; // timer on current dict - hc_timer_t timer_paused; // timer on current dict - - double ms_paused; // timer on current dict - - /** - * hash_info and username - */ - - hashinfo_t **hash_info; - uint username; - - int (*sort_by_digest) (const void *, const void *); - - int (*parse_func) (char *, uint, hash_t *); - -} hc_global_data_t; - -extern hc_global_data_t data; diff --git a/src/Makefile b/src/Makefile index a410a85c0..690f1edb4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -165,7 +165,7 @@ LFLAGS_CROSS_WIN := -lpsapi ## Objects ## -NATIVE_OBJS := obj/memory.NATIVE.o obj/logging.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/bitops.NATIVE.o obj/bitops.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/shared.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o +NATIVE_OBJS := obj/data.NATIVE.o obj/convert.NATIVE.o obj/memory.NATIVE.o obj/logging.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/bitops.NATIVE.o obj/bitops.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/shared.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/interface.NATIVE.o ifeq ($(UNAME),Linux) NATIVE_OBJS += obj/ext_ADL.NATIVE.o @@ -174,8 +174,8 @@ NATIVE_OBJS += obj/ext_nvml.NATIVE.o NATIVE_OBJS += obj/ext_xnvctrl.NATIVE.o endif -LINUX_32_OBJS := obj/memory.LINUX.32.o obj/logging.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/bitops.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/shared.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o -LINUX_64_OBJS := obj/memory.LINUX.64.o obj/logging.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/bitops.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/shared.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o +LINUX_32_OBJS := obj/data.LINUX.32.o obj/convert.LINUX.32.o obj/memory.LINUX.32.o obj/logging.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/bitops.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/shared.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/interface.LINUX.32.o +LINUX_64_OBJS := obj/data.LINUX.64.o obj/convert.LINUX.64.o obj/memory.LINUX.64.o obj/logging.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/bitops.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/shared.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/interface.LINUX.64.o # Windows CRT file globbing: @@ -185,8 +185,8 @@ CRT_GLOB_INCLUDE_FOLDER := $(dir $(lastword $(MAKEFILE_LIST))) include $(CRT_GLOB_INCLUDE_FOLDER)/win_file_globbing.mk -WIN_32_OBJS := obj/memory.WIN.32.o obj/logging.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/bitops.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/shared.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_xnvctrl.WIN.32.o $(CRT_GLOB_32) -WIN_64_OBJS := obj/memory.WIN.64.o obj/logging.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/bitops.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/shared.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_xnvctrl.WIN.64.o $(CRT_GLOB_64) +WIN_32_OBJS := obj/data.WIN.32.o obj/convert.WIN.32.o obj/memory.WIN.32.o obj/logging.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/bitops.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/shared.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/interface.WIN.32.o $(CRT_GLOB_32) +WIN_64_OBJS := obj/data.WIN.64.o obj/convert.WIN.64.o obj/memory.WIN.64.o obj/logging.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/bitops.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/shared.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/interface.WIN.64.o $(CRT_GLOB_64) ## ## Targets: Global diff --git a/src/convert.c b/src/convert.c new file mode 100644 index 000000000..d60efb2ff --- /dev/null +++ b/src/convert.c @@ -0,0 +1,428 @@ +/** + * Author......: Jens Steube + * License.....: MIT + */ + +#include "common.h" +#include "types_int.h" +#include "convert.h" + +int is_valid_hex_char (const u8 c) +{ + if ((c >= '0') && (c <= '9')) return 1; + if ((c >= 'A') && (c <= 'F')) return 1; + if ((c >= 'a') && (c <= 'f')) return 1; + + return 0; +} + +u8 hex_convert (const u8 c) +{ + return (c & 15) + (c >> 6) * 9; +} + +u8 hex_to_u8 (const u8 hex[2]) +{ + u8 v = 0; + + v |= (hex_convert (hex[1]) << 0); + v |= (hex_convert (hex[0]) << 4); + + return (v); +} + +u32 hex_to_u32 (const u8 hex[8]) +{ + u32 v = 0; + + v |= ((u32) hex_convert (hex[7])) << 0; + v |= ((u32) hex_convert (hex[6])) << 4; + v |= ((u32) hex_convert (hex[5])) << 8; + v |= ((u32) hex_convert (hex[4])) << 12; + v |= ((u32) hex_convert (hex[3])) << 16; + v |= ((u32) hex_convert (hex[2])) << 20; + v |= ((u32) hex_convert (hex[1])) << 24; + v |= ((u32) hex_convert (hex[0])) << 28; + + return (v); +} + +u64 hex_to_u64 (const u8 hex[16]) +{ + u64 v = 0; + + v |= ((u64) hex_convert (hex[15]) << 0); + v |= ((u64) hex_convert (hex[14]) << 4); + v |= ((u64) hex_convert (hex[13]) << 8); + v |= ((u64) hex_convert (hex[12]) << 12); + v |= ((u64) hex_convert (hex[11]) << 16); + v |= ((u64) hex_convert (hex[10]) << 20); + v |= ((u64) hex_convert (hex[ 9]) << 24); + v |= ((u64) hex_convert (hex[ 8]) << 28); + v |= ((u64) hex_convert (hex[ 7]) << 32); + v |= ((u64) hex_convert (hex[ 6]) << 36); + v |= ((u64) hex_convert (hex[ 5]) << 40); + v |= ((u64) hex_convert (hex[ 4]) << 44); + v |= ((u64) hex_convert (hex[ 3]) << 48); + v |= ((u64) hex_convert (hex[ 2]) << 52); + v |= ((u64) hex_convert (hex[ 1]) << 56); + v |= ((u64) hex_convert (hex[ 0]) << 60); + + return (v); +} + +void bin_to_hex_lower (const u32 v, u8 hex[8]) +{ + hex[0] = v >> 28 & 15; + hex[1] = v >> 24 & 15; + hex[2] = v >> 20 & 15; + hex[3] = v >> 16 & 15; + hex[4] = v >> 12 & 15; + hex[5] = v >> 8 & 15; + hex[6] = v >> 4 & 15; + hex[7] = v >> 0 & 15; + + u32 add; + + hex[0] += 6; add = ((hex[0] & 0x10) >> 4) * 39; hex[0] += 42 + add; + hex[1] += 6; add = ((hex[1] & 0x10) >> 4) * 39; hex[1] += 42 + add; + hex[2] += 6; add = ((hex[2] & 0x10) >> 4) * 39; hex[2] += 42 + add; + hex[3] += 6; add = ((hex[3] & 0x10) >> 4) * 39; hex[3] += 42 + add; + hex[4] += 6; add = ((hex[4] & 0x10) >> 4) * 39; hex[4] += 42 + add; + hex[5] += 6; add = ((hex[5] & 0x10) >> 4) * 39; hex[5] += 42 + add; + hex[6] += 6; add = ((hex[6] & 0x10) >> 4) * 39; hex[6] += 42 + add; + hex[7] += 6; add = ((hex[7] & 0x10) >> 4) * 39; hex[7] += 42 + add; +} + +u8 int_to_base32 (const u8 c) +{ + const u8 tbl[0x20] = + { + 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, + 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + }; + + return tbl[c]; +} + +u8 base32_to_int (const u8 c) +{ + if ((c >= 'A') && (c <= 'Z')) return c - 'A'; + else if ((c >= '2') && (c <= '7')) return c - '2' + 26; + + return 0; +} + +u8 int_to_itoa32 (const u8 c) +{ + const u8 tbl[0x20] = + { + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, + 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, + }; + + return tbl[c]; +} + +u8 itoa32_to_int (const u8 c) +{ + if ((c >= '0') && (c <= '9')) return c - '0'; + else if ((c >= 'a') && (c <= 'v')) return c - 'a' + 10; + + return 0; +} + +u8 int_to_itoa64 (const u8 c) +{ + const u8 tbl[0x40] = + { + 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, + 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, + 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, + }; + + return tbl[c]; +} + +u8 itoa64_to_int (const u8 c) +{ + const u8 tbl[0x100] = + { + 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, + 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, + 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, + 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, + 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x01, 0x02, 0x03, 0x04, + }; + + return tbl[c]; +} + +u8 int_to_base64 (const u8 c) +{ + const u8 tbl[0x40] = + { + 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, + 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, + 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, + 0x77, 0x78, 0x79, 0x7a, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f, + }; + + return tbl[c]; +} + +u8 base64_to_int (const u8 c) +{ + const u8 tbl[0x100] = + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x3f, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + + return tbl[c]; +} + +u8 int_to_bf64 (const u8 c) +{ + const u8 tbl[0x40] = + { + 0x2e, 0x2f, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, + 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, + 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, + 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + }; + + return tbl[c]; +} + +u8 bf64_to_int (const u8 c) +{ + const u8 tbl[0x100] = + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, + 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + + return tbl[c]; +} + +u8 int_to_lotus64 (const u8 c) +{ + if (c < 10) return '0' + c; + else if (c < 36) return 'A' + c - 10; + else if (c < 62) return 'a' + c - 36; + else if (c == 62) return '+'; + else if (c == 63) return '/'; + + return 0; +} + +u8 lotus64_to_int (const u8 c) +{ + if ((c >= '0') && (c <= '9')) return c - '0'; + else if ((c >= 'A') && (c <= 'Z')) return c - 'A' + 10; + else if ((c >= 'a') && (c <= 'z')) return c - 'a' + 36; + else if (c == '+') return 62; + else if (c == '/') return 63; + else + + return 0; +} + +int base32_decode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf) +{ + const u8 *in_ptr = in_buf; + + u8 *out_ptr = out_buf; + + for (int i = 0; i < in_len; i += 8) + { + const u8 out_val0 = f (in_ptr[0] & 0x7f); + const u8 out_val1 = f (in_ptr[1] & 0x7f); + const u8 out_val2 = f (in_ptr[2] & 0x7f); + const u8 out_val3 = f (in_ptr[3] & 0x7f); + const u8 out_val4 = f (in_ptr[4] & 0x7f); + const u8 out_val5 = f (in_ptr[5] & 0x7f); + const u8 out_val6 = f (in_ptr[6] & 0x7f); + const u8 out_val7 = f (in_ptr[7] & 0x7f); + + out_ptr[0] = ((out_val0 << 3) & 0xf8) | ((out_val1 >> 2) & 0x07); + out_ptr[1] = ((out_val1 << 6) & 0xc0) | ((out_val2 << 1) & 0x3e) | ((out_val3 >> 4) & 0x01); + out_ptr[2] = ((out_val3 << 4) & 0xf0) | ((out_val4 >> 1) & 0x0f); + out_ptr[3] = ((out_val4 << 7) & 0x80) | ((out_val5 << 2) & 0x7c) | ((out_val6 >> 3) & 0x03); + out_ptr[4] = ((out_val6 << 5) & 0xe0) | ((out_val7 >> 0) & 0x1f); + + in_ptr += 8; + out_ptr += 5; + } + + for (int i = 0; i < in_len; i++) + { + if (in_buf[i] != '=') continue; + + in_len = i; + } + + int out_len = (in_len * 5) / 8; + + return out_len; +} + +int base32_encode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf) +{ + const u8 *in_ptr = in_buf; + + u8 *out_ptr = out_buf; + + for (int i = 0; i < in_len; i += 5) + { + const u8 out_val0 = f ( ((in_ptr[0] >> 3) & 0x1f)); + const u8 out_val1 = f (((in_ptr[0] << 2) & 0x1c) | ((in_ptr[1] >> 6) & 0x03)); + const u8 out_val2 = f ( ((in_ptr[1] >> 1) & 0x1f)); + const u8 out_val3 = f (((in_ptr[1] << 4) & 0x10) | ((in_ptr[2] >> 4) & 0x0f)); + const u8 out_val4 = f (((in_ptr[2] << 1) & 0x1e) | ((in_ptr[3] >> 7) & 0x01)); + const u8 out_val5 = f ( ((in_ptr[3] >> 2) & 0x1f)); + const u8 out_val6 = f (((in_ptr[3] << 3) & 0x18) | ((in_ptr[4] >> 5) & 0x07)); + const u8 out_val7 = f ( ((in_ptr[4] >> 0) & 0x1f)); + + out_ptr[0] = out_val0 & 0x7f; + out_ptr[1] = out_val1 & 0x7f; + out_ptr[2] = out_val2 & 0x7f; + out_ptr[3] = out_val3 & 0x7f; + out_ptr[4] = out_val4 & 0x7f; + out_ptr[5] = out_val5 & 0x7f; + out_ptr[6] = out_val6 & 0x7f; + out_ptr[7] = out_val7 & 0x7f; + + in_ptr += 5; + out_ptr += 8; + } + + int out_len = (int) (((0.5 + (double) in_len) * 8) / 5); // ceil (in_len * 8 / 5) + + while (out_len % 8) + { + out_buf[out_len] = '='; + + out_len++; + } + + return out_len; +} + +int base64_decode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf) +{ + const u8 *in_ptr = in_buf; + + u8 *out_ptr = out_buf; + + for (int i = 0; i < in_len; i += 4) + { + const u8 out_val0 = f (in_ptr[0] & 0x7f); + const u8 out_val1 = f (in_ptr[1] & 0x7f); + const u8 out_val2 = f (in_ptr[2] & 0x7f); + const u8 out_val3 = f (in_ptr[3] & 0x7f); + + out_ptr[0] = ((out_val0 << 2) & 0xfc) | ((out_val1 >> 4) & 0x03); + out_ptr[1] = ((out_val1 << 4) & 0xf0) | ((out_val2 >> 2) & 0x0f); + out_ptr[2] = ((out_val2 << 6) & 0xc0) | ((out_val3 >> 0) & 0x3f); + + in_ptr += 4; + out_ptr += 3; + } + + for (int i = 0; i < in_len; i++) + { + if (in_buf[i] != '=') continue; + + in_len = i; + } + + int out_len = (in_len * 6) / 8; + + return out_len; +} + +int base64_encode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf) +{ + const u8 *in_ptr = in_buf; + + u8 *out_ptr = out_buf; + + for (int i = 0; i < in_len; i += 3) + { + const u8 out_val0 = f ( ((in_ptr[0] >> 2) & 0x3f)); + const u8 out_val1 = f (((in_ptr[0] << 4) & 0x30) | ((in_ptr[1] >> 4) & 0x0f)); + const u8 out_val2 = f (((in_ptr[1] << 2) & 0x3c) | ((in_ptr[2] >> 6) & 0x03)); + const u8 out_val3 = f ( ((in_ptr[2] >> 0) & 0x3f)); + + out_ptr[0] = out_val0 & 0x7f; + out_ptr[1] = out_val1 & 0x7f; + out_ptr[2] = out_val2 & 0x7f; + out_ptr[3] = out_val3 & 0x7f; + + in_ptr += 3; + out_ptr += 4; + } + + int out_len = (int) (((0.5 + (double) in_len) * 8) / 6); // ceil (in_len * 8 / 6) + + while (out_len % 4) + { + out_buf[out_len] = '='; + + out_len++; + } + + return out_len; +} + +void lowercase (u8 *buf, int len) +{ + for (int i = 0; i < len; i++) buf[i] = tolower (buf[i]); +} + +void uppercase (u8 *buf, int len) +{ + for (int i = 0; i < len; i++) buf[i] = toupper (buf[i]); +} diff --git a/src/cpu_aes.c b/src/cpu_aes.c index 730532e84..eb07b020a 100644 --- a/src/cpu_aes.c +++ b/src/cpu_aes.c @@ -629,3 +629,47 @@ void AES_decrypt (AES_KEY *aes_key, const u8 *input, u8 *output) AES256_decrypt ((const u32 *) input, (u32 *) output, aes_key->rdk); } } + +// helper + +void AES128_decrypt_cbc (const u32 key[4], const u32 iv[4], const u32 in[16], u32 out[16]) +{ + AES_KEY skey; + + AES_set_decrypt_key ((const u8 *) key, 128, &skey); + + u32 _iv[4] = { 0 }; + + _iv[0] = iv[0]; + _iv[1] = iv[1]; + _iv[2] = iv[2]; + _iv[3] = iv[3]; + + for (int i = 0; i < 16; i += 4) + { + u32 _in[4] = { 0 }; + u32 _out[4] = { 0 }; + + _in[0] = in[i + 0]; + _in[1] = in[i + 1]; + _in[2] = in[i + 2]; + _in[3] = in[i + 3]; + + AES_decrypt (&skey, (const u8 *) _in, (u8 *) _out); + + _out[0] ^= _iv[0]; + _out[1] ^= _iv[1]; + _out[2] ^= _iv[2]; + _out[3] ^= _iv[3]; + + out[i + 0] = _out[0]; + out[i + 1] = _out[1]; + out[i + 2] = _out[2]; + out[i + 3] = _out[3]; + + _iv[0] = _in[0]; + _iv[1] = _in[1]; + _iv[2] = _in[2]; + _iv[3] = _in[3]; + } +} diff --git a/src/data.c b/src/data.c new file mode 100644 index 000000000..65e29efc9 --- /dev/null +++ b/src/data.c @@ -0,0 +1,17 @@ +/** + * Author......: Jens Steube + * License.....: MIT + */ + +#include "common.h" +#include "types_int.h" +#include "ext_OpenCL.h" +#include "ext_ADL.h" +#include "ext_nvapi.h" +#include "ext_nvml.h" +#include "ext_xnvctrl.h" +#include "timer.h" +#include "types.h" +#include "data.h" + +hc_global_data_t data; diff --git a/src/hashcat.c b/src/hashcat.c index 62c6c93b8..2c0556795 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -10,6 +10,7 @@ #include "types_int.h" #include "bitops.h" #include "memory.h" +#include "convert.h" #include "logging.h" #include "ext_OpenCL.h" #include "ext_ADL.h" @@ -28,7 +29,14 @@ #include "rp_cpu.h" #include "rp_kernel_on_cpu.h" #include "inc_hash_constants.h" +#include "interface.h" #include "shared.h" +#include "data.h" + +#include +#include + +extern hc_global_data_t data; static const char *PROGNAME = "hashcat"; @@ -188,6 +196,23 @@ typedef enum combinator_mode } combinator_mode_t; +typedef enum kern_run +{ + KERN_RUN_1 = 1000, + KERN_RUN_12 = 1500, + KERN_RUN_2 = 2000, + KERN_RUN_23 = 2500, + KERN_RUN_3 = 3000 + +} kern_run_t; + +typedef enum kern_run_mp +{ + KERN_RUN_MP = 101, + KERN_RUN_MP_L = 102, + KERN_RUN_MP_R = 103 + +} kern_run_mp_t; #ifdef _WIN #define mkdir(name,mode) mkdir (name) diff --git a/src/interface.c b/src/interface.c new file mode 100644 index 000000000..b2354262d --- /dev/null +++ b/src/interface.c @@ -0,0 +1,15846 @@ +/** + * Authors.....: Jens Steube + * License.....: MIT + */ + +#include "common.h" +#include "types_int.h" +#include "bitops.h" +#include "memory.h" +#include "convert.h" +#include "logging.h" +#include "ext_OpenCL.h" +#include "ext_ADL.h" +#include "ext_nvapi.h" +#include "ext_nvml.h" +#include "ext_xnvctrl.h" +#include "cpu_aes.h" +#include "cpu_crc32.h" +#include "cpu_des.h" +#include "cpu_md5.h" +#include "cpu_sha1.h" +#include "cpu_sha256.h" +#include "rp_kernel_on_cpu.h" +#include "inc_hash_constants.h" +#include "timer.h" +#include "types.h" +#include "data.h" +#include "interface.h" + +extern hc_global_data_t data; + + +/** + * decoder / encoder + */ + +static void juniper_decrypt_hash (char *in, char *out) +{ + // base64 decode + + u8 base64_buf[100] = { 0 }; + + base64_decode (base64_to_int, (const u8 *) in, DISPLAY_LEN_MIN_501, base64_buf); + + // iv stuff + + u32 juniper_iv[4] = { 0 }; + + memcpy (juniper_iv, base64_buf, 12); + + memcpy (out, juniper_iv, 12); + + // reversed key + + u32 juniper_key[4] = { 0 }; + + juniper_key[0] = byte_swap_32 (0xa6707a7e); + juniper_key[1] = byte_swap_32 (0x8df91059); + juniper_key[2] = byte_swap_32 (0xdea70ae5); + juniper_key[3] = byte_swap_32 (0x2f9c2442); + + // AES decrypt + + u32 *in_ptr = (u32 *) (base64_buf + 12); + u32 *out_ptr = (u32 *) (out + 12); + + AES128_decrypt_cbc (juniper_key, juniper_iv, in_ptr, out_ptr); +} + +static void phpass_decode (u8 digest[16], u8 buf[22]) +{ + int l; + + l = itoa64_to_int (buf[ 0]) << 0; + l |= itoa64_to_int (buf[ 1]) << 6; + l |= itoa64_to_int (buf[ 2]) << 12; + l |= itoa64_to_int (buf[ 3]) << 18; + + digest[ 0] = (l >> 0) & 0xff; + digest[ 1] = (l >> 8) & 0xff; + digest[ 2] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[ 4]) << 0; + l |= itoa64_to_int (buf[ 5]) << 6; + l |= itoa64_to_int (buf[ 6]) << 12; + l |= itoa64_to_int (buf[ 7]) << 18; + + digest[ 3] = (l >> 0) & 0xff; + digest[ 4] = (l >> 8) & 0xff; + digest[ 5] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[ 8]) << 0; + l |= itoa64_to_int (buf[ 9]) << 6; + l |= itoa64_to_int (buf[10]) << 12; + l |= itoa64_to_int (buf[11]) << 18; + + digest[ 6] = (l >> 0) & 0xff; + digest[ 7] = (l >> 8) & 0xff; + digest[ 8] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[12]) << 0; + l |= itoa64_to_int (buf[13]) << 6; + l |= itoa64_to_int (buf[14]) << 12; + l |= itoa64_to_int (buf[15]) << 18; + + digest[ 9] = (l >> 0) & 0xff; + digest[10] = (l >> 8) & 0xff; + digest[11] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[16]) << 0; + l |= itoa64_to_int (buf[17]) << 6; + l |= itoa64_to_int (buf[18]) << 12; + l |= itoa64_to_int (buf[19]) << 18; + + digest[12] = (l >> 0) & 0xff; + digest[13] = (l >> 8) & 0xff; + digest[14] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[20]) << 0; + l |= itoa64_to_int (buf[21]) << 6; + + digest[15] = (l >> 0) & 0xff; +} + +static void phpass_encode (u8 digest[16], u8 buf[22]) +{ + int l; + + l = (digest[ 0] << 0) | (digest[ 1] << 8) | (digest[ 2] << 16); + + buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 3] = int_to_itoa64 (l & 0x3f); + + l = (digest[ 3] << 0) | (digest[ 4] << 8) | (digest[ 5] << 16); + + buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 7] = int_to_itoa64 (l & 0x3f); + + l = (digest[ 6] << 0) | (digest[ 7] << 8) | (digest[ 8] << 16); + + buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[11] = int_to_itoa64 (l & 0x3f); + + l = (digest[ 9] << 0) | (digest[10] << 8) | (digest[11] << 16); + + buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[15] = int_to_itoa64 (l & 0x3f); + + l = (digest[12] << 0) | (digest[13] << 8) | (digest[14] << 16); + + buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[19] = int_to_itoa64 (l & 0x3f); + + l = (digest[15] << 0); + + buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[21] = int_to_itoa64 (l & 0x3f); +} + +static void md5crypt_decode (u8 digest[16], u8 buf[22]) +{ + int l; + + l = itoa64_to_int (buf[ 0]) << 0; + l |= itoa64_to_int (buf[ 1]) << 6; + l |= itoa64_to_int (buf[ 2]) << 12; + l |= itoa64_to_int (buf[ 3]) << 18; + + digest[ 0] = (l >> 16) & 0xff; + digest[ 6] = (l >> 8) & 0xff; + digest[12] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[ 4]) << 0; + l |= itoa64_to_int (buf[ 5]) << 6; + l |= itoa64_to_int (buf[ 6]) << 12; + l |= itoa64_to_int (buf[ 7]) << 18; + + digest[ 1] = (l >> 16) & 0xff; + digest[ 7] = (l >> 8) & 0xff; + digest[13] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[ 8]) << 0; + l |= itoa64_to_int (buf[ 9]) << 6; + l |= itoa64_to_int (buf[10]) << 12; + l |= itoa64_to_int (buf[11]) << 18; + + digest[ 2] = (l >> 16) & 0xff; + digest[ 8] = (l >> 8) & 0xff; + digest[14] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[12]) << 0; + l |= itoa64_to_int (buf[13]) << 6; + l |= itoa64_to_int (buf[14]) << 12; + l |= itoa64_to_int (buf[15]) << 18; + + digest[ 3] = (l >> 16) & 0xff; + digest[ 9] = (l >> 8) & 0xff; + digest[15] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[16]) << 0; + l |= itoa64_to_int (buf[17]) << 6; + l |= itoa64_to_int (buf[18]) << 12; + l |= itoa64_to_int (buf[19]) << 18; + + digest[ 4] = (l >> 16) & 0xff; + digest[10] = (l >> 8) & 0xff; + digest[ 5] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[20]) << 0; + l |= itoa64_to_int (buf[21]) << 6; + + digest[11] = (l >> 0) & 0xff; +} + +static void md5crypt_encode (u8 digest[16], u8 buf[22]) +{ + int l; + + l = (digest[ 0] << 16) | (digest[ 6] << 8) | (digest[12] << 0); + + buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 3] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[ 1] << 16) | (digest[ 7] << 8) | (digest[13] << 0); + + buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 7] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[ 2] << 16) | (digest[ 8] << 8) | (digest[14] << 0); + + buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[11] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[ 3] << 16) | (digest[ 9] << 8) | (digest[15] << 0); + + buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[15] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[ 4] << 16) | (digest[10] << 8) | (digest[ 5] << 0); + + buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[19] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[11] << 0); + + buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; +} + +static void sha512crypt_decode (u8 digest[64], u8 buf[86]) +{ + int l; + + l = itoa64_to_int (buf[ 0]) << 0; + l |= itoa64_to_int (buf[ 1]) << 6; + l |= itoa64_to_int (buf[ 2]) << 12; + l |= itoa64_to_int (buf[ 3]) << 18; + + digest[ 0] = (l >> 16) & 0xff; + digest[21] = (l >> 8) & 0xff; + digest[42] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[ 4]) << 0; + l |= itoa64_to_int (buf[ 5]) << 6; + l |= itoa64_to_int (buf[ 6]) << 12; + l |= itoa64_to_int (buf[ 7]) << 18; + + digest[22] = (l >> 16) & 0xff; + digest[43] = (l >> 8) & 0xff; + digest[ 1] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[ 8]) << 0; + l |= itoa64_to_int (buf[ 9]) << 6; + l |= itoa64_to_int (buf[10]) << 12; + l |= itoa64_to_int (buf[11]) << 18; + + digest[44] = (l >> 16) & 0xff; + digest[ 2] = (l >> 8) & 0xff; + digest[23] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[12]) << 0; + l |= itoa64_to_int (buf[13]) << 6; + l |= itoa64_to_int (buf[14]) << 12; + l |= itoa64_to_int (buf[15]) << 18; + + digest[ 3] = (l >> 16) & 0xff; + digest[24] = (l >> 8) & 0xff; + digest[45] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[16]) << 0; + l |= itoa64_to_int (buf[17]) << 6; + l |= itoa64_to_int (buf[18]) << 12; + l |= itoa64_to_int (buf[19]) << 18; + + digest[25] = (l >> 16) & 0xff; + digest[46] = (l >> 8) & 0xff; + digest[ 4] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[20]) << 0; + l |= itoa64_to_int (buf[21]) << 6; + l |= itoa64_to_int (buf[22]) << 12; + l |= itoa64_to_int (buf[23]) << 18; + + digest[47] = (l >> 16) & 0xff; + digest[ 5] = (l >> 8) & 0xff; + digest[26] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[24]) << 0; + l |= itoa64_to_int (buf[25]) << 6; + l |= itoa64_to_int (buf[26]) << 12; + l |= itoa64_to_int (buf[27]) << 18; + + digest[ 6] = (l >> 16) & 0xff; + digest[27] = (l >> 8) & 0xff; + digest[48] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[28]) << 0; + l |= itoa64_to_int (buf[29]) << 6; + l |= itoa64_to_int (buf[30]) << 12; + l |= itoa64_to_int (buf[31]) << 18; + + digest[28] = (l >> 16) & 0xff; + digest[49] = (l >> 8) & 0xff; + digest[ 7] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[32]) << 0; + l |= itoa64_to_int (buf[33]) << 6; + l |= itoa64_to_int (buf[34]) << 12; + l |= itoa64_to_int (buf[35]) << 18; + + digest[50] = (l >> 16) & 0xff; + digest[ 8] = (l >> 8) & 0xff; + digest[29] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[36]) << 0; + l |= itoa64_to_int (buf[37]) << 6; + l |= itoa64_to_int (buf[38]) << 12; + l |= itoa64_to_int (buf[39]) << 18; + + digest[ 9] = (l >> 16) & 0xff; + digest[30] = (l >> 8) & 0xff; + digest[51] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[40]) << 0; + l |= itoa64_to_int (buf[41]) << 6; + l |= itoa64_to_int (buf[42]) << 12; + l |= itoa64_to_int (buf[43]) << 18; + + digest[31] = (l >> 16) & 0xff; + digest[52] = (l >> 8) & 0xff; + digest[10] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[44]) << 0; + l |= itoa64_to_int (buf[45]) << 6; + l |= itoa64_to_int (buf[46]) << 12; + l |= itoa64_to_int (buf[47]) << 18; + + digest[53] = (l >> 16) & 0xff; + digest[11] = (l >> 8) & 0xff; + digest[32] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[48]) << 0; + l |= itoa64_to_int (buf[49]) << 6; + l |= itoa64_to_int (buf[50]) << 12; + l |= itoa64_to_int (buf[51]) << 18; + + digest[12] = (l >> 16) & 0xff; + digest[33] = (l >> 8) & 0xff; + digest[54] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[52]) << 0; + l |= itoa64_to_int (buf[53]) << 6; + l |= itoa64_to_int (buf[54]) << 12; + l |= itoa64_to_int (buf[55]) << 18; + + digest[34] = (l >> 16) & 0xff; + digest[55] = (l >> 8) & 0xff; + digest[13] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[56]) << 0; + l |= itoa64_to_int (buf[57]) << 6; + l |= itoa64_to_int (buf[58]) << 12; + l |= itoa64_to_int (buf[59]) << 18; + + digest[56] = (l >> 16) & 0xff; + digest[14] = (l >> 8) & 0xff; + digest[35] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[60]) << 0; + l |= itoa64_to_int (buf[61]) << 6; + l |= itoa64_to_int (buf[62]) << 12; + l |= itoa64_to_int (buf[63]) << 18; + + digest[15] = (l >> 16) & 0xff; + digest[36] = (l >> 8) & 0xff; + digest[57] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[64]) << 0; + l |= itoa64_to_int (buf[65]) << 6; + l |= itoa64_to_int (buf[66]) << 12; + l |= itoa64_to_int (buf[67]) << 18; + + digest[37] = (l >> 16) & 0xff; + digest[58] = (l >> 8) & 0xff; + digest[16] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[68]) << 0; + l |= itoa64_to_int (buf[69]) << 6; + l |= itoa64_to_int (buf[70]) << 12; + l |= itoa64_to_int (buf[71]) << 18; + + digest[59] = (l >> 16) & 0xff; + digest[17] = (l >> 8) & 0xff; + digest[38] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[72]) << 0; + l |= itoa64_to_int (buf[73]) << 6; + l |= itoa64_to_int (buf[74]) << 12; + l |= itoa64_to_int (buf[75]) << 18; + + digest[18] = (l >> 16) & 0xff; + digest[39] = (l >> 8) & 0xff; + digest[60] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[76]) << 0; + l |= itoa64_to_int (buf[77]) << 6; + l |= itoa64_to_int (buf[78]) << 12; + l |= itoa64_to_int (buf[79]) << 18; + + digest[40] = (l >> 16) & 0xff; + digest[61] = (l >> 8) & 0xff; + digest[19] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[80]) << 0; + l |= itoa64_to_int (buf[81]) << 6; + l |= itoa64_to_int (buf[82]) << 12; + l |= itoa64_to_int (buf[83]) << 18; + + digest[62] = (l >> 16) & 0xff; + digest[20] = (l >> 8) & 0xff; + digest[41] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[84]) << 0; + l |= itoa64_to_int (buf[85]) << 6; + + digest[63] = (l >> 0) & 0xff; +} + +static void sha512crypt_encode (u8 digest[64], u8 buf[86]) +{ + int l; + + l = (digest[ 0] << 16) | (digest[21] << 8) | (digest[42] << 0); + + buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 3] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[22] << 16) | (digest[43] << 8) | (digest[ 1] << 0); + + buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 7] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[44] << 16) | (digest[ 2] << 8) | (digest[23] << 0); + + buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[11] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[ 3] << 16) | (digest[24] << 8) | (digest[45] << 0); + + buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[15] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[25] << 16) | (digest[46] << 8) | (digest[ 4] << 0); + + buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[19] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[47] << 16) | (digest[ 5] << 8) | (digest[26] << 0); + + buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[22] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[23] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[ 6] << 16) | (digest[27] << 8) | (digest[48] << 0); + + buf[24] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[25] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[26] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[27] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[28] << 16) | (digest[49] << 8) | (digest[ 7] << 0); + + buf[28] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[29] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[30] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[31] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[50] << 16) | (digest[ 8] << 8) | (digest[29] << 0); + + buf[32] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[33] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[34] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[35] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[ 9] << 16) | (digest[30] << 8) | (digest[51] << 0); + + buf[36] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[37] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[38] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[39] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[31] << 16) | (digest[52] << 8) | (digest[10] << 0); + + buf[40] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[41] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[42] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[43] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[53] << 16) | (digest[11] << 8) | (digest[32] << 0); + + buf[44] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[45] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[46] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[47] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[12] << 16) | (digest[33] << 8) | (digest[54] << 0); + + buf[48] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[49] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[50] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[51] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[34] << 16) | (digest[55] << 8) | (digest[13] << 0); + + buf[52] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[53] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[54] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[55] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[56] << 16) | (digest[14] << 8) | (digest[35] << 0); + + buf[56] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[57] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[58] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[59] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[15] << 16) | (digest[36] << 8) | (digest[57] << 0); + + buf[60] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[61] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[62] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[63] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[37] << 16) | (digest[58] << 8) | (digest[16] << 0); + + buf[64] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[65] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[66] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[67] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[59] << 16) | (digest[17] << 8) | (digest[38] << 0); + + buf[68] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[69] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[70] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[71] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[18] << 16) | (digest[39] << 8) | (digest[60] << 0); + + buf[72] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[73] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[74] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[75] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[40] << 16) | (digest[61] << 8) | (digest[19] << 0); + + buf[76] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[77] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[78] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[79] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[62] << 16) | (digest[20] << 8) | (digest[41] << 0); + + buf[80] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[81] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[82] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[83] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = 0 | 0 | (digest[63] << 0); + + buf[84] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[85] = int_to_itoa64 (l & 0x3f); l >>= 6; +} + +static void sha1aix_decode (u8 digest[20], u8 buf[27]) +{ + int l; + + l = itoa64_to_int (buf[ 0]) << 0; + l |= itoa64_to_int (buf[ 1]) << 6; + l |= itoa64_to_int (buf[ 2]) << 12; + l |= itoa64_to_int (buf[ 3]) << 18; + + digest[ 2] = (l >> 0) & 0xff; + digest[ 1] = (l >> 8) & 0xff; + digest[ 0] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[ 4]) << 0; + l |= itoa64_to_int (buf[ 5]) << 6; + l |= itoa64_to_int (buf[ 6]) << 12; + l |= itoa64_to_int (buf[ 7]) << 18; + + digest[ 5] = (l >> 0) & 0xff; + digest[ 4] = (l >> 8) & 0xff; + digest[ 3] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[ 8]) << 0; + l |= itoa64_to_int (buf[ 9]) << 6; + l |= itoa64_to_int (buf[10]) << 12; + l |= itoa64_to_int (buf[11]) << 18; + + digest[ 8] = (l >> 0) & 0xff; + digest[ 7] = (l >> 8) & 0xff; + digest[ 6] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[12]) << 0; + l |= itoa64_to_int (buf[13]) << 6; + l |= itoa64_to_int (buf[14]) << 12; + l |= itoa64_to_int (buf[15]) << 18; + + digest[11] = (l >> 0) & 0xff; + digest[10] = (l >> 8) & 0xff; + digest[ 9] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[16]) << 0; + l |= itoa64_to_int (buf[17]) << 6; + l |= itoa64_to_int (buf[18]) << 12; + l |= itoa64_to_int (buf[19]) << 18; + + digest[14] = (l >> 0) & 0xff; + digest[13] = (l >> 8) & 0xff; + digest[12] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[20]) << 0; + l |= itoa64_to_int (buf[21]) << 6; + l |= itoa64_to_int (buf[22]) << 12; + l |= itoa64_to_int (buf[23]) << 18; + + digest[17] = (l >> 0) & 0xff; + digest[16] = (l >> 8) & 0xff; + digest[15] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[24]) << 0; + l |= itoa64_to_int (buf[25]) << 6; + l |= itoa64_to_int (buf[26]) << 12; + + digest[19] = (l >> 8) & 0xff; + digest[18] = (l >> 16) & 0xff; +} + +static void sha1aix_encode (u8 digest[20], u8 buf[27]) +{ + int l; + + l = (digest[ 2] << 0) | (digest[ 1] << 8) | (digest[ 0] << 16); + + buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 3] = int_to_itoa64 (l & 0x3f); + + l = (digest[ 5] << 0) | (digest[ 4] << 8) | (digest[ 3] << 16); + + buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 7] = int_to_itoa64 (l & 0x3f); + + l = (digest[ 8] << 0) | (digest[ 7] << 8) | (digest[ 6] << 16); + + buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[11] = int_to_itoa64 (l & 0x3f); + + l = (digest[11] << 0) | (digest[10] << 8) | (digest[ 9] << 16); + + buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[15] = int_to_itoa64 (l & 0x3f); + + l = (digest[14] << 0) | (digest[13] << 8) | (digest[12] << 16); + + buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[19] = int_to_itoa64 (l & 0x3f); + + l = (digest[17] << 0) | (digest[16] << 8) | (digest[15] << 16); + + buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[22] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[23] = int_to_itoa64 (l & 0x3f); + + l = 0 | (digest[19] << 8) | (digest[18] << 16); + + buf[24] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[25] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[26] = int_to_itoa64 (l & 0x3f); +} + +static void sha256aix_decode (u8 digest[32], u8 buf[43]) +{ + int l; + + l = itoa64_to_int (buf[ 0]) << 0; + l |= itoa64_to_int (buf[ 1]) << 6; + l |= itoa64_to_int (buf[ 2]) << 12; + l |= itoa64_to_int (buf[ 3]) << 18; + + digest[ 2] = (l >> 0) & 0xff; + digest[ 1] = (l >> 8) & 0xff; + digest[ 0] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[ 4]) << 0; + l |= itoa64_to_int (buf[ 5]) << 6; + l |= itoa64_to_int (buf[ 6]) << 12; + l |= itoa64_to_int (buf[ 7]) << 18; + + digest[ 5] = (l >> 0) & 0xff; + digest[ 4] = (l >> 8) & 0xff; + digest[ 3] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[ 8]) << 0; + l |= itoa64_to_int (buf[ 9]) << 6; + l |= itoa64_to_int (buf[10]) << 12; + l |= itoa64_to_int (buf[11]) << 18; + + digest[ 8] = (l >> 0) & 0xff; + digest[ 7] = (l >> 8) & 0xff; + digest[ 6] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[12]) << 0; + l |= itoa64_to_int (buf[13]) << 6; + l |= itoa64_to_int (buf[14]) << 12; + l |= itoa64_to_int (buf[15]) << 18; + + digest[11] = (l >> 0) & 0xff; + digest[10] = (l >> 8) & 0xff; + digest[ 9] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[16]) << 0; + l |= itoa64_to_int (buf[17]) << 6; + l |= itoa64_to_int (buf[18]) << 12; + l |= itoa64_to_int (buf[19]) << 18; + + digest[14] = (l >> 0) & 0xff; + digest[13] = (l >> 8) & 0xff; + digest[12] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[20]) << 0; + l |= itoa64_to_int (buf[21]) << 6; + l |= itoa64_to_int (buf[22]) << 12; + l |= itoa64_to_int (buf[23]) << 18; + + digest[17] = (l >> 0) & 0xff; + digest[16] = (l >> 8) & 0xff; + digest[15] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[24]) << 0; + l |= itoa64_to_int (buf[25]) << 6; + l |= itoa64_to_int (buf[26]) << 12; + l |= itoa64_to_int (buf[27]) << 18; + + digest[20] = (l >> 0) & 0xff; + digest[19] = (l >> 8) & 0xff; + digest[18] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[28]) << 0; + l |= itoa64_to_int (buf[29]) << 6; + l |= itoa64_to_int (buf[30]) << 12; + l |= itoa64_to_int (buf[31]) << 18; + + digest[23] = (l >> 0) & 0xff; + digest[22] = (l >> 8) & 0xff; + digest[21] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[32]) << 0; + l |= itoa64_to_int (buf[33]) << 6; + l |= itoa64_to_int (buf[34]) << 12; + l |= itoa64_to_int (buf[35]) << 18; + + digest[26] = (l >> 0) & 0xff; + digest[25] = (l >> 8) & 0xff; + digest[24] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[36]) << 0; + l |= itoa64_to_int (buf[37]) << 6; + l |= itoa64_to_int (buf[38]) << 12; + l |= itoa64_to_int (buf[39]) << 18; + + digest[29] = (l >> 0) & 0xff; + digest[28] = (l >> 8) & 0xff; + digest[27] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[40]) << 0; + l |= itoa64_to_int (buf[41]) << 6; + l |= itoa64_to_int (buf[42]) << 12; + + //digest[32] = (l >> 0) & 0xff; + digest[31] = (l >> 8) & 0xff; + digest[30] = (l >> 16) & 0xff; +} + +static void sha256aix_encode (u8 digest[32], u8 buf[43]) +{ + int l; + + l = (digest[ 2] << 0) | (digest[ 1] << 8) | (digest[ 0] << 16); + + buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 3] = int_to_itoa64 (l & 0x3f); + + l = (digest[ 5] << 0) | (digest[ 4] << 8) | (digest[ 3] << 16); + + buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 7] = int_to_itoa64 (l & 0x3f); + + l = (digest[ 8] << 0) | (digest[ 7] << 8) | (digest[ 6] << 16); + + buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[11] = int_to_itoa64 (l & 0x3f); + + l = (digest[11] << 0) | (digest[10] << 8) | (digest[ 9] << 16); + + buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[15] = int_to_itoa64 (l & 0x3f); + + l = (digest[14] << 0) | (digest[13] << 8) | (digest[12] << 16); + + buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[19] = int_to_itoa64 (l & 0x3f); + + l = (digest[17] << 0) | (digest[16] << 8) | (digest[15] << 16); + + buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[22] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[23] = int_to_itoa64 (l & 0x3f); + + l = (digest[20] << 0) | (digest[19] << 8) | (digest[18] << 16); + + buf[24] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[25] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[26] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[27] = int_to_itoa64 (l & 0x3f); + + l = (digest[23] << 0) | (digest[22] << 8) | (digest[21] << 16); + + buf[28] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[29] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[30] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[31] = int_to_itoa64 (l & 0x3f); + + l = (digest[26] << 0) | (digest[25] << 8) | (digest[24] << 16); + + buf[32] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[33] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[34] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[35] = int_to_itoa64 (l & 0x3f); + + l = (digest[29] << 0) | (digest[28] << 8) | (digest[27] << 16); + + buf[36] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[37] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[38] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[39] = int_to_itoa64 (l & 0x3f); + + l = 0 | (digest[31] << 8) | (digest[30] << 16); + + buf[40] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[41] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[42] = int_to_itoa64 (l & 0x3f); +} + +static void sha512aix_decode (u8 digest[64], u8 buf[86]) +{ + int l; + + l = itoa64_to_int (buf[ 0]) << 0; + l |= itoa64_to_int (buf[ 1]) << 6; + l |= itoa64_to_int (buf[ 2]) << 12; + l |= itoa64_to_int (buf[ 3]) << 18; + + digest[ 2] = (l >> 0) & 0xff; + digest[ 1] = (l >> 8) & 0xff; + digest[ 0] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[ 4]) << 0; + l |= itoa64_to_int (buf[ 5]) << 6; + l |= itoa64_to_int (buf[ 6]) << 12; + l |= itoa64_to_int (buf[ 7]) << 18; + + digest[ 5] = (l >> 0) & 0xff; + digest[ 4] = (l >> 8) & 0xff; + digest[ 3] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[ 8]) << 0; + l |= itoa64_to_int (buf[ 9]) << 6; + l |= itoa64_to_int (buf[10]) << 12; + l |= itoa64_to_int (buf[11]) << 18; + + digest[ 8] = (l >> 0) & 0xff; + digest[ 7] = (l >> 8) & 0xff; + digest[ 6] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[12]) << 0; + l |= itoa64_to_int (buf[13]) << 6; + l |= itoa64_to_int (buf[14]) << 12; + l |= itoa64_to_int (buf[15]) << 18; + + digest[11] = (l >> 0) & 0xff; + digest[10] = (l >> 8) & 0xff; + digest[ 9] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[16]) << 0; + l |= itoa64_to_int (buf[17]) << 6; + l |= itoa64_to_int (buf[18]) << 12; + l |= itoa64_to_int (buf[19]) << 18; + + digest[14] = (l >> 0) & 0xff; + digest[13] = (l >> 8) & 0xff; + digest[12] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[20]) << 0; + l |= itoa64_to_int (buf[21]) << 6; + l |= itoa64_to_int (buf[22]) << 12; + l |= itoa64_to_int (buf[23]) << 18; + + digest[17] = (l >> 0) & 0xff; + digest[16] = (l >> 8) & 0xff; + digest[15] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[24]) << 0; + l |= itoa64_to_int (buf[25]) << 6; + l |= itoa64_to_int (buf[26]) << 12; + l |= itoa64_to_int (buf[27]) << 18; + + digest[20] = (l >> 0) & 0xff; + digest[19] = (l >> 8) & 0xff; + digest[18] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[28]) << 0; + l |= itoa64_to_int (buf[29]) << 6; + l |= itoa64_to_int (buf[30]) << 12; + l |= itoa64_to_int (buf[31]) << 18; + + digest[23] = (l >> 0) & 0xff; + digest[22] = (l >> 8) & 0xff; + digest[21] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[32]) << 0; + l |= itoa64_to_int (buf[33]) << 6; + l |= itoa64_to_int (buf[34]) << 12; + l |= itoa64_to_int (buf[35]) << 18; + + digest[26] = (l >> 0) & 0xff; + digest[25] = (l >> 8) & 0xff; + digest[24] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[36]) << 0; + l |= itoa64_to_int (buf[37]) << 6; + l |= itoa64_to_int (buf[38]) << 12; + l |= itoa64_to_int (buf[39]) << 18; + + digest[29] = (l >> 0) & 0xff; + digest[28] = (l >> 8) & 0xff; + digest[27] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[40]) << 0; + l |= itoa64_to_int (buf[41]) << 6; + l |= itoa64_to_int (buf[42]) << 12; + l |= itoa64_to_int (buf[43]) << 18; + + digest[32] = (l >> 0) & 0xff; + digest[31] = (l >> 8) & 0xff; + digest[30] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[44]) << 0; + l |= itoa64_to_int (buf[45]) << 6; + l |= itoa64_to_int (buf[46]) << 12; + l |= itoa64_to_int (buf[47]) << 18; + + digest[35] = (l >> 0) & 0xff; + digest[34] = (l >> 8) & 0xff; + digest[33] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[48]) << 0; + l |= itoa64_to_int (buf[49]) << 6; + l |= itoa64_to_int (buf[50]) << 12; + l |= itoa64_to_int (buf[51]) << 18; + + digest[38] = (l >> 0) & 0xff; + digest[37] = (l >> 8) & 0xff; + digest[36] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[52]) << 0; + l |= itoa64_to_int (buf[53]) << 6; + l |= itoa64_to_int (buf[54]) << 12; + l |= itoa64_to_int (buf[55]) << 18; + + digest[41] = (l >> 0) & 0xff; + digest[40] = (l >> 8) & 0xff; + digest[39] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[56]) << 0; + l |= itoa64_to_int (buf[57]) << 6; + l |= itoa64_to_int (buf[58]) << 12; + l |= itoa64_to_int (buf[59]) << 18; + + digest[44] = (l >> 0) & 0xff; + digest[43] = (l >> 8) & 0xff; + digest[42] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[60]) << 0; + l |= itoa64_to_int (buf[61]) << 6; + l |= itoa64_to_int (buf[62]) << 12; + l |= itoa64_to_int (buf[63]) << 18; + + digest[47] = (l >> 0) & 0xff; + digest[46] = (l >> 8) & 0xff; + digest[45] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[64]) << 0; + l |= itoa64_to_int (buf[65]) << 6; + l |= itoa64_to_int (buf[66]) << 12; + l |= itoa64_to_int (buf[67]) << 18; + + digest[50] = (l >> 0) & 0xff; + digest[49] = (l >> 8) & 0xff; + digest[48] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[68]) << 0; + l |= itoa64_to_int (buf[69]) << 6; + l |= itoa64_to_int (buf[70]) << 12; + l |= itoa64_to_int (buf[71]) << 18; + + digest[53] = (l >> 0) & 0xff; + digest[52] = (l >> 8) & 0xff; + digest[51] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[72]) << 0; + l |= itoa64_to_int (buf[73]) << 6; + l |= itoa64_to_int (buf[74]) << 12; + l |= itoa64_to_int (buf[75]) << 18; + + digest[56] = (l >> 0) & 0xff; + digest[55] = (l >> 8) & 0xff; + digest[54] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[76]) << 0; + l |= itoa64_to_int (buf[77]) << 6; + l |= itoa64_to_int (buf[78]) << 12; + l |= itoa64_to_int (buf[79]) << 18; + + digest[59] = (l >> 0) & 0xff; + digest[58] = (l >> 8) & 0xff; + digest[57] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[80]) << 0; + l |= itoa64_to_int (buf[81]) << 6; + l |= itoa64_to_int (buf[82]) << 12; + l |= itoa64_to_int (buf[83]) << 18; + + digest[62] = (l >> 0) & 0xff; + digest[61] = (l >> 8) & 0xff; + digest[60] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[84]) << 0; + l |= itoa64_to_int (buf[85]) << 6; + + digest[63] = (l >> 16) & 0xff; +} + +static void sha512aix_encode (u8 digest[64], u8 buf[86]) +{ + int l; + + l = (digest[ 2] << 0) | (digest[ 1] << 8) | (digest[ 0] << 16); + + buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 3] = int_to_itoa64 (l & 0x3f); + + l = (digest[ 5] << 0) | (digest[ 4] << 8) | (digest[ 3] << 16); + + buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 7] = int_to_itoa64 (l & 0x3f); + + l = (digest[ 8] << 0) | (digest[ 7] << 8) | (digest[ 6] << 16); + + buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[11] = int_to_itoa64 (l & 0x3f); + + l = (digest[11] << 0) | (digest[10] << 8) | (digest[ 9] << 16); + + buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[15] = int_to_itoa64 (l & 0x3f); + + l = (digest[14] << 0) | (digest[13] << 8) | (digest[12] << 16); + + buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[19] = int_to_itoa64 (l & 0x3f); + + l = (digest[17] << 0) | (digest[16] << 8) | (digest[15] << 16); + + buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[22] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[23] = int_to_itoa64 (l & 0x3f); + + l = (digest[20] << 0) | (digest[19] << 8) | (digest[18] << 16); + + buf[24] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[25] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[26] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[27] = int_to_itoa64 (l & 0x3f); + + l = (digest[23] << 0) | (digest[22] << 8) | (digest[21] << 16); + + buf[28] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[29] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[30] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[31] = int_to_itoa64 (l & 0x3f); + + l = (digest[26] << 0) | (digest[25] << 8) | (digest[24] << 16); + + buf[32] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[33] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[34] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[35] = int_to_itoa64 (l & 0x3f); + + l = (digest[29] << 0) | (digest[28] << 8) | (digest[27] << 16); + + buf[36] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[37] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[38] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[39] = int_to_itoa64 (l & 0x3f); + + l = (digest[32] << 0) | (digest[31] << 8) | (digest[30] << 16); + + buf[40] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[41] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[42] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[43] = int_to_itoa64 (l & 0x3f); + + l = (digest[35] << 0) | (digest[34] << 8) | (digest[33] << 16); + + buf[44] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[45] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[46] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[47] = int_to_itoa64 (l & 0x3f); + + l = (digest[38] << 0) | (digest[37] << 8) | (digest[36] << 16); + + buf[48] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[49] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[50] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[51] = int_to_itoa64 (l & 0x3f); + + l = (digest[41] << 0) | (digest[40] << 8) | (digest[39] << 16); + + buf[52] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[53] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[54] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[55] = int_to_itoa64 (l & 0x3f); + + l = (digest[44] << 0) | (digest[43] << 8) | (digest[42] << 16); + + buf[56] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[57] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[58] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[59] = int_to_itoa64 (l & 0x3f); + + l = (digest[47] << 0) | (digest[46] << 8) | (digest[45] << 16); + + buf[60] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[61] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[62] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[63] = int_to_itoa64 (l & 0x3f); + + l = (digest[50] << 0) | (digest[49] << 8) | (digest[48] << 16); + + buf[64] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[65] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[66] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[67] = int_to_itoa64 (l & 0x3f); + + l = (digest[53] << 0) | (digest[52] << 8) | (digest[51] << 16); + + buf[68] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[69] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[70] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[71] = int_to_itoa64 (l & 0x3f); + + l = (digest[56] << 0) | (digest[55] << 8) | (digest[54] << 16); + + buf[72] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[73] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[74] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[75] = int_to_itoa64 (l & 0x3f); + + l = (digest[59] << 0) | (digest[58] << 8) | (digest[57] << 16); + + buf[76] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[77] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[78] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[79] = int_to_itoa64 (l & 0x3f); + + l = (digest[62] << 0) | (digest[61] << 8) | (digest[60] << 16); + + buf[80] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[81] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[82] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[83] = int_to_itoa64 (l & 0x3f); + + l = 0 | 0 | (digest[63] << 16); + + buf[84] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[85] = int_to_itoa64 (l & 0x3f); l >>= 6; +} + +static void sha256crypt_decode (u8 digest[32], u8 buf[43]) +{ + int l; + + l = itoa64_to_int (buf[ 0]) << 0; + l |= itoa64_to_int (buf[ 1]) << 6; + l |= itoa64_to_int (buf[ 2]) << 12; + l |= itoa64_to_int (buf[ 3]) << 18; + + digest[ 0] = (l >> 16) & 0xff; + digest[10] = (l >> 8) & 0xff; + digest[20] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[ 4]) << 0; + l |= itoa64_to_int (buf[ 5]) << 6; + l |= itoa64_to_int (buf[ 6]) << 12; + l |= itoa64_to_int (buf[ 7]) << 18; + + digest[21] = (l >> 16) & 0xff; + digest[ 1] = (l >> 8) & 0xff; + digest[11] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[ 8]) << 0; + l |= itoa64_to_int (buf[ 9]) << 6; + l |= itoa64_to_int (buf[10]) << 12; + l |= itoa64_to_int (buf[11]) << 18; + + digest[12] = (l >> 16) & 0xff; + digest[22] = (l >> 8) & 0xff; + digest[ 2] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[12]) << 0; + l |= itoa64_to_int (buf[13]) << 6; + l |= itoa64_to_int (buf[14]) << 12; + l |= itoa64_to_int (buf[15]) << 18; + + digest[ 3] = (l >> 16) & 0xff; + digest[13] = (l >> 8) & 0xff; + digest[23] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[16]) << 0; + l |= itoa64_to_int (buf[17]) << 6; + l |= itoa64_to_int (buf[18]) << 12; + l |= itoa64_to_int (buf[19]) << 18; + + digest[24] = (l >> 16) & 0xff; + digest[ 4] = (l >> 8) & 0xff; + digest[14] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[20]) << 0; + l |= itoa64_to_int (buf[21]) << 6; + l |= itoa64_to_int (buf[22]) << 12; + l |= itoa64_to_int (buf[23]) << 18; + + digest[15] = (l >> 16) & 0xff; + digest[25] = (l >> 8) & 0xff; + digest[ 5] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[24]) << 0; + l |= itoa64_to_int (buf[25]) << 6; + l |= itoa64_to_int (buf[26]) << 12; + l |= itoa64_to_int (buf[27]) << 18; + + digest[ 6] = (l >> 16) & 0xff; + digest[16] = (l >> 8) & 0xff; + digest[26] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[28]) << 0; + l |= itoa64_to_int (buf[29]) << 6; + l |= itoa64_to_int (buf[30]) << 12; + l |= itoa64_to_int (buf[31]) << 18; + + digest[27] = (l >> 16) & 0xff; + digest[ 7] = (l >> 8) & 0xff; + digest[17] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[32]) << 0; + l |= itoa64_to_int (buf[33]) << 6; + l |= itoa64_to_int (buf[34]) << 12; + l |= itoa64_to_int (buf[35]) << 18; + + digest[18] = (l >> 16) & 0xff; + digest[28] = (l >> 8) & 0xff; + digest[ 8] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[36]) << 0; + l |= itoa64_to_int (buf[37]) << 6; + l |= itoa64_to_int (buf[38]) << 12; + l |= itoa64_to_int (buf[39]) << 18; + + digest[ 9] = (l >> 16) & 0xff; + digest[19] = (l >> 8) & 0xff; + digest[29] = (l >> 0) & 0xff; + + l = itoa64_to_int (buf[40]) << 0; + l |= itoa64_to_int (buf[41]) << 6; + l |= itoa64_to_int (buf[42]) << 12; + + digest[31] = (l >> 8) & 0xff; + digest[30] = (l >> 0) & 0xff; +} + +static void sha256crypt_encode (u8 digest[32], u8 buf[43]) +{ + int l; + + l = (digest[ 0] << 16) | (digest[10] << 8) | (digest[20] << 0); + + buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 3] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[21] << 16) | (digest[ 1] << 8) | (digest[11] << 0); + + buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 7] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[12] << 16) | (digest[22] << 8) | (digest[ 2] << 0); + + buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[11] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[ 3] << 16) | (digest[13] << 8) | (digest[23] << 0); + + buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[15] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[24] << 16) | (digest[ 4] << 8) | (digest[14] << 0); + + buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[19] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[15] << 16) | (digest[25] << 8) | (digest[ 5] << 0); + + buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[22] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[23] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[ 6] << 16) | (digest[16] << 8) | (digest[26] << 0); + + buf[24] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[25] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[26] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[27] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[27] << 16) | (digest[ 7] << 8) | (digest[17] << 0); + + buf[28] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[29] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[30] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[31] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[18] << 16) | (digest[28] << 8) | (digest[ 8] << 0); + + buf[32] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[33] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[34] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[35] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = (digest[ 9] << 16) | (digest[19] << 8) | (digest[29] << 0); + + buf[36] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[37] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[38] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[39] = int_to_itoa64 (l & 0x3f); l >>= 6; + + l = 0 | (digest[31] << 8) | (digest[30] << 0); + + buf[40] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[41] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[42] = int_to_itoa64 (l & 0x3f); +} + +static void drupal7_decode (u8 digest[64], u8 buf[44]) +{ + int l; + + l = itoa64_to_int (buf[ 0]) << 0; + l |= itoa64_to_int (buf[ 1]) << 6; + l |= itoa64_to_int (buf[ 2]) << 12; + l |= itoa64_to_int (buf[ 3]) << 18; + + digest[ 0] = (l >> 0) & 0xff; + digest[ 1] = (l >> 8) & 0xff; + digest[ 2] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[ 4]) << 0; + l |= itoa64_to_int (buf[ 5]) << 6; + l |= itoa64_to_int (buf[ 6]) << 12; + l |= itoa64_to_int (buf[ 7]) << 18; + + digest[ 3] = (l >> 0) & 0xff; + digest[ 4] = (l >> 8) & 0xff; + digest[ 5] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[ 8]) << 0; + l |= itoa64_to_int (buf[ 9]) << 6; + l |= itoa64_to_int (buf[10]) << 12; + l |= itoa64_to_int (buf[11]) << 18; + + digest[ 6] = (l >> 0) & 0xff; + digest[ 7] = (l >> 8) & 0xff; + digest[ 8] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[12]) << 0; + l |= itoa64_to_int (buf[13]) << 6; + l |= itoa64_to_int (buf[14]) << 12; + l |= itoa64_to_int (buf[15]) << 18; + + digest[ 9] = (l >> 0) & 0xff; + digest[10] = (l >> 8) & 0xff; + digest[11] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[16]) << 0; + l |= itoa64_to_int (buf[17]) << 6; + l |= itoa64_to_int (buf[18]) << 12; + l |= itoa64_to_int (buf[19]) << 18; + + digest[12] = (l >> 0) & 0xff; + digest[13] = (l >> 8) & 0xff; + digest[14] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[20]) << 0; + l |= itoa64_to_int (buf[21]) << 6; + l |= itoa64_to_int (buf[22]) << 12; + l |= itoa64_to_int (buf[23]) << 18; + + digest[15] = (l >> 0) & 0xff; + digest[16] = (l >> 8) & 0xff; + digest[17] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[24]) << 0; + l |= itoa64_to_int (buf[25]) << 6; + l |= itoa64_to_int (buf[26]) << 12; + l |= itoa64_to_int (buf[27]) << 18; + + digest[18] = (l >> 0) & 0xff; + digest[19] = (l >> 8) & 0xff; + digest[20] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[28]) << 0; + l |= itoa64_to_int (buf[29]) << 6; + l |= itoa64_to_int (buf[30]) << 12; + l |= itoa64_to_int (buf[31]) << 18; + + digest[21] = (l >> 0) & 0xff; + digest[22] = (l >> 8) & 0xff; + digest[23] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[32]) << 0; + l |= itoa64_to_int (buf[33]) << 6; + l |= itoa64_to_int (buf[34]) << 12; + l |= itoa64_to_int (buf[35]) << 18; + + digest[24] = (l >> 0) & 0xff; + digest[25] = (l >> 8) & 0xff; + digest[26] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[36]) << 0; + l |= itoa64_to_int (buf[37]) << 6; + l |= itoa64_to_int (buf[38]) << 12; + l |= itoa64_to_int (buf[39]) << 18; + + digest[27] = (l >> 0) & 0xff; + digest[28] = (l >> 8) & 0xff; + digest[29] = (l >> 16) & 0xff; + + l = itoa64_to_int (buf[40]) << 0; + l |= itoa64_to_int (buf[41]) << 6; + l |= itoa64_to_int (buf[42]) << 12; + l |= itoa64_to_int (buf[43]) << 18; + + digest[30] = (l >> 0) & 0xff; + digest[31] = (l >> 8) & 0xff; + digest[32] = (l >> 16) & 0xff; + + digest[33] = 0; + digest[34] = 0; + digest[35] = 0; + digest[36] = 0; + digest[37] = 0; + digest[38] = 0; + digest[39] = 0; + digest[40] = 0; + digest[41] = 0; + digest[42] = 0; + digest[43] = 0; + digest[44] = 0; + digest[45] = 0; + digest[46] = 0; + digest[47] = 0; + digest[48] = 0; + digest[49] = 0; + digest[50] = 0; + digest[51] = 0; + digest[52] = 0; + digest[53] = 0; + digest[54] = 0; + digest[55] = 0; + digest[56] = 0; + digest[57] = 0; + digest[58] = 0; + digest[59] = 0; + digest[60] = 0; + digest[61] = 0; + digest[62] = 0; + digest[63] = 0; +} + +static void drupal7_encode (u8 digest[64], u8 buf[43]) +{ + int l; + + l = (digest[ 0] << 0) | (digest[ 1] << 8) | (digest[ 2] << 16); + + buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 3] = int_to_itoa64 (l & 0x3f); + + l = (digest[ 3] << 0) | (digest[ 4] << 8) | (digest[ 5] << 16); + + buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 7] = int_to_itoa64 (l & 0x3f); + + l = (digest[ 6] << 0) | (digest[ 7] << 8) | (digest[ 8] << 16); + + buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[11] = int_to_itoa64 (l & 0x3f); + + l = (digest[ 9] << 0) | (digest[10] << 8) | (digest[11] << 16); + + buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[15] = int_to_itoa64 (l & 0x3f); + + l = (digest[12] << 0) | (digest[13] << 8) | (digest[14] << 16); + + buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[19] = int_to_itoa64 (l & 0x3f); + + l = (digest[15] << 0) | (digest[16] << 8) | (digest[17] << 16); + + buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[22] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[23] = int_to_itoa64 (l & 0x3f); + + l = (digest[18] << 0) | (digest[19] << 8) | (digest[20] << 16); + + buf[24] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[25] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[26] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[27] = int_to_itoa64 (l & 0x3f); + + l = (digest[21] << 0) | (digest[22] << 8) | (digest[23] << 16); + + buf[28] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[29] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[30] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[31] = int_to_itoa64 (l & 0x3f); + + l = (digest[24] << 0) | (digest[25] << 8) | (digest[26] << 16); + + buf[32] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[33] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[34] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[35] = int_to_itoa64 (l & 0x3f); + + l = (digest[27] << 0) | (digest[28] << 8) | (digest[29] << 16); + + buf[36] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[37] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[38] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[39] = int_to_itoa64 (l & 0x3f); + + l = (digest[30] << 0) | (digest[31] << 8) | (digest[32] << 16); + + buf[40] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[41] = int_to_itoa64 (l & 0x3f); l >>= 6; + buf[42] = int_to_itoa64 (l & 0x3f); l >>= 6; + //buf[43] = int_to_itoa64 (l & 0x3f); +} + +/** + * parser + */ + +static uint parse_and_store_salt (char *out, char *in, uint salt_len) +{ + u8 tmp[256] = { 0 }; + + if (salt_len > sizeof (tmp)) + { + return UINT_MAX; + } + + memcpy (tmp, in, salt_len); + + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((salt_len % 2) == 0) + { + u32 new_salt_len = salt_len / 2; + + for (uint i = 0, j = 0; i < new_salt_len; i += 1, j += 2) + { + u8 p0 = tmp[j + 0]; + u8 p1 = tmp[j + 1]; + + tmp[i] = hex_convert (p1) << 0; + tmp[i] |= hex_convert (p0) << 4; + } + + salt_len = new_salt_len; + } + else + { + return UINT_MAX; + } + } + else if (data.opts_type & OPTS_TYPE_ST_BASE64) + { + salt_len = base64_decode (base64_to_int, (const u8 *) in, salt_len, (u8 *) tmp); + } + + memset (tmp + salt_len, 0, sizeof (tmp) - salt_len); + + if (data.opts_type & OPTS_TYPE_ST_UNICODE) + { + if (salt_len < 20) + { + u32 *tmp_uint = (u32 *) tmp; + + tmp_uint[9] = ((tmp_uint[4] >> 8) & 0x00FF0000) | ((tmp_uint[4] >> 16) & 0x000000FF); + tmp_uint[8] = ((tmp_uint[4] << 8) & 0x00FF0000) | ((tmp_uint[4] >> 0) & 0x000000FF); + tmp_uint[7] = ((tmp_uint[3] >> 8) & 0x00FF0000) | ((tmp_uint[3] >> 16) & 0x000000FF); + tmp_uint[6] = ((tmp_uint[3] << 8) & 0x00FF0000) | ((tmp_uint[3] >> 0) & 0x000000FF); + tmp_uint[5] = ((tmp_uint[2] >> 8) & 0x00FF0000) | ((tmp_uint[2] >> 16) & 0x000000FF); + tmp_uint[4] = ((tmp_uint[2] << 8) & 0x00FF0000) | ((tmp_uint[2] >> 0) & 0x000000FF); + tmp_uint[3] = ((tmp_uint[1] >> 8) & 0x00FF0000) | ((tmp_uint[1] >> 16) & 0x000000FF); + tmp_uint[2] = ((tmp_uint[1] << 8) & 0x00FF0000) | ((tmp_uint[1] >> 0) & 0x000000FF); + tmp_uint[1] = ((tmp_uint[0] >> 8) & 0x00FF0000) | ((tmp_uint[0] >> 16) & 0x000000FF); + tmp_uint[0] = ((tmp_uint[0] << 8) & 0x00FF0000) | ((tmp_uint[0] >> 0) & 0x000000FF); + + salt_len = salt_len * 2; + } + else + { + return UINT_MAX; + } + } + + if (data.opts_type & OPTS_TYPE_ST_LOWER) + { + lowercase (tmp, salt_len); + } + + if (data.opts_type & OPTS_TYPE_ST_UPPER) + { + uppercase (tmp, salt_len); + } + + u32 len = salt_len; + + if (data.opts_type & OPTS_TYPE_ST_ADD80) + { + tmp[len++] = 0x80; + } + + if (data.opts_type & OPTS_TYPE_ST_ADD01) + { + tmp[len++] = 0x01; + } + + if (data.opts_type & OPTS_TYPE_ST_GENERATE_LE) + { + u32 *tmp_uint = (uint *) tmp; + + u32 max = len / 4; + + if (len % 4) max++; + + for (u32 i = 0; i < max; i++) + { + tmp_uint[i] = byte_swap_32 (tmp_uint[i]); + } + + // Important: we may need to increase the length of memcpy since + // we don't want to "loose" some swapped bytes (could happen if + // they do not perfectly fit in the 4-byte blocks) + // Memcpy does always copy the bytes in the BE order, but since + // we swapped them, some important bytes could be in positions + // we normally skip with the original len + + if (len % 4) len += 4 - (len % 4); + } + + memcpy (out, tmp, len); + + return (salt_len); +} + +int bcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_3200) || (input_len > DISPLAY_LEN_MAX_3200)) return (PARSER_GLOBAL_LENGTH); + + if ((memcmp (SIGNATURE_BCRYPT1, input_buf, 4)) && (memcmp (SIGNATURE_BCRYPT2, input_buf, 4)) && (memcmp (SIGNATURE_BCRYPT3, input_buf, 4)) && (memcmp (SIGNATURE_BCRYPT4, input_buf, 4))) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + memcpy ((char *) salt->salt_sign, input_buf, 6); + + char *iter_pos = input_buf + 4; + + salt->salt_iter = 1u << atoi (iter_pos); + + char *salt_pos = strchr (iter_pos, '$'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + uint salt_len = 16; + + salt->salt_len = salt_len; + + u8 tmp_buf[100] = { 0 }; + + base64_decode (bf64_to_int, (const u8 *) salt_pos, 22, tmp_buf); + + char *salt_buf_ptr = (char *) salt->salt_buf; + + memcpy (salt_buf_ptr, tmp_buf, 16); + + salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); + salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); + salt->salt_buf[2] = byte_swap_32 (salt->salt_buf[2]); + salt->salt_buf[3] = byte_swap_32 (salt->salt_buf[3]); + + char *hash_pos = salt_pos + 22; + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + base64_decode (bf64_to_int, (const u8 *) hash_pos, 31, tmp_buf); + + memcpy (digest, tmp_buf, 24); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + digest[5] = byte_swap_32 (digest[5]); + + digest[5] &= ~0xffu; // its just 23 not 24 ! + + return (PARSER_OK); +} + +int cisco4_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_5700) || (input_len > DISPLAY_LEN_MAX_5700)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + u8 tmp_buf[100] = { 0 }; + + base64_decode (itoa64_to_int, (const u8 *) input_buf, 43, tmp_buf); + + memcpy (digest, tmp_buf, 32); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + digest[5] = byte_swap_32 (digest[5]); + digest[6] = byte_swap_32 (digest[6]); + digest[7] = byte_swap_32 (digest[7]); + + digest[0] -= SHA256M_A; + digest[1] -= SHA256M_B; + digest[2] -= SHA256M_C; + digest[3] -= SHA256M_D; + digest[4] -= SHA256M_E; + digest[5] -= SHA256M_F; + digest[6] -= SHA256M_G; + digest[7] -= SHA256M_H; + + return (PARSER_OK); +} + +int lm_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_3000) || (input_len > DISPLAY_LEN_MAX_3000)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + + uint tt; + + IP (digest[0], digest[1], tt); + + digest[0] = digest[0]; + digest[1] = digest[1]; + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int arubaos_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_125) || (input_len > DISPLAY_LEN_MAX_125)) return (PARSER_GLOBAL_LENGTH); + + if ((input_buf[8] != '0') || (input_buf[9] != '1')) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *hash_pos = input_buf + 10; + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + uint salt_len = 10; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, input_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int osx1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_122) || (input_len > DISPLAY_LEN_MAX_122)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *hash_pos = input_buf + 8; + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + uint salt_len = 8; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, input_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int osx512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_1722) || (input_len > DISPLAY_LEN_MAX_1722)) return (PARSER_GLOBAL_LENGTH); + + u64 *digest = (u64 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *hash_pos = input_buf + 8; + + digest[0] = hex_to_u64 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u64 ((const u8 *) &hash_pos[ 16]); + digest[2] = hex_to_u64 ((const u8 *) &hash_pos[ 32]); + digest[3] = hex_to_u64 ((const u8 *) &hash_pos[ 48]); + digest[4] = hex_to_u64 ((const u8 *) &hash_pos[ 64]); + digest[5] = hex_to_u64 ((const u8 *) &hash_pos[ 80]); + digest[6] = hex_to_u64 ((const u8 *) &hash_pos[ 96]); + digest[7] = hex_to_u64 ((const u8 *) &hash_pos[112]); + + digest[0] -= SHA512M_A; + digest[1] -= SHA512M_B; + digest[2] -= SHA512M_C; + digest[3] -= SHA512M_D; + digest[4] -= SHA512M_E; + digest[5] -= SHA512M_F; + digest[6] -= SHA512M_G; + digest[7] -= SHA512M_H; + + uint salt_len = 8; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, input_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int osc_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_21H) || (input_len > DISPLAY_LEN_MAX_21H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_21) || (input_len > DISPLAY_LEN_MAX_21)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 32 - 1; + + char *salt_buf = input_buf + 32 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int netscreen_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_22H) || (input_len > DISPLAY_LEN_MAX_22H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_22) || (input_len > DISPLAY_LEN_MAX_22)) return (PARSER_GLOBAL_LENGTH); + } + + // unscramble + + char clean_input_buf[32] = { 0 }; + + char sig[6] = { 'n', 'r', 'c', 's', 't', 'n' }; + int pos[6] = { 0, 6, 12, 17, 23, 29 }; + + for (int i = 0, j = 0, k = 0; i < 30; i++) + { + if (i == pos[j]) + { + if (sig[j] != input_buf[i]) return (PARSER_SIGNATURE_UNMATCHED); + + j++; + } + else + { + clean_input_buf[k] = input_buf[i]; + + k++; + } + } + + // base64 decode + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + u32 a, b, c, d, e, f; + + a = base64_to_int (clean_input_buf[ 0] & 0x7f); + b = base64_to_int (clean_input_buf[ 1] & 0x7f); + c = base64_to_int (clean_input_buf[ 2] & 0x7f); + d = base64_to_int (clean_input_buf[ 3] & 0x7f); + e = base64_to_int (clean_input_buf[ 4] & 0x7f); + f = base64_to_int (clean_input_buf[ 5] & 0x7f); + + digest[0] = (((a << 12) | (b << 6) | (c)) << 16) + | (((d << 12) | (e << 6) | (f)) << 0); + + a = base64_to_int (clean_input_buf[ 6] & 0x7f); + b = base64_to_int (clean_input_buf[ 7] & 0x7f); + c = base64_to_int (clean_input_buf[ 8] & 0x7f); + d = base64_to_int (clean_input_buf[ 9] & 0x7f); + e = base64_to_int (clean_input_buf[10] & 0x7f); + f = base64_to_int (clean_input_buf[11] & 0x7f); + + digest[1] = (((a << 12) | (b << 6) | (c)) << 16) + | (((d << 12) | (e << 6) | (f)) << 0); + + a = base64_to_int (clean_input_buf[12] & 0x7f); + b = base64_to_int (clean_input_buf[13] & 0x7f); + c = base64_to_int (clean_input_buf[14] & 0x7f); + d = base64_to_int (clean_input_buf[15] & 0x7f); + e = base64_to_int (clean_input_buf[16] & 0x7f); + f = base64_to_int (clean_input_buf[17] & 0x7f); + + digest[2] = (((a << 12) | (b << 6) | (c)) << 16) + | (((d << 12) | (e << 6) | (f)) << 0); + + a = base64_to_int (clean_input_buf[18] & 0x7f); + b = base64_to_int (clean_input_buf[19] & 0x7f); + c = base64_to_int (clean_input_buf[20] & 0x7f); + d = base64_to_int (clean_input_buf[21] & 0x7f); + e = base64_to_int (clean_input_buf[22] & 0x7f); + f = base64_to_int (clean_input_buf[23] & 0x7f); + + digest[3] = (((a << 12) | (b << 6) | (c)) << 16) + | (((d << 12) | (e << 6) | (f)) << 0); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + if (input_buf[30] != ':') return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 30 - 1; + + char *salt_buf = input_buf + 30 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + // max. salt length: 55 (max for MD5) - 22 (":Administration Tools:") - 1 (0x80) = 32 + // 32 - 4 bytes (to fit w0lr for all attack modes) = 28 + + if (salt_len > 28) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + memcpy (salt_buf_ptr + salt_len, ":Administration Tools:", 22); + + salt->salt_len += 22; + + return (PARSER_OK); +} + +int smf_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_121H) || (input_len > DISPLAY_LEN_MAX_121H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_121) || (input_len > DISPLAY_LEN_MAX_121)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 40 - 1; + + char *salt_buf = input_buf + 40 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int dcc2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_2100H) || (input_len > DISPLAY_LEN_MAX_2100H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_2100) || (input_len > DISPLAY_LEN_MAX_2100)) return (PARSER_GLOBAL_LENGTH); + } + + if (memcmp (SIGNATURE_DCC2, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + char *iter_pos = input_buf + 6; + + salt_t *salt = hash_buf->salt; + + uint iter = atoi (iter_pos); + + if (iter < 1) + { + iter = ROUNDS_DCC2; + } + + salt->salt_iter = iter - 1; + + char *salt_pos = strchr (iter_pos, '#'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + char *digest_pos = strchr (salt_pos, '#'); + + if (digest_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + digest_pos++; + + uint salt_len = digest_pos - salt_pos - 1; + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &digest_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &digest_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &digest_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &digest_pos[24]); + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int wpa_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + wpa_t *wpa = (wpa_t *) hash_buf->esalt; + + hccap_t in; + + memcpy (&in, input_buf, input_len); + + if (in.eapol_size < 1 || in.eapol_size > 255) return (PARSER_HCCAP_EAPOL_SIZE); + + memcpy (digest, in.keymic, 16); + + /* + http://www.one-net.eu/jsw/j_sec/m_ptype.html + The phrase "Pairwise key expansion" + Access Point Address (referred to as Authenticator Address AA) + Supplicant Address (referred to as Supplicant Address SA) + Access Point Nonce (referred to as Authenticator Anonce) + Wireless Device Nonce (referred to as Supplicant Nonce Snonce) + */ + + uint salt_len = strlen (in.essid); + + if (salt_len > 36) + { + log_info ("WARNING: The ESSID length is too long, the hccap file may be invalid or corrupted"); + + return (PARSER_SALT_LENGTH); + } + + memcpy (salt->salt_buf, in.essid, salt_len); + + salt->salt_len = salt_len; + + salt->salt_iter = ROUNDS_WPA2 - 1; + + unsigned char *pke_ptr = (unsigned char *) wpa->pke; + + memcpy (pke_ptr, "Pairwise key expansion", 23); + + if (memcmp (in.mac1, in.mac2, 6) < 0) + { + memcpy (pke_ptr + 23, in.mac1, 6); + memcpy (pke_ptr + 29, in.mac2, 6); + } + else + { + memcpy (pke_ptr + 23, in.mac2, 6); + memcpy (pke_ptr + 29, in.mac1, 6); + } + + if (memcmp (in.nonce1, in.nonce2, 32) < 0) + { + memcpy (pke_ptr + 35, in.nonce1, 32); + memcpy (pke_ptr + 67, in.nonce2, 32); + } + else + { + memcpy (pke_ptr + 35, in.nonce2, 32); + memcpy (pke_ptr + 67, in.nonce1, 32); + } + + for (int i = 0; i < 25; i++) + { + wpa->pke[i] = byte_swap_32 (wpa->pke[i]); + } + + memcpy (wpa->orig_mac1, in.mac1, 6); + memcpy (wpa->orig_mac2, in.mac2, 6); + memcpy (wpa->orig_nonce1, in.nonce1, 32); + memcpy (wpa->orig_nonce2, in.nonce2, 32); + + wpa->keyver = in.keyver; + + if (wpa->keyver > 255) + { + log_info ("ATTENTION!"); + log_info (" The WPA/WPA2 key version in your .hccap file is invalid!"); + log_info (" This could be due to a recent aircrack-ng bug."); + log_info (" The key version was automatically reset to a reasonable value."); + log_info (""); + + wpa->keyver &= 0xff; + } + + wpa->eapol_size = in.eapol_size; + + unsigned char *eapol_ptr = (unsigned char *) wpa->eapol; + + memcpy (eapol_ptr, in.eapol, wpa->eapol_size); + + memset (eapol_ptr + wpa->eapol_size, 0, 256 - wpa->eapol_size); + + eapol_ptr[wpa->eapol_size] = (unsigned char) 0x80; + + if (wpa->keyver == 1) + { + // nothing to do + } + else + { + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + for (int i = 0; i < 64; i++) + { + wpa->eapol[i] = byte_swap_32 (wpa->eapol[i]); + } + } + + uint32_t *p0 = (uint32_t *) in.essid; + uint32_t c0 = 0; + uint32_t c1 = 0; + + for (uint i = 0; i < sizeof (in.essid) / sizeof (uint32_t); i++) c0 ^= *p0++; + for (uint i = 0; i < sizeof (wpa->pke) / sizeof (wpa->pke[0]); i++) c1 ^= wpa->pke[i]; + + salt->salt_buf[10] = c0; + salt->salt_buf[11] = c1; + + return (PARSER_OK); +} + +int psafe2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + if (input_len == 0) + { + log_error ("Password Safe v2 container not specified"); + + exit (-1); + } + + FILE *fp = fopen (input_buf, "rb"); + + if (fp == NULL) + { + log_error ("%s: %s", input_buf, strerror (errno)); + + exit (-1); + } + + psafe2_hdr buf; + + memset (&buf, 0, sizeof (psafe2_hdr)); + + int n = fread (&buf, sizeof (psafe2_hdr), 1, fp); + + fclose (fp); + + if (n != 1) return (PARSER_PSAFE2_FILE_SIZE); + + salt->salt_buf[0] = buf.random[0]; + salt->salt_buf[1] = buf.random[1]; + + salt->salt_len = 8; + salt->salt_iter = 1000; + + digest[0] = byte_swap_32 (buf.hash[0]); + digest[1] = byte_swap_32 (buf.hash[1]); + digest[2] = byte_swap_32 (buf.hash[2]); + digest[3] = byte_swap_32 (buf.hash[3]); + digest[4] = byte_swap_32 (buf.hash[4]); + + return (PARSER_OK); +} + +int psafe3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + if (input_len == 0) + { + log_error (".psafe3 not specified"); + + exit (-1); + } + + FILE *fp = fopen (input_buf, "rb"); + + if (fp == NULL) + { + log_error ("%s: %s", input_buf, strerror (errno)); + + exit (-1); + } + + psafe3_t in; + + int n = fread (&in, sizeof (psafe3_t), 1, fp); + + fclose (fp); + + data.hashfile = input_buf; // we will need this in case it gets cracked + + if (memcmp (SIGNATURE_PSAFE3, in.signature, 4)) return (PARSER_SIGNATURE_UNMATCHED); + + if (n != 1) return (PARSER_PSAFE3_FILE_SIZE); + + salt->salt_iter = in.iterations + 1; + + salt->salt_buf[0] = in.salt_buf[0]; + salt->salt_buf[1] = in.salt_buf[1]; + salt->salt_buf[2] = in.salt_buf[2]; + salt->salt_buf[3] = in.salt_buf[3]; + salt->salt_buf[4] = in.salt_buf[4]; + salt->salt_buf[5] = in.salt_buf[5]; + salt->salt_buf[6] = in.salt_buf[6]; + salt->salt_buf[7] = in.salt_buf[7]; + + salt->salt_len = 32; + + digest[0] = in.hash_buf[0]; + digest[1] = in.hash_buf[1]; + digest[2] = in.hash_buf[2]; + digest[3] = in.hash_buf[3]; + digest[4] = in.hash_buf[4]; + digest[5] = in.hash_buf[5]; + digest[6] = in.hash_buf[6]; + digest[7] = in.hash_buf[7]; + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + digest[5] = byte_swap_32 (digest[5]); + digest[6] = byte_swap_32 (digest[6]); + digest[7] = byte_swap_32 (digest[7]); + + return (PARSER_OK); +} + +int phpass_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_400) || (input_len > DISPLAY_LEN_MAX_400)) return (PARSER_GLOBAL_LENGTH); + + if ((memcmp (SIGNATURE_PHPASS1, input_buf, 3)) && (memcmp (SIGNATURE_PHPASS2, input_buf, 3))) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *iter_pos = input_buf + 3; + + uint salt_iter = 1u << itoa64_to_int (iter_pos[0]); + + if (salt_iter > 0x80000000) return (PARSER_SALT_ITERATION); + + memcpy ((char *) salt->salt_sign, input_buf, 4); + + salt->salt_iter = salt_iter; + + char *salt_pos = iter_pos + 1; + + uint salt_len = 8; + + memcpy ((char *) salt->salt_buf, salt_pos, salt_len); + + salt->salt_len = salt_len; + + char *hash_pos = salt_pos + salt_len; + + phpass_decode ((unsigned char *) digest, (unsigned char *) hash_pos); + + return (PARSER_OK); +} + +int md5crypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (input_len < DISPLAY_LEN_MIN_500) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_MD5CRYPT, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_pos = input_buf + 3; + + uint iterations_len = 0; + + if (memcmp (salt_pos, "rounds=", 7) == 0) + { + salt_pos += 7; + + for (iterations_len = 0; salt_pos[0] >= '0' && salt_pos[0] <= '9' && iterations_len < 7; iterations_len++, salt_pos += 1) continue; + + if (iterations_len == 0 ) return (PARSER_SALT_ITERATION); + if (salt_pos[0] != '$') return (PARSER_SIGNATURE_UNMATCHED); + + salt_pos[0] = 0x0; + + salt->salt_iter = atoi (salt_pos - iterations_len); + + salt_pos += 1; + + iterations_len += 8; + } + else + { + salt->salt_iter = ROUNDS_MD5CRYPT; + } + + if (input_len > (DISPLAY_LEN_MAX_500 + iterations_len)) return (PARSER_GLOBAL_LENGTH); + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + if (salt_len > 8) return (PARSER_SALT_LENGTH); + + memcpy ((char *) salt->salt_buf, salt_pos, salt_len); + + salt->salt_len = salt_len; + + hash_pos++; + + uint hash_len = input_len - 3 - iterations_len - salt_len - 1; + + if (hash_len != 22) return (PARSER_HASH_LENGTH); + + md5crypt_decode ((unsigned char *) digest, (unsigned char *) hash_pos); + + return (PARSER_OK); +} + +int md5apr1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (memcmp (SIGNATURE_MD5APR1, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_pos = input_buf + 6; + + uint iterations_len = 0; + + if (memcmp (salt_pos, "rounds=", 7) == 0) + { + salt_pos += 7; + + for (iterations_len = 0; salt_pos[0] >= '0' && salt_pos[0] <= '9' && iterations_len < 7; iterations_len++, salt_pos += 1) continue; + + if (iterations_len == 0 ) return (PARSER_SALT_ITERATION); + if (salt_pos[0] != '$') return (PARSER_SIGNATURE_UNMATCHED); + + salt_pos[0] = 0x0; + + salt->salt_iter = atoi (salt_pos - iterations_len); + + salt_pos += 1; + + iterations_len += 8; + } + else + { + salt->salt_iter = ROUNDS_MD5CRYPT; + } + + if ((input_len < DISPLAY_LEN_MIN_1600) || (input_len > DISPLAY_LEN_MAX_1600 + iterations_len)) return (PARSER_GLOBAL_LENGTH); + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + if (salt_len > 8) return (PARSER_SALT_LENGTH); + + memcpy ((char *) salt->salt_buf, salt_pos, salt_len); + + salt->salt_len = salt_len; + + hash_pos++; + + md5crypt_decode ((unsigned char *) digest, (unsigned char *) hash_pos); + + return (PARSER_OK); +} + +int episerver_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_141) || (input_len > DISPLAY_LEN_MAX_141)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_EPISERVER, input_buf, 14)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_pos = input_buf + 14; + + char *hash_pos = strchr (salt_pos, '*'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + hash_pos++; + + uint salt_len = hash_pos - salt_pos - 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + u8 tmp_buf[100] = { 0 }; + + base64_decode (base64_to_int, (const u8 *) hash_pos, 27, tmp_buf); + + memcpy (digest, tmp_buf, 20); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + return (PARSER_OK); +} + +int descrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_1500) || (input_len > DISPLAY_LEN_MAX_1500)) return (PARSER_GLOBAL_LENGTH); + + unsigned char c12 = itoa64_to_int (input_buf[12]); + + if (c12 & 3) return (PARSER_HASH_VALUE); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + // for ascii_digest + salt->salt_sign[0] = input_buf[0]; + salt->salt_sign[1] = input_buf[1]; + + salt->salt_buf[0] = itoa64_to_int (input_buf[0]) + | itoa64_to_int (input_buf[1]) << 6; + + salt->salt_len = 2; + + u8 tmp_buf[100] = { 0 }; + + base64_decode (itoa64_to_int, (const u8 *) input_buf + 2, 11, tmp_buf); + + memcpy (digest, tmp_buf, 8); + + uint tt; + + IP (digest[0], digest[1], tt); + + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int md4_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_900) || (input_len > DISPLAY_LEN_MAX_900)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD4M_A; + digest[1] -= MD4M_B; + digest[2] -= MD4M_C; + digest[3] -= MD4M_D; + + return (PARSER_OK); +} + +int md4s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_910H) || (input_len > DISPLAY_LEN_MAX_910H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_910) || (input_len > DISPLAY_LEN_MAX_910)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD4M_A; + digest[1] -= MD4M_B; + digest[2] -= MD4M_C; + digest[3] -= MD4M_D; + + if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 32 - 1; + + char *salt_buf = input_buf + 32 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_0) || (input_len > DISPLAY_LEN_MAX_0)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + return (PARSER_OK); +} + +int md5half_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_5100) || (input_len > DISPLAY_LEN_MAX_5100)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[8]); + digest[2] = 0; + digest[3] = 0; + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + + return (PARSER_OK); +} + +int md5s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_10H) || (input_len > DISPLAY_LEN_MAX_10H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_10) || (input_len > DISPLAY_LEN_MAX_10)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 32 - 1; + + char *salt_buf = input_buf + 32 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int md5pix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_2400) || (input_len > DISPLAY_LEN_MAX_2400)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = itoa64_to_int (input_buf[ 0]) << 0 + | itoa64_to_int (input_buf[ 1]) << 6 + | itoa64_to_int (input_buf[ 2]) << 12 + | itoa64_to_int (input_buf[ 3]) << 18; + digest[1] = itoa64_to_int (input_buf[ 4]) << 0 + | itoa64_to_int (input_buf[ 5]) << 6 + | itoa64_to_int (input_buf[ 6]) << 12 + | itoa64_to_int (input_buf[ 7]) << 18; + digest[2] = itoa64_to_int (input_buf[ 8]) << 0 + | itoa64_to_int (input_buf[ 9]) << 6 + | itoa64_to_int (input_buf[10]) << 12 + | itoa64_to_int (input_buf[11]) << 18; + digest[3] = itoa64_to_int (input_buf[12]) << 0 + | itoa64_to_int (input_buf[13]) << 6 + | itoa64_to_int (input_buf[14]) << 12 + | itoa64_to_int (input_buf[15]) << 18; + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + digest[0] &= 0x00ffffff; + digest[1] &= 0x00ffffff; + digest[2] &= 0x00ffffff; + digest[3] &= 0x00ffffff; + + return (PARSER_OK); +} + +int md5asa_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_2410H) || (input_len > DISPLAY_LEN_MAX_2410H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_2410) || (input_len > DISPLAY_LEN_MAX_2410)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = itoa64_to_int (input_buf[ 0]) << 0 + | itoa64_to_int (input_buf[ 1]) << 6 + | itoa64_to_int (input_buf[ 2]) << 12 + | itoa64_to_int (input_buf[ 3]) << 18; + digest[1] = itoa64_to_int (input_buf[ 4]) << 0 + | itoa64_to_int (input_buf[ 5]) << 6 + | itoa64_to_int (input_buf[ 6]) << 12 + | itoa64_to_int (input_buf[ 7]) << 18; + digest[2] = itoa64_to_int (input_buf[ 8]) << 0 + | itoa64_to_int (input_buf[ 9]) << 6 + | itoa64_to_int (input_buf[10]) << 12 + | itoa64_to_int (input_buf[11]) << 18; + digest[3] = itoa64_to_int (input_buf[12]) << 0 + | itoa64_to_int (input_buf[13]) << 6 + | itoa64_to_int (input_buf[14]) << 12 + | itoa64_to_int (input_buf[15]) << 18; + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + digest[0] &= 0x00ffffff; + digest[1] &= 0x00ffffff; + digest[2] &= 0x00ffffff; + digest[3] &= 0x00ffffff; + + if (input_buf[16] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 16 - 1; + + char *salt_buf = input_buf + 16 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +static void transform_netntlmv1_key (const u8 *nthash, u8 *key) +{ + key[0] = (nthash[0] >> 0); + key[1] = (nthash[0] << 7) | (nthash[1] >> 1); + key[2] = (nthash[1] << 6) | (nthash[2] >> 2); + key[3] = (nthash[2] << 5) | (nthash[3] >> 3); + key[4] = (nthash[3] << 4) | (nthash[4] >> 4); + key[5] = (nthash[4] << 3) | (nthash[5] >> 5); + key[6] = (nthash[5] << 2) | (nthash[6] >> 6); + key[7] = (nthash[6] << 1); + + key[0] |= 0x01; + key[1] |= 0x01; + key[2] |= 0x01; + key[3] |= 0x01; + key[4] |= 0x01; + key[5] |= 0x01; + key[6] |= 0x01; + key[7] |= 0x01; +} + +int netntlmv1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_5500) || (input_len > DISPLAY_LEN_MAX_5500)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + netntlm_t *netntlm = (netntlm_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *user_pos = input_buf; + + char *unused_pos = strchr (user_pos, ':'); + + if (unused_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint user_len = unused_pos - user_pos; + + if (user_len > 60) return (PARSER_SALT_LENGTH); + + unused_pos++; + + char *domain_pos = strchr (unused_pos, ':'); + + if (domain_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint unused_len = domain_pos - unused_pos; + + if (unused_len != 0) return (PARSER_SALT_LENGTH); + + domain_pos++; + + char *srvchall_pos = strchr (domain_pos, ':'); + + if (srvchall_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint domain_len = srvchall_pos - domain_pos; + + if (domain_len > 45) return (PARSER_SALT_LENGTH); + + srvchall_pos++; + + char *hash_pos = strchr (srvchall_pos, ':'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint srvchall_len = hash_pos - srvchall_pos; + + // if (srvchall_len != 0) return (PARSER_SALT_LENGTH); + + hash_pos++; + + char *clichall_pos = strchr (hash_pos, ':'); + + if (clichall_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint hash_len = clichall_pos - hash_pos; + + if (hash_len != 48) return (PARSER_HASH_LENGTH); + + clichall_pos++; + + uint clichall_len = input_len - user_len - 1 - unused_len - 1 - domain_len - 1 - srvchall_len - 1 - hash_len - 1; + + if (clichall_len != 16) return (PARSER_SALT_LENGTH); + + /** + * store some data for later use + */ + + netntlm->user_len = user_len * 2; + netntlm->domain_len = domain_len * 2; + netntlm->srvchall_len = srvchall_len / 2; + netntlm->clichall_len = clichall_len / 2; + + char *userdomain_ptr = (char *) netntlm->userdomain_buf; + char *chall_ptr = (char *) netntlm->chall_buf; + + /** + * handle username and domainname + */ + + for (uint i = 0; i < user_len; i++) + { + *userdomain_ptr++ = user_pos[i]; + *userdomain_ptr++ = 0; + } + + for (uint i = 0; i < domain_len; i++) + { + *userdomain_ptr++ = domain_pos[i]; + *userdomain_ptr++ = 0; + } + + /** + * handle server challenge encoding + */ + + for (uint i = 0; i < srvchall_len; i += 2) + { + const char p0 = srvchall_pos[i + 0]; + const char p1 = srvchall_pos[i + 1]; + + *chall_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + /** + * handle client challenge encoding + */ + + for (uint i = 0; i < clichall_len; i += 2) + { + const char p0 = clichall_pos[i + 0]; + const char p1 = clichall_pos[i + 1]; + + *chall_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + /** + * store data + */ + + char *salt_buf_ptr = (char *) salt->salt_buf; + + uint salt_len = parse_and_store_salt (salt_buf_ptr, clichall_pos, clichall_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + /* special case, last 8 byte do not need to be checked since they are brute-forced next */ + + uint digest_tmp[2] = { 0 }; + + digest_tmp[0] = hex_to_u32 ((const u8 *) &hash_pos[32]); + digest_tmp[1] = hex_to_u32 ((const u8 *) &hash_pos[40]); + + digest_tmp[0] = byte_swap_32 (digest_tmp[0]); + digest_tmp[1] = byte_swap_32 (digest_tmp[1]); + + /* special case 2: ESS */ + + if (srvchall_len == 48) + { + if ((netntlm->chall_buf[2] == 0) && (netntlm->chall_buf[3] == 0) && (netntlm->chall_buf[4] == 0) && (netntlm->chall_buf[5] == 0)) + { + uint w[16] = { 0 }; + + w[ 0] = netntlm->chall_buf[6]; + w[ 1] = netntlm->chall_buf[7]; + w[ 2] = netntlm->chall_buf[0]; + w[ 3] = netntlm->chall_buf[1]; + w[ 4] = 0x80; + w[14] = 16 * 8; + + uint dgst[4] = { 0 }; + + dgst[0] = MD5M_A; + dgst[1] = MD5M_B; + dgst[2] = MD5M_C; + dgst[3] = MD5M_D; + + md5_64 (w, dgst); + + salt->salt_buf[0] = dgst[0]; + salt->salt_buf[1] = dgst[1]; + } + } + + /* precompute netntlmv1 exploit start */ + + for (uint i = 0; i < 0x10000; i++) + { + uint key_md4[2] = { i, 0 }; + uint key_des[2] = { 0, 0 }; + + transform_netntlmv1_key ((u8 *) key_md4, (u8 *) key_des); + + uint Kc[16] = { 0 }; + uint Kd[16] = { 0 }; + + _des_keysetup (key_des, Kc, Kd, c_skb); + + uint data3[2] = { salt->salt_buf[0], salt->salt_buf[1] }; + + _des_encrypt (data3, Kc, Kd, c_SPtrans); + + if (data3[0] != digest_tmp[0]) continue; + if (data3[1] != digest_tmp[1]) continue; + + salt->salt_buf[2] = i; + + salt->salt_len = 24; + + break; + } + + salt->salt_buf_pc[0] = digest_tmp[0]; + salt->salt_buf_pc[1] = digest_tmp[1]; + + /* precompute netntlmv1 exploit stop */ + + u32 tt; + + IP (digest[0], digest[1], tt); + IP (digest[2], digest[3], tt); + + digest[0] = rotr32 (digest[0], 29); + digest[1] = rotr32 (digest[1], 29); + digest[2] = rotr32 (digest[2], 29); + digest[3] = rotr32 (digest[3], 29); + + IP (salt->salt_buf[0], salt->salt_buf[1], tt); + + salt->salt_buf[0] = rotl32 (salt->salt_buf[0], 3); + salt->salt_buf[1] = rotl32 (salt->salt_buf[1], 3); + + return (PARSER_OK); +} + +int netntlmv2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_5600) || (input_len > DISPLAY_LEN_MAX_5600)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + netntlm_t *netntlm = (netntlm_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *user_pos = input_buf; + + char *unused_pos = strchr (user_pos, ':'); + + if (unused_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint user_len = unused_pos - user_pos; + + if (user_len > 60) return (PARSER_SALT_LENGTH); + + unused_pos++; + + char *domain_pos = strchr (unused_pos, ':'); + + if (domain_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint unused_len = domain_pos - unused_pos; + + if (unused_len != 0) return (PARSER_SALT_LENGTH); + + domain_pos++; + + char *srvchall_pos = strchr (domain_pos, ':'); + + if (srvchall_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint domain_len = srvchall_pos - domain_pos; + + if (domain_len > 45) return (PARSER_SALT_LENGTH); + + srvchall_pos++; + + char *hash_pos = strchr (srvchall_pos, ':'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint srvchall_len = hash_pos - srvchall_pos; + + if (srvchall_len != 16) return (PARSER_SALT_LENGTH); + + hash_pos++; + + char *clichall_pos = strchr (hash_pos, ':'); + + if (clichall_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint hash_len = clichall_pos - hash_pos; + + if (hash_len != 32) return (PARSER_HASH_LENGTH); + + clichall_pos++; + + uint clichall_len = input_len - user_len - 1 - unused_len - 1 - domain_len - 1 - srvchall_len - 1 - hash_len - 1; + + if (clichall_len > 1024) return (PARSER_SALT_LENGTH); + + if (clichall_len % 2) return (PARSER_SALT_VALUE); + + /** + * store some data for later use + */ + + netntlm->user_len = user_len * 2; + netntlm->domain_len = domain_len * 2; + netntlm->srvchall_len = srvchall_len / 2; + netntlm->clichall_len = clichall_len / 2; + + char *userdomain_ptr = (char *) netntlm->userdomain_buf; + char *chall_ptr = (char *) netntlm->chall_buf; + + /** + * handle username and domainname + */ + + for (uint i = 0; i < user_len; i++) + { + *userdomain_ptr++ = toupper (user_pos[i]); + *userdomain_ptr++ = 0; + } + + for (uint i = 0; i < domain_len; i++) + { + *userdomain_ptr++ = domain_pos[i]; + *userdomain_ptr++ = 0; + } + + *userdomain_ptr++ = 0x80; + + /** + * handle server challenge encoding + */ + + for (uint i = 0; i < srvchall_len; i += 2) + { + const char p0 = srvchall_pos[i + 0]; + const char p1 = srvchall_pos[i + 1]; + + *chall_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + /** + * handle client challenge encoding + */ + + for (uint i = 0; i < clichall_len; i += 2) + { + const char p0 = clichall_pos[i + 0]; + const char p1 = clichall_pos[i + 1]; + + *chall_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + *chall_ptr++ = 0x80; + + /** + * handle hash itself + */ + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + /** + * reuse challange data as salt_buf, its the buffer that is most likely unique + */ + + salt->salt_buf[0] = 0; + salt->salt_buf[1] = 0; + salt->salt_buf[2] = 0; + salt->salt_buf[3] = 0; + salt->salt_buf[4] = 0; + salt->salt_buf[5] = 0; + salt->salt_buf[6] = 0; + salt->salt_buf[7] = 0; + + uint *uptr; + + uptr = (uint *) netntlm->userdomain_buf; + + for (uint i = 0; i < 16; i += 16) + { + md5_64 (uptr, salt->salt_buf); + } + + uptr = (uint *) netntlm->chall_buf; + + for (uint i = 0; i < 256; i += 16) + { + md5_64 (uptr, salt->salt_buf); + } + + salt->salt_len = 16; + + return (PARSER_OK); +} + +int joomla_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_11H) || (input_len > DISPLAY_LEN_MAX_11H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_11) || (input_len > DISPLAY_LEN_MAX_11)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 32 - 1; + + char *salt_buf = input_buf + 32 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int postgresql_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_12H) || (input_len > DISPLAY_LEN_MAX_12H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_12) || (input_len > DISPLAY_LEN_MAX_12)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 32 - 1; + + char *salt_buf = input_buf + 32 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int md5md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_2600) || (input_len > DISPLAY_LEN_MAX_2600)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + /** + * This is a virtual salt. While the algorithm is basically not salted + * we can exploit the salt buffer to set the 0x80 and the w[14] value. + * This way we can save a special md5md5 kernel and reuse the one from vbull. + */ + + char *salt_buf_ptr = (char *) salt->salt_buf; + + uint salt_len = parse_and_store_salt (salt_buf_ptr, (char *) "", 0); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int vb3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_2611H) || (input_len > DISPLAY_LEN_MAX_2611H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_2611) || (input_len > DISPLAY_LEN_MAX_2611)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 32 - 1; + + char *salt_buf = input_buf + 32 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int vb30_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_2711H) || (input_len > DISPLAY_LEN_MAX_2711H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_2711) || (input_len > DISPLAY_LEN_MAX_2711)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 32 - 1; + + char *salt_buf = input_buf + 32 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int dcc_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_1100H) || (input_len > DISPLAY_LEN_MAX_1100H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_1100) || (input_len > DISPLAY_LEN_MAX_1100)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD4M_A; + digest[1] -= MD4M_B; + digest[2] -= MD4M_C; + digest[3] -= MD4M_D; + + if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 32 - 1; + + char *salt_buf = input_buf + 32 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int ipb2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_2811H) || (input_len > DISPLAY_LEN_MAX_2811H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_2811) || (input_len > DISPLAY_LEN_MAX_2811)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 32 - 1; + + char *salt_buf = input_buf + 32 + 1; + + uint salt_pc_block[16] = { 0 }; + + char *salt_pc_block_ptr = (char *) salt_pc_block; + + salt_len = parse_and_store_salt (salt_pc_block_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt_pc_block_ptr[salt_len] = (unsigned char) 0x80; + + salt_pc_block[14] = salt_len * 8; + + uint salt_pc_digest[4] = { MD5M_A, MD5M_B, MD5M_C, MD5M_D }; + + md5_64 (salt_pc_block, salt_pc_digest); + + salt_pc_digest[0] = byte_swap_32 (salt_pc_digest[0]); + salt_pc_digest[1] = byte_swap_32 (salt_pc_digest[1]); + salt_pc_digest[2] = byte_swap_32 (salt_pc_digest[2]); + salt_pc_digest[3] = byte_swap_32 (salt_pc_digest[3]); + + u8 *salt_buf_ptr = (u8 *) salt->salt_buf; + + memcpy (salt_buf_ptr, salt_buf, salt_len); + + u8 *salt_buf_pc_ptr = (u8 *) salt->salt_buf_pc; + + bin_to_hex_lower (salt_pc_digest[0], salt_buf_pc_ptr + 0); + bin_to_hex_lower (salt_pc_digest[1], salt_buf_pc_ptr + 8); + bin_to_hex_lower (salt_pc_digest[2], salt_buf_pc_ptr + 16); + bin_to_hex_lower (salt_pc_digest[3], salt_buf_pc_ptr + 24); + + salt->salt_len = 32; // changed, was salt_len before -- was a bug? 32 should be correct + + return (PARSER_OK); +} + +int sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_100) || (input_len > DISPLAY_LEN_MAX_100)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + return (PARSER_OK); +} + +int sha1axcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_13300) || (input_len > DISPLAY_LEN_MAX_13300)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_AXCRYPT_SHA1, input_buf, 13)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + input_buf += 14; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = 0; + + return (PARSER_OK); +} + +int sha1s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_110H) || (input_len > DISPLAY_LEN_MAX_110H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_110) || (input_len > DISPLAY_LEN_MAX_110)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 40 - 1; + + char *salt_buf = input_buf + 40 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int pstoken_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_13500) || (input_len > DISPLAY_LEN_MAX_13500)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pstoken_t *pstoken = (pstoken_t *) hash_buf->esalt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + + if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 40 - 1; + + char *salt_buf = input_buf + 40 + 1; + + if (salt_len == UINT_MAX || salt_len % 2 != 0) return (PARSER_SALT_LENGTH); + + u8 *pstoken_ptr = (u8 *) pstoken->salt_buf; + + for (uint i = 0, j = 0; i < salt_len; i += 2, j += 1) + { + pstoken_ptr[j] = hex_to_u8 ((const u8 *) &salt_buf[i]); + } + + pstoken->salt_len = salt_len / 2; + + /* some fake salt for the sorting mechanisms */ + + salt->salt_buf[0] = pstoken->salt_buf[0]; + salt->salt_buf[1] = pstoken->salt_buf[1]; + salt->salt_buf[2] = pstoken->salt_buf[2]; + salt->salt_buf[3] = pstoken->salt_buf[3]; + salt->salt_buf[4] = pstoken->salt_buf[4]; + salt->salt_buf[5] = pstoken->salt_buf[5]; + salt->salt_buf[6] = pstoken->salt_buf[6]; + salt->salt_buf[7] = pstoken->salt_buf[7]; + + salt->salt_len = 32; + + /* we need to check if we can precompute some of the data -- + this is possible since the scheme is badly designed */ + + pstoken->pc_digest[0] = SHA1M_A; + pstoken->pc_digest[1] = SHA1M_B; + pstoken->pc_digest[2] = SHA1M_C; + pstoken->pc_digest[3] = SHA1M_D; + pstoken->pc_digest[4] = SHA1M_E; + + pstoken->pc_offset = 0; + + for (int i = 0; i < (int) pstoken->salt_len - 63; i += 64) + { + uint w[16]; + + w[ 0] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 0]); + w[ 1] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 1]); + w[ 2] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 2]); + w[ 3] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 3]); + w[ 4] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 4]); + w[ 5] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 5]); + w[ 6] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 6]); + w[ 7] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 7]); + w[ 8] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 8]); + w[ 9] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 9]); + w[10] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 10]); + w[11] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 11]); + w[12] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 12]); + w[13] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 13]); + w[14] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 14]); + w[15] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 15]); + + sha1_64 (w, pstoken->pc_digest); + + pstoken->pc_offset += 16; + } + + return (PARSER_OK); +} + +int sha1b64_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_101) || (input_len > DISPLAY_LEN_MAX_101)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SHA1B64, input_buf, 5)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + u8 tmp_buf[100] = { 0 }; + + base64_decode (base64_to_int, (const u8 *) input_buf + 5, input_len - 5, tmp_buf); + + memcpy (digest, tmp_buf, 20); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + return (PARSER_OK); +} + +int sha1b64s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_111) || (input_len > DISPLAY_LEN_MAX_111)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SSHA1B64_lower, input_buf, 6) && memcmp (SIGNATURE_SSHA1B64_upper, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + u8 tmp_buf[100] = { 0 }; + + int tmp_len = base64_decode (base64_to_int, (const u8 *) input_buf + 6, input_len - 6, tmp_buf); + + if (tmp_len < 20) return (PARSER_HASH_LENGTH); + + memcpy (digest, tmp_buf, 20); + + int salt_len = tmp_len - 20; + + if (salt_len < 0) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + memcpy (salt->salt_buf, tmp_buf + 20, salt->salt_len); + + if (data.opts_type & OPTS_TYPE_ST_ADD80) + { + char *ptr = (char *) salt->salt_buf; + + ptr[salt->salt_len] = 0x80; + } + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + return (PARSER_OK); +} + +int mssql2000_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_131) || (input_len > DISPLAY_LEN_MAX_131)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_MSSQL, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_buf = input_buf + 6; + + uint salt_len = 8; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + char *hash_pos = input_buf + 6 + 8 + 40; + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + return (PARSER_OK); +} + +int mssql2005_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_132) || (input_len > DISPLAY_LEN_MAX_132)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_MSSQL, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_buf = input_buf + 6; + + uint salt_len = 8; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + char *hash_pos = input_buf + 6 + 8; + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + return (PARSER_OK); +} + +int mssql2012_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_1731) || (input_len > DISPLAY_LEN_MAX_1731)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_MSSQL2012, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + u64 *digest = (u64 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_buf = input_buf + 6; + + uint salt_len = 8; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + char *hash_pos = input_buf + 6 + 8; + + digest[0] = hex_to_u64 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u64 ((const u8 *) &hash_pos[ 16]); + digest[2] = hex_to_u64 ((const u8 *) &hash_pos[ 32]); + digest[3] = hex_to_u64 ((const u8 *) &hash_pos[ 48]); + digest[4] = hex_to_u64 ((const u8 *) &hash_pos[ 64]); + digest[5] = hex_to_u64 ((const u8 *) &hash_pos[ 80]); + digest[6] = hex_to_u64 ((const u8 *) &hash_pos[ 96]); + digest[7] = hex_to_u64 ((const u8 *) &hash_pos[112]); + + digest[0] -= SHA512M_A; + digest[1] -= SHA512M_B; + digest[2] -= SHA512M_C; + digest[3] -= SHA512M_D; + digest[4] -= SHA512M_E; + digest[5] -= SHA512M_F; + digest[6] -= SHA512M_G; + digest[7] -= SHA512M_H; + + return (PARSER_OK); +} + +int oracleh_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_3100H) || (input_len > DISPLAY_LEN_MAX_3100H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_3100) || (input_len > DISPLAY_LEN_MAX_3100)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = 0; + digest[3] = 0; + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + + if (input_buf[16] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 16 - 1; + + char *salt_buf = input_buf + 16 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int oracles_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_112) || (input_len > DISPLAY_LEN_MAX_112)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 40 - 1; + + char *salt_buf = input_buf + 40 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int oraclet_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_12300) || (input_len > DISPLAY_LEN_MAX_12300)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *hash_pos = input_buf; + + digest[ 0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[ 1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[ 2] = hex_to_u32 ((const u8 *) &hash_pos[ 16]); + digest[ 3] = hex_to_u32 ((const u8 *) &hash_pos[ 24]); + digest[ 4] = hex_to_u32 ((const u8 *) &hash_pos[ 32]); + digest[ 5] = hex_to_u32 ((const u8 *) &hash_pos[ 40]); + digest[ 6] = hex_to_u32 ((const u8 *) &hash_pos[ 48]); + digest[ 7] = hex_to_u32 ((const u8 *) &hash_pos[ 56]); + digest[ 8] = hex_to_u32 ((const u8 *) &hash_pos[ 64]); + digest[ 9] = hex_to_u32 ((const u8 *) &hash_pos[ 72]); + digest[10] = hex_to_u32 ((const u8 *) &hash_pos[ 80]); + digest[11] = hex_to_u32 ((const u8 *) &hash_pos[ 88]); + digest[12] = hex_to_u32 ((const u8 *) &hash_pos[ 96]); + digest[13] = hex_to_u32 ((const u8 *) &hash_pos[104]); + digest[14] = hex_to_u32 ((const u8 *) &hash_pos[112]); + digest[15] = hex_to_u32 ((const u8 *) &hash_pos[120]); + + char *salt_pos = input_buf + 128; + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_pos[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_pos[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &salt_pos[24]); + + salt->salt_iter = ROUNDS_ORACLET - 1; + salt->salt_len = 16; + + return (PARSER_OK); +} + +int sha256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_1400) || (input_len > DISPLAY_LEN_MAX_1400)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); + digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); + digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); + + digest[0] -= SHA256M_A; + digest[1] -= SHA256M_B; + digest[2] -= SHA256M_C; + digest[3] -= SHA256M_D; + digest[4] -= SHA256M_E; + digest[5] -= SHA256M_F; + digest[6] -= SHA256M_G; + digest[7] -= SHA256M_H; + + return (PARSER_OK); +} + +int sha256s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_1410H) || (input_len > DISPLAY_LEN_MAX_1410H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_1410) || (input_len > DISPLAY_LEN_MAX_1410)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); + digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); + digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); + + digest[0] -= SHA256M_A; + digest[1] -= SHA256M_B; + digest[2] -= SHA256M_C; + digest[3] -= SHA256M_D; + digest[4] -= SHA256M_E; + digest[5] -= SHA256M_F; + digest[6] -= SHA256M_G; + digest[7] -= SHA256M_H; + + if (input_buf[64] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 64 - 1; + + char *salt_buf = input_buf + 64 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int sha384_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_10800) || (input_len > DISPLAY_LEN_MAX_10800)) return (PARSER_GLOBAL_LENGTH); + + u64 *digest = (u64 *) hash_buf->digest; + + digest[0] = hex_to_u64 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u64 ((const u8 *) &input_buf[ 16]); + digest[2] = hex_to_u64 ((const u8 *) &input_buf[ 32]); + digest[3] = hex_to_u64 ((const u8 *) &input_buf[ 48]); + digest[4] = hex_to_u64 ((const u8 *) &input_buf[ 64]); + digest[5] = hex_to_u64 ((const u8 *) &input_buf[ 80]); + digest[6] = 0; + digest[7] = 0; + + digest[0] -= SHA384M_A; + digest[1] -= SHA384M_B; + digest[2] -= SHA384M_C; + digest[3] -= SHA384M_D; + digest[4] -= SHA384M_E; + digest[5] -= SHA384M_F; + digest[6] -= 0; + digest[7] -= 0; + + return (PARSER_OK); +} + +int sha512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_1700) || (input_len > DISPLAY_LEN_MAX_1700)) return (PARSER_GLOBAL_LENGTH); + + u64 *digest = (u64 *) hash_buf->digest; + + digest[0] = hex_to_u64 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u64 ((const u8 *) &input_buf[ 16]); + digest[2] = hex_to_u64 ((const u8 *) &input_buf[ 32]); + digest[3] = hex_to_u64 ((const u8 *) &input_buf[ 48]); + digest[4] = hex_to_u64 ((const u8 *) &input_buf[ 64]); + digest[5] = hex_to_u64 ((const u8 *) &input_buf[ 80]); + digest[6] = hex_to_u64 ((const u8 *) &input_buf[ 96]); + digest[7] = hex_to_u64 ((const u8 *) &input_buf[112]); + + digest[0] -= SHA512M_A; + digest[1] -= SHA512M_B; + digest[2] -= SHA512M_C; + digest[3] -= SHA512M_D; + digest[4] -= SHA512M_E; + digest[5] -= SHA512M_F; + digest[6] -= SHA512M_G; + digest[7] -= SHA512M_H; + + return (PARSER_OK); +} + +int sha512s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_1710H) || (input_len > DISPLAY_LEN_MAX_1710H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_1710) || (input_len > DISPLAY_LEN_MAX_1710)) return (PARSER_GLOBAL_LENGTH); + } + + u64 *digest = (u64 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u64 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u64 ((const u8 *) &input_buf[ 16]); + digest[2] = hex_to_u64 ((const u8 *) &input_buf[ 32]); + digest[3] = hex_to_u64 ((const u8 *) &input_buf[ 48]); + digest[4] = hex_to_u64 ((const u8 *) &input_buf[ 64]); + digest[5] = hex_to_u64 ((const u8 *) &input_buf[ 80]); + digest[6] = hex_to_u64 ((const u8 *) &input_buf[ 96]); + digest[7] = hex_to_u64 ((const u8 *) &input_buf[112]); + + digest[0] -= SHA512M_A; + digest[1] -= SHA512M_B; + digest[2] -= SHA512M_C; + digest[3] -= SHA512M_D; + digest[4] -= SHA512M_E; + digest[5] -= SHA512M_F; + digest[6] -= SHA512M_G; + digest[7] -= SHA512M_H; + + if (input_buf[128] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 128 - 1; + + char *salt_buf = input_buf + 128 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int sha512crypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (memcmp (SIGNATURE_SHA512CRYPT, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); + + u64 *digest = (u64 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_pos = input_buf + 3; + + uint iterations_len = 0; + + if (memcmp (salt_pos, "rounds=", 7) == 0) + { + salt_pos += 7; + + for (iterations_len = 0; salt_pos[0] >= '0' && salt_pos[0] <= '9' && iterations_len < 7; iterations_len++, salt_pos += 1) continue; + + if (iterations_len == 0 ) return (PARSER_SALT_ITERATION); + if (salt_pos[0] != '$') return (PARSER_SIGNATURE_UNMATCHED); + + salt_pos[0] = 0x0; + + salt->salt_iter = atoi (salt_pos - iterations_len); + + salt_pos += 1; + + iterations_len += 8; + } + else + { + salt->salt_iter = ROUNDS_SHA512CRYPT; + } + + if ((input_len < DISPLAY_LEN_MIN_1800) || (input_len > DISPLAY_LEN_MAX_1800 + iterations_len)) return (PARSER_GLOBAL_LENGTH); + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + if (salt_len > 16) return (PARSER_SALT_LENGTH); + + memcpy ((char *) salt->salt_buf, salt_pos, salt_len); + + salt->salt_len = salt_len; + + hash_pos++; + + sha512crypt_decode ((unsigned char *) digest, (unsigned char *) hash_pos); + + return (PARSER_OK); +} + +int keccak_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_5000) || (input_len > DISPLAY_LEN_MAX_5000)) return (PARSER_GLOBAL_LENGTH); + + if (input_len % 16) return (PARSER_GLOBAL_LENGTH); + + u64 *digest = (u64 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + uint keccak_mdlen = input_len / 2; + + for (uint i = 0; i < keccak_mdlen / 8; i++) + { + digest[i] = hex_to_u64 ((const u8 *) &input_buf[i * 16]); + + digest[i] = byte_swap_64 (digest[i]); + } + + salt->keccak_mdlen = keccak_mdlen; + + return (PARSER_OK); +} + +int ikepsk_md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_5300) || (input_len > DISPLAY_LEN_MAX_5300)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + ikepsk_t *ikepsk = (ikepsk_t *) hash_buf->esalt; + + /** + * Parse that strange long line + */ + + char *in_off[9]; + + size_t in_len[9] = { 0 }; + + in_off[0] = strtok (input_buf, ":"); + + if (in_off[0] == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + in_len[0] = strlen (in_off[0]); + + size_t i; + + for (i = 1; i < 9; i++) + { + in_off[i] = strtok (NULL, ":"); + + if (in_off[i] == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + in_len[i] = strlen (in_off[i]); + } + + char *ptr = (char *) ikepsk->msg_buf; + + for (i = 0; i < in_len[0]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[0] + i); + for (i = 0; i < in_len[1]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[1] + i); + for (i = 0; i < in_len[2]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[2] + i); + for (i = 0; i < in_len[3]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[3] + i); + for (i = 0; i < in_len[4]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[4] + i); + for (i = 0; i < in_len[5]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[5] + i); + + *ptr = 0x80; + + ikepsk->msg_len = (in_len[0] + in_len[1] + in_len[2] + in_len[3] + in_len[4] + in_len[5]) / 2; + + ptr = (char *) ikepsk->nr_buf; + + for (i = 0; i < in_len[6]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[6] + i); + for (i = 0; i < in_len[7]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[7] + i); + + *ptr = 0x80; + + ikepsk->nr_len = (in_len[6] + in_len[7]) / 2; + + /** + * Store to database + */ + + ptr = in_off[8]; + + digest[0] = hex_to_u32 ((const u8 *) &ptr[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &ptr[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &ptr[16]); + digest[3] = hex_to_u32 ((const u8 *) &ptr[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + salt->salt_len = 32; + + salt->salt_buf[0] = ikepsk->nr_buf[0]; + salt->salt_buf[1] = ikepsk->nr_buf[1]; + salt->salt_buf[2] = ikepsk->nr_buf[2]; + salt->salt_buf[3] = ikepsk->nr_buf[3]; + salt->salt_buf[4] = ikepsk->nr_buf[4]; + salt->salt_buf[5] = ikepsk->nr_buf[5]; + salt->salt_buf[6] = ikepsk->nr_buf[6]; + salt->salt_buf[7] = ikepsk->nr_buf[7]; + + return (PARSER_OK); +} + +int ikepsk_sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_5400) || (input_len > DISPLAY_LEN_MAX_5400)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + ikepsk_t *ikepsk = (ikepsk_t *) hash_buf->esalt; + + /** + * Parse that strange long line + */ + + char *in_off[9]; + + size_t in_len[9] = { 0 }; + + in_off[0] = strtok (input_buf, ":"); + + if (in_off[0] == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + in_len[0] = strlen (in_off[0]); + + size_t i; + + for (i = 1; i < 9; i++) + { + in_off[i] = strtok (NULL, ":"); + + if (in_off[i] == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + in_len[i] = strlen (in_off[i]); + } + + char *ptr = (char *) ikepsk->msg_buf; + + for (i = 0; i < in_len[0]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[0] + i); + for (i = 0; i < in_len[1]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[1] + i); + for (i = 0; i < in_len[2]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[2] + i); + for (i = 0; i < in_len[3]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[3] + i); + for (i = 0; i < in_len[4]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[4] + i); + for (i = 0; i < in_len[5]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[5] + i); + + *ptr = 0x80; + + ikepsk->msg_len = (in_len[0] + in_len[1] + in_len[2] + in_len[3] + in_len[4] + in_len[5]) / 2; + + ptr = (char *) ikepsk->nr_buf; + + for (i = 0; i < in_len[6]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[6] + i); + for (i = 0; i < in_len[7]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[7] + i); + + *ptr = 0x80; + + ikepsk->nr_len = (in_len[6] + in_len[7]) / 2; + + /** + * Store to database + */ + + ptr = in_off[8]; + + digest[0] = hex_to_u32 ((const u8 *) &ptr[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &ptr[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &ptr[16]); + digest[3] = hex_to_u32 ((const u8 *) &ptr[24]); + digest[4] = hex_to_u32 ((const u8 *) &ptr[32]); + + salt->salt_len = 32; + + salt->salt_buf[0] = ikepsk->nr_buf[0]; + salt->salt_buf[1] = ikepsk->nr_buf[1]; + salt->salt_buf[2] = ikepsk->nr_buf[2]; + salt->salt_buf[3] = ikepsk->nr_buf[3]; + salt->salt_buf[4] = ikepsk->nr_buf[4]; + salt->salt_buf[5] = ikepsk->nr_buf[5]; + salt->salt_buf[6] = ikepsk->nr_buf[6]; + salt->salt_buf[7] = ikepsk->nr_buf[7]; + + return (PARSER_OK); +} + +int ripemd160_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_6000) || (input_len > DISPLAY_LEN_MAX_6000)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + + return (PARSER_OK); +} + +int whirlpool_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_6100) || (input_len > DISPLAY_LEN_MAX_6100)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[ 0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[ 1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[ 2] = hex_to_u32 ((const u8 *) &input_buf[ 16]); + digest[ 3] = hex_to_u32 ((const u8 *) &input_buf[ 24]); + digest[ 4] = hex_to_u32 ((const u8 *) &input_buf[ 32]); + digest[ 5] = hex_to_u32 ((const u8 *) &input_buf[ 40]); + digest[ 6] = hex_to_u32 ((const u8 *) &input_buf[ 48]); + digest[ 7] = hex_to_u32 ((const u8 *) &input_buf[ 56]); + digest[ 8] = hex_to_u32 ((const u8 *) &input_buf[ 64]); + digest[ 9] = hex_to_u32 ((const u8 *) &input_buf[ 72]); + digest[10] = hex_to_u32 ((const u8 *) &input_buf[ 80]); + digest[11] = hex_to_u32 ((const u8 *) &input_buf[ 88]); + digest[12] = hex_to_u32 ((const u8 *) &input_buf[ 96]); + digest[13] = hex_to_u32 ((const u8 *) &input_buf[104]); + digest[14] = hex_to_u32 ((const u8 *) &input_buf[112]); + digest[15] = hex_to_u32 ((const u8 *) &input_buf[120]); + + return (PARSER_OK); +} + +int androidpin_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_5800) || (input_len > DISPLAY_LEN_MAX_5800)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + + if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 40 - 1; + + char *salt_buf = input_buf + 40 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + salt->salt_iter = ROUNDS_ANDROIDPIN - 1; + + return (PARSER_OK); +} + +int truecrypt_parse_hash_1k (char *input_buf, uint input_len, hash_t *hash_buf) +{ + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + tc_t *tc = (tc_t *) hash_buf->esalt; + + if (input_len == 0) + { + log_error ("TrueCrypt container not specified"); + + exit (-1); + } + + FILE *fp = fopen (input_buf, "rb"); + + if (fp == NULL) + { + log_error ("%s: %s", input_buf, strerror (errno)); + + exit (-1); + } + + char buf[512] = { 0 }; + + int n = fread (buf, 1, sizeof (buf), fp); + + fclose (fp); + + if (n != 512) return (PARSER_TC_FILE_SIZE); + + memcpy (tc->salt_buf, buf, 64); + + memcpy (tc->data_buf, buf + 64, 512 - 64); + + salt->salt_buf[0] = tc->salt_buf[0]; + + salt->salt_len = 4; + + salt->salt_iter = ROUNDS_TRUECRYPT_1K - 1; + + tc->signature = 0x45555254; // "TRUE" + + digest[0] = tc->data_buf[0]; + + return (PARSER_OK); +} + +int truecrypt_parse_hash_2k (char *input_buf, uint input_len, hash_t *hash_buf) +{ + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + tc_t *tc = (tc_t *) hash_buf->esalt; + + if (input_len == 0) + { + log_error ("TrueCrypt container not specified"); + + exit (-1); + } + + FILE *fp = fopen (input_buf, "rb"); + + if (fp == NULL) + { + log_error ("%s: %s", input_buf, strerror (errno)); + + exit (-1); + } + + char buf[512] = { 0 }; + + int n = fread (buf, 1, sizeof (buf), fp); + + fclose (fp); + + if (n != 512) return (PARSER_TC_FILE_SIZE); + + memcpy (tc->salt_buf, buf, 64); + + memcpy (tc->data_buf, buf + 64, 512 - 64); + + salt->salt_buf[0] = tc->salt_buf[0]; + + salt->salt_len = 4; + + salt->salt_iter = ROUNDS_TRUECRYPT_2K - 1; + + tc->signature = 0x45555254; // "TRUE" + + digest[0] = tc->data_buf[0]; + + return (PARSER_OK); +} + +int veracrypt_parse_hash_200000 (char *input_buf, uint input_len, hash_t *hash_buf) +{ + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + tc_t *tc = (tc_t *) hash_buf->esalt; + + if (input_len == 0) + { + log_error ("VeraCrypt container not specified"); + + exit (-1); + } + + FILE *fp = fopen (input_buf, "rb"); + + if (fp == NULL) + { + log_error ("%s: %s", input_buf, strerror (errno)); + + exit (-1); + } + + char buf[512] = { 0 }; + + int n = fread (buf, 1, sizeof (buf), fp); + + fclose (fp); + + if (n != 512) return (PARSER_VC_FILE_SIZE); + + memcpy (tc->salt_buf, buf, 64); + + memcpy (tc->data_buf, buf + 64, 512 - 64); + + salt->salt_buf[0] = tc->salt_buf[0]; + + salt->salt_len = 4; + + salt->salt_iter = ROUNDS_VERACRYPT_200000 - 1; + + tc->signature = 0x41524556; // "VERA" + + digest[0] = tc->data_buf[0]; + + return (PARSER_OK); +} + +int veracrypt_parse_hash_500000 (char *input_buf, uint input_len, hash_t *hash_buf) +{ + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + tc_t *tc = (tc_t *) hash_buf->esalt; + + if (input_len == 0) + { + log_error ("VeraCrypt container not specified"); + + exit (-1); + } + + FILE *fp = fopen (input_buf, "rb"); + + if (fp == NULL) + { + log_error ("%s: %s", input_buf, strerror (errno)); + + exit (-1); + } + + char buf[512] = { 0 }; + + int n = fread (buf, 1, sizeof (buf), fp); + + fclose (fp); + + if (n != 512) return (PARSER_VC_FILE_SIZE); + + memcpy (tc->salt_buf, buf, 64); + + memcpy (tc->data_buf, buf + 64, 512 - 64); + + salt->salt_buf[0] = tc->salt_buf[0]; + + salt->salt_len = 4; + + salt->salt_iter = ROUNDS_VERACRYPT_500000 - 1; + + tc->signature = 0x41524556; // "VERA" + + digest[0] = tc->data_buf[0]; + + return (PARSER_OK); +} + +int veracrypt_parse_hash_327661 (char *input_buf, uint input_len, hash_t *hash_buf) +{ + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + tc_t *tc = (tc_t *) hash_buf->esalt; + + if (input_len == 0) + { + log_error ("VeraCrypt container not specified"); + + exit (-1); + } + + FILE *fp = fopen (input_buf, "rb"); + + if (fp == NULL) + { + log_error ("%s: %s", input_buf, strerror (errno)); + + exit (-1); + } + + char buf[512] = { 0 }; + + int n = fread (buf, 1, sizeof (buf), fp); + + fclose (fp); + + if (n != 512) return (PARSER_VC_FILE_SIZE); + + memcpy (tc->salt_buf, buf, 64); + + memcpy (tc->data_buf, buf + 64, 512 - 64); + + salt->salt_buf[0] = tc->salt_buf[0]; + + salt->salt_len = 4; + + salt->salt_iter = ROUNDS_VERACRYPT_327661 - 1; + + tc->signature = 0x41524556; // "VERA" + + digest[0] = tc->data_buf[0]; + + return (PARSER_OK); +} + +int veracrypt_parse_hash_655331 (char *input_buf, uint input_len, hash_t *hash_buf) +{ + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + tc_t *tc = (tc_t *) hash_buf->esalt; + + if (input_len == 0) + { + log_error ("VeraCrypt container not specified"); + + exit (-1); + } + + FILE *fp = fopen (input_buf, "rb"); + + if (fp == NULL) + { + log_error ("%s: %s", input_buf, strerror (errno)); + + exit (-1); + } + + char buf[512] = { 0 }; + + int n = fread (buf, 1, sizeof (buf), fp); + + fclose (fp); + + if (n != 512) return (PARSER_VC_FILE_SIZE); + + memcpy (tc->salt_buf, buf, 64); + + memcpy (tc->data_buf, buf + 64, 512 - 64); + + salt->salt_buf[0] = tc->salt_buf[0]; + + salt->salt_len = 4; + + salt->salt_iter = ROUNDS_VERACRYPT_655331 - 1; + + tc->signature = 0x41524556; // "VERA" + + digest[0] = tc->data_buf[0]; + + return (PARSER_OK); +} + +int md5aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_6300) || (input_len > DISPLAY_LEN_MAX_6300)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_MD5AIX, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_pos = input_buf + 6; + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + if (salt_len < 8) return (PARSER_SALT_LENGTH); + + memcpy ((char *) salt->salt_buf, salt_pos, salt_len); + + salt->salt_len = salt_len; + + salt->salt_iter = 1000; + + hash_pos++; + + md5crypt_decode ((unsigned char *) digest, (unsigned char *) hash_pos); + + return (PARSER_OK); +} + +int sha1aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_6700) || (input_len > DISPLAY_LEN_MAX_6700)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SHA1AIX, input_buf, 7)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *iter_pos = input_buf + 7; + + char *salt_pos = strchr (iter_pos, '$'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + if (salt_len < 16) return (PARSER_SALT_LENGTH); + + memcpy ((char *) salt->salt_buf, salt_pos, salt_len); + + salt->salt_len = salt_len; + + char salt_iter[3] = { iter_pos[0], iter_pos[1], 0 }; + + salt->salt_sign[0] = atoi (salt_iter); + + salt->salt_iter = (1u << atoi (salt_iter)) - 1; + + hash_pos++; + + sha1aix_decode ((unsigned char *) digest, (unsigned char *) hash_pos); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + + return (PARSER_OK); +} + +int sha256aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_6400) || (input_len > DISPLAY_LEN_MAX_6400)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SHA256AIX, input_buf, 9)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *iter_pos = input_buf + 9; + + char *salt_pos = strchr (iter_pos, '$'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + if (salt_len < 16) return (PARSER_SALT_LENGTH); + + memcpy ((char *) salt->salt_buf, salt_pos, salt_len); + + salt->salt_len = salt_len; + + char salt_iter[3] = { iter_pos[0], iter_pos[1], 0 }; + + salt->salt_sign[0] = atoi (salt_iter); + + salt->salt_iter = (1u << atoi (salt_iter)) - 1; + + hash_pos++; + + sha256aix_decode ((unsigned char *) digest, (unsigned char *) hash_pos); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + digest[5] = byte_swap_32 (digest[5]); + digest[6] = byte_swap_32 (digest[6]); + digest[7] = byte_swap_32 (digest[7]); + + return (PARSER_OK); +} + +int sha512aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_6500) || (input_len > DISPLAY_LEN_MAX_6500)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SHA512AIX, input_buf, 9)) return (PARSER_SIGNATURE_UNMATCHED); + + u64 *digest = (u64 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *iter_pos = input_buf + 9; + + char *salt_pos = strchr (iter_pos, '$'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + if (salt_len < 16) return (PARSER_SALT_LENGTH); + + memcpy ((char *) salt->salt_buf, salt_pos, salt_len); + + salt->salt_len = salt_len; + + char salt_iter[3] = { iter_pos[0], iter_pos[1], 0 }; + + salt->salt_sign[0] = atoi (salt_iter); + + salt->salt_iter = (1u << atoi (salt_iter)) - 1; + + hash_pos++; + + sha512aix_decode ((unsigned char *) digest, (unsigned char *) hash_pos); + + digest[0] = byte_swap_64 (digest[0]); + digest[1] = byte_swap_64 (digest[1]); + digest[2] = byte_swap_64 (digest[2]); + digest[3] = byte_swap_64 (digest[3]); + digest[4] = byte_swap_64 (digest[4]); + digest[5] = byte_swap_64 (digest[5]); + digest[6] = byte_swap_64 (digest[6]); + digest[7] = byte_swap_64 (digest[7]); + + return (PARSER_OK); +} + +int agilekey_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_6600) || (input_len > DISPLAY_LEN_MAX_6600)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + agilekey_t *agilekey = (agilekey_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *iterations_pos = input_buf; + + char *saltbuf_pos = strchr (iterations_pos, ':'); + + if (saltbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint iterations_len = saltbuf_pos - iterations_pos; + + if (iterations_len > 6) return (PARSER_SALT_LENGTH); + + saltbuf_pos++; + + char *cipherbuf_pos = strchr (saltbuf_pos, ':'); + + if (cipherbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint saltbuf_len = cipherbuf_pos - saltbuf_pos; + + if (saltbuf_len != 16) return (PARSER_SALT_LENGTH); + + uint cipherbuf_len = input_len - iterations_len - 1 - saltbuf_len - 1; + + if (cipherbuf_len != 2080) return (PARSER_HASH_LENGTH); + + cipherbuf_pos++; + + /** + * pbkdf2 iterations + */ + + salt->salt_iter = atoi (iterations_pos) - 1; + + /** + * handle salt encoding + */ + + char *saltbuf_ptr = (char *) salt->salt_buf; + + for (uint i = 0; i < saltbuf_len; i += 2) + { + const char p0 = saltbuf_pos[i + 0]; + const char p1 = saltbuf_pos[i + 1]; + + *saltbuf_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + salt->salt_len = saltbuf_len / 2; + + /** + * handle cipher encoding + */ + + uint *tmp = (uint *) mymalloc (32); + + char *cipherbuf_ptr = (char *) tmp; + + for (uint i = 2016; i < cipherbuf_len; i += 2) + { + const char p0 = cipherbuf_pos[i + 0]; + const char p1 = cipherbuf_pos[i + 1]; + + *cipherbuf_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + // iv is stored at salt_buf 4 (length 16) + // data is stored at salt_buf 8 (length 16) + + salt->salt_buf[ 4] = byte_swap_32 (tmp[0]); + salt->salt_buf[ 5] = byte_swap_32 (tmp[1]); + salt->salt_buf[ 6] = byte_swap_32 (tmp[2]); + salt->salt_buf[ 7] = byte_swap_32 (tmp[3]); + + salt->salt_buf[ 8] = byte_swap_32 (tmp[4]); + salt->salt_buf[ 9] = byte_swap_32 (tmp[5]); + salt->salt_buf[10] = byte_swap_32 (tmp[6]); + salt->salt_buf[11] = byte_swap_32 (tmp[7]); + + myfree (tmp); + + for (uint i = 0, j = 0; i < 1040; i += 1, j += 2) + { + const char p0 = cipherbuf_pos[j + 0]; + const char p1 = cipherbuf_pos[j + 1]; + + agilekey->cipher[i] = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + /** + * digest buf + */ + + digest[0] = 0x10101010; + digest[1] = 0x10101010; + digest[2] = 0x10101010; + digest[3] = 0x10101010; + + return (PARSER_OK); +} + +int lastpass_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_6800) || (input_len > DISPLAY_LEN_MAX_6800)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *hashbuf_pos = input_buf; + + char *iterations_pos = strchr (hashbuf_pos, ':'); + + if (iterations_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint hash_len = iterations_pos - hashbuf_pos; + + if ((hash_len != 32) && (hash_len != 64)) return (PARSER_HASH_LENGTH); + + iterations_pos++; + + char *saltbuf_pos = strchr (iterations_pos, ':'); + + if (saltbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint iterations_len = saltbuf_pos - iterations_pos; + + saltbuf_pos++; + + uint salt_len = input_len - hash_len - 1 - iterations_len - 1; + + if (salt_len > 32) return (PARSER_SALT_LENGTH); + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, saltbuf_pos, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + salt->salt_iter = atoi (iterations_pos) - 1; + + digest[0] = hex_to_u32 ((const u8 *) &hashbuf_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hashbuf_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hashbuf_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hashbuf_pos[24]); + + return (PARSER_OK); +} + +int gost_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_6900) || (input_len > DISPLAY_LEN_MAX_6900)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); + digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); + digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + digest[5] = byte_swap_32 (digest[5]); + digest[6] = byte_swap_32 (digest[6]); + digest[7] = byte_swap_32 (digest[7]); + + return (PARSER_OK); +} + +int sha256crypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (memcmp (SIGNATURE_SHA256CRYPT, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_pos = input_buf + 3; + + uint iterations_len = 0; + + if (memcmp (salt_pos, "rounds=", 7) == 0) + { + salt_pos += 7; + + for (iterations_len = 0; salt_pos[0] >= '0' && salt_pos[0] <= '9' && iterations_len < 7; iterations_len++, salt_pos += 1) continue; + + if (iterations_len == 0 ) return (PARSER_SALT_ITERATION); + if (salt_pos[0] != '$') return (PARSER_SIGNATURE_UNMATCHED); + + salt_pos[0] = 0x0; + + salt->salt_iter = atoi (salt_pos - iterations_len); + + salt_pos += 1; + + iterations_len += 8; + } + else + { + salt->salt_iter = ROUNDS_SHA256CRYPT; + } + + if ((input_len < DISPLAY_LEN_MIN_7400) || (input_len > DISPLAY_LEN_MAX_7400 + iterations_len)) return (PARSER_GLOBAL_LENGTH); + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + if (salt_len > 16) return (PARSER_SALT_LENGTH); + + memcpy ((char *) salt->salt_buf, salt_pos, salt_len); + + salt->salt_len = salt_len; + + hash_pos++; + + sha256crypt_decode ((unsigned char *) digest, (unsigned char *) hash_pos); + + return (PARSER_OK); +} + +int sha512osx_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + uint max_len = DISPLAY_LEN_MAX_7100 + (2 * 128); + + if ((input_len < DISPLAY_LEN_MIN_7100) || (input_len > max_len)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SHA512OSX, input_buf, 4)) return (PARSER_SIGNATURE_UNMATCHED); + + u64 *digest = (u64 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pbkdf2_sha512_t *pbkdf2_sha512 = (pbkdf2_sha512_t *) hash_buf->esalt; + + char *iter_pos = input_buf + 4; + + char *salt_pos = strchr (iter_pos, '$'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + if (((input_len - (hash_pos - input_buf) - 1) % 128) != 0) return (PARSER_GLOBAL_LENGTH); + + hash_pos++; + + digest[0] = hex_to_u64 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u64 ((const u8 *) &hash_pos[ 16]); + digest[2] = hex_to_u64 ((const u8 *) &hash_pos[ 32]); + digest[3] = hex_to_u64 ((const u8 *) &hash_pos[ 48]); + digest[4] = hex_to_u64 ((const u8 *) &hash_pos[ 64]); + digest[5] = hex_to_u64 ((const u8 *) &hash_pos[ 80]); + digest[6] = hex_to_u64 ((const u8 *) &hash_pos[ 96]); + digest[7] = hex_to_u64 ((const u8 *) &hash_pos[112]); + + uint salt_len = hash_pos - salt_pos - 1; + + if ((salt_len % 2) != 0) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len / 2; + + pbkdf2_sha512->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[ 0]); + pbkdf2_sha512->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_pos[ 8]); + pbkdf2_sha512->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_pos[16]); + pbkdf2_sha512->salt_buf[3] = hex_to_u32 ((const u8 *) &salt_pos[24]); + pbkdf2_sha512->salt_buf[4] = hex_to_u32 ((const u8 *) &salt_pos[32]); + pbkdf2_sha512->salt_buf[5] = hex_to_u32 ((const u8 *) &salt_pos[40]); + pbkdf2_sha512->salt_buf[6] = hex_to_u32 ((const u8 *) &salt_pos[48]); + pbkdf2_sha512->salt_buf[7] = hex_to_u32 ((const u8 *) &salt_pos[56]); + + pbkdf2_sha512->salt_buf[0] = byte_swap_32 (pbkdf2_sha512->salt_buf[0]); + pbkdf2_sha512->salt_buf[1] = byte_swap_32 (pbkdf2_sha512->salt_buf[1]); + pbkdf2_sha512->salt_buf[2] = byte_swap_32 (pbkdf2_sha512->salt_buf[2]); + pbkdf2_sha512->salt_buf[3] = byte_swap_32 (pbkdf2_sha512->salt_buf[3]); + pbkdf2_sha512->salt_buf[4] = byte_swap_32 (pbkdf2_sha512->salt_buf[4]); + pbkdf2_sha512->salt_buf[5] = byte_swap_32 (pbkdf2_sha512->salt_buf[5]); + pbkdf2_sha512->salt_buf[6] = byte_swap_32 (pbkdf2_sha512->salt_buf[6]); + pbkdf2_sha512->salt_buf[7] = byte_swap_32 (pbkdf2_sha512->salt_buf[7]); + pbkdf2_sha512->salt_buf[8] = 0x01000000; + pbkdf2_sha512->salt_buf[9] = 0x80; + + salt->salt_buf[0] = pbkdf2_sha512->salt_buf[0]; + + salt->salt_iter = atoi (iter_pos) - 1; + + return (PARSER_OK); +} + +int episerver4_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_1441) || (input_len > DISPLAY_LEN_MAX_1441)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_EPISERVER4, input_buf, 14)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_pos = input_buf + 14; + + char *hash_pos = strchr (salt_pos, '*'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + hash_pos++; + + uint salt_len = hash_pos - salt_pos - 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + u8 tmp_buf[100] = { 0 }; + + base64_decode (base64_to_int, (const u8 *) hash_pos, 43, tmp_buf); + + memcpy (digest, tmp_buf, 32); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + digest[5] = byte_swap_32 (digest[5]); + digest[6] = byte_swap_32 (digest[6]); + digest[7] = byte_swap_32 (digest[7]); + + digest[0] -= SHA256M_A; + digest[1] -= SHA256M_B; + digest[2] -= SHA256M_C; + digest[3] -= SHA256M_D; + digest[4] -= SHA256M_E; + digest[5] -= SHA256M_F; + digest[6] -= SHA256M_G; + digest[7] -= SHA256M_H; + + return (PARSER_OK); +} + +int sha512grub_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + uint max_len = DISPLAY_LEN_MAX_7200 + (8 * 128); + + if ((input_len < DISPLAY_LEN_MIN_7200) || (input_len > max_len)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SHA512GRUB, input_buf, 19)) return (PARSER_SIGNATURE_UNMATCHED); + + u64 *digest = (u64 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pbkdf2_sha512_t *pbkdf2_sha512 = (pbkdf2_sha512_t *) hash_buf->esalt; + + char *iter_pos = input_buf + 19; + + char *salt_pos = strchr (iter_pos, '.'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + char *hash_pos = strchr (salt_pos, '.'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + if (((input_len - (hash_pos - input_buf) - 1) % 128) != 0) return (PARSER_GLOBAL_LENGTH); + + hash_pos++; + + digest[0] = hex_to_u64 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u64 ((const u8 *) &hash_pos[ 16]); + digest[2] = hex_to_u64 ((const u8 *) &hash_pos[ 32]); + digest[3] = hex_to_u64 ((const u8 *) &hash_pos[ 48]); + digest[4] = hex_to_u64 ((const u8 *) &hash_pos[ 64]); + digest[5] = hex_to_u64 ((const u8 *) &hash_pos[ 80]); + digest[6] = hex_to_u64 ((const u8 *) &hash_pos[ 96]); + digest[7] = hex_to_u64 ((const u8 *) &hash_pos[112]); + + uint salt_len = hash_pos - salt_pos - 1; + + salt_len /= 2; + + char *salt_buf_ptr = (char *) pbkdf2_sha512->salt_buf; + + uint i; + + for (i = 0; i < salt_len; i++) + { + salt_buf_ptr[i] = hex_to_u8 ((const u8 *) &salt_pos[i * 2]); + } + + salt_buf_ptr[salt_len + 3] = 0x01; + salt_buf_ptr[salt_len + 4] = 0x80; + + salt->salt_buf[0] = pbkdf2_sha512->salt_buf[0]; + + salt->salt_len = salt_len; + + salt->salt_iter = atoi (iter_pos) - 1; + + return (PARSER_OK); +} + +int sha512b64s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_1711) || (input_len > DISPLAY_LEN_MAX_1711)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SHA512B64S, input_buf, 9)) return (PARSER_SIGNATURE_UNMATCHED); + + u64 *digest = (u64 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + u8 tmp_buf[120] = { 0 }; + + int tmp_len = base64_decode (base64_to_int, (const u8 *) input_buf + 9, input_len - 9, tmp_buf); + + if (tmp_len < 64) return (PARSER_HASH_LENGTH); + + memcpy (digest, tmp_buf, 64); + + digest[0] = byte_swap_64 (digest[0]); + digest[1] = byte_swap_64 (digest[1]); + digest[2] = byte_swap_64 (digest[2]); + digest[3] = byte_swap_64 (digest[3]); + digest[4] = byte_swap_64 (digest[4]); + digest[5] = byte_swap_64 (digest[5]); + digest[6] = byte_swap_64 (digest[6]); + digest[7] = byte_swap_64 (digest[7]); + + digest[0] -= SHA512M_A; + digest[1] -= SHA512M_B; + digest[2] -= SHA512M_C; + digest[3] -= SHA512M_D; + digest[4] -= SHA512M_E; + digest[5] -= SHA512M_F; + digest[6] -= SHA512M_G; + digest[7] -= SHA512M_H; + + int salt_len = tmp_len - 64; + + if (salt_len < 0) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + memcpy (salt->salt_buf, tmp_buf + 64, salt->salt_len); + + if (data.opts_type & OPTS_TYPE_ST_ADD80) + { + char *ptr = (char *) salt->salt_buf; + + ptr[salt->salt_len] = 0x80; + } + + return (PARSER_OK); +} + +int hmacmd5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_50H) || (input_len > DISPLAY_LEN_MAX_50H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_50) || (input_len > DISPLAY_LEN_MAX_50)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 32 - 1; + + char *salt_buf = input_buf + 32 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int hmacsha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_150H) || (input_len > DISPLAY_LEN_MAX_150H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_150) || (input_len > DISPLAY_LEN_MAX_150)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + + if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 40 - 1; + + char *salt_buf = input_buf + 40 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int hmacsha256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_1450H) || (input_len > DISPLAY_LEN_MAX_1450H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_1450) || (input_len > DISPLAY_LEN_MAX_1450)) return (PARSER_GLOBAL_LENGTH); + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); + digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); + digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); + + if (input_buf[64] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 64 - 1; + + char *salt_buf = input_buf + 64 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int hmacsha512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (data.opts_type & OPTS_TYPE_ST_HEX) + { + if ((input_len < DISPLAY_LEN_MIN_1750H) || (input_len > DISPLAY_LEN_MAX_1750H)) return (PARSER_GLOBAL_LENGTH); + } + else + { + if ((input_len < DISPLAY_LEN_MIN_1750) || (input_len > DISPLAY_LEN_MAX_1750)) return (PARSER_GLOBAL_LENGTH); + } + + u64 *digest = (u64 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u64 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u64 ((const u8 *) &input_buf[ 16]); + digest[2] = hex_to_u64 ((const u8 *) &input_buf[ 32]); + digest[3] = hex_to_u64 ((const u8 *) &input_buf[ 48]); + digest[4] = hex_to_u64 ((const u8 *) &input_buf[ 64]); + digest[5] = hex_to_u64 ((const u8 *) &input_buf[ 80]); + digest[6] = hex_to_u64 ((const u8 *) &input_buf[ 96]); + digest[7] = hex_to_u64 ((const u8 *) &input_buf[112]); + + if (input_buf[128] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 128 - 1; + + char *salt_buf = input_buf + 128 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int krb5pa_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_7500) || (input_len > DISPLAY_LEN_MAX_7500)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_KRB5PA, input_buf, 10)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + krb5pa_t *krb5pa = (krb5pa_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *user_pos = input_buf + 10 + 1; + + char *realm_pos = strchr (user_pos, '$'); + + if (realm_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint user_len = realm_pos - user_pos; + + if (user_len >= 64) return (PARSER_SALT_LENGTH); + + realm_pos++; + + char *salt_pos = strchr (realm_pos, '$'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint realm_len = salt_pos - realm_pos; + + if (realm_len >= 64) return (PARSER_SALT_LENGTH); + + salt_pos++; + + char *data_pos = strchr (salt_pos, '$'); + + if (data_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = data_pos - salt_pos; + + if (salt_len >= 128) return (PARSER_SALT_LENGTH); + + data_pos++; + + uint data_len = input_len - 10 - 1 - user_len - 1 - realm_len - 1 - salt_len - 1; + + if (data_len != ((36 + 16) * 2)) return (PARSER_SALT_LENGTH); + + /** + * copy data + */ + + memcpy (krb5pa->user, user_pos, user_len); + memcpy (krb5pa->realm, realm_pos, realm_len); + memcpy (krb5pa->salt, salt_pos, salt_len); + + char *timestamp_ptr = (char *) krb5pa->timestamp; + + for (uint i = 0; i < (36 * 2); i += 2) + { + const char p0 = data_pos[i + 0]; + const char p1 = data_pos[i + 1]; + + *timestamp_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + char *checksum_ptr = (char *) krb5pa->checksum; + + for (uint i = (36 * 2); i < ((36 + 16) * 2); i += 2) + { + const char p0 = data_pos[i + 0]; + const char p1 = data_pos[i + 1]; + + *checksum_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + /** + * copy some data to generic buffers to make sorting happy + */ + + salt->salt_buf[0] = krb5pa->timestamp[0]; + salt->salt_buf[1] = krb5pa->timestamp[1]; + salt->salt_buf[2] = krb5pa->timestamp[2]; + salt->salt_buf[3] = krb5pa->timestamp[3]; + salt->salt_buf[4] = krb5pa->timestamp[4]; + salt->salt_buf[5] = krb5pa->timestamp[5]; + salt->salt_buf[6] = krb5pa->timestamp[6]; + salt->salt_buf[7] = krb5pa->timestamp[7]; + salt->salt_buf[8] = krb5pa->timestamp[8]; + + salt->salt_len = 36; + + digest[0] = krb5pa->checksum[0]; + digest[1] = krb5pa->checksum[1]; + digest[2] = krb5pa->checksum[2]; + digest[3] = krb5pa->checksum[3]; + + return (PARSER_OK); +} + +int sapb_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_7700) || (input_len > DISPLAY_LEN_MAX_7700)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + /** + * parse line + */ + + char *salt_pos = input_buf; + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + if (salt_len >= 40) return (PARSER_SALT_LENGTH); + + hash_pos++; + + uint hash_len = input_len - 1 - salt_len; + + if (hash_len != 16) return (PARSER_HASH_LENGTH); + + /** + * valid some data + */ + + uint user_len = 0; + + for (uint i = 0; i < salt_len; i++) + { + if (salt_pos[i] == ' ') continue; + + user_len++; + } + + // SAP user names cannot be longer than 12 characters + if (user_len > 12) return (PARSER_SALT_LENGTH); + + // SAP user name cannot start with ! or ? + if (salt_pos[0] == '!' || salt_pos[0] == '?') return (PARSER_SALT_VALUE); + + /** + * copy data + */ + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[8]); + digest[2] = 0; + digest[3] = 0; + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + + return (PARSER_OK); +} + +int sapg_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_7800) || (input_len > DISPLAY_LEN_MAX_7800)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + /** + * parse line + */ + + char *salt_pos = input_buf; + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + if (salt_len >= 40) return (PARSER_SALT_LENGTH); + + hash_pos++; + + uint hash_len = input_len - 1 - salt_len; + + if (hash_len != 40) return (PARSER_HASH_LENGTH); + + /** + * valid some data + */ + + uint user_len = 0; + + for (uint i = 0; i < salt_len; i++) + { + if (salt_pos[i] == ' ') continue; + + user_len++; + } + + // SAP user names cannot be longer than 12 characters + // this is kinda buggy. if the username is in utf the length can be up to length 12*3 + // so far nobody complained so we stay with this because it helps in optimization + // final string can have a max size of 32 (password) + (10 * 5) = lengthMagicArray + 12 (max salt) + 1 (the 0x80) + + if (user_len > 12) return (PARSER_SALT_LENGTH); + + // SAP user name cannot start with ! or ? + if (salt_pos[0] == '!' || salt_pos[0] == '?') return (PARSER_SALT_VALUE); + + /** + * copy data + */ + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); + + return (PARSER_OK); +} + +int drupal7_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_7900) || (input_len > DISPLAY_LEN_MAX_7900)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_DRUPAL7, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); + + u64 *digest = (u64 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *iter_pos = input_buf + 3; + + uint salt_iter = 1u << itoa64_to_int (iter_pos[0]); + + if (salt_iter > 0x80000000) return (PARSER_SALT_ITERATION); + + memcpy ((char *) salt->salt_sign, input_buf, 4); + + salt->salt_iter = salt_iter; + + char *salt_pos = iter_pos + 1; + + uint salt_len = 8; + + memcpy ((char *) salt->salt_buf, salt_pos, salt_len); + + salt->salt_len = salt_len; + + char *hash_pos = salt_pos + salt_len; + + drupal7_decode ((unsigned char *) digest, (unsigned char *) hash_pos); + + // ugly hack start + + char *tmp = (char *) salt->salt_buf_pc; + + tmp[0] = hash_pos[42]; + + // ugly hack end + + digest[ 0] = byte_swap_64 (digest[ 0]); + digest[ 1] = byte_swap_64 (digest[ 1]); + digest[ 2] = byte_swap_64 (digest[ 2]); + digest[ 3] = byte_swap_64 (digest[ 3]); + digest[ 4] = 0; + digest[ 5] = 0; + digest[ 6] = 0; + digest[ 7] = 0; + + return (PARSER_OK); +} + +int sybasease_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_8000) || (input_len > DISPLAY_LEN_MAX_8000)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SYBASEASE, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_buf = input_buf + 6; + + uint salt_len = 16; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + char *hash_pos = input_buf + 6 + 16; + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); + digest[5] = hex_to_u32 ((const u8 *) &hash_pos[40]); + digest[6] = hex_to_u32 ((const u8 *) &hash_pos[48]); + digest[7] = hex_to_u32 ((const u8 *) &hash_pos[56]); + + return (PARSER_OK); +} + +int mysql323_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_200) || (input_len > DISPLAY_LEN_MAX_200)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int rakp_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_7300) || (input_len > DISPLAY_LEN_MAX_7300)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + rakp_t *rakp = (rakp_t *) hash_buf->esalt; + + char *saltbuf_pos = input_buf; + + char *hashbuf_pos = strchr (saltbuf_pos, ':'); + + if (hashbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint saltbuf_len = hashbuf_pos - saltbuf_pos; + + if (saltbuf_len < 64) return (PARSER_SALT_LENGTH); + if (saltbuf_len > 512) return (PARSER_SALT_LENGTH); + + if (saltbuf_len & 1) return (PARSER_SALT_LENGTH); // muss gerade sein wegen hex + + hashbuf_pos++; + + uint hashbuf_len = input_len - saltbuf_len - 1; + + if (hashbuf_len != 40) return (PARSER_HASH_LENGTH); + + char *salt_ptr = (char *) saltbuf_pos; + char *rakp_ptr = (char *) rakp->salt_buf; + + uint i; + uint j; + + for (i = 0, j = 0; i < saltbuf_len; i += 2, j += 1) + { + rakp_ptr[j] = hex_to_u8 ((const u8 *) &salt_ptr[i]); + } + + rakp_ptr[j] = 0x80; + + rakp->salt_len = j; + + for (i = 0; i < 64; i++) + { + rakp->salt_buf[i] = byte_swap_32 (rakp->salt_buf[i]); + } + + salt->salt_buf[0] = rakp->salt_buf[0]; + salt->salt_buf[1] = rakp->salt_buf[1]; + salt->salt_buf[2] = rakp->salt_buf[2]; + salt->salt_buf[3] = rakp->salt_buf[3]; + salt->salt_buf[4] = rakp->salt_buf[4]; + salt->salt_buf[5] = rakp->salt_buf[5]; + salt->salt_buf[6] = rakp->salt_buf[6]; + salt->salt_buf[7] = rakp->salt_buf[7]; + + salt->salt_len = 32; // muss min. 32 haben + + digest[0] = hex_to_u32 ((const u8 *) &hashbuf_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hashbuf_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hashbuf_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hashbuf_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hashbuf_pos[32]); + + return (PARSER_OK); +} + +int netscaler_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_8100) || (input_len > DISPLAY_LEN_MAX_8100)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + if (memcmp (SIGNATURE_NETSCALER, input_buf, 1)) return (PARSER_SIGNATURE_UNMATCHED); + + char *salt_pos = input_buf + 1; + + memcpy (salt->salt_buf, salt_pos, 8); + + salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); + salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); + + salt->salt_len = 8; + + char *hash_pos = salt_pos + 8; + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + return (PARSER_OK); +} + +int chap_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_4800) || (input_len > DISPLAY_LEN_MAX_4800)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + char *salt_buf_ptr = input_buf + 32 + 1; + + u32 *salt_buf = salt->salt_buf; + + salt_buf[0] = hex_to_u32 ((const u8 *) &salt_buf_ptr[ 0]); + salt_buf[1] = hex_to_u32 ((const u8 *) &salt_buf_ptr[ 8]); + salt_buf[2] = hex_to_u32 ((const u8 *) &salt_buf_ptr[16]); + salt_buf[3] = hex_to_u32 ((const u8 *) &salt_buf_ptr[24]); + + salt_buf[0] = byte_swap_32 (salt_buf[0]); + salt_buf[1] = byte_swap_32 (salt_buf[1]); + salt_buf[2] = byte_swap_32 (salt_buf[2]); + salt_buf[3] = byte_swap_32 (salt_buf[3]); + + salt->salt_len = 16 + 1; + + if (input_buf[65] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + char *idbyte_buf_ptr = input_buf + 32 + 1 + 32 + 1; + + salt_buf[4] = hex_to_u8 ((const u8 *) &idbyte_buf_ptr[0]) & 0xff; + + return (PARSER_OK); +} + +int cloudkey_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_8200) || (input_len > DISPLAY_LEN_MAX_8200)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + cloudkey_t *cloudkey = (cloudkey_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *hashbuf_pos = input_buf; + + char *saltbuf_pos = strchr (hashbuf_pos, ':'); + + if (saltbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + const uint hashbuf_len = saltbuf_pos - hashbuf_pos; + + if (hashbuf_len != 64) return (PARSER_HASH_LENGTH); + + saltbuf_pos++; + + char *iteration_pos = strchr (saltbuf_pos, ':'); + + if (iteration_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + const uint saltbuf_len = iteration_pos - saltbuf_pos; + + if (saltbuf_len != 32) return (PARSER_SALT_LENGTH); + + iteration_pos++; + + char *databuf_pos = strchr (iteration_pos, ':'); + + if (databuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + const uint iteration_len = databuf_pos - iteration_pos; + + if (iteration_len < 1) return (PARSER_SALT_ITERATION); + if (iteration_len > 8) return (PARSER_SALT_ITERATION); + + const uint databuf_len = input_len - hashbuf_len - 1 - saltbuf_len - 1 - iteration_len - 1; + + if (databuf_len < 1) return (PARSER_SALT_LENGTH); + if (databuf_len > 2048) return (PARSER_SALT_LENGTH); + + databuf_pos++; + + // digest + + digest[0] = hex_to_u32 ((const u8 *) &hashbuf_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hashbuf_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hashbuf_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hashbuf_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hashbuf_pos[32]); + digest[5] = hex_to_u32 ((const u8 *) &hashbuf_pos[40]); + digest[6] = hex_to_u32 ((const u8 *) &hashbuf_pos[48]); + digest[7] = hex_to_u32 ((const u8 *) &hashbuf_pos[56]); + + // salt + + char *saltbuf_ptr = (char *) salt->salt_buf; + + for (uint i = 0; i < saltbuf_len; i += 2) + { + const char p0 = saltbuf_pos[i + 0]; + const char p1 = saltbuf_pos[i + 1]; + + *saltbuf_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + salt->salt_buf[4] = 0x01000000; + salt->salt_buf[5] = 0x80; + + salt->salt_len = saltbuf_len / 2; + + // iteration + + salt->salt_iter = atoi (iteration_pos) - 1; + + // data + + char *databuf_ptr = (char *) cloudkey->data_buf; + + for (uint i = 0; i < databuf_len; i += 2) + { + const char p0 = databuf_pos[i + 0]; + const char p1 = databuf_pos[i + 1]; + + *databuf_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + *databuf_ptr++ = 0x80; + + for (uint i = 0; i < 512; i++) + { + cloudkey->data_buf[i] = byte_swap_32 (cloudkey->data_buf[i]); + } + + cloudkey->data_len = databuf_len / 2; + + return (PARSER_OK); +} + +int nsec3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_8300) || (input_len > DISPLAY_LEN_MAX_8300)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + /** + * parse line + */ + + char *hashbuf_pos = input_buf; + + char *domainbuf_pos = strchr (hashbuf_pos, ':'); + + if (domainbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + const uint hashbuf_len = domainbuf_pos - hashbuf_pos; + + if (hashbuf_len != 32) return (PARSER_HASH_LENGTH); + + domainbuf_pos++; + + if (domainbuf_pos[0] != '.') return (PARSER_SALT_VALUE); + + char *saltbuf_pos = strchr (domainbuf_pos, ':'); + + if (saltbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + const uint domainbuf_len = saltbuf_pos - domainbuf_pos; + + if (domainbuf_len >= 32) return (PARSER_SALT_LENGTH); + + saltbuf_pos++; + + char *iteration_pos = strchr (saltbuf_pos, ':'); + + if (iteration_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + const uint saltbuf_len = iteration_pos - saltbuf_pos; + + if (saltbuf_len >= 28) return (PARSER_SALT_LENGTH); // 28 = 32 - 4; 4 = length + + if ((domainbuf_len + saltbuf_len) >= 48) return (PARSER_SALT_LENGTH); + + iteration_pos++; + + const uint iteration_len = input_len - hashbuf_len - 1 - domainbuf_len - 1 - saltbuf_len - 1; + + if (iteration_len < 1) return (PARSER_SALT_ITERATION); + if (iteration_len > 5) return (PARSER_SALT_ITERATION); + + // ok, the plan for this algorithm is the following: + // we have 2 salts here, the domain-name and a random salt + // while both are used in the initial transformation, + // only the random salt is used in the following iterations + // so we create two buffer, one that includes domain-name (stored into salt_buf_pc[]) + // and one that includes only the real salt (stored into salt_buf[]). + // the domain-name length is put into array position 7 of salt_buf_pc[] since there is not salt_pc_len + + u8 tmp_buf[100] = { 0 }; + + base32_decode (itoa32_to_int, (const u8 *) hashbuf_pos, 32, tmp_buf); + + memcpy (digest, tmp_buf, 20); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + + // domain + + char *salt_buf_pc_ptr = (char *) salt->salt_buf_pc; + + memcpy (salt_buf_pc_ptr, domainbuf_pos, domainbuf_len); + + char *len_ptr = NULL; + + for (uint i = 0; i < domainbuf_len; i++) + { + if (salt_buf_pc_ptr[i] == '.') + { + len_ptr = &salt_buf_pc_ptr[i]; + + *len_ptr = 0; + } + else + { + *len_ptr += 1; + } + } + + salt->salt_buf_pc[7] = domainbuf_len; + + // "real" salt + + char *salt_buf_ptr = (char *) salt->salt_buf; + + const uint salt_len = parse_and_store_salt (salt_buf_ptr, saltbuf_pos, saltbuf_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + // iteration + + salt->salt_iter = atoi (iteration_pos); + + return (PARSER_OK); +} + +int wbb3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_8400) || (input_len > DISPLAY_LEN_MAX_8400)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + + if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 40 - 1; + + char *salt_buf = input_buf + 40 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int opencart_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_13900) || (input_len > DISPLAY_LEN_MAX_13900)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + + if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 40 - 1; + + char *salt_buf = input_buf + 40 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if ((salt_len != 9) || (salt_len == UINT_MAX)) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int racf_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + const u8 ascii_to_ebcdic[] = + { + 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, + 0x40, 0x4f, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, + 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, + 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0x4a, 0xe0, 0x5a, 0x5f, 0x6d, + 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, + 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xc0, 0x6a, 0xd0, 0xa1, 0x07, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x15, 0x06, 0x17, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x1b, + 0x30, 0x31, 0x1a, 0x33, 0x34, 0x35, 0x36, 0x08, 0x38, 0x39, 0x3a, 0x3b, 0x04, 0x14, 0x3e, 0xe1, + 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, + 0x76, 0x77, 0x78, 0x80, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, + 0x9f, 0xa0, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xda, 0xdb, + 0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, + }; + + if ((input_len < DISPLAY_LEN_MIN_8500) || (input_len > DISPLAY_LEN_MAX_8500)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_RACF, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_pos = input_buf + 6 + 1; + + char *digest_pos = strchr (salt_pos, '*'); + + if (digest_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = digest_pos - salt_pos; + + if (salt_len > 8) return (PARSER_SALT_LENGTH); + + uint hash_len = input_len - 1 - salt_len - 1 - 6; + + if (hash_len != 16) return (PARSER_HASH_LENGTH); + + digest_pos++; + + char *salt_buf_ptr = (char *) salt->salt_buf; + char *salt_buf_pc_ptr = (char *) salt->salt_buf_pc; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + for (uint i = 0; i < salt_len; i++) + { + salt_buf_pc_ptr[i] = ascii_to_ebcdic[(int) salt_buf_ptr[i]]; + } + for (uint i = salt_len; i < 8; i++) + { + salt_buf_pc_ptr[i] = 0x40; + } + + uint tt; + + IP (salt->salt_buf_pc[0], salt->salt_buf_pc[1], tt); + + salt->salt_buf_pc[0] = rotl32 (salt->salt_buf_pc[0], 3u); + salt->salt_buf_pc[1] = rotl32 (salt->salt_buf_pc[1], 3u); + + digest[0] = hex_to_u32 ((const u8 *) &digest_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &digest_pos[ 8]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + + IP (digest[0], digest[1], tt); + + digest[0] = rotr32 (digest[0], 29); + digest[1] = rotr32 (digest[1], 29); + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int des_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_14000) || (input_len > DISPLAY_LEN_MAX_14000)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *digest_pos = input_buf; + + char *salt_pos = strchr (digest_pos, ':'); + + if (input_buf[16] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = salt_pos - digest_pos; + + if (salt_len != 16) return (PARSER_SALT_LENGTH); + + uint hash_len = input_len - 1 - salt_len; + + if (hash_len != 16) return (PARSER_HASH_LENGTH); + + salt_pos++; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + uint tt; + + salt->salt_buf_pc[0] = byte_swap_32 (salt->salt_buf[0]); + salt->salt_buf_pc[1] = byte_swap_32 (salt->salt_buf[1]); + + IP (salt->salt_buf_pc[0], salt->salt_buf_pc[1], tt); + + digest[0] = hex_to_u32 ((const u8 *) &digest_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &digest_pos[ 8]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + + IP (digest[0], digest[1], tt); + + digest[0] = digest[0]; + digest[1] = digest[1]; + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int lotus5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_8600) || (input_len > DISPLAY_LEN_MAX_8600)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + return (PARSER_OK); +} + +int lotus6_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_8700) || (input_len > DISPLAY_LEN_MAX_8700)) return (PARSER_GLOBAL_LENGTH); + + if ((input_buf[0] != '(') || (input_buf[1] != 'G') || (input_buf[21] != ')')) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + u8 tmp_buf[120] = { 0 }; + + base64_decode (lotus64_to_int, (const u8 *) input_buf + 2, input_len - 3, tmp_buf); + + tmp_buf[3] += -4; // dont ask! + + memcpy (salt->salt_buf, tmp_buf, 5); + + salt->salt_len = 5; + + memcpy (digest, tmp_buf + 5, 9); + + // yes, only 9 byte are needed to crack, but 10 to display + + salt->salt_buf_pc[7] = input_buf[20]; + + return (PARSER_OK); +} + +int lotus8_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_9100) || (input_len > DISPLAY_LEN_MAX_9100)) return (PARSER_GLOBAL_LENGTH); + + if ((input_buf[0] != '(') || (input_buf[1] != 'H') || (input_buf[DISPLAY_LEN_MAX_9100 - 1] != ')')) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + u8 tmp_buf[120] = { 0 }; + + base64_decode (lotus64_to_int, (const u8 *) input_buf + 2, input_len - 3, tmp_buf); + + tmp_buf[3] += -4; // dont ask! + + // salt + + memcpy (salt->salt_buf, tmp_buf, 16); + + salt->salt_len = 16; // Attention: in theory we have 2 salt_len, one for the -m 8700 part (len: 8), 2nd for the 9100 part (len: 16) + + // iteration + + char tmp_iter_buf[11] = { 0 }; + + memcpy (tmp_iter_buf, tmp_buf + 16, 10); + + tmp_iter_buf[10] = 0; + + salt->salt_iter = atoi (tmp_iter_buf); + + if (salt->salt_iter < 1) // well, the limit hopefully is much higher + { + return (PARSER_SALT_ITERATION); + } + + salt->salt_iter--; // first round in init + + // 2 additional bytes for display only + + salt->salt_buf_pc[0] = tmp_buf[26]; + salt->salt_buf_pc[1] = tmp_buf[27]; + + // digest + + memcpy (digest, tmp_buf + 28, 8); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int hmailserver_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_1421) || (input_len > DISPLAY_LEN_MAX_1421)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_buf_pos = input_buf; + + char *hash_buf_pos = salt_buf_pos + 6; + + digest[0] = hex_to_u32 ((const u8 *) &hash_buf_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_buf_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_buf_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_buf_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hash_buf_pos[32]); + digest[5] = hex_to_u32 ((const u8 *) &hash_buf_pos[40]); + digest[6] = hex_to_u32 ((const u8 *) &hash_buf_pos[48]); + digest[7] = hex_to_u32 ((const u8 *) &hash_buf_pos[56]); + + digest[0] -= SHA256M_A; + digest[1] -= SHA256M_B; + digest[2] -= SHA256M_C; + digest[3] -= SHA256M_D; + digest[4] -= SHA256M_E; + digest[5] -= SHA256M_F; + digest[6] -= SHA256M_G; + digest[7] -= SHA256M_H; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + const uint salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf_pos, 6); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int phps_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_2612) || (input_len > DISPLAY_LEN_MAX_2612)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + if (memcmp (SIGNATURE_PHPS, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + salt_t *salt = hash_buf->salt; + + char *salt_buf = input_buf + 6; + + char *digest_buf = strchr (salt_buf, '$'); + + if (digest_buf == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = digest_buf - salt_buf; + + digest_buf++; // skip the '$' symbol + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + digest[0] = hex_to_u32 ((const u8 *) &digest_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &digest_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &digest_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &digest_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + return (PARSER_OK); +} + +int mediawiki_b_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_3711) || (input_len > DISPLAY_LEN_MAX_3711)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_MEDIAWIKI_B, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_buf = input_buf + 3; + + char *digest_buf = strchr (salt_buf, '$'); + + if (digest_buf == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = digest_buf - salt_buf; + + digest_buf++; // skip the '$' symbol + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt_buf_ptr[salt_len] = 0x2d; + + salt->salt_len = salt_len + 1; + + digest[0] = hex_to_u32 ((const u8 *) &digest_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &digest_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &digest_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &digest_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + return (PARSER_OK); +} + +int peoplesoft_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_133) || (input_len > DISPLAY_LEN_MAX_133)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + u8 tmp_buf[100] = { 0 }; + + base64_decode (base64_to_int, (const u8 *) input_buf, input_len, tmp_buf); + + memcpy (digest, tmp_buf, 20); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + salt->salt_buf[0] = 0x80; + + salt->salt_len = 0; + + return (PARSER_OK); +} + +int skype_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_23) || (input_len > DISPLAY_LEN_MAX_23)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + if (input_buf[32] != ':') return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 32 - 1; + + char *salt_buf = input_buf + 32 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + /* + * add static "salt" part + */ + + memcpy (salt_buf_ptr + salt_len, "\nskyper\n", 8); + + salt_len += 8; + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int androidfde_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_8800) || (input_len > DISPLAY_LEN_MAX_8800)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_ANDROIDFDE, input_buf, 5)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + androidfde_t *androidfde = (androidfde_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *saltlen_pos = input_buf + 1 + 3 + 1; + + char *saltbuf_pos = strchr (saltlen_pos, '$'); + + if (saltbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint saltlen_len = saltbuf_pos - saltlen_pos; + + if (saltlen_len != 2) return (PARSER_SALT_LENGTH); + + saltbuf_pos++; + + char *keylen_pos = strchr (saltbuf_pos, '$'); + + if (keylen_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint saltbuf_len = keylen_pos - saltbuf_pos; + + if (saltbuf_len != 32) return (PARSER_SALT_LENGTH); + + keylen_pos++; + + char *keybuf_pos = strchr (keylen_pos, '$'); + + if (keybuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint keylen_len = keybuf_pos - keylen_pos; + + if (keylen_len != 2) return (PARSER_SALT_LENGTH); + + keybuf_pos++; + + char *databuf_pos = strchr (keybuf_pos, '$'); + + if (databuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint keybuf_len = databuf_pos - keybuf_pos; + + if (keybuf_len != 32) return (PARSER_SALT_LENGTH); + + databuf_pos++; + + uint data_len = input_len - 1 - 3 - 1 - saltlen_len - 1 - saltbuf_len - 1 - keylen_len - 1 - keybuf_len - 1; + + if (data_len != 3072) return (PARSER_SALT_LENGTH); + + /** + * copy data + */ + + digest[0] = hex_to_u32 ((const u8 *) &keybuf_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &keybuf_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &keybuf_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &keybuf_pos[24]); + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &saltbuf_pos[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &saltbuf_pos[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &saltbuf_pos[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &saltbuf_pos[24]); + + salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); + salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); + salt->salt_buf[2] = byte_swap_32 (salt->salt_buf[2]); + salt->salt_buf[3] = byte_swap_32 (salt->salt_buf[3]); + + salt->salt_len = 16; + salt->salt_iter = ROUNDS_ANDROIDFDE - 1; + + for (uint i = 0, j = 0; i < 3072; i += 8, j += 1) + { + androidfde->data[j] = hex_to_u32 ((const u8 *) &databuf_pos[i]); + } + + return (PARSER_OK); +} + +int scrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_8900) || (input_len > DISPLAY_LEN_MAX_8900)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SCRYPT, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + /** + * parse line + */ + + // first is the N salt parameter + + char *N_pos = input_buf + 6; + + if (N_pos[0] != ':') return (PARSER_SEPARATOR_UNMATCHED); + + N_pos++; + + salt->scrypt_N = atoi (N_pos); + + // r + + char *r_pos = strchr (N_pos, ':'); + + if (r_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + r_pos++; + + salt->scrypt_r = atoi (r_pos); + + // p + + char *p_pos = strchr (r_pos, ':'); + + if (p_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + p_pos++; + + salt->scrypt_p = atoi (p_pos); + + // salt + + char *saltbuf_pos = strchr (p_pos, ':'); + + if (saltbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + saltbuf_pos++; + + char *hash_pos = strchr (saltbuf_pos, ':'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + hash_pos++; + + // base64 decode + + int salt_len_base64 = hash_pos - saltbuf_pos; + + if (salt_len_base64 > 45) return (PARSER_SALT_LENGTH); + + u8 tmp_buf[33] = { 0 }; + + int tmp_len = base64_decode (base64_to_int, (const u8 *) saltbuf_pos, salt_len_base64, tmp_buf); + + char *salt_buf_ptr = (char *) salt->salt_buf; + + memcpy (salt_buf_ptr, tmp_buf, tmp_len); + + salt->salt_len = tmp_len; + salt->salt_iter = 1; + + // digest - base64 decode + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + tmp_len = input_len - (hash_pos - input_buf); + + if (tmp_len != 44) return (PARSER_GLOBAL_LENGTH); + + base64_decode (base64_to_int, (const u8 *) hash_pos, tmp_len, tmp_buf); + + memcpy (digest, tmp_buf, 32); + + return (PARSER_OK); +} + +int juniper_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_501) || (input_len > DISPLAY_LEN_MAX_501)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + /** + * parse line + */ + + char decrypted[76] = { 0 }; // iv + hash + + juniper_decrypt_hash (input_buf, decrypted); + + char *md5crypt_hash = decrypted + 12; + + if (memcmp (md5crypt_hash, "$1$danastre$", 12)) return (PARSER_SALT_VALUE); + + salt->salt_iter = ROUNDS_MD5CRYPT; + + char *salt_pos = md5crypt_hash + 3; + + char *hash_pos = strchr (salt_pos, '$'); // or simply salt_pos + 8 + + salt->salt_len = hash_pos - salt_pos; // should be 8 + + memcpy ((char *) salt->salt_buf, salt_pos, salt->salt_len); + + hash_pos++; + + md5crypt_decode ((unsigned char *) digest, (unsigned char *) hash_pos); + + return (PARSER_OK); +} + +int cisco8_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_9200) || (input_len > DISPLAY_LEN_MAX_9200)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_CISCO8, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pbkdf2_sha256_t *pbkdf2_sha256 = (pbkdf2_sha256_t *) hash_buf->esalt; + + /** + * parse line + */ + + // first is *raw* salt + + char *salt_pos = input_buf + 3; + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + if (salt_len != 14) return (PARSER_SALT_LENGTH); + + hash_pos++; + + char *salt_buf_ptr = (char *) pbkdf2_sha256->salt_buf; + + memcpy (salt_buf_ptr, salt_pos, 14); + + salt_buf_ptr[17] = 0x01; + salt_buf_ptr[18] = 0x80; + + // add some stuff to normal salt to make sorted happy + + salt->salt_buf[0] = pbkdf2_sha256->salt_buf[0]; + salt->salt_buf[1] = pbkdf2_sha256->salt_buf[1]; + salt->salt_buf[2] = pbkdf2_sha256->salt_buf[2]; + salt->salt_buf[3] = pbkdf2_sha256->salt_buf[3]; + + salt->salt_len = salt_len; + salt->salt_iter = ROUNDS_CISCO8 - 1; + + // base64 decode hash + + u8 tmp_buf[100] = { 0 }; + + uint hash_len = input_len - 3 - salt_len - 1; + + int tmp_len = base64_decode (itoa64_to_int, (const u8 *) hash_pos, hash_len, tmp_buf); + + if (tmp_len != 32) return (PARSER_HASH_LENGTH); + + memcpy (digest, tmp_buf, 32); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + digest[5] = byte_swap_32 (digest[5]); + digest[6] = byte_swap_32 (digest[6]); + digest[7] = byte_swap_32 (digest[7]); + + return (PARSER_OK); +} + +int cisco9_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_9300) || (input_len > DISPLAY_LEN_MAX_9300)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_CISCO9, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + /** + * parse line + */ + + // first is *raw* salt + + char *salt_pos = input_buf + 3; + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + if (salt_len != 14) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + hash_pos++; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + memcpy (salt_buf_ptr, salt_pos, salt_len); + salt_buf_ptr[salt_len] = 0; + + // base64 decode hash + + u8 tmp_buf[100] = { 0 }; + + uint hash_len = input_len - 3 - salt_len - 1; + + int tmp_len = base64_decode (itoa64_to_int, (const u8 *) hash_pos, hash_len, tmp_buf); + + if (tmp_len != 32) return (PARSER_HASH_LENGTH); + + memcpy (digest, tmp_buf, 32); + + // fixed: + salt->scrypt_N = 16384; + salt->scrypt_r = 1; + salt->scrypt_p = 1; + salt->salt_iter = 1; + + return (PARSER_OK); +} + +int office2007_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_9400) || (input_len > DISPLAY_LEN_MAX_9400)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_OFFICE2007, input_buf, 8)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + office2007_t *office2007 = (office2007_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *version_pos = input_buf + 8 + 1; + + char *verifierHashSize_pos = strchr (version_pos, '*'); + + if (verifierHashSize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 version_len = verifierHashSize_pos - version_pos; + + if (version_len != 4) return (PARSER_SALT_LENGTH); + + verifierHashSize_pos++; + + char *keySize_pos = strchr (verifierHashSize_pos, '*'); + + if (keySize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 verifierHashSize_len = keySize_pos - verifierHashSize_pos; + + if (verifierHashSize_len != 2) return (PARSER_SALT_LENGTH); + + keySize_pos++; + + char *saltSize_pos = strchr (keySize_pos, '*'); + + if (saltSize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 keySize_len = saltSize_pos - keySize_pos; + + if (keySize_len != 3) return (PARSER_SALT_LENGTH); + + saltSize_pos++; + + char *osalt_pos = strchr (saltSize_pos, '*'); + + if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 saltSize_len = osalt_pos - saltSize_pos; + + if (saltSize_len != 2) return (PARSER_SALT_LENGTH); + + osalt_pos++; + + char *encryptedVerifier_pos = strchr (osalt_pos, '*'); + + if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 osalt_len = encryptedVerifier_pos - osalt_pos; + + if (osalt_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifier_pos++; + + char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); + + if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; + + if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifierHash_pos++; + + u32 encryptedVerifierHash_len = input_len - 8 - 1 - version_len - 1 - verifierHashSize_len - 1 - keySize_len - 1 - saltSize_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1; + + if (encryptedVerifierHash_len != 40) return (PARSER_SALT_LENGTH); + + const uint version = atoi (version_pos); + + if (version != 2007) return (PARSER_SALT_VALUE); + + const uint verifierHashSize = atoi (verifierHashSize_pos); + + if (verifierHashSize != 20) return (PARSER_SALT_VALUE); + + const uint keySize = atoi (keySize_pos); + + if ((keySize != 128) && (keySize != 256)) return (PARSER_SALT_VALUE); + + office2007->keySize = keySize; + + const uint saltSize = atoi (saltSize_pos); + + if (saltSize != 16) return (PARSER_SALT_VALUE); + + /** + * salt + */ + + salt->salt_len = 16; + salt->salt_iter = ROUNDS_OFFICE2007; + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); + + /** + * esalt + */ + + office2007->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); + office2007->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); + office2007->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); + office2007->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); + + office2007->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); + office2007->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); + office2007->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); + office2007->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); + office2007->encryptedVerifierHash[4] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[32]); + + /** + * digest + */ + + digest[0] = office2007->encryptedVerifierHash[0]; + digest[1] = office2007->encryptedVerifierHash[1]; + digest[2] = office2007->encryptedVerifierHash[2]; + digest[3] = office2007->encryptedVerifierHash[3]; + + return (PARSER_OK); +} + +int office2010_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_9500) || (input_len > DISPLAY_LEN_MAX_9500)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_OFFICE2010, input_buf, 8)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + office2010_t *office2010 = (office2010_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *version_pos = input_buf + 8 + 1; + + char *spinCount_pos = strchr (version_pos, '*'); + + if (spinCount_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 version_len = spinCount_pos - version_pos; + + if (version_len != 4) return (PARSER_SALT_LENGTH); + + spinCount_pos++; + + char *keySize_pos = strchr (spinCount_pos, '*'); + + if (keySize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 spinCount_len = keySize_pos - spinCount_pos; + + if (spinCount_len != 6) return (PARSER_SALT_LENGTH); + + keySize_pos++; + + char *saltSize_pos = strchr (keySize_pos, '*'); + + if (saltSize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 keySize_len = saltSize_pos - keySize_pos; + + if (keySize_len != 3) return (PARSER_SALT_LENGTH); + + saltSize_pos++; + + char *osalt_pos = strchr (saltSize_pos, '*'); + + if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 saltSize_len = osalt_pos - saltSize_pos; + + if (saltSize_len != 2) return (PARSER_SALT_LENGTH); + + osalt_pos++; + + char *encryptedVerifier_pos = strchr (osalt_pos, '*'); + + if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 osalt_len = encryptedVerifier_pos - osalt_pos; + + if (osalt_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifier_pos++; + + char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); + + if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; + + if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifierHash_pos++; + + u32 encryptedVerifierHash_len = input_len - 8 - 1 - version_len - 1 - spinCount_len - 1 - keySize_len - 1 - saltSize_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1; + + if (encryptedVerifierHash_len != 64) return (PARSER_SALT_LENGTH); + + const uint version = atoi (version_pos); + + if (version != 2010) return (PARSER_SALT_VALUE); + + const uint spinCount = atoi (spinCount_pos); + + if (spinCount != 100000) return (PARSER_SALT_VALUE); + + const uint keySize = atoi (keySize_pos); + + if (keySize != 128) return (PARSER_SALT_VALUE); + + const uint saltSize = atoi (saltSize_pos); + + if (saltSize != 16) return (PARSER_SALT_VALUE); + + /** + * salt + */ + + salt->salt_len = 16; + salt->salt_iter = spinCount; + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); + + /** + * esalt + */ + + office2010->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); + office2010->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); + office2010->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); + office2010->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); + + office2010->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); + office2010->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); + office2010->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); + office2010->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); + office2010->encryptedVerifierHash[4] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[32]); + office2010->encryptedVerifierHash[5] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[40]); + office2010->encryptedVerifierHash[6] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[48]); + office2010->encryptedVerifierHash[7] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[56]); + + /** + * digest + */ + + digest[0] = office2010->encryptedVerifierHash[0]; + digest[1] = office2010->encryptedVerifierHash[1]; + digest[2] = office2010->encryptedVerifierHash[2]; + digest[3] = office2010->encryptedVerifierHash[3]; + + return (PARSER_OK); +} + +int office2013_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_9600) || (input_len > DISPLAY_LEN_MAX_9600)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_OFFICE2013, input_buf, 8)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + office2013_t *office2013 = (office2013_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *version_pos = input_buf + 8 + 1; + + char *spinCount_pos = strchr (version_pos, '*'); + + if (spinCount_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 version_len = spinCount_pos - version_pos; + + if (version_len != 4) return (PARSER_SALT_LENGTH); + + spinCount_pos++; + + char *keySize_pos = strchr (spinCount_pos, '*'); + + if (keySize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 spinCount_len = keySize_pos - spinCount_pos; + + if (spinCount_len != 6) return (PARSER_SALT_LENGTH); + + keySize_pos++; + + char *saltSize_pos = strchr (keySize_pos, '*'); + + if (saltSize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 keySize_len = saltSize_pos - keySize_pos; + + if (keySize_len != 3) return (PARSER_SALT_LENGTH); + + saltSize_pos++; + + char *osalt_pos = strchr (saltSize_pos, '*'); + + if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 saltSize_len = osalt_pos - saltSize_pos; + + if (saltSize_len != 2) return (PARSER_SALT_LENGTH); + + osalt_pos++; + + char *encryptedVerifier_pos = strchr (osalt_pos, '*'); + + if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 osalt_len = encryptedVerifier_pos - osalt_pos; + + if (osalt_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifier_pos++; + + char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); + + if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; + + if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifierHash_pos++; + + u32 encryptedVerifierHash_len = input_len - 8 - 1 - version_len - 1 - spinCount_len - 1 - keySize_len - 1 - saltSize_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1; + + if (encryptedVerifierHash_len != 64) return (PARSER_SALT_LENGTH); + + const uint version = atoi (version_pos); + + if (version != 2013) return (PARSER_SALT_VALUE); + + const uint spinCount = atoi (spinCount_pos); + + if (spinCount != 100000) return (PARSER_SALT_VALUE); + + const uint keySize = atoi (keySize_pos); + + if (keySize != 256) return (PARSER_SALT_VALUE); + + const uint saltSize = atoi (saltSize_pos); + + if (saltSize != 16) return (PARSER_SALT_VALUE); + + /** + * salt + */ + + salt->salt_len = 16; + salt->salt_iter = spinCount; + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); + + /** + * esalt + */ + + office2013->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); + office2013->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); + office2013->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); + office2013->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); + + office2013->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); + office2013->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); + office2013->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); + office2013->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); + office2013->encryptedVerifierHash[4] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[32]); + office2013->encryptedVerifierHash[5] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[40]); + office2013->encryptedVerifierHash[6] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[48]); + office2013->encryptedVerifierHash[7] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[56]); + + /** + * digest + */ + + digest[0] = office2013->encryptedVerifierHash[0]; + digest[1] = office2013->encryptedVerifierHash[1]; + digest[2] = office2013->encryptedVerifierHash[2]; + digest[3] = office2013->encryptedVerifierHash[3]; + + return (PARSER_OK); +} + +int oldoffice01_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_9700) || (input_len > DISPLAY_LEN_MAX_9700)) return (PARSER_GLOBAL_LENGTH); + + if ((memcmp (SIGNATURE_OLDOFFICE0, input_buf, 12)) && (memcmp (SIGNATURE_OLDOFFICE1, input_buf, 12))) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + oldoffice01_t *oldoffice01 = (oldoffice01_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *version_pos = input_buf + 11; + + char *osalt_pos = strchr (version_pos, '*'); + + if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 version_len = osalt_pos - version_pos; + + if (version_len != 1) return (PARSER_SALT_LENGTH); + + osalt_pos++; + + char *encryptedVerifier_pos = strchr (osalt_pos, '*'); + + if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 osalt_len = encryptedVerifier_pos - osalt_pos; + + if (osalt_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifier_pos++; + + char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); + + if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; + + if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifierHash_pos++; + + u32 encryptedVerifierHash_len = input_len - 11 - version_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1; + + if (encryptedVerifierHash_len != 32) return (PARSER_SALT_LENGTH); + + const uint version = *version_pos - 0x30; + + if (version != 0 && version != 1) return (PARSER_SALT_VALUE); + + /** + * esalt + */ + + oldoffice01->version = version; + + oldoffice01->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); + oldoffice01->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); + oldoffice01->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); + oldoffice01->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); + + oldoffice01->encryptedVerifier[0] = byte_swap_32 (oldoffice01->encryptedVerifier[0]); + oldoffice01->encryptedVerifier[1] = byte_swap_32 (oldoffice01->encryptedVerifier[1]); + oldoffice01->encryptedVerifier[2] = byte_swap_32 (oldoffice01->encryptedVerifier[2]); + oldoffice01->encryptedVerifier[3] = byte_swap_32 (oldoffice01->encryptedVerifier[3]); + + oldoffice01->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); + oldoffice01->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); + oldoffice01->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); + oldoffice01->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); + + oldoffice01->encryptedVerifierHash[0] = byte_swap_32 (oldoffice01->encryptedVerifierHash[0]); + oldoffice01->encryptedVerifierHash[1] = byte_swap_32 (oldoffice01->encryptedVerifierHash[1]); + oldoffice01->encryptedVerifierHash[2] = byte_swap_32 (oldoffice01->encryptedVerifierHash[2]); + oldoffice01->encryptedVerifierHash[3] = byte_swap_32 (oldoffice01->encryptedVerifierHash[3]); + + /** + * salt + */ + + salt->salt_len = 16; + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); + + salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); + salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); + salt->salt_buf[2] = byte_swap_32 (salt->salt_buf[2]); + salt->salt_buf[3] = byte_swap_32 (salt->salt_buf[3]); + + // this is a workaround as office produces multiple documents with the same salt + + salt->salt_len += 32; + + salt->salt_buf[ 4] = oldoffice01->encryptedVerifier[0]; + salt->salt_buf[ 5] = oldoffice01->encryptedVerifier[1]; + salt->salt_buf[ 6] = oldoffice01->encryptedVerifier[2]; + salt->salt_buf[ 7] = oldoffice01->encryptedVerifier[3]; + salt->salt_buf[ 8] = oldoffice01->encryptedVerifierHash[0]; + salt->salt_buf[ 9] = oldoffice01->encryptedVerifierHash[1]; + salt->salt_buf[10] = oldoffice01->encryptedVerifierHash[2]; + salt->salt_buf[11] = oldoffice01->encryptedVerifierHash[3]; + + /** + * digest + */ + + digest[0] = oldoffice01->encryptedVerifierHash[0]; + digest[1] = oldoffice01->encryptedVerifierHash[1]; + digest[2] = oldoffice01->encryptedVerifierHash[2]; + digest[3] = oldoffice01->encryptedVerifierHash[3]; + + return (PARSER_OK); +} + +int oldoffice01cm1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + return oldoffice01_parse_hash (input_buf, input_len, hash_buf); +} + +int oldoffice01cm2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_9720) || (input_len > DISPLAY_LEN_MAX_9720)) return (PARSER_GLOBAL_LENGTH); + + if ((memcmp (SIGNATURE_OLDOFFICE0, input_buf, 12)) && (memcmp (SIGNATURE_OLDOFFICE1, input_buf, 12))) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + oldoffice01_t *oldoffice01 = (oldoffice01_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *version_pos = input_buf + 11; + + char *osalt_pos = strchr (version_pos, '*'); + + if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 version_len = osalt_pos - version_pos; + + if (version_len != 1) return (PARSER_SALT_LENGTH); + + osalt_pos++; + + char *encryptedVerifier_pos = strchr (osalt_pos, '*'); + + if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 osalt_len = encryptedVerifier_pos - osalt_pos; + + if (osalt_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifier_pos++; + + char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); + + if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; + + if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifierHash_pos++; + + char *rc4key_pos = strchr (encryptedVerifierHash_pos, ':'); + + if (rc4key_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 encryptedVerifierHash_len = rc4key_pos - encryptedVerifierHash_pos; + + if (encryptedVerifierHash_len != 32) return (PARSER_SALT_LENGTH); + + rc4key_pos++; + + u32 rc4key_len = input_len - 11 - version_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1 - encryptedVerifierHash_len - 1; + + if (rc4key_len != 10) return (PARSER_SALT_LENGTH); + + const uint version = *version_pos - 0x30; + + if (version != 0 && version != 1) return (PARSER_SALT_VALUE); + + /** + * esalt + */ + + oldoffice01->version = version; + + oldoffice01->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); + oldoffice01->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); + oldoffice01->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); + oldoffice01->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); + + oldoffice01->encryptedVerifier[0] = byte_swap_32 (oldoffice01->encryptedVerifier[0]); + oldoffice01->encryptedVerifier[1] = byte_swap_32 (oldoffice01->encryptedVerifier[1]); + oldoffice01->encryptedVerifier[2] = byte_swap_32 (oldoffice01->encryptedVerifier[2]); + oldoffice01->encryptedVerifier[3] = byte_swap_32 (oldoffice01->encryptedVerifier[3]); + + oldoffice01->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); + oldoffice01->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); + oldoffice01->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); + oldoffice01->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); + + oldoffice01->encryptedVerifierHash[0] = byte_swap_32 (oldoffice01->encryptedVerifierHash[0]); + oldoffice01->encryptedVerifierHash[1] = byte_swap_32 (oldoffice01->encryptedVerifierHash[1]); + oldoffice01->encryptedVerifierHash[2] = byte_swap_32 (oldoffice01->encryptedVerifierHash[2]); + oldoffice01->encryptedVerifierHash[3] = byte_swap_32 (oldoffice01->encryptedVerifierHash[3]); + + oldoffice01->rc4key[1] = 0; + oldoffice01->rc4key[0] = 0; + + oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[0]) << 28; + oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[1]) << 24; + oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[2]) << 20; + oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[3]) << 16; + oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[4]) << 12; + oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[5]) << 8; + oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[6]) << 4; + oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[7]) << 0; + oldoffice01->rc4key[1] |= hex_convert (rc4key_pos[8]) << 28; + oldoffice01->rc4key[1] |= hex_convert (rc4key_pos[9]) << 24; + + oldoffice01->rc4key[0] = byte_swap_32 (oldoffice01->rc4key[0]); + oldoffice01->rc4key[1] = byte_swap_32 (oldoffice01->rc4key[1]); + + /** + * salt + */ + + salt->salt_len = 16; + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); + + salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); + salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); + salt->salt_buf[2] = byte_swap_32 (salt->salt_buf[2]); + salt->salt_buf[3] = byte_swap_32 (salt->salt_buf[3]); + + // this is a workaround as office produces multiple documents with the same salt + + salt->salt_len += 32; + + salt->salt_buf[ 4] = oldoffice01->encryptedVerifier[0]; + salt->salt_buf[ 5] = oldoffice01->encryptedVerifier[1]; + salt->salt_buf[ 6] = oldoffice01->encryptedVerifier[2]; + salt->salt_buf[ 7] = oldoffice01->encryptedVerifier[3]; + salt->salt_buf[ 8] = oldoffice01->encryptedVerifierHash[0]; + salt->salt_buf[ 9] = oldoffice01->encryptedVerifierHash[1]; + salt->salt_buf[10] = oldoffice01->encryptedVerifierHash[2]; + salt->salt_buf[11] = oldoffice01->encryptedVerifierHash[3]; + + /** + * digest + */ + + digest[0] = oldoffice01->rc4key[0]; + digest[1] = oldoffice01->rc4key[1]; + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int oldoffice34_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_9800) || (input_len > DISPLAY_LEN_MAX_9800)) return (PARSER_GLOBAL_LENGTH); + + if ((memcmp (SIGNATURE_OLDOFFICE3, input_buf, 12)) && (memcmp (SIGNATURE_OLDOFFICE4, input_buf, 12))) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + oldoffice34_t *oldoffice34 = (oldoffice34_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *version_pos = input_buf + 11; + + char *osalt_pos = strchr (version_pos, '*'); + + if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 version_len = osalt_pos - version_pos; + + if (version_len != 1) return (PARSER_SALT_LENGTH); + + osalt_pos++; + + char *encryptedVerifier_pos = strchr (osalt_pos, '*'); + + if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 osalt_len = encryptedVerifier_pos - osalt_pos; + + if (osalt_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifier_pos++; + + char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); + + if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; + + if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifierHash_pos++; + + u32 encryptedVerifierHash_len = input_len - 11 - version_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1; + + if (encryptedVerifierHash_len != 40) return (PARSER_SALT_LENGTH); + + const uint version = *version_pos - 0x30; + + if (version != 3 && version != 4) return (PARSER_SALT_VALUE); + + /** + * esalt + */ + + oldoffice34->version = version; + + oldoffice34->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); + oldoffice34->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); + oldoffice34->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); + oldoffice34->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); + + oldoffice34->encryptedVerifier[0] = byte_swap_32 (oldoffice34->encryptedVerifier[0]); + oldoffice34->encryptedVerifier[1] = byte_swap_32 (oldoffice34->encryptedVerifier[1]); + oldoffice34->encryptedVerifier[2] = byte_swap_32 (oldoffice34->encryptedVerifier[2]); + oldoffice34->encryptedVerifier[3] = byte_swap_32 (oldoffice34->encryptedVerifier[3]); + + oldoffice34->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); + oldoffice34->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); + oldoffice34->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); + oldoffice34->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); + oldoffice34->encryptedVerifierHash[4] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[32]); + + oldoffice34->encryptedVerifierHash[0] = byte_swap_32 (oldoffice34->encryptedVerifierHash[0]); + oldoffice34->encryptedVerifierHash[1] = byte_swap_32 (oldoffice34->encryptedVerifierHash[1]); + oldoffice34->encryptedVerifierHash[2] = byte_swap_32 (oldoffice34->encryptedVerifierHash[2]); + oldoffice34->encryptedVerifierHash[3] = byte_swap_32 (oldoffice34->encryptedVerifierHash[3]); + oldoffice34->encryptedVerifierHash[4] = byte_swap_32 (oldoffice34->encryptedVerifierHash[4]); + + /** + * salt + */ + + salt->salt_len = 16; + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); + + // this is a workaround as office produces multiple documents with the same salt + + salt->salt_len += 32; + + salt->salt_buf[ 4] = oldoffice34->encryptedVerifier[0]; + salt->salt_buf[ 5] = oldoffice34->encryptedVerifier[1]; + salt->salt_buf[ 6] = oldoffice34->encryptedVerifier[2]; + salt->salt_buf[ 7] = oldoffice34->encryptedVerifier[3]; + salt->salt_buf[ 8] = oldoffice34->encryptedVerifierHash[0]; + salt->salt_buf[ 9] = oldoffice34->encryptedVerifierHash[1]; + salt->salt_buf[10] = oldoffice34->encryptedVerifierHash[2]; + salt->salt_buf[11] = oldoffice34->encryptedVerifierHash[3]; + + /** + * digest + */ + + digest[0] = oldoffice34->encryptedVerifierHash[0]; + digest[1] = oldoffice34->encryptedVerifierHash[1]; + digest[2] = oldoffice34->encryptedVerifierHash[2]; + digest[3] = oldoffice34->encryptedVerifierHash[3]; + + return (PARSER_OK); +} + +int oldoffice34cm1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if (memcmp (SIGNATURE_OLDOFFICE3, input_buf, 12)) return (PARSER_SIGNATURE_UNMATCHED); + + return oldoffice34_parse_hash (input_buf, input_len, hash_buf); +} + +int oldoffice34cm2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_9820) || (input_len > DISPLAY_LEN_MAX_9820)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_OLDOFFICE3, input_buf, 12)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + oldoffice34_t *oldoffice34 = (oldoffice34_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *version_pos = input_buf + 11; + + char *osalt_pos = strchr (version_pos, '*'); + + if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 version_len = osalt_pos - version_pos; + + if (version_len != 1) return (PARSER_SALT_LENGTH); + + osalt_pos++; + + char *encryptedVerifier_pos = strchr (osalt_pos, '*'); + + if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 osalt_len = encryptedVerifier_pos - osalt_pos; + + if (osalt_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifier_pos++; + + char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); + + if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; + + if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); + + encryptedVerifierHash_pos++; + + char *rc4key_pos = strchr (encryptedVerifierHash_pos, ':'); + + if (rc4key_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 encryptedVerifierHash_len = rc4key_pos - encryptedVerifierHash_pos; + + if (encryptedVerifierHash_len != 40) return (PARSER_SALT_LENGTH); + + rc4key_pos++; + + u32 rc4key_len = input_len - 11 - version_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1 - encryptedVerifierHash_len - 1; + + if (rc4key_len != 10) return (PARSER_SALT_LENGTH); + + const uint version = *version_pos - 0x30; + + if (version != 3 && version != 4) return (PARSER_SALT_VALUE); + + /** + * esalt + */ + + oldoffice34->version = version; + + oldoffice34->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); + oldoffice34->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); + oldoffice34->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); + oldoffice34->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); + + oldoffice34->encryptedVerifier[0] = byte_swap_32 (oldoffice34->encryptedVerifier[0]); + oldoffice34->encryptedVerifier[1] = byte_swap_32 (oldoffice34->encryptedVerifier[1]); + oldoffice34->encryptedVerifier[2] = byte_swap_32 (oldoffice34->encryptedVerifier[2]); + oldoffice34->encryptedVerifier[3] = byte_swap_32 (oldoffice34->encryptedVerifier[3]); + + oldoffice34->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); + oldoffice34->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); + oldoffice34->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); + oldoffice34->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); + oldoffice34->encryptedVerifierHash[4] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[32]); + + oldoffice34->encryptedVerifierHash[0] = byte_swap_32 (oldoffice34->encryptedVerifierHash[0]); + oldoffice34->encryptedVerifierHash[1] = byte_swap_32 (oldoffice34->encryptedVerifierHash[1]); + oldoffice34->encryptedVerifierHash[2] = byte_swap_32 (oldoffice34->encryptedVerifierHash[2]); + oldoffice34->encryptedVerifierHash[3] = byte_swap_32 (oldoffice34->encryptedVerifierHash[3]); + oldoffice34->encryptedVerifierHash[4] = byte_swap_32 (oldoffice34->encryptedVerifierHash[4]); + + oldoffice34->rc4key[1] = 0; + oldoffice34->rc4key[0] = 0; + + oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[0]) << 28; + oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[1]) << 24; + oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[2]) << 20; + oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[3]) << 16; + oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[4]) << 12; + oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[5]) << 8; + oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[6]) << 4; + oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[7]) << 0; + oldoffice34->rc4key[1] |= hex_convert (rc4key_pos[8]) << 28; + oldoffice34->rc4key[1] |= hex_convert (rc4key_pos[9]) << 24; + + oldoffice34->rc4key[0] = byte_swap_32 (oldoffice34->rc4key[0]); + oldoffice34->rc4key[1] = byte_swap_32 (oldoffice34->rc4key[1]); + + /** + * salt + */ + + salt->salt_len = 16; + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); + + // this is a workaround as office produces multiple documents with the same salt + + salt->salt_len += 32; + + salt->salt_buf[ 4] = oldoffice34->encryptedVerifier[0]; + salt->salt_buf[ 5] = oldoffice34->encryptedVerifier[1]; + salt->salt_buf[ 6] = oldoffice34->encryptedVerifier[2]; + salt->salt_buf[ 7] = oldoffice34->encryptedVerifier[3]; + salt->salt_buf[ 8] = oldoffice34->encryptedVerifierHash[0]; + salt->salt_buf[ 9] = oldoffice34->encryptedVerifierHash[1]; + salt->salt_buf[10] = oldoffice34->encryptedVerifierHash[2]; + salt->salt_buf[11] = oldoffice34->encryptedVerifierHash[3]; + + /** + * digest + */ + + digest[0] = oldoffice34->rc4key[0]; + digest[1] = oldoffice34->rc4key[1]; + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int radmin2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_9900) || (input_len > DISPLAY_LEN_MAX_9900)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + return (PARSER_OK); +} + +int djangosha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_124) || (input_len > DISPLAY_LEN_MAX_124)) return (PARSER_GLOBAL_LENGTH); + + if ((memcmp (SIGNATURE_DJANGOSHA1, input_buf, 5)) && (memcmp (SIGNATURE_DJANGOSHA1, input_buf, 5))) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *signature_pos = input_buf; + + char *salt_pos = strchr (signature_pos, '$'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 signature_len = salt_pos - signature_pos; + + if (signature_len != 4) return (PARSER_SIGNATURE_UNMATCHED); + + salt_pos++; + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 salt_len = hash_pos - salt_pos; + + if (salt_len > 32) return (PARSER_SALT_LENGTH); + + hash_pos++; + + u32 hash_len = input_len - signature_len - 1 - salt_len - 1; + + if (hash_len != 40) return (PARSER_SALT_LENGTH); + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); + + digest[0] -= SHA1M_A; + digest[1] -= SHA1M_B; + digest[2] -= SHA1M_C; + digest[3] -= SHA1M_D; + digest[4] -= SHA1M_E; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + memcpy (salt_buf_ptr, salt_pos, salt_len); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int djangopbkdf2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_10000) || (input_len > DISPLAY_LEN_MAX_10000)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_DJANGOPBKDF2, input_buf, 14)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pbkdf2_sha256_t *pbkdf2_sha256 = (pbkdf2_sha256_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *iter_pos = input_buf + 14; + + const int iter = atoi (iter_pos); + + if (iter < 1) return (PARSER_SALT_ITERATION); + + salt->salt_iter = iter - 1; + + char *salt_pos = strchr (iter_pos, '$'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + const uint salt_len = hash_pos - salt_pos; + + hash_pos++; + + char *salt_buf_ptr = (char *) pbkdf2_sha256->salt_buf; + + memcpy (salt_buf_ptr, salt_pos, salt_len); + + salt->salt_len = salt_len; + + salt_buf_ptr[salt_len + 3] = 0x01; + salt_buf_ptr[salt_len + 4] = 0x80; + + // add some stuff to normal salt to make sorted happy + + salt->salt_buf[0] = pbkdf2_sha256->salt_buf[0]; + salt->salt_buf[1] = pbkdf2_sha256->salt_buf[1]; + salt->salt_buf[2] = pbkdf2_sha256->salt_buf[2]; + salt->salt_buf[3] = pbkdf2_sha256->salt_buf[3]; + salt->salt_buf[4] = salt->salt_iter; + + // base64 decode hash + + u8 tmp_buf[100] = { 0 }; + + uint hash_len = input_len - (hash_pos - input_buf); + + if (hash_len != 44) return (PARSER_HASH_LENGTH); + + base64_decode (base64_to_int, (const u8 *) hash_pos, hash_len, tmp_buf); + + memcpy (digest, tmp_buf, 32); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + digest[5] = byte_swap_32 (digest[5]); + digest[6] = byte_swap_32 (digest[6]); + digest[7] = byte_swap_32 (digest[7]); + + return (PARSER_OK); +} + +int siphash_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_10100) || (input_len > DISPLAY_LEN_MAX_10100)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = 0; + digest[3] = 0; + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + + if (input_buf[16] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + if (input_buf[18] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + if (input_buf[20] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + char iter_c = input_buf[17]; + char iter_d = input_buf[19]; + + // atm only defaults, let's see if there's more request + if (iter_c != '2') return (PARSER_SALT_ITERATION); + if (iter_d != '4') return (PARSER_SALT_ITERATION); + + char *salt_buf = input_buf + 16 + 1 + 1 + 1 + 1 + 1; + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_buf[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_buf[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_buf[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &salt_buf[24]); + + salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); + salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); + salt->salt_buf[2] = byte_swap_32 (salt->salt_buf[2]); + salt->salt_buf[3] = byte_swap_32 (salt->salt_buf[3]); + + salt->salt_len = 16; + + return (PARSER_OK); +} + +int crammd5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_10200) || (input_len > DISPLAY_LEN_MAX_10200)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_CRAM_MD5, input_buf, 10)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + cram_md5_t *cram_md5 = (cram_md5_t *) hash_buf->esalt; + + salt_t *salt = hash_buf->salt; + + char *salt_pos = input_buf + 10; + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = hash_pos - salt_pos; + + hash_pos++; + + uint hash_len = input_len - 10 - salt_len - 1; + + // base64 decode salt + + if (salt_len > 133) return (PARSER_SALT_LENGTH); + + u8 tmp_buf[100] = { 0 }; + + salt_len = base64_decode (base64_to_int, (const u8 *) salt_pos, salt_len, tmp_buf); + + if (salt_len > 55) return (PARSER_SALT_LENGTH); + + tmp_buf[salt_len] = 0x80; + + memcpy (&salt->salt_buf, tmp_buf, salt_len + 1); + + salt->salt_len = salt_len; + + // base64 decode hash + + if (hash_len > 133) return (PARSER_HASH_LENGTH); + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + hash_len = base64_decode (base64_to_int, (const u8 *) hash_pos, hash_len, tmp_buf); + + if (hash_len < 32 + 1) return (PARSER_HASH_LENGTH); + + uint user_len = hash_len - 32; + + const u8 *tmp_hash = tmp_buf + user_len; + + user_len--; // skip the trailing space + + digest[0] = hex_to_u32 (&tmp_hash[ 0]); + digest[1] = hex_to_u32 (&tmp_hash[ 8]); + digest[2] = hex_to_u32 (&tmp_hash[16]); + digest[3] = hex_to_u32 (&tmp_hash[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + // store username for host only (output hash if cracked) + + memset (cram_md5->user, 0, sizeof (cram_md5->user)); + memcpy (cram_md5->user, tmp_buf, user_len); + + return (PARSER_OK); +} + +int saph_sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_10300) || (input_len > DISPLAY_LEN_MAX_10300)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SAPH_SHA1, input_buf, 10)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *iter_pos = input_buf + 10; + + u32 iter = atoi (iter_pos); + + if (iter < 1) + { + return (PARSER_SALT_ITERATION); + } + + iter--; // first iteration is special + + salt->salt_iter = iter; + + char *base64_pos = strchr (iter_pos, '}'); + + if (base64_pos == NULL) + { + return (PARSER_SIGNATURE_UNMATCHED); + } + + base64_pos++; + + // base64 decode salt + + u32 base64_len = input_len - (base64_pos - input_buf); + + u8 tmp_buf[100] = { 0 }; + + u32 decoded_len = base64_decode (base64_to_int, (const u8 *) base64_pos, base64_len, tmp_buf); + + if (decoded_len < 24) + { + return (PARSER_SALT_LENGTH); + } + + // copy the salt + + uint salt_len = decoded_len - 20; + + if (salt_len < 4) return (PARSER_SALT_LENGTH); + if (salt_len > 16) return (PARSER_SALT_LENGTH); + + memcpy (&salt->salt_buf, tmp_buf + 20, salt_len); + + salt->salt_len = salt_len; + + // set digest + + u32 *digest_ptr = (u32*) tmp_buf; + + digest[0] = byte_swap_32 (digest_ptr[0]); + digest[1] = byte_swap_32 (digest_ptr[1]); + digest[2] = byte_swap_32 (digest_ptr[2]); + digest[3] = byte_swap_32 (digest_ptr[3]); + digest[4] = byte_swap_32 (digest_ptr[4]); + + return (PARSER_OK); +} + +int redmine_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_7600) || (input_len > DISPLAY_LEN_MAX_7600)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + + if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 40 - 1; + + char *salt_buf = input_buf + 40 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len != 32) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int pdf11_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_10400) || (input_len > DISPLAY_LEN_MAX_10400)) return (PARSER_GLOBAL_LENGTH); + + if ((memcmp (SIGNATURE_PDF, input_buf, 5)) && (memcmp (SIGNATURE_PDF, input_buf, 5))) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pdf_t *pdf = (pdf_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *V_pos = input_buf + 5; + + char *R_pos = strchr (V_pos, '*'); + + if (R_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 V_len = R_pos - V_pos; + + R_pos++; + + char *bits_pos = strchr (R_pos, '*'); + + if (bits_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 R_len = bits_pos - R_pos; + + bits_pos++; + + char *P_pos = strchr (bits_pos, '*'); + + if (P_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 bits_len = P_pos - bits_pos; + + P_pos++; + + char *enc_md_pos = strchr (P_pos, '*'); + + if (enc_md_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 P_len = enc_md_pos - P_pos; + + enc_md_pos++; + + char *id_len_pos = strchr (enc_md_pos, '*'); + + if (id_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 enc_md_len = id_len_pos - enc_md_pos; + + id_len_pos++; + + char *id_buf_pos = strchr (id_len_pos, '*'); + + if (id_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 id_len_len = id_buf_pos - id_len_pos; + + id_buf_pos++; + + char *u_len_pos = strchr (id_buf_pos, '*'); + + if (u_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 id_buf_len = u_len_pos - id_buf_pos; + + if (id_buf_len != 32) return (PARSER_SALT_LENGTH); + + u_len_pos++; + + char *u_buf_pos = strchr (u_len_pos, '*'); + + if (u_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 u_len_len = u_buf_pos - u_len_pos; + + u_buf_pos++; + + char *o_len_pos = strchr (u_buf_pos, '*'); + + if (o_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 u_buf_len = o_len_pos - u_buf_pos; + + if (u_buf_len != 64) return (PARSER_SALT_LENGTH); + + o_len_pos++; + + char *o_buf_pos = strchr (o_len_pos, '*'); + + if (o_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 o_len_len = o_buf_pos - o_len_pos; + + o_buf_pos++; + + u32 o_buf_len = input_len - 5 - V_len - 1 - R_len - 1 - bits_len - 1 - P_len - 1 - enc_md_len - 1 - id_len_len - 1 - id_buf_len - 1 - u_len_len - 1 - u_buf_len - 1 - o_len_len - 1; + + if (o_buf_len != 64) return (PARSER_SALT_LENGTH); + + // validate data + + const int V = atoi (V_pos); + const int R = atoi (R_pos); + const int P = atoi (P_pos); + + if (V != 1) return (PARSER_SALT_VALUE); + if (R != 2) return (PARSER_SALT_VALUE); + + const int enc_md = atoi (enc_md_pos); + + if ((enc_md != 0) && (enc_md != 1)) return (PARSER_SALT_VALUE); + + const int id_len = atoi (id_len_pos); + const int u_len = atoi (u_len_pos); + const int o_len = atoi (o_len_pos); + + if (id_len != 16) return (PARSER_SALT_VALUE); + if (u_len != 32) return (PARSER_SALT_VALUE); + if (o_len != 32) return (PARSER_SALT_VALUE); + + const int bits = atoi (bits_pos); + + if (bits != 40) return (PARSER_SALT_VALUE); + + // copy data to esalt + + pdf->V = V; + pdf->R = R; + pdf->P = P; + + pdf->enc_md = enc_md; + + pdf->id_buf[0] = hex_to_u32 ((const u8 *) &id_buf_pos[ 0]); + pdf->id_buf[1] = hex_to_u32 ((const u8 *) &id_buf_pos[ 8]); + pdf->id_buf[2] = hex_to_u32 ((const u8 *) &id_buf_pos[16]); + pdf->id_buf[3] = hex_to_u32 ((const u8 *) &id_buf_pos[24]); + pdf->id_len = id_len; + + pdf->u_buf[0] = hex_to_u32 ((const u8 *) &u_buf_pos[ 0]); + pdf->u_buf[1] = hex_to_u32 ((const u8 *) &u_buf_pos[ 8]); + pdf->u_buf[2] = hex_to_u32 ((const u8 *) &u_buf_pos[16]); + pdf->u_buf[3] = hex_to_u32 ((const u8 *) &u_buf_pos[24]); + pdf->u_buf[4] = hex_to_u32 ((const u8 *) &u_buf_pos[32]); + pdf->u_buf[5] = hex_to_u32 ((const u8 *) &u_buf_pos[40]); + pdf->u_buf[6] = hex_to_u32 ((const u8 *) &u_buf_pos[48]); + pdf->u_buf[7] = hex_to_u32 ((const u8 *) &u_buf_pos[56]); + pdf->u_len = u_len; + + pdf->o_buf[0] = hex_to_u32 ((const u8 *) &o_buf_pos[ 0]); + pdf->o_buf[1] = hex_to_u32 ((const u8 *) &o_buf_pos[ 8]); + pdf->o_buf[2] = hex_to_u32 ((const u8 *) &o_buf_pos[16]); + pdf->o_buf[3] = hex_to_u32 ((const u8 *) &o_buf_pos[24]); + pdf->o_buf[4] = hex_to_u32 ((const u8 *) &o_buf_pos[32]); + pdf->o_buf[5] = hex_to_u32 ((const u8 *) &o_buf_pos[40]); + pdf->o_buf[6] = hex_to_u32 ((const u8 *) &o_buf_pos[48]); + pdf->o_buf[7] = hex_to_u32 ((const u8 *) &o_buf_pos[56]); + pdf->o_len = o_len; + + pdf->id_buf[0] = byte_swap_32 (pdf->id_buf[0]); + pdf->id_buf[1] = byte_swap_32 (pdf->id_buf[1]); + pdf->id_buf[2] = byte_swap_32 (pdf->id_buf[2]); + pdf->id_buf[3] = byte_swap_32 (pdf->id_buf[3]); + + pdf->u_buf[0] = byte_swap_32 (pdf->u_buf[0]); + pdf->u_buf[1] = byte_swap_32 (pdf->u_buf[1]); + pdf->u_buf[2] = byte_swap_32 (pdf->u_buf[2]); + pdf->u_buf[3] = byte_swap_32 (pdf->u_buf[3]); + pdf->u_buf[4] = byte_swap_32 (pdf->u_buf[4]); + pdf->u_buf[5] = byte_swap_32 (pdf->u_buf[5]); + pdf->u_buf[6] = byte_swap_32 (pdf->u_buf[6]); + pdf->u_buf[7] = byte_swap_32 (pdf->u_buf[7]); + + pdf->o_buf[0] = byte_swap_32 (pdf->o_buf[0]); + pdf->o_buf[1] = byte_swap_32 (pdf->o_buf[1]); + pdf->o_buf[2] = byte_swap_32 (pdf->o_buf[2]); + pdf->o_buf[3] = byte_swap_32 (pdf->o_buf[3]); + pdf->o_buf[4] = byte_swap_32 (pdf->o_buf[4]); + pdf->o_buf[5] = byte_swap_32 (pdf->o_buf[5]); + pdf->o_buf[6] = byte_swap_32 (pdf->o_buf[6]); + pdf->o_buf[7] = byte_swap_32 (pdf->o_buf[7]); + + // we use ID for salt, maybe needs to change, we will see... + + salt->salt_buf[0] = pdf->id_buf[0]; + salt->salt_buf[1] = pdf->id_buf[1]; + salt->salt_buf[2] = pdf->id_buf[2]; + salt->salt_buf[3] = pdf->id_buf[3]; + salt->salt_len = pdf->id_len; + + digest[0] = pdf->u_buf[0]; + digest[1] = pdf->u_buf[1]; + digest[2] = pdf->u_buf[2]; + digest[3] = pdf->u_buf[3]; + + return (PARSER_OK); +} + +int pdf11cm1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + return pdf11_parse_hash (input_buf, input_len, hash_buf); +} + +int pdf11cm2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_10420) || (input_len > DISPLAY_LEN_MAX_10420)) return (PARSER_GLOBAL_LENGTH); + + if ((memcmp (SIGNATURE_PDF, input_buf, 5)) && (memcmp (SIGNATURE_PDF, input_buf, 5))) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pdf_t *pdf = (pdf_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *V_pos = input_buf + 5; + + char *R_pos = strchr (V_pos, '*'); + + if (R_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 V_len = R_pos - V_pos; + + R_pos++; + + char *bits_pos = strchr (R_pos, '*'); + + if (bits_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 R_len = bits_pos - R_pos; + + bits_pos++; + + char *P_pos = strchr (bits_pos, '*'); + + if (P_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 bits_len = P_pos - bits_pos; + + P_pos++; + + char *enc_md_pos = strchr (P_pos, '*'); + + if (enc_md_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 P_len = enc_md_pos - P_pos; + + enc_md_pos++; + + char *id_len_pos = strchr (enc_md_pos, '*'); + + if (id_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 enc_md_len = id_len_pos - enc_md_pos; + + id_len_pos++; + + char *id_buf_pos = strchr (id_len_pos, '*'); + + if (id_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 id_len_len = id_buf_pos - id_len_pos; + + id_buf_pos++; + + char *u_len_pos = strchr (id_buf_pos, '*'); + + if (u_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 id_buf_len = u_len_pos - id_buf_pos; + + if (id_buf_len != 32) return (PARSER_SALT_LENGTH); + + u_len_pos++; + + char *u_buf_pos = strchr (u_len_pos, '*'); + + if (u_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 u_len_len = u_buf_pos - u_len_pos; + + u_buf_pos++; + + char *o_len_pos = strchr (u_buf_pos, '*'); + + if (o_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 u_buf_len = o_len_pos - u_buf_pos; + + if (u_buf_len != 64) return (PARSER_SALT_LENGTH); + + o_len_pos++; + + char *o_buf_pos = strchr (o_len_pos, '*'); + + if (o_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 o_len_len = o_buf_pos - o_len_pos; + + o_buf_pos++; + + char *rc4key_pos = strchr (o_buf_pos, ':'); + + if (rc4key_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 o_buf_len = rc4key_pos - o_buf_pos; + + if (o_buf_len != 64) return (PARSER_SALT_LENGTH); + + rc4key_pos++; + + u32 rc4key_len = input_len - 5 - V_len - 1 - R_len - 1 - bits_len - 1 - P_len - 1 - enc_md_len - 1 - id_len_len - 1 - id_buf_len - 1 - u_len_len - 1 - u_buf_len - 1 - o_len_len - 1 - o_buf_len - 1; + + if (rc4key_len != 10) return (PARSER_SALT_LENGTH); + + // validate data + + const int V = atoi (V_pos); + const int R = atoi (R_pos); + const int P = atoi (P_pos); + + if (V != 1) return (PARSER_SALT_VALUE); + if (R != 2) return (PARSER_SALT_VALUE); + + const int enc_md = atoi (enc_md_pos); + + if ((enc_md != 0) && (enc_md != 1)) return (PARSER_SALT_VALUE); + + const int id_len = atoi (id_len_pos); + const int u_len = atoi (u_len_pos); + const int o_len = atoi (o_len_pos); + + if (id_len != 16) return (PARSER_SALT_VALUE); + if (u_len != 32) return (PARSER_SALT_VALUE); + if (o_len != 32) return (PARSER_SALT_VALUE); + + const int bits = atoi (bits_pos); + + if (bits != 40) return (PARSER_SALT_VALUE); + + // copy data to esalt + + pdf->V = V; + pdf->R = R; + pdf->P = P; + + pdf->enc_md = enc_md; + + pdf->id_buf[0] = hex_to_u32 ((const u8 *) &id_buf_pos[ 0]); + pdf->id_buf[1] = hex_to_u32 ((const u8 *) &id_buf_pos[ 8]); + pdf->id_buf[2] = hex_to_u32 ((const u8 *) &id_buf_pos[16]); + pdf->id_buf[3] = hex_to_u32 ((const u8 *) &id_buf_pos[24]); + pdf->id_len = id_len; + + pdf->u_buf[0] = hex_to_u32 ((const u8 *) &u_buf_pos[ 0]); + pdf->u_buf[1] = hex_to_u32 ((const u8 *) &u_buf_pos[ 8]); + pdf->u_buf[2] = hex_to_u32 ((const u8 *) &u_buf_pos[16]); + pdf->u_buf[3] = hex_to_u32 ((const u8 *) &u_buf_pos[24]); + pdf->u_buf[4] = hex_to_u32 ((const u8 *) &u_buf_pos[32]); + pdf->u_buf[5] = hex_to_u32 ((const u8 *) &u_buf_pos[40]); + pdf->u_buf[6] = hex_to_u32 ((const u8 *) &u_buf_pos[48]); + pdf->u_buf[7] = hex_to_u32 ((const u8 *) &u_buf_pos[56]); + pdf->u_len = u_len; + + pdf->o_buf[0] = hex_to_u32 ((const u8 *) &o_buf_pos[ 0]); + pdf->o_buf[1] = hex_to_u32 ((const u8 *) &o_buf_pos[ 8]); + pdf->o_buf[2] = hex_to_u32 ((const u8 *) &o_buf_pos[16]); + pdf->o_buf[3] = hex_to_u32 ((const u8 *) &o_buf_pos[24]); + pdf->o_buf[4] = hex_to_u32 ((const u8 *) &o_buf_pos[32]); + pdf->o_buf[5] = hex_to_u32 ((const u8 *) &o_buf_pos[40]); + pdf->o_buf[6] = hex_to_u32 ((const u8 *) &o_buf_pos[48]); + pdf->o_buf[7] = hex_to_u32 ((const u8 *) &o_buf_pos[56]); + pdf->o_len = o_len; + + pdf->id_buf[0] = byte_swap_32 (pdf->id_buf[0]); + pdf->id_buf[1] = byte_swap_32 (pdf->id_buf[1]); + pdf->id_buf[2] = byte_swap_32 (pdf->id_buf[2]); + pdf->id_buf[3] = byte_swap_32 (pdf->id_buf[3]); + + pdf->u_buf[0] = byte_swap_32 (pdf->u_buf[0]); + pdf->u_buf[1] = byte_swap_32 (pdf->u_buf[1]); + pdf->u_buf[2] = byte_swap_32 (pdf->u_buf[2]); + pdf->u_buf[3] = byte_swap_32 (pdf->u_buf[3]); + pdf->u_buf[4] = byte_swap_32 (pdf->u_buf[4]); + pdf->u_buf[5] = byte_swap_32 (pdf->u_buf[5]); + pdf->u_buf[6] = byte_swap_32 (pdf->u_buf[6]); + pdf->u_buf[7] = byte_swap_32 (pdf->u_buf[7]); + + pdf->o_buf[0] = byte_swap_32 (pdf->o_buf[0]); + pdf->o_buf[1] = byte_swap_32 (pdf->o_buf[1]); + pdf->o_buf[2] = byte_swap_32 (pdf->o_buf[2]); + pdf->o_buf[3] = byte_swap_32 (pdf->o_buf[3]); + pdf->o_buf[4] = byte_swap_32 (pdf->o_buf[4]); + pdf->o_buf[5] = byte_swap_32 (pdf->o_buf[5]); + pdf->o_buf[6] = byte_swap_32 (pdf->o_buf[6]); + pdf->o_buf[7] = byte_swap_32 (pdf->o_buf[7]); + + pdf->rc4key[1] = 0; + pdf->rc4key[0] = 0; + + pdf->rc4key[0] |= hex_convert (rc4key_pos[0]) << 28; + pdf->rc4key[0] |= hex_convert (rc4key_pos[1]) << 24; + pdf->rc4key[0] |= hex_convert (rc4key_pos[2]) << 20; + pdf->rc4key[0] |= hex_convert (rc4key_pos[3]) << 16; + pdf->rc4key[0] |= hex_convert (rc4key_pos[4]) << 12; + pdf->rc4key[0] |= hex_convert (rc4key_pos[5]) << 8; + pdf->rc4key[0] |= hex_convert (rc4key_pos[6]) << 4; + pdf->rc4key[0] |= hex_convert (rc4key_pos[7]) << 0; + pdf->rc4key[1] |= hex_convert (rc4key_pos[8]) << 28; + pdf->rc4key[1] |= hex_convert (rc4key_pos[9]) << 24; + + pdf->rc4key[0] = byte_swap_32 (pdf->rc4key[0]); + pdf->rc4key[1] = byte_swap_32 (pdf->rc4key[1]); + + // we use ID for salt, maybe needs to change, we will see... + + salt->salt_buf[0] = pdf->id_buf[0]; + salt->salt_buf[1] = pdf->id_buf[1]; + salt->salt_buf[2] = pdf->id_buf[2]; + salt->salt_buf[3] = pdf->id_buf[3]; + salt->salt_buf[4] = pdf->u_buf[0]; + salt->salt_buf[5] = pdf->u_buf[1]; + salt->salt_buf[6] = pdf->o_buf[0]; + salt->salt_buf[7] = pdf->o_buf[1]; + salt->salt_len = pdf->id_len + 16; + + digest[0] = pdf->rc4key[0]; + digest[1] = pdf->rc4key[1]; + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int pdf14_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_10500) || (input_len > DISPLAY_LEN_MAX_10500)) return (PARSER_GLOBAL_LENGTH); + + if ((memcmp (SIGNATURE_PDF, input_buf, 5)) && (memcmp (SIGNATURE_PDF, input_buf, 5))) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pdf_t *pdf = (pdf_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *V_pos = input_buf + 5; + + char *R_pos = strchr (V_pos, '*'); + + if (R_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 V_len = R_pos - V_pos; + + R_pos++; + + char *bits_pos = strchr (R_pos, '*'); + + if (bits_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 R_len = bits_pos - R_pos; + + bits_pos++; + + char *P_pos = strchr (bits_pos, '*'); + + if (P_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 bits_len = P_pos - bits_pos; + + P_pos++; + + char *enc_md_pos = strchr (P_pos, '*'); + + if (enc_md_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 P_len = enc_md_pos - P_pos; + + enc_md_pos++; + + char *id_len_pos = strchr (enc_md_pos, '*'); + + if (id_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 enc_md_len = id_len_pos - enc_md_pos; + + id_len_pos++; + + char *id_buf_pos = strchr (id_len_pos, '*'); + + if (id_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 id_len_len = id_buf_pos - id_len_pos; + + id_buf_pos++; + + char *u_len_pos = strchr (id_buf_pos, '*'); + + if (u_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 id_buf_len = u_len_pos - id_buf_pos; + + if ((id_buf_len != 32) && (id_buf_len != 64)) return (PARSER_SALT_LENGTH); + + u_len_pos++; + + char *u_buf_pos = strchr (u_len_pos, '*'); + + if (u_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 u_len_len = u_buf_pos - u_len_pos; + + u_buf_pos++; + + char *o_len_pos = strchr (u_buf_pos, '*'); + + if (o_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 u_buf_len = o_len_pos - u_buf_pos; + + if (u_buf_len != 64) return (PARSER_SALT_LENGTH); + + o_len_pos++; + + char *o_buf_pos = strchr (o_len_pos, '*'); + + if (o_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 o_len_len = o_buf_pos - o_len_pos; + + o_buf_pos++; + + u32 o_buf_len = input_len - 5 - V_len - 1 - R_len - 1 - bits_len - 1 - P_len - 1 - enc_md_len - 1 - id_len_len - 1 - id_buf_len - 1 - u_len_len - 1 - u_buf_len - 1 - o_len_len - 1; + + if (o_buf_len != 64) return (PARSER_SALT_LENGTH); + + // validate data + + const int V = atoi (V_pos); + const int R = atoi (R_pos); + const int P = atoi (P_pos); + + int vr_ok = 0; + + if ((V == 2) && (R == 3)) vr_ok = 1; + if ((V == 4) && (R == 4)) vr_ok = 1; + + if (vr_ok == 0) return (PARSER_SALT_VALUE); + + const int id_len = atoi (id_len_pos); + const int u_len = atoi (u_len_pos); + const int o_len = atoi (o_len_pos); + + if ((id_len != 16) && (id_len != 32)) return (PARSER_SALT_VALUE); + + if (u_len != 32) return (PARSER_SALT_VALUE); + if (o_len != 32) return (PARSER_SALT_VALUE); + + const int bits = atoi (bits_pos); + + if (bits != 128) return (PARSER_SALT_VALUE); + + int enc_md = 1; + + if (R >= 4) + { + enc_md = atoi (enc_md_pos); + } + + // copy data to esalt + + pdf->V = V; + pdf->R = R; + pdf->P = P; + + pdf->enc_md = enc_md; + + pdf->id_buf[0] = hex_to_u32 ((const u8 *) &id_buf_pos[ 0]); + pdf->id_buf[1] = hex_to_u32 ((const u8 *) &id_buf_pos[ 8]); + pdf->id_buf[2] = hex_to_u32 ((const u8 *) &id_buf_pos[16]); + pdf->id_buf[3] = hex_to_u32 ((const u8 *) &id_buf_pos[24]); + + if (id_len == 32) + { + pdf->id_buf[4] = hex_to_u32 ((const u8 *) &id_buf_pos[32]); + pdf->id_buf[5] = hex_to_u32 ((const u8 *) &id_buf_pos[40]); + pdf->id_buf[6] = hex_to_u32 ((const u8 *) &id_buf_pos[48]); + pdf->id_buf[7] = hex_to_u32 ((const u8 *) &id_buf_pos[56]); + } + + pdf->id_len = id_len; + + pdf->u_buf[0] = hex_to_u32 ((const u8 *) &u_buf_pos[ 0]); + pdf->u_buf[1] = hex_to_u32 ((const u8 *) &u_buf_pos[ 8]); + pdf->u_buf[2] = hex_to_u32 ((const u8 *) &u_buf_pos[16]); + pdf->u_buf[3] = hex_to_u32 ((const u8 *) &u_buf_pos[24]); + pdf->u_buf[4] = hex_to_u32 ((const u8 *) &u_buf_pos[32]); + pdf->u_buf[5] = hex_to_u32 ((const u8 *) &u_buf_pos[40]); + pdf->u_buf[6] = hex_to_u32 ((const u8 *) &u_buf_pos[48]); + pdf->u_buf[7] = hex_to_u32 ((const u8 *) &u_buf_pos[56]); + pdf->u_len = u_len; + + pdf->o_buf[0] = hex_to_u32 ((const u8 *) &o_buf_pos[ 0]); + pdf->o_buf[1] = hex_to_u32 ((const u8 *) &o_buf_pos[ 8]); + pdf->o_buf[2] = hex_to_u32 ((const u8 *) &o_buf_pos[16]); + pdf->o_buf[3] = hex_to_u32 ((const u8 *) &o_buf_pos[24]); + pdf->o_buf[4] = hex_to_u32 ((const u8 *) &o_buf_pos[32]); + pdf->o_buf[5] = hex_to_u32 ((const u8 *) &o_buf_pos[40]); + pdf->o_buf[6] = hex_to_u32 ((const u8 *) &o_buf_pos[48]); + pdf->o_buf[7] = hex_to_u32 ((const u8 *) &o_buf_pos[56]); + pdf->o_len = o_len; + + pdf->id_buf[0] = byte_swap_32 (pdf->id_buf[0]); + pdf->id_buf[1] = byte_swap_32 (pdf->id_buf[1]); + pdf->id_buf[2] = byte_swap_32 (pdf->id_buf[2]); + pdf->id_buf[3] = byte_swap_32 (pdf->id_buf[3]); + + if (id_len == 32) + { + pdf->id_buf[4] = byte_swap_32 (pdf->id_buf[4]); + pdf->id_buf[5] = byte_swap_32 (pdf->id_buf[5]); + pdf->id_buf[6] = byte_swap_32 (pdf->id_buf[6]); + pdf->id_buf[7] = byte_swap_32 (pdf->id_buf[7]); + } + + pdf->u_buf[0] = byte_swap_32 (pdf->u_buf[0]); + pdf->u_buf[1] = byte_swap_32 (pdf->u_buf[1]); + pdf->u_buf[2] = byte_swap_32 (pdf->u_buf[2]); + pdf->u_buf[3] = byte_swap_32 (pdf->u_buf[3]); + pdf->u_buf[4] = byte_swap_32 (pdf->u_buf[4]); + pdf->u_buf[5] = byte_swap_32 (pdf->u_buf[5]); + pdf->u_buf[6] = byte_swap_32 (pdf->u_buf[6]); + pdf->u_buf[7] = byte_swap_32 (pdf->u_buf[7]); + + pdf->o_buf[0] = byte_swap_32 (pdf->o_buf[0]); + pdf->o_buf[1] = byte_swap_32 (pdf->o_buf[1]); + pdf->o_buf[2] = byte_swap_32 (pdf->o_buf[2]); + pdf->o_buf[3] = byte_swap_32 (pdf->o_buf[3]); + pdf->o_buf[4] = byte_swap_32 (pdf->o_buf[4]); + pdf->o_buf[5] = byte_swap_32 (pdf->o_buf[5]); + pdf->o_buf[6] = byte_swap_32 (pdf->o_buf[6]); + pdf->o_buf[7] = byte_swap_32 (pdf->o_buf[7]); + + // precompute rc4 data for later use + + uint padding[8] = + { + 0x5e4ebf28, + 0x418a754e, + 0x564e0064, + 0x0801faff, + 0xb6002e2e, + 0x803e68d0, + 0xfea90c2f, + 0x7a695364 + }; + + // md5 + + uint salt_pc_block[32] = { 0 }; + + char *salt_pc_ptr = (char *) salt_pc_block; + + memcpy (salt_pc_ptr, padding, 32); + memcpy (salt_pc_ptr + 32, pdf->id_buf, pdf->id_len); + + uint salt_pc_digest[4] = { 0 }; + + md5_complete_no_limit (salt_pc_digest, salt_pc_block, 32 + pdf->id_len); + + pdf->rc4data[0] = salt_pc_digest[0]; + pdf->rc4data[1] = salt_pc_digest[1]; + + // we use ID for salt, maybe needs to change, we will see... + + salt->salt_buf[0] = pdf->id_buf[0]; + salt->salt_buf[1] = pdf->id_buf[1]; + salt->salt_buf[2] = pdf->id_buf[2]; + salt->salt_buf[3] = pdf->id_buf[3]; + salt->salt_buf[4] = pdf->u_buf[0]; + salt->salt_buf[5] = pdf->u_buf[1]; + salt->salt_buf[6] = pdf->o_buf[0]; + salt->salt_buf[7] = pdf->o_buf[1]; + salt->salt_len = pdf->id_len + 16; + + salt->salt_iter = ROUNDS_PDF14; + + digest[0] = pdf->u_buf[0]; + digest[1] = pdf->u_buf[1]; + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int pdf17l3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + int ret = pdf17l8_parse_hash (input_buf, input_len, hash_buf); + + if (ret != PARSER_OK) + { + return ret; + } + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] -= SHA256M_A; + digest[1] -= SHA256M_B; + digest[2] -= SHA256M_C; + digest[3] -= SHA256M_D; + digest[4] -= SHA256M_E; + digest[5] -= SHA256M_F; + digest[6] -= SHA256M_G; + digest[7] -= SHA256M_H; + + salt->salt_buf[2] = 0x80; + + return (PARSER_OK); +} + +int pdf17l8_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_10600) || (input_len > DISPLAY_LEN_MAX_10600)) return (PARSER_GLOBAL_LENGTH); + + if ((memcmp (SIGNATURE_PDF, input_buf, 5)) && (memcmp (SIGNATURE_PDF, input_buf, 5))) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pdf_t *pdf = (pdf_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *V_pos = input_buf + 5; + + char *R_pos = strchr (V_pos, '*'); + + if (R_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 V_len = R_pos - V_pos; + + R_pos++; + + char *bits_pos = strchr (R_pos, '*'); + + if (bits_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 R_len = bits_pos - R_pos; + + bits_pos++; + + char *P_pos = strchr (bits_pos, '*'); + + if (P_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 bits_len = P_pos - bits_pos; + + P_pos++; + + char *enc_md_pos = strchr (P_pos, '*'); + + if (enc_md_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 P_len = enc_md_pos - P_pos; + + enc_md_pos++; + + char *id_len_pos = strchr (enc_md_pos, '*'); + + if (id_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 enc_md_len = id_len_pos - enc_md_pos; + + id_len_pos++; + + char *id_buf_pos = strchr (id_len_pos, '*'); + + if (id_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 id_len_len = id_buf_pos - id_len_pos; + + id_buf_pos++; + + char *u_len_pos = strchr (id_buf_pos, '*'); + + if (u_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 id_buf_len = u_len_pos - id_buf_pos; + + u_len_pos++; + + char *u_buf_pos = strchr (u_len_pos, '*'); + + if (u_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 u_len_len = u_buf_pos - u_len_pos; + + u_buf_pos++; + + char *o_len_pos = strchr (u_buf_pos, '*'); + + if (o_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 u_buf_len = o_len_pos - u_buf_pos; + + o_len_pos++; + + char *o_buf_pos = strchr (o_len_pos, '*'); + + if (o_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 o_len_len = o_buf_pos - o_len_pos; + + o_buf_pos++; + + char *last = strchr (o_buf_pos, '*'); + + if (last == NULL) last = input_buf + input_len; + + u32 o_buf_len = last - o_buf_pos; + + // validate data + + const int V = atoi (V_pos); + const int R = atoi (R_pos); + + int vr_ok = 0; + + if ((V == 5) && (R == 5)) vr_ok = 1; + if ((V == 5) && (R == 6)) vr_ok = 1; + + if (vr_ok == 0) return (PARSER_SALT_VALUE); + + const int bits = atoi (bits_pos); + + if (bits != 256) return (PARSER_SALT_VALUE); + + int enc_md = atoi (enc_md_pos); + + if ((enc_md != 0) && (enc_md != 1)) return (PARSER_SALT_VALUE); + + const uint id_len = atoi (id_len_pos); + const uint u_len = atoi (u_len_pos); + const uint o_len = atoi (o_len_pos); + + if (V_len > 6) return (PARSER_SALT_LENGTH); + if (R_len > 6) return (PARSER_SALT_LENGTH); + if (P_len > 6) return (PARSER_SALT_LENGTH); + if (id_len_len > 6) return (PARSER_SALT_LENGTH); + if (u_len_len > 6) return (PARSER_SALT_LENGTH); + if (o_len_len > 6) return (PARSER_SALT_LENGTH); + if (bits_len > 6) return (PARSER_SALT_LENGTH); + if (enc_md_len > 6) return (PARSER_SALT_LENGTH); + + if ((id_len * 2) != id_buf_len) return (PARSER_SALT_VALUE); + if ((u_len * 2) != u_buf_len) return (PARSER_SALT_VALUE); + if ((o_len * 2) != o_buf_len) return (PARSER_SALT_VALUE); + + // copy data to esalt + + if (u_len < 40) return (PARSER_SALT_VALUE); + + for (int i = 0, j = 0; i < 8 + 2; i += 1, j += 8) + { + pdf->u_buf[i] = hex_to_u32 ((const u8 *) &u_buf_pos[j]); + } + + salt->salt_buf[0] = pdf->u_buf[8]; + salt->salt_buf[1] = pdf->u_buf[9]; + + salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); + salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); + + salt->salt_len = 8; + salt->salt_iter = ROUNDS_PDF17L8; + + digest[0] = pdf->u_buf[0]; + digest[1] = pdf->u_buf[1]; + digest[2] = pdf->u_buf[2]; + digest[3] = pdf->u_buf[3]; + digest[4] = pdf->u_buf[4]; + digest[5] = pdf->u_buf[5]; + digest[6] = pdf->u_buf[6]; + digest[7] = pdf->u_buf[7]; + + return (PARSER_OK); +} + +int pbkdf2_sha256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_10900) || (input_len > DISPLAY_LEN_MAX_10900)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_PBKDF2_SHA256, input_buf, 7)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pbkdf2_sha256_t *pbkdf2_sha256 = (pbkdf2_sha256_t *) hash_buf->esalt; + + /** + * parse line + */ + + // iterations + + char *iter_pos = input_buf + 7; + + u32 iter = atoi (iter_pos); + + if (iter < 1) return (PARSER_SALT_ITERATION); + if (iter > 999999) return (PARSER_SALT_ITERATION); + + // first is *raw* salt + + char *salt_pos = strchr (iter_pos, ':'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + char *hash_pos = strchr (salt_pos, ':'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 salt_len = hash_pos - salt_pos; + + if (salt_len > 64) return (PARSER_SALT_LENGTH); + + hash_pos++; + + u32 hash_b64_len = input_len - (hash_pos - input_buf); + + if (hash_b64_len > 88) return (PARSER_HASH_LENGTH); + + // decode salt + + char *salt_buf_ptr = (char *) pbkdf2_sha256->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt_buf_ptr[salt_len + 3] = 0x01; + salt_buf_ptr[salt_len + 4] = 0x80; + + salt->salt_len = salt_len; + salt->salt_iter = iter - 1; + + // decode hash + + u8 tmp_buf[100] = { 0 }; + + int hash_len = base64_decode (base64_to_int, (const u8 *) hash_pos, hash_b64_len, tmp_buf); + + if (hash_len < 16) return (PARSER_HASH_LENGTH); + + memcpy (digest, tmp_buf, 16); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + // add some stuff to normal salt to make sorted happy + + salt->salt_buf[0] = pbkdf2_sha256->salt_buf[0]; + salt->salt_buf[1] = pbkdf2_sha256->salt_buf[1]; + salt->salt_buf[2] = pbkdf2_sha256->salt_buf[2]; + salt->salt_buf[3] = pbkdf2_sha256->salt_buf[3]; + salt->salt_buf[4] = salt->salt_iter; + + return (PARSER_OK); +} + +int prestashop_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_11000) || (input_len > DISPLAY_LEN_MAX_11000)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 32 - 1; + + char *salt_buf = input_buf + 32 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int postgresql_auth_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_11100) || (input_len > DISPLAY_LEN_MAX_11100)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_POSTGRESQL_AUTH, input_buf, 10)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *user_pos = input_buf + 10; + + char *salt_pos = strchr (user_pos, '*'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + char *hash_pos = strchr (salt_pos, '*'); + + hash_pos++; + + uint hash_len = input_len - (hash_pos - input_buf); + + if (hash_len != 32) return (PARSER_HASH_LENGTH); + + uint user_len = salt_pos - user_pos - 1; + + uint salt_len = hash_pos - salt_pos - 1; + + if (salt_len != 8) return (PARSER_SALT_LENGTH); + + /* + * store digest + */ + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + digest[0] -= MD5M_A; + digest[1] -= MD5M_B; + digest[2] -= MD5M_C; + digest[3] -= MD5M_D; + + /* + * store salt + */ + + char *salt_buf_ptr = (char *) salt->salt_buf; + + // first 4 bytes are the "challenge" + + salt_buf_ptr[0] = hex_to_u8 ((const u8 *) &salt_pos[0]); + salt_buf_ptr[1] = hex_to_u8 ((const u8 *) &salt_pos[2]); + salt_buf_ptr[2] = hex_to_u8 ((const u8 *) &salt_pos[4]); + salt_buf_ptr[3] = hex_to_u8 ((const u8 *) &salt_pos[6]); + + // append the user name + + user_len = parse_and_store_salt (salt_buf_ptr + 4, user_pos, user_len); + + salt->salt_len = 4 + user_len; + + return (PARSER_OK); +} + +int mysql_auth_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_11200) || (input_len > DISPLAY_LEN_MAX_11200)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_MYSQL_AUTH, input_buf, 9)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + char *salt_pos = input_buf + 9; + + char *hash_pos = strchr (salt_pos, '*'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + hash_pos++; + + uint hash_len = input_len - (hash_pos - input_buf); + + if (hash_len != 40) return (PARSER_HASH_LENGTH); + + uint salt_len = hash_pos - salt_pos - 1; + + if (salt_len != 40) return (PARSER_SALT_LENGTH); + + /* + * store digest + */ + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); + + /* + * store salt + */ + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int bitcoin_wallet_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_11300) || (input_len > DISPLAY_LEN_MAX_11300)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_BITCOIN_WALLET, input_buf, 9)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + bitcoin_wallet_t *bitcoin_wallet = (bitcoin_wallet_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *cry_master_len_pos = input_buf + 9; + + char *cry_master_buf_pos = strchr (cry_master_len_pos, '$'); + + if (cry_master_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 cry_master_len_len = cry_master_buf_pos - cry_master_len_pos; + + cry_master_buf_pos++; + + char *cry_salt_len_pos = strchr (cry_master_buf_pos, '$'); + + if (cry_salt_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 cry_master_buf_len = cry_salt_len_pos - cry_master_buf_pos; + + cry_salt_len_pos++; + + char *cry_salt_buf_pos = strchr (cry_salt_len_pos, '$'); + + if (cry_salt_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 cry_salt_len_len = cry_salt_buf_pos - cry_salt_len_pos; + + cry_salt_buf_pos++; + + char *cry_rounds_pos = strchr (cry_salt_buf_pos, '$'); + + if (cry_rounds_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 cry_salt_buf_len = cry_rounds_pos - cry_salt_buf_pos; + + cry_rounds_pos++; + + char *ckey_len_pos = strchr (cry_rounds_pos, '$'); + + if (ckey_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 cry_rounds_len = ckey_len_pos - cry_rounds_pos; + + ckey_len_pos++; + + char *ckey_buf_pos = strchr (ckey_len_pos, '$'); + + if (ckey_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 ckey_len_len = ckey_buf_pos - ckey_len_pos; + + ckey_buf_pos++; + + char *public_key_len_pos = strchr (ckey_buf_pos, '$'); + + if (public_key_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 ckey_buf_len = public_key_len_pos - ckey_buf_pos; + + public_key_len_pos++; + + char *public_key_buf_pos = strchr (public_key_len_pos, '$'); + + if (public_key_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 public_key_len_len = public_key_buf_pos - public_key_len_pos; + + public_key_buf_pos++; + + u32 public_key_buf_len = input_len - 1 - 7 - 1 - cry_master_len_len - 1 - cry_master_buf_len - 1 - cry_salt_len_len - 1 - cry_salt_buf_len - 1 - cry_rounds_len - 1 - ckey_len_len - 1 - ckey_buf_len - 1 - public_key_len_len - 1; + + const uint cry_master_len = atoi (cry_master_len_pos); + const uint cry_salt_len = atoi (cry_salt_len_pos); + const uint ckey_len = atoi (ckey_len_pos); + const uint public_key_len = atoi (public_key_len_pos); + + if (cry_master_buf_len != cry_master_len) return (PARSER_SALT_VALUE); + if (cry_salt_buf_len != cry_salt_len) return (PARSER_SALT_VALUE); + if (ckey_buf_len != ckey_len) return (PARSER_SALT_VALUE); + if (public_key_buf_len != public_key_len) return (PARSER_SALT_VALUE); + + for (uint i = 0, j = 0; j < cry_master_len; i += 1, j += 8) + { + bitcoin_wallet->cry_master_buf[i] = hex_to_u32 ((const u8 *) &cry_master_buf_pos[j]); + + bitcoin_wallet->cry_master_buf[i] = byte_swap_32 (bitcoin_wallet->cry_master_buf[i]); + } + + for (uint i = 0, j = 0; j < ckey_len; i += 1, j += 8) + { + bitcoin_wallet->ckey_buf[i] = hex_to_u32 ((const u8 *) &ckey_buf_pos[j]); + + bitcoin_wallet->ckey_buf[i] = byte_swap_32 (bitcoin_wallet->ckey_buf[i]); + } + + for (uint i = 0, j = 0; j < public_key_len; i += 1, j += 8) + { + bitcoin_wallet->public_key_buf[i] = hex_to_u32 ((const u8 *) &public_key_buf_pos[j]); + + bitcoin_wallet->public_key_buf[i] = byte_swap_32 (bitcoin_wallet->public_key_buf[i]); + } + + bitcoin_wallet->cry_master_len = cry_master_len / 2; + bitcoin_wallet->ckey_len = ckey_len / 2; + bitcoin_wallet->public_key_len = public_key_len / 2; + + /* + * store digest (should be unique enought, hopefully) + */ + + digest[0] = bitcoin_wallet->cry_master_buf[0]; + digest[1] = bitcoin_wallet->cry_master_buf[1]; + digest[2] = bitcoin_wallet->cry_master_buf[2]; + digest[3] = bitcoin_wallet->cry_master_buf[3]; + + /* + * store salt + */ + + if (cry_rounds_len >= 7) return (PARSER_SALT_VALUE); + + const uint cry_rounds = atoi (cry_rounds_pos); + + salt->salt_iter = cry_rounds - 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + const uint salt_len = parse_and_store_salt (salt_buf_ptr, cry_salt_buf_pos, cry_salt_buf_len); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int sip_auth_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_11400) || (input_len > DISPLAY_LEN_MAX_11400)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SIP_AUTH, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + sip_t *sip = (sip_t *) hash_buf->esalt; + + // work with a temporary copy of input_buf (s.t. we can manipulate it directly) + + char *temp_input_buf = (char *) mymalloc (input_len + 1); + + memcpy (temp_input_buf, input_buf, input_len); + + // URI_server: + + char *URI_server_pos = temp_input_buf + 6; + + char *URI_client_pos = strchr (URI_server_pos, '*'); + + if (URI_client_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + URI_client_pos[0] = 0; + URI_client_pos++; + + uint URI_server_len = strlen (URI_server_pos); + + if (URI_server_len > 512) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + // URI_client: + + char *user_pos = strchr (URI_client_pos, '*'); + + if (user_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + user_pos[0] = 0; + user_pos++; + + uint URI_client_len = strlen (URI_client_pos); + + if (URI_client_len > 512) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + // user: + + char *realm_pos = strchr (user_pos, '*'); + + if (realm_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + realm_pos[0] = 0; + realm_pos++; + + uint user_len = strlen (user_pos); + + if (user_len > 116) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + // realm: + + char *method_pos = strchr (realm_pos, '*'); + + if (method_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + method_pos[0] = 0; + method_pos++; + + uint realm_len = strlen (realm_pos); + + if (realm_len > 116) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + // method: + + char *URI_prefix_pos = strchr (method_pos, '*'); + + if (URI_prefix_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + URI_prefix_pos[0] = 0; + URI_prefix_pos++; + + uint method_len = strlen (method_pos); + + if (method_len > 246) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + // URI_prefix: + + char *URI_resource_pos = strchr (URI_prefix_pos, '*'); + + if (URI_resource_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + URI_resource_pos[0] = 0; + URI_resource_pos++; + + uint URI_prefix_len = strlen (URI_prefix_pos); + + if (URI_prefix_len > 245) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + // URI_resource: + + char *URI_suffix_pos = strchr (URI_resource_pos, '*'); + + if (URI_suffix_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + URI_suffix_pos[0] = 0; + URI_suffix_pos++; + + uint URI_resource_len = strlen (URI_resource_pos); + + if (URI_resource_len < 1 || URI_resource_len > 246) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + // URI_suffix: + + char *nonce_pos = strchr (URI_suffix_pos, '*'); + + if (nonce_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + nonce_pos[0] = 0; + nonce_pos++; + + uint URI_suffix_len = strlen (URI_suffix_pos); + + if (URI_suffix_len > 245) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + // nonce: + + char *nonce_client_pos = strchr (nonce_pos, '*'); + + if (nonce_client_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + nonce_client_pos[0] = 0; + nonce_client_pos++; + + uint nonce_len = strlen (nonce_pos); + + if (nonce_len < 1 || nonce_len > 50) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + // nonce_client: + + char *nonce_count_pos = strchr (nonce_client_pos, '*'); + + if (nonce_count_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + nonce_count_pos[0] = 0; + nonce_count_pos++; + + uint nonce_client_len = strlen (nonce_client_pos); + + if (nonce_client_len > 50) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + // nonce_count: + + char *qop_pos = strchr (nonce_count_pos, '*'); + + if (qop_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + qop_pos[0] = 0; + qop_pos++; + + uint nonce_count_len = strlen (nonce_count_pos); + + if (nonce_count_len > 50) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + // qop: + + char *directive_pos = strchr (qop_pos, '*'); + + if (directive_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + directive_pos[0] = 0; + directive_pos++; + + uint qop_len = strlen (qop_pos); + + if (qop_len > 50) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + // directive + + char *digest_pos = strchr (directive_pos, '*'); + + if (digest_pos == NULL) + { + myfree (temp_input_buf); + + return (PARSER_SEPARATOR_UNMATCHED); + } + + digest_pos[0] = 0; + digest_pos++; + + uint directive_len = strlen (directive_pos); + + if (directive_len != 3) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + if (memcmp (directive_pos, "MD5", 3)) + { + log_info ("ERROR: Only the MD5 directive is currently supported\n"); + + myfree (temp_input_buf); + + return (PARSER_SIP_AUTH_DIRECTIVE); + } + + /* + * first (pre-)compute: HA2 = md5 ($method . ":" . $uri) + */ + + uint md5_len = 0; + + uint md5_max_len = 4 * 64; + + uint md5_remaining_len = md5_max_len; + + uint tmp_md5_buf[64] = { 0 }; + + char *tmp_md5_ptr = (char *) tmp_md5_buf; + + snprintf (tmp_md5_ptr, md5_remaining_len, "%s:", method_pos); + + md5_len += method_len + 1; + tmp_md5_ptr += method_len + 1; + + if (URI_prefix_len > 0) + { + md5_remaining_len = md5_max_len - md5_len; + + snprintf (tmp_md5_ptr, md5_remaining_len + 1, "%s:", URI_prefix_pos); + + md5_len += URI_prefix_len + 1; + tmp_md5_ptr += URI_prefix_len + 1; + } + + md5_remaining_len = md5_max_len - md5_len; + + snprintf (tmp_md5_ptr, md5_remaining_len + 1, "%s", URI_resource_pos); + + md5_len += URI_resource_len; + tmp_md5_ptr += URI_resource_len; + + if (URI_suffix_len > 0) + { + md5_remaining_len = md5_max_len - md5_len; + + snprintf (tmp_md5_ptr, md5_remaining_len + 1, ":%s", URI_suffix_pos); + + md5_len += 1 + URI_suffix_len; + } + + uint tmp_digest[4] = { 0 }; + + md5_complete_no_limit (tmp_digest, tmp_md5_buf, md5_len); + + tmp_digest[0] = byte_swap_32 (tmp_digest[0]); + tmp_digest[1] = byte_swap_32 (tmp_digest[1]); + tmp_digest[2] = byte_swap_32 (tmp_digest[2]); + tmp_digest[3] = byte_swap_32 (tmp_digest[3]); + + /* + * esalt + */ + + char *esalt_buf_ptr = (char *) sip->esalt_buf; + + uint esalt_len = 0; + + uint max_esalt_len = sizeof (sip->esalt_buf); // 151 = (64 + 64 + 55) - 32, where 32 is the hexadecimal MD5 HA1 hash + + // there are 2 possibilities for the esalt: + + if ((strcmp (qop_pos, "auth") == 0) || (strcmp (qop_pos, "auth-int") == 0)) + { + esalt_len = 1 + nonce_len + 1 + nonce_count_len + 1 + nonce_client_len + 1 + qop_len + 1 + 32; + + if (esalt_len > max_esalt_len) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + snprintf (esalt_buf_ptr, max_esalt_len, ":%s:%s:%s:%s:%08x%08x%08x%08x", + nonce_pos, + nonce_count_pos, + nonce_client_pos, + qop_pos, + tmp_digest[0], + tmp_digest[1], + tmp_digest[2], + tmp_digest[3]); + } + else + { + esalt_len = 1 + nonce_len + 1 + 32; + + if (esalt_len > max_esalt_len) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + snprintf (esalt_buf_ptr, max_esalt_len, ":%s:%08x%08x%08x%08x", + nonce_pos, + tmp_digest[0], + tmp_digest[1], + tmp_digest[2], + tmp_digest[3]); + } + + // add 0x80 to esalt + + esalt_buf_ptr[esalt_len] = 0x80; + + sip->esalt_len = esalt_len; + + /* + * actual salt + */ + + char *sip_salt_ptr = (char *) sip->salt_buf; + + uint salt_len = user_len + 1 + realm_len + 1; + + uint max_salt_len = 119; + + if (salt_len > max_salt_len) + { + myfree (temp_input_buf); + + return (PARSER_SALT_LENGTH); + } + + snprintf (sip_salt_ptr, max_salt_len + 1, "%s:%s:", user_pos, realm_pos); + + sip->salt_len = salt_len; + + /* + * fake salt (for sorting) + */ + + char *salt_buf_ptr = (char *) salt->salt_buf; + + max_salt_len = 55; + + uint fake_salt_len = salt_len; + + if (fake_salt_len > max_salt_len) + { + fake_salt_len = max_salt_len; + } + + snprintf (salt_buf_ptr, max_salt_len + 1, "%s:%s:", user_pos, realm_pos); + + salt->salt_len = fake_salt_len; + + /* + * digest + */ + + digest[0] = hex_to_u32 ((const u8 *) &digest_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &digest_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &digest_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &digest_pos[24]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + myfree (temp_input_buf); + + return (PARSER_OK); +} + +int crc32_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_11500) || (input_len > DISPLAY_LEN_MAX_11500)) return (PARSER_GLOBAL_LENGTH); + + if (input_buf[8] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + // digest + + char *digest_pos = input_buf; + + digest[0] = hex_to_u32 ((const u8 *) &digest_pos[0]); + digest[1] = 0; + digest[2] = 0; + digest[3] = 0; + + // salt + + char *salt_buf = input_buf + 8 + 1; + + uint salt_len = 8; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + return (PARSER_OK); +} + +int seven_zip_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_11600) || (input_len > DISPLAY_LEN_MAX_11600)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_SEVEN_ZIP, input_buf, 4)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + seven_zip_t *seven_zip = (seven_zip_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *p_buf_pos = input_buf + 4; + + char *NumCyclesPower_pos = strchr (p_buf_pos, '$'); + + if (NumCyclesPower_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 p_buf_len = NumCyclesPower_pos - p_buf_pos; + + NumCyclesPower_pos++; + + char *salt_len_pos = strchr (NumCyclesPower_pos, '$'); + + if (salt_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 NumCyclesPower_len = salt_len_pos - NumCyclesPower_pos; + + salt_len_pos++; + + char *salt_buf_pos = strchr (salt_len_pos, '$'); + + if (salt_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 salt_len_len = salt_buf_pos - salt_len_pos; + + salt_buf_pos++; + + char *iv_len_pos = strchr (salt_buf_pos, '$'); + + if (iv_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 salt_buf_len = iv_len_pos - salt_buf_pos; + + iv_len_pos++; + + char *iv_buf_pos = strchr (iv_len_pos, '$'); + + if (iv_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 iv_len_len = iv_buf_pos - iv_len_pos; + + iv_buf_pos++; + + char *crc_buf_pos = strchr (iv_buf_pos, '$'); + + if (crc_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 iv_buf_len = crc_buf_pos - iv_buf_pos; + + crc_buf_pos++; + + char *data_len_pos = strchr (crc_buf_pos, '$'); + + if (data_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 crc_buf_len = data_len_pos - crc_buf_pos; + + data_len_pos++; + + char *unpack_size_pos = strchr (data_len_pos, '$'); + + if (unpack_size_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 data_len_len = unpack_size_pos - data_len_pos; + + unpack_size_pos++; + + char *data_buf_pos = strchr (unpack_size_pos, '$'); + + if (data_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 unpack_size_len = data_buf_pos - unpack_size_pos; + + data_buf_pos++; + + u32 data_buf_len = input_len - 1 - 2 - 1 - p_buf_len - 1 - NumCyclesPower_len - 1 - salt_len_len - 1 - salt_buf_len - 1 - iv_len_len - 1 - iv_buf_len - 1 - crc_buf_len - 1 - data_len_len - 1 - unpack_size_len - 1; + + const uint iter = atoi (NumCyclesPower_pos); + const uint crc = atoi (crc_buf_pos); + const uint p_buf = atoi (p_buf_pos); + const uint salt_len = atoi (salt_len_pos); + const uint iv_len = atoi (iv_len_pos); + const uint unpack_size = atoi (unpack_size_pos); + const uint data_len = atoi (data_len_pos); + + /** + * verify some data + */ + + if (p_buf != 0) return (PARSER_SALT_VALUE); + if (salt_len != 0) return (PARSER_SALT_VALUE); + + if ((data_len * 2) != data_buf_len) return (PARSER_SALT_VALUE); + + if (data_len > 384) return (PARSER_SALT_VALUE); + + if (unpack_size > data_len) return (PARSER_SALT_VALUE); + + /** + * store data + */ + + seven_zip->iv_buf[0] = hex_to_u32 ((const u8 *) &iv_buf_pos[ 0]); + seven_zip->iv_buf[1] = hex_to_u32 ((const u8 *) &iv_buf_pos[ 8]); + seven_zip->iv_buf[2] = hex_to_u32 ((const u8 *) &iv_buf_pos[16]); + seven_zip->iv_buf[3] = hex_to_u32 ((const u8 *) &iv_buf_pos[24]); + + seven_zip->iv_len = iv_len; + + memcpy (seven_zip->salt_buf, salt_buf_pos, salt_buf_len); // we just need that for later ascii_digest() + + seven_zip->salt_len = 0; + + seven_zip->crc = crc; + + for (uint i = 0, j = 0; j < data_buf_len; i += 1, j += 8) + { + seven_zip->data_buf[i] = hex_to_u32 ((const u8 *) &data_buf_pos[j]); + + seven_zip->data_buf[i] = byte_swap_32 (seven_zip->data_buf[i]); + } + + seven_zip->data_len = data_len; + + seven_zip->unpack_size = unpack_size; + + // real salt + + salt->salt_buf[0] = seven_zip->data_buf[0]; + salt->salt_buf[1] = seven_zip->data_buf[1]; + salt->salt_buf[2] = seven_zip->data_buf[2]; + salt->salt_buf[3] = seven_zip->data_buf[3]; + + salt->salt_len = 16; + + salt->salt_sign[0] = iter; + + salt->salt_iter = 1u << iter; + + /** + * digest + */ + + digest[0] = crc; + digest[1] = 0; + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int gost2012sbog_256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_11700) || (input_len > DISPLAY_LEN_MAX_11700)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); + digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); + digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + digest[4] = byte_swap_32 (digest[4]); + digest[5] = byte_swap_32 (digest[5]); + digest[6] = byte_swap_32 (digest[6]); + digest[7] = byte_swap_32 (digest[7]); + + return (PARSER_OK); +} + +int gost2012sbog_512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_11800) || (input_len > DISPLAY_LEN_MAX_11800)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + digest[ 0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[ 1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[ 2] = hex_to_u32 ((const u8 *) &input_buf[ 16]); + digest[ 3] = hex_to_u32 ((const u8 *) &input_buf[ 24]); + digest[ 4] = hex_to_u32 ((const u8 *) &input_buf[ 32]); + digest[ 5] = hex_to_u32 ((const u8 *) &input_buf[ 40]); + digest[ 6] = hex_to_u32 ((const u8 *) &input_buf[ 48]); + digest[ 7] = hex_to_u32 ((const u8 *) &input_buf[ 56]); + digest[ 8] = hex_to_u32 ((const u8 *) &input_buf[ 64]); + digest[ 9] = hex_to_u32 ((const u8 *) &input_buf[ 72]); + digest[10] = hex_to_u32 ((const u8 *) &input_buf[ 80]); + digest[11] = hex_to_u32 ((const u8 *) &input_buf[ 88]); + digest[12] = hex_to_u32 ((const u8 *) &input_buf[ 96]); + digest[13] = hex_to_u32 ((const u8 *) &input_buf[104]); + digest[14] = hex_to_u32 ((const u8 *) &input_buf[112]); + digest[15] = hex_to_u32 ((const u8 *) &input_buf[120]); + + digest[ 0] = byte_swap_32 (digest[ 0]); + digest[ 1] = byte_swap_32 (digest[ 1]); + digest[ 2] = byte_swap_32 (digest[ 2]); + digest[ 3] = byte_swap_32 (digest[ 3]); + digest[ 4] = byte_swap_32 (digest[ 4]); + digest[ 5] = byte_swap_32 (digest[ 5]); + digest[ 6] = byte_swap_32 (digest[ 6]); + digest[ 7] = byte_swap_32 (digest[ 7]); + digest[ 8] = byte_swap_32 (digest[ 8]); + digest[ 9] = byte_swap_32 (digest[ 9]); + digest[10] = byte_swap_32 (digest[10]); + digest[11] = byte_swap_32 (digest[11]); + digest[12] = byte_swap_32 (digest[12]); + digest[13] = byte_swap_32 (digest[13]); + digest[14] = byte_swap_32 (digest[14]); + digest[15] = byte_swap_32 (digest[15]); + + return (PARSER_OK); +} + +int pbkdf2_md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_11900) || (input_len > DISPLAY_LEN_MAX_11900)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_PBKDF2_MD5, input_buf, 4)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pbkdf2_md5_t *pbkdf2_md5 = (pbkdf2_md5_t *) hash_buf->esalt; + + /** + * parse line + */ + + // iterations + + char *iter_pos = input_buf + 4; + + u32 iter = atoi (iter_pos); + + if (iter < 1) return (PARSER_SALT_ITERATION); + if (iter > 999999) return (PARSER_SALT_ITERATION); + + // first is *raw* salt + + char *salt_pos = strchr (iter_pos, ':'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + char *hash_pos = strchr (salt_pos, ':'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 salt_len = hash_pos - salt_pos; + + if (salt_len > 64) return (PARSER_SALT_LENGTH); + + hash_pos++; + + u32 hash_b64_len = input_len - (hash_pos - input_buf); + + if (hash_b64_len > 88) return (PARSER_HASH_LENGTH); + + // decode salt + + char *salt_buf_ptr = (char *) pbkdf2_md5->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt_buf_ptr[salt_len + 3] = 0x01; + salt_buf_ptr[salt_len + 4] = 0x80; + + salt->salt_len = salt_len; + salt->salt_iter = iter - 1; + + // decode hash + + u8 tmp_buf[100] = { 0 }; + + int hash_len = base64_decode (base64_to_int, (const u8 *) hash_pos, hash_b64_len, tmp_buf); + + if (hash_len < 16) return (PARSER_HASH_LENGTH); + + memcpy (digest, tmp_buf, 16); + + // add some stuff to normal salt to make sorted happy + + salt->salt_buf[0] = pbkdf2_md5->salt_buf[0]; + salt->salt_buf[1] = pbkdf2_md5->salt_buf[1]; + salt->salt_buf[2] = pbkdf2_md5->salt_buf[2]; + salt->salt_buf[3] = pbkdf2_md5->salt_buf[3]; + salt->salt_buf[4] = salt->salt_iter; + + return (PARSER_OK); +} + +int pbkdf2_sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_12000) || (input_len > DISPLAY_LEN_MAX_12000)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_PBKDF2_SHA1, input_buf, 5)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pbkdf2_sha1_t *pbkdf2_sha1 = (pbkdf2_sha1_t *) hash_buf->esalt; + + /** + * parse line + */ + + // iterations + + char *iter_pos = input_buf + 5; + + u32 iter = atoi (iter_pos); + + if (iter < 1) return (PARSER_SALT_ITERATION); + if (iter > 999999) return (PARSER_SALT_ITERATION); + + // first is *raw* salt + + char *salt_pos = strchr (iter_pos, ':'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + char *hash_pos = strchr (salt_pos, ':'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 salt_len = hash_pos - salt_pos; + + if (salt_len > 64) return (PARSER_SALT_LENGTH); + + hash_pos++; + + u32 hash_b64_len = input_len - (hash_pos - input_buf); + + if (hash_b64_len > 88) return (PARSER_HASH_LENGTH); + + // decode salt + + char *salt_buf_ptr = (char *) pbkdf2_sha1->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt_buf_ptr[salt_len + 3] = 0x01; + salt_buf_ptr[salt_len + 4] = 0x80; + + salt->salt_len = salt_len; + salt->salt_iter = iter - 1; + + // decode hash + + u8 tmp_buf[100] = { 0 }; + + int hash_len = base64_decode (base64_to_int, (const u8 *) hash_pos, hash_b64_len, tmp_buf); + + if (hash_len < 16) return (PARSER_HASH_LENGTH); + + memcpy (digest, tmp_buf, 16); + + digest[0] = byte_swap_32 (digest[0]); + digest[1] = byte_swap_32 (digest[1]); + digest[2] = byte_swap_32 (digest[2]); + digest[3] = byte_swap_32 (digest[3]); + + // add some stuff to normal salt to make sorted happy + + salt->salt_buf[0] = pbkdf2_sha1->salt_buf[0]; + salt->salt_buf[1] = pbkdf2_sha1->salt_buf[1]; + salt->salt_buf[2] = pbkdf2_sha1->salt_buf[2]; + salt->salt_buf[3] = pbkdf2_sha1->salt_buf[3]; + salt->salt_buf[4] = salt->salt_iter; + + return (PARSER_OK); +} + +int pbkdf2_sha512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_12100) || (input_len > DISPLAY_LEN_MAX_12100)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_PBKDF2_SHA512, input_buf, 7)) return (PARSER_SIGNATURE_UNMATCHED); + + u64 *digest = (u64 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + pbkdf2_sha512_t *pbkdf2_sha512 = (pbkdf2_sha512_t *) hash_buf->esalt; + + /** + * parse line + */ + + // iterations + + char *iter_pos = input_buf + 7; + + u32 iter = atoi (iter_pos); + + if (iter < 1) return (PARSER_SALT_ITERATION); + if (iter > 999999) return (PARSER_SALT_ITERATION); + + // first is *raw* salt + + char *salt_pos = strchr (iter_pos, ':'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + salt_pos++; + + char *hash_pos = strchr (salt_pos, ':'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 salt_len = hash_pos - salt_pos; + + if (salt_len > 64) return (PARSER_SALT_LENGTH); + + hash_pos++; + + u32 hash_b64_len = input_len - (hash_pos - input_buf); + + if (hash_b64_len > 88) return (PARSER_HASH_LENGTH); + + // decode salt + + char *salt_buf_ptr = (char *) pbkdf2_sha512->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt_buf_ptr[salt_len + 3] = 0x01; + salt_buf_ptr[salt_len + 4] = 0x80; + + salt->salt_len = salt_len; + salt->salt_iter = iter - 1; + + // decode hash + + u8 tmp_buf[100] = { 0 }; + + int hash_len = base64_decode (base64_to_int, (const u8 *) hash_pos, hash_b64_len, tmp_buf); + + if (hash_len < 16) return (PARSER_HASH_LENGTH); + + memcpy (digest, tmp_buf, 64); + + digest[0] = byte_swap_64 (digest[0]); + digest[1] = byte_swap_64 (digest[1]); + digest[2] = byte_swap_64 (digest[2]); + digest[3] = byte_swap_64 (digest[3]); + digest[4] = byte_swap_64 (digest[4]); + digest[5] = byte_swap_64 (digest[5]); + digest[6] = byte_swap_64 (digest[6]); + digest[7] = byte_swap_64 (digest[7]); + + // add some stuff to normal salt to make sorted happy + + salt->salt_buf[0] = pbkdf2_sha512->salt_buf[0]; + salt->salt_buf[1] = pbkdf2_sha512->salt_buf[1]; + salt->salt_buf[2] = pbkdf2_sha512->salt_buf[2]; + salt->salt_buf[3] = pbkdf2_sha512->salt_buf[3]; + salt->salt_buf[4] = salt->salt_iter; + + return (PARSER_OK); +} + +int ecryptfs_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_12200) || (input_len > DISPLAY_LEN_MAX_12200)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_ECRYPTFS, input_buf, 10)) return (PARSER_SIGNATURE_UNMATCHED); + + uint *digest = (uint *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + /** + * parse line + */ + + char *salt_pos = input_buf + 10 + 2 + 2; // skip over "0$" and "1$" + + char *hash_pos = strchr (salt_pos, '$'); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 salt_len = hash_pos - salt_pos; + + if (salt_len != 16) return (PARSER_SALT_LENGTH); + + hash_pos++; + + u32 hash_len = input_len - 10 - 2 - 2 - salt_len - 1; + + if (hash_len != 16) return (PARSER_HASH_LENGTH); + + // decode hash + + digest[ 0] = hex_to_u32 ((const u8 *) &hash_pos[0]); + digest[ 1] = hex_to_u32 ((const u8 *) &hash_pos[8]); + digest[ 2] = 0; + digest[ 3] = 0; + digest[ 4] = 0; + digest[ 5] = 0; + digest[ 6] = 0; + digest[ 7] = 0; + digest[ 8] = 0; + digest[ 9] = 0; + digest[10] = 0; + digest[11] = 0; + digest[12] = 0; + digest[13] = 0; + digest[14] = 0; + digest[15] = 0; + + // decode salt + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_pos[8]); + + salt->salt_iter = ROUNDS_ECRYPTFS; + salt->salt_len = 8; + + return (PARSER_OK); +} + +int bsdicrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_12400) || (input_len > DISPLAY_LEN_MAX_12400)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_BSDICRYPT, input_buf, 1)) return (PARSER_SIGNATURE_UNMATCHED); + + unsigned char c19 = itoa64_to_int (input_buf[19]); + + if (c19 & 3) return (PARSER_HASH_VALUE); + + salt_t *salt = hash_buf->salt; + + u32 *digest = (u32 *) hash_buf->digest; + + // iteration count + + salt->salt_iter = itoa64_to_int (input_buf[1]) + | itoa64_to_int (input_buf[2]) << 6 + | itoa64_to_int (input_buf[3]) << 12 + | itoa64_to_int (input_buf[4]) << 18; + + // set salt + + salt->salt_buf[0] = itoa64_to_int (input_buf[5]) + | itoa64_to_int (input_buf[6]) << 6 + | itoa64_to_int (input_buf[7]) << 12 + | itoa64_to_int (input_buf[8]) << 18; + + salt->salt_len = 4; + + u8 tmp_buf[100] = { 0 }; + + base64_decode (itoa64_to_int, (const u8 *) input_buf + 9, 11, tmp_buf); + + memcpy (digest, tmp_buf, 8); + + uint tt; + + IP (digest[0], digest[1], tt); + + digest[0] = rotr32 (digest[0], 31); + digest[1] = rotr32 (digest[1], 31); + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int rar3hp_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_12500) || (input_len > DISPLAY_LEN_MAX_12500)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_RAR3, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + /** + * parse line + */ + + char *type_pos = input_buf + 6 + 1; + + char *salt_pos = strchr (type_pos, '*'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 type_len = salt_pos - type_pos; + + if (type_len != 1) return (PARSER_SALT_LENGTH); + + salt_pos++; + + char *crypted_pos = strchr (salt_pos, '*'); + + if (crypted_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 salt_len = crypted_pos - salt_pos; + + if (salt_len != 16) return (PARSER_SALT_LENGTH); + + crypted_pos++; + + u32 crypted_len = input_len - 6 - 1 - type_len - 1 - salt_len - 1; + + if (crypted_len != 32) return (PARSER_SALT_LENGTH); + + /** + * copy data + */ + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_pos[8]); + + salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); + salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); + + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &crypted_pos[ 0]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &crypted_pos[ 8]); + salt->salt_buf[4] = hex_to_u32 ((const u8 *) &crypted_pos[16]); + salt->salt_buf[5] = hex_to_u32 ((const u8 *) &crypted_pos[24]); + + salt->salt_len = 24; + salt->salt_iter = ROUNDS_RAR3; + + // there's no hash for rar3. the data which is in crypted_pos is some encrypted data and + // if it matches the value \xc4\x3d\x7b\x00\x40\x07\x00 after decrypt we know that we successfully cracked it. + + digest[0] = 0xc43d7b00; + digest[1] = 0x40070000; + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int rar5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_13000) || (input_len > DISPLAY_LEN_MAX_13000)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_RAR5, input_buf, 1 + 4 + 1)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + rar5_t *rar5 = (rar5_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *param0_pos = input_buf + 1 + 4 + 1; + + char *param1_pos = strchr (param0_pos, '$'); + + if (param1_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param0_len = param1_pos - param0_pos; + + param1_pos++; + + char *param2_pos = strchr (param1_pos, '$'); + + if (param2_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param1_len = param2_pos - param1_pos; + + param2_pos++; + + char *param3_pos = strchr (param2_pos, '$'); + + if (param3_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param2_len = param3_pos - param2_pos; + + param3_pos++; + + char *param4_pos = strchr (param3_pos, '$'); + + if (param4_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param3_len = param4_pos - param3_pos; + + param4_pos++; + + char *param5_pos = strchr (param4_pos, '$'); + + if (param5_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param4_len = param5_pos - param4_pos; + + param5_pos++; + + u32 param5_len = input_len - 1 - 4 - 1 - param0_len - 1 - param1_len - 1 - param2_len - 1 - param3_len - 1 - param4_len - 1; + + char *salt_buf = param1_pos; + char *iv = param3_pos; + char *pswcheck = param5_pos; + + const uint salt_len = atoi (param0_pos); + const uint iterations = atoi (param2_pos); + const uint pswcheck_len = atoi (param4_pos); + + /** + * verify some data + */ + + if (param1_len != 32) return (PARSER_SALT_VALUE); + if (param3_len != 32) return (PARSER_SALT_VALUE); + if (param5_len != 16) return (PARSER_SALT_VALUE); + + if (salt_len != 16) return (PARSER_SALT_VALUE); + if (iterations == 0) return (PARSER_SALT_VALUE); + if (pswcheck_len != 8) return (PARSER_SALT_VALUE); + + /** + * store data + */ + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_buf[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_buf[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_buf[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &salt_buf[24]); + + rar5->iv[0] = hex_to_u32 ((const u8 *) &iv[ 0]); + rar5->iv[1] = hex_to_u32 ((const u8 *) &iv[ 8]); + rar5->iv[2] = hex_to_u32 ((const u8 *) &iv[16]); + rar5->iv[3] = hex_to_u32 ((const u8 *) &iv[24]); + + salt->salt_len = 16; + + salt->salt_sign[0] = iterations; + + salt->salt_iter = ((1u << iterations) + 32) - 1; + + /** + * digest buf + */ + + digest[0] = hex_to_u32 ((const u8 *) &pswcheck[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &pswcheck[ 8]); + digest[2] = 0; + digest[3] = 0; + + return (PARSER_OK); +} + +int krb5tgs_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_13100) || (input_len > DISPLAY_LEN_MAX_13100)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_KRB5TGS, input_buf, 11)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + krb5tgs_t *krb5tgs = (krb5tgs_t *) hash_buf->esalt; + + /** + * parse line + */ + + /* Skip '$' */ + char *account_pos = input_buf + 11 + 1; + + char *data_pos; + + uint data_len; + + if (account_pos[0] == '*') + { + account_pos++; + + data_pos = strchr (account_pos, '*'); + + /* Skip '*' */ + data_pos++; + + if (data_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint account_len = data_pos - account_pos + 1; + + if (account_len >= 512) return (PARSER_SALT_LENGTH); + + /* Skip '$' */ + data_pos++; + + data_len = input_len - 11 - 1 - account_len - 2; + + memcpy (krb5tgs->account_info, account_pos - 1, account_len); + } + else + { + /* assume $krb5tgs$23$checksum$edata2 */ + data_pos = account_pos; + + memcpy (krb5tgs->account_info, "**", 3); + + data_len = input_len - 11 - 1 - 1; + } + + if (data_len < ((16 + 32) * 2)) return (PARSER_SALT_LENGTH); + + char *checksum_ptr = (char *) krb5tgs->checksum; + + for (uint i = 0; i < 16 * 2; i += 2) + { + const char p0 = data_pos[i + 0]; + const char p1 = data_pos[i + 1]; + + *checksum_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + char *edata_ptr = (char *) krb5tgs->edata2; + + krb5tgs->edata2_len = (data_len - 32) / 2 ; + + /* skip '$' */ + for (uint i = 16 * 2 + 1; i < (krb5tgs->edata2_len * 2) + (16 * 2 + 1); i += 2) + { + const char p0 = data_pos[i + 0]; + const char p1 = data_pos[i + 1]; + *edata_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + } + + /* this is needed for hmac_md5 */ + *edata_ptr++ = 0x80; + + salt->salt_buf[0] = krb5tgs->checksum[0]; + salt->salt_buf[1] = krb5tgs->checksum[1]; + salt->salt_buf[2] = krb5tgs->checksum[2]; + salt->salt_buf[3] = krb5tgs->checksum[3]; + + salt->salt_len = 32; + + digest[0] = krb5tgs->checksum[0]; + digest[1] = krb5tgs->checksum[1]; + digest[2] = krb5tgs->checksum[2]; + digest[3] = krb5tgs->checksum[3]; + + return (PARSER_OK); +} + +int axcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_13200) || (input_len > DISPLAY_LEN_MAX_13200)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_AXCRYPT, input_buf, 11)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + /** + * parse line + */ + + /* Skip '*' */ + char *wrapping_rounds_pos = input_buf + 11 + 1; + + char *salt_pos; + + char *wrapped_key_pos; + + char *data_pos; + + salt->salt_iter = atoi (wrapping_rounds_pos); + + salt_pos = strchr (wrapping_rounds_pos, '*'); + + if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint wrapping_rounds_len = salt_pos - wrapping_rounds_pos; + + /* Skip '*' */ + salt_pos++; + + data_pos = salt_pos; + + wrapped_key_pos = strchr (salt_pos, '*'); + + if (wrapped_key_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = wrapped_key_pos - salt_pos; + + if (salt_len != 32) return (PARSER_SALT_LENGTH); + + /* Skip '*' */ + wrapped_key_pos++; + + uint wrapped_key_len = input_len - 11 - 1 - wrapping_rounds_len - 1 - salt_len - 1; + + if (wrapped_key_len != 48) return (PARSER_SALT_LENGTH); + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &data_pos[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &data_pos[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &data_pos[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &data_pos[24]); + + data_pos += 33; + + salt->salt_buf[4] = hex_to_u32 ((const u8 *) &data_pos[ 0]); + salt->salt_buf[5] = hex_to_u32 ((const u8 *) &data_pos[ 8]); + salt->salt_buf[6] = hex_to_u32 ((const u8 *) &data_pos[16]); + salt->salt_buf[7] = hex_to_u32 ((const u8 *) &data_pos[24]); + salt->salt_buf[8] = hex_to_u32 ((const u8 *) &data_pos[32]); + salt->salt_buf[9] = hex_to_u32 ((const u8 *) &data_pos[40]); + + salt->salt_len = 40; + + digest[0] = salt->salt_buf[0]; + digest[1] = salt->salt_buf[1]; + digest[2] = salt->salt_buf[2]; + digest[3] = salt->salt_buf[3]; + + return (PARSER_OK); +} + +int keepass_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_13400) || (input_len > DISPLAY_LEN_MAX_13400)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_KEEPASS, input_buf, 9)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + keepass_t *keepass = (keepass_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *version_pos; + + char *rounds_pos; + + char *algorithm_pos; + + char *final_random_seed_pos; + u32 final_random_seed_len; + + char *transf_random_seed_pos; + u32 transf_random_seed_len; + + char *enc_iv_pos; + u32 enc_iv_len; + + /* default is no keyfile provided */ + char *keyfile_len_pos; + u32 keyfile_len = 0; + u32 is_keyfile_present = 0; + char *keyfile_inline_pos; + char *keyfile_pos; + + /* specific to version 1 */ + char *contents_len_pos; + u32 contents_len; + char *contents_pos; + + /* specific to version 2 */ + char *expected_bytes_pos; + u32 expected_bytes_len; + + char *contents_hash_pos; + u32 contents_hash_len; + + version_pos = input_buf + 8 + 1 + 1; + + keepass->version = atoi (version_pos); + + rounds_pos = strchr (version_pos, '*'); + + if (rounds_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + rounds_pos++; + + salt->salt_iter = (atoi (rounds_pos)); + + algorithm_pos = strchr (rounds_pos, '*'); + + if (algorithm_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + algorithm_pos++; + + keepass->algorithm = atoi (algorithm_pos); + + final_random_seed_pos = strchr (algorithm_pos, '*'); + + if (final_random_seed_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + final_random_seed_pos++; + + keepass->final_random_seed[0] = hex_to_u32 ((const u8 *) &final_random_seed_pos[ 0]); + keepass->final_random_seed[1] = hex_to_u32 ((const u8 *) &final_random_seed_pos[ 8]); + keepass->final_random_seed[2] = hex_to_u32 ((const u8 *) &final_random_seed_pos[16]); + keepass->final_random_seed[3] = hex_to_u32 ((const u8 *) &final_random_seed_pos[24]); + + if (keepass->version == 2) + { + keepass->final_random_seed[4] = hex_to_u32 ((const u8 *) &final_random_seed_pos[32]); + keepass->final_random_seed[5] = hex_to_u32 ((const u8 *) &final_random_seed_pos[40]); + keepass->final_random_seed[6] = hex_to_u32 ((const u8 *) &final_random_seed_pos[48]); + keepass->final_random_seed[7] = hex_to_u32 ((const u8 *) &final_random_seed_pos[56]); + } + + transf_random_seed_pos = strchr (final_random_seed_pos, '*'); + + if (transf_random_seed_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + final_random_seed_len = transf_random_seed_pos - final_random_seed_pos; + + if (keepass->version == 1 && final_random_seed_len != 32) return (PARSER_SALT_LENGTH); + if (keepass->version == 2 && final_random_seed_len != 64) return (PARSER_SALT_LENGTH); + + transf_random_seed_pos++; + + keepass->transf_random_seed[0] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[ 0]); + keepass->transf_random_seed[1] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[ 8]); + keepass->transf_random_seed[2] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[16]); + keepass->transf_random_seed[3] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[24]); + keepass->transf_random_seed[4] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[32]); + keepass->transf_random_seed[5] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[40]); + keepass->transf_random_seed[6] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[48]); + keepass->transf_random_seed[7] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[56]); + + enc_iv_pos = strchr (transf_random_seed_pos, '*'); + + if (enc_iv_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + transf_random_seed_len = enc_iv_pos - transf_random_seed_pos; + + if (transf_random_seed_len != 64) return (PARSER_SALT_LENGTH); + + enc_iv_pos++; + + keepass->enc_iv[0] = hex_to_u32 ((const u8 *) &enc_iv_pos[ 0]); + keepass->enc_iv[1] = hex_to_u32 ((const u8 *) &enc_iv_pos[ 8]); + keepass->enc_iv[2] = hex_to_u32 ((const u8 *) &enc_iv_pos[16]); + keepass->enc_iv[3] = hex_to_u32 ((const u8 *) &enc_iv_pos[24]); + + if (keepass->version == 1) + { + contents_hash_pos = strchr (enc_iv_pos, '*'); + + if (contents_hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + enc_iv_len = contents_hash_pos - enc_iv_pos; + + if (enc_iv_len != 32) return (PARSER_SALT_LENGTH); + + contents_hash_pos++; + + keepass->contents_hash[0] = hex_to_u32 ((const u8 *) &contents_hash_pos[ 0]); + keepass->contents_hash[1] = hex_to_u32 ((const u8 *) &contents_hash_pos[ 8]); + keepass->contents_hash[2] = hex_to_u32 ((const u8 *) &contents_hash_pos[16]); + keepass->contents_hash[3] = hex_to_u32 ((const u8 *) &contents_hash_pos[24]); + keepass->contents_hash[4] = hex_to_u32 ((const u8 *) &contents_hash_pos[32]); + keepass->contents_hash[5] = hex_to_u32 ((const u8 *) &contents_hash_pos[40]); + keepass->contents_hash[6] = hex_to_u32 ((const u8 *) &contents_hash_pos[48]); + keepass->contents_hash[7] = hex_to_u32 ((const u8 *) &contents_hash_pos[56]); + + /* get length of contents following */ + char *inline_flag_pos = strchr (contents_hash_pos, '*'); + + if (inline_flag_pos == NULL) return (PARSER_SALT_LENGTH); + + contents_hash_len = inline_flag_pos - contents_hash_pos; + + if (contents_hash_len != 64) return (PARSER_SALT_LENGTH); + + inline_flag_pos++; + + u32 inline_flag = atoi (inline_flag_pos); + + if (inline_flag != 1) return (PARSER_SALT_LENGTH); + + contents_len_pos = strchr (inline_flag_pos, '*'); + + if (contents_len_pos == NULL) return (PARSER_SALT_LENGTH); + + contents_len_pos++; + + contents_len = atoi (contents_len_pos); + + if (contents_len > 50000) return (PARSER_SALT_LENGTH); + + contents_pos = strchr (contents_len_pos, '*'); + + if (contents_pos == NULL) return (PARSER_SALT_LENGTH); + + contents_pos++; + + u32 i; + + keepass->contents_len = contents_len; + + contents_len = contents_len / 4; + + keyfile_inline_pos = strchr (contents_pos, '*'); + + u32 real_contents_len; + + if (keyfile_inline_pos == NULL) + real_contents_len = input_len - (contents_pos - input_buf); + else + { + real_contents_len = keyfile_inline_pos - contents_pos; + keyfile_inline_pos++; + is_keyfile_present = 1; + } + + if (real_contents_len != keepass->contents_len * 2) return (PARSER_SALT_LENGTH); + + for (i = 0; i < contents_len; i++) + keepass->contents[i] = hex_to_u32 ((const u8 *) &contents_pos[i * 8]); + } + else if (keepass->version == 2) + { + expected_bytes_pos = strchr (enc_iv_pos, '*'); + + if (expected_bytes_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + enc_iv_len = expected_bytes_pos - enc_iv_pos; + + if (enc_iv_len != 32) return (PARSER_SALT_LENGTH); + + expected_bytes_pos++; + + keepass->expected_bytes[0] = hex_to_u32 ((const u8 *) &expected_bytes_pos[ 0]); + keepass->expected_bytes[1] = hex_to_u32 ((const u8 *) &expected_bytes_pos[ 8]); + keepass->expected_bytes[2] = hex_to_u32 ((const u8 *) &expected_bytes_pos[16]); + keepass->expected_bytes[3] = hex_to_u32 ((const u8 *) &expected_bytes_pos[24]); + keepass->expected_bytes[4] = hex_to_u32 ((const u8 *) &expected_bytes_pos[32]); + keepass->expected_bytes[5] = hex_to_u32 ((const u8 *) &expected_bytes_pos[40]); + keepass->expected_bytes[6] = hex_to_u32 ((const u8 *) &expected_bytes_pos[48]); + keepass->expected_bytes[7] = hex_to_u32 ((const u8 *) &expected_bytes_pos[56]); + + contents_hash_pos = strchr (expected_bytes_pos, '*'); + + if (contents_hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + expected_bytes_len = contents_hash_pos - expected_bytes_pos; + + if (expected_bytes_len != 64) return (PARSER_SALT_LENGTH); + + contents_hash_pos++; + + keepass->contents_hash[0] = hex_to_u32 ((const u8 *) &contents_hash_pos[ 0]); + keepass->contents_hash[1] = hex_to_u32 ((const u8 *) &contents_hash_pos[ 8]); + keepass->contents_hash[2] = hex_to_u32 ((const u8 *) &contents_hash_pos[16]); + keepass->contents_hash[3] = hex_to_u32 ((const u8 *) &contents_hash_pos[24]); + keepass->contents_hash[4] = hex_to_u32 ((const u8 *) &contents_hash_pos[32]); + keepass->contents_hash[5] = hex_to_u32 ((const u8 *) &contents_hash_pos[40]); + keepass->contents_hash[6] = hex_to_u32 ((const u8 *) &contents_hash_pos[48]); + keepass->contents_hash[7] = hex_to_u32 ((const u8 *) &contents_hash_pos[56]); + + keyfile_inline_pos = strchr (contents_hash_pos, '*'); + + if (keyfile_inline_pos == NULL) + contents_hash_len = input_len - (int) (contents_hash_pos - input_buf); + else + { + contents_hash_len = keyfile_inline_pos - contents_hash_pos; + keyfile_inline_pos++; + is_keyfile_present = 1; + } + if (contents_hash_len != 64) return (PARSER_SALT_LENGTH); + } + + if (is_keyfile_present != 0) + { + keyfile_len_pos = strchr (keyfile_inline_pos, '*'); + + keyfile_len_pos++; + + keyfile_len = atoi (keyfile_len_pos); + + keepass->keyfile_len = keyfile_len; + + if (keyfile_len != 64) return (PARSER_SALT_LENGTH); + + keyfile_pos = strchr (keyfile_len_pos, '*'); + + if (keyfile_pos == NULL) return (PARSER_SALT_LENGTH); + + keyfile_pos++; + + u32 real_keyfile_len = input_len - (keyfile_pos - input_buf); + + if (real_keyfile_len != 64) return (PARSER_SALT_LENGTH); + + keepass->keyfile[0] = hex_to_u32 ((const u8 *) &keyfile_pos[ 0]); + keepass->keyfile[1] = hex_to_u32 ((const u8 *) &keyfile_pos[ 8]); + keepass->keyfile[2] = hex_to_u32 ((const u8 *) &keyfile_pos[16]); + keepass->keyfile[3] = hex_to_u32 ((const u8 *) &keyfile_pos[24]); + keepass->keyfile[4] = hex_to_u32 ((const u8 *) &keyfile_pos[32]); + keepass->keyfile[5] = hex_to_u32 ((const u8 *) &keyfile_pos[40]); + keepass->keyfile[6] = hex_to_u32 ((const u8 *) &keyfile_pos[48]); + keepass->keyfile[7] = hex_to_u32 ((const u8 *) &keyfile_pos[56]); + } + + digest[0] = keepass->enc_iv[0]; + digest[1] = keepass->enc_iv[1]; + digest[2] = keepass->enc_iv[2]; + digest[3] = keepass->enc_iv[3]; + + salt->salt_buf[0] = keepass->transf_random_seed[0]; + salt->salt_buf[1] = keepass->transf_random_seed[1]; + salt->salt_buf[2] = keepass->transf_random_seed[2]; + salt->salt_buf[3] = keepass->transf_random_seed[3]; + salt->salt_buf[4] = keepass->transf_random_seed[4]; + salt->salt_buf[5] = keepass->transf_random_seed[5]; + salt->salt_buf[6] = keepass->transf_random_seed[6]; + salt->salt_buf[7] = keepass->transf_random_seed[7]; + + return (PARSER_OK); +} + +int cf10_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_12600) || (input_len > DISPLAY_LEN_MAX_12600)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); + digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); + digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); + + if (input_buf[64] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + uint salt_len = input_len - 64 - 1; + + char *salt_buf = input_buf + 64 + 1; + + char *salt_buf_ptr = (char *) salt->salt_buf; + + salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); + + if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); + + salt->salt_len = salt_len; + + /** + * we can precompute the first sha256 transform + */ + + uint w[16] = { 0 }; + + w[ 0] = byte_swap_32 (salt->salt_buf[ 0]); + w[ 1] = byte_swap_32 (salt->salt_buf[ 1]); + w[ 2] = byte_swap_32 (salt->salt_buf[ 2]); + w[ 3] = byte_swap_32 (salt->salt_buf[ 3]); + w[ 4] = byte_swap_32 (salt->salt_buf[ 4]); + w[ 5] = byte_swap_32 (salt->salt_buf[ 5]); + w[ 6] = byte_swap_32 (salt->salt_buf[ 6]); + w[ 7] = byte_swap_32 (salt->salt_buf[ 7]); + w[ 8] = byte_swap_32 (salt->salt_buf[ 8]); + w[ 9] = byte_swap_32 (salt->salt_buf[ 9]); + w[10] = byte_swap_32 (salt->salt_buf[10]); + w[11] = byte_swap_32 (salt->salt_buf[11]); + w[12] = byte_swap_32 (salt->salt_buf[12]); + w[13] = byte_swap_32 (salt->salt_buf[13]); + w[14] = byte_swap_32 (salt->salt_buf[14]); + w[15] = byte_swap_32 (salt->salt_buf[15]); + + uint pc256[8] = { SHA256M_A, SHA256M_B, SHA256M_C, SHA256M_D, SHA256M_E, SHA256M_F, SHA256M_G, SHA256M_H }; + + sha256_64 (w, pc256); + + salt->salt_buf_pc[0] = pc256[0]; + salt->salt_buf_pc[1] = pc256[1]; + salt->salt_buf_pc[2] = pc256[2]; + salt->salt_buf_pc[3] = pc256[3]; + salt->salt_buf_pc[4] = pc256[4]; + salt->salt_buf_pc[5] = pc256[5]; + salt->salt_buf_pc[6] = pc256[6]; + salt->salt_buf_pc[7] = pc256[7]; + + digest[0] -= pc256[0]; + digest[1] -= pc256[1]; + digest[2] -= pc256[2]; + digest[3] -= pc256[3]; + digest[4] -= pc256[4]; + digest[5] -= pc256[5]; + digest[6] -= pc256[6]; + digest[7] -= pc256[7]; + + return (PARSER_OK); +} + +int mywallet_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_12700) || (input_len > DISPLAY_LEN_MAX_12700)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_MYWALLET, input_buf, 12)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + /** + * parse line + */ + + char *data_len_pos = input_buf + 1 + 10 + 1; + + char *data_buf_pos = strchr (data_len_pos, '$'); + + if (data_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 data_len_len = data_buf_pos - data_len_pos; + + if (data_len_len < 1) return (PARSER_SALT_LENGTH); + if (data_len_len > 5) return (PARSER_SALT_LENGTH); + + data_buf_pos++; + + u32 data_buf_len = input_len - 1 - 10 - 1 - data_len_len - 1; + + if (data_buf_len < 64) return (PARSER_HASH_LENGTH); + + if (data_buf_len % 16) return (PARSER_HASH_LENGTH); + + u32 data_len = atoi (data_len_pos); + + if ((data_len * 2) != data_buf_len) return (PARSER_HASH_LENGTH); + + /** + * salt + */ + + char *salt_pos = data_buf_pos; + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_pos[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_pos[16]); + salt->salt_buf[3] = hex_to_u32 ((const u8 *) &salt_pos[24]); + + // this is actually the CT, which is also the hash later (if matched) + + salt->salt_buf[4] = hex_to_u32 ((const u8 *) &salt_pos[32]); + salt->salt_buf[5] = hex_to_u32 ((const u8 *) &salt_pos[40]); + salt->salt_buf[6] = hex_to_u32 ((const u8 *) &salt_pos[48]); + salt->salt_buf[7] = hex_to_u32 ((const u8 *) &salt_pos[56]); + + salt->salt_len = 32; // note we need to fix this to 16 in kernel + + salt->salt_iter = 10 - 1; + + /** + * digest buf + */ + + digest[0] = salt->salt_buf[4]; + digest[1] = salt->salt_buf[5]; + digest[2] = salt->salt_buf[6]; + digest[3] = salt->salt_buf[7]; + + return (PARSER_OK); +} + +int ms_drsr_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_12800) || (input_len > DISPLAY_LEN_MAX_12800)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_MS_DRSR, input_buf, 11)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + /** + * parse line + */ + + char *salt_pos = input_buf + 11 + 1; + + char *iter_pos = strchr (salt_pos, ','); + + if (iter_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 salt_len = iter_pos - salt_pos; + + if (salt_len != 20) return (PARSER_SALT_LENGTH); + + iter_pos++; + + char *hash_pos = strchr (iter_pos, ','); + + if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 iter_len = hash_pos - iter_pos; + + if (iter_len > 5) return (PARSER_SALT_LENGTH); + + hash_pos++; + + u32 hash_len = input_len - 11 - 1 - salt_len - 1 - iter_len - 1; + + if (hash_len != 64) return (PARSER_HASH_LENGTH); + + /** + * salt + */ + + salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[ 0]); + salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_pos[ 8]); + salt->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_pos[16]) & 0xffff0000; + salt->salt_buf[3] = 0x00018000; + + salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); + salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); + salt->salt_buf[2] = byte_swap_32 (salt->salt_buf[2]); + salt->salt_buf[3] = byte_swap_32 (salt->salt_buf[3]); + + salt->salt_len = salt_len / 2; + + salt->salt_iter = atoi (iter_pos) - 1u; + + /** + * digest buf + */ + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); + digest[5] = hex_to_u32 ((const u8 *) &hash_pos[40]); + digest[6] = hex_to_u32 ((const u8 *) &hash_pos[48]); + digest[7] = hex_to_u32 ((const u8 *) &hash_pos[56]); + + return (PARSER_OK); +} + +int androidfde_samsung_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_12900) || (input_len > DISPLAY_LEN_MAX_12900)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + /** + * parse line + */ + + char *hash_pos = input_buf + 64; + char *salt1_pos = input_buf + 128; + char *salt2_pos = input_buf; + + /** + * salt + */ + + salt->salt_buf[ 0] = hex_to_u32 ((const u8 *) &salt1_pos[ 0]); + salt->salt_buf[ 1] = hex_to_u32 ((const u8 *) &salt1_pos[ 8]); + salt->salt_buf[ 2] = hex_to_u32 ((const u8 *) &salt1_pos[16]); + salt->salt_buf[ 3] = hex_to_u32 ((const u8 *) &salt1_pos[24]); + + salt->salt_buf[ 4] = hex_to_u32 ((const u8 *) &salt2_pos[ 0]); + salt->salt_buf[ 5] = hex_to_u32 ((const u8 *) &salt2_pos[ 8]); + salt->salt_buf[ 6] = hex_to_u32 ((const u8 *) &salt2_pos[16]); + salt->salt_buf[ 7] = hex_to_u32 ((const u8 *) &salt2_pos[24]); + + salt->salt_buf[ 8] = hex_to_u32 ((const u8 *) &salt2_pos[32]); + salt->salt_buf[ 9] = hex_to_u32 ((const u8 *) &salt2_pos[40]); + salt->salt_buf[10] = hex_to_u32 ((const u8 *) &salt2_pos[48]); + salt->salt_buf[11] = hex_to_u32 ((const u8 *) &salt2_pos[56]); + + salt->salt_len = 48; + + salt->salt_iter = ROUNDS_ANDROIDFDE_SAMSUNG - 1; + + /** + * digest buf + */ + + digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); + digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); + digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); + digest[5] = hex_to_u32 ((const u8 *) &hash_pos[40]); + digest[6] = hex_to_u32 ((const u8 *) &hash_pos[48]); + digest[7] = hex_to_u32 ((const u8 *) &hash_pos[56]); + + return (PARSER_OK); +} + +int zip2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_13600) || (input_len > DISPLAY_LEN_MAX_13600)) return (PARSER_GLOBAL_LENGTH); + + if (memcmp (SIGNATURE_ZIP2_START, input_buf , 6)) return (PARSER_SIGNATURE_UNMATCHED); + if (memcmp (SIGNATURE_ZIP2_STOP , input_buf + input_len - 7, 7)) return (PARSER_SIGNATURE_UNMATCHED); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + zip2_t *zip2 = (zip2_t *) hash_buf->esalt; + + /** + * parse line + */ + + char *param0_pos = input_buf + 6 + 1; + + char *param1_pos = strchr (param0_pos, '*'); + + if (param1_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param0_len = param1_pos - param0_pos; + + param1_pos++; + + char *param2_pos = strchr (param1_pos, '*'); + + if (param2_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param1_len = param2_pos - param1_pos; + + param2_pos++; + + char *param3_pos = strchr (param2_pos, '*'); + + if (param3_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param2_len = param3_pos - param2_pos; + + param3_pos++; + + char *param4_pos = strchr (param3_pos, '*'); + + if (param4_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param3_len = param4_pos - param3_pos; + + param4_pos++; + + char *param5_pos = strchr (param4_pos, '*'); + + if (param5_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param4_len = param5_pos - param4_pos; + + param5_pos++; + + char *param6_pos = strchr (param5_pos, '*'); + + if (param6_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param5_len = param6_pos - param5_pos; + + param6_pos++; + + char *param7_pos = strchr (param6_pos, '*'); + + if (param7_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param6_len = param7_pos - param6_pos; + + param7_pos++; + + char *param8_pos = strchr (param7_pos, '*'); + + if (param8_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); + + u32 param7_len = param8_pos - param7_pos; + + param8_pos++; + + const uint type = atoi (param0_pos); + const uint mode = atoi (param1_pos); + const uint magic = atoi (param2_pos); + + char *salt_buf = param3_pos; + + uint verify_bytes; sscanf (param4_pos, "%4x*", &verify_bytes); + + const uint compress_length = atoi (param5_pos); + + char *data_buf = param6_pos; + char *auth = param7_pos; + + /** + * verify some data + */ + + if (param0_len != 1) return (PARSER_SALT_VALUE); + + if (param1_len != 1) return (PARSER_SALT_VALUE); + + if (param2_len != 1) return (PARSER_SALT_VALUE); + + if ((param3_len != 16) && (param3_len != 24) && (param3_len != 32)) return (PARSER_SALT_VALUE); + + if (param4_len >= 5) return (PARSER_SALT_VALUE); + + if (param5_len >= 5) return (PARSER_SALT_VALUE); + + if (param6_len >= 8192) return (PARSER_SALT_VALUE); + + if (param6_len & 1) return (PARSER_SALT_VALUE); + + if (param7_len != 20) return (PARSER_SALT_VALUE); + + if (type != 0) return (PARSER_SALT_VALUE); + + if ((mode != 1) && (mode != 2) && (mode != 3)) return (PARSER_SALT_VALUE); + + if (magic != 0) return (PARSER_SALT_VALUE); + + if (verify_bytes >= 0x10000) return (PARSER_SALT_VALUE); + + /** + * store data + */ + + zip2->type = type; + zip2->mode = mode; + zip2->magic = magic; + + if (mode == 1) + { + zip2->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_buf[ 0]); + zip2->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_buf[ 8]); + zip2->salt_buf[2] = 0; + zip2->salt_buf[3] = 0; + + zip2->salt_len = 8; + } + else if (mode == 2) + { + zip2->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_buf[ 0]); + zip2->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_buf[ 8]); + zip2->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_buf[16]); + zip2->salt_buf[3] = 0; + + zip2->salt_len = 12; + } + else if (mode == 3) + { + zip2->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_buf[ 0]); + zip2->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_buf[ 8]); + zip2->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_buf[16]); + zip2->salt_buf[3] = hex_to_u32 ((const u8 *) &salt_buf[24]); + + zip2->salt_len = 16; + } + + zip2->salt_buf[0] = byte_swap_32 (zip2->salt_buf[0]); + zip2->salt_buf[1] = byte_swap_32 (zip2->salt_buf[1]); + zip2->salt_buf[2] = byte_swap_32 (zip2->salt_buf[2]); + zip2->salt_buf[3] = byte_swap_32 (zip2->salt_buf[3]); + + zip2->verify_bytes = verify_bytes; + + zip2->compress_length = compress_length; + + char *data_buf_ptr = (char *) zip2->data_buf; + + for (uint i = 0; i < param6_len; i += 2) + { + const char p0 = data_buf[i + 0]; + const char p1 = data_buf[i + 1]; + + *data_buf_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + + zip2->data_len++; + } + + *data_buf_ptr = 0x80; + + char *auth_ptr = (char *) zip2->auth_buf; + + for (uint i = 0; i < param7_len; i += 2) + { + const char p0 = auth[i + 0]; + const char p1 = auth[i + 1]; + + *auth_ptr++ = hex_convert (p1) << 0 + | hex_convert (p0) << 4; + + zip2->auth_len++; + } + + /** + * salt buf (fake) + */ + + salt->salt_buf[0] = zip2->salt_buf[0]; + salt->salt_buf[1] = zip2->salt_buf[1]; + salt->salt_buf[2] = zip2->salt_buf[2]; + salt->salt_buf[3] = zip2->salt_buf[3]; + salt->salt_buf[4] = zip2->data_buf[0]; + salt->salt_buf[5] = zip2->data_buf[1]; + salt->salt_buf[6] = zip2->data_buf[2]; + salt->salt_buf[7] = zip2->data_buf[3]; + + salt->salt_len = 32; + + salt->salt_iter = ROUNDS_ZIP2 - 1; + + /** + * digest buf (fake) + */ + + digest[0] = zip2->auth_buf[0]; + digest[1] = zip2->auth_buf[1]; + digest[2] = zip2->auth_buf[2]; + digest[3] = zip2->auth_buf[3]; + + return (PARSER_OK); +} + +int win8phone_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) +{ + if ((input_len < DISPLAY_LEN_MIN_13800) || (input_len > DISPLAY_LEN_MAX_13800)) return (PARSER_GLOBAL_LENGTH); + + u32 *digest = (u32 *) hash_buf->digest; + + salt_t *salt = hash_buf->salt; + + win8phone_t *esalt = hash_buf->esalt; + + digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); + digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); + digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); + digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); + digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); + digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); + digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); + digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); + + if (input_buf[64] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); + + char *salt_buf_ptr = input_buf + 64 + 1; + + u32 *salt_buf = esalt->salt_buf; + + for (int i = 0, j = 0; i < 32; i += 1, j += 8) + { + salt_buf[i] = hex_to_u32 ((const u8 *) &salt_buf_ptr[j]); + } + + salt->salt_buf[0] = salt_buf[0]; + salt->salt_buf[1] = salt_buf[1]; + salt->salt_buf[2] = salt_buf[2]; + salt->salt_buf[3] = salt_buf[3]; + salt->salt_buf[4] = salt_buf[4]; + salt->salt_buf[5] = salt_buf[5]; + salt->salt_buf[6] = salt_buf[6]; + salt->salt_buf[7] = salt_buf[7]; + + salt->salt_len = 64; + + return (PARSER_OK); +} + +/** + * output + */ + +char *strhashtype (const uint hash_mode) +{ + switch (hash_mode) + { + case 0: return ((char *) HT_00000); + case 10: return ((char *) HT_00010); + case 11: return ((char *) HT_00011); + case 12: return ((char *) HT_00012); + case 20: return ((char *) HT_00020); + case 21: return ((char *) HT_00021); + case 22: return ((char *) HT_00022); + case 23: return ((char *) HT_00023); + case 30: return ((char *) HT_00030); + case 40: return ((char *) HT_00040); + case 50: return ((char *) HT_00050); + case 60: return ((char *) HT_00060); + case 100: return ((char *) HT_00100); + case 101: return ((char *) HT_00101); + case 110: return ((char *) HT_00110); + case 111: return ((char *) HT_00111); + case 112: return ((char *) HT_00112); + case 120: return ((char *) HT_00120); + case 121: return ((char *) HT_00121); + case 122: return ((char *) HT_00122); + case 124: return ((char *) HT_00124); + case 125: return ((char *) HT_00125); + case 130: return ((char *) HT_00130); + case 131: return ((char *) HT_00131); + case 132: return ((char *) HT_00132); + case 133: return ((char *) HT_00133); + case 140: return ((char *) HT_00140); + case 141: return ((char *) HT_00141); + case 150: return ((char *) HT_00150); + case 160: return ((char *) HT_00160); + case 200: return ((char *) HT_00200); + case 300: return ((char *) HT_00300); + case 400: return ((char *) HT_00400); + case 500: return ((char *) HT_00500); + case 501: return ((char *) HT_00501); + case 900: return ((char *) HT_00900); + case 910: return ((char *) HT_00910); + case 1000: return ((char *) HT_01000); + case 1100: return ((char *) HT_01100); + case 1400: return ((char *) HT_01400); + case 1410: return ((char *) HT_01410); + case 1420: return ((char *) HT_01420); + case 1421: return ((char *) HT_01421); + case 1430: return ((char *) HT_01430); + case 1440: return ((char *) HT_01440); + case 1441: return ((char *) HT_01441); + case 1450: return ((char *) HT_01450); + case 1460: return ((char *) HT_01460); + case 1500: return ((char *) HT_01500); + case 1600: return ((char *) HT_01600); + case 1700: return ((char *) HT_01700); + case 1710: return ((char *) HT_01710); + case 1711: return ((char *) HT_01711); + case 1720: return ((char *) HT_01720); + case 1722: return ((char *) HT_01722); + case 1730: return ((char *) HT_01730); + case 1731: return ((char *) HT_01731); + case 1740: return ((char *) HT_01740); + case 1750: return ((char *) HT_01750); + case 1760: return ((char *) HT_01760); + case 1800: return ((char *) HT_01800); + case 2100: return ((char *) HT_02100); + case 2400: return ((char *) HT_02400); + case 2410: return ((char *) HT_02410); + case 2500: return ((char *) HT_02500); + case 2600: return ((char *) HT_02600); + case 2611: return ((char *) HT_02611); + case 2612: return ((char *) HT_02612); + case 2711: return ((char *) HT_02711); + case 2811: return ((char *) HT_02811); + case 3000: return ((char *) HT_03000); + case 3100: return ((char *) HT_03100); + case 3200: return ((char *) HT_03200); + case 3710: return ((char *) HT_03710); + case 3711: return ((char *) HT_03711); + case 3800: return ((char *) HT_03800); + case 4300: return ((char *) HT_04300); + case 4400: return ((char *) HT_04400); + case 4500: return ((char *) HT_04500); + case 4700: return ((char *) HT_04700); + case 4800: return ((char *) HT_04800); + case 4900: return ((char *) HT_04900); + case 5000: return ((char *) HT_05000); + case 5100: return ((char *) HT_05100); + case 5200: return ((char *) HT_05200); + case 5300: return ((char *) HT_05300); + case 5400: return ((char *) HT_05400); + case 5500: return ((char *) HT_05500); + case 5600: return ((char *) HT_05600); + case 5700: return ((char *) HT_05700); + case 5800: return ((char *) HT_05800); + case 6000: return ((char *) HT_06000); + case 6100: return ((char *) HT_06100); + case 6211: return ((char *) HT_06211); + case 6212: return ((char *) HT_06212); + case 6213: return ((char *) HT_06213); + case 6221: return ((char *) HT_06221); + case 6222: return ((char *) HT_06222); + case 6223: return ((char *) HT_06223); + case 6231: return ((char *) HT_06231); + case 6232: return ((char *) HT_06232); + case 6233: return ((char *) HT_06233); + case 6241: return ((char *) HT_06241); + case 6242: return ((char *) HT_06242); + case 6243: return ((char *) HT_06243); + case 6300: return ((char *) HT_06300); + case 6400: return ((char *) HT_06400); + case 6500: return ((char *) HT_06500); + case 6600: return ((char *) HT_06600); + case 6700: return ((char *) HT_06700); + case 6800: return ((char *) HT_06800); + case 6900: return ((char *) HT_06900); + case 7100: return ((char *) HT_07100); + case 7200: return ((char *) HT_07200); + case 7300: return ((char *) HT_07300); + case 7400: return ((char *) HT_07400); + case 7500: return ((char *) HT_07500); + case 7600: return ((char *) HT_07600); + case 7700: return ((char *) HT_07700); + case 7800: return ((char *) HT_07800); + case 7900: return ((char *) HT_07900); + case 8000: return ((char *) HT_08000); + case 8100: return ((char *) HT_08100); + case 8200: return ((char *) HT_08200); + case 8300: return ((char *) HT_08300); + case 8400: return ((char *) HT_08400); + case 8500: return ((char *) HT_08500); + case 8600: return ((char *) HT_08600); + case 8700: return ((char *) HT_08700); + case 8800: return ((char *) HT_08800); + case 8900: return ((char *) HT_08900); + case 9000: return ((char *) HT_09000); + case 9100: return ((char *) HT_09100); + case 9200: return ((char *) HT_09200); + case 9300: return ((char *) HT_09300); + case 9400: return ((char *) HT_09400); + case 9500: return ((char *) HT_09500); + case 9600: return ((char *) HT_09600); + case 9700: return ((char *) HT_09700); + case 9710: return ((char *) HT_09710); + case 9720: return ((char *) HT_09720); + case 9800: return ((char *) HT_09800); + case 9810: return ((char *) HT_09810); + case 9820: return ((char *) HT_09820); + case 9900: return ((char *) HT_09900); + case 10000: return ((char *) HT_10000); + case 10100: return ((char *) HT_10100); + case 10200: return ((char *) HT_10200); + case 10300: return ((char *) HT_10300); + case 10400: return ((char *) HT_10400); + case 10410: return ((char *) HT_10410); + case 10420: return ((char *) HT_10420); + case 10500: return ((char *) HT_10500); + case 10600: return ((char *) HT_10600); + case 10700: return ((char *) HT_10700); + case 10800: return ((char *) HT_10800); + case 10900: return ((char *) HT_10900); + case 11000: return ((char *) HT_11000); + case 11100: return ((char *) HT_11100); + case 11200: return ((char *) HT_11200); + case 11300: return ((char *) HT_11300); + case 11400: return ((char *) HT_11400); + case 11500: return ((char *) HT_11500); + case 11600: return ((char *) HT_11600); + case 11700: return ((char *) HT_11700); + case 11800: return ((char *) HT_11800); + case 11900: return ((char *) HT_11900); + case 12000: return ((char *) HT_12000); + case 12100: return ((char *) HT_12100); + case 12200: return ((char *) HT_12200); + case 12300: return ((char *) HT_12300); + case 12400: return ((char *) HT_12400); + case 12500: return ((char *) HT_12500); + case 12600: return ((char *) HT_12600); + case 12700: return ((char *) HT_12700); + case 12800: return ((char *) HT_12800); + case 12900: return ((char *) HT_12900); + case 13000: return ((char *) HT_13000); + case 13100: return ((char *) HT_13100); + case 13200: return ((char *) HT_13200); + case 13300: return ((char *) HT_13300); + case 13400: return ((char *) HT_13400); + case 13500: return ((char *) HT_13500); + case 13600: return ((char *) HT_13600); + case 13711: return ((char *) HT_13711); + case 13712: return ((char *) HT_13712); + case 13713: return ((char *) HT_13713); + case 13721: return ((char *) HT_13721); + case 13722: return ((char *) HT_13722); + case 13723: return ((char *) HT_13723); + case 13731: return ((char *) HT_13731); + case 13732: return ((char *) HT_13732); + case 13733: return ((char *) HT_13733); + case 13741: return ((char *) HT_13741); + case 13742: return ((char *) HT_13742); + case 13743: return ((char *) HT_13743); + case 13751: return ((char *) HT_13751); + case 13752: return ((char *) HT_13752); + case 13753: return ((char *) HT_13753); + case 13761: return ((char *) HT_13761); + case 13762: return ((char *) HT_13762); + case 13763: return ((char *) HT_13763); + case 13800: return ((char *) HT_13800); + case 13900: return ((char *) HT_13900); + case 14000: return ((char *) HT_14000); + case 14100: return ((char *) HT_14100); + } + + return ((char *) "Unknown"); +} + +char *strparser (const uint parser_status) +{ + switch (parser_status) + { + case PARSER_OK: return ((char *) PA_000); + case PARSER_COMMENT: return ((char *) PA_001); + case PARSER_GLOBAL_ZERO: return ((char *) PA_002); + case PARSER_GLOBAL_LENGTH: return ((char *) PA_003); + case PARSER_HASH_LENGTH: return ((char *) PA_004); + case PARSER_HASH_VALUE: return ((char *) PA_005); + case PARSER_SALT_LENGTH: return ((char *) PA_006); + case PARSER_SALT_VALUE: return ((char *) PA_007); + case PARSER_SALT_ITERATION: return ((char *) PA_008); + case PARSER_SEPARATOR_UNMATCHED: return ((char *) PA_009); + case PARSER_SIGNATURE_UNMATCHED: return ((char *) PA_010); + case PARSER_HCCAP_FILE_SIZE: return ((char *) PA_011); + case PARSER_HCCAP_EAPOL_SIZE: return ((char *) PA_012); + case PARSER_PSAFE2_FILE_SIZE: return ((char *) PA_013); + case PARSER_PSAFE3_FILE_SIZE: return ((char *) PA_014); + case PARSER_TC_FILE_SIZE: return ((char *) PA_015); + case PARSER_SIP_AUTH_DIRECTIVE: return ((char *) PA_016); + } + + return ((char *) PA_255); +} + +void to_hccap_t (hccap_t *hccap, uint salt_pos, uint digest_pos) +{ + memset (hccap, 0, sizeof (hccap_t)); + + salt_t *salt = &data.salts_buf[salt_pos]; + + memcpy (hccap->essid, salt->salt_buf, salt->salt_len); + + wpa_t *wpas = (wpa_t *) data.esalts_buf; + wpa_t *wpa = &wpas[salt_pos]; + + hccap->keyver = wpa->keyver; + + hccap->eapol_size = wpa->eapol_size; + + if (wpa->keyver != 1) + { + uint eapol_tmp[64] = { 0 }; + + for (uint i = 0; i < 64; i++) + { + eapol_tmp[i] = byte_swap_32 (wpa->eapol[i]); + } + + memcpy (hccap->eapol, eapol_tmp, wpa->eapol_size); + } + else + { + memcpy (hccap->eapol, wpa->eapol, wpa->eapol_size); + } + + memcpy (hccap->mac1, wpa->orig_mac1, 6); + memcpy (hccap->mac2, wpa->orig_mac2, 6); + memcpy (hccap->nonce1, wpa->orig_nonce1, 32); + memcpy (hccap->nonce2, wpa->orig_nonce2, 32); + + char *digests_buf_ptr = (char *) data.digests_buf; + + uint dgst_size = data.dgst_size; + + uint *digest_ptr = (uint *) (digests_buf_ptr + (data.salts_buf[salt_pos].digests_offset * dgst_size) + (digest_pos * dgst_size)); + + if (wpa->keyver != 1) + { + uint digest_tmp[4] = { 0 }; + + digest_tmp[0] = byte_swap_32 (digest_ptr[0]); + digest_tmp[1] = byte_swap_32 (digest_ptr[1]); + digest_tmp[2] = byte_swap_32 (digest_ptr[2]); + digest_tmp[3] = byte_swap_32 (digest_ptr[3]); + + memcpy (hccap->keymic, digest_tmp, 16); + } + else + { + memcpy (hccap->keymic, digest_ptr, 16); + } +} + +void truecrypt_crc32 (const char *filename, u8 keytab[64]) +{ + uint crc = ~0u; + + FILE *fd = fopen (filename, "rb"); + + if (fd == NULL) + { + log_error ("%s: %s", filename, strerror (errno)); + + exit (-1); + } + + #define MAX_KEY_SIZE (1024 * 1024) + + u8 *buf = (u8 *) mymalloc (MAX_KEY_SIZE + 1); + + int nread = fread (buf, sizeof (u8), MAX_KEY_SIZE, fd); + + fclose (fd); + + int kpos = 0; + + for (int fpos = 0; fpos < nread; fpos++) + { + crc = crc32tab[(crc ^ buf[fpos]) & 0xff] ^ (crc >> 8); + + keytab[kpos++] += (crc >> 24) & 0xff; + keytab[kpos++] += (crc >> 16) & 0xff; + keytab[kpos++] += (crc >> 8) & 0xff; + keytab[kpos++] += (crc >> 0) & 0xff; + + if (kpos >= 64) kpos = 0; + } + + myfree (buf); +} + +void ascii_digest (char *out_buf, uint salt_pos, uint digest_pos) +{ + uint hash_type = data.hash_type; + uint hash_mode = data.hash_mode; + uint salt_type = data.salt_type; + uint opts_type = data.opts_type; + uint opti_type = data.opti_type; + uint dgst_size = data.dgst_size; + + char *hashfile = data.hashfile; + + uint len = 4096; + + u8 datax[256] = { 0 }; + + u64 *digest_buf64 = (u64 *) datax; + u32 *digest_buf = (u32 *) datax; + + char *digests_buf_ptr = (char *) data.digests_buf; + + memcpy (digest_buf, digests_buf_ptr + (data.salts_buf[salt_pos].digests_offset * dgst_size) + (digest_pos * dgst_size), dgst_size); + + if (opti_type & OPTI_TYPE_PRECOMPUTE_PERMUT) + { + uint tt; + + switch (hash_type) + { + case HASH_TYPE_DES: + FP (digest_buf[1], digest_buf[0], tt); + break; + + case HASH_TYPE_DESCRYPT: + FP (digest_buf[1], digest_buf[0], tt); + break; + + case HASH_TYPE_DESRACF: + digest_buf[0] = rotl32 (digest_buf[0], 29); + digest_buf[1] = rotl32 (digest_buf[1], 29); + + FP (digest_buf[1], digest_buf[0], tt); + break; + + case HASH_TYPE_LM: + FP (digest_buf[1], digest_buf[0], tt); + break; + + case HASH_TYPE_NETNTLM: + digest_buf[0] = rotl32 (digest_buf[0], 29); + digest_buf[1] = rotl32 (digest_buf[1], 29); + digest_buf[2] = rotl32 (digest_buf[2], 29); + digest_buf[3] = rotl32 (digest_buf[3], 29); + + FP (digest_buf[1], digest_buf[0], tt); + FP (digest_buf[3], digest_buf[2], tt); + break; + + case HASH_TYPE_BSDICRYPT: + digest_buf[0] = rotl32 (digest_buf[0], 31); + digest_buf[1] = rotl32 (digest_buf[1], 31); + + FP (digest_buf[1], digest_buf[0], tt); + break; + } + } + + if (opti_type & OPTI_TYPE_PRECOMPUTE_MERKLE) + { + switch (hash_type) + { + case HASH_TYPE_MD4: + digest_buf[0] += MD4M_A; + digest_buf[1] += MD4M_B; + digest_buf[2] += MD4M_C; + digest_buf[3] += MD4M_D; + break; + + case HASH_TYPE_MD5: + digest_buf[0] += MD5M_A; + digest_buf[1] += MD5M_B; + digest_buf[2] += MD5M_C; + digest_buf[3] += MD5M_D; + break; + + case HASH_TYPE_SHA1: + digest_buf[0] += SHA1M_A; + digest_buf[1] += SHA1M_B; + digest_buf[2] += SHA1M_C; + digest_buf[3] += SHA1M_D; + digest_buf[4] += SHA1M_E; + break; + + case HASH_TYPE_SHA256: + digest_buf[0] += SHA256M_A; + digest_buf[1] += SHA256M_B; + digest_buf[2] += SHA256M_C; + digest_buf[3] += SHA256M_D; + digest_buf[4] += SHA256M_E; + digest_buf[5] += SHA256M_F; + digest_buf[6] += SHA256M_G; + digest_buf[7] += SHA256M_H; + break; + + case HASH_TYPE_SHA384: + digest_buf64[0] += SHA384M_A; + digest_buf64[1] += SHA384M_B; + digest_buf64[2] += SHA384M_C; + digest_buf64[3] += SHA384M_D; + digest_buf64[4] += SHA384M_E; + digest_buf64[5] += SHA384M_F; + digest_buf64[6] += 0; + digest_buf64[7] += 0; + break; + + case HASH_TYPE_SHA512: + digest_buf64[0] += SHA512M_A; + digest_buf64[1] += SHA512M_B; + digest_buf64[2] += SHA512M_C; + digest_buf64[3] += SHA512M_D; + digest_buf64[4] += SHA512M_E; + digest_buf64[5] += SHA512M_F; + digest_buf64[6] += SHA512M_G; + digest_buf64[7] += SHA512M_H; + break; + } + } + + if (opts_type & OPTS_TYPE_PT_GENERATE_LE) + { + if (dgst_size == DGST_SIZE_4_2) + { + for (int i = 0; i < 2; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); + } + else if (dgst_size == DGST_SIZE_4_4) + { + for (int i = 0; i < 4; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); + } + else if (dgst_size == DGST_SIZE_4_5) + { + for (int i = 0; i < 5; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); + } + else if (dgst_size == DGST_SIZE_4_6) + { + for (int i = 0; i < 6; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); + } + else if (dgst_size == DGST_SIZE_4_8) + { + for (int i = 0; i < 8; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); + } + else if ((dgst_size == DGST_SIZE_4_16) || (dgst_size == DGST_SIZE_8_8)) // same size, same result :) + { + if (hash_type == HASH_TYPE_WHIRLPOOL) + { + for (int i = 0; i < 16; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); + } + else if (hash_type == HASH_TYPE_SHA384) + { + for (int i = 0; i < 8; i++) digest_buf64[i] = byte_swap_64 (digest_buf64[i]); + } + else if (hash_type == HASH_TYPE_SHA512) + { + for (int i = 0; i < 8; i++) digest_buf64[i] = byte_swap_64 (digest_buf64[i]); + } + else if (hash_type == HASH_TYPE_GOST) + { + for (int i = 0; i < 16; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); + } + } + else if (dgst_size == DGST_SIZE_4_64) + { + for (int i = 0; i < 64; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); + } + else if (dgst_size == DGST_SIZE_8_25) + { + for (int i = 0; i < 25; i++) digest_buf64[i] = byte_swap_64 (digest_buf64[i]); + } + } + + uint isSalted = ((data.salt_type == SALT_TYPE_INTERN) + | (data.salt_type == SALT_TYPE_EXTERN) + | (data.salt_type == SALT_TYPE_EMBEDDED)); + + salt_t salt; + + if (isSalted) + { + memset (&salt, 0, sizeof (salt_t)); + + memcpy (&salt, &data.salts_buf[salt_pos], sizeof (salt_t)); + + char *ptr = (char *) salt.salt_buf; + + uint len = salt.salt_len; + + if (opti_type & OPTI_TYPE_PRECOMPUTE_PERMUT) + { + uint tt; + + switch (hash_type) + { + case HASH_TYPE_NETNTLM: + + salt.salt_buf[0] = rotr32 (salt.salt_buf[0], 3); + salt.salt_buf[1] = rotr32 (salt.salt_buf[1], 3); + + FP (salt.salt_buf[1], salt.salt_buf[0], tt); + + break; + } + } + + if (opts_type & OPTS_TYPE_ST_UNICODE) + { + for (uint i = 0, j = 0; i < len; i += 1, j += 2) + { + ptr[i] = ptr[j]; + } + + len = len / 2; + } + + if (opts_type & OPTS_TYPE_ST_GENERATE_LE) + { + uint max = salt.salt_len / 4; + + if (len % 4) max++; + + for (uint i = 0; i < max; i++) + { + salt.salt_buf[i] = byte_swap_32 (salt.salt_buf[i]); + } + } + + if (opts_type & OPTS_TYPE_ST_HEX) + { + char tmp[64] = { 0 }; + + for (uint i = 0, j = 0; i < len; i += 1, j += 2) + { + sprintf (tmp + j, "%02x", (unsigned char) ptr[i]); + } + + len = len * 2; + + memcpy (ptr, tmp, len); + } + + uint memset_size = ((48 - (int) len) > 0) ? (48 - len) : 0; + + memset (ptr + len, 0, memset_size); + + salt.salt_len = len; + } + + // + // some modes require special encoding + // + + uint out_buf_plain[256] = { 0 }; + uint out_buf_salt[256] = { 0 }; + + char tmp_buf[1024] = { 0 }; + + char *ptr_plain = (char *) out_buf_plain; + char *ptr_salt = (char *) out_buf_salt; + + if (hash_mode == 22) + { + char username[30] = { 0 }; + + memcpy (username, salt.salt_buf, salt.salt_len - 22); + + char sig[6] = { 'n', 'r', 'c', 's', 't', 'n' }; + + u16 *ptr = (u16 *) digest_buf; + + tmp_buf[ 0] = sig[0]; + tmp_buf[ 1] = int_to_base64 (((ptr[1]) >> 12) & 0x3f); + tmp_buf[ 2] = int_to_base64 (((ptr[1]) >> 6) & 0x3f); + tmp_buf[ 3] = int_to_base64 (((ptr[1]) >> 0) & 0x3f); + tmp_buf[ 4] = int_to_base64 (((ptr[0]) >> 12) & 0x3f); + tmp_buf[ 5] = int_to_base64 (((ptr[0]) >> 6) & 0x3f); + tmp_buf[ 6] = sig[1]; + tmp_buf[ 7] = int_to_base64 (((ptr[0]) >> 0) & 0x3f); + tmp_buf[ 8] = int_to_base64 (((ptr[3]) >> 12) & 0x3f); + tmp_buf[ 9] = int_to_base64 (((ptr[3]) >> 6) & 0x3f); + tmp_buf[10] = int_to_base64 (((ptr[3]) >> 0) & 0x3f); + tmp_buf[11] = int_to_base64 (((ptr[2]) >> 12) & 0x3f); + tmp_buf[12] = sig[2]; + tmp_buf[13] = int_to_base64 (((ptr[2]) >> 6) & 0x3f); + tmp_buf[14] = int_to_base64 (((ptr[2]) >> 0) & 0x3f); + tmp_buf[15] = int_to_base64 (((ptr[5]) >> 12) & 0x3f); + tmp_buf[16] = int_to_base64 (((ptr[5]) >> 6) & 0x3f); + tmp_buf[17] = sig[3]; + tmp_buf[18] = int_to_base64 (((ptr[5]) >> 0) & 0x3f); + tmp_buf[19] = int_to_base64 (((ptr[4]) >> 12) & 0x3f); + tmp_buf[20] = int_to_base64 (((ptr[4]) >> 6) & 0x3f); + tmp_buf[21] = int_to_base64 (((ptr[4]) >> 0) & 0x3f); + tmp_buf[22] = int_to_base64 (((ptr[7]) >> 12) & 0x3f); + tmp_buf[23] = sig[4]; + tmp_buf[24] = int_to_base64 (((ptr[7]) >> 6) & 0x3f); + tmp_buf[25] = int_to_base64 (((ptr[7]) >> 0) & 0x3f); + tmp_buf[26] = int_to_base64 (((ptr[6]) >> 12) & 0x3f); + tmp_buf[27] = int_to_base64 (((ptr[6]) >> 6) & 0x3f); + tmp_buf[28] = int_to_base64 (((ptr[6]) >> 0) & 0x3f); + tmp_buf[29] = sig[5]; + + snprintf (out_buf, len-1, "%s:%s", + tmp_buf, + username); + } + else if (hash_mode == 23) + { + // do not show the skyper part in output + + char *salt_buf_ptr = (char *) salt.salt_buf; + + salt_buf_ptr[salt.salt_len - 8] = 0; + + snprintf (out_buf, len-1, "%08x%08x%08x%08x:%s", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + salt_buf_ptr); + } + else if (hash_mode == 101) + { + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + + memcpy (tmp_buf, digest_buf, 20); + + base64_encode (int_to_base64, (const u8 *) tmp_buf, 20, (u8 *) ptr_plain); + + snprintf (out_buf, len-1, "{SHA}%s", ptr_plain); + } + else if (hash_mode == 111) + { + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + + memcpy (tmp_buf, digest_buf, 20); + memcpy (tmp_buf + 20, salt.salt_buf, salt.salt_len); + + base64_encode (int_to_base64, (const u8 *) tmp_buf, 20 + salt.salt_len, (u8 *) ptr_plain); + + snprintf (out_buf, len-1, "{SSHA}%s", ptr_plain); + } + else if ((hash_mode == 122) || (hash_mode == 125)) + { + snprintf (out_buf, len-1, "%s%08x%08x%08x%08x%08x", + (char *) salt.salt_buf, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4]); + } + else if (hash_mode == 124) + { + snprintf (out_buf, len-1, "sha1$%s$%08x%08x%08x%08x%08x", + (char *) salt.salt_buf, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4]); + } + else if (hash_mode == 131) + { + snprintf (out_buf, len-1, "0x0100%s%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", + (char *) salt.salt_buf, + 0, 0, 0, 0, 0, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4]); + } + else if (hash_mode == 132) + { + snprintf (out_buf, len-1, "0x0100%s%08x%08x%08x%08x%08x", + (char *) salt.salt_buf, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4]); + } + else if (hash_mode == 133) + { + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + + memcpy (tmp_buf, digest_buf, 20); + + base64_encode (int_to_base64, (const u8 *) tmp_buf, 20, (u8 *) ptr_plain); + + snprintf (out_buf, len-1, "%s", ptr_plain); + } + else if (hash_mode == 141) + { + memcpy (tmp_buf, salt.salt_buf, salt.salt_len); + + base64_encode (int_to_base64, (const u8 *) tmp_buf, salt.salt_len, (u8 *) ptr_salt); + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + + memcpy (tmp_buf, digest_buf, 20); + + base64_encode (int_to_base64, (const u8 *) tmp_buf, 20, (u8 *) ptr_plain); + + ptr_plain[27] = 0; + + snprintf (out_buf, len-1, "%s%s*%s", SIGNATURE_EPISERVER, ptr_salt, ptr_plain); + } + else if (hash_mode == 400) + { + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + + phpass_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); + + snprintf (out_buf, len-1, "%s%s%s", (char *) salt.salt_sign, (char *) salt.salt_buf, (char *) ptr_plain); + } + else if (hash_mode == 500) + { + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + + md5crypt_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); + + if (salt.salt_iter == ROUNDS_MD5CRYPT) + { + snprintf (out_buf, len-1, "$1$%s$%s", (char *) salt.salt_buf, (char *) ptr_plain); + } + else + { + snprintf (out_buf, len-1, "$1$rounds=%i$%s$%s", salt.salt_iter, (char *) salt.salt_buf, (char *) ptr_plain); + } + } + else if (hash_mode == 501) + { + uint digest_idx = salt.digests_offset + digest_pos; + + hashinfo_t **hashinfo_ptr = data.hash_info; + char *hash_buf = hashinfo_ptr[digest_idx]->orighash; + + snprintf (out_buf, len-1, "%s", hash_buf); + } + else if (hash_mode == 1421) + { + u8 *salt_ptr = (u8 *) salt.salt_buf; + + snprintf (out_buf, len-1, "%c%c%c%c%c%c%08x%08x%08x%08x%08x%08x%08x%08x", + salt_ptr[0], + salt_ptr[1], + salt_ptr[2], + salt_ptr[3], + salt_ptr[4], + salt_ptr[5], + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4], + digest_buf[5], + digest_buf[6], + digest_buf[7]); + } + else if (hash_mode == 1441) + { + memcpy (tmp_buf, salt.salt_buf, salt.salt_len); + + base64_encode (int_to_base64, (const u8 *) tmp_buf, salt.salt_len, (u8 *) ptr_salt); + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + digest_buf[5] = byte_swap_32 (digest_buf[5]); + digest_buf[6] = byte_swap_32 (digest_buf[6]); + digest_buf[7] = byte_swap_32 (digest_buf[7]); + + memcpy (tmp_buf, digest_buf, 32); + + base64_encode (int_to_base64, (const u8 *) tmp_buf, 32, (u8 *) ptr_plain); + + ptr_plain[43] = 0; + + snprintf (out_buf, len-1, "%s%s*%s", SIGNATURE_EPISERVER4, ptr_salt, ptr_plain); + } + else if (hash_mode == 1500) + { + out_buf[0] = salt.salt_sign[0] & 0xff; + out_buf[1] = salt.salt_sign[1] & 0xff; + //original method, but changed because of this ticket: https://hashcat.net/trac/ticket/269 + //out_buf[0] = int_to_itoa64 ((salt.salt_buf[0] >> 0) & 0x3f); + //out_buf[1] = int_to_itoa64 ((salt.salt_buf[0] >> 6) & 0x3f); + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + + memcpy (tmp_buf, digest_buf, 8); + + base64_encode (int_to_itoa64, (const u8 *) tmp_buf, 8, (u8 *) ptr_plain); + + snprintf (out_buf + 2, len-1-2, "%s", ptr_plain); + + out_buf[13] = 0; + } + else if (hash_mode == 1600) + { + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + + md5crypt_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); + + if (salt.salt_iter == ROUNDS_MD5CRYPT) + { + snprintf (out_buf, len-1, "$apr1$%s$%s", (char *) salt.salt_buf, (char *) ptr_plain); + } + else + { + snprintf (out_buf, len-1, "$apr1$rounds=%i$%s$%s", salt.salt_iter, (char *) salt.salt_buf, (char *) ptr_plain); + } + } + else if (hash_mode == 1711) + { + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf64[0] = byte_swap_64 (digest_buf64[0]); + digest_buf64[1] = byte_swap_64 (digest_buf64[1]); + digest_buf64[2] = byte_swap_64 (digest_buf64[2]); + digest_buf64[3] = byte_swap_64 (digest_buf64[3]); + digest_buf64[4] = byte_swap_64 (digest_buf64[4]); + digest_buf64[5] = byte_swap_64 (digest_buf64[5]); + digest_buf64[6] = byte_swap_64 (digest_buf64[6]); + digest_buf64[7] = byte_swap_64 (digest_buf64[7]); + + memcpy (tmp_buf, digest_buf, 64); + memcpy (tmp_buf + 64, salt.salt_buf, salt.salt_len); + + base64_encode (int_to_base64, (const u8 *) tmp_buf, 64 + salt.salt_len, (u8 *) ptr_plain); + + snprintf (out_buf, len-1, "%s%s", SIGNATURE_SHA512B64S, ptr_plain); + } + else if (hash_mode == 1722) + { + uint *ptr = digest_buf; + + snprintf (out_buf, len-1, "%s%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", + (unsigned char *) salt.salt_buf, + ptr[ 1], ptr[ 0], + ptr[ 3], ptr[ 2], + ptr[ 5], ptr[ 4], + ptr[ 7], ptr[ 6], + ptr[ 9], ptr[ 8], + ptr[11], ptr[10], + ptr[13], ptr[12], + ptr[15], ptr[14]); + } + else if (hash_mode == 1731) + { + uint *ptr = digest_buf; + + snprintf (out_buf, len-1, "0x0200%s%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", + (unsigned char *) salt.salt_buf, + ptr[ 1], ptr[ 0], + ptr[ 3], ptr[ 2], + ptr[ 5], ptr[ 4], + ptr[ 7], ptr[ 6], + ptr[ 9], ptr[ 8], + ptr[11], ptr[10], + ptr[13], ptr[12], + ptr[15], ptr[14]); + } + else if (hash_mode == 1800) + { + // temp workaround + + digest_buf64[0] = byte_swap_64 (digest_buf64[0]); + digest_buf64[1] = byte_swap_64 (digest_buf64[1]); + digest_buf64[2] = byte_swap_64 (digest_buf64[2]); + digest_buf64[3] = byte_swap_64 (digest_buf64[3]); + digest_buf64[4] = byte_swap_64 (digest_buf64[4]); + digest_buf64[5] = byte_swap_64 (digest_buf64[5]); + digest_buf64[6] = byte_swap_64 (digest_buf64[6]); + digest_buf64[7] = byte_swap_64 (digest_buf64[7]); + + sha512crypt_encode ((unsigned char *) digest_buf64, (unsigned char *) ptr_plain); + + if (salt.salt_iter == ROUNDS_SHA512CRYPT) + { + snprintf (out_buf, len-1, "$6$%s$%s", (char *) salt.salt_buf, (char *) ptr_plain); + } + else + { + snprintf (out_buf, len-1, "$6$rounds=%i$%s$%s", salt.salt_iter, (char *) salt.salt_buf, (char *) ptr_plain); + } + } + else if (hash_mode == 2100) + { + uint pos = 0; + + snprintf (out_buf + pos, len-1, "%s%i#", + SIGNATURE_DCC2, + salt.salt_iter + 1); + + uint signature_len = strlen (out_buf); + + pos += signature_len; + len -= signature_len; + + char *salt_ptr = (char *) salt.salt_buf; + + for (uint i = 0; i < salt.salt_len; i++, pos++, len--) snprintf (out_buf + pos, len-1, "%c", salt_ptr[i]); + + snprintf (out_buf + pos, len-1, "#%08x%08x%08x%08x", + byte_swap_32 (digest_buf[0]), + byte_swap_32 (digest_buf[1]), + byte_swap_32 (digest_buf[2]), + byte_swap_32 (digest_buf[3])); + } + else if ((hash_mode == 2400) || (hash_mode == 2410)) + { + memcpy (tmp_buf, digest_buf, 16); + + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + + out_buf[ 0] = int_to_itoa64 ((digest_buf[0] >> 0) & 0x3f); + out_buf[ 1] = int_to_itoa64 ((digest_buf[0] >> 6) & 0x3f); + out_buf[ 2] = int_to_itoa64 ((digest_buf[0] >> 12) & 0x3f); + out_buf[ 3] = int_to_itoa64 ((digest_buf[0] >> 18) & 0x3f); + + out_buf[ 4] = int_to_itoa64 ((digest_buf[1] >> 0) & 0x3f); + out_buf[ 5] = int_to_itoa64 ((digest_buf[1] >> 6) & 0x3f); + out_buf[ 6] = int_to_itoa64 ((digest_buf[1] >> 12) & 0x3f); + out_buf[ 7] = int_to_itoa64 ((digest_buf[1] >> 18) & 0x3f); + + out_buf[ 8] = int_to_itoa64 ((digest_buf[2] >> 0) & 0x3f); + out_buf[ 9] = int_to_itoa64 ((digest_buf[2] >> 6) & 0x3f); + out_buf[10] = int_to_itoa64 ((digest_buf[2] >> 12) & 0x3f); + out_buf[11] = int_to_itoa64 ((digest_buf[2] >> 18) & 0x3f); + + out_buf[12] = int_to_itoa64 ((digest_buf[3] >> 0) & 0x3f); + out_buf[13] = int_to_itoa64 ((digest_buf[3] >> 6) & 0x3f); + out_buf[14] = int_to_itoa64 ((digest_buf[3] >> 12) & 0x3f); + out_buf[15] = int_to_itoa64 ((digest_buf[3] >> 18) & 0x3f); + + out_buf[16] = 0; + } + else if (hash_mode == 2500) + { + wpa_t *wpas = (wpa_t *) data.esalts_buf; + + wpa_t *wpa = &wpas[salt_pos]; + + snprintf (out_buf, len-1, "%s:%02x%02x%02x%02x%02x%02x:%02x%02x%02x%02x%02x%02x", + (char *) salt.salt_buf, + wpa->orig_mac1[0], + wpa->orig_mac1[1], + wpa->orig_mac1[2], + wpa->orig_mac1[3], + wpa->orig_mac1[4], + wpa->orig_mac1[5], + wpa->orig_mac2[0], + wpa->orig_mac2[1], + wpa->orig_mac2[2], + wpa->orig_mac2[3], + wpa->orig_mac2[4], + wpa->orig_mac2[5]); + } + else if (hash_mode == 4400) + { + snprintf (out_buf, len-1, "%08x%08x%08x%08x", + byte_swap_32 (digest_buf[0]), + byte_swap_32 (digest_buf[1]), + byte_swap_32 (digest_buf[2]), + byte_swap_32 (digest_buf[3])); + } + else if (hash_mode == 4700) + { + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x", + byte_swap_32 (digest_buf[0]), + byte_swap_32 (digest_buf[1]), + byte_swap_32 (digest_buf[2]), + byte_swap_32 (digest_buf[3]), + byte_swap_32 (digest_buf[4])); + } + else if (hash_mode == 4800) + { + u8 chap_id_byte = (u8) salt.salt_buf[4]; + + snprintf (out_buf, len-1, "%08x%08x%08x%08x:%08x%08x%08x%08x:%02x", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + byte_swap_32 (salt.salt_buf[0]), + byte_swap_32 (salt.salt_buf[1]), + byte_swap_32 (salt.salt_buf[2]), + byte_swap_32 (salt.salt_buf[3]), + chap_id_byte); + } + else if (hash_mode == 4900) + { + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x", + byte_swap_32 (digest_buf[0]), + byte_swap_32 (digest_buf[1]), + byte_swap_32 (digest_buf[2]), + byte_swap_32 (digest_buf[3]), + byte_swap_32 (digest_buf[4])); + } + else if (hash_mode == 5100) + { + snprintf (out_buf, len-1, "%08x%08x", + digest_buf[0], + digest_buf[1]); + } + else if (hash_mode == 5200) + { + snprintf (out_buf, len-1, "%s", hashfile); + } + else if (hash_mode == 5300) + { + ikepsk_t *ikepsks = (ikepsk_t *) data.esalts_buf; + + ikepsk_t *ikepsk = &ikepsks[salt_pos]; + + int buf_len = len - 1; + + // msg_buf + + uint ikepsk_msg_len = ikepsk->msg_len / 4; + + for (uint i = 0; i < ikepsk_msg_len; i++) + { + if ((i == 32) || (i == 64) || (i == 66) || (i == 68) || (i == 108)) + { + snprintf (out_buf, buf_len, ":"); + + buf_len--; + out_buf++; + } + + snprintf (out_buf, buf_len, "%08x", byte_swap_32 (ikepsk->msg_buf[i])); + + buf_len -= 8; + out_buf += 8; + } + + // nr_buf + + uint ikepsk_nr_len = ikepsk->nr_len / 4; + + for (uint i = 0; i < ikepsk_nr_len; i++) + { + if ((i == 0) || (i == 5)) + { + snprintf (out_buf, buf_len, ":"); + + buf_len--; + out_buf++; + } + + snprintf (out_buf, buf_len, "%08x", byte_swap_32 (ikepsk->nr_buf[i])); + + buf_len -= 8; + out_buf += 8; + } + + // digest_buf + + for (uint i = 0; i < 4; i++) + { + if (i == 0) + { + snprintf (out_buf, buf_len, ":"); + + buf_len--; + out_buf++; + } + + snprintf (out_buf, buf_len, "%08x", digest_buf[i]); + + buf_len -= 8; + out_buf += 8; + } + } + else if (hash_mode == 5400) + { + ikepsk_t *ikepsks = (ikepsk_t *) data.esalts_buf; + + ikepsk_t *ikepsk = &ikepsks[salt_pos]; + + int buf_len = len - 1; + + // msg_buf + + uint ikepsk_msg_len = ikepsk->msg_len / 4; + + for (uint i = 0; i < ikepsk_msg_len; i++) + { + if ((i == 32) || (i == 64) || (i == 66) || (i == 68) || (i == 108)) + { + snprintf (out_buf, buf_len, ":"); + + buf_len--; + out_buf++; + } + + snprintf (out_buf, buf_len, "%08x", byte_swap_32 (ikepsk->msg_buf[i])); + + buf_len -= 8; + out_buf += 8; + } + + // nr_buf + + uint ikepsk_nr_len = ikepsk->nr_len / 4; + + for (uint i = 0; i < ikepsk_nr_len; i++) + { + if ((i == 0) || (i == 5)) + { + snprintf (out_buf, buf_len, ":"); + + buf_len--; + out_buf++; + } + + snprintf (out_buf, buf_len, "%08x", byte_swap_32 (ikepsk->nr_buf[i])); + + buf_len -= 8; + out_buf += 8; + } + + // digest_buf + + for (uint i = 0; i < 5; i++) + { + if (i == 0) + { + snprintf (out_buf, buf_len, ":"); + + buf_len--; + out_buf++; + } + + snprintf (out_buf, buf_len, "%08x", digest_buf[i]); + + buf_len -= 8; + out_buf += 8; + } + } + else if (hash_mode == 5500) + { + netntlm_t *netntlms = (netntlm_t *) data.esalts_buf; + + netntlm_t *netntlm = &netntlms[salt_pos]; + + char user_buf[64] = { 0 }; + char domain_buf[64] = { 0 }; + char srvchall_buf[1024] = { 0 }; + char clichall_buf[1024] = { 0 }; + + for (uint i = 0, j = 0; j < netntlm->user_len; i += 1, j += 2) + { + char *ptr = (char *) netntlm->userdomain_buf; + + user_buf[i] = ptr[j]; + } + + for (uint i = 0, j = 0; j < netntlm->domain_len; i += 1, j += 2) + { + char *ptr = (char *) netntlm->userdomain_buf; + + domain_buf[i] = ptr[netntlm->user_len + j]; + } + + for (uint i = 0, j = 0; i < netntlm->srvchall_len; i += 1, j += 2) + { + u8 *ptr = (u8 *) netntlm->chall_buf; + + sprintf (srvchall_buf + j, "%02x", ptr[i]); + } + + for (uint i = 0, j = 0; i < netntlm->clichall_len; i += 1, j += 2) + { + u8 *ptr = (u8 *) netntlm->chall_buf; + + sprintf (clichall_buf + j, "%02x", ptr[netntlm->srvchall_len + i]); + } + + snprintf (out_buf, len-1, "%s::%s:%s:%08x%08x%08x%08x%08x%08x:%s", + user_buf, + domain_buf, + srvchall_buf, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + byte_swap_32 (salt.salt_buf_pc[0]), + byte_swap_32 (salt.salt_buf_pc[1]), + clichall_buf); + } + else if (hash_mode == 5600) + { + netntlm_t *netntlms = (netntlm_t *) data.esalts_buf; + + netntlm_t *netntlm = &netntlms[salt_pos]; + + char user_buf[64] = { 0 }; + char domain_buf[64] = { 0 }; + char srvchall_buf[1024] = { 0 }; + char clichall_buf[1024] = { 0 }; + + for (uint i = 0, j = 0; j < netntlm->user_len; i += 1, j += 2) + { + char *ptr = (char *) netntlm->userdomain_buf; + + user_buf[i] = ptr[j]; + } + + for (uint i = 0, j = 0; j < netntlm->domain_len; i += 1, j += 2) + { + char *ptr = (char *) netntlm->userdomain_buf; + + domain_buf[i] = ptr[netntlm->user_len + j]; + } + + for (uint i = 0, j = 0; i < netntlm->srvchall_len; i += 1, j += 2) + { + u8 *ptr = (u8 *) netntlm->chall_buf; + + sprintf (srvchall_buf + j, "%02x", ptr[i]); + } + + for (uint i = 0, j = 0; i < netntlm->clichall_len; i += 1, j += 2) + { + u8 *ptr = (u8 *) netntlm->chall_buf; + + sprintf (clichall_buf + j, "%02x", ptr[netntlm->srvchall_len + i]); + } + + snprintf (out_buf, len-1, "%s::%s:%s:%08x%08x%08x%08x:%s", + user_buf, + domain_buf, + srvchall_buf, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + clichall_buf); + } + else if (hash_mode == 5700) + { + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + digest_buf[5] = byte_swap_32 (digest_buf[5]); + digest_buf[6] = byte_swap_32 (digest_buf[6]); + digest_buf[7] = byte_swap_32 (digest_buf[7]); + + memcpy (tmp_buf, digest_buf, 32); + + base64_encode (int_to_itoa64, (const u8 *) tmp_buf, 32, (u8 *) ptr_plain); + + ptr_plain[43] = 0; + + snprintf (out_buf, len-1, "%s", ptr_plain); + } + else if (hash_mode == 5800) + { + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4]); + } + else if ((hash_mode >= 6200) && (hash_mode <= 6299)) + { + snprintf (out_buf, len-1, "%s", hashfile); + } + else if (hash_mode == 6300) + { + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + + md5crypt_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); + + snprintf (out_buf, len-1, "{smd5}%s$%s", (char *) salt.salt_buf, (char *) ptr_plain); + } + else if (hash_mode == 6400) + { + sha256aix_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); + + snprintf (out_buf, len-1, "{ssha256}%02d$%s$%s", salt.salt_sign[0], (char *) salt.salt_buf, (char *) ptr_plain); + } + else if (hash_mode == 6500) + { + sha512aix_encode ((unsigned char *) digest_buf64, (unsigned char *) ptr_plain); + + snprintf (out_buf, len-1, "{ssha512}%02d$%s$%s", salt.salt_sign[0], (char *) salt.salt_buf, (char *) ptr_plain); + } + else if (hash_mode == 6600) + { + agilekey_t *agilekeys = (agilekey_t *) data.esalts_buf; + + agilekey_t *agilekey = &agilekeys[salt_pos]; + + salt.salt_buf[0] = byte_swap_32 (salt.salt_buf[0]); + salt.salt_buf[1] = byte_swap_32 (salt.salt_buf[1]); + + uint buf_len = len - 1; + + uint off = snprintf (out_buf, buf_len, "%d:%08x%08x:", salt.salt_iter + 1, salt.salt_buf[0], salt.salt_buf[1]); + buf_len -= 22; + + for (uint i = 0, j = off; i < 1040; i++, j += 2) + { + snprintf (out_buf + j, buf_len, "%02x", agilekey->cipher[i]); + + buf_len -= 2; + } + } + else if (hash_mode == 6700) + { + sha1aix_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); + + snprintf (out_buf, len-1, "{ssha1}%02d$%s$%s", salt.salt_sign[0], (char *) salt.salt_buf, (char *) ptr_plain); + } + else if (hash_mode == 6800) + { + snprintf (out_buf, len-1, "%s", (char *) salt.salt_buf); + } + else if (hash_mode == 7100) + { + uint *ptr = digest_buf; + + pbkdf2_sha512_t *pbkdf2_sha512s = (pbkdf2_sha512_t *) data.esalts_buf; + + pbkdf2_sha512_t *pbkdf2_sha512 = &pbkdf2_sha512s[salt_pos]; + + uint esalt[8] = { 0 }; + + esalt[0] = byte_swap_32 (pbkdf2_sha512->salt_buf[0]); + esalt[1] = byte_swap_32 (pbkdf2_sha512->salt_buf[1]); + esalt[2] = byte_swap_32 (pbkdf2_sha512->salt_buf[2]); + esalt[3] = byte_swap_32 (pbkdf2_sha512->salt_buf[3]); + esalt[4] = byte_swap_32 (pbkdf2_sha512->salt_buf[4]); + esalt[5] = byte_swap_32 (pbkdf2_sha512->salt_buf[5]); + esalt[6] = byte_swap_32 (pbkdf2_sha512->salt_buf[6]); + esalt[7] = byte_swap_32 (pbkdf2_sha512->salt_buf[7]); + + snprintf (out_buf, len-1, "%s%i$%08x%08x%08x%08x%08x%08x%08x%08x$%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", + SIGNATURE_SHA512OSX, + salt.salt_iter + 1, + esalt[ 0], esalt[ 1], + esalt[ 2], esalt[ 3], + esalt[ 4], esalt[ 5], + esalt[ 6], esalt[ 7], + ptr [ 1], ptr [ 0], + ptr [ 3], ptr [ 2], + ptr [ 5], ptr [ 4], + ptr [ 7], ptr [ 6], + ptr [ 9], ptr [ 8], + ptr [11], ptr [10], + ptr [13], ptr [12], + ptr [15], ptr [14]); + } + else if (hash_mode == 7200) + { + uint *ptr = digest_buf; + + pbkdf2_sha512_t *pbkdf2_sha512s = (pbkdf2_sha512_t *) data.esalts_buf; + + pbkdf2_sha512_t *pbkdf2_sha512 = &pbkdf2_sha512s[salt_pos]; + + uint len_used = 0; + + snprintf (out_buf + len_used, len - len_used - 1, "%s%i.", SIGNATURE_SHA512GRUB, salt.salt_iter + 1); + + len_used = strlen (out_buf); + + unsigned char *salt_buf_ptr = (unsigned char *) pbkdf2_sha512->salt_buf; + + for (uint i = 0; i < salt.salt_len; i++, len_used += 2) + { + snprintf (out_buf + len_used, len - len_used - 1, "%02x", salt_buf_ptr[i]); + } + + snprintf (out_buf + len_used, len - len_used - 1, ".%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", + ptr [ 1], ptr [ 0], + ptr [ 3], ptr [ 2], + ptr [ 5], ptr [ 4], + ptr [ 7], ptr [ 6], + ptr [ 9], ptr [ 8], + ptr [11], ptr [10], + ptr [13], ptr [12], + ptr [15], ptr [14]); + } + else if (hash_mode == 7300) + { + rakp_t *rakps = (rakp_t *) data.esalts_buf; + + rakp_t *rakp = &rakps[salt_pos]; + + for (uint i = 0, j = 0; (i * 4) < rakp->salt_len; i += 1, j += 8) + { + sprintf (out_buf + j, "%08x", rakp->salt_buf[i]); + } + + snprintf (out_buf + rakp->salt_len * 2, len - 1, ":%08x%08x%08x%08x%08x", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4]); + } + else if (hash_mode == 7400) + { + // the encoder is a bit too intelligent, it expects the input data in the wrong BOM + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + digest_buf[5] = byte_swap_32 (digest_buf[5]); + digest_buf[6] = byte_swap_32 (digest_buf[6]); + digest_buf[7] = byte_swap_32 (digest_buf[7]); + + sha256crypt_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); + + if (salt.salt_iter == ROUNDS_SHA256CRYPT) + { + snprintf (out_buf, len-1, "$5$%s$%s", (char *) salt.salt_buf, (char *) ptr_plain); + } + else + { + snprintf (out_buf, len-1, "$5$rounds=%i$%s$%s", salt.salt_iter, (char *) salt.salt_buf, (char *) ptr_plain); + } + } + else if (hash_mode == 7500) + { + krb5pa_t *krb5pas = (krb5pa_t *) data.esalts_buf; + + krb5pa_t *krb5pa = &krb5pas[salt_pos]; + + u8 *ptr_timestamp = (u8 *) krb5pa->timestamp; + u8 *ptr_checksum = (u8 *) krb5pa->checksum; + + char data[128] = { 0 }; + + char *ptr_data = data; + + for (uint i = 0; i < 36; i++, ptr_data += 2) + { + sprintf (ptr_data, "%02x", ptr_timestamp[i]); + } + + for (uint i = 0; i < 16; i++, ptr_data += 2) + { + sprintf (ptr_data, "%02x", ptr_checksum[i]); + } + + *ptr_data = 0; + + snprintf (out_buf, len-1, "%s$%s$%s$%s$%s", + SIGNATURE_KRB5PA, + (char *) krb5pa->user, + (char *) krb5pa->realm, + (char *) krb5pa->salt, + data); + } + else if (hash_mode == 7700) + { + snprintf (out_buf, len-1, "%s$%08X%08X", + (char *) salt.salt_buf, + digest_buf[0], + digest_buf[1]); + } + else if (hash_mode == 7800) + { + snprintf (out_buf, len-1, "%s$%08X%08X%08X%08X%08X", + (char *) salt.salt_buf, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4]); + } + else if (hash_mode == 7900) + { + drupal7_encode ((unsigned char *) digest_buf64, (unsigned char *) ptr_plain); + + // ugly hack start + + char *tmp = (char *) salt.salt_buf_pc; + + ptr_plain[42] = tmp[0]; + + // ugly hack end + + ptr_plain[43] = 0; + + snprintf (out_buf, len-1, "%s%s%s", (char *) salt.salt_sign, (char *) salt.salt_buf, (char *) ptr_plain); + } + else if (hash_mode == 8000) + { + snprintf (out_buf, len-1, "0xc007%s%08x%08x%08x%08x%08x%08x%08x%08x", + (unsigned char *) salt.salt_buf, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4], + digest_buf[5], + digest_buf[6], + digest_buf[7]); + } + else if (hash_mode == 8100) + { + salt.salt_buf[0] = byte_swap_32 (salt.salt_buf[0]); + salt.salt_buf[1] = byte_swap_32 (salt.salt_buf[1]); + + snprintf (out_buf, len-1, "1%s%08x%08x%08x%08x%08x", + (unsigned char *) salt.salt_buf, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4]); + } + else if (hash_mode == 8200) + { + cloudkey_t *cloudkeys = (cloudkey_t *) data.esalts_buf; + + cloudkey_t *cloudkey = &cloudkeys[salt_pos]; + + char data_buf[4096] = { 0 }; + + for (int i = 0, j = 0; i < 512; i += 1, j += 8) + { + sprintf (data_buf + j, "%08x", cloudkey->data_buf[i]); + } + + data_buf[cloudkey->data_len * 2] = 0; + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + digest_buf[5] = byte_swap_32 (digest_buf[5]); + digest_buf[6] = byte_swap_32 (digest_buf[6]); + digest_buf[7] = byte_swap_32 (digest_buf[7]); + + salt.salt_buf[0] = byte_swap_32 (salt.salt_buf[0]); + salt.salt_buf[1] = byte_swap_32 (salt.salt_buf[1]); + salt.salt_buf[2] = byte_swap_32 (salt.salt_buf[2]); + salt.salt_buf[3] = byte_swap_32 (salt.salt_buf[3]); + + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x:%08x%08x%08x%08x:%u:%s", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4], + digest_buf[5], + digest_buf[6], + digest_buf[7], + salt.salt_buf[0], + salt.salt_buf[1], + salt.salt_buf[2], + salt.salt_buf[3], + salt.salt_iter + 1, + data_buf); + } + else if (hash_mode == 8300) + { + char digest_buf_c[34] = { 0 }; + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + + base32_encode (int_to_itoa32, (const u8 *) digest_buf, 20, (u8 *) digest_buf_c); + + digest_buf_c[32] = 0; + + // domain + + const uint salt_pc_len = salt.salt_buf_pc[7]; // what a hack + + char domain_buf_c[33] = { 0 }; + + memcpy (domain_buf_c, (char *) salt.salt_buf_pc, salt_pc_len); + + for (uint i = 0; i < salt_pc_len; i++) + { + const char next = domain_buf_c[i]; + + domain_buf_c[i] = '.'; + + i += next; + } + + domain_buf_c[salt_pc_len] = 0; + + // final + + snprintf (out_buf, len-1, "%s:%s:%s:%u", digest_buf_c, domain_buf_c, (char *) salt.salt_buf, salt.salt_iter); + } + else if (hash_mode == 8500) + { + snprintf (out_buf, len-1, "%s*%s*%08X%08X", SIGNATURE_RACF, (char *) salt.salt_buf, digest_buf[0], digest_buf[1]); + } + else if (hash_mode == 2612) + { + snprintf (out_buf, len-1, "%s%s$%08x%08x%08x%08x", + SIGNATURE_PHPS, + (char *) salt.salt_buf, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3]); + } + else if (hash_mode == 3711) + { + char *salt_ptr = (char *) salt.salt_buf; + + salt_ptr[salt.salt_len - 1] = 0; + + snprintf (out_buf, len-1, "%s%s$%08x%08x%08x%08x", + SIGNATURE_MEDIAWIKI_B, + salt_ptr, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3]); + } + else if (hash_mode == 8800) + { + androidfde_t *androidfdes = (androidfde_t *) data.esalts_buf; + + androidfde_t *androidfde = &androidfdes[salt_pos]; + + char tmp[3073] = { 0 }; + + for (uint i = 0, j = 0; i < 384; i += 1, j += 8) + { + sprintf (tmp + j, "%08x", androidfde->data[i]); + } + + tmp[3072] = 0; + + snprintf (out_buf, len-1, "%s16$%08x%08x%08x%08x$16$%08x%08x%08x%08x$%s", + SIGNATURE_ANDROIDFDE, + byte_swap_32 (salt.salt_buf[0]), + byte_swap_32 (salt.salt_buf[1]), + byte_swap_32 (salt.salt_buf[2]), + byte_swap_32 (salt.salt_buf[3]), + byte_swap_32 (digest_buf[0]), + byte_swap_32 (digest_buf[1]), + byte_swap_32 (digest_buf[2]), + byte_swap_32 (digest_buf[3]), + tmp); + } + else if (hash_mode == 8900) + { + uint N = salt.scrypt_N; + uint r = salt.scrypt_r; + uint p = salt.scrypt_p; + + char base64_salt[32] = { 0 }; + + base64_encode (int_to_base64, (const u8 *) salt.salt_buf, salt.salt_len, (u8 *) base64_salt); + + memset (tmp_buf, 0, 46); + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + digest_buf[5] = byte_swap_32 (digest_buf[5]); + digest_buf[6] = byte_swap_32 (digest_buf[6]); + digest_buf[7] = byte_swap_32 (digest_buf[7]); + digest_buf[8] = 0; // needed for base64_encode () + + base64_encode (int_to_base64, (const u8 *) digest_buf, 32, (u8 *) tmp_buf); + + snprintf (out_buf, len-1, "%s:%i:%i:%i:%s:%s", + SIGNATURE_SCRYPT, + N, + r, + p, + base64_salt, + tmp_buf); + } + else if (hash_mode == 9000) + { + snprintf (out_buf, len-1, "%s", hashfile); + } + else if (hash_mode == 9200) + { + // salt + + pbkdf2_sha256_t *pbkdf2_sha256s = (pbkdf2_sha256_t *) data.esalts_buf; + + pbkdf2_sha256_t *pbkdf2_sha256 = &pbkdf2_sha256s[salt_pos]; + + unsigned char *salt_buf_ptr = (unsigned char *) pbkdf2_sha256->salt_buf; + + // hash + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + digest_buf[5] = byte_swap_32 (digest_buf[5]); + digest_buf[6] = byte_swap_32 (digest_buf[6]); + digest_buf[7] = byte_swap_32 (digest_buf[7]); + digest_buf[8] = 0; // needed for base64_encode () + + char tmp_buf[64] = { 0 }; + + base64_encode (int_to_itoa64, (const u8 *) digest_buf, 32, (u8 *) tmp_buf); + tmp_buf[43] = 0; // cut it here + + // output + + snprintf (out_buf, len-1, "%s%s$%s", SIGNATURE_CISCO8, salt_buf_ptr, tmp_buf); + } + else if (hash_mode == 9300) + { + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + digest_buf[5] = byte_swap_32 (digest_buf[5]); + digest_buf[6] = byte_swap_32 (digest_buf[6]); + digest_buf[7] = byte_swap_32 (digest_buf[7]); + digest_buf[8] = 0; // needed for base64_encode () + + char tmp_buf[64] = { 0 }; + + base64_encode (int_to_itoa64, (const u8 *) digest_buf, 32, (u8 *) tmp_buf); + tmp_buf[43] = 0; // cut it here + + unsigned char *salt_buf_ptr = (unsigned char *) salt.salt_buf; + + snprintf (out_buf, len-1, "%s%s$%s", SIGNATURE_CISCO9, salt_buf_ptr, tmp_buf); + } + else if (hash_mode == 9400) + { + office2007_t *office2007s = (office2007_t *) data.esalts_buf; + + office2007_t *office2007 = &office2007s[salt_pos]; + + snprintf (out_buf, len-1, "%s*%u*%u*%u*%u*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x%08x", + SIGNATURE_OFFICE2007, + 2007, + 20, + office2007->keySize, + 16, + salt.salt_buf[0], + salt.salt_buf[1], + salt.salt_buf[2], + salt.salt_buf[3], + office2007->encryptedVerifier[0], + office2007->encryptedVerifier[1], + office2007->encryptedVerifier[2], + office2007->encryptedVerifier[3], + office2007->encryptedVerifierHash[0], + office2007->encryptedVerifierHash[1], + office2007->encryptedVerifierHash[2], + office2007->encryptedVerifierHash[3], + office2007->encryptedVerifierHash[4]); + } + else if (hash_mode == 9500) + { + office2010_t *office2010s = (office2010_t *) data.esalts_buf; + + office2010_t *office2010 = &office2010s[salt_pos]; + + snprintf (out_buf, len-1, "%s*%u*%u*%u*%u*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x%08x%08x%08x%08x", SIGNATURE_OFFICE2010, 2010, 100000, 128, 16, + + salt.salt_buf[0], + salt.salt_buf[1], + salt.salt_buf[2], + salt.salt_buf[3], + office2010->encryptedVerifier[0], + office2010->encryptedVerifier[1], + office2010->encryptedVerifier[2], + office2010->encryptedVerifier[3], + office2010->encryptedVerifierHash[0], + office2010->encryptedVerifierHash[1], + office2010->encryptedVerifierHash[2], + office2010->encryptedVerifierHash[3], + office2010->encryptedVerifierHash[4], + office2010->encryptedVerifierHash[5], + office2010->encryptedVerifierHash[6], + office2010->encryptedVerifierHash[7]); + } + else if (hash_mode == 9600) + { + office2013_t *office2013s = (office2013_t *) data.esalts_buf; + + office2013_t *office2013 = &office2013s[salt_pos]; + + snprintf (out_buf, len-1, "%s*%u*%u*%u*%u*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x%08x%08x%08x%08x", SIGNATURE_OFFICE2013, 2013, 100000, 256, 16, + + salt.salt_buf[0], + salt.salt_buf[1], + salt.salt_buf[2], + salt.salt_buf[3], + office2013->encryptedVerifier[0], + office2013->encryptedVerifier[1], + office2013->encryptedVerifier[2], + office2013->encryptedVerifier[3], + office2013->encryptedVerifierHash[0], + office2013->encryptedVerifierHash[1], + office2013->encryptedVerifierHash[2], + office2013->encryptedVerifierHash[3], + office2013->encryptedVerifierHash[4], + office2013->encryptedVerifierHash[5], + office2013->encryptedVerifierHash[6], + office2013->encryptedVerifierHash[7]); + } + else if (hash_mode == 9700) + { + oldoffice01_t *oldoffice01s = (oldoffice01_t *) data.esalts_buf; + + oldoffice01_t *oldoffice01 = &oldoffice01s[salt_pos]; + + snprintf (out_buf, len-1, "%s*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x", + (oldoffice01->version == 0) ? SIGNATURE_OLDOFFICE0 : SIGNATURE_OLDOFFICE1, + byte_swap_32 (salt.salt_buf[0]), + byte_swap_32 (salt.salt_buf[1]), + byte_swap_32 (salt.salt_buf[2]), + byte_swap_32 (salt.salt_buf[3]), + byte_swap_32 (oldoffice01->encryptedVerifier[0]), + byte_swap_32 (oldoffice01->encryptedVerifier[1]), + byte_swap_32 (oldoffice01->encryptedVerifier[2]), + byte_swap_32 (oldoffice01->encryptedVerifier[3]), + byte_swap_32 (oldoffice01->encryptedVerifierHash[0]), + byte_swap_32 (oldoffice01->encryptedVerifierHash[1]), + byte_swap_32 (oldoffice01->encryptedVerifierHash[2]), + byte_swap_32 (oldoffice01->encryptedVerifierHash[3])); + } + else if (hash_mode == 9710) + { + oldoffice01_t *oldoffice01s = (oldoffice01_t *) data.esalts_buf; + + oldoffice01_t *oldoffice01 = &oldoffice01s[salt_pos]; + + snprintf (out_buf, len-1, "%s*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x", + (oldoffice01->version == 0) ? SIGNATURE_OLDOFFICE0 : SIGNATURE_OLDOFFICE1, + byte_swap_32 (salt.salt_buf[0]), + byte_swap_32 (salt.salt_buf[1]), + byte_swap_32 (salt.salt_buf[2]), + byte_swap_32 (salt.salt_buf[3]), + byte_swap_32 (oldoffice01->encryptedVerifier[0]), + byte_swap_32 (oldoffice01->encryptedVerifier[1]), + byte_swap_32 (oldoffice01->encryptedVerifier[2]), + byte_swap_32 (oldoffice01->encryptedVerifier[3]), + byte_swap_32 (oldoffice01->encryptedVerifierHash[0]), + byte_swap_32 (oldoffice01->encryptedVerifierHash[1]), + byte_swap_32 (oldoffice01->encryptedVerifierHash[2]), + byte_swap_32 (oldoffice01->encryptedVerifierHash[3])); + } + else if (hash_mode == 9720) + { + oldoffice01_t *oldoffice01s = (oldoffice01_t *) data.esalts_buf; + + oldoffice01_t *oldoffice01 = &oldoffice01s[salt_pos]; + + u8 *rc4key = (u8 *) oldoffice01->rc4key; + + snprintf (out_buf, len-1, "%s*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x:%02x%02x%02x%02x%02x", + (oldoffice01->version == 0) ? SIGNATURE_OLDOFFICE0 : SIGNATURE_OLDOFFICE1, + byte_swap_32 (salt.salt_buf[0]), + byte_swap_32 (salt.salt_buf[1]), + byte_swap_32 (salt.salt_buf[2]), + byte_swap_32 (salt.salt_buf[3]), + byte_swap_32 (oldoffice01->encryptedVerifier[0]), + byte_swap_32 (oldoffice01->encryptedVerifier[1]), + byte_swap_32 (oldoffice01->encryptedVerifier[2]), + byte_swap_32 (oldoffice01->encryptedVerifier[3]), + byte_swap_32 (oldoffice01->encryptedVerifierHash[0]), + byte_swap_32 (oldoffice01->encryptedVerifierHash[1]), + byte_swap_32 (oldoffice01->encryptedVerifierHash[2]), + byte_swap_32 (oldoffice01->encryptedVerifierHash[3]), + rc4key[0], + rc4key[1], + rc4key[2], + rc4key[3], + rc4key[4]); + } + else if (hash_mode == 9800) + { + oldoffice34_t *oldoffice34s = (oldoffice34_t *) data.esalts_buf; + + oldoffice34_t *oldoffice34 = &oldoffice34s[salt_pos]; + + snprintf (out_buf, len-1, "%s*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x%08x", + (oldoffice34->version == 3) ? SIGNATURE_OLDOFFICE3 : SIGNATURE_OLDOFFICE4, + salt.salt_buf[0], + salt.salt_buf[1], + salt.salt_buf[2], + salt.salt_buf[3], + byte_swap_32 (oldoffice34->encryptedVerifier[0]), + byte_swap_32 (oldoffice34->encryptedVerifier[1]), + byte_swap_32 (oldoffice34->encryptedVerifier[2]), + byte_swap_32 (oldoffice34->encryptedVerifier[3]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[0]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[1]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[2]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[3]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[4])); + } + else if (hash_mode == 9810) + { + oldoffice34_t *oldoffice34s = (oldoffice34_t *) data.esalts_buf; + + oldoffice34_t *oldoffice34 = &oldoffice34s[salt_pos]; + + snprintf (out_buf, len-1, "%s*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x%08x", + (oldoffice34->version == 3) ? SIGNATURE_OLDOFFICE3 : SIGNATURE_OLDOFFICE4, + salt.salt_buf[0], + salt.salt_buf[1], + salt.salt_buf[2], + salt.salt_buf[3], + byte_swap_32 (oldoffice34->encryptedVerifier[0]), + byte_swap_32 (oldoffice34->encryptedVerifier[1]), + byte_swap_32 (oldoffice34->encryptedVerifier[2]), + byte_swap_32 (oldoffice34->encryptedVerifier[3]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[0]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[1]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[2]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[3]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[4])); + } + else if (hash_mode == 9820) + { + oldoffice34_t *oldoffice34s = (oldoffice34_t *) data.esalts_buf; + + oldoffice34_t *oldoffice34 = &oldoffice34s[salt_pos]; + + u8 *rc4key = (u8 *) oldoffice34->rc4key; + + snprintf (out_buf, len-1, "%s*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x%08x:%02x%02x%02x%02x%02x", + (oldoffice34->version == 3) ? SIGNATURE_OLDOFFICE3 : SIGNATURE_OLDOFFICE4, + salt.salt_buf[0], + salt.salt_buf[1], + salt.salt_buf[2], + salt.salt_buf[3], + byte_swap_32 (oldoffice34->encryptedVerifier[0]), + byte_swap_32 (oldoffice34->encryptedVerifier[1]), + byte_swap_32 (oldoffice34->encryptedVerifier[2]), + byte_swap_32 (oldoffice34->encryptedVerifier[3]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[0]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[1]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[2]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[3]), + byte_swap_32 (oldoffice34->encryptedVerifierHash[4]), + rc4key[0], + rc4key[1], + rc4key[2], + rc4key[3], + rc4key[4]); + } + else if (hash_mode == 10000) + { + // salt + + pbkdf2_sha256_t *pbkdf2_sha256s = (pbkdf2_sha256_t *) data.esalts_buf; + + pbkdf2_sha256_t *pbkdf2_sha256 = &pbkdf2_sha256s[salt_pos]; + + unsigned char *salt_buf_ptr = (unsigned char *) pbkdf2_sha256->salt_buf; + + // hash + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + digest_buf[2] = byte_swap_32 (digest_buf[2]); + digest_buf[3] = byte_swap_32 (digest_buf[3]); + digest_buf[4] = byte_swap_32 (digest_buf[4]); + digest_buf[5] = byte_swap_32 (digest_buf[5]); + digest_buf[6] = byte_swap_32 (digest_buf[6]); + digest_buf[7] = byte_swap_32 (digest_buf[7]); + digest_buf[8] = 0; // needed for base64_encode () + + char tmp_buf[64] = { 0 }; + + base64_encode (int_to_base64, (const u8 *) digest_buf, 32, (u8 *) tmp_buf); + + // output + + snprintf (out_buf, len-1, "%s%i$%s$%s", SIGNATURE_DJANGOPBKDF2, salt.salt_iter + 1, salt_buf_ptr, tmp_buf); + } + else if (hash_mode == 10100) + { + snprintf (out_buf, len-1, "%08x%08x:%u:%u:%08x%08x%08x%08x", + digest_buf[0], + digest_buf[1], + 2, + 4, + byte_swap_32 (salt.salt_buf[0]), + byte_swap_32 (salt.salt_buf[1]), + byte_swap_32 (salt.salt_buf[2]), + byte_swap_32 (salt.salt_buf[3])); + } + else if (hash_mode == 10200) + { + cram_md5_t *cram_md5s = (cram_md5_t *) data.esalts_buf; + + cram_md5_t *cram_md5 = &cram_md5s[salt_pos]; + + // challenge + + char challenge[100] = { 0 }; + + base64_encode (int_to_base64, (const u8 *) salt.salt_buf, salt.salt_len, (u8 *) challenge); + + // response + + char tmp_buf[100] = { 0 }; + + uint tmp_len = snprintf (tmp_buf, 100, "%s %08x%08x%08x%08x", + (char *) cram_md5->user, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3]); + + char response[100] = { 0 }; + + base64_encode (int_to_base64, (const u8 *) tmp_buf, tmp_len, (u8 *) response); + + snprintf (out_buf, len-1, "%s%s$%s", SIGNATURE_CRAM_MD5, challenge, response); + } + else if (hash_mode == 10300) + { + char tmp_buf[100] = { 0 }; + + memcpy (tmp_buf + 0, digest_buf, 20); + memcpy (tmp_buf + 20, salt.salt_buf, salt.salt_len); + + uint tmp_len = 20 + salt.salt_len; + + // base64 encode it + + char base64_encoded[100] = { 0 }; + + base64_encode (int_to_base64, (const u8 *) tmp_buf, tmp_len, (u8 *) base64_encoded); + + snprintf (out_buf, len-1, "%s%i}%s", SIGNATURE_SAPH_SHA1, salt.salt_iter + 1, base64_encoded); + } + else if (hash_mode == 10400) + { + pdf_t *pdfs = (pdf_t *) data.esalts_buf; + + pdf_t *pdf = &pdfs[salt_pos]; + + snprintf (out_buf, len-1, "$pdf$%d*%d*%d*%d*%d*%d*%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x", + + pdf->V, + pdf->R, + 40, + pdf->P, + pdf->enc_md, + pdf->id_len, + byte_swap_32 (pdf->id_buf[0]), + byte_swap_32 (pdf->id_buf[1]), + byte_swap_32 (pdf->id_buf[2]), + byte_swap_32 (pdf->id_buf[3]), + pdf->u_len, + byte_swap_32 (pdf->u_buf[0]), + byte_swap_32 (pdf->u_buf[1]), + byte_swap_32 (pdf->u_buf[2]), + byte_swap_32 (pdf->u_buf[3]), + byte_swap_32 (pdf->u_buf[4]), + byte_swap_32 (pdf->u_buf[5]), + byte_swap_32 (pdf->u_buf[6]), + byte_swap_32 (pdf->u_buf[7]), + pdf->o_len, + byte_swap_32 (pdf->o_buf[0]), + byte_swap_32 (pdf->o_buf[1]), + byte_swap_32 (pdf->o_buf[2]), + byte_swap_32 (pdf->o_buf[3]), + byte_swap_32 (pdf->o_buf[4]), + byte_swap_32 (pdf->o_buf[5]), + byte_swap_32 (pdf->o_buf[6]), + byte_swap_32 (pdf->o_buf[7]) + ); + } + else if (hash_mode == 10410) + { + pdf_t *pdfs = (pdf_t *) data.esalts_buf; + + pdf_t *pdf = &pdfs[salt_pos]; + + snprintf (out_buf, len-1, "$pdf$%d*%d*%d*%d*%d*%d*%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x", + + pdf->V, + pdf->R, + 40, + pdf->P, + pdf->enc_md, + pdf->id_len, + byte_swap_32 (pdf->id_buf[0]), + byte_swap_32 (pdf->id_buf[1]), + byte_swap_32 (pdf->id_buf[2]), + byte_swap_32 (pdf->id_buf[3]), + pdf->u_len, + byte_swap_32 (pdf->u_buf[0]), + byte_swap_32 (pdf->u_buf[1]), + byte_swap_32 (pdf->u_buf[2]), + byte_swap_32 (pdf->u_buf[3]), + byte_swap_32 (pdf->u_buf[4]), + byte_swap_32 (pdf->u_buf[5]), + byte_swap_32 (pdf->u_buf[6]), + byte_swap_32 (pdf->u_buf[7]), + pdf->o_len, + byte_swap_32 (pdf->o_buf[0]), + byte_swap_32 (pdf->o_buf[1]), + byte_swap_32 (pdf->o_buf[2]), + byte_swap_32 (pdf->o_buf[3]), + byte_swap_32 (pdf->o_buf[4]), + byte_swap_32 (pdf->o_buf[5]), + byte_swap_32 (pdf->o_buf[6]), + byte_swap_32 (pdf->o_buf[7]) + ); + } + else if (hash_mode == 10420) + { + pdf_t *pdfs = (pdf_t *) data.esalts_buf; + + pdf_t *pdf = &pdfs[salt_pos]; + + u8 *rc4key = (u8 *) pdf->rc4key; + + snprintf (out_buf, len-1, "$pdf$%d*%d*%d*%d*%d*%d*%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x:%02x%02x%02x%02x%02x", + + pdf->V, + pdf->R, + 40, + pdf->P, + pdf->enc_md, + pdf->id_len, + byte_swap_32 (pdf->id_buf[0]), + byte_swap_32 (pdf->id_buf[1]), + byte_swap_32 (pdf->id_buf[2]), + byte_swap_32 (pdf->id_buf[3]), + pdf->u_len, + byte_swap_32 (pdf->u_buf[0]), + byte_swap_32 (pdf->u_buf[1]), + byte_swap_32 (pdf->u_buf[2]), + byte_swap_32 (pdf->u_buf[3]), + byte_swap_32 (pdf->u_buf[4]), + byte_swap_32 (pdf->u_buf[5]), + byte_swap_32 (pdf->u_buf[6]), + byte_swap_32 (pdf->u_buf[7]), + pdf->o_len, + byte_swap_32 (pdf->o_buf[0]), + byte_swap_32 (pdf->o_buf[1]), + byte_swap_32 (pdf->o_buf[2]), + byte_swap_32 (pdf->o_buf[3]), + byte_swap_32 (pdf->o_buf[4]), + byte_swap_32 (pdf->o_buf[5]), + byte_swap_32 (pdf->o_buf[6]), + byte_swap_32 (pdf->o_buf[7]), + rc4key[0], + rc4key[1], + rc4key[2], + rc4key[3], + rc4key[4] + ); + } + else if (hash_mode == 10500) + { + pdf_t *pdfs = (pdf_t *) data.esalts_buf; + + pdf_t *pdf = &pdfs[salt_pos]; + + if (pdf->id_len == 32) + { + snprintf (out_buf, len-1, "$pdf$%d*%d*%d*%d*%d*%d*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x", + + pdf->V, + pdf->R, + 128, + pdf->P, + pdf->enc_md, + pdf->id_len, + byte_swap_32 (pdf->id_buf[0]), + byte_swap_32 (pdf->id_buf[1]), + byte_swap_32 (pdf->id_buf[2]), + byte_swap_32 (pdf->id_buf[3]), + byte_swap_32 (pdf->id_buf[4]), + byte_swap_32 (pdf->id_buf[5]), + byte_swap_32 (pdf->id_buf[6]), + byte_swap_32 (pdf->id_buf[7]), + pdf->u_len, + byte_swap_32 (pdf->u_buf[0]), + byte_swap_32 (pdf->u_buf[1]), + byte_swap_32 (pdf->u_buf[2]), + byte_swap_32 (pdf->u_buf[3]), + byte_swap_32 (pdf->u_buf[4]), + byte_swap_32 (pdf->u_buf[5]), + byte_swap_32 (pdf->u_buf[6]), + byte_swap_32 (pdf->u_buf[7]), + pdf->o_len, + byte_swap_32 (pdf->o_buf[0]), + byte_swap_32 (pdf->o_buf[1]), + byte_swap_32 (pdf->o_buf[2]), + byte_swap_32 (pdf->o_buf[3]), + byte_swap_32 (pdf->o_buf[4]), + byte_swap_32 (pdf->o_buf[5]), + byte_swap_32 (pdf->o_buf[6]), + byte_swap_32 (pdf->o_buf[7]) + ); + } + else + { + snprintf (out_buf, len-1, "$pdf$%d*%d*%d*%d*%d*%d*%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x", + + pdf->V, + pdf->R, + 128, + pdf->P, + pdf->enc_md, + pdf->id_len, + byte_swap_32 (pdf->id_buf[0]), + byte_swap_32 (pdf->id_buf[1]), + byte_swap_32 (pdf->id_buf[2]), + byte_swap_32 (pdf->id_buf[3]), + pdf->u_len, + byte_swap_32 (pdf->u_buf[0]), + byte_swap_32 (pdf->u_buf[1]), + byte_swap_32 (pdf->u_buf[2]), + byte_swap_32 (pdf->u_buf[3]), + byte_swap_32 (pdf->u_buf[4]), + byte_swap_32 (pdf->u_buf[5]), + byte_swap_32 (pdf->u_buf[6]), + byte_swap_32 (pdf->u_buf[7]), + pdf->o_len, + byte_swap_32 (pdf->o_buf[0]), + byte_swap_32 (pdf->o_buf[1]), + byte_swap_32 (pdf->o_buf[2]), + byte_swap_32 (pdf->o_buf[3]), + byte_swap_32 (pdf->o_buf[4]), + byte_swap_32 (pdf->o_buf[5]), + byte_swap_32 (pdf->o_buf[6]), + byte_swap_32 (pdf->o_buf[7]) + ); + } + } + else if (hash_mode == 10600) + { + uint digest_idx = salt.digests_offset + digest_pos; + + hashinfo_t **hashinfo_ptr = data.hash_info; + char *hash_buf = hashinfo_ptr[digest_idx]->orighash; + + snprintf (out_buf, len-1, "%s", hash_buf); + } + else if (hash_mode == 10700) + { + uint digest_idx = salt.digests_offset + digest_pos; + + hashinfo_t **hashinfo_ptr = data.hash_info; + char *hash_buf = hashinfo_ptr[digest_idx]->orighash; + + snprintf (out_buf, len-1, "%s", hash_buf); + } + else if (hash_mode == 10900) + { + uint digest_idx = salt.digests_offset + digest_pos; + + hashinfo_t **hashinfo_ptr = data.hash_info; + char *hash_buf = hashinfo_ptr[digest_idx]->orighash; + + snprintf (out_buf, len-1, "%s", hash_buf); + } + else if (hash_mode == 11100) + { + u32 salt_challenge = salt.salt_buf[0]; + + salt_challenge = byte_swap_32 (salt_challenge); + + unsigned char *user_name = (unsigned char *) (salt.salt_buf + 1); + + snprintf (out_buf, len-1, "%s%s*%08x*%08x%08x%08x%08x", + SIGNATURE_POSTGRESQL_AUTH, + user_name, + salt_challenge, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3]); + } + else if (hash_mode == 11200) + { + snprintf (out_buf, len-1, "%s%s*%08x%08x%08x%08x%08x", + SIGNATURE_MYSQL_AUTH, + (unsigned char *) salt.salt_buf, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4]); + } + else if (hash_mode == 11300) + { + bitcoin_wallet_t *bitcoin_wallets = (bitcoin_wallet_t *) data.esalts_buf; + + bitcoin_wallet_t *bitcoin_wallet = &bitcoin_wallets[salt_pos]; + + const uint cry_master_len = bitcoin_wallet->cry_master_len; + const uint ckey_len = bitcoin_wallet->ckey_len; + const uint public_key_len = bitcoin_wallet->public_key_len; + + char *cry_master_buf = (char *) mymalloc ((cry_master_len * 2) + 1); + char *ckey_buf = (char *) mymalloc ((ckey_len * 2) + 1); + char *public_key_buf = (char *) mymalloc ((public_key_len * 2) + 1); + + for (uint i = 0, j = 0; i < cry_master_len; i += 1, j += 2) + { + const u8 *ptr = (const u8 *) bitcoin_wallet->cry_master_buf; + + sprintf (cry_master_buf + j, "%02x", ptr[i]); + } + + for (uint i = 0, j = 0; i < ckey_len; i += 1, j += 2) + { + const u8 *ptr = (const u8 *) bitcoin_wallet->ckey_buf; + + sprintf (ckey_buf + j, "%02x", ptr[i]); + } + + for (uint i = 0, j = 0; i < public_key_len; i += 1, j += 2) + { + const u8 *ptr = (const u8 *) bitcoin_wallet->public_key_buf; + + sprintf (public_key_buf + j, "%02x", ptr[i]); + } + + snprintf (out_buf, len-1, "%s%d$%s$%d$%s$%d$%d$%s$%d$%s", + SIGNATURE_BITCOIN_WALLET, + cry_master_len * 2, + cry_master_buf, + salt.salt_len, + (unsigned char *) salt.salt_buf, + salt.salt_iter + 1, + ckey_len * 2, + ckey_buf, + public_key_len * 2, + public_key_buf + ); + + myfree (cry_master_buf); + myfree (ckey_buf); + myfree (public_key_buf); + } + else if (hash_mode == 11400) + { + uint digest_idx = salt.digests_offset + digest_pos; + + hashinfo_t **hashinfo_ptr = data.hash_info; + char *hash_buf = hashinfo_ptr[digest_idx]->orighash; + + snprintf (out_buf, len-1, "%s", hash_buf); + } + else if (hash_mode == 11600) + { + seven_zip_t *seven_zips = (seven_zip_t *) data.esalts_buf; + + seven_zip_t *seven_zip = &seven_zips[salt_pos]; + + const uint data_len = seven_zip->data_len; + + char *data_buf = (char *) mymalloc ((data_len * 2) + 1); + + for (uint i = 0, j = 0; i < data_len; i += 1, j += 2) + { + const u8 *ptr = (const u8 *) seven_zip->data_buf; + + sprintf (data_buf + j, "%02x", ptr[i]); + } + + snprintf (out_buf, len-1, "%s%u$%u$%u$%s$%u$%08x%08x%08x%08x$%u$%u$%u$%s", + SIGNATURE_SEVEN_ZIP, + 0, + salt.salt_sign[0], + 0, + (char *) seven_zip->salt_buf, + seven_zip->iv_len, + seven_zip->iv_buf[0], + seven_zip->iv_buf[1], + seven_zip->iv_buf[2], + seven_zip->iv_buf[3], + seven_zip->crc, + seven_zip->data_len, + seven_zip->unpack_size, + data_buf); + + myfree (data_buf); + } + else if (hash_mode == 11700) + { + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4], + digest_buf[5], + digest_buf[6], + digest_buf[7]); + } + else if (hash_mode == 11800) + { + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", + digest_buf[ 0], + digest_buf[ 1], + digest_buf[ 2], + digest_buf[ 3], + digest_buf[ 4], + digest_buf[ 5], + digest_buf[ 6], + digest_buf[ 7], + digest_buf[ 8], + digest_buf[ 9], + digest_buf[10], + digest_buf[11], + digest_buf[12], + digest_buf[13], + digest_buf[14], + digest_buf[15]); + } + else if (hash_mode == 11900) + { + uint digest_idx = salt.digests_offset + digest_pos; + + hashinfo_t **hashinfo_ptr = data.hash_info; + char *hash_buf = hashinfo_ptr[digest_idx]->orighash; + + snprintf (out_buf, len-1, "%s", hash_buf); + } + else if (hash_mode == 12000) + { + uint digest_idx = salt.digests_offset + digest_pos; + + hashinfo_t **hashinfo_ptr = data.hash_info; + char *hash_buf = hashinfo_ptr[digest_idx]->orighash; + + snprintf (out_buf, len-1, "%s", hash_buf); + } + else if (hash_mode == 12100) + { + uint digest_idx = salt.digests_offset + digest_pos; + + hashinfo_t **hashinfo_ptr = data.hash_info; + char *hash_buf = hashinfo_ptr[digest_idx]->orighash; + + snprintf (out_buf, len-1, "%s", hash_buf); + } + else if (hash_mode == 12200) + { + uint *ptr_digest = digest_buf; + uint *ptr_salt = salt.salt_buf; + + snprintf (out_buf, len-1, "%s0$1$%08x%08x$%08x%08x", + SIGNATURE_ECRYPTFS, + ptr_salt[0], + ptr_salt[1], + ptr_digest[0], + ptr_digest[1]); + } + else if (hash_mode == 12300) + { + uint *ptr_digest = digest_buf; + uint *ptr_salt = salt.salt_buf; + + snprintf (out_buf, len-1, "%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X", + ptr_digest[ 0], ptr_digest[ 1], + ptr_digest[ 2], ptr_digest[ 3], + ptr_digest[ 4], ptr_digest[ 5], + ptr_digest[ 6], ptr_digest[ 7], + ptr_digest[ 8], ptr_digest[ 9], + ptr_digest[10], ptr_digest[11], + ptr_digest[12], ptr_digest[13], + ptr_digest[14], ptr_digest[15], + ptr_salt[0], + ptr_salt[1], + ptr_salt[2], + ptr_salt[3]); + } + else if (hash_mode == 12400) + { + // encode iteration count + + char salt_iter[5] = { 0 }; + + salt_iter[0] = int_to_itoa64 ((salt.salt_iter ) & 0x3f); + salt_iter[1] = int_to_itoa64 ((salt.salt_iter >> 6) & 0x3f); + salt_iter[2] = int_to_itoa64 ((salt.salt_iter >> 12) & 0x3f); + salt_iter[3] = int_to_itoa64 ((salt.salt_iter >> 18) & 0x3f); + salt_iter[4] = 0; + + // encode salt + + ptr_salt[0] = int_to_itoa64 ((salt.salt_buf[0] ) & 0x3f); + ptr_salt[1] = int_to_itoa64 ((salt.salt_buf[0] >> 6) & 0x3f); + ptr_salt[2] = int_to_itoa64 ((salt.salt_buf[0] >> 12) & 0x3f); + ptr_salt[3] = int_to_itoa64 ((salt.salt_buf[0] >> 18) & 0x3f); + ptr_salt[4] = 0; + + // encode digest + + memset (tmp_buf, 0, sizeof (tmp_buf)); + + digest_buf[0] = byte_swap_32 (digest_buf[0]); + digest_buf[1] = byte_swap_32 (digest_buf[1]); + + memcpy (tmp_buf, digest_buf, 8); + + base64_encode (int_to_itoa64, (const u8 *) tmp_buf, 8, (u8 *) ptr_plain); + + ptr_plain[11] = 0; + + // fill the resulting buffer + + snprintf (out_buf, len - 1, "_%s%s%s", salt_iter, ptr_salt, ptr_plain); + } + else if (hash_mode == 12500) + { + snprintf (out_buf, len - 1, "%s*0*%08x%08x*%08x%08x%08x%08x", + SIGNATURE_RAR3, + byte_swap_32 (salt.salt_buf[0]), + byte_swap_32 (salt.salt_buf[1]), + salt.salt_buf[2], + salt.salt_buf[3], + salt.salt_buf[4], + salt.salt_buf[5]); + } + else if (hash_mode == 12600) + { + snprintf (out_buf, len - 1, "%08x%08x%08x%08x%08x%08x%08x%08x", + digest_buf[0] + salt.salt_buf_pc[0], + digest_buf[1] + salt.salt_buf_pc[1], + digest_buf[2] + salt.salt_buf_pc[2], + digest_buf[3] + salt.salt_buf_pc[3], + digest_buf[4] + salt.salt_buf_pc[4], + digest_buf[5] + salt.salt_buf_pc[5], + digest_buf[6] + salt.salt_buf_pc[6], + digest_buf[7] + salt.salt_buf_pc[7]); + } + else if (hash_mode == 12700) + { + uint digest_idx = salt.digests_offset + digest_pos; + + hashinfo_t **hashinfo_ptr = data.hash_info; + char *hash_buf = hashinfo_ptr[digest_idx]->orighash; + + snprintf (out_buf, len-1, "%s", hash_buf); + } + else if (hash_mode == 12800) + { + const u8 *ptr = (const u8 *) salt.salt_buf; + + snprintf (out_buf, len-1, "%s,%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x,%d,%08x%08x%08x%08x%08x%08x%08x%08x", + SIGNATURE_MS_DRSR, + ptr[0], + ptr[1], + ptr[2], + ptr[3], + ptr[4], + ptr[5], + ptr[6], + ptr[7], + ptr[8], + ptr[9], + salt.salt_iter + 1, + byte_swap_32 (digest_buf[0]), + byte_swap_32 (digest_buf[1]), + byte_swap_32 (digest_buf[2]), + byte_swap_32 (digest_buf[3]), + byte_swap_32 (digest_buf[4]), + byte_swap_32 (digest_buf[5]), + byte_swap_32 (digest_buf[6]), + byte_swap_32 (digest_buf[7]) + ); + } + else if (hash_mode == 12900) + { + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", + salt.salt_buf[ 4], + salt.salt_buf[ 5], + salt.salt_buf[ 6], + salt.salt_buf[ 7], + salt.salt_buf[ 8], + salt.salt_buf[ 9], + salt.salt_buf[10], + salt.salt_buf[11], + byte_swap_32 (digest_buf[0]), + byte_swap_32 (digest_buf[1]), + byte_swap_32 (digest_buf[2]), + byte_swap_32 (digest_buf[3]), + byte_swap_32 (digest_buf[4]), + byte_swap_32 (digest_buf[5]), + byte_swap_32 (digest_buf[6]), + byte_swap_32 (digest_buf[7]), + salt.salt_buf[ 0], + salt.salt_buf[ 1], + salt.salt_buf[ 2], + salt.salt_buf[ 3] + ); + } + else if (hash_mode == 13000) + { + rar5_t *rar5s = (rar5_t *) data.esalts_buf; + + rar5_t *rar5 = &rar5s[salt_pos]; + + snprintf (out_buf, len-1, "$rar5$16$%08x%08x%08x%08x$%u$%08x%08x%08x%08x$8$%08x%08x", + salt.salt_buf[0], + salt.salt_buf[1], + salt.salt_buf[2], + salt.salt_buf[3], + salt.salt_sign[0], + rar5->iv[0], + rar5->iv[1], + rar5->iv[2], + rar5->iv[3], + byte_swap_32 (digest_buf[0]), + byte_swap_32 (digest_buf[1]) + ); + } + else if (hash_mode == 13100) + { + krb5tgs_t *krb5tgss = (krb5tgs_t *) data.esalts_buf; + + krb5tgs_t *krb5tgs = &krb5tgss[salt_pos]; + + u8 *ptr_checksum = (u8 *) krb5tgs->checksum; + u8 *ptr_edata2 = (u8 *) krb5tgs->edata2; + + char data[2560 * 4 * 2] = { 0 }; + + char *ptr_data = data; + + for (uint i = 0; i < 16; i++, ptr_data += 2) + sprintf (ptr_data, "%02x", ptr_checksum[i]); + + /* skip '$' */ + ptr_data++; + + for (uint i = 0; i < krb5tgs->edata2_len; i++, ptr_data += 2) + sprintf (ptr_data, "%02x", ptr_edata2[i]); + + snprintf (out_buf, len-1, "%s$%s$%s$%s", + SIGNATURE_KRB5TGS, + (char *) krb5tgs->account_info, + data, + data + 33); + } + else if (hash_mode == 13200) + { + snprintf (out_buf, len-1, "%s*%d*%08x%08x%08x%08x*%08x%08x%08x%08x%08x%08x", + SIGNATURE_AXCRYPT, + salt.salt_iter, + salt.salt_buf[0], + salt.salt_buf[1], + salt.salt_buf[2], + salt.salt_buf[3], + salt.salt_buf[4], + salt.salt_buf[5], + salt.salt_buf[6], + salt.salt_buf[7], + salt.salt_buf[8], + salt.salt_buf[9]); + } + else if (hash_mode == 13300) + { + snprintf (out_buf, len-1, "%s$%08x%08x%08x%08x", + SIGNATURE_AXCRYPT_SHA1, + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3]); + } + else if (hash_mode == 13400) + { + keepass_t *keepasss = (keepass_t *) data.esalts_buf; + + keepass_t *keepass = &keepasss[salt_pos]; + + u32 version = (u32) keepass->version; + u32 rounds = salt.salt_iter; + u32 algorithm = (u32) keepass->algorithm; + u32 keyfile_len = (u32) keepass->keyfile_len; + + u32 *ptr_final_random_seed = (u32 *) keepass->final_random_seed ; + u32 *ptr_transf_random_seed = (u32 *) keepass->transf_random_seed ; + u32 *ptr_enc_iv = (u32 *) keepass->enc_iv ; + u32 *ptr_contents_hash = (u32 *) keepass->contents_hash ; + u32 *ptr_keyfile = (u32 *) keepass->keyfile ; + + /* specific to version 1 */ + u32 contents_len; + u32 *ptr_contents; + + /* specific to version 2 */ + u32 expected_bytes_len; + u32 *ptr_expected_bytes; + + u32 final_random_seed_len; + u32 transf_random_seed_len; + u32 enc_iv_len; + u32 contents_hash_len; + + transf_random_seed_len = 8; + enc_iv_len = 4; + contents_hash_len = 8; + final_random_seed_len = 8; + + if (version == 1) + final_random_seed_len = 4; + + snprintf (out_buf, len-1, "%s*%d*%d*%d", + SIGNATURE_KEEPASS, + version, + rounds, + algorithm); + + char *ptr_data = out_buf; + + ptr_data += strlen(out_buf); + + *ptr_data = '*'; + ptr_data++; + + for (uint i = 0; i < final_random_seed_len; i++, ptr_data += 8) + sprintf (ptr_data, "%08x", ptr_final_random_seed[i]); + + *ptr_data = '*'; + ptr_data++; + + for (uint i = 0; i < transf_random_seed_len; i++, ptr_data += 8) + sprintf (ptr_data, "%08x", ptr_transf_random_seed[i]); + + *ptr_data = '*'; + ptr_data++; + + for (uint i = 0; i < enc_iv_len; i++, ptr_data += 8) + sprintf (ptr_data, "%08x", ptr_enc_iv[i]); + + *ptr_data = '*'; + ptr_data++; + + if (version == 1) + { + contents_len = (u32) keepass->contents_len; + ptr_contents = (u32 *) keepass->contents; + + for (uint i = 0; i < contents_hash_len; i++, ptr_data += 8) + sprintf (ptr_data, "%08x", ptr_contents_hash[i]); + + *ptr_data = '*'; + ptr_data++; + + /* inline flag */ + *ptr_data = '1'; + ptr_data++; + + *ptr_data = '*'; + ptr_data++; + + char ptr_contents_len[10] = { 0 }; + + sprintf ((char*) ptr_contents_len, "%d", contents_len); + + sprintf (ptr_data, "%d", contents_len); + + ptr_data += strlen(ptr_contents_len); + + *ptr_data = '*'; + ptr_data++; + + for (uint i = 0; i < contents_len / 4; i++, ptr_data += 8) + sprintf (ptr_data, "%08x", ptr_contents[i]); + } + else if (version == 2) + { + expected_bytes_len = 8; + ptr_expected_bytes = (u32 *) keepass->expected_bytes ; + + for (uint i = 0; i < expected_bytes_len; i++, ptr_data += 8) + sprintf (ptr_data, "%08x", ptr_expected_bytes[i]); + + *ptr_data = '*'; + ptr_data++; + + for (uint i = 0; i < contents_hash_len; i++, ptr_data += 8) + sprintf (ptr_data, "%08x", ptr_contents_hash[i]); + } + if (keyfile_len) + { + *ptr_data = '*'; + ptr_data++; + + /* inline flag */ + *ptr_data = '1'; + ptr_data++; + + *ptr_data = '*'; + ptr_data++; + + sprintf (ptr_data, "%d", keyfile_len); + + ptr_data += 2; + + *ptr_data = '*'; + ptr_data++; + + for (uint i = 0; i < 8; i++, ptr_data += 8) + sprintf (ptr_data, "%08x", ptr_keyfile[i]); + } + } + else if (hash_mode == 13500) + { + pstoken_t *pstokens = (pstoken_t *) data.esalts_buf; + + pstoken_t *pstoken = &pstokens[salt_pos]; + + const u32 salt_len = (pstoken->salt_len > 512) ? 512 : pstoken->salt_len; + + char pstoken_tmp[1024 + 1] = { 0 }; + + for (uint i = 0, j = 0; i < salt_len; i += 1, j += 2) + { + const u8 *ptr = (const u8 *) pstoken->salt_buf; + + sprintf (pstoken_tmp + j, "%02x", ptr[i]); + } + + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x:%s", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4], + pstoken_tmp); + } + else if (hash_mode == 13600) + { + zip2_t *zip2s = (zip2_t *) data.esalts_buf; + + zip2_t *zip2 = &zip2s[salt_pos]; + + const u32 salt_len = zip2->salt_len; + + char salt_tmp[32 + 1] = { 0 }; + + for (uint i = 0, j = 0; i < salt_len; i += 1, j += 2) + { + const u8 *ptr = (const u8 *) zip2->salt_buf; + + sprintf (salt_tmp + j, "%02x", ptr[i]); + } + + const u32 data_len = zip2->data_len; + + char data_tmp[8192 + 1] = { 0 }; + + for (uint i = 0, j = 0; i < data_len; i += 1, j += 2) + { + const u8 *ptr = (const u8 *) zip2->data_buf; + + sprintf (data_tmp + j, "%02x", ptr[i]); + } + + const u32 auth_len = zip2->auth_len; + + char auth_tmp[20 + 1] = { 0 }; + + for (uint i = 0, j = 0; i < auth_len; i += 1, j += 2) + { + const u8 *ptr = (const u8 *) zip2->auth_buf; + + sprintf (auth_tmp + j, "%02x", ptr[i]); + } + + snprintf (out_buf, 255, "%s*%u*%u*%u*%s*%x*%u*%s*%s*%s", + SIGNATURE_ZIP2_START, + zip2->type, + zip2->mode, + zip2->magic, + salt_tmp, + zip2->verify_bytes, + zip2->compress_length, + data_tmp, + auth_tmp, + SIGNATURE_ZIP2_STOP); + } + else if ((hash_mode >= 13700) && (hash_mode <= 13799)) + { + snprintf (out_buf, len-1, "%s", hashfile); + } + else if (hash_mode == 13800) + { + win8phone_t *esalts = (win8phone_t *) data.esalts_buf; + + win8phone_t *esalt = &esalts[salt_pos]; + + char buf[256 + 1] = { 0 }; + + for (int i = 0, j = 0; i < 32; i += 1, j += 8) + { + sprintf (buf + j, "%08x", esalt->salt_buf[i]); + } + + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x:%s", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4], + digest_buf[5], + digest_buf[6], + digest_buf[7], + buf); + } + else if (hash_mode == 14000) + { + snprintf (out_buf, len - 1, "%08x%08x:%s", digest_buf[0], digest_buf[1], (char *) salt.salt_buf); + } + else if (hash_mode == 14100) + { + snprintf (out_buf, len - 1, "%08x%08x:%s", digest_buf[0], digest_buf[1], (char *) salt.salt_buf); + } + else + { + if (hash_type == HASH_TYPE_MD4) + { + snprintf (out_buf, 255, "%08x%08x%08x%08x", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3]); + } + else if (hash_type == HASH_TYPE_MD5) + { + snprintf (out_buf, len-1, "%08x%08x%08x%08x", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3]); + } + else if (hash_type == HASH_TYPE_SHA1) + { + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4]); + } + else if (hash_type == HASH_TYPE_SHA256) + { + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4], + digest_buf[5], + digest_buf[6], + digest_buf[7]); + } + else if (hash_type == HASH_TYPE_SHA384) + { + uint *ptr = digest_buf; + + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", + ptr[ 1], ptr[ 0], + ptr[ 3], ptr[ 2], + ptr[ 5], ptr[ 4], + ptr[ 7], ptr[ 6], + ptr[ 9], ptr[ 8], + ptr[11], ptr[10]); + } + else if (hash_type == HASH_TYPE_SHA512) + { + uint *ptr = digest_buf; + + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", + ptr[ 1], ptr[ 0], + ptr[ 3], ptr[ 2], + ptr[ 5], ptr[ 4], + ptr[ 7], ptr[ 6], + ptr[ 9], ptr[ 8], + ptr[11], ptr[10], + ptr[13], ptr[12], + ptr[15], ptr[14]); + } + else if (hash_type == HASH_TYPE_LM) + { + snprintf (out_buf, len-1, "%08x%08x", + digest_buf[0], + digest_buf[1]); + } + else if (hash_type == HASH_TYPE_ORACLEH) + { + snprintf (out_buf, len-1, "%08X%08X", + digest_buf[0], + digest_buf[1]); + } + else if (hash_type == HASH_TYPE_BCRYPT) + { + base64_encode (int_to_bf64, (const u8 *) salt.salt_buf, 16, (u8 *) tmp_buf + 0); + base64_encode (int_to_bf64, (const u8 *) digest_buf, 23, (u8 *) tmp_buf + 22); + + tmp_buf[22 + 31] = 0; // base64_encode wants to pad + + snprintf (out_buf, len-1, "%s$%s", (char *) salt.salt_sign, tmp_buf); + } + else if (hash_type == HASH_TYPE_KECCAK) + { + uint *ptr = digest_buf; + + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", + ptr[ 1], ptr[ 0], + ptr[ 3], ptr[ 2], + ptr[ 5], ptr[ 4], + ptr[ 7], ptr[ 6], + ptr[ 9], ptr[ 8], + ptr[11], ptr[10], + ptr[13], ptr[12], + ptr[15], ptr[14], + ptr[17], ptr[16], + ptr[19], ptr[18], + ptr[21], ptr[20], + ptr[23], ptr[22], + ptr[25], ptr[24], + ptr[27], ptr[26], + ptr[29], ptr[28], + ptr[31], ptr[30], + ptr[33], ptr[32], + ptr[35], ptr[34], + ptr[37], ptr[36], + ptr[39], ptr[38], + ptr[41], ptr[30], + ptr[43], ptr[42], + ptr[45], ptr[44], + ptr[47], ptr[46], + ptr[49], ptr[48] + ); + + out_buf[salt.keccak_mdlen * 2] = 0; + } + else if (hash_type == HASH_TYPE_RIPEMD160) + { + snprintf (out_buf, 255, "%08x%08x%08x%08x%08x", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4]); + } + else if (hash_type == HASH_TYPE_WHIRLPOOL) + { + digest_buf[ 0] = digest_buf[ 0]; + digest_buf[ 1] = digest_buf[ 1]; + digest_buf[ 2] = digest_buf[ 2]; + digest_buf[ 3] = digest_buf[ 3]; + digest_buf[ 4] = digest_buf[ 4]; + digest_buf[ 5] = digest_buf[ 5]; + digest_buf[ 6] = digest_buf[ 6]; + digest_buf[ 7] = digest_buf[ 7]; + digest_buf[ 8] = digest_buf[ 8]; + digest_buf[ 9] = digest_buf[ 9]; + digest_buf[10] = digest_buf[10]; + digest_buf[11] = digest_buf[11]; + digest_buf[12] = digest_buf[12]; + digest_buf[13] = digest_buf[13]; + digest_buf[14] = digest_buf[14]; + digest_buf[15] = digest_buf[15]; + + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", + digest_buf[ 0], + digest_buf[ 1], + digest_buf[ 2], + digest_buf[ 3], + digest_buf[ 4], + digest_buf[ 5], + digest_buf[ 6], + digest_buf[ 7], + digest_buf[ 8], + digest_buf[ 9], + digest_buf[10], + digest_buf[11], + digest_buf[12], + digest_buf[13], + digest_buf[14], + digest_buf[15]); + } + else if (hash_type == HASH_TYPE_GOST) + { + snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3], + digest_buf[4], + digest_buf[5], + digest_buf[6], + digest_buf[7]); + } + else if (hash_type == HASH_TYPE_MYSQL) + { + snprintf (out_buf, len-1, "%08x%08x", + digest_buf[0], + digest_buf[1]); + } + else if (hash_type == HASH_TYPE_LOTUS5) + { + snprintf (out_buf, len-1, "%08x%08x%08x%08x", + digest_buf[0], + digest_buf[1], + digest_buf[2], + digest_buf[3]); + } + else if (hash_type == HASH_TYPE_LOTUS6) + { + digest_buf[ 0] = byte_swap_32 (digest_buf[ 0]); + digest_buf[ 1] = byte_swap_32 (digest_buf[ 1]); + digest_buf[ 2] = byte_swap_32 (digest_buf[ 2]); + digest_buf[ 3] = byte_swap_32 (digest_buf[ 3]); + + char buf[16] = { 0 }; + + memcpy (buf + 0, salt.salt_buf, 5); + memcpy (buf + 5, digest_buf, 9); + + buf[3] -= -4; + + base64_encode (int_to_lotus64, (const u8 *) buf, 14, (u8 *) tmp_buf); + + tmp_buf[18] = salt.salt_buf_pc[7]; + tmp_buf[19] = 0; + + snprintf (out_buf, len-1, "(G%s)", tmp_buf); + } + else if (hash_type == HASH_TYPE_LOTUS8) + { + char buf[52] = { 0 }; + + // salt + + memcpy (buf + 0, salt.salt_buf, 16); + + buf[3] -= -4; + + // iteration + + snprintf (buf + 16, 11, "%010i", salt.salt_iter + 1); + + // chars + + buf[26] = salt.salt_buf_pc[0]; + buf[27] = salt.salt_buf_pc[1]; + + // digest + + memcpy (buf + 28, digest_buf, 8); + + base64_encode (int_to_lotus64, (const u8 *) buf, 36, (u8 *) tmp_buf); + + tmp_buf[49] = 0; + + snprintf (out_buf, len-1, "(H%s)", tmp_buf); + } + else if (hash_type == HASH_TYPE_CRC32) + { + snprintf (out_buf, len-1, "%08x", byte_swap_32 (digest_buf[0])); + } + } + + if (salt_type == SALT_TYPE_INTERN) + { + size_t pos = strlen (out_buf); + + out_buf[pos] = data.separator; + + char *ptr = (char *) salt.salt_buf; + + memcpy (out_buf + pos + 1, ptr, salt.salt_len); + + out_buf[pos + 1 + salt.salt_len] = 0; + } +} diff --git a/src/shared.c b/src/shared.c index 354d77cf8..ee49b0675 100644 --- a/src/shared.c +++ b/src/shared.c @@ -8,7 +8,6 @@ #include "common.h" #include "types_int.h" -#include "bitops.h" #include "memory.h" #include "logging.h" #include "ext_OpenCL.h" @@ -16,2130 +15,15 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" -#include "cpu_aes.h" -#include "cpu_crc32.h" -#include "cpu_des.h" -#include "cpu_md5.h" -#include "cpu_sha1.h" -#include "cpu_sha256.h" +#include "convert.h" #include "thread.h" #include "timer.h" #include "types.h" #include "rp_cpu.h" -#include "rp_kernel_on_cpu.h" -#include "inc_hash_constants.h" +#include "data.h" #include "shared.h" -/** - * converter - */ - -#if 0 //unused -static u8 int_to_base32 (const u8 c) -{ - static const u8 tbl[0x20] = - { - 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, - 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - }; - - return tbl[c]; -} - -static u8 base32_to_int (const u8 c) -{ - if ((c >= 'A') && (c <= 'Z')) return c - 'A'; - else if ((c >= '2') && (c <= '7')) return c - '2' + 26; - - return 0; -} -#endif - -static u8 int_to_itoa32 (const u8 c) -{ - static const u8 tbl[0x20] = - { - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, - }; - - return tbl[c]; -} - -static u8 itoa32_to_int (const u8 c) -{ - if ((c >= '0') && (c <= '9')) return c - '0'; - else if ((c >= 'a') && (c <= 'v')) return c - 'a' + 10; - - return 0; -} - -static u8 int_to_itoa64 (const u8 c) -{ - static const u8 tbl[0x40] = - { - 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, - 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, - 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, - 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, - }; - - return tbl[c]; -} - -static u8 itoa64_to_int (const u8 c) -{ - static const u8 tbl[0x100] = - { - 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, - 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, - 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x01, - 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, - 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, - 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x01, 0x02, 0x03, 0x04, - 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, - 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x01, 0x02, 0x03, 0x04, - 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, - 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x01, 0x02, 0x03, 0x04, - }; - - return tbl[c]; -} - -static u8 int_to_base64 (const u8 c) -{ - static const u8 tbl[0x40] = - { - 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, - 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, - 0x77, 0x78, 0x79, 0x7a, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f, - }; - - return tbl[c]; -} - -static u8 base64_to_int (const u8 c) -{ - static const u8 tbl[0x100] = - { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x3f, - 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, - 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - }; - - return tbl[c]; -} - -static u8 int_to_bf64 (const u8 c) -{ - static const u8 tbl[0x40] = - { - 0x2e, 0x2f, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, - 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, - 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, - 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - }; - - return tbl[c]; -} - -static u8 bf64_to_int (const u8 c) -{ - static const u8 tbl[0x100] = - { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, - 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - }; - - return tbl[c]; -} - -static u8 int_to_lotus64 (const u8 c) -{ - if (c < 10) return '0' + c; - else if (c < 36) return 'A' + c - 10; - else if (c < 62) return 'a' + c - 36; - else if (c == 62) return '+'; - else if (c == 63) return '/'; - - return 0; -} - -static u8 lotus64_to_int (const u8 c) -{ - if ((c >= '0') && (c <= '9')) return c - '0'; - else if ((c >= 'A') && (c <= 'Z')) return c - 'A' + 10; - else if ((c >= 'a') && (c <= 'z')) return c - 'a' + 36; - else if (c == '+') return 62; - else if (c == '/') return 63; - else - - return 0; -} - -static int base32_decode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf) -{ - const u8 *in_ptr = in_buf; - - u8 *out_ptr = out_buf; - - for (int i = 0; i < in_len; i += 8) - { - const u8 out_val0 = f (in_ptr[0] & 0x7f); - const u8 out_val1 = f (in_ptr[1] & 0x7f); - const u8 out_val2 = f (in_ptr[2] & 0x7f); - const u8 out_val3 = f (in_ptr[3] & 0x7f); - const u8 out_val4 = f (in_ptr[4] & 0x7f); - const u8 out_val5 = f (in_ptr[5] & 0x7f); - const u8 out_val6 = f (in_ptr[6] & 0x7f); - const u8 out_val7 = f (in_ptr[7] & 0x7f); - - out_ptr[0] = ((out_val0 << 3) & 0xf8) | ((out_val1 >> 2) & 0x07); - out_ptr[1] = ((out_val1 << 6) & 0xc0) | ((out_val2 << 1) & 0x3e) | ((out_val3 >> 4) & 0x01); - out_ptr[2] = ((out_val3 << 4) & 0xf0) | ((out_val4 >> 1) & 0x0f); - out_ptr[3] = ((out_val4 << 7) & 0x80) | ((out_val5 << 2) & 0x7c) | ((out_val6 >> 3) & 0x03); - out_ptr[4] = ((out_val6 << 5) & 0xe0) | ((out_val7 >> 0) & 0x1f); - - in_ptr += 8; - out_ptr += 5; - } - - for (int i = 0; i < in_len; i++) - { - if (in_buf[i] != '=') continue; - - in_len = i; - } - - int out_len = (in_len * 5) / 8; - - return out_len; -} - -static int base32_encode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf) -{ - const u8 *in_ptr = in_buf; - - u8 *out_ptr = out_buf; - - for (int i = 0; i < in_len; i += 5) - { - const u8 out_val0 = f ( ((in_ptr[0] >> 3) & 0x1f)); - const u8 out_val1 = f (((in_ptr[0] << 2) & 0x1c) | ((in_ptr[1] >> 6) & 0x03)); - const u8 out_val2 = f ( ((in_ptr[1] >> 1) & 0x1f)); - const u8 out_val3 = f (((in_ptr[1] << 4) & 0x10) | ((in_ptr[2] >> 4) & 0x0f)); - const u8 out_val4 = f (((in_ptr[2] << 1) & 0x1e) | ((in_ptr[3] >> 7) & 0x01)); - const u8 out_val5 = f ( ((in_ptr[3] >> 2) & 0x1f)); - const u8 out_val6 = f (((in_ptr[3] << 3) & 0x18) | ((in_ptr[4] >> 5) & 0x07)); - const u8 out_val7 = f ( ((in_ptr[4] >> 0) & 0x1f)); - - out_ptr[0] = out_val0 & 0x7f; - out_ptr[1] = out_val1 & 0x7f; - out_ptr[2] = out_val2 & 0x7f; - out_ptr[3] = out_val3 & 0x7f; - out_ptr[4] = out_val4 & 0x7f; - out_ptr[5] = out_val5 & 0x7f; - out_ptr[6] = out_val6 & 0x7f; - out_ptr[7] = out_val7 & 0x7f; - - in_ptr += 5; - out_ptr += 8; - } - - int out_len = (int) (((0.5 + (double) in_len) * 8) / 5); // ceil (in_len * 8 / 5) - - while (out_len % 8) - { - out_buf[out_len] = '='; - - out_len++; - } - - return out_len; -} - -static int base64_decode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf) -{ - const u8 *in_ptr = in_buf; - - u8 *out_ptr = out_buf; - - for (int i = 0; i < in_len; i += 4) - { - const u8 out_val0 = f (in_ptr[0] & 0x7f); - const u8 out_val1 = f (in_ptr[1] & 0x7f); - const u8 out_val2 = f (in_ptr[2] & 0x7f); - const u8 out_val3 = f (in_ptr[3] & 0x7f); - - out_ptr[0] = ((out_val0 << 2) & 0xfc) | ((out_val1 >> 4) & 0x03); - out_ptr[1] = ((out_val1 << 4) & 0xf0) | ((out_val2 >> 2) & 0x0f); - out_ptr[2] = ((out_val2 << 6) & 0xc0) | ((out_val3 >> 0) & 0x3f); - - in_ptr += 4; - out_ptr += 3; - } - - for (int i = 0; i < in_len; i++) - { - if (in_buf[i] != '=') continue; - - in_len = i; - } - - int out_len = (in_len * 6) / 8; - - return out_len; -} - -static int base64_encode (u8 (*f) (const u8), const u8 *in_buf, int in_len, u8 *out_buf) -{ - const u8 *in_ptr = in_buf; - - u8 *out_ptr = out_buf; - - for (int i = 0; i < in_len; i += 3) - { - const u8 out_val0 = f ( ((in_ptr[0] >> 2) & 0x3f)); - const u8 out_val1 = f (((in_ptr[0] << 4) & 0x30) | ((in_ptr[1] >> 4) & 0x0f)); - const u8 out_val2 = f (((in_ptr[1] << 2) & 0x3c) | ((in_ptr[2] >> 6) & 0x03)); - const u8 out_val3 = f ( ((in_ptr[2] >> 0) & 0x3f)); - - out_ptr[0] = out_val0 & 0x7f; - out_ptr[1] = out_val1 & 0x7f; - out_ptr[2] = out_val2 & 0x7f; - out_ptr[3] = out_val3 & 0x7f; - - in_ptr += 3; - out_ptr += 4; - } - - int out_len = (int) (((0.5 + (double) in_len) * 8) / 6); // ceil (in_len * 8 / 6) - - while (out_len % 4) - { - out_buf[out_len] = '='; - - out_len++; - } - - return out_len; -} - -static int is_valid_hex_char (const u8 c) -{ - if ((c >= '0') && (c <= '9')) return 1; - if ((c >= 'A') && (c <= 'F')) return 1; - if ((c >= 'a') && (c <= 'f')) return 1; - - return 0; -} - -u8 hex_convert (const u8 c) -{ - return (c & 15) + (c >> 6) * 9; -} - -u8 hex_to_u8 (const u8 hex[2]) -{ - u8 v = 0; - - v |= (hex_convert (hex[1]) << 0); - v |= (hex_convert (hex[0]) << 4); - - return (v); -} - -u32 hex_to_u32 (const u8 hex[8]) -{ - u32 v = 0; - - v |= ((u32) hex_convert (hex[7])) << 0; - v |= ((u32) hex_convert (hex[6])) << 4; - v |= ((u32) hex_convert (hex[5])) << 8; - v |= ((u32) hex_convert (hex[4])) << 12; - v |= ((u32) hex_convert (hex[3])) << 16; - v |= ((u32) hex_convert (hex[2])) << 20; - v |= ((u32) hex_convert (hex[1])) << 24; - v |= ((u32) hex_convert (hex[0])) << 28; - - return (v); -} - -u64 hex_to_u64 (const u8 hex[16]) -{ - u64 v = 0; - - v |= ((u64) hex_convert (hex[15]) << 0); - v |= ((u64) hex_convert (hex[14]) << 4); - v |= ((u64) hex_convert (hex[13]) << 8); - v |= ((u64) hex_convert (hex[12]) << 12); - v |= ((u64) hex_convert (hex[11]) << 16); - v |= ((u64) hex_convert (hex[10]) << 20); - v |= ((u64) hex_convert (hex[ 9]) << 24); - v |= ((u64) hex_convert (hex[ 8]) << 28); - v |= ((u64) hex_convert (hex[ 7]) << 32); - v |= ((u64) hex_convert (hex[ 6]) << 36); - v |= ((u64) hex_convert (hex[ 5]) << 40); - v |= ((u64) hex_convert (hex[ 4]) << 44); - v |= ((u64) hex_convert (hex[ 3]) << 48); - v |= ((u64) hex_convert (hex[ 2]) << 52); - v |= ((u64) hex_convert (hex[ 1]) << 56); - v |= ((u64) hex_convert (hex[ 0]) << 60); - - return (v); -} - -static void bin_to_hex_lower (const u32 v, u8 hex[8]) -{ - hex[0] = v >> 28 & 15; - hex[1] = v >> 24 & 15; - hex[2] = v >> 20 & 15; - hex[3] = v >> 16 & 15; - hex[4] = v >> 12 & 15; - hex[5] = v >> 8 & 15; - hex[6] = v >> 4 & 15; - hex[7] = v >> 0 & 15; - - u32 add; - - hex[0] += 6; add = ((hex[0] & 0x10) >> 4) * 39; hex[0] += 42 + add; - hex[1] += 6; add = ((hex[1] & 0x10) >> 4) * 39; hex[1] += 42 + add; - hex[2] += 6; add = ((hex[2] & 0x10) >> 4) * 39; hex[2] += 42 + add; - hex[3] += 6; add = ((hex[3] & 0x10) >> 4) * 39; hex[3] += 42 + add; - hex[4] += 6; add = ((hex[4] & 0x10) >> 4) * 39; hex[4] += 42 + add; - hex[5] += 6; add = ((hex[5] & 0x10) >> 4) * 39; hex[5] += 42 + add; - hex[6] += 6; add = ((hex[6] & 0x10) >> 4) * 39; hex[6] += 42 + add; - hex[7] += 6; add = ((hex[7] & 0x10) >> 4) * 39; hex[7] += 42 + add; -} - -/** - * decoder - */ - -static void AES128_decrypt_cbc (const u32 key[4], const u32 iv[4], const u32 in[16], u32 out[16]) -{ - AES_KEY skey; - - AES_set_decrypt_key ((const u8 *) key, 128, &skey); - - u32 _iv[4] = { 0 }; - - _iv[0] = iv[0]; - _iv[1] = iv[1]; - _iv[2] = iv[2]; - _iv[3] = iv[3]; - - for (int i = 0; i < 16; i += 4) - { - u32 _in[4] = { 0 }; - u32 _out[4] = { 0 }; - - _in[0] = in[i + 0]; - _in[1] = in[i + 1]; - _in[2] = in[i + 2]; - _in[3] = in[i + 3]; - - AES_decrypt (&skey, (const u8 *) _in, (u8 *) _out); - - _out[0] ^= _iv[0]; - _out[1] ^= _iv[1]; - _out[2] ^= _iv[2]; - _out[3] ^= _iv[3]; - - out[i + 0] = _out[0]; - out[i + 1] = _out[1]; - out[i + 2] = _out[2]; - out[i + 3] = _out[3]; - - _iv[0] = _in[0]; - _iv[1] = _in[1]; - _iv[2] = _in[2]; - _iv[3] = _in[3]; - } -} - -static void juniper_decrypt_hash (char *in, char *out) -{ - // base64 decode - - u8 base64_buf[100] = { 0 }; - - base64_decode (base64_to_int, (const u8 *) in, DISPLAY_LEN_MIN_501, base64_buf); - - // iv stuff - - u32 juniper_iv[4] = { 0 }; - - memcpy (juniper_iv, base64_buf, 12); - - memcpy (out, juniper_iv, 12); - - // reversed key - - u32 juniper_key[4] = { 0 }; - - juniper_key[0] = byte_swap_32 (0xa6707a7e); - juniper_key[1] = byte_swap_32 (0x8df91059); - juniper_key[2] = byte_swap_32 (0xdea70ae5); - juniper_key[3] = byte_swap_32 (0x2f9c2442); - - // AES decrypt - - u32 *in_ptr = (u32 *) (base64_buf + 12); - u32 *out_ptr = (u32 *) (out + 12); - - AES128_decrypt_cbc (juniper_key, juniper_iv, in_ptr, out_ptr); -} - -static void phpass_decode (u8 digest[16], u8 buf[22]) -{ - int l; - - l = itoa64_to_int (buf[ 0]) << 0; - l |= itoa64_to_int (buf[ 1]) << 6; - l |= itoa64_to_int (buf[ 2]) << 12; - l |= itoa64_to_int (buf[ 3]) << 18; - - digest[ 0] = (l >> 0) & 0xff; - digest[ 1] = (l >> 8) & 0xff; - digest[ 2] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[ 4]) << 0; - l |= itoa64_to_int (buf[ 5]) << 6; - l |= itoa64_to_int (buf[ 6]) << 12; - l |= itoa64_to_int (buf[ 7]) << 18; - - digest[ 3] = (l >> 0) & 0xff; - digest[ 4] = (l >> 8) & 0xff; - digest[ 5] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[ 8]) << 0; - l |= itoa64_to_int (buf[ 9]) << 6; - l |= itoa64_to_int (buf[10]) << 12; - l |= itoa64_to_int (buf[11]) << 18; - - digest[ 6] = (l >> 0) & 0xff; - digest[ 7] = (l >> 8) & 0xff; - digest[ 8] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[12]) << 0; - l |= itoa64_to_int (buf[13]) << 6; - l |= itoa64_to_int (buf[14]) << 12; - l |= itoa64_to_int (buf[15]) << 18; - - digest[ 9] = (l >> 0) & 0xff; - digest[10] = (l >> 8) & 0xff; - digest[11] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[16]) << 0; - l |= itoa64_to_int (buf[17]) << 6; - l |= itoa64_to_int (buf[18]) << 12; - l |= itoa64_to_int (buf[19]) << 18; - - digest[12] = (l >> 0) & 0xff; - digest[13] = (l >> 8) & 0xff; - digest[14] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[20]) << 0; - l |= itoa64_to_int (buf[21]) << 6; - - digest[15] = (l >> 0) & 0xff; -} - -static void phpass_encode (u8 digest[16], u8 buf[22]) -{ - int l; - - l = (digest[ 0] << 0) | (digest[ 1] << 8) | (digest[ 2] << 16); - - buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 3] = int_to_itoa64 (l & 0x3f); - - l = (digest[ 3] << 0) | (digest[ 4] << 8) | (digest[ 5] << 16); - - buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 7] = int_to_itoa64 (l & 0x3f); - - l = (digest[ 6] << 0) | (digest[ 7] << 8) | (digest[ 8] << 16); - - buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[11] = int_to_itoa64 (l & 0x3f); - - l = (digest[ 9] << 0) | (digest[10] << 8) | (digest[11] << 16); - - buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[15] = int_to_itoa64 (l & 0x3f); - - l = (digest[12] << 0) | (digest[13] << 8) | (digest[14] << 16); - - buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[19] = int_to_itoa64 (l & 0x3f); - - l = (digest[15] << 0); - - buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[21] = int_to_itoa64 (l & 0x3f); -} - -static void md5crypt_decode (u8 digest[16], u8 buf[22]) -{ - int l; - - l = itoa64_to_int (buf[ 0]) << 0; - l |= itoa64_to_int (buf[ 1]) << 6; - l |= itoa64_to_int (buf[ 2]) << 12; - l |= itoa64_to_int (buf[ 3]) << 18; - - digest[ 0] = (l >> 16) & 0xff; - digest[ 6] = (l >> 8) & 0xff; - digest[12] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[ 4]) << 0; - l |= itoa64_to_int (buf[ 5]) << 6; - l |= itoa64_to_int (buf[ 6]) << 12; - l |= itoa64_to_int (buf[ 7]) << 18; - - digest[ 1] = (l >> 16) & 0xff; - digest[ 7] = (l >> 8) & 0xff; - digest[13] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[ 8]) << 0; - l |= itoa64_to_int (buf[ 9]) << 6; - l |= itoa64_to_int (buf[10]) << 12; - l |= itoa64_to_int (buf[11]) << 18; - - digest[ 2] = (l >> 16) & 0xff; - digest[ 8] = (l >> 8) & 0xff; - digest[14] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[12]) << 0; - l |= itoa64_to_int (buf[13]) << 6; - l |= itoa64_to_int (buf[14]) << 12; - l |= itoa64_to_int (buf[15]) << 18; - - digest[ 3] = (l >> 16) & 0xff; - digest[ 9] = (l >> 8) & 0xff; - digest[15] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[16]) << 0; - l |= itoa64_to_int (buf[17]) << 6; - l |= itoa64_to_int (buf[18]) << 12; - l |= itoa64_to_int (buf[19]) << 18; - - digest[ 4] = (l >> 16) & 0xff; - digest[10] = (l >> 8) & 0xff; - digest[ 5] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[20]) << 0; - l |= itoa64_to_int (buf[21]) << 6; - - digest[11] = (l >> 0) & 0xff; -} - -static void md5crypt_encode (u8 digest[16], u8 buf[22]) -{ - int l; - - l = (digest[ 0] << 16) | (digest[ 6] << 8) | (digest[12] << 0); - - buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 3] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[ 1] << 16) | (digest[ 7] << 8) | (digest[13] << 0); - - buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 7] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[ 2] << 16) | (digest[ 8] << 8) | (digest[14] << 0); - - buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[11] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[ 3] << 16) | (digest[ 9] << 8) | (digest[15] << 0); - - buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[15] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[ 4] << 16) | (digest[10] << 8) | (digest[ 5] << 0); - - buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[19] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[11] << 0); - - buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; -} - -static void sha512crypt_decode (u8 digest[64], u8 buf[86]) -{ - int l; - - l = itoa64_to_int (buf[ 0]) << 0; - l |= itoa64_to_int (buf[ 1]) << 6; - l |= itoa64_to_int (buf[ 2]) << 12; - l |= itoa64_to_int (buf[ 3]) << 18; - - digest[ 0] = (l >> 16) & 0xff; - digest[21] = (l >> 8) & 0xff; - digest[42] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[ 4]) << 0; - l |= itoa64_to_int (buf[ 5]) << 6; - l |= itoa64_to_int (buf[ 6]) << 12; - l |= itoa64_to_int (buf[ 7]) << 18; - - digest[22] = (l >> 16) & 0xff; - digest[43] = (l >> 8) & 0xff; - digest[ 1] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[ 8]) << 0; - l |= itoa64_to_int (buf[ 9]) << 6; - l |= itoa64_to_int (buf[10]) << 12; - l |= itoa64_to_int (buf[11]) << 18; - - digest[44] = (l >> 16) & 0xff; - digest[ 2] = (l >> 8) & 0xff; - digest[23] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[12]) << 0; - l |= itoa64_to_int (buf[13]) << 6; - l |= itoa64_to_int (buf[14]) << 12; - l |= itoa64_to_int (buf[15]) << 18; - - digest[ 3] = (l >> 16) & 0xff; - digest[24] = (l >> 8) & 0xff; - digest[45] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[16]) << 0; - l |= itoa64_to_int (buf[17]) << 6; - l |= itoa64_to_int (buf[18]) << 12; - l |= itoa64_to_int (buf[19]) << 18; - - digest[25] = (l >> 16) & 0xff; - digest[46] = (l >> 8) & 0xff; - digest[ 4] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[20]) << 0; - l |= itoa64_to_int (buf[21]) << 6; - l |= itoa64_to_int (buf[22]) << 12; - l |= itoa64_to_int (buf[23]) << 18; - - digest[47] = (l >> 16) & 0xff; - digest[ 5] = (l >> 8) & 0xff; - digest[26] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[24]) << 0; - l |= itoa64_to_int (buf[25]) << 6; - l |= itoa64_to_int (buf[26]) << 12; - l |= itoa64_to_int (buf[27]) << 18; - - digest[ 6] = (l >> 16) & 0xff; - digest[27] = (l >> 8) & 0xff; - digest[48] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[28]) << 0; - l |= itoa64_to_int (buf[29]) << 6; - l |= itoa64_to_int (buf[30]) << 12; - l |= itoa64_to_int (buf[31]) << 18; - - digest[28] = (l >> 16) & 0xff; - digest[49] = (l >> 8) & 0xff; - digest[ 7] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[32]) << 0; - l |= itoa64_to_int (buf[33]) << 6; - l |= itoa64_to_int (buf[34]) << 12; - l |= itoa64_to_int (buf[35]) << 18; - - digest[50] = (l >> 16) & 0xff; - digest[ 8] = (l >> 8) & 0xff; - digest[29] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[36]) << 0; - l |= itoa64_to_int (buf[37]) << 6; - l |= itoa64_to_int (buf[38]) << 12; - l |= itoa64_to_int (buf[39]) << 18; - - digest[ 9] = (l >> 16) & 0xff; - digest[30] = (l >> 8) & 0xff; - digest[51] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[40]) << 0; - l |= itoa64_to_int (buf[41]) << 6; - l |= itoa64_to_int (buf[42]) << 12; - l |= itoa64_to_int (buf[43]) << 18; - - digest[31] = (l >> 16) & 0xff; - digest[52] = (l >> 8) & 0xff; - digest[10] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[44]) << 0; - l |= itoa64_to_int (buf[45]) << 6; - l |= itoa64_to_int (buf[46]) << 12; - l |= itoa64_to_int (buf[47]) << 18; - - digest[53] = (l >> 16) & 0xff; - digest[11] = (l >> 8) & 0xff; - digest[32] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[48]) << 0; - l |= itoa64_to_int (buf[49]) << 6; - l |= itoa64_to_int (buf[50]) << 12; - l |= itoa64_to_int (buf[51]) << 18; - - digest[12] = (l >> 16) & 0xff; - digest[33] = (l >> 8) & 0xff; - digest[54] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[52]) << 0; - l |= itoa64_to_int (buf[53]) << 6; - l |= itoa64_to_int (buf[54]) << 12; - l |= itoa64_to_int (buf[55]) << 18; - - digest[34] = (l >> 16) & 0xff; - digest[55] = (l >> 8) & 0xff; - digest[13] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[56]) << 0; - l |= itoa64_to_int (buf[57]) << 6; - l |= itoa64_to_int (buf[58]) << 12; - l |= itoa64_to_int (buf[59]) << 18; - - digest[56] = (l >> 16) & 0xff; - digest[14] = (l >> 8) & 0xff; - digest[35] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[60]) << 0; - l |= itoa64_to_int (buf[61]) << 6; - l |= itoa64_to_int (buf[62]) << 12; - l |= itoa64_to_int (buf[63]) << 18; - - digest[15] = (l >> 16) & 0xff; - digest[36] = (l >> 8) & 0xff; - digest[57] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[64]) << 0; - l |= itoa64_to_int (buf[65]) << 6; - l |= itoa64_to_int (buf[66]) << 12; - l |= itoa64_to_int (buf[67]) << 18; - - digest[37] = (l >> 16) & 0xff; - digest[58] = (l >> 8) & 0xff; - digest[16] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[68]) << 0; - l |= itoa64_to_int (buf[69]) << 6; - l |= itoa64_to_int (buf[70]) << 12; - l |= itoa64_to_int (buf[71]) << 18; - - digest[59] = (l >> 16) & 0xff; - digest[17] = (l >> 8) & 0xff; - digest[38] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[72]) << 0; - l |= itoa64_to_int (buf[73]) << 6; - l |= itoa64_to_int (buf[74]) << 12; - l |= itoa64_to_int (buf[75]) << 18; - - digest[18] = (l >> 16) & 0xff; - digest[39] = (l >> 8) & 0xff; - digest[60] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[76]) << 0; - l |= itoa64_to_int (buf[77]) << 6; - l |= itoa64_to_int (buf[78]) << 12; - l |= itoa64_to_int (buf[79]) << 18; - - digest[40] = (l >> 16) & 0xff; - digest[61] = (l >> 8) & 0xff; - digest[19] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[80]) << 0; - l |= itoa64_to_int (buf[81]) << 6; - l |= itoa64_to_int (buf[82]) << 12; - l |= itoa64_to_int (buf[83]) << 18; - - digest[62] = (l >> 16) & 0xff; - digest[20] = (l >> 8) & 0xff; - digest[41] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[84]) << 0; - l |= itoa64_to_int (buf[85]) << 6; - - digest[63] = (l >> 0) & 0xff; -} - -static void sha512crypt_encode (u8 digest[64], u8 buf[86]) -{ - int l; - - l = (digest[ 0] << 16) | (digest[21] << 8) | (digest[42] << 0); - - buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 3] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[22] << 16) | (digest[43] << 8) | (digest[ 1] << 0); - - buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 7] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[44] << 16) | (digest[ 2] << 8) | (digest[23] << 0); - - buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[11] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[ 3] << 16) | (digest[24] << 8) | (digest[45] << 0); - - buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[15] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[25] << 16) | (digest[46] << 8) | (digest[ 4] << 0); - - buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[19] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[47] << 16) | (digest[ 5] << 8) | (digest[26] << 0); - - buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[22] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[23] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[ 6] << 16) | (digest[27] << 8) | (digest[48] << 0); - - buf[24] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[25] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[26] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[27] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[28] << 16) | (digest[49] << 8) | (digest[ 7] << 0); - - buf[28] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[29] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[30] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[31] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[50] << 16) | (digest[ 8] << 8) | (digest[29] << 0); - - buf[32] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[33] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[34] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[35] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[ 9] << 16) | (digest[30] << 8) | (digest[51] << 0); - - buf[36] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[37] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[38] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[39] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[31] << 16) | (digest[52] << 8) | (digest[10] << 0); - - buf[40] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[41] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[42] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[43] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[53] << 16) | (digest[11] << 8) | (digest[32] << 0); - - buf[44] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[45] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[46] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[47] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[12] << 16) | (digest[33] << 8) | (digest[54] << 0); - - buf[48] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[49] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[50] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[51] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[34] << 16) | (digest[55] << 8) | (digest[13] << 0); - - buf[52] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[53] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[54] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[55] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[56] << 16) | (digest[14] << 8) | (digest[35] << 0); - - buf[56] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[57] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[58] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[59] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[15] << 16) | (digest[36] << 8) | (digest[57] << 0); - - buf[60] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[61] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[62] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[63] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[37] << 16) | (digest[58] << 8) | (digest[16] << 0); - - buf[64] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[65] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[66] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[67] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[59] << 16) | (digest[17] << 8) | (digest[38] << 0); - - buf[68] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[69] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[70] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[71] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[18] << 16) | (digest[39] << 8) | (digest[60] << 0); - - buf[72] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[73] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[74] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[75] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[40] << 16) | (digest[61] << 8) | (digest[19] << 0); - - buf[76] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[77] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[78] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[79] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[62] << 16) | (digest[20] << 8) | (digest[41] << 0); - - buf[80] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[81] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[82] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[83] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = 0 | 0 | (digest[63] << 0); - - buf[84] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[85] = int_to_itoa64 (l & 0x3f); l >>= 6; -} - -static void sha1aix_decode (u8 digest[20], u8 buf[27]) -{ - int l; - - l = itoa64_to_int (buf[ 0]) << 0; - l |= itoa64_to_int (buf[ 1]) << 6; - l |= itoa64_to_int (buf[ 2]) << 12; - l |= itoa64_to_int (buf[ 3]) << 18; - - digest[ 2] = (l >> 0) & 0xff; - digest[ 1] = (l >> 8) & 0xff; - digest[ 0] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[ 4]) << 0; - l |= itoa64_to_int (buf[ 5]) << 6; - l |= itoa64_to_int (buf[ 6]) << 12; - l |= itoa64_to_int (buf[ 7]) << 18; - - digest[ 5] = (l >> 0) & 0xff; - digest[ 4] = (l >> 8) & 0xff; - digest[ 3] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[ 8]) << 0; - l |= itoa64_to_int (buf[ 9]) << 6; - l |= itoa64_to_int (buf[10]) << 12; - l |= itoa64_to_int (buf[11]) << 18; - - digest[ 8] = (l >> 0) & 0xff; - digest[ 7] = (l >> 8) & 0xff; - digest[ 6] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[12]) << 0; - l |= itoa64_to_int (buf[13]) << 6; - l |= itoa64_to_int (buf[14]) << 12; - l |= itoa64_to_int (buf[15]) << 18; - - digest[11] = (l >> 0) & 0xff; - digest[10] = (l >> 8) & 0xff; - digest[ 9] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[16]) << 0; - l |= itoa64_to_int (buf[17]) << 6; - l |= itoa64_to_int (buf[18]) << 12; - l |= itoa64_to_int (buf[19]) << 18; - - digest[14] = (l >> 0) & 0xff; - digest[13] = (l >> 8) & 0xff; - digest[12] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[20]) << 0; - l |= itoa64_to_int (buf[21]) << 6; - l |= itoa64_to_int (buf[22]) << 12; - l |= itoa64_to_int (buf[23]) << 18; - - digest[17] = (l >> 0) & 0xff; - digest[16] = (l >> 8) & 0xff; - digest[15] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[24]) << 0; - l |= itoa64_to_int (buf[25]) << 6; - l |= itoa64_to_int (buf[26]) << 12; - - digest[19] = (l >> 8) & 0xff; - digest[18] = (l >> 16) & 0xff; -} - -static void sha1aix_encode (u8 digest[20], u8 buf[27]) -{ - int l; - - l = (digest[ 2] << 0) | (digest[ 1] << 8) | (digest[ 0] << 16); - - buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 3] = int_to_itoa64 (l & 0x3f); - - l = (digest[ 5] << 0) | (digest[ 4] << 8) | (digest[ 3] << 16); - - buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 7] = int_to_itoa64 (l & 0x3f); - - l = (digest[ 8] << 0) | (digest[ 7] << 8) | (digest[ 6] << 16); - - buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[11] = int_to_itoa64 (l & 0x3f); - - l = (digest[11] << 0) | (digest[10] << 8) | (digest[ 9] << 16); - - buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[15] = int_to_itoa64 (l & 0x3f); - - l = (digest[14] << 0) | (digest[13] << 8) | (digest[12] << 16); - - buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[19] = int_to_itoa64 (l & 0x3f); - - l = (digest[17] << 0) | (digest[16] << 8) | (digest[15] << 16); - - buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[22] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[23] = int_to_itoa64 (l & 0x3f); - - l = 0 | (digest[19] << 8) | (digest[18] << 16); - - buf[24] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[25] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[26] = int_to_itoa64 (l & 0x3f); -} - -static void sha256aix_decode (u8 digest[32], u8 buf[43]) -{ - int l; - - l = itoa64_to_int (buf[ 0]) << 0; - l |= itoa64_to_int (buf[ 1]) << 6; - l |= itoa64_to_int (buf[ 2]) << 12; - l |= itoa64_to_int (buf[ 3]) << 18; - - digest[ 2] = (l >> 0) & 0xff; - digest[ 1] = (l >> 8) & 0xff; - digest[ 0] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[ 4]) << 0; - l |= itoa64_to_int (buf[ 5]) << 6; - l |= itoa64_to_int (buf[ 6]) << 12; - l |= itoa64_to_int (buf[ 7]) << 18; - - digest[ 5] = (l >> 0) & 0xff; - digest[ 4] = (l >> 8) & 0xff; - digest[ 3] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[ 8]) << 0; - l |= itoa64_to_int (buf[ 9]) << 6; - l |= itoa64_to_int (buf[10]) << 12; - l |= itoa64_to_int (buf[11]) << 18; - - digest[ 8] = (l >> 0) & 0xff; - digest[ 7] = (l >> 8) & 0xff; - digest[ 6] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[12]) << 0; - l |= itoa64_to_int (buf[13]) << 6; - l |= itoa64_to_int (buf[14]) << 12; - l |= itoa64_to_int (buf[15]) << 18; - - digest[11] = (l >> 0) & 0xff; - digest[10] = (l >> 8) & 0xff; - digest[ 9] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[16]) << 0; - l |= itoa64_to_int (buf[17]) << 6; - l |= itoa64_to_int (buf[18]) << 12; - l |= itoa64_to_int (buf[19]) << 18; - - digest[14] = (l >> 0) & 0xff; - digest[13] = (l >> 8) & 0xff; - digest[12] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[20]) << 0; - l |= itoa64_to_int (buf[21]) << 6; - l |= itoa64_to_int (buf[22]) << 12; - l |= itoa64_to_int (buf[23]) << 18; - - digest[17] = (l >> 0) & 0xff; - digest[16] = (l >> 8) & 0xff; - digest[15] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[24]) << 0; - l |= itoa64_to_int (buf[25]) << 6; - l |= itoa64_to_int (buf[26]) << 12; - l |= itoa64_to_int (buf[27]) << 18; - - digest[20] = (l >> 0) & 0xff; - digest[19] = (l >> 8) & 0xff; - digest[18] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[28]) << 0; - l |= itoa64_to_int (buf[29]) << 6; - l |= itoa64_to_int (buf[30]) << 12; - l |= itoa64_to_int (buf[31]) << 18; - - digest[23] = (l >> 0) & 0xff; - digest[22] = (l >> 8) & 0xff; - digest[21] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[32]) << 0; - l |= itoa64_to_int (buf[33]) << 6; - l |= itoa64_to_int (buf[34]) << 12; - l |= itoa64_to_int (buf[35]) << 18; - - digest[26] = (l >> 0) & 0xff; - digest[25] = (l >> 8) & 0xff; - digest[24] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[36]) << 0; - l |= itoa64_to_int (buf[37]) << 6; - l |= itoa64_to_int (buf[38]) << 12; - l |= itoa64_to_int (buf[39]) << 18; - - digest[29] = (l >> 0) & 0xff; - digest[28] = (l >> 8) & 0xff; - digest[27] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[40]) << 0; - l |= itoa64_to_int (buf[41]) << 6; - l |= itoa64_to_int (buf[42]) << 12; - - //digest[32] = (l >> 0) & 0xff; - digest[31] = (l >> 8) & 0xff; - digest[30] = (l >> 16) & 0xff; -} - -static void sha256aix_encode (u8 digest[32], u8 buf[43]) -{ - int l; - - l = (digest[ 2] << 0) | (digest[ 1] << 8) | (digest[ 0] << 16); - - buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 3] = int_to_itoa64 (l & 0x3f); - - l = (digest[ 5] << 0) | (digest[ 4] << 8) | (digest[ 3] << 16); - - buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 7] = int_to_itoa64 (l & 0x3f); - - l = (digest[ 8] << 0) | (digest[ 7] << 8) | (digest[ 6] << 16); - - buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[11] = int_to_itoa64 (l & 0x3f); - - l = (digest[11] << 0) | (digest[10] << 8) | (digest[ 9] << 16); - - buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[15] = int_to_itoa64 (l & 0x3f); - - l = (digest[14] << 0) | (digest[13] << 8) | (digest[12] << 16); - - buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[19] = int_to_itoa64 (l & 0x3f); - - l = (digest[17] << 0) | (digest[16] << 8) | (digest[15] << 16); - - buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[22] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[23] = int_to_itoa64 (l & 0x3f); - - l = (digest[20] << 0) | (digest[19] << 8) | (digest[18] << 16); - - buf[24] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[25] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[26] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[27] = int_to_itoa64 (l & 0x3f); - - l = (digest[23] << 0) | (digest[22] << 8) | (digest[21] << 16); - - buf[28] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[29] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[30] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[31] = int_to_itoa64 (l & 0x3f); - - l = (digest[26] << 0) | (digest[25] << 8) | (digest[24] << 16); - - buf[32] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[33] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[34] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[35] = int_to_itoa64 (l & 0x3f); - - l = (digest[29] << 0) | (digest[28] << 8) | (digest[27] << 16); - - buf[36] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[37] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[38] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[39] = int_to_itoa64 (l & 0x3f); - - l = 0 | (digest[31] << 8) | (digest[30] << 16); - - buf[40] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[41] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[42] = int_to_itoa64 (l & 0x3f); -} - -static void sha512aix_decode (u8 digest[64], u8 buf[86]) -{ - int l; - - l = itoa64_to_int (buf[ 0]) << 0; - l |= itoa64_to_int (buf[ 1]) << 6; - l |= itoa64_to_int (buf[ 2]) << 12; - l |= itoa64_to_int (buf[ 3]) << 18; - - digest[ 2] = (l >> 0) & 0xff; - digest[ 1] = (l >> 8) & 0xff; - digest[ 0] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[ 4]) << 0; - l |= itoa64_to_int (buf[ 5]) << 6; - l |= itoa64_to_int (buf[ 6]) << 12; - l |= itoa64_to_int (buf[ 7]) << 18; - - digest[ 5] = (l >> 0) & 0xff; - digest[ 4] = (l >> 8) & 0xff; - digest[ 3] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[ 8]) << 0; - l |= itoa64_to_int (buf[ 9]) << 6; - l |= itoa64_to_int (buf[10]) << 12; - l |= itoa64_to_int (buf[11]) << 18; - - digest[ 8] = (l >> 0) & 0xff; - digest[ 7] = (l >> 8) & 0xff; - digest[ 6] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[12]) << 0; - l |= itoa64_to_int (buf[13]) << 6; - l |= itoa64_to_int (buf[14]) << 12; - l |= itoa64_to_int (buf[15]) << 18; - - digest[11] = (l >> 0) & 0xff; - digest[10] = (l >> 8) & 0xff; - digest[ 9] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[16]) << 0; - l |= itoa64_to_int (buf[17]) << 6; - l |= itoa64_to_int (buf[18]) << 12; - l |= itoa64_to_int (buf[19]) << 18; - - digest[14] = (l >> 0) & 0xff; - digest[13] = (l >> 8) & 0xff; - digest[12] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[20]) << 0; - l |= itoa64_to_int (buf[21]) << 6; - l |= itoa64_to_int (buf[22]) << 12; - l |= itoa64_to_int (buf[23]) << 18; - - digest[17] = (l >> 0) & 0xff; - digest[16] = (l >> 8) & 0xff; - digest[15] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[24]) << 0; - l |= itoa64_to_int (buf[25]) << 6; - l |= itoa64_to_int (buf[26]) << 12; - l |= itoa64_to_int (buf[27]) << 18; - - digest[20] = (l >> 0) & 0xff; - digest[19] = (l >> 8) & 0xff; - digest[18] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[28]) << 0; - l |= itoa64_to_int (buf[29]) << 6; - l |= itoa64_to_int (buf[30]) << 12; - l |= itoa64_to_int (buf[31]) << 18; - - digest[23] = (l >> 0) & 0xff; - digest[22] = (l >> 8) & 0xff; - digest[21] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[32]) << 0; - l |= itoa64_to_int (buf[33]) << 6; - l |= itoa64_to_int (buf[34]) << 12; - l |= itoa64_to_int (buf[35]) << 18; - - digest[26] = (l >> 0) & 0xff; - digest[25] = (l >> 8) & 0xff; - digest[24] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[36]) << 0; - l |= itoa64_to_int (buf[37]) << 6; - l |= itoa64_to_int (buf[38]) << 12; - l |= itoa64_to_int (buf[39]) << 18; - - digest[29] = (l >> 0) & 0xff; - digest[28] = (l >> 8) & 0xff; - digest[27] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[40]) << 0; - l |= itoa64_to_int (buf[41]) << 6; - l |= itoa64_to_int (buf[42]) << 12; - l |= itoa64_to_int (buf[43]) << 18; - - digest[32] = (l >> 0) & 0xff; - digest[31] = (l >> 8) & 0xff; - digest[30] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[44]) << 0; - l |= itoa64_to_int (buf[45]) << 6; - l |= itoa64_to_int (buf[46]) << 12; - l |= itoa64_to_int (buf[47]) << 18; - - digest[35] = (l >> 0) & 0xff; - digest[34] = (l >> 8) & 0xff; - digest[33] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[48]) << 0; - l |= itoa64_to_int (buf[49]) << 6; - l |= itoa64_to_int (buf[50]) << 12; - l |= itoa64_to_int (buf[51]) << 18; - - digest[38] = (l >> 0) & 0xff; - digest[37] = (l >> 8) & 0xff; - digest[36] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[52]) << 0; - l |= itoa64_to_int (buf[53]) << 6; - l |= itoa64_to_int (buf[54]) << 12; - l |= itoa64_to_int (buf[55]) << 18; - - digest[41] = (l >> 0) & 0xff; - digest[40] = (l >> 8) & 0xff; - digest[39] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[56]) << 0; - l |= itoa64_to_int (buf[57]) << 6; - l |= itoa64_to_int (buf[58]) << 12; - l |= itoa64_to_int (buf[59]) << 18; - - digest[44] = (l >> 0) & 0xff; - digest[43] = (l >> 8) & 0xff; - digest[42] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[60]) << 0; - l |= itoa64_to_int (buf[61]) << 6; - l |= itoa64_to_int (buf[62]) << 12; - l |= itoa64_to_int (buf[63]) << 18; - - digest[47] = (l >> 0) & 0xff; - digest[46] = (l >> 8) & 0xff; - digest[45] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[64]) << 0; - l |= itoa64_to_int (buf[65]) << 6; - l |= itoa64_to_int (buf[66]) << 12; - l |= itoa64_to_int (buf[67]) << 18; - - digest[50] = (l >> 0) & 0xff; - digest[49] = (l >> 8) & 0xff; - digest[48] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[68]) << 0; - l |= itoa64_to_int (buf[69]) << 6; - l |= itoa64_to_int (buf[70]) << 12; - l |= itoa64_to_int (buf[71]) << 18; - - digest[53] = (l >> 0) & 0xff; - digest[52] = (l >> 8) & 0xff; - digest[51] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[72]) << 0; - l |= itoa64_to_int (buf[73]) << 6; - l |= itoa64_to_int (buf[74]) << 12; - l |= itoa64_to_int (buf[75]) << 18; - - digest[56] = (l >> 0) & 0xff; - digest[55] = (l >> 8) & 0xff; - digest[54] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[76]) << 0; - l |= itoa64_to_int (buf[77]) << 6; - l |= itoa64_to_int (buf[78]) << 12; - l |= itoa64_to_int (buf[79]) << 18; - - digest[59] = (l >> 0) & 0xff; - digest[58] = (l >> 8) & 0xff; - digest[57] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[80]) << 0; - l |= itoa64_to_int (buf[81]) << 6; - l |= itoa64_to_int (buf[82]) << 12; - l |= itoa64_to_int (buf[83]) << 18; - - digest[62] = (l >> 0) & 0xff; - digest[61] = (l >> 8) & 0xff; - digest[60] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[84]) << 0; - l |= itoa64_to_int (buf[85]) << 6; - - digest[63] = (l >> 16) & 0xff; -} - -static void sha512aix_encode (u8 digest[64], u8 buf[86]) -{ - int l; - - l = (digest[ 2] << 0) | (digest[ 1] << 8) | (digest[ 0] << 16); - - buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 3] = int_to_itoa64 (l & 0x3f); - - l = (digest[ 5] << 0) | (digest[ 4] << 8) | (digest[ 3] << 16); - - buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 7] = int_to_itoa64 (l & 0x3f); - - l = (digest[ 8] << 0) | (digest[ 7] << 8) | (digest[ 6] << 16); - - buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[11] = int_to_itoa64 (l & 0x3f); - - l = (digest[11] << 0) | (digest[10] << 8) | (digest[ 9] << 16); - - buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[15] = int_to_itoa64 (l & 0x3f); - - l = (digest[14] << 0) | (digest[13] << 8) | (digest[12] << 16); - - buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[19] = int_to_itoa64 (l & 0x3f); - - l = (digest[17] << 0) | (digest[16] << 8) | (digest[15] << 16); - - buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[22] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[23] = int_to_itoa64 (l & 0x3f); - - l = (digest[20] << 0) | (digest[19] << 8) | (digest[18] << 16); - - buf[24] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[25] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[26] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[27] = int_to_itoa64 (l & 0x3f); - - l = (digest[23] << 0) | (digest[22] << 8) | (digest[21] << 16); - - buf[28] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[29] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[30] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[31] = int_to_itoa64 (l & 0x3f); - - l = (digest[26] << 0) | (digest[25] << 8) | (digest[24] << 16); - - buf[32] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[33] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[34] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[35] = int_to_itoa64 (l & 0x3f); - - l = (digest[29] << 0) | (digest[28] << 8) | (digest[27] << 16); - - buf[36] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[37] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[38] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[39] = int_to_itoa64 (l & 0x3f); - - l = (digest[32] << 0) | (digest[31] << 8) | (digest[30] << 16); - - buf[40] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[41] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[42] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[43] = int_to_itoa64 (l & 0x3f); - - l = (digest[35] << 0) | (digest[34] << 8) | (digest[33] << 16); - - buf[44] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[45] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[46] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[47] = int_to_itoa64 (l & 0x3f); - - l = (digest[38] << 0) | (digest[37] << 8) | (digest[36] << 16); - - buf[48] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[49] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[50] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[51] = int_to_itoa64 (l & 0x3f); - - l = (digest[41] << 0) | (digest[40] << 8) | (digest[39] << 16); - - buf[52] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[53] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[54] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[55] = int_to_itoa64 (l & 0x3f); - - l = (digest[44] << 0) | (digest[43] << 8) | (digest[42] << 16); - - buf[56] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[57] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[58] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[59] = int_to_itoa64 (l & 0x3f); - - l = (digest[47] << 0) | (digest[46] << 8) | (digest[45] << 16); - - buf[60] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[61] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[62] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[63] = int_to_itoa64 (l & 0x3f); - - l = (digest[50] << 0) | (digest[49] << 8) | (digest[48] << 16); - - buf[64] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[65] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[66] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[67] = int_to_itoa64 (l & 0x3f); - - l = (digest[53] << 0) | (digest[52] << 8) | (digest[51] << 16); - - buf[68] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[69] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[70] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[71] = int_to_itoa64 (l & 0x3f); - - l = (digest[56] << 0) | (digest[55] << 8) | (digest[54] << 16); - - buf[72] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[73] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[74] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[75] = int_to_itoa64 (l & 0x3f); - - l = (digest[59] << 0) | (digest[58] << 8) | (digest[57] << 16); - - buf[76] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[77] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[78] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[79] = int_to_itoa64 (l & 0x3f); - - l = (digest[62] << 0) | (digest[61] << 8) | (digest[60] << 16); - - buf[80] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[81] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[82] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[83] = int_to_itoa64 (l & 0x3f); - - l = 0 | 0 | (digest[63] << 16); - - buf[84] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[85] = int_to_itoa64 (l & 0x3f); l >>= 6; -} - -static void sha256crypt_decode (u8 digest[32], u8 buf[43]) -{ - int l; - - l = itoa64_to_int (buf[ 0]) << 0; - l |= itoa64_to_int (buf[ 1]) << 6; - l |= itoa64_to_int (buf[ 2]) << 12; - l |= itoa64_to_int (buf[ 3]) << 18; - - digest[ 0] = (l >> 16) & 0xff; - digest[10] = (l >> 8) & 0xff; - digest[20] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[ 4]) << 0; - l |= itoa64_to_int (buf[ 5]) << 6; - l |= itoa64_to_int (buf[ 6]) << 12; - l |= itoa64_to_int (buf[ 7]) << 18; - - digest[21] = (l >> 16) & 0xff; - digest[ 1] = (l >> 8) & 0xff; - digest[11] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[ 8]) << 0; - l |= itoa64_to_int (buf[ 9]) << 6; - l |= itoa64_to_int (buf[10]) << 12; - l |= itoa64_to_int (buf[11]) << 18; - - digest[12] = (l >> 16) & 0xff; - digest[22] = (l >> 8) & 0xff; - digest[ 2] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[12]) << 0; - l |= itoa64_to_int (buf[13]) << 6; - l |= itoa64_to_int (buf[14]) << 12; - l |= itoa64_to_int (buf[15]) << 18; - - digest[ 3] = (l >> 16) & 0xff; - digest[13] = (l >> 8) & 0xff; - digest[23] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[16]) << 0; - l |= itoa64_to_int (buf[17]) << 6; - l |= itoa64_to_int (buf[18]) << 12; - l |= itoa64_to_int (buf[19]) << 18; - - digest[24] = (l >> 16) & 0xff; - digest[ 4] = (l >> 8) & 0xff; - digest[14] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[20]) << 0; - l |= itoa64_to_int (buf[21]) << 6; - l |= itoa64_to_int (buf[22]) << 12; - l |= itoa64_to_int (buf[23]) << 18; - - digest[15] = (l >> 16) & 0xff; - digest[25] = (l >> 8) & 0xff; - digest[ 5] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[24]) << 0; - l |= itoa64_to_int (buf[25]) << 6; - l |= itoa64_to_int (buf[26]) << 12; - l |= itoa64_to_int (buf[27]) << 18; - - digest[ 6] = (l >> 16) & 0xff; - digest[16] = (l >> 8) & 0xff; - digest[26] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[28]) << 0; - l |= itoa64_to_int (buf[29]) << 6; - l |= itoa64_to_int (buf[30]) << 12; - l |= itoa64_to_int (buf[31]) << 18; - - digest[27] = (l >> 16) & 0xff; - digest[ 7] = (l >> 8) & 0xff; - digest[17] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[32]) << 0; - l |= itoa64_to_int (buf[33]) << 6; - l |= itoa64_to_int (buf[34]) << 12; - l |= itoa64_to_int (buf[35]) << 18; - - digest[18] = (l >> 16) & 0xff; - digest[28] = (l >> 8) & 0xff; - digest[ 8] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[36]) << 0; - l |= itoa64_to_int (buf[37]) << 6; - l |= itoa64_to_int (buf[38]) << 12; - l |= itoa64_to_int (buf[39]) << 18; - - digest[ 9] = (l >> 16) & 0xff; - digest[19] = (l >> 8) & 0xff; - digest[29] = (l >> 0) & 0xff; - - l = itoa64_to_int (buf[40]) << 0; - l |= itoa64_to_int (buf[41]) << 6; - l |= itoa64_to_int (buf[42]) << 12; - - digest[31] = (l >> 8) & 0xff; - digest[30] = (l >> 0) & 0xff; -} - -static void sha256crypt_encode (u8 digest[32], u8 buf[43]) -{ - int l; - - l = (digest[ 0] << 16) | (digest[10] << 8) | (digest[20] << 0); - - buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 3] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[21] << 16) | (digest[ 1] << 8) | (digest[11] << 0); - - buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 7] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[12] << 16) | (digest[22] << 8) | (digest[ 2] << 0); - - buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[11] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[ 3] << 16) | (digest[13] << 8) | (digest[23] << 0); - - buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[15] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[24] << 16) | (digest[ 4] << 8) | (digest[14] << 0); - - buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[19] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[15] << 16) | (digest[25] << 8) | (digest[ 5] << 0); - - buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[22] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[23] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[ 6] << 16) | (digest[16] << 8) | (digest[26] << 0); - - buf[24] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[25] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[26] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[27] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[27] << 16) | (digest[ 7] << 8) | (digest[17] << 0); - - buf[28] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[29] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[30] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[31] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[18] << 16) | (digest[28] << 8) | (digest[ 8] << 0); - - buf[32] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[33] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[34] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[35] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = (digest[ 9] << 16) | (digest[19] << 8) | (digest[29] << 0); - - buf[36] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[37] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[38] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[39] = int_to_itoa64 (l & 0x3f); l >>= 6; - - l = 0 | (digest[31] << 8) | (digest[30] << 0); - - buf[40] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[41] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[42] = int_to_itoa64 (l & 0x3f); -} - -static void drupal7_decode (u8 digest[64], u8 buf[44]) -{ - int l; - - l = itoa64_to_int (buf[ 0]) << 0; - l |= itoa64_to_int (buf[ 1]) << 6; - l |= itoa64_to_int (buf[ 2]) << 12; - l |= itoa64_to_int (buf[ 3]) << 18; - - digest[ 0] = (l >> 0) & 0xff; - digest[ 1] = (l >> 8) & 0xff; - digest[ 2] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[ 4]) << 0; - l |= itoa64_to_int (buf[ 5]) << 6; - l |= itoa64_to_int (buf[ 6]) << 12; - l |= itoa64_to_int (buf[ 7]) << 18; - - digest[ 3] = (l >> 0) & 0xff; - digest[ 4] = (l >> 8) & 0xff; - digest[ 5] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[ 8]) << 0; - l |= itoa64_to_int (buf[ 9]) << 6; - l |= itoa64_to_int (buf[10]) << 12; - l |= itoa64_to_int (buf[11]) << 18; - - digest[ 6] = (l >> 0) & 0xff; - digest[ 7] = (l >> 8) & 0xff; - digest[ 8] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[12]) << 0; - l |= itoa64_to_int (buf[13]) << 6; - l |= itoa64_to_int (buf[14]) << 12; - l |= itoa64_to_int (buf[15]) << 18; - - digest[ 9] = (l >> 0) & 0xff; - digest[10] = (l >> 8) & 0xff; - digest[11] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[16]) << 0; - l |= itoa64_to_int (buf[17]) << 6; - l |= itoa64_to_int (buf[18]) << 12; - l |= itoa64_to_int (buf[19]) << 18; - - digest[12] = (l >> 0) & 0xff; - digest[13] = (l >> 8) & 0xff; - digest[14] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[20]) << 0; - l |= itoa64_to_int (buf[21]) << 6; - l |= itoa64_to_int (buf[22]) << 12; - l |= itoa64_to_int (buf[23]) << 18; - - digest[15] = (l >> 0) & 0xff; - digest[16] = (l >> 8) & 0xff; - digest[17] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[24]) << 0; - l |= itoa64_to_int (buf[25]) << 6; - l |= itoa64_to_int (buf[26]) << 12; - l |= itoa64_to_int (buf[27]) << 18; - - digest[18] = (l >> 0) & 0xff; - digest[19] = (l >> 8) & 0xff; - digest[20] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[28]) << 0; - l |= itoa64_to_int (buf[29]) << 6; - l |= itoa64_to_int (buf[30]) << 12; - l |= itoa64_to_int (buf[31]) << 18; - - digest[21] = (l >> 0) & 0xff; - digest[22] = (l >> 8) & 0xff; - digest[23] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[32]) << 0; - l |= itoa64_to_int (buf[33]) << 6; - l |= itoa64_to_int (buf[34]) << 12; - l |= itoa64_to_int (buf[35]) << 18; - - digest[24] = (l >> 0) & 0xff; - digest[25] = (l >> 8) & 0xff; - digest[26] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[36]) << 0; - l |= itoa64_to_int (buf[37]) << 6; - l |= itoa64_to_int (buf[38]) << 12; - l |= itoa64_to_int (buf[39]) << 18; - - digest[27] = (l >> 0) & 0xff; - digest[28] = (l >> 8) & 0xff; - digest[29] = (l >> 16) & 0xff; - - l = itoa64_to_int (buf[40]) << 0; - l |= itoa64_to_int (buf[41]) << 6; - l |= itoa64_to_int (buf[42]) << 12; - l |= itoa64_to_int (buf[43]) << 18; - - digest[30] = (l >> 0) & 0xff; - digest[31] = (l >> 8) & 0xff; - digest[32] = (l >> 16) & 0xff; - - digest[33] = 0; - digest[34] = 0; - digest[35] = 0; - digest[36] = 0; - digest[37] = 0; - digest[38] = 0; - digest[39] = 0; - digest[40] = 0; - digest[41] = 0; - digest[42] = 0; - digest[43] = 0; - digest[44] = 0; - digest[45] = 0; - digest[46] = 0; - digest[47] = 0; - digest[48] = 0; - digest[49] = 0; - digest[50] = 0; - digest[51] = 0; - digest[52] = 0; - digest[53] = 0; - digest[54] = 0; - digest[55] = 0; - digest[56] = 0; - digest[57] = 0; - digest[58] = 0; - digest[59] = 0; - digest[60] = 0; - digest[61] = 0; - digest[62] = 0; - digest[63] = 0; -} - -static void drupal7_encode (u8 digest[64], u8 buf[43]) -{ - int l; - - l = (digest[ 0] << 0) | (digest[ 1] << 8) | (digest[ 2] << 16); - - buf[ 0] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 1] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 2] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 3] = int_to_itoa64 (l & 0x3f); - - l = (digest[ 3] << 0) | (digest[ 4] << 8) | (digest[ 5] << 16); - - buf[ 4] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 5] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 6] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 7] = int_to_itoa64 (l & 0x3f); - - l = (digest[ 6] << 0) | (digest[ 7] << 8) | (digest[ 8] << 16); - - buf[ 8] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[ 9] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[10] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[11] = int_to_itoa64 (l & 0x3f); - - l = (digest[ 9] << 0) | (digest[10] << 8) | (digest[11] << 16); - - buf[12] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[13] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[14] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[15] = int_to_itoa64 (l & 0x3f); - - l = (digest[12] << 0) | (digest[13] << 8) | (digest[14] << 16); - - buf[16] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[17] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[18] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[19] = int_to_itoa64 (l & 0x3f); - - l = (digest[15] << 0) | (digest[16] << 8) | (digest[17] << 16); - - buf[20] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[21] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[22] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[23] = int_to_itoa64 (l & 0x3f); - - l = (digest[18] << 0) | (digest[19] << 8) | (digest[20] << 16); - - buf[24] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[25] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[26] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[27] = int_to_itoa64 (l & 0x3f); - - l = (digest[21] << 0) | (digest[22] << 8) | (digest[23] << 16); - - buf[28] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[29] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[30] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[31] = int_to_itoa64 (l & 0x3f); - - l = (digest[24] << 0) | (digest[25] << 8) | (digest[26] << 16); - - buf[32] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[33] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[34] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[35] = int_to_itoa64 (l & 0x3f); - - l = (digest[27] << 0) | (digest[28] << 8) | (digest[29] << 16); - - buf[36] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[37] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[38] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[39] = int_to_itoa64 (l & 0x3f); - - l = (digest[30] << 0) | (digest[31] << 8) | (digest[32] << 16); - - buf[40] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[41] = int_to_itoa64 (l & 0x3f); l >>= 6; - buf[42] = int_to_itoa64 (l & 0x3f); l >>= 6; - //buf[43] = int_to_itoa64 (l & 0x3f); -} +extern hc_global_data_t data; /** * tty @@ -4220,44 +2104,6 @@ uint count_lines (FILE *fd) return cnt; } -void truecrypt_crc32 (const char *filename, u8 keytab[64]) -{ - uint crc = ~0u; - - FILE *fd = fopen (filename, "rb"); - - if (fd == NULL) - { - log_error ("%s: %s", filename, strerror (errno)); - - exit (-1); - } - - #define MAX_KEY_SIZE (1024 * 1024) - - u8 *buf = (u8 *) mymalloc (MAX_KEY_SIZE + 1); - - int nread = fread (buf, sizeof (u8), MAX_KEY_SIZE, fd); - - fclose (fd); - - int kpos = 0; - - for (int fpos = 0; fpos < nread; fpos++) - { - crc = crc32tab[(crc ^ buf[fpos]) & 0xff] ^ (crc >> 8); - - keytab[kpos++] += (crc >> 24) & 0xff; - keytab[kpos++] += (crc >> 16) & 0xff; - keytab[kpos++] += (crc >> 8) & 0xff; - keytab[kpos++] += (crc >> 0) & 0xff; - - if (kpos >= 64) kpos = 0; - } - - myfree (buf); -} - #ifdef __APPLE__ int pthread_setaffinity_np (pthread_t thread, size_t cpu_size, cpu_set_t *cpu_set) { @@ -5434,16 +3280,6 @@ void format_speed_display (double val, char *buf, size_t len) } } -void lowercase (u8 *buf, int len) -{ - for (int i = 0; i < len; i++) buf[i] = tolower (buf[i]); -} - -void uppercase (u8 *buf, int len) -{ - for (int i = 0; i < len; i++) buf[i] = toupper (buf[i]); -} - int fgetl (FILE *fp, char *line_buf) { int line_len = 0; @@ -5653,247 +3489,6 @@ char *stroptitype (const uint opti_type) return (NULL); } -char *strparser (const uint parser_status) -{ - switch (parser_status) - { - case PARSER_OK: return ((char *) PA_000); - case PARSER_COMMENT: return ((char *) PA_001); - case PARSER_GLOBAL_ZERO: return ((char *) PA_002); - case PARSER_GLOBAL_LENGTH: return ((char *) PA_003); - case PARSER_HASH_LENGTH: return ((char *) PA_004); - case PARSER_HASH_VALUE: return ((char *) PA_005); - case PARSER_SALT_LENGTH: return ((char *) PA_006); - case PARSER_SALT_VALUE: return ((char *) PA_007); - case PARSER_SALT_ITERATION: return ((char *) PA_008); - case PARSER_SEPARATOR_UNMATCHED: return ((char *) PA_009); - case PARSER_SIGNATURE_UNMATCHED: return ((char *) PA_010); - case PARSER_HCCAP_FILE_SIZE: return ((char *) PA_011); - case PARSER_HCCAP_EAPOL_SIZE: return ((char *) PA_012); - case PARSER_PSAFE2_FILE_SIZE: return ((char *) PA_013); - case PARSER_PSAFE3_FILE_SIZE: return ((char *) PA_014); - case PARSER_TC_FILE_SIZE: return ((char *) PA_015); - case PARSER_SIP_AUTH_DIRECTIVE: return ((char *) PA_016); - } - - return ((char *) PA_255); -} - -char *strhashtype (const uint hash_mode) -{ - switch (hash_mode) - { - case 0: return ((char *) HT_00000); - case 10: return ((char *) HT_00010); - case 11: return ((char *) HT_00011); - case 12: return ((char *) HT_00012); - case 20: return ((char *) HT_00020); - case 21: return ((char *) HT_00021); - case 22: return ((char *) HT_00022); - case 23: return ((char *) HT_00023); - case 30: return ((char *) HT_00030); - case 40: return ((char *) HT_00040); - case 50: return ((char *) HT_00050); - case 60: return ((char *) HT_00060); - case 100: return ((char *) HT_00100); - case 101: return ((char *) HT_00101); - case 110: return ((char *) HT_00110); - case 111: return ((char *) HT_00111); - case 112: return ((char *) HT_00112); - case 120: return ((char *) HT_00120); - case 121: return ((char *) HT_00121); - case 122: return ((char *) HT_00122); - case 124: return ((char *) HT_00124); - case 125: return ((char *) HT_00125); - case 130: return ((char *) HT_00130); - case 131: return ((char *) HT_00131); - case 132: return ((char *) HT_00132); - case 133: return ((char *) HT_00133); - case 140: return ((char *) HT_00140); - case 141: return ((char *) HT_00141); - case 150: return ((char *) HT_00150); - case 160: return ((char *) HT_00160); - case 200: return ((char *) HT_00200); - case 300: return ((char *) HT_00300); - case 400: return ((char *) HT_00400); - case 500: return ((char *) HT_00500); - case 501: return ((char *) HT_00501); - case 900: return ((char *) HT_00900); - case 910: return ((char *) HT_00910); - case 1000: return ((char *) HT_01000); - case 1100: return ((char *) HT_01100); - case 1400: return ((char *) HT_01400); - case 1410: return ((char *) HT_01410); - case 1420: return ((char *) HT_01420); - case 1421: return ((char *) HT_01421); - case 1430: return ((char *) HT_01430); - case 1440: return ((char *) HT_01440); - case 1441: return ((char *) HT_01441); - case 1450: return ((char *) HT_01450); - case 1460: return ((char *) HT_01460); - case 1500: return ((char *) HT_01500); - case 1600: return ((char *) HT_01600); - case 1700: return ((char *) HT_01700); - case 1710: return ((char *) HT_01710); - case 1711: return ((char *) HT_01711); - case 1720: return ((char *) HT_01720); - case 1722: return ((char *) HT_01722); - case 1730: return ((char *) HT_01730); - case 1731: return ((char *) HT_01731); - case 1740: return ((char *) HT_01740); - case 1750: return ((char *) HT_01750); - case 1760: return ((char *) HT_01760); - case 1800: return ((char *) HT_01800); - case 2100: return ((char *) HT_02100); - case 2400: return ((char *) HT_02400); - case 2410: return ((char *) HT_02410); - case 2500: return ((char *) HT_02500); - case 2600: return ((char *) HT_02600); - case 2611: return ((char *) HT_02611); - case 2612: return ((char *) HT_02612); - case 2711: return ((char *) HT_02711); - case 2811: return ((char *) HT_02811); - case 3000: return ((char *) HT_03000); - case 3100: return ((char *) HT_03100); - case 3200: return ((char *) HT_03200); - case 3710: return ((char *) HT_03710); - case 3711: return ((char *) HT_03711); - case 3800: return ((char *) HT_03800); - case 4300: return ((char *) HT_04300); - case 4400: return ((char *) HT_04400); - case 4500: return ((char *) HT_04500); - case 4700: return ((char *) HT_04700); - case 4800: return ((char *) HT_04800); - case 4900: return ((char *) HT_04900); - case 5000: return ((char *) HT_05000); - case 5100: return ((char *) HT_05100); - case 5200: return ((char *) HT_05200); - case 5300: return ((char *) HT_05300); - case 5400: return ((char *) HT_05400); - case 5500: return ((char *) HT_05500); - case 5600: return ((char *) HT_05600); - case 5700: return ((char *) HT_05700); - case 5800: return ((char *) HT_05800); - case 6000: return ((char *) HT_06000); - case 6100: return ((char *) HT_06100); - case 6211: return ((char *) HT_06211); - case 6212: return ((char *) HT_06212); - case 6213: return ((char *) HT_06213); - case 6221: return ((char *) HT_06221); - case 6222: return ((char *) HT_06222); - case 6223: return ((char *) HT_06223); - case 6231: return ((char *) HT_06231); - case 6232: return ((char *) HT_06232); - case 6233: return ((char *) HT_06233); - case 6241: return ((char *) HT_06241); - case 6242: return ((char *) HT_06242); - case 6243: return ((char *) HT_06243); - case 6300: return ((char *) HT_06300); - case 6400: return ((char *) HT_06400); - case 6500: return ((char *) HT_06500); - case 6600: return ((char *) HT_06600); - case 6700: return ((char *) HT_06700); - case 6800: return ((char *) HT_06800); - case 6900: return ((char *) HT_06900); - case 7100: return ((char *) HT_07100); - case 7200: return ((char *) HT_07200); - case 7300: return ((char *) HT_07300); - case 7400: return ((char *) HT_07400); - case 7500: return ((char *) HT_07500); - case 7600: return ((char *) HT_07600); - case 7700: return ((char *) HT_07700); - case 7800: return ((char *) HT_07800); - case 7900: return ((char *) HT_07900); - case 8000: return ((char *) HT_08000); - case 8100: return ((char *) HT_08100); - case 8200: return ((char *) HT_08200); - case 8300: return ((char *) HT_08300); - case 8400: return ((char *) HT_08400); - case 8500: return ((char *) HT_08500); - case 8600: return ((char *) HT_08600); - case 8700: return ((char *) HT_08700); - case 8800: return ((char *) HT_08800); - case 8900: return ((char *) HT_08900); - case 9000: return ((char *) HT_09000); - case 9100: return ((char *) HT_09100); - case 9200: return ((char *) HT_09200); - case 9300: return ((char *) HT_09300); - case 9400: return ((char *) HT_09400); - case 9500: return ((char *) HT_09500); - case 9600: return ((char *) HT_09600); - case 9700: return ((char *) HT_09700); - case 9710: return ((char *) HT_09710); - case 9720: return ((char *) HT_09720); - case 9800: return ((char *) HT_09800); - case 9810: return ((char *) HT_09810); - case 9820: return ((char *) HT_09820); - case 9900: return ((char *) HT_09900); - case 10000: return ((char *) HT_10000); - case 10100: return ((char *) HT_10100); - case 10200: return ((char *) HT_10200); - case 10300: return ((char *) HT_10300); - case 10400: return ((char *) HT_10400); - case 10410: return ((char *) HT_10410); - case 10420: return ((char *) HT_10420); - case 10500: return ((char *) HT_10500); - case 10600: return ((char *) HT_10600); - case 10700: return ((char *) HT_10700); - case 10800: return ((char *) HT_10800); - case 10900: return ((char *) HT_10900); - case 11000: return ((char *) HT_11000); - case 11100: return ((char *) HT_11100); - case 11200: return ((char *) HT_11200); - case 11300: return ((char *) HT_11300); - case 11400: return ((char *) HT_11400); - case 11500: return ((char *) HT_11500); - case 11600: return ((char *) HT_11600); - case 11700: return ((char *) HT_11700); - case 11800: return ((char *) HT_11800); - case 11900: return ((char *) HT_11900); - case 12000: return ((char *) HT_12000); - case 12100: return ((char *) HT_12100); - case 12200: return ((char *) HT_12200); - case 12300: return ((char *) HT_12300); - case 12400: return ((char *) HT_12400); - case 12500: return ((char *) HT_12500); - case 12600: return ((char *) HT_12600); - case 12700: return ((char *) HT_12700); - case 12800: return ((char *) HT_12800); - case 12900: return ((char *) HT_12900); - case 13000: return ((char *) HT_13000); - case 13100: return ((char *) HT_13100); - case 13200: return ((char *) HT_13200); - case 13300: return ((char *) HT_13300); - case 13400: return ((char *) HT_13400); - case 13500: return ((char *) HT_13500); - case 13600: return ((char *) HT_13600); - case 13711: return ((char *) HT_13711); - case 13712: return ((char *) HT_13712); - case 13713: return ((char *) HT_13713); - case 13721: return ((char *) HT_13721); - case 13722: return ((char *) HT_13722); - case 13723: return ((char *) HT_13723); - case 13731: return ((char *) HT_13731); - case 13732: return ((char *) HT_13732); - case 13733: return ((char *) HT_13733); - case 13741: return ((char *) HT_13741); - case 13742: return ((char *) HT_13742); - case 13743: return ((char *) HT_13743); - case 13751: return ((char *) HT_13751); - case 13752: return ((char *) HT_13752); - case 13753: return ((char *) HT_13753); - case 13761: return ((char *) HT_13761); - case 13762: return ((char *) HT_13762); - case 13763: return ((char *) HT_13763); - case 13800: return ((char *) HT_13800); - case 13900: return ((char *) HT_13900); - case 14000: return ((char *) HT_14000); - case 14100: return ((char *) HT_14100); - } - - return ((char *) "Unknown"); -} - char *strstatus (const uint devices_status) { switch (devices_status) @@ -5914,3045 +3509,6 @@ char *strstatus (const uint devices_status) return ((char *) "Unknown"); } -void ascii_digest (char *out_buf, uint salt_pos, uint digest_pos) -{ - uint hash_type = data.hash_type; - uint hash_mode = data.hash_mode; - uint salt_type = data.salt_type; - uint opts_type = data.opts_type; - uint opti_type = data.opti_type; - uint dgst_size = data.dgst_size; - - char *hashfile = data.hashfile; - - uint len = 4096; - - u8 datax[256] = { 0 }; - - u64 *digest_buf64 = (u64 *) datax; - u32 *digest_buf = (u32 *) datax; - - char *digests_buf_ptr = (char *) data.digests_buf; - - memcpy (digest_buf, digests_buf_ptr + (data.salts_buf[salt_pos].digests_offset * dgst_size) + (digest_pos * dgst_size), dgst_size); - - if (opti_type & OPTI_TYPE_PRECOMPUTE_PERMUT) - { - uint tt; - - switch (hash_type) - { - case HASH_TYPE_DES: - FP (digest_buf[1], digest_buf[0], tt); - break; - - case HASH_TYPE_DESCRYPT: - FP (digest_buf[1], digest_buf[0], tt); - break; - - case HASH_TYPE_DESRACF: - digest_buf[0] = rotl32 (digest_buf[0], 29); - digest_buf[1] = rotl32 (digest_buf[1], 29); - - FP (digest_buf[1], digest_buf[0], tt); - break; - - case HASH_TYPE_LM: - FP (digest_buf[1], digest_buf[0], tt); - break; - - case HASH_TYPE_NETNTLM: - digest_buf[0] = rotl32 (digest_buf[0], 29); - digest_buf[1] = rotl32 (digest_buf[1], 29); - digest_buf[2] = rotl32 (digest_buf[2], 29); - digest_buf[3] = rotl32 (digest_buf[3], 29); - - FP (digest_buf[1], digest_buf[0], tt); - FP (digest_buf[3], digest_buf[2], tt); - break; - - case HASH_TYPE_BSDICRYPT: - digest_buf[0] = rotl32 (digest_buf[0], 31); - digest_buf[1] = rotl32 (digest_buf[1], 31); - - FP (digest_buf[1], digest_buf[0], tt); - break; - } - } - - if (opti_type & OPTI_TYPE_PRECOMPUTE_MERKLE) - { - switch (hash_type) - { - case HASH_TYPE_MD4: - digest_buf[0] += MD4M_A; - digest_buf[1] += MD4M_B; - digest_buf[2] += MD4M_C; - digest_buf[3] += MD4M_D; - break; - - case HASH_TYPE_MD5: - digest_buf[0] += MD5M_A; - digest_buf[1] += MD5M_B; - digest_buf[2] += MD5M_C; - digest_buf[3] += MD5M_D; - break; - - case HASH_TYPE_SHA1: - digest_buf[0] += SHA1M_A; - digest_buf[1] += SHA1M_B; - digest_buf[2] += SHA1M_C; - digest_buf[3] += SHA1M_D; - digest_buf[4] += SHA1M_E; - break; - - case HASH_TYPE_SHA256: - digest_buf[0] += SHA256M_A; - digest_buf[1] += SHA256M_B; - digest_buf[2] += SHA256M_C; - digest_buf[3] += SHA256M_D; - digest_buf[4] += SHA256M_E; - digest_buf[5] += SHA256M_F; - digest_buf[6] += SHA256M_G; - digest_buf[7] += SHA256M_H; - break; - - case HASH_TYPE_SHA384: - digest_buf64[0] += SHA384M_A; - digest_buf64[1] += SHA384M_B; - digest_buf64[2] += SHA384M_C; - digest_buf64[3] += SHA384M_D; - digest_buf64[4] += SHA384M_E; - digest_buf64[5] += SHA384M_F; - digest_buf64[6] += 0; - digest_buf64[7] += 0; - break; - - case HASH_TYPE_SHA512: - digest_buf64[0] += SHA512M_A; - digest_buf64[1] += SHA512M_B; - digest_buf64[2] += SHA512M_C; - digest_buf64[3] += SHA512M_D; - digest_buf64[4] += SHA512M_E; - digest_buf64[5] += SHA512M_F; - digest_buf64[6] += SHA512M_G; - digest_buf64[7] += SHA512M_H; - break; - } - } - - if (opts_type & OPTS_TYPE_PT_GENERATE_LE) - { - if (dgst_size == DGST_SIZE_4_2) - { - for (int i = 0; i < 2; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); - } - else if (dgst_size == DGST_SIZE_4_4) - { - for (int i = 0; i < 4; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); - } - else if (dgst_size == DGST_SIZE_4_5) - { - for (int i = 0; i < 5; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); - } - else if (dgst_size == DGST_SIZE_4_6) - { - for (int i = 0; i < 6; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); - } - else if (dgst_size == DGST_SIZE_4_8) - { - for (int i = 0; i < 8; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); - } - else if ((dgst_size == DGST_SIZE_4_16) || (dgst_size == DGST_SIZE_8_8)) // same size, same result :) - { - if (hash_type == HASH_TYPE_WHIRLPOOL) - { - for (int i = 0; i < 16; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); - } - else if (hash_type == HASH_TYPE_SHA384) - { - for (int i = 0; i < 8; i++) digest_buf64[i] = byte_swap_64 (digest_buf64[i]); - } - else if (hash_type == HASH_TYPE_SHA512) - { - for (int i = 0; i < 8; i++) digest_buf64[i] = byte_swap_64 (digest_buf64[i]); - } - else if (hash_type == HASH_TYPE_GOST) - { - for (int i = 0; i < 16; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); - } - } - else if (dgst_size == DGST_SIZE_4_64) - { - for (int i = 0; i < 64; i++) digest_buf[i] = byte_swap_32 (digest_buf[i]); - } - else if (dgst_size == DGST_SIZE_8_25) - { - for (int i = 0; i < 25; i++) digest_buf64[i] = byte_swap_64 (digest_buf64[i]); - } - } - - uint isSalted = ((data.salt_type == SALT_TYPE_INTERN) - | (data.salt_type == SALT_TYPE_EXTERN) - | (data.salt_type == SALT_TYPE_EMBEDDED)); - - salt_t salt; - - if (isSalted) - { - memset (&salt, 0, sizeof (salt_t)); - - memcpy (&salt, &data.salts_buf[salt_pos], sizeof (salt_t)); - - char *ptr = (char *) salt.salt_buf; - - uint len = salt.salt_len; - - if (opti_type & OPTI_TYPE_PRECOMPUTE_PERMUT) - { - uint tt; - - switch (hash_type) - { - case HASH_TYPE_NETNTLM: - - salt.salt_buf[0] = rotr32 (salt.salt_buf[0], 3); - salt.salt_buf[1] = rotr32 (salt.salt_buf[1], 3); - - FP (salt.salt_buf[1], salt.salt_buf[0], tt); - - break; - } - } - - if (opts_type & OPTS_TYPE_ST_UNICODE) - { - for (uint i = 0, j = 0; i < len; i += 1, j += 2) - { - ptr[i] = ptr[j]; - } - - len = len / 2; - } - - if (opts_type & OPTS_TYPE_ST_GENERATE_LE) - { - uint max = salt.salt_len / 4; - - if (len % 4) max++; - - for (uint i = 0; i < max; i++) - { - salt.salt_buf[i] = byte_swap_32 (salt.salt_buf[i]); - } - } - - if (opts_type & OPTS_TYPE_ST_HEX) - { - char tmp[64] = { 0 }; - - for (uint i = 0, j = 0; i < len; i += 1, j += 2) - { - sprintf (tmp + j, "%02x", (unsigned char) ptr[i]); - } - - len = len * 2; - - memcpy (ptr, tmp, len); - } - - uint memset_size = ((48 - (int) len) > 0) ? (48 - len) : 0; - - memset (ptr + len, 0, memset_size); - - salt.salt_len = len; - } - - // - // some modes require special encoding - // - - uint out_buf_plain[256] = { 0 }; - uint out_buf_salt[256] = { 0 }; - - char tmp_buf[1024] = { 0 }; - - char *ptr_plain = (char *) out_buf_plain; - char *ptr_salt = (char *) out_buf_salt; - - if (hash_mode == 22) - { - char username[30] = { 0 }; - - memcpy (username, salt.salt_buf, salt.salt_len - 22); - - char sig[6] = { 'n', 'r', 'c', 's', 't', 'n' }; - - u16 *ptr = (u16 *) digest_buf; - - tmp_buf[ 0] = sig[0]; - tmp_buf[ 1] = int_to_base64 (((ptr[1]) >> 12) & 0x3f); - tmp_buf[ 2] = int_to_base64 (((ptr[1]) >> 6) & 0x3f); - tmp_buf[ 3] = int_to_base64 (((ptr[1]) >> 0) & 0x3f); - tmp_buf[ 4] = int_to_base64 (((ptr[0]) >> 12) & 0x3f); - tmp_buf[ 5] = int_to_base64 (((ptr[0]) >> 6) & 0x3f); - tmp_buf[ 6] = sig[1]; - tmp_buf[ 7] = int_to_base64 (((ptr[0]) >> 0) & 0x3f); - tmp_buf[ 8] = int_to_base64 (((ptr[3]) >> 12) & 0x3f); - tmp_buf[ 9] = int_to_base64 (((ptr[3]) >> 6) & 0x3f); - tmp_buf[10] = int_to_base64 (((ptr[3]) >> 0) & 0x3f); - tmp_buf[11] = int_to_base64 (((ptr[2]) >> 12) & 0x3f); - tmp_buf[12] = sig[2]; - tmp_buf[13] = int_to_base64 (((ptr[2]) >> 6) & 0x3f); - tmp_buf[14] = int_to_base64 (((ptr[2]) >> 0) & 0x3f); - tmp_buf[15] = int_to_base64 (((ptr[5]) >> 12) & 0x3f); - tmp_buf[16] = int_to_base64 (((ptr[5]) >> 6) & 0x3f); - tmp_buf[17] = sig[3]; - tmp_buf[18] = int_to_base64 (((ptr[5]) >> 0) & 0x3f); - tmp_buf[19] = int_to_base64 (((ptr[4]) >> 12) & 0x3f); - tmp_buf[20] = int_to_base64 (((ptr[4]) >> 6) & 0x3f); - tmp_buf[21] = int_to_base64 (((ptr[4]) >> 0) & 0x3f); - tmp_buf[22] = int_to_base64 (((ptr[7]) >> 12) & 0x3f); - tmp_buf[23] = sig[4]; - tmp_buf[24] = int_to_base64 (((ptr[7]) >> 6) & 0x3f); - tmp_buf[25] = int_to_base64 (((ptr[7]) >> 0) & 0x3f); - tmp_buf[26] = int_to_base64 (((ptr[6]) >> 12) & 0x3f); - tmp_buf[27] = int_to_base64 (((ptr[6]) >> 6) & 0x3f); - tmp_buf[28] = int_to_base64 (((ptr[6]) >> 0) & 0x3f); - tmp_buf[29] = sig[5]; - - snprintf (out_buf, len-1, "%s:%s", - tmp_buf, - username); - } - else if (hash_mode == 23) - { - // do not show the skyper part in output - - char *salt_buf_ptr = (char *) salt.salt_buf; - - salt_buf_ptr[salt.salt_len - 8] = 0; - - snprintf (out_buf, len-1, "%08x%08x%08x%08x:%s", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - salt_buf_ptr); - } - else if (hash_mode == 101) - { - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - - memcpy (tmp_buf, digest_buf, 20); - - base64_encode (int_to_base64, (const u8 *) tmp_buf, 20, (u8 *) ptr_plain); - - snprintf (out_buf, len-1, "{SHA}%s", ptr_plain); - } - else if (hash_mode == 111) - { - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - - memcpy (tmp_buf, digest_buf, 20); - memcpy (tmp_buf + 20, salt.salt_buf, salt.salt_len); - - base64_encode (int_to_base64, (const u8 *) tmp_buf, 20 + salt.salt_len, (u8 *) ptr_plain); - - snprintf (out_buf, len-1, "{SSHA}%s", ptr_plain); - } - else if ((hash_mode == 122) || (hash_mode == 125)) - { - snprintf (out_buf, len-1, "%s%08x%08x%08x%08x%08x", - (char *) salt.salt_buf, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4]); - } - else if (hash_mode == 124) - { - snprintf (out_buf, len-1, "sha1$%s$%08x%08x%08x%08x%08x", - (char *) salt.salt_buf, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4]); - } - else if (hash_mode == 131) - { - snprintf (out_buf, len-1, "0x0100%s%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", - (char *) salt.salt_buf, - 0, 0, 0, 0, 0, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4]); - } - else if (hash_mode == 132) - { - snprintf (out_buf, len-1, "0x0100%s%08x%08x%08x%08x%08x", - (char *) salt.salt_buf, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4]); - } - else if (hash_mode == 133) - { - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - - memcpy (tmp_buf, digest_buf, 20); - - base64_encode (int_to_base64, (const u8 *) tmp_buf, 20, (u8 *) ptr_plain); - - snprintf (out_buf, len-1, "%s", ptr_plain); - } - else if (hash_mode == 141) - { - memcpy (tmp_buf, salt.salt_buf, salt.salt_len); - - base64_encode (int_to_base64, (const u8 *) tmp_buf, salt.salt_len, (u8 *) ptr_salt); - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - - memcpy (tmp_buf, digest_buf, 20); - - base64_encode (int_to_base64, (const u8 *) tmp_buf, 20, (u8 *) ptr_plain); - - ptr_plain[27] = 0; - - snprintf (out_buf, len-1, "%s%s*%s", SIGNATURE_EPISERVER, ptr_salt, ptr_plain); - } - else if (hash_mode == 400) - { - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - - phpass_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); - - snprintf (out_buf, len-1, "%s%s%s", (char *) salt.salt_sign, (char *) salt.salt_buf, (char *) ptr_plain); - } - else if (hash_mode == 500) - { - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - - md5crypt_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); - - if (salt.salt_iter == ROUNDS_MD5CRYPT) - { - snprintf (out_buf, len-1, "$1$%s$%s", (char *) salt.salt_buf, (char *) ptr_plain); - } - else - { - snprintf (out_buf, len-1, "$1$rounds=%i$%s$%s", salt.salt_iter, (char *) salt.salt_buf, (char *) ptr_plain); - } - } - else if (hash_mode == 501) - { - uint digest_idx = salt.digests_offset + digest_pos; - - hashinfo_t **hashinfo_ptr = data.hash_info; - char *hash_buf = hashinfo_ptr[digest_idx]->orighash; - - snprintf (out_buf, len-1, "%s", hash_buf); - } - else if (hash_mode == 1421) - { - u8 *salt_ptr = (u8 *) salt.salt_buf; - - snprintf (out_buf, len-1, "%c%c%c%c%c%c%08x%08x%08x%08x%08x%08x%08x%08x", - salt_ptr[0], - salt_ptr[1], - salt_ptr[2], - salt_ptr[3], - salt_ptr[4], - salt_ptr[5], - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4], - digest_buf[5], - digest_buf[6], - digest_buf[7]); - } - else if (hash_mode == 1441) - { - memcpy (tmp_buf, salt.salt_buf, salt.salt_len); - - base64_encode (int_to_base64, (const u8 *) tmp_buf, salt.salt_len, (u8 *) ptr_salt); - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - digest_buf[5] = byte_swap_32 (digest_buf[5]); - digest_buf[6] = byte_swap_32 (digest_buf[6]); - digest_buf[7] = byte_swap_32 (digest_buf[7]); - - memcpy (tmp_buf, digest_buf, 32); - - base64_encode (int_to_base64, (const u8 *) tmp_buf, 32, (u8 *) ptr_plain); - - ptr_plain[43] = 0; - - snprintf (out_buf, len-1, "%s%s*%s", SIGNATURE_EPISERVER4, ptr_salt, ptr_plain); - } - else if (hash_mode == 1500) - { - out_buf[0] = salt.salt_sign[0] & 0xff; - out_buf[1] = salt.salt_sign[1] & 0xff; - //original method, but changed because of this ticket: https://hashcat.net/trac/ticket/269 - //out_buf[0] = int_to_itoa64 ((salt.salt_buf[0] >> 0) & 0x3f); - //out_buf[1] = int_to_itoa64 ((salt.salt_buf[0] >> 6) & 0x3f); - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - - memcpy (tmp_buf, digest_buf, 8); - - base64_encode (int_to_itoa64, (const u8 *) tmp_buf, 8, (u8 *) ptr_plain); - - snprintf (out_buf + 2, len-1-2, "%s", ptr_plain); - - out_buf[13] = 0; - } - else if (hash_mode == 1600) - { - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - - md5crypt_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); - - if (salt.salt_iter == ROUNDS_MD5CRYPT) - { - snprintf (out_buf, len-1, "$apr1$%s$%s", (char *) salt.salt_buf, (char *) ptr_plain); - } - else - { - snprintf (out_buf, len-1, "$apr1$rounds=%i$%s$%s", salt.salt_iter, (char *) salt.salt_buf, (char *) ptr_plain); - } - } - else if (hash_mode == 1711) - { - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf64[0] = byte_swap_64 (digest_buf64[0]); - digest_buf64[1] = byte_swap_64 (digest_buf64[1]); - digest_buf64[2] = byte_swap_64 (digest_buf64[2]); - digest_buf64[3] = byte_swap_64 (digest_buf64[3]); - digest_buf64[4] = byte_swap_64 (digest_buf64[4]); - digest_buf64[5] = byte_swap_64 (digest_buf64[5]); - digest_buf64[6] = byte_swap_64 (digest_buf64[6]); - digest_buf64[7] = byte_swap_64 (digest_buf64[7]); - - memcpy (tmp_buf, digest_buf, 64); - memcpy (tmp_buf + 64, salt.salt_buf, salt.salt_len); - - base64_encode (int_to_base64, (const u8 *) tmp_buf, 64 + salt.salt_len, (u8 *) ptr_plain); - - snprintf (out_buf, len-1, "%s%s", SIGNATURE_SHA512B64S, ptr_plain); - } - else if (hash_mode == 1722) - { - uint *ptr = digest_buf; - - snprintf (out_buf, len-1, "%s%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", - (unsigned char *) salt.salt_buf, - ptr[ 1], ptr[ 0], - ptr[ 3], ptr[ 2], - ptr[ 5], ptr[ 4], - ptr[ 7], ptr[ 6], - ptr[ 9], ptr[ 8], - ptr[11], ptr[10], - ptr[13], ptr[12], - ptr[15], ptr[14]); - } - else if (hash_mode == 1731) - { - uint *ptr = digest_buf; - - snprintf (out_buf, len-1, "0x0200%s%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", - (unsigned char *) salt.salt_buf, - ptr[ 1], ptr[ 0], - ptr[ 3], ptr[ 2], - ptr[ 5], ptr[ 4], - ptr[ 7], ptr[ 6], - ptr[ 9], ptr[ 8], - ptr[11], ptr[10], - ptr[13], ptr[12], - ptr[15], ptr[14]); - } - else if (hash_mode == 1800) - { - // temp workaround - - digest_buf64[0] = byte_swap_64 (digest_buf64[0]); - digest_buf64[1] = byte_swap_64 (digest_buf64[1]); - digest_buf64[2] = byte_swap_64 (digest_buf64[2]); - digest_buf64[3] = byte_swap_64 (digest_buf64[3]); - digest_buf64[4] = byte_swap_64 (digest_buf64[4]); - digest_buf64[5] = byte_swap_64 (digest_buf64[5]); - digest_buf64[6] = byte_swap_64 (digest_buf64[6]); - digest_buf64[7] = byte_swap_64 (digest_buf64[7]); - - sha512crypt_encode ((unsigned char *) digest_buf64, (unsigned char *) ptr_plain); - - if (salt.salt_iter == ROUNDS_SHA512CRYPT) - { - snprintf (out_buf, len-1, "$6$%s$%s", (char *) salt.salt_buf, (char *) ptr_plain); - } - else - { - snprintf (out_buf, len-1, "$6$rounds=%i$%s$%s", salt.salt_iter, (char *) salt.salt_buf, (char *) ptr_plain); - } - } - else if (hash_mode == 2100) - { - uint pos = 0; - - snprintf (out_buf + pos, len-1, "%s%i#", - SIGNATURE_DCC2, - salt.salt_iter + 1); - - uint signature_len = strlen (out_buf); - - pos += signature_len; - len -= signature_len; - - char *salt_ptr = (char *) salt.salt_buf; - - for (uint i = 0; i < salt.salt_len; i++, pos++, len--) snprintf (out_buf + pos, len-1, "%c", salt_ptr[i]); - - snprintf (out_buf + pos, len-1, "#%08x%08x%08x%08x", - byte_swap_32 (digest_buf[0]), - byte_swap_32 (digest_buf[1]), - byte_swap_32 (digest_buf[2]), - byte_swap_32 (digest_buf[3])); - } - else if ((hash_mode == 2400) || (hash_mode == 2410)) - { - memcpy (tmp_buf, digest_buf, 16); - - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - - out_buf[ 0] = int_to_itoa64 ((digest_buf[0] >> 0) & 0x3f); - out_buf[ 1] = int_to_itoa64 ((digest_buf[0] >> 6) & 0x3f); - out_buf[ 2] = int_to_itoa64 ((digest_buf[0] >> 12) & 0x3f); - out_buf[ 3] = int_to_itoa64 ((digest_buf[0] >> 18) & 0x3f); - - out_buf[ 4] = int_to_itoa64 ((digest_buf[1] >> 0) & 0x3f); - out_buf[ 5] = int_to_itoa64 ((digest_buf[1] >> 6) & 0x3f); - out_buf[ 6] = int_to_itoa64 ((digest_buf[1] >> 12) & 0x3f); - out_buf[ 7] = int_to_itoa64 ((digest_buf[1] >> 18) & 0x3f); - - out_buf[ 8] = int_to_itoa64 ((digest_buf[2] >> 0) & 0x3f); - out_buf[ 9] = int_to_itoa64 ((digest_buf[2] >> 6) & 0x3f); - out_buf[10] = int_to_itoa64 ((digest_buf[2] >> 12) & 0x3f); - out_buf[11] = int_to_itoa64 ((digest_buf[2] >> 18) & 0x3f); - - out_buf[12] = int_to_itoa64 ((digest_buf[3] >> 0) & 0x3f); - out_buf[13] = int_to_itoa64 ((digest_buf[3] >> 6) & 0x3f); - out_buf[14] = int_to_itoa64 ((digest_buf[3] >> 12) & 0x3f); - out_buf[15] = int_to_itoa64 ((digest_buf[3] >> 18) & 0x3f); - - out_buf[16] = 0; - } - else if (hash_mode == 2500) - { - wpa_t *wpas = (wpa_t *) data.esalts_buf; - - wpa_t *wpa = &wpas[salt_pos]; - - snprintf (out_buf, len-1, "%s:%02x%02x%02x%02x%02x%02x:%02x%02x%02x%02x%02x%02x", - (char *) salt.salt_buf, - wpa->orig_mac1[0], - wpa->orig_mac1[1], - wpa->orig_mac1[2], - wpa->orig_mac1[3], - wpa->orig_mac1[4], - wpa->orig_mac1[5], - wpa->orig_mac2[0], - wpa->orig_mac2[1], - wpa->orig_mac2[2], - wpa->orig_mac2[3], - wpa->orig_mac2[4], - wpa->orig_mac2[5]); - } - else if (hash_mode == 4400) - { - snprintf (out_buf, len-1, "%08x%08x%08x%08x", - byte_swap_32 (digest_buf[0]), - byte_swap_32 (digest_buf[1]), - byte_swap_32 (digest_buf[2]), - byte_swap_32 (digest_buf[3])); - } - else if (hash_mode == 4700) - { - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x", - byte_swap_32 (digest_buf[0]), - byte_swap_32 (digest_buf[1]), - byte_swap_32 (digest_buf[2]), - byte_swap_32 (digest_buf[3]), - byte_swap_32 (digest_buf[4])); - } - else if (hash_mode == 4800) - { - u8 chap_id_byte = (u8) salt.salt_buf[4]; - - snprintf (out_buf, len-1, "%08x%08x%08x%08x:%08x%08x%08x%08x:%02x", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - byte_swap_32 (salt.salt_buf[0]), - byte_swap_32 (salt.salt_buf[1]), - byte_swap_32 (salt.salt_buf[2]), - byte_swap_32 (salt.salt_buf[3]), - chap_id_byte); - } - else if (hash_mode == 4900) - { - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x", - byte_swap_32 (digest_buf[0]), - byte_swap_32 (digest_buf[1]), - byte_swap_32 (digest_buf[2]), - byte_swap_32 (digest_buf[3]), - byte_swap_32 (digest_buf[4])); - } - else if (hash_mode == 5100) - { - snprintf (out_buf, len-1, "%08x%08x", - digest_buf[0], - digest_buf[1]); - } - else if (hash_mode == 5200) - { - snprintf (out_buf, len-1, "%s", hashfile); - } - else if (hash_mode == 5300) - { - ikepsk_t *ikepsks = (ikepsk_t *) data.esalts_buf; - - ikepsk_t *ikepsk = &ikepsks[salt_pos]; - - int buf_len = len - 1; - - // msg_buf - - uint ikepsk_msg_len = ikepsk->msg_len / 4; - - for (uint i = 0; i < ikepsk_msg_len; i++) - { - if ((i == 32) || (i == 64) || (i == 66) || (i == 68) || (i == 108)) - { - snprintf (out_buf, buf_len, ":"); - - buf_len--; - out_buf++; - } - - snprintf (out_buf, buf_len, "%08x", byte_swap_32 (ikepsk->msg_buf[i])); - - buf_len -= 8; - out_buf += 8; - } - - // nr_buf - - uint ikepsk_nr_len = ikepsk->nr_len / 4; - - for (uint i = 0; i < ikepsk_nr_len; i++) - { - if ((i == 0) || (i == 5)) - { - snprintf (out_buf, buf_len, ":"); - - buf_len--; - out_buf++; - } - - snprintf (out_buf, buf_len, "%08x", byte_swap_32 (ikepsk->nr_buf[i])); - - buf_len -= 8; - out_buf += 8; - } - - // digest_buf - - for (uint i = 0; i < 4; i++) - { - if (i == 0) - { - snprintf (out_buf, buf_len, ":"); - - buf_len--; - out_buf++; - } - - snprintf (out_buf, buf_len, "%08x", digest_buf[i]); - - buf_len -= 8; - out_buf += 8; - } - } - else if (hash_mode == 5400) - { - ikepsk_t *ikepsks = (ikepsk_t *) data.esalts_buf; - - ikepsk_t *ikepsk = &ikepsks[salt_pos]; - - int buf_len = len - 1; - - // msg_buf - - uint ikepsk_msg_len = ikepsk->msg_len / 4; - - for (uint i = 0; i < ikepsk_msg_len; i++) - { - if ((i == 32) || (i == 64) || (i == 66) || (i == 68) || (i == 108)) - { - snprintf (out_buf, buf_len, ":"); - - buf_len--; - out_buf++; - } - - snprintf (out_buf, buf_len, "%08x", byte_swap_32 (ikepsk->msg_buf[i])); - - buf_len -= 8; - out_buf += 8; - } - - // nr_buf - - uint ikepsk_nr_len = ikepsk->nr_len / 4; - - for (uint i = 0; i < ikepsk_nr_len; i++) - { - if ((i == 0) || (i == 5)) - { - snprintf (out_buf, buf_len, ":"); - - buf_len--; - out_buf++; - } - - snprintf (out_buf, buf_len, "%08x", byte_swap_32 (ikepsk->nr_buf[i])); - - buf_len -= 8; - out_buf += 8; - } - - // digest_buf - - for (uint i = 0; i < 5; i++) - { - if (i == 0) - { - snprintf (out_buf, buf_len, ":"); - - buf_len--; - out_buf++; - } - - snprintf (out_buf, buf_len, "%08x", digest_buf[i]); - - buf_len -= 8; - out_buf += 8; - } - } - else if (hash_mode == 5500) - { - netntlm_t *netntlms = (netntlm_t *) data.esalts_buf; - - netntlm_t *netntlm = &netntlms[salt_pos]; - - char user_buf[64] = { 0 }; - char domain_buf[64] = { 0 }; - char srvchall_buf[1024] = { 0 }; - char clichall_buf[1024] = { 0 }; - - for (uint i = 0, j = 0; j < netntlm->user_len; i += 1, j += 2) - { - char *ptr = (char *) netntlm->userdomain_buf; - - user_buf[i] = ptr[j]; - } - - for (uint i = 0, j = 0; j < netntlm->domain_len; i += 1, j += 2) - { - char *ptr = (char *) netntlm->userdomain_buf; - - domain_buf[i] = ptr[netntlm->user_len + j]; - } - - for (uint i = 0, j = 0; i < netntlm->srvchall_len; i += 1, j += 2) - { - u8 *ptr = (u8 *) netntlm->chall_buf; - - sprintf (srvchall_buf + j, "%02x", ptr[i]); - } - - for (uint i = 0, j = 0; i < netntlm->clichall_len; i += 1, j += 2) - { - u8 *ptr = (u8 *) netntlm->chall_buf; - - sprintf (clichall_buf + j, "%02x", ptr[netntlm->srvchall_len + i]); - } - - snprintf (out_buf, len-1, "%s::%s:%s:%08x%08x%08x%08x%08x%08x:%s", - user_buf, - domain_buf, - srvchall_buf, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - byte_swap_32 (salt.salt_buf_pc[0]), - byte_swap_32 (salt.salt_buf_pc[1]), - clichall_buf); - } - else if (hash_mode == 5600) - { - netntlm_t *netntlms = (netntlm_t *) data.esalts_buf; - - netntlm_t *netntlm = &netntlms[salt_pos]; - - char user_buf[64] = { 0 }; - char domain_buf[64] = { 0 }; - char srvchall_buf[1024] = { 0 }; - char clichall_buf[1024] = { 0 }; - - for (uint i = 0, j = 0; j < netntlm->user_len; i += 1, j += 2) - { - char *ptr = (char *) netntlm->userdomain_buf; - - user_buf[i] = ptr[j]; - } - - for (uint i = 0, j = 0; j < netntlm->domain_len; i += 1, j += 2) - { - char *ptr = (char *) netntlm->userdomain_buf; - - domain_buf[i] = ptr[netntlm->user_len + j]; - } - - for (uint i = 0, j = 0; i < netntlm->srvchall_len; i += 1, j += 2) - { - u8 *ptr = (u8 *) netntlm->chall_buf; - - sprintf (srvchall_buf + j, "%02x", ptr[i]); - } - - for (uint i = 0, j = 0; i < netntlm->clichall_len; i += 1, j += 2) - { - u8 *ptr = (u8 *) netntlm->chall_buf; - - sprintf (clichall_buf + j, "%02x", ptr[netntlm->srvchall_len + i]); - } - - snprintf (out_buf, len-1, "%s::%s:%s:%08x%08x%08x%08x:%s", - user_buf, - domain_buf, - srvchall_buf, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - clichall_buf); - } - else if (hash_mode == 5700) - { - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - digest_buf[5] = byte_swap_32 (digest_buf[5]); - digest_buf[6] = byte_swap_32 (digest_buf[6]); - digest_buf[7] = byte_swap_32 (digest_buf[7]); - - memcpy (tmp_buf, digest_buf, 32); - - base64_encode (int_to_itoa64, (const u8 *) tmp_buf, 32, (u8 *) ptr_plain); - - ptr_plain[43] = 0; - - snprintf (out_buf, len-1, "%s", ptr_plain); - } - else if (hash_mode == 5800) - { - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4]); - } - else if ((hash_mode >= 6200) && (hash_mode <= 6299)) - { - snprintf (out_buf, len-1, "%s", hashfile); - } - else if (hash_mode == 6300) - { - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - - md5crypt_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); - - snprintf (out_buf, len-1, "{smd5}%s$%s", (char *) salt.salt_buf, (char *) ptr_plain); - } - else if (hash_mode == 6400) - { - sha256aix_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); - - snprintf (out_buf, len-1, "{ssha256}%02d$%s$%s", salt.salt_sign[0], (char *) salt.salt_buf, (char *) ptr_plain); - } - else if (hash_mode == 6500) - { - sha512aix_encode ((unsigned char *) digest_buf64, (unsigned char *) ptr_plain); - - snprintf (out_buf, len-1, "{ssha512}%02d$%s$%s", salt.salt_sign[0], (char *) salt.salt_buf, (char *) ptr_plain); - } - else if (hash_mode == 6600) - { - agilekey_t *agilekeys = (agilekey_t *) data.esalts_buf; - - agilekey_t *agilekey = &agilekeys[salt_pos]; - - salt.salt_buf[0] = byte_swap_32 (salt.salt_buf[0]); - salt.salt_buf[1] = byte_swap_32 (salt.salt_buf[1]); - - uint buf_len = len - 1; - - uint off = snprintf (out_buf, buf_len, "%d:%08x%08x:", salt.salt_iter + 1, salt.salt_buf[0], salt.salt_buf[1]); - buf_len -= 22; - - for (uint i = 0, j = off; i < 1040; i++, j += 2) - { - snprintf (out_buf + j, buf_len, "%02x", agilekey->cipher[i]); - - buf_len -= 2; - } - } - else if (hash_mode == 6700) - { - sha1aix_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); - - snprintf (out_buf, len-1, "{ssha1}%02d$%s$%s", salt.salt_sign[0], (char *) salt.salt_buf, (char *) ptr_plain); - } - else if (hash_mode == 6800) - { - snprintf (out_buf, len-1, "%s", (char *) salt.salt_buf); - } - else if (hash_mode == 7100) - { - uint *ptr = digest_buf; - - pbkdf2_sha512_t *pbkdf2_sha512s = (pbkdf2_sha512_t *) data.esalts_buf; - - pbkdf2_sha512_t *pbkdf2_sha512 = &pbkdf2_sha512s[salt_pos]; - - uint esalt[8] = { 0 }; - - esalt[0] = byte_swap_32 (pbkdf2_sha512->salt_buf[0]); - esalt[1] = byte_swap_32 (pbkdf2_sha512->salt_buf[1]); - esalt[2] = byte_swap_32 (pbkdf2_sha512->salt_buf[2]); - esalt[3] = byte_swap_32 (pbkdf2_sha512->salt_buf[3]); - esalt[4] = byte_swap_32 (pbkdf2_sha512->salt_buf[4]); - esalt[5] = byte_swap_32 (pbkdf2_sha512->salt_buf[5]); - esalt[6] = byte_swap_32 (pbkdf2_sha512->salt_buf[6]); - esalt[7] = byte_swap_32 (pbkdf2_sha512->salt_buf[7]); - - snprintf (out_buf, len-1, "%s%i$%08x%08x%08x%08x%08x%08x%08x%08x$%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", - SIGNATURE_SHA512OSX, - salt.salt_iter + 1, - esalt[ 0], esalt[ 1], - esalt[ 2], esalt[ 3], - esalt[ 4], esalt[ 5], - esalt[ 6], esalt[ 7], - ptr [ 1], ptr [ 0], - ptr [ 3], ptr [ 2], - ptr [ 5], ptr [ 4], - ptr [ 7], ptr [ 6], - ptr [ 9], ptr [ 8], - ptr [11], ptr [10], - ptr [13], ptr [12], - ptr [15], ptr [14]); - } - else if (hash_mode == 7200) - { - uint *ptr = digest_buf; - - pbkdf2_sha512_t *pbkdf2_sha512s = (pbkdf2_sha512_t *) data.esalts_buf; - - pbkdf2_sha512_t *pbkdf2_sha512 = &pbkdf2_sha512s[salt_pos]; - - uint len_used = 0; - - snprintf (out_buf + len_used, len - len_used - 1, "%s%i.", SIGNATURE_SHA512GRUB, salt.salt_iter + 1); - - len_used = strlen (out_buf); - - unsigned char *salt_buf_ptr = (unsigned char *) pbkdf2_sha512->salt_buf; - - for (uint i = 0; i < salt.salt_len; i++, len_used += 2) - { - snprintf (out_buf + len_used, len - len_used - 1, "%02x", salt_buf_ptr[i]); - } - - snprintf (out_buf + len_used, len - len_used - 1, ".%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", - ptr [ 1], ptr [ 0], - ptr [ 3], ptr [ 2], - ptr [ 5], ptr [ 4], - ptr [ 7], ptr [ 6], - ptr [ 9], ptr [ 8], - ptr [11], ptr [10], - ptr [13], ptr [12], - ptr [15], ptr [14]); - } - else if (hash_mode == 7300) - { - rakp_t *rakps = (rakp_t *) data.esalts_buf; - - rakp_t *rakp = &rakps[salt_pos]; - - for (uint i = 0, j = 0; (i * 4) < rakp->salt_len; i += 1, j += 8) - { - sprintf (out_buf + j, "%08x", rakp->salt_buf[i]); - } - - snprintf (out_buf + rakp->salt_len * 2, len - 1, ":%08x%08x%08x%08x%08x", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4]); - } - else if (hash_mode == 7400) - { - // the encoder is a bit too intelligent, it expects the input data in the wrong BOM - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - digest_buf[5] = byte_swap_32 (digest_buf[5]); - digest_buf[6] = byte_swap_32 (digest_buf[6]); - digest_buf[7] = byte_swap_32 (digest_buf[7]); - - sha256crypt_encode ((unsigned char *) digest_buf, (unsigned char *) ptr_plain); - - if (salt.salt_iter == ROUNDS_SHA256CRYPT) - { - snprintf (out_buf, len-1, "$5$%s$%s", (char *) salt.salt_buf, (char *) ptr_plain); - } - else - { - snprintf (out_buf, len-1, "$5$rounds=%i$%s$%s", salt.salt_iter, (char *) salt.salt_buf, (char *) ptr_plain); - } - } - else if (hash_mode == 7500) - { - krb5pa_t *krb5pas = (krb5pa_t *) data.esalts_buf; - - krb5pa_t *krb5pa = &krb5pas[salt_pos]; - - u8 *ptr_timestamp = (u8 *) krb5pa->timestamp; - u8 *ptr_checksum = (u8 *) krb5pa->checksum; - - char data[128] = { 0 }; - - char *ptr_data = data; - - for (uint i = 0; i < 36; i++, ptr_data += 2) - { - sprintf (ptr_data, "%02x", ptr_timestamp[i]); - } - - for (uint i = 0; i < 16; i++, ptr_data += 2) - { - sprintf (ptr_data, "%02x", ptr_checksum[i]); - } - - *ptr_data = 0; - - snprintf (out_buf, len-1, "%s$%s$%s$%s$%s", - SIGNATURE_KRB5PA, - (char *) krb5pa->user, - (char *) krb5pa->realm, - (char *) krb5pa->salt, - data); - } - else if (hash_mode == 7700) - { - snprintf (out_buf, len-1, "%s$%08X%08X", - (char *) salt.salt_buf, - digest_buf[0], - digest_buf[1]); - } - else if (hash_mode == 7800) - { - snprintf (out_buf, len-1, "%s$%08X%08X%08X%08X%08X", - (char *) salt.salt_buf, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4]); - } - else if (hash_mode == 7900) - { - drupal7_encode ((unsigned char *) digest_buf64, (unsigned char *) ptr_plain); - - // ugly hack start - - char *tmp = (char *) salt.salt_buf_pc; - - ptr_plain[42] = tmp[0]; - - // ugly hack end - - ptr_plain[43] = 0; - - snprintf (out_buf, len-1, "%s%s%s", (char *) salt.salt_sign, (char *) salt.salt_buf, (char *) ptr_plain); - } - else if (hash_mode == 8000) - { - snprintf (out_buf, len-1, "0xc007%s%08x%08x%08x%08x%08x%08x%08x%08x", - (unsigned char *) salt.salt_buf, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4], - digest_buf[5], - digest_buf[6], - digest_buf[7]); - } - else if (hash_mode == 8100) - { - salt.salt_buf[0] = byte_swap_32 (salt.salt_buf[0]); - salt.salt_buf[1] = byte_swap_32 (salt.salt_buf[1]); - - snprintf (out_buf, len-1, "1%s%08x%08x%08x%08x%08x", - (unsigned char *) salt.salt_buf, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4]); - } - else if (hash_mode == 8200) - { - cloudkey_t *cloudkeys = (cloudkey_t *) data.esalts_buf; - - cloudkey_t *cloudkey = &cloudkeys[salt_pos]; - - char data_buf[4096] = { 0 }; - - for (int i = 0, j = 0; i < 512; i += 1, j += 8) - { - sprintf (data_buf + j, "%08x", cloudkey->data_buf[i]); - } - - data_buf[cloudkey->data_len * 2] = 0; - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - digest_buf[5] = byte_swap_32 (digest_buf[5]); - digest_buf[6] = byte_swap_32 (digest_buf[6]); - digest_buf[7] = byte_swap_32 (digest_buf[7]); - - salt.salt_buf[0] = byte_swap_32 (salt.salt_buf[0]); - salt.salt_buf[1] = byte_swap_32 (salt.salt_buf[1]); - salt.salt_buf[2] = byte_swap_32 (salt.salt_buf[2]); - salt.salt_buf[3] = byte_swap_32 (salt.salt_buf[3]); - - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x:%08x%08x%08x%08x:%u:%s", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4], - digest_buf[5], - digest_buf[6], - digest_buf[7], - salt.salt_buf[0], - salt.salt_buf[1], - salt.salt_buf[2], - salt.salt_buf[3], - salt.salt_iter + 1, - data_buf); - } - else if (hash_mode == 8300) - { - char digest_buf_c[34] = { 0 }; - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - - base32_encode (int_to_itoa32, (const u8 *) digest_buf, 20, (u8 *) digest_buf_c); - - digest_buf_c[32] = 0; - - // domain - - const uint salt_pc_len = salt.salt_buf_pc[7]; // what a hack - - char domain_buf_c[33] = { 0 }; - - memcpy (domain_buf_c, (char *) salt.salt_buf_pc, salt_pc_len); - - for (uint i = 0; i < salt_pc_len; i++) - { - const char next = domain_buf_c[i]; - - domain_buf_c[i] = '.'; - - i += next; - } - - domain_buf_c[salt_pc_len] = 0; - - // final - - snprintf (out_buf, len-1, "%s:%s:%s:%u", digest_buf_c, domain_buf_c, (char *) salt.salt_buf, salt.salt_iter); - } - else if (hash_mode == 8500) - { - snprintf (out_buf, len-1, "%s*%s*%08X%08X", SIGNATURE_RACF, (char *) salt.salt_buf, digest_buf[0], digest_buf[1]); - } - else if (hash_mode == 2612) - { - snprintf (out_buf, len-1, "%s%s$%08x%08x%08x%08x", - SIGNATURE_PHPS, - (char *) salt.salt_buf, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3]); - } - else if (hash_mode == 3711) - { - char *salt_ptr = (char *) salt.salt_buf; - - salt_ptr[salt.salt_len - 1] = 0; - - snprintf (out_buf, len-1, "%s%s$%08x%08x%08x%08x", - SIGNATURE_MEDIAWIKI_B, - salt_ptr, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3]); - } - else if (hash_mode == 8800) - { - androidfde_t *androidfdes = (androidfde_t *) data.esalts_buf; - - androidfde_t *androidfde = &androidfdes[salt_pos]; - - char tmp[3073] = { 0 }; - - for (uint i = 0, j = 0; i < 384; i += 1, j += 8) - { - sprintf (tmp + j, "%08x", androidfde->data[i]); - } - - tmp[3072] = 0; - - snprintf (out_buf, len-1, "%s16$%08x%08x%08x%08x$16$%08x%08x%08x%08x$%s", - SIGNATURE_ANDROIDFDE, - byte_swap_32 (salt.salt_buf[0]), - byte_swap_32 (salt.salt_buf[1]), - byte_swap_32 (salt.salt_buf[2]), - byte_swap_32 (salt.salt_buf[3]), - byte_swap_32 (digest_buf[0]), - byte_swap_32 (digest_buf[1]), - byte_swap_32 (digest_buf[2]), - byte_swap_32 (digest_buf[3]), - tmp); - } - else if (hash_mode == 8900) - { - uint N = salt.scrypt_N; - uint r = salt.scrypt_r; - uint p = salt.scrypt_p; - - char base64_salt[32] = { 0 }; - - base64_encode (int_to_base64, (const u8 *) salt.salt_buf, salt.salt_len, (u8 *) base64_salt); - - memset (tmp_buf, 0, 46); - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - digest_buf[5] = byte_swap_32 (digest_buf[5]); - digest_buf[6] = byte_swap_32 (digest_buf[6]); - digest_buf[7] = byte_swap_32 (digest_buf[7]); - digest_buf[8] = 0; // needed for base64_encode () - - base64_encode (int_to_base64, (const u8 *) digest_buf, 32, (u8 *) tmp_buf); - - snprintf (out_buf, len-1, "%s:%i:%i:%i:%s:%s", - SIGNATURE_SCRYPT, - N, - r, - p, - base64_salt, - tmp_buf); - } - else if (hash_mode == 9000) - { - snprintf (out_buf, len-1, "%s", hashfile); - } - else if (hash_mode == 9200) - { - // salt - - pbkdf2_sha256_t *pbkdf2_sha256s = (pbkdf2_sha256_t *) data.esalts_buf; - - pbkdf2_sha256_t *pbkdf2_sha256 = &pbkdf2_sha256s[salt_pos]; - - unsigned char *salt_buf_ptr = (unsigned char *) pbkdf2_sha256->salt_buf; - - // hash - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - digest_buf[5] = byte_swap_32 (digest_buf[5]); - digest_buf[6] = byte_swap_32 (digest_buf[6]); - digest_buf[7] = byte_swap_32 (digest_buf[7]); - digest_buf[8] = 0; // needed for base64_encode () - - char tmp_buf[64] = { 0 }; - - base64_encode (int_to_itoa64, (const u8 *) digest_buf, 32, (u8 *) tmp_buf); - tmp_buf[43] = 0; // cut it here - - // output - - snprintf (out_buf, len-1, "%s%s$%s", SIGNATURE_CISCO8, salt_buf_ptr, tmp_buf); - } - else if (hash_mode == 9300) - { - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - digest_buf[5] = byte_swap_32 (digest_buf[5]); - digest_buf[6] = byte_swap_32 (digest_buf[6]); - digest_buf[7] = byte_swap_32 (digest_buf[7]); - digest_buf[8] = 0; // needed for base64_encode () - - char tmp_buf[64] = { 0 }; - - base64_encode (int_to_itoa64, (const u8 *) digest_buf, 32, (u8 *) tmp_buf); - tmp_buf[43] = 0; // cut it here - - unsigned char *salt_buf_ptr = (unsigned char *) salt.salt_buf; - - snprintf (out_buf, len-1, "%s%s$%s", SIGNATURE_CISCO9, salt_buf_ptr, tmp_buf); - } - else if (hash_mode == 9400) - { - office2007_t *office2007s = (office2007_t *) data.esalts_buf; - - office2007_t *office2007 = &office2007s[salt_pos]; - - snprintf (out_buf, len-1, "%s*%u*%u*%u*%u*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x%08x", - SIGNATURE_OFFICE2007, - 2007, - 20, - office2007->keySize, - 16, - salt.salt_buf[0], - salt.salt_buf[1], - salt.salt_buf[2], - salt.salt_buf[3], - office2007->encryptedVerifier[0], - office2007->encryptedVerifier[1], - office2007->encryptedVerifier[2], - office2007->encryptedVerifier[3], - office2007->encryptedVerifierHash[0], - office2007->encryptedVerifierHash[1], - office2007->encryptedVerifierHash[2], - office2007->encryptedVerifierHash[3], - office2007->encryptedVerifierHash[4]); - } - else if (hash_mode == 9500) - { - office2010_t *office2010s = (office2010_t *) data.esalts_buf; - - office2010_t *office2010 = &office2010s[salt_pos]; - - snprintf (out_buf, len-1, "%s*%u*%u*%u*%u*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x%08x%08x%08x%08x", SIGNATURE_OFFICE2010, 2010, 100000, 128, 16, - - salt.salt_buf[0], - salt.salt_buf[1], - salt.salt_buf[2], - salt.salt_buf[3], - office2010->encryptedVerifier[0], - office2010->encryptedVerifier[1], - office2010->encryptedVerifier[2], - office2010->encryptedVerifier[3], - office2010->encryptedVerifierHash[0], - office2010->encryptedVerifierHash[1], - office2010->encryptedVerifierHash[2], - office2010->encryptedVerifierHash[3], - office2010->encryptedVerifierHash[4], - office2010->encryptedVerifierHash[5], - office2010->encryptedVerifierHash[6], - office2010->encryptedVerifierHash[7]); - } - else if (hash_mode == 9600) - { - office2013_t *office2013s = (office2013_t *) data.esalts_buf; - - office2013_t *office2013 = &office2013s[salt_pos]; - - snprintf (out_buf, len-1, "%s*%u*%u*%u*%u*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x%08x%08x%08x%08x", SIGNATURE_OFFICE2013, 2013, 100000, 256, 16, - - salt.salt_buf[0], - salt.salt_buf[1], - salt.salt_buf[2], - salt.salt_buf[3], - office2013->encryptedVerifier[0], - office2013->encryptedVerifier[1], - office2013->encryptedVerifier[2], - office2013->encryptedVerifier[3], - office2013->encryptedVerifierHash[0], - office2013->encryptedVerifierHash[1], - office2013->encryptedVerifierHash[2], - office2013->encryptedVerifierHash[3], - office2013->encryptedVerifierHash[4], - office2013->encryptedVerifierHash[5], - office2013->encryptedVerifierHash[6], - office2013->encryptedVerifierHash[7]); - } - else if (hash_mode == 9700) - { - oldoffice01_t *oldoffice01s = (oldoffice01_t *) data.esalts_buf; - - oldoffice01_t *oldoffice01 = &oldoffice01s[salt_pos]; - - snprintf (out_buf, len-1, "%s*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x", - (oldoffice01->version == 0) ? SIGNATURE_OLDOFFICE0 : SIGNATURE_OLDOFFICE1, - byte_swap_32 (salt.salt_buf[0]), - byte_swap_32 (salt.salt_buf[1]), - byte_swap_32 (salt.salt_buf[2]), - byte_swap_32 (salt.salt_buf[3]), - byte_swap_32 (oldoffice01->encryptedVerifier[0]), - byte_swap_32 (oldoffice01->encryptedVerifier[1]), - byte_swap_32 (oldoffice01->encryptedVerifier[2]), - byte_swap_32 (oldoffice01->encryptedVerifier[3]), - byte_swap_32 (oldoffice01->encryptedVerifierHash[0]), - byte_swap_32 (oldoffice01->encryptedVerifierHash[1]), - byte_swap_32 (oldoffice01->encryptedVerifierHash[2]), - byte_swap_32 (oldoffice01->encryptedVerifierHash[3])); - } - else if (hash_mode == 9710) - { - oldoffice01_t *oldoffice01s = (oldoffice01_t *) data.esalts_buf; - - oldoffice01_t *oldoffice01 = &oldoffice01s[salt_pos]; - - snprintf (out_buf, len-1, "%s*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x", - (oldoffice01->version == 0) ? SIGNATURE_OLDOFFICE0 : SIGNATURE_OLDOFFICE1, - byte_swap_32 (salt.salt_buf[0]), - byte_swap_32 (salt.salt_buf[1]), - byte_swap_32 (salt.salt_buf[2]), - byte_swap_32 (salt.salt_buf[3]), - byte_swap_32 (oldoffice01->encryptedVerifier[0]), - byte_swap_32 (oldoffice01->encryptedVerifier[1]), - byte_swap_32 (oldoffice01->encryptedVerifier[2]), - byte_swap_32 (oldoffice01->encryptedVerifier[3]), - byte_swap_32 (oldoffice01->encryptedVerifierHash[0]), - byte_swap_32 (oldoffice01->encryptedVerifierHash[1]), - byte_swap_32 (oldoffice01->encryptedVerifierHash[2]), - byte_swap_32 (oldoffice01->encryptedVerifierHash[3])); - } - else if (hash_mode == 9720) - { - oldoffice01_t *oldoffice01s = (oldoffice01_t *) data.esalts_buf; - - oldoffice01_t *oldoffice01 = &oldoffice01s[salt_pos]; - - u8 *rc4key = (u8 *) oldoffice01->rc4key; - - snprintf (out_buf, len-1, "%s*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x:%02x%02x%02x%02x%02x", - (oldoffice01->version == 0) ? SIGNATURE_OLDOFFICE0 : SIGNATURE_OLDOFFICE1, - byte_swap_32 (salt.salt_buf[0]), - byte_swap_32 (salt.salt_buf[1]), - byte_swap_32 (salt.salt_buf[2]), - byte_swap_32 (salt.salt_buf[3]), - byte_swap_32 (oldoffice01->encryptedVerifier[0]), - byte_swap_32 (oldoffice01->encryptedVerifier[1]), - byte_swap_32 (oldoffice01->encryptedVerifier[2]), - byte_swap_32 (oldoffice01->encryptedVerifier[3]), - byte_swap_32 (oldoffice01->encryptedVerifierHash[0]), - byte_swap_32 (oldoffice01->encryptedVerifierHash[1]), - byte_swap_32 (oldoffice01->encryptedVerifierHash[2]), - byte_swap_32 (oldoffice01->encryptedVerifierHash[3]), - rc4key[0], - rc4key[1], - rc4key[2], - rc4key[3], - rc4key[4]); - } - else if (hash_mode == 9800) - { - oldoffice34_t *oldoffice34s = (oldoffice34_t *) data.esalts_buf; - - oldoffice34_t *oldoffice34 = &oldoffice34s[salt_pos]; - - snprintf (out_buf, len-1, "%s*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x%08x", - (oldoffice34->version == 3) ? SIGNATURE_OLDOFFICE3 : SIGNATURE_OLDOFFICE4, - salt.salt_buf[0], - salt.salt_buf[1], - salt.salt_buf[2], - salt.salt_buf[3], - byte_swap_32 (oldoffice34->encryptedVerifier[0]), - byte_swap_32 (oldoffice34->encryptedVerifier[1]), - byte_swap_32 (oldoffice34->encryptedVerifier[2]), - byte_swap_32 (oldoffice34->encryptedVerifier[3]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[0]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[1]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[2]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[3]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[4])); - } - else if (hash_mode == 9810) - { - oldoffice34_t *oldoffice34s = (oldoffice34_t *) data.esalts_buf; - - oldoffice34_t *oldoffice34 = &oldoffice34s[salt_pos]; - - snprintf (out_buf, len-1, "%s*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x%08x", - (oldoffice34->version == 3) ? SIGNATURE_OLDOFFICE3 : SIGNATURE_OLDOFFICE4, - salt.salt_buf[0], - salt.salt_buf[1], - salt.salt_buf[2], - salt.salt_buf[3], - byte_swap_32 (oldoffice34->encryptedVerifier[0]), - byte_swap_32 (oldoffice34->encryptedVerifier[1]), - byte_swap_32 (oldoffice34->encryptedVerifier[2]), - byte_swap_32 (oldoffice34->encryptedVerifier[3]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[0]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[1]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[2]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[3]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[4])); - } - else if (hash_mode == 9820) - { - oldoffice34_t *oldoffice34s = (oldoffice34_t *) data.esalts_buf; - - oldoffice34_t *oldoffice34 = &oldoffice34s[salt_pos]; - - u8 *rc4key = (u8 *) oldoffice34->rc4key; - - snprintf (out_buf, len-1, "%s*%08x%08x%08x%08x*%08x%08x%08x%08x*%08x%08x%08x%08x%08x:%02x%02x%02x%02x%02x", - (oldoffice34->version == 3) ? SIGNATURE_OLDOFFICE3 : SIGNATURE_OLDOFFICE4, - salt.salt_buf[0], - salt.salt_buf[1], - salt.salt_buf[2], - salt.salt_buf[3], - byte_swap_32 (oldoffice34->encryptedVerifier[0]), - byte_swap_32 (oldoffice34->encryptedVerifier[1]), - byte_swap_32 (oldoffice34->encryptedVerifier[2]), - byte_swap_32 (oldoffice34->encryptedVerifier[3]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[0]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[1]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[2]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[3]), - byte_swap_32 (oldoffice34->encryptedVerifierHash[4]), - rc4key[0], - rc4key[1], - rc4key[2], - rc4key[3], - rc4key[4]); - } - else if (hash_mode == 10000) - { - // salt - - pbkdf2_sha256_t *pbkdf2_sha256s = (pbkdf2_sha256_t *) data.esalts_buf; - - pbkdf2_sha256_t *pbkdf2_sha256 = &pbkdf2_sha256s[salt_pos]; - - unsigned char *salt_buf_ptr = (unsigned char *) pbkdf2_sha256->salt_buf; - - // hash - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - digest_buf[2] = byte_swap_32 (digest_buf[2]); - digest_buf[3] = byte_swap_32 (digest_buf[3]); - digest_buf[4] = byte_swap_32 (digest_buf[4]); - digest_buf[5] = byte_swap_32 (digest_buf[5]); - digest_buf[6] = byte_swap_32 (digest_buf[6]); - digest_buf[7] = byte_swap_32 (digest_buf[7]); - digest_buf[8] = 0; // needed for base64_encode () - - char tmp_buf[64] = { 0 }; - - base64_encode (int_to_base64, (const u8 *) digest_buf, 32, (u8 *) tmp_buf); - - // output - - snprintf (out_buf, len-1, "%s%i$%s$%s", SIGNATURE_DJANGOPBKDF2, salt.salt_iter + 1, salt_buf_ptr, tmp_buf); - } - else if (hash_mode == 10100) - { - snprintf (out_buf, len-1, "%08x%08x:%u:%u:%08x%08x%08x%08x", - digest_buf[0], - digest_buf[1], - 2, - 4, - byte_swap_32 (salt.salt_buf[0]), - byte_swap_32 (salt.salt_buf[1]), - byte_swap_32 (salt.salt_buf[2]), - byte_swap_32 (salt.salt_buf[3])); - } - else if (hash_mode == 10200) - { - cram_md5_t *cram_md5s = (cram_md5_t *) data.esalts_buf; - - cram_md5_t *cram_md5 = &cram_md5s[salt_pos]; - - // challenge - - char challenge[100] = { 0 }; - - base64_encode (int_to_base64, (const u8 *) salt.salt_buf, salt.salt_len, (u8 *) challenge); - - // response - - char tmp_buf[100] = { 0 }; - - uint tmp_len = snprintf (tmp_buf, 100, "%s %08x%08x%08x%08x", - (char *) cram_md5->user, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3]); - - char response[100] = { 0 }; - - base64_encode (int_to_base64, (const u8 *) tmp_buf, tmp_len, (u8 *) response); - - snprintf (out_buf, len-1, "%s%s$%s", SIGNATURE_CRAM_MD5, challenge, response); - } - else if (hash_mode == 10300) - { - char tmp_buf[100] = { 0 }; - - memcpy (tmp_buf + 0, digest_buf, 20); - memcpy (tmp_buf + 20, salt.salt_buf, salt.salt_len); - - uint tmp_len = 20 + salt.salt_len; - - // base64 encode it - - char base64_encoded[100] = { 0 }; - - base64_encode (int_to_base64, (const u8 *) tmp_buf, tmp_len, (u8 *) base64_encoded); - - snprintf (out_buf, len-1, "%s%i}%s", SIGNATURE_SAPH_SHA1, salt.salt_iter + 1, base64_encoded); - } - else if (hash_mode == 10400) - { - pdf_t *pdfs = (pdf_t *) data.esalts_buf; - - pdf_t *pdf = &pdfs[salt_pos]; - - snprintf (out_buf, len-1, "$pdf$%d*%d*%d*%d*%d*%d*%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x", - - pdf->V, - pdf->R, - 40, - pdf->P, - pdf->enc_md, - pdf->id_len, - byte_swap_32 (pdf->id_buf[0]), - byte_swap_32 (pdf->id_buf[1]), - byte_swap_32 (pdf->id_buf[2]), - byte_swap_32 (pdf->id_buf[3]), - pdf->u_len, - byte_swap_32 (pdf->u_buf[0]), - byte_swap_32 (pdf->u_buf[1]), - byte_swap_32 (pdf->u_buf[2]), - byte_swap_32 (pdf->u_buf[3]), - byte_swap_32 (pdf->u_buf[4]), - byte_swap_32 (pdf->u_buf[5]), - byte_swap_32 (pdf->u_buf[6]), - byte_swap_32 (pdf->u_buf[7]), - pdf->o_len, - byte_swap_32 (pdf->o_buf[0]), - byte_swap_32 (pdf->o_buf[1]), - byte_swap_32 (pdf->o_buf[2]), - byte_swap_32 (pdf->o_buf[3]), - byte_swap_32 (pdf->o_buf[4]), - byte_swap_32 (pdf->o_buf[5]), - byte_swap_32 (pdf->o_buf[6]), - byte_swap_32 (pdf->o_buf[7]) - ); - } - else if (hash_mode == 10410) - { - pdf_t *pdfs = (pdf_t *) data.esalts_buf; - - pdf_t *pdf = &pdfs[salt_pos]; - - snprintf (out_buf, len-1, "$pdf$%d*%d*%d*%d*%d*%d*%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x", - - pdf->V, - pdf->R, - 40, - pdf->P, - pdf->enc_md, - pdf->id_len, - byte_swap_32 (pdf->id_buf[0]), - byte_swap_32 (pdf->id_buf[1]), - byte_swap_32 (pdf->id_buf[2]), - byte_swap_32 (pdf->id_buf[3]), - pdf->u_len, - byte_swap_32 (pdf->u_buf[0]), - byte_swap_32 (pdf->u_buf[1]), - byte_swap_32 (pdf->u_buf[2]), - byte_swap_32 (pdf->u_buf[3]), - byte_swap_32 (pdf->u_buf[4]), - byte_swap_32 (pdf->u_buf[5]), - byte_swap_32 (pdf->u_buf[6]), - byte_swap_32 (pdf->u_buf[7]), - pdf->o_len, - byte_swap_32 (pdf->o_buf[0]), - byte_swap_32 (pdf->o_buf[1]), - byte_swap_32 (pdf->o_buf[2]), - byte_swap_32 (pdf->o_buf[3]), - byte_swap_32 (pdf->o_buf[4]), - byte_swap_32 (pdf->o_buf[5]), - byte_swap_32 (pdf->o_buf[6]), - byte_swap_32 (pdf->o_buf[7]) - ); - } - else if (hash_mode == 10420) - { - pdf_t *pdfs = (pdf_t *) data.esalts_buf; - - pdf_t *pdf = &pdfs[salt_pos]; - - u8 *rc4key = (u8 *) pdf->rc4key; - - snprintf (out_buf, len-1, "$pdf$%d*%d*%d*%d*%d*%d*%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x:%02x%02x%02x%02x%02x", - - pdf->V, - pdf->R, - 40, - pdf->P, - pdf->enc_md, - pdf->id_len, - byte_swap_32 (pdf->id_buf[0]), - byte_swap_32 (pdf->id_buf[1]), - byte_swap_32 (pdf->id_buf[2]), - byte_swap_32 (pdf->id_buf[3]), - pdf->u_len, - byte_swap_32 (pdf->u_buf[0]), - byte_swap_32 (pdf->u_buf[1]), - byte_swap_32 (pdf->u_buf[2]), - byte_swap_32 (pdf->u_buf[3]), - byte_swap_32 (pdf->u_buf[4]), - byte_swap_32 (pdf->u_buf[5]), - byte_swap_32 (pdf->u_buf[6]), - byte_swap_32 (pdf->u_buf[7]), - pdf->o_len, - byte_swap_32 (pdf->o_buf[0]), - byte_swap_32 (pdf->o_buf[1]), - byte_swap_32 (pdf->o_buf[2]), - byte_swap_32 (pdf->o_buf[3]), - byte_swap_32 (pdf->o_buf[4]), - byte_swap_32 (pdf->o_buf[5]), - byte_swap_32 (pdf->o_buf[6]), - byte_swap_32 (pdf->o_buf[7]), - rc4key[0], - rc4key[1], - rc4key[2], - rc4key[3], - rc4key[4] - ); - } - else if (hash_mode == 10500) - { - pdf_t *pdfs = (pdf_t *) data.esalts_buf; - - pdf_t *pdf = &pdfs[salt_pos]; - - if (pdf->id_len == 32) - { - snprintf (out_buf, len-1, "$pdf$%d*%d*%d*%d*%d*%d*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x", - - pdf->V, - pdf->R, - 128, - pdf->P, - pdf->enc_md, - pdf->id_len, - byte_swap_32 (pdf->id_buf[0]), - byte_swap_32 (pdf->id_buf[1]), - byte_swap_32 (pdf->id_buf[2]), - byte_swap_32 (pdf->id_buf[3]), - byte_swap_32 (pdf->id_buf[4]), - byte_swap_32 (pdf->id_buf[5]), - byte_swap_32 (pdf->id_buf[6]), - byte_swap_32 (pdf->id_buf[7]), - pdf->u_len, - byte_swap_32 (pdf->u_buf[0]), - byte_swap_32 (pdf->u_buf[1]), - byte_swap_32 (pdf->u_buf[2]), - byte_swap_32 (pdf->u_buf[3]), - byte_swap_32 (pdf->u_buf[4]), - byte_swap_32 (pdf->u_buf[5]), - byte_swap_32 (pdf->u_buf[6]), - byte_swap_32 (pdf->u_buf[7]), - pdf->o_len, - byte_swap_32 (pdf->o_buf[0]), - byte_swap_32 (pdf->o_buf[1]), - byte_swap_32 (pdf->o_buf[2]), - byte_swap_32 (pdf->o_buf[3]), - byte_swap_32 (pdf->o_buf[4]), - byte_swap_32 (pdf->o_buf[5]), - byte_swap_32 (pdf->o_buf[6]), - byte_swap_32 (pdf->o_buf[7]) - ); - } - else - { - snprintf (out_buf, len-1, "$pdf$%d*%d*%d*%d*%d*%d*%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x*%d*%08x%08x%08x%08x%08x%08x%08x%08x", - - pdf->V, - pdf->R, - 128, - pdf->P, - pdf->enc_md, - pdf->id_len, - byte_swap_32 (pdf->id_buf[0]), - byte_swap_32 (pdf->id_buf[1]), - byte_swap_32 (pdf->id_buf[2]), - byte_swap_32 (pdf->id_buf[3]), - pdf->u_len, - byte_swap_32 (pdf->u_buf[0]), - byte_swap_32 (pdf->u_buf[1]), - byte_swap_32 (pdf->u_buf[2]), - byte_swap_32 (pdf->u_buf[3]), - byte_swap_32 (pdf->u_buf[4]), - byte_swap_32 (pdf->u_buf[5]), - byte_swap_32 (pdf->u_buf[6]), - byte_swap_32 (pdf->u_buf[7]), - pdf->o_len, - byte_swap_32 (pdf->o_buf[0]), - byte_swap_32 (pdf->o_buf[1]), - byte_swap_32 (pdf->o_buf[2]), - byte_swap_32 (pdf->o_buf[3]), - byte_swap_32 (pdf->o_buf[4]), - byte_swap_32 (pdf->o_buf[5]), - byte_swap_32 (pdf->o_buf[6]), - byte_swap_32 (pdf->o_buf[7]) - ); - } - } - else if (hash_mode == 10600) - { - uint digest_idx = salt.digests_offset + digest_pos; - - hashinfo_t **hashinfo_ptr = data.hash_info; - char *hash_buf = hashinfo_ptr[digest_idx]->orighash; - - snprintf (out_buf, len-1, "%s", hash_buf); - } - else if (hash_mode == 10700) - { - uint digest_idx = salt.digests_offset + digest_pos; - - hashinfo_t **hashinfo_ptr = data.hash_info; - char *hash_buf = hashinfo_ptr[digest_idx]->orighash; - - snprintf (out_buf, len-1, "%s", hash_buf); - } - else if (hash_mode == 10900) - { - uint digest_idx = salt.digests_offset + digest_pos; - - hashinfo_t **hashinfo_ptr = data.hash_info; - char *hash_buf = hashinfo_ptr[digest_idx]->orighash; - - snprintf (out_buf, len-1, "%s", hash_buf); - } - else if (hash_mode == 11100) - { - u32 salt_challenge = salt.salt_buf[0]; - - salt_challenge = byte_swap_32 (salt_challenge); - - unsigned char *user_name = (unsigned char *) (salt.salt_buf + 1); - - snprintf (out_buf, len-1, "%s%s*%08x*%08x%08x%08x%08x", - SIGNATURE_POSTGRESQL_AUTH, - user_name, - salt_challenge, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3]); - } - else if (hash_mode == 11200) - { - snprintf (out_buf, len-1, "%s%s*%08x%08x%08x%08x%08x", - SIGNATURE_MYSQL_AUTH, - (unsigned char *) salt.salt_buf, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4]); - } - else if (hash_mode == 11300) - { - bitcoin_wallet_t *bitcoin_wallets = (bitcoin_wallet_t *) data.esalts_buf; - - bitcoin_wallet_t *bitcoin_wallet = &bitcoin_wallets[salt_pos]; - - const uint cry_master_len = bitcoin_wallet->cry_master_len; - const uint ckey_len = bitcoin_wallet->ckey_len; - const uint public_key_len = bitcoin_wallet->public_key_len; - - char *cry_master_buf = (char *) mymalloc ((cry_master_len * 2) + 1); - char *ckey_buf = (char *) mymalloc ((ckey_len * 2) + 1); - char *public_key_buf = (char *) mymalloc ((public_key_len * 2) + 1); - - for (uint i = 0, j = 0; i < cry_master_len; i += 1, j += 2) - { - const u8 *ptr = (const u8 *) bitcoin_wallet->cry_master_buf; - - sprintf (cry_master_buf + j, "%02x", ptr[i]); - } - - for (uint i = 0, j = 0; i < ckey_len; i += 1, j += 2) - { - const u8 *ptr = (const u8 *) bitcoin_wallet->ckey_buf; - - sprintf (ckey_buf + j, "%02x", ptr[i]); - } - - for (uint i = 0, j = 0; i < public_key_len; i += 1, j += 2) - { - const u8 *ptr = (const u8 *) bitcoin_wallet->public_key_buf; - - sprintf (public_key_buf + j, "%02x", ptr[i]); - } - - snprintf (out_buf, len-1, "%s%d$%s$%d$%s$%d$%d$%s$%d$%s", - SIGNATURE_BITCOIN_WALLET, - cry_master_len * 2, - cry_master_buf, - salt.salt_len, - (unsigned char *) salt.salt_buf, - salt.salt_iter + 1, - ckey_len * 2, - ckey_buf, - public_key_len * 2, - public_key_buf - ); - - myfree (cry_master_buf); - myfree (ckey_buf); - myfree (public_key_buf); - } - else if (hash_mode == 11400) - { - uint digest_idx = salt.digests_offset + digest_pos; - - hashinfo_t **hashinfo_ptr = data.hash_info; - char *hash_buf = hashinfo_ptr[digest_idx]->orighash; - - snprintf (out_buf, len-1, "%s", hash_buf); - } - else if (hash_mode == 11600) - { - seven_zip_t *seven_zips = (seven_zip_t *) data.esalts_buf; - - seven_zip_t *seven_zip = &seven_zips[salt_pos]; - - const uint data_len = seven_zip->data_len; - - char *data_buf = (char *) mymalloc ((data_len * 2) + 1); - - for (uint i = 0, j = 0; i < data_len; i += 1, j += 2) - { - const u8 *ptr = (const u8 *) seven_zip->data_buf; - - sprintf (data_buf + j, "%02x", ptr[i]); - } - - snprintf (out_buf, len-1, "%s%u$%u$%u$%s$%u$%08x%08x%08x%08x$%u$%u$%u$%s", - SIGNATURE_SEVEN_ZIP, - 0, - salt.salt_sign[0], - 0, - (char *) seven_zip->salt_buf, - seven_zip->iv_len, - seven_zip->iv_buf[0], - seven_zip->iv_buf[1], - seven_zip->iv_buf[2], - seven_zip->iv_buf[3], - seven_zip->crc, - seven_zip->data_len, - seven_zip->unpack_size, - data_buf); - - myfree (data_buf); - } - else if (hash_mode == 11700) - { - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4], - digest_buf[5], - digest_buf[6], - digest_buf[7]); - } - else if (hash_mode == 11800) - { - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", - digest_buf[ 0], - digest_buf[ 1], - digest_buf[ 2], - digest_buf[ 3], - digest_buf[ 4], - digest_buf[ 5], - digest_buf[ 6], - digest_buf[ 7], - digest_buf[ 8], - digest_buf[ 9], - digest_buf[10], - digest_buf[11], - digest_buf[12], - digest_buf[13], - digest_buf[14], - digest_buf[15]); - } - else if (hash_mode == 11900) - { - uint digest_idx = salt.digests_offset + digest_pos; - - hashinfo_t **hashinfo_ptr = data.hash_info; - char *hash_buf = hashinfo_ptr[digest_idx]->orighash; - - snprintf (out_buf, len-1, "%s", hash_buf); - } - else if (hash_mode == 12000) - { - uint digest_idx = salt.digests_offset + digest_pos; - - hashinfo_t **hashinfo_ptr = data.hash_info; - char *hash_buf = hashinfo_ptr[digest_idx]->orighash; - - snprintf (out_buf, len-1, "%s", hash_buf); - } - else if (hash_mode == 12100) - { - uint digest_idx = salt.digests_offset + digest_pos; - - hashinfo_t **hashinfo_ptr = data.hash_info; - char *hash_buf = hashinfo_ptr[digest_idx]->orighash; - - snprintf (out_buf, len-1, "%s", hash_buf); - } - else if (hash_mode == 12200) - { - uint *ptr_digest = digest_buf; - uint *ptr_salt = salt.salt_buf; - - snprintf (out_buf, len-1, "%s0$1$%08x%08x$%08x%08x", - SIGNATURE_ECRYPTFS, - ptr_salt[0], - ptr_salt[1], - ptr_digest[0], - ptr_digest[1]); - } - else if (hash_mode == 12300) - { - uint *ptr_digest = digest_buf; - uint *ptr_salt = salt.salt_buf; - - snprintf (out_buf, len-1, "%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X", - ptr_digest[ 0], ptr_digest[ 1], - ptr_digest[ 2], ptr_digest[ 3], - ptr_digest[ 4], ptr_digest[ 5], - ptr_digest[ 6], ptr_digest[ 7], - ptr_digest[ 8], ptr_digest[ 9], - ptr_digest[10], ptr_digest[11], - ptr_digest[12], ptr_digest[13], - ptr_digest[14], ptr_digest[15], - ptr_salt[0], - ptr_salt[1], - ptr_salt[2], - ptr_salt[3]); - } - else if (hash_mode == 12400) - { - // encode iteration count - - char salt_iter[5] = { 0 }; - - salt_iter[0] = int_to_itoa64 ((salt.salt_iter ) & 0x3f); - salt_iter[1] = int_to_itoa64 ((salt.salt_iter >> 6) & 0x3f); - salt_iter[2] = int_to_itoa64 ((salt.salt_iter >> 12) & 0x3f); - salt_iter[3] = int_to_itoa64 ((salt.salt_iter >> 18) & 0x3f); - salt_iter[4] = 0; - - // encode salt - - ptr_salt[0] = int_to_itoa64 ((salt.salt_buf[0] ) & 0x3f); - ptr_salt[1] = int_to_itoa64 ((salt.salt_buf[0] >> 6) & 0x3f); - ptr_salt[2] = int_to_itoa64 ((salt.salt_buf[0] >> 12) & 0x3f); - ptr_salt[3] = int_to_itoa64 ((salt.salt_buf[0] >> 18) & 0x3f); - ptr_salt[4] = 0; - - // encode digest - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - digest_buf[0] = byte_swap_32 (digest_buf[0]); - digest_buf[1] = byte_swap_32 (digest_buf[1]); - - memcpy (tmp_buf, digest_buf, 8); - - base64_encode (int_to_itoa64, (const u8 *) tmp_buf, 8, (u8 *) ptr_plain); - - ptr_plain[11] = 0; - - // fill the resulting buffer - - snprintf (out_buf, len - 1, "_%s%s%s", salt_iter, ptr_salt, ptr_plain); - } - else if (hash_mode == 12500) - { - snprintf (out_buf, len - 1, "%s*0*%08x%08x*%08x%08x%08x%08x", - SIGNATURE_RAR3, - byte_swap_32 (salt.salt_buf[0]), - byte_swap_32 (salt.salt_buf[1]), - salt.salt_buf[2], - salt.salt_buf[3], - salt.salt_buf[4], - salt.salt_buf[5]); - } - else if (hash_mode == 12600) - { - snprintf (out_buf, len - 1, "%08x%08x%08x%08x%08x%08x%08x%08x", - digest_buf[0] + salt.salt_buf_pc[0], - digest_buf[1] + salt.salt_buf_pc[1], - digest_buf[2] + salt.salt_buf_pc[2], - digest_buf[3] + salt.salt_buf_pc[3], - digest_buf[4] + salt.salt_buf_pc[4], - digest_buf[5] + salt.salt_buf_pc[5], - digest_buf[6] + salt.salt_buf_pc[6], - digest_buf[7] + salt.salt_buf_pc[7]); - } - else if (hash_mode == 12700) - { - uint digest_idx = salt.digests_offset + digest_pos; - - hashinfo_t **hashinfo_ptr = data.hash_info; - char *hash_buf = hashinfo_ptr[digest_idx]->orighash; - - snprintf (out_buf, len-1, "%s", hash_buf); - } - else if (hash_mode == 12800) - { - const u8 *ptr = (const u8 *) salt.salt_buf; - - snprintf (out_buf, len-1, "%s,%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x,%d,%08x%08x%08x%08x%08x%08x%08x%08x", - SIGNATURE_MS_DRSR, - ptr[0], - ptr[1], - ptr[2], - ptr[3], - ptr[4], - ptr[5], - ptr[6], - ptr[7], - ptr[8], - ptr[9], - salt.salt_iter + 1, - byte_swap_32 (digest_buf[0]), - byte_swap_32 (digest_buf[1]), - byte_swap_32 (digest_buf[2]), - byte_swap_32 (digest_buf[3]), - byte_swap_32 (digest_buf[4]), - byte_swap_32 (digest_buf[5]), - byte_swap_32 (digest_buf[6]), - byte_swap_32 (digest_buf[7]) - ); - } - else if (hash_mode == 12900) - { - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", - salt.salt_buf[ 4], - salt.salt_buf[ 5], - salt.salt_buf[ 6], - salt.salt_buf[ 7], - salt.salt_buf[ 8], - salt.salt_buf[ 9], - salt.salt_buf[10], - salt.salt_buf[11], - byte_swap_32 (digest_buf[0]), - byte_swap_32 (digest_buf[1]), - byte_swap_32 (digest_buf[2]), - byte_swap_32 (digest_buf[3]), - byte_swap_32 (digest_buf[4]), - byte_swap_32 (digest_buf[5]), - byte_swap_32 (digest_buf[6]), - byte_swap_32 (digest_buf[7]), - salt.salt_buf[ 0], - salt.salt_buf[ 1], - salt.salt_buf[ 2], - salt.salt_buf[ 3] - ); - } - else if (hash_mode == 13000) - { - rar5_t *rar5s = (rar5_t *) data.esalts_buf; - - rar5_t *rar5 = &rar5s[salt_pos]; - - snprintf (out_buf, len-1, "$rar5$16$%08x%08x%08x%08x$%u$%08x%08x%08x%08x$8$%08x%08x", - salt.salt_buf[0], - salt.salt_buf[1], - salt.salt_buf[2], - salt.salt_buf[3], - salt.salt_sign[0], - rar5->iv[0], - rar5->iv[1], - rar5->iv[2], - rar5->iv[3], - byte_swap_32 (digest_buf[0]), - byte_swap_32 (digest_buf[1]) - ); - } - else if (hash_mode == 13100) - { - krb5tgs_t *krb5tgss = (krb5tgs_t *) data.esalts_buf; - - krb5tgs_t *krb5tgs = &krb5tgss[salt_pos]; - - u8 *ptr_checksum = (u8 *) krb5tgs->checksum; - u8 *ptr_edata2 = (u8 *) krb5tgs->edata2; - - char data[2560 * 4 * 2] = { 0 }; - - char *ptr_data = data; - - for (uint i = 0; i < 16; i++, ptr_data += 2) - sprintf (ptr_data, "%02x", ptr_checksum[i]); - - /* skip '$' */ - ptr_data++; - - for (uint i = 0; i < krb5tgs->edata2_len; i++, ptr_data += 2) - sprintf (ptr_data, "%02x", ptr_edata2[i]); - - snprintf (out_buf, len-1, "%s$%s$%s$%s", - SIGNATURE_KRB5TGS, - (char *) krb5tgs->account_info, - data, - data + 33); - } - else if (hash_mode == 13200) - { - snprintf (out_buf, len-1, "%s*%d*%08x%08x%08x%08x*%08x%08x%08x%08x%08x%08x", - SIGNATURE_AXCRYPT, - salt.salt_iter, - salt.salt_buf[0], - salt.salt_buf[1], - salt.salt_buf[2], - salt.salt_buf[3], - salt.salt_buf[4], - salt.salt_buf[5], - salt.salt_buf[6], - salt.salt_buf[7], - salt.salt_buf[8], - salt.salt_buf[9]); - } - else if (hash_mode == 13300) - { - snprintf (out_buf, len-1, "%s$%08x%08x%08x%08x", - SIGNATURE_AXCRYPT_SHA1, - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3]); - } - else if (hash_mode == 13400) - { - keepass_t *keepasss = (keepass_t *) data.esalts_buf; - - keepass_t *keepass = &keepasss[salt_pos]; - - u32 version = (u32) keepass->version; - u32 rounds = salt.salt_iter; - u32 algorithm = (u32) keepass->algorithm; - u32 keyfile_len = (u32) keepass->keyfile_len; - - u32 *ptr_final_random_seed = (u32 *) keepass->final_random_seed ; - u32 *ptr_transf_random_seed = (u32 *) keepass->transf_random_seed ; - u32 *ptr_enc_iv = (u32 *) keepass->enc_iv ; - u32 *ptr_contents_hash = (u32 *) keepass->contents_hash ; - u32 *ptr_keyfile = (u32 *) keepass->keyfile ; - - /* specific to version 1 */ - u32 contents_len; - u32 *ptr_contents; - - /* specific to version 2 */ - u32 expected_bytes_len; - u32 *ptr_expected_bytes; - - u32 final_random_seed_len; - u32 transf_random_seed_len; - u32 enc_iv_len; - u32 contents_hash_len; - - transf_random_seed_len = 8; - enc_iv_len = 4; - contents_hash_len = 8; - final_random_seed_len = 8; - - if (version == 1) - final_random_seed_len = 4; - - snprintf (out_buf, len-1, "%s*%d*%d*%d", - SIGNATURE_KEEPASS, - version, - rounds, - algorithm); - - char *ptr_data = out_buf; - - ptr_data += strlen(out_buf); - - *ptr_data = '*'; - ptr_data++; - - for (uint i = 0; i < final_random_seed_len; i++, ptr_data += 8) - sprintf (ptr_data, "%08x", ptr_final_random_seed[i]); - - *ptr_data = '*'; - ptr_data++; - - for (uint i = 0; i < transf_random_seed_len; i++, ptr_data += 8) - sprintf (ptr_data, "%08x", ptr_transf_random_seed[i]); - - *ptr_data = '*'; - ptr_data++; - - for (uint i = 0; i < enc_iv_len; i++, ptr_data += 8) - sprintf (ptr_data, "%08x", ptr_enc_iv[i]); - - *ptr_data = '*'; - ptr_data++; - - if (version == 1) - { - contents_len = (u32) keepass->contents_len; - ptr_contents = (u32 *) keepass->contents; - - for (uint i = 0; i < contents_hash_len; i++, ptr_data += 8) - sprintf (ptr_data, "%08x", ptr_contents_hash[i]); - - *ptr_data = '*'; - ptr_data++; - - /* inline flag */ - *ptr_data = '1'; - ptr_data++; - - *ptr_data = '*'; - ptr_data++; - - char ptr_contents_len[10] = { 0 }; - - sprintf ((char*) ptr_contents_len, "%d", contents_len); - - sprintf (ptr_data, "%d", contents_len); - - ptr_data += strlen(ptr_contents_len); - - *ptr_data = '*'; - ptr_data++; - - for (uint i = 0; i < contents_len / 4; i++, ptr_data += 8) - sprintf (ptr_data, "%08x", ptr_contents[i]); - } - else if (version == 2) - { - expected_bytes_len = 8; - ptr_expected_bytes = (u32 *) keepass->expected_bytes ; - - for (uint i = 0; i < expected_bytes_len; i++, ptr_data += 8) - sprintf (ptr_data, "%08x", ptr_expected_bytes[i]); - - *ptr_data = '*'; - ptr_data++; - - for (uint i = 0; i < contents_hash_len; i++, ptr_data += 8) - sprintf (ptr_data, "%08x", ptr_contents_hash[i]); - } - if (keyfile_len) - { - *ptr_data = '*'; - ptr_data++; - - /* inline flag */ - *ptr_data = '1'; - ptr_data++; - - *ptr_data = '*'; - ptr_data++; - - sprintf (ptr_data, "%d", keyfile_len); - - ptr_data += 2; - - *ptr_data = '*'; - ptr_data++; - - for (uint i = 0; i < 8; i++, ptr_data += 8) - sprintf (ptr_data, "%08x", ptr_keyfile[i]); - } - } - else if (hash_mode == 13500) - { - pstoken_t *pstokens = (pstoken_t *) data.esalts_buf; - - pstoken_t *pstoken = &pstokens[salt_pos]; - - const u32 salt_len = (pstoken->salt_len > 512) ? 512 : pstoken->salt_len; - - char pstoken_tmp[1024 + 1] = { 0 }; - - for (uint i = 0, j = 0; i < salt_len; i += 1, j += 2) - { - const u8 *ptr = (const u8 *) pstoken->salt_buf; - - sprintf (pstoken_tmp + j, "%02x", ptr[i]); - } - - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x:%s", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4], - pstoken_tmp); - } - else if (hash_mode == 13600) - { - zip2_t *zip2s = (zip2_t *) data.esalts_buf; - - zip2_t *zip2 = &zip2s[salt_pos]; - - const u32 salt_len = zip2->salt_len; - - char salt_tmp[32 + 1] = { 0 }; - - for (uint i = 0, j = 0; i < salt_len; i += 1, j += 2) - { - const u8 *ptr = (const u8 *) zip2->salt_buf; - - sprintf (salt_tmp + j, "%02x", ptr[i]); - } - - const u32 data_len = zip2->data_len; - - char data_tmp[8192 + 1] = { 0 }; - - for (uint i = 0, j = 0; i < data_len; i += 1, j += 2) - { - const u8 *ptr = (const u8 *) zip2->data_buf; - - sprintf (data_tmp + j, "%02x", ptr[i]); - } - - const u32 auth_len = zip2->auth_len; - - char auth_tmp[20 + 1] = { 0 }; - - for (uint i = 0, j = 0; i < auth_len; i += 1, j += 2) - { - const u8 *ptr = (const u8 *) zip2->auth_buf; - - sprintf (auth_tmp + j, "%02x", ptr[i]); - } - - snprintf (out_buf, 255, "%s*%u*%u*%u*%s*%x*%u*%s*%s*%s", - SIGNATURE_ZIP2_START, - zip2->type, - zip2->mode, - zip2->magic, - salt_tmp, - zip2->verify_bytes, - zip2->compress_length, - data_tmp, - auth_tmp, - SIGNATURE_ZIP2_STOP); - } - else if ((hash_mode >= 13700) && (hash_mode <= 13799)) - { - snprintf (out_buf, len-1, "%s", hashfile); - } - else if (hash_mode == 13800) - { - win8phone_t *esalts = (win8phone_t *) data.esalts_buf; - - win8phone_t *esalt = &esalts[salt_pos]; - - char buf[256 + 1] = { 0 }; - - for (int i = 0, j = 0; i < 32; i += 1, j += 8) - { - sprintf (buf + j, "%08x", esalt->salt_buf[i]); - } - - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x:%s", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4], - digest_buf[5], - digest_buf[6], - digest_buf[7], - buf); - } - else if (hash_mode == 14000) - { - snprintf (out_buf, len - 1, "%08x%08x:%s", digest_buf[0], digest_buf[1], (char *) salt.salt_buf); - } - else if (hash_mode == 14100) - { - snprintf (out_buf, len - 1, "%08x%08x:%s", digest_buf[0], digest_buf[1], (char *) salt.salt_buf); - } - else - { - if (hash_type == HASH_TYPE_MD4) - { - snprintf (out_buf, 255, "%08x%08x%08x%08x", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3]); - } - else if (hash_type == HASH_TYPE_MD5) - { - snprintf (out_buf, len-1, "%08x%08x%08x%08x", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3]); - } - else if (hash_type == HASH_TYPE_SHA1) - { - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4]); - } - else if (hash_type == HASH_TYPE_SHA256) - { - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4], - digest_buf[5], - digest_buf[6], - digest_buf[7]); - } - else if (hash_type == HASH_TYPE_SHA384) - { - uint *ptr = digest_buf; - - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", - ptr[ 1], ptr[ 0], - ptr[ 3], ptr[ 2], - ptr[ 5], ptr[ 4], - ptr[ 7], ptr[ 6], - ptr[ 9], ptr[ 8], - ptr[11], ptr[10]); - } - else if (hash_type == HASH_TYPE_SHA512) - { - uint *ptr = digest_buf; - - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", - ptr[ 1], ptr[ 0], - ptr[ 3], ptr[ 2], - ptr[ 5], ptr[ 4], - ptr[ 7], ptr[ 6], - ptr[ 9], ptr[ 8], - ptr[11], ptr[10], - ptr[13], ptr[12], - ptr[15], ptr[14]); - } - else if (hash_type == HASH_TYPE_LM) - { - snprintf (out_buf, len-1, "%08x%08x", - digest_buf[0], - digest_buf[1]); - } - else if (hash_type == HASH_TYPE_ORACLEH) - { - snprintf (out_buf, len-1, "%08X%08X", - digest_buf[0], - digest_buf[1]); - } - else if (hash_type == HASH_TYPE_BCRYPT) - { - base64_encode (int_to_bf64, (const u8 *) salt.salt_buf, 16, (u8 *) tmp_buf + 0); - base64_encode (int_to_bf64, (const u8 *) digest_buf, 23, (u8 *) tmp_buf + 22); - - tmp_buf[22 + 31] = 0; // base64_encode wants to pad - - snprintf (out_buf, len-1, "%s$%s", (char *) salt.salt_sign, tmp_buf); - } - else if (hash_type == HASH_TYPE_KECCAK) - { - uint *ptr = digest_buf; - - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", - ptr[ 1], ptr[ 0], - ptr[ 3], ptr[ 2], - ptr[ 5], ptr[ 4], - ptr[ 7], ptr[ 6], - ptr[ 9], ptr[ 8], - ptr[11], ptr[10], - ptr[13], ptr[12], - ptr[15], ptr[14], - ptr[17], ptr[16], - ptr[19], ptr[18], - ptr[21], ptr[20], - ptr[23], ptr[22], - ptr[25], ptr[24], - ptr[27], ptr[26], - ptr[29], ptr[28], - ptr[31], ptr[30], - ptr[33], ptr[32], - ptr[35], ptr[34], - ptr[37], ptr[36], - ptr[39], ptr[38], - ptr[41], ptr[30], - ptr[43], ptr[42], - ptr[45], ptr[44], - ptr[47], ptr[46], - ptr[49], ptr[48] - ); - - out_buf[salt.keccak_mdlen * 2] = 0; - } - else if (hash_type == HASH_TYPE_RIPEMD160) - { - snprintf (out_buf, 255, "%08x%08x%08x%08x%08x", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4]); - } - else if (hash_type == HASH_TYPE_WHIRLPOOL) - { - digest_buf[ 0] = digest_buf[ 0]; - digest_buf[ 1] = digest_buf[ 1]; - digest_buf[ 2] = digest_buf[ 2]; - digest_buf[ 3] = digest_buf[ 3]; - digest_buf[ 4] = digest_buf[ 4]; - digest_buf[ 5] = digest_buf[ 5]; - digest_buf[ 6] = digest_buf[ 6]; - digest_buf[ 7] = digest_buf[ 7]; - digest_buf[ 8] = digest_buf[ 8]; - digest_buf[ 9] = digest_buf[ 9]; - digest_buf[10] = digest_buf[10]; - digest_buf[11] = digest_buf[11]; - digest_buf[12] = digest_buf[12]; - digest_buf[13] = digest_buf[13]; - digest_buf[14] = digest_buf[14]; - digest_buf[15] = digest_buf[15]; - - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", - digest_buf[ 0], - digest_buf[ 1], - digest_buf[ 2], - digest_buf[ 3], - digest_buf[ 4], - digest_buf[ 5], - digest_buf[ 6], - digest_buf[ 7], - digest_buf[ 8], - digest_buf[ 9], - digest_buf[10], - digest_buf[11], - digest_buf[12], - digest_buf[13], - digest_buf[14], - digest_buf[15]); - } - else if (hash_type == HASH_TYPE_GOST) - { - snprintf (out_buf, len-1, "%08x%08x%08x%08x%08x%08x%08x%08x", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3], - digest_buf[4], - digest_buf[5], - digest_buf[6], - digest_buf[7]); - } - else if (hash_type == HASH_TYPE_MYSQL) - { - snprintf (out_buf, len-1, "%08x%08x", - digest_buf[0], - digest_buf[1]); - } - else if (hash_type == HASH_TYPE_LOTUS5) - { - snprintf (out_buf, len-1, "%08x%08x%08x%08x", - digest_buf[0], - digest_buf[1], - digest_buf[2], - digest_buf[3]); - } - else if (hash_type == HASH_TYPE_LOTUS6) - { - digest_buf[ 0] = byte_swap_32 (digest_buf[ 0]); - digest_buf[ 1] = byte_swap_32 (digest_buf[ 1]); - digest_buf[ 2] = byte_swap_32 (digest_buf[ 2]); - digest_buf[ 3] = byte_swap_32 (digest_buf[ 3]); - - char buf[16] = { 0 }; - - memcpy (buf + 0, salt.salt_buf, 5); - memcpy (buf + 5, digest_buf, 9); - - buf[3] -= -4; - - base64_encode (int_to_lotus64, (const u8 *) buf, 14, (u8 *) tmp_buf); - - tmp_buf[18] = salt.salt_buf_pc[7]; - tmp_buf[19] = 0; - - snprintf (out_buf, len-1, "(G%s)", tmp_buf); - } - else if (hash_type == HASH_TYPE_LOTUS8) - { - char buf[52] = { 0 }; - - // salt - - memcpy (buf + 0, salt.salt_buf, 16); - - buf[3] -= -4; - - // iteration - - snprintf (buf + 16, 11, "%010i", salt.salt_iter + 1); - - // chars - - buf[26] = salt.salt_buf_pc[0]; - buf[27] = salt.salt_buf_pc[1]; - - // digest - - memcpy (buf + 28, digest_buf, 8); - - base64_encode (int_to_lotus64, (const u8 *) buf, 36, (u8 *) tmp_buf); - - tmp_buf[49] = 0; - - snprintf (out_buf, len-1, "(H%s)", tmp_buf); - } - else if (hash_type == HASH_TYPE_CRC32) - { - snprintf (out_buf, len-1, "%08x", byte_swap_32 (digest_buf[0])); - } - } - - if (salt_type == SALT_TYPE_INTERN) - { - size_t pos = strlen (out_buf); - - out_buf[pos] = data.separator; - - char *ptr = (char *) salt.salt_buf; - - memcpy (out_buf + pos + 1, ptr, salt.salt_len); - - out_buf[pos + 1 + salt.salt_len] = 0; - } -} - -void to_hccap_t (hccap_t *hccap, uint salt_pos, uint digest_pos) -{ - memset (hccap, 0, sizeof (hccap_t)); - - salt_t *salt = &data.salts_buf[salt_pos]; - - memcpy (hccap->essid, salt->salt_buf, salt->salt_len); - - wpa_t *wpas = (wpa_t *) data.esalts_buf; - wpa_t *wpa = &wpas[salt_pos]; - - hccap->keyver = wpa->keyver; - - hccap->eapol_size = wpa->eapol_size; - - if (wpa->keyver != 1) - { - uint eapol_tmp[64] = { 0 }; - - for (uint i = 0; i < 64; i++) - { - eapol_tmp[i] = byte_swap_32 (wpa->eapol[i]); - } - - memcpy (hccap->eapol, eapol_tmp, wpa->eapol_size); - } - else - { - memcpy (hccap->eapol, wpa->eapol, wpa->eapol_size); - } - - memcpy (hccap->mac1, wpa->orig_mac1, 6); - memcpy (hccap->mac2, wpa->orig_mac2, 6); - memcpy (hccap->nonce1, wpa->orig_nonce1, 32); - memcpy (hccap->nonce2, wpa->orig_nonce2, 32); - - char *digests_buf_ptr = (char *) data.digests_buf; - - uint dgst_size = data.dgst_size; - - uint *digest_ptr = (uint *) (digests_buf_ptr + (data.salts_buf[salt_pos].digests_offset * dgst_size) + (digest_pos * dgst_size)); - - if (wpa->keyver != 1) - { - uint digest_tmp[4] = { 0 }; - - digest_tmp[0] = byte_swap_32 (digest_ptr[0]); - digest_tmp[1] = byte_swap_32 (digest_ptr[1]); - digest_tmp[2] = byte_swap_32 (digest_ptr[2]); - digest_tmp[3] = byte_swap_32 (digest_ptr[3]); - - memcpy (hccap->keymic, digest_tmp, 16); - } - else - { - memcpy (hccap->keymic, digest_ptr, 16); - } -} - static void SuspendThreads () { if (data.devices_status != STATUS_RUNNING) return; @@ -9720,10846 +4276,6 @@ tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, hc_device_param_t * return entry; } -/** - * parser - */ - -static uint parse_and_store_salt (char *out, char *in, uint salt_len) -{ - u8 tmp[256] = { 0 }; - - if (salt_len > sizeof (tmp)) - { - return UINT_MAX; - } - - memcpy (tmp, in, salt_len); - - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((salt_len % 2) == 0) - { - u32 new_salt_len = salt_len / 2; - - for (uint i = 0, j = 0; i < new_salt_len; i += 1, j += 2) - { - u8 p0 = tmp[j + 0]; - u8 p1 = tmp[j + 1]; - - tmp[i] = hex_convert (p1) << 0; - tmp[i] |= hex_convert (p0) << 4; - } - - salt_len = new_salt_len; - } - else - { - return UINT_MAX; - } - } - else if (data.opts_type & OPTS_TYPE_ST_BASE64) - { - salt_len = base64_decode (base64_to_int, (const u8 *) in, salt_len, (u8 *) tmp); - } - - memset (tmp + salt_len, 0, sizeof (tmp) - salt_len); - - if (data.opts_type & OPTS_TYPE_ST_UNICODE) - { - if (salt_len < 20) - { - u32 *tmp_uint = (u32 *) tmp; - - tmp_uint[9] = ((tmp_uint[4] >> 8) & 0x00FF0000) | ((tmp_uint[4] >> 16) & 0x000000FF); - tmp_uint[8] = ((tmp_uint[4] << 8) & 0x00FF0000) | ((tmp_uint[4] >> 0) & 0x000000FF); - tmp_uint[7] = ((tmp_uint[3] >> 8) & 0x00FF0000) | ((tmp_uint[3] >> 16) & 0x000000FF); - tmp_uint[6] = ((tmp_uint[3] << 8) & 0x00FF0000) | ((tmp_uint[3] >> 0) & 0x000000FF); - tmp_uint[5] = ((tmp_uint[2] >> 8) & 0x00FF0000) | ((tmp_uint[2] >> 16) & 0x000000FF); - tmp_uint[4] = ((tmp_uint[2] << 8) & 0x00FF0000) | ((tmp_uint[2] >> 0) & 0x000000FF); - tmp_uint[3] = ((tmp_uint[1] >> 8) & 0x00FF0000) | ((tmp_uint[1] >> 16) & 0x000000FF); - tmp_uint[2] = ((tmp_uint[1] << 8) & 0x00FF0000) | ((tmp_uint[1] >> 0) & 0x000000FF); - tmp_uint[1] = ((tmp_uint[0] >> 8) & 0x00FF0000) | ((tmp_uint[0] >> 16) & 0x000000FF); - tmp_uint[0] = ((tmp_uint[0] << 8) & 0x00FF0000) | ((tmp_uint[0] >> 0) & 0x000000FF); - - salt_len = salt_len * 2; - } - else - { - return UINT_MAX; - } - } - - if (data.opts_type & OPTS_TYPE_ST_LOWER) - { - lowercase (tmp, salt_len); - } - - if (data.opts_type & OPTS_TYPE_ST_UPPER) - { - uppercase (tmp, salt_len); - } - - u32 len = salt_len; - - if (data.opts_type & OPTS_TYPE_ST_ADD80) - { - tmp[len++] = 0x80; - } - - if (data.opts_type & OPTS_TYPE_ST_ADD01) - { - tmp[len++] = 0x01; - } - - if (data.opts_type & OPTS_TYPE_ST_GENERATE_LE) - { - u32 *tmp_uint = (uint *) tmp; - - u32 max = len / 4; - - if (len % 4) max++; - - for (u32 i = 0; i < max; i++) - { - tmp_uint[i] = byte_swap_32 (tmp_uint[i]); - } - - // Important: we may need to increase the length of memcpy since - // we don't want to "loose" some swapped bytes (could happen if - // they do not perfectly fit in the 4-byte blocks) - // Memcpy does always copy the bytes in the BE order, but since - // we swapped them, some important bytes could be in positions - // we normally skip with the original len - - if (len % 4) len += 4 - (len % 4); - } - - memcpy (out, tmp, len); - - return (salt_len); -} - -int bcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_3200) || (input_len > DISPLAY_LEN_MAX_3200)) return (PARSER_GLOBAL_LENGTH); - - if ((memcmp (SIGNATURE_BCRYPT1, input_buf, 4)) && (memcmp (SIGNATURE_BCRYPT2, input_buf, 4)) && (memcmp (SIGNATURE_BCRYPT3, input_buf, 4)) && (memcmp (SIGNATURE_BCRYPT4, input_buf, 4))) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - memcpy ((char *) salt->salt_sign, input_buf, 6); - - char *iter_pos = input_buf + 4; - - salt->salt_iter = 1u << atoi (iter_pos); - - char *salt_pos = strchr (iter_pos, '$'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - uint salt_len = 16; - - salt->salt_len = salt_len; - - u8 tmp_buf[100] = { 0 }; - - base64_decode (bf64_to_int, (const u8 *) salt_pos, 22, tmp_buf); - - char *salt_buf_ptr = (char *) salt->salt_buf; - - memcpy (salt_buf_ptr, tmp_buf, 16); - - salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); - salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); - salt->salt_buf[2] = byte_swap_32 (salt->salt_buf[2]); - salt->salt_buf[3] = byte_swap_32 (salt->salt_buf[3]); - - char *hash_pos = salt_pos + 22; - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - base64_decode (bf64_to_int, (const u8 *) hash_pos, 31, tmp_buf); - - memcpy (digest, tmp_buf, 24); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - digest[5] = byte_swap_32 (digest[5]); - - digest[5] &= ~0xffu; // its just 23 not 24 ! - - return (PARSER_OK); -} - -int cisco4_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_5700) || (input_len > DISPLAY_LEN_MAX_5700)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - u8 tmp_buf[100] = { 0 }; - - base64_decode (itoa64_to_int, (const u8 *) input_buf, 43, tmp_buf); - - memcpy (digest, tmp_buf, 32); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - digest[5] = byte_swap_32 (digest[5]); - digest[6] = byte_swap_32 (digest[6]); - digest[7] = byte_swap_32 (digest[7]); - - digest[0] -= SHA256M_A; - digest[1] -= SHA256M_B; - digest[2] -= SHA256M_C; - digest[3] -= SHA256M_D; - digest[4] -= SHA256M_E; - digest[5] -= SHA256M_F; - digest[6] -= SHA256M_G; - digest[7] -= SHA256M_H; - - return (PARSER_OK); -} - -int lm_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_3000) || (input_len > DISPLAY_LEN_MAX_3000)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - - uint tt; - - IP (digest[0], digest[1], tt); - - digest[0] = digest[0]; - digest[1] = digest[1]; - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int arubaos_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_125) || (input_len > DISPLAY_LEN_MAX_125)) return (PARSER_GLOBAL_LENGTH); - - if ((input_buf[8] != '0') || (input_buf[9] != '1')) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *hash_pos = input_buf + 10; - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - uint salt_len = 10; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, input_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int osx1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_122) || (input_len > DISPLAY_LEN_MAX_122)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *hash_pos = input_buf + 8; - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - uint salt_len = 8; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, input_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int osx512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_1722) || (input_len > DISPLAY_LEN_MAX_1722)) return (PARSER_GLOBAL_LENGTH); - - u64 *digest = (u64 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *hash_pos = input_buf + 8; - - digest[0] = hex_to_u64 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u64 ((const u8 *) &hash_pos[ 16]); - digest[2] = hex_to_u64 ((const u8 *) &hash_pos[ 32]); - digest[3] = hex_to_u64 ((const u8 *) &hash_pos[ 48]); - digest[4] = hex_to_u64 ((const u8 *) &hash_pos[ 64]); - digest[5] = hex_to_u64 ((const u8 *) &hash_pos[ 80]); - digest[6] = hex_to_u64 ((const u8 *) &hash_pos[ 96]); - digest[7] = hex_to_u64 ((const u8 *) &hash_pos[112]); - - digest[0] -= SHA512M_A; - digest[1] -= SHA512M_B; - digest[2] -= SHA512M_C; - digest[3] -= SHA512M_D; - digest[4] -= SHA512M_E; - digest[5] -= SHA512M_F; - digest[6] -= SHA512M_G; - digest[7] -= SHA512M_H; - - uint salt_len = 8; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, input_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int osc_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_21H) || (input_len > DISPLAY_LEN_MAX_21H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_21) || (input_len > DISPLAY_LEN_MAX_21)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 32 - 1; - - char *salt_buf = input_buf + 32 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int netscreen_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_22H) || (input_len > DISPLAY_LEN_MAX_22H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_22) || (input_len > DISPLAY_LEN_MAX_22)) return (PARSER_GLOBAL_LENGTH); - } - - // unscramble - - char clean_input_buf[32] = { 0 }; - - char sig[6] = { 'n', 'r', 'c', 's', 't', 'n' }; - int pos[6] = { 0, 6, 12, 17, 23, 29 }; - - for (int i = 0, j = 0, k = 0; i < 30; i++) - { - if (i == pos[j]) - { - if (sig[j] != input_buf[i]) return (PARSER_SIGNATURE_UNMATCHED); - - j++; - } - else - { - clean_input_buf[k] = input_buf[i]; - - k++; - } - } - - // base64 decode - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - u32 a, b, c, d, e, f; - - a = base64_to_int (clean_input_buf[ 0] & 0x7f); - b = base64_to_int (clean_input_buf[ 1] & 0x7f); - c = base64_to_int (clean_input_buf[ 2] & 0x7f); - d = base64_to_int (clean_input_buf[ 3] & 0x7f); - e = base64_to_int (clean_input_buf[ 4] & 0x7f); - f = base64_to_int (clean_input_buf[ 5] & 0x7f); - - digest[0] = (((a << 12) | (b << 6) | (c)) << 16) - | (((d << 12) | (e << 6) | (f)) << 0); - - a = base64_to_int (clean_input_buf[ 6] & 0x7f); - b = base64_to_int (clean_input_buf[ 7] & 0x7f); - c = base64_to_int (clean_input_buf[ 8] & 0x7f); - d = base64_to_int (clean_input_buf[ 9] & 0x7f); - e = base64_to_int (clean_input_buf[10] & 0x7f); - f = base64_to_int (clean_input_buf[11] & 0x7f); - - digest[1] = (((a << 12) | (b << 6) | (c)) << 16) - | (((d << 12) | (e << 6) | (f)) << 0); - - a = base64_to_int (clean_input_buf[12] & 0x7f); - b = base64_to_int (clean_input_buf[13] & 0x7f); - c = base64_to_int (clean_input_buf[14] & 0x7f); - d = base64_to_int (clean_input_buf[15] & 0x7f); - e = base64_to_int (clean_input_buf[16] & 0x7f); - f = base64_to_int (clean_input_buf[17] & 0x7f); - - digest[2] = (((a << 12) | (b << 6) | (c)) << 16) - | (((d << 12) | (e << 6) | (f)) << 0); - - a = base64_to_int (clean_input_buf[18] & 0x7f); - b = base64_to_int (clean_input_buf[19] & 0x7f); - c = base64_to_int (clean_input_buf[20] & 0x7f); - d = base64_to_int (clean_input_buf[21] & 0x7f); - e = base64_to_int (clean_input_buf[22] & 0x7f); - f = base64_to_int (clean_input_buf[23] & 0x7f); - - digest[3] = (((a << 12) | (b << 6) | (c)) << 16) - | (((d << 12) | (e << 6) | (f)) << 0); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - if (input_buf[30] != ':') return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 30 - 1; - - char *salt_buf = input_buf + 30 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - // max. salt length: 55 (max for MD5) - 22 (":Administration Tools:") - 1 (0x80) = 32 - // 32 - 4 bytes (to fit w0lr for all attack modes) = 28 - - if (salt_len > 28) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - memcpy (salt_buf_ptr + salt_len, ":Administration Tools:", 22); - - salt->salt_len += 22; - - return (PARSER_OK); -} - -int smf_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_121H) || (input_len > DISPLAY_LEN_MAX_121H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_121) || (input_len > DISPLAY_LEN_MAX_121)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 40 - 1; - - char *salt_buf = input_buf + 40 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int dcc2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_2100H) || (input_len > DISPLAY_LEN_MAX_2100H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_2100) || (input_len > DISPLAY_LEN_MAX_2100)) return (PARSER_GLOBAL_LENGTH); - } - - if (memcmp (SIGNATURE_DCC2, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - char *iter_pos = input_buf + 6; - - salt_t *salt = hash_buf->salt; - - uint iter = atoi (iter_pos); - - if (iter < 1) - { - iter = ROUNDS_DCC2; - } - - salt->salt_iter = iter - 1; - - char *salt_pos = strchr (iter_pos, '#'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - char *digest_pos = strchr (salt_pos, '#'); - - if (digest_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - digest_pos++; - - uint salt_len = digest_pos - salt_pos - 1; - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &digest_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &digest_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &digest_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &digest_pos[24]); - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int wpa_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - wpa_t *wpa = (wpa_t *) hash_buf->esalt; - - hccap_t in; - - memcpy (&in, input_buf, input_len); - - if (in.eapol_size < 1 || in.eapol_size > 255) return (PARSER_HCCAP_EAPOL_SIZE); - - memcpy (digest, in.keymic, 16); - - /* - http://www.one-net.eu/jsw/j_sec/m_ptype.html - The phrase "Pairwise key expansion" - Access Point Address (referred to as Authenticator Address AA) - Supplicant Address (referred to as Supplicant Address SA) - Access Point Nonce (referred to as Authenticator Anonce) - Wireless Device Nonce (referred to as Supplicant Nonce Snonce) - */ - - uint salt_len = strlen (in.essid); - - if (salt_len > 36) - { - log_info ("WARNING: The ESSID length is too long, the hccap file may be invalid or corrupted"); - - return (PARSER_SALT_LENGTH); - } - - memcpy (salt->salt_buf, in.essid, salt_len); - - salt->salt_len = salt_len; - - salt->salt_iter = ROUNDS_WPA2 - 1; - - unsigned char *pke_ptr = (unsigned char *) wpa->pke; - - memcpy (pke_ptr, "Pairwise key expansion", 23); - - if (memcmp (in.mac1, in.mac2, 6) < 0) - { - memcpy (pke_ptr + 23, in.mac1, 6); - memcpy (pke_ptr + 29, in.mac2, 6); - } - else - { - memcpy (pke_ptr + 23, in.mac2, 6); - memcpy (pke_ptr + 29, in.mac1, 6); - } - - if (memcmp (in.nonce1, in.nonce2, 32) < 0) - { - memcpy (pke_ptr + 35, in.nonce1, 32); - memcpy (pke_ptr + 67, in.nonce2, 32); - } - else - { - memcpy (pke_ptr + 35, in.nonce2, 32); - memcpy (pke_ptr + 67, in.nonce1, 32); - } - - for (int i = 0; i < 25; i++) - { - wpa->pke[i] = byte_swap_32 (wpa->pke[i]); - } - - memcpy (wpa->orig_mac1, in.mac1, 6); - memcpy (wpa->orig_mac2, in.mac2, 6); - memcpy (wpa->orig_nonce1, in.nonce1, 32); - memcpy (wpa->orig_nonce2, in.nonce2, 32); - - wpa->keyver = in.keyver; - - if (wpa->keyver > 255) - { - log_info ("ATTENTION!"); - log_info (" The WPA/WPA2 key version in your .hccap file is invalid!"); - log_info (" This could be due to a recent aircrack-ng bug."); - log_info (" The key version was automatically reset to a reasonable value."); - log_info (""); - - wpa->keyver &= 0xff; - } - - wpa->eapol_size = in.eapol_size; - - unsigned char *eapol_ptr = (unsigned char *) wpa->eapol; - - memcpy (eapol_ptr, in.eapol, wpa->eapol_size); - - memset (eapol_ptr + wpa->eapol_size, 0, 256 - wpa->eapol_size); - - eapol_ptr[wpa->eapol_size] = (unsigned char) 0x80; - - if (wpa->keyver == 1) - { - // nothing to do - } - else - { - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - for (int i = 0; i < 64; i++) - { - wpa->eapol[i] = byte_swap_32 (wpa->eapol[i]); - } - } - - uint32_t *p0 = (uint32_t *) in.essid; - uint32_t c0 = 0; - uint32_t c1 = 0; - - for (uint i = 0; i < sizeof (in.essid) / sizeof (uint32_t); i++) c0 ^= *p0++; - for (uint i = 0; i < sizeof (wpa->pke) / sizeof (wpa->pke[0]); i++) c1 ^= wpa->pke[i]; - - salt->salt_buf[10] = c0; - salt->salt_buf[11] = c1; - - return (PARSER_OK); -} - -int psafe2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - if (input_len == 0) - { - log_error ("Password Safe v2 container not specified"); - - exit (-1); - } - - FILE *fp = fopen (input_buf, "rb"); - - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } - - psafe2_hdr buf; - - memset (&buf, 0, sizeof (psafe2_hdr)); - - int n = fread (&buf, sizeof (psafe2_hdr), 1, fp); - - fclose (fp); - - if (n != 1) return (PARSER_PSAFE2_FILE_SIZE); - - salt->salt_buf[0] = buf.random[0]; - salt->salt_buf[1] = buf.random[1]; - - salt->salt_len = 8; - salt->salt_iter = 1000; - - digest[0] = byte_swap_32 (buf.hash[0]); - digest[1] = byte_swap_32 (buf.hash[1]); - digest[2] = byte_swap_32 (buf.hash[2]); - digest[3] = byte_swap_32 (buf.hash[3]); - digest[4] = byte_swap_32 (buf.hash[4]); - - return (PARSER_OK); -} - -int psafe3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - if (input_len == 0) - { - log_error (".psafe3 not specified"); - - exit (-1); - } - - FILE *fp = fopen (input_buf, "rb"); - - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } - - psafe3_t in; - - int n = fread (&in, sizeof (psafe3_t), 1, fp); - - fclose (fp); - - data.hashfile = input_buf; // we will need this in case it gets cracked - - if (memcmp (SIGNATURE_PSAFE3, in.signature, 4)) return (PARSER_SIGNATURE_UNMATCHED); - - if (n != 1) return (PARSER_PSAFE3_FILE_SIZE); - - salt->salt_iter = in.iterations + 1; - - salt->salt_buf[0] = in.salt_buf[0]; - salt->salt_buf[1] = in.salt_buf[1]; - salt->salt_buf[2] = in.salt_buf[2]; - salt->salt_buf[3] = in.salt_buf[3]; - salt->salt_buf[4] = in.salt_buf[4]; - salt->salt_buf[5] = in.salt_buf[5]; - salt->salt_buf[6] = in.salt_buf[6]; - salt->salt_buf[7] = in.salt_buf[7]; - - salt->salt_len = 32; - - digest[0] = in.hash_buf[0]; - digest[1] = in.hash_buf[1]; - digest[2] = in.hash_buf[2]; - digest[3] = in.hash_buf[3]; - digest[4] = in.hash_buf[4]; - digest[5] = in.hash_buf[5]; - digest[6] = in.hash_buf[6]; - digest[7] = in.hash_buf[7]; - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - digest[5] = byte_swap_32 (digest[5]); - digest[6] = byte_swap_32 (digest[6]); - digest[7] = byte_swap_32 (digest[7]); - - return (PARSER_OK); -} - -int phpass_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_400) || (input_len > DISPLAY_LEN_MAX_400)) return (PARSER_GLOBAL_LENGTH); - - if ((memcmp (SIGNATURE_PHPASS1, input_buf, 3)) && (memcmp (SIGNATURE_PHPASS2, input_buf, 3))) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *iter_pos = input_buf + 3; - - uint salt_iter = 1u << itoa64_to_int (iter_pos[0]); - - if (salt_iter > 0x80000000) return (PARSER_SALT_ITERATION); - - memcpy ((char *) salt->salt_sign, input_buf, 4); - - salt->salt_iter = salt_iter; - - char *salt_pos = iter_pos + 1; - - uint salt_len = 8; - - memcpy ((char *) salt->salt_buf, salt_pos, salt_len); - - salt->salt_len = salt_len; - - char *hash_pos = salt_pos + salt_len; - - phpass_decode ((unsigned char *) digest, (unsigned char *) hash_pos); - - return (PARSER_OK); -} - -int md5crypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (input_len < DISPLAY_LEN_MIN_500) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_MD5CRYPT, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_pos = input_buf + 3; - - uint iterations_len = 0; - - if (memcmp (salt_pos, "rounds=", 7) == 0) - { - salt_pos += 7; - - for (iterations_len = 0; salt_pos[0] >= '0' && salt_pos[0] <= '9' && iterations_len < 7; iterations_len++, salt_pos += 1) continue; - - if (iterations_len == 0 ) return (PARSER_SALT_ITERATION); - if (salt_pos[0] != '$') return (PARSER_SIGNATURE_UNMATCHED); - - salt_pos[0] = 0x0; - - salt->salt_iter = atoi (salt_pos - iterations_len); - - salt_pos += 1; - - iterations_len += 8; - } - else - { - salt->salt_iter = ROUNDS_MD5CRYPT; - } - - if (input_len > (DISPLAY_LEN_MAX_500 + iterations_len)) return (PARSER_GLOBAL_LENGTH); - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - if (salt_len > 8) return (PARSER_SALT_LENGTH); - - memcpy ((char *) salt->salt_buf, salt_pos, salt_len); - - salt->salt_len = salt_len; - - hash_pos++; - - uint hash_len = input_len - 3 - iterations_len - salt_len - 1; - - if (hash_len != 22) return (PARSER_HASH_LENGTH); - - md5crypt_decode ((unsigned char *) digest, (unsigned char *) hash_pos); - - return (PARSER_OK); -} - -int md5apr1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (memcmp (SIGNATURE_MD5APR1, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_pos = input_buf + 6; - - uint iterations_len = 0; - - if (memcmp (salt_pos, "rounds=", 7) == 0) - { - salt_pos += 7; - - for (iterations_len = 0; salt_pos[0] >= '0' && salt_pos[0] <= '9' && iterations_len < 7; iterations_len++, salt_pos += 1) continue; - - if (iterations_len == 0 ) return (PARSER_SALT_ITERATION); - if (salt_pos[0] != '$') return (PARSER_SIGNATURE_UNMATCHED); - - salt_pos[0] = 0x0; - - salt->salt_iter = atoi (salt_pos - iterations_len); - - salt_pos += 1; - - iterations_len += 8; - } - else - { - salt->salt_iter = ROUNDS_MD5CRYPT; - } - - if ((input_len < DISPLAY_LEN_MIN_1600) || (input_len > DISPLAY_LEN_MAX_1600 + iterations_len)) return (PARSER_GLOBAL_LENGTH); - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - if (salt_len > 8) return (PARSER_SALT_LENGTH); - - memcpy ((char *) salt->salt_buf, salt_pos, salt_len); - - salt->salt_len = salt_len; - - hash_pos++; - - md5crypt_decode ((unsigned char *) digest, (unsigned char *) hash_pos); - - return (PARSER_OK); -} - -int episerver_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_141) || (input_len > DISPLAY_LEN_MAX_141)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_EPISERVER, input_buf, 14)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_pos = input_buf + 14; - - char *hash_pos = strchr (salt_pos, '*'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - hash_pos++; - - uint salt_len = hash_pos - salt_pos - 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - u8 tmp_buf[100] = { 0 }; - - base64_decode (base64_to_int, (const u8 *) hash_pos, 27, tmp_buf); - - memcpy (digest, tmp_buf, 20); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - return (PARSER_OK); -} - -int descrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_1500) || (input_len > DISPLAY_LEN_MAX_1500)) return (PARSER_GLOBAL_LENGTH); - - unsigned char c12 = itoa64_to_int (input_buf[12]); - - if (c12 & 3) return (PARSER_HASH_VALUE); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - // for ascii_digest - salt->salt_sign[0] = input_buf[0]; - salt->salt_sign[1] = input_buf[1]; - - salt->salt_buf[0] = itoa64_to_int (input_buf[0]) - | itoa64_to_int (input_buf[1]) << 6; - - salt->salt_len = 2; - - u8 tmp_buf[100] = { 0 }; - - base64_decode (itoa64_to_int, (const u8 *) input_buf + 2, 11, tmp_buf); - - memcpy (digest, tmp_buf, 8); - - uint tt; - - IP (digest[0], digest[1], tt); - - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int md4_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_900) || (input_len > DISPLAY_LEN_MAX_900)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD4M_A; - digest[1] -= MD4M_B; - digest[2] -= MD4M_C; - digest[3] -= MD4M_D; - - return (PARSER_OK); -} - -int md4s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_910H) || (input_len > DISPLAY_LEN_MAX_910H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_910) || (input_len > DISPLAY_LEN_MAX_910)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD4M_A; - digest[1] -= MD4M_B; - digest[2] -= MD4M_C; - digest[3] -= MD4M_D; - - if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 32 - 1; - - char *salt_buf = input_buf + 32 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_0) || (input_len > DISPLAY_LEN_MAX_0)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - return (PARSER_OK); -} - -int md5half_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_5100) || (input_len > DISPLAY_LEN_MAX_5100)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[8]); - digest[2] = 0; - digest[3] = 0; - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - - return (PARSER_OK); -} - -int md5s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_10H) || (input_len > DISPLAY_LEN_MAX_10H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_10) || (input_len > DISPLAY_LEN_MAX_10)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 32 - 1; - - char *salt_buf = input_buf + 32 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int md5pix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_2400) || (input_len > DISPLAY_LEN_MAX_2400)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = itoa64_to_int (input_buf[ 0]) << 0 - | itoa64_to_int (input_buf[ 1]) << 6 - | itoa64_to_int (input_buf[ 2]) << 12 - | itoa64_to_int (input_buf[ 3]) << 18; - digest[1] = itoa64_to_int (input_buf[ 4]) << 0 - | itoa64_to_int (input_buf[ 5]) << 6 - | itoa64_to_int (input_buf[ 6]) << 12 - | itoa64_to_int (input_buf[ 7]) << 18; - digest[2] = itoa64_to_int (input_buf[ 8]) << 0 - | itoa64_to_int (input_buf[ 9]) << 6 - | itoa64_to_int (input_buf[10]) << 12 - | itoa64_to_int (input_buf[11]) << 18; - digest[3] = itoa64_to_int (input_buf[12]) << 0 - | itoa64_to_int (input_buf[13]) << 6 - | itoa64_to_int (input_buf[14]) << 12 - | itoa64_to_int (input_buf[15]) << 18; - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - digest[0] &= 0x00ffffff; - digest[1] &= 0x00ffffff; - digest[2] &= 0x00ffffff; - digest[3] &= 0x00ffffff; - - return (PARSER_OK); -} - -int md5asa_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_2410H) || (input_len > DISPLAY_LEN_MAX_2410H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_2410) || (input_len > DISPLAY_LEN_MAX_2410)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = itoa64_to_int (input_buf[ 0]) << 0 - | itoa64_to_int (input_buf[ 1]) << 6 - | itoa64_to_int (input_buf[ 2]) << 12 - | itoa64_to_int (input_buf[ 3]) << 18; - digest[1] = itoa64_to_int (input_buf[ 4]) << 0 - | itoa64_to_int (input_buf[ 5]) << 6 - | itoa64_to_int (input_buf[ 6]) << 12 - | itoa64_to_int (input_buf[ 7]) << 18; - digest[2] = itoa64_to_int (input_buf[ 8]) << 0 - | itoa64_to_int (input_buf[ 9]) << 6 - | itoa64_to_int (input_buf[10]) << 12 - | itoa64_to_int (input_buf[11]) << 18; - digest[3] = itoa64_to_int (input_buf[12]) << 0 - | itoa64_to_int (input_buf[13]) << 6 - | itoa64_to_int (input_buf[14]) << 12 - | itoa64_to_int (input_buf[15]) << 18; - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - digest[0] &= 0x00ffffff; - digest[1] &= 0x00ffffff; - digest[2] &= 0x00ffffff; - digest[3] &= 0x00ffffff; - - if (input_buf[16] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 16 - 1; - - char *salt_buf = input_buf + 16 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -static void transform_netntlmv1_key (const u8 *nthash, u8 *key) -{ - key[0] = (nthash[0] >> 0); - key[1] = (nthash[0] << 7) | (nthash[1] >> 1); - key[2] = (nthash[1] << 6) | (nthash[2] >> 2); - key[3] = (nthash[2] << 5) | (nthash[3] >> 3); - key[4] = (nthash[3] << 4) | (nthash[4] >> 4); - key[5] = (nthash[4] << 3) | (nthash[5] >> 5); - key[6] = (nthash[5] << 2) | (nthash[6] >> 6); - key[7] = (nthash[6] << 1); - - key[0] |= 0x01; - key[1] |= 0x01; - key[2] |= 0x01; - key[3] |= 0x01; - key[4] |= 0x01; - key[5] |= 0x01; - key[6] |= 0x01; - key[7] |= 0x01; -} - -int netntlmv1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_5500) || (input_len > DISPLAY_LEN_MAX_5500)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - netntlm_t *netntlm = (netntlm_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *user_pos = input_buf; - - char *unused_pos = strchr (user_pos, ':'); - - if (unused_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint user_len = unused_pos - user_pos; - - if (user_len > 60) return (PARSER_SALT_LENGTH); - - unused_pos++; - - char *domain_pos = strchr (unused_pos, ':'); - - if (domain_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint unused_len = domain_pos - unused_pos; - - if (unused_len != 0) return (PARSER_SALT_LENGTH); - - domain_pos++; - - char *srvchall_pos = strchr (domain_pos, ':'); - - if (srvchall_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint domain_len = srvchall_pos - domain_pos; - - if (domain_len > 45) return (PARSER_SALT_LENGTH); - - srvchall_pos++; - - char *hash_pos = strchr (srvchall_pos, ':'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint srvchall_len = hash_pos - srvchall_pos; - - // if (srvchall_len != 0) return (PARSER_SALT_LENGTH); - - hash_pos++; - - char *clichall_pos = strchr (hash_pos, ':'); - - if (clichall_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint hash_len = clichall_pos - hash_pos; - - if (hash_len != 48) return (PARSER_HASH_LENGTH); - - clichall_pos++; - - uint clichall_len = input_len - user_len - 1 - unused_len - 1 - domain_len - 1 - srvchall_len - 1 - hash_len - 1; - - if (clichall_len != 16) return (PARSER_SALT_LENGTH); - - /** - * store some data for later use - */ - - netntlm->user_len = user_len * 2; - netntlm->domain_len = domain_len * 2; - netntlm->srvchall_len = srvchall_len / 2; - netntlm->clichall_len = clichall_len / 2; - - char *userdomain_ptr = (char *) netntlm->userdomain_buf; - char *chall_ptr = (char *) netntlm->chall_buf; - - /** - * handle username and domainname - */ - - for (uint i = 0; i < user_len; i++) - { - *userdomain_ptr++ = user_pos[i]; - *userdomain_ptr++ = 0; - } - - for (uint i = 0; i < domain_len; i++) - { - *userdomain_ptr++ = domain_pos[i]; - *userdomain_ptr++ = 0; - } - - /** - * handle server challenge encoding - */ - - for (uint i = 0; i < srvchall_len; i += 2) - { - const char p0 = srvchall_pos[i + 0]; - const char p1 = srvchall_pos[i + 1]; - - *chall_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - /** - * handle client challenge encoding - */ - - for (uint i = 0; i < clichall_len; i += 2) - { - const char p0 = clichall_pos[i + 0]; - const char p1 = clichall_pos[i + 1]; - - *chall_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - /** - * store data - */ - - char *salt_buf_ptr = (char *) salt->salt_buf; - - uint salt_len = parse_and_store_salt (salt_buf_ptr, clichall_pos, clichall_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - /* special case, last 8 byte do not need to be checked since they are brute-forced next */ - - uint digest_tmp[2] = { 0 }; - - digest_tmp[0] = hex_to_u32 ((const u8 *) &hash_pos[32]); - digest_tmp[1] = hex_to_u32 ((const u8 *) &hash_pos[40]); - - digest_tmp[0] = byte_swap_32 (digest_tmp[0]); - digest_tmp[1] = byte_swap_32 (digest_tmp[1]); - - /* special case 2: ESS */ - - if (srvchall_len == 48) - { - if ((netntlm->chall_buf[2] == 0) && (netntlm->chall_buf[3] == 0) && (netntlm->chall_buf[4] == 0) && (netntlm->chall_buf[5] == 0)) - { - uint w[16] = { 0 }; - - w[ 0] = netntlm->chall_buf[6]; - w[ 1] = netntlm->chall_buf[7]; - w[ 2] = netntlm->chall_buf[0]; - w[ 3] = netntlm->chall_buf[1]; - w[ 4] = 0x80; - w[14] = 16 * 8; - - uint dgst[4] = { 0 }; - - dgst[0] = MD5M_A; - dgst[1] = MD5M_B; - dgst[2] = MD5M_C; - dgst[3] = MD5M_D; - - md5_64 (w, dgst); - - salt->salt_buf[0] = dgst[0]; - salt->salt_buf[1] = dgst[1]; - } - } - - /* precompute netntlmv1 exploit start */ - - for (uint i = 0; i < 0x10000; i++) - { - uint key_md4[2] = { i, 0 }; - uint key_des[2] = { 0, 0 }; - - transform_netntlmv1_key ((u8 *) key_md4, (u8 *) key_des); - - uint Kc[16] = { 0 }; - uint Kd[16] = { 0 }; - - _des_keysetup (key_des, Kc, Kd, c_skb); - - uint data3[2] = { salt->salt_buf[0], salt->salt_buf[1] }; - - _des_encrypt (data3, Kc, Kd, c_SPtrans); - - if (data3[0] != digest_tmp[0]) continue; - if (data3[1] != digest_tmp[1]) continue; - - salt->salt_buf[2] = i; - - salt->salt_len = 24; - - break; - } - - salt->salt_buf_pc[0] = digest_tmp[0]; - salt->salt_buf_pc[1] = digest_tmp[1]; - - /* precompute netntlmv1 exploit stop */ - - u32 tt; - - IP (digest[0], digest[1], tt); - IP (digest[2], digest[3], tt); - - digest[0] = rotr32 (digest[0], 29); - digest[1] = rotr32 (digest[1], 29); - digest[2] = rotr32 (digest[2], 29); - digest[3] = rotr32 (digest[3], 29); - - IP (salt->salt_buf[0], salt->salt_buf[1], tt); - - salt->salt_buf[0] = rotl32 (salt->salt_buf[0], 3); - salt->salt_buf[1] = rotl32 (salt->salt_buf[1], 3); - - return (PARSER_OK); -} - -int netntlmv2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_5600) || (input_len > DISPLAY_LEN_MAX_5600)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - netntlm_t *netntlm = (netntlm_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *user_pos = input_buf; - - char *unused_pos = strchr (user_pos, ':'); - - if (unused_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint user_len = unused_pos - user_pos; - - if (user_len > 60) return (PARSER_SALT_LENGTH); - - unused_pos++; - - char *domain_pos = strchr (unused_pos, ':'); - - if (domain_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint unused_len = domain_pos - unused_pos; - - if (unused_len != 0) return (PARSER_SALT_LENGTH); - - domain_pos++; - - char *srvchall_pos = strchr (domain_pos, ':'); - - if (srvchall_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint domain_len = srvchall_pos - domain_pos; - - if (domain_len > 45) return (PARSER_SALT_LENGTH); - - srvchall_pos++; - - char *hash_pos = strchr (srvchall_pos, ':'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint srvchall_len = hash_pos - srvchall_pos; - - if (srvchall_len != 16) return (PARSER_SALT_LENGTH); - - hash_pos++; - - char *clichall_pos = strchr (hash_pos, ':'); - - if (clichall_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint hash_len = clichall_pos - hash_pos; - - if (hash_len != 32) return (PARSER_HASH_LENGTH); - - clichall_pos++; - - uint clichall_len = input_len - user_len - 1 - unused_len - 1 - domain_len - 1 - srvchall_len - 1 - hash_len - 1; - - if (clichall_len > 1024) return (PARSER_SALT_LENGTH); - - if (clichall_len % 2) return (PARSER_SALT_VALUE); - - /** - * store some data for later use - */ - - netntlm->user_len = user_len * 2; - netntlm->domain_len = domain_len * 2; - netntlm->srvchall_len = srvchall_len / 2; - netntlm->clichall_len = clichall_len / 2; - - char *userdomain_ptr = (char *) netntlm->userdomain_buf; - char *chall_ptr = (char *) netntlm->chall_buf; - - /** - * handle username and domainname - */ - - for (uint i = 0; i < user_len; i++) - { - *userdomain_ptr++ = toupper (user_pos[i]); - *userdomain_ptr++ = 0; - } - - for (uint i = 0; i < domain_len; i++) - { - *userdomain_ptr++ = domain_pos[i]; - *userdomain_ptr++ = 0; - } - - *userdomain_ptr++ = 0x80; - - /** - * handle server challenge encoding - */ - - for (uint i = 0; i < srvchall_len; i += 2) - { - const char p0 = srvchall_pos[i + 0]; - const char p1 = srvchall_pos[i + 1]; - - *chall_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - /** - * handle client challenge encoding - */ - - for (uint i = 0; i < clichall_len; i += 2) - { - const char p0 = clichall_pos[i + 0]; - const char p1 = clichall_pos[i + 1]; - - *chall_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - *chall_ptr++ = 0x80; - - /** - * handle hash itself - */ - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - /** - * reuse challange data as salt_buf, its the buffer that is most likely unique - */ - - salt->salt_buf[0] = 0; - salt->salt_buf[1] = 0; - salt->salt_buf[2] = 0; - salt->salt_buf[3] = 0; - salt->salt_buf[4] = 0; - salt->salt_buf[5] = 0; - salt->salt_buf[6] = 0; - salt->salt_buf[7] = 0; - - uint *uptr; - - uptr = (uint *) netntlm->userdomain_buf; - - for (uint i = 0; i < 16; i += 16) - { - md5_64 (uptr, salt->salt_buf); - } - - uptr = (uint *) netntlm->chall_buf; - - for (uint i = 0; i < 256; i += 16) - { - md5_64 (uptr, salt->salt_buf); - } - - salt->salt_len = 16; - - return (PARSER_OK); -} - -int joomla_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_11H) || (input_len > DISPLAY_LEN_MAX_11H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_11) || (input_len > DISPLAY_LEN_MAX_11)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 32 - 1; - - char *salt_buf = input_buf + 32 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int postgresql_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_12H) || (input_len > DISPLAY_LEN_MAX_12H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_12) || (input_len > DISPLAY_LEN_MAX_12)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 32 - 1; - - char *salt_buf = input_buf + 32 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int md5md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_2600) || (input_len > DISPLAY_LEN_MAX_2600)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - /** - * This is a virtual salt. While the algorithm is basically not salted - * we can exploit the salt buffer to set the 0x80 and the w[14] value. - * This way we can save a special md5md5 kernel and reuse the one from vbull. - */ - - char *salt_buf_ptr = (char *) salt->salt_buf; - - uint salt_len = parse_and_store_salt (salt_buf_ptr, (char *) "", 0); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int vb3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_2611H) || (input_len > DISPLAY_LEN_MAX_2611H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_2611) || (input_len > DISPLAY_LEN_MAX_2611)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 32 - 1; - - char *salt_buf = input_buf + 32 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int vb30_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_2711H) || (input_len > DISPLAY_LEN_MAX_2711H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_2711) || (input_len > DISPLAY_LEN_MAX_2711)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 32 - 1; - - char *salt_buf = input_buf + 32 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int dcc_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_1100H) || (input_len > DISPLAY_LEN_MAX_1100H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_1100) || (input_len > DISPLAY_LEN_MAX_1100)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD4M_A; - digest[1] -= MD4M_B; - digest[2] -= MD4M_C; - digest[3] -= MD4M_D; - - if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 32 - 1; - - char *salt_buf = input_buf + 32 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int ipb2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_2811H) || (input_len > DISPLAY_LEN_MAX_2811H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_2811) || (input_len > DISPLAY_LEN_MAX_2811)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 32 - 1; - - char *salt_buf = input_buf + 32 + 1; - - uint salt_pc_block[16] = { 0 }; - - char *salt_pc_block_ptr = (char *) salt_pc_block; - - salt_len = parse_and_store_salt (salt_pc_block_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt_pc_block_ptr[salt_len] = (unsigned char) 0x80; - - salt_pc_block[14] = salt_len * 8; - - uint salt_pc_digest[4] = { MD5M_A, MD5M_B, MD5M_C, MD5M_D }; - - md5_64 (salt_pc_block, salt_pc_digest); - - salt_pc_digest[0] = byte_swap_32 (salt_pc_digest[0]); - salt_pc_digest[1] = byte_swap_32 (salt_pc_digest[1]); - salt_pc_digest[2] = byte_swap_32 (salt_pc_digest[2]); - salt_pc_digest[3] = byte_swap_32 (salt_pc_digest[3]); - - u8 *salt_buf_ptr = (u8 *) salt->salt_buf; - - memcpy (salt_buf_ptr, salt_buf, salt_len); - - u8 *salt_buf_pc_ptr = (u8 *) salt->salt_buf_pc; - - bin_to_hex_lower (salt_pc_digest[0], salt_buf_pc_ptr + 0); - bin_to_hex_lower (salt_pc_digest[1], salt_buf_pc_ptr + 8); - bin_to_hex_lower (salt_pc_digest[2], salt_buf_pc_ptr + 16); - bin_to_hex_lower (salt_pc_digest[3], salt_buf_pc_ptr + 24); - - salt->salt_len = 32; // changed, was salt_len before -- was a bug? 32 should be correct - - return (PARSER_OK); -} - -int sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_100) || (input_len > DISPLAY_LEN_MAX_100)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - return (PARSER_OK); -} - -int sha1axcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_13300) || (input_len > DISPLAY_LEN_MAX_13300)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_AXCRYPT_SHA1, input_buf, 13)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - input_buf += 14; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = 0; - - return (PARSER_OK); -} - -int sha1s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_110H) || (input_len > DISPLAY_LEN_MAX_110H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_110) || (input_len > DISPLAY_LEN_MAX_110)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 40 - 1; - - char *salt_buf = input_buf + 40 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int pstoken_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_13500) || (input_len > DISPLAY_LEN_MAX_13500)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pstoken_t *pstoken = (pstoken_t *) hash_buf->esalt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - - if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 40 - 1; - - char *salt_buf = input_buf + 40 + 1; - - if (salt_len == UINT_MAX || salt_len % 2 != 0) return (PARSER_SALT_LENGTH); - - u8 *pstoken_ptr = (u8 *) pstoken->salt_buf; - - for (uint i = 0, j = 0; i < salt_len; i += 2, j += 1) - { - pstoken_ptr[j] = hex_to_u8 ((const u8 *) &salt_buf[i]); - } - - pstoken->salt_len = salt_len / 2; - - /* some fake salt for the sorting mechanisms */ - - salt->salt_buf[0] = pstoken->salt_buf[0]; - salt->salt_buf[1] = pstoken->salt_buf[1]; - salt->salt_buf[2] = pstoken->salt_buf[2]; - salt->salt_buf[3] = pstoken->salt_buf[3]; - salt->salt_buf[4] = pstoken->salt_buf[4]; - salt->salt_buf[5] = pstoken->salt_buf[5]; - salt->salt_buf[6] = pstoken->salt_buf[6]; - salt->salt_buf[7] = pstoken->salt_buf[7]; - - salt->salt_len = 32; - - /* we need to check if we can precompute some of the data -- - this is possible since the scheme is badly designed */ - - pstoken->pc_digest[0] = SHA1M_A; - pstoken->pc_digest[1] = SHA1M_B; - pstoken->pc_digest[2] = SHA1M_C; - pstoken->pc_digest[3] = SHA1M_D; - pstoken->pc_digest[4] = SHA1M_E; - - pstoken->pc_offset = 0; - - for (int i = 0; i < (int) pstoken->salt_len - 63; i += 64) - { - uint w[16]; - - w[ 0] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 0]); - w[ 1] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 1]); - w[ 2] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 2]); - w[ 3] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 3]); - w[ 4] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 4]); - w[ 5] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 5]); - w[ 6] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 6]); - w[ 7] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 7]); - w[ 8] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 8]); - w[ 9] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 9]); - w[10] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 10]); - w[11] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 11]); - w[12] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 12]); - w[13] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 13]); - w[14] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 14]); - w[15] = byte_swap_32 (pstoken->salt_buf[pstoken->pc_offset + 15]); - - sha1_64 (w, pstoken->pc_digest); - - pstoken->pc_offset += 16; - } - - return (PARSER_OK); -} - -int sha1b64_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_101) || (input_len > DISPLAY_LEN_MAX_101)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SHA1B64, input_buf, 5)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - u8 tmp_buf[100] = { 0 }; - - base64_decode (base64_to_int, (const u8 *) input_buf + 5, input_len - 5, tmp_buf); - - memcpy (digest, tmp_buf, 20); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - return (PARSER_OK); -} - -int sha1b64s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_111) || (input_len > DISPLAY_LEN_MAX_111)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SSHA1B64_lower, input_buf, 6) && memcmp (SIGNATURE_SSHA1B64_upper, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - u8 tmp_buf[100] = { 0 }; - - int tmp_len = base64_decode (base64_to_int, (const u8 *) input_buf + 6, input_len - 6, tmp_buf); - - if (tmp_len < 20) return (PARSER_HASH_LENGTH); - - memcpy (digest, tmp_buf, 20); - - int salt_len = tmp_len - 20; - - if (salt_len < 0) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - memcpy (salt->salt_buf, tmp_buf + 20, salt->salt_len); - - if (data.opts_type & OPTS_TYPE_ST_ADD80) - { - char *ptr = (char *) salt->salt_buf; - - ptr[salt->salt_len] = 0x80; - } - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - return (PARSER_OK); -} - -int mssql2000_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_131) || (input_len > DISPLAY_LEN_MAX_131)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_MSSQL, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_buf = input_buf + 6; - - uint salt_len = 8; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - char *hash_pos = input_buf + 6 + 8 + 40; - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - return (PARSER_OK); -} - -int mssql2005_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_132) || (input_len > DISPLAY_LEN_MAX_132)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_MSSQL, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_buf = input_buf + 6; - - uint salt_len = 8; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - char *hash_pos = input_buf + 6 + 8; - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - return (PARSER_OK); -} - -int mssql2012_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_1731) || (input_len > DISPLAY_LEN_MAX_1731)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_MSSQL2012, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - u64 *digest = (u64 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_buf = input_buf + 6; - - uint salt_len = 8; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - char *hash_pos = input_buf + 6 + 8; - - digest[0] = hex_to_u64 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u64 ((const u8 *) &hash_pos[ 16]); - digest[2] = hex_to_u64 ((const u8 *) &hash_pos[ 32]); - digest[3] = hex_to_u64 ((const u8 *) &hash_pos[ 48]); - digest[4] = hex_to_u64 ((const u8 *) &hash_pos[ 64]); - digest[5] = hex_to_u64 ((const u8 *) &hash_pos[ 80]); - digest[6] = hex_to_u64 ((const u8 *) &hash_pos[ 96]); - digest[7] = hex_to_u64 ((const u8 *) &hash_pos[112]); - - digest[0] -= SHA512M_A; - digest[1] -= SHA512M_B; - digest[2] -= SHA512M_C; - digest[3] -= SHA512M_D; - digest[4] -= SHA512M_E; - digest[5] -= SHA512M_F; - digest[6] -= SHA512M_G; - digest[7] -= SHA512M_H; - - return (PARSER_OK); -} - -int oracleh_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_3100H) || (input_len > DISPLAY_LEN_MAX_3100H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_3100) || (input_len > DISPLAY_LEN_MAX_3100)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = 0; - digest[3] = 0; - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - - if (input_buf[16] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 16 - 1; - - char *salt_buf = input_buf + 16 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int oracles_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_112) || (input_len > DISPLAY_LEN_MAX_112)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 40 - 1; - - char *salt_buf = input_buf + 40 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int oraclet_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_12300) || (input_len > DISPLAY_LEN_MAX_12300)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *hash_pos = input_buf; - - digest[ 0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[ 1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[ 2] = hex_to_u32 ((const u8 *) &hash_pos[ 16]); - digest[ 3] = hex_to_u32 ((const u8 *) &hash_pos[ 24]); - digest[ 4] = hex_to_u32 ((const u8 *) &hash_pos[ 32]); - digest[ 5] = hex_to_u32 ((const u8 *) &hash_pos[ 40]); - digest[ 6] = hex_to_u32 ((const u8 *) &hash_pos[ 48]); - digest[ 7] = hex_to_u32 ((const u8 *) &hash_pos[ 56]); - digest[ 8] = hex_to_u32 ((const u8 *) &hash_pos[ 64]); - digest[ 9] = hex_to_u32 ((const u8 *) &hash_pos[ 72]); - digest[10] = hex_to_u32 ((const u8 *) &hash_pos[ 80]); - digest[11] = hex_to_u32 ((const u8 *) &hash_pos[ 88]); - digest[12] = hex_to_u32 ((const u8 *) &hash_pos[ 96]); - digest[13] = hex_to_u32 ((const u8 *) &hash_pos[104]); - digest[14] = hex_to_u32 ((const u8 *) &hash_pos[112]); - digest[15] = hex_to_u32 ((const u8 *) &hash_pos[120]); - - char *salt_pos = input_buf + 128; - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_pos[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_pos[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &salt_pos[24]); - - salt->salt_iter = ROUNDS_ORACLET - 1; - salt->salt_len = 16; - - return (PARSER_OK); -} - -int sha256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_1400) || (input_len > DISPLAY_LEN_MAX_1400)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); - digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); - digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); - - digest[0] -= SHA256M_A; - digest[1] -= SHA256M_B; - digest[2] -= SHA256M_C; - digest[3] -= SHA256M_D; - digest[4] -= SHA256M_E; - digest[5] -= SHA256M_F; - digest[6] -= SHA256M_G; - digest[7] -= SHA256M_H; - - return (PARSER_OK); -} - -int sha256s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_1410H) || (input_len > DISPLAY_LEN_MAX_1410H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_1410) || (input_len > DISPLAY_LEN_MAX_1410)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); - digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); - digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); - - digest[0] -= SHA256M_A; - digest[1] -= SHA256M_B; - digest[2] -= SHA256M_C; - digest[3] -= SHA256M_D; - digest[4] -= SHA256M_E; - digest[5] -= SHA256M_F; - digest[6] -= SHA256M_G; - digest[7] -= SHA256M_H; - - if (input_buf[64] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 64 - 1; - - char *salt_buf = input_buf + 64 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int sha384_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_10800) || (input_len > DISPLAY_LEN_MAX_10800)) return (PARSER_GLOBAL_LENGTH); - - u64 *digest = (u64 *) hash_buf->digest; - - digest[0] = hex_to_u64 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u64 ((const u8 *) &input_buf[ 16]); - digest[2] = hex_to_u64 ((const u8 *) &input_buf[ 32]); - digest[3] = hex_to_u64 ((const u8 *) &input_buf[ 48]); - digest[4] = hex_to_u64 ((const u8 *) &input_buf[ 64]); - digest[5] = hex_to_u64 ((const u8 *) &input_buf[ 80]); - digest[6] = 0; - digest[7] = 0; - - digest[0] -= SHA384M_A; - digest[1] -= SHA384M_B; - digest[2] -= SHA384M_C; - digest[3] -= SHA384M_D; - digest[4] -= SHA384M_E; - digest[5] -= SHA384M_F; - digest[6] -= 0; - digest[7] -= 0; - - return (PARSER_OK); -} - -int sha512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_1700) || (input_len > DISPLAY_LEN_MAX_1700)) return (PARSER_GLOBAL_LENGTH); - - u64 *digest = (u64 *) hash_buf->digest; - - digest[0] = hex_to_u64 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u64 ((const u8 *) &input_buf[ 16]); - digest[2] = hex_to_u64 ((const u8 *) &input_buf[ 32]); - digest[3] = hex_to_u64 ((const u8 *) &input_buf[ 48]); - digest[4] = hex_to_u64 ((const u8 *) &input_buf[ 64]); - digest[5] = hex_to_u64 ((const u8 *) &input_buf[ 80]); - digest[6] = hex_to_u64 ((const u8 *) &input_buf[ 96]); - digest[7] = hex_to_u64 ((const u8 *) &input_buf[112]); - - digest[0] -= SHA512M_A; - digest[1] -= SHA512M_B; - digest[2] -= SHA512M_C; - digest[3] -= SHA512M_D; - digest[4] -= SHA512M_E; - digest[5] -= SHA512M_F; - digest[6] -= SHA512M_G; - digest[7] -= SHA512M_H; - - return (PARSER_OK); -} - -int sha512s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_1710H) || (input_len > DISPLAY_LEN_MAX_1710H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_1710) || (input_len > DISPLAY_LEN_MAX_1710)) return (PARSER_GLOBAL_LENGTH); - } - - u64 *digest = (u64 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u64 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u64 ((const u8 *) &input_buf[ 16]); - digest[2] = hex_to_u64 ((const u8 *) &input_buf[ 32]); - digest[3] = hex_to_u64 ((const u8 *) &input_buf[ 48]); - digest[4] = hex_to_u64 ((const u8 *) &input_buf[ 64]); - digest[5] = hex_to_u64 ((const u8 *) &input_buf[ 80]); - digest[6] = hex_to_u64 ((const u8 *) &input_buf[ 96]); - digest[7] = hex_to_u64 ((const u8 *) &input_buf[112]); - - digest[0] -= SHA512M_A; - digest[1] -= SHA512M_B; - digest[2] -= SHA512M_C; - digest[3] -= SHA512M_D; - digest[4] -= SHA512M_E; - digest[5] -= SHA512M_F; - digest[6] -= SHA512M_G; - digest[7] -= SHA512M_H; - - if (input_buf[128] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 128 - 1; - - char *salt_buf = input_buf + 128 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int sha512crypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (memcmp (SIGNATURE_SHA512CRYPT, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); - - u64 *digest = (u64 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_pos = input_buf + 3; - - uint iterations_len = 0; - - if (memcmp (salt_pos, "rounds=", 7) == 0) - { - salt_pos += 7; - - for (iterations_len = 0; salt_pos[0] >= '0' && salt_pos[0] <= '9' && iterations_len < 7; iterations_len++, salt_pos += 1) continue; - - if (iterations_len == 0 ) return (PARSER_SALT_ITERATION); - if (salt_pos[0] != '$') return (PARSER_SIGNATURE_UNMATCHED); - - salt_pos[0] = 0x0; - - salt->salt_iter = atoi (salt_pos - iterations_len); - - salt_pos += 1; - - iterations_len += 8; - } - else - { - salt->salt_iter = ROUNDS_SHA512CRYPT; - } - - if ((input_len < DISPLAY_LEN_MIN_1800) || (input_len > DISPLAY_LEN_MAX_1800 + iterations_len)) return (PARSER_GLOBAL_LENGTH); - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - if (salt_len > 16) return (PARSER_SALT_LENGTH); - - memcpy ((char *) salt->salt_buf, salt_pos, salt_len); - - salt->salt_len = salt_len; - - hash_pos++; - - sha512crypt_decode ((unsigned char *) digest, (unsigned char *) hash_pos); - - return (PARSER_OK); -} - -int keccak_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_5000) || (input_len > DISPLAY_LEN_MAX_5000)) return (PARSER_GLOBAL_LENGTH); - - if (input_len % 16) return (PARSER_GLOBAL_LENGTH); - - u64 *digest = (u64 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - uint keccak_mdlen = input_len / 2; - - for (uint i = 0; i < keccak_mdlen / 8; i++) - { - digest[i] = hex_to_u64 ((const u8 *) &input_buf[i * 16]); - - digest[i] = byte_swap_64 (digest[i]); - } - - salt->keccak_mdlen = keccak_mdlen; - - return (PARSER_OK); -} - -int ikepsk_md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_5300) || (input_len > DISPLAY_LEN_MAX_5300)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - ikepsk_t *ikepsk = (ikepsk_t *) hash_buf->esalt; - - /** - * Parse that strange long line - */ - - char *in_off[9]; - - size_t in_len[9] = { 0 }; - - in_off[0] = strtok (input_buf, ":"); - - if (in_off[0] == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - in_len[0] = strlen (in_off[0]); - - size_t i; - - for (i = 1; i < 9; i++) - { - in_off[i] = strtok (NULL, ":"); - - if (in_off[i] == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - in_len[i] = strlen (in_off[i]); - } - - char *ptr = (char *) ikepsk->msg_buf; - - for (i = 0; i < in_len[0]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[0] + i); - for (i = 0; i < in_len[1]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[1] + i); - for (i = 0; i < in_len[2]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[2] + i); - for (i = 0; i < in_len[3]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[3] + i); - for (i = 0; i < in_len[4]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[4] + i); - for (i = 0; i < in_len[5]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[5] + i); - - *ptr = 0x80; - - ikepsk->msg_len = (in_len[0] + in_len[1] + in_len[2] + in_len[3] + in_len[4] + in_len[5]) / 2; - - ptr = (char *) ikepsk->nr_buf; - - for (i = 0; i < in_len[6]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[6] + i); - for (i = 0; i < in_len[7]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[7] + i); - - *ptr = 0x80; - - ikepsk->nr_len = (in_len[6] + in_len[7]) / 2; - - /** - * Store to database - */ - - ptr = in_off[8]; - - digest[0] = hex_to_u32 ((const u8 *) &ptr[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &ptr[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &ptr[16]); - digest[3] = hex_to_u32 ((const u8 *) &ptr[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - salt->salt_len = 32; - - salt->salt_buf[0] = ikepsk->nr_buf[0]; - salt->salt_buf[1] = ikepsk->nr_buf[1]; - salt->salt_buf[2] = ikepsk->nr_buf[2]; - salt->salt_buf[3] = ikepsk->nr_buf[3]; - salt->salt_buf[4] = ikepsk->nr_buf[4]; - salt->salt_buf[5] = ikepsk->nr_buf[5]; - salt->salt_buf[6] = ikepsk->nr_buf[6]; - salt->salt_buf[7] = ikepsk->nr_buf[7]; - - return (PARSER_OK); -} - -int ikepsk_sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_5400) || (input_len > DISPLAY_LEN_MAX_5400)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - ikepsk_t *ikepsk = (ikepsk_t *) hash_buf->esalt; - - /** - * Parse that strange long line - */ - - char *in_off[9]; - - size_t in_len[9] = { 0 }; - - in_off[0] = strtok (input_buf, ":"); - - if (in_off[0] == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - in_len[0] = strlen (in_off[0]); - - size_t i; - - for (i = 1; i < 9; i++) - { - in_off[i] = strtok (NULL, ":"); - - if (in_off[i] == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - in_len[i] = strlen (in_off[i]); - } - - char *ptr = (char *) ikepsk->msg_buf; - - for (i = 0; i < in_len[0]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[0] + i); - for (i = 0; i < in_len[1]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[1] + i); - for (i = 0; i < in_len[2]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[2] + i); - for (i = 0; i < in_len[3]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[3] + i); - for (i = 0; i < in_len[4]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[4] + i); - for (i = 0; i < in_len[5]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[5] + i); - - *ptr = 0x80; - - ikepsk->msg_len = (in_len[0] + in_len[1] + in_len[2] + in_len[3] + in_len[4] + in_len[5]) / 2; - - ptr = (char *) ikepsk->nr_buf; - - for (i = 0; i < in_len[6]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[6] + i); - for (i = 0; i < in_len[7]; i += 2) *ptr++ = hex_to_u8 ((const u8 *) in_off[7] + i); - - *ptr = 0x80; - - ikepsk->nr_len = (in_len[6] + in_len[7]) / 2; - - /** - * Store to database - */ - - ptr = in_off[8]; - - digest[0] = hex_to_u32 ((const u8 *) &ptr[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &ptr[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &ptr[16]); - digest[3] = hex_to_u32 ((const u8 *) &ptr[24]); - digest[4] = hex_to_u32 ((const u8 *) &ptr[32]); - - salt->salt_len = 32; - - salt->salt_buf[0] = ikepsk->nr_buf[0]; - salt->salt_buf[1] = ikepsk->nr_buf[1]; - salt->salt_buf[2] = ikepsk->nr_buf[2]; - salt->salt_buf[3] = ikepsk->nr_buf[3]; - salt->salt_buf[4] = ikepsk->nr_buf[4]; - salt->salt_buf[5] = ikepsk->nr_buf[5]; - salt->salt_buf[6] = ikepsk->nr_buf[6]; - salt->salt_buf[7] = ikepsk->nr_buf[7]; - - return (PARSER_OK); -} - -int ripemd160_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_6000) || (input_len > DISPLAY_LEN_MAX_6000)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - - return (PARSER_OK); -} - -int whirlpool_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_6100) || (input_len > DISPLAY_LEN_MAX_6100)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[ 0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[ 1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[ 2] = hex_to_u32 ((const u8 *) &input_buf[ 16]); - digest[ 3] = hex_to_u32 ((const u8 *) &input_buf[ 24]); - digest[ 4] = hex_to_u32 ((const u8 *) &input_buf[ 32]); - digest[ 5] = hex_to_u32 ((const u8 *) &input_buf[ 40]); - digest[ 6] = hex_to_u32 ((const u8 *) &input_buf[ 48]); - digest[ 7] = hex_to_u32 ((const u8 *) &input_buf[ 56]); - digest[ 8] = hex_to_u32 ((const u8 *) &input_buf[ 64]); - digest[ 9] = hex_to_u32 ((const u8 *) &input_buf[ 72]); - digest[10] = hex_to_u32 ((const u8 *) &input_buf[ 80]); - digest[11] = hex_to_u32 ((const u8 *) &input_buf[ 88]); - digest[12] = hex_to_u32 ((const u8 *) &input_buf[ 96]); - digest[13] = hex_to_u32 ((const u8 *) &input_buf[104]); - digest[14] = hex_to_u32 ((const u8 *) &input_buf[112]); - digest[15] = hex_to_u32 ((const u8 *) &input_buf[120]); - - return (PARSER_OK); -} - -int androidpin_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_5800) || (input_len > DISPLAY_LEN_MAX_5800)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - - if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 40 - 1; - - char *salt_buf = input_buf + 40 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - salt->salt_iter = ROUNDS_ANDROIDPIN - 1; - - return (PARSER_OK); -} - -int truecrypt_parse_hash_1k (char *input_buf, uint input_len, hash_t *hash_buf) -{ - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - tc_t *tc = (tc_t *) hash_buf->esalt; - - if (input_len == 0) - { - log_error ("TrueCrypt container not specified"); - - exit (-1); - } - - FILE *fp = fopen (input_buf, "rb"); - - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } - - char buf[512] = { 0 }; - - int n = fread (buf, 1, sizeof (buf), fp); - - fclose (fp); - - if (n != 512) return (PARSER_TC_FILE_SIZE); - - memcpy (tc->salt_buf, buf, 64); - - memcpy (tc->data_buf, buf + 64, 512 - 64); - - salt->salt_buf[0] = tc->salt_buf[0]; - - salt->salt_len = 4; - - salt->salt_iter = ROUNDS_TRUECRYPT_1K - 1; - - tc->signature = 0x45555254; // "TRUE" - - digest[0] = tc->data_buf[0]; - - return (PARSER_OK); -} - -int truecrypt_parse_hash_2k (char *input_buf, uint input_len, hash_t *hash_buf) -{ - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - tc_t *tc = (tc_t *) hash_buf->esalt; - - if (input_len == 0) - { - log_error ("TrueCrypt container not specified"); - - exit (-1); - } - - FILE *fp = fopen (input_buf, "rb"); - - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } - - char buf[512] = { 0 }; - - int n = fread (buf, 1, sizeof (buf), fp); - - fclose (fp); - - if (n != 512) return (PARSER_TC_FILE_SIZE); - - memcpy (tc->salt_buf, buf, 64); - - memcpy (tc->data_buf, buf + 64, 512 - 64); - - salt->salt_buf[0] = tc->salt_buf[0]; - - salt->salt_len = 4; - - salt->salt_iter = ROUNDS_TRUECRYPT_2K - 1; - - tc->signature = 0x45555254; // "TRUE" - - digest[0] = tc->data_buf[0]; - - return (PARSER_OK); -} - -int veracrypt_parse_hash_200000 (char *input_buf, uint input_len, hash_t *hash_buf) -{ - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - tc_t *tc = (tc_t *) hash_buf->esalt; - - if (input_len == 0) - { - log_error ("VeraCrypt container not specified"); - - exit (-1); - } - - FILE *fp = fopen (input_buf, "rb"); - - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } - - char buf[512] = { 0 }; - - int n = fread (buf, 1, sizeof (buf), fp); - - fclose (fp); - - if (n != 512) return (PARSER_VC_FILE_SIZE); - - memcpy (tc->salt_buf, buf, 64); - - memcpy (tc->data_buf, buf + 64, 512 - 64); - - salt->salt_buf[0] = tc->salt_buf[0]; - - salt->salt_len = 4; - - salt->salt_iter = ROUNDS_VERACRYPT_200000 - 1; - - tc->signature = 0x41524556; // "VERA" - - digest[0] = tc->data_buf[0]; - - return (PARSER_OK); -} - -int veracrypt_parse_hash_500000 (char *input_buf, uint input_len, hash_t *hash_buf) -{ - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - tc_t *tc = (tc_t *) hash_buf->esalt; - - if (input_len == 0) - { - log_error ("VeraCrypt container not specified"); - - exit (-1); - } - - FILE *fp = fopen (input_buf, "rb"); - - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } - - char buf[512] = { 0 }; - - int n = fread (buf, 1, sizeof (buf), fp); - - fclose (fp); - - if (n != 512) return (PARSER_VC_FILE_SIZE); - - memcpy (tc->salt_buf, buf, 64); - - memcpy (tc->data_buf, buf + 64, 512 - 64); - - salt->salt_buf[0] = tc->salt_buf[0]; - - salt->salt_len = 4; - - salt->salt_iter = ROUNDS_VERACRYPT_500000 - 1; - - tc->signature = 0x41524556; // "VERA" - - digest[0] = tc->data_buf[0]; - - return (PARSER_OK); -} - -int veracrypt_parse_hash_327661 (char *input_buf, uint input_len, hash_t *hash_buf) -{ - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - tc_t *tc = (tc_t *) hash_buf->esalt; - - if (input_len == 0) - { - log_error ("VeraCrypt container not specified"); - - exit (-1); - } - - FILE *fp = fopen (input_buf, "rb"); - - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } - - char buf[512] = { 0 }; - - int n = fread (buf, 1, sizeof (buf), fp); - - fclose (fp); - - if (n != 512) return (PARSER_VC_FILE_SIZE); - - memcpy (tc->salt_buf, buf, 64); - - memcpy (tc->data_buf, buf + 64, 512 - 64); - - salt->salt_buf[0] = tc->salt_buf[0]; - - salt->salt_len = 4; - - salt->salt_iter = ROUNDS_VERACRYPT_327661 - 1; - - tc->signature = 0x41524556; // "VERA" - - digest[0] = tc->data_buf[0]; - - return (PARSER_OK); -} - -int veracrypt_parse_hash_655331 (char *input_buf, uint input_len, hash_t *hash_buf) -{ - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - tc_t *tc = (tc_t *) hash_buf->esalt; - - if (input_len == 0) - { - log_error ("VeraCrypt container not specified"); - - exit (-1); - } - - FILE *fp = fopen (input_buf, "rb"); - - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } - - char buf[512] = { 0 }; - - int n = fread (buf, 1, sizeof (buf), fp); - - fclose (fp); - - if (n != 512) return (PARSER_VC_FILE_SIZE); - - memcpy (tc->salt_buf, buf, 64); - - memcpy (tc->data_buf, buf + 64, 512 - 64); - - salt->salt_buf[0] = tc->salt_buf[0]; - - salt->salt_len = 4; - - salt->salt_iter = ROUNDS_VERACRYPT_655331 - 1; - - tc->signature = 0x41524556; // "VERA" - - digest[0] = tc->data_buf[0]; - - return (PARSER_OK); -} - -int md5aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_6300) || (input_len > DISPLAY_LEN_MAX_6300)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_MD5AIX, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_pos = input_buf + 6; - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - if (salt_len < 8) return (PARSER_SALT_LENGTH); - - memcpy ((char *) salt->salt_buf, salt_pos, salt_len); - - salt->salt_len = salt_len; - - salt->salt_iter = 1000; - - hash_pos++; - - md5crypt_decode ((unsigned char *) digest, (unsigned char *) hash_pos); - - return (PARSER_OK); -} - -int sha1aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_6700) || (input_len > DISPLAY_LEN_MAX_6700)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SHA1AIX, input_buf, 7)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *iter_pos = input_buf + 7; - - char *salt_pos = strchr (iter_pos, '$'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - if (salt_len < 16) return (PARSER_SALT_LENGTH); - - memcpy ((char *) salt->salt_buf, salt_pos, salt_len); - - salt->salt_len = salt_len; - - char salt_iter[3] = { iter_pos[0], iter_pos[1], 0 }; - - salt->salt_sign[0] = atoi (salt_iter); - - salt->salt_iter = (1u << atoi (salt_iter)) - 1; - - hash_pos++; - - sha1aix_decode ((unsigned char *) digest, (unsigned char *) hash_pos); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - - return (PARSER_OK); -} - -int sha256aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_6400) || (input_len > DISPLAY_LEN_MAX_6400)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SHA256AIX, input_buf, 9)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *iter_pos = input_buf + 9; - - char *salt_pos = strchr (iter_pos, '$'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - if (salt_len < 16) return (PARSER_SALT_LENGTH); - - memcpy ((char *) salt->salt_buf, salt_pos, salt_len); - - salt->salt_len = salt_len; - - char salt_iter[3] = { iter_pos[0], iter_pos[1], 0 }; - - salt->salt_sign[0] = atoi (salt_iter); - - salt->salt_iter = (1u << atoi (salt_iter)) - 1; - - hash_pos++; - - sha256aix_decode ((unsigned char *) digest, (unsigned char *) hash_pos); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - digest[5] = byte_swap_32 (digest[5]); - digest[6] = byte_swap_32 (digest[6]); - digest[7] = byte_swap_32 (digest[7]); - - return (PARSER_OK); -} - -int sha512aix_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_6500) || (input_len > DISPLAY_LEN_MAX_6500)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SHA512AIX, input_buf, 9)) return (PARSER_SIGNATURE_UNMATCHED); - - u64 *digest = (u64 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *iter_pos = input_buf + 9; - - char *salt_pos = strchr (iter_pos, '$'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - if (salt_len < 16) return (PARSER_SALT_LENGTH); - - memcpy ((char *) salt->salt_buf, salt_pos, salt_len); - - salt->salt_len = salt_len; - - char salt_iter[3] = { iter_pos[0], iter_pos[1], 0 }; - - salt->salt_sign[0] = atoi (salt_iter); - - salt->salt_iter = (1u << atoi (salt_iter)) - 1; - - hash_pos++; - - sha512aix_decode ((unsigned char *) digest, (unsigned char *) hash_pos); - - digest[0] = byte_swap_64 (digest[0]); - digest[1] = byte_swap_64 (digest[1]); - digest[2] = byte_swap_64 (digest[2]); - digest[3] = byte_swap_64 (digest[3]); - digest[4] = byte_swap_64 (digest[4]); - digest[5] = byte_swap_64 (digest[5]); - digest[6] = byte_swap_64 (digest[6]); - digest[7] = byte_swap_64 (digest[7]); - - return (PARSER_OK); -} - -int agilekey_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_6600) || (input_len > DISPLAY_LEN_MAX_6600)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - agilekey_t *agilekey = (agilekey_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *iterations_pos = input_buf; - - char *saltbuf_pos = strchr (iterations_pos, ':'); - - if (saltbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint iterations_len = saltbuf_pos - iterations_pos; - - if (iterations_len > 6) return (PARSER_SALT_LENGTH); - - saltbuf_pos++; - - char *cipherbuf_pos = strchr (saltbuf_pos, ':'); - - if (cipherbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint saltbuf_len = cipherbuf_pos - saltbuf_pos; - - if (saltbuf_len != 16) return (PARSER_SALT_LENGTH); - - uint cipherbuf_len = input_len - iterations_len - 1 - saltbuf_len - 1; - - if (cipherbuf_len != 2080) return (PARSER_HASH_LENGTH); - - cipherbuf_pos++; - - /** - * pbkdf2 iterations - */ - - salt->salt_iter = atoi (iterations_pos) - 1; - - /** - * handle salt encoding - */ - - char *saltbuf_ptr = (char *) salt->salt_buf; - - for (uint i = 0; i < saltbuf_len; i += 2) - { - const char p0 = saltbuf_pos[i + 0]; - const char p1 = saltbuf_pos[i + 1]; - - *saltbuf_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - salt->salt_len = saltbuf_len / 2; - - /** - * handle cipher encoding - */ - - uint *tmp = (uint *) mymalloc (32); - - char *cipherbuf_ptr = (char *) tmp; - - for (uint i = 2016; i < cipherbuf_len; i += 2) - { - const char p0 = cipherbuf_pos[i + 0]; - const char p1 = cipherbuf_pos[i + 1]; - - *cipherbuf_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - // iv is stored at salt_buf 4 (length 16) - // data is stored at salt_buf 8 (length 16) - - salt->salt_buf[ 4] = byte_swap_32 (tmp[0]); - salt->salt_buf[ 5] = byte_swap_32 (tmp[1]); - salt->salt_buf[ 6] = byte_swap_32 (tmp[2]); - salt->salt_buf[ 7] = byte_swap_32 (tmp[3]); - - salt->salt_buf[ 8] = byte_swap_32 (tmp[4]); - salt->salt_buf[ 9] = byte_swap_32 (tmp[5]); - salt->salt_buf[10] = byte_swap_32 (tmp[6]); - salt->salt_buf[11] = byte_swap_32 (tmp[7]); - - myfree (tmp); - - for (uint i = 0, j = 0; i < 1040; i += 1, j += 2) - { - const char p0 = cipherbuf_pos[j + 0]; - const char p1 = cipherbuf_pos[j + 1]; - - agilekey->cipher[i] = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - /** - * digest buf - */ - - digest[0] = 0x10101010; - digest[1] = 0x10101010; - digest[2] = 0x10101010; - digest[3] = 0x10101010; - - return (PARSER_OK); -} - -int lastpass_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_6800) || (input_len > DISPLAY_LEN_MAX_6800)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *hashbuf_pos = input_buf; - - char *iterations_pos = strchr (hashbuf_pos, ':'); - - if (iterations_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint hash_len = iterations_pos - hashbuf_pos; - - if ((hash_len != 32) && (hash_len != 64)) return (PARSER_HASH_LENGTH); - - iterations_pos++; - - char *saltbuf_pos = strchr (iterations_pos, ':'); - - if (saltbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint iterations_len = saltbuf_pos - iterations_pos; - - saltbuf_pos++; - - uint salt_len = input_len - hash_len - 1 - iterations_len - 1; - - if (salt_len > 32) return (PARSER_SALT_LENGTH); - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, saltbuf_pos, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - salt->salt_iter = atoi (iterations_pos) - 1; - - digest[0] = hex_to_u32 ((const u8 *) &hashbuf_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hashbuf_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hashbuf_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hashbuf_pos[24]); - - return (PARSER_OK); -} - -int gost_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_6900) || (input_len > DISPLAY_LEN_MAX_6900)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); - digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); - digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - digest[5] = byte_swap_32 (digest[5]); - digest[6] = byte_swap_32 (digest[6]); - digest[7] = byte_swap_32 (digest[7]); - - return (PARSER_OK); -} - -int sha256crypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (memcmp (SIGNATURE_SHA256CRYPT, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_pos = input_buf + 3; - - uint iterations_len = 0; - - if (memcmp (salt_pos, "rounds=", 7) == 0) - { - salt_pos += 7; - - for (iterations_len = 0; salt_pos[0] >= '0' && salt_pos[0] <= '9' && iterations_len < 7; iterations_len++, salt_pos += 1) continue; - - if (iterations_len == 0 ) return (PARSER_SALT_ITERATION); - if (salt_pos[0] != '$') return (PARSER_SIGNATURE_UNMATCHED); - - salt_pos[0] = 0x0; - - salt->salt_iter = atoi (salt_pos - iterations_len); - - salt_pos += 1; - - iterations_len += 8; - } - else - { - salt->salt_iter = ROUNDS_SHA256CRYPT; - } - - if ((input_len < DISPLAY_LEN_MIN_7400) || (input_len > DISPLAY_LEN_MAX_7400 + iterations_len)) return (PARSER_GLOBAL_LENGTH); - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - if (salt_len > 16) return (PARSER_SALT_LENGTH); - - memcpy ((char *) salt->salt_buf, salt_pos, salt_len); - - salt->salt_len = salt_len; - - hash_pos++; - - sha256crypt_decode ((unsigned char *) digest, (unsigned char *) hash_pos); - - return (PARSER_OK); -} - -int sha512osx_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - uint max_len = DISPLAY_LEN_MAX_7100 + (2 * 128); - - if ((input_len < DISPLAY_LEN_MIN_7100) || (input_len > max_len)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SHA512OSX, input_buf, 4)) return (PARSER_SIGNATURE_UNMATCHED); - - u64 *digest = (u64 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pbkdf2_sha512_t *pbkdf2_sha512 = (pbkdf2_sha512_t *) hash_buf->esalt; - - char *iter_pos = input_buf + 4; - - char *salt_pos = strchr (iter_pos, '$'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - if (((input_len - (hash_pos - input_buf) - 1) % 128) != 0) return (PARSER_GLOBAL_LENGTH); - - hash_pos++; - - digest[0] = hex_to_u64 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u64 ((const u8 *) &hash_pos[ 16]); - digest[2] = hex_to_u64 ((const u8 *) &hash_pos[ 32]); - digest[3] = hex_to_u64 ((const u8 *) &hash_pos[ 48]); - digest[4] = hex_to_u64 ((const u8 *) &hash_pos[ 64]); - digest[5] = hex_to_u64 ((const u8 *) &hash_pos[ 80]); - digest[6] = hex_to_u64 ((const u8 *) &hash_pos[ 96]); - digest[7] = hex_to_u64 ((const u8 *) &hash_pos[112]); - - uint salt_len = hash_pos - salt_pos - 1; - - if ((salt_len % 2) != 0) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len / 2; - - pbkdf2_sha512->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[ 0]); - pbkdf2_sha512->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_pos[ 8]); - pbkdf2_sha512->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_pos[16]); - pbkdf2_sha512->salt_buf[3] = hex_to_u32 ((const u8 *) &salt_pos[24]); - pbkdf2_sha512->salt_buf[4] = hex_to_u32 ((const u8 *) &salt_pos[32]); - pbkdf2_sha512->salt_buf[5] = hex_to_u32 ((const u8 *) &salt_pos[40]); - pbkdf2_sha512->salt_buf[6] = hex_to_u32 ((const u8 *) &salt_pos[48]); - pbkdf2_sha512->salt_buf[7] = hex_to_u32 ((const u8 *) &salt_pos[56]); - - pbkdf2_sha512->salt_buf[0] = byte_swap_32 (pbkdf2_sha512->salt_buf[0]); - pbkdf2_sha512->salt_buf[1] = byte_swap_32 (pbkdf2_sha512->salt_buf[1]); - pbkdf2_sha512->salt_buf[2] = byte_swap_32 (pbkdf2_sha512->salt_buf[2]); - pbkdf2_sha512->salt_buf[3] = byte_swap_32 (pbkdf2_sha512->salt_buf[3]); - pbkdf2_sha512->salt_buf[4] = byte_swap_32 (pbkdf2_sha512->salt_buf[4]); - pbkdf2_sha512->salt_buf[5] = byte_swap_32 (pbkdf2_sha512->salt_buf[5]); - pbkdf2_sha512->salt_buf[6] = byte_swap_32 (pbkdf2_sha512->salt_buf[6]); - pbkdf2_sha512->salt_buf[7] = byte_swap_32 (pbkdf2_sha512->salt_buf[7]); - pbkdf2_sha512->salt_buf[8] = 0x01000000; - pbkdf2_sha512->salt_buf[9] = 0x80; - - salt->salt_buf[0] = pbkdf2_sha512->salt_buf[0]; - - salt->salt_iter = atoi (iter_pos) - 1; - - return (PARSER_OK); -} - -int episerver4_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_1441) || (input_len > DISPLAY_LEN_MAX_1441)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_EPISERVER4, input_buf, 14)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_pos = input_buf + 14; - - char *hash_pos = strchr (salt_pos, '*'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - hash_pos++; - - uint salt_len = hash_pos - salt_pos - 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - u8 tmp_buf[100] = { 0 }; - - base64_decode (base64_to_int, (const u8 *) hash_pos, 43, tmp_buf); - - memcpy (digest, tmp_buf, 32); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - digest[5] = byte_swap_32 (digest[5]); - digest[6] = byte_swap_32 (digest[6]); - digest[7] = byte_swap_32 (digest[7]); - - digest[0] -= SHA256M_A; - digest[1] -= SHA256M_B; - digest[2] -= SHA256M_C; - digest[3] -= SHA256M_D; - digest[4] -= SHA256M_E; - digest[5] -= SHA256M_F; - digest[6] -= SHA256M_G; - digest[7] -= SHA256M_H; - - return (PARSER_OK); -} - -int sha512grub_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - uint max_len = DISPLAY_LEN_MAX_7200 + (8 * 128); - - if ((input_len < DISPLAY_LEN_MIN_7200) || (input_len > max_len)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SHA512GRUB, input_buf, 19)) return (PARSER_SIGNATURE_UNMATCHED); - - u64 *digest = (u64 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pbkdf2_sha512_t *pbkdf2_sha512 = (pbkdf2_sha512_t *) hash_buf->esalt; - - char *iter_pos = input_buf + 19; - - char *salt_pos = strchr (iter_pos, '.'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - char *hash_pos = strchr (salt_pos, '.'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - if (((input_len - (hash_pos - input_buf) - 1) % 128) != 0) return (PARSER_GLOBAL_LENGTH); - - hash_pos++; - - digest[0] = hex_to_u64 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u64 ((const u8 *) &hash_pos[ 16]); - digest[2] = hex_to_u64 ((const u8 *) &hash_pos[ 32]); - digest[3] = hex_to_u64 ((const u8 *) &hash_pos[ 48]); - digest[4] = hex_to_u64 ((const u8 *) &hash_pos[ 64]); - digest[5] = hex_to_u64 ((const u8 *) &hash_pos[ 80]); - digest[6] = hex_to_u64 ((const u8 *) &hash_pos[ 96]); - digest[7] = hex_to_u64 ((const u8 *) &hash_pos[112]); - - uint salt_len = hash_pos - salt_pos - 1; - - salt_len /= 2; - - char *salt_buf_ptr = (char *) pbkdf2_sha512->salt_buf; - - uint i; - - for (i = 0; i < salt_len; i++) - { - salt_buf_ptr[i] = hex_to_u8 ((const u8 *) &salt_pos[i * 2]); - } - - salt_buf_ptr[salt_len + 3] = 0x01; - salt_buf_ptr[salt_len + 4] = 0x80; - - salt->salt_buf[0] = pbkdf2_sha512->salt_buf[0]; - - salt->salt_len = salt_len; - - salt->salt_iter = atoi (iter_pos) - 1; - - return (PARSER_OK); -} - -int sha512b64s_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_1711) || (input_len > DISPLAY_LEN_MAX_1711)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SHA512B64S, input_buf, 9)) return (PARSER_SIGNATURE_UNMATCHED); - - u64 *digest = (u64 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - u8 tmp_buf[120] = { 0 }; - - int tmp_len = base64_decode (base64_to_int, (const u8 *) input_buf + 9, input_len - 9, tmp_buf); - - if (tmp_len < 64) return (PARSER_HASH_LENGTH); - - memcpy (digest, tmp_buf, 64); - - digest[0] = byte_swap_64 (digest[0]); - digest[1] = byte_swap_64 (digest[1]); - digest[2] = byte_swap_64 (digest[2]); - digest[3] = byte_swap_64 (digest[3]); - digest[4] = byte_swap_64 (digest[4]); - digest[5] = byte_swap_64 (digest[5]); - digest[6] = byte_swap_64 (digest[6]); - digest[7] = byte_swap_64 (digest[7]); - - digest[0] -= SHA512M_A; - digest[1] -= SHA512M_B; - digest[2] -= SHA512M_C; - digest[3] -= SHA512M_D; - digest[4] -= SHA512M_E; - digest[5] -= SHA512M_F; - digest[6] -= SHA512M_G; - digest[7] -= SHA512M_H; - - int salt_len = tmp_len - 64; - - if (salt_len < 0) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - memcpy (salt->salt_buf, tmp_buf + 64, salt->salt_len); - - if (data.opts_type & OPTS_TYPE_ST_ADD80) - { - char *ptr = (char *) salt->salt_buf; - - ptr[salt->salt_len] = 0x80; - } - - return (PARSER_OK); -} - -int hmacmd5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_50H) || (input_len > DISPLAY_LEN_MAX_50H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_50) || (input_len > DISPLAY_LEN_MAX_50)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 32 - 1; - - char *salt_buf = input_buf + 32 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int hmacsha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_150H) || (input_len > DISPLAY_LEN_MAX_150H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_150) || (input_len > DISPLAY_LEN_MAX_150)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - - if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 40 - 1; - - char *salt_buf = input_buf + 40 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int hmacsha256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_1450H) || (input_len > DISPLAY_LEN_MAX_1450H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_1450) || (input_len > DISPLAY_LEN_MAX_1450)) return (PARSER_GLOBAL_LENGTH); - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); - digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); - digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); - - if (input_buf[64] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 64 - 1; - - char *salt_buf = input_buf + 64 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int hmacsha512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (data.opts_type & OPTS_TYPE_ST_HEX) - { - if ((input_len < DISPLAY_LEN_MIN_1750H) || (input_len > DISPLAY_LEN_MAX_1750H)) return (PARSER_GLOBAL_LENGTH); - } - else - { - if ((input_len < DISPLAY_LEN_MIN_1750) || (input_len > DISPLAY_LEN_MAX_1750)) return (PARSER_GLOBAL_LENGTH); - } - - u64 *digest = (u64 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u64 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u64 ((const u8 *) &input_buf[ 16]); - digest[2] = hex_to_u64 ((const u8 *) &input_buf[ 32]); - digest[3] = hex_to_u64 ((const u8 *) &input_buf[ 48]); - digest[4] = hex_to_u64 ((const u8 *) &input_buf[ 64]); - digest[5] = hex_to_u64 ((const u8 *) &input_buf[ 80]); - digest[6] = hex_to_u64 ((const u8 *) &input_buf[ 96]); - digest[7] = hex_to_u64 ((const u8 *) &input_buf[112]); - - if (input_buf[128] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 128 - 1; - - char *salt_buf = input_buf + 128 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int krb5pa_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_7500) || (input_len > DISPLAY_LEN_MAX_7500)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_KRB5PA, input_buf, 10)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - krb5pa_t *krb5pa = (krb5pa_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *user_pos = input_buf + 10 + 1; - - char *realm_pos = strchr (user_pos, '$'); - - if (realm_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint user_len = realm_pos - user_pos; - - if (user_len >= 64) return (PARSER_SALT_LENGTH); - - realm_pos++; - - char *salt_pos = strchr (realm_pos, '$'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint realm_len = salt_pos - realm_pos; - - if (realm_len >= 64) return (PARSER_SALT_LENGTH); - - salt_pos++; - - char *data_pos = strchr (salt_pos, '$'); - - if (data_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = data_pos - salt_pos; - - if (salt_len >= 128) return (PARSER_SALT_LENGTH); - - data_pos++; - - uint data_len = input_len - 10 - 1 - user_len - 1 - realm_len - 1 - salt_len - 1; - - if (data_len != ((36 + 16) * 2)) return (PARSER_SALT_LENGTH); - - /** - * copy data - */ - - memcpy (krb5pa->user, user_pos, user_len); - memcpy (krb5pa->realm, realm_pos, realm_len); - memcpy (krb5pa->salt, salt_pos, salt_len); - - char *timestamp_ptr = (char *) krb5pa->timestamp; - - for (uint i = 0; i < (36 * 2); i += 2) - { - const char p0 = data_pos[i + 0]; - const char p1 = data_pos[i + 1]; - - *timestamp_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - char *checksum_ptr = (char *) krb5pa->checksum; - - for (uint i = (36 * 2); i < ((36 + 16) * 2); i += 2) - { - const char p0 = data_pos[i + 0]; - const char p1 = data_pos[i + 1]; - - *checksum_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - /** - * copy some data to generic buffers to make sorting happy - */ - - salt->salt_buf[0] = krb5pa->timestamp[0]; - salt->salt_buf[1] = krb5pa->timestamp[1]; - salt->salt_buf[2] = krb5pa->timestamp[2]; - salt->salt_buf[3] = krb5pa->timestamp[3]; - salt->salt_buf[4] = krb5pa->timestamp[4]; - salt->salt_buf[5] = krb5pa->timestamp[5]; - salt->salt_buf[6] = krb5pa->timestamp[6]; - salt->salt_buf[7] = krb5pa->timestamp[7]; - salt->salt_buf[8] = krb5pa->timestamp[8]; - - salt->salt_len = 36; - - digest[0] = krb5pa->checksum[0]; - digest[1] = krb5pa->checksum[1]; - digest[2] = krb5pa->checksum[2]; - digest[3] = krb5pa->checksum[3]; - - return (PARSER_OK); -} - -int sapb_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_7700) || (input_len > DISPLAY_LEN_MAX_7700)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - /** - * parse line - */ - - char *salt_pos = input_buf; - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - if (salt_len >= 40) return (PARSER_SALT_LENGTH); - - hash_pos++; - - uint hash_len = input_len - 1 - salt_len; - - if (hash_len != 16) return (PARSER_HASH_LENGTH); - - /** - * valid some data - */ - - uint user_len = 0; - - for (uint i = 0; i < salt_len; i++) - { - if (salt_pos[i] == ' ') continue; - - user_len++; - } - - // SAP user names cannot be longer than 12 characters - if (user_len > 12) return (PARSER_SALT_LENGTH); - - // SAP user name cannot start with ! or ? - if (salt_pos[0] == '!' || salt_pos[0] == '?') return (PARSER_SALT_VALUE); - - /** - * copy data - */ - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[8]); - digest[2] = 0; - digest[3] = 0; - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - - return (PARSER_OK); -} - -int sapg_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_7800) || (input_len > DISPLAY_LEN_MAX_7800)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - /** - * parse line - */ - - char *salt_pos = input_buf; - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - if (salt_len >= 40) return (PARSER_SALT_LENGTH); - - hash_pos++; - - uint hash_len = input_len - 1 - salt_len; - - if (hash_len != 40) return (PARSER_HASH_LENGTH); - - /** - * valid some data - */ - - uint user_len = 0; - - for (uint i = 0; i < salt_len; i++) - { - if (salt_pos[i] == ' ') continue; - - user_len++; - } - - // SAP user names cannot be longer than 12 characters - // this is kinda buggy. if the username is in utf the length can be up to length 12*3 - // so far nobody complained so we stay with this because it helps in optimization - // final string can have a max size of 32 (password) + (10 * 5) = lengthMagicArray + 12 (max salt) + 1 (the 0x80) - - if (user_len > 12) return (PARSER_SALT_LENGTH); - - // SAP user name cannot start with ! or ? - if (salt_pos[0] == '!' || salt_pos[0] == '?') return (PARSER_SALT_VALUE); - - /** - * copy data - */ - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); - - return (PARSER_OK); -} - -int drupal7_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_7900) || (input_len > DISPLAY_LEN_MAX_7900)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_DRUPAL7, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); - - u64 *digest = (u64 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *iter_pos = input_buf + 3; - - uint salt_iter = 1u << itoa64_to_int (iter_pos[0]); - - if (salt_iter > 0x80000000) return (PARSER_SALT_ITERATION); - - memcpy ((char *) salt->salt_sign, input_buf, 4); - - salt->salt_iter = salt_iter; - - char *salt_pos = iter_pos + 1; - - uint salt_len = 8; - - memcpy ((char *) salt->salt_buf, salt_pos, salt_len); - - salt->salt_len = salt_len; - - char *hash_pos = salt_pos + salt_len; - - drupal7_decode ((unsigned char *) digest, (unsigned char *) hash_pos); - - // ugly hack start - - char *tmp = (char *) salt->salt_buf_pc; - - tmp[0] = hash_pos[42]; - - // ugly hack end - - digest[ 0] = byte_swap_64 (digest[ 0]); - digest[ 1] = byte_swap_64 (digest[ 1]); - digest[ 2] = byte_swap_64 (digest[ 2]); - digest[ 3] = byte_swap_64 (digest[ 3]); - digest[ 4] = 0; - digest[ 5] = 0; - digest[ 6] = 0; - digest[ 7] = 0; - - return (PARSER_OK); -} - -int sybasease_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_8000) || (input_len > DISPLAY_LEN_MAX_8000)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SYBASEASE, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_buf = input_buf + 6; - - uint salt_len = 16; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - char *hash_pos = input_buf + 6 + 16; - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); - digest[5] = hex_to_u32 ((const u8 *) &hash_pos[40]); - digest[6] = hex_to_u32 ((const u8 *) &hash_pos[48]); - digest[7] = hex_to_u32 ((const u8 *) &hash_pos[56]); - - return (PARSER_OK); -} - -int mysql323_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_200) || (input_len > DISPLAY_LEN_MAX_200)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int rakp_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_7300) || (input_len > DISPLAY_LEN_MAX_7300)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - rakp_t *rakp = (rakp_t *) hash_buf->esalt; - - char *saltbuf_pos = input_buf; - - char *hashbuf_pos = strchr (saltbuf_pos, ':'); - - if (hashbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint saltbuf_len = hashbuf_pos - saltbuf_pos; - - if (saltbuf_len < 64) return (PARSER_SALT_LENGTH); - if (saltbuf_len > 512) return (PARSER_SALT_LENGTH); - - if (saltbuf_len & 1) return (PARSER_SALT_LENGTH); // muss gerade sein wegen hex - - hashbuf_pos++; - - uint hashbuf_len = input_len - saltbuf_len - 1; - - if (hashbuf_len != 40) return (PARSER_HASH_LENGTH); - - char *salt_ptr = (char *) saltbuf_pos; - char *rakp_ptr = (char *) rakp->salt_buf; - - uint i; - uint j; - - for (i = 0, j = 0; i < saltbuf_len; i += 2, j += 1) - { - rakp_ptr[j] = hex_to_u8 ((const u8 *) &salt_ptr[i]); - } - - rakp_ptr[j] = 0x80; - - rakp->salt_len = j; - - for (i = 0; i < 64; i++) - { - rakp->salt_buf[i] = byte_swap_32 (rakp->salt_buf[i]); - } - - salt->salt_buf[0] = rakp->salt_buf[0]; - salt->salt_buf[1] = rakp->salt_buf[1]; - salt->salt_buf[2] = rakp->salt_buf[2]; - salt->salt_buf[3] = rakp->salt_buf[3]; - salt->salt_buf[4] = rakp->salt_buf[4]; - salt->salt_buf[5] = rakp->salt_buf[5]; - salt->salt_buf[6] = rakp->salt_buf[6]; - salt->salt_buf[7] = rakp->salt_buf[7]; - - salt->salt_len = 32; // muss min. 32 haben - - digest[0] = hex_to_u32 ((const u8 *) &hashbuf_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hashbuf_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hashbuf_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hashbuf_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hashbuf_pos[32]); - - return (PARSER_OK); -} - -int netscaler_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_8100) || (input_len > DISPLAY_LEN_MAX_8100)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - if (memcmp (SIGNATURE_NETSCALER, input_buf, 1)) return (PARSER_SIGNATURE_UNMATCHED); - - char *salt_pos = input_buf + 1; - - memcpy (salt->salt_buf, salt_pos, 8); - - salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); - salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); - - salt->salt_len = 8; - - char *hash_pos = salt_pos + 8; - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - return (PARSER_OK); -} - -int chap_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_4800) || (input_len > DISPLAY_LEN_MAX_4800)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - char *salt_buf_ptr = input_buf + 32 + 1; - - u32 *salt_buf = salt->salt_buf; - - salt_buf[0] = hex_to_u32 ((const u8 *) &salt_buf_ptr[ 0]); - salt_buf[1] = hex_to_u32 ((const u8 *) &salt_buf_ptr[ 8]); - salt_buf[2] = hex_to_u32 ((const u8 *) &salt_buf_ptr[16]); - salt_buf[3] = hex_to_u32 ((const u8 *) &salt_buf_ptr[24]); - - salt_buf[0] = byte_swap_32 (salt_buf[0]); - salt_buf[1] = byte_swap_32 (salt_buf[1]); - salt_buf[2] = byte_swap_32 (salt_buf[2]); - salt_buf[3] = byte_swap_32 (salt_buf[3]); - - salt->salt_len = 16 + 1; - - if (input_buf[65] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - char *idbyte_buf_ptr = input_buf + 32 + 1 + 32 + 1; - - salt_buf[4] = hex_to_u8 ((const u8 *) &idbyte_buf_ptr[0]) & 0xff; - - return (PARSER_OK); -} - -int cloudkey_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_8200) || (input_len > DISPLAY_LEN_MAX_8200)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - cloudkey_t *cloudkey = (cloudkey_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *hashbuf_pos = input_buf; - - char *saltbuf_pos = strchr (hashbuf_pos, ':'); - - if (saltbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - const uint hashbuf_len = saltbuf_pos - hashbuf_pos; - - if (hashbuf_len != 64) return (PARSER_HASH_LENGTH); - - saltbuf_pos++; - - char *iteration_pos = strchr (saltbuf_pos, ':'); - - if (iteration_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - const uint saltbuf_len = iteration_pos - saltbuf_pos; - - if (saltbuf_len != 32) return (PARSER_SALT_LENGTH); - - iteration_pos++; - - char *databuf_pos = strchr (iteration_pos, ':'); - - if (databuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - const uint iteration_len = databuf_pos - iteration_pos; - - if (iteration_len < 1) return (PARSER_SALT_ITERATION); - if (iteration_len > 8) return (PARSER_SALT_ITERATION); - - const uint databuf_len = input_len - hashbuf_len - 1 - saltbuf_len - 1 - iteration_len - 1; - - if (databuf_len < 1) return (PARSER_SALT_LENGTH); - if (databuf_len > 2048) return (PARSER_SALT_LENGTH); - - databuf_pos++; - - // digest - - digest[0] = hex_to_u32 ((const u8 *) &hashbuf_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hashbuf_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hashbuf_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hashbuf_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hashbuf_pos[32]); - digest[5] = hex_to_u32 ((const u8 *) &hashbuf_pos[40]); - digest[6] = hex_to_u32 ((const u8 *) &hashbuf_pos[48]); - digest[7] = hex_to_u32 ((const u8 *) &hashbuf_pos[56]); - - // salt - - char *saltbuf_ptr = (char *) salt->salt_buf; - - for (uint i = 0; i < saltbuf_len; i += 2) - { - const char p0 = saltbuf_pos[i + 0]; - const char p1 = saltbuf_pos[i + 1]; - - *saltbuf_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - salt->salt_buf[4] = 0x01000000; - salt->salt_buf[5] = 0x80; - - salt->salt_len = saltbuf_len / 2; - - // iteration - - salt->salt_iter = atoi (iteration_pos) - 1; - - // data - - char *databuf_ptr = (char *) cloudkey->data_buf; - - for (uint i = 0; i < databuf_len; i += 2) - { - const char p0 = databuf_pos[i + 0]; - const char p1 = databuf_pos[i + 1]; - - *databuf_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - *databuf_ptr++ = 0x80; - - for (uint i = 0; i < 512; i++) - { - cloudkey->data_buf[i] = byte_swap_32 (cloudkey->data_buf[i]); - } - - cloudkey->data_len = databuf_len / 2; - - return (PARSER_OK); -} - -int nsec3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_8300) || (input_len > DISPLAY_LEN_MAX_8300)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - /** - * parse line - */ - - char *hashbuf_pos = input_buf; - - char *domainbuf_pos = strchr (hashbuf_pos, ':'); - - if (domainbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - const uint hashbuf_len = domainbuf_pos - hashbuf_pos; - - if (hashbuf_len != 32) return (PARSER_HASH_LENGTH); - - domainbuf_pos++; - - if (domainbuf_pos[0] != '.') return (PARSER_SALT_VALUE); - - char *saltbuf_pos = strchr (domainbuf_pos, ':'); - - if (saltbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - const uint domainbuf_len = saltbuf_pos - domainbuf_pos; - - if (domainbuf_len >= 32) return (PARSER_SALT_LENGTH); - - saltbuf_pos++; - - char *iteration_pos = strchr (saltbuf_pos, ':'); - - if (iteration_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - const uint saltbuf_len = iteration_pos - saltbuf_pos; - - if (saltbuf_len >= 28) return (PARSER_SALT_LENGTH); // 28 = 32 - 4; 4 = length - - if ((domainbuf_len + saltbuf_len) >= 48) return (PARSER_SALT_LENGTH); - - iteration_pos++; - - const uint iteration_len = input_len - hashbuf_len - 1 - domainbuf_len - 1 - saltbuf_len - 1; - - if (iteration_len < 1) return (PARSER_SALT_ITERATION); - if (iteration_len > 5) return (PARSER_SALT_ITERATION); - - // ok, the plan for this algorithm is the following: - // we have 2 salts here, the domain-name and a random salt - // while both are used in the initial transformation, - // only the random salt is used in the following iterations - // so we create two buffer, one that includes domain-name (stored into salt_buf_pc[]) - // and one that includes only the real salt (stored into salt_buf[]). - // the domain-name length is put into array position 7 of salt_buf_pc[] since there is not salt_pc_len - - u8 tmp_buf[100] = { 0 }; - - base32_decode (itoa32_to_int, (const u8 *) hashbuf_pos, 32, tmp_buf); - - memcpy (digest, tmp_buf, 20); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - - // domain - - char *salt_buf_pc_ptr = (char *) salt->salt_buf_pc; - - memcpy (salt_buf_pc_ptr, domainbuf_pos, domainbuf_len); - - char *len_ptr = NULL; - - for (uint i = 0; i < domainbuf_len; i++) - { - if (salt_buf_pc_ptr[i] == '.') - { - len_ptr = &salt_buf_pc_ptr[i]; - - *len_ptr = 0; - } - else - { - *len_ptr += 1; - } - } - - salt->salt_buf_pc[7] = domainbuf_len; - - // "real" salt - - char *salt_buf_ptr = (char *) salt->salt_buf; - - const uint salt_len = parse_and_store_salt (salt_buf_ptr, saltbuf_pos, saltbuf_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - // iteration - - salt->salt_iter = atoi (iteration_pos); - - return (PARSER_OK); -} - -int wbb3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_8400) || (input_len > DISPLAY_LEN_MAX_8400)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - - if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 40 - 1; - - char *salt_buf = input_buf + 40 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int opencart_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_13900) || (input_len > DISPLAY_LEN_MAX_13900)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - - if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 40 - 1; - - char *salt_buf = input_buf + 40 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if ((salt_len != 9) || (salt_len == UINT_MAX)) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int racf_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - const u8 ascii_to_ebcdic[] = - { - 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, - 0x40, 0x4f, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, - 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, - 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0x4a, 0xe0, 0x5a, 0x5f, 0x6d, - 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, - 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xc0, 0x6a, 0xd0, 0xa1, 0x07, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x15, 0x06, 0x17, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x1b, - 0x30, 0x31, 0x1a, 0x33, 0x34, 0x35, 0x36, 0x08, 0x38, 0x39, 0x3a, 0x3b, 0x04, 0x14, 0x3e, 0xe1, - 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, - 0x76, 0x77, 0x78, 0x80, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, - 0x9f, 0xa0, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, - 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xda, 0xdb, - 0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, - }; - - if ((input_len < DISPLAY_LEN_MIN_8500) || (input_len > DISPLAY_LEN_MAX_8500)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_RACF, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_pos = input_buf + 6 + 1; - - char *digest_pos = strchr (salt_pos, '*'); - - if (digest_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = digest_pos - salt_pos; - - if (salt_len > 8) return (PARSER_SALT_LENGTH); - - uint hash_len = input_len - 1 - salt_len - 1 - 6; - - if (hash_len != 16) return (PARSER_HASH_LENGTH); - - digest_pos++; - - char *salt_buf_ptr = (char *) salt->salt_buf; - char *salt_buf_pc_ptr = (char *) salt->salt_buf_pc; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - for (uint i = 0; i < salt_len; i++) - { - salt_buf_pc_ptr[i] = ascii_to_ebcdic[(int) salt_buf_ptr[i]]; - } - for (uint i = salt_len; i < 8; i++) - { - salt_buf_pc_ptr[i] = 0x40; - } - - uint tt; - - IP (salt->salt_buf_pc[0], salt->salt_buf_pc[1], tt); - - salt->salt_buf_pc[0] = rotl32 (salt->salt_buf_pc[0], 3u); - salt->salt_buf_pc[1] = rotl32 (salt->salt_buf_pc[1], 3u); - - digest[0] = hex_to_u32 ((const u8 *) &digest_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &digest_pos[ 8]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - - IP (digest[0], digest[1], tt); - - digest[0] = rotr32 (digest[0], 29); - digest[1] = rotr32 (digest[1], 29); - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int des_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_14000) || (input_len > DISPLAY_LEN_MAX_14000)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *digest_pos = input_buf; - - char *salt_pos = strchr (digest_pos, ':'); - - if (input_buf[16] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = salt_pos - digest_pos; - - if (salt_len != 16) return (PARSER_SALT_LENGTH); - - uint hash_len = input_len - 1 - salt_len; - - if (hash_len != 16) return (PARSER_HASH_LENGTH); - - salt_pos++; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - uint tt; - - salt->salt_buf_pc[0] = byte_swap_32 (salt->salt_buf[0]); - salt->salt_buf_pc[1] = byte_swap_32 (salt->salt_buf[1]); - - IP (salt->salt_buf_pc[0], salt->salt_buf_pc[1], tt); - - digest[0] = hex_to_u32 ((const u8 *) &digest_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &digest_pos[ 8]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - - IP (digest[0], digest[1], tt); - - digest[0] = digest[0]; - digest[1] = digest[1]; - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int lotus5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_8600) || (input_len > DISPLAY_LEN_MAX_8600)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - return (PARSER_OK); -} - -int lotus6_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_8700) || (input_len > DISPLAY_LEN_MAX_8700)) return (PARSER_GLOBAL_LENGTH); - - if ((input_buf[0] != '(') || (input_buf[1] != 'G') || (input_buf[21] != ')')) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - u8 tmp_buf[120] = { 0 }; - - base64_decode (lotus64_to_int, (const u8 *) input_buf + 2, input_len - 3, tmp_buf); - - tmp_buf[3] += -4; // dont ask! - - memcpy (salt->salt_buf, tmp_buf, 5); - - salt->salt_len = 5; - - memcpy (digest, tmp_buf + 5, 9); - - // yes, only 9 byte are needed to crack, but 10 to display - - salt->salt_buf_pc[7] = input_buf[20]; - - return (PARSER_OK); -} - -int lotus8_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_9100) || (input_len > DISPLAY_LEN_MAX_9100)) return (PARSER_GLOBAL_LENGTH); - - if ((input_buf[0] != '(') || (input_buf[1] != 'H') || (input_buf[DISPLAY_LEN_MAX_9100 - 1] != ')')) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - u8 tmp_buf[120] = { 0 }; - - base64_decode (lotus64_to_int, (const u8 *) input_buf + 2, input_len - 3, tmp_buf); - - tmp_buf[3] += -4; // dont ask! - - // salt - - memcpy (salt->salt_buf, tmp_buf, 16); - - salt->salt_len = 16; // Attention: in theory we have 2 salt_len, one for the -m 8700 part (len: 8), 2nd for the 9100 part (len: 16) - - // iteration - - char tmp_iter_buf[11] = { 0 }; - - memcpy (tmp_iter_buf, tmp_buf + 16, 10); - - tmp_iter_buf[10] = 0; - - salt->salt_iter = atoi (tmp_iter_buf); - - if (salt->salt_iter < 1) // well, the limit hopefully is much higher - { - return (PARSER_SALT_ITERATION); - } - - salt->salt_iter--; // first round in init - - // 2 additional bytes for display only - - salt->salt_buf_pc[0] = tmp_buf[26]; - salt->salt_buf_pc[1] = tmp_buf[27]; - - // digest - - memcpy (digest, tmp_buf + 28, 8); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int hmailserver_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_1421) || (input_len > DISPLAY_LEN_MAX_1421)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_buf_pos = input_buf; - - char *hash_buf_pos = salt_buf_pos + 6; - - digest[0] = hex_to_u32 ((const u8 *) &hash_buf_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_buf_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_buf_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_buf_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hash_buf_pos[32]); - digest[5] = hex_to_u32 ((const u8 *) &hash_buf_pos[40]); - digest[6] = hex_to_u32 ((const u8 *) &hash_buf_pos[48]); - digest[7] = hex_to_u32 ((const u8 *) &hash_buf_pos[56]); - - digest[0] -= SHA256M_A; - digest[1] -= SHA256M_B; - digest[2] -= SHA256M_C; - digest[3] -= SHA256M_D; - digest[4] -= SHA256M_E; - digest[5] -= SHA256M_F; - digest[6] -= SHA256M_G; - digest[7] -= SHA256M_H; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - const uint salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf_pos, 6); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int phps_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_2612) || (input_len > DISPLAY_LEN_MAX_2612)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - if (memcmp (SIGNATURE_PHPS, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - salt_t *salt = hash_buf->salt; - - char *salt_buf = input_buf + 6; - - char *digest_buf = strchr (salt_buf, '$'); - - if (digest_buf == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = digest_buf - salt_buf; - - digest_buf++; // skip the '$' symbol - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - digest[0] = hex_to_u32 ((const u8 *) &digest_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &digest_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &digest_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &digest_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - return (PARSER_OK); -} - -int mediawiki_b_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_3711) || (input_len > DISPLAY_LEN_MAX_3711)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_MEDIAWIKI_B, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_buf = input_buf + 3; - - char *digest_buf = strchr (salt_buf, '$'); - - if (digest_buf == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = digest_buf - salt_buf; - - digest_buf++; // skip the '$' symbol - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt_buf_ptr[salt_len] = 0x2d; - - salt->salt_len = salt_len + 1; - - digest[0] = hex_to_u32 ((const u8 *) &digest_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &digest_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &digest_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &digest_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - return (PARSER_OK); -} - -int peoplesoft_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_133) || (input_len > DISPLAY_LEN_MAX_133)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - u8 tmp_buf[100] = { 0 }; - - base64_decode (base64_to_int, (const u8 *) input_buf, input_len, tmp_buf); - - memcpy (digest, tmp_buf, 20); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - salt->salt_buf[0] = 0x80; - - salt->salt_len = 0; - - return (PARSER_OK); -} - -int skype_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_23) || (input_len > DISPLAY_LEN_MAX_23)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - if (input_buf[32] != ':') return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 32 - 1; - - char *salt_buf = input_buf + 32 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - /* - * add static "salt" part - */ - - memcpy (salt_buf_ptr + salt_len, "\nskyper\n", 8); - - salt_len += 8; - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int androidfde_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_8800) || (input_len > DISPLAY_LEN_MAX_8800)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_ANDROIDFDE, input_buf, 5)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - androidfde_t *androidfde = (androidfde_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *saltlen_pos = input_buf + 1 + 3 + 1; - - char *saltbuf_pos = strchr (saltlen_pos, '$'); - - if (saltbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint saltlen_len = saltbuf_pos - saltlen_pos; - - if (saltlen_len != 2) return (PARSER_SALT_LENGTH); - - saltbuf_pos++; - - char *keylen_pos = strchr (saltbuf_pos, '$'); - - if (keylen_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint saltbuf_len = keylen_pos - saltbuf_pos; - - if (saltbuf_len != 32) return (PARSER_SALT_LENGTH); - - keylen_pos++; - - char *keybuf_pos = strchr (keylen_pos, '$'); - - if (keybuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint keylen_len = keybuf_pos - keylen_pos; - - if (keylen_len != 2) return (PARSER_SALT_LENGTH); - - keybuf_pos++; - - char *databuf_pos = strchr (keybuf_pos, '$'); - - if (databuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint keybuf_len = databuf_pos - keybuf_pos; - - if (keybuf_len != 32) return (PARSER_SALT_LENGTH); - - databuf_pos++; - - uint data_len = input_len - 1 - 3 - 1 - saltlen_len - 1 - saltbuf_len - 1 - keylen_len - 1 - keybuf_len - 1; - - if (data_len != 3072) return (PARSER_SALT_LENGTH); - - /** - * copy data - */ - - digest[0] = hex_to_u32 ((const u8 *) &keybuf_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &keybuf_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &keybuf_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &keybuf_pos[24]); - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &saltbuf_pos[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &saltbuf_pos[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &saltbuf_pos[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &saltbuf_pos[24]); - - salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); - salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); - salt->salt_buf[2] = byte_swap_32 (salt->salt_buf[2]); - salt->salt_buf[3] = byte_swap_32 (salt->salt_buf[3]); - - salt->salt_len = 16; - salt->salt_iter = ROUNDS_ANDROIDFDE - 1; - - for (uint i = 0, j = 0; i < 3072; i += 8, j += 1) - { - androidfde->data[j] = hex_to_u32 ((const u8 *) &databuf_pos[i]); - } - - return (PARSER_OK); -} - -int scrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_8900) || (input_len > DISPLAY_LEN_MAX_8900)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SCRYPT, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - /** - * parse line - */ - - // first is the N salt parameter - - char *N_pos = input_buf + 6; - - if (N_pos[0] != ':') return (PARSER_SEPARATOR_UNMATCHED); - - N_pos++; - - salt->scrypt_N = atoi (N_pos); - - // r - - char *r_pos = strchr (N_pos, ':'); - - if (r_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - r_pos++; - - salt->scrypt_r = atoi (r_pos); - - // p - - char *p_pos = strchr (r_pos, ':'); - - if (p_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - p_pos++; - - salt->scrypt_p = atoi (p_pos); - - // salt - - char *saltbuf_pos = strchr (p_pos, ':'); - - if (saltbuf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - saltbuf_pos++; - - char *hash_pos = strchr (saltbuf_pos, ':'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - hash_pos++; - - // base64 decode - - int salt_len_base64 = hash_pos - saltbuf_pos; - - if (salt_len_base64 > 45) return (PARSER_SALT_LENGTH); - - u8 tmp_buf[33] = { 0 }; - - int tmp_len = base64_decode (base64_to_int, (const u8 *) saltbuf_pos, salt_len_base64, tmp_buf); - - char *salt_buf_ptr = (char *) salt->salt_buf; - - memcpy (salt_buf_ptr, tmp_buf, tmp_len); - - salt->salt_len = tmp_len; - salt->salt_iter = 1; - - // digest - base64 decode - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - tmp_len = input_len - (hash_pos - input_buf); - - if (tmp_len != 44) return (PARSER_GLOBAL_LENGTH); - - base64_decode (base64_to_int, (const u8 *) hash_pos, tmp_len, tmp_buf); - - memcpy (digest, tmp_buf, 32); - - return (PARSER_OK); -} - -int juniper_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_501) || (input_len > DISPLAY_LEN_MAX_501)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - /** - * parse line - */ - - char decrypted[76] = { 0 }; // iv + hash - - juniper_decrypt_hash (input_buf, decrypted); - - char *md5crypt_hash = decrypted + 12; - - if (memcmp (md5crypt_hash, "$1$danastre$", 12)) return (PARSER_SALT_VALUE); - - salt->salt_iter = ROUNDS_MD5CRYPT; - - char *salt_pos = md5crypt_hash + 3; - - char *hash_pos = strchr (salt_pos, '$'); // or simply salt_pos + 8 - - salt->salt_len = hash_pos - salt_pos; // should be 8 - - memcpy ((char *) salt->salt_buf, salt_pos, salt->salt_len); - - hash_pos++; - - md5crypt_decode ((unsigned char *) digest, (unsigned char *) hash_pos); - - return (PARSER_OK); -} - -int cisco8_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_9200) || (input_len > DISPLAY_LEN_MAX_9200)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_CISCO8, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pbkdf2_sha256_t *pbkdf2_sha256 = (pbkdf2_sha256_t *) hash_buf->esalt; - - /** - * parse line - */ - - // first is *raw* salt - - char *salt_pos = input_buf + 3; - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - if (salt_len != 14) return (PARSER_SALT_LENGTH); - - hash_pos++; - - char *salt_buf_ptr = (char *) pbkdf2_sha256->salt_buf; - - memcpy (salt_buf_ptr, salt_pos, 14); - - salt_buf_ptr[17] = 0x01; - salt_buf_ptr[18] = 0x80; - - // add some stuff to normal salt to make sorted happy - - salt->salt_buf[0] = pbkdf2_sha256->salt_buf[0]; - salt->salt_buf[1] = pbkdf2_sha256->salt_buf[1]; - salt->salt_buf[2] = pbkdf2_sha256->salt_buf[2]; - salt->salt_buf[3] = pbkdf2_sha256->salt_buf[3]; - - salt->salt_len = salt_len; - salt->salt_iter = ROUNDS_CISCO8 - 1; - - // base64 decode hash - - u8 tmp_buf[100] = { 0 }; - - uint hash_len = input_len - 3 - salt_len - 1; - - int tmp_len = base64_decode (itoa64_to_int, (const u8 *) hash_pos, hash_len, tmp_buf); - - if (tmp_len != 32) return (PARSER_HASH_LENGTH); - - memcpy (digest, tmp_buf, 32); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - digest[5] = byte_swap_32 (digest[5]); - digest[6] = byte_swap_32 (digest[6]); - digest[7] = byte_swap_32 (digest[7]); - - return (PARSER_OK); -} - -int cisco9_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_9300) || (input_len > DISPLAY_LEN_MAX_9300)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_CISCO9, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - /** - * parse line - */ - - // first is *raw* salt - - char *salt_pos = input_buf + 3; - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - if (salt_len != 14) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - hash_pos++; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - memcpy (salt_buf_ptr, salt_pos, salt_len); - salt_buf_ptr[salt_len] = 0; - - // base64 decode hash - - u8 tmp_buf[100] = { 0 }; - - uint hash_len = input_len - 3 - salt_len - 1; - - int tmp_len = base64_decode (itoa64_to_int, (const u8 *) hash_pos, hash_len, tmp_buf); - - if (tmp_len != 32) return (PARSER_HASH_LENGTH); - - memcpy (digest, tmp_buf, 32); - - // fixed: - salt->scrypt_N = 16384; - salt->scrypt_r = 1; - salt->scrypt_p = 1; - salt->salt_iter = 1; - - return (PARSER_OK); -} - -int office2007_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_9400) || (input_len > DISPLAY_LEN_MAX_9400)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_OFFICE2007, input_buf, 8)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - office2007_t *office2007 = (office2007_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *version_pos = input_buf + 8 + 1; - - char *verifierHashSize_pos = strchr (version_pos, '*'); - - if (verifierHashSize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 version_len = verifierHashSize_pos - version_pos; - - if (version_len != 4) return (PARSER_SALT_LENGTH); - - verifierHashSize_pos++; - - char *keySize_pos = strchr (verifierHashSize_pos, '*'); - - if (keySize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 verifierHashSize_len = keySize_pos - verifierHashSize_pos; - - if (verifierHashSize_len != 2) return (PARSER_SALT_LENGTH); - - keySize_pos++; - - char *saltSize_pos = strchr (keySize_pos, '*'); - - if (saltSize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 keySize_len = saltSize_pos - keySize_pos; - - if (keySize_len != 3) return (PARSER_SALT_LENGTH); - - saltSize_pos++; - - char *osalt_pos = strchr (saltSize_pos, '*'); - - if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 saltSize_len = osalt_pos - saltSize_pos; - - if (saltSize_len != 2) return (PARSER_SALT_LENGTH); - - osalt_pos++; - - char *encryptedVerifier_pos = strchr (osalt_pos, '*'); - - if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 osalt_len = encryptedVerifier_pos - osalt_pos; - - if (osalt_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifier_pos++; - - char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); - - if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; - - if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifierHash_pos++; - - u32 encryptedVerifierHash_len = input_len - 8 - 1 - version_len - 1 - verifierHashSize_len - 1 - keySize_len - 1 - saltSize_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1; - - if (encryptedVerifierHash_len != 40) return (PARSER_SALT_LENGTH); - - const uint version = atoi (version_pos); - - if (version != 2007) return (PARSER_SALT_VALUE); - - const uint verifierHashSize = atoi (verifierHashSize_pos); - - if (verifierHashSize != 20) return (PARSER_SALT_VALUE); - - const uint keySize = atoi (keySize_pos); - - if ((keySize != 128) && (keySize != 256)) return (PARSER_SALT_VALUE); - - office2007->keySize = keySize; - - const uint saltSize = atoi (saltSize_pos); - - if (saltSize != 16) return (PARSER_SALT_VALUE); - - /** - * salt - */ - - salt->salt_len = 16; - salt->salt_iter = ROUNDS_OFFICE2007; - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); - - /** - * esalt - */ - - office2007->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); - office2007->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); - office2007->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); - office2007->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); - - office2007->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); - office2007->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); - office2007->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); - office2007->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); - office2007->encryptedVerifierHash[4] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[32]); - - /** - * digest - */ - - digest[0] = office2007->encryptedVerifierHash[0]; - digest[1] = office2007->encryptedVerifierHash[1]; - digest[2] = office2007->encryptedVerifierHash[2]; - digest[3] = office2007->encryptedVerifierHash[3]; - - return (PARSER_OK); -} - -int office2010_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_9500) || (input_len > DISPLAY_LEN_MAX_9500)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_OFFICE2010, input_buf, 8)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - office2010_t *office2010 = (office2010_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *version_pos = input_buf + 8 + 1; - - char *spinCount_pos = strchr (version_pos, '*'); - - if (spinCount_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 version_len = spinCount_pos - version_pos; - - if (version_len != 4) return (PARSER_SALT_LENGTH); - - spinCount_pos++; - - char *keySize_pos = strchr (spinCount_pos, '*'); - - if (keySize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 spinCount_len = keySize_pos - spinCount_pos; - - if (spinCount_len != 6) return (PARSER_SALT_LENGTH); - - keySize_pos++; - - char *saltSize_pos = strchr (keySize_pos, '*'); - - if (saltSize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 keySize_len = saltSize_pos - keySize_pos; - - if (keySize_len != 3) return (PARSER_SALT_LENGTH); - - saltSize_pos++; - - char *osalt_pos = strchr (saltSize_pos, '*'); - - if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 saltSize_len = osalt_pos - saltSize_pos; - - if (saltSize_len != 2) return (PARSER_SALT_LENGTH); - - osalt_pos++; - - char *encryptedVerifier_pos = strchr (osalt_pos, '*'); - - if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 osalt_len = encryptedVerifier_pos - osalt_pos; - - if (osalt_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifier_pos++; - - char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); - - if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; - - if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifierHash_pos++; - - u32 encryptedVerifierHash_len = input_len - 8 - 1 - version_len - 1 - spinCount_len - 1 - keySize_len - 1 - saltSize_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1; - - if (encryptedVerifierHash_len != 64) return (PARSER_SALT_LENGTH); - - const uint version = atoi (version_pos); - - if (version != 2010) return (PARSER_SALT_VALUE); - - const uint spinCount = atoi (spinCount_pos); - - if (spinCount != 100000) return (PARSER_SALT_VALUE); - - const uint keySize = atoi (keySize_pos); - - if (keySize != 128) return (PARSER_SALT_VALUE); - - const uint saltSize = atoi (saltSize_pos); - - if (saltSize != 16) return (PARSER_SALT_VALUE); - - /** - * salt - */ - - salt->salt_len = 16; - salt->salt_iter = spinCount; - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); - - /** - * esalt - */ - - office2010->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); - office2010->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); - office2010->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); - office2010->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); - - office2010->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); - office2010->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); - office2010->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); - office2010->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); - office2010->encryptedVerifierHash[4] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[32]); - office2010->encryptedVerifierHash[5] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[40]); - office2010->encryptedVerifierHash[6] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[48]); - office2010->encryptedVerifierHash[7] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[56]); - - /** - * digest - */ - - digest[0] = office2010->encryptedVerifierHash[0]; - digest[1] = office2010->encryptedVerifierHash[1]; - digest[2] = office2010->encryptedVerifierHash[2]; - digest[3] = office2010->encryptedVerifierHash[3]; - - return (PARSER_OK); -} - -int office2013_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_9600) || (input_len > DISPLAY_LEN_MAX_9600)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_OFFICE2013, input_buf, 8)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - office2013_t *office2013 = (office2013_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *version_pos = input_buf + 8 + 1; - - char *spinCount_pos = strchr (version_pos, '*'); - - if (spinCount_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 version_len = spinCount_pos - version_pos; - - if (version_len != 4) return (PARSER_SALT_LENGTH); - - spinCount_pos++; - - char *keySize_pos = strchr (spinCount_pos, '*'); - - if (keySize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 spinCount_len = keySize_pos - spinCount_pos; - - if (spinCount_len != 6) return (PARSER_SALT_LENGTH); - - keySize_pos++; - - char *saltSize_pos = strchr (keySize_pos, '*'); - - if (saltSize_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 keySize_len = saltSize_pos - keySize_pos; - - if (keySize_len != 3) return (PARSER_SALT_LENGTH); - - saltSize_pos++; - - char *osalt_pos = strchr (saltSize_pos, '*'); - - if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 saltSize_len = osalt_pos - saltSize_pos; - - if (saltSize_len != 2) return (PARSER_SALT_LENGTH); - - osalt_pos++; - - char *encryptedVerifier_pos = strchr (osalt_pos, '*'); - - if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 osalt_len = encryptedVerifier_pos - osalt_pos; - - if (osalt_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifier_pos++; - - char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); - - if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; - - if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifierHash_pos++; - - u32 encryptedVerifierHash_len = input_len - 8 - 1 - version_len - 1 - spinCount_len - 1 - keySize_len - 1 - saltSize_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1; - - if (encryptedVerifierHash_len != 64) return (PARSER_SALT_LENGTH); - - const uint version = atoi (version_pos); - - if (version != 2013) return (PARSER_SALT_VALUE); - - const uint spinCount = atoi (spinCount_pos); - - if (spinCount != 100000) return (PARSER_SALT_VALUE); - - const uint keySize = atoi (keySize_pos); - - if (keySize != 256) return (PARSER_SALT_VALUE); - - const uint saltSize = atoi (saltSize_pos); - - if (saltSize != 16) return (PARSER_SALT_VALUE); - - /** - * salt - */ - - salt->salt_len = 16; - salt->salt_iter = spinCount; - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); - - /** - * esalt - */ - - office2013->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); - office2013->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); - office2013->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); - office2013->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); - - office2013->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); - office2013->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); - office2013->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); - office2013->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); - office2013->encryptedVerifierHash[4] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[32]); - office2013->encryptedVerifierHash[5] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[40]); - office2013->encryptedVerifierHash[6] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[48]); - office2013->encryptedVerifierHash[7] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[56]); - - /** - * digest - */ - - digest[0] = office2013->encryptedVerifierHash[0]; - digest[1] = office2013->encryptedVerifierHash[1]; - digest[2] = office2013->encryptedVerifierHash[2]; - digest[3] = office2013->encryptedVerifierHash[3]; - - return (PARSER_OK); -} - -int oldoffice01_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_9700) || (input_len > DISPLAY_LEN_MAX_9700)) return (PARSER_GLOBAL_LENGTH); - - if ((memcmp (SIGNATURE_OLDOFFICE0, input_buf, 12)) && (memcmp (SIGNATURE_OLDOFFICE1, input_buf, 12))) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - oldoffice01_t *oldoffice01 = (oldoffice01_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *version_pos = input_buf + 11; - - char *osalt_pos = strchr (version_pos, '*'); - - if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 version_len = osalt_pos - version_pos; - - if (version_len != 1) return (PARSER_SALT_LENGTH); - - osalt_pos++; - - char *encryptedVerifier_pos = strchr (osalt_pos, '*'); - - if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 osalt_len = encryptedVerifier_pos - osalt_pos; - - if (osalt_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifier_pos++; - - char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); - - if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; - - if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifierHash_pos++; - - u32 encryptedVerifierHash_len = input_len - 11 - version_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1; - - if (encryptedVerifierHash_len != 32) return (PARSER_SALT_LENGTH); - - const uint version = *version_pos - 0x30; - - if (version != 0 && version != 1) return (PARSER_SALT_VALUE); - - /** - * esalt - */ - - oldoffice01->version = version; - - oldoffice01->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); - oldoffice01->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); - oldoffice01->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); - oldoffice01->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); - - oldoffice01->encryptedVerifier[0] = byte_swap_32 (oldoffice01->encryptedVerifier[0]); - oldoffice01->encryptedVerifier[1] = byte_swap_32 (oldoffice01->encryptedVerifier[1]); - oldoffice01->encryptedVerifier[2] = byte_swap_32 (oldoffice01->encryptedVerifier[2]); - oldoffice01->encryptedVerifier[3] = byte_swap_32 (oldoffice01->encryptedVerifier[3]); - - oldoffice01->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); - oldoffice01->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); - oldoffice01->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); - oldoffice01->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); - - oldoffice01->encryptedVerifierHash[0] = byte_swap_32 (oldoffice01->encryptedVerifierHash[0]); - oldoffice01->encryptedVerifierHash[1] = byte_swap_32 (oldoffice01->encryptedVerifierHash[1]); - oldoffice01->encryptedVerifierHash[2] = byte_swap_32 (oldoffice01->encryptedVerifierHash[2]); - oldoffice01->encryptedVerifierHash[3] = byte_swap_32 (oldoffice01->encryptedVerifierHash[3]); - - /** - * salt - */ - - salt->salt_len = 16; - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); - - salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); - salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); - salt->salt_buf[2] = byte_swap_32 (salt->salt_buf[2]); - salt->salt_buf[3] = byte_swap_32 (salt->salt_buf[3]); - - // this is a workaround as office produces multiple documents with the same salt - - salt->salt_len += 32; - - salt->salt_buf[ 4] = oldoffice01->encryptedVerifier[0]; - salt->salt_buf[ 5] = oldoffice01->encryptedVerifier[1]; - salt->salt_buf[ 6] = oldoffice01->encryptedVerifier[2]; - salt->salt_buf[ 7] = oldoffice01->encryptedVerifier[3]; - salt->salt_buf[ 8] = oldoffice01->encryptedVerifierHash[0]; - salt->salt_buf[ 9] = oldoffice01->encryptedVerifierHash[1]; - salt->salt_buf[10] = oldoffice01->encryptedVerifierHash[2]; - salt->salt_buf[11] = oldoffice01->encryptedVerifierHash[3]; - - /** - * digest - */ - - digest[0] = oldoffice01->encryptedVerifierHash[0]; - digest[1] = oldoffice01->encryptedVerifierHash[1]; - digest[2] = oldoffice01->encryptedVerifierHash[2]; - digest[3] = oldoffice01->encryptedVerifierHash[3]; - - return (PARSER_OK); -} - -int oldoffice01cm1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - return oldoffice01_parse_hash (input_buf, input_len, hash_buf); -} - -int oldoffice01cm2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_9720) || (input_len > DISPLAY_LEN_MAX_9720)) return (PARSER_GLOBAL_LENGTH); - - if ((memcmp (SIGNATURE_OLDOFFICE0, input_buf, 12)) && (memcmp (SIGNATURE_OLDOFFICE1, input_buf, 12))) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - oldoffice01_t *oldoffice01 = (oldoffice01_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *version_pos = input_buf + 11; - - char *osalt_pos = strchr (version_pos, '*'); - - if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 version_len = osalt_pos - version_pos; - - if (version_len != 1) return (PARSER_SALT_LENGTH); - - osalt_pos++; - - char *encryptedVerifier_pos = strchr (osalt_pos, '*'); - - if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 osalt_len = encryptedVerifier_pos - osalt_pos; - - if (osalt_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifier_pos++; - - char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); - - if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; - - if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifierHash_pos++; - - char *rc4key_pos = strchr (encryptedVerifierHash_pos, ':'); - - if (rc4key_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 encryptedVerifierHash_len = rc4key_pos - encryptedVerifierHash_pos; - - if (encryptedVerifierHash_len != 32) return (PARSER_SALT_LENGTH); - - rc4key_pos++; - - u32 rc4key_len = input_len - 11 - version_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1 - encryptedVerifierHash_len - 1; - - if (rc4key_len != 10) return (PARSER_SALT_LENGTH); - - const uint version = *version_pos - 0x30; - - if (version != 0 && version != 1) return (PARSER_SALT_VALUE); - - /** - * esalt - */ - - oldoffice01->version = version; - - oldoffice01->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); - oldoffice01->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); - oldoffice01->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); - oldoffice01->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); - - oldoffice01->encryptedVerifier[0] = byte_swap_32 (oldoffice01->encryptedVerifier[0]); - oldoffice01->encryptedVerifier[1] = byte_swap_32 (oldoffice01->encryptedVerifier[1]); - oldoffice01->encryptedVerifier[2] = byte_swap_32 (oldoffice01->encryptedVerifier[2]); - oldoffice01->encryptedVerifier[3] = byte_swap_32 (oldoffice01->encryptedVerifier[3]); - - oldoffice01->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); - oldoffice01->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); - oldoffice01->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); - oldoffice01->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); - - oldoffice01->encryptedVerifierHash[0] = byte_swap_32 (oldoffice01->encryptedVerifierHash[0]); - oldoffice01->encryptedVerifierHash[1] = byte_swap_32 (oldoffice01->encryptedVerifierHash[1]); - oldoffice01->encryptedVerifierHash[2] = byte_swap_32 (oldoffice01->encryptedVerifierHash[2]); - oldoffice01->encryptedVerifierHash[3] = byte_swap_32 (oldoffice01->encryptedVerifierHash[3]); - - oldoffice01->rc4key[1] = 0; - oldoffice01->rc4key[0] = 0; - - oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[0]) << 28; - oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[1]) << 24; - oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[2]) << 20; - oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[3]) << 16; - oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[4]) << 12; - oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[5]) << 8; - oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[6]) << 4; - oldoffice01->rc4key[0] |= hex_convert (rc4key_pos[7]) << 0; - oldoffice01->rc4key[1] |= hex_convert (rc4key_pos[8]) << 28; - oldoffice01->rc4key[1] |= hex_convert (rc4key_pos[9]) << 24; - - oldoffice01->rc4key[0] = byte_swap_32 (oldoffice01->rc4key[0]); - oldoffice01->rc4key[1] = byte_swap_32 (oldoffice01->rc4key[1]); - - /** - * salt - */ - - salt->salt_len = 16; - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); - - salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); - salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); - salt->salt_buf[2] = byte_swap_32 (salt->salt_buf[2]); - salt->salt_buf[3] = byte_swap_32 (salt->salt_buf[3]); - - // this is a workaround as office produces multiple documents with the same salt - - salt->salt_len += 32; - - salt->salt_buf[ 4] = oldoffice01->encryptedVerifier[0]; - salt->salt_buf[ 5] = oldoffice01->encryptedVerifier[1]; - salt->salt_buf[ 6] = oldoffice01->encryptedVerifier[2]; - salt->salt_buf[ 7] = oldoffice01->encryptedVerifier[3]; - salt->salt_buf[ 8] = oldoffice01->encryptedVerifierHash[0]; - salt->salt_buf[ 9] = oldoffice01->encryptedVerifierHash[1]; - salt->salt_buf[10] = oldoffice01->encryptedVerifierHash[2]; - salt->salt_buf[11] = oldoffice01->encryptedVerifierHash[3]; - - /** - * digest - */ - - digest[0] = oldoffice01->rc4key[0]; - digest[1] = oldoffice01->rc4key[1]; - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int oldoffice34_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_9800) || (input_len > DISPLAY_LEN_MAX_9800)) return (PARSER_GLOBAL_LENGTH); - - if ((memcmp (SIGNATURE_OLDOFFICE3, input_buf, 12)) && (memcmp (SIGNATURE_OLDOFFICE4, input_buf, 12))) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - oldoffice34_t *oldoffice34 = (oldoffice34_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *version_pos = input_buf + 11; - - char *osalt_pos = strchr (version_pos, '*'); - - if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 version_len = osalt_pos - version_pos; - - if (version_len != 1) return (PARSER_SALT_LENGTH); - - osalt_pos++; - - char *encryptedVerifier_pos = strchr (osalt_pos, '*'); - - if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 osalt_len = encryptedVerifier_pos - osalt_pos; - - if (osalt_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifier_pos++; - - char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); - - if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; - - if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifierHash_pos++; - - u32 encryptedVerifierHash_len = input_len - 11 - version_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1; - - if (encryptedVerifierHash_len != 40) return (PARSER_SALT_LENGTH); - - const uint version = *version_pos - 0x30; - - if (version != 3 && version != 4) return (PARSER_SALT_VALUE); - - /** - * esalt - */ - - oldoffice34->version = version; - - oldoffice34->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); - oldoffice34->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); - oldoffice34->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); - oldoffice34->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); - - oldoffice34->encryptedVerifier[0] = byte_swap_32 (oldoffice34->encryptedVerifier[0]); - oldoffice34->encryptedVerifier[1] = byte_swap_32 (oldoffice34->encryptedVerifier[1]); - oldoffice34->encryptedVerifier[2] = byte_swap_32 (oldoffice34->encryptedVerifier[2]); - oldoffice34->encryptedVerifier[3] = byte_swap_32 (oldoffice34->encryptedVerifier[3]); - - oldoffice34->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); - oldoffice34->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); - oldoffice34->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); - oldoffice34->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); - oldoffice34->encryptedVerifierHash[4] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[32]); - - oldoffice34->encryptedVerifierHash[0] = byte_swap_32 (oldoffice34->encryptedVerifierHash[0]); - oldoffice34->encryptedVerifierHash[1] = byte_swap_32 (oldoffice34->encryptedVerifierHash[1]); - oldoffice34->encryptedVerifierHash[2] = byte_swap_32 (oldoffice34->encryptedVerifierHash[2]); - oldoffice34->encryptedVerifierHash[3] = byte_swap_32 (oldoffice34->encryptedVerifierHash[3]); - oldoffice34->encryptedVerifierHash[4] = byte_swap_32 (oldoffice34->encryptedVerifierHash[4]); - - /** - * salt - */ - - salt->salt_len = 16; - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); - - // this is a workaround as office produces multiple documents with the same salt - - salt->salt_len += 32; - - salt->salt_buf[ 4] = oldoffice34->encryptedVerifier[0]; - salt->salt_buf[ 5] = oldoffice34->encryptedVerifier[1]; - salt->salt_buf[ 6] = oldoffice34->encryptedVerifier[2]; - salt->salt_buf[ 7] = oldoffice34->encryptedVerifier[3]; - salt->salt_buf[ 8] = oldoffice34->encryptedVerifierHash[0]; - salt->salt_buf[ 9] = oldoffice34->encryptedVerifierHash[1]; - salt->salt_buf[10] = oldoffice34->encryptedVerifierHash[2]; - salt->salt_buf[11] = oldoffice34->encryptedVerifierHash[3]; - - /** - * digest - */ - - digest[0] = oldoffice34->encryptedVerifierHash[0]; - digest[1] = oldoffice34->encryptedVerifierHash[1]; - digest[2] = oldoffice34->encryptedVerifierHash[2]; - digest[3] = oldoffice34->encryptedVerifierHash[3]; - - return (PARSER_OK); -} - -int oldoffice34cm1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if (memcmp (SIGNATURE_OLDOFFICE3, input_buf, 12)) return (PARSER_SIGNATURE_UNMATCHED); - - return oldoffice34_parse_hash (input_buf, input_len, hash_buf); -} - -int oldoffice34cm2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_9820) || (input_len > DISPLAY_LEN_MAX_9820)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_OLDOFFICE3, input_buf, 12)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - oldoffice34_t *oldoffice34 = (oldoffice34_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *version_pos = input_buf + 11; - - char *osalt_pos = strchr (version_pos, '*'); - - if (osalt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 version_len = osalt_pos - version_pos; - - if (version_len != 1) return (PARSER_SALT_LENGTH); - - osalt_pos++; - - char *encryptedVerifier_pos = strchr (osalt_pos, '*'); - - if (encryptedVerifier_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 osalt_len = encryptedVerifier_pos - osalt_pos; - - if (osalt_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifier_pos++; - - char *encryptedVerifierHash_pos = strchr (encryptedVerifier_pos, '*'); - - if (encryptedVerifierHash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 encryptedVerifier_len = encryptedVerifierHash_pos - encryptedVerifier_pos; - - if (encryptedVerifier_len != 32) return (PARSER_SALT_LENGTH); - - encryptedVerifierHash_pos++; - - char *rc4key_pos = strchr (encryptedVerifierHash_pos, ':'); - - if (rc4key_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 encryptedVerifierHash_len = rc4key_pos - encryptedVerifierHash_pos; - - if (encryptedVerifierHash_len != 40) return (PARSER_SALT_LENGTH); - - rc4key_pos++; - - u32 rc4key_len = input_len - 11 - version_len - 1 - osalt_len - 1 - encryptedVerifier_len - 1 - encryptedVerifierHash_len - 1; - - if (rc4key_len != 10) return (PARSER_SALT_LENGTH); - - const uint version = *version_pos - 0x30; - - if (version != 3 && version != 4) return (PARSER_SALT_VALUE); - - /** - * esalt - */ - - oldoffice34->version = version; - - oldoffice34->encryptedVerifier[0] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 0]); - oldoffice34->encryptedVerifier[1] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[ 8]); - oldoffice34->encryptedVerifier[2] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[16]); - oldoffice34->encryptedVerifier[3] = hex_to_u32 ((const u8 *) &encryptedVerifier_pos[24]); - - oldoffice34->encryptedVerifier[0] = byte_swap_32 (oldoffice34->encryptedVerifier[0]); - oldoffice34->encryptedVerifier[1] = byte_swap_32 (oldoffice34->encryptedVerifier[1]); - oldoffice34->encryptedVerifier[2] = byte_swap_32 (oldoffice34->encryptedVerifier[2]); - oldoffice34->encryptedVerifier[3] = byte_swap_32 (oldoffice34->encryptedVerifier[3]); - - oldoffice34->encryptedVerifierHash[0] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 0]); - oldoffice34->encryptedVerifierHash[1] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[ 8]); - oldoffice34->encryptedVerifierHash[2] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[16]); - oldoffice34->encryptedVerifierHash[3] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[24]); - oldoffice34->encryptedVerifierHash[4] = hex_to_u32 ((const u8 *) &encryptedVerifierHash_pos[32]); - - oldoffice34->encryptedVerifierHash[0] = byte_swap_32 (oldoffice34->encryptedVerifierHash[0]); - oldoffice34->encryptedVerifierHash[1] = byte_swap_32 (oldoffice34->encryptedVerifierHash[1]); - oldoffice34->encryptedVerifierHash[2] = byte_swap_32 (oldoffice34->encryptedVerifierHash[2]); - oldoffice34->encryptedVerifierHash[3] = byte_swap_32 (oldoffice34->encryptedVerifierHash[3]); - oldoffice34->encryptedVerifierHash[4] = byte_swap_32 (oldoffice34->encryptedVerifierHash[4]); - - oldoffice34->rc4key[1] = 0; - oldoffice34->rc4key[0] = 0; - - oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[0]) << 28; - oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[1]) << 24; - oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[2]) << 20; - oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[3]) << 16; - oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[4]) << 12; - oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[5]) << 8; - oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[6]) << 4; - oldoffice34->rc4key[0] |= hex_convert (rc4key_pos[7]) << 0; - oldoffice34->rc4key[1] |= hex_convert (rc4key_pos[8]) << 28; - oldoffice34->rc4key[1] |= hex_convert (rc4key_pos[9]) << 24; - - oldoffice34->rc4key[0] = byte_swap_32 (oldoffice34->rc4key[0]); - oldoffice34->rc4key[1] = byte_swap_32 (oldoffice34->rc4key[1]); - - /** - * salt - */ - - salt->salt_len = 16; - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &osalt_pos[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &osalt_pos[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &osalt_pos[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &osalt_pos[24]); - - // this is a workaround as office produces multiple documents with the same salt - - salt->salt_len += 32; - - salt->salt_buf[ 4] = oldoffice34->encryptedVerifier[0]; - salt->salt_buf[ 5] = oldoffice34->encryptedVerifier[1]; - salt->salt_buf[ 6] = oldoffice34->encryptedVerifier[2]; - salt->salt_buf[ 7] = oldoffice34->encryptedVerifier[3]; - salt->salt_buf[ 8] = oldoffice34->encryptedVerifierHash[0]; - salt->salt_buf[ 9] = oldoffice34->encryptedVerifierHash[1]; - salt->salt_buf[10] = oldoffice34->encryptedVerifierHash[2]; - salt->salt_buf[11] = oldoffice34->encryptedVerifierHash[3]; - - /** - * digest - */ - - digest[0] = oldoffice34->rc4key[0]; - digest[1] = oldoffice34->rc4key[1]; - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int radmin2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_9900) || (input_len > DISPLAY_LEN_MAX_9900)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - return (PARSER_OK); -} - -int djangosha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_124) || (input_len > DISPLAY_LEN_MAX_124)) return (PARSER_GLOBAL_LENGTH); - - if ((memcmp (SIGNATURE_DJANGOSHA1, input_buf, 5)) && (memcmp (SIGNATURE_DJANGOSHA1, input_buf, 5))) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *signature_pos = input_buf; - - char *salt_pos = strchr (signature_pos, '$'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 signature_len = salt_pos - signature_pos; - - if (signature_len != 4) return (PARSER_SIGNATURE_UNMATCHED); - - salt_pos++; - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 salt_len = hash_pos - salt_pos; - - if (salt_len > 32) return (PARSER_SALT_LENGTH); - - hash_pos++; - - u32 hash_len = input_len - signature_len - 1 - salt_len - 1; - - if (hash_len != 40) return (PARSER_SALT_LENGTH); - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); - - digest[0] -= SHA1M_A; - digest[1] -= SHA1M_B; - digest[2] -= SHA1M_C; - digest[3] -= SHA1M_D; - digest[4] -= SHA1M_E; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - memcpy (salt_buf_ptr, salt_pos, salt_len); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int djangopbkdf2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_10000) || (input_len > DISPLAY_LEN_MAX_10000)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_DJANGOPBKDF2, input_buf, 14)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pbkdf2_sha256_t *pbkdf2_sha256 = (pbkdf2_sha256_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *iter_pos = input_buf + 14; - - const int iter = atoi (iter_pos); - - if (iter < 1) return (PARSER_SALT_ITERATION); - - salt->salt_iter = iter - 1; - - char *salt_pos = strchr (iter_pos, '$'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - const uint salt_len = hash_pos - salt_pos; - - hash_pos++; - - char *salt_buf_ptr = (char *) pbkdf2_sha256->salt_buf; - - memcpy (salt_buf_ptr, salt_pos, salt_len); - - salt->salt_len = salt_len; - - salt_buf_ptr[salt_len + 3] = 0x01; - salt_buf_ptr[salt_len + 4] = 0x80; - - // add some stuff to normal salt to make sorted happy - - salt->salt_buf[0] = pbkdf2_sha256->salt_buf[0]; - salt->salt_buf[1] = pbkdf2_sha256->salt_buf[1]; - salt->salt_buf[2] = pbkdf2_sha256->salt_buf[2]; - salt->salt_buf[3] = pbkdf2_sha256->salt_buf[3]; - salt->salt_buf[4] = salt->salt_iter; - - // base64 decode hash - - u8 tmp_buf[100] = { 0 }; - - uint hash_len = input_len - (hash_pos - input_buf); - - if (hash_len != 44) return (PARSER_HASH_LENGTH); - - base64_decode (base64_to_int, (const u8 *) hash_pos, hash_len, tmp_buf); - - memcpy (digest, tmp_buf, 32); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - digest[5] = byte_swap_32 (digest[5]); - digest[6] = byte_swap_32 (digest[6]); - digest[7] = byte_swap_32 (digest[7]); - - return (PARSER_OK); -} - -int siphash_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_10100) || (input_len > DISPLAY_LEN_MAX_10100)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = 0; - digest[3] = 0; - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - - if (input_buf[16] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - if (input_buf[18] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - if (input_buf[20] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - char iter_c = input_buf[17]; - char iter_d = input_buf[19]; - - // atm only defaults, let's see if there's more request - if (iter_c != '2') return (PARSER_SALT_ITERATION); - if (iter_d != '4') return (PARSER_SALT_ITERATION); - - char *salt_buf = input_buf + 16 + 1 + 1 + 1 + 1 + 1; - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_buf[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_buf[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_buf[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &salt_buf[24]); - - salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); - salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); - salt->salt_buf[2] = byte_swap_32 (salt->salt_buf[2]); - salt->salt_buf[3] = byte_swap_32 (salt->salt_buf[3]); - - salt->salt_len = 16; - - return (PARSER_OK); -} - -int crammd5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_10200) || (input_len > DISPLAY_LEN_MAX_10200)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_CRAM_MD5, input_buf, 10)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - cram_md5_t *cram_md5 = (cram_md5_t *) hash_buf->esalt; - - salt_t *salt = hash_buf->salt; - - char *salt_pos = input_buf + 10; - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = hash_pos - salt_pos; - - hash_pos++; - - uint hash_len = input_len - 10 - salt_len - 1; - - // base64 decode salt - - if (salt_len > 133) return (PARSER_SALT_LENGTH); - - u8 tmp_buf[100] = { 0 }; - - salt_len = base64_decode (base64_to_int, (const u8 *) salt_pos, salt_len, tmp_buf); - - if (salt_len > 55) return (PARSER_SALT_LENGTH); - - tmp_buf[salt_len] = 0x80; - - memcpy (&salt->salt_buf, tmp_buf, salt_len + 1); - - salt->salt_len = salt_len; - - // base64 decode hash - - if (hash_len > 133) return (PARSER_HASH_LENGTH); - - memset (tmp_buf, 0, sizeof (tmp_buf)); - - hash_len = base64_decode (base64_to_int, (const u8 *) hash_pos, hash_len, tmp_buf); - - if (hash_len < 32 + 1) return (PARSER_HASH_LENGTH); - - uint user_len = hash_len - 32; - - const u8 *tmp_hash = tmp_buf + user_len; - - user_len--; // skip the trailing space - - digest[0] = hex_to_u32 (&tmp_hash[ 0]); - digest[1] = hex_to_u32 (&tmp_hash[ 8]); - digest[2] = hex_to_u32 (&tmp_hash[16]); - digest[3] = hex_to_u32 (&tmp_hash[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - // store username for host only (output hash if cracked) - - memset (cram_md5->user, 0, sizeof (cram_md5->user)); - memcpy (cram_md5->user, tmp_buf, user_len); - - return (PARSER_OK); -} - -int saph_sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_10300) || (input_len > DISPLAY_LEN_MAX_10300)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SAPH_SHA1, input_buf, 10)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *iter_pos = input_buf + 10; - - u32 iter = atoi (iter_pos); - - if (iter < 1) - { - return (PARSER_SALT_ITERATION); - } - - iter--; // first iteration is special - - salt->salt_iter = iter; - - char *base64_pos = strchr (iter_pos, '}'); - - if (base64_pos == NULL) - { - return (PARSER_SIGNATURE_UNMATCHED); - } - - base64_pos++; - - // base64 decode salt - - u32 base64_len = input_len - (base64_pos - input_buf); - - u8 tmp_buf[100] = { 0 }; - - u32 decoded_len = base64_decode (base64_to_int, (const u8 *) base64_pos, base64_len, tmp_buf); - - if (decoded_len < 24) - { - return (PARSER_SALT_LENGTH); - } - - // copy the salt - - uint salt_len = decoded_len - 20; - - if (salt_len < 4) return (PARSER_SALT_LENGTH); - if (salt_len > 16) return (PARSER_SALT_LENGTH); - - memcpy (&salt->salt_buf, tmp_buf + 20, salt_len); - - salt->salt_len = salt_len; - - // set digest - - u32 *digest_ptr = (u32*) tmp_buf; - - digest[0] = byte_swap_32 (digest_ptr[0]); - digest[1] = byte_swap_32 (digest_ptr[1]); - digest[2] = byte_swap_32 (digest_ptr[2]); - digest[3] = byte_swap_32 (digest_ptr[3]); - digest[4] = byte_swap_32 (digest_ptr[4]); - - return (PARSER_OK); -} - -int redmine_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_7600) || (input_len > DISPLAY_LEN_MAX_7600)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - - if (input_buf[40] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 40 - 1; - - char *salt_buf = input_buf + 40 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len != 32) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int pdf11_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_10400) || (input_len > DISPLAY_LEN_MAX_10400)) return (PARSER_GLOBAL_LENGTH); - - if ((memcmp (SIGNATURE_PDF, input_buf, 5)) && (memcmp (SIGNATURE_PDF, input_buf, 5))) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pdf_t *pdf = (pdf_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *V_pos = input_buf + 5; - - char *R_pos = strchr (V_pos, '*'); - - if (R_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 V_len = R_pos - V_pos; - - R_pos++; - - char *bits_pos = strchr (R_pos, '*'); - - if (bits_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 R_len = bits_pos - R_pos; - - bits_pos++; - - char *P_pos = strchr (bits_pos, '*'); - - if (P_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 bits_len = P_pos - bits_pos; - - P_pos++; - - char *enc_md_pos = strchr (P_pos, '*'); - - if (enc_md_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 P_len = enc_md_pos - P_pos; - - enc_md_pos++; - - char *id_len_pos = strchr (enc_md_pos, '*'); - - if (id_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 enc_md_len = id_len_pos - enc_md_pos; - - id_len_pos++; - - char *id_buf_pos = strchr (id_len_pos, '*'); - - if (id_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 id_len_len = id_buf_pos - id_len_pos; - - id_buf_pos++; - - char *u_len_pos = strchr (id_buf_pos, '*'); - - if (u_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 id_buf_len = u_len_pos - id_buf_pos; - - if (id_buf_len != 32) return (PARSER_SALT_LENGTH); - - u_len_pos++; - - char *u_buf_pos = strchr (u_len_pos, '*'); - - if (u_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 u_len_len = u_buf_pos - u_len_pos; - - u_buf_pos++; - - char *o_len_pos = strchr (u_buf_pos, '*'); - - if (o_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 u_buf_len = o_len_pos - u_buf_pos; - - if (u_buf_len != 64) return (PARSER_SALT_LENGTH); - - o_len_pos++; - - char *o_buf_pos = strchr (o_len_pos, '*'); - - if (o_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 o_len_len = o_buf_pos - o_len_pos; - - o_buf_pos++; - - u32 o_buf_len = input_len - 5 - V_len - 1 - R_len - 1 - bits_len - 1 - P_len - 1 - enc_md_len - 1 - id_len_len - 1 - id_buf_len - 1 - u_len_len - 1 - u_buf_len - 1 - o_len_len - 1; - - if (o_buf_len != 64) return (PARSER_SALT_LENGTH); - - // validate data - - const int V = atoi (V_pos); - const int R = atoi (R_pos); - const int P = atoi (P_pos); - - if (V != 1) return (PARSER_SALT_VALUE); - if (R != 2) return (PARSER_SALT_VALUE); - - const int enc_md = atoi (enc_md_pos); - - if ((enc_md != 0) && (enc_md != 1)) return (PARSER_SALT_VALUE); - - const int id_len = atoi (id_len_pos); - const int u_len = atoi (u_len_pos); - const int o_len = atoi (o_len_pos); - - if (id_len != 16) return (PARSER_SALT_VALUE); - if (u_len != 32) return (PARSER_SALT_VALUE); - if (o_len != 32) return (PARSER_SALT_VALUE); - - const int bits = atoi (bits_pos); - - if (bits != 40) return (PARSER_SALT_VALUE); - - // copy data to esalt - - pdf->V = V; - pdf->R = R; - pdf->P = P; - - pdf->enc_md = enc_md; - - pdf->id_buf[0] = hex_to_u32 ((const u8 *) &id_buf_pos[ 0]); - pdf->id_buf[1] = hex_to_u32 ((const u8 *) &id_buf_pos[ 8]); - pdf->id_buf[2] = hex_to_u32 ((const u8 *) &id_buf_pos[16]); - pdf->id_buf[3] = hex_to_u32 ((const u8 *) &id_buf_pos[24]); - pdf->id_len = id_len; - - pdf->u_buf[0] = hex_to_u32 ((const u8 *) &u_buf_pos[ 0]); - pdf->u_buf[1] = hex_to_u32 ((const u8 *) &u_buf_pos[ 8]); - pdf->u_buf[2] = hex_to_u32 ((const u8 *) &u_buf_pos[16]); - pdf->u_buf[3] = hex_to_u32 ((const u8 *) &u_buf_pos[24]); - pdf->u_buf[4] = hex_to_u32 ((const u8 *) &u_buf_pos[32]); - pdf->u_buf[5] = hex_to_u32 ((const u8 *) &u_buf_pos[40]); - pdf->u_buf[6] = hex_to_u32 ((const u8 *) &u_buf_pos[48]); - pdf->u_buf[7] = hex_to_u32 ((const u8 *) &u_buf_pos[56]); - pdf->u_len = u_len; - - pdf->o_buf[0] = hex_to_u32 ((const u8 *) &o_buf_pos[ 0]); - pdf->o_buf[1] = hex_to_u32 ((const u8 *) &o_buf_pos[ 8]); - pdf->o_buf[2] = hex_to_u32 ((const u8 *) &o_buf_pos[16]); - pdf->o_buf[3] = hex_to_u32 ((const u8 *) &o_buf_pos[24]); - pdf->o_buf[4] = hex_to_u32 ((const u8 *) &o_buf_pos[32]); - pdf->o_buf[5] = hex_to_u32 ((const u8 *) &o_buf_pos[40]); - pdf->o_buf[6] = hex_to_u32 ((const u8 *) &o_buf_pos[48]); - pdf->o_buf[7] = hex_to_u32 ((const u8 *) &o_buf_pos[56]); - pdf->o_len = o_len; - - pdf->id_buf[0] = byte_swap_32 (pdf->id_buf[0]); - pdf->id_buf[1] = byte_swap_32 (pdf->id_buf[1]); - pdf->id_buf[2] = byte_swap_32 (pdf->id_buf[2]); - pdf->id_buf[3] = byte_swap_32 (pdf->id_buf[3]); - - pdf->u_buf[0] = byte_swap_32 (pdf->u_buf[0]); - pdf->u_buf[1] = byte_swap_32 (pdf->u_buf[1]); - pdf->u_buf[2] = byte_swap_32 (pdf->u_buf[2]); - pdf->u_buf[3] = byte_swap_32 (pdf->u_buf[3]); - pdf->u_buf[4] = byte_swap_32 (pdf->u_buf[4]); - pdf->u_buf[5] = byte_swap_32 (pdf->u_buf[5]); - pdf->u_buf[6] = byte_swap_32 (pdf->u_buf[6]); - pdf->u_buf[7] = byte_swap_32 (pdf->u_buf[7]); - - pdf->o_buf[0] = byte_swap_32 (pdf->o_buf[0]); - pdf->o_buf[1] = byte_swap_32 (pdf->o_buf[1]); - pdf->o_buf[2] = byte_swap_32 (pdf->o_buf[2]); - pdf->o_buf[3] = byte_swap_32 (pdf->o_buf[3]); - pdf->o_buf[4] = byte_swap_32 (pdf->o_buf[4]); - pdf->o_buf[5] = byte_swap_32 (pdf->o_buf[5]); - pdf->o_buf[6] = byte_swap_32 (pdf->o_buf[6]); - pdf->o_buf[7] = byte_swap_32 (pdf->o_buf[7]); - - // we use ID for salt, maybe needs to change, we will see... - - salt->salt_buf[0] = pdf->id_buf[0]; - salt->salt_buf[1] = pdf->id_buf[1]; - salt->salt_buf[2] = pdf->id_buf[2]; - salt->salt_buf[3] = pdf->id_buf[3]; - salt->salt_len = pdf->id_len; - - digest[0] = pdf->u_buf[0]; - digest[1] = pdf->u_buf[1]; - digest[2] = pdf->u_buf[2]; - digest[3] = pdf->u_buf[3]; - - return (PARSER_OK); -} - -int pdf11cm1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - return pdf11_parse_hash (input_buf, input_len, hash_buf); -} - -int pdf11cm2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_10420) || (input_len > DISPLAY_LEN_MAX_10420)) return (PARSER_GLOBAL_LENGTH); - - if ((memcmp (SIGNATURE_PDF, input_buf, 5)) && (memcmp (SIGNATURE_PDF, input_buf, 5))) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pdf_t *pdf = (pdf_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *V_pos = input_buf + 5; - - char *R_pos = strchr (V_pos, '*'); - - if (R_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 V_len = R_pos - V_pos; - - R_pos++; - - char *bits_pos = strchr (R_pos, '*'); - - if (bits_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 R_len = bits_pos - R_pos; - - bits_pos++; - - char *P_pos = strchr (bits_pos, '*'); - - if (P_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 bits_len = P_pos - bits_pos; - - P_pos++; - - char *enc_md_pos = strchr (P_pos, '*'); - - if (enc_md_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 P_len = enc_md_pos - P_pos; - - enc_md_pos++; - - char *id_len_pos = strchr (enc_md_pos, '*'); - - if (id_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 enc_md_len = id_len_pos - enc_md_pos; - - id_len_pos++; - - char *id_buf_pos = strchr (id_len_pos, '*'); - - if (id_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 id_len_len = id_buf_pos - id_len_pos; - - id_buf_pos++; - - char *u_len_pos = strchr (id_buf_pos, '*'); - - if (u_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 id_buf_len = u_len_pos - id_buf_pos; - - if (id_buf_len != 32) return (PARSER_SALT_LENGTH); - - u_len_pos++; - - char *u_buf_pos = strchr (u_len_pos, '*'); - - if (u_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 u_len_len = u_buf_pos - u_len_pos; - - u_buf_pos++; - - char *o_len_pos = strchr (u_buf_pos, '*'); - - if (o_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 u_buf_len = o_len_pos - u_buf_pos; - - if (u_buf_len != 64) return (PARSER_SALT_LENGTH); - - o_len_pos++; - - char *o_buf_pos = strchr (o_len_pos, '*'); - - if (o_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 o_len_len = o_buf_pos - o_len_pos; - - o_buf_pos++; - - char *rc4key_pos = strchr (o_buf_pos, ':'); - - if (rc4key_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 o_buf_len = rc4key_pos - o_buf_pos; - - if (o_buf_len != 64) return (PARSER_SALT_LENGTH); - - rc4key_pos++; - - u32 rc4key_len = input_len - 5 - V_len - 1 - R_len - 1 - bits_len - 1 - P_len - 1 - enc_md_len - 1 - id_len_len - 1 - id_buf_len - 1 - u_len_len - 1 - u_buf_len - 1 - o_len_len - 1 - o_buf_len - 1; - - if (rc4key_len != 10) return (PARSER_SALT_LENGTH); - - // validate data - - const int V = atoi (V_pos); - const int R = atoi (R_pos); - const int P = atoi (P_pos); - - if (V != 1) return (PARSER_SALT_VALUE); - if (R != 2) return (PARSER_SALT_VALUE); - - const int enc_md = atoi (enc_md_pos); - - if ((enc_md != 0) && (enc_md != 1)) return (PARSER_SALT_VALUE); - - const int id_len = atoi (id_len_pos); - const int u_len = atoi (u_len_pos); - const int o_len = atoi (o_len_pos); - - if (id_len != 16) return (PARSER_SALT_VALUE); - if (u_len != 32) return (PARSER_SALT_VALUE); - if (o_len != 32) return (PARSER_SALT_VALUE); - - const int bits = atoi (bits_pos); - - if (bits != 40) return (PARSER_SALT_VALUE); - - // copy data to esalt - - pdf->V = V; - pdf->R = R; - pdf->P = P; - - pdf->enc_md = enc_md; - - pdf->id_buf[0] = hex_to_u32 ((const u8 *) &id_buf_pos[ 0]); - pdf->id_buf[1] = hex_to_u32 ((const u8 *) &id_buf_pos[ 8]); - pdf->id_buf[2] = hex_to_u32 ((const u8 *) &id_buf_pos[16]); - pdf->id_buf[3] = hex_to_u32 ((const u8 *) &id_buf_pos[24]); - pdf->id_len = id_len; - - pdf->u_buf[0] = hex_to_u32 ((const u8 *) &u_buf_pos[ 0]); - pdf->u_buf[1] = hex_to_u32 ((const u8 *) &u_buf_pos[ 8]); - pdf->u_buf[2] = hex_to_u32 ((const u8 *) &u_buf_pos[16]); - pdf->u_buf[3] = hex_to_u32 ((const u8 *) &u_buf_pos[24]); - pdf->u_buf[4] = hex_to_u32 ((const u8 *) &u_buf_pos[32]); - pdf->u_buf[5] = hex_to_u32 ((const u8 *) &u_buf_pos[40]); - pdf->u_buf[6] = hex_to_u32 ((const u8 *) &u_buf_pos[48]); - pdf->u_buf[7] = hex_to_u32 ((const u8 *) &u_buf_pos[56]); - pdf->u_len = u_len; - - pdf->o_buf[0] = hex_to_u32 ((const u8 *) &o_buf_pos[ 0]); - pdf->o_buf[1] = hex_to_u32 ((const u8 *) &o_buf_pos[ 8]); - pdf->o_buf[2] = hex_to_u32 ((const u8 *) &o_buf_pos[16]); - pdf->o_buf[3] = hex_to_u32 ((const u8 *) &o_buf_pos[24]); - pdf->o_buf[4] = hex_to_u32 ((const u8 *) &o_buf_pos[32]); - pdf->o_buf[5] = hex_to_u32 ((const u8 *) &o_buf_pos[40]); - pdf->o_buf[6] = hex_to_u32 ((const u8 *) &o_buf_pos[48]); - pdf->o_buf[7] = hex_to_u32 ((const u8 *) &o_buf_pos[56]); - pdf->o_len = o_len; - - pdf->id_buf[0] = byte_swap_32 (pdf->id_buf[0]); - pdf->id_buf[1] = byte_swap_32 (pdf->id_buf[1]); - pdf->id_buf[2] = byte_swap_32 (pdf->id_buf[2]); - pdf->id_buf[3] = byte_swap_32 (pdf->id_buf[3]); - - pdf->u_buf[0] = byte_swap_32 (pdf->u_buf[0]); - pdf->u_buf[1] = byte_swap_32 (pdf->u_buf[1]); - pdf->u_buf[2] = byte_swap_32 (pdf->u_buf[2]); - pdf->u_buf[3] = byte_swap_32 (pdf->u_buf[3]); - pdf->u_buf[4] = byte_swap_32 (pdf->u_buf[4]); - pdf->u_buf[5] = byte_swap_32 (pdf->u_buf[5]); - pdf->u_buf[6] = byte_swap_32 (pdf->u_buf[6]); - pdf->u_buf[7] = byte_swap_32 (pdf->u_buf[7]); - - pdf->o_buf[0] = byte_swap_32 (pdf->o_buf[0]); - pdf->o_buf[1] = byte_swap_32 (pdf->o_buf[1]); - pdf->o_buf[2] = byte_swap_32 (pdf->o_buf[2]); - pdf->o_buf[3] = byte_swap_32 (pdf->o_buf[3]); - pdf->o_buf[4] = byte_swap_32 (pdf->o_buf[4]); - pdf->o_buf[5] = byte_swap_32 (pdf->o_buf[5]); - pdf->o_buf[6] = byte_swap_32 (pdf->o_buf[6]); - pdf->o_buf[7] = byte_swap_32 (pdf->o_buf[7]); - - pdf->rc4key[1] = 0; - pdf->rc4key[0] = 0; - - pdf->rc4key[0] |= hex_convert (rc4key_pos[0]) << 28; - pdf->rc4key[0] |= hex_convert (rc4key_pos[1]) << 24; - pdf->rc4key[0] |= hex_convert (rc4key_pos[2]) << 20; - pdf->rc4key[0] |= hex_convert (rc4key_pos[3]) << 16; - pdf->rc4key[0] |= hex_convert (rc4key_pos[4]) << 12; - pdf->rc4key[0] |= hex_convert (rc4key_pos[5]) << 8; - pdf->rc4key[0] |= hex_convert (rc4key_pos[6]) << 4; - pdf->rc4key[0] |= hex_convert (rc4key_pos[7]) << 0; - pdf->rc4key[1] |= hex_convert (rc4key_pos[8]) << 28; - pdf->rc4key[1] |= hex_convert (rc4key_pos[9]) << 24; - - pdf->rc4key[0] = byte_swap_32 (pdf->rc4key[0]); - pdf->rc4key[1] = byte_swap_32 (pdf->rc4key[1]); - - // we use ID for salt, maybe needs to change, we will see... - - salt->salt_buf[0] = pdf->id_buf[0]; - salt->salt_buf[1] = pdf->id_buf[1]; - salt->salt_buf[2] = pdf->id_buf[2]; - salt->salt_buf[3] = pdf->id_buf[3]; - salt->salt_buf[4] = pdf->u_buf[0]; - salt->salt_buf[5] = pdf->u_buf[1]; - salt->salt_buf[6] = pdf->o_buf[0]; - salt->salt_buf[7] = pdf->o_buf[1]; - salt->salt_len = pdf->id_len + 16; - - digest[0] = pdf->rc4key[0]; - digest[1] = pdf->rc4key[1]; - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int pdf14_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_10500) || (input_len > DISPLAY_LEN_MAX_10500)) return (PARSER_GLOBAL_LENGTH); - - if ((memcmp (SIGNATURE_PDF, input_buf, 5)) && (memcmp (SIGNATURE_PDF, input_buf, 5))) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pdf_t *pdf = (pdf_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *V_pos = input_buf + 5; - - char *R_pos = strchr (V_pos, '*'); - - if (R_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 V_len = R_pos - V_pos; - - R_pos++; - - char *bits_pos = strchr (R_pos, '*'); - - if (bits_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 R_len = bits_pos - R_pos; - - bits_pos++; - - char *P_pos = strchr (bits_pos, '*'); - - if (P_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 bits_len = P_pos - bits_pos; - - P_pos++; - - char *enc_md_pos = strchr (P_pos, '*'); - - if (enc_md_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 P_len = enc_md_pos - P_pos; - - enc_md_pos++; - - char *id_len_pos = strchr (enc_md_pos, '*'); - - if (id_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 enc_md_len = id_len_pos - enc_md_pos; - - id_len_pos++; - - char *id_buf_pos = strchr (id_len_pos, '*'); - - if (id_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 id_len_len = id_buf_pos - id_len_pos; - - id_buf_pos++; - - char *u_len_pos = strchr (id_buf_pos, '*'); - - if (u_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 id_buf_len = u_len_pos - id_buf_pos; - - if ((id_buf_len != 32) && (id_buf_len != 64)) return (PARSER_SALT_LENGTH); - - u_len_pos++; - - char *u_buf_pos = strchr (u_len_pos, '*'); - - if (u_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 u_len_len = u_buf_pos - u_len_pos; - - u_buf_pos++; - - char *o_len_pos = strchr (u_buf_pos, '*'); - - if (o_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 u_buf_len = o_len_pos - u_buf_pos; - - if (u_buf_len != 64) return (PARSER_SALT_LENGTH); - - o_len_pos++; - - char *o_buf_pos = strchr (o_len_pos, '*'); - - if (o_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 o_len_len = o_buf_pos - o_len_pos; - - o_buf_pos++; - - u32 o_buf_len = input_len - 5 - V_len - 1 - R_len - 1 - bits_len - 1 - P_len - 1 - enc_md_len - 1 - id_len_len - 1 - id_buf_len - 1 - u_len_len - 1 - u_buf_len - 1 - o_len_len - 1; - - if (o_buf_len != 64) return (PARSER_SALT_LENGTH); - - // validate data - - const int V = atoi (V_pos); - const int R = atoi (R_pos); - const int P = atoi (P_pos); - - int vr_ok = 0; - - if ((V == 2) && (R == 3)) vr_ok = 1; - if ((V == 4) && (R == 4)) vr_ok = 1; - - if (vr_ok == 0) return (PARSER_SALT_VALUE); - - const int id_len = atoi (id_len_pos); - const int u_len = atoi (u_len_pos); - const int o_len = atoi (o_len_pos); - - if ((id_len != 16) && (id_len != 32)) return (PARSER_SALT_VALUE); - - if (u_len != 32) return (PARSER_SALT_VALUE); - if (o_len != 32) return (PARSER_SALT_VALUE); - - const int bits = atoi (bits_pos); - - if (bits != 128) return (PARSER_SALT_VALUE); - - int enc_md = 1; - - if (R >= 4) - { - enc_md = atoi (enc_md_pos); - } - - // copy data to esalt - - pdf->V = V; - pdf->R = R; - pdf->P = P; - - pdf->enc_md = enc_md; - - pdf->id_buf[0] = hex_to_u32 ((const u8 *) &id_buf_pos[ 0]); - pdf->id_buf[1] = hex_to_u32 ((const u8 *) &id_buf_pos[ 8]); - pdf->id_buf[2] = hex_to_u32 ((const u8 *) &id_buf_pos[16]); - pdf->id_buf[3] = hex_to_u32 ((const u8 *) &id_buf_pos[24]); - - if (id_len == 32) - { - pdf->id_buf[4] = hex_to_u32 ((const u8 *) &id_buf_pos[32]); - pdf->id_buf[5] = hex_to_u32 ((const u8 *) &id_buf_pos[40]); - pdf->id_buf[6] = hex_to_u32 ((const u8 *) &id_buf_pos[48]); - pdf->id_buf[7] = hex_to_u32 ((const u8 *) &id_buf_pos[56]); - } - - pdf->id_len = id_len; - - pdf->u_buf[0] = hex_to_u32 ((const u8 *) &u_buf_pos[ 0]); - pdf->u_buf[1] = hex_to_u32 ((const u8 *) &u_buf_pos[ 8]); - pdf->u_buf[2] = hex_to_u32 ((const u8 *) &u_buf_pos[16]); - pdf->u_buf[3] = hex_to_u32 ((const u8 *) &u_buf_pos[24]); - pdf->u_buf[4] = hex_to_u32 ((const u8 *) &u_buf_pos[32]); - pdf->u_buf[5] = hex_to_u32 ((const u8 *) &u_buf_pos[40]); - pdf->u_buf[6] = hex_to_u32 ((const u8 *) &u_buf_pos[48]); - pdf->u_buf[7] = hex_to_u32 ((const u8 *) &u_buf_pos[56]); - pdf->u_len = u_len; - - pdf->o_buf[0] = hex_to_u32 ((const u8 *) &o_buf_pos[ 0]); - pdf->o_buf[1] = hex_to_u32 ((const u8 *) &o_buf_pos[ 8]); - pdf->o_buf[2] = hex_to_u32 ((const u8 *) &o_buf_pos[16]); - pdf->o_buf[3] = hex_to_u32 ((const u8 *) &o_buf_pos[24]); - pdf->o_buf[4] = hex_to_u32 ((const u8 *) &o_buf_pos[32]); - pdf->o_buf[5] = hex_to_u32 ((const u8 *) &o_buf_pos[40]); - pdf->o_buf[6] = hex_to_u32 ((const u8 *) &o_buf_pos[48]); - pdf->o_buf[7] = hex_to_u32 ((const u8 *) &o_buf_pos[56]); - pdf->o_len = o_len; - - pdf->id_buf[0] = byte_swap_32 (pdf->id_buf[0]); - pdf->id_buf[1] = byte_swap_32 (pdf->id_buf[1]); - pdf->id_buf[2] = byte_swap_32 (pdf->id_buf[2]); - pdf->id_buf[3] = byte_swap_32 (pdf->id_buf[3]); - - if (id_len == 32) - { - pdf->id_buf[4] = byte_swap_32 (pdf->id_buf[4]); - pdf->id_buf[5] = byte_swap_32 (pdf->id_buf[5]); - pdf->id_buf[6] = byte_swap_32 (pdf->id_buf[6]); - pdf->id_buf[7] = byte_swap_32 (pdf->id_buf[7]); - } - - pdf->u_buf[0] = byte_swap_32 (pdf->u_buf[0]); - pdf->u_buf[1] = byte_swap_32 (pdf->u_buf[1]); - pdf->u_buf[2] = byte_swap_32 (pdf->u_buf[2]); - pdf->u_buf[3] = byte_swap_32 (pdf->u_buf[3]); - pdf->u_buf[4] = byte_swap_32 (pdf->u_buf[4]); - pdf->u_buf[5] = byte_swap_32 (pdf->u_buf[5]); - pdf->u_buf[6] = byte_swap_32 (pdf->u_buf[6]); - pdf->u_buf[7] = byte_swap_32 (pdf->u_buf[7]); - - pdf->o_buf[0] = byte_swap_32 (pdf->o_buf[0]); - pdf->o_buf[1] = byte_swap_32 (pdf->o_buf[1]); - pdf->o_buf[2] = byte_swap_32 (pdf->o_buf[2]); - pdf->o_buf[3] = byte_swap_32 (pdf->o_buf[3]); - pdf->o_buf[4] = byte_swap_32 (pdf->o_buf[4]); - pdf->o_buf[5] = byte_swap_32 (pdf->o_buf[5]); - pdf->o_buf[6] = byte_swap_32 (pdf->o_buf[6]); - pdf->o_buf[7] = byte_swap_32 (pdf->o_buf[7]); - - // precompute rc4 data for later use - - uint padding[8] = - { - 0x5e4ebf28, - 0x418a754e, - 0x564e0064, - 0x0801faff, - 0xb6002e2e, - 0x803e68d0, - 0xfea90c2f, - 0x7a695364 - }; - - // md5 - - uint salt_pc_block[32] = { 0 }; - - char *salt_pc_ptr = (char *) salt_pc_block; - - memcpy (salt_pc_ptr, padding, 32); - memcpy (salt_pc_ptr + 32, pdf->id_buf, pdf->id_len); - - uint salt_pc_digest[4] = { 0 }; - - md5_complete_no_limit (salt_pc_digest, salt_pc_block, 32 + pdf->id_len); - - pdf->rc4data[0] = salt_pc_digest[0]; - pdf->rc4data[1] = salt_pc_digest[1]; - - // we use ID for salt, maybe needs to change, we will see... - - salt->salt_buf[0] = pdf->id_buf[0]; - salt->salt_buf[1] = pdf->id_buf[1]; - salt->salt_buf[2] = pdf->id_buf[2]; - salt->salt_buf[3] = pdf->id_buf[3]; - salt->salt_buf[4] = pdf->u_buf[0]; - salt->salt_buf[5] = pdf->u_buf[1]; - salt->salt_buf[6] = pdf->o_buf[0]; - salt->salt_buf[7] = pdf->o_buf[1]; - salt->salt_len = pdf->id_len + 16; - - salt->salt_iter = ROUNDS_PDF14; - - digest[0] = pdf->u_buf[0]; - digest[1] = pdf->u_buf[1]; - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int pdf17l3_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - int ret = pdf17l8_parse_hash (input_buf, input_len, hash_buf); - - if (ret != PARSER_OK) - { - return ret; - } - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] -= SHA256M_A; - digest[1] -= SHA256M_B; - digest[2] -= SHA256M_C; - digest[3] -= SHA256M_D; - digest[4] -= SHA256M_E; - digest[5] -= SHA256M_F; - digest[6] -= SHA256M_G; - digest[7] -= SHA256M_H; - - salt->salt_buf[2] = 0x80; - - return (PARSER_OK); -} - -int pdf17l8_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_10600) || (input_len > DISPLAY_LEN_MAX_10600)) return (PARSER_GLOBAL_LENGTH); - - if ((memcmp (SIGNATURE_PDF, input_buf, 5)) && (memcmp (SIGNATURE_PDF, input_buf, 5))) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pdf_t *pdf = (pdf_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *V_pos = input_buf + 5; - - char *R_pos = strchr (V_pos, '*'); - - if (R_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 V_len = R_pos - V_pos; - - R_pos++; - - char *bits_pos = strchr (R_pos, '*'); - - if (bits_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 R_len = bits_pos - R_pos; - - bits_pos++; - - char *P_pos = strchr (bits_pos, '*'); - - if (P_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 bits_len = P_pos - bits_pos; - - P_pos++; - - char *enc_md_pos = strchr (P_pos, '*'); - - if (enc_md_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 P_len = enc_md_pos - P_pos; - - enc_md_pos++; - - char *id_len_pos = strchr (enc_md_pos, '*'); - - if (id_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 enc_md_len = id_len_pos - enc_md_pos; - - id_len_pos++; - - char *id_buf_pos = strchr (id_len_pos, '*'); - - if (id_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 id_len_len = id_buf_pos - id_len_pos; - - id_buf_pos++; - - char *u_len_pos = strchr (id_buf_pos, '*'); - - if (u_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 id_buf_len = u_len_pos - id_buf_pos; - - u_len_pos++; - - char *u_buf_pos = strchr (u_len_pos, '*'); - - if (u_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 u_len_len = u_buf_pos - u_len_pos; - - u_buf_pos++; - - char *o_len_pos = strchr (u_buf_pos, '*'); - - if (o_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 u_buf_len = o_len_pos - u_buf_pos; - - o_len_pos++; - - char *o_buf_pos = strchr (o_len_pos, '*'); - - if (o_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 o_len_len = o_buf_pos - o_len_pos; - - o_buf_pos++; - - char *last = strchr (o_buf_pos, '*'); - - if (last == NULL) last = input_buf + input_len; - - u32 o_buf_len = last - o_buf_pos; - - // validate data - - const int V = atoi (V_pos); - const int R = atoi (R_pos); - - int vr_ok = 0; - - if ((V == 5) && (R == 5)) vr_ok = 1; - if ((V == 5) && (R == 6)) vr_ok = 1; - - if (vr_ok == 0) return (PARSER_SALT_VALUE); - - const int bits = atoi (bits_pos); - - if (bits != 256) return (PARSER_SALT_VALUE); - - int enc_md = atoi (enc_md_pos); - - if ((enc_md != 0) && (enc_md != 1)) return (PARSER_SALT_VALUE); - - const uint id_len = atoi (id_len_pos); - const uint u_len = atoi (u_len_pos); - const uint o_len = atoi (o_len_pos); - - if (V_len > 6) return (PARSER_SALT_LENGTH); - if (R_len > 6) return (PARSER_SALT_LENGTH); - if (P_len > 6) return (PARSER_SALT_LENGTH); - if (id_len_len > 6) return (PARSER_SALT_LENGTH); - if (u_len_len > 6) return (PARSER_SALT_LENGTH); - if (o_len_len > 6) return (PARSER_SALT_LENGTH); - if (bits_len > 6) return (PARSER_SALT_LENGTH); - if (enc_md_len > 6) return (PARSER_SALT_LENGTH); - - if ((id_len * 2) != id_buf_len) return (PARSER_SALT_VALUE); - if ((u_len * 2) != u_buf_len) return (PARSER_SALT_VALUE); - if ((o_len * 2) != o_buf_len) return (PARSER_SALT_VALUE); - - // copy data to esalt - - if (u_len < 40) return (PARSER_SALT_VALUE); - - for (int i = 0, j = 0; i < 8 + 2; i += 1, j += 8) - { - pdf->u_buf[i] = hex_to_u32 ((const u8 *) &u_buf_pos[j]); - } - - salt->salt_buf[0] = pdf->u_buf[8]; - salt->salt_buf[1] = pdf->u_buf[9]; - - salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); - salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); - - salt->salt_len = 8; - salt->salt_iter = ROUNDS_PDF17L8; - - digest[0] = pdf->u_buf[0]; - digest[1] = pdf->u_buf[1]; - digest[2] = pdf->u_buf[2]; - digest[3] = pdf->u_buf[3]; - digest[4] = pdf->u_buf[4]; - digest[5] = pdf->u_buf[5]; - digest[6] = pdf->u_buf[6]; - digest[7] = pdf->u_buf[7]; - - return (PARSER_OK); -} - -int pbkdf2_sha256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_10900) || (input_len > DISPLAY_LEN_MAX_10900)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_PBKDF2_SHA256, input_buf, 7)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pbkdf2_sha256_t *pbkdf2_sha256 = (pbkdf2_sha256_t *) hash_buf->esalt; - - /** - * parse line - */ - - // iterations - - char *iter_pos = input_buf + 7; - - u32 iter = atoi (iter_pos); - - if (iter < 1) return (PARSER_SALT_ITERATION); - if (iter > 999999) return (PARSER_SALT_ITERATION); - - // first is *raw* salt - - char *salt_pos = strchr (iter_pos, ':'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - char *hash_pos = strchr (salt_pos, ':'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 salt_len = hash_pos - salt_pos; - - if (salt_len > 64) return (PARSER_SALT_LENGTH); - - hash_pos++; - - u32 hash_b64_len = input_len - (hash_pos - input_buf); - - if (hash_b64_len > 88) return (PARSER_HASH_LENGTH); - - // decode salt - - char *salt_buf_ptr = (char *) pbkdf2_sha256->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt_buf_ptr[salt_len + 3] = 0x01; - salt_buf_ptr[salt_len + 4] = 0x80; - - salt->salt_len = salt_len; - salt->salt_iter = iter - 1; - - // decode hash - - u8 tmp_buf[100] = { 0 }; - - int hash_len = base64_decode (base64_to_int, (const u8 *) hash_pos, hash_b64_len, tmp_buf); - - if (hash_len < 16) return (PARSER_HASH_LENGTH); - - memcpy (digest, tmp_buf, 16); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - // add some stuff to normal salt to make sorted happy - - salt->salt_buf[0] = pbkdf2_sha256->salt_buf[0]; - salt->salt_buf[1] = pbkdf2_sha256->salt_buf[1]; - salt->salt_buf[2] = pbkdf2_sha256->salt_buf[2]; - salt->salt_buf[3] = pbkdf2_sha256->salt_buf[3]; - salt->salt_buf[4] = salt->salt_iter; - - return (PARSER_OK); -} - -int prestashop_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_11000) || (input_len > DISPLAY_LEN_MAX_11000)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - if (input_buf[32] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 32 - 1; - - char *salt_buf = input_buf + 32 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int postgresql_auth_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_11100) || (input_len > DISPLAY_LEN_MAX_11100)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_POSTGRESQL_AUTH, input_buf, 10)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *user_pos = input_buf + 10; - - char *salt_pos = strchr (user_pos, '*'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - char *hash_pos = strchr (salt_pos, '*'); - - hash_pos++; - - uint hash_len = input_len - (hash_pos - input_buf); - - if (hash_len != 32) return (PARSER_HASH_LENGTH); - - uint user_len = salt_pos - user_pos - 1; - - uint salt_len = hash_pos - salt_pos - 1; - - if (salt_len != 8) return (PARSER_SALT_LENGTH); - - /* - * store digest - */ - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - digest[0] -= MD5M_A; - digest[1] -= MD5M_B; - digest[2] -= MD5M_C; - digest[3] -= MD5M_D; - - /* - * store salt - */ - - char *salt_buf_ptr = (char *) salt->salt_buf; - - // first 4 bytes are the "challenge" - - salt_buf_ptr[0] = hex_to_u8 ((const u8 *) &salt_pos[0]); - salt_buf_ptr[1] = hex_to_u8 ((const u8 *) &salt_pos[2]); - salt_buf_ptr[2] = hex_to_u8 ((const u8 *) &salt_pos[4]); - salt_buf_ptr[3] = hex_to_u8 ((const u8 *) &salt_pos[6]); - - // append the user name - - user_len = parse_and_store_salt (salt_buf_ptr + 4, user_pos, user_len); - - salt->salt_len = 4 + user_len; - - return (PARSER_OK); -} - -int mysql_auth_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_11200) || (input_len > DISPLAY_LEN_MAX_11200)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_MYSQL_AUTH, input_buf, 9)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - char *salt_pos = input_buf + 9; - - char *hash_pos = strchr (salt_pos, '*'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - hash_pos++; - - uint hash_len = input_len - (hash_pos - input_buf); - - if (hash_len != 40) return (PARSER_HASH_LENGTH); - - uint salt_len = hash_pos - salt_pos - 1; - - if (salt_len != 40) return (PARSER_SALT_LENGTH); - - /* - * store digest - */ - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); - - /* - * store salt - */ - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int bitcoin_wallet_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_11300) || (input_len > DISPLAY_LEN_MAX_11300)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_BITCOIN_WALLET, input_buf, 9)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - bitcoin_wallet_t *bitcoin_wallet = (bitcoin_wallet_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *cry_master_len_pos = input_buf + 9; - - char *cry_master_buf_pos = strchr (cry_master_len_pos, '$'); - - if (cry_master_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 cry_master_len_len = cry_master_buf_pos - cry_master_len_pos; - - cry_master_buf_pos++; - - char *cry_salt_len_pos = strchr (cry_master_buf_pos, '$'); - - if (cry_salt_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 cry_master_buf_len = cry_salt_len_pos - cry_master_buf_pos; - - cry_salt_len_pos++; - - char *cry_salt_buf_pos = strchr (cry_salt_len_pos, '$'); - - if (cry_salt_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 cry_salt_len_len = cry_salt_buf_pos - cry_salt_len_pos; - - cry_salt_buf_pos++; - - char *cry_rounds_pos = strchr (cry_salt_buf_pos, '$'); - - if (cry_rounds_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 cry_salt_buf_len = cry_rounds_pos - cry_salt_buf_pos; - - cry_rounds_pos++; - - char *ckey_len_pos = strchr (cry_rounds_pos, '$'); - - if (ckey_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 cry_rounds_len = ckey_len_pos - cry_rounds_pos; - - ckey_len_pos++; - - char *ckey_buf_pos = strchr (ckey_len_pos, '$'); - - if (ckey_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 ckey_len_len = ckey_buf_pos - ckey_len_pos; - - ckey_buf_pos++; - - char *public_key_len_pos = strchr (ckey_buf_pos, '$'); - - if (public_key_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 ckey_buf_len = public_key_len_pos - ckey_buf_pos; - - public_key_len_pos++; - - char *public_key_buf_pos = strchr (public_key_len_pos, '$'); - - if (public_key_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 public_key_len_len = public_key_buf_pos - public_key_len_pos; - - public_key_buf_pos++; - - u32 public_key_buf_len = input_len - 1 - 7 - 1 - cry_master_len_len - 1 - cry_master_buf_len - 1 - cry_salt_len_len - 1 - cry_salt_buf_len - 1 - cry_rounds_len - 1 - ckey_len_len - 1 - ckey_buf_len - 1 - public_key_len_len - 1; - - const uint cry_master_len = atoi (cry_master_len_pos); - const uint cry_salt_len = atoi (cry_salt_len_pos); - const uint ckey_len = atoi (ckey_len_pos); - const uint public_key_len = atoi (public_key_len_pos); - - if (cry_master_buf_len != cry_master_len) return (PARSER_SALT_VALUE); - if (cry_salt_buf_len != cry_salt_len) return (PARSER_SALT_VALUE); - if (ckey_buf_len != ckey_len) return (PARSER_SALT_VALUE); - if (public_key_buf_len != public_key_len) return (PARSER_SALT_VALUE); - - for (uint i = 0, j = 0; j < cry_master_len; i += 1, j += 8) - { - bitcoin_wallet->cry_master_buf[i] = hex_to_u32 ((const u8 *) &cry_master_buf_pos[j]); - - bitcoin_wallet->cry_master_buf[i] = byte_swap_32 (bitcoin_wallet->cry_master_buf[i]); - } - - for (uint i = 0, j = 0; j < ckey_len; i += 1, j += 8) - { - bitcoin_wallet->ckey_buf[i] = hex_to_u32 ((const u8 *) &ckey_buf_pos[j]); - - bitcoin_wallet->ckey_buf[i] = byte_swap_32 (bitcoin_wallet->ckey_buf[i]); - } - - for (uint i = 0, j = 0; j < public_key_len; i += 1, j += 8) - { - bitcoin_wallet->public_key_buf[i] = hex_to_u32 ((const u8 *) &public_key_buf_pos[j]); - - bitcoin_wallet->public_key_buf[i] = byte_swap_32 (bitcoin_wallet->public_key_buf[i]); - } - - bitcoin_wallet->cry_master_len = cry_master_len / 2; - bitcoin_wallet->ckey_len = ckey_len / 2; - bitcoin_wallet->public_key_len = public_key_len / 2; - - /* - * store digest (should be unique enought, hopefully) - */ - - digest[0] = bitcoin_wallet->cry_master_buf[0]; - digest[1] = bitcoin_wallet->cry_master_buf[1]; - digest[2] = bitcoin_wallet->cry_master_buf[2]; - digest[3] = bitcoin_wallet->cry_master_buf[3]; - - /* - * store salt - */ - - if (cry_rounds_len >= 7) return (PARSER_SALT_VALUE); - - const uint cry_rounds = atoi (cry_rounds_pos); - - salt->salt_iter = cry_rounds - 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - const uint salt_len = parse_and_store_salt (salt_buf_ptr, cry_salt_buf_pos, cry_salt_buf_len); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int sip_auth_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_11400) || (input_len > DISPLAY_LEN_MAX_11400)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SIP_AUTH, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - sip_t *sip = (sip_t *) hash_buf->esalt; - - // work with a temporary copy of input_buf (s.t. we can manipulate it directly) - - char *temp_input_buf = (char *) mymalloc (input_len + 1); - - memcpy (temp_input_buf, input_buf, input_len); - - // URI_server: - - char *URI_server_pos = temp_input_buf + 6; - - char *URI_client_pos = strchr (URI_server_pos, '*'); - - if (URI_client_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - URI_client_pos[0] = 0; - URI_client_pos++; - - uint URI_server_len = strlen (URI_server_pos); - - if (URI_server_len > 512) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - // URI_client: - - char *user_pos = strchr (URI_client_pos, '*'); - - if (user_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - user_pos[0] = 0; - user_pos++; - - uint URI_client_len = strlen (URI_client_pos); - - if (URI_client_len > 512) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - // user: - - char *realm_pos = strchr (user_pos, '*'); - - if (realm_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - realm_pos[0] = 0; - realm_pos++; - - uint user_len = strlen (user_pos); - - if (user_len > 116) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - // realm: - - char *method_pos = strchr (realm_pos, '*'); - - if (method_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - method_pos[0] = 0; - method_pos++; - - uint realm_len = strlen (realm_pos); - - if (realm_len > 116) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - // method: - - char *URI_prefix_pos = strchr (method_pos, '*'); - - if (URI_prefix_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - URI_prefix_pos[0] = 0; - URI_prefix_pos++; - - uint method_len = strlen (method_pos); - - if (method_len > 246) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - // URI_prefix: - - char *URI_resource_pos = strchr (URI_prefix_pos, '*'); - - if (URI_resource_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - URI_resource_pos[0] = 0; - URI_resource_pos++; - - uint URI_prefix_len = strlen (URI_prefix_pos); - - if (URI_prefix_len > 245) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - // URI_resource: - - char *URI_suffix_pos = strchr (URI_resource_pos, '*'); - - if (URI_suffix_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - URI_suffix_pos[0] = 0; - URI_suffix_pos++; - - uint URI_resource_len = strlen (URI_resource_pos); - - if (URI_resource_len < 1 || URI_resource_len > 246) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - // URI_suffix: - - char *nonce_pos = strchr (URI_suffix_pos, '*'); - - if (nonce_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - nonce_pos[0] = 0; - nonce_pos++; - - uint URI_suffix_len = strlen (URI_suffix_pos); - - if (URI_suffix_len > 245) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - // nonce: - - char *nonce_client_pos = strchr (nonce_pos, '*'); - - if (nonce_client_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - nonce_client_pos[0] = 0; - nonce_client_pos++; - - uint nonce_len = strlen (nonce_pos); - - if (nonce_len < 1 || nonce_len > 50) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - // nonce_client: - - char *nonce_count_pos = strchr (nonce_client_pos, '*'); - - if (nonce_count_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - nonce_count_pos[0] = 0; - nonce_count_pos++; - - uint nonce_client_len = strlen (nonce_client_pos); - - if (nonce_client_len > 50) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - // nonce_count: - - char *qop_pos = strchr (nonce_count_pos, '*'); - - if (qop_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - qop_pos[0] = 0; - qop_pos++; - - uint nonce_count_len = strlen (nonce_count_pos); - - if (nonce_count_len > 50) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - // qop: - - char *directive_pos = strchr (qop_pos, '*'); - - if (directive_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - directive_pos[0] = 0; - directive_pos++; - - uint qop_len = strlen (qop_pos); - - if (qop_len > 50) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - // directive - - char *digest_pos = strchr (directive_pos, '*'); - - if (digest_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } - - digest_pos[0] = 0; - digest_pos++; - - uint directive_len = strlen (directive_pos); - - if (directive_len != 3) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - if (memcmp (directive_pos, "MD5", 3)) - { - log_info ("ERROR: Only the MD5 directive is currently supported\n"); - - myfree (temp_input_buf); - - return (PARSER_SIP_AUTH_DIRECTIVE); - } - - /* - * first (pre-)compute: HA2 = md5 ($method . ":" . $uri) - */ - - uint md5_len = 0; - - uint md5_max_len = 4 * 64; - - uint md5_remaining_len = md5_max_len; - - uint tmp_md5_buf[64] = { 0 }; - - char *tmp_md5_ptr = (char *) tmp_md5_buf; - - snprintf (tmp_md5_ptr, md5_remaining_len, "%s:", method_pos); - - md5_len += method_len + 1; - tmp_md5_ptr += method_len + 1; - - if (URI_prefix_len > 0) - { - md5_remaining_len = md5_max_len - md5_len; - - snprintf (tmp_md5_ptr, md5_remaining_len + 1, "%s:", URI_prefix_pos); - - md5_len += URI_prefix_len + 1; - tmp_md5_ptr += URI_prefix_len + 1; - } - - md5_remaining_len = md5_max_len - md5_len; - - snprintf (tmp_md5_ptr, md5_remaining_len + 1, "%s", URI_resource_pos); - - md5_len += URI_resource_len; - tmp_md5_ptr += URI_resource_len; - - if (URI_suffix_len > 0) - { - md5_remaining_len = md5_max_len - md5_len; - - snprintf (tmp_md5_ptr, md5_remaining_len + 1, ":%s", URI_suffix_pos); - - md5_len += 1 + URI_suffix_len; - } - - uint tmp_digest[4] = { 0 }; - - md5_complete_no_limit (tmp_digest, tmp_md5_buf, md5_len); - - tmp_digest[0] = byte_swap_32 (tmp_digest[0]); - tmp_digest[1] = byte_swap_32 (tmp_digest[1]); - tmp_digest[2] = byte_swap_32 (tmp_digest[2]); - tmp_digest[3] = byte_swap_32 (tmp_digest[3]); - - /* - * esalt - */ - - char *esalt_buf_ptr = (char *) sip->esalt_buf; - - uint esalt_len = 0; - - uint max_esalt_len = sizeof (sip->esalt_buf); // 151 = (64 + 64 + 55) - 32, where 32 is the hexadecimal MD5 HA1 hash - - // there are 2 possibilities for the esalt: - - if ((strcmp (qop_pos, "auth") == 0) || (strcmp (qop_pos, "auth-int") == 0)) - { - esalt_len = 1 + nonce_len + 1 + nonce_count_len + 1 + nonce_client_len + 1 + qop_len + 1 + 32; - - if (esalt_len > max_esalt_len) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - snprintf (esalt_buf_ptr, max_esalt_len, ":%s:%s:%s:%s:%08x%08x%08x%08x", - nonce_pos, - nonce_count_pos, - nonce_client_pos, - qop_pos, - tmp_digest[0], - tmp_digest[1], - tmp_digest[2], - tmp_digest[3]); - } - else - { - esalt_len = 1 + nonce_len + 1 + 32; - - if (esalt_len > max_esalt_len) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - snprintf (esalt_buf_ptr, max_esalt_len, ":%s:%08x%08x%08x%08x", - nonce_pos, - tmp_digest[0], - tmp_digest[1], - tmp_digest[2], - tmp_digest[3]); - } - - // add 0x80 to esalt - - esalt_buf_ptr[esalt_len] = 0x80; - - sip->esalt_len = esalt_len; - - /* - * actual salt - */ - - char *sip_salt_ptr = (char *) sip->salt_buf; - - uint salt_len = user_len + 1 + realm_len + 1; - - uint max_salt_len = 119; - - if (salt_len > max_salt_len) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } - - snprintf (sip_salt_ptr, max_salt_len + 1, "%s:%s:", user_pos, realm_pos); - - sip->salt_len = salt_len; - - /* - * fake salt (for sorting) - */ - - char *salt_buf_ptr = (char *) salt->salt_buf; - - max_salt_len = 55; - - uint fake_salt_len = salt_len; - - if (fake_salt_len > max_salt_len) - { - fake_salt_len = max_salt_len; - } - - snprintf (salt_buf_ptr, max_salt_len + 1, "%s:%s:", user_pos, realm_pos); - - salt->salt_len = fake_salt_len; - - /* - * digest - */ - - digest[0] = hex_to_u32 ((const u8 *) &digest_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &digest_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &digest_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &digest_pos[24]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - myfree (temp_input_buf); - - return (PARSER_OK); -} - -int crc32_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_11500) || (input_len > DISPLAY_LEN_MAX_11500)) return (PARSER_GLOBAL_LENGTH); - - if (input_buf[8] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - // digest - - char *digest_pos = input_buf; - - digest[0] = hex_to_u32 ((const u8 *) &digest_pos[0]); - digest[1] = 0; - digest[2] = 0; - digest[3] = 0; - - // salt - - char *salt_buf = input_buf + 8 + 1; - - uint salt_len = 8; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - return (PARSER_OK); -} - -int seven_zip_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_11600) || (input_len > DISPLAY_LEN_MAX_11600)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_SEVEN_ZIP, input_buf, 4)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - seven_zip_t *seven_zip = (seven_zip_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *p_buf_pos = input_buf + 4; - - char *NumCyclesPower_pos = strchr (p_buf_pos, '$'); - - if (NumCyclesPower_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 p_buf_len = NumCyclesPower_pos - p_buf_pos; - - NumCyclesPower_pos++; - - char *salt_len_pos = strchr (NumCyclesPower_pos, '$'); - - if (salt_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 NumCyclesPower_len = salt_len_pos - NumCyclesPower_pos; - - salt_len_pos++; - - char *salt_buf_pos = strchr (salt_len_pos, '$'); - - if (salt_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 salt_len_len = salt_buf_pos - salt_len_pos; - - salt_buf_pos++; - - char *iv_len_pos = strchr (salt_buf_pos, '$'); - - if (iv_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 salt_buf_len = iv_len_pos - salt_buf_pos; - - iv_len_pos++; - - char *iv_buf_pos = strchr (iv_len_pos, '$'); - - if (iv_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 iv_len_len = iv_buf_pos - iv_len_pos; - - iv_buf_pos++; - - char *crc_buf_pos = strchr (iv_buf_pos, '$'); - - if (crc_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 iv_buf_len = crc_buf_pos - iv_buf_pos; - - crc_buf_pos++; - - char *data_len_pos = strchr (crc_buf_pos, '$'); - - if (data_len_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 crc_buf_len = data_len_pos - crc_buf_pos; - - data_len_pos++; - - char *unpack_size_pos = strchr (data_len_pos, '$'); - - if (unpack_size_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 data_len_len = unpack_size_pos - data_len_pos; - - unpack_size_pos++; - - char *data_buf_pos = strchr (unpack_size_pos, '$'); - - if (data_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 unpack_size_len = data_buf_pos - unpack_size_pos; - - data_buf_pos++; - - u32 data_buf_len = input_len - 1 - 2 - 1 - p_buf_len - 1 - NumCyclesPower_len - 1 - salt_len_len - 1 - salt_buf_len - 1 - iv_len_len - 1 - iv_buf_len - 1 - crc_buf_len - 1 - data_len_len - 1 - unpack_size_len - 1; - - const uint iter = atoi (NumCyclesPower_pos); - const uint crc = atoi (crc_buf_pos); - const uint p_buf = atoi (p_buf_pos); - const uint salt_len = atoi (salt_len_pos); - const uint iv_len = atoi (iv_len_pos); - const uint unpack_size = atoi (unpack_size_pos); - const uint data_len = atoi (data_len_pos); - - /** - * verify some data - */ - - if (p_buf != 0) return (PARSER_SALT_VALUE); - if (salt_len != 0) return (PARSER_SALT_VALUE); - - if ((data_len * 2) != data_buf_len) return (PARSER_SALT_VALUE); - - if (data_len > 384) return (PARSER_SALT_VALUE); - - if (unpack_size > data_len) return (PARSER_SALT_VALUE); - - /** - * store data - */ - - seven_zip->iv_buf[0] = hex_to_u32 ((const u8 *) &iv_buf_pos[ 0]); - seven_zip->iv_buf[1] = hex_to_u32 ((const u8 *) &iv_buf_pos[ 8]); - seven_zip->iv_buf[2] = hex_to_u32 ((const u8 *) &iv_buf_pos[16]); - seven_zip->iv_buf[3] = hex_to_u32 ((const u8 *) &iv_buf_pos[24]); - - seven_zip->iv_len = iv_len; - - memcpy (seven_zip->salt_buf, salt_buf_pos, salt_buf_len); // we just need that for later ascii_digest() - - seven_zip->salt_len = 0; - - seven_zip->crc = crc; - - for (uint i = 0, j = 0; j < data_buf_len; i += 1, j += 8) - { - seven_zip->data_buf[i] = hex_to_u32 ((const u8 *) &data_buf_pos[j]); - - seven_zip->data_buf[i] = byte_swap_32 (seven_zip->data_buf[i]); - } - - seven_zip->data_len = data_len; - - seven_zip->unpack_size = unpack_size; - - // real salt - - salt->salt_buf[0] = seven_zip->data_buf[0]; - salt->salt_buf[1] = seven_zip->data_buf[1]; - salt->salt_buf[2] = seven_zip->data_buf[2]; - salt->salt_buf[3] = seven_zip->data_buf[3]; - - salt->salt_len = 16; - - salt->salt_sign[0] = iter; - - salt->salt_iter = 1u << iter; - - /** - * digest - */ - - digest[0] = crc; - digest[1] = 0; - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int gost2012sbog_256_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_11700) || (input_len > DISPLAY_LEN_MAX_11700)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); - digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); - digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - digest[4] = byte_swap_32 (digest[4]); - digest[5] = byte_swap_32 (digest[5]); - digest[6] = byte_swap_32 (digest[6]); - digest[7] = byte_swap_32 (digest[7]); - - return (PARSER_OK); -} - -int gost2012sbog_512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_11800) || (input_len > DISPLAY_LEN_MAX_11800)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - digest[ 0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[ 1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[ 2] = hex_to_u32 ((const u8 *) &input_buf[ 16]); - digest[ 3] = hex_to_u32 ((const u8 *) &input_buf[ 24]); - digest[ 4] = hex_to_u32 ((const u8 *) &input_buf[ 32]); - digest[ 5] = hex_to_u32 ((const u8 *) &input_buf[ 40]); - digest[ 6] = hex_to_u32 ((const u8 *) &input_buf[ 48]); - digest[ 7] = hex_to_u32 ((const u8 *) &input_buf[ 56]); - digest[ 8] = hex_to_u32 ((const u8 *) &input_buf[ 64]); - digest[ 9] = hex_to_u32 ((const u8 *) &input_buf[ 72]); - digest[10] = hex_to_u32 ((const u8 *) &input_buf[ 80]); - digest[11] = hex_to_u32 ((const u8 *) &input_buf[ 88]); - digest[12] = hex_to_u32 ((const u8 *) &input_buf[ 96]); - digest[13] = hex_to_u32 ((const u8 *) &input_buf[104]); - digest[14] = hex_to_u32 ((const u8 *) &input_buf[112]); - digest[15] = hex_to_u32 ((const u8 *) &input_buf[120]); - - digest[ 0] = byte_swap_32 (digest[ 0]); - digest[ 1] = byte_swap_32 (digest[ 1]); - digest[ 2] = byte_swap_32 (digest[ 2]); - digest[ 3] = byte_swap_32 (digest[ 3]); - digest[ 4] = byte_swap_32 (digest[ 4]); - digest[ 5] = byte_swap_32 (digest[ 5]); - digest[ 6] = byte_swap_32 (digest[ 6]); - digest[ 7] = byte_swap_32 (digest[ 7]); - digest[ 8] = byte_swap_32 (digest[ 8]); - digest[ 9] = byte_swap_32 (digest[ 9]); - digest[10] = byte_swap_32 (digest[10]); - digest[11] = byte_swap_32 (digest[11]); - digest[12] = byte_swap_32 (digest[12]); - digest[13] = byte_swap_32 (digest[13]); - digest[14] = byte_swap_32 (digest[14]); - digest[15] = byte_swap_32 (digest[15]); - - return (PARSER_OK); -} - -int pbkdf2_md5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_11900) || (input_len > DISPLAY_LEN_MAX_11900)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_PBKDF2_MD5, input_buf, 4)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pbkdf2_md5_t *pbkdf2_md5 = (pbkdf2_md5_t *) hash_buf->esalt; - - /** - * parse line - */ - - // iterations - - char *iter_pos = input_buf + 4; - - u32 iter = atoi (iter_pos); - - if (iter < 1) return (PARSER_SALT_ITERATION); - if (iter > 999999) return (PARSER_SALT_ITERATION); - - // first is *raw* salt - - char *salt_pos = strchr (iter_pos, ':'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - char *hash_pos = strchr (salt_pos, ':'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 salt_len = hash_pos - salt_pos; - - if (salt_len > 64) return (PARSER_SALT_LENGTH); - - hash_pos++; - - u32 hash_b64_len = input_len - (hash_pos - input_buf); - - if (hash_b64_len > 88) return (PARSER_HASH_LENGTH); - - // decode salt - - char *salt_buf_ptr = (char *) pbkdf2_md5->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt_buf_ptr[salt_len + 3] = 0x01; - salt_buf_ptr[salt_len + 4] = 0x80; - - salt->salt_len = salt_len; - salt->salt_iter = iter - 1; - - // decode hash - - u8 tmp_buf[100] = { 0 }; - - int hash_len = base64_decode (base64_to_int, (const u8 *) hash_pos, hash_b64_len, tmp_buf); - - if (hash_len < 16) return (PARSER_HASH_LENGTH); - - memcpy (digest, tmp_buf, 16); - - // add some stuff to normal salt to make sorted happy - - salt->salt_buf[0] = pbkdf2_md5->salt_buf[0]; - salt->salt_buf[1] = pbkdf2_md5->salt_buf[1]; - salt->salt_buf[2] = pbkdf2_md5->salt_buf[2]; - salt->salt_buf[3] = pbkdf2_md5->salt_buf[3]; - salt->salt_buf[4] = salt->salt_iter; - - return (PARSER_OK); -} - -int pbkdf2_sha1_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_12000) || (input_len > DISPLAY_LEN_MAX_12000)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_PBKDF2_SHA1, input_buf, 5)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pbkdf2_sha1_t *pbkdf2_sha1 = (pbkdf2_sha1_t *) hash_buf->esalt; - - /** - * parse line - */ - - // iterations - - char *iter_pos = input_buf + 5; - - u32 iter = atoi (iter_pos); - - if (iter < 1) return (PARSER_SALT_ITERATION); - if (iter > 999999) return (PARSER_SALT_ITERATION); - - // first is *raw* salt - - char *salt_pos = strchr (iter_pos, ':'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - char *hash_pos = strchr (salt_pos, ':'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 salt_len = hash_pos - salt_pos; - - if (salt_len > 64) return (PARSER_SALT_LENGTH); - - hash_pos++; - - u32 hash_b64_len = input_len - (hash_pos - input_buf); - - if (hash_b64_len > 88) return (PARSER_HASH_LENGTH); - - // decode salt - - char *salt_buf_ptr = (char *) pbkdf2_sha1->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt_buf_ptr[salt_len + 3] = 0x01; - salt_buf_ptr[salt_len + 4] = 0x80; - - salt->salt_len = salt_len; - salt->salt_iter = iter - 1; - - // decode hash - - u8 tmp_buf[100] = { 0 }; - - int hash_len = base64_decode (base64_to_int, (const u8 *) hash_pos, hash_b64_len, tmp_buf); - - if (hash_len < 16) return (PARSER_HASH_LENGTH); - - memcpy (digest, tmp_buf, 16); - - digest[0] = byte_swap_32 (digest[0]); - digest[1] = byte_swap_32 (digest[1]); - digest[2] = byte_swap_32 (digest[2]); - digest[3] = byte_swap_32 (digest[3]); - - // add some stuff to normal salt to make sorted happy - - salt->salt_buf[0] = pbkdf2_sha1->salt_buf[0]; - salt->salt_buf[1] = pbkdf2_sha1->salt_buf[1]; - salt->salt_buf[2] = pbkdf2_sha1->salt_buf[2]; - salt->salt_buf[3] = pbkdf2_sha1->salt_buf[3]; - salt->salt_buf[4] = salt->salt_iter; - - return (PARSER_OK); -} - -int pbkdf2_sha512_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_12100) || (input_len > DISPLAY_LEN_MAX_12100)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_PBKDF2_SHA512, input_buf, 7)) return (PARSER_SIGNATURE_UNMATCHED); - - u64 *digest = (u64 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - pbkdf2_sha512_t *pbkdf2_sha512 = (pbkdf2_sha512_t *) hash_buf->esalt; - - /** - * parse line - */ - - // iterations - - char *iter_pos = input_buf + 7; - - u32 iter = atoi (iter_pos); - - if (iter < 1) return (PARSER_SALT_ITERATION); - if (iter > 999999) return (PARSER_SALT_ITERATION); - - // first is *raw* salt - - char *salt_pos = strchr (iter_pos, ':'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - salt_pos++; - - char *hash_pos = strchr (salt_pos, ':'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 salt_len = hash_pos - salt_pos; - - if (salt_len > 64) return (PARSER_SALT_LENGTH); - - hash_pos++; - - u32 hash_b64_len = input_len - (hash_pos - input_buf); - - if (hash_b64_len > 88) return (PARSER_HASH_LENGTH); - - // decode salt - - char *salt_buf_ptr = (char *) pbkdf2_sha512->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_pos, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt_buf_ptr[salt_len + 3] = 0x01; - salt_buf_ptr[salt_len + 4] = 0x80; - - salt->salt_len = salt_len; - salt->salt_iter = iter - 1; - - // decode hash - - u8 tmp_buf[100] = { 0 }; - - int hash_len = base64_decode (base64_to_int, (const u8 *) hash_pos, hash_b64_len, tmp_buf); - - if (hash_len < 16) return (PARSER_HASH_LENGTH); - - memcpy (digest, tmp_buf, 64); - - digest[0] = byte_swap_64 (digest[0]); - digest[1] = byte_swap_64 (digest[1]); - digest[2] = byte_swap_64 (digest[2]); - digest[3] = byte_swap_64 (digest[3]); - digest[4] = byte_swap_64 (digest[4]); - digest[5] = byte_swap_64 (digest[5]); - digest[6] = byte_swap_64 (digest[6]); - digest[7] = byte_swap_64 (digest[7]); - - // add some stuff to normal salt to make sorted happy - - salt->salt_buf[0] = pbkdf2_sha512->salt_buf[0]; - salt->salt_buf[1] = pbkdf2_sha512->salt_buf[1]; - salt->salt_buf[2] = pbkdf2_sha512->salt_buf[2]; - salt->salt_buf[3] = pbkdf2_sha512->salt_buf[3]; - salt->salt_buf[4] = salt->salt_iter; - - return (PARSER_OK); -} - -int ecryptfs_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_12200) || (input_len > DISPLAY_LEN_MAX_12200)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_ECRYPTFS, input_buf, 10)) return (PARSER_SIGNATURE_UNMATCHED); - - uint *digest = (uint *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - /** - * parse line - */ - - char *salt_pos = input_buf + 10 + 2 + 2; // skip over "0$" and "1$" - - char *hash_pos = strchr (salt_pos, '$'); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 salt_len = hash_pos - salt_pos; - - if (salt_len != 16) return (PARSER_SALT_LENGTH); - - hash_pos++; - - u32 hash_len = input_len - 10 - 2 - 2 - salt_len - 1; - - if (hash_len != 16) return (PARSER_HASH_LENGTH); - - // decode hash - - digest[ 0] = hex_to_u32 ((const u8 *) &hash_pos[0]); - digest[ 1] = hex_to_u32 ((const u8 *) &hash_pos[8]); - digest[ 2] = 0; - digest[ 3] = 0; - digest[ 4] = 0; - digest[ 5] = 0; - digest[ 6] = 0; - digest[ 7] = 0; - digest[ 8] = 0; - digest[ 9] = 0; - digest[10] = 0; - digest[11] = 0; - digest[12] = 0; - digest[13] = 0; - digest[14] = 0; - digest[15] = 0; - - // decode salt - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_pos[8]); - - salt->salt_iter = ROUNDS_ECRYPTFS; - salt->salt_len = 8; - - return (PARSER_OK); -} - -int bsdicrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_12400) || (input_len > DISPLAY_LEN_MAX_12400)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_BSDICRYPT, input_buf, 1)) return (PARSER_SIGNATURE_UNMATCHED); - - unsigned char c19 = itoa64_to_int (input_buf[19]); - - if (c19 & 3) return (PARSER_HASH_VALUE); - - salt_t *salt = hash_buf->salt; - - u32 *digest = (u32 *) hash_buf->digest; - - // iteration count - - salt->salt_iter = itoa64_to_int (input_buf[1]) - | itoa64_to_int (input_buf[2]) << 6 - | itoa64_to_int (input_buf[3]) << 12 - | itoa64_to_int (input_buf[4]) << 18; - - // set salt - - salt->salt_buf[0] = itoa64_to_int (input_buf[5]) - | itoa64_to_int (input_buf[6]) << 6 - | itoa64_to_int (input_buf[7]) << 12 - | itoa64_to_int (input_buf[8]) << 18; - - salt->salt_len = 4; - - u8 tmp_buf[100] = { 0 }; - - base64_decode (itoa64_to_int, (const u8 *) input_buf + 9, 11, tmp_buf); - - memcpy (digest, tmp_buf, 8); - - uint tt; - - IP (digest[0], digest[1], tt); - - digest[0] = rotr32 (digest[0], 31); - digest[1] = rotr32 (digest[1], 31); - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int rar3hp_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_12500) || (input_len > DISPLAY_LEN_MAX_12500)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_RAR3, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - /** - * parse line - */ - - char *type_pos = input_buf + 6 + 1; - - char *salt_pos = strchr (type_pos, '*'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 type_len = salt_pos - type_pos; - - if (type_len != 1) return (PARSER_SALT_LENGTH); - - salt_pos++; - - char *crypted_pos = strchr (salt_pos, '*'); - - if (crypted_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 salt_len = crypted_pos - salt_pos; - - if (salt_len != 16) return (PARSER_SALT_LENGTH); - - crypted_pos++; - - u32 crypted_len = input_len - 6 - 1 - type_len - 1 - salt_len - 1; - - if (crypted_len != 32) return (PARSER_SALT_LENGTH); - - /** - * copy data - */ - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_pos[8]); - - salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); - salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); - - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &crypted_pos[ 0]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &crypted_pos[ 8]); - salt->salt_buf[4] = hex_to_u32 ((const u8 *) &crypted_pos[16]); - salt->salt_buf[5] = hex_to_u32 ((const u8 *) &crypted_pos[24]); - - salt->salt_len = 24; - salt->salt_iter = ROUNDS_RAR3; - - // there's no hash for rar3. the data which is in crypted_pos is some encrypted data and - // if it matches the value \xc4\x3d\x7b\x00\x40\x07\x00 after decrypt we know that we successfully cracked it. - - digest[0] = 0xc43d7b00; - digest[1] = 0x40070000; - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int rar5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_13000) || (input_len > DISPLAY_LEN_MAX_13000)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_RAR5, input_buf, 1 + 4 + 1)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - rar5_t *rar5 = (rar5_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *param0_pos = input_buf + 1 + 4 + 1; - - char *param1_pos = strchr (param0_pos, '$'); - - if (param1_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param0_len = param1_pos - param0_pos; - - param1_pos++; - - char *param2_pos = strchr (param1_pos, '$'); - - if (param2_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param1_len = param2_pos - param1_pos; - - param2_pos++; - - char *param3_pos = strchr (param2_pos, '$'); - - if (param3_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param2_len = param3_pos - param2_pos; - - param3_pos++; - - char *param4_pos = strchr (param3_pos, '$'); - - if (param4_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param3_len = param4_pos - param3_pos; - - param4_pos++; - - char *param5_pos = strchr (param4_pos, '$'); - - if (param5_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param4_len = param5_pos - param4_pos; - - param5_pos++; - - u32 param5_len = input_len - 1 - 4 - 1 - param0_len - 1 - param1_len - 1 - param2_len - 1 - param3_len - 1 - param4_len - 1; - - char *salt_buf = param1_pos; - char *iv = param3_pos; - char *pswcheck = param5_pos; - - const uint salt_len = atoi (param0_pos); - const uint iterations = atoi (param2_pos); - const uint pswcheck_len = atoi (param4_pos); - - /** - * verify some data - */ - - if (param1_len != 32) return (PARSER_SALT_VALUE); - if (param3_len != 32) return (PARSER_SALT_VALUE); - if (param5_len != 16) return (PARSER_SALT_VALUE); - - if (salt_len != 16) return (PARSER_SALT_VALUE); - if (iterations == 0) return (PARSER_SALT_VALUE); - if (pswcheck_len != 8) return (PARSER_SALT_VALUE); - - /** - * store data - */ - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_buf[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_buf[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_buf[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &salt_buf[24]); - - rar5->iv[0] = hex_to_u32 ((const u8 *) &iv[ 0]); - rar5->iv[1] = hex_to_u32 ((const u8 *) &iv[ 8]); - rar5->iv[2] = hex_to_u32 ((const u8 *) &iv[16]); - rar5->iv[3] = hex_to_u32 ((const u8 *) &iv[24]); - - salt->salt_len = 16; - - salt->salt_sign[0] = iterations; - - salt->salt_iter = ((1u << iterations) + 32) - 1; - - /** - * digest buf - */ - - digest[0] = hex_to_u32 ((const u8 *) &pswcheck[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &pswcheck[ 8]); - digest[2] = 0; - digest[3] = 0; - - return (PARSER_OK); -} - -int krb5tgs_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_13100) || (input_len > DISPLAY_LEN_MAX_13100)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_KRB5TGS, input_buf, 11)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - krb5tgs_t *krb5tgs = (krb5tgs_t *) hash_buf->esalt; - - /** - * parse line - */ - - /* Skip '$' */ - char *account_pos = input_buf + 11 + 1; - - char *data_pos; - - uint data_len; - - if (account_pos[0] == '*') - { - account_pos++; - - data_pos = strchr (account_pos, '*'); - - /* Skip '*' */ - data_pos++; - - if (data_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint account_len = data_pos - account_pos + 1; - - if (account_len >= 512) return (PARSER_SALT_LENGTH); - - /* Skip '$' */ - data_pos++; - - data_len = input_len - 11 - 1 - account_len - 2; - - memcpy (krb5tgs->account_info, account_pos - 1, account_len); - } - else - { - /* assume $krb5tgs$23$checksum$edata2 */ - data_pos = account_pos; - - memcpy (krb5tgs->account_info, "**", 3); - - data_len = input_len - 11 - 1 - 1; - } - - if (data_len < ((16 + 32) * 2)) return (PARSER_SALT_LENGTH); - - char *checksum_ptr = (char *) krb5tgs->checksum; - - for (uint i = 0; i < 16 * 2; i += 2) - { - const char p0 = data_pos[i + 0]; - const char p1 = data_pos[i + 1]; - - *checksum_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - char *edata_ptr = (char *) krb5tgs->edata2; - - krb5tgs->edata2_len = (data_len - 32) / 2 ; - - /* skip '$' */ - for (uint i = 16 * 2 + 1; i < (krb5tgs->edata2_len * 2) + (16 * 2 + 1); i += 2) - { - const char p0 = data_pos[i + 0]; - const char p1 = data_pos[i + 1]; - *edata_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - } - - /* this is needed for hmac_md5 */ - *edata_ptr++ = 0x80; - - salt->salt_buf[0] = krb5tgs->checksum[0]; - salt->salt_buf[1] = krb5tgs->checksum[1]; - salt->salt_buf[2] = krb5tgs->checksum[2]; - salt->salt_buf[3] = krb5tgs->checksum[3]; - - salt->salt_len = 32; - - digest[0] = krb5tgs->checksum[0]; - digest[1] = krb5tgs->checksum[1]; - digest[2] = krb5tgs->checksum[2]; - digest[3] = krb5tgs->checksum[3]; - - return (PARSER_OK); -} - -int axcrypt_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_13200) || (input_len > DISPLAY_LEN_MAX_13200)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_AXCRYPT, input_buf, 11)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - /** - * parse line - */ - - /* Skip '*' */ - char *wrapping_rounds_pos = input_buf + 11 + 1; - - char *salt_pos; - - char *wrapped_key_pos; - - char *data_pos; - - salt->salt_iter = atoi (wrapping_rounds_pos); - - salt_pos = strchr (wrapping_rounds_pos, '*'); - - if (salt_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint wrapping_rounds_len = salt_pos - wrapping_rounds_pos; - - /* Skip '*' */ - salt_pos++; - - data_pos = salt_pos; - - wrapped_key_pos = strchr (salt_pos, '*'); - - if (wrapped_key_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = wrapped_key_pos - salt_pos; - - if (salt_len != 32) return (PARSER_SALT_LENGTH); - - /* Skip '*' */ - wrapped_key_pos++; - - uint wrapped_key_len = input_len - 11 - 1 - wrapping_rounds_len - 1 - salt_len - 1; - - if (wrapped_key_len != 48) return (PARSER_SALT_LENGTH); - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &data_pos[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &data_pos[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &data_pos[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &data_pos[24]); - - data_pos += 33; - - salt->salt_buf[4] = hex_to_u32 ((const u8 *) &data_pos[ 0]); - salt->salt_buf[5] = hex_to_u32 ((const u8 *) &data_pos[ 8]); - salt->salt_buf[6] = hex_to_u32 ((const u8 *) &data_pos[16]); - salt->salt_buf[7] = hex_to_u32 ((const u8 *) &data_pos[24]); - salt->salt_buf[8] = hex_to_u32 ((const u8 *) &data_pos[32]); - salt->salt_buf[9] = hex_to_u32 ((const u8 *) &data_pos[40]); - - salt->salt_len = 40; - - digest[0] = salt->salt_buf[0]; - digest[1] = salt->salt_buf[1]; - digest[2] = salt->salt_buf[2]; - digest[3] = salt->salt_buf[3]; - - return (PARSER_OK); -} - -int keepass_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_13400) || (input_len > DISPLAY_LEN_MAX_13400)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_KEEPASS, input_buf, 9)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - keepass_t *keepass = (keepass_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *version_pos; - - char *rounds_pos; - - char *algorithm_pos; - - char *final_random_seed_pos; - u32 final_random_seed_len; - - char *transf_random_seed_pos; - u32 transf_random_seed_len; - - char *enc_iv_pos; - u32 enc_iv_len; - - /* default is no keyfile provided */ - char *keyfile_len_pos; - u32 keyfile_len = 0; - u32 is_keyfile_present = 0; - char *keyfile_inline_pos; - char *keyfile_pos; - - /* specific to version 1 */ - char *contents_len_pos; - u32 contents_len; - char *contents_pos; - - /* specific to version 2 */ - char *expected_bytes_pos; - u32 expected_bytes_len; - - char *contents_hash_pos; - u32 contents_hash_len; - - version_pos = input_buf + 8 + 1 + 1; - - keepass->version = atoi (version_pos); - - rounds_pos = strchr (version_pos, '*'); - - if (rounds_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - rounds_pos++; - - salt->salt_iter = (atoi (rounds_pos)); - - algorithm_pos = strchr (rounds_pos, '*'); - - if (algorithm_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - algorithm_pos++; - - keepass->algorithm = atoi (algorithm_pos); - - final_random_seed_pos = strchr (algorithm_pos, '*'); - - if (final_random_seed_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - final_random_seed_pos++; - - keepass->final_random_seed[0] = hex_to_u32 ((const u8 *) &final_random_seed_pos[ 0]); - keepass->final_random_seed[1] = hex_to_u32 ((const u8 *) &final_random_seed_pos[ 8]); - keepass->final_random_seed[2] = hex_to_u32 ((const u8 *) &final_random_seed_pos[16]); - keepass->final_random_seed[3] = hex_to_u32 ((const u8 *) &final_random_seed_pos[24]); - - if (keepass->version == 2) - { - keepass->final_random_seed[4] = hex_to_u32 ((const u8 *) &final_random_seed_pos[32]); - keepass->final_random_seed[5] = hex_to_u32 ((const u8 *) &final_random_seed_pos[40]); - keepass->final_random_seed[6] = hex_to_u32 ((const u8 *) &final_random_seed_pos[48]); - keepass->final_random_seed[7] = hex_to_u32 ((const u8 *) &final_random_seed_pos[56]); - } - - transf_random_seed_pos = strchr (final_random_seed_pos, '*'); - - if (transf_random_seed_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - final_random_seed_len = transf_random_seed_pos - final_random_seed_pos; - - if (keepass->version == 1 && final_random_seed_len != 32) return (PARSER_SALT_LENGTH); - if (keepass->version == 2 && final_random_seed_len != 64) return (PARSER_SALT_LENGTH); - - transf_random_seed_pos++; - - keepass->transf_random_seed[0] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[ 0]); - keepass->transf_random_seed[1] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[ 8]); - keepass->transf_random_seed[2] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[16]); - keepass->transf_random_seed[3] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[24]); - keepass->transf_random_seed[4] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[32]); - keepass->transf_random_seed[5] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[40]); - keepass->transf_random_seed[6] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[48]); - keepass->transf_random_seed[7] = hex_to_u32 ((const u8 *) &transf_random_seed_pos[56]); - - enc_iv_pos = strchr (transf_random_seed_pos, '*'); - - if (enc_iv_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - transf_random_seed_len = enc_iv_pos - transf_random_seed_pos; - - if (transf_random_seed_len != 64) return (PARSER_SALT_LENGTH); - - enc_iv_pos++; - - keepass->enc_iv[0] = hex_to_u32 ((const u8 *) &enc_iv_pos[ 0]); - keepass->enc_iv[1] = hex_to_u32 ((const u8 *) &enc_iv_pos[ 8]); - keepass->enc_iv[2] = hex_to_u32 ((const u8 *) &enc_iv_pos[16]); - keepass->enc_iv[3] = hex_to_u32 ((const u8 *) &enc_iv_pos[24]); - - if (keepass->version == 1) - { - contents_hash_pos = strchr (enc_iv_pos, '*'); - - if (contents_hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - enc_iv_len = contents_hash_pos - enc_iv_pos; - - if (enc_iv_len != 32) return (PARSER_SALT_LENGTH); - - contents_hash_pos++; - - keepass->contents_hash[0] = hex_to_u32 ((const u8 *) &contents_hash_pos[ 0]); - keepass->contents_hash[1] = hex_to_u32 ((const u8 *) &contents_hash_pos[ 8]); - keepass->contents_hash[2] = hex_to_u32 ((const u8 *) &contents_hash_pos[16]); - keepass->contents_hash[3] = hex_to_u32 ((const u8 *) &contents_hash_pos[24]); - keepass->contents_hash[4] = hex_to_u32 ((const u8 *) &contents_hash_pos[32]); - keepass->contents_hash[5] = hex_to_u32 ((const u8 *) &contents_hash_pos[40]); - keepass->contents_hash[6] = hex_to_u32 ((const u8 *) &contents_hash_pos[48]); - keepass->contents_hash[7] = hex_to_u32 ((const u8 *) &contents_hash_pos[56]); - - /* get length of contents following */ - char *inline_flag_pos = strchr (contents_hash_pos, '*'); - - if (inline_flag_pos == NULL) return (PARSER_SALT_LENGTH); - - contents_hash_len = inline_flag_pos - contents_hash_pos; - - if (contents_hash_len != 64) return (PARSER_SALT_LENGTH); - - inline_flag_pos++; - - u32 inline_flag = atoi (inline_flag_pos); - - if (inline_flag != 1) return (PARSER_SALT_LENGTH); - - contents_len_pos = strchr (inline_flag_pos, '*'); - - if (contents_len_pos == NULL) return (PARSER_SALT_LENGTH); - - contents_len_pos++; - - contents_len = atoi (contents_len_pos); - - if (contents_len > 50000) return (PARSER_SALT_LENGTH); - - contents_pos = strchr (contents_len_pos, '*'); - - if (contents_pos == NULL) return (PARSER_SALT_LENGTH); - - contents_pos++; - - u32 i; - - keepass->contents_len = contents_len; - - contents_len = contents_len / 4; - - keyfile_inline_pos = strchr (contents_pos, '*'); - - u32 real_contents_len; - - if (keyfile_inline_pos == NULL) - real_contents_len = input_len - (contents_pos - input_buf); - else - { - real_contents_len = keyfile_inline_pos - contents_pos; - keyfile_inline_pos++; - is_keyfile_present = 1; - } - - if (real_contents_len != keepass->contents_len * 2) return (PARSER_SALT_LENGTH); - - for (i = 0; i < contents_len; i++) - keepass->contents[i] = hex_to_u32 ((const u8 *) &contents_pos[i * 8]); - } - else if (keepass->version == 2) - { - expected_bytes_pos = strchr (enc_iv_pos, '*'); - - if (expected_bytes_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - enc_iv_len = expected_bytes_pos - enc_iv_pos; - - if (enc_iv_len != 32) return (PARSER_SALT_LENGTH); - - expected_bytes_pos++; - - keepass->expected_bytes[0] = hex_to_u32 ((const u8 *) &expected_bytes_pos[ 0]); - keepass->expected_bytes[1] = hex_to_u32 ((const u8 *) &expected_bytes_pos[ 8]); - keepass->expected_bytes[2] = hex_to_u32 ((const u8 *) &expected_bytes_pos[16]); - keepass->expected_bytes[3] = hex_to_u32 ((const u8 *) &expected_bytes_pos[24]); - keepass->expected_bytes[4] = hex_to_u32 ((const u8 *) &expected_bytes_pos[32]); - keepass->expected_bytes[5] = hex_to_u32 ((const u8 *) &expected_bytes_pos[40]); - keepass->expected_bytes[6] = hex_to_u32 ((const u8 *) &expected_bytes_pos[48]); - keepass->expected_bytes[7] = hex_to_u32 ((const u8 *) &expected_bytes_pos[56]); - - contents_hash_pos = strchr (expected_bytes_pos, '*'); - - if (contents_hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - expected_bytes_len = contents_hash_pos - expected_bytes_pos; - - if (expected_bytes_len != 64) return (PARSER_SALT_LENGTH); - - contents_hash_pos++; - - keepass->contents_hash[0] = hex_to_u32 ((const u8 *) &contents_hash_pos[ 0]); - keepass->contents_hash[1] = hex_to_u32 ((const u8 *) &contents_hash_pos[ 8]); - keepass->contents_hash[2] = hex_to_u32 ((const u8 *) &contents_hash_pos[16]); - keepass->contents_hash[3] = hex_to_u32 ((const u8 *) &contents_hash_pos[24]); - keepass->contents_hash[4] = hex_to_u32 ((const u8 *) &contents_hash_pos[32]); - keepass->contents_hash[5] = hex_to_u32 ((const u8 *) &contents_hash_pos[40]); - keepass->contents_hash[6] = hex_to_u32 ((const u8 *) &contents_hash_pos[48]); - keepass->contents_hash[7] = hex_to_u32 ((const u8 *) &contents_hash_pos[56]); - - keyfile_inline_pos = strchr (contents_hash_pos, '*'); - - if (keyfile_inline_pos == NULL) - contents_hash_len = input_len - (int) (contents_hash_pos - input_buf); - else - { - contents_hash_len = keyfile_inline_pos - contents_hash_pos; - keyfile_inline_pos++; - is_keyfile_present = 1; - } - if (contents_hash_len != 64) return (PARSER_SALT_LENGTH); - } - - if (is_keyfile_present != 0) - { - keyfile_len_pos = strchr (keyfile_inline_pos, '*'); - - keyfile_len_pos++; - - keyfile_len = atoi (keyfile_len_pos); - - keepass->keyfile_len = keyfile_len; - - if (keyfile_len != 64) return (PARSER_SALT_LENGTH); - - keyfile_pos = strchr (keyfile_len_pos, '*'); - - if (keyfile_pos == NULL) return (PARSER_SALT_LENGTH); - - keyfile_pos++; - - u32 real_keyfile_len = input_len - (keyfile_pos - input_buf); - - if (real_keyfile_len != 64) return (PARSER_SALT_LENGTH); - - keepass->keyfile[0] = hex_to_u32 ((const u8 *) &keyfile_pos[ 0]); - keepass->keyfile[1] = hex_to_u32 ((const u8 *) &keyfile_pos[ 8]); - keepass->keyfile[2] = hex_to_u32 ((const u8 *) &keyfile_pos[16]); - keepass->keyfile[3] = hex_to_u32 ((const u8 *) &keyfile_pos[24]); - keepass->keyfile[4] = hex_to_u32 ((const u8 *) &keyfile_pos[32]); - keepass->keyfile[5] = hex_to_u32 ((const u8 *) &keyfile_pos[40]); - keepass->keyfile[6] = hex_to_u32 ((const u8 *) &keyfile_pos[48]); - keepass->keyfile[7] = hex_to_u32 ((const u8 *) &keyfile_pos[56]); - } - - digest[0] = keepass->enc_iv[0]; - digest[1] = keepass->enc_iv[1]; - digest[2] = keepass->enc_iv[2]; - digest[3] = keepass->enc_iv[3]; - - salt->salt_buf[0] = keepass->transf_random_seed[0]; - salt->salt_buf[1] = keepass->transf_random_seed[1]; - salt->salt_buf[2] = keepass->transf_random_seed[2]; - salt->salt_buf[3] = keepass->transf_random_seed[3]; - salt->salt_buf[4] = keepass->transf_random_seed[4]; - salt->salt_buf[5] = keepass->transf_random_seed[5]; - salt->salt_buf[6] = keepass->transf_random_seed[6]; - salt->salt_buf[7] = keepass->transf_random_seed[7]; - - return (PARSER_OK); -} - -int cf10_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_12600) || (input_len > DISPLAY_LEN_MAX_12600)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); - digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); - digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); - - if (input_buf[64] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - uint salt_len = input_len - 64 - 1; - - char *salt_buf = input_buf + 64 + 1; - - char *salt_buf_ptr = (char *) salt->salt_buf; - - salt_len = parse_and_store_salt (salt_buf_ptr, salt_buf, salt_len); - - if (salt_len == UINT_MAX) return (PARSER_SALT_LENGTH); - - salt->salt_len = salt_len; - - /** - * we can precompute the first sha256 transform - */ - - uint w[16] = { 0 }; - - w[ 0] = byte_swap_32 (salt->salt_buf[ 0]); - w[ 1] = byte_swap_32 (salt->salt_buf[ 1]); - w[ 2] = byte_swap_32 (salt->salt_buf[ 2]); - w[ 3] = byte_swap_32 (salt->salt_buf[ 3]); - w[ 4] = byte_swap_32 (salt->salt_buf[ 4]); - w[ 5] = byte_swap_32 (salt->salt_buf[ 5]); - w[ 6] = byte_swap_32 (salt->salt_buf[ 6]); - w[ 7] = byte_swap_32 (salt->salt_buf[ 7]); - w[ 8] = byte_swap_32 (salt->salt_buf[ 8]); - w[ 9] = byte_swap_32 (salt->salt_buf[ 9]); - w[10] = byte_swap_32 (salt->salt_buf[10]); - w[11] = byte_swap_32 (salt->salt_buf[11]); - w[12] = byte_swap_32 (salt->salt_buf[12]); - w[13] = byte_swap_32 (salt->salt_buf[13]); - w[14] = byte_swap_32 (salt->salt_buf[14]); - w[15] = byte_swap_32 (salt->salt_buf[15]); - - uint pc256[8] = { SHA256M_A, SHA256M_B, SHA256M_C, SHA256M_D, SHA256M_E, SHA256M_F, SHA256M_G, SHA256M_H }; - - sha256_64 (w, pc256); - - salt->salt_buf_pc[0] = pc256[0]; - salt->salt_buf_pc[1] = pc256[1]; - salt->salt_buf_pc[2] = pc256[2]; - salt->salt_buf_pc[3] = pc256[3]; - salt->salt_buf_pc[4] = pc256[4]; - salt->salt_buf_pc[5] = pc256[5]; - salt->salt_buf_pc[6] = pc256[6]; - salt->salt_buf_pc[7] = pc256[7]; - - digest[0] -= pc256[0]; - digest[1] -= pc256[1]; - digest[2] -= pc256[2]; - digest[3] -= pc256[3]; - digest[4] -= pc256[4]; - digest[5] -= pc256[5]; - digest[6] -= pc256[6]; - digest[7] -= pc256[7]; - - return (PARSER_OK); -} - -int mywallet_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_12700) || (input_len > DISPLAY_LEN_MAX_12700)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_MYWALLET, input_buf, 12)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - /** - * parse line - */ - - char *data_len_pos = input_buf + 1 + 10 + 1; - - char *data_buf_pos = strchr (data_len_pos, '$'); - - if (data_buf_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 data_len_len = data_buf_pos - data_len_pos; - - if (data_len_len < 1) return (PARSER_SALT_LENGTH); - if (data_len_len > 5) return (PARSER_SALT_LENGTH); - - data_buf_pos++; - - u32 data_buf_len = input_len - 1 - 10 - 1 - data_len_len - 1; - - if (data_buf_len < 64) return (PARSER_HASH_LENGTH); - - if (data_buf_len % 16) return (PARSER_HASH_LENGTH); - - u32 data_len = atoi (data_len_pos); - - if ((data_len * 2) != data_buf_len) return (PARSER_HASH_LENGTH); - - /** - * salt - */ - - char *salt_pos = data_buf_pos; - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_pos[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_pos[16]); - salt->salt_buf[3] = hex_to_u32 ((const u8 *) &salt_pos[24]); - - // this is actually the CT, which is also the hash later (if matched) - - salt->salt_buf[4] = hex_to_u32 ((const u8 *) &salt_pos[32]); - salt->salt_buf[5] = hex_to_u32 ((const u8 *) &salt_pos[40]); - salt->salt_buf[6] = hex_to_u32 ((const u8 *) &salt_pos[48]); - salt->salt_buf[7] = hex_to_u32 ((const u8 *) &salt_pos[56]); - - salt->salt_len = 32; // note we need to fix this to 16 in kernel - - salt->salt_iter = 10 - 1; - - /** - * digest buf - */ - - digest[0] = salt->salt_buf[4]; - digest[1] = salt->salt_buf[5]; - digest[2] = salt->salt_buf[6]; - digest[3] = salt->salt_buf[7]; - - return (PARSER_OK); -} - -int ms_drsr_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_12800) || (input_len > DISPLAY_LEN_MAX_12800)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_MS_DRSR, input_buf, 11)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - /** - * parse line - */ - - char *salt_pos = input_buf + 11 + 1; - - char *iter_pos = strchr (salt_pos, ','); - - if (iter_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 salt_len = iter_pos - salt_pos; - - if (salt_len != 20) return (PARSER_SALT_LENGTH); - - iter_pos++; - - char *hash_pos = strchr (iter_pos, ','); - - if (hash_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 iter_len = hash_pos - iter_pos; - - if (iter_len > 5) return (PARSER_SALT_LENGTH); - - hash_pos++; - - u32 hash_len = input_len - 11 - 1 - salt_len - 1 - iter_len - 1; - - if (hash_len != 64) return (PARSER_HASH_LENGTH); - - /** - * salt - */ - - salt->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_pos[ 0]); - salt->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_pos[ 8]); - salt->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_pos[16]) & 0xffff0000; - salt->salt_buf[3] = 0x00018000; - - salt->salt_buf[0] = byte_swap_32 (salt->salt_buf[0]); - salt->salt_buf[1] = byte_swap_32 (salt->salt_buf[1]); - salt->salt_buf[2] = byte_swap_32 (salt->salt_buf[2]); - salt->salt_buf[3] = byte_swap_32 (salt->salt_buf[3]); - - salt->salt_len = salt_len / 2; - - salt->salt_iter = atoi (iter_pos) - 1u; - - /** - * digest buf - */ - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); - digest[5] = hex_to_u32 ((const u8 *) &hash_pos[40]); - digest[6] = hex_to_u32 ((const u8 *) &hash_pos[48]); - digest[7] = hex_to_u32 ((const u8 *) &hash_pos[56]); - - return (PARSER_OK); -} - -int androidfde_samsung_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_12900) || (input_len > DISPLAY_LEN_MAX_12900)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - /** - * parse line - */ - - char *hash_pos = input_buf + 64; - char *salt1_pos = input_buf + 128; - char *salt2_pos = input_buf; - - /** - * salt - */ - - salt->salt_buf[ 0] = hex_to_u32 ((const u8 *) &salt1_pos[ 0]); - salt->salt_buf[ 1] = hex_to_u32 ((const u8 *) &salt1_pos[ 8]); - salt->salt_buf[ 2] = hex_to_u32 ((const u8 *) &salt1_pos[16]); - salt->salt_buf[ 3] = hex_to_u32 ((const u8 *) &salt1_pos[24]); - - salt->salt_buf[ 4] = hex_to_u32 ((const u8 *) &salt2_pos[ 0]); - salt->salt_buf[ 5] = hex_to_u32 ((const u8 *) &salt2_pos[ 8]); - salt->salt_buf[ 6] = hex_to_u32 ((const u8 *) &salt2_pos[16]); - salt->salt_buf[ 7] = hex_to_u32 ((const u8 *) &salt2_pos[24]); - - salt->salt_buf[ 8] = hex_to_u32 ((const u8 *) &salt2_pos[32]); - salt->salt_buf[ 9] = hex_to_u32 ((const u8 *) &salt2_pos[40]); - salt->salt_buf[10] = hex_to_u32 ((const u8 *) &salt2_pos[48]); - salt->salt_buf[11] = hex_to_u32 ((const u8 *) &salt2_pos[56]); - - salt->salt_len = 48; - - salt->salt_iter = ROUNDS_ANDROIDFDE_SAMSUNG - 1; - - /** - * digest buf - */ - - digest[0] = hex_to_u32 ((const u8 *) &hash_pos[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &hash_pos[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &hash_pos[16]); - digest[3] = hex_to_u32 ((const u8 *) &hash_pos[24]); - digest[4] = hex_to_u32 ((const u8 *) &hash_pos[32]); - digest[5] = hex_to_u32 ((const u8 *) &hash_pos[40]); - digest[6] = hex_to_u32 ((const u8 *) &hash_pos[48]); - digest[7] = hex_to_u32 ((const u8 *) &hash_pos[56]); - - return (PARSER_OK); -} - -int zip2_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_13600) || (input_len > DISPLAY_LEN_MAX_13600)) return (PARSER_GLOBAL_LENGTH); - - if (memcmp (SIGNATURE_ZIP2_START, input_buf , 6)) return (PARSER_SIGNATURE_UNMATCHED); - if (memcmp (SIGNATURE_ZIP2_STOP , input_buf + input_len - 7, 7)) return (PARSER_SIGNATURE_UNMATCHED); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - zip2_t *zip2 = (zip2_t *) hash_buf->esalt; - - /** - * parse line - */ - - char *param0_pos = input_buf + 6 + 1; - - char *param1_pos = strchr (param0_pos, '*'); - - if (param1_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param0_len = param1_pos - param0_pos; - - param1_pos++; - - char *param2_pos = strchr (param1_pos, '*'); - - if (param2_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param1_len = param2_pos - param1_pos; - - param2_pos++; - - char *param3_pos = strchr (param2_pos, '*'); - - if (param3_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param2_len = param3_pos - param2_pos; - - param3_pos++; - - char *param4_pos = strchr (param3_pos, '*'); - - if (param4_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param3_len = param4_pos - param3_pos; - - param4_pos++; - - char *param5_pos = strchr (param4_pos, '*'); - - if (param5_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param4_len = param5_pos - param4_pos; - - param5_pos++; - - char *param6_pos = strchr (param5_pos, '*'); - - if (param6_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param5_len = param6_pos - param5_pos; - - param6_pos++; - - char *param7_pos = strchr (param6_pos, '*'); - - if (param7_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param6_len = param7_pos - param6_pos; - - param7_pos++; - - char *param8_pos = strchr (param7_pos, '*'); - - if (param8_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); - - u32 param7_len = param8_pos - param7_pos; - - param8_pos++; - - const uint type = atoi (param0_pos); - const uint mode = atoi (param1_pos); - const uint magic = atoi (param2_pos); - - char *salt_buf = param3_pos; - - uint verify_bytes; sscanf (param4_pos, "%4x*", &verify_bytes); - - const uint compress_length = atoi (param5_pos); - - char *data_buf = param6_pos; - char *auth = param7_pos; - - /** - * verify some data - */ - - if (param0_len != 1) return (PARSER_SALT_VALUE); - - if (param1_len != 1) return (PARSER_SALT_VALUE); - - if (param2_len != 1) return (PARSER_SALT_VALUE); - - if ((param3_len != 16) && (param3_len != 24) && (param3_len != 32)) return (PARSER_SALT_VALUE); - - if (param4_len >= 5) return (PARSER_SALT_VALUE); - - if (param5_len >= 5) return (PARSER_SALT_VALUE); - - if (param6_len >= 8192) return (PARSER_SALT_VALUE); - - if (param6_len & 1) return (PARSER_SALT_VALUE); - - if (param7_len != 20) return (PARSER_SALT_VALUE); - - if (type != 0) return (PARSER_SALT_VALUE); - - if ((mode != 1) && (mode != 2) && (mode != 3)) return (PARSER_SALT_VALUE); - - if (magic != 0) return (PARSER_SALT_VALUE); - - if (verify_bytes >= 0x10000) return (PARSER_SALT_VALUE); - - /** - * store data - */ - - zip2->type = type; - zip2->mode = mode; - zip2->magic = magic; - - if (mode == 1) - { - zip2->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_buf[ 0]); - zip2->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_buf[ 8]); - zip2->salt_buf[2] = 0; - zip2->salt_buf[3] = 0; - - zip2->salt_len = 8; - } - else if (mode == 2) - { - zip2->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_buf[ 0]); - zip2->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_buf[ 8]); - zip2->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_buf[16]); - zip2->salt_buf[3] = 0; - - zip2->salt_len = 12; - } - else if (mode == 3) - { - zip2->salt_buf[0] = hex_to_u32 ((const u8 *) &salt_buf[ 0]); - zip2->salt_buf[1] = hex_to_u32 ((const u8 *) &salt_buf[ 8]); - zip2->salt_buf[2] = hex_to_u32 ((const u8 *) &salt_buf[16]); - zip2->salt_buf[3] = hex_to_u32 ((const u8 *) &salt_buf[24]); - - zip2->salt_len = 16; - } - - zip2->salt_buf[0] = byte_swap_32 (zip2->salt_buf[0]); - zip2->salt_buf[1] = byte_swap_32 (zip2->salt_buf[1]); - zip2->salt_buf[2] = byte_swap_32 (zip2->salt_buf[2]); - zip2->salt_buf[3] = byte_swap_32 (zip2->salt_buf[3]); - - zip2->verify_bytes = verify_bytes; - - zip2->compress_length = compress_length; - - char *data_buf_ptr = (char *) zip2->data_buf; - - for (uint i = 0; i < param6_len; i += 2) - { - const char p0 = data_buf[i + 0]; - const char p1 = data_buf[i + 1]; - - *data_buf_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - - zip2->data_len++; - } - - *data_buf_ptr = 0x80; - - char *auth_ptr = (char *) zip2->auth_buf; - - for (uint i = 0; i < param7_len; i += 2) - { - const char p0 = auth[i + 0]; - const char p1 = auth[i + 1]; - - *auth_ptr++ = hex_convert (p1) << 0 - | hex_convert (p0) << 4; - - zip2->auth_len++; - } - - /** - * salt buf (fake) - */ - - salt->salt_buf[0] = zip2->salt_buf[0]; - salt->salt_buf[1] = zip2->salt_buf[1]; - salt->salt_buf[2] = zip2->salt_buf[2]; - salt->salt_buf[3] = zip2->salt_buf[3]; - salt->salt_buf[4] = zip2->data_buf[0]; - salt->salt_buf[5] = zip2->data_buf[1]; - salt->salt_buf[6] = zip2->data_buf[2]; - salt->salt_buf[7] = zip2->data_buf[3]; - - salt->salt_len = 32; - - salt->salt_iter = ROUNDS_ZIP2 - 1; - - /** - * digest buf (fake) - */ - - digest[0] = zip2->auth_buf[0]; - digest[1] = zip2->auth_buf[1]; - digest[2] = zip2->auth_buf[2]; - digest[3] = zip2->auth_buf[3]; - - return (PARSER_OK); -} - -int win8phone_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf) -{ - if ((input_len < DISPLAY_LEN_MIN_13800) || (input_len > DISPLAY_LEN_MAX_13800)) return (PARSER_GLOBAL_LENGTH); - - u32 *digest = (u32 *) hash_buf->digest; - - salt_t *salt = hash_buf->salt; - - win8phone_t *esalt = hash_buf->esalt; - - digest[0] = hex_to_u32 ((const u8 *) &input_buf[ 0]); - digest[1] = hex_to_u32 ((const u8 *) &input_buf[ 8]); - digest[2] = hex_to_u32 ((const u8 *) &input_buf[16]); - digest[3] = hex_to_u32 ((const u8 *) &input_buf[24]); - digest[4] = hex_to_u32 ((const u8 *) &input_buf[32]); - digest[5] = hex_to_u32 ((const u8 *) &input_buf[40]); - digest[6] = hex_to_u32 ((const u8 *) &input_buf[48]); - digest[7] = hex_to_u32 ((const u8 *) &input_buf[56]); - - if (input_buf[64] != data.separator) return (PARSER_SEPARATOR_UNMATCHED); - - char *salt_buf_ptr = input_buf + 64 + 1; - - u32 *salt_buf = esalt->salt_buf; - - for (int i = 0, j = 0; i < 32; i += 1, j += 8) - { - salt_buf[i] = hex_to_u32 ((const u8 *) &salt_buf_ptr[j]); - } - - salt->salt_buf[0] = salt_buf[0]; - salt->salt_buf[1] = salt_buf[1]; - salt->salt_buf[2] = salt_buf[2]; - salt->salt_buf[3] = salt_buf[3]; - salt->salt_buf[4] = salt_buf[4]; - salt->salt_buf[5] = salt_buf[5]; - salt->salt_buf[6] = salt_buf[6]; - salt->salt_buf[7] = salt_buf[7]; - - salt->salt_len = 64; - - return (PARSER_OK); -} - /** * parallel running threads */