Beispiel #1
0
  //-----------------------------------------------------------------
  crypto::secret_key account_base::generate(const crypto::secret_key& recovery_key, bool recover, bool two_random)
  {
    crypto::secret_key first = generate_keys(m_keys.m_account_address.m_spend_public_key, m_keys.m_spend_secret_key, recovery_key, recover);

    // rng for generating second set of keys is hash of first rng.  means only one set of electrum-style words needed for recovery
    crypto::secret_key second;
    blake256_hash((uint8_t *)&second, (uint8_t *)&first, sizeof(crypto::secret_key));

    generate_keys(m_keys.m_account_address.m_view_public_key, m_keys.m_view_secret_key, second, two_random ? false : true);
    m_creation_timestamp = time(NULL);
    return first;
  }
Beispiel #2
0
void blake256_test()
{
  int i, v;
  uint8_t in[72], out[32];
  uint8_t test1[] =
  {
    0x0c, 0xe8, 0xd4, 0xef, 0x4d, 0xd7, 0xcd, 0x8d,
    0x62, 0xdf, 0xde, 0xd9, 0xd4, 0xed, 0xb0, 0xa7,
    0x74, 0xae, 0x6a, 0x41, 0x92, 0x9a, 0x74, 0xda,
    0x23, 0x10, 0x9e, 0x8f, 0x11, 0x13, 0x9c, 0x87
  };
  uint8_t test2[] =
  {
    0xd4, 0x19, 0xba, 0xd3, 0x2d, 0x50, 0x4f, 0xb7,
    0xd4, 0x4d, 0x46, 0x0c, 0x42, 0xc5, 0x59, 0x3f,
    0xe5, 0x44, 0xfa, 0x4c, 0x13, 0x5d, 0xec, 0x31,
    0xe2, 0x1b, 0xd9, 0xab, 0xdc, 0xc2, 0x2d, 0x41
  };
  memset( in, 0, 72 );
  blake256_hash( out, in, 1 );
  v = 0;

  for( i = 0; i < 32; ++i )
  {
    if ( out[i] != test1[i] ) v = 1;
  }

  if ( v ) printf( "test 1 error\n" );

  blake256_hash( out, in, 72 );
  v = 0;

  for( i = 0; i < 32; ++i )
  {
    if ( out[i] != test2[i] ) v = 1;
  }

  if ( v ) printf( "test 2 error\n" );
}
Beispiel #3
0
static void do_blake_hash(const void* input, size_t len, char* output) {
	blake256_hash((uint8_t*)output, input, len);
}
void hash_extra_blake(const void *data, size_t length, char *hash) {
  blake256_hash((uint8_t*)hash, data, length);
}
void main()
{
  MYSQL *con = mysql_init(NULL);
  char statement[512];
  char myHash[] =        "d5852d4dac50bbc61d6cb794f99bdf0f12cc5220dd2d043bbde18ebedd3ca95f";
  unsigned char dynamicHash[32];
  char *plaintext = NULL;
  char *currentHash = NULL;
  char hash64[65];
  char temp[3];
  char r[6];
  int num_fields,i,k;
  MYSQL_ROW row;
  MYSQL_RES *result;
  int successFlag = 0;
  
  char *pos = myHash;
  size_t count = 0;    
     /* Convert back from hex string to byte array */
  for(count = 0; count < sizeof(dynamicHash)/sizeof(dynamicHash[0]); count++) 
  {
      sscanf(pos, "%2hhx", &dynamicHash[count]);
      pos += 2 * sizeof(char);
  }


  plaintext = malloc(7);
  currentHash = malloc(33);   

  if (con == NULL) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      exit(1);
  }

  if (mysql_real_connect(con, "localhost", "root", "botiotia", 
          "test", 0, NULL, 0) == NULL) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }  

   for(k=0;k<32;k++)
   {	
	snprintf(temp,3,"%02x",dynamicHash[k]);
	hash64[2*k] = temp[0];
	hash64[2*k+1] = temp[1];
   }
   hash64[64] = '\0';

   for(i = chainLength-1; i >= 0; i--)      //iterate chain backwards
   {
	snprintf(statement, 512, "SELECT * FROM Rainbow where Hash = '%s'",hash64);
  	if (mysql_query(con, statement) )
  	{
  		finish_with_error(con);
  	}
	result = mysql_store_result(con); 
        if (result == NULL) 
  	{
      		finish_with_error(con);
 	}
  	row = mysql_fetch_row(result);  //we know that if any result is produced, it is going to be distinct from creation and thus no iteration with num_fields is required.(maximum 1 row per query)

        if(row != NULL)              //if found a result
	{
           
	   if(plaintext == NULL)
	       plaintext = malloc(7);
	   if(currentHash == NULL)  
	       currentHash = malloc(33); 
           //copy to the corresponding buffers
	   strncpy(plaintext,row[0],7);                         //row[0] to plaintext        
           char *pos1 = row[1];					//now convert this row[1] to byte array and copy it to hash
           size_t count = 0;    
           /* Convert back from hex string to byte array, because the R and Blake take the byte array as a parameter */
           for(count = 0; count < sizeof(currentHash)/sizeof(currentHash[0]); count++) 
           {
              sscanf(pos1, "%2hhx", &currentHash[count]);
              pos1 += 2 * sizeof(char);
           }
	}
	else                             //else both NULL
	{
	   plaintext = NULL;
	   currentHash = NULL;
        }
	
	if(currentHash != NULL)         //hash is found.
	{   
	    blake256_hash(dynamicHash,plaintext,6);         //start from the beginning of the chain
	    for(k = 0; k <= i; k++)         //iterate through all the R functions until the hash
	    {
		Reduce(dynamicHash,k,r);           //k is the position
                //printf("%s\n",currentHash);
	  	if(i == k)
		{
			printf("Found at %d. The password is: %s \n",k,r);
			successFlag = 1;
		}
		blake256_hash(dynamicHash,r,6);
	    }
            i = -1;                     //to stop the iteration
	}
        Reduce(dynamicHash,i,r);                
        blake256_hash(dynamicHash,r,6);          
        
	for(k=0;k<32;k++)
	{	
	   snprintf(temp,3,"%02x",dynamicHash[k]);
	   hash64[2*k] = temp[0];
	   hash64[2*k+1] = temp[1];
	}
        hash64[64] = '\0';
        if((i % 10000) == 0)
           printf("%d steps from %d\n",chainLength-i,chainLength);
   }

  if(!successFlag)
      printf("Password not Found :-(\n");

  mysql_free_result(result);
  mysql_close(con);
  
  exit(0);

}
void do_blake_hash(const void* input, size_t len, char* output) {
	//char *hashhex2 = bin2hex((const unsigned char *)input, len);
	//applog(LOG_ERR, "!!!!!!!!!!!BLAKE: %s", hashhex2);
	blake256_hash((uint8_t*)output, input, len);
}