.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Required to disable full justification in groff 1.23.0. .if n .ds AD l .\" ======================================================================== .\" .IX Title "Crypt::Checksum::CRC32 3" .TH Crypt::Checksum::CRC32 3 2026-08-10 "perl v5.42.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Crypt::Checksum::CRC32 \- Compute CRC32 checksum .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& ### Functional interface: \& use Crypt::Checksum::CRC32 \*(Aq:all\*(Aq; \& \& # calculate CRC32 checksum from string/buffer \& my $data = \*(Aqdata string\*(Aq; \& my $checksum_raw = crc32_data($data); \& my $checksum_hex = crc32_data_hex($data); \& my $checksum_int = crc32_data_int($data); \& # or from file \& my $checksum_file_raw = crc32_file(\*(Aqfilename.dat\*(Aq); \& my $checksum_file_hex = crc32_file_hex(\*(Aqfilename.dat\*(Aq); \& my $checksum_file_int = crc32_file_int(\*(Aqfilename.dat\*(Aq); \& # or from filehandle \& my $filehandle = ...; # existing binary\-mode filehandle \& my $checksum_fh_raw = crc32_file($filehandle); \& my $checksum_fh_hex = crc32_file_hex($filehandle); \& my $checksum_fh_int = crc32_file_int($filehandle); \& \& ### OO interface: \& use Crypt::Checksum::CRC32; \& \& my $d = Crypt::Checksum::CRC32\->new; \& $d\->add(\*(Aqany data\*(Aq); \& $d\->add(\*(Aqanother data\*(Aq); \& my $checksum_raw = $d\->digest; # raw 4 bytes \& my $checksum_hex = $d\->hexdigest; # hexadecimal form \& my $checksum_int = $d\->intdigest; # 32\-bit unsigned integer \& \& # or checksum a file instead \& my $checksum_file_raw = Crypt::Checksum::CRC32\->new\->addfile(\*(Aqfilename.dat\*(Aq)\->digest; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Computes CRC\-32 checksums using the ISO 3309 / ITU\-T V.42 polynomial (\f(CW0xEDB88320\fR, also known as CRC\-32/ISO\-HDLC). This is the same variant used by Ethernet (IEEE 802.3), PKZIP, gzip, and PNG. .PP \&\fIUpdated: v0.057\fR .SH EXPORT .IX Header "EXPORT" Nothing is exported by default. .PP You can export selected functions: .PP .Vb 1 \& use Crypt::Checksum::CRC32 qw(crc32_data crc32_data_hex crc32_data_int crc32_file crc32_file_hex crc32_file_int); .Ve .PP Or all of them at once: .PP .Vb 1 \& use Crypt::Checksum::CRC32 \*(Aq:all\*(Aq; .Ve .SH FUNCTIONS .IX Header "FUNCTIONS" .SS crc32_data .IX Subsection "crc32_data" Returns the checksum as raw octets. .PP .Vb 3 \& my $checksum_raw = crc32_data(\*(Aqdata string\*(Aq); \& #or \& my $checksum_raw = crc32_data(\*(Aqany data\*(Aq, \*(Aqmore data\*(Aq, \*(Aqeven more data\*(Aq); .Ve .SS crc32_data_hex .IX Subsection "crc32_data_hex" Returns checksum as a hexadecimal string. .PP .Vb 3 \& my $checksum_hex = crc32_data_hex(\*(Aqdata string\*(Aq); \& #or \& my $checksum_hex = crc32_data_hex(\*(Aqany data\*(Aq, \*(Aqmore data\*(Aq, \*(Aqeven more data\*(Aq); .Ve .SS crc32_data_int .IX Subsection "crc32_data_int" Returns checksum as unsigned 32\-bit integer. .PP .Vb 3 \& my $checksum_int = crc32_data_int(\*(Aqdata string\*(Aq); \& #or \& my $checksum_int = crc32_data_int(\*(Aqany data\*(Aq, \*(Aqmore data\*(Aq, \*(Aqeven more data\*(Aq); .Ve .PP Each \f(CW\*(C`crc32_data*\*(C'\fR function converts its data arguments to bytes using Perl\*(Aqs usual scalar stringification. Defined scalars, including numbers and string\-overloaded objects, are accepted. \f(CW\*(C`undef\*(C'\fR is treated as an empty string and may emit Perl\*(Aqs usual "uninitialized value" warning. .SS crc32_file .IX Subsection "crc32_file" Returns the checksum as raw octets. .PP .Vb 4 \& my $checksum_raw = crc32_file(\*(Aqfilename.dat\*(Aq); \& #or \& my $filehandle = ...; # existing binary\-mode filehandle \& my $checksum_raw = crc32_file($filehandle); .Ve .SS crc32_file_hex .IX Subsection "crc32_file_hex" Returns checksum as a hexadecimal string. .PP .Vb 4 \& my $checksum_hex = crc32_file_hex(\*(Aqfilename.dat\*(Aq); \& #or \& my $filehandle = ...; # existing binary\-mode filehandle \& my $checksum_hex = crc32_file_hex($filehandle); .Ve .SS crc32_file_int .IX Subsection "crc32_file_int" Returns checksum as unsigned 32\-bit integer. .PP .Vb 4 \& my $checksum_int = crc32_file_int(\*(Aqfilename.dat\*(Aq); \& #or \& my $filehandle = ...; # existing binary\-mode filehandle \& my $checksum_int = crc32_file_int($filehandle); .Ve .SH METHODS .IX Header "METHODS" Unless noted otherwise, assume \f(CW$d\fR is an existing checksum object created via \&\f(CW\*(C`new\*(C'\fR. .SS new .IX Subsection "new" Constructor, returns a reference to the checksum object. .PP .Vb 1 \& my $d = Crypt::Checksum::CRC32\->new; .Ve .SS clone .IX Subsection "clone" Creates a copy of the checksum object state and returns a reference to the copy. .PP .Vb 1 \& $d\->clone(); .Ve .SS reset .IX Subsection "reset" Reinitialize the checksum object state and returns a reference to the checksum object. .PP .Vb 1 \& $d\->reset(); .Ve .SS add .IX Subsection "add" All arguments are appended to the message we calculate checksum for. The return value is the checksum object itself. .PP Each argument is converted to bytes using Perl\*(Aqs usual scalar stringification. Defined scalars, including numbers and string\-overloaded objects, are accepted. \&\f(CW\*(C`undef\*(C'\fR is treated as an empty string and may emit Perl\*(Aqs usual "uninitialized value" warning. .PP .Vb 3 \& $d\->add(\*(Aqany data\*(Aq); \& #or \& $d\->add(\*(Aqany data\*(Aq, \*(Aqmore data\*(Aq, \*(Aqeven more data\*(Aq); .Ve .SS addfile .IX Subsection "addfile" The content of the file (or filehandle) is appended to the message we calculate checksum for. The return value is the checksum object itself. .PP .Vb 4 \& $d\->addfile(\*(Aqfilename.dat\*(Aq); \& #or \& my $filehandle = ...; # existing binary\-mode filehandle \& $d\->addfile($filehandle); .Ve .PP \&\fBNote:\fR The filehandle must be in binary mode before you pass it to \f(CWaddfile()\fR. .SS digest .IX Subsection "digest" Returns the binary checksum (raw bytes). This method does not alter the object state, so you can call it repeatedly and continue with \f(CWadd()\fR or \f(CWaddfile()\fR afterwards. .PP .Vb 1 \& my $result_raw = $d\->digest(); .Ve .SS hexdigest .IX Subsection "hexdigest" Returns the checksum encoded as a hexadecimal string. Like \f(CWdigest()\fR, this method does not alter the object state. .PP .Vb 1 \& my $result_hex = $d\->hexdigest(); .Ve .SS intdigest .IX Subsection "intdigest" Returns the checksum encoded as unsigned 32\-bit integer. Like \f(CWdigest()\fR, this method does not alter the object state. .PP .Vb 1 \& my $result_int = $d\->intdigest(); .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" .IP \(bu 4 CryptX .IP \(bu 4