Skip to content
Draft
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
68 changes: 28 additions & 40 deletions src/7z_common_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ struct fmt_tests sevenzip_tests[] = {

sevenzip_salt_t *sevenzip_salt;

#define YEL "\x1b[0;33m"
#define NRM "\x1b[0m"

int sevenzip_trust_padding;

static char *comp_type[16] = { "stored", "LZMA1", "LZMA2", "PPMD", NULL, NULL, "BZIP2", "DEFLATE" };
Expand Down Expand Up @@ -140,23 +137,23 @@ int sevenzip_valid(char *ciphertext, struct fmt_main *self)
&& type != 128) {
if (john_main_process && !warned[type]) {
warned[type] = 1;
fprintf(stderr, YEL "Warning: Not loading files with unsupported compression type %s (0x%02x)\n" NRM,
fprintf_color(color_warning, stderr, "Warning: Not loading files with unsupported compression type %s (0x%02x)\n",
comp_type[c_type] ? comp_type[c_type] : "(unknown)", type);
#if !HAVE_LIBBZ2
if (type == 6)
fprintf(stderr, YEL "Rebuild with libbz2 to get support for that type.\n" NRM);
fprintf_color(color_warning, stderr, "Rebuild with libbz2 to get support for that type.\n");
#endif
#if !HAVE_LIBZ
if (type == 7)
fprintf(stderr, YEL "Rebuild with libz (zlib) to get support for that type.\n" NRM);
fprintf_color(color_warning, stderr, "Rebuild with libz (zlib) to get support for that type.\n");
#endif
}
goto err;
}
if (john_main_process && !ldr_in_pot && !self_test_running &&
options.verbosity > VERB_DEFAULT && !warned[type]) {
warned[type] = 1;
fprintf(stderr, YEL "Saw file(s) with compression type %s%s%s (0x%02x)\n" NRM,
fprintf_color(color_notice, stderr, "Saw file(s) with compression type %s%s%s (0x%02x)\n",
precomp_type[p_type], p_type ? "+" : "", comp_type[c_type], type);
}
if ((p = strtokm(NULL, "$")) == NULL) /* NumCyclesPower */
Expand All @@ -174,11 +171,8 @@ int sevenzip_valid(char *ciphertext, struct fmt_main *self)
goto err;
len = atoi(p);
if (len > 0 && strstr(self->params.label, "-opencl")) {
static int warned;

if (!warned++)
fprintf(stderr, YEL "%s: Warning: Not loading hashes with salt due to optimizations. Please report!\n" NRM,
self->params.label);
if (!ldr_in_pot && john_main_process)
WARN_ONCE(color_warning, stderr, "%s: Warning: Not loading hashes with salt due to optimizations. Please report!\n", self->params.label);
goto err;
}
if (len > 16)
Expand Down Expand Up @@ -355,7 +349,7 @@ int sevenzip_decrypt(unsigned char *derived_key)

#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, "\nType %02x (%s%s%s) AES length %zu, packed len %zu, pad size %d, crc len %zu\n",
fprintf_color(color_notice, stderr, "\nType %02x (%s%s%s) AES length %zu, packed len %zu, pad size %d, crc len %zu\n",
sevenzip_salt->type, precomp_type[p_type] ? precomp_type[p_type] : "",
p_type ? "+" : "",
comp_type[c_type] ? comp_type[c_type] : "(unknown)",
Expand All @@ -379,12 +373,11 @@ int sevenzip_decrypt(unsigned char *derived_key)
if (buf[i] != 0) {
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG) {
fprintf(stderr, YEL "Early padding check failed, ");
fprintf_color(color_warning, stderr, "Early padding check failed, ");
dump_stderr_msg("padding", buf + 16 - pad_size, pad_size);
fprintf(stderr, NRM);
}
if (sevenzip_salt->type == 0x80)
fprintf(stderr, YEL "We don't have data for complete decryption\n");
WARN_ONCE(color_warning, stderr, "We don't have data for complete decryption\n");
break;
#else
return 0;
Expand All @@ -395,13 +388,13 @@ int sevenzip_decrypt(unsigned char *derived_key)
}
#if DEBUG
if (!nbytes && !benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, "Early padding check passed\n");
fprintf_color(color_notice, stderr, "Early padding check passed\n");
else
nbytes = 0;
#else
if (self_test_running)
#endif
if (sevenzip_salt->type == 0x80) /* We only have truncated data */
return 1;
#endif
}

/* Complete decryption */
Expand All @@ -417,9 +410,8 @@ int sevenzip_decrypt(unsigned char *derived_key)
if (out[i] != 0) {
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG) {
fprintf(stderr, YEL "Full data padding check failed, ");
fprintf_color(color_warning, stderr, "Full data padding check failed, ");
dump_stderr_msg("padding", out + sevenzip_salt->aes_length - pad_size, pad_size);
fprintf(stderr, NRM);
}
break;
#else
Expand All @@ -431,7 +423,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
}
#if DEBUG
if (!nbytes && !benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, "Padding check passed\n");
fprintf_color(color_notice, stderr, "Padding check passed\n");
#endif
}

Expand All @@ -456,7 +448,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
out_size == crc_len) {
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, "LZMA decoding passed, %zu/%zu -> %zu/%zu, props %02x%02x%02x%02x\n",
fprintf_color(color_notice, stderr, "LZMA decoding passed, %zu/%zu -> %zu/%zu, props %02x%02x%02x%02x\n",
in_size, sevenzip_salt->packed_size, out_size, crc_len, sevenzip_salt->decoder_props[0],
sevenzip_salt->decoder_props[1], sevenzip_salt->decoder_props[2], sevenzip_salt->decoder_props[3]);
#endif
Expand All @@ -465,7 +457,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
} else {
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, YEL "LZMA decoding failed, %zu/%zu -> %zu/%zu, props %02x%02x%02x%02x\n" NRM,
fprintf_color(color_warning, stderr, "LZMA decoding failed, %zu/%zu -> %zu/%zu, props %02x%02x%02x%02x\n",
in_size, sevenzip_salt->packed_size, out_size, crc_len, sevenzip_salt->decoder_props[0],
sevenzip_salt->decoder_props[1], sevenzip_salt->decoder_props[2], sevenzip_salt->decoder_props[3]);
#endif
Expand All @@ -488,15 +480,15 @@ int sevenzip_decrypt(unsigned char *derived_key)
out_size == crc_len) {
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, "LZMA2 decoding passed, %zu/%zu -> %zu/%zu, props %02x\n",
fprintf_color(color_notice, stderr, "LZMA2 decoding passed, %zu/%zu -> %zu/%zu, props %02x\n",
in_size, sevenzip_salt->packed_size, out_size, crc_len, sevenzip_salt->decoder_props[0]);
#endif
MEM_FREE(out);
out = new_out;
} else {
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, YEL "LZMA2 decoding failed, %zu/%zu -> %zu/%zu, props %02x\n" NRM,
fprintf_color(color_warning, stderr, "LZMA2 decoding failed, %zu/%zu -> %zu/%zu, props %02x\n",
in_size, sevenzip_salt->packed_size, out_size, crc_len, sevenzip_salt->decoder_props[0]);
#endif
MEM_FREE(new_out);
Expand Down Expand Up @@ -526,7 +518,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
if (ret == BZ_STREAM_END) {
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, "BZIP2 decoding passed, %zu/%zu -> %zu/%zu\n",
fprintf_color(color_notice, stderr, "BZIP2 decoding passed, %zu/%zu -> %zu/%zu\n",
sevenzip_salt->packed_size - inf_stream.avail_in, sevenzip_salt->packed_size,
crc_len - inf_stream.avail_out, crc_len);
#endif
Expand All @@ -535,7 +527,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
} else {
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, YEL "BZIP2 decoding failed, %zu/%zu -> %zu/%zu\n" NRM,
fprintf_color(color_warning, stderr, "BZIP2 decoding failed, %zu/%zu -> %zu/%zu\n",
sevenzip_salt->packed_size - inf_stream.avail_in, sevenzip_salt->packed_size,
crc_len - inf_stream.avail_out, crc_len);
#endif
Expand Down Expand Up @@ -564,7 +556,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
if (ret == Z_STREAM_END) {
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, "DEFLATE decoding passed, %zu/%zu -> %zu/%zu\n",
fprintf_color(color_notice, stderr, "DEFLATE decoding passed, %zu/%zu -> %zu/%zu\n",
sevenzip_salt->packed_size - inf_stream.avail_in, sevenzip_salt->packed_size,
crc_len - inf_stream.avail_out, crc_len);
#endif
Expand All @@ -573,7 +565,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
} else {
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, YEL "DEFLATE decoding failed, %zu/%zu -> %zu/%zu\n" NRM,
fprintf_color(color_warning, stderr, "DEFLATE decoding failed, %zu/%zu -> %zu/%zu\n",
sevenzip_salt->packed_size - inf_stream.avail_in, sevenzip_salt->packed_size,
crc_len - inf_stream.avail_out, crc_len);
#endif
Expand All @@ -586,7 +578,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
if (p_type) {
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, "Decoding %s, props %02x\n", precomp_type[p_type], sevenzip_salt->preproc_props);
fprintf_color(color_notice, stderr, "Decoding %s, props %02x\n", precomp_type[p_type], sevenzip_salt->preproc_props);
#endif
if (p_type == 1) {
uint32_t state;
Expand All @@ -595,12 +587,8 @@ int sevenzip_decrypt(unsigned char *derived_key)
x86_Convert(out, crc_len, 0, &state, 0);
}
else if (p_type == 2) {
if (!benchmark_running && options.verbosity >= VERB_DEFAULT) {
static int warned;

if (!warned++)
fprintf(stderr, YEL "Can't decode BCJ2, so skipping CRC check" NRM);
}
if (!benchmark_running && options.verbosity >= VERB_DEFAULT)
WARN_ONCE(color_warning, stderr, "Can't decode BCJ2, so skipping CRC check");
goto exit_good;
}
else if (p_type == 3)
Expand All @@ -620,7 +608,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
Delta_Decode(state, sevenzip_salt->preproc_props + 1, out, crc_len);
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, YEL "DELTA decoding can't fail so result unknown\n" NRM);
fprintf_color(color_notice, stderr, "DELTA decoding can't fail so result unknown\n");
#endif
}
}
Expand All @@ -636,13 +624,13 @@ int sevenzip_decrypt(unsigned char *derived_key)
if (ccrc == sevenzip_salt->crc) {
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, "CRC check passed (%08x)\n", ccrc);
fprintf_color(color_notice, stderr, "CRC check passed (%08x)\n", ccrc);
#endif
goto exit_good;
}
#if DEBUG
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
fprintf(stderr, YEL "CRC failed, %08x vs %08x\n" NRM, ccrc, sevenzip_salt->crc);
fprintf_color(color_warning, stderr, "CRC failed, %08x vs %08x\n", ccrc, sevenzip_salt->crc);
#endif

exit_bad:
Expand Down
6 changes: 2 additions & 4 deletions src/LM_fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,12 @@ static void init(struct fmt_main *self)
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 &&
if (options.target_enc > CP_DOS_HI && !options.listconf &&
sizeof(tests) / sizeof(tests[0]) > 16) {
fprintf_color(color_warning, stderr,
WARN_ONCE(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
warned = 1;
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/argon2_fmt_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ static void set_salt(void *salt)
static int allocate(uint8_t **memory, size_t size)
{
if (THREAD_NUMBER < 0 || THREAD_NUMBER > NUM_THREADS) {
fprintf(stderr, "Error: Argon2: Thread number %d out of range\n", THREAD_NUMBER);
fprintf_color(color_error, stderr, "Error: Argon2: Thread number %d out of range\n", THREAD_NUMBER);
goto fail;
}
if (thread_mem[THREAD_NUMBER].used) {
fprintf(stderr, "Error: Argon2: Thread %d: Memory allocated twice\n", THREAD_NUMBER);
fprintf_color(color_error, stderr, "Error: Argon2: Thread %d: Memory allocated twice\n", THREAD_NUMBER);
goto fail;
}

Expand All @@ -299,15 +299,15 @@ static int allocate(uint8_t **memory, size_t size)
static void deallocate(uint8_t *memory, size_t size)
{
if (THREAD_NUMBER < 0 || THREAD_NUMBER > NUM_THREADS) {
fprintf(stderr, "Error: Argon2: Thread number %d out of range\n", THREAD_NUMBER);
fprintf_color(color_error, stderr, "Error: Argon2: Thread number %d out of range\n", THREAD_NUMBER);
return;
}

if (!thread_mem[THREAD_NUMBER].used)
fprintf(stderr, "Error: Argon2: Thread %d: Freed memory not in use\n", THREAD_NUMBER);
fprintf_color(color_error, stderr, "Error: Argon2: Thread %d: Freed memory not in use\n", THREAD_NUMBER);

if (thread_mem[THREAD_NUMBER].region.aligned_size < size)
fprintf(stderr, "Error: Argon2: Thread %d: Freeing incorrect size %zu, was %zu\n",
fprintf_color(color_error, stderr, "Error: Argon2: Thread %d: Freeing incorrect size %zu, was %zu\n",
THREAD_NUMBER, size, thread_mem[THREAD_NUMBER].region.aligned_size);

thread_mem[THREAD_NUMBER].used = 0;
Expand Down Expand Up @@ -343,7 +343,7 @@ static int crypt_all(int *pcount, struct db_salt *salt)
error_code = argon2_ctx(&context, saved_salt.type);
if (error_code != ARGON2_OK) {
failed = -1;
fprintf(stderr, "Error: Argon2 failed: %s\n", argon2_error_message(error_code));
fprintf_color(color_error, stderr, "Error: Argon2 failed: %s\n", argon2_error_message(error_code));
#ifndef _OPENMP
break;
#endif
Expand All @@ -352,7 +352,7 @@ static int crypt_all(int *pcount, struct db_salt *salt)

if (failed) {
#ifdef _OPENMP
fprintf(stderr, "Error: Argon2 failed in some threads\n");
fprintf_color(color_error, stderr, "Error: Argon2 failed in some threads\n");
#endif
error();
}
Expand Down
6 changes: 3 additions & 3 deletions src/armory_fmt_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static void init(struct fmt_main *self)
* calls that take a const pointer.
*/
if (!(secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN))) {
fprintf(stderr, "Failed to create secp256k1 context\n");
fprintf_color(color_error, stderr, "Failed to create secp256k1 context\n");
error();
}
}
Expand Down Expand Up @@ -439,11 +439,11 @@ static int crypt_all(int *pcount, struct db_salt *salt)
if (failed) {
#ifdef _OPENMP
if (failed < 0) {
fprintf(stderr, "OpenMP thread number out of range\n");
fprintf_color(color_error, stderr, "OpenMP thread number out of range\n");
error();
}
#endif
fprintf(stderr, "Memory allocation failed: %s\n", strerror(failed));
fprintf_color(color_error, stderr, "Memory allocation failed: %s\n", strerror(failed));
error();
}

Expand Down
7 changes: 3 additions & 4 deletions src/as400_ssha1_fmt_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ john_register_one(&fmt_AS400_ssha1);
#include "options.h"
#include "unicode.h"
#include "base64_convert.h"
#include "john.h"

#define FORMAT_LABEL "as400-ssha1"
#define FORMAT_NAME "AS400-SaltedSHA1"
Expand Down Expand Up @@ -150,14 +151,12 @@ static int our_valid(char *ciphertext, struct fmt_main *self)
if (strlen(&ciphertext[FORMAT_TAG_LEN + 2 * BINARY_SIZE + 1]) > 10)
return 0;
if (options.input_enc == UTF_8 && !valid_utf8((UTF8*)ciphertext)) {
static int error_shown = 0;
#ifdef HAVE_FUZZ
if (options.flags & (FLG_FUZZ_CHK | FLG_FUZZ_DUMP_CHK))
return 0;
#endif
if (!error_shown)
fprintf(stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label);
error_shown = 1;
if (john_main_process)
WARN_ONCE(color_error, stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label);
return 0;
}
return pDynamic->methods.valid(Convert(Conv_Buf, ciphertext), pDynamic);
Expand Down
5 changes: 3 additions & 2 deletions src/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ static void bench_set_keys(struct fmt_main *format,
}

if (warn == 1) {
fprintf(stderr, "Warning: not enough candidates under "
"benchmark length %d\n", length);
fprintf_color(color_warning, stderr,
"Warning: not enough candidates under benchmark length %d\n",
length);
warn = 2;
}

Expand Down
8 changes: 5 additions & 3 deletions src/bestcrypt_ve_fmt_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ john_register_one(&fmt_bestcrypt_ve);
#endif

#include "arch.h"
#include "john.h"
#include "misc.h"
#include "common.h"
#include "formats.h"
Expand Down Expand Up @@ -229,7 +230,8 @@ static int valid(char *ciphertext, struct fmt_main *self)
if (atoi(p) != 8 && atoi(p) != 9 && atoi(p) != 10 && atoi(p) != 11 && atoi(p) != 15)
goto err;
if (atoi(p) == 11) {
fprintf(stderr, "Warning: " FORMAT_LABEL ": RC6 encryption not supported yet!\n");
if (john_main_process && !ldr_in_pot)
fprintf_color(color_warning, stderr, "Warning: " FORMAT_LABEL ": RC6 encryption not supported yet!\n");
goto err;
}
if ((p = strtokm(NULL, "$")) == NULL) // salt
Expand Down Expand Up @@ -401,11 +403,11 @@ static int crypt_all(int *pcount, struct db_salt *salt)
if (failed) {
#ifdef _OPENMP
if (failed < 0) {
fprintf(stderr, "OpenMP thread number out of range\n");
fprintf_color(color_error, stderr, "OpenMP thread number out of range\n");
error();
}
#endif
fprintf(stderr, "scrypt failed: %s\n", strerror(failed));
fprintf_color(color_error, stderr, "scrypt failed: %s\n", strerror(failed));
error();
}

Expand Down
Loading