Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/LM_fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "DES_bs.h"
#include "common.h"
#include "formats.h"
#include "color.h"
#include "unicode.h"

#define FORMAT_LABEL "LM"
#define FORMAT_NAME ""
Expand Down Expand Up @@ -48,6 +50,7 @@ static struct fmt_tests tests[] = {
{"$LM$1d91a081d4b37861", "Z"},
{"$LM$" LM_EMPTY, ""},
{"$LM$fea4ab7d7b7d0452", "0688648"},
/* tests[16] and up may be disabled in init() */
{"$LM$2734832a3bee748c", "273.15\xf8"}, /* 8-bit, 273.15° using DOS codepage */
{"$LM$db82323cb0693862", "2275490"},
{"$LM$44b3b60db75c15c1", "2716388"},
Expand Down Expand Up @@ -120,6 +123,16 @@ static void init(struct fmt_main *self)
fmt_LM.params.min_keys_per_crypt = DES_bs_min_kpc;
fmt_LM.params.max_keys_per_crypt = DES_bs_max_kpc;
#endif

static int warned;
if (!warned && options.target_enc > CP_DOS_HI && !options.listconf &&
sizeof(tests) / sizeof(tests[0]) > 16) {
fprintf_color(color_warning, stderr,
"Warning: LM formats incompatible with %s encoding, disabling some tests\n",
cp_id2name(options.target_enc));
tests[16].ciphertext = NULL; // Truncates the array after 16 entries
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we at least add a comment within the tests array initializer about index/element 16 being special. Also, let's not end messages with a dot except when it's multiple sentences/lines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added a test for sizeof(tests) / sizeof(tests[0]) > 16 before truncating. I often comment out many test vectors when debugging.

warned = 1;
}
}

static char *prepare(char *fields[10], struct fmt_main *self)
Expand Down
13 changes: 13 additions & 0 deletions src/opencl_lm_fmt_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ john_register_one(&fmt_opencl_lm);
#include "common.h"
#include "formats.h"
#include "config.h"
#include "color.h"
#include "unicode.h"
#include "../run/opencl/opencl_lm_hst_dev_shared.h"

#define FORMAT_NAME ""
Expand Down Expand Up @@ -50,6 +52,7 @@ static struct fmt_tests tests[] = {
{"$LM$1d91a081d4b37861", "Z"},
{"$LM$" LM_EMPTY, ""},
{"$LM$fea4ab7d7b7d0452", "0688648"},
/* tests[16] and up may be disabled in init() */
{"$LM$2734832a3bee748c", "273.15\xf8"}, /* 8-bit, 273.15° using DOS codepage */
{"$LM$db82323cb0693862", "2275490"},
{"$LM$44b3b60db75c15c1", "2716388"},
Expand Down Expand Up @@ -116,6 +119,16 @@ static void init(struct fmt_main *pFmt)
opencl_prepare_dev(gpu_id);
opencl_lm_b_register_functions(pFmt);
opencl_lm_init_global_variables();

static int warned;
if (!warned && options.target_enc > CP_DOS_HI && !options.listconf &&
sizeof(tests) / sizeof(tests[0]) > 16) {
fprintf_color(color_warning, stderr,
"Warning: LM formats incompatible with %s encoding, disabling some self-tests\n",
cp_id2name(options.target_enc));
tests[16].ciphertext = NULL; // Truncates the array after 16 entries
warned = 1;
}
}

static char *prepare(char *fields[10], struct fmt_main *self)
Expand Down
6 changes: 6 additions & 0 deletions src/unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ extern void utf8_to_utf8_32(UTF32 *dst, UTF8 *src);
/* Convert UTF-32 to UTF-8-32, in place */
extern void utf32_to_utf8_32(UTF32 *in_place_string);

/* Return codepage class (eg. CP_DOS) of a specific encoding */
extern int cp_class(int encoding);

/* Convert numerical encoding ID to canonical name */
char *cp_id2name(int encoding);

/*
* NOTE! Please read the comments in formats.h for FMT_UNICODE and FMT_ENC
*/
Expand Down