>From d4749798f42bf3f6a5261ed3028137236b3852e5 Mon Sep 17 00:00:00 2001 From: Frank Dittrich Date: Fri, 15 Jun 2012 12:23:33 +0200 Subject: [PATCH 1/4] Markov mode: move parameter validation into new function get_markov_options Additionaly, the logic has been changed so that the max. values for level and length are adjusted prior to checking min. values, to avoid adjusting min. value to a max. value which is changed afterwards: Instead of $ ./john --markov=501-500:0:0:35-31 --stdout Warning: max level(500) < min level(501), min level set to 500 Warning: minimum length(35) < maximum length(31), minimum length set to 31 Warning: Maxlen = 31 is too large (max = 30) Warning: Level = 500 is too large (max = 400) MKV start (lvl=500-400 len=31-30 pwd=182847102117099741) the new logic will be $ ./john --markov=501-500:0:0:35-31 --stdout Warning: Level = 500 is too large (max = 400) Warning: Maxlen = 31 is too large (max = 30) Warning: max level(400) < min level(501), min level set to 400 Warning: minimum length(35) < maximum length(30), minimum length set to 30 MKV start (lvl=400-400 len=30-30 pwd=182847102117099741) Furthermore, maxlen > MAX_MKV_LEN will only be checked if db->format->params.plaintext_length > MAX_MKV_LEN. (Otherwise, the format specific max. length is the limit.) --- src/mkv.c | 148 +++++++++++++++++++++++++++++++++--------------------------- 1 files changed, 81 insertions(+), 67 deletions(-) diff --git a/src/mkv.c b/src/mkv.c index dd43e24..e72188f 100644 --- a/src/mkv.c +++ b/src/mkv.c @@ -239,31 +239,29 @@ static int get_progress(int *hundth_perc) return per; } - -void do_markov_crack(struct db_main *db, char * mkv_param) +void get_markov_options(struct db_main *db, + char *mkv_param, + unsigned int *minlevel, unsigned int *level, + unsigned long long *start, unsigned long long *end, + unsigned int *minlen, unsigned int *maxlen, + char **statfile) { - char * statfile; - unsigned int mkv_minlevel, mkv_level, mkv_maxlen, mkv_minlen; - unsigned long long mkv_start, mkv_end; - -#ifdef HAVE_MPI - unsigned long long mkv_size; -#endif char * token; - mkv_level = 0; - mkv_start = 0; - mkv_end = 0; - mkv_maxlen = 0; - mkv_minlevel = 0; - mkv_minlen = 0; + *level = 0; + *start = 0; + *end = 0; + *maxlen = 0; + *minlevel = 0; + *minlen = 0; + if (mkv_param) { token = strtok(mkv_param, ":"); - if(sscanf(token, "%d-%d", &mkv_minlevel, &mkv_level) != 2) + if(sscanf(token, "%d-%d", minlevel, level) != 2) { - mkv_minlevel = 0; - if (sscanf(token, "%d", &mkv_level) != 1) + *minlevel = 0; + if (sscanf(token, "%d", level) != 1) { #ifdef HAVE_MPI if (mpi_id == 0) @@ -273,40 +271,23 @@ void do_markov_crack(struct db_main *db, char * mkv_param) } } token = strtok(NULL, ":"); - if( (token != NULL) && (sscanf(token, LLd, &mkv_start)==1) ) + if( (token != NULL) && (sscanf(token, LLd, start)==1) ) { token = strtok(NULL, ":"); - if( (token != NULL) && (sscanf(token, LLd, &mkv_end)==1) ) + if( (token != NULL) && (sscanf(token, LLd, end)==1) ) { token = strtok(NULL, ":"); - if( (token != NULL) && (sscanf(token, "%d-%d", &mkv_minlen, &mkv_maxlen)!=2) ) + if( (token != NULL) && (sscanf(token, "%d-%d", minlen, maxlen)!=2) ) { - mkv_minlen = 0; - sscanf(token, "%d", &mkv_maxlen); + *minlen = 0; + sscanf(token, "%d", maxlen); } } } } - if(mkv_level mkv_maxlen) - { -#ifdef HAVE_MPI - if (mpi_id == 0) -#endif - fprintf(stderr, "Warning: minimum length(%d) < maximum length(%d), minimum length set to %d\n", mkv_minlen, mkv_maxlen, mkv_maxlen); - mkv_minlen = mkv_maxlen; - } - - if(mkv_level == 0) - if( (mkv_level = cfg_get_int(SECTION_MARKOV, SUBSECTION_DEFAULT, "MkvLvl")) == -1 ) + if(*level == 0) + if( (*level = cfg_get_int(SECTION_MARKOV, SUBSECTION_DEFAULT, "MkvLvl")) == -1 ) { log_event("no markov level defined!"); #ifdef HAVE_MPI @@ -316,8 +297,17 @@ void do_markov_crack(struct db_main *db, char * mkv_param) error(); } - if(mkv_maxlen == 0) - if( (mkv_maxlen = cfg_get_int(SECTION_MARKOV, SUBSECTION_DEFAULT, "MkvMaxLen")) == -1 ) + if (*level > MAX_MKV_LVL) { + log_event("! Level = %d is too large (max=%d)", *level, MAX_MKV_LVL); +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, "Warning: Level = %d is too large (max = %d)\n", *level, MAX_MKV_LVL); + *level = MAX_MKV_LVL; + } + + if(*maxlen == 0) + if( (*maxlen = cfg_get_int(SECTION_MARKOV, SUBSECTION_DEFAULT, "MkvMaxLen")) == -1 ) { log_event("no markov max length defined!"); #ifdef HAVE_MPI @@ -327,47 +317,71 @@ void do_markov_crack(struct db_main *db, char * mkv_param) error(); } - statfile = cfg_get_param(SECTION_MARKOV, SUBSECTION_DEFAULT, "Statsfile"); - if(statfile == NULL) - { - log_event("statfile not defined"); -#ifdef HAVE_MPI - if (mpi_id == 0) -#endif - fprintf(stderr, "Statfile not defined\n"); - error(); - } - - if (mkv_maxlen > db->format->params.plaintext_length) { + if (db->format->params.plaintext_length <= MAX_MKV_LEN && + *maxlen > db->format->params.plaintext_length) { log_event("! MaxLen = %d is too large for this hash type", - mkv_maxlen); + *maxlen); #ifdef HAVE_MPI if (mpi_id == 0) #endif fprintf(stderr, "Warning: " "MaxLen = %d is too large for the current hash type, " "reduced to %d\n", - mkv_maxlen, db->format->params.plaintext_length); - mkv_maxlen = db->format->params.plaintext_length; + *maxlen, db->format->params.plaintext_length); + *maxlen = db->format->params.plaintext_length; + } + else + if (*maxlen > MAX_MKV_LEN) { + log_event("! MaxLen = %d is too large (max=%d)", *maxlen, MAX_MKV_LEN); +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, "Warning: Maxlen = %d is too large (max = %d)\n", *maxlen, MAX_MKV_LEN); + *maxlen = MAX_MKV_LEN; } - if (mkv_maxlen > MAX_MKV_LEN) { - log_event("! MaxLen = %d is too large (max=%d)", mkv_maxlen, MAX_MKV_LEN); + if(*level<*minlevel) + { +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, "Warning: max level(%d) < min level(%d), min level set to %d\n", *level, *minlevel, *level); + *minlevel = *level; + } + if(*minlen > *maxlen) + { #ifdef HAVE_MPI if (mpi_id == 0) #endif - fprintf(stderr, "Warning: Maxlen = %d is too large (max = %d)\n", mkv_maxlen, MAX_MKV_LEN); - mkv_maxlen = MAX_MKV_LEN; + fprintf(stderr, "Warning: minimum length(%d) < maximum length(%d), minimum length set to %d\n", *minlen, *maxlen, *maxlen); + *minlen = *maxlen; } - if (mkv_level > MAX_MKV_LVL) { - log_event("! Level = %d is too large (max=%d)", mkv_level, MAX_MKV_LVL); + *statfile = cfg_get_param(SECTION_MARKOV, SUBSECTION_DEFAULT, "Statsfile"); + if(*statfile == NULL) + { + log_event("statfile not defined"); #ifdef HAVE_MPI if (mpi_id == 0) #endif - fprintf(stderr, "Warning: Level = %d is too large (max = %d)\n", mkv_level, MAX_MKV_LVL); - mkv_level = MAX_MKV_LVL; + fprintf(stderr, "Statfile not defined\n"); + error(); } +} +void do_markov_crack(struct db_main *db, char *mkv_param) +{ + char *statfile = NULL; + unsigned int mkv_minlevel, mkv_level, mkv_maxlen, mkv_minlen; + unsigned long long mkv_start, mkv_end; + +#ifdef HAVE_MPI + unsigned long long mkv_size; +#endif + + get_markov_options(db, + mkv_param, + &mkv_minlevel, &mkv_level, &mkv_start, &mkv_end, + &mkv_minlen, &mkv_maxlen, &statfile); gidx = 0; status_init(get_progress, 0); -- 1.7.7.6