#4400, #5462: Move random helpers to crypto-utils

On a way to factoring out OpenSSL support to a standalone file to ease
addition of other crypto libraries support in the future, move helpers
providing random numbers/data generation to crypto-utils.{c,h}. OpenSSL-
related functionality (generation of cryptographically strong random
data) is moved to crypto-utils-openssl.c.

Rename functions to follow currently accepted style:
* tr_cryptoRandBuf -> tr_rand_buffer
* tr_cryptoRandInt -> tr_rand_int
* tr_cryptoWeakRandInt -> tr_rand_int_weak

Fix rare case of invalid value being returned from tr_rand_int. Return
value for abs(INT_MIN) may be undefined and thus negative, and so
tr_rand_int will return negative value which is incorrect (out of
requested and expected range).


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14354 f4695dd4-2c0a-0410-b89c-da849a56a58e
#4400, #5462: Move SHA1 helpers to crypto-utils

On a way to factoring out OpenSSL support to a standalone file to ease
addition of other crypto libraries support in the future, move helpers
providing SHA1 calculation to crypto-utils.{c,h}. OpenSSL-related
functionality (SHA1 context management) is moved to crypto-utils-openssl.c.

Add new tr_sha1_ctx_t type and functions to be implemented by crypto
backends:
* tr_sha1_init - allocate SHA1 context and and initialize it,
* tr_sha1_update - hash some [more] data,
* tr_sha1_final - finish hash calculation and free the context.

Add new files to CMakeLists.txt (leftover from previous commit) to fix
CMake-based configuration.


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14355 f4695dd4-2c0a-0410-b89c-da849a56a58e
#4400, #5462: Move RC4 helpers to crypto-utils

On a way to factoring out OpenSSL support to a standalone file to ease
addition of other crypto libraries support in the future, move helpers
providing RC4 ciphering to crypto-utils.{c,h}. OpenSSL-related
functionality (RC4 context management) is moved to crypto-utils-openssl.c.

Add new tr_rc4_ctx_t type and functions to be implemented by crypto
backends:
* tr_rc4_new - allocate RC4 context,
* tr_rc4_free - free the context,
* tr_rc4_set_key - set cipher key,
* tr_rc4_process - cipher memory block.


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14356 f4695dd4-2c0a-0410-b89c-da849a56a58e
#4400, #5462: Do not assert on input to SHA1 or RC4 if input length is 0.


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14357 f4695dd4-2c0a-0410-b89c-da849a56a58e
#4400, #5462: Move DH helpers to crypto-utils

On a way to factoring out OpenSSL support to a standalone file to ease
addition of other crypto libraries support in the future, move helpers
providing DH key exchange to crypto-utils.{c,h}. OpenSSL-related
functionality (DH context management) is moved to crypto-utils-openssl.c.
Since we know in advance that DH secret key management code will be the
same for most of backends, implement common functionality in separate
crypto-utils-fallback.c.

Add new tr_dh_ctx_t and tr_dh_secret_t types and functions to be
implemented by crypto backends:
* tr_dh_new - allocate DH context,
* tr_dh_free - free the context,
* tr_dh_make_key - generate private/public keypair,
* tr_dh_agree - perform DH key exchange and generate secret key,
* tr_dh_secret_derive - calculate secret key hash,
* tr_dh_secret_free - free the secret key,
* tr_dh_align_key - align some DH key in the buffer allocated for it.

Make DH secret key not accessible in plain form outside the crypto
backend. This allows for implementations where the key is managed by
the underlying library and is not even exposed to our backend.


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14358 f4695dd4-2c0a-0410-b89c-da849a56a58e
#4400, #5462: Move BASE64 helpers to crypto-utils

On a way to factoring out OpenSSL support to a standalone file to ease
addition of other crypto libraries support in the future, move helpers
providing BASE64 encoding and decoding to crypto-utils.{c,h}. OpenSSL-
related functionality is moved to crypto-utils-openssl.c.

Add new functions to be implemented by crypto backends:
* tr_base64_encode_impl - encode from binary to BASE64,
* tr_base64_decode_impl - decode from BASE64 to binary.

Change `tr_base64_encode` and `tr_base64_decode` functions to expect
non-negative input data length which is considered real and never adjusted.
To process null-terminated strings (which was achieved before by passing 0
or -1 as input data length), add new `tr_base64_encode_str` and
`tr_base64_decode_str` functions which do not accept input data length as
an argument but calculate it on their own.


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14359 f4695dd4-2c0a-0410-b89c-da849a56a58e
#4400, #5462: Move SSHA1 helpers to crypto-utils

On a way to factoring out OpenSSL support to a standalone file to ease
addition of other crypto libraries support in the future, move helpers
providing SSHA1 password generation and checking to crypto-utils.{c,h}.


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14360 f4695dd4-2c0a-0410-b89c-da849a56a58e
#4400, #5462: Move SHA1/HEX helpers to crypto-utils

On a way to factoring out OpenSSL support to a standalone file to ease
addition of other crypto libraries support in the future, move helpers
providing SHA1/HEX conversion to crypto-utils.{c,h}.

Rename functions:
* tr_sha1_to_hex -> tr_binary_to_hex (add length argument),
* tr_hex_to_sha1 -> tr_hex_to_binary (add length argument).

Make tr_sha1_to_hex and tr_hex_to_sha1 wrappers around above functions.


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14361 f4695dd4-2c0a-0410-b89c-da849a56a58e
#4400, #5462: Fix Mac build by adding new crypto-utils files to Xcode project.


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14362 f4695dd4-2c0a-0410-b89c-da849a56a58e
Remove duplicate -Wcast-align flag, add canonicalize_file_name function check


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14363 f4695dd4-2c0a-0410-b89c-da849a56a58e
Include CTest to enable memcheck


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14364 f4695dd4-2c0a-0410-b89c-da849a56a58e
Increase move test timeouts from 5 sec to 5 min


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14365 f4695dd4-2c0a-0410-b89c-da849a56a58e
Fix small memory leaks in crypto (base64) and rename (multi-file torrent) unit tests


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14366 f4695dd4-2c0a-0410-b89c-da849a56a58e
#5369: Improve file allocation error checking (initial patch by g.proskurin)

Additionally,
* always close file descriptor on error in cached_file_open (FD leak),
* only store file descriptor to tr_cached_file on success,
* call ftruncate after xfsctl-based preallocation so that correct size
  is reported by the system.


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14367 f4695dd4-2c0a-0410-b89c-da849a56a58e
Fix tr_moveFile error reporting

Remove unused `renamed` argument.
Use tr_error instead of errno to report errors to support Win32 file
wrappers which do not map Windows error codes to POSIX ones.
Return bool instead of int (0/-1).

Uncomment tr_error_prefix and tr_error_propagate_prefixed functions.


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14368 f4695dd4-2c0a-0410-b89c-da849a56a58e
Add missing svn:keywords property to recently (and not so recently) added files


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14369 f4695dd4-2c0a-0410-b89c-da849a56a58e
Fix a couple of ordinary and pedantic warnings

Add previously missing -Wall to warning flags in CMake. Remove -Wformat
and -Wvariadic-macros (enabled by default; latter is not meaningful in
C99 mode we use), -Wdeclaration-after-statement (again, not needed as
we use C99). Move -Wmissing-declarations to C-only flags (GCC man says
so).

Add copyrights year to crypto-utils-fallback.c.


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14370 f4695dd4-2c0a-0410-b89c-da849a56a58e
Fix utils test; move -Winline to C-only flags (it only harms C++)


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14371 f4695dd4-2c0a-0410-b89c-da849a56a58e
#5407: Fix crash on Mac when pausing torrents (patch by x190)


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14372 f4695dd4-2c0a-0410-b89c-da849a56a58e
#5692: Fix build under Cygwin (patch by rb07)


git-svn-id: svn://svn.transmissionbt.com/Transmission/trunk@14373 f4695dd4-2c0a-0410-b89c-da849a56a58e