Пример #1
0
static void *get_salt(char *ciphertext)
{
	char *ctcopy = strdup(ciphertext);
	char *keeptr = ctcopy;
	char *p;
	int i;
	static pwsafe_salt *salt_struct;

	if (!salt_struct)
		salt_struct = mem_calloc_tiny(sizeof(pwsafe_salt),
		                              MEM_ALIGN_WORD);
	ctcopy += 9;		/* skip over "$pwsafe$*" */
	p = strtok(ctcopy, "*");
	salt_struct->version = atoi(p);
	p = strtok(NULL, "*");
	for (i = 0; i < 32; i++)
		salt_struct->salt[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
		    + atoi16[ARCH_INDEX(p[i * 2 + 1])];
	p = strtok(NULL, "*");
	salt_struct->iterations = (unsigned int) atoi(p);
	p = strtok(NULL, "*");
	for (i = 0; i < 32; i++)
		salt_struct->hash[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16
		    + atoi16[ARCH_INDEX(p[i * 2 + 1])];

	MEM_FREE(keeptr);
        alter_endianity(salt_struct->hash, 32);
	return (void *) salt_struct;
}
Пример #2
0
static char *source(char *source, void *binary)
{
    static char Buf[CIPHERTEXT_LENGTH + 1];
    unsigned char realcipher[BINARY_SIZE];
    unsigned char *cpi;
    char *cpo;
    int i;

    memcpy(realcipher, binary, BINARY_SIZE);
#ifdef SIMD_COEF_32
    alter_endianity(realcipher, BINARY_SIZE);
#endif
    strcpy(Buf, FORMAT_TAG);
    cpo = &Buf[TAG_LENGTH];

    cpi = realcipher;

    for (i = 0; i < BINARY_SIZE; ++i) {
        *cpo++ = itoa16[(*cpi)>>4];
        *cpo++ = itoa16[*cpi&0xF];
        ++cpi;
    }
    *cpo = 0;
    return Buf;
}
Пример #3
0
static int crypt_all(int *pcount, struct db_salt *salt)
{
	int count = *pcount;
	int index = 0;
#ifdef _OPENMP
#pragma omp parallel for
	for (index = 0; index < count; index += MAX_KEYS_PER_CRYPT)
#endif
	{
		AES_KEY akey;
		unsigned char mask_key[MAX_KEYS_PER_CRYPT][32];
		unsigned char unmasked_keys[OPENBSD_SOFTRAID_KEYLENGTH * OPENBSD_SOFTRAID_KEYS];
		unsigned char hashed_mask_key[20];
		int i, j;

		/* derive masking key from password */
#ifdef SSE_GROUP_SZ_SHA1
    int lens[SSE_GROUP_SZ_SHA1];
    unsigned char *pin[SSE_GROUP_SZ_SHA1], *pout[SSE_GROUP_SZ_SHA1];
    for (i = 0; i < SSE_GROUP_SZ_SHA1; ++i) {
      lens[i] = strlen(key_buffer[index+i]);
      pin[i] = (unsigned char*)key_buffer[index+i];
      pout[i] = mask_key[i];
    }
    pbkdf2_sha1_sse((const unsigned char **)pin, lens,
        cur_salt->salt, OPENBSD_SOFTRAID_SALTLENGTH,
        cur_salt->num_iterations, (unsigned char**)pout,
        32, 0);
#else
    pbkdf2_sha1((const unsigned char*)(key_buffer[index]),
        strlen(key_buffer[index]),
        cur_salt->salt, OPENBSD_SOFTRAID_SALTLENGTH,
        cur_salt->num_iterations, mask_key[0],
        32, 0);
#endif

    for (i = 0; i < MAX_KEYS_PER_CRYPT; ++i) {

#if !ARCH_LITTLE_ENDIAN
      alter_endianity(mask_key[i], 32);
#endif

      /* decrypt sector keys */
      AES_set_decrypt_key(mask_key[i], 256, &akey);
      for(j = 0; j < (OPENBSD_SOFTRAID_KEYLENGTH * OPENBSD_SOFTRAID_KEYS) / 16;  j++) {
        AES_decrypt(&cur_salt->masked_keys[16*j], &unmasked_keys[16*j], &akey);
      }

      /* get SHA1 of mask_key */
      SHA1(mask_key[i], 32, hashed_mask_key);

      /* get HMAC-SHA1 of unmasked_keys using hashed_mask_key */
      HMAC(EVP_sha1(), hashed_mask_key, OPENBSD_SOFTRAID_MACLENGTH,
          unmasked_keys, OPENBSD_SOFTRAID_KEYLENGTH * OPENBSD_SOFTRAID_KEYS,
          (unsigned char*)crypt_out[index+i], NULL);
    }

	}
	return count;
}
Пример #4
0
static void * binary(char *ciphertext) {
  static char *realcipher;

  if (!realcipher) realcipher = mem_alloc_tiny(BINARY_SIZE + SALT_SIZE + 9, MEM_ALIGN_WORD);

  /* stupid overflows */
  memset(realcipher, 0, BINARY_SIZE + SALT_SIZE + 9);
  base64_decode(NSLDAP_MAGIC_LENGTH+ciphertext, CIPHERTEXT_LENGTH, realcipher);
#ifdef MMX_COEF
  alter_endianity((unsigned char*)realcipher, BINARY_SIZE);
#endif
  return (void *)realcipher;
}
Пример #5
0
static void * get_binary(char *ciphertext) {
	static char *realcipher;

	if (!realcipher) realcipher = mem_alloc_tiny(BINARY_SIZE + 1 + SALT_SIZE, MEM_ALIGN_WORD);

	ciphertext += NSLDAP_MAGIC_LENGTH;
	memset(realcipher, 0, BINARY_SIZE);
	base64_decode(ciphertext, strlen(ciphertext), realcipher);
#ifdef SIMD_COEF_32
	alter_endianity((unsigned char *)realcipher, BINARY_SIZE);
#endif
	return (void *)realcipher;
}
Пример #6
0
static void *get_binary (char *ciphertext)
{
    static unsigned char *out;
    int i;

    if (!out)
        out = mem_alloc_tiny (DIGEST_SIZE, MEM_ALIGN_WORD);

    ciphertext += HEX_TAG_LEN;

    for(i=0; i < BINARY_SIZE; i++)
        out[i] = atoi16[ARCH_INDEX(ciphertext[i*2])] * 16 +
                 atoi16[ARCH_INDEX(ciphertext[i*2 + 1])];

    alter_endianity (out, DIGEST_SIZE);

    return (void *) out;
}
Пример #7
0
static void *get_binary(char *ciphertext)
{
    static unsigned char *realcipher;
    int i;

    if (!realcipher)
        realcipher = mem_alloc_tiny(DIGEST_SIZE, MEM_ALIGN_WORD);

    ciphertext += TAG_LENGTH;

    for(i=0; i<DIGEST_SIZE; i++)
    {
        realcipher[i] = atoi16[ARCH_INDEX(ciphertext[i*2])]*16 + atoi16[ARCH_INDEX(ciphertext[i*2+1])];
    }
#ifdef SIMD_COEF_32
    alter_endianity(realcipher, DIGEST_SIZE);
#endif
    return (void*)realcipher;
}
Пример #8
0
static void *get_binary(char *ciphertext)
{
	static unsigned char *realcipher;
	int i;

	if (!realcipher)
		realcipher = mem_alloc_tiny(BINARY_SIZE, MEM_ALIGN_WORD);

	// ignore first character '*'
	ciphertext += 1;
	for (i=0;i<BINARY_SIZE;i++)
	{
		realcipher[i] = atoi16[ARCH_INDEX(ciphertext[i*2])]*16 + atoi16[ARCH_INDEX(ciphertext[i*2+1])];
	}
#ifdef SIMD_COEF_32
	alter_endianity((unsigned char *)realcipher, BINARY_SIZE);
#endif
	return (void *)realcipher;
}