Esempio n. 1
0
static void wpapsk_set_key(char *key, int index) {
	int i;
	int len;
	
	len = strlen(key);
	if(len>PLAINTEXT_LENGTH)
		len = PLAINTEXT_LENGTH;

#ifdef MMX_COEF
	if(index==0)
	{
		memset(ipad, 0x36, 64*MMX_COEF);
		memset(opad, 0x5C, 64*MMX_COEF);
	}
	
	for(i=0;i<len;i++)
	{
		ipad[GETPOS(i, index)] = 0x36 ^ key[i];
		opad[GETPOS(i, index)] = 0x5C ^ key[i];
	}

	//saved_key[GETPOS(i, index)] = 0x80;
#else
	memset(ipad, 0x36, 64);
	memset(opad, 0x5C, 64);
	for(i=0;i<len;i++)
	{
		ipad[i] ^= key[i];
		opad[i] ^= key[i];
	}
#endif
}
static void set_key(char *key, int index)
{
#ifdef MMX_COEF
	int len;
	int i;

	if(index==0)
	{
		memset(saved_key, 0, sizeof(saved_key));
	}
	len = strlen(key);
	if(len>PLAINTEXT_LENGTH)
		len = PLAINTEXT_LENGTH;

	length[index] = len;

	for(i=0;i<len;i++)
		saved_key[GETPOS(i, index)] = key[i];

	saved_key[GETPOS( (i+SALT_SIZE) , index)] = 0x80;
	((unsigned int *)saved_key)[15*MMX_COEF+index] = (len+SALT_SIZE)<<3;
#else
	strnzcpy(saved_key, key, PLAINTEXT_LENGTH+1);
#endif
}
Esempio n. 3
0
static void set_key(char *key, int index)
{
#ifdef MMX_COEF
	int len;
	int i;

	if(index==0)
	{
		total_len = 0;
		memset(saved_key, 0, sizeof(saved_key));
		memset(length, 0, sizeof(length));
	}
	len = strlen(key);
	if(len>PLAINTEXT_LENGTH)
		len = PLAINTEXT_LENGTH;

	length[index] = len;

	total_len += (len + SALT_SIZE) << ( ( (32/MMX_COEF) * index ) );
	for(i=0;i<len;i++)
		saved_key[GETPOS(i, index)] = key[i];

	saved_key[GETPOS( (i+SALT_SIZE) , index)] = 0x80;
#else
	strnzcpy(saved_key, key, PLAINTEXT_LENGTH+1);
#endif
}
static void hmacmd5_init(void)
{
#ifdef MMX_COEF
	memset(crypt_key, 0, sizeof(crypt_key));
	crypt_key[GETPOS(BINARY_SIZE,0)] = 0x80;
	crypt_key[GETPOS(BINARY_SIZE,1)] = 0x80;
#if (MMX_COEF == 4)
	crypt_key[GETPOS(BINARY_SIZE,2)] = 0x80;
	crypt_key[GETPOS(BINARY_SIZE,3)] = 0x80;
#endif
#endif
}
static void set_key(char *key, int index)
{
	int len;

#ifdef SIMD_COEF_64
	ARCH_WORD_64 *ipadp = (ARCH_WORD_64*)&ipad[GETPOS(7, index)];
	ARCH_WORD_64 *opadp = (ARCH_WORD_64*)&opad[GETPOS(7, index)];
	const ARCH_WORD_64 *keyp = (ARCH_WORD_64*)key;
	ARCH_WORD_64 temp;

	len = strlen(key);
	memcpy(saved_plain[index], key, len);
	saved_plain[index][len] = 0;

#if PAD_SIZE < PLAINTEXT_LENGTH
	if (len > PAD_SIZE) {
		unsigned char k0[BINARY_SIZE];
		SHA512_CTX ctx;
		int i;

		SHA384_Init(&ctx);
		SHA384_Update(&ctx, key, len);
		SHA384_Final(k0, &ctx);

		keyp = (ARCH_WORD_64*)k0;
		for(i = 0; i < BINARY_SIZE / 8; i++, ipadp += SIMD_COEF_64, opadp += SIMD_COEF_64)
		{
			temp = JOHNSWAP64(*keyp++);
			*ipadp ^= temp;
			*opadp ^= temp;
		}
	}
	else
#endif
	while(((temp = JOHNSWAP64(*keyp++)) & 0xff00000000000000)) {
		if (!(temp & 0x00ff000000000000) || !(temp & 0x0000ff0000000000))
		{
			((unsigned short*)ipadp)[3] ^=
				(unsigned short)(temp >> 48);
			((unsigned short*)opadp)[3] ^=
				(unsigned short)(temp >> 48);
			break;
		}
		if (!(temp & 0x00ff00000000) || !(temp & 0x0000ff000000))
		{
			((ARCH_WORD_32*)ipadp)[1] ^=
				(ARCH_WORD_32)(temp >> 32);
			((ARCH_WORD_32*)opadp)[1] ^=
				(ARCH_WORD_32)(temp >> 32);
			break;
		}
static inline void set_onesalt(int index)
{
	unsigned int i, idx=index%NBKEYS;
	unsigned char *sk = (unsigned char*)&saved_key[index/NBKEYS];

	for(i=0;i<saved_salt->len;++i)
		sk[GETPOS(i+saved_len[index], idx)] = saved_salt->data.c[i];
	sk[GETPOS(i+saved_len[index], idx)] = 0x80;

	while (++i <= last_salt_size)
		sk[GETPOS(i+saved_len[index], idx)] = 0;

	((unsigned int*)sk)[15*SIMD_COEF_32 + (index&(SIMD_COEF_32-1)) + idx/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32] = (saved_salt->len + saved_len[index])<<3;
}
static void hmacmd5_set_salt(void *salt) 
{
#ifdef MMX_COEF
	total_len = 0;
	while(((unsigned char *)salt)[total_len])
	{
		cursalt[GETPOS(total_len, 0)] = ((unsigned char *)salt)[total_len];
		cursalt[GETPOS(total_len, 1)] = ((unsigned char *)salt)[total_len];
#if (MMX_COEF == 4)
		cursalt[GETPOS(total_len, 2)] = ((unsigned char *)salt)[total_len];
		cursalt[GETPOS(total_len, 3)] = ((unsigned char *)salt)[total_len];
#endif
		total_len ++;
	}
	cursalt[GETPOS(total_len, 0)] = 0x80;
	cursalt[GETPOS(total_len, 1)] = 0x80;
#if (MMX_COEF == 4)
	cursalt[GETPOS(total_len, 2)] = 0x80;
	cursalt[GETPOS(total_len, 3)] = 0x80;
#endif
	//total_len += 64;
	//total_len += (total_len<<16);
#else
	memcpy(cursalt, salt, SALT_SIZE);
#endif
}
Esempio n. 8
0
static void set_key(char *key, int index)
{
    int len;

#ifdef SIMD_COEF_32
    ARCH_WORD_32 *ipadp = (ARCH_WORD_32*)&ipad[GETPOS(3, index)];
    ARCH_WORD_32 *opadp = (ARCH_WORD_32*)&opad[GETPOS(3, index)];
    const ARCH_WORD_32 *keyp = (ARCH_WORD_32*)key;
    unsigned int temp;

    len = strlen(key);
    memcpy(saved_plain[index], key, len);
    saved_plain[index][len] = 0;

    if (len > PAD_SIZE) {
        unsigned char k0[BINARY_SIZE];
        SHA256_CTX ctx;
        int i;

        SHA256_Init(&ctx);
        SHA256_Update(&ctx, key, len);
        SHA256_Final(k0, &ctx);

        keyp = (unsigned int*)k0;
        for(i = 0; i < BINARY_SIZE / 4; i++, ipadp += SIMD_COEF_32, opadp += SIMD_COEF_32)
        {
            temp = JOHNSWAP(*keyp++);
            *ipadp ^= temp;
            *opadp ^= temp;
        }
    }
    else
        while(((temp = JOHNSWAP(*keyp++)) & 0xff000000)) {
            if (!(temp & 0x00ff0000) || !(temp & 0x0000ff00))
            {
                ((unsigned short*)ipadp)[1] ^=
                    (unsigned short)(temp >> 16);
                ((unsigned short*)opadp)[1] ^=
                    (unsigned short)(temp >> 16);
                break;
            }
            *ipadp ^= temp;
            *opadp ^= temp;
            if (!(temp & 0x000000ff))
                break;
            ipadp += SIMD_COEF_32;
            opadp += SIMD_COEF_32;
        }
static void init(struct fmt_main *self)
{
#ifdef SIMD_COEF_64
	int i;
#endif
#ifdef _OPENMP
	int omp_t = omp_get_max_threads();
	self->params.min_keys_per_crypt *= omp_t;
	omp_t *= OMP_SCALE;
	self->params.max_keys_per_crypt *= omp_t;
#endif
#ifdef SIMD_COEF_64
	bufsize = sizeof(ARCH_WORD_64) * self->params.max_keys_per_crypt * SHA_BUF_SIZ;
	crypt_key = mem_calloc_tiny(bufsize, MEM_ALIGN_SIMD);
	ipad = mem_calloc_tiny(bufsize, MEM_ALIGN_SIMD);
	opad = mem_calloc_tiny(bufsize, MEM_ALIGN_SIMD);
	prep_ipad = mem_calloc_tiny(self->params.max_keys_per_crypt * BINARY_SIZE_512, MEM_ALIGN_SIMD);
	prep_opad = mem_calloc_tiny(self->params.max_keys_per_crypt * BINARY_SIZE_512, MEM_ALIGN_SIMD);
	for (i = 0; i < self->params.max_keys_per_crypt; ++i) {
		crypt_key[GETPOS(BINARY_SIZE, i)] = 0x80;
		((ARCH_WORD_64*)crypt_key)[15 * SIMD_COEF_64 + (i & (SIMD_COEF_64-1)) + (i/SIMD_COEF_64) * SHA_BUF_SIZ * SIMD_COEF_64] = (BINARY_SIZE + PAD_SIZE) << 3;
	}
	clear_keys();
#else
	crypt_key = mem_calloc_tiny(sizeof(*crypt_key) * self->params.max_keys_per_crypt, MEM_ALIGN_WORD);
	ipad = mem_calloc_tiny(sizeof(*ipad) * self->params.max_keys_per_crypt, MEM_ALIGN_WORD);
	opad = mem_calloc_tiny(sizeof(*opad) * self->params.max_keys_per_crypt, MEM_ALIGN_WORD);
	ipad_ctx = mem_calloc_tiny(sizeof(*ipad_ctx) * self->params.max_keys_per_crypt, 8);
	opad_ctx = mem_calloc_tiny(sizeof(*opad_ctx) * self->params.max_keys_per_crypt, 8);
#endif
	saved_plain = mem_calloc_tiny(sizeof(*saved_plain) * self->params.max_keys_per_crypt, MEM_ALIGN_WORD);
}
Esempio n. 10
0
static char *get_key(int index)
{
#ifdef MMX_COEF
	static char out[PLAINTEXT_LENGTH + 1];
	unsigned int i,len;

	len = ((ARCH_WORD_32*)&saved_key[GETPOS(0, index)])[14*MMX_COEF] >> 3;

	for(i=0;i<len;i++)
		out[i] = saved_key[GETPOS(i, index)];
	out[i] = 0;
	return (char*)out;
#else
	saved_key[saved_key_length] = 0;
	return saved_key;
#endif
}
Esempio n. 11
0
static void wpapsk_init(void)
{
#ifdef MMX_COEF
	memset(crypt_key, 0, 64*MMX_COEF);
	memset(cursalt, 0, 64*MMX_COEF);
	crypt_key[GETPOS(BINARY_SIZE,0)] = 0x80;
	crypt_key[GETPOS(BINARY_SIZE,1)] = 0x80;
#if (MMX_COEF == 4)
	crypt_key[GETPOS(BINARY_SIZE,2)] = 0x80;
	crypt_key[GETPOS(BINARY_SIZE,3)] = 0x80;
#endif
#else
	memset(nipad, 0x36, 64);
	memset(nopad, 0x5C, 64);
	memset(EAPOL, 0, sizeof(EAPOL));
	strcpy(nDATA, "Pairwise key expansion");
#endif
}
Esempio n. 12
0
void dump_stuff_mmx_noeol(void * buf, unsigned int size, unsigned int index)
{
	unsigned int i;
	for (i = 0; i < size; i++)
	{
		printf("%.2x", ((unsigned char *) buf)[GETPOS(i, index)]);
		if ((i % 4) == 3) printf(" ");
	}
}
Esempio n. 13
0
unsigned long strcrlflen (STRING *s)
{
  unsigned long pos = GETPOS (s);
  unsigned long i = SIZE (s);
  unsigned long j = i;
  while (j--) if ((SNX (s) == '\015') && ((CHR (s) != '\012') || !j)) i++;
  SETPOS (s,pos);		/* restore old position */
  return i;
}
Esempio n. 14
0
static char *wpapsk_get_key(int index) {
	unsigned int i;
	for(i=0;i<PLAINTEXT_LENGTH;i++)
#ifdef MMX_COEF
		out[i] = ipad[ GETPOS(i, index) ] ^ 0x36;
#else
		out[i] = ipad[ i ] ^ 0x36;
#endif
	return out;
}
static void set_key(char *key, int index)
{
    int i;
    int length = strlen(key);

    for (i = 0; i < length; i++)
        ((char*)inbuffer)[GETPOS(i, index)] = key[i];

    new_keys = 1;
}
Esempio n. 16
0
static char *get_key(int index) {
	unsigned int i,s;
	static char out[PLAINTEXT_LENGTH+1];
	unsigned char *wucp = (unsigned char*)saved_key;

	s = ((ARCH_WORD_32 *)saved_key)[15*SIMD_COEF_32 + (index&(SIMD_COEF_32-1)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32] >> 3;
	for(i=0;i<s;i++)
		out[i] = wucp[ GETPOS(i, index) ];
	out[i] = 0;
	return (char*) out;
}
Esempio n. 17
0
void dump_stuff_mmx(unsigned char * buf, unsigned int size, unsigned int index)
{
	int i;
	for(i=0;i<size;i++)
	{
		if(!(i%4))
			printf(" ");
		printf("%.2x", buf[GETPOS(i, index)]);
	}
	printf("\n");
}
static char* get_key(int index)
{
    static char ret[PLAINTEXT_LENGTH + 1];
    int i = 0;

    while (i < PLAINTEXT_LENGTH &&
            (ret[i] = ((char*)inbuffer)[GETPOS(i, index)]))
        i++;
    ret[i] = 0;

    return ret;
}
Esempio n. 19
0
static void set_key(char *_key, int index)
{
#ifdef MMX_COEF
	const ARCH_WORD_32 *key = (ARCH_WORD_32*)_key;
	ARCH_WORD_32 *keybuffer = (ARCH_WORD_32*)&saved_key[GETPOS(0, index)];
	ARCH_WORD_32 *keybuf_word = keybuffer;
	unsigned int len;
	ARCH_WORD_32 temp;

	len = 0;
	while((temp = *key++) & 0xff) {
		if (!(temp & 0xff00))
		{
			*keybuf_word = (temp & 0xff) | (0x80 << 8);
			len++;
			goto key_cleaning;
		}
		if (!(temp & 0xff0000))
		{
			*keybuf_word = (temp & 0xffff) | (0x80 << 16);
			len+=2;
			goto key_cleaning;
		}
		if (!(temp & 0xff000000))
		{
			*keybuf_word = temp | (0x80 << 24);
			len+=3;
			goto key_cleaning;
		}
		*keybuf_word = temp;
		len += 4;
		keybuf_word += MMX_COEF;
	}
	*keybuf_word = 0x80;

key_cleaning:
	keybuf_word += MMX_COEF;
	while(*keybuf_word) {
		*keybuf_word = 0;
		keybuf_word += MMX_COEF;
	}
	/*
	 * This works for MMX, SSE2 and SSE2i.  Note, for 32 bit MMX/SSE2, we now use
	 * mdfivemmx_nosizeupdate and not mdfivemmx function. Setting the size here,
	 * and calling the 'nosizeupdate' function is about 5% faster, AND it makes the
	 * code much more similar between SSE2i and older 32 bit SSE2
	 */
	keybuffer[14*MMX_COEF] = len << 3;
#else
	saved_key_length = strlen(_key);
	memcpy(saved_key, _key, saved_key_length);
#endif
}
Esempio n. 20
0
static char *get_key(int index) {
#ifdef SIMD_COEF_32
	unsigned int i,s;

	s = saved_len[index];
	for(i=0;i<s;i++)
		out[i] = ((char*)saved_key)[GETPOS(i, index)];
	out[i] = 0;
	return (char *) out;
#else
	return saved_key[index];
#endif
}
Esempio n. 21
0
static void init(struct fmt_main *self)
{
#ifdef _OPENMP
	int omp_t = omp_get_max_threads();
	self->params.min_keys_per_crypt *= omp_t;
	self->params.max_keys_per_crypt *= omp_t;
#endif

	assert(sizeof(hccap_t) == HCCAP_SIZE);

	inbuffer = mem_alloc(sizeof(*inbuffer) *
	                     self->params.max_keys_per_crypt);
	outbuffer = mem_alloc(sizeof(*outbuffer) *
	                      self->params.max_keys_per_crypt);
	mic = mem_alloc(sizeof(*mic) *
	                self->params.max_keys_per_crypt);

#if defined (SIMD_COEF_32)
	sse_hash1 = mem_calloc_align(self->params.max_keys_per_crypt,
	                             SHA_BUF_SIZ * 4 * sizeof(*sse_hash1),
	                             MEM_ALIGN_SIMD);
	sse_crypt1 = mem_calloc_align(self->params.max_keys_per_crypt,
	                              20 * sizeof(*sse_crypt1), MEM_ALIGN_SIMD);
	sse_crypt2 = mem_calloc_align(self->params.max_keys_per_crypt,
	                              20 * sizeof(*sse_crypt2), MEM_ALIGN_SIMD);
	sse_crypt = mem_calloc_align(self->params.max_keys_per_crypt,
	                             20 * sizeof(*sse_crypt), MEM_ALIGN_SIMD);
	{
		int index;
		for (index = 0; index < self->params.max_keys_per_crypt; ++index) {
			// set the length of all hash1 SSE buffer to 64+20 * 8 bits. The 64 is for the ipad/opad,
			// the 20 is for the length of the SHA1 buffer that also gets into each crypt.
			// Works for SSE2i and SSE2
			((unsigned int *)sse_hash1)[15*SIMD_COEF_32 + (index&(SIMD_COEF_32-1)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32] = (84<<3); // all encrypts are 64+20 bytes.
			sse_hash1[GETPOS(20,index)] = 0x80;
		}
	}
	// From this point on, we ONLY touch the first 20 bytes (* SIMD_COEF_32) of each buffer 'block'.  If !SHA_PARA', then only the first
	// block is written to after this, if there are more that one SHA_PARA, then the start of each para block will be updated inside the inner loop.
#endif

/*
 * Zeroize the lengths in case crypt_all() is called with some keys still
 * not set.  This may happen during self-tests.
 */
	{
		int i;
		for (i = 0; i < self->params.max_keys_per_crypt; i++)
			inbuffer[i].length = 0;
	}
}
Esempio n. 22
0
static char *get_key(int index) {
#ifdef SIMD_COEF_32
	static char out[PLAINTEXT_LENGTH+1];
	unsigned int i, s;

	s = ((unsigned int *)saved_key)[15*SIMD_COEF_32 + (index&(SIMD_COEF_32-1)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32] >> 3;
	for (i = 0; i < s; i++)
		out[i] = saved_key[ GETPOS(i, index) ];
	out[i] = 0;
	return out;
#else
	return saved_key;
#endif
}
Esempio n. 23
0
static char *get_key(int index)
{
#ifdef MMX_COEF
	unsigned int i,s;

	s = length[index];
	for(i=0;i<s;i++)
		out[i] = saved_key[ GETPOS(i, index) ];
	out[i] = 0;
	return (char*)out;
#else
  return saved_key;
#endif
}
Esempio n. 24
0
static void init(struct fmt_main *self)
{
#ifdef SIMD_COEF_32
	int i;

	/* input strings have to be terminated by 0x80. The input strings in
	 * interm_key have a static length (20 bytes) so we can set them just
	 * once. If intrinsics, we do the same for the length byte.
	 */
	for (i = 0; i < NBKEYS; i++) {
		interm_key[GETPOS(20,i)] = 0x80;
		((unsigned int *)interm_key)[15*SIMD_COEF_32 + (i&(SIMD_COEF_32-1)) + i/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32] = 20 << 3;
	}
#endif
}
Esempio n. 25
0
static void set_key(char *key, int index)
{
#ifdef SIMD_COEF_32
	const ARCH_WORD_32 *wkey = (ARCH_WORD_32*)key;
	ARCH_WORD_32 *keybuf_word = (ARCH_WORD_32*)&saved_key[GETPOS(3, index)];
	unsigned int len;
	ARCH_WORD_32 temp;

	len = 0;
	while((temp = *wkey++) & 0xff) {
		if (!(temp & 0xff00))
		{
			*keybuf_word = JOHNSWAP((temp & 0xff) | (0x80 << 8));
			len++;
			goto key_cleaning;
		}
		if (!(temp & 0xff0000))
		{
			*keybuf_word = JOHNSWAP((temp & 0xffff) | (0x80 << 16));
			len+=2;
			goto key_cleaning;
		}
		if (!(temp & 0xff000000))
		{
			*keybuf_word = JOHNSWAP(temp | (0x80 << 24));
			len+=3;
			goto key_cleaning;
		}
		*keybuf_word = JOHNSWAP(temp);
		len += 4;
		keybuf_word += SIMD_COEF_32;
	}
	*keybuf_word = 0x80000000;

key_cleaning:
	keybuf_word += SIMD_COEF_32;
	while(*keybuf_word) {
		*keybuf_word = 0;
		keybuf_word += SIMD_COEF_32;
	}
	((unsigned int *)saved_key)[15*SIMD_COEF_32 + (index&(SIMD_COEF_32-1)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32] = len << 3;
#else
	strnzcpy(saved_key, key, PLAINTEXT_LENGTH + 1);
#endif
}
Esempio n. 26
0
static char *get_key(int index)
{
#ifdef SIMD_COEF_64
	unsigned i;
	ARCH_WORD_64 s;
	static char out[PLAINTEXT_LENGTH + 1];
	unsigned char *wucp = (unsigned char*)saved_key;

	s = ((ARCH_WORD_64*)saved_key)[15*SIMD_COEF_64 + (index&(SIMD_COEF_64-1)) + index/SIMD_COEF_64*SHA_BUF_SIZ*SIMD_COEF_64] >> 3;
	for(i = 0; i < (unsigned)s; i++)
		out[i] = wucp[ GETPOS(i, index) ];
	out[i] = 0;
	return (char*) out;
#else
	saved_key[index][saved_len[index]] = 0;
	return saved_key[index];
#endif
}
Esempio n. 27
0
static void crypt_all(int count)
{
#ifdef MMX_COEF
	int i,idx;

	for(idx=0;idx<MAX_KEYS_PER_CRYPT;idx++)
	{
		for(i=0;i<SALT_SIZE;i++)
			saved_key[GETPOS((i+length[idx]),idx)] = ((unsigned char *)saved_salt)[i];
	}
	shammx((unsigned char*)crypt_key, (unsigned char*)saved_key);
#else
	static SHA_CTX ctx;
	SHA1_Init(&ctx);
	SHA1_Update(&ctx, (unsigned char*)saved_key, strlen(saved_key));
	SHA1_Update(&ctx, (unsigned char*)saved_salt, SALT_SIZE);
	SHA1_Final((unsigned char*)crypt_key, &ctx);
#endif
}
Esempio n. 28
0
unsigned long unix_crlflen (STRING *s)
{
  unsigned long pos = GETPOS (s);
  unsigned long i = SIZE (s);
  unsigned long j = i;
  while (j--) switch (SNX (s)) {/* search for newlines */
  case '\015':			/* unlikely carriage return */
    if (j && (CHR (s) == '\012')) {
      SNX (s);			/* eat the line feed */
      j--;
    }
    break;
  case '\012':			/* line feed? */
    i++;
  default:			/* ordinary chararacter */
    break;
  }
  SETPOS (s,pos);		/* restore old position */
  return i;
}
Esempio n. 29
0
static void init(struct fmt_main *self)
{
#ifdef SIMD_COEF_32
	int i;
#endif
#ifdef _OPENMP
	int omp_t = omp_get_num_threads();

	self->params.min_keys_per_crypt *= omp_t;
	omp_t *= OMP_SCALE;
	self->params.max_keys_per_crypt *= omp_t;
#endif
#ifdef SIMD_COEF_32
	bufsize = sizeof(*opad) * self->params.max_keys_per_crypt * SHA_BUF_SIZ * 4;
	crypt_key = mem_calloc_align(1, bufsize, MEM_ALIGN_SIMD);
	ipad = mem_calloc_align(1, bufsize, MEM_ALIGN_SIMD);
	opad = mem_calloc_align(1, bufsize, MEM_ALIGN_SIMD);
	prep_ipad = mem_calloc_align(self->params.max_keys_per_crypt *
	                             BINARY_SIZE,
	                             sizeof(*prep_ipad), MEM_ALIGN_SIMD);
	prep_opad = mem_calloc_align(self->params.max_keys_per_crypt *
	                             BINARY_SIZE,
	                             sizeof(*prep_opad), MEM_ALIGN_SIMD);
	for (i = 0; i < self->params.max_keys_per_crypt; ++i) {
		crypt_key[GETPOS(BINARY_SIZE, i)] = 0x80;
		((unsigned int*)crypt_key)[15 * SIMD_COEF_32 + (i&(SIMD_COEF_32-1)) + i/SIMD_COEF_32 * SHA_BUF_SIZ * SIMD_COEF_32] = (BINARY_SIZE + 64) << 3;
	}
	clear_keys();
#else
	crypt_key = mem_calloc(self->params.max_keys_per_crypt,
	                       sizeof(*crypt_key));
	ipad = mem_calloc(self->params.max_keys_per_crypt, sizeof(*ipad));
	opad = mem_calloc(self->params.max_keys_per_crypt, sizeof(*opad));
	ipad_ctx = mem_calloc(self->params.max_keys_per_crypt,
	                      sizeof(*ipad_ctx));
	opad_ctx = mem_calloc(self->params.max_keys_per_crypt,
	                      sizeof(*opad_ctx));
#endif
	saved_plain = mem_calloc(self->params.max_keys_per_crypt,
	                         sizeof(*saved_plain));
}
Esempio n. 30
0
static void crypt_all(int count)
{
#ifdef MMX_COEF
	int i,idx;

	for(idx=0;idx<MAX_KEYS_PER_CRYPT;idx++)
		for(i=0;i<SALT_SIZE;i++)
		{
			saved_key[GETPOS(i+length[idx],idx)] = ((unsigned char *)saved_salt)[i];
		}

	memcpy(buffer, saved_key, (PLAINTEXT_LENGTH+SALT_SIZE+4)*MMX_COEF);
	shammx((unsigned char *) crypt_key, buffer, total_len);
#else
	static SHA_CTX ctx;
	SHA1_Init(&ctx);
	SHA1_Update(&ctx, (unsigned char *) saved_key, strlen(saved_key));
	SHA1_Update(&ctx, (unsigned char *) saved_salt, SALT_SIZE);
	SHA1_Final((unsigned char *) crypt_key, &ctx);
#endif
}