pax_global_header 0000666 0000000 0000000 00000000064 13575211473 0014522 g ustar 00root root 0000000 0000000 52 comment=75716b45c21416c98c0ab2e3c2735b150e7afb03
RHash-1.3.9/ 0000775 0000000 0000000 00000000000 13575211473 0012541 5 ustar 00root root 0000000 0000000 RHash-1.3.9/.gitignore 0000664 0000000 0000000 00000000327 13575211473 0014533 0 ustar 00root root 0000000 0000000 /dist/rhash.spec
/dist/rhash.1.*
/dist/librhash.pc
/librhash/exports.sym
po/*.gmo
/rhash
/rhash_shared
/rhash_static
/librhash/test_shared
/librhash/test_static
config.mak
*.[ao]
*.exe
*.dll
*.def
*.so
*.so.0
*.log
RHash-1.3.9/COPYING 0000664 0000000 0000000 00000001340 13575211473 0013572 0 ustar 00root root 0000000 0000000
BSD Zero Clause License
Copyright (c) 2005, Aleksey Kravchenko
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
RHash-1.3.9/ChangeLog 0000664 0000000 0000000 00000053530 13575211473 0014321 0 ustar 00root root 0000000 0000000 Sat 14 Dec 2019 Aleksey
* === Version 1.3.9 ===
Sun 08 Dec 2019 Aleksey
* add uk translations
Thu 28 Nov 2019 Aleksey
* change project license to BSD Zero Clause License
Mon 18 Nov 2019 Aleksey
* new printf-format modifier '%u' to print url-encoded filename, path or hash
Fri 15 Nov 2019 Aleksey
* Bugfix: btih in magnet links shall be hex-encoded
Tue 12 Nov 2019 Aleksey
* correctly align UTF8 file paths, while printing verification results
* respect UTF8 BOM when updating or verifying a hash file
Thu 17 Oct 2019 Aleksey
* print a new-line after ed2k link, when --ed2k-link option is passed
Mon 14 Oct 2019 Aleksey
* exit on output errors with exit_code = 2
* change option --update= to update the specified file
Sun 29 Sep 2019 Aleksey
* make short option '-P' to be an alias for --percents
Tue 02 Jul 2019 Aleksey
* change %{mtime} format to 'YYYY-MM-DD hh:mm:ss'
Wed 26 Jun 2019 Aleksey
* Bugfix: --sysconfdir was ignored while searching for config on Linux
Tue 25 Jun 2019 Aleksey
* support verification of base64-formated hash sums
* add formatting options: --hex, --base32, -b/--base64
Mon 17 Jun 2019 Aleksey
* Bugfix: properly handle symlinks on the command line
Mon 04 Feb 2019 Aleksey
* === Version 1.3.8 ===
Wed Jan 30 2019 Aleksey
* rename Windows encoding options: --ansi to --win, --oem to --dos
Mon Jan 28 2019 Aleksey
* support GOST R 34.11-2012 hash function
* changed the short option `-G' to be alias of --gost12-256
* changed printf format token `%g' to be alias of %{gost12-256}
Sat Dec 22 2018 Aleksey
* === Version 1.3.7 ===
* new option `--message==' to calculate a hash for string
* changed magnet link short option from '-m' to '-g'
Sat Sep 29 2018 Aleksey
* Bugfix: `--file-list=-' shall read a file list from stdin
Tue Sep 11 2018 Aleksey
* CRC32C hash function supported, option --crc32c
* speedup CRC32 hash function
Wed Mar 14 2018 Aleksey
* === Version 1.3.6 ===
* support --file-list option
Sun Mar 11 2018 And Sch
* librhash: speedup sha3
Sun Feb 18 2018 Aleksey
* Bugfix: fix --follow option
Mon Jan 29 2018 J. Peter Mugaas
* better MSYS and CygWin support
Fri Jan 26 2018 Aleksey
* configuration script
Mon Sep 4 2017 Aleksey
* Bugfix: broken binary hash output
Mon Aug 28 2017 Aleksey
* Bugfix: fix running on WinXP
Mon Aug 14 2017 Aleksey
* === Version 1.3.5 ===
* look for locales directory at PROGRAM_DIRECTORY\locale on Windows
* look for config at PROGRAM_DIRECTORY\rhashrc on Windows
Fri Aug 4 2017 Aleksey
* support LibRhash bindings to PHP7
Sun Jul 30 2017 Aleksey
* Bugfix: illegal instruction error on macOS
Sat Jul 29 2017 Aleksey
* improve utf-8 support on Windows
Thu Jul 27 2017 Aleksey
* Bugfix: fix access to long paths on Windows
Mon Jul 17 2017 Aleksey
* add ca, fr, ro translations
Sun Jul 16 2017 Darío Hereñú
* full Spanish translation
Mon Jul 10 2017 James Le Cuirot
* correct build/install command for freebsd
Mon Jul 10 2017 Przemyslaw Pawelczyk
* compilation fixes for aarch64 and musl
Mon Jul 10 2017 Aleksey
* improve support of clang on macOS
Sun Nov 6 2016 Aleksey
* === Version 1.3.4 ===
Tue Nov 17 2015 Alexey Dokuchaev, Kurt Jaeger
* compilation fixes for FreeBSD
Sat Aug 9 2014 Aleksey
* return non zero exit code if a file was not found
Tue Aug 5 2014 Aleksey
* === Version 1.3.3 ===
Mon Aug 4 2014 And Sch, Aleksey
* librhash: small optimization of Whirlpool
Sat Aug 2 2014 Aleksey
* option --exclude for skipping some files during recursive scanning
Fri Aug 1 2014 Aleksey
* update the SHA3 algorithm to follow the changes of the FIPS 202 draft
Wed Jul 30 2014 Aleksey
* support torrents with more than one announce url
Tue Jul 29 2014 Aleksey
* LibRHash now exports torrent functions
Mon Jul 21 2014 Tsukasa Oi
* fixed test_rhash.sh script failing on the en_US.UTF-8 locale
Wed Jul 16 2014 Aleksey
* changed the `-p' format names of sha* families, see manpage
* set a boolean in config to true by a string `true', `on' or `yes'
Sun Jul 13 2014 Aleksey
* Ctrl-C now interrupts benchmarking
Wed Jul 2 2014 Aleksey
* === Version 1.3.2 ===
Sat Jun 21 2014 Aleksey
* report warnings on files locked by some processes
Thu Jun 19 2014 Brad Campbell
* ignore non-regular files while scanning directories recursively
Wed Jun 18 2014 Aleksey
* option --follow for following symlinks to directories
Sun Apr 13 2014 ZinnKid
* BTIH piece length calculation updated to follow the uTorrent algorithm change
Wed Jan 8 2014 Aleksey
* === Version 1.3.1 ===
* Exclude the files specified by -o and -l from processing
Sat Jan 4 2014 Aleksey
* Improved directory scanning
Sat Dec 28 2013 Aleksey
* Bugfix: suppress the R6034 error popup on Windows
Fri Oct 25 2013 Aleksey
* Fixed 'value too large' error on 32-bit Linux
Thu Sep 19 2013 Aleksey
* Bugfix: corrected sha3-224 for big-endian processors
Tue Sep 17 2013 Aleksey
* === Version 1.3.0 ===
Tue May 21 2013 Aleksey
* Fixed output of percents when two or more files are hashed
Mon Apr 29 2013 Aleksey
* Supported SHA3 (Keccak) hash function
Sat Apr 27 2013 Aleksey
* Fixed memory leaks
Tue Apr 23 2013 Aleksey
* Bugfix: %{mtime} formatting option was broken
Mon Dec 31 2012 Aleksey
* imported translations from Launchpad: de, es, gl, it
Tue Dec 25 2012 Aleksey
* === Version 1.2.10 ===
Mon Nov 5 2012 Aleksey
* Bugfix: incorrect GOST hash for ("\FF" x 64) on non-x86 CPU
Mon Oct 8 2012 Aleksey
* Shortcut -k for --check-embedded
Thu Sep 27 2012 Aleksey
* Bugfix: non-zero exit code if some files were not found
* improved Ctrl-C processing
Sat Aug 4 2012 Aleksey
* Bugfix: path issue with verification of hash files
Mon Jun 25 2012 Aleksey
* Bugfix: different BTIH were generated for the same file
Sun May 13 2012 Aleksey
* BugFix: python crashed on ia64
Tue Apr 17 2012 Aleksey
* PHP bindings for librhash
Sat Apr 14 2012 Aleksey
* === Version 1.2.9 ===
Fri Apr 13 2012 Aleksey, Sergey Basalaev
* translations: de, en_AU, es, gl, it
Sun Apr 08 2012 Aleksey
* Bugfix: handling UNC filenames on Windows
* option --bt-batch for batch torrents
Sat Jan 7 2012 Aleksey
* librhash: rhash_print_magnet function
Sun Nov 06 2011 Sergey Basalaev
* .NET/Mono bindings to librhash
Wed Sep 14 2011 Aleksey
* === Version 1.2.8 ===
Wed Sep 14 2011 Aleksey, SBasalaev
* LibRHash bindings to Java, Perl, Python, Ruby
Tue Sep 6 2011 Aleksey
* librhash: implemented auto-final feature, turned on by default
Tue Sep 6 2011 Aleksey, SBasalaev
* Russian translation
Sat Sep 3 2011 Aleksey
* Bugfix: not enough trailing '=' in a base64-encoded hash
Sat Aug 20 2011 Aleksey
* Bugfix: fix broken --openssl option parsing
* Bugfix: buffer overflow when using --embed-crc-delimiter
* Bugfix: segmentation fault on SUSE Linux
Sun Aug 14 2011 Aleksey
* === Version 1.2.7 ===
Sun Aug 7 2011 Aleksey
* Bugfix: percents option was broken in v1.2.6
Fri Aug 5 2011 Aleksey
* supported verification of sha256, sha512 and other hash sums
Mon Jul 11 2011 Aleksey
* librhash: rhash_cancel() macro to cancel hashing from another thread
Fri Jun 24 2011 Aleksey
* Bugfix: repaired default output encoding to be UTF-8 on Windows
Wed Jun 22 2011 Aleksey
* Bugfix: crash on WinXP
Thu Jun 16 2011 Aleksey
* === Version 1.2.6 ===
Sat Jun 11 2011 Aleksey
* allowed options to be intermixed with file names in arbitrary order
* switched option -G and the '%G' printf pattern to print GOST hash
* Bugfix: --output failed for cyrillic file name
Wed Jun 8 2011 Aleksey
* librhash: better shared library compilation/testing support
Mon Jun 6 2011 Aleksey
* librhash: exported benchmarking functions in the shared library
* librhash: added prefix to all functions to avoid poluting linker namespace
* librhash: fixed rare alignment bugs in rhash_print and EDON-R 512
Sat May 28 2011 Aleksey
* librhash: loading openssl at runtime if it is present
* Bugfix: LLVM GOST amd64 asm compilation error
Wed May 18 2011 Aleksey
* === Version 1.2.5 ===
* option --openssl allows to replace some algorithms by the OpenSSL ones
* Bugfix: incorrect recursive traversing of very long UTF-8 filepaths
Wed Apr 27 2011 Aleksey
* Bugfix: corrected calculation of BTIH hash and torrent files
Fri Apr 15 2011 Aleksey
* === Version 1.2.4 ===
* option --benchmark-raw for machine-readable benchmark output format
* on Intel/AMD CPUs benchmark now prints the clocks-per-byte value
Tue Apr 5 2011 Aleksey
* changed config file locations
Fri Apr 1 2011 Aleksey
* Bugfix: repaired --path-separator on linux/unix
Sun Mar 27 2011 Aleksey
* === Version 1.2.3 ===
Fri Mar 25 2011 Aleksey
* one-line percent for linux/unix
Mon Mar 14 2011 Aleksey
* added printf modificator %{mtime} to print the last modified date of a file
Thu Feb 17 2011 Aleksey
* Bugfix: verification of base2-like formatted md5 hash sums
Fri Jan 14 2011 Aleksey
* === Version 1.2.2 ===
* one-line percents (windows only)
Tue Jan 11 2011 Aleksey
* supported EDON-R 256/512 hash sums
Sun Dec 19 2010 Aleksey
* increased process priority when benchmarking on windows
Thu Dec 16 2010 Aleksey
* Bugfix: eight hash sums were broken on PowerPC
* Bugfix: --accept/--crc-accept were not working since 1.1.9
Tue Dec 14 2010 Aleksey
* === Version 1.2.1 ===
* Bugfix: GOST broken on OpenSolaris since 1.2.0
* option --list-hashes: list names of all supported hashes, one per line
Mon Nov 29 2010 Aleksey
* SHA 224/256/384/512 hash functions supported
* Bugfix: broken asm compilation on openbsd and freebsd
Wed Nov 24 2010 Aleksey
* option --path-separator= for directories scanning
Sun Nov 14 2010 Aleksey
* === Version 1.2.0 ===
* --gost-cryptopro option: calculate GOST with CryptoPro parameters
* --gost-reverse option: reverse bytes in GOST hash sum
* Bugfix: btih/gost/ripemd/has160/snefru were not verified correctly in bsd and magnet formats
Fri Oct 29 2010 Aleksey
* Bugfix: rhash compiled by MS VC skipped files of size >4Gb
Fri Oct 15 2010 Aleksey
* === Version 1.1.9 ===
* new interface for internal library librhash
Mon Jul 5 2010 Ruslan Nikolaev
* GOST algorithm x86-64 assembler optimization
Sun Apr 25 2010 Aleksey
* new options --uppercase and --lowercase
* Bugfix: GOST worked incorrectly when compiled by GCC with `-O0'
Wed Apr 21 2010 Aleksey
* windows distribution updated
Fri Apr 16 2010 Aleksey
* BugFix: options with string values were incorrectly loaded from config
Wed Apr 14 2010 Aleksey
* === Version 1.1.8 ===
* option --template= to read printf-like template from
Mon Apr 12 2010 Xiangli Huang
* BugFix: `--recursive *' traversed parent directory .. under windows
* BugFix: `--check ' reported strange warning for dirs
Mon Apr 12 2010 Aleksey
* printf-directives starting with capital letter print upper-cased hashes, e.g. %{Gost}
* %u directive switched to print url-encoded filename (alias for %{urlname})
* ed2k links verification supported
Fri Apr 9 2010 Aleksey
* BugFix: linking problem on OpenSolaris
* filenames in urls are now always utf8-encoded (Windows only fix)
Wed Apr 7 2010 Aleksey
* '%B','%@' modifiers to print base64/raw representation of any hash (e.g. '%BM')
Wed Mar 31 2010 Aleksey
* === Version 1.1.7 ===
* option --btih to print BitTorrent infohash
* option --torrent to create torrent file
* option --bt-private for private torrents
* option --bt-piece-length to change torrent piece length
* option --bt-announce to set torrent announcement url
Tue Mar 30 2010 Aleksey
* the -m option made to be an alias for --magnet
Mon Mar 29 2010 Xiangli Huang
* print program version, when benchmarking
Fri Mar 26 2010 Aleksey
* Bugfix: infite loop while recursively updating hash files under Windows
Thu Mar 4 2010 Aleksey
* maxdepth parameter now is checked to be a number
Thu Feb 25 2010 Aleksey
* output tiger hash in the big-endian order
Wed Feb 24 2010 Aleksey
* === Version 1.1.6 ===
* man page updated
* now all supported hashes are verified when cheking magnet links
* benchmark now reports the size of the hashed message
Fri Feb 19 2010 Aleksey
* Bugfix: fixed GOST for big-endian systems
Wed Feb 17 2010 Aleksey
* Bugfix: buffer owerflow while parsing long command line under Windows
Sun Feb 14 2010 Aleksey
* Bugfix: fixed HAS-160 for big-endian systems
Wed Feb 3 2010 Aleksey
* Bugfix: crash while printing sfv header for files modified before 1970
Fri Jan 29 2010 Aleksey
* Bugfix: sfv-hash symlink now sets default print format to SFV
* Bugfix: ed2k-link symlink did not work as expected
Thu Jan 28 2010 Aleksey
* === Version 1.1.5 ===
* option --utf8 under Windows, also UTF8 now is the default encoding
* Bugfix: non-existing files were reported twice in `-r --sfv' mode
Wed Jan 27 2010 Aleksey
* option --embed-crc-delimiter= to insert before a crc sum in -e mode
* alias -e for --embed-crc
* alias -B for --benchmark
Mon Jan 11 2010 Aleksey
* Bugfix: percents output fixed for files of more than 4Gb of data
Fri Dec 18 2009 Aleksey
* AICH algorithm has been re-written to process files of unknown size like stdin, pipes, sockets
* ED2K switched to use eMule algorithm when filesize is an exact multiple of 9728000 bytes
Thu Dec 17 2009 Aleksey
* Bugfix: buffer overflow when printing eDonkey links for 0-sized files
* Bugfix: --ripemd160 and --md4 option were broken
* added `%R' printf entity for RIPEMD-160
Mon Dec 14 2009 Aleksey
* === Version 1.1.4 ===
* supported algorithms: RIPEMD-160, HAS-160, GOST, MD4, SNEFRU-128, SNEFRU-256
* long printf format entities, e.g. %{md4}, %{has160}, %{gost}, %{snefru256}
* `u' printf modifier for uppercase hashes, e.g. %u{gost}
* switched to %{urlname} printf-entity for url-encoded file name
* useful symlinks are installed by `make install-symlinks'
Sun Dec 6 2009 Aleksey
* WHIRLPOOL hash function supported, option --whirlpool
Wed Dec 2 2009 Aleksey
* print file checking statistics when --check-embedded specified
Sun Nov 29 2009 Aleksey
* === Version 1.1.3 ===
* forbid simultaneous usage of --check, --update and --check-embedded options
Sun Nov 22 2009 Aleksey
* Bugfix: Checking of md5 file always reported OK
* --check-embedded option to verify files by crc32 sum embedded in their names.
* --embed-crc option to rename processed files by embedding crc32 sum into name.
Mon Nov 9 2009 Aleksey
* --benchmark option now prints names of tested hash sums
* use magnet format as default if the program name contains 'magnet'
Wed Jun 24 2009 Aleksey
* supported checking of files containing a single hash sum without a filename
Mon Jun 15 2009 Aleksey
* === Version 1.1.2 ===
* verification of files with magnet links supported
Wed May 20 2009 Aleksey
* Bugfix: --skip-ok was broken since 1.1.0
Fri May 15 2009 Aleksey
* Bugfix: checking of ed2k hashes was broken since version 1.1.0
* Bugfix: --verbose lead to crash under OpenSolaris when config file not present
Mon Mar 23 2009 Aleksey
* === Version 1.1.1 ===
* config file described in the man page
* Bugfix: buffer owerflow when printing tiger hash
Sat Mar 21 2009 Aleksey
* Bugfix: some options couldn't be read from config file
Sat Mar 14 2009 Aleksey
* === Version 1.1.0 ===
* various small changes and refactoring
Tue Mar 10 2009 Aleksey
* option --speed to print per-file and total speed statistics
Thu Mar 5 2009 Aleksey
* option --output to write calculation and check results to a file
* option --log to log percents, speed and verbose messages
Wed Mar 4 2009 Aleksey
* option --percents to show wget-like percents
Tue Feb 26 2009 Aleksey
* Bugfix: fixed processing of unaligned messages in the get_crc32() function
Sat Feb 14 2009 Aleksey
* === Version 1.0.8 ===
* --magnet option supported to format sums as a magnet link
* Bugfix: printf option from config conflicted with command line
Sun Dec 14 2008 Aleksey
* === Version 1.0.7 ===
* config file supported to load default options values
* if --verbose, report verification errors as "sum is XXXXXXXX, should be YYYYYYYY"
* '%h' modifier changed to '%x'
Fri Nov 14 2008 Aleksey
* === Version 1.0.6 ===
* reg-file for FAR user menu
Thu Oct 9 2008 Aleksey
* interpret '#' symbol as a comment
Sat Sep 20 2008 ivan386
* under windows skip files openned for writing
* Bugfix: printf arguments %p and %f corrected
Sun Sep 14 2008 Aleksey
* === Version 1.0.5 ===
Wed Aug 6 2008 Aleksey
* '%b','%h' modifiers to print base32/hex representation of any hash (e.g. '%bH')
* supported -p '\0' symbol
* supported setting width for filesizes (e.g. -p '%12s')
Tue Jul 22 2008 Aleksey
* --verbose prints read speed statistics to stderr after each file
* read buffer increased to 2 MiB
Wed Jul 9 2008 Aleksey
* === Version 1.0.4 ===
* '%u' prints URL-encoded filename
* EDonkey links now have URL-encoded filename and contain AICH hash
Mon Jul 7 2008 Aleksey
* AICH hashsums supported, option --aich
Sat Jun 28 2008 Aleksey
* === Version 1.0.3 ===
* ed2k calculation fixed for files with 9728000 < filesize <= 9732096
* Big-endian processors supported for all sums
Sat Jun 14 2008 Aleksey
* === Version 1.0.2 ===
Fri Jun 6 2008 Aleksey
* --benchmark option added
* skip locked files under win32 when calculating 'em sums
Tue May 20 2008 Aleksey
* Bugfix: updating of md5 files was broken
* Bugfix: more rigid parsing of base32/hex hash sums
Wed May 15 2008 Aleksey
* === Version 1.0.1 ===
* Bugfix: last line without '\n' couldn't be parsed
Wed May 14 2008 Aleksey
* Bugfix: empty lines were not skipped, when verifying a crc file
* option '--skip-ok' to skip OK messages for successfuly verified files
Tue Jan 22 2008 Aleksey
* option '-a' to print all supported hash sums
* Changed default behavior: if no formatting option are set, sfv header is printed only for --crc32
Wed Dec 19 2007 Aleksey
* Bugfix: fixed buffer overflow for command line -p '%%%%d'
* Bugfix: fixed size calculation for stdin (rhash -p '%s' - = 56
* Tiger hash optimised to be 5% faster
Wed May 02 2007 Aleksey
* === Version 0.8.8 ===
Sun Apr 22 2007 Aleksey
* added options --accept and --crc-accept
* added --verbose option
* added --maxdepth option
* added check before verifying a crc file that it isn't a binary file
Mon Apr 16 2007 Aleksey
* === Version 0.8.7 ===
* Tiger hash sum optimised for IA32
Tue Apr 10 2007 Aleksey
* Bugfix: --update of sfv files worked incorrectly under windows
Mon Apr 09 2007 Aleksey
* implemented Tiger hash function
Sun Apr 01 2007 Aleksey
* added check before updating a crc file that it isn't a binary file
Mon Mar 26 2007 Aleksey
* === Version 0.8.6 ===
* Ctrl+C now prints a message and partitial statistics
Sat Mar 24 2007 Aleksey
* default format changed to SFV
Mon Mar 19 2007 Aleksey
* updating of crc files supported
Wed Jan 31 2007 Aleksey
* === Version 0.8.5 ===
* supported many short options as one argument, e.g. '-MCEr'
* option -S (--sha1) changed to -H
* Bugfix: program crashed under BSD while printing SFV file header
Sun Nov 05 2006 Aleksey
* === Version 0.8.4 ===
* Bugfix: errors/miss stats calculation corrected
Sun Oct 29 2006 Aleksey
* supported "-c -" option to check hash sums from stdin
* added stdout flushing after each processed file
* the program returns exit code 0 on success and 1 if an error occurred
Fri Sep 08 2006 Aleksey
* corrected parsing of md5-like files with star-prepended filenames
Wed Apr 19 2006 Aleksey
* checking of md5/sha1 files in *BSD format supported
* improved I/O errors handling
Mon Apr 10 2006 Aleksey
* === Version 0.8.3 ===
* cheking of files in standard md5sum/sha1sum format supported
* default output format for md5/sha1/ed2k sums changed
* man page rewrited
Thu Mar 30 2006 Aleksey
* === Version 0.8.2 ===
* GCC 2.96 supported
Thu Feb 23 2006 Aleksey
* Bugfix: files with .SFV extension (in uppercase) were skiped while recursive checking
Wed Jan 25 2006 Aleksey
* === Version 0.8.1 ===
* option --check now works with --recursive
* Bugfix: corrected output format when checking files
* Bugfix: files wasn't opened as binary on Windows when checking sums
Mon Jan 23 2006 Aleksey
* === Version 0.8 ===
* documentation now distributed with windows version
* some *.bat files added to windows version
Sun Jan 22 2006 Aleksey
* --check option added, to check hash sums files
* --ansi option added (for Windows version only)
* program name is parsed now to specify default sums to compute
Sat Jan 14 2006 Aleksey
* Bugfix: console windows version now uses OEM (DOS) character set for output
* === Version 0.7 ===
* some fixes in sfv format output
Fri Sep 16 2005 Aleksey
* --recursive option added
* --ed2k-link option added
Fri Sep 02 2005 Aleksey
* === Version 0.6 ===
Sun Aug 28 2005 Aleksey
* Bugfix: files wasn't opened as binary on win32
* --sfv format now implies uppercase hashes
Wed Aug 24 2005 Aleksey
* added .spec file and Makefile 'rpm' target
Sun Aug 14 2005 Aleksey
* === Version 0.5 ===
* the first public version
* win32 platform supported
Mon Aug 08 2005 Aleksey
* Bugfix: fixed calculation of md5/ed2k hashes for AMD64
Fri Aug 05 2005 Aleksey
* === Version 0.06 ===
* initial linux version supporting crc32, md5, ed2k and sha1
RHash-1.3.9/INSTALL.md 0000664 0000000 0000000 00000002655 13575211473 0014201 0 ustar 00root root 0000000 0000000
Installation
============
Build Prerequisites
-------------------
- GCC or Intel Compiler for Linux / macOS / Unix.
- MinGW or MS VC++ for Windows.
- (optionally) gettext library for internationalization
- (optionally) OpenSSL for optimized algorithms
Build and install
-----------------
To compile and install the program use command
```sh
./configure && make && make install
```
The compiled program and library can be tested by command `make test test-lib`
To compile using MS VC++, take the project file from /win32/vc-2010/ directory.
Enabling features
-----------------
RHash can use optimized algorithms of MD5, SHA1, SHA2 from the OpenSSL library.
To link OpenSSL at run-time (preffered way), configure RHash as
```sh
./configure --enable-openssl-runtime
```
To link it at load-time, use options
```sh
./configure --enable-openssl --disable-openssl-runtime
```
Internationalization support can be compiled and installed by commands
```sh
./configure --enable-gettext
make install install-gmo
```
Run `./configure --help` for a full list of configuration options.
Building an OS native package
-----------------------------
When building a package for an OS Repository, one should correctly specify system directories, e.g.:
```sh
./configure --sysconfdir=/etc --exec-prefix=/usr
```
Example of installing RHash with shared and static LibRHash library:
```sh
./configure --enable-lib-static
make install install-lib-so-link
```
RHash-1.3.9/Makefile 0000664 0000000 0000000 00000027743 13575211473 0014216 0 ustar 00root root 0000000 0000000
include config.mak
HEADERS = calc_sums.h hash_print.h common_func.h hash_update.h file.h file_mask.h file_set.h find_file.h hash_check.h output.h parse_cmdline.h rhash_main.h win_utils.h platform.h version.h
SOURCES = calc_sums.c hash_print.c common_func.c hash_update.c file.c file_mask.c file_set.c find_file.c hash_check.c output.c parse_cmdline.c rhash_main.c win_utils.c
OBJECTS = $(SOURCES:.c=.o)
WIN_DIST_FILES = dist/MD5.bat dist/magnet.bat dist/rhashrc.sample
OTHER_FILES = configure Makefile ChangeLog INSTALL.md COPYING README.md \
build/vc-2010/rhash.vcxproj dist/rhash.spec.in dist/rhash.1 dist/rhash.1.win.sed \
docs/CONTRIBUTING.md docs/LIBRHASH.md librhash/Doxyfile po/rhash.pot \
tests/test_rhash.sh tests/test1K.data
LIBRHASH_FILES = librhash/algorithms.c librhash/algorithms.h \
librhash/byte_order.c librhash/byte_order.h librhash/plug_openssl.c librhash/plug_openssl.h \
librhash/rhash.c librhash/rhash.h librhash/rhash_torrent.c librhash/rhash_torrent.h \
librhash/rhash_timing.c librhash/rhash_timing.h \
librhash/aich.c librhash/aich.h librhash/crc32.c librhash/crc32.h \
librhash/ed2k.c librhash/ed2k.h librhash/edonr.c librhash/edonr.h \
librhash/gost12.c librhash/gost12.h librhash/gost94.c librhash/gost94.h \
librhash/has160.c librhash/has160.h librhash/hex.c librhash/hex.h librhash/md4.c \
librhash/md4.h librhash/md5.c librhash/md5.h librhash/ripemd-160.c librhash/ripemd-160.h \
librhash/sha1.c librhash/sha1.h librhash/sha3.c librhash/sha3.h \
librhash/sha256.c librhash/sha256.h librhash/sha512.c librhash/sha512.h \
librhash/snefru.c librhash/snefru.h librhash/tiger.c librhash/tiger.h \
librhash/tiger_sbox.c librhash/tth.c librhash/tth.h librhash/whirlpool.c \
librhash/whirlpool.h librhash/whirlpool_sbox.c librhash/test_hashes.c \
librhash/test_hashes.h librhash/torrent.h librhash/torrent.c librhash/ustd.h \
librhash/util.h librhash/Makefile
I18N_FILES = po/ca.po po/de.po po/en_AU.po po/es.po po/fr.po po/gl.po po/it.po po/ro.po po/ru.po po/uk.po
ALL_FILES = $(SOURCES) $(HEADERS) $(LIBRHASH_FILES) $(OTHER_FILES) $(WIN_DIST_FILES) $(I18N_FILES)
SPECFILE = dist/rhash.spec
LIBRHASH_PC = dist/librhash.pc
RHASH_NAME = rhash
RHASH_BINARY = rhash$(EXEC_EXT)
TEST_OPTIONS =
RPMTOP = rpms
RPMDIRS = SOURCES SPECS BUILD SRPMS RPMS
INSTALL_PROGRAM = $(INSTALL) -m 755
INSTALL_DATA = $(INSTALL) -m 644
all: $(BUILD_TARGETS)
install: build-install-binary install-data install-symlinks $(EXTRA_INSTALL)
build-static: $(RHASH_STATIC)
build-shared: $(RHASH_SHARED)
lib-shared: $(LIBRHASH_SHARED)
lib-static: $(LIBRHASH_STATIC)
install-data: install-man install-conf
uninstall: uninstall-binary uninstall-data uninstall-symlinks uninstall-lib uninstall-gmo uninstall-pkg-config
config.mak:
echo "Run the ./configure script first" && false
# creating archives
WIN_SUFFIX = win32
PACKAGE_NAME = $(RHASH_NAME)-$(VERSION)
ARCHIVE_TARGZ = $(PACKAGE_NAME)-src.tar.gz
ARCHIVE_TARGZ_CORE = $(RHASH_NAME)-core-$(VERSION)-src.tar.gz
ARCHIVE_TARGZ_BINDINGS = $(RHASH_NAME)-bindings-$(VERSION)-src.tar.gz
ARCHIVE_TARGZ_DEB = $(RHASH_NAME)_$(VERSION).orig.tar.gz
ARCHIVE_XZ = $(PACKAGE_NAME)-src.tar.xz
ARCHIVE_ZIP = $(PACKAGE_NAME)-$(WIN_SUFFIX).zip
WIN_ZIP_DIR = RHash-$(VERSION)-$(WIN_SUFFIX)
dist: tgz
win-dist: zip
zip: $(ARCHIVE_ZIP)
dgz: check $(ARCHIVE_TARGZ_DEB)
build-install-binary: $(BUILD_TARGETS)
+$(MAKE) install-binary
mkdir-bin:
$(INSTALL) -d $(BINDIR)
# install binary without (re-)compilation
install-binary: mkdir-bin
$(INSTALL_PROGRAM) $(RHASH_BINARY) $(BINDIR)/$(RHASH_BINARY)
install-man:
$(INSTALL) -d $(MANDIR)/man1
$(INSTALL_DATA) dist/rhash.1 $(MANDIR)/man1/rhash.1
install-conf:
$(INSTALL) -d $(SYSCONFDIR)
tr -d \\r < dist/rhashrc.sample > rc.tmp && $(INSTALL_DATA) rc.tmp $(SYSCONFDIR)/rhashrc
rm -f rc.tmp
# dependencies should be properly set, otherwise 'make -j' can fail
install-symlinks: mkdir-bin install-man install-binary
cd $(BINDIR) && for f in $(SYMLINKS); do $(LN_S) $(RHASH_BINARY) $$f$(EXEC_EXT); done
cd $(MANDIR)/man1 && for f in $(SYMLINKS); do $(LN_S) rhash.1 $$f.1; done
install-pkg-config:
$(INSTALL) -d $(PKGCONFIGDIR)
$(INSTALL_DATA) $(LIBRHASH_PC) $(PKGCONFIGDIR)/
uninstall-binary:
rm -f $(BINDIR)/$(RHASH_BINARY)
uninstall-data:
rm -f $(MANDIR)/man1/rhash.1
uninstall-symlinks:
for f in $(SYMLINKS); do rm -f $(BINDIR)/$$f$(EXEC_EXT) $(MANDIR)/man1/$$f.1; done
uninstall-pkg-config:
rm -f $(PKGCONFIGDIR)/librhash.pc
uninstall-lib:
+cd librhash && $(MAKE) uninstall-lib
install-lib-static: $(LIBRHASH_STATIC) install-lib-headers
+cd librhash && $(MAKE) install-lib-static
install-lib-shared: $(LIBRHASH_SHARED)
+cd librhash && $(MAKE) install-lib-shared
install-lib-headers:
+cd librhash && $(MAKE) install-lib-headers
install-lib-so-link:
+cd librhash && $(MAKE) install-so-link
$(LIBRHASH_SHARED): $(LIBRHASH_FILES)
+cd librhash && $(MAKE) lib-shared
$(LIBRHASH_STATIC): $(LIBRHASH_FILES)
+cd librhash && $(MAKE) lib-static
test-lib: test-lib-$(BUILD_TYPE)
test-lib-static: $(LIBRHASH_STATIC)
+cd librhash && $(MAKE) test-static
test-lib-shared: $(LIBRHASH_SHARED)
+cd librhash && $(MAKE) test-shared
test-libs: $(LIBRHASH_STATIC) $(LIBRHASH_SHARED)
+cd librhash && $(MAKE) test-static test-shared
test-full:
+$(MAKE) TEST_OPTIONS=--full test
test: test-$(BUILD_TYPE)
test-static: $(RHASH_STATIC)
/bin/sh tests/test_rhash.sh $(TEST_OPTIONS) ./$(RHASH_STATIC)
test-shared: $(RHASH_SHARED)
/bin/sh tests/test_rhash.sh --shared $(TEST_OPTIONS) ./$(RHASH_SHARED)
print-info: lib-$(BUILD_TYPE)
+cd librhash && $(MAKE) print-info
# check that source tree is consistent
check:
grep -q '\* === Version $(VERSION) ===' ChangeLog
grep -q '^#define VERSION "$(VERSION)"' version.h
test ! -f bindings/version.properties || grep -q '^version=$(VERSION)$$' bindings/version.properties
$(RHASH_STATIC): $(OBJECTS) $(LIBRHASH_STATIC)
$(CC) $(OBJECTS) $(LIBRHASH_STATIC) $(BIN_STATIC_LDFLAGS) -o $@
$(RHASH_SHARED): $(OBJECTS) $(LIBRHASH_SHARED)
$(CC) $(OBJECTS) $(LIBRHASH_SHARED) $(LDFLAGS) -o $@
# NOTE: dependences were generated by 'gcc -Ilibrhash -MM *.c'
# we are using plain old makefile style to support BSD make
calc_sums.o: calc_sums.c platform.h calc_sums.h common_func.h file.h \
hash_check.h hash_print.h output.h parse_cmdline.h rhash_main.h \
win_utils.h librhash/rhash.h librhash/rhash_torrent.h
$(CC) -c $(CFLAGS) $< -o $@
common_func.o: common_func.c common_func.h parse_cmdline.h version.h \
win_utils.h
$(CC) -c $(CFLAGS) $< -o $@
file.o: file.c file.h common_func.h platform.h win_utils.h
$(CC) -c $(CFLAGS) $< -o $@
file_mask.o: file_mask.c file_mask.h common_func.h
$(CC) -c $(CFLAGS) $< -o $@
file_set.o: file_set.c file_set.h calc_sums.h common_func.h file.h \
hash_check.h hash_print.h output.h parse_cmdline.h rhash_main.h \
librhash/rhash.h
$(CC) -c $(CFLAGS) $< -o $@
find_file.o: find_file.c platform.h find_file.h common_func.h file.h \
output.h win_utils.h
$(CC) -c $(CFLAGS) $< -o $@
hash_check.o: hash_check.c hash_check.h hash_print.h common_func.h \
output.h parse_cmdline.h librhash/rhash.h
$(CC) -c $(CFLAGS) $< -o $@
hash_print.o: hash_print.c hash_print.h calc_sums.h common_func.h file.h \
hash_check.h output.h parse_cmdline.h win_utils.h librhash/rhash.h
$(CC) -c $(CFLAGS) $< -o $@
hash_update.o: hash_update.c calc_sums.h common_func.h file.h \
hash_check.h file_set.h file_mask.h hash_print.h hash_update.h output.h \
parse_cmdline.h rhash_main.h win_utils.h
$(CC) -c $(CFLAGS) $< -o $@
output.o: output.c platform.h calc_sums.h common_func.h file.h \
hash_check.h output.h parse_cmdline.h rhash_main.h win_utils.h \
librhash/rhash.h
$(CC) -c $(CFLAGS) $< -o $@
parse_cmdline.o: parse_cmdline.c parse_cmdline.h common_func.h file.h \
file_mask.h find_file.h hash_print.h output.h rhash_main.h win_utils.h \
librhash/rhash.h
$(CC) -c $(CFLAGS) $(CONFCFLAGS) $< -o $@
rhash_main.o: rhash_main.c rhash_main.h calc_sums.h common_func.h file.h \
hash_check.h file_mask.h find_file.h hash_print.h hash_update.h \
parse_cmdline.h output.h win_utils.h librhash/rhash.h
$(CC) -c $(CFLAGS) $< -o $@
win_utils.o: win_utils.c win_utils.h common_func.h file.h parse_cmdline.h \
rhash_main.h
$(CC) -c $(CFLAGS) $< -o $@
dist/rhash.1.win.html: dist/rhash.1 dist/rhash.1.win.sed
sed -f dist/rhash.1.win.sed dist/rhash.1 | rman -fHTML -roff | \
sed -e '/ dist/rhash.1.win.html
# verify the result
grep -q "utf8" dist/rhash.1.win.html
grep -q "APPDATA" dist/rhash.1.win.html
dist/rhash.1.html: dist/rhash.1
-which rman 2>/dev/null && (rman -fHTML -roff dist/rhash.1 | sed -e '/ $@)
dist/rhash.1.txt: dist/rhash.1
-which groff &>/dev/null && (groff -t -e -mandoc -Tascii dist/rhash.1 | sed -e 's/.\[[0-9]*m//g' > $@)
permissions:
find . build dist docs librhash po tests -maxdepth 1 -type f -exec chmod -x '{}' \;
chmod +x configure tests/test_rhash.sh
copy-dist: $(ALL_FILES) permissions
rm -rf $(PACKAGE_NAME)
mkdir $(PACKAGE_NAME)
cp -rl --parents $(ALL_FILES) $(PACKAGE_NAME)/
tgz-core: check
+$(MAKE) copy-dist PACKAGE_NAME=$(PACKAGE_NAME)-core
tar czf $(ARCHIVE_TARGZ_CORE) --owner=root --group=root $(PACKAGE_NAME)-core/
rm -rf $(PACKAGE_NAME)-core
tgz-bindings:
+cd bindings && $(MAKE) gzip ARCHIVE_GZIP=../$(ARCHIVE_TARGZ_BINDINGS)
tgz: check clean-bindings
+$(MAKE) copy-dist
+cd bindings && $(MAKE) copy-dist COPYDIR=../$(PACKAGE_NAME)/bindings
tar czf $(ARCHIVE_TARGZ) --owner=root:0 --group=root:0 $(PACKAGE_NAME)/
rm -rf $(PACKAGE_NAME)
xz: check clean-bindings
+$(MAKE) copy-dist
+cd bindings && $(MAKE) copy-dist COPYDIR=../$(PACKAGE_NAME)/bindings
tar cJf $(ARCHIVE_XZ) --owner=root:0 --group=root:0 $(PACKAGE_NAME)/
rm -rf $(PACKAGE_NAME)
$(ARCHIVE_ZIP): $(WIN_DIST_FILES) dist/rhash.1.win.html
test -s dist/rhash.1.win.html && test -x $(RHASH_BINARY)
-rm -rf $(WIN_ZIP_DIR)
mkdir $(WIN_ZIP_DIR)
cp $(RHASH_BINARY) ChangeLog $(WIN_DIST_FILES) $(WIN_ZIP_DIR)/
cp dist/rhash.1.win.html $(WIN_ZIP_DIR)/rhash-doc.html
zip -9r $(ARCHIVE_ZIP) $(WIN_ZIP_DIR)
rm -rf $(WIN_ZIP_DIR)
$(ARCHIVE_TARGZ_DEB) : $(ALL_FILES)
+$(MAKE) tgz
mv -f $(ARCHIVE_TARGZ) $(ARCHIVE_TARGZ_DEB)
# rpm packaging
$(SPECFILE): $(SPECFILE).in config.mak
sed -e 's/@VERSION@/$(VERSION)/' $(SPECFILE).in > $(SPECFILE)
rpm: tgz
-for i in $(RPMDIRS); do mkdir -p $(RPMTOP)/$$i; done
cp -f $(ARCHIVE_TARGZ) $(RPMTOP)/SOURCES
rpmbuild -ba --clean --define "_topdir `pwd`/$(RPMTOP)" $(SPECFILE)
mv -f `find $(RPMTOP) -name "*rhash*-$(VERSION)*.rpm"` .
rm -rf $(RPMTOP)
clean-bindings:
+cd bindings && $(MAKE) clean
clean-local:
rm -f *.o $(RHASH_SHARED) $(RHASH_STATIC)
rm -f po/*.gmo po/*.po~
distclean: clean-local
rm -f config.log config.mak $(SPECFILE) $(LIBRHASH_PC)
+cd librhash && $(MAKE) distclean
clean: clean-local
+cd librhash && $(MAKE) clean
update-po:
xgettext *.c -k_ -cTRANSLATORS -o po/rhash.pot \
--msgid-bugs-address='Aleksey ' --package-name='RHash'
for f in $(I18N_FILES); do \
msgmerge -U $$f po/rhash.pot; \
done
compile-gmo:
for f in $(I18N_FILES); do \
g=`basename $$f .po`; \
msgfmt -o po/$$g.gmo $$f; \
done
install-gmo: compile-gmo
for f in $(I18N_FILES); do \
l=`basename $$f .po`; \
$(INSTALL) -d $(LOCALEDIR)/$$l/LC_MESSAGES; \
$(INSTALL_DATA) po/$$l.gmo $(LOCALEDIR)/$$l/LC_MESSAGES/rhash.mo; \
done
uninstall-gmo:
for f in $(I18N_FILES); do \
rm -f $(LOCALEDIR)/`basename $$f .po`/LC_MESSAGES/rhash.mo; \
done
.PHONY: all build-shared build-static lib-shared lib-static clean clean-bindings distclean clean-local \
test test-shared test-static test-full test-lib test-libs test-lib-shared test-lib-static \
install build-install-binary install-binary install-lib-shared install-lib-static \
install-lib-headers install-lib-so-link install-conf install-data install-gmo install-man \
install-symlinks install-pkg-config uninstall-gmo uninstall-pkg-config \
uninstall uninstall-binary uninstall-data uninstall-lib uninstall-symlinks \
print-info check copy-dist update-po compile-gmo mkdir-bin permissions \
dgz dist tgz tgz-bindings tgz-core rpm win-dist xz zip
RHash-1.3.9/README.md 0000664 0000000 0000000 00000003321 13575211473 0014017 0 ustar 00root root 0000000 0000000 # RHash
RHash (Recursive Hasher) is a console utility for calculation and
verification of magnet links and various hash sums, including CRC32, CRC32C,
MD4, MD5, SHA1, SHA256, SHA512, SHA3, AICH, ED2K, DC++ TTH, BitTorrent BTIH,
Tiger, GOST R 34.11-94, GOST R 34.11-2012, RIPEMD-160, HAS-160, EDON-R, and
Whirlpool.
Hash sums are used to ensure and verify integrity of large volumes of data
for a long-term storing or transferring.
### Program features:
* Ability to process directories recursively.
* Output in a predefined (SFV, BSD-like) or a user-defined format.
* Calculation of Magnet links.
* Updating hash files (adding hash sums of files missing in the hash file).
* Calculates several hash sums in one pass.
* Portability: the program works the same on Linux, Unix, macOS or Windows.
## Installation
```shell
./configure && make install
```
For more complicated cases of installation see the [INSTALL.md] file.
## Documentation
* RHash [ChangeLog]
* [The LibRHash Library] documentation
## Links
* Project Home Page: http://rhash.sourceforge.net/
* Official Releases: https://github.com/rhash/RHash/releases/
* Binary Windows Releases: https://sf.net/projects/rhash/files/rhash/
* The table of the supported by RHash [hash functions](http://sf.net/p/rhash/wiki/HashFunctions/)
* ECRYPT [The Hash Function Zoo](http://ehash.iaik.tugraz.at/wiki/The_Hash_Function_Zoo)
* ECRYPT [Benchmarking of hash functions](https://bench.cr.yp.to/results-hash.html)
## Contribution
Please read the [Contribution guidelines](docs/CONTRIBUTING.md) document.
## License
The code is distributed under [BSD Zero Clause License](COPYING).
[INSTALL.md]: INSTALL.md
[The LibRHash Library]: docs/LIBRHASH.md
[ChangeLog]: ChangeLog
RHash-1.3.9/bindings/ 0000775 0000000 0000000 00000000000 13575211473 0014336 5 ustar 00root root 0000000 0000000 RHash-1.3.9/bindings/COPYING 0000664 0000000 0000000 00000001334 13575211473 0015372 0 ustar 00root root 0000000 0000000
BSD Zero Clause License
Copyright (c) 2011, Aleksey Kravchenko and Sergey Basalaev
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
RHash-1.3.9/bindings/ChangeLog 0000664 0000000 0000000 00000001366 13575211473 0016116 0 ustar 00root root 0000000 0000000 Fri Aug 1 2014 Aleksey
* python 3 support
* update SHA3 test vectors to follow the changes of the spec
Sun Jan 19 2014 Aleksey
* renamed perl module to the Crypt::Rhash
Tue Sep 17 2013 Aleksey
* === Version 1.3.0 ===
Tue Dec 25 2012 Aleksey
* === Version 1.2.10 ===
Sun May 13 2012 Aleksey
* BugFix: python crashed on ia64
Tue Apr 17 2012 Aleksey
* PHP bindings for librhash
Sat Apr 14 2012 Aleksey
* === Version 1.2.9 ===
Sun Nov 06 2011 Sergey Basalaev
* .NET/Mono bindings to librhash
Wed Sep 14 2011 Aleksey
* === Version 1.2.8 ===
Wed Sep 14 2011 Aleksey
* Perl bindings
Sat Jul 9 2011 Sergey Basalaev
* Ruby bindings
Thu Jun 16 2011 Sergey Basalaev
* Python bindings
Sun Jun 12 2011 Sergey Basalaev
* LibRHash Java bindings
RHash-1.3.9/bindings/Makefile 0000664 0000000 0000000 00000007036 13575211473 0016004 0 ustar 00root root 0000000 0000000 VERSION := $(shell sed -ne 's/^version=\(.*\)/\1/p' version.properties)
BINDINGS = java mono perl python ruby php
FILES = Makefile version.properties ChangeLog COPYING
DESTDIR =
PREFIX = /usr/local
RUBY ?= ruby
PYTHON ?= python
PERL ?= perl
PERL_LIBRHASH_TYPE ?= auto
PERL_OPTIMIZE ?= -O2 -g -Wall
ARCHIVE_GZIP = rhash-bindings-$(VERSION)-src.tar.gz
COPYDIR = rhash-bindings-$(VERSION)
CP = cp -l --parents
all: configure build test
clean: distclean
configure: $(patsubst %, configure-%, $(filter perl ruby php, $(BINDINGS)))
build: $(patsubst %, build-%, $(BINDINGS))
test: $(patsubst %, test-%, $(BINDINGS))
install: $(patsubst %, install-%, $(filter perl ruby php, $(BINDINGS)))
distclean: $(patsubst %, clean-%, $(BINDINGS))
configure-perl: perl/Makefile
configure-ruby: ruby/Makefile
configure-php: php/Makefile
perl/Makefile: perl/Makefile.PL
cd perl && LIBRHASH="$(PERL_LIBRHASH_TYPE)" $(PERL) Makefile.PL INSTALLDIRS=vendor
php/Makefile: php/config.m4
cd php && phpize && ./configure --with-rhash
ruby/Makefile: ruby/extconf.rb
$(RUBY) -C ruby extconf.rb
build-java:
+$(MAKE) -C java build-binary
build-perl: configure-perl
+$(MAKE) -C perl OPTIMIZE="$(PERL_OPTIMIZE)"
build-php: configure-php
+$(MAKE) -C php
build-python:
# not required
build-ruby: configure-ruby
+$(MAKE) -C ruby
build-mono:
+$(MAKE) -C mono
test-java:
+$(MAKE) -C java test
test-perl:
+$(MAKE) -C perl test
test-php:
+$(MAKE) -C php test TEST_PHP_ARGS=-q
test-ruby:
$(RUBY) -C ruby -I. test_rhash.rb
test-mono:
+$(MAKE) -C mono test
test-python:
$(PYTHON) python/test_rhash.py
install-ruby:
# clear MAKEFLAGS to overcome ruby1.8 mkmf concurrency bug
+MAKEFLAGS= $(MAKE) -C ruby install DESTDIR=$(DESTDIR) sitedir=$(DESTDIR)/usr/lib/ruby
install-perl:
+$(MAKE) -C perl install DESTDIR=$(DESTDIR)
install-php:
+$(MAKE) -C php install INSTALL_ROOT=$(DESTDIR)
copy-dist:
mkdir -p $(COPYDIR)
find java ruby python -type f -regex '.*\(\.\([hc]\|java\|py\|rb\|txt\)\|Makefile\)' -exec $(CP) '{}' $(COPYDIR)/ \;
find mono -type f -regex '.*\(\.\([hc]\|cs\|xml\|txt\|snk\|sln\|csproj\|config\)\|Makefile\)' -exec $(CP) '{}' "$(COPYDIR)/" \;
$(CP) $(shell sed -e 's/\([^ ]*\).*/perl\/\1/' perl/MANIFEST) "$(COPYDIR)/"
find php -type f -regex '.*\.\(m4\|c\|h\|phpt\)' -exec $(CP) '{}' "$(COPYDIR)/" \;
$(CP) $(FILES) "$(COPYDIR)/"
gzip: distclean
rm -rf "$(COPYDIR)" $(ARCHIVE_GZIP)
+$(MAKE) copy-dist
tar -czf $(ARCHIVE_GZIP) --owner=root:0 --group=root:0 "$(COPYDIR)"
rm -rf "$(COPYDIR)"
PERL_PKG_VER = $(shell [ -f perl/Rhash.pm ] && sed -ne "s/^our \+.VERSION *= *'\([0-9\.]*\)';/\1/p;" perl/Rhash.pm)
PERL_PKG = Crypt-RHash-$(PERL_PKG_VER)
cpan:
[ -f ../librhash/rhash.h ]
echo "$(PERL_PKG_VER)" | grep -q '^[0-9\.]\+$$'
rm -rf $(PERL_PKG)/ $(PERL_PKG).tar.gz
mkdir -p $(PERL_PKG)/librhash/
grep -q / perl/MANIFEST && mkdir -p `sed -ne '/\//s/\([^\/]*\/\).*/$(PERL_PKG)\/\1/p' perl/MANIFEST | sort -u`
sed -e 's/^\([^ ]*\)\( .*\)\?/cp perl\/\1 $(PERL_PKG)\/\1/' perl/MANIFEST > _cpy.sh
sh _cpy.sh && rm -f _cpy.sh
cp ../librhash/*.[hc] $(PERL_PKG)/librhash/
cp perl/MANIFEST $(PERL_PKG)/
find $(PERL_PKG)/librhash/ -type f -printf "librhash/%f\n" | sort >> $(PERL_PKG)/MANIFEST
tar -czf $(PERL_PKG).tar.gz --owner=root:0 --group=root:0 $(PERL_PKG)/
rm -rf $(PERL_PKG)/
clean-java:
+$(MAKE) -C java distclean
clean-mono:
+$(MAKE) -C mono clean
clean-ruby:
+[ ! -f ruby/Makefile ] || $(MAKE) -C ruby distclean
clean-perl:
+[ ! -f perl/Makefile ] || $(MAKE) -C perl distclean
clean-php:
[ ! -f php/configure ] || (cd php && phpize --clean)
clean-python:
rm -f python/*.pyc
RHash-1.3.9/bindings/java/ 0000775 0000000 0000000 00000000000 13575211473 0015257 5 ustar 00root root 0000000 0000000 RHash-1.3.9/bindings/java/.gitignore 0000664 0000000 0000000 00000000036 13575211473 0017246 0 ustar 00root root 0000000 0000000 classes/*
dist/*
*.so
*.class
RHash-1.3.9/bindings/java/Makefile 0000664 0000000 0000000 00000006020 13575211473 0016715 0 ustar 00root root 0000000 0000000 #!/usr/bin/make -f
# This file is a part of Java Bindings for Librhash
#
# Copyright (c) 2011, Sergey Basalaev
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
JAVA = java
JAVAC = javac
JAVADOC = javadoc
JAVAH = javah
JAR = jar
JUNIT_CLASSPATH = /usr/share/java/junit4.jar
VERSION = $(shell sed -ne 's/^version=\(.*\)/\1/p' ../version.properties)
JAVASRC_DIR = src
CSRC_DIR = native
DEST_DIR ?= dist
CLASSES_DIR = classes
JAVADOC_DIR = javadoc
TEST_DIR = test
JAVA_FILES := $(shell find $(JAVASRC_DIR) -name '*.java')
JNI_FILES := $(shell find $(CSRC_DIR) -name '*.c' -o -name '*.h')
LIB_PREFIX ?= lib
LIB_SUFFIX ?= .so
JNI_LIBRARY = $(LIB_PREFIX)rhash-jni$(LIB_SUFFIX)
JARFILE = $(DEST_DIR)/rhash-$(VERSION).jar
JAVADOC_FILE = $(DEST_DIR)/rhash-$(VERSION)-javadoc.zip
JAVADOC_API_URL = http://download.oracle.com/javase/6/docs/api/
all: build-binary javadoc
build-binary: jar jar-symlink jni
jar: $(JARFILE)
jni: $(DEST_DIR)/$(JNI_LIBRARY)
zip-javadoc: $(JAVADOC_FILE)
jar-symlink:
mkdir -p $(DEST_DIR)
ln -fs rhash-$(VERSION).jar $(DEST_DIR)/rhash.jar
$(JARFILE): $(JAVA_FILES)
+$(MAKE) compile-classes
mkdir -p $(DEST_DIR)
$(JAR) cf $(JARFILE) -C $(CLASSES_DIR) org/
compile-classes:
mkdir -p $(CLASSES_DIR)
$(JAVAC) -d $(CLASSES_DIR) -sourcepath $(JAVASRC_DIR) $(JAVA_FILES)
update-header: compile-classes
$(JAVAH) -o $(CSRC_DIR)/bindings.h -classpath $(CLASSES_DIR) org.sf.rhash.Bindings
$(DEST_DIR)/$(JNI_LIBRARY): $(JNI_FILES)
+$(MAKE) -C $(CSRC_DIR)
mkdir -p $(DEST_DIR)
cp $(CSRC_DIR)/$(JNI_LIBRARY) $(DEST_DIR)
javadoc: clean-javadoc
$(JAVADOC) -windowtitle 'RHash' \
-sourcepath $(JAVASRC_DIR) \
-subpackages org \
-d $(JAVADOC_DIR) \
-link $(JAVADOC_API_URL)
$(JAVADOC_FILE): $(JAVA_FILES)
+$(MAKE) javadoc
jar -cMf $(JAVADOC_FILE) $(JAVADOC_DIR)
$(TEST_DIR)/RHashTest.class: $(JARFILE) $(TEST_DIR)/RHashTest.java
$(JAVAC) -classpath $(JARFILE):$(JUNIT_CLASSPATH) $(TEST_DIR)/RHashTest.java
test: $(TEST_DIR)/RHashTest.class jni
$(JAVA) -classpath $(TEST_DIR):$(JARFILE):$(JUNIT_CLASSPATH) -Djava.library.path=$(DEST_DIR) junit.textui.TestRunner RHashTest
clean: clean-javadoc clean-jni clean-classes clean-test
clean-javadoc:
rm -rf $(JAVADOC_DIR)
clean-classes:
rm -rf $(CLASSES_DIR)
clean-jni:
+$(MAKE) -C $(CSRC_DIR) clean
clean-test:
rm -f $(TEST_DIR)/*.class
distclean: clean
rm -rf $(DEST_DIR)
.PHONY: jar jni javadoc test clean clean-javadoc distclean
RHash-1.3.9/bindings/java/native/ 0000775 0000000 0000000 00000000000 13575211473 0016545 5 ustar 00root root 0000000 0000000 RHash-1.3.9/bindings/java/native/Makefile 0000664 0000000 0000000 00000003210 13575211473 0020201 0 ustar 00root root 0000000 0000000 #!/usr/bin/make -f
# This file is a part of Java Bindings for Librhash
#
# Copyright (c) 2011, Sergey Basalaev
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
CC ?= gcc
JAVAC ?= javac
CFLAGS ?= -g -O2
LDFLAGS ?=
LIBRHASH_INC ?=
LIBRHASH_LD ?=
ALLLDFLAGS = $(LDFLAGS) -lrhash $(LIBRHASH_LD)
ALLCFLAGS = $(CFLAGS) $(LIBRHASH_INC) -fPIC
#Platform dependent
JAVAC_PATH = $(shell readlink -f $(shell which $(JAVAC)))
JDK_HOME ?=$(realpath $(dir $(JAVAC_PATH))/..)
JNI_CFLAGS1 = $(shell test -d "$(JDK_HOME)/include" && echo -I$(JDK_HOME)/include)
JNI_CFLAGS2 = $(shell test -d "$(JDK_HOME)/include/linux" && echo -I$(JDK_HOME)/include/linux)
JNI_CFLAGS ?= $(JNI_CFLAGS1) $(JNI_CFLAGS2)
LIB_PREFIX ?= lib
LIB_SUFFIX ?= .so
OBJECTS = bindings.o digest.o
LIBRARY = $(LIB_PREFIX)rhash-jni$(LIB_SUFFIX)
all: $(LIBRARY)
bindings.o: bindings.c bindings.h
$(CC) $(ALLCFLAGS) $(JNI_CFLAGS) -c $< -o $@
digest.o: digest.c digest.h
$(CC) $(ALLCFLAGS) -c $< -o $@
$(LIBRARY): $(OBJECTS)
$(CC) -shared -o $@ $(OBJECTS) $(ALLLDFLAGS)
clean:
rm -f *.o $(LIBRARY)
RHash-1.3.9/bindings/java/native/bindings.c 0000664 0000000 0000000 00000014541 13575211473 0020513 0 ustar 00root root 0000000 0000000 /*
* This file is a part of Java Bindings for Librhash
*
* Copyright (c) 2011, Sergey Basalaev
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include
#include
#ifdef __GNUC__
#include
#define TO_RHASH(a) ((rhash)(intptr_t)(a))
#define TO_DIGEST(a) ((Digest)(intptr_t)(a))
#define TO_JLONG(a) ((jlong)(intptr_t)(a))
#else
#define TO_RHASH(a) ((rhash)(a))
#define TO_DIGEST(a) ((Digest)(a))
#define TO_JLONG(a) ((jlong)(a))
#endif /* __GNUC__ */
#include "bindings.h"
#include "digest.h"
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_library_init
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1library_1init
(JNIEnv *env, jclass clz) {
rhash_library_init();
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_count
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_sf_rhash_Bindings_rhash_1count
(JNIEnv *env, jclass clz) {
return rhash_count();
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_msg
* Signature: (I[BII)J
*/
JNIEXPORT jlong JNICALL Java_org_sf_rhash_Bindings_rhash_1msg
(JNIEnv *env, jclass clz, jint hash_id, jbyteArray buf, jint ofs, jint len) {
// reading data
void* msg = malloc(len);
(*env)->GetByteArrayRegion(env, buf, ofs, len, msg);
// creating and populating Digest
Digest obj = malloc(sizeof(DigestStruct));
obj->hash_len = rhash_get_digest_size(hash_id);
obj->hash_data = calloc(obj->hash_len, sizeof(unsigned char));
rhash_msg(hash_id, msg, len, obj->hash_data);
//cleaning
free(msg);
//returning
return TO_JLONG(obj);
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_print_bytes
* Signature: (JI)[B
*/
JNIEXPORT jbyteArray JNICALL Java_org_sf_rhash_Bindings_rhash_1print_1bytes
(JNIEnv *env, jclass clz, jlong ptr, jint flags) {
Digest obj = TO_DIGEST(ptr);
char output[130];
int len = rhash_print_bytes(output, obj->hash_data, obj->hash_len, flags);
jbyteArray arr = (*env)->NewByteArray(env, len);
(*env)->SetByteArrayRegion(env, arr, 0, len, (jbyte*)output);
return arr;
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_print_magnet
* Signature: (JLjava/lang/String;I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_sf_rhash_Bindings_rhash_1print_1magnet
(JNIEnv *env, jclass clz, jlong context, jstring filepath, jint flags) {
const char* fpath = (filepath != NULL) ?
(*env)->GetStringUTFChars(env, filepath, NULL) : NULL;
size_t len = rhash_print_magnet(NULL, fpath, TO_RHASH(context), flags, RHPR_FILESIZE);
char *buf = (char*)malloc(len);
rhash_print_magnet(buf, fpath, TO_RHASH(context), flags, RHPR_FILESIZE);
if (filepath != NULL) {
(*env)->ReleaseStringUTFChars(env, filepath, fpath);
}
jstring str = (*env)->NewStringUTF(env, buf);
free(buf);
return str;
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_is_base32
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL Java_org_sf_rhash_Bindings_rhash_1is_1base32
(JNIEnv *env, jclass clz, jint hash_id) {
return rhash_is_base32(hash_id);
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_get_digest_size
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_org_sf_rhash_Bindings_rhash_1get_1digest_1size
(JNIEnv *env, jclass clz, jint hash_id) {
return rhash_get_digest_size(hash_id);
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_init
* Signature: (I)J
*/
JNIEXPORT jlong JNICALL Java_org_sf_rhash_Bindings_rhash_1init
(JNIEnv *env, jclass clz, jint hash_flags) {
rhash ctx = rhash_init(hash_flags);
rhash_set_autofinal(ctx, 0);
return TO_JLONG(ctx);
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_update
* Signature: (J[BII)V
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1update
(JNIEnv *env, jclass clz, jlong context, jbyteArray data, jint ofs, jint len) {
void* msg = malloc(len);
(*env)->GetByteArrayRegion(env, data, ofs, len, msg);
rhash_update(TO_RHASH(context), msg, len);
free(msg);
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_final
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1final
(JNIEnv *env, jclass clz, jlong context) {
rhash_final(TO_RHASH(context), NULL);
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_reset
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1reset
(JNIEnv *env, jclass clz, jlong context) {
rhash_reset(TO_RHASH(context));
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_print
* Signature: (JI)J
*/
JNIEXPORT jlong JNICALL Java_org_sf_rhash_Bindings_rhash_1print
(JNIEnv *env, jclass clz, jlong context, jint hash_id) {
Digest obj = malloc(sizeof(DigestStruct));
obj->hash_len = rhash_get_digest_size(hash_id);
obj->hash_data = calloc(obj->hash_len, sizeof(unsigned char));
rhash_print((char*)obj->hash_data, TO_RHASH(context), hash_id, RHPR_RAW);
return TO_JLONG(obj);
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_free
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1free
(JNIEnv *env, jclass clz, jlong context) {
rhash_free(TO_RHASH(context));
}
/*
* Class: org_sf_rhash_Bindings
* Method: compareDigests
* Signature: (JJ)Z
*/
JNIEXPORT jboolean JNICALL Java_org_sf_rhash_Bindings_compareDigests
(JNIEnv *env, jclass clz, jlong ptr1, jlong ptr2) {
return compareDigests(TO_DIGEST(ptr1), TO_DIGEST(ptr2));
}
/*
* Class: org_sf_rhash_Bindings
* Method: hashcodeForDigest
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_org_sf_rhash_Bindings_hashcodeForDigest
(JNIEnv *env, jclass clz, jlong ptr) {
return hashcodeForDigest(TO_DIGEST(ptr));
}
/*
* Class: org_sf_rhash_Bindings
* Method: freeDigest
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_freeDigest
(JNIEnv *env, jclass clz, jlong ptr) {
freeDigest(TO_DIGEST(ptr));
}
RHash-1.3.9/bindings/java/native/bindings.h 0000664 0000000 0000000 00000006462 13575211473 0020523 0 ustar 00root root 0000000 0000000 /* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class org_sf_rhash_Bindings */
#ifndef _Included_org_sf_rhash_Bindings
#define _Included_org_sf_rhash_Bindings
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_library_init
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1library_1init
(JNIEnv *, jclass);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_count
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_sf_rhash_Bindings_rhash_1count
(JNIEnv *, jclass);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_msg
* Signature: (I[BII)J
*/
JNIEXPORT jlong JNICALL Java_org_sf_rhash_Bindings_rhash_1msg
(JNIEnv *, jclass, jint, jbyteArray, jint, jint);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_print_bytes
* Signature: (JI)[B
*/
JNIEXPORT jbyteArray JNICALL Java_org_sf_rhash_Bindings_rhash_1print_1bytes
(JNIEnv *, jclass, jlong, jint);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_print_magnet
* Signature: (JLjava/lang/String;I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_sf_rhash_Bindings_rhash_1print_1magnet
(JNIEnv *, jclass, jlong, jstring, jint);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_is_base32
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL Java_org_sf_rhash_Bindings_rhash_1is_1base32
(JNIEnv *, jclass, jint);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_get_digest_size
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_org_sf_rhash_Bindings_rhash_1get_1digest_1size
(JNIEnv *, jclass, jint);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_init
* Signature: (I)J
*/
JNIEXPORT jlong JNICALL Java_org_sf_rhash_Bindings_rhash_1init
(JNIEnv *, jclass, jint);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_update
* Signature: (J[BII)V
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1update
(JNIEnv *, jclass, jlong, jbyteArray, jint, jint);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_final
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1final
(JNIEnv *, jclass, jlong);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_reset
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1reset
(JNIEnv *, jclass, jlong);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_print
* Signature: (JI)J
*/
JNIEXPORT jlong JNICALL Java_org_sf_rhash_Bindings_rhash_1print
(JNIEnv *, jclass, jlong, jint);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_free
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1free
(JNIEnv *, jclass, jlong);
/*
* Class: org_sf_rhash_Bindings
* Method: compareDigests
* Signature: (JJ)Z
*/
JNIEXPORT jboolean JNICALL Java_org_sf_rhash_Bindings_compareDigests
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: org_sf_rhash_Bindings
* Method: hashcodeForDigest
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_org_sf_rhash_Bindings_hashcodeForDigest
(JNIEnv *, jclass, jlong);
/*
* Class: org_sf_rhash_Bindings
* Method: freeDigest
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_freeDigest
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus
}
#endif
#endif
RHash-1.3.9/bindings/java/native/digest.c 0000664 0000000 0000000 00000002575 13575211473 0020201 0 ustar 00root root 0000000 0000000 /*
* This file is a part of Java Bindings for Librhash
*
* Copyright (c) 2011, Sergey Basalaev
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include
#include
#include "digest.h"
void freeDigest(Digest obj) {
free(obj->hash_data);
free(obj);
}
int compareDigests(Digest o1, Digest o2) {
if (o1->hash_len != o2->hash_len) return 0;
return memcmp(o1->hash_data, o2->hash_data, o1->hash_len) == 0;
}
int hashcodeForDigest(Digest obj) {
int hash = 123321, i;
for (i = 0; i < obj->hash_len; i++) {
switch (i % 3) {
case 0: hash ^= obj->hash_data[i];
case 1: hash ^= obj->hash_data[i] << 8;
case 2: hash ^= obj->hash_data[i] << 16;
case 3: hash ^= obj->hash_data[i] << 24;
}
}
return hash ^ (obj->hash_id + obj->hash_len);
}
RHash-1.3.9/bindings/java/native/digest.h 0000664 0000000 0000000 00000002674 13575211473 0020206 0 ustar 00root root 0000000 0000000 /*
* This file is a part of Java Bindings for Librhash
*
* Copyright (c) 2011, Sergey Basalaev
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* This is convenient structure to hold message digest. */
#ifndef DIGEST_H
#define DIGEST_H
typedef struct {
int hash_id;
size_t hash_len;
unsigned char *hash_data;
} DigestStruct;
typedef DigestStruct* Digest;
/**
* Frees memory occupated by Digest.
* @param obj object to free
*/
void freeDigest(Digest obj);
/**
* Compares two Digest instances.
* @param obj1 first object to compare
* @param obj2 second object to compare
* @return 1 if objects are equal, 0 otherwise
*/
int compareDigests(Digest obj1, Digest obj2);
/**
* Calculates hashcode for Digest.
* @param obj object to calculate hash code
*/
int hashcodeForDigest(Digest obj);
#endif /* DIGEST_H */
RHash-1.3.9/bindings/java/src/ 0000775 0000000 0000000 00000000000 13575211473 0016046 5 ustar 00root root 0000000 0000000 RHash-1.3.9/bindings/java/src/org/ 0000775 0000000 0000000 00000000000 13575211473 0016635 5 ustar 00root root 0000000 0000000 RHash-1.3.9/bindings/java/src/org/sf/ 0000775 0000000 0000000 00000000000 13575211473 0017245 5 ustar 00root root 0000000 0000000 RHash-1.3.9/bindings/java/src/org/sf/rhash/ 0000775 0000000 0000000 00000000000 13575211473 0020352 5 ustar 00root root 0000000 0000000 RHash-1.3.9/bindings/java/src/org/sf/rhash/Bindings.java 0000664 0000000 0000000 00000010413 13575211473 0022751 0 ustar 00root root 0000000 0000000 /*
* This file is a part of Java Bindings for Librhash
*
* Copyright (c) 2011, Sergey Basalaev
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
package org.sf.rhash;
/**
* Glue to the native API.
*/
final class Bindings {
/** This class is not instantiable. */
private Bindings() { }
/**
* Initializes library.
*/
static native void rhash_library_init();
/**
* Returns the number of supported hash algorithms.
*/
static native int rhash_count();
/**
* Computes a hash of the given data.
*
* @param hash_id id of hash function
* @param data the data to process
* @param ofs offset in data array from which to start processing
* @param len data length
* @return pointer to the native digest object
*/
static native long rhash_msg(int hash_id, byte[] data, int ofs, int len);
/**
* Prints text representation of a given digest.
*
* @param rhash pointer to native digest object
* @param flags output flags
* @return text representation as byte array
*/
static native byte[] rhash_print_bytes(long rhash, int flags);
/**
* Returns magnet link for given hash context and hashing algorithms.
*
* @param rhash pointer to native digest object
* @param filename the name of the file to incorporate in magnet
* @param flags mask of hash_id values
* @return magnet string
*/
static native String rhash_print_magnet(long rhash, String filename, int flags);
/**
* Tests whether given default hash algorithm output is base32.
* @param hash_id id of hash function
* @return true
if default output for hash algorithm is base32,
* false
otherwise
*/
static native boolean rhash_is_base32(int hash_id);
/**
* Returns size of binary message digest.
* @param hash_id id of hash function
* @return size of message digest
*/
static native int rhash_get_digest_size(int hash_id);
/**
* Creates new hash context.
* @param flags mask of hash_id values
* @return pointer to the native hash context
*/
static native long rhash_init(int flags);
/**
* Updates hash context with given data.
* @param rhash pointer to native hash context
* @param data data to process
* @param ofs index of the first byte to process
* @param len count of bytes to process
*/
static native void rhash_update(long rhash, byte[] data, int ofs, int len);
/**
* Finalizes hash context.
* @param rhash pointer to native hash context
*/
static native void rhash_final(long rhash);
/**
* Resets hash context.
* @param rhash pointer to native hash context
*/
static native void rhash_reset(long rhash);
/**
* Generates message digest for given context and hash_id.
* @param rhash pointer to native hash context
* @param hash_id id of hashing algorithm
* @return pointer to native digest
*/
static native long rhash_print(long rhash, int hash_id);
/**
* Frees hash context.
* @param rhash pointer to native hash context
*/
static native void rhash_free(long rhash);
/**
* Compares two native hash objects.
* @param hash1 pointer to first object
* @param hash2 pointer to second object
* @return true
if objects are the same,
* false
otherwise
*/
static native boolean compareDigests(long hash1, long hash2);
/**
* Computes hashcode for native digest object.
* @param hash pointer to first object
* @return hash code for the object
*/
static native int hashcodeForDigest(long hash);
/**
* Frees previously created native digest object.
*/
static native void freeDigest(long hash);
static {
System.loadLibrary("rhash-jni");
rhash_library_init();
}
}
RHash-1.3.9/bindings/java/src/org/sf/rhash/Digest.java 0000664 0000000 0000000 00000007742 13575211473 0022446 0 ustar 00root root 0000000 0000000 /*
* This file is a part of Java Bindings for Librhash
*
* Copyright (c) 2011, Sergey Basalaev
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
package org.sf.rhash;
/**
* Message digest.
*/
public final class Digest {
static final int RAW = 0x1;
static final int HEX = 0x2;
static final int BASE32 = 0x3;
static final int BASE64 = 0x4;
static final int UPPERCASE = 0x8;
static final int REVERSE = 0x10;
private final HashType type;
/** Pointer to native structure. */
private final long digest_ptr;
/**
* Creates new Digest
.
* @param ptr pointer to the native object
* @param type hash type
*/
Digest(long ptr, HashType type) {
this.digest_ptr = ptr;
this.type = type;
}
/**
* Returns type of hashing algorithm that produced
* this digest.
*
* @return type of hashing algorithm
*/
public HashType hashType() {
return type;
}
/**
* Returns value of this digest as raw bytes.
* This method allocates new byte array, modifying it
* has no effect on this Digest
.
*
* @return value of this digest as raw bytes
* @see #hex()
* @see #base32()
* @see #base64()
*/
public byte[] raw() {
return Bindings.rhash_print_bytes(digest_ptr, RAW);
}
/**
* Returns value of this digest as hexadecimal string.
*
* @return value of the digest as hexadecimal string
* @see #raw()
* @see #base32()
* @see #base64()
*/
public String hex() {
return new String(Bindings.rhash_print_bytes(digest_ptr, HEX));
}
/**
* Returns value of this digest as base32 string.
*
* @return value of the digest as base32 string
* @see #raw()
* @see #hex()
* @see #base64()
*/
public String base32() {
return new String(Bindings.rhash_print_bytes(digest_ptr, BASE32));
}
/**
* Returns value of this digest as base64 string.
*
* @return value of the digest as base64 string
* @see #raw()
* @see #hex()
* @see #base32()
*/
public String base64() {
return new String(Bindings.rhash_print_bytes(digest_ptr, BASE64));
}
/**
* Called by garbage collector to free native resources.
*/
@Override
protected void finalize() {
Bindings.freeDigest(digest_ptr);
}
/**
* Returns string representation of this object.
* If default output for hashing algorithm is base32 then
* returned value is the same as if base32()
* method was called; otherwise value is the same as returned
* by hex()
method.
*
* @return string representation of this object
* @see #base32()
* @see #hex()
*/
@Override
public String toString() {
return (Bindings.rhash_is_base32(type.hashId())) ? base32() : hex();
}
/**
* Tests whether this object equals to another one
* @param obj object to compare to
* @return
* true
if obj
is Digest
* instance with the same HashType
and value;
* otherwise false
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Digest)) return false;
final Digest other = (Digest)obj;
if (!this.hashType().equals(other.hashType())) return false;
if (this.digest_ptr == other.digest_ptr) return true;
return Bindings.compareDigests(this.digest_ptr, other.digest_ptr);
}
/**
* Returns hash code for this object.
* @return hash code for the object
*/
@Override
public int hashCode() {
return Bindings.hashcodeForDigest(digest_ptr);
}
}
RHash-1.3.9/bindings/java/src/org/sf/rhash/HashType.java 0000664 0000000 0000000 00000006432 13575211473 0022747 0 ustar 00root root 0000000 0000000 /*
* This file is a part of Java Bindings for Librhash
*
* Copyright (c) 2011, Sergey Basalaev
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
package org.sf.rhash;
/**
* Type of hashing algorithm. Supported algorithms are CRC32, CRC32C,
* MD4, MD5, SHA1/SHA2, Tiger, DC++ TTH, BitTorrent BTIH,
* AICH, EDonkey 2000 hash, GOST R 34.11-94, GOST R 34.11-2012,
* RIPEMD-160, HAS-160, EDON-R 256/512, Whirlpool and Snefru-128/256.
*/
public enum HashType {
/** CRC32 checksum. */
CRC32(1),
/** MD4 hash. */
MD4(1 << 1),
/** MD5 hash. */
MD5(1 << 2),
/** SHA-1 hash. */
SHA1(1 << 3),
/** Tiger hash. */
TIGER(1 << 4),
/** Tiger tree hash */
TTH(1 << 5),
/** BitTorrent info hash. */
BTIH(1 << 6),
/** EDonkey 2000 hash. */
ED2K(1 << 7),
/** eMule AICH. */
AICH(1 << 8),
/** Whirlpool hash. */
WHIRLPOOL(1 << 9),
/** RIPEMD-160 hash. */
RIPEMD160(1 << 10),
/** GOST R 34.11-94. */
GOST94(1 << 11),
GOST94_CRYPTOPRO(1 << 12),
/** HAS-160 hash. */
HAS160(1 << 13),
/** GOST R 34.11-2012 - 256 bit. */
GOST12_256(1 << 14),
/** GOST R 34.11-2012 - 512 bit. */
GOST12_512(1 << 15),
/** SHA-224 hash. */
SHA224(1 << 16),
/** SHA-256 hash. */
SHA256(1 << 17),
/** SHA-384 hash. */
SHA384(1 << 18),
/** SHA-512 hash. */
SHA512(1 << 19),
/** EDON-R 256. */
EDONR256(1 << 20),
/** EDON-R 512. */
EDONR512(1 << 21),
/** SHA3-224 hash. */
SHA3_224(1 << 22),
/** SHA3-256 hash. */
SHA3_256(1 << 23),
/** SHA3-384 hash. */
SHA3_384(1 << 24),
/** SHA3-512 hash. */
SHA3_512(1 << 25),
/** CRC32C checksum. */
CRC32C(1 << 26),
/** Snefru-128 hash. */
SNEFRU128(1 << 27),
/** Snefru-256 hash. */
SNEFRU256(1 << 28);
/** hash_id for the native API */
private int hashId;
/**
* Construct HashType for specified native hash_id
* @param hashId hash identifier for native API
*/
private HashType(int hashId) {
this.hashId = hashId;
}
/**
* Returns hash_id for the native API.
* @return hash identifier
*/
int hashId() {
return hashId;
}
/**
* Returns lowest HashType
for given id mask.
* Used by RHash.getDigest()
.
* @param flags mask of hash identifiers
* @return HashType
object or null
* if no HashType
for given mask exists
*/
static HashType forHashFlags(int flags) {
if (flags == 0) return null;
int lowest = 0;
while ((flags % 2) == 0) {
flags >>>= 1;
lowest++;
}
for (HashType t : HashType.values()) {
if (t.hashId == (1 << lowest)) return t;
}
return null;
}
/**
* Returns size of binary digest for this type.
* @return size of binary digest, in bytes
*/
public int getDigestSize() {
//TODO: rhash_get_digest_size
return -1;
}
}
RHash-1.3.9/bindings/java/src/org/sf/rhash/RHash.java 0000664 0000000 0000000 00000034113 13575211473 0022224 0 ustar 00root root 0000000 0000000 /*
* This file is a part of Java Bindings for Librhash
*
* Copyright (c) 2011, Sergey Basalaev
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
package org.sf.rhash;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Set;
/**
* Incremental hasher.
* This class allows you to do incremental hashing for set
* of hashing algorithms.
*
* To do hashing RHash
instance is first created
* and then filled with message chunks using update()
* methods. Finally, finish()
should be called to end
* all calculations and generate digests, which then can be obtained
* with getDigest()
method. Note, that trying to update
* finished RHash
has no effect other than throwing
* IllegalStateException
though you can reuse this class
* by calling reset()
method, returning it to the state
* which was immediately after creating.
*
* To quickly produce message digest for a single message/file
* and a single algorithm you may use convenience methods
* RHash.computeHash()
.
*
* This class is thread safe.
*
*/
public final class RHash {
/* == EXCEPTION MESSAGES == */
static private final String ERR_FINISHED = "RHash is finished, data update is not possible";
static private final String ERR_NOHASH = "No HashTypes specified";
static private final String ERR_UNFINISHED = "RHash should be finished before generating Digest";
static private final String ERR_WRONGTYPE = "RHash was not created to generate Digest for ";
/**
* Computes hash of given range in data.
* This method calculates message digest for byte subsequence
* in array data
starting from data[ofs]
* and ending at data[ofs+len-1]
.
*
* @param type type of hash algorithm
* @param data the bytes to process
* @param ofs index of the first byte in array to process
* @param len count of bytes to process
* @return message digest for specified subarray
* @throws NullPointerException
* if either type
or data
* is null
* @throws IndexOutOfBoundsException
* if ofs < 0
, len < 0
or
* ofs+len > data.length
*/
static public Digest computeHash(HashType type, byte[] data, int ofs, int len) {
if (type == null || data == null) {
throw new NullPointerException();
}
if (ofs < 0 || len < 0 || ofs+len > data.length) {
throw new IndexOutOfBoundsException();
}
return new Digest(Bindings.rhash_msg(type.hashId(), data, ofs, len), type);
}
/**
* Computes hash of given data.
*
* @param type type of hash algorithm
* @param data the bytes to process
* @return message digest for specified array
* @throws NullPointerException
* if either type
or data
* is null
*/
static public Digest computeHash(HashType type, byte[] data) {
return computeHash(type, data, 0, data.length);
}
/**
* Computes hash of given string.
* String is encoded into a sequence of bytes
* using the specified charset.
*
* @param type type of hash algorithm
* @param str the string to process
* @param encoding encoding to use
* @return message digest for specified string
* @throws NullPointerException if any of arguments is null
* @throws UnsupportedEncodingException if specified encoding is not supported
*/
static public Digest computeHash(HashType type, String str, String encoding)
throws UnsupportedEncodingException {
if (type == null || str == null || encoding == null) {
throw new NullPointerException();
}
return computeHash(type, str.getBytes(encoding));
}
/**
* Computes hash of given string.
* String is encoded into a sequence of bytes using the
* default platform encoding.
*
* @param type type of hash algorithm
* @param str the string to process
* @return message digest for specified string
* @throws NullPointerException if any of arguments is null
*/
static public Digest computeHash(HashType type, String str) {
if (type == null || str == null) throw new NullPointerException();
return computeHash(type, str.getBytes());
}
/**
* Computes hash of given string.
* @param type type of hash algorithm
* @param file the file to process
* @return data hash
* @throws NullPointerException if any of arguments is null
* @throws IOException
* if an I/O error occurs while hashing
*/
static public Digest computeHash(HashType type, File file) throws IOException {
if (type == null || file == null) {
throw new NullPointerException();
}
RHash hasher = new RHash(type);
hasher.update(file).finish();
return hasher.getDigest();
}
/**
* Produces magnet link for specified file with given hashes.
*
* @param filename the file to generate magnet for
* @param types types of hashing algorithms
*/
static public String getMagnetFor(String filename, HashType... types) throws IOException {
RHash hasher = new RHash(types);
hasher.update(new File(filename)).finish();
return hasher.getMagnet(filename);
}
/**
* Produces magnet link for specified file with given hashes.
*
* @param filename the file to generate magnet for
* @param types set of hashing types
*/
static public String getMagnetFor(String filename, Set types) throws IOException {
RHash hasher = new RHash(types);
hasher.update(new File(filename)).finish();
return hasher.getMagnet(filename);
}
/** Indicates whether this RHash
is finished. */
private boolean finished = false;
/** Mask of hash_id values. */
private final int hash_flags;
/** Pointer to the native hash context. */
private final long context_ptr;
/** Default hash type used in getDigest()
. */
private final HashType deftype;
/**
* Creates new RHash
to compute
* message digests for given types.
* @param types types of hashing algorithms
* @throws NullPointerException
* if any of arguments is null
* @throws IllegalArgumentException
* if zero hash types specified
*/
public RHash(HashType... types) {
if (types.length == 0) {
throw new IllegalArgumentException(ERR_NOHASH);
}
int flags = 0;
HashType def = types[0];
for (HashType t : types) {
flags |= t.hashId();
if (def.compareTo(t) > 0) def = t;
}
this.deftype = def;
this.hash_flags = flags;
this.context_ptr = Bindings.rhash_init(flags);
}
/**
* Creates new RHash
to compute
* message digests for given types.
* @param types set of hashing types
* @throws NullPointerException
* if argument is null
* @throws IllegalArgumentException
* if argument is empty set
*/
public RHash(Set types) {
if (types.isEmpty()) {
throw new IllegalArgumentException(ERR_NOHASH);
}
int flags = 0;
HashType def = null;
for (HashType t : types) {
flags |= t.hashId();
if (def == null || def.compareTo(t) > 0) def = t;
}
this.deftype = def;
this.hash_flags = flags;
this.context_ptr = Bindings.rhash_init(flags);
}
/**
* Updates this RHash
with new data chunk.
* This method hashes bytes from data[ofs]
* through data[ofs+len-1]
.
*
* @param data data to be hashed
* @param ofs index of the first byte to hash
* @param len number of bytes to hash
* @return this object
* @throws NullPointerException
* if data
is null
* @throws IndexOutOfBoundsException
* if ofs < 0
, len < 0
or
* ofs+len > data.length
* @throws IllegalStateException
* if finish()
was called and there were no
* subsequent calls of reset()
*/
public synchronized RHash update(byte[] data, int ofs, int len) {
if (finished) {
throw new IllegalStateException(ERR_FINISHED);
}
if (ofs < 0 || len < 0 || ofs+len > data.length) {
throw new IndexOutOfBoundsException();
}
Bindings.rhash_update(context_ptr, data, ofs, len);
return this;
}
/**
* Updates this RHash
with new data chunk.
* This method has the same effect as
* update(data, 0, data.length)
*
* @param data data to be hashed
* @return this object
* @throws NullPointerException
* if data
is null
* @throws IllegalStateException
* if finish()
was called and there were no
* subsequent calls of reset()
*/
public RHash update(byte[] data) {
return update(data, 0, data.length);
}
/**
* Updates this RHash
with new data chunk.
* String is encoded into a sequence of bytes using the
* default platform encoding.
*
* @param str string to be hashed
* @return this object
* @throws NullPointerException
* if str
is null
* @throws IllegalStateException
* if finish()
was called and there were no
* subsequent calls of reset()
*/
public RHash update(String str) {
return update(str.getBytes());
}
/**
* Updates this RHash
with data from given file.
*
* @param file file to be hashed
* @return this object
* @throws IOException if an I/O error occurs
* @throws NullPointerException
* if file
is null
* @throws IllegalStateException
* if finish()
was called and there were no
* subsequent calls of reset()
*/
public synchronized RHash update(File file) throws IOException {
if (finished) {
throw new IllegalStateException(ERR_FINISHED);
}
InputStream in = new FileInputStream(file);
byte[] buf = new byte[8192]; //shouldn't we avoid magic numbers?
int len = in.read(buf);
while (len > 0) {
this.update(buf, 0, len);
len = in.read(buf);
}
in.close();
return this;
}
/**
* Finishes calculation of hash codes.
* Does nothing if RHash
is already finished.
*/
public synchronized void finish() {
if (!finished) {
Bindings.rhash_final(context_ptr);
finished = true;
}
}
/**
* Resets this RHash
to initial state.
* The RHash
becomes available to process
* new data chunks. Note, that this method returns
* RHash
to the state after creating the
* object, NOT the state when hashing continues.
* Therefore, all previously calculated hashes are lost
* and process starts from the very beginning.
*/
public synchronized void reset() {
Bindings.rhash_reset(context_ptr);
finished = false;
}
/**
* Tests whether this RHash
is finished or not.
* @return
* false
if this RHash
is ready to
* receive new data for hashing;
* true
if hash calculations are finished
*/
public boolean isFinished() {
return finished;
}
/**
* Returns digest for given hash type.
*
* @param type hash type
* @return Digest
for processed data
* @throws NullPointerException
* if type
is null
* @throws IllegalStateException
* if this RHash
is not finished
* @throws IllegalArgumentException
* if this RHash
was not created to calculate
* hash for specified algorithm
*/
public Digest getDigest(HashType type) {
if (type == null) {
throw new NullPointerException();
}
if (!finished) {
throw new IllegalStateException(ERR_UNFINISHED);
}
if ((hash_flags & type.hashId()) == 0) {
throw new IllegalArgumentException(ERR_WRONGTYPE+type);
}
return new Digest(Bindings.rhash_print(context_ptr, type.hashId()), type);
}
/**
* Returns digest for processed data.
* If more than one hashing type was passed to the
* RHash
constructor, then the least
* hash type (in the order induced by
* {@link Enum#compareTo(Enum) compareTo()}) is used.
*
* @return Digest
for processed data
* @throws IllegalStateException
* if this RHash
is not finished
*/
public Digest getDigest() {
return getDigest(deftype);
}
/**
* Returns magnet link that includes specified filename
* and hashes for given algorithms. Only hashes that were
* computed by this RHash
are included.
*
* @param filename file name to include in magnet, may be null
* @return magnet link
* @throws IllegalStateException
* if this RHash
is not finished
*/
public String getMagnet(String filename, HashType... types) {
if (!finished) {
throw new IllegalStateException(ERR_UNFINISHED);
}
int flags = 0;
for (HashType t : types) {
flags |= t.hashId();
}
return Bindings.rhash_print_magnet(context_ptr, filename, flags);
}
/**
* Returns magnet link for given filename.
* Magnet includes all hashes that were computed
* by this RHash
.
*
* @param filename file name to include in magnet, may be null
* @return magnet link
* @throws IllegalStateException
* if this RHash
is not finished
*/
public String getMagnet(String filename) {
if (!finished) {
throw new IllegalStateException(ERR_UNFINISHED);
}
return Bindings.rhash_print_magnet(context_ptr, filename, hash_flags);
}
/**
* Called by garbage collector to free native resources.
*/
@Override
protected void finalize() {
Bindings.rhash_free(context_ptr);
}
}
RHash-1.3.9/bindings/java/src/org/sf/rhash/package-info.java 0000664 0000000 0000000 00000005231 13575211473 0023542 0 ustar 00root root 0000000 0000000 /*
* This file is a part of Java Bindings for Librhash
*
* Copyright (c) 2011, Sergey Basalaev
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/**
* Java bindings for librhash.
* Librhash is a library for computing and verifying hash sums.
* List of all supported hash functions can be found in
* {@link org.sf.rhash.HashType} class description.
*
* In its simplest usage to calculate a hash for message or file
* you just need to use one of RHash.computeHash()
* methods:
*
* RHash.computeHash("Hello, world!");
* RHash.computeHash(new byte[] { 0, 1, 2, 3});
* RHash.computeHash(new File("SomeFile.txt"));
* These methods return value of type Digest
which is
* a message digest. To convert Digest
in human readable
* format you might use one of methods
* {@link org.sf.rhash.Digest#hex() hex()},
* {@link org.sf.rhash.Digest#base32() base32()},
* {@link org.sf.rhash.Digest#base64() base64()} or
* {@link org.sf.rhash.Digest#raw() raw()}.
*
* Next, RHash
allows you to do incremental hashing,
* processing data given in portions like it was one big byte sequence.
* To do this you first need to create RHash
instance
* with a set of needed hash algorithms and then to fill it using
* update()
:
*
* RHash hasher = new RHash(HashType.MD5);
* hasher.update("Foo").update(new File("Bar.zip")).finish();
* Digest result = hasher.getDigest();
* Method finish()
should be called before obtaining
* digest to end all calculations and generate result.
*
* You can setup RHash
to calculate several digests
* at once, passing corresponding HashType
s in
* constructor. Specifically, you can calculate all of them creating
* RHash
like
*
* new Rhash(EnumSet.allOf(HashType.class));
* In this case to obtain digest for particular hash type use
* {@link org.sf.rhash.RHash#getDigest(HashType) }
* method.
*
*/
package org.sf.rhash;
RHash-1.3.9/bindings/java/test/ 0000775 0000000 0000000 00000000000 13575211473 0016236 5 ustar 00root root 0000000 0000000 RHash-1.3.9/bindings/java/test/RHashTest.java 0000664 0000000 0000000 00000010713 13575211473 0020750 0 ustar 00root root 0000000 0000000 import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.EnumSet;
import org.sf.rhash.*;
import static org.sf.rhash.HashType.*;
import org.junit.Test;
import junit.framework.JUnit4TestAdapter;
import static junit.framework.TestCase.*;
public class RHashTest {
@Test
public void testAllHashes() {
RHash r = new RHash(EnumSet.allOf(HashType.class));
r.update("a").finish();
assertEquals("e8b7be43", r.getDigest(CRC32).toString());
assertEquals("c1d04330", r.getDigest(CRC32C).toString());
assertEquals("bde52cb31de33e46245e05fbdbd6fb24", r.getDigest(MD4).toString());
assertEquals("0cc175b9c0f1b6a831c399e269772661", r.getDigest(MD5).toString());
assertEquals("86f7e437faa5a7fce15d1ddcb9eaeaea377667b8", r.getDigest(SHA1).toString());
assertEquals("77befbef2e7ef8ab2ec8f93bf587a7fc613e247f5f247809", r.getDigest(TIGER).toString());
assertEquals("czquwh3iyxbf5l3bgyugzhassmxu647ip2ike4y", r.getDigest(TTH).toString());
assertEquals(40, r.getDigest(BTIH).toString().length());
assertEquals("bde52cb31de33e46245e05fbdbd6fb24", r.getDigest(ED2K).toString());
assertEquals("q336in72uwt7zyk5dxolt2xk5i3xmz5y", r.getDigest(AICH).toString());
assertEquals("8aca2602792aec6f11a67206531fb7d7f0dff59413145e6973c45001d0087b42d11bc645413aeff63a42391a39145a591a92200d560195e53b478584fdae231a", r.getDigest(WHIRLPOOL).toString());
assertEquals("0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", r.getDigest(RIPEMD160).toString());
assertEquals("d42c539e367c66e9c88a801f6649349c21871b4344c6a573f849fdce62f314dd", r.getDigest(GOST94).toString());
assertEquals("e74c52dd282183bf37af0079c9f78055715a103f17e3133ceff1aacf2f403011", r.getDigest(GOST94_CRYPTOPRO).toString());
assertEquals("4872bcbc4cd0f0a9dc7c2f7045e5b43b6c830db8", r.getDigest(HAS160).toString());
assertEquals("ba31099b9cc84ec2a671e9313572378920a705b363b031a1cb4fc03e01ce8df3", r.getDigest(GOST12_256).toString());
assertEquals("8b2a40ecab7b7496bc4cc0f773595452baf658849b495acc3ba017206810efb00420ccd73fb3297e0f7890941b84ac4a8bc27e3c95e1f97c094609e2136abb7e", r.getDigest(GOST12_512).toString());
assertEquals("abd37534c7d9a2efb9465de931cd7055ffdb8879563ae98078d6d6d5", r.getDigest(SHA224).toString());
assertEquals("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", r.getDigest(SHA256).toString());
assertEquals("54a59b9f22b0b80880d8427e548b7c23abd873486e1f035dce9cd697e85175033caa88e6d57bc35efae0b5afd3145f31", r.getDigest(SHA384).toString());
assertEquals("1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75", r.getDigest(SHA512).toString());
assertEquals("943aa9225a2cf154ec2e4dd81237720ba538ca8df2fd83c0b893c5d265f353a0", r.getDigest(EDONR256).toString());
assertEquals("b59ec44f7beef8a04ceed38a973d77c65e22e9458d5f67b497948da34986c093b5efc5483fbee55f2f740fcad31f18d80db44bb6b8843e7fd599188e7c07233b", r.getDigest(EDONR512).toString());
assertEquals("9e86ff69557ca95f405f081269685b38e3a819b309ee942f482b6a8b", r.getDigest(SHA3_224).toString());
assertEquals("80084bf2fba02475726feb2cab2d8215eab14bc6bdd8bfb2c8151257032ecd8b", r.getDigest(SHA3_256).toString());
assertEquals("1815f774f320491b48569efec794d249eeb59aae46d22bf77dafe25c5edc28d7ea44f93ee1234aa88f61c91912a4ccd9", r.getDigest(SHA3_384).toString());
assertEquals("697f2d856172cb8309d6b8b97dac4de344b549d4dee61edfb4962d8698b7fa803f4f93ff24393586e28b5b957ac3d1d369420ce53332712f997bd336d09ab02a", r.getDigest(SHA3_512).toString());
assertEquals("bf5ce540ae51bc50399f96746c5a15bd", r.getDigest(SNEFRU128).toString());
assertEquals("45161589ac317be0ceba70db2573ddda6e668a31984b39bf65e4b664b584c63d", r.getDigest(SNEFRU256).toString());
r.reset();
r.finish();
assertEquals("d41d8cd98f00b204e9800998ecf8427e", r.getDigest(MD5).toString()); // MD5 of ""
}
@Test
public void testMagnet() {
RHash r = new RHash(MD5, TTH);
r.update("abc").finish();
assertEquals("magnet:?xl=3&dn=file.txt&xt=urn:md5:900150983cd24fb0d6963f7d28e17f72&xt=urn:tree:tiger:asd4ujseh5m47pdyb46kbtsqtsgdklbhyxomuia", r.getMagnet("file.txt"));
}
@Test
public void testUpdateFile() throws IOException {
File f = new File("java_test_input_123.txt");
PrintStream out = new PrintStream(f);
out.println("\0\1\2");
out.flush();
out.close();
assertEquals("e3869ec477661fad6b9fc25914bb2eee5455b483", RHash.computeHash(SHA1, f).toString());
f.delete();
}
public static junit.framework.Test suite(){
return new JUnit4TestAdapter(RHashTest.class);
}
}
RHash-1.3.9/bindings/mono/ 0000775 0000000 0000000 00000000000 13575211473 0015306 5 ustar 00root root 0000000 0000000 RHash-1.3.9/bindings/mono/.gitignore 0000664 0000000 0000000 00000000121 13575211473 0017270 0 ustar 00root root 0000000 0000000 bin
RHash.dll
RHash.dll.mdb
RHash.pidb
RHash.tree
RHash.userprefs
RHash.zip
html
RHash-1.3.9/bindings/mono/AssemblyInfo.cs 0000664 0000000 0000000 00000003422 13575211473 0020231 0 ustar 00root root 0000000 0000000 /*
* This file is a part of Mono Bindings for Librhash
*
* Copyright (c) 2011, Sergey Basalaev
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("RHash")]
[assembly: AssemblyDescription(".NET/Mono bindings for librhash")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("(c) 2011, Sergey Basalaev")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.1.1")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("RHash.snk")]
RHash-1.3.9/bindings/mono/Bindings.cs 0000664 0000000 0000000 00000003643 13575211473 0017400 0 ustar 00root root 0000000 0000000 /*
* This file is a part of Mono Bindings for Librhash
*
* Copyright (c) 2011, Sergey Basalaev
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace RHash {
/* Pointer to native structure. */
sealed class Bindings {
private const string librhash = "librhash.dll";
private Bindings() { }
static Bindings() {
rhash_library_init();
}
[DllImport (librhash)]
public static extern
void rhash_library_init();
[DllImport (librhash)]
public static extern
IntPtr rhash_init(uint hash_ids);
[DllImport (librhash)]
public static extern
void rhash_update(IntPtr ctx, byte[] message, int length);
//may crash, rhash_final actually have 2 arguments
[DllImport (librhash)]
public static extern
void rhash_final(IntPtr ctx, IntPtr unused);
[DllImport (librhash)]
public static extern
void rhash_reset(IntPtr ctx);
[DllImport (librhash)]
public static extern
void rhash_free(IntPtr ctx);
[DllImport (librhash, CharSet=CharSet.Ansi)]
public static extern
void rhash_print(StringBuilder output, IntPtr ctx, uint hash_id, int flags);
[DllImport (librhash)]
public static extern
int rhash_print_magnet(StringBuilder output, String filepath, IntPtr ctx, uint hash_mask, int flags);
}
}
RHash-1.3.9/bindings/mono/HashType.cs 0000664 0000000 0000000 00000004371 13575211473 0017367 0 ustar 00root root 0000000 0000000 /*
* This file is a part of Java Bindings for Librhash
*
* Copyright (c) 2011, Sergey Basalaev
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
using System;
namespace RHash {
/*
* Type of hashing algorithm.
* Supported algorithms are MD4, MD5, SHA1/SHA2, Tiger,
* DC++ TTH, BitTorrent BTIH, AICH, EDonkey 2000 hash, GOST R 34.11-94,
* RIPEMD-160, HAS-160, EDON-R 256/512, Whirlpool and Snefru-128/256.
*/
public enum HashType : uint {
/* CRC32 checksum. */
CRC32 = 1,
/* MD4 hash. */
MD4 = 1 << 1,
/* MD5 hash. */
MD5 = 1 << 2,
/* SHA-1 hash. */
SHA1 = 1 << 3,
/* Tiger hash. */
TIGER = 1 << 4,
/* Tiger tree hash */
TTH = 1 << 5,
/* BitTorrent info hash. */
BTIH = 1 << 6,
/* EDonkey 2000 hash. */
ED2K = 1 << 7,
/* eMule AICH. */
AICH = 1 << 8,
/* Whirlpool hash. */
WHIRLPOOL = 1 << 9,
/* RIPEMD-160 hash. */
RIPEMD160 = 1 << 10,
/* GOST R 34.11-94. */
GOST94 = 1 << 11,
GOST94_CRYPTOPRO = 1 << 12,
/* HAS-160 hash. */
HAS160 = 1 << 13,
/* GOST R 34.11-2012. */
GOST12_256 = 1 << 14,
GOST12_512 = 1 << 15,
/* SHA-224 hash. */
SHA224 = 1 << 16,
/* SHA-256 hash. */
SHA256 = 1 << 17,
/* SHA-384 hash. */
SHA384 = 1 << 18,
/* SHA-512 hash. */
SHA512 = 1 << 19,
/* EDON-R 256. */
EDONR256 = 1 << 20,
/* EDON-R 512. */
EDONR512 = 1 << 21,
/** SHA3-224 hash. */
SHA3_224 = 1 << 22,
/** SHA3-256 hash. */
SHA3_256 = 1 << 23,
/** SHA3-384 hash. */
SHA3_384 = 1 << 24,
/** SHA3-512 hash. */
SHA3_512 = 1 << 25,
/* CRC32C checksum. */
CRC32C = 1 << 26,
/* Snefru-128 hash. */
SNEFRU128 = 1 << 27,
/* Snefru-256 hash. */
SNEFRU256 = 1 << 28
}
}
RHash-1.3.9/bindings/mono/Hasher.cs 0000664 0000000 0000000 00000012051 13575211473 0017046 0 ustar 00root root 0000000 0000000 /*
* This file is a part of Java Bindings for Librhash
*
* Copyright (c) 2011, Sergey Basalaev
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
using System;
using System.IO;
using System.Text;
namespace RHash {
public sealed class Hasher {
private const int DEFAULT = 0x0;
/* output as binary message digest */
private const int RAW = 0x1;
/* print as a hexadecimal string */
private const int HEX = 0x2;
/* print as a base32-encoded string */
private const int BASE32 = 0x3;
/* print as a base64-encoded string */
private const int BASE64 = 0x4;
/* Print as an uppercase string. */
private const int UPPERCASE = 0x8;
/* Reverse hash bytes. */
private const int REVERSE = 0x10;
/* Print file size. */
private const int FILESIZE = 0x40;
private uint hash_ids;
/* Pointer to the native structure. */
private IntPtr ptr;
public Hasher (HashType hashtype) {
this.hash_ids = (uint)hashtype;
this.ptr = Bindings.rhash_init(hash_ids);
}
public Hasher (uint hashmask) {
this.hash_ids = hashmask;
this.ptr = Bindings.rhash_init(hash_ids);
if (ptr == IntPtr.Zero) throw new ArgumentException("Invalid mask of hashes", "hashmask");
}
~Hasher() {
if (ptr != IntPtr.Zero) {
Bindings.rhash_free(ptr);
ptr = IntPtr.Zero;
}
}
public Hasher Update(byte[] buf) {
Bindings.rhash_update(ptr, buf, buf.Length);
return this;
}
public Hasher Update(byte[] buf, int len) {
if (len < 0 || len >= buf.Length) {
throw new IndexOutOfRangeException();
}
Bindings.rhash_update(ptr, buf, len);
return this;
}
public Hasher UpdateFile(string filename) {
Stream file = new FileStream(filename, FileMode.Open);
byte[] buf = new byte[8192];
int len = file.Read(buf, 0, 8192);
while (len > 0) {
Bindings.rhash_update(ptr, buf, len);
len = file.Read(buf, 0, 8192);
}
file.Close();
return this;
}
public void Finish() {
Bindings.rhash_final(ptr, IntPtr.Zero);
}
public void Reset() {
Bindings.rhash_reset(ptr);
}
public override string ToString() {
StringBuilder sb = new StringBuilder(130);
Bindings.rhash_print(sb, ptr, 0, 0);
return sb.ToString();
}
public string ToString(HashType type) {
if ((hash_ids & (uint)type) == 0) {
throw new ArgumentException("This hasher does not support hash type "+type, "type");
}
StringBuilder sb = new StringBuilder(130);
Bindings.rhash_print(sb, ptr, (uint)type, 0);
return sb.ToString();
}
public string ToHex(HashType type) {
if ((hash_ids & (uint)type) == 0) {
throw new ArgumentException("This hasher does not support hash type "+type, "type");
}
StringBuilder sb = new StringBuilder(130);
Bindings.rhash_print(sb, ptr, (uint)type, HEX);
return sb.ToString();
}
public string ToBase32(HashType type) {
if ((hash_ids & (uint)type) == 0) {
throw new ArgumentException("This hasher does not support hash type "+type, "type");
}
StringBuilder sb = new StringBuilder(130);
Bindings.rhash_print(sb, ptr, (uint)type, BASE32);
return sb.ToString();
}
public string ToBase64(HashType type) {
if ((hash_ids & (uint)type) == 0) {
throw new ArgumentException("This hasher does not support hash type "+type, "type");
}
StringBuilder sb = new StringBuilder(130);
Bindings.rhash_print(sb, ptr, (uint)type, BASE64);
return sb.ToString();
}
public string ToRaw(HashType type) {
if ((hash_ids & (uint)type) == 0) {
throw new ArgumentException("This hasher does not support hash type "+type, "type");
}
StringBuilder sb = new StringBuilder(130);
Bindings.rhash_print(sb, ptr, (uint)type, RAW);
return sb.ToString();
}
public string GetMagnet(string filepath) {
return GetMagnet(filepath, hash_ids);
}
public string GetMagnet(string filepath, uint hashmask) {
int len = Bindings.rhash_print_magnet(null, filepath, ptr, hashmask, FILESIZE);
StringBuilder sb = new StringBuilder(len);
Bindings.rhash_print_magnet(sb, filepath, ptr, hashmask, FILESIZE);
return sb.ToString();
}
public static string GetHashForMsg(byte[] buf, HashType type) {
return new Hasher(type).Update(buf).ToString(type);
}
public static string GetHashForFile(string filename, HashType type) {
return new Hasher(type).UpdateFile(filename).ToString(type);
}
public static string GetMagnetFor(string filepath, uint hashmask) {
return new Hasher(hashmask).UpdateFile(filepath).GetMagnet(filepath);
}
}
}
RHash-1.3.9/bindings/mono/Makefile 0000664 0000000 0000000 00000002547 13575211473 0016756 0 ustar 00root root 0000000 0000000 #!/usr/bin/make -f
# This file is a part of Mono Bindings for Librhash
#
# Copyright (c) 2011, Sergey Basalaev
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
CS?=mcs
MDOC?=mdoc
SOURCES=AssemblyInfo.cs Bindings.cs Hasher.cs HashType.cs
all: assembly assemble-doc html
assembly: RHash.dll RHash.dll.mdb
RHash.dll RHash.dll.mdb: $(SOURCES)
$(CS) -target:library -out:RHash.dll -debug -keyfile:RHash.snk $(SOURCES)
update-doc: RHash.dll
$(MDOC) update RHash.dll -o doc
assemble-doc: RHash.tree RHash.zip
RHash.tree RHash.zip:
$(MDOC) assemble -o RHash doc
html:
$(MDOC) export-html -o html doc
test: RHash.dll
+$(MAKE) -C test
clean:
rm -f RHash.dll RHash.dll.mdb
rm -f RHash.tree RHash.zip
rm -rf html
+$(MAKE) -C test clean
.PHONY : clean html test
RHash-1.3.9/bindings/mono/RHash.csproj 0000664 0000000 0000000 00000003414 13575211473 0017537 0 ustar 00root root 0000000 0000000
Debug
AnyCPU
10.0.0
2.0
{2EC1635A-308E-46E4-B016-017C2AF3CDD9}
Library
RHash
RHash
v4.0
.NET/Mono bindings for librhash
1.0
true
full
false
bin\Debug
DEBUG
prompt
4
false
none
false
bin\Release
prompt
4
false