Commit 849913f7 authored by Aleksey Kravchenko's avatar Aleksey Kravchenko

New upstream version 1.3.6

parent 32cc4253
/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
......
Wed 14 Mar 2018 Aleksey
* === Version 1.3.6 ===
* support --file-list option
Sun 11 Mar 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
......@@ -111,7 +133,7 @@ Sat Apr 27 2013 Aleksey
* Fixed memory leaks
Tue Apr 23 2013 Aleksey
* Bugfix: %{mtime} formating option was broken
* Bugfix: %{mtime} formatting option was broken
Mon Dec 31 2012 Aleksey
* imported translations from Launchpad: de, es, gl, it
......@@ -519,7 +541,7 @@ Wed May 14 2008 Aleksey
Tue Jan 22 2008 Aleksey
* option '-a' to print all supported hash sums
* Changed default behavior: if no formating option are set, sfv header is printed only for --crc32
* 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'
......
Linux Installation:
===================
You need GCC (or Intel Compiler) and GNU Make.
To compile and install the program just type
'make install'
To test the compiled program run 'make test'.
RPM package can be created by commands
'make rpm' or 'setarch i586 make rpm'.
For internationalization support RHash should be compiled with gettext library
make ADDCFLAGS="-DUSE_GETTEXT"
To compile with openssl support use the following flags
make ADDCFLAGS="-DOPENSSL_RUNTIME -rdynamic" ADDLDFLAGS="-ldl"
The LibRHash static/shared library can be compiled by
'make lib-static' or 'make lib-shared'
Windows Installation:
=====================
You need MinGW compiler and MSYS environment.
To compile the program run 'make'.
Optionally you can run 'make test'.
The LibRHash DLL can be created by
cd librhash && make dll test-dll
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
```
This diff is collapsed.
......@@ -8,13 +8,13 @@ RIPEMD-160, HAS-160, EDON-R, Whirlpool and Snefru.
Hash sums are used to ensure and verify integrity of large volumes of data
for a long-term storing or transferring.
Features:
Program features:
* Output in a predefined (SFV, BSD-like) or a user-defined format.
* Can calculate Magnet links.
* Updating hash files (adding hash sums of files missing in the hash file).
* Calculates several hash sums in one pass
* Calculation of Magnet links.
* Ability to process directories recursively.
* Portability: the program works the same on Linux, *BSD or Windows.
* 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.
=== The LibRHash library ===
......@@ -40,7 +40,7 @@ Features:
* RHash hash functions descriptions http://rhash.anz.ru/hashes.php
* The table of the hash functions supported by RHash
http://sf.net/apps/mediawiki/rhash/index.php?title=Hash_sums
https://sf.net/p/rhash/wiki/HashFunctions/
* ECRYPT: The Hash Function Zoo
http://ehash.iaik.tugraz.at/wiki/The_Hash_Function_Zoo
......
......@@ -3,9 +3,9 @@ BINDINGS = java mono perl python ruby php
FILES = Makefile version.properties ChangeLog COPYING
DESTDIR =
PREFIX = /usr/local
RUBY = ruby
PYTHON = python
PERL = perl
RUBY ?= ruby
PYTHON ?= python
PERL ?= perl
CP = cp -l --parents
PERL_OPTIMIZE = -O2 -g -Wall
ARCHIVE_GZIP = rhash-bindings-$(VERSION)-src.tar.gz
......@@ -33,62 +33,62 @@ ruby/Makefile: ruby/extconf.rb
$(RUBY) -C ruby extconf.rb
build-java:
$(MAKE) -C java build-binary
+$(MAKE) -C java build-binary
build-perl: configure-perl
$(MAKE) -C perl OPTIMIZE="$(PERL_OPTIMIZE)"
+$(MAKE) -C perl OPTIMIZE="$(PERL_OPTIMIZE)"
build-php: configure-php
$(MAKE) -C php
+$(MAKE) -C php
build-python:
# not required
build-ruby: configure-ruby
$(MAKE) -C ruby
+$(MAKE) -C ruby
build-mono:
$(MAKE) -C mono
+$(MAKE) -C mono
test-java:
$(MAKE) -C java test
+$(MAKE) -C java test
test-perl:
$(MAKE) -C perl test
+$(MAKE) -C perl test
test-php:
$(MAKE) -C php test TEST_PHP_ARGS=-q
+$(MAKE) -C php test TEST_PHP_ARGS=-q
test-ruby:
$(RUBY) -C ruby -I. test_rhash.rb
test-mono:
$(MAKE) -C mono test
+$(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
+MAKEFLAGS= $(MAKE) -C ruby install DESTDIR=$(DESTDIR) sitedir=$(DESTDIR)/usr/lib/ruby
install-perl:
$(MAKE) -C perl install DESTDIR=$(DESTDIR)
+$(MAKE) -C perl install DESTDIR=$(DESTDIR)
install-php:
$(MAKE) -C php install INSTALL_ROOT=$(DESTDIR)
+$(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\)\|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
+$(MAKE) copy-dist
tar -czf $(ARCHIVE_GZIP) --owner=root:0 --group=root:0 "$(COPYDIR)"
rm -rf "$(COPYDIR)"
......@@ -110,9 +110,9 @@ cpan:
rm -rf $(PERL_PKG)/
distclean:
$(MAKE) -C java distclean
$(MAKE) -C mono clean
[ ! -f ruby/Makefile ] || $(MAKE) -C ruby distclean
[ ! -f perl/Makefile ] || $(MAKE) -C perl distclean
+$(MAKE) -C java distclean
+$(MAKE) -C mono clean
+[ ! -f ruby/Makefile ] || $(MAKE) -C ruby distclean
+[ ! -f perl/Makefile ] || $(MAKE) -C perl distclean
[ ! -f php/configure ] || (cd php && phpize --clean)
rm -f python/*.pyc
......@@ -53,7 +53,7 @@ jar-symlink:
ln -fs rhash-$(VERSION).jar $(DEST_DIR)/rhash.jar
$(JARFILE): $(JAVA_FILES)
$(MAKE) compile-classes
+$(MAKE) compile-classes
mkdir -p $(DEST_DIR)
$(JAR) cf $(JARFILE) -C $(CLASSES_DIR) org/
......@@ -65,7 +65,7 @@ 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)
+$(MAKE) -C $(CSRC_DIR)
mkdir -p $(DEST_DIR)
cp $(CSRC_DIR)/$(JNI_LIBRARY) $(DEST_DIR)
......@@ -77,7 +77,7 @@ javadoc: clean-javadoc
-link $(JAVADOC_API_URL)
$(JAVADOC_FILE): $(JAVA_FILES)
$(MAKE) javadoc
+$(MAKE) javadoc
jar -cMf $(JAVADOC_FILE) $(JAVADOC_DIR)
$(TEST_DIR)/RHashTest.class: $(JARFILE) $(TEST_DIR)/RHashTest.java
......@@ -95,7 +95,7 @@ clean-classes:
rm -rf $(CLASSES_DIR)
clean-jni:
$(MAKE) -C $(CSRC_DIR) clean
+$(MAKE) -C $(CSRC_DIR) clean
clean-test:
rm -f $(TEST_DIR)/*.class
......
......@@ -23,11 +23,7 @@ namespace RHash {
/* Pointer to native structure. */
sealed class Bindings {
#if UNIX
private const string librhash = "librhash.so.0";
#else
private const string librhash = "librhash.dll";
#endif
private Bindings() { }
......
......@@ -15,8 +15,8 @@
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. Use it at your own risk!
CS=gmcs
MDOC=mdoc
CS?=mcs
MDOC?=mdoc
SOURCES=AssemblyInfo.cs Bindings.cs Hasher.cs HashType.cs
all: assembly assemble-doc html
......@@ -24,7 +24,7 @@ all: assembly assemble-doc html
assembly: RHash.dll RHash.dll.mdb
RHash.dll RHash.dll.mdb: $(SOURCES)
$(CS) -target:library -define:UNIX -out:RHash.dll -debug -keyfile:RHash.snk $(SOURCES)
$(CS) -target:library -out:RHash.dll -debug -keyfile:RHash.snk $(SOURCES)
update-doc: RHash.dll
$(MDOC) update RHash.dll -o doc
......@@ -38,13 +38,12 @@ html:
$(MDOC) export-html -o html doc
test: RHash.dll
cp RHash.dll test/
$(MAKE) -C test
+$(MAKE) -C test
clean:
rm -f RHash.dll RHash.dll.mdb
rm -f RHash.tree RHash.zip
rm -rf html
$(MAKE) -C test clean
+$(MAKE) -C test clean
.PHONY : clean html test
<configuration>
<dllmap dll="librhash.dll" os="!windows" target="librhash.so.0" />
<dllmap dll="librhash.dll" os="osx" target="librhash.0.dylib" />
</configuration>
......@@ -15,14 +15,15 @@
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. Use it at your own risk!
MONO=mono
CS=gmcs
MONO?=mono
CS?=mcs
MONO_PATH?=..
test: Test.exe
$(MONO) Test.exe
MONO_PATH="$(MONO_PATH)" $(MONO) Test.exe
Test.exe: Test.cs
$(CS) -r:RHash.dll Test.cs
$(CS) -r:RHash.dll -lib:.. Test.cs
clean:
rm -f Test.exe RHash.dll
rm -f Test.exe
......@@ -47,5 +47,5 @@
"url" : "https://github.com/rhash/RHash"
}
},
"version" : "0.93"
"version" : "0.94"
}
......@@ -23,4 +23,4 @@ resources:
homepage: http://rhash.sf.net/
license: http://rhash.anz.ru/license.php
repository: https://github.com/rhash/RHash
version: 0.93
version: 0.94
......@@ -21,7 +21,7 @@ our %EXPORT_TAGS = (
Exporter::export_tags( );
Exporter::export_ok_tags( qw(Functions Constants) );
our $VERSION = '0.93';
our $VERSION = '0.94';
require XSLoader;
XSLoader::load('Crypt::Rhash', $VERSION);
......@@ -358,7 +358,7 @@ Returns the hash mask, the $rhash object was constructed with.
=back
=head1 FORMATING HASH VALUE
=head1 FORMATTING HASH VALUE
Computed hash can be formatted as a hexadecimal string (in the forward or
reverse byte order), a base32/base64-encoded string or as raw binary data.
......
......@@ -82,6 +82,12 @@ from ctypes import (
# initialization
if sys.platform == 'win32':
LIBNAME = 'librhash.dll'
elif sys.platform == 'darwin':
LIBNAME = 'librhash.0.dylib'
elif sys.platform == 'cygwin':
LIBNAME = 'cygrhash.dll'
elif sys.platform == 'msys':
LIBNAME = 'msys-rhash.dll'
else:
LIBNAME = 'librhash.so.0'
LIBRHASH = CDLL(LIBNAME)
......
......@@ -300,6 +300,7 @@ void Init_rhash() {
while block = f.read(4096) \n\
self.update(block) \n\
end \n\
f.close \n\
self \n\
end \n\
end\n\
......
/* calc_sums.c - crc calculating and printing functions */
#include "common_func.h" /* should be included before the C library files */
#include "platform.h" /* unlink() on unix */
#include <stdio.h>
#include <string.h>
#include <stdlib.h> /* free() */
#include <unistd.h> /* read() */
#include <fcntl.h> /* open() */
#include <time.h> /* localtime(), time() */
#include <sys/stat.h> /* stat() */
#include <errno.h>
#include <assert.h>
#ifdef _WIN32
# include <fcntl.h> /* _O_BINARY */
# include <io.h>
#endif
#include "librhash/rhash.h"
#include "librhash/rhash_torrent.h"
#include "parse_cmdline.h"
#include "rhash_main.h"
#include "calc_sums.h"
#include "common_func.h"
#include "file.h"
#include "hash_print.h"
#include "output.h"
#include "parse_cmdline.h"
#include "rhash_main.h"
#include "win_utils.h"
#include "calc_sums.h"
#include "librhash/rhash.h"
#include "librhash/rhash_torrent.h"
/**
* Initialize BTIH hash function. Unlike other algorithms BTIH
......@@ -123,10 +124,8 @@ static int calc_sums(struct file_info *info)
/* skip without reporting an error the files
* opened exclusively by another process */
fd = rsh_fopen_bin(info->full_path, "rb");
if (!fd) {
return -1;
}
fd = file_fopen(info->file, FOpenRead | FOpenBin);
if (!fd) return -1;
}
re_init_rhash_context(info);
......@@ -315,6 +314,7 @@ int rename_file_by_embeding_crc32(struct file_info *info)
*/
int save_torrent_to(const char* path, rhash_context* rctx)
{
file_t file;
FILE* fd;
int res = 0;
......@@ -334,7 +334,8 @@ int save_torrent_to(const char* path, rhash_context* rctx)
}
/* write the torrent file */
fd = rsh_fopen_bin(path, "wb");
file_init(&file, path, FILE_OPT_DONT_FREE_PATH);
fd = file_fopen(&file, FOpenWrite | FOpenBin);
if (fd && text->length == fwrite(text->str, 1, text->length, fd) &&
!ferror(fd) && !fflush(fd))
{
......@@ -344,6 +345,7 @@ int save_torrent_to(const char* path, rhash_context* rctx)
res = -1;
}
if (fd) fclose(fd);
file_cleanup(&file);
return res;
}
......@@ -397,7 +399,7 @@ int calculate_and_print_sums(FILE* out, file_t* file, const char *print_path)
/* calculate sums */
if (calc_sums(&info) < 0) {
/* print i/o error */
log_file_error(file->path);
log_file_t_error(file);
res = -1;
}
if (rhash_data.interrupted) {
......@@ -431,12 +433,10 @@ int calculate_and_print_sums(FILE* out, file_t* file, const char *print_path)
if (rhash_data.print_list && res >= 0) {
if (!opt.bt_batch_file) {
print_line(out, rhash_data.print_list, &info);
fflush(out);
/* print calculated line to stderr or log-file if verbose */
if ((opt.mode & MODE_UPDATE) && (opt.flags & OPT_VERBOSE)) {
print_line(rhash_data.log, rhash_data.print_list, &info);
fflush(rhash_data.log);
}
}
......@@ -551,7 +551,7 @@ int check_hash_file(file_t* file, int chdir)
if (file->mode & FILE_IFSTDIN) {
fd = stdin;
hash_file_path = "<stdin>";
} else if ( !(fd = rsh_fopen_bin(hash_file_path, "rb") )) {
} else if ( !(fd = file_fopen(file, FOpenRead | FOpenBin) )) {
log_file_error(hash_file_path);
return -1;
}
......@@ -624,7 +624,7 @@ int check_hash_file(file_t* file, int chdir)
}
memset(&file_to_check, 0, sizeof(file_t));
file_to_check.path = info.full_path;
file_stat(&file_to_check);
file_stat(&file_to_check, 0);
info.file = &file_to_check;
/* verify hash sums of the file */
......
......@@ -10,8 +10,7 @@
extern "C" {
#endif
#include <sys/types.h> /* struct stat */
#include <sys/stat.h> /* stat() */
struct file_t;
/**
* Information about a file to calculate/verify hashes for.
......@@ -38,8 +37,8 @@ void file_info_destroy(struct file_info*); /* free allocated memory */
const char* file_info_get_utf8_print_path(struct file_info*);
int save_torrent_to(const char* path, struct rhash_context* rctx);
int calculate_and_print_sums(FILE* out, file_t* file, const char *print_path);
int check_hash_file(file_t* file, int chdir);
int calculate_and_print_sums(FILE* out, struct file_t* file, const char *print_path);
int check_hash_file(struct file_t* file, int chdir);
int rename_file_by_embeding_crc32(struct file_info *info);
/* Benchmarking */
......
/* common_func.c */
/* common_func.c - functions used almost everywhere */
#include "common_func.h" /* should be included before the C library files */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <stdint.h>
#include <time.h>
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <errno.h>
#include <sys/stat.h>
#ifdef _WIN32
#include <windows.h>
#if defined( _WIN32) || defined(__CYGWIN__)
# include <windows.h>
#endif
#include "win_utils.h"
#include "common_func.h"
#include "parse_cmdline.h"
#include "version.h"
#include "win_utils.h"
/*=========================================================================
* String functions
......@@ -233,106 +229,6 @@ const char* get_bt_program_name(void)
return bt_program_name;
}
/*=========================================================================
* Path functions
*=========================================================================*/
/**
* Return filename without path.
*
* @param path file path
* @return filename
*/
const char* get_basename(const char* path)
{
const char *p = path + strlen(path) - 1;
for (; p >= path && !IS_PATH_SEPARATOR(*p); p--);
return (p+1);
}
/**
* Return allocated buffer with the directory part of the path.
* The buffer must be freed by calling free().
*
* @param path file path
* @return directory
*/
char* get_dirname(const char* path)
{
const char *p = path + strlen(path) - 1;
char *res;
for (; p > path && !IS_PATH_SEPARATOR(*p); p--);
if ((p - path) > 1) {
res = (char*)rsh_malloc(p-path+1);
memcpy(res, path, p-path);
res[p-path] = 0;
return res;
} else {
return rsh_strdup(".");
}
}
/**
* Assemble a filepath from its directory and filename.
*
* @param dir_path directory path
* @param filename file name
* @return filepath
*/
char* make_path(const char* dir_path, const char* filename)
{
char* buf;
size_t len;
assert(dir_path);
assert(filename);
/* remove leading path separators from filename */
while (IS_PATH_SEPARATOR(*filename)) filename++;
if (dir_path[0] == '.' && dir_path[1] == 0) {
/* do not extend filename for dir_path="." */
return rsh_strdup(filename);
}
/* copy directory path */
len = strlen(dir_path);
buf = (char*)rsh_malloc(len + strlen(filename) + 2);
strcpy(buf, dir_path);
/* separate directory from filename */
if (len > 0 && !IS_PATH_SEPARATOR(buf[len-1])) {
buf[len++] = SYS_PATH_SEPARATOR;
}
/* append filename */
strcpy(buf+len, filename);
return buf;
}
#define IS_ANY_SLASH(c) ((c) == RSH_T('/') || (c) == RSH_T('\\'))
/**
* Compare paths.
*
* @param a the first path
* @param b the second path
*/
int are_paths_equal(const rsh_tchar* a, const rsh_tchar* b)
{
if (!a || !b) return 0;
if (a[0] == RSH_T('.') && IS_ANY_SLASH(a[1])) a += 2;
if (b[0] == RSH_T('.') && IS_ANY_SLASH(b[1])) b += 2;
for (; *a; ++a, ++b) {
if (*a != *b && (!IS_ANY_SLASH(*b) || !IS_ANY_SLASH(*a))) {
/* paths are different */
return 0;
}
}
/* check if both paths terminated */
return (*a == *b);
}
/*=========================================================================
* Timer functions
*=========================================================================*/
......@@ -347,7 +243,7 @@ int are_paths_equal(const rsh_tchar* a, const rsh_tchar* b)
*/
static double rsh_fsec(timedelta_t* timer)
{
#ifdef _WIN32
#if defined( _WIN32) || defined(__CYGWIN__)
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
return (double)*timer / freq.QuadPart;
......@@ -356,8 +252,7 @@ static double rsh_fsec(timedelta_t* timer)
#endif
}
#ifdef _WIN32
#include <windows.h>
#if defined( _WIN32) || defined(__CYGWIN__)
#define get_timedelta(delta) QueryPerformanceCounter((LARGE_INTEGER*)delta)
#else
#define get_timedelta(delta) gettimeofday(delta, NULL)
......@@ -372,7 +267,7 @@ double rsh_timer_stop(timedelta_t* timer)
{