diff -Nrup john-1.7.2-a/src/MD5SUM_fmt.c john-1.7.2-b/src/MD5SUM_fmt.c --- john-1.7.2-a/src/MD5SUM_fmt.c 1970-01-01 02:00:00.000000000 +0200 +++ john-1.7.2-b/src/MD5SUM_fmt.c 2007-10-14 12:19:01.000000000 +0300 @@ -0,0 +1,226 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 2007 Tommi Saviranta + */ + +#include +#include + +#include "arch.h" +#include "misc.h" +#include "common.h" +#include "formats.h" + +#define FORMAT_LABEL "md5sum" +#define FORMAT_NAME "MD5SUM" +#define ALGORITHM_NAME "OpenSSL/MD5" + +#define BENCHMARK_COMMENT "" +#define BENCHMARK_LENGTH -1 + +/* Assume passwords do not exceed 63 characters in length. */ +#define PLAINTEXT_LENGTH 64 +#define CIPHERTEXT_LENGTH MD5_DIGEST_LENGTH + +#define BINARY_SIZE 4 +#define SALT_SIZE 0 + +#define MIN_KEYS_PER_CRYPT 1 +#define MAX_KEYS_PER_CRYPT 1 + +static struct fmt_tests tests[] = { + {"e169a0cb4f44334ad3ea5e4551176e4a", "0123456789ABCDE"}, + {"25d55ad283aa400af464c76d713c07ad", "12345678"}, + {"d41d8cd98f00b204e9800998ecf8427e", ""}, + {"81dc9bdb52d04dc20036dbd8313ed055", "1234"}, + {NULL} +}; + +static char saved_key[MAX_KEYS_PER_CRYPT][PLAINTEXT_LENGTH + 1]; +static char saved_hash[MAX_KEYS_PER_CRYPT][CIPHERTEXT_LENGTH]; +static unsigned int hexlookup[256] = { + ['0'] = 0, + ['1'] = 1, + ['2'] = 2, + ['3'] = 3, + ['4'] = 4, + ['5'] = 5, + ['6'] = 6, + ['7'] = 7, + ['8'] = 8, + ['9'] = 9, + ['a'] = 10, + ['b'] = 11, + ['c'] = 12, + ['d'] = 13, + ['e'] = 14, + ['f'] = 15, + ['A'] = 10, + ['B'] = 11, + ['C'] = 12, + ['D'] = 13, + ['E'] = 14, + ['F'] = 15, +}; + + +static inline unsigned int hex2dec(char c) +{ + return hexlookup[(unsigned int) c]; +} + +static int valid(char *ciphertext) +{ + char *i; + static char validchar[] = "0123456789abcdefABCDEF"; + + if (strlen(ciphertext) != CIPHERTEXT_LENGTH * 2) return 0; + + for (i = ciphertext; *i != '\0'; i++) + if (! strchr(validchar, (int) *i)) return 0; + + return 1; +} + +static void *binary(char *ciphertext) +{ + static char hash[CIPHERTEXT_LENGTH]; + char *src, *dest; + + for (src = ciphertext, dest = hash; *src != '\0'; /* empty */) { + *dest = (unsigned char) + ((hex2dec(src[0]) << 4) + hex2dec(src[1])); + src += 2; + dest++; + } + + return hash; +} + +static void *salt(char *ciphertext) +{ + static char t = '\0'; + return &t; +} + +static int binary_hash_0(void *binary) +{ + return ((int *) binary)[0] & 0xF; +} + +static int binary_hash_1(void *binary) +{ + return ((int *) binary)[0] & 0xFF; +} + +static int binary_hash_2(void *binary) +{ + return ((int *) binary)[0] & 0xFFF; +} + +static void set_salt(void *salt) +{ + /* nothing here */ +} + +static void crypt_all(int count) +{ + static MD5_CTX ctx; + + MD5_Init(&ctx); + MD5_Update(&ctx, saved_key[0], strlen(saved_key[0])); + MD5_Final((void *) saved_hash[0], &ctx); +} + +static int get_hash_0(int index) +{ + return ((int *) saved_hash[index])[0] & 0xF; +} + +static int get_hash_1(int index) +{ + return ((int *) saved_hash[index])[0] & 0xFF; +} + +static int get_hash_2(int index) +{ + return ((int *) saved_hash[index])[0] & 0xFFF; +} + +static int salt_hash(void *salt) +{ + return 0; +} + +/* Sets a plaintext, with index from 0 to fmt_params.max_keys_per_crypt - 1 */ +static void set_key(char *key, int index) +{ + strncpy(saved_key[index], key, PLAINTEXT_LENGTH); + saved_key[index][PLAINTEXT_LENGTH] = '\0'; +} + +static char *get_key(int index) +{ + return saved_key[index]; +} + +static int cmp_all(void *binary, int index) +{ + return *(int *) binary == ((int *) saved_hash[0])[0]; +} + +static int cmp_exact(char *source, int index) +{ + unsigned char *i, *j; + for (i = (unsigned char *) source, + j = (unsigned char *) saved_hash[0]; + *i != '\0'; /* nothing */) { + if ((hex2dec(i[0]) << 4) + hex2dec(i[1]) != *j) + return 0; + i += 2; + j++; + } + return 1; +} + +struct fmt_main fmt_MD5SUM = { + { + FORMAT_LABEL, + FORMAT_NAME, + ALGORITHM_NAME, + BENCHMARK_COMMENT, + BENCHMARK_LENGTH, + PLAINTEXT_LENGTH, + BINARY_SIZE, + SALT_SIZE, + MIN_KEYS_PER_CRYPT, + MAX_KEYS_PER_CRYPT, + FMT_CASE | FMT_8_BIT, + tests + }, { + fmt_default_init, + valid, + fmt_default_split, + binary, + salt, + { + binary_hash_0, + binary_hash_1, + binary_hash_2 + }, + salt_hash, + set_salt, + set_key, + get_key, + fmt_default_clear_keys, + crypt_all, + { + get_hash_0, + get_hash_1, + get_hash_2 + }, + cmp_all, + cmp_all, + cmp_exact + } +}; diff -Nrup john-1.7.2-a/src/Makefile john-1.7.2-b/src/Makefile --- john-1.7.2-a/src/Makefile 2006-05-15 19:38:00.000000000 +0300 +++ john-1.7.2-b/src/Makefile 2007-10-14 12:19:39.000000000 +0300 @@ -17,7 +17,7 @@ NULL = /dev/null CPPFLAGS = -E CFLAGS = -c -Wall -O2 -fomit-frame-pointer ASFLAGS = -c -LDFLAGS = -s +LDFLAGS = -s `pkg-config --libs libssl` OPT_NORMAL = -funroll-loops OPT_INLINE = -finline-functions @@ -28,6 +28,7 @@ JOHN_OBJS_MINIMAL = \ BF_fmt.o BF_std.o \ AFS_fmt.o \ LM_fmt.o \ + MD5SUM_fmt.o \ batch.o bench.o charset.o common.o compiler.o config.o cracker.o \ crc32.o external.o formats.o getopt.o idle.o inc.o john.o list.o \ loader.o logger.o math.o memory.o misc.o options.o params.o path.o \ @@ -55,6 +56,9 @@ BENCH_DES_BS_OBJS_DEPEND = \ BENCH_MD5_OBJS_DEPEND = \ MD5_fmt.o MD5_std.o +BENCH_MD5SUM_OBJS_DEPEND = \ + MD5SUM_fmt.o + BENCH_BF_OBJS_DEPEND = \ BF_std.o @@ -62,6 +66,7 @@ BENCH_OBJS = \ $(BENCH_DES_OBJS_DEPEND) \ DES_bs.o $(BENCH_DES_BS_OBJS_DEPEND) \ $(BENCH_MD5_OBJS_DEPEND) \ + $(BENCH_MD5SUM_OBJS_DEPEND) \ BF_fmt.o $(BENCH_BF_OBJS_DEPEND) \ bench.o best.o common.o config.o formats.o math.o memory.o miscnl.o \ params.o path.o signals.o tty.o @@ -651,6 +656,7 @@ generic.h: "$(BENCH_DES_OBJS_DEPEND)" \ "$(BENCH_DES_BS_OBJS_DEPEND)" \ "$(BENCH_MD5_OBJS_DEPEND)" \ + "$(BENCH_MD5SUM_OBJS_DEPEND)" \ "$(BENCH_BF_OBJS_DEPEND)" bench: $(BENCH_OBJS) diff -Nrup john-1.7.2-a/src/john.c john-1.7.2-b/src/john.c --- john-1.7.2-a/src/john.c 2006-05-08 17:48:48.000000000 +0300 +++ john-1.7.2-b/src/john.c 2007-10-14 12:19:57.000000000 +0300 @@ -38,6 +38,7 @@ extern int CPU_detect(void); extern struct fmt_main fmt_DES, fmt_BSDI, fmt_MD5, fmt_BF; extern struct fmt_main fmt_AFS, fmt_LM; +extern struct fmt_main fmt_MD5SUM; extern int unshadow(int argc, char **argv); extern int unafs(int argc, char **argv); @@ -64,6 +65,7 @@ static void john_register_all(void) john_register_one(&fmt_BF); john_register_one(&fmt_AFS); john_register_one(&fmt_LM); + john_register_one(&fmt_MD5SUM); if (!fmt_list) { fprintf(stderr, "Unknown ciphertext format name requested\n");