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-25 22:23:39.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-25 22:25:57.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,9 @@ JOHN_OBJS_MINIMAL = \ BF_fmt.o BF_std.o \ AFS_fmt.o \ LM_fmt.o \ + MD5SUM_fmt.o \ + SHA1SUM_fmt.o SHASUM_std.o \ + SHA224SUM_fmt.o SHA256SUM_fmt.o SHA384SUM_fmt.o SHA512SUM_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,13 +58,22 @@ 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 +BENCH_SHASUM_OBJS_DEPEND = \ + SHA1SUM_fmt.o SHASUM_std.o \ + SHA224SUM_fmt.o SHA256SUM_fmt.o SHA384SUM_fmt.o SHA512SUM_fmt.o + BENCH_OBJS = \ $(BENCH_DES_OBJS_DEPEND) \ DES_bs.o $(BENCH_DES_BS_OBJS_DEPEND) \ $(BENCH_MD5_OBJS_DEPEND) \ + $(BENCH_MD5SUM_OBJS_DEPEND) \ + $(BENCH_SHASUM_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 +663,8 @@ generic.h: "$(BENCH_DES_OBJS_DEPEND)" \ "$(BENCH_DES_BS_OBJS_DEPEND)" \ "$(BENCH_MD5_OBJS_DEPEND)" \ + "$(BENCH_MD5SUM_OBJS_DEPEND)" \ + "$(BENCH_SHASUM_OBJS_DEPEND)" \ "$(BENCH_BF_OBJS_DEPEND)" bench: $(BENCH_OBJS) diff -Nrup john-1.7.2-a/src/SHA1SUM_fmt.c john-1.7.2-b/src/SHA1SUM_fmt.c --- john-1.7.2-a/src/SHA1SUM_fmt.c 1970-01-01 02:00:00.000000000 +0200 +++ john-1.7.2-b/src/SHA1SUM_fmt.c 2007-10-25 22:23:46.000000000 +0300 @@ -0,0 +1,153 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 2007 Tommi Saviranta + */ + +#include "SHASUM_std.h" + +#include +#include + +#include "arch.h" +#include "misc.h" +#include "common.h" +#include "formats.h" + +#define FORMAT_LABEL "sha1sum" +#define FORMAT_NAME "SHA1SUM" +#define ALGORITHM_NAME "OpenSSL/SHA1" + +#define BENCHMARK_COMMENT "" +#define BENCHMARK_LENGTH -1 + +/* Assume passwords do not exceed 63 characters in length. */ +#define PLAINTEXT_LENGTH 64 +#define CIPHERTEXT_LENGTH SHA_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[] = { + {"dde677e94792ee98d99dea11316e9dbbb7953a33", "0123456789ABCDE"}, + {"7c222fb2927d828af22f592134e8932480637c0d", "12345678"}, + {"da39a3ee5e6b4b0d3255bfef95601890afd80709", ""}, + {"7110eda4d09e062aa5e4a390b0a572ac0d2c0220", "1234"}, + {NULL} +}; + +static unsigned char saved_key[PLAINTEXT_LENGTH + 1]; +static unsigned char saved_key_len; +static unsigned char saved_hash[CIPHERTEXT_LENGTH]; + +static int valid(char *ciphertext) +{ + return shasum_valid(ciphertext, SHA_DIGEST_LENGTH * 2); /* bin to hex */ +} + +static void *binary(char *ciphertext) +{ + static char hash[CIPHERTEXT_LENGTH]; + + return shasum_binary(hash, ciphertext, SHA_DIGEST_LENGTH); +} + +static void crypt_all(int count) +{ + SHA_CTX ctx; + + SHA1_Init(&ctx); + SHA1_Update(&ctx, saved_key, saved_key_len); + SHA1_Final(saved_hash, &ctx); +} + +static int get_hash_0(int index) +{ + return ((int *) saved_hash)[0] & 0xF; +} + +static int get_hash_1(int index) +{ + return ((int *) saved_hash)[0] & 0xFF; +} + +static int get_hash_2(int index) +{ + return ((int *) saved_hash)[0] & 0xFFF; +} + +static void set_key(char *key, int index) +{ + saved_key_len = strlen(key); + strncpy((char *) saved_key, key, PLAINTEXT_LENGTH); + saved_key[PLAINTEXT_LENGTH] = '\0'; +} + +static char *get_key(int index) +{ + return (char *) saved_key; +} + +static int cmp_all(void *binary, int index) +{ + return *(int *) binary == ((int *) saved_hash)[0]; +} + +static int cmp_exact(char *source, int index) +{ + unsigned char *i, *j; + for (i = (unsigned char *) source, + j = (unsigned char *) saved_hash; + *i != '\0'; /* nothing */) { + if ((shasum_hex2dec(i[0]) << 4) + shasum_hex2dec(i[1]) != *j) + return 0; + i += 2; + j++; + } + return 1; +} + +struct fmt_main fmt_SHA1SUM = { + { + 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, + shasum_salt, + { + shasum_binary_hash_0, + shasum_binary_hash_1, + shasum_binary_hash_2 + }, + shasum_salt_hash, + shasum_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/SHA224SUM_fmt.c john-1.7.2-b/src/SHA224SUM_fmt.c --- john-1.7.2-a/src/SHA224SUM_fmt.c 1970-01-01 02:00:00.000000000 +0200 +++ john-1.7.2-b/src/SHA224SUM_fmt.c 2007-10-25 22:23:46.000000000 +0300 @@ -0,0 +1,157 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 2007 Tommi Saviranta + */ + +#include "SHASUM_std.h" + +#include +#include + +#include "arch.h" +#include "misc.h" +#include "common.h" +#include "formats.h" + +#define FORMAT_LABEL "sha224sum" +#define FORMAT_NAME "SHA224SUM" +#define ALGORITHM_NAME "OpenSSL/SHA224" + +#define BENCHMARK_COMMENT "" +#define BENCHMARK_LENGTH -1 + +/* Assume passwords do not exceed 63 characters in length. */ +#define PLAINTEXT_LENGTH 64 +#define CIPHERTEXT_LENGTH SHA224_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[] = { + {"377189874b8fa08fe42595943de1948ccaa0631b21b8e5ea9e799cce", + "0123456789ABCDE"}, + {"7e6a4309ddf6e8866679f61ace4f621b0e3455ebac2e831a60f13cd1", + "12345678"}, + {"d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", + ""}, + {"99fb2f48c6af4761f904fc85f95eb56190e5d40b1f44ec3a9c1fa319", + "1234"}, + {NULL} +}; + +static unsigned char saved_key[PLAINTEXT_LENGTH + 1]; +static unsigned char saved_key_len; +static unsigned char saved_hash[CIPHERTEXT_LENGTH]; + +static int valid(char *ciphertext) +{ + return shasum_valid(ciphertext, SHA224_DIGEST_LENGTH * 2); /* bin to hex */ +} + +static void *binary(char *ciphertext) +{ + static char hash[CIPHERTEXT_LENGTH]; + + return shasum_binary(hash, ciphertext, SHA_DIGEST_LENGTH); +} + +static void crypt_all(int count) +{ + SHA256_CTX ctx; + + SHA224_Init(&ctx); + SHA224_Update(&ctx, saved_key, saved_key_len); + SHA224_Final(saved_hash, &ctx); +} + +static int get_hash_0(int index) +{ + return ((int *) saved_hash)[0] & 0xF; +} + +static int get_hash_1(int index) +{ + return ((int *) saved_hash)[0] & 0xFF; +} + +static int get_hash_2(int index) +{ + return ((int *) saved_hash)[0] & 0xFFF; +} + +static void set_key(char *key, int index) +{ + saved_key_len = strlen(key); + strncpy((char *) saved_key, key, PLAINTEXT_LENGTH); + saved_key[PLAINTEXT_LENGTH] = '\0'; +} + +static char *get_key(int index) +{ + return (char *) saved_key; +} + +static int cmp_all(void *binary, int index) +{ + return *(int *) binary == ((int *) saved_hash)[0]; +} + +static int cmp_exact(char *source, int index) +{ + unsigned char *i, *j; + for (i = (unsigned char *) source, + j = (unsigned char *) saved_hash; + *i != '\0'; /* nothing */) { + if ((shasum_hex2dec(i[0]) << 4) + shasum_hex2dec(i[1]) != *j) + return 0; + i += 2; + j++; + } + return 1; +} + +struct fmt_main fmt_SHA224SUM = { + { + 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, + shasum_salt, + { + shasum_binary_hash_0, + shasum_binary_hash_1, + shasum_binary_hash_2 + }, + shasum_salt_hash, + shasum_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/SHA256SUM_fmt.c john-1.7.2-b/src/SHA256SUM_fmt.c --- john-1.7.2-a/src/SHA256SUM_fmt.c 1970-01-01 02:00:00.000000000 +0200 +++ john-1.7.2-b/src/SHA256SUM_fmt.c 2007-10-25 22:23:46.000000000 +0300 @@ -0,0 +1,157 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 2007 Tommi Saviranta + */ + +#include "SHASUM_std.h" + +#include +#include + +#include "arch.h" +#include "misc.h" +#include "common.h" +#include "formats.h" + +#define FORMAT_LABEL "sha256sum" +#define FORMAT_NAME "SHA256SUM" +#define ALGORITHM_NAME "OpenSSL/SHA256" + +#define BENCHMARK_COMMENT "" +#define BENCHMARK_LENGTH -1 + +/* Assume passwords do not exceed 63 characters in length. */ +#define PLAINTEXT_LENGTH 64 +#define CIPHERTEXT_LENGTH SHA256_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[] = { + {"fa6b86f30f55fc38d1e98443ab7b6184a2d67acc438329476bade54c634192e5", + "0123456789ABCDE"}, + {"ef797c8118f02dfb649607dd5d3f8c7623048c9c063d532cc95c5ed7a898a64f", + "12345678"}, + {"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + ""}, + {"03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4", + "1234"}, + {NULL} +}; + +static unsigned char saved_key[PLAINTEXT_LENGTH + 1]; +static unsigned char saved_key_len; +static unsigned char saved_hash[CIPHERTEXT_LENGTH]; + +static int valid(char *ciphertext) +{ + return shasum_valid(ciphertext, SHA256_DIGEST_LENGTH * 2); /* bin to hex */ +} + +static void *binary(char *ciphertext) +{ + static char hash[CIPHERTEXT_LENGTH]; + + return shasum_binary(hash, ciphertext, SHA_DIGEST_LENGTH); +} + +static void crypt_all(int count) +{ + SHA256_CTX ctx; + + SHA256_Init(&ctx); + SHA256_Update(&ctx, saved_key, saved_key_len); + SHA256_Final(saved_hash, &ctx); +} + +static int get_hash_0(int index) +{ + return ((int *) saved_hash)[0] & 0xF; +} + +static int get_hash_1(int index) +{ + return ((int *) saved_hash)[0] & 0xFF; +} + +static int get_hash_2(int index) +{ + return ((int *) saved_hash)[0] & 0xFFF; +} + +static void set_key(char *key, int index) +{ + saved_key_len = strlen(key); + strncpy((char *) saved_key, key, PLAINTEXT_LENGTH); + saved_key[PLAINTEXT_LENGTH] = '\0'; +} + +static char *get_key(int index) +{ + return (char *) saved_key; +} + +static int cmp_all(void *binary, int index) +{ + return *(int *) binary == ((int *) saved_hash)[0]; +} + +static int cmp_exact(char *source, int index) +{ + unsigned char *i, *j; + for (i = (unsigned char *) source, + j = (unsigned char *) saved_hash; + *i != '\0'; /* nothing */) { + if ((shasum_hex2dec(i[0]) << 4) + shasum_hex2dec(i[1]) != *j) + return 0; + i += 2; + j++; + } + return 1; +} + +struct fmt_main fmt_SHA256SUM = { + { + 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, + shasum_salt, + { + shasum_binary_hash_0, + shasum_binary_hash_1, + shasum_binary_hash_2 + }, + shasum_salt_hash, + shasum_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/SHA384SUM_fmt.c john-1.7.2-b/src/SHA384SUM_fmt.c --- john-1.7.2-a/src/SHA384SUM_fmt.c 1970-01-01 02:00:00.000000000 +0200 +++ john-1.7.2-b/src/SHA384SUM_fmt.c 2007-10-25 22:23:46.000000000 +0300 @@ -0,0 +1,161 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 2007 Tommi Saviranta + */ + +#include "SHASUM_std.h" + +#include +#include + +#include "arch.h" +#include "misc.h" +#include "common.h" +#include "formats.h" + +#define FORMAT_LABEL "sha384sum" +#define FORMAT_NAME "SHA384SUM" +#define ALGORITHM_NAME "OpenSSL/SHA384" + +#define BENCHMARK_COMMENT "" +#define BENCHMARK_LENGTH -1 + +/* Assume passwords do not exceed 63 characters in length. */ +#define PLAINTEXT_LENGTH 64 +#define CIPHERTEXT_LENGTH SHA384_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[] = { + {"9895a96bbbd52c8f5dce5f34ef485b2e2d63775291ccdb93" + "6500ebfbaa86de9af15ad110cc2a67fa479f3f6d6d646933", + "0123456789ABCDE"}, + {"8cafed2235386cc5855e75f0d34f103ccc183912e5f02446" + "b77c66539f776e4bf2bf87339b4518a7cb1c2441c568b0f8", + "12345678"}, + {"38b060a751ac96384cd9327eb1b1e36a21fdb71114be0743" + "4c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b", + ""}, + {"504f008c8fcf8b2ed5dfcde752fc5464ab8ba064215d9c5b" + "5fc486af3d9ab8c81b14785180d2ad7cee1ab792ad44798c", + "1234"}, + {NULL} +}; + +static unsigned char saved_key[PLAINTEXT_LENGTH + 1]; +static unsigned char saved_key_len; +static unsigned char saved_hash[CIPHERTEXT_LENGTH]; + +static int valid(char *ciphertext) +{ + return shasum_valid(ciphertext, SHA384_DIGEST_LENGTH * 2); /* bin to hex */ +} + +static void *binary(char *ciphertext) +{ + static char hash[CIPHERTEXT_LENGTH]; + + return shasum_binary(hash, ciphertext, SHA_DIGEST_LENGTH); +} + +static void crypt_all(int count) +{ + SHA512_CTX ctx; + + SHA384_Init(&ctx); + SHA384_Update(&ctx, saved_key, saved_key_len); + SHA384_Final(saved_hash, &ctx); +} + +static int get_hash_0(int index) +{ + return ((int *) saved_hash)[0] & 0xF; +} + +static int get_hash_1(int index) +{ + return ((int *) saved_hash)[0] & 0xFF; +} + +static int get_hash_2(int index) +{ + return ((int *) saved_hash)[0] & 0xFFF; +} + +static void set_key(char *key, int index) +{ + saved_key_len = strlen(key); + strncpy((char *) saved_key, key, PLAINTEXT_LENGTH); + saved_key[PLAINTEXT_LENGTH] = '\0'; +} + +static char *get_key(int index) +{ + return (char *) saved_key; +} + +static int cmp_all(void *binary, int index) +{ + return *(int *) binary == ((int *) saved_hash)[0]; +} + +static int cmp_exact(char *source, int index) +{ + unsigned char *i, *j; + for (i = (unsigned char *) source, + j = (unsigned char *) saved_hash; + *i != '\0'; /* nothing */) { + if ((shasum_hex2dec(i[0]) << 4) + shasum_hex2dec(i[1]) != *j) + return 0; + i += 2; + j++; + } + return 1; +} + +struct fmt_main fmt_SHA384SUM = { + { + 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, + shasum_salt, + { + shasum_binary_hash_0, + shasum_binary_hash_1, + shasum_binary_hash_2 + }, + shasum_salt_hash, + shasum_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/SHA512SUM_fmt.c john-1.7.2-b/src/SHA512SUM_fmt.c --- john-1.7.2-a/src/SHA512SUM_fmt.c 1970-01-01 02:00:00.000000000 +0200 +++ john-1.7.2-b/src/SHA512SUM_fmt.c 2007-10-25 22:23:46.000000000 +0300 @@ -0,0 +1,165 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 2007 Tommi Saviranta + */ + +#include "SHASUM_std.h" + +#include +#include + +#include "arch.h" +#include "misc.h" +#include "common.h" +#include "formats.h" + +#define FORMAT_LABEL "sha512sum" +#define FORMAT_NAME "SHA512SUM" +#define ALGORITHM_NAME "OpenSSL/SHA512" + +#define BENCHMARK_COMMENT "" +#define BENCHMARK_LENGTH -1 + +/* Assume passwords do not exceed 63 characters in length. */ +#define PLAINTEXT_LENGTH 64 +#define CIPHERTEXT_LENGTH SHA512_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[] = { + {"c169bcab3bcff4bf3d57a3390c2ae05775a124c02ed4d8be" + "6e2a4933d30c0ab5a6ba18ea1c798d6dcdc8d5a7a859436c" + "8e8e38689a5fc6fbe893e49d3ab2d5e9", + "0123456789ABCDE"}, + {"fa585d89c851dd338a70dcf535aa2a92fee7836dd6aff122" + "6583e88e0996293f16bc009c652826e0fc5c706695a03cdd" + "ce372f139eff4d13959da6f1f5d3eabe", + "12345678"}, + {"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc" + "83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f" + "63b931bd47417a81a538327af927da3e", + ""}, + {"d404559f602eab6fd602ac7680dacbfaadd13630335e951f" + "097af3900e9de176b6db28512f2e000b9d04fba5133e8b1c" + "6e8df59db3a8ab9d60be4b97cc9e81db", + "1234"}, + {NULL} +}; + +static unsigned char saved_key[PLAINTEXT_LENGTH + 1]; +static unsigned char saved_key_len; +static unsigned char saved_hash[CIPHERTEXT_LENGTH]; + +static int valid(char *ciphertext) +{ + return shasum_valid(ciphertext, SHA512_DIGEST_LENGTH * 2); /* bin to hex */ +} + +static void *binary(char *ciphertext) +{ + static char hash[CIPHERTEXT_LENGTH]; + + return shasum_binary(hash, ciphertext, SHA_DIGEST_LENGTH); +} + +static void crypt_all(int count) +{ + SHA512_CTX ctx; + + SHA512_Init(&ctx); + SHA512_Update(&ctx, saved_key, saved_key_len); + SHA512_Final(saved_hash, &ctx); +} + +static int get_hash_0(int index) +{ + return ((int *) saved_hash)[0] & 0xF; +} + +static int get_hash_1(int index) +{ + return ((int *) saved_hash)[0] & 0xFF; +} + +static int get_hash_2(int index) +{ + return ((int *) saved_hash)[0] & 0xFFF; +} + +static void set_key(char *key, int index) +{ + saved_key_len = strlen(key); + strncpy((char *) saved_key, key, PLAINTEXT_LENGTH); + saved_key[PLAINTEXT_LENGTH] = '\0'; +} + +static char *get_key(int index) +{ + return (char *) saved_key; +} + +static int cmp_all(void *binary, int index) +{ + return *(int *) binary == ((int *) saved_hash)[0]; +} + +static int cmp_exact(char *source, int index) +{ + unsigned char *i, *j; + for (i = (unsigned char *) source, + j = (unsigned char *) saved_hash; + *i != '\0'; /* nothing */) { + if ((shasum_hex2dec(i[0]) << 4) + shasum_hex2dec(i[1]) != *j) + return 0; + i += 2; + j++; + } + return 1; +} + +struct fmt_main fmt_SHA512SUM = { + { + 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, + shasum_salt, + { + shasum_binary_hash_0, + shasum_binary_hash_1, + shasum_binary_hash_2 + }, + shasum_salt_hash, + shasum_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/SHASUM_std.c john-1.7.2-b/src/SHASUM_std.c --- john-1.7.2-a/src/SHASUM_std.c 1970-01-01 02:00:00.000000000 +0200 +++ john-1.7.2-b/src/SHASUM_std.c 2007-10-25 22:23:46.000000000 +0300 @@ -0,0 +1,68 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 2007 Tommi Saviranta + */ + +#include "SHASUM_std.h" + +#include +#include + +int shasum_valid(char *ciphertext, int len) +{ + static char validchar[] = "0123456789abcdefABCDEF"; + char *i; + int t_len = 0; + + if (strlen(ciphertext) != len) return 0; + + for (i = ciphertext, t_len = 0; *i != '\0'; i++, t_len++) + if (! strchr(validchar, (int) *i)) return 0; + + return len == t_len; +} + +void *shasum_binary(char *hash, char *ciphertext, int len) +{ + char *src, *dest; + + for (src = ciphertext, dest = hash; *src != '\0'; /* empty */) { + *dest = (unsigned char) + ((shasum_hex2dec(src[0]) << 4) + shasum_hex2dec(src[1])); + src += 2; + dest++; + } + + return hash; +} + +int shasum_binary_hash_0(void *binary) +{ + return ((int *) binary)[0] & 0xF; +} + +int shasum_binary_hash_1(void *binary) +{ + return ((int *) binary)[0] & 0xFF; +} + +int shasum_binary_hash_2(void *binary) +{ + return ((int *) binary)[0] & 0xFFF; +} + +void *shasum_salt(char *ciphertext) +{ + static char t = '\0'; + return &t; +} + +void shasum_set_salt(void *salt) +{ + /* nothing here */ +} + +int shasum_salt_hash(void *salt) +{ + return 0; +} diff -Nrup john-1.7.2-a/src/SHASUM_std.h john-1.7.2-b/src/SHASUM_std.h --- john-1.7.2-a/src/SHASUM_std.h 1970-01-01 02:00:00.000000000 +0200 +++ john-1.7.2-b/src/SHASUM_std.h 2007-10-25 22:23:46.000000000 +0300 @@ -0,0 +1,54 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 2007 Tommi Saviranta + */ + +#ifndef _JOHN_SHASUM_STD_H +#define _JOHN_SHASUM_STD_H + +static inline unsigned int shasum_hex2dec(char c) +{ + 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, + }; + return hexlookup[(unsigned int) c]; +} + +int shasum_valid(char *ciphertext, int len); + +void *shasum_binary(char *hash, char *ciphertext, int len); + +int shasum_binary_hash_0(void *binary); + +int shasum_binary_hash_1(void *binary); + +int shasum_binary_hash_2(void *binary); + +void *shasum_salt(char *ciphertext); + +void shasum_set_salt(void *salt); + +int shasum_salt_hash(void *salt); + +#endif 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-25 22:24:17.000000000 +0300 @@ -38,6 +38,9 @@ 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 struct fmt_main fmt_SHA1SUM, fmt_SHA224SUM, fmt_SHA256SUM; +extern struct fmt_main fmt_SHA384SUM, fmt_SHA512SUM; extern int unshadow(int argc, char **argv); extern int unafs(int argc, char **argv); @@ -64,6 +67,12 @@ 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); + john_register_one(&fmt_SHA1SUM); + john_register_one(&fmt_SHA224SUM); + john_register_one(&fmt_SHA256SUM); + john_register_one(&fmt_SHA384SUM); + john_register_one(&fmt_SHA512SUM); if (!fmt_list) { fprintf(stderr, "Unknown ciphertext format name requested\n"); diff -Nrup john-1.7.2-a/src/john.c.orig john-1.7.2-b/src/john.c.orig --- john-1.7.2-a/src/john.c.orig 1970-01-01 02:00:00.000000000 +0200 +++ john-1.7.2-b/src/john.c.orig 2007-10-25 22:23:39.000000000 +0300 @@ -0,0 +1,358 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 1996-2004,2006 by Solar Designer + */ + +#include +#include +#include +#include +#include + +#include "arch.h" +#include "misc.h" +#include "params.h" +#include "path.h" +#include "memory.h" +#include "list.h" +#include "tty.h" +#include "signals.h" +#include "common.h" +#include "formats.h" +#include "loader.h" +#include "logger.h" +#include "status.h" +#include "options.h" +#include "config.h" +#include "bench.h" +#include "charset.h" +#include "single.h" +#include "wordlist.h" +#include "inc.h" +#include "external.h" +#include "batch.h" + +#if CPU_DETECT +extern int CPU_detect(void); +#endif + +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); +extern int unique(int argc, char **argv); + +static struct db_main database; +static struct fmt_main dummy_format; + +static void john_register_one(struct fmt_main *format) +{ + if (options.format) + if (strcmp(options.format, format->params.label)) return; + + fmt_register(format); +} + +static void john_register_all(void) +{ + if (options.format) strlwr(options.format); + + john_register_one(&fmt_DES); + john_register_one(&fmt_BSDI); + john_register_one(&fmt_MD5); + 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"); + error(); + } +} + +static void john_log_format(void) +{ + int min_chunk, chunk; + + log_event("- Hash type: %.100s (lengths up to %d%s)", + database.format->params.format_name, + database.format->params.plaintext_length, + database.format->methods.split != fmt_default_split ? + ", longer passwords split" : ""); + + log_event("- Algorithm: %.100s", + database.format->params.algorithm_name); + + chunk = min_chunk = database.format->params.max_keys_per_crypt; + if (options.flags & (FLG_SINGLE_CHK | FLG_BATCH_CHK) && + chunk < SINGLE_HASH_MIN) + chunk = SINGLE_HASH_MIN; + if (chunk > 1) + log_event("- Candidate passwords %s be buffered and " + "tried in chunks of %d", + min_chunk > 1 ? "will" : "may", + chunk); +} + +static char *john_loaded_counts(void) +{ + static char s_loaded_counts[80]; + + if (database.password_count == 1) + return "1 password hash"; + + sprintf(s_loaded_counts, + database.salt_count > 1 ? + "%d password hashes with %d different salts" : + "%d password hashes with no different salts", + database.password_count, + database.salt_count); + + return s_loaded_counts; +} + +static void john_load(void) +{ + struct list_entry *current; + + umask(077); + + if (options.flags & FLG_EXTERNAL_CHK) + ext_init(options.external); + + if (options.flags & FLG_MAKECHR_CHK) { + options.loader.flags |= DB_CRACKED; + ldr_init_database(&database, &options.loader); + + if (options.flags & FLG_PASSWD) { + ldr_show_pot_file(&database, POT_NAME); + + database.options->flags |= DB_PLAINTEXTS; + if ((current = options.passwd->head)) + do { + ldr_show_pw_file(&database, current->data); + } while ((current = current->next)); + } else { + database.options->flags |= DB_PLAINTEXTS; + ldr_show_pot_file(&database, POT_NAME); + } + + return; + } + + if (options.flags & FLG_STDOUT) { + ldr_init_database(&database, &options.loader); + database.format = &dummy_format; + memset(&dummy_format, 0, sizeof(dummy_format)); + dummy_format.params.plaintext_length = options.length; + dummy_format.params.flags = FMT_CASE | FMT_8_BIT; + } + + if (options.flags & FLG_PASSWD) { + if (options.flags & FLG_SHOW_CHK) { + options.loader.flags |= DB_CRACKED; + ldr_init_database(&database, &options.loader); + + ldr_show_pot_file(&database, POT_NAME); + + if ((current = options.passwd->head)) + do { + ldr_show_pw_file(&database, current->data); + } while ((current = current->next)); + + printf("%s%d password hash%s cracked, %d left\n", + database.guess_count ? "\n" : "", + database.guess_count, + database.guess_count != 1 ? "es" : "", + database.password_count - + database.guess_count); + + return; + } + + if (options.flags & (FLG_SINGLE_CHK | FLG_BATCH_CHK)) + options.loader.flags |= DB_WORDS; + else + if (mem_saving_level) + options.loader.flags &= ~DB_LOGIN; + ldr_init_database(&database, &options.loader); + + if ((current = options.passwd->head)) + do { + ldr_load_pw_file(&database, current->data); + } while ((current = current->next)); + + if ((options.flags & FLG_CRACKING_CHK) && + database.password_count) { + log_init(LOG_NAME, NULL, options.session); + if (status_restored_time) + log_event("Continuing an interrupted session"); + else + log_event("Starting a new session"); + log_event("Loaded a total of %s", john_loaded_counts()); + } + + ldr_load_pot_file(&database, POT_NAME); + + ldr_fix_database(&database); + + if (database.password_count) { + log_event("Remaining %s", john_loaded_counts()); + printf("Loaded %s (%s [%s])\n", + john_loaded_counts(), + database.format->params.format_name, + database.format->params.algorithm_name); + } else { + log_discard(); + puts("No password hashes loaded"); + } + + if ((options.flags & FLG_PWD_REQ) && !database.salts) exit(0); + } +} + +static void john_init(char *name, int argc, char **argv) +{ +#if CPU_DETECT + int detected; + + switch ((detected = CPU_detect())) { +#if CPU_REQ + case 0: +#if CPU_FALLBACK +#if defined(__DJGPP__) || defined(__CYGWIN32__) +#error CPU_FALLBACK is incompatible with the current DOS and Win32 code +#endif + case 2: + execv(JOHN_SYSTEMWIDE_EXEC "/" CPU_FALLBACK_BINARY, argv); + perror("execv: " JOHN_SYSTEMWIDE_EXEC "/" CPU_FALLBACK_BINARY); +#endif + if (!detected) + fprintf(stderr, "Sorry, %s is required\n", CPU_NAME); + error(); +#endif + default: + break; + } +#endif + + path_init(argv); + +#if JOHN_SYSTEMWIDE + cfg_init(CFG_PRIVATE_FULL_NAME, 1); + cfg_init(CFG_PRIVATE_ALT_NAME, 1); +#endif + cfg_init(CFG_FULL_NAME, 1); + cfg_init(CFG_ALT_NAME, 0); + + status_init(NULL, 1); + opt_init(name, argc, argv); + + john_register_all(); + common_init(); + + sig_init(); + + john_load(); +} + +static void john_run(void) +{ + if (options.flags & FLG_TEST_CHK) + benchmark_all(); + else + if (options.flags & FLG_MAKECHR_CHK) + do_makechars(&database, options.charset); + else + if (options.flags & FLG_CRACKING_CHK) { + if (!(options.flags & FLG_STDOUT)) { + status_init(NULL, 1); + log_init(LOG_NAME, POT_NAME, options.session); + john_log_format(); + if (cfg_get_bool(SECTION_OPTIONS, NULL, "Idle")) + log_event("- Configured to use otherwise idle " + "processor cycles only"); + } + tty_init(); + + if (options.flags & FLG_SINGLE_CHK) + do_single_crack(&database); + else + if (options.flags & FLG_WORDLIST_CHK) + do_wordlist_crack(&database, options.wordlist, + (options.flags & FLG_RULES) != 0); + else + if (options.flags & FLG_INC_CHK) + do_incremental_crack(&database, options.charset); + else + if (options.flags & FLG_EXTERNAL_CHK) + do_external_crack(&database); + else + if (options.flags & FLG_BATCH_CHK) + do_batch_crack(&database); + + status_print(); + tty_done(); + } +} + +static void john_done(void) +{ + path_done(); + + if ((options.flags & FLG_CRACKING_CHK) && + !(options.flags & FLG_STDOUT)) { + if (event_abort) + log_event("Session aborted"); + else + log_event("Session completed"); + } + log_done(); + check_abort(0); +} + +int main(int argc, char **argv) +{ + char *name; + +#ifdef __DJGPP__ + if (--argc <= 0) return 1; + if ((name = strrchr(argv[0], '/'))) + strcpy(name + 1, argv[1]); + name = argv[1]; + argv[1] = argv[0]; + argv++; +#else + if (!argv[0]) + name = "john"; + else + if ((name = strrchr(argv[0], '/'))) + name++; + else + name = argv[0]; +#endif + +#ifdef __CYGWIN32__ + strlwr(name); + if (strlen(name) > 4 && !strcmp(name + strlen(name) - 4, ".exe")) + name[strlen(name) - 4] = 0; +#endif + + if (!strcmp(name, "unshadow")) + return unshadow(argc, argv); + + if (!strcmp(name, "unafs")) + return unafs(argc, argv); + + if (!strcmp(name, "unique")) + return unique(argc, argv); + + john_init(name, argc, argv); + john_run(); + john_done(); + + return 0; +}