示例#1
0
bool Sekrit::VerifyHash(const Plaintext& plaintext, const unsigned char *iv) const
{
	char hash[sha256::hashbits/8];

	ComputeHash(hash, plaintext, iv);
	return( 0 == memcmp(hash, m_impl->header.hash, sizeof(hash)) );
}
示例#2
0
void SymbolMap::CompileFuncSignaturesFile(const char *filename)
{
    // Store name,length,first instruction,hash into file
    FILE *f = fopen(filename, "w");
    fprintf(f,"00000000\n");
    int count=0;
    for (size_t i = 0; i < entries.size(); i++)
    {
        int size = entries[i].size;
        if (size >= 16 && entries[i].type == ST_FUNCTION)
        {
            u32 inst = Memory::Read_Instruction(entries[i].vaddress); //try to make a bigger number of different vals sometime
            if (inst != 0)
            {
                char temp[64];
                strncpy(temp,entries[i].name,63);
                fprintf(f, "%08x\t%08x\t%08x\t%s\n", inst, size, ComputeHash(entries[i].vaddress,size), temp);
                count++;
            }
        }
    }
    fseek(f,0,SEEK_SET);
    fprintf(f,"%08x",count);
    fclose(f);
}
示例#3
0
 std::string GetFastFileHash(const std::string & filename)
 {
     FileHashResultPtr fileHashResultPtr;
     {
         AutoMutex lock(g_fastFileHashCache_mutex);
         FileCacheMap::iterator iter = g_fastFileHashCache.find(filename);
         if(iter != g_fastFileHashCache.end())
         {
             fileHashResultPtr = iter->second;
         }
         else
         {
             fileHashResultPtr = FileHashResultPtr(new FileHashResult);
             g_fastFileHashCache[filename] = fileHashResultPtr;
         }
     }
     
     std::string hash;
     {
         AutoMutex lock(fileHashResultPtr->mutex);
         if(!fileHashResultPtr->ready)
         {
             fileHashResultPtr->ready = true;
             fileHashResultPtr->hash = ComputeHash(filename);
         }
         
         hash = fileHashResultPtr->hash;
     }
     
     return hash;
 }
示例#4
0
void StateMonitor::OnSchedulePoint(SchedulePointType type, Task tid, SyncVar var, SyncVarOp op, size_t sid){
	if(!getStateCallback) return;
	//if(Chess::GetOptions().depth_bound && sid > Chess::GetOptions().depth_bound) return;
	if(!stateBuf){
		stateLen = 1024;
		stateBuf = new char[stateLen];
	}
	assert(stateLen > 0);
	int len = getStateCallback(stateBuf, stateLen);
	if(len > stateLen){
		while(len > stateLen){
			stateLen *= 2; 
		}
		delete stateBuf;
		stateBuf = new char[stateLen];
		len = getStateCallback(stateBuf, stateLen);
		assert(len <= stateLen);
	}

	HashValue hash = ComputeHash(stateBuf, len);
	stdext::hash_set<HashValue>::iterator f = stateTable.find(hash);
	if(f == stateTable.end()){
		ChessImpl::GetStats()->OnNewState();
		stateTable.insert(hash);
	}
}
示例#5
0
bool LibDictionary::InsertInDictionary(const char *name, int index)
{
    bool put = false;
    ComputeHash(name);
    int l = strlen(name);
    int n = l + 1;
    if (n & 1)
        n++;
    do
    {
        DICTPAGE *dptr = &data[block_x];
        do
        {
            if (!dptr->f.htab[bucket_x])
            {
                int start;
                if (!dptr->f.fflag)
                    start = dptr->f.names - dptr->bytes;
                else
                    start = dptr->f.fflag *2;
                if (LIB_PAGE_SIZE-start >= n + 2)
                {
                    dptr->f.htab[bucket_x] = start/2;					
                    dptr->bytes[start] = l;
                    strncpy((char *)&dptr->bytes[start+1], name, l);
                    if (!caseSensitive)
                        for (int i=start+1; i <= start +l; i++)
                            dptr->bytes[i] = toupper(dptr->bytes[i]);
                                                            
                    start += n;
                    *(unsigned short *)(&dptr->bytes[start]) = index; // endian
                    start += 2;
                    if (start == 512)
                        start = 511;
                    dptr->f.fflag = start / 2;
                    put = true;
                    break;
                }
                else
                {
                    dptr->f.fflag = 0xff;
                    break;
                }
            }
            bucket_x += bucket_d;
            if (bucket_x >= LIB_BUCKETS)
                bucket_x -= LIB_BUCKETS;
        }
        while (obucket_x != bucket_x) ;
        if (put)
            break;
        dptr->f.fflag = 0xff;
        block_x += block_d;
        if (block_x >= blockCount)
            block_x -= blockCount;
    }
    while (oblock_x != block_x);
    return put;
}
示例#6
0
int main(){
	char *s="The quick brown fox jumps over the lazy dog";
	unsigned char b[43];
	unsigned char *r;
	memcpy(b,s,43);
	r=ComputeHash(b,43);
	//printf("%02x\n",r[0]);
	printf("%c\n",b[42]);
	return 0;
}
示例#7
0
AggregateSyncVar::AggregateSyncVar(SyncVar v[], int n){
	assert(n > 1);
	num = n;
	var = new SyncVar[n];
	for(int i=0; i<n; i++){
		var[i] = v[i];
	}
	hash = ComputeHash(v, n);
	numRefs = 0;
}
示例#8
0
void Sekrit::SetPlaintext(const Plaintext& plaintext)
{
	if(plaintext.empty())
	{
		// input empty, reset content
		m_impl->header.realsize = m_impl->header.size = 0;
		memset( m_impl->header.hash, 0, sizeof(m_impl->header.hash) );
		m_impl->data.clear();
	} else
	{
		DoEncrypt(plaintext);
		ComputeHash(m_impl->header.hash, plaintext, m_impl->header.iv);
	}
}
示例#9
0
文件: myfunc.c 项目: xunen/publicwrt
u_char *checkPass(u_char id, const u_char *md5Seed, int seedLen)
{
	u_char md5Src[80];
	int md5Len = strlen(password);
	md5Src[0] = id;
	memcpy(md5Src+1, password, md5Len);
	md5Len++;
	if (startMode % 3 == 2)	/* 赛尔? */
	{
		memcpy(md5Src+md5Len, "xxghlmxhzb", 10);
		md5Len += 10;
	}
	memcpy(md5Src+md5Len, md5Seed, seedLen);
	md5Len += seedLen;
	return ComputeHash(md5Src, md5Len);
}
示例#10
0
bool Sekrit::GetPlaintext(Plaintext& data) const
{
	if( !m_impl->data.empty() )
	{
		char hash[sha256::hashbits/8];
		Plaintext plaintext(DoDecrypt());
		ComputeHash(hash, plaintext, m_impl->header.iv);

		if( 0 == memcmp(hash, m_impl->header.hash, sizeof(hash)) )
		{
			data.swap(plaintext);
			return true;
		} else
			return false;
	} else
	{
		data.clear();
		return true;
	}
}
示例#11
0
/*
 * 802.1x的MD5加密处理(最主要的区别)
 * 返回值:指向密码包的value(16)的指针
 * para1: Request, MD5-Challenge [RFC3748](服务器要求发送密码包)
 * para2:用户密码
 */
u_char * md5_challenge(const u_char pkt_data[], char passwd[])
{
	u_char  md5_data[256];// = id, passwd, value (smu)
	u_char *p, *q;
	int  md5_len = 1;

	md5_data[0]=pkt_data[19];	//md5_data=id(1)

	//md5_data += passwd(?)
	for(p = md5_data + md5_len, q = passwd; *q != '\0'; ){
		*(p++) = *(q++);		
		md5_len++;
	}

	memcpy(md5_data + md5_len, pkt_data + 24, 16);
	md5_len+=16;

	//密码包的value(16)=hash(id(1) + passwd(?) + value(16));
	return ComputeHash(md5_data, md5_len);//point to static u_char array[16]	
}
示例#12
0
char *computePwd(const unsigned char *md5)
{
    static char buf[20];

    unsigned char tmp[40];
    int tmpl=0;
    tmpl = strlen(userName);
    strcpy((char*)tmp, userName);
    memcpy(tmp + tmpl, md5, 16);
    tmpl += 16;

    memcpy(buf, ComputeHash(tmp, tmpl), 16);

    memset(tmp, 0, 16);
    strcpy((char*)tmp, password);

    int i;
    for (i=0; i<16; ++i)
        buf[i] ^= tmp[i];
    return buf;
}
示例#13
0
文件: rcsym.c 项目: doniexun/OrangeC
/* Add a hash item to the table */
HASHREC *AddHash(HASHREC *item, HASHREC **table, int size)
{
    int index = ComputeHash(item->key, size);
    HASHREC **p;

    item->link = 0;

    if (*(p = &table[index]))
    {
        HASHREC *q =  *p,  *r =  *p;
        while (q)
        {
            r = q;
            if (!strcmp(r->key, item->key))
                return (r);
            q = q->link;
        }
        r->link = item;
    }
    else
        *p = item;
    return (0);
}
示例#14
0
		Void Hash::ComputeHash(const StringW& string)
		{
			ComputeHash((PCByte)string.GetBuffer(), string.GetSize() * sizeof(WChar));
		}
示例#15
0
文件: sha-3.cpp 项目: sirmax1/coin
hashval SHA3<256>::ComputeHash(Stream& stm) {
	MemoryStream ms;
	stm.CopyTo(ms);
	return ComputeHash(ms);
}
示例#16
0
		Void Hash::ComputeHash(const Buffer& buffer)
		{
			ComputeHash(buffer.GetBuffer(), buffer.GetSize());
		}
示例#17
0
CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), hash(ComputeHash()) {}
示例#18
0
CTransaction::CTransaction(CMutableTransaction&& tx) : vin(std::move(tx.vin)), vout(std::move(tx.vout)), nVersion(tx.nVersion), nLockTime(tx.nLockTime), strTxComment(tx.strTxComment), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {}
示例#19
0
CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), vin(std::move(tx.vin)), vout(std::move(tx.vout)), nLockTime(tx.nLockTime), hash(ComputeHash()) {}
示例#20
0
void SymbolMap::UseFuncSignaturesFile(const char *filename, u32 maxAddress)
{
    sigs.clear();
    //SymbolMap::ResetSymbolMap();
    //#1: Read the signature file and put them in a fast data structure
    FILE *f = fopen(filename, "r");
    int count;
    if (fscanf(f, "%08x\n", &count) != 1)
        count = 0;
    char name[256];
    for (int a=0; a<count; a++)
    {
        u32 inst, size, hash;
        if (fscanf(f,"%08x\t%08x\t%08x\t%s\n",&inst,&size,&hash,name)!=EOF)
            sigs.push_back(Sig(inst,size,hash,name));
        else
            break;
    }
    size_t numSigs = sigs.size();
    fclose(f);
    std::sort(sigs.begin(), sigs.end());

    f = fopen("C:\\mojs.txt", "w");
    fprintf(f,"00000000\n");
    for (size_t j=0; j<numSigs; j++)
        fprintf(f, "%08x\t%08x\t%08x\t%s\n", sigs[j].inst, sigs[j].size, sigs[j].hash, sigs[j].name);
    fseek(f,0,SEEK_SET);
    fprintf(f,"%08x", (unsigned int)numSigs);
    fclose(f);

    u32 last = 0xc0d3babe;
    for (size_t i=0; i<numSigs; i++)
    {
        if (sigs[i].inst != last)
        {
            sigmap.insert(Sigmap::value_type(sigs[i].inst, &sigs[i]));
            last = sigs[i].inst;
        }
    }

    //#2: Scan/hash the memory and locate functions
    char temp[256];
    u32 lastAddr=0;
    for (u32 addr = 0x80000000; addr<maxAddress; addr+=4)
    {
        if ((addr&0xFFFF0000) != (lastAddr&0xFFFF0000))
        {
            sprintf(temp,"Scanning: %08x",addr);
            lastAddr=addr;
        }
        u32 inst = Memory::Read_Instruction(addr);
        if (!inst)
            continue;

        Sigmap::iterator iter = sigmap.find(inst);
        if (iter != sigmap.end())
        {
            Sig *sig = iter->second;
            while (true)
            {
                if (sig->inst != inst)
                    break;

                u32 hash = ComputeHash(addr,sig->size);
                if (hash==sig->hash)
                {
                    //MATCH!!!!
                    MapEntry e;
                    e.address=addr;
                    e.size= sig->size;
                    e.vaddress = addr;
                    e.type=ST_FUNCTION;
                    strcpy(e.name,sig->name);
                    addr+=sig->size-4; //don't need to check function interior
                    entries.push_back(e);
                    break;
                }
                sig++;
            }
        }
    }
    //ensure code coloring even if symbols were loaded before
    SymbolMap::SortSymbols();
}
CTransaction::CTransaction(const CMutableTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {}