>>From 25ee3b317c984349d552b196e43cd3f0207b1029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claudio=20Andr=C3=A9?= Date: Thu, 22 Aug 2013 11:34:21 -0300 Subject: [PATCH 1541/1541] OpenCL raw-sha256 format file must follow CPU format conventions. --- src/cryptsha512_common.h | 82 +++++++++++++++++ src/cryptsha512_fmt_plug.c | 2 +- src/cryptsha512_valid.h | 78 ---------------- src/john.c | 2 - src/opencl_cryptsha512_fmt.c | 2 +- src/opencl_rawsha256.h | 3 - src/opencl_rawsha256_fmt.c | 208 +++---------------------------------------- src/rawSHA256_common.h | 121 +++++++++++++++++++++++++ src/rawSHA256_fmt_plug.c | 103 +-------------------- 9 files changed, 216 insertions(+), 385 deletions(-) create mode 100644 src/cryptsha512_common.h delete mode 100644 src/cryptsha512_valid.h create mode 100644 src/rawSHA256_common.h diff --git a/src/cryptsha512_common.h b/src/cryptsha512_common.h new file mode 100644 index 0000000..82f6226 --- /dev/null +++ b/src/cryptsha512_common.h @@ -0,0 +1,82 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 2012 magnum + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. + * + * There's ABSOLUTELY NO WARRANTY, express or implied. + */ + +#ifndef _COMMON_CRYPTSHA512_H +#define _COMMON_CRYPTSHA512_H + +/* ------ Contains (at least) prepare(), valid() and split() ------ */ +/* Prefix for optional rounds specification. */ +#define ROUNDS_PREFIX "rounds=" +/* Default number of rounds if not explicitly specified. */ +#define ROUNDS_DEFAULT 5000 +/* Minimum number of rounds. */ +#define ROUNDS_MIN 1 /* Drepper has it as 1000 */ +/* Maximum number of rounds. */ +#define ROUNDS_MAX 999999999 + +#define FORMAT_NAME "crypt(3) $6$" +#define BENCHMARK_COMMENT " (rounds=5000)" +#define BENCHMARK_LENGTH -1 + +/* ------- Check if the ciphertext if a valid SHA-512 crypt ------- */ +static int valid(char * ciphertext, struct fmt_main * self) { + char *pos, *start; + + if (strncmp(ciphertext, "$6$", 3)) + return 0; + + ciphertext += 3; + + if (!strncmp(ciphertext, ROUNDS_PREFIX, + sizeof(ROUNDS_PREFIX) - 1)) { + const char *num = ciphertext + sizeof(ROUNDS_PREFIX) - 1; + char *endp; + if (!strtoul(num, &endp, 10)) + return 0; + if (*endp == '$') + ciphertext = endp + 1; + } + for (pos = ciphertext; *pos && *pos != '$'; pos++); + if (!*pos || pos < ciphertext || pos > &ciphertext[SALT_LENGTH]) return 0; + + start = ++pos; + while (atoi64[ARCH_INDEX(*pos)] != 0x7F) pos++; + if (*pos || pos - start != CIPHERTEXT_LENGTH) return 0; + return 1; +} + +/* ------- To binary functions ------- */ +#define TO_BINARY(b1, b2, b3) \ + value = (ARCH_WORD_32)atoi64[ARCH_INDEX(pos[0])] | \ + ((ARCH_WORD_32)atoi64[ARCH_INDEX(pos[1])] << 6) | \ + ((ARCH_WORD_32)atoi64[ARCH_INDEX(pos[2])] << 12) | \ + ((ARCH_WORD_32)atoi64[ARCH_INDEX(pos[3])] << 18); \ + pos += 4; \ + out[b1] = value >> 16; \ + out[b2] = value >> 8; \ + out[b3] = value; + +static void * get_binary(char * ciphertext) { + static ARCH_WORD_32 outbuf[BINARY_SIZE/4]; + ARCH_WORD_32 value; + char *pos = strrchr(ciphertext, '$') + 1; + unsigned char *out = (unsigned char*)outbuf; + int i = 0; + + do { + TO_BINARY(i, (i+21)%63, (i+42)%63); + i = (i+22)%63; + } while (i != 21); + value = (ARCH_WORD_32)atoi64[ARCH_INDEX(pos[0])] | + ((ARCH_WORD_32)atoi64[ARCH_INDEX(pos[1])] << 6); + out[63] = value; + return (void *)out; +} +#endif diff --git a/src/cryptsha512_fmt_plug.c b/src/cryptsha512_fmt_plug.c index f0c8a85..3ec67a5 100644 --- a/src/cryptsha512_fmt_plug.c +++ b/src/cryptsha512_fmt_plug.c @@ -44,7 +44,7 @@ #define MIN_KEYS_PER_CRYPT 1 #define MAX_KEYS_PER_CRYPT 1 -#include "cryptsha512_valid.h" +#include "cryptsha512_common.h" static struct fmt_tests tests[] = { {"$6$LKO/Ute40T3FNF95$6S/6T2YuOIHY0N3XpLKABJ3soYcXD9mB7uVbtEZDj/LNscVhZoZ9DEH.sBciDrMsHOWOoASbNLTypH/5X26gN0", "U*U*U*U*"}, diff --git a/src/cryptsha512_valid.h b/src/cryptsha512_valid.h deleted file mode 100644 index bcf2030..0000000 --- a/src/cryptsha512_valid.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This file is part of John the Ripper password cracker, - * Copyright (c) 2012 magnum - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted. - * - * There's ABSOLUTELY NO WARRANTY, express or implied. - */ - -/* ------ Contains (at least) prepare(), valid() and split() ------ */ -/* Prefix for optional rounds specification. */ -#define ROUNDS_PREFIX "rounds=" -/* Default number of rounds if not explicitly specified. */ -#define ROUNDS_DEFAULT 5000 -/* Minimum number of rounds. */ -#define ROUNDS_MIN 1 /* Drepper has it as 1000 */ -/* Maximum number of rounds. */ -#define ROUNDS_MAX 999999999 - -#define FORMAT_NAME "crypt(3) $6$" -#define BENCHMARK_COMMENT " (rounds=5000)" -#define BENCHMARK_LENGTH -1 - -/* ------- Check if the ciphertext if a valid SHA-512 crypt ------- */ -static int valid(char * ciphertext, struct fmt_main * self) { - char *pos, *start; - - if (strncmp(ciphertext, "$6$", 3)) - return 0; - - ciphertext += 3; - - if (!strncmp(ciphertext, ROUNDS_PREFIX, - sizeof(ROUNDS_PREFIX) - 1)) { - const char *num = ciphertext + sizeof(ROUNDS_PREFIX) - 1; - char *endp; - if (!strtoul(num, &endp, 10)) - return 0; - if (*endp == '$') - ciphertext = endp + 1; - } - for (pos = ciphertext; *pos && *pos != '$'; pos++); - if (!*pos || pos < ciphertext || pos > &ciphertext[SALT_LENGTH]) return 0; - - start = ++pos; - while (atoi64[ARCH_INDEX(*pos)] != 0x7F) pos++; - if (*pos || pos - start != CIPHERTEXT_LENGTH) return 0; - return 1; -} - -/* ------- To binary functions ------- */ -#define TO_BINARY(b1, b2, b3) \ - value = (ARCH_WORD_32)atoi64[ARCH_INDEX(pos[0])] | \ - ((ARCH_WORD_32)atoi64[ARCH_INDEX(pos[1])] << 6) | \ - ((ARCH_WORD_32)atoi64[ARCH_INDEX(pos[2])] << 12) | \ - ((ARCH_WORD_32)atoi64[ARCH_INDEX(pos[3])] << 18); \ - pos += 4; \ - out[b1] = value >> 16; \ - out[b2] = value >> 8; \ - out[b3] = value; - -static void * get_binary(char * ciphertext) { - static ARCH_WORD_32 outbuf[BINARY_SIZE/4]; - ARCH_WORD_32 value; - char *pos = strrchr(ciphertext, '$') + 1; - unsigned char *out = (unsigned char*)outbuf; - int i = 0; - - do { - TO_BINARY(i, (i+21)%63, (i+42)%63); - i = (i+22)%63; - } while (i != 21); - value = (ARCH_WORD_32)atoi64[ARCH_INDEX(pos[0])] | - ((ARCH_WORD_32)atoi64[ARCH_INDEX(pos[1])] << 6); - out[63] = value; - return (void *)out; -} diff --git a/src/john.c b/src/john.c index ed1a7e2..c00cf35 100644 --- a/src/john.c +++ b/src/john.c @@ -162,7 +162,6 @@ extern struct fmt_main fmt_opencl_NT; extern struct fmt_main fmt_opencl_NTLMv2; extern struct fmt_main fmt_opencl_agilekeychain; extern struct fmt_main fmt_opencl_bf; -extern struct fmt_main fmt_opencl_cisco4; extern struct fmt_main fmt_opencl_cryptMD5; extern struct fmt_main fmt_opencl_cryptsha256; extern struct fmt_main fmt_opencl_cryptsha512; @@ -376,7 +375,6 @@ static void john_register_all(void) john_register_one(&fmt_opencl_agilekeychain); john_register_one(&fmt_opencl_bf); john_register_one(&fmt_opencl_blockchain); - john_register_one(&fmt_opencl_cisco4); john_register_one(&fmt_opencl_cryptMD5); john_register_one(&fmt_opencl_cryptsha256); john_register_one(&fmt_opencl_cryptsha512); diff --git a/src/opencl_cryptsha512_fmt.c b/src/opencl_cryptsha512_fmt.c index 7f329e7..6659c86 100644 --- a/src/opencl_cryptsha512_fmt.c +++ b/src/opencl_cryptsha512_fmt.c @@ -18,7 +18,7 @@ #include "config.h" #include "options.h" #include "opencl_cryptsha512.h" -#include "cryptsha512_valid.h" +#include "cryptsha512_common.h" #define FORMAT_LABEL "sha512crypt-opencl" #define ALGORITHM_NAME "SHA512 OpenCL" diff --git a/src/opencl_rawsha256.h b/src/opencl_rawsha256.h index ab68467..6968b25 100644 --- a/src/opencl_rawsha256.h +++ b/src/opencl_rawsha256.h @@ -21,9 +21,6 @@ #define RAW_PLAINTEXT_LENGTH 56 /* 55 characters + 0x80 */ #define CISCO_PLAINTEXT_LENGTH 26 /* 25 characters + 0x80 */ -#define RAW_CIPHERTEXT_LENGTH 64 -#define CISCO_CIPHERTEXT_LENGTH 43 - #define BUFFER_SIZE 56 /* RAW_PLAINTEXT_LENGTH multiple of 4 */ #define CIPHERTEXT_LENGTH 64 #define BINARY_SIZE 4 diff --git a/src/opencl_rawsha256_fmt.c b/src/opencl_rawsha256_fmt.c index fba2918..7038893 100644 --- a/src/opencl_rawsha256_fmt.c +++ b/src/opencl_rawsha256_fmt.c @@ -21,17 +21,13 @@ #include "config.h" #include "options.h" #include "opencl_rawsha256.h" +#include "rawSHA256_common.h" -#define RAW_FORMAT_LABEL "Raw-SHA256-opencl" -#define RAW_FORMAT_NAME "" -#define CISCO_FORMAT_LABEL "cisco4-opencl" -#define CISCO_FORMAT_NAME "Cisco \"type 4\" hashes" +#define FORMAT_LABEL "Raw-SHA256-opencl" +#define FORMAT_NAME "" #define ALGORITHM_NAME "SHA256 OpenCL (inefficient, development use mostly)" -#define BENCHMARK_COMMENT "" -#define BENCHMARK_LENGTH -1 - #define CONFIG_NAME "rawsha256" static uint32_t * plaintext, * saved_idx; // plaintext ciphertexts @@ -53,7 +49,7 @@ static size_t offset = 0, offset_idx = 0; static int crypt_all(int *pcount, struct db_salt *_salt); static int crypt_all_benchmark(int *pcount, struct db_salt *_salt); -static struct fmt_tests raw_tests[] = { +static struct fmt_tests tests[] = { {"5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", "password"}, {"$SHA256$ef797c8118f02dfb649607dd5d3f8c7623048c9c063d532cc95c5ed7a898a64f", "12345678"}, {"$SHA256$e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""}, @@ -66,11 +62,6 @@ static struct fmt_tests raw_tests[] = { {"f58fffba129aa67ec63bf12571a42977c0b785d3b2a93cc0538557c91da2115d", "12345678901234567890123456789012345678901234567890"}, {"3874d5c9cc5ab726e6bbebadee22c680ce530004d4f0bb32f765d42a0a6c6dc1", "123456789012345678901234567890123456789012345678901"}, {"03c3a70e99ed5eeccd80f73771fcf1ece643d939d9ecc76f25544b0233f708e9", "1234567890123456789012345678901234567890123456789012345"}, -#endif - {NULL} -}; - -static struct fmt_tests cisco_tests[] = { {"$cisco4$OsOmQzwozC4ROs/CzpczJoShdCeW9lp7k/tGrPS5Kog", "1"}, {"$cisco4$LcV6aBcc/53FoCJjXQMd7rBUDEpeevrK8V5jQVoJEhU", "password"}, {"$cisco4$d7kgbEk.P6mpKdduC66fUy1BF0MImo3eyJ9uI/JbMRk", "openwall"}, @@ -81,6 +72,7 @@ static struct fmt_tests cisco_tests[] = { {"$cisco4$fLUL1VG98zYDf9Q.M40nZ5blVT3M6UBex74Blw.UDCc", "thismaximumpasswordlength"}, {"$cisco4$Xq81UiuCj7bz9B..EX2BZumsU/d8pF5gs2NlRMW6sTk", "applesucks"}, {"$cisco4$O/D/cn1nawcByQoJfBxrNnUx6jjfWV.FNFx5TzmzihU", "AppleSucks"}, +#endif {NULL} }; @@ -104,29 +96,6 @@ static size_t get_default_workgroup(){ return 64; } -static void decode64(unsigned char * dst, unsigned char * src) { - int i, j; - unsigned int ch; - - for (i = 0, j = 0; j < SHA256_DIGEST_LENGTH; j += 3) { - // Get 1st byte of input (1st and 2nd) - ch = src[i++]; - dst[j] = ((atoi64[ch] << 2) & 252) + (atoi64[src[i]] >> 4 & 0x03); - - // Get 2nd byte of input (2nd and 3rd) - ch = src[i++]; - dst[j + 1] = ((atoi64[ch] << 4) & 240) + (atoi64[src[i]] >> 2 & 0x0f); - - // Size of destination string. - if (j + 2 == SHA256_DIGEST_LENGTH) { - break; - } - // Get 3rd byte of input (3rd and 4th) - ch = src[i++]; - dst[j + 2] = ((atoi64[ch] << 6) & 192) + (atoi64[src[i++]] & 0x3f); - } -} - static void crypt_one(int index, sha256_hash * hash) { SHA256_CTX ctx; @@ -403,58 +372,6 @@ static void done(void) { HANDLE_CLERROR(clReleaseProgram(program[ocl_gpu_id]), "Release Program"); } -/* ------- Check if the ciphertext if a valid SHA-256 ------- */ -static int valid(char * ciphertext, struct fmt_main * self) { - char *p, *q; - - p = ciphertext; - if (!strncmp(p, "$SHA256$", 8)) - p += 8; - - q = p; - while (atoi16[ARCH_INDEX(*q)] != 0x7F) - q++; - return !*q && q - p == CIPHERTEXT_LENGTH; -} - -static char *split(char *ciphertext, int index, struct fmt_main *pFmt) { - - static char out[8 + CIPHERTEXT_LENGTH + 1]; - - if (!strncmp(ciphertext, "$SHA256$", 8)) - return ciphertext; - - memcpy(out, "$SHA256$", 8); - memcpy(out + 8, ciphertext, CIPHERTEXT_LENGTH + 1); - strlwr(out + 8); - return out; -} - -static int valid_cisco(char * ciphertext, struct fmt_main * self) { - char *p, *q; - - p = ciphertext; - if (!strncmp(p, "$cisco4$", 8)) - p += 8; - - q = p; - while (atoi64[ARCH_INDEX(*q)] != 0x7F) - q++; - return !*q && q - p == CISCO_CIPHERTEXT_LENGTH; -} - -static char *split_cisco(char *ciphertext, int index, struct fmt_main *pFmt) { - - static char out[8 + CISCO_CIPHERTEXT_LENGTH + 1]; - - if (!strncmp(ciphertext, "$cisco4$", 8)) - return ciphertext; - - memcpy(out, "$cisco4$", 8); - memcpy(out + 8, ciphertext, CISCO_CIPHERTEXT_LENGTH + 1); - return out; -} - /* ------- To binary functions ------- */ static void * get_binary(char *ciphertext) { static unsigned char *out; @@ -495,39 +412,6 @@ static void * get_full_binary(char *ciphertext) { return out; } -static void * get_cisco_binary(char *ciphertext) { - static unsigned char *out; - uint32_t * b; - unsigned char *p; - - if (!out) out = mem_alloc_tiny(FULL_BINARY_SIZE, MEM_ALIGN_WORD); - - p = (unsigned char *) ciphertext + 8; - - //Decode for CISCO-4. - decode64(out, p); - - //Undo some computation. - b = (uint32_t *) out; - b[0] = SWAP32(b[3]) - H3; - - return out; -} - -static void * get_cisco_full_binary(char *ciphertext) { - static unsigned char *out; - unsigned char *p; - - if (!out) out = mem_alloc_tiny(FULL_BINARY_SIZE, MEM_ALIGN_WORD); - - p = (unsigned char *) ciphertext + 8; - - //Decode for CISCO-4. - decode64(out, p); - - return out; -} - /* ------- Crypt function ------- */ static int crypt_all_benchmark(int *pcount, struct db_salt *_salt) { int count = *pcount; @@ -651,21 +535,6 @@ static int cmp_exact(char *source, int index) { return !memcmp(binary, (void *) &full_hash, FULL_BINARY_SIZE); } -static int cmp_exact_cisco(char *source, int index) { - //I don't know why, but this is called and i have to recheck. - //If i skip this final test i get: - //form=raw-sha512-ng-opencl guesses: 1468 time: 0:00:00:02 : Expected count(s) (1500) [!!!FAILED!!!] - //.pot CHK:raw-sha512-ng-opencl guesses: 1452 time: 0:00:00:02 : Expected count(s) (1500) [!!!FAILED!!!] - - uint32_t * binary; - sha256_hash full_hash; - - crypt_one(index, &full_hash); - - binary = (uint32_t *) get_cisco_full_binary(source); - return !memcmp(binary, (void *) &full_hash, FULL_BINARY_SIZE); -} - /* ------- Binary Hash functions group ------- */ #ifdef DEBUG static void print_binary(void * binary) { @@ -708,8 +577,8 @@ static int get_hash_6(int index) { return calculated_hash[index] & 0x7ffffff; } /* ------- Format structure ------- */ struct fmt_main fmt_opencl_rawsha256 = { { - RAW_FORMAT_LABEL, - RAW_FORMAT_NAME, + FORMAT_LABEL, + FORMAT_NAME, ALGORITHM_NAME, BENCHMARK_COMMENT, BENCHMARK_LENGTH, @@ -721,12 +590,12 @@ struct fmt_main fmt_opencl_rawsha256 = { MIN_KEYS_PER_CRYPT, MAX_KEYS_PER_CRYPT, FMT_CASE | FMT_8_BIT | FMT_SPLIT_UNIFIES_CASE, - raw_tests + tests }, { init, done, fmt_default_reset, - fmt_default_prepare, + prepare, valid, split, get_binary, @@ -760,61 +629,4 @@ struct fmt_main fmt_opencl_rawsha256 = { cmp_one, cmp_exact } -}; - -/* ------- Format structure ------- */ -struct fmt_main fmt_opencl_cisco4 = { - { - CISCO_FORMAT_LABEL, - CISCO_FORMAT_NAME, - ALGORITHM_NAME, - BENCHMARK_COMMENT, - BENCHMARK_LENGTH, - CISCO_PLAINTEXT_LENGTH - 1, - BINARY_SIZE, - BINARY_ALIGN, - SALT_SIZE, - SALT_ALIGN, - MIN_KEYS_PER_CRYPT, - MAX_KEYS_PER_CRYPT, - FMT_CASE | FMT_8_BIT, - cisco_tests - }, { - init, - done, - fmt_default_reset, - fmt_default_prepare, - valid_cisco, - split_cisco, - get_cisco_binary, - fmt_default_salt, - fmt_default_source, - { - fmt_default_binary_hash_0, - fmt_default_binary_hash_1, - fmt_default_binary_hash_2, - fmt_default_binary_hash_3, - fmt_default_binary_hash_4, - fmt_default_binary_hash_5, - fmt_default_binary_hash_6 - }, - fmt_default_salt_hash, - fmt_default_set_salt, - set_key, - get_key, - clear_keys, - crypt_all, - { - get_hash_0, - get_hash_1, - get_hash_2, - get_hash_3, - get_hash_4, - get_hash_5, - get_hash_6 - }, - cmp_all, - cmp_one, - cmp_exact_cisco - } -}; +}; \ No newline at end of file diff --git a/src/rawSHA256_common.h b/src/rawSHA256_common.h new file mode 100644 index 0000000..69a60e0 --- /dev/null +++ b/src/rawSHA256_common.h @@ -0,0 +1,121 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 2012 magnum + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. + * + * There's ABSOLUTELY NO WARRANTY, express or implied. + */ + +#ifndef _COMMON_RAWSHA256_H +#define _COMMON_RAWSHA256_H + +/* ------ Contains (at least) prepare(), valid() and split() ------ */ +/* Note: Cisco hashes are truncated at length 25. We currently ignore this. */ +#define HEX_CIPHERTEXT_LENGTH 64 +#define CISCO_CIPHERTEXT_LENGTH 43 + +#define HEX_TAG "$SHA256$" +#define CISCO_TAG "$cisco4$" + +#define HEX_TAG_LEN (sizeof(HEX_TAG) - 1) +#define CISCO_TAG_LEN (sizeof(CISCO_TAG) - 1) + +#define BENCHMARK_COMMENT "" +#define BENCHMARK_LENGTH -1 + +/* ------- Check if the ciphertext if a valid SHA2 hash ------- */ +static int valid_cisco(char *ciphertext) +{ + char *p, *q; + + p = ciphertext; + if (!strncmp(p, CISCO_TAG, CISCO_TAG_LEN)) + p += CISCO_TAG_LEN; + + q = p; + while (atoi64[ARCH_INDEX(*q)] != 0x7F) + q++; + return !*q && q - p == CISCO_CIPHERTEXT_LENGTH; +} + +static int valid_hex(char *ciphertext) +{ + char *p, *q; + + p = ciphertext; + if (!strncmp(p, HEX_TAG, HEX_TAG_LEN)) + p += HEX_TAG_LEN; + + q = p; + while (atoi16[ARCH_INDEX(*q)] != 0x7F) + q++; + return !*q && q - p == HEX_CIPHERTEXT_LENGTH; +} + +static int valid(char *ciphertext, struct fmt_main *self) +{ + return (valid_hex(ciphertext) || valid_cisco(ciphertext)); +} + +/* Convert Cisco hashes to hex ones, so .pot entries are compatible */ +static char *prepare(char *split_fields[10], struct fmt_main *self) +{ + static char out[HEX_TAG_LEN + HEX_CIPHERTEXT_LENGTH + 1]; + char *o, *p = split_fields[1]; + + if (!valid_cisco(p)) + return p; + + if (!strncmp(p, CISCO_TAG, CISCO_TAG_LEN)) + p += CISCO_TAG_LEN; + + strcpy(out, HEX_TAG); + o = out + HEX_TAG_LEN; + + while(*p) { + unsigned int ch, b; + + // Get 1st byte of input (1st and 2nd) + ch = *p++; + b = ((atoi64[ch] << 2) & 252) + + (atoi64[ARCH_INDEX(*p)] >> 4 & 0x03); + *o++ = itoa16[b >> 4]; + *o++ = itoa16[b & 0x0f]; + + // Get 2nd byte of input (2nd and 3rd) + ch = *p++; + b = ((atoi64[ch] << 4) & 240) + + (atoi64[ARCH_INDEX(*p)] >> 2 & 0x0f); + *o++ = itoa16[b >> 4]; + *o++ = itoa16[b & 0x0f]; + + if (!p[1]) + return out; + + // Get 3rd byte of input (3rd and 4th) + ch = *p++; + b = ((atoi64[ch] << 6) & 192) + + (atoi64[ARCH_INDEX(*p++)] & 0x3f); + *o++ = itoa16[b >> 4]; + *o++ = itoa16[b & 0x0f]; + } + printf("Error in prepare()"); + exit(1); +} + +/* ------- Split ------- */ +static char *split(char *ciphertext, int index, struct fmt_main *self) +{ + static char out[HEX_TAG_LEN + HEX_CIPHERTEXT_LENGTH + 1]; + + if (!strncmp(ciphertext, HEX_TAG, HEX_TAG_LEN)) + return ciphertext; + + memcpy(out, HEX_TAG, HEX_TAG_LEN); + memcpy(out + HEX_TAG_LEN, ciphertext, HEX_CIPHERTEXT_LENGTH + 1); + strlwr(out + HEX_TAG_LEN); + return out; +} +#endif \ No newline at end of file diff --git a/src/rawSHA256_fmt_plug.c b/src/rawSHA256_fmt_plug.c index 3ba629f..04c2a13 100644 --- a/src/rawSHA256_fmt_plug.c +++ b/src/rawSHA256_fmt_plug.c @@ -23,6 +23,7 @@ #include "common.h" #include "johnswap.h" #include "formats.h" +#include "rawSHA256_common.h" #ifdef _OPENMP #ifdef MMX_COEF_SHA256 @@ -36,11 +37,6 @@ #define FORMAT_LABEL "Raw-SHA256" #define FORMAT_NAME "" -#define HEX_TAG "$SHA256$" -#define CISCO_TAG "$cisco4$" - -#define HEX_TAG_LEN (sizeof(HEX_TAG) - 1) -#define CISCO_TAG_LEN (sizeof(CISCO_TAG) - 1) #ifdef MMX_COEF_SHA256 #define ALGORITHM_NAME SHA256_ALGORITHM_NAME @@ -48,17 +44,12 @@ #define ALGORITHM_NAME "32/" ARCH_BITS_STR " " SHA2_LIB #endif -#define BENCHMARK_COMMENT "" -#define BENCHMARK_LENGTH -1 - /* Note: Cisco hashes are truncated at length 25. We currently ignore this. */ #ifdef MMX_COEF_SHA256 #define PLAINTEXT_LENGTH 55 #else #define PLAINTEXT_LENGTH 125 #endif -#define HEX_CIPHERTEXT_LENGTH 64 -#define CISCO_CIPHERTEXT_LENGTH 43 #define BINARY_SIZE 32 #define BINARY_ALIGN MEM_ALIGN_WORD @@ -112,98 +103,6 @@ static void init(struct fmt_main *self) #endif } -static int valid_cisco(char *ciphertext) -{ - char *p, *q; - - p = ciphertext; - if (!strncmp(p, CISCO_TAG, CISCO_TAG_LEN)) - p += CISCO_TAG_LEN; - - q = p; - while (atoi64[ARCH_INDEX(*q)] != 0x7F) - q++; - return !*q && q - p == CISCO_CIPHERTEXT_LENGTH; -} - -static int valid_hex(char *ciphertext) -{ - char *p, *q; - - p = ciphertext; - if (!strncmp(p, HEX_TAG, HEX_TAG_LEN)) - p += HEX_TAG_LEN; - - q = p; - while (atoi16[ARCH_INDEX(*q)] != 0x7F) - q++; - return !*q && q - p == HEX_CIPHERTEXT_LENGTH; -} - -static int valid(char *ciphertext, struct fmt_main *self) -{ - return (valid_hex(ciphertext) || valid_cisco(ciphertext)); -} - -/* Convert Cisco hashes to hex ones, so .pot entries are compatible */ -static char *prepare(char *split_fields[10], struct fmt_main *self) -{ - static char out[HEX_TAG_LEN + HEX_CIPHERTEXT_LENGTH + 1]; - char *o, *p = split_fields[1]; - - if (!valid_cisco(p)) - return p; - - if (!strncmp(p, CISCO_TAG, CISCO_TAG_LEN)) - p += CISCO_TAG_LEN; - - strcpy(out, HEX_TAG); - o = out + HEX_TAG_LEN; - - while(*p) { - unsigned int ch, b; - - // Get 1st byte of input (1st and 2nd) - ch = *p++; - b = ((atoi64[ch] << 2) & 252) + - (atoi64[ARCH_INDEX(*p)] >> 4 & 0x03); - *o++ = itoa16[b >> 4]; - *o++ = itoa16[b & 0x0f]; - - // Get 2nd byte of input (2nd and 3rd) - ch = *p++; - b = ((atoi64[ch] << 4) & 240) + - (atoi64[ARCH_INDEX(*p)] >> 2 & 0x0f); - *o++ = itoa16[b >> 4]; - *o++ = itoa16[b & 0x0f]; - - if (!p[1]) - return out; - - // Get 3rd byte of input (3rd and 4th) - ch = *p++; - b = ((atoi64[ch] << 6) & 192) + - (atoi64[ARCH_INDEX(*p++)] & 0x3f); - *o++ = itoa16[b >> 4]; - *o++ = itoa16[b & 0x0f]; - } - printf("Error in prepare()"); - exit(1); -} - -static char *split(char *ciphertext, int index, struct fmt_main *self) -{ - static char out[HEX_TAG_LEN + HEX_CIPHERTEXT_LENGTH + 1]; - - if (!strncmp(ciphertext, HEX_TAG, HEX_TAG_LEN)) - return ciphertext; - - memcpy(out, HEX_TAG, HEX_TAG_LEN); - memcpy(out + HEX_TAG_LEN, ciphertext, HEX_CIPHERTEXT_LENGTH + 1); - strlwr(out + HEX_TAG_LEN); - return out; -} - static void *binary(char *ciphertext) { static unsigned char *out; -- 1.8.1.2