Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CRC-32 implementation in java.util.zip.CRC32

Tags:

java

crc

crc32

Which CRC-32 algorithm is used in the Java CRC-32 class ? The java doc does not give any details. What is the polynomail used and the initial value for calculaton ?

like image 713
Dunxton Avatar asked Jan 25 '12 14:01

Dunxton


People also ask

What is CRC32 in Java?

public class CRC32 extends Object implements Checksum. A class that can be used to compute the CRC-32 of a data stream. Passing a null argument to a method in this class will cause a NullPointerException to be thrown.

What is CRC 32bit?

The ASCII and Binary OEM7 family and SMART2 message formats all contain a 32-bit CRC for data verification. This allows the user to ensure the data received (or transmitted) is valid with a high level of certainty. The C functions below may be implemented to generate the CRC of a block of data.

Is CRC32 faster than MD5?

Save this answer. Show activity on this post. If you want to check if two files are the same, CRC32 checksum is the way to go because it's faster than MD5. But be careful: CRC only reliably tells you if the binaries are different; it doesn't tell you if they're identical.


2 Answers

CRC-32 is a indicated in the package docs for java.util.zip to be specified in RFC 1952. RFC 1952 defines CRC32 as specified in ISO 3309 which I could not find a free copy of to link you to. However RFC 1952 also indicates that section 8.1.1.6.2 of ITU-T recommendation V.42 specifies the same implementation.

In partcular the polynomial being used is

x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
like image 88
Dev Avatar answered Sep 22 '22 17:09

Dev


According to the source:

Computes CRC32 data checksum of a data stream. The actual CRC32 algorithm is described in RFC 1952 (GZIP file format specification version 4.3). Can be used to get the CRC32 over a stream if used with checked input/output streams.

The RFC1952 can be found here, but presents a quite technical read.

The initial value for the CRC is 0xFFFFFFFF, and the CRC table is built the first time the class is loaded on the VM.

like image 34
Marcelo Avatar answered Sep 20 '22 17:09

Marcelo