.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' '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 turned on, 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. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Rhash 3pm" .TH Rhash 3pm "2012-01-09" "perl v5.14.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" Rhash \- Perl extension for LibRHash Hash library .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Rhash; \& \& my $msg = "a message text"; \& print "MD5 = " . Rhash\->new(Rhash::MD5)\->update($msg)\->hash() . "\en"; \& \& # more complex example \- calculate two hash functions simultaniously \& my $r = Rhash\->new(Rhash::MD5 | Rhash::SHA1); \& $r\->update("a message text")\->update(" another message"); \& print "MD5 = ". $r\->hash(Rhash::MD5) . "\en"; \& print "SHA1 = ". $r\->hash(Rhash::SHA1) . "\en"; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Rhash module is an object-oriented interface to the LibRHash library, which allows one to simultaniously calculate several hash functions for a file or a text message. .SH "SUPPORTED ALGORITHMS" .IX Header "SUPPORTED ALGORITHMS" The module supports the following hashing algorithms: \&\s-1CRC32\s0, \s-1MD4\s0, \s-1MD5\s0, \s-1SHA1\s0, \s-1SHA256\s0, \s-1SHA512\s0, \&\s-1AICH\s0, \s-1ED2K\s0, Tiger, \s-1DC++\s0 \s-1TTH\s0, BitTorrent \s-1BTIH\s0, \s-1GOST\s0 R 34.11\-94, \s-1RIPEMD\-160\s0, \&\s-1HAS\-160\s0, EDON-R 256/512, Whirlpool and Snefru\-128/256. .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" Creates and returns new Rhash object. .PP .Vb 2 \& my $r = Rhash\->new($hash_id); \& my $p = new Rhash($hash_id); # alternative way to call the constructor .Ve .PP The \f(CW$hash_id\fR parameter can be union (via bitwise \s-1OR\s0) of any of the following bit-flags: .PP .Vb 10 \& Rhash::CRC32, \& Rhash::MD4, \& Rhash::MD5, \& Rhash::SHA1, \& Rhash::TIGER, \& Rhash::TTH, \& Rhash::BTIH, \& Rhash::ED2K, \& Rhash::AICH, \& Rhash::WHIRLPOOL, \& Rhash::RIPEMD160, \& Rhash::GOST, \& Rhash::GOST_CRYPTOPRO, \& Rhash::HAS160, \& Rhash::SNEFRU128, \& Rhash::SNEFRU256, \& Rhash::SHA224, \& Rhash::SHA256, \& Rhash::SHA384, \& Rhash::SHA512, \& Rhash::EDONR256, \& Rhash::EDONR512 .Ve .PP Also the Rhash::ALL bit mask is the union of all listed bit-flags. So the object created via Rhash\->new(Rhash::ALL) calculates all supported hash functions for the same data. .SH "COMPUTING HASHES" .IX Header "COMPUTING HASHES" .ie n .IP "$rhash\->update( $msg )" 4 .el .IP "\f(CW$rhash\fR\->update( \f(CW$msg\fR )" 4 .IX Item "$rhash->update( $msg )" Calculates hashes of the \f(CW$msg\fR string. The method can be called repeatedly with chunks of the message to be hashed. It returns the \f(CW$rhash\fR object itself allowing the following construct: .Sp .Vb 1 \& $rhash = Rhash\->new(Rhash::MD5)\->update( $chunk1 )\->update( $chunk2 ); .Ve .ie n .IP "$rhash\->update_file( $file_path, $start, $size )" 4 .el .IP "\f(CW$rhash\fR\->update_file( \f(CW$file_path\fR, \f(CW$start\fR, \f(CW$size\fR )" 4 .IX Item "$rhash->update_file( $file_path, $start, $size )" .PD 0 .ie n .IP "$rhash\->update_fd( $fd, $start, $size )" 4 .el .IP "\f(CW$rhash\fR\->update_fd( \f(CW$fd\fR, \f(CW$start\fR, \f(CW$size\fR )" 4 .IX Item "$rhash->update_fd( $fd, $start, $size )" .PD Calculate a hash of the file (or its part) specified by \f(CW$file_path\fR or a file descriptor \f(CW$fd\fR. The update_fd method doesn't close the \f(CW$fd\fR, leaving the file position after the hashed block. The optional \f(CW$start\fR and \f(CW$size\fR specify the block of the file to hash. No error is reported if the \f(CW$size\fR is grater than the number of the unread bytes left in the file. .Sp Returns the number of characters actually read, 0 at end of file, or undef if there was an error (in the latter case $! is also set). .Sp .Vb 9 \& use Rhash; \& my $r = new Rhash(Rhash::SHA1); \& open(my $fd, "<", "input.txt") or die "cannot open < input.txt: $!"; \& while ((my $n = $r\->update_fd($fd, undef, 1024) != 0) { \& print "$n bytes hashed. The SHA1 hash is " . $r\->final()\->hash() . "\en"; \& $r\->reset(); \& } \& defined($n) or die "read error for input.txt: $!"; \& close($fd); .Ve .ie n .IP "$rhash\->\fIfinal()\fR" 4 .el .IP "\f(CW$rhash\fR\->\fIfinal()\fR" 4 .IX Item "$rhash->final()" Finishes calculation for all data buffered by updating methods and stops hash calculation. The function is called automatically by any of the \&\f(CW$rhash\fR\->hash*() methods if the \fIfinal()\fR call was skipped. .ie n .IP "$rhash\->\fIreset()\fR" 4 .el .IP "\f(CW$rhash\fR\->\fIreset()\fR" 4 .IX Item "$rhash->reset()" Resets the \f(CW$rhash\fR object to the initial state. .ie n .IP "$rhash\->\fIhashed_length()\fR" 4 .el .IP "\f(CW$rhash\fR\->\fIhashed_length()\fR" 4 .IX Item "$rhash->hashed_length()" Returns the total length of the hashed message. .ie n .IP "$rhash\->\fIhash_id()\fR" 4 .el .IP "\f(CW$rhash\fR\->\fIhash_id()\fR" 4 .IX Item "$rhash->hash_id()" Returns the hash mask, the \f(CW$rhash\fR object was constructed with. .SH "FORMATING HASH VALUE" .IX Header "FORMATING HASH VALUE" Computed hash can be formated as a hexadecimal string (in the forward or reverse byte order), a base32/base64\-encoded string or as raw binary data. .ie n .IP "$rhash\->hash( $hash_id )" 4 .el .IP "\f(CW$rhash\fR\->hash( \f(CW$hash_id\fR )" 4 .IX Item "$rhash->hash( $hash_id )" Returns the hash string in the default format, which can be hexadecimal or base32. Actually the method is equvalent of .Sp .Vb 2 \& (Rhash::is_base32($hash_id) ? $rhash\->hash_base32($hash_id) : \& $rhash\->hash_hex($hash_id)) .Ve .Sp If the optional \f(CW$hash_id\fR parameter is omited or zero, then the method returns the hash for the algorithm contained in \f(CW$rhash\fR with the lowest identifier. .ie n .IP "$rhash\->hash_hex( $hash_id )" 4 .el .IP "\f(CW$rhash\fR\->hash_hex( \f(CW$hash_id\fR )" 4 .IX Item "$rhash->hash_hex( $hash_id )" Returns a specified hash in the hexadecimal format. .ie n .IP "$rhash\->hash_rhex( $hash_id )" 4 .el .IP "\f(CW$rhash\fR\->hash_rhex( \f(CW$hash_id\fR )" 4 .IX Item "$rhash->hash_rhex( $hash_id )" Returns a hexadecimal string of the hash in reversed bytes order. Some programs prefer to output \s-1GOST\s0 hash in this format. .ie n .IP "$rhash\->hash_base32( $hash_id )" 4 .el .IP "\f(CW$rhash\fR\->hash_base32( \f(CW$hash_id\fR )" 4 .IX Item "$rhash->hash_base32( $hash_id )" Returns a specified hash in the base32 format. .ie n .IP "$rhash\->hash_base64( $hash_id )" 4 .el .IP "\f(CW$rhash\fR\->hash_base64( \f(CW$hash_id\fR )" 4 .IX Item "$rhash->hash_base64( $hash_id )" Returns a specified hash in the base64 format. .ie n .IP "$rhash\->magnet_link( $filename, $hash_mask )" 4 .el .IP "\f(CW$rhash\fR\->magnet_link( \f(CW$filename\fR, \f(CW$hash_mask\fR )" 4 .IX Item "$rhash->magnet_link( $filename, $hash_mask )" Returns the magnet link containing the computed hashes, filesize, and, optionaly, \f(CW$filename\fR. The \f(CW$filename\fR (if specified) is URL-encoded, by converting special characters into the % form. The optional parameter \f(CW$hash_mask\fR can limit which hash values to put into the link. .SH "STATIC INFORMATION METHODS" .IX Header "STATIC INFORMATION METHODS" .IP "\fIRhash::count()\fR" 4 .IX Item "Rhash::count()" Returns the number of supported hash algorithms .IP "Rhash::is_base32($hash_id)" 4 .IX Item "Rhash::is_base32($hash_id)" Returns nonzero if default output format is Base32 for the hash function specified by \f(CW$hash_id\fR. Retruns zero if default format is hexadecimal. .IP "Rhash::get_digest_size($hash_id)" 4 .IX Item "Rhash::get_digest_size($hash_id)" Returns the size in bytes of raw binary hash of the specified hash algorithm. .IP "Rhash::get_hash_length($hash_id)" 4 .IX Item "Rhash::get_hash_length($hash_id)" Returns the length of a hash string in default output format for the specified hash algorithm. .IP "Rhash::get_name($hash_id)" 4 .IX Item "Rhash::get_name($hash_id)" Returns the name of the specified hash algorithm. .SH "ALTERNATIVE WAY TO COMPUTE HASH" .IX Header "ALTERNATIVE WAY TO COMPUTE HASH" .ie n .IP "Rhash::msg($hash_id, $message)" 4 .el .IP "Rhash::msg($hash_id, \f(CW$message\fR)" 4 .IX Item "Rhash::msg($hash_id, $message)" Computes and returns a single hash (in its default format) of the \f(CW$message\fR by the selected hash algorithm. .Sp .Vb 2 \& use Rhash; \& print "SHA1( \*(Aqabc\*(Aq ) = " . Rhash::msg(Rhash::SHA1, "abc"); .Ve .SH "LICENSE" .IX Header "LICENSE" .Vb 6 \& Permission is hereby granted, free of charge, to any person obtaining a copy \& of this software and associated documentation files (the "Software"), to deal \& in the Software without restriction, including without limitation the rights \& to use, copy, modify, merge, publish, distribute, sublicense, and/or sell \& copies of the Software, and to permit persons to whom the Software is \& furnished to do so. \& \& The Software is distributed in the hope that it will be useful, but WITHOUT \& ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS \& FOR A PARTICULAR PURPOSE. Use this program at your own risk! .Ve