/* ------- Binary ------- */
void * sha512_common_binary(char *ciphertext)
{
	static unsigned char * out;
	char *p;
	int i;

	if (!out) out = mem_calloc_tiny(BINARY_SIZE, MEM_ALIGN_WORD);

	p = ciphertext + TAG_LENGTH;
	for (i = 0; i < BINARY_SIZE; i++) {
		out[i] =
				(atoi16[ARCH_INDEX(*p)] << 4) |
				 atoi16[ARCH_INDEX(p[1])];
		p += 2;
	}

#ifdef SIMD_COEF_64
	alter_endianity_to_BE64(out, BINARY_SIZE/8);
#endif
	return out;
}
示例#2
0
/* We're essentially using three salts, but we're going to pack it into a single blob for now.
   |Client Challenge (8 Bytes)|Server Challenge (8 Bytes)|Unicode(Username (<=20).Domain (<=15))
*/
static void *get_salt(char *ciphertext)
{
  static unsigned char *binary_salt;
  unsigned char identity[USERNAME_LENGTH + DOMAIN_LENGTH + 1];
  UTF16 identity_ucs2[USERNAME_LENGTH + DOMAIN_LENGTH + 1];
  int i, identity_length;
  int identity_ucs2_length;
  char *pos = NULL;

  if (!binary_salt) binary_salt = mem_alloc_tiny(SALT_SIZE, MEM_ALIGN_WORD);

  /* Calculate identity length */
  for (pos = ciphertext + 9; *pos != '$'; pos++);
  identity_length = pos - (ciphertext + 9);

  /* Convert identity (username + domain) string to NT unicode */
  strnzcpy((char *)identity, ciphertext + 9, sizeof(identity));
  identity_ucs2_length = enc_to_utf16((UTF16 *)identity_ucs2, USERNAME_LENGTH + DOMAIN_LENGTH, (UTF8 *)identity, identity_length) * sizeof(int16);

  if (identity_ucs2_length < 0) // Truncated at Unicode conversion.
	  identity_ucs2_length = strlen16((UTF16 *)identity_ucs2) * sizeof(int16);

  binary_salt[16] = (unsigned char)identity_ucs2_length;
  memcpy(&binary_salt[17], (char *)identity_ucs2, identity_ucs2_length);

  /* Set server challenge */
  ciphertext += 10 + identity_length;

  for (i = 0; i < 8; i++)
    binary_salt[i] = (atoi16[ARCH_INDEX(ciphertext[i*2])] << 4) + atoi16[ARCH_INDEX(ciphertext[i*2+1])];

  /* Set client challenge */
  ciphertext += 2 + CHALLENGE_LENGTH / 2 + CIPHERTEXT_LENGTH;

  for (i = 0; i < 8; ++i)
    binary_salt[i + 8] = (atoi16[ARCH_INDEX(ciphertext[i*2])] << 4) + atoi16[ARCH_INDEX(ciphertext[i*2+1])];

  /* Return a concatenation of the server and client challenges and the identity value */
  return (void*)binary_salt;
}
//code from historical JtR phpass patch
static void *get_binary(char *ciphertext)
{
	static unsigned char b[BINARY_SIZE];
	int i, bidx = 0;
	unsigned sixbits;
	char *pos = &ciphertext[3 + 1 + 8];
	memset(b, 0, BINARY_SIZE);

	for (i = 0; i < 5; i++) {
		sixbits = atoi64[ARCH_INDEX(*pos++)];
		b[bidx] = sixbits;
		sixbits = atoi64[ARCH_INDEX(*pos++)];
		b[bidx++] |= (sixbits << 6);
		sixbits >>= 2;
		b[bidx] = sixbits;
		sixbits = atoi64[ARCH_INDEX(*pos++)];
		b[bidx++] |= (sixbits << 4);
		sixbits >>= 4;
		b[bidx] = sixbits;
		sixbits = atoi64[ARCH_INDEX(*pos++)];
		b[bidx++] |= (sixbits << 2);
	}
	sixbits = atoi64[ARCH_INDEX(*pos++)];
	b[bidx] = sixbits;
	sixbits = atoi64[ARCH_INDEX(*pos++)];
	b[bidx] |= (sixbits << 6);
	return (void *) b;
}
示例#4
0
static void * wpapsk_binary(char *ciphertext) 
{
	static unsigned char realcipher[BINARY_SIZE];
	int i,pos;
	
	for(i=0;ciphertext[i]!='#';i++);
	pos=i+1;
	for(i=0;i<BINARY_SIZE;i++)
	{
		realcipher[i] = atoi16[ARCH_INDEX(ciphertext[i*2+pos])]*16 + atoi16[ARCH_INDEX(ciphertext[i*2+1+pos])];
	}
	pos += i*2+1;
	i=0;
	while(ciphertext[pos]!=' ')
	{
		DATA[i] = atoi16[ARCH_INDEX(ciphertext[pos])]*16 + atoi16[ARCH_INDEX(ciphertext[1+pos])];
		i++;
		pos += 2;
	}
	memcpy(nDATA+23, DATA, 12+64);
	pos++;
	i=0;
	while(ciphertext[pos])
	{
		EAPOL[i] = atoi16[ARCH_INDEX(ciphertext[pos])]*16 + atoi16[ARCH_INDEX(ciphertext[1+pos])];
		i++;
		pos += 2;
	}

	return (void *)realcipher;
}
static void *get_salt(char *ciphertext)
{
	char *ctcopy = strdup(ciphertext);
	char *keeptr = ctcopy;
	int i;
	char *p;

	salt_struct = mem_calloc_tiny(sizeof(struct custom_salt),
	                              MEM_ALIGN_WORD);
	ctcopy += 11;	/* skip over "$keychain$*" */
	p = strtokm(ctcopy, "*");
	for (i = 0; i < SALTLEN; i++)
		salt_struct->salt[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
			+ atoi16[ARCH_INDEX(p[i * 2 + 1])];
	p = strtokm(NULL, "*");
	for (i = 0; i < IVLEN; i++)
		salt_struct->iv[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
			+ atoi16[ARCH_INDEX(p[i * 2 + 1])];
	p = strtokm(NULL, "*");
	for (i = 0; i < CTLEN; i++)
		salt_struct->ct[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
			+ atoi16[ARCH_INDEX(p[i * 2 + 1])];

	MEM_FREE(keeptr);
	return (void *)salt_struct;
}
示例#6
0
static void *get_salt(char *ciphertext)
{
	char *ctcopy = strdup(ciphertext);
	char *keeptr = ctcopy;
	int i;
	char *p;

	ctcopy += 5;	/* skip over "$pdf$" marker */
	salt_struct = mem_calloc_tiny(sizeof(struct custom_salt), MEM_ALIGN_WORD);

	/* restore serialized data */
	salt_struct->e.s_handler = strtok(ctcopy, "*");
	salt_struct->e.o_string = (uint8_t *) malloc(32);
	p = strtok(NULL, "*");
	for (i = 0; i < 32; i++)
		salt_struct->e.o_string[i] =
		    atoi16[ARCH_INDEX(p[i * 2])] * 16 +
		    atoi16[ARCH_INDEX(p[i * 2 + 1])];
	salt_struct->e.u_string = (uint8_t *) malloc(32);
	p = strtok(NULL, "*");
	for (i = 0; i < 32; i++)
		salt_struct->e.u_string[i] =
		    atoi16[ARCH_INDEX(p[i * 2])] * 16 +
		    atoi16[ARCH_INDEX(p[i * 2 + 1])];
	p = strtok(NULL, "*");
	salt_struct->e.fileIDLen = atoi(p);
	salt_struct->e.fileID = (uint8_t *) malloc(salt_struct->e.fileIDLen);
	p = strtok(NULL, "*");
	for (i = 0; i < salt_struct->e.fileIDLen; i++)
		salt_struct->e.fileID[i] =
		    atoi16[ARCH_INDEX(p[i * 2])] * 16 +
		    atoi16[ARCH_INDEX(p[i * 2 + 1])];
	p = strtok(NULL, "*");
	salt_struct->e.encryptMetaData = atoi(p);
	p = strtok(NULL, "*");
	salt_struct->e.work_with_user = atoi(p);
	p = strtok(NULL, "*");
	salt_struct->e.have_userpassword = atoi(p);
	p = strtok(NULL, "*");
	salt_struct->e.version_major = atoi(p);
	p = strtok(NULL, "*");
	salt_struct->e.version_minor = atoi(p);
	p = strtok(NULL, "*");
	salt_struct->e.length = atoi(p);
	p = strtok(NULL, "*");
	salt_struct->e.permissions = atoi(p);
	p = strtok(NULL, "*");
	salt_struct->e.revision = atoi(p);
	p = strtok(NULL, "*");
	salt_struct->e.version = atoi(p);
	if (salt_struct->e.have_userpassword)
		salt_struct->userpassword = (unsigned char *)strtok(NULL, "*");
	free(keeptr);
	/* try to initialize the cracking-engine */
	if (!initPDFCrack(salt_struct)) {
		fprintf(stderr, "Wrong userpassword, '%s'\n", salt_struct->userpassword);
		exit(-1);
	}
	return (void *)salt_struct;
}
示例#7
0
static void *get_salt(char *ciphertext)
{
	char *ctcopy = strdup(ciphertext);
	char *keeptr = ctcopy;
	char *p;
	int i;

	memset(&cs, 0, sizeof(cs));
	ctcopy += TAG_LEN;	/* skip over "$oldoffice$" */
	p = strtok(ctcopy, "*");
	cs.type = atoi(p);
	p = strtok(NULL, "*");
	for (i = 0; i < 16; i++)
		cs.salt[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
			+ atoi16[ARCH_INDEX(p[i * 2 + 1])];
	p = strtok(NULL, "*");
	for (i = 0; i < 16; i++)
		cs.verifier[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
			+ atoi16[ARCH_INDEX(p[i * 2 + 1])];
	p = strtok(NULL, "*");
	if(cs.type < 3) {
		for (i = 0; i < 16; i++)
			cs.verifierHash[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
				+ atoi16[ARCH_INDEX(p[i * 2 + 1])];
	}
	else {
		for (i = 0; i < 20; i++)
			cs.verifierHash[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
				+ atoi16[ARCH_INDEX(p[i * 2 + 1])];
	}
	if ((p = strtok(NULL, "*"))) {
		cs.has_mitm = 1;
		for (i = 0; i < 5; i++)
			cs.mitm[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
				+ atoi16[ARCH_INDEX(p[i * 2 + 1])];
	} else
		cs.has_mitm = 0;
	MEM_FREE(keeptr);
	return (void *)&cs;
}
示例#8
0
static void *get_salt(char *ciphertext)
{
    int i, length;
    char *ctcopy = strdup(ciphertext);
    char *keeptr = ctcopy, *p;
    ctcopy += 9;	/* skip over "$office$*" */
    cur_salt = mem_alloc_tiny(sizeof(struct custom_salt), MEM_ALIGN_WORD);
    p = strtok(ctcopy, "*");
    cur_salt->version = atoi(p);
    p = strtok(NULL, "*");
    cur_salt->verifierHashSize = atoi(p);
    p = strtok(NULL, "*");
    cur_salt->keySize = atoi(p);
    p = strtok(NULL, "*");
    cur_salt->saltSize = atoi(p);
    if (cur_salt->saltSize > SALT_LENGTH) {
        fprintf(stderr, "** error: salt longer than supported:\n%s\n", ciphertext);
        cur_salt->saltSize = SALT_LENGTH; /* will not work, but protects us from segfault */
    }
    p = strtok(NULL, "*");
    for (i = 0; i < cur_salt->saltSize; i++)
        cur_salt->osalt[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
                             + atoi16[ARCH_INDEX(p[i * 2 + 1])];
    p = strtok(NULL, "*");
    for (i = 0; i < 16; i++)
        cur_salt->encryptedVerifier[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
                                         + atoi16[ARCH_INDEX(p[i * 2 + 1])];
    p = strtok(NULL, "*");
    length = strlen(p) / 2;
    for (i = 0; i < length; i++)
        cur_salt->encryptedVerifierHash[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
                                             + atoi16[ARCH_INDEX(p[i * 2 + 1])];
    MEM_FREE(keeptr);
    return (void *)cur_salt;
}
static void *get_salt(char *ciphertext)
{
	char *ctcopy = strdup(ciphertext);
	char *keeptr = ctcopy;
	int i;
	char *p;

	static union {
		struct custom_salt _cs;
		ARCH_WORD_32 dummy;
	} un;
	struct custom_salt *cs = &(un._cs);

	ctcopy += 4;
	p = strtokm(ctcopy, "$");
	cs->type = atoi(p);
	p = strtokm(NULL, "$");
	cs->NumCyclesPower = atoi(p);
	p = strtokm(NULL, "$");
	cs->SaltSize = atoi(p);
	p = strtokm(NULL, "$"); /* salt */
	p = strtokm(NULL, "$");
	cs->ivSize = atoi(p);
	p = strtokm(NULL, "$"); /* iv */
	for (i = 0; i < cs->ivSize; i++)
		cs->iv[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
			+ atoi16[ARCH_INDEX(p[i * 2 + 1])];
	p = strtokm(NULL, "$"); /* crc */
	cs->crc = atou(p);
	p = strtokm(NULL, "$");
	cs->length = atoi(p);
	p = strtokm(NULL, "$");
	cs->unpacksize = atoi(p);
	p = strtokm(NULL, "$"); /* crc */
	for (i = 0; i < cs->length; i++)
		cs->data[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
			+ atoi16[ARCH_INDEX(p[i * 2 + 1])];
	MEM_FREE(keeptr);
	return (void *)cs;
}
示例#10
0
///code from historical JtR phpass patch
static void pbinary(char *ciphertext, unsigned char *out)
{
	int i, bidx = 0;
	unsigned sixbits;
	char *pos = &ciphertext[3 + 1 + 8];
	memset(out, 0, BINARY_SIZE);

	for (i = 0; i < 5; i++) {
		sixbits = atoi64[ARCH_INDEX(*pos++)];
		out[bidx] = sixbits;
		sixbits = atoi64[ARCH_INDEX(*pos++)];
		out[bidx++] |= (sixbits << 6);
		sixbits >>= 2;
		out[bidx] = sixbits;
		sixbits = atoi64[ARCH_INDEX(*pos++)];
		out[bidx++] |= (sixbits << 4);
		sixbits >>= 4;
		out[bidx] = sixbits;
		sixbits = atoi64[ARCH_INDEX(*pos++)];
		out[bidx++] |= (sixbits << 2);
	}
	sixbits = atoi64[ARCH_INDEX(*pos++)];
	out[bidx] = sixbits;
	sixbits = atoi64[ARCH_INDEX(*pos++)];
	out[bidx] |= (sixbits << 6);
}
示例#11
0
static int valid(char *ciphertext, struct fmt_main *self)
{
	char *pos, *start;

	if (strncmp(ciphertext, "$1$", 3)) {
		if (strncmp(ciphertext, "$apr1$", 6) &&
		    strncmp(ciphertext, "{smd5}", 6))
			return 0;
		ciphertext += 3;
	}

	for (pos = &ciphertext[3]; *pos && *pos != '$'; pos++);
	if (!*pos || pos < &ciphertext[3] || pos > &ciphertext[11]) return 0;

	start = ++pos;
	while (atoi64[ARCH_INDEX(*pos)] != 0x7F) pos++;
	if (*pos || pos - start != CIPHERTEXT_LENGTH) return 0;

	if (atoi64[ARCH_INDEX(*(pos - 1))] & 0x3C) return 0;

	return 1;
}
示例#12
0
static int valid(char *ciphertext, struct fmt_main *pFmt)
{
	uint8_t i, len = strlen(ciphertext), prefix = 0;

	if (strncmp(ciphertext, md5_salt_prefix, strlen(md5_salt_prefix)) == 0)
		prefix |= 1;
	if (strncmp(ciphertext, apr1_salt_prefix,
		strlen(apr1_salt_prefix)) == 0)
		prefix |= 2;
	if (prefix == 0)
		return 0;

	char *p = strrchr(ciphertext, '$');
	for (i = p - ciphertext + 1; i < len; i++) {
		uint8_t z = ARCH_INDEX(ciphertext[i]);
		if (ARCH_INDEX(atoi64[z]) == 0x7f)
			return 0;
	}
	if (len - (p - ciphertext + 1) != 22)
		return 0;
	return 1;
};
示例#13
0
static int valid(char* ciphertext, struct fmt_main *self)
{
	unsigned int i;

	if (strlen(ciphertext) != CIPHERTEXT_LENGTH)
		return 0;

	for (i = 0; i < CIPHERTEXT_LENGTH; i++)
		if (atoi16[ARCH_INDEX(ciphertext[i])] > 15)
			return 0;

	return 1;
}
static int valid(char *ciphertext, struct fmt_main *self)
{
	char *p, *q;
	if (strncmp(ciphertext, "$mysqlna$", 9))
		return 0;
	p = ciphertext + 9;
	q = strstr(ciphertext, "*");
	if(!q)
		return 0;
	if (q - p != CIPHERTEXT_LENGTH)
		return 0;
	while (atoi16[ARCH_INDEX(*p)] != 0x7F && p < q)
		p++;
	if (q - p != 0)
		return 0;
	if(strlen(p) < CIPHERTEXT_LENGTH)
		return 0;
	q = p + 1;
	while (atoi16[ARCH_INDEX(*q)] != 0x7F)
		q++;
	return !*q && q - p - 1 == CIPHERTEXT_LENGTH;
}
示例#15
0
static int valid(char *ciphertext, struct fmt_main *self)
{
	char *pos;

	/* Require lowercase hex digits (assume ASCII) */
	pos = ciphertext;
	if (strncmp(pos, "$LION$", 6))
		return 0;
	pos += 6;
	while (atoi16[ARCH_INDEX(*pos)] != 0x7F && (*pos <= '9' || *pos >= 'a'))
		pos++;
	return !*pos && pos - ciphertext == CIPHERTEXT_LENGTH+6;
}
示例#16
0
// Don't copy this code without realising it mimics bugs in the original code!
// We are actually missing the last 16 bits with this implementation.
static void *get_binary(char *ciphertext)
{
	static ARCH_WORD_32 outbuf[BINARY_SIZE/4];
	ARCH_WORD_32 value;
	char *pos;
	unsigned char *out = (unsigned char*)outbuf;
	int i;

	pos = strrchr(ciphertext, '$') + 1;

	for (i = 0; i < 20; i++) {
		TO_BINARY(i, i + 21, i + 42);
	}
	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);
	out[20] = value >> 16;
	out[41] = value >> 8;

	return (void *)out;
}
示例#17
0
文件: LM_fmt.c 项目: bhargavz/pac4mac
static int valid(char *ciphertext, struct fmt_main *self)
{
    char *pos;
    char lower[CIPHERTEXT_LENGTH - 16 + 1];

    for (pos = ciphertext; atoi16[ARCH_INDEX(*pos)] != 0x7F; pos++);
    if (!*pos && pos - ciphertext == CIPHERTEXT_LENGTH) {
        strcpy(lower, &ciphertext[16]);
        strlwr(lower);
        if (strcmp(lower, LM_EMPTY))
            return 2;
        else
            return 1;
    }

    if (strncmp(ciphertext, "$LM$", 4)) return 0;

    for (pos = &ciphertext[4]; atoi16[ARCH_INDEX(*pos)] != 0x7F; pos++);
    if (*pos || pos - ciphertext != 20) return 0;

    return 1;
}
static void *get_binary(char *ciphertext)
{
	static unsigned char out[FULL_BINARY_SIZE];
	char *p;
	int i;
	uint64_t *b;

	p = ciphertext;
	for (i = 0; i < sizeof(out); i++) {
		out[i] =
		    (atoi16[ARCH_INDEX(*p)] << 4) |
		    atoi16[ARCH_INDEX(p[1])];
		p += 2;
	}
	b = (uint64_t*)out;
	for (i = 0; i < 8; i++) {
		uint64_t t = SWAP64(b[i])-H[i];
		b[i] = SWAP64(t);
	}
	return out;

}
int sha512_common_valid_xsha(char *ciphertext, struct fmt_main *self)
{
	char *pos;

	/* Require lowercase hex digits (assume ASCII) */
	pos = ciphertext;
	if (strncmp(pos, XSHA512_FORMAT_TAG, XSHA512_TAG_LENGTH))
		return 0;
	pos += 6;
	while (atoi16[ARCH_INDEX(*pos)] != 0x7F && (*pos <= '9' || *pos >= 'a'))
		pos++;
	return !*pos && pos - ciphertext == XSHA512_CIPHERTEXT_LENGTH+6;
}
示例#20
0
static int valid(char *ciphertext, struct fmt_main *self)
{
	char *p, *q;

	p = ciphertext;
	if (!strncmp(p, FORMAT_TAG, TAG_LENGTH))
		p += 8;

	q = p;
	while (atoi16[ARCH_INDEX(*q)] != 0x7F)
		q++;
	return !*q && q - p == CIPHERTEXT_LENGTH;
}
示例#21
0
/* 
  We're essentially using three salts, but we're going to pack it into a single blob for now.

  Input:  $NETNTLMv2$USER_DOMAIN$_SERVER_CHALLENGE_$_NTLMv2_RESP_$_CLIENT_CHALLENGE_
    Username: <=20
    Domain: <=15
    Server Challenge: 8 bytes
    Client Challenge: ???
  Output: Identity \0 Challenge Size \0 Server Challenge + Client Challenge
*/
static void *netntlmv2_get_salt(char *ciphertext)
{
  static unsigned char binary_salt[SALT_SIZE_MAX];
  int i, identity_length, challenge_size;
  char *pos = NULL;

  memset(binary_salt, 0, SALT_SIZE_MAX);

  /* Calculate identity length; Set identity */
  for (pos = ciphertext + 11; strncmp(pos, "$", 1) != 0; pos++);
  identity_length = pos - (ciphertext + 11);
  strncpy((char *)binary_salt, ciphertext + 11, identity_length);

  /* Set server and client challenge size */

  /* Skip: $NETNTLMv2$USER_DOMAIN$ */
  ciphertext += 11 + identity_length + 1;

  /* SERVER_CHALLENGE$NTLMV2_RESPONSE$CLIENT_CHALLENGE --> SERVER_CHALLENGECLIENT_CHALLENGE */
  /* CIPHERTEXT == NTLMV2_RESPONSE (16 bytes / 32 characters) */
  challenge_size = (strlen(ciphertext) - CIPHERTEXT_LENGTH - 2) / 2;

  /* Set challenge size in response - 2 bytes - use NULL separators */
  memset(binary_salt + identity_length + 1, (challenge_size & 0xFF00) >> 8, 1); 
  memset(binary_salt + identity_length + 2, challenge_size & 0x00FF, 1); 
  
  /* Set server challenge - add NULL separator after challenge size */
  for (i = 0; i < SERVER_CHALL_LENGTH / 2; i++)
    binary_salt[identity_length + 1 + 2 + 1 + i] = (atoi16[ARCH_INDEX(ciphertext[i*2])] << 4) + atoi16[ARCH_INDEX(ciphertext[i*2+1])];
  
  /* Set client challenge */
  ciphertext += SERVER_CHALL_LENGTH + 1 + CIPHERTEXT_LENGTH + 1; 
  for (i = 0; i < strlen(ciphertext) / 2; ++i)
    binary_salt[identity_length + 1 + 2 + 1 + SERVER_CHALL_LENGTH / 2 + i] = (atoi16[ARCH_INDEX(ciphertext[i*2])] << 4) + atoi16[ARCH_INDEX(ciphertext[i*2+1])];

  /* Return a concatenation of the server and client challenges and the identity value */ 
  return (void*)binary_salt;
}
示例#22
0
static void *get_salt(char *ciphertext)
{
	char *decoded_data;
	int i;
	char *ctcopy = strdup(ciphertext);
	char *keeptr = ctcopy;
	char *p;
	static struct custom_salt cs;
	PKCS12 *p12 = NULL;
	BIO *bp;
	ctcopy += 6;	/* skip over "$pfx$*" */
	p = strtok(ctcopy, "*");
	cs.len = atoi(p);
	decoded_data = (char *) malloc(cs.len + 1);
	p = strtok(NULL, "*");
	for (i = 0; i < cs.len; i++)
		decoded_data[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16 +
    			atoi16[ARCH_INDEX(p[i * 2 + 1])];
	decoded_data[cs.len] = 0;
	/* load decoded data into OpenSSL structures */
	bp = BIO_new(BIO_s_mem());
	if (!bp) {
		fprintf(stderr, "OpenSSL BIO allocation failure\n");
		exit(-2);
	}
	BIO_write(bp, decoded_data, cs.len);
	if(!(p12 = d2i_PKCS12_bio(bp, NULL))) {
		perror("Unable to create PKCS12 object from bio\n");
		exit(-3);
	}
	/* save custom_salt information */
	memset(&cs, 0, sizeof(cs));
	memcpy(&cs.pfx, p12, sizeof(PKCS12));
	BIO_free(bp);
	MEM_FREE(decoded_data);
	MEM_FREE(keeptr);
	return (void *) &cs;
}
示例#23
0
static void* get_salt(char *ciphertext)
{
	static struct custom_salt cs;
	char *ctcopy = strdup(ciphertext);
	char *keeptr = ctcopy;
	int i;
	char *p;

	ctcopy += 18;
	p = strtok(ctcopy, "$"); /* iterations */
	cs.num_iterations = atoi(p);
	p = strtok(NULL, "$");   /* salt */
	for (i = 0; i < OPENBSD_SOFTRAID_SALTLENGTH ; i++)
		cs.salt[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
			+ atoi16[ARCH_INDEX(p[i * 2 + 1])];
	p = strtok(NULL, "$");   /* masked keys */
	for (i = 0; i < OPENBSD_SOFTRAID_KEYLENGTH * OPENBSD_SOFTRAID_KEYS; i++)
		cs.masked_keys[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
			+ atoi16[ARCH_INDEX(p[i * 2 + 1])];

	MEM_FREE(keeptr);
	return (void *)&cs;
}
示例#24
0
static int valid(char *ciphertext,struct fmt_main *pFmt)
{
	int rounds;
	char *pos;

	if (strncmp(ciphertext, "$2a$", 4) &&
	    strncmp(ciphertext, "$2x$", 4)) return 0;

	if (ciphertext[4] < '0' || ciphertext[4] > '9') return 0;
	if (ciphertext[5] < '0' || ciphertext[5] > '9') return 0;
	rounds = atoi(ciphertext + 4);
	if (rounds < 4 || rounds > 31) return 0;

	if (ciphertext[6] != '$') return 0;

	for (pos = &ciphertext[7]; atoi64[ARCH_INDEX(*pos)] != 0x7F; pos++);
	if (*pos || pos - ciphertext != CIPHERTEXT_LENGTH) return 0;

	if (opencl_BF_atoi64[ARCH_INDEX(*(pos - 1))] & 3) return 0;
	if (opencl_BF_atoi64[ARCH_INDEX(ciphertext[28])] & 0xF) return 0;

	return 1;
}
示例#25
0
static void *get_binary(char *ciphertext)
{
	static ARCH_WORD out[6];
	char base64[14];
	int known_long;
	int index;
	unsigned int value;

	out[0] = out[1] = 0;
	strcpy(base64, AFS_SALT);
	known_long = 0;

	for (index = 0; index < 16; index += 2) {
		value = atoi16[ARCH_INDEX(ciphertext[index + 4])] << 4;
		value |= atoi16[ARCH_INDEX(ciphertext[index + 5])];

		out[index >> 3] |= (value | 1) << ((index << 2) & 0x18);

		if (atoi64[value >>= 1] == 0x7F)
			known_long = 1;
		else
			base64[(index >> 1) + 2] = value;
	}
示例#26
0
文件: DES_fmt.c 项目: mimaun/Rose
static int valid(char *ciphertext, struct fmt_main *self)
{
	char *pos;

	if (!ciphertext[0] || !ciphertext[1]) return 0;

	for (pos = &ciphertext[2]; atoi64[ARCH_INDEX(*pos)] != 0x7F; pos++);
	if (*pos && *pos != ',') return 0;

	if (atoi64[ARCH_INDEX(*(pos - 1))] & 3) return 0;

	switch (pos - ciphertext) {
	case CIPHERTEXT_LENGTH_1:
		return 1;

	case CIPHERTEXT_LENGTH_2:
		if (atoi64[ARCH_INDEX(ciphertext[12])] & 3) return 0;
		return 2;

	default:
		return 0;
	}
}
示例#27
0
/* The mixing function: perturbs the first three rows of the matrix*/
void MAYBE_INLINE lotus_mix (unsigned char *m1, unsigned char *m2)
{
  int i, j;
  unsigned char p1, p2;
  unsigned char *t1, *t2;

  p1 = p2 = 0x00;

  for (i = 18; i > 0; i--)
    {
      t1 = m1;
      t2 = m2;
      for (j = 48; j > 0; )
	{
	  p1 = t1[0] ^= lotus_magic_table[ARCH_INDEX((j + p1) & 0xff)];
	  p2 = t2[0] ^= lotus_magic_table[ARCH_INDEX((j-- + p2) & 0xff)];
	  p1 = t1[1] ^= lotus_magic_table[ARCH_INDEX((j + p1) & 0xff)];
	  p2 = t2[1] ^= lotus_magic_table[ARCH_INDEX((j-- + p2) & 0xff)];
	  t1 += 2;
	  t2 += 2;
	}
    }
}
示例#28
0
static int valid(char *ciphertext, struct fmt_main *self)
{
	uint32_t i, count_log2;

	int prefix=0;
	if (strlen(ciphertext) != CIPHERTEXT_LENGTH)
		return 0;
	if (strncmp(ciphertext, "$P$", 3) == 0)
		prefix=1;
	if (strncmp(ciphertext, "$H$", 3) == 0)
		prefix=1;
	if(prefix==0) return 0;

	for (i = 3; i < CIPHERTEXT_LENGTH; i++)
		if (atoi64[ARCH_INDEX(ciphertext[i])] == 0x7F)
			return 0;

	count_log2 = atoi64[ARCH_INDEX(ciphertext[3])];
	if (count_log2 < 7 || count_log2 > 31)
		return 0;

	return 1;
};
示例#29
0
static void *get_binary_256(char *ciphertext)
{
    static union {
        unsigned char c[32];
        ARCH_WORD dummy;
    } buf;
    unsigned char *out = buf.c;
    char *p;
    int i;

    if (!strncmp(ciphertext, FORMAT_TAG, TAG_LENGTH))
        p = strrchr(ciphertext, '$') + 1;
    else
        p = ciphertext;
    for (i = 0; i < 32; i++) {
        out[i] =
            (atoi16[ARCH_INDEX(*p)] << 4) |
            atoi16[ARCH_INDEX(p[1])];
        p += 2;
    }

    return out;
}
示例#30
0
static void ldr_init_issep(void)
{
	char *pos;

	if (issep_initialized) return;

	memset(issep_map, 0, sizeof(issep_map));

	memset(issep_map, 1, 33);
	for (pos = issep; *pos; pos++)
		issep_map[ARCH_INDEX(*pos)] = 1;

	issep_initialized = 1;
}