Intel® Integrated Performance Primitives Developer Guide and Reference

ID 790148
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

CRC32, CRC32C

Computes the CRC32 checksum for the source data buffer.

Syntax

IppStatus ippsCRC32_8u (const Ipp8u* pSrc, int srcLen, Ipp32u* pCRC32);

IppStatus ippsCRC32C_8u(const Ipp8u* pSrc, Ipp32u srcLen, Ipp32u* pCRC32C);

Include Files

ippdc.h

Domain Dependencies

Headers: ippcore.h, ippvm.h, ipps.h

Libraries: ippcore.lib, ippvm.lib, ipps.lib

Parameters

pSrc

Pointer to the source data buffer.

srcLen

Number of elements in the source data buffer.

pCRC32, pCRC32C

Pointer to the checksum value.

Description

These functions compute the checksum for srcLen elements of the source data buffer pSrc using different algorithms and stores it in the pCRC32 or pCRC32C respectively.

The function ippsCRC32 uses algorithm described in [Griff87], [Nel92], the function ippsCRC32C uses algorithm described in [Cast93].

These functions can be used to compute the accumulated value of the checksum for multiple buffers in the data stream by specifying as an input parameter the checksum value obtained in the preceding function call.

Return Values

ippStsNoErr

Indicates no error.

ippStsNullPtrErr

Indicates an error if the pSrc pointer is NULL.

ippStsSizeErr

Indicates an error if the length of the source vector is less than or equal to 0.

Example

The example below shows how to use the function ippsCRC32C_8u.

#include <iostream>
#include <iomanip>
#include "ipp.h"

using namespace std;

void crc32c_core( Ipp8u* src, Ipp32u src_len ) {
	Ipp32u crc32c = ~(Ipp32u)0;
	ippsCRC32C_8u( src, src_len, &crc32c );
	ippsSwapBytes_32u_I( &crc32c, 1 );
	cout << "0x" << setbase(16) << ~crc32c << endl;
}

int main() {
	Ipp8u buff[48] = { 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
		0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18,
		0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
	cout << "An iSCSI - SCSI Read (10) Command PDU: ";
	crc32c_core( buff, 48 );
	
	cout << "32 bytes of zeroes: ";
	for( int i = 0; i < 32; i++ ) buff[i] = 0;
	crc32c_core( buff, 32 );
	
	cout << "32 bytes of ones: ";
	for( int i = 0; i < 32; i++ ) buff[i] = 0xff;
	crc32c_core( buff, 32 );
	
	cout << "32 bytes of incrementing 00..1f: ";
	for( int i = 0; i < 32; i++ ) buff[i] = i;
	crc32c_core( buff, 32 );
	
	cout << "32 bytes of decrementing 1f..00: ";
	for( int i = 0; i < 32; i++ ) buff[i] = 31 - i;
	crc32c_core( buff, 32 );
	
	return 0;
}
Output: An iSCSI - SCSI Read (10) Command PDU: 0x563a96d9 32 bytes of zeroes: 0xaa36918a 32 bytes of ones: 0x43aba862 32 bytes of incrementing 00..1f: 0x4e79dd46 32 bytes of decrementing 1f..00: 0x5cdb3f11