/* * 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() ------ */ /* ------- 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; }