Beispiel #1
0
uint64_t mix_hashed_nums(uint8_t *hashed_nums, const uint8_t *unhashedData, size_t unhashed_sz,
                       uint8_t **mixed_hash, uint8_t *hash_digest)
{
  uint32_t i, index = 0;
  const uint32_t hashed_nums_len = SHA256_LEN;

  uint64_t count;
  uint8_t tmp_val, tmp_array[SHA256_LEN + 2];

  //initialize the class for the extend hash
  Extend_Array new_hash;
  Extend_Array_init(&new_hash);

  //set the first hash length in the temp array to all 0xff
  memset(tmp_array, 0xff, SHA256_LEN);
  //set the last two bytes to \000
  *(tmp_array + SHA256_LEN) = *(tmp_array + SHA256_LEN + 1) = 0;

  for(count = 0;; count++)
  {
    //+1 to keeps a 0 value of *(hashed_nums + index) moving on
    i = hex_char_to_int(*(hashed_nums + index)) + 1;
    index += i;
    
    //if we hit the end of the hash, rehash it
    if(index >= hashed_nums_len)
    {
      index = index % hashed_nums_len;
      sha256_to_str(hashed_nums, hashed_nums_len, hashed_nums, hash_digest); //rescramble
    }
    
    tmp_val = *(hashed_nums + index);

    join_to_array(tmp_array, tmp_val); //plop tmp_val at the end of tmp_array
    sha256_to_str(tmp_array, SHA256_LEN + 1, tmp_array, hash_digest);

    //extend the expanded hash to the array
    extend_array(&new_hash, count * SHA256_LEN, tmp_array, SHA256_LEN, false);

    //check if the last value of hashed_nums is the same as the last value in tmp_array
    if(index == hashed_nums_len - 1)
      if(tmp_val == *(tmp_array + SHA256_LEN - 1))
      {
        //add to count since we extended the array, but break will exit the for loop and count
        // will not get incremenented by the for loop
        count++;
        break;
      }

  }

  //extend the unhashed data to the end and add the \000 to the end
  extend_array(&new_hash, count * SHA256_LEN, (unsigned char*)unhashedData, unhashed_sz, true);

  //assign the address of new_hash's array to mixed_hash
  *mixed_hash = new_hash.array;

  return count * SHA256_LEN + unhashed_sz;
}
Beispiel #2
0
bool dcrypt(const uint8_t *data, size_t data_sz, uint8_t *hash_digest, u32int *hashRet, int num_iter)
{
    uint8_t hashed_nums[SHA256_LEN + 1], *mix_hash;

    bool allocDigest = false;
    bool completed = false;
    if(!hash_digest)
    {
        hash_digest = alloca(DCRYPT_DIGEST_LENGTH);
        allocDigest = true;
    }

    sha256_to_str(data, data_sz, hashed_nums, hash_digest);

    //mix the hashes up, magority of the time takes here
    uint64 mix_hash_len = mix_hashed_nums(hashed_nums, data, data_sz, &mix_hash, hash_digest, num_iter, &completed);

    //apply the final hash to the output
    if (completed)  sha256((const uint8_t*)mix_hash, mix_hash_len, hashRet);

    free(mix_hash);

    //sucess
    return completed;
}
Beispiel #3
0
void dcrypt(const uint8_t *data, size_t data_sz, uint8_t *hash_digest, uint32_t *hashRet)
{
  uint8_t hashed_nums[SHA256_LEN + 1], *mix_hash;

  bool allocDigest = false;
  if(!hash_digest)
  {
    hash_digest = (uint8_t*)malloc(DCRYPT_DIGEST_LENGTH);
    allocDigest = true;
  }

  sha256_to_str(data, data_sz, hashed_nums, hash_digest);

  //mix the hashes up, magority of the time takes here
  uint64_t mix_hash_len = mix_hashed_nums(hashed_nums, data, data_sz, &mix_hash, hash_digest);

  //apply the final hash to the output
  sha256((const uint8_t*)mix_hash, mix_hash_len, hashRet);

  free(mix_hash);

  if(allocDigest)
    free(hash_digest);

  //sucess
  return;
}
Beispiel #4
0
bool dcrypt_fast(u8int *data, size_t data_sz,uint32_t*md)
{
#define MAX_INC 16

    unsigned char hash_buffer[SHA256_LEN*MAX_INC+SHA256_LEN*4+80+1];

    unsigned char		index_buffer[SHA256_LEN+1];
    unsigned char 		*tmp_array = hash_buffer;
    unsigned int	    index = 0;
    unsigned char		tmp_val;

    SHA256_CTX	hash;
    SHA256_Init(&hash);

    digest_to_skiplist((u8int *)md,index_buffer);

    int steps = 0,index_test=index;
    while(1)
    {
        index_test += index_buffer[index_test]+1;

        if(index_test >= SHA256_LEN) return 0;
        if(index_test == SHA256_LEN - 1) break;
        steps++;
    }
    if(steps >= MAX_INC) return 0;/**/

    memset(tmp_array, 0xff, SHA256_LEN);      //set the first hash length in the temp array to all 0xff'
    memset(tmp_array + SHA256_LEN, 0x00, 2);  //set the last bytes to \000

    int count = 0;

    if(tmp_array_1 && hash_1) // copy pre-calulated internal hashes
    {
        index += index_buffer[index]+1;
        unsigned int offset_1 = index_buffer[index];

        if(tmp_array_2 && hash_2) // depth 2
        {
            index += index_buffer[index]+1;
            unsigned int offset_2 = offset_1*16+index_buffer[index];

            if(tmp_array_3 && hash_3) // depth 3
            {
                index += index_buffer[index]+1;
                unsigned int offset_3 = offset_2*16+index_buffer[index];

                if(tmp_array_4 && hash_4) // depth 4
                {
                    index += index_buffer[index]+1;
                    unsigned int offset_4 = offset_3*16+index_buffer[index];

                    if(tmp_array_5 && hash_5) // depth 5
                    {
                        index += index_buffer[index]+1;
                        unsigned int offset_5 = offset_4*16+index_buffer[index];

                        // depth 6?

                        memcpy(tmp_array,&tmp_array_5[item_size*offset_5],SHA256_LEN);
                        memcpy(&hash,&hash_5[offset_5],sizeof(SHA256_CTX));
                    }
                    else
                    {
                        memcpy(tmp_array,&tmp_array_4[item_size*offset_4],SHA256_LEN);
                        memcpy(&hash,&hash_4[offset_4],sizeof(SHA256_CTX));
                    }
                }
                else
                {
                    memcpy(tmp_array,&tmp_array_3[item_size*offset_3],SHA256_LEN);
                    memcpy(&hash,&hash_3[offset_3],sizeof(SHA256_CTX));
                }
            }
            else
            {
                memcpy(tmp_array,&tmp_array_2[item_size*offset_2],SHA256_LEN);
                memcpy(&hash,&hash_2[offset_2],sizeof(SHA256_CTX));
            }
        }
        else {
            memcpy(tmp_array,&tmp_array_1[item_size*offset_1],SHA256_LEN);
            memcpy(&hash,&hash_1[offset_1],sizeof(SHA256_CTX));
        }
    }

    do
    {
        index += index_buffer[index]+1;

        if(index >= SHA256_LEN) return 0;

        tmp_val = hex_digits[index_buffer[index]];

        tmp_array[SHA256_LEN] =  tmp_val; //set  end of tmp_array to tmp_val
        sha256_to_str(tmp_array, SHA256_LEN + 1, tmp_array+SHA256_LEN,(u8int *)md);

        count++;
        tmp_array += SHA256_LEN;

    }
    while ((index != SHA256_LEN - 1) || (tmp_val != tmp_array[SHA256_LEN - 1] ));

    SHA256_Update(&hash,hash_buffer+SHA256_LEN,SHA256_LEN*count);
    SHA256_Update(&hash,data,data_sz);
    SHA256_Final((u8int *)md, &hash);

    return 1;
}
Beispiel #5
0
void init_hashtable_values()
{
    printf("Pre-computing dcrypt internal hash values.\n");

    SHA256_CTX	hash;
    SHA256_Init(&hash);
    unsigned char md[32];

    if(tmp_array_1 && hash_1)
    {
        for(int x1 = 0; x1 < 16; x1++)
        {
            unsigned int offset_1 = x1;
            uint8_t * ta1 = &tmp_array_1[item_size*x1];
            memset(ta1, 0xff, SHA256_LEN);
            ta1[SHA256_LEN] = hex_digits[x1];
            sha256_to_str(ta1, SHA256_LEN + 1, ta1,md);

            SHA256_CTX	*current_hash = &hash_1[x1];
            memcpy(current_hash,&hash,sizeof(SHA256_CTX));
            SHA256_Update(current_hash,ta1,SHA256_LEN);

            if(tmp_array_2 && hash_2)
            {
                for(int x2 = 0; x2 < 16; x2++)
                {
                    unsigned int offset_2 = offset_1*16+x2;
                    uint8_t * ta2 = &tmp_array_2[item_size*offset_2];
                    memcpy(ta2,ta1,SHA256_LEN);
                    ta2[SHA256_LEN] = hex_digits[x2];
                    sha256_to_str(ta2, SHA256_LEN + 1, ta2,md);

                    memcpy(&hash_2[offset_2],&hash_1[offset_1],sizeof(SHA256_CTX));
                    SHA256_Update(&hash_2[offset_2],ta2,SHA256_LEN);

                    if(tmp_array_3 && hash_3)
                    {
                        for(int x3 = 0; x3 < 16; x3++)
                        {
                            unsigned int offset_3 = offset_2*16+x3;
                            uint8_t * ta3 = &tmp_array_3[item_size*offset_3];
                            memcpy(ta3,ta2,SHA256_LEN);
                            ta3[SHA256_LEN] = hex_digits[x3];
                            sha256_to_str(ta3, SHA256_LEN + 1, ta3,md);

                            memcpy(&hash_3[offset_3],&hash_2[offset_2],sizeof(SHA256_CTX));
                            SHA256_Update(&hash_3[offset_3],ta3,SHA256_LEN);

                            if(tmp_array_4 && hash_4)
                            {
                                for(int x4 = 0; x4 < 16; x4++)
                                {
                                    unsigned int offset_4 = offset_3*16+x4;
                                    uint8_t * ta4 = &tmp_array_4[item_size*offset_4];
                                    memcpy(ta4,ta3,SHA256_LEN);
                                    ta4[SHA256_LEN] = hex_digits[x4];
                                    sha256_to_str(ta4, SHA256_LEN + 1, ta4,md);

                                    memcpy(&hash_4[offset_4],&hash_3[offset_3],sizeof(SHA256_CTX));
                                    SHA256_Update(&hash_4[offset_4],ta4,SHA256_LEN);

                                    if(tmp_array_5 && hash_5)
                                    {
                                        for(int x5 = 0; x5 < 16; x5++)
                                        {
                                            unsigned int offset_5 = offset_4*16+x5;
                                            uint8_t * ta5 = &tmp_array_5[item_size*offset_5];
                                            memcpy(ta5,ta4,SHA256_LEN);
                                            ta5[SHA256_LEN] = hex_digits[x5];
                                            sha256_to_str(ta5, SHA256_LEN + 1, ta5,md);

                                            memcpy(&hash_5[offset_5],&hash_4[offset_4],sizeof(SHA256_CTX));
                                            SHA256_Update(&hash_5[offset_5],ta5,SHA256_LEN);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    printf("Ready to rumble.\n");
}