예제 #1
0
static void
decrypt(struct trad_pkware *ctx, zip_uint8_t *out, const zip_uint8_t *in,
	zip_uint64_t len, int update_only)
{
    zip_uint16_t tmp;
    zip_uint64_t i;
    Bytef b;

    for (i=0; i<len; i++) {
	b = in[i];

	if (!update_only) {
	    /* decrypt next byte */
	    tmp = ctx->key[2] | 2;
	    tmp = (tmp * (tmp ^ 1)) >> 8;
	    b ^= tmp;
	}

	/* store cleartext */
	if (out)
	    out[i] = b;

	/* update keys */
	ctx->key[0] = CRC32(ctx->key[0], b);
	ctx->key[1] = (ctx->key[1] + (ctx->key[0] & 0xff)) * 134775813 + 1;
	b = ctx->key[1] >> 24;
	ctx->key[2] = CRC32(ctx->key[2], b);
    }
예제 #2
0
int RageFileObj::Read( void *pBuffer, size_t iBytes )
{
        int ret = 0;

	while( !m_bEOF && iBytes > 0 )
	{
		if( m_pReadBuffer != NULL && m_iReadBufAvail )
		{
			/* Copy data out of the buffer first. */
			int iFromBuffer = min( (int) iBytes, m_iReadBufAvail );
			memcpy( pBuffer, m_pReadBuf, iFromBuffer );
			if( m_bCRC32Enabled )
				CRC32( m_iCRC32, pBuffer, iFromBuffer );

			ret += iFromBuffer;
			m_iFilePos += iFromBuffer;
			iBytes -= iFromBuffer;
			m_iReadBufAvail -= iFromBuffer;
			m_pReadBuf += iFromBuffer;

			pBuffer = (char *) pBuffer + iFromBuffer;
		}

		if( !iBytes )
			break;

		ASSERT( m_iReadBufAvail == 0 );

		/* If buffering is disabled, or the block is bigger than the buffer,
		 * read the remainder of the data directly into the desteination buffer. */
		if( m_pReadBuffer == NULL || iBytes >= BSIZE )
		{
			/* We have a lot more to read, so don't waste time copying it into the
			 * buffer. */
			int iFromFile = this->ReadInternal( pBuffer, iBytes );
			if( iFromFile == -1 )
				return -1;

			if( iFromFile == 0 )
				m_bEOF = true;

			if( m_bCRC32Enabled )
				CRC32( m_iCRC32, pBuffer, iFromFile );
			ret += iFromFile;
			m_iFilePos += iFromFile;
			return ret;
		}

		/* If buffering is enabled, and we need more data, fill the buffer. */
		m_pReadBuf = m_pReadBuffer;
		int got = FillReadBuf();
		if( got == -1 )
			return got;
		if( got == 0 )
			m_bEOF = true;
	}

	return ret;
}
예제 #3
0
static int ZipUpdateKeys(unsigned long* pkeys, const unsigned long* crc32tab, int c)
{
	(*(pkeys + 0)) = CRC32((*(pkeys + 0)), c);
	(*(pkeys + 1)) += (*(pkeys + 0)) & 0xff;
	(*(pkeys + 1)) = (*(pkeys + 1)) * 134775813L + 1;

	{
		register int keyshift = (int)((*(pkeys + 1)) >> 24);
		(*(pkeys + 2)) = CRC32((*(pkeys + 2)), keyshift);
	}

	return c;
}
예제 #4
0
파일: recvol5.cpp 프로젝트: 1ldk/mpc-hc
uint RecVolumes5::ReadHeader(File *RecFile,bool FirstRev)
{
  const size_t FirstReadSize=REV5_SIGN_SIZE+8;
  byte ShortBuf[FirstReadSize];
  if (RecFile->Read(ShortBuf,FirstReadSize)!=FirstReadSize)
    return 0;
  if (memcmp(ShortBuf,REV5_SIGN,REV5_SIGN_SIZE)!=0)
    return 0;
  uint HeaderSize=RawGet4(ShortBuf+REV5_SIGN_SIZE+4);
  if (HeaderSize>0x100000 || HeaderSize<=5)
    return 0;
  uint BlockCRC=RawGet4(ShortBuf+REV5_SIGN_SIZE);

  RawRead Raw(RecFile);
  if (Raw.Read(HeaderSize)!=HeaderSize)
    return 0;

  // Calculate CRC32 of entire header including 4 byte size field.
  uint CalcCRC=CRC32(0xffffffff,ShortBuf+REV5_SIGN_SIZE+4,4);
  if ((CRC32(CalcCRC,Raw.GetDataPtr(),HeaderSize)^0xffffffff)!=BlockCRC)
    return 0;

  if (Raw.Get1()!=1) // Version check.
    return 0;
  DataCount=Raw.Get2();
  RecCount=Raw.Get2();
  TotalCount=DataCount+RecCount;
  uint RecNum=Raw.Get2(); // Number of recovery volume.
  if (RecNum>=TotalCount || TotalCount>MaxVolumes)
    return 0;
  uint RevCRC=Raw.Get4(); // CRC of current REV volume.

  if (FirstRev)
  {
    // If we have read the first valid REV file, init data structures
    // using information from REV header.
    size_t CurSize=RecItems.Size();
    RecItems.Alloc(TotalCount);
    for (size_t I=CurSize;I<TotalCount;I++)
      RecItems[I].f=NULL;
    for (uint I=0;I<DataCount;I++)
    {
      RecItems[I].FileSize=Raw.Get8();
      RecItems[I].CRC=Raw.Get4();
    }
  }

  RecItems[RecNum].CRC=RevCRC; // Assign it here, after allocating RecItems.

  return RecNum;
}
예제 #5
0
파일: zzip-data.c 프로젝트: caldwell/zzip
char *ZzipData(char *image_type, char *data, size_t *length, char **extra_headers)
{
    // zzip the data without the compression:
    unsigned int rounded_length = *length;
    char *buffer = malloc(*length+1024);   if (!buffer)                  return NULL;
    char *data2 = malloc(*length+8);     if (!data2) { free(buffer); return NULL; }
    char *key = getenv("ZZIP_KEY");
    char key_index = -1;
    uint32_t plaintextCRC;
    uint32_t plaintextChecksum;
    if (key) {
        key_index = strtoul(key, NULL, 10);
        key += 3;
        plaintextCRC = CRC32(0, data, *length);
        // Blowfish (at least our implementation) requires the input to be on an 8 byte
        // boundary. Otherwise when we decrypt we will get garbled data on the last little bit.
        if (rounded_length % 8 != 0)
            rounded_length += 8 - rounded_length % 8;
        memset(data2, 0, rounded_length);
        memcpy(data2, data, *length);
        plaintextChecksum = Checksum((uint8_t*)data2,rounded_length);
        data = data2;
        BlowfishContext context;
        Blowfish_Init(&context,(uint8_t*)key,strlen(key));
        Blowfish_Encrypt_Buffer(&context, (unsigned long*)data, rounded_length);
    }
    int o = 0;
    o += sprintf(buffer+o,"zzip version 1.0 (1394 %s)\n","1.0");
    o += sprintf(buffer+o,"Compressed Length   = 0x%08X\n",rounded_length); // should really be called "encrypted length" (only on encryption) because it's rounded up.
    o += sprintf(buffer+o,"Uncompressed Length = 0x%08X\n",*length);
    o += sprintf(buffer+o,"Checksum            = 0x%08lX\n",Checksum((uint8_t*)data,rounded_length));
    o += sprintf(buffer+o,"CRC                 = 0x%08lX\n",(unsigned long)CRC32(0, (uint8_t*)data, rounded_length));
    o += sprintf(buffer+o,"Compression         = none\n");
    o += sprintf(buffer+o,"Image Type          = %s\n", image_type);
    if (key) {
        o += sprintf(buffer+o,"Unencrypted Length  = 0x%08X\n",*length); // Should really be called "compressed length" because it's not rounded
        o += sprintf(buffer+o,"Encryption          = blowfish\n");
        o += sprintf(buffer+o,"Encryption Key      = %d\n",key_index);
        o += sprintf(buffer+o,"Plaintext Checksum  = 0x%08X\n",plaintextChecksum);
        o += sprintf(buffer+o,"Plaintext CRC       = 0x%08X\n",plaintextCRC);
    }
    while(extra_headers && *extra_headers)
        o += sprintf(buffer+o, "%s\n", *extra_headers++);
    time_t t = time(&t);
    o += sprintf(buffer+o,"Date                = %s",ctime(&t));
    memcpy(buffer+o+1, data, rounded_length);
    // Boy that was tough.
    free(data2);
    *length = o+1+rounded_length;
    return buffer;
}
예제 #6
0
파일: rawread.cpp 프로젝트: 1ldk/mpc-hc
uint RawRead::GetCRC15(bool ProcessedOnly) // RAR 1.5 block CRC.
{
  if (DataSize<=2)
    return 0;
  uint HeaderCRC=CRC32(0xffffffff,&Data[2],(ProcessedOnly ? ReadPos:DataSize)-2);
  return ~HeaderCRC & 0xffff;
}
예제 #7
0
void RarVM::Prepare(byte *Code,uint CodeSize,VM_PreparedProgram *Prg)
{
  // Calculate the single byte XOR checksum to check validity of VM code.
  byte XorSum=0;
  for (uint I=1;I<CodeSize;I++)
    XorSum^=Code[I];

  if (XorSum!=Code[0])
    return;

  struct StandardFilters
  {
    uint Length;
    uint CRC;
    VM_StandardFilters Type;
  } static StdList[]={
    53, 0xad576887, VMSF_E8,
    57, 0x3cd7e57e, VMSF_E8E9,
   120, 0x3769893f, VMSF_ITANIUM,
    29, 0x0e06077d, VMSF_DELTA,
   149, 0x1c2c5dc8, VMSF_RGB,
   216, 0xbc85e701, VMSF_AUDIO
  };
  uint CodeCRC=CRC32(0xffffffff,Code,CodeSize)^0xffffffff;
  for (uint I=0;I<ASIZE(StdList);I++)
    if (StdList[I].CRC==CodeCRC && StdList[I].Length==CodeSize)
    {
      Prg->Type=StdList[I].Type;
      break;
    }
}
예제 #8
0
Evt_MoveData::Evt_MoveData(int16_t px, int16_t py, std::string pName):
    x(px),
    y(py),
    name(pName)
{
   ID = CRC32(name.c_str(), name.length()); 
}
예제 #9
0
bool  LoadFile(char* filename)
{
    bool result=true;
    unsigned long size;
    result &= ReadFile(filename,pBufferforLoadedFile, &size, g_ucFill);
    g_uiFileChecksum=CRC32(pBufferforLoadedFile,g_ulFileSize);
    return result;
}
예제 #10
0
uint32 CRC32(const unsigned char* str, uint64 len)
{
	uint32 ulCRC = 0xFFFFFFFF; //Initilaize the CRC.

	for (uint64 x=0; x<len; x++)
		ulCRC = CRC32(str[x], ulCRC);

	return ~ulCRC; //Finalize the CRC and return.;
}
static unsigned int mmc_hash_crc32_combine(unsigned int seed, const void *key, unsigned int key_len) /*
	CRC32 hash {{{ */
{
	const char *p = (const char *)key, *end = p + key_len;
	while (p < end) {
		CRC32(seed, *(p++));
	}

  	return seed;
}
예제 #12
0
파일: column.c 프로젝트: binlu1981/ncbi-vdb
/* ValidateBuffer
 *  run checksum validation on buffer data
 *
 *  "buffer" [ IN ] - returned blob buffer from ReadAll
 *
 *  "cs_data" [ IN ] and "cs_data_size" [ IN ] - returned checksum data from ReadAll
 */
static
rc_t KColumnBlobValidateBufferCRC32 ( const void * buffer, size_t size, uint32_t cs )
{
    uint32_t crc32 = CRC32 ( 0, buffer, size );

    if ( cs != crc32 )
        return RC ( rcDB, rcBlob, rcValidating, rcBlob, rcCorrupt );

    return 0;
}
예제 #13
0
static int
fcoe_crc_verify(fcoe_frame_t *frm)
{
	uint32_t crc;
	uint8_t *crc_array = FRM2FMI(frm)->fmi_fft->fft_crc;
	uint32_t crc_from_frame = ~(crc_array[0] | (crc_array[1] << 8) |
	    (crc_array[2] << 16) | (crc_array[3] << 24));
	CRC32(crc, frm->frm_fc_frame, frm->frm_fc_frame_size, -1U, crc32_table);
	return (crc == crc_from_frame ? FCOE_SUCCESS : FCOE_FAILURE);
}
예제 #14
0
파일: mcch.c 프로젝트: jimrobinson/Lua-MCCH
unsigned int mc_hash_crc32(const char *key, int key_len)
{
	unsigned int crc = ~0;
	int i;

	for (i = 0; i < key_len; i++)
		CRC32(crc, key[i]);

	return ~crc;
}
예제 #15
0
void sector_update_tiles_checksum(int sector)
{
	char temp[16];
	int fy=(sector<<2)/tile_map_size_y<<2;
	int fx=(sector<<2)%tile_map_size_x;
	int i,j,k=0;
	for(i=fx;i<fx+4;i++)
		for(j=fy;j<fy+4;j++)
			temp[k++]=tile_map[(j*tile_map_size_x)+i];
	sectors[sector].tiles_checksum=CRC32(temp, 16);
}
예제 #16
0
static inline int GetInterfaceHash(const char *hash)
{
	int key = 0;
	if ((!hash) || (strlen(hash) <= 0)) {
		return 0;
	}
	if ((key = (int)CRC32(0L, (void*)hash, strlen(hash))) == 0) {
		return 0;
	}
	return (key);
}
예제 #17
0
int RageFileObj::Write( const void *pBuffer, size_t iBytes )
{
	int iRet = WriteInternal( pBuffer, iBytes );
	if( iRet != -1 )
	{
		m_iFilePos += iRet;
		if( m_bCRC32Enabled )
			CRC32( m_iCRC32, pBuffer, iBytes );
	}
	return iRet;
}
예제 #18
0
void main (int argc,char **argv) {
    /* argc = number of parameters from DOS + 1 */
    /* argv[1] is first parameter from DOS */

    puts("RACDK - Test CRC-32 routine/demonstration\n        ");
    if (argc==2) printf("The 32-bit CRC of '%s' is 0x%lx\n",
                            argv[1], CRC32(argv[1], strlen(argv[1])));
    else
        puts("Syntax: TESTCRC.EXE string\n");
    while(!kbhit()) TimeSlice();
}
예제 #19
0
bool threadCompareFileAndChip(int Index)
{
    bool result = true;
//    bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index);

//    if(is_greater_than_5_0_0)
//        SetLEDOnOff(SITE_BUSY,Index);

    SetIOMode(false,Index);

    if(g_ulFileSize==0)
        result = false;

    if( result && (!ValidateProgramParameters(Index)) )
        result = false;

    if( result )
    {
        ReadChip(DownloadAddrRange,Index);

        size_t offset = min(DownloadAddrRange.length,g_ulFileSize);
        unsigned int crcFile = CRC32(pBufferforLoadedFile,offset);
        unsigned int crcChip = CRC32(pBufferForLastReadData,offset);
        unsigned int i=0;
        #if 0
        for(i=0; i<10; i++)
        {
            if(pBufferforLoadedFile[i] != pBufferForLastReadData[i])
                printf("Data deferent at %X, pBufferforLoadedFile[i]=%x,pBufferForLastReadData[i]=%x\r\n",i,pBufferforLoadedFile[i],pBufferForLastReadData[i]);
        }
        #endif

        result = (crcChip == crcFile);
    }

//    if(is_greater_than_5_0_0)
//        SetLEDOnOff(result? SITE_OK:SITE_ERROR,Index);

    g_is_operation_successful = result;
    return result;
}
예제 #20
0
파일: crc32.c 프로젝트: thecocce/flaswf
unsigned int scws_crc32(const char *str)
{
    unsigned int crc = ~0;
    unsigned char *p = (unsigned char *) str;

    while (*p != '\0')
    {
        CRC32(crc, *p);
        p++;
    }
    return ~crc;
}
예제 #21
0
// encrypt string using KeyX, return encoded string as ASCII or NULL
LPSTR __cdecl cpp_encrypt(pCNTX ptr, LPCSTR szPlainMsg)
{
	ptr->error = ERROR_NONE;
	pSIMDATA p = (pSIMDATA)ptr->pdata;

	BYTE dataflag = 0;
	size_t slen = strlen(szPlainMsg);

	LPSTR szMsg;
	if (ptr->features & FEATURES_GZIP) {
		size_t clen;
		szMsg = (LPSTR)cpp_gzip((BYTE*)szPlainMsg, slen, clen);
		if (clen >= slen) {
			free(szMsg);
			szMsg = _strdup(szPlainMsg);
		}
		else {
			slen = clen;
			dataflag |= DATA_GZIP;
		}
	}
	else szMsg = _strdup(szPlainMsg);

	string ciphered;

	CBC_Mode<AES>::Encryption enc(p->KeyX, Tiger::DIGESTSIZE, IV);
	StreamTransformationFilter cbcEncryptor(enc, new StringSink(ciphered));

	cbcEncryptor.Put((PBYTE)szMsg, slen);
	cbcEncryptor.MessageEnd();

	free(szMsg);

	unsigned clen = (unsigned)ciphered.length();
	if (ptr->features & FEATURES_CRC32) {
		BYTE crc32[CRC32::DIGESTSIZE];
		memset(crc32, 0, sizeof(crc32));
		CRC32().CalculateDigest(crc32, (BYTE*)ciphered.data(), clen);
		ciphered.insert(0, (LPSTR)&crc32, CRC32::DIGESTSIZE);
		ciphered.insert(0, (LPSTR)&clen, 2);
	}
	if (ptr->features & FEATURES_GZIP)
		ciphered.insert(0, (LPSTR)&dataflag, 1);

	clen = (unsigned)ciphered.length();
	if (ptr->features & FEATURES_BASE64)
		replaceStr(ptr->tmp, mir_base64_encode((PBYTE)ciphered.data(), clen));
	else
		replaceStr(ptr->tmp, base16encode(ciphered.data(), clen));

	return ptr->tmp;
}
예제 #22
0
static
rc_t CC refseq_meta_stats( void *self, const VXformInfo *info, int64_t row_id,
                             VRowResult *rslt, uint32_t argc, const VRowData argv [] )
{
    rc_t rc = 0;
    KMDataNode* node;
    refseq_meta_stats_data* data = self;
    uint64_t i, seq_len = argv[0].u.data.elem_count;
    const INSDC_4na_bin * seq = argv[0].u.data.base;
   
    seq +=  argv[0].u.data.first_elem;

    assert(data != NULL);

    if( data->buf_sz < seq_len ) {
        char* x = realloc(data->buf, seq_len);
        if( x == NULL ) {
            rc = RC(rcVDB, rcFunction, rcUpdating, rcMemory, rcExhausted);
        } else {
            data->buf = x;
            data->buf_sz = seq_len;
        }
    }
    for(i = 0; rc == 0 && i < seq_len; i++) {
        data->buf[i] = INSDC_4na_map_CHARSET[seq[i]];
    }
    if( rc == 0 && (rc = KMDataNodeOpenNodeUpdate(data->stats, &node, "TOTAL_SEQ_LEN")) == 0 ) {
        if( data->total_seq_len + seq_len < data->total_seq_len ) {
            rc = RC(rcVDB, rcFunction, rcUpdating, rcMetadata, rcOutofrange);
        } else {
            data->total_seq_len += seq_len;
            rc = KMDataNodeWriteB64(node, &data->total_seq_len);
        }
        KMDataNodeRelease(node);
    }
    if( rc == 0 && (rc = KMDataNodeOpenNodeUpdate(data->stats, &node, "CRC32")) == 0 ) {
        data->crc32 = CRC32(data->crc32, data->buf, seq_len);
        rc = KMDataNodeWriteB32(node, &data->crc32);
        KMDataNodeRelease(node);
    }
    if( rc == 0 && (rc = KMDataNodeOpenNodeUpdate(data->stats, &node, "MD5")) == 0 ) {
        uint8_t digest[16];
        MD5State md5;
        MD5StateAppend(&data->md5, data->buf, seq_len);
        memcpy(&md5, &data->md5, sizeof(md5));
        MD5StateFinish(&md5, digest);
        rc = KMDataNodeWrite(node, digest, sizeof(digest));
        KMDataNodeRelease(node);
    }
    return rc;
}
예제 #23
0
int RageFileObj::Write( const void *pBuffer, size_t iBytes )
{
	if( m_pWriteBuffer != NULL )
	{
		/* If the file position has moved away from the write buffer, or the
		 * incoming data won't fit in the buffer, flush. */
		if( m_iWriteBufferPos+m_iWriteBufferUsed != m_iFilePos || m_iWriteBufferUsed + (int)iBytes > m_iWriteBufferSize )
		{
			int iRet = EmptyWriteBuf();
			if( iRet == -1 )
				return iRet;
		}

		if( m_iWriteBufferUsed + (int)iBytes <= m_iWriteBufferSize )
		{
			memcpy( m_pWriteBuffer+m_iWriteBufferUsed, pBuffer, iBytes );
			m_iWriteBufferUsed += iBytes;
			m_iFilePos += iBytes;
			if( m_bCRC32Enabled )
				CRC32( m_iCRC32, pBuffer, iBytes );
			return iBytes;
		}

		/* We're writing a lot of data, and it won't fit in the buffer.  We already
		 * flushed above, so m_iWriteBufferUsed; fall through and write the block normally. */
		ASSERT_M( m_iWriteBufferUsed == 0, ssprintf("%i", m_iWriteBufferUsed) );
	}

	int iRet = WriteInternal( pBuffer, iBytes );
	if( iRet != -1 )
	{
		m_iFilePos += iRet;
		if( m_bCRC32Enabled )
			CRC32( m_iCRC32, pBuffer, iBytes );
	}
	return iRet;
}
예제 #24
0
int
efe_m_multicst(void *arg, boolean_t add, const uint8_t *macaddr)
{
	efe_t *efep = arg;
	uint32_t val;
	int index;
	int bit;
	boolean_t restart = B_FALSE;

	mutex_enter(&efep->efe_intrlock);
	mutex_enter(&efep->efe_txlock);

	if (efep->efe_flags & FLAG_SUSPENDED) {
		mutex_exit(&efep->efe_txlock);
		mutex_exit(&efep->efe_intrlock);
		return (0);
	}

	CRC32(val, macaddr, ETHERADDRL, -1U, crc32_table);
	val %= MCHASHL;

	index = val / MCHASHSZ;
	bit = 1U << (val % MCHASHSZ);

	if (add) {
		efep->efe_mccount[val]++;
		if (efep->efe_mccount[val] == 1) {
			efep->efe_mchash[index] |= bit;
			restart = B_TRUE;
		}

	} else {
		efep->efe_mccount[val]--;
		if (efep->efe_mccount[val] == 0) {
			efep->efe_mchash[index] &= ~bit;
			restart = B_TRUE;
		}
	}

	if (restart && efep->efe_flags & FLAG_RUNNING) {
		efe_restart(efep);
	}

	mutex_exit(&efep->efe_txlock);
	mutex_exit(&efep->efe_intrlock);

	return (0);
}
예제 #25
0
int OpenMessageQueue(const char *name)
{
    int key;
    int queue;

    if ((name == NULL) || (strlen(name) <= 0))
        return -EINVAL;

    if ((key = (int)CRC32(0L, (void*)name, strlen(name))) == 0)
        return -EINVAL;

    if ((queue = msgget((key_t)key, 0)) < 0)
        return -errno;

    return queue;
}
예제 #26
0
파일: buffer.c 프로젝트: mrDIMAS/OldTech
bool Buffer_LoadFile( TBuffer * buf, const char * fileName, unsigned int * crc32 ) {
    FILE * file = fopen( fileName, "rb" );
    if( !file ) {
        return false;
    };
    fseek( file, 0, SEEK_END );
    buf->size = ftell( file );
    fseek( file, 0, SEEK_SET );
    buf->data = Memory_Allocate( buf->size );
    fread( buf->data, buf->size, 1, file );
    if( crc32 ) {
        *crc32 = CRC32( 0, buf->data, buf->size );
    }
    buf->pointer = 0;
    buf->file = NULL;
    fclose( file );
    return true;
}
예제 #27
0
파일: column.c 프로젝트: binlu1981/ncbi-vdb
/* KColumnBlobValidate
 *  runs checksum validation on unmodified blob
 */
static
rc_t KColumnBlobValidateCRC32 ( const KColumnBlob *self )
{
    rc_t rc;
    const KColumn *col = self -> col;

    uint8_t buffer [ 8 * 1024 ];
    size_t to_read, num_read, total, size;

    uint32_t cs, crc32 = 0;

    /* calculate checksum */
    for ( size = self -> loc . u . blob . size, total = 0; total < size; total += num_read )
    {
        to_read = size - total;
        if ( to_read > sizeof buffer )
            to_read = sizeof buffer;

        rc = KColumnDataRead ( & col -> df,
            & self -> pmorig, total, buffer, to_read, & num_read );
        if ( rc != 0 )
            return rc;
        if ( num_read == 0 )
            return RC ( rcDB, rcBlob, rcValidating, rcTransfer, rcIncomplete );

        crc32 = CRC32 ( crc32, buffer, num_read );
    }

    /* read stored checksum */
    rc = KColumnDataRead ( & col -> df,
        & self -> pmorig, size, & cs, sizeof cs, & num_read );
    if ( rc != 0 )
        return rc;
    if ( num_read != sizeof cs )
        return RC ( rcDB, rcBlob, rcValidating, rcTransfer, rcIncomplete );

    if ( self -> bswap )
        cs = bswap_32 ( cs );

    if ( cs != crc32 )
        return RC ( rcDB, rcBlob, rcValidating, rcBlob, rcCorrupt );

    return 0;
}
예제 #28
0
DWORD CalcFileCrc(FILE* lpFile)
{
	const int nBuffLen = 500;
	BYTE cBuff[nBuffLen];
	DWORD dwCRC = 0;

	while ( TRUE )
	{
		size_t dwRead = fread(cBuff, 1, nBuffLen, lpFile);
		if ( dwRead == 0 )
		{
			break;
		}

		dwCRC = CRC32(dwCRC, cBuff, (DWORD)dwRead);
	}

	return dwCRC;
}
예제 #29
0
파일: pcn.c 프로젝트: apprisi/illumos-gate
static int
pcn_m_multicast(void *arg, boolean_t add, const uint8_t *macaddr)
{
	pcn_t		*pcnp = (pcn_t *)arg;
	int		index;
	uint32_t	crc;
	uint16_t	bit;
	uint16_t	newval, oldval;

	/*
	 * PCNet uses the upper 6 bits of the CRC of the macaddr
	 * to index into a 64bit mask
	 */
	CRC32(crc, macaddr, ETHERADDRL, -1U, crc32_table);
	crc >>= 26;
	index = crc / 16;
	bit = (1U << (crc % 16));

	mutex_enter(&pcnp->pcn_intrlock);
	mutex_enter(&pcnp->pcn_xmtlock);
	newval = oldval = pcnp->pcn_mctab[index];

	if (add) {
		pcnp->pcn_mccount[crc]++;
		if (pcnp->pcn_mccount[crc] == 1)
			newval |= bit;
	} else {
		pcnp->pcn_mccount[crc]--;
		if (pcnp->pcn_mccount[crc] == 0)
			newval &= ~bit;
	}
	if (newval != oldval) {
		pcnp->pcn_mctab[index] = newval;
		pcn_suspend(pcnp);
		pcn_csr_write(pcnp, PCN_CSR_MAR0 + index, newval);
		pcn_resume(pcnp);
	}

	mutex_exit(&pcnp->pcn_xmtlock);
	mutex_exit(&pcnp->pcn_intrlock);

	return (0);
}
예제 #30
0
void DataHash::Update(const void *Data,size_t DataSize)
{
#ifndef SFX_MODULE
  if (HashType==HASH_RAR14)
    CurCRC32=Checksum14((ushort)CurCRC32,Data,DataSize);
#endif
  if (HashType==HASH_CRC32)
    CurCRC32=CRC32(CurCRC32,Data,DataSize);

  if (HashType==HASH_BLAKE2)
  {
#ifdef RAR_SMP
    if (MaxThreads>1 && ThPool==NULL)
      ThPool=CreateThreadPool();
    blake2ctx.ThPool=ThPool;
    blake2ctx.MaxThreads=MaxThreads;
#endif
    blake2sp_update( &blake2ctx, (byte *)Data, DataSize);
  }
}