Skip to content

Commit 25c1ab6

Browse files
committed
LM formats: Fix for 8-bit self-tests
The test vectors we ended up with in d7a4b6d are only compatible with DOS codepages. We now detect if running with non-DOS codepage or UTF8, and emit a warning. We then also truncate the array of self-tests so they don't fail. Closes #5887
1 parent 4f29349 commit 25c1ab6

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/LM_fmt.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "DES_bs.h"
1818
#include "common.h"
1919
#include "formats.h"
20+
#include "color.h"
21+
#include "unicode.h"
2022

2123
#define FORMAT_LABEL "LM"
2224
#define FORMAT_NAME ""
@@ -48,6 +50,7 @@ static struct fmt_tests tests[] = {
4850
{"$LM$1d91a081d4b37861", "Z"},
4951
{"$LM$" LM_EMPTY, ""},
5052
{"$LM$fea4ab7d7b7d0452", "0688648"},
53+
/* tests[16] and up may be disabled in init() */
5154
{"$LM$2734832a3bee748c", "273.15\xf8"}, /* 8-bit, 273.15° using DOS codepage */
5255
{"$LM$db82323cb0693862", "2275490"},
5356
{"$LM$44b3b60db75c15c1", "2716388"},
@@ -120,6 +123,16 @@ static void init(struct fmt_main *self)
120123
fmt_LM.params.min_keys_per_crypt = DES_bs_min_kpc;
121124
fmt_LM.params.max_keys_per_crypt = DES_bs_max_kpc;
122125
#endif
126+
127+
static int warned;
128+
if (!warned && options.target_enc > CP_DOS_HI && !options.listconf &&
129+
sizeof(tests) / sizeof(tests[0]) > 16) {
130+
fprintf_color(color_warning, stderr,
131+
"Warning: LM formats incompatible with %s encoding, disabling some tests\n",
132+
cp_id2name(options.target_enc));
133+
tests[16].ciphertext = NULL; // Truncates the array after 16 entries
134+
warned = 1;
135+
}
123136
}
124137

125138
static char *prepare(char *fields[10], struct fmt_main *self)

src/opencl_lm_fmt_plug.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ john_register_one(&fmt_opencl_lm);
2020
#include "common.h"
2121
#include "formats.h"
2222
#include "config.h"
23+
#include "color.h"
24+
#include "unicode.h"
2325
#include "../run/opencl/opencl_lm_hst_dev_shared.h"
2426

2527
#define FORMAT_NAME ""
@@ -50,6 +52,7 @@ static struct fmt_tests tests[] = {
5052
{"$LM$1d91a081d4b37861", "Z"},
5153
{"$LM$" LM_EMPTY, ""},
5254
{"$LM$fea4ab7d7b7d0452", "0688648"},
55+
/* tests[16] and up may be disabled in init() */
5356
{"$LM$2734832a3bee748c", "273.15\xf8"}, /* 8-bit, 273.15° using DOS codepage */
5457
{"$LM$db82323cb0693862", "2275490"},
5558
{"$LM$44b3b60db75c15c1", "2716388"},
@@ -116,6 +119,16 @@ static void init(struct fmt_main *pFmt)
116119
opencl_prepare_dev(gpu_id);
117120
opencl_lm_b_register_functions(pFmt);
118121
opencl_lm_init_global_variables();
122+
123+
static int warned;
124+
if (!warned && options.target_enc > CP_DOS_HI && !options.listconf &&
125+
sizeof(tests) / sizeof(tests[0]) > 16) {
126+
fprintf_color(color_warning, stderr,
127+
"Warning: LM formats incompatible with %s encoding, disabling some self-tests\n",
128+
cp_id2name(options.target_enc));
129+
tests[16].ciphertext = NULL; // Truncates the array after 16 entries
130+
warned = 1;
131+
}
119132
}
120133

121134
static char *prepare(char *fields[10], struct fmt_main *self)

src/unicode.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ extern void utf8_to_utf8_32(UTF32 *dst, UTF8 *src);
403403
/* Convert UTF-32 to UTF-8-32, in place */
404404
extern void utf32_to_utf8_32(UTF32 *in_place_string);
405405

406+
/* Return codepage class (eg. CP_DOS) of a specific encoding */
407+
extern int cp_class(int encoding);
408+
409+
/* Convert numerical encoding ID to canonical name */
410+
char *cp_id2name(int encoding);
411+
406412
/*
407413
* NOTE! Please read the comments in formats.h for FMT_UNICODE and FMT_ENC
408414
*/

0 commit comments

Comments
 (0)