示例#1
0
static PyObject *dcrypt_getpowhash(PyObject *self, PyObject *args)
{
    char *output;
    PyObject *value;
#if PY_MAJOR_VERSION >= 3
    PyBytesObject *input;
#else
    PyStringObject *input;
#endif
    if (!PyArg_ParseTuple(args, "S", &input))
        return NULL;
    Py_INCREF(input);
    output = PyMem_Malloc(32);

#if PY_MAJOR_VERSION >= 3
    dcrypt((char *)PyBytes_AsString((PyObject*) input), 80, NULL, output);
#else
    dcrypt((char *)PyString_AsString((PyObject*) input), 80, NULL, output);
#endif
    Py_DECREF(input);
#if PY_MAJOR_VERSION >= 3
    value = Py_BuildValue("y#", output, 32);
#else
    value = Py_BuildValue("s#", output, 32);
#endif
    PyMem_Free(output);
    return value;
}
示例#2
0
uint8_t* readCredential(uint8_t* c, uint8_t* buff, FILE* file)
{   
    
	credentialFlash_t cred;
	uint8_t tempDecryptBuff[4096];
	uint8_t* ptr;
	int ctr, i, offset;
    
	/* Credential */
	ptr = c;
    cred.name = c;
    while(*ptr++ != 0);
    cred.next = ((uint16_t)ptr[1] << 8) + ptr[0];
    cred.nextaddr = &buff[cred.next];

    /* Decrypt */
    ptr += 2;
    offset = 0;
    ctr=0;
    while(ctr < 4)
    {

    	dcrypt( &ptr[offset], &tempDecryptBuff[offset], 16);
    	for(i=0; i<16; i++)
    	{
    		if(tempDecryptBuff[offset+i] == 0)
    		{
    			ctr++;
    		}
    	}
    	offset += 16;
    }

    cred.line1 = tempDecryptBuff;
    ptr = tempDecryptBuff;
    while(*ptr++ != 0);
    cred.hop = ptr;
    while(*ptr++ != 0);
    cred.line2 = ptr;
    while(*ptr++ != 0);
    cred.submit = ptr;

    /* Create Tags */
	XML_createTag(file, "name",(char*) cred.name);
	XML_createTag(file, "user",(char*) cred.line1);
	XML_createTag(file, "hop",(char*) cred.hop);
	XML_createTag(file, "pass",(char*) cred.line2);
	XML_createTag(file, "submit",(char*) cred.submit);

    return cred.nextaddr;
}
示例#3
0
int scanhash_dcrypt(int thr_id, uint32_t *pdata,
                    const uint32_t *ptarget,
                    uint32_t max_nonce, uint64_t *hashes_done)
{
  uint32_t block[20], hash[8];
  uint32_t nNonce = pdata[19] - 1;
  const uint32_t Htarg = ptarget[7]; //the last element in the target is the first 32 bits of the target
  int i;

  //copy the block (first 80 bytes of pdata) into block
  memcpy(block, pdata, 80);

  do
  {
    //increment nNonce
    block[19] = ++nNonce;

    dcrypt((u8int*)block, 80, ctx.digest, hash);

    //hash[7] <= Htarg just compares the first 32 bits of the hash with the target
    // full_test fully compares the entire hash with the entire target
    if(hash[7] <= Htarg && fulltest(hash, ptarget))
    {
      *hashes_done = nNonce - pdata[19] + 1;
      pdata[19] = block[19];

      //found a hash!
      return 1;
    }

  }while(nNonce < max_nonce && !work_restart[thr_id].restart);

  *hashes_done = nNonce - pdata[19] + 1;
  pdata[19] = nNonce;

  //No luck yet
  return 0;
}
示例#4
0
int scanhash_dcrypt(int thr_id, uint32_t *pdata,
                    unsigned char *digest, const uint32_t *ptarget,
                    uint32_t max_nonce, unsigned long *hashes_done, int num_iter)
{
    uint32_t block[20], hash[8];
    uint32_t nNonce = pdata[19] - 1;
    const uint32_t Htarg = ptarget[7]; //the last element in the target is the first 32 bits of the target
    int i;
    bool completed;
    int missed = 0;
    //copy the block (first 80 bytes of pdata) into block
    memcpy(block, pdata, 80);

    SHA256_CTX	halfstate,fullstate;
    SHA256_Init(&halfstate);
    SHA256_Update(&halfstate,&block,sizeof(uint32_t)*19);

    do
    {
        //increment nNonce
        block[19] = ++nNonce;

        //completed = dcrypt((u8int*)block, 80, digest, hash, num_iter);

        memcpy(&fullstate,&halfstate,sizeof(SHA256_CTX));
        SHA256_Update(&fullstate,&block[19],sizeof(uint32_t));
        SHA256_Final((u8int *)hash, &fullstate);
        completed = dcrypt_fast((u8int*)block, 80,hash);/**/

        if (!completed)
        {
            missed += 1;
            continue;
        }

        /*
        // check optimized hash against previous hash function

        uint32_t hash2[8];

        int c2 = dcrypt((u8int*)block, 80, digest, hash2, num_iter);

        for(int i = 0; i < 8 ; i++)
        {
        	if(hash[i] != hash2[i])
        	{
        		char s1[65],s2[65];
        		digest_to_string((u8int*)hash, s1);
        		digest_to_string((u8int*)hash2, s2);
        		printf("Fail!!!\n%s %d\n%s %d\n",s1,completed,s2,c2);
        		exit(0);
        	}
        }/**/


        //hash[7] <= Htarg just compares the first 32 bits of the hash with the target
        // full_test fully compares the entire hash with the entire target

        if(hash[7] <= Htarg && fulltest(hash, ptarget))
        {
            *hashes_done = nNonce - pdata[19] + 1 - missed;
            pdata[19] = block[19];

            char s[65];
            digest_to_string((u8int*)hash, s);
            applog(LOG_INFO, "hash found: %s", s);

            // check

            uint32_t hash2[8];

            int c2 = dcrypt((u8int*)block, 80, digest, hash2, num_iter);

            for(int i = 0; i < 8 ; i++)
            {
                if(hash[i] != hash2[i])
                {
                    char s1[65],s2[65];
                    digest_to_string((u8int*)hash, s1);
                    digest_to_string((u8int*)hash2, s2);
                    printf("Error invalid hash found.\n%s %d\n%s %d\n",s1,completed,s2,c2);
                    exit(0);
                }
            }
            //printf("hash verified.\n");

            //found a hash!
            return 1;
        }

    } while(nNonce < max_nonce && !work_restart[thr_id].restart);

    *hashes_done = nNonce - pdata[19] + 1 - missed;
    pdata[19] = nNonce;

    //No luck yet
    return 0;
}
示例#5
0
void dcrypthash(void *output, const void *input) {
    dcrypt((u8int*)input, 80, ctx.digest, output);
}