summaryrefslogtreecommitdiff
path: root/Utilities/cmlibrhash
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-11-03 11:15:19 -0400
committerBrad King <brad.king@kitware.com>2016-11-10 08:26:54 -0500
commit53048afa8dc24327d82a1ff0f78801e1f344a4b6 (patch)
treefff00aff401fe55e08d9371a194735a0eaf4980c /Utilities/cmlibrhash
parent5cb1b345d932d3e0dc34a2d423894a59a6c8db35 (diff)
downloadcmake-53048afa8dc24327d82a1ff0f78801e1f344a4b6.tar.gz
librhash: Remove source fragments not needed for CMake
We only need a subset of the hash algorithms supported by librhash. Add preprocessor conditionals to remove source fragments that we do not need. Write an alternative algorithm enumeration that matches the indexing on our reduced array. Also remove a few fragments outright.
Diffstat (limited to 'Utilities/cmlibrhash')
-rw-r--r--Utilities/cmlibrhash/README54
-rw-r--r--Utilities/cmlibrhash/librhash/algorithms.c24
-rw-r--r--Utilities/cmlibrhash/librhash/byte_order.h4
-rw-r--r--Utilities/cmlibrhash/librhash/rhash.c59
-rw-r--r--Utilities/cmlibrhash/librhash/rhash.h31
5 files changed, 47 insertions, 125 deletions
diff --git a/Utilities/cmlibrhash/README b/Utilities/cmlibrhash/README
index 1e510170c0..4ea492fd2d 100644
--- a/Utilities/cmlibrhash/README
+++ b/Utilities/cmlibrhash/README
@@ -1,57 +1,3 @@
- === RHash program ===
-
-RHash is a console utility for calculation and verification of magnet links
-and a wide range of hash sums like CRC32, MD4, MD5, SHA1, SHA256, SHA512,
-SHA3, AICH, ED2K, Tiger, DC++ TTH, BitTorrent BTIH, GOST R 34.11-94,
-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:
- * 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
- * Ability to process directories recursively.
- * Portability: the program works the same on Linux, *BSD or Windows.
-
-
- === The LibRHash library ===
-
-LibRHash is a professional, portable, thread-safe C library for computing
-a wide variety of hash sums, such as CRC32, MD4, MD5, SHA1, SHA256, SHA512,
-SHA3, AICH, ED2K, Tiger, DC++ TTH, BitTorrent BTIH, GOST R 34.11-94,
-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:
- * Small and easy to learn interface.
- * Hi-level and Low-level API.
- * Allows calculating of several hash functions simultaneously.
- * Portability: the library works on Linux, *BSD and Windows.
-
-
- === Links ===
-
- * Project Home Page: http://rhash.sourceforge.net/
- * Official Releases: http://sf.net/projects/rhash/files/rhash/
-
- * 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
- * ECRYPT: The Hash Function Zoo
- http://ehash.iaik.tugraz.at/wiki/The_Hash_Function_Zoo
-
-
- === Getting latest source code ===
-
-The latest source code can be obtained from Git repository by command:
-
- git clone git://github.com/rhash/RHash.git
-
-
=== Notes on RHash License ===
The RHash program and LibRHash library are distributed under RHash License,
diff --git a/Utilities/cmlibrhash/librhash/algorithms.c b/Utilities/cmlibrhash/librhash/algorithms.c
index 1f343a167a..56d20b8676 100644
--- a/Utilities/cmlibrhash/librhash/algorithms.c
+++ b/Utilities/cmlibrhash/librhash/algorithms.c
@@ -22,6 +22,7 @@
#include "algorithms.h"
/* header files of all supported hash sums */
+#if 0
#include "aich.h"
#include "crc32.h"
#include "ed2k.h"
@@ -29,17 +30,21 @@
#include "gost.h"
#include "has160.h"
#include "md4.h"
+#endif
#include "md5.h"
+#if 0
#include "ripemd-160.h"
#include "snefru.h"
+#endif
#include "sha1.h"
#include "sha256.h"
#include "sha512.h"
+#if 0
#include "sha3.h"
#include "tiger.h"
-#include "torrent.h"
#include "tth.h"
#include "whirlpool.h"
+#endif
#ifdef USE_OPENSSL
/* note: BTIH and AICH depends on the used SHA1 algorithm */
@@ -66,14 +71,19 @@ unsigned rhash_uninitialized_algorithms = RHASH_NEED_INIT_ALG;
rhash_hash_info* rhash_info_table = rhash_hash_info_default;
int rhash_info_size = RHASH_HASH_COUNT;
+#if 0
static void rhash_crc32_init(uint32_t* crc32);
static void rhash_crc32_update(uint32_t* crc32, const unsigned char* msg, size_t size);
static void rhash_crc32_final(uint32_t* crc32, unsigned char* result);
+#endif
+#if 0
rhash_info info_crc32 = { RHASH_CRC32, F_BE32, 4, "CRC32", "crc32" };
rhash_info info_md4 = { RHASH_MD4, F_LE32, 16, "MD4", "md4" };
+#endif
rhash_info info_md5 = { RHASH_MD5, F_LE32, 16, "MD5", "md5" };
rhash_info info_sha1 = { RHASH_SHA1, F_BE32, 20, "SHA1", "sha1" };
+#if 0
rhash_info info_tiger = { RHASH_TIGER, F_LE64, 24, "TIGER", "tiger" };
rhash_info info_tth = { RHASH_TTH, F_BS32, 24, "TTH", "tree:tiger" };
rhash_info info_btih = { RHASH_BTIH, 0, 20, "BTIH", "btih" };
@@ -86,16 +96,19 @@ rhash_info info_gostpro = { RHASH_GOST_CRYPTOPRO, F_LE32, 32, "GOST-CRYPTOPRO",
rhash_info info_has160 = { RHASH_HAS160, F_LE32, 20, "HAS-160", "has160" };
rhash_info info_snf128 = { RHASH_SNEFRU128, F_BE32, 16, "SNEFRU-128", "snefru128" };
rhash_info info_snf256 = { RHASH_SNEFRU256, F_BE32, 32, "SNEFRU-256", "snefru256" };
+#endif
rhash_info info_sha224 = { RHASH_SHA224, F_BE32, 28, "SHA-224", "sha224" };
rhash_info info_sha256 = { RHASH_SHA256, F_BE32, 32, "SHA-256", "sha256" };
rhash_info info_sha384 = { RHASH_SHA384, F_BE64, 48, "SHA-384", "sha384" };
rhash_info info_sha512 = { RHASH_SHA512, F_BE64, 64, "SHA-512", "sha512" };
+#if 0
rhash_info info_edr256 = { RHASH_EDONR256, F_LE32, 32, "EDON-R256", "edon-r256" };
rhash_info info_edr512 = { RHASH_EDONR512, F_LE64, 64, "EDON-R512", "edon-r512" };
rhash_info info_sha3_224 = { RHASH_SHA3_224, F_LE64, 28, "SHA3-224", "sha3-224" };
rhash_info info_sha3_256 = { RHASH_SHA3_256, F_LE64, 32, "SHA3-256", "sha3-256" };
rhash_info info_sha3_384 = { RHASH_SHA3_384, F_LE64, 48, "SHA3-384", "sha3-384" };
rhash_info info_sha3_512 = { RHASH_SHA3_512, F_LE64, 64, "SHA3-512", "sha3-512" };
+#endif
/* some helper macros */
#define dgshft(name) (((char*)&((name##_ctx*)0)->hash) - (char*)0)
@@ -109,13 +122,15 @@ rhash_info info_sha3_512 = { RHASH_SHA3_512, F_LE64, 64, "SHA3-512", "sha3-512"
/* information about all hashes */
rhash_hash_info rhash_hash_info_default[RHASH_HASH_COUNT] =
{
+#if 0
{ &info_crc32, sizeof(uint32_t), 0, iuf(rhash_crc32), 0 }, /* 32 bit */
{ &info_md4, sizeof(md4_ctx), dgshft(md4), iuf(rhash_md4), 0 }, /* 128 bit */
+#endif
{ &info_md5, sizeof(md5_ctx), dgshft(md5), iuf(rhash_md5), 0 }, /* 128 bit */
{ &info_sha1, sizeof(sha1_ctx), dgshft(sha1), iuf(rhash_sha1), 0 }, /* 160 bit */
+#if 0
{ &info_tiger, sizeof(tiger_ctx), dgshft(tiger), iuf(rhash_tiger), 0 }, /* 192 bit */
{ &info_tth, sizeof(tth_ctx), dgshft2(tth, tiger.hash), iuf(rhash_tth), 0 }, /* 192 bit */
- { &info_btih, sizeof(torrent_ctx), dgshft2(torrent, btih), iuf(bt), (pcleanup_t)bt_cleanup }, /* 160 bit */
{ &info_ed2k, sizeof(ed2k_ctx), dgshft2(ed2k, md4_context_inner.hash), iuf(rhash_ed2k), 0 }, /* 128 bit */
{ &info_aich, sizeof(aich_ctx), dgshft2(aich, sha1_context.hash), iuf(rhash_aich), (pcleanup_t)rhash_aich_cleanup }, /* 160 bit */
{ &info_whirlpool, sizeof(whirlpool_ctx), dgshft(whirlpool), iuf(rhash_whirlpool), 0 }, /* 512 bit */
@@ -125,16 +140,19 @@ rhash_hash_info rhash_hash_info_default[RHASH_HASH_COUNT] =
{ &info_has160, sizeof(has160_ctx), dgshft(has160), iuf(rhash_has160), 0 }, /* 160 bit */
{ &info_snf128, sizeof(snefru_ctx), dgshft(snefru), ini(rhash_snefru128), upd(rhash_snefru), fin(rhash_snefru), 0 }, /* 128 bit */
{ &info_snf256, sizeof(snefru_ctx), dgshft(snefru), ini(rhash_snefru256), upd(rhash_snefru), fin(rhash_snefru), 0 }, /* 256 bit */
+#endif
{ &info_sha224, sizeof(sha256_ctx), dgshft(sha256), ini(rhash_sha224), upd(rhash_sha256), fin(rhash_sha256), 0 }, /* 224 bit */
{ &info_sha256, sizeof(sha256_ctx), dgshft(sha256), iuf(rhash_sha256), 0 }, /* 256 bit */
{ &info_sha384, sizeof(sha512_ctx), dgshft(sha512), ini(rhash_sha384), upd(rhash_sha512), fin(rhash_sha512), 0 }, /* 384 bit */
{ &info_sha512, sizeof(sha512_ctx), dgshft(sha512), iuf(rhash_sha512), 0 }, /* 512 bit */
+#if 0
{ &info_edr256, sizeof(edonr_ctx), dgshft2(edonr, u.data256.hash) + 32, iuf(rhash_edonr256), 0 }, /* 256 bit */
{ &info_edr512, sizeof(edonr_ctx), dgshft2(edonr, u.data512.hash) + 64, iuf(rhash_edonr512), 0 }, /* 512 bit */
{ &info_sha3_224, sizeof(sha3_ctx), dgshft(sha3), ini(rhash_sha3_224), upd(rhash_sha3), fin(rhash_sha3), 0 }, /* 224 bit */
{ &info_sha3_256, sizeof(sha3_ctx), dgshft(sha3), ini(rhash_sha3_256), upd(rhash_sha3), fin(rhash_sha3), 0 }, /* 256 bit */
{ &info_sha3_384, sizeof(sha3_ctx), dgshft(sha3), ini(rhash_sha3_384), upd(rhash_sha3), fin(rhash_sha3), 0 }, /* 384 bit */
{ &info_sha3_512, sizeof(sha3_ctx), dgshft(sha3), ini(rhash_sha3_512), upd(rhash_sha3), fin(rhash_sha3), 0 }, /* 512 bit */
+#endif
};
/**
@@ -156,6 +174,7 @@ void rhash_init_algorithms(unsigned mask)
rhash_uninitialized_algorithms = 0;
}
+#if 0
/* CRC32 helper functions */
/**
@@ -198,3 +217,4 @@ static void rhash_crc32_final(uint32_t* crc32, unsigned char* result)
result[2] = (unsigned char)(*crc32 >> 8), result[3] = (unsigned char)(*crc32);
#endif
}
+#endif
diff --git a/Utilities/cmlibrhash/librhash/byte_order.h b/Utilities/cmlibrhash/librhash/byte_order.h
index 77b8bb9603..59a6c233b1 100644
--- a/Utilities/cmlibrhash/librhash/byte_order.h
+++ b/Utilities/cmlibrhash/librhash/byte_order.h
@@ -4,10 +4,6 @@
#include "ustd.h"
#include <stdlib.h>
-#ifdef IN_RHASH
-#include "config.h"
-#endif
-
#ifdef __GLIBC__
# include <endian.h>
#endif
diff --git a/Utilities/cmlibrhash/librhash/rhash.c b/Utilities/cmlibrhash/librhash/rhash.c
index 98cf97eb61..ad6249b177 100644
--- a/Utilities/cmlibrhash/librhash/rhash.c
+++ b/Utilities/cmlibrhash/librhash/rhash.c
@@ -32,8 +32,6 @@
#include "byte_order.h"
#include "algorithms.h"
-#include "torrent.h"
-#include "plug_openssl.h"
#include "util.h"
#include "hex.h"
#include "rhash.h" /* RHash library interface */
@@ -155,8 +153,10 @@ RHASH_API rhash rhash_init(unsigned hash_id)
rctx->vector[i].hash_info = info;
rctx->vector[i].context = phash_ctx;
+#if 0
/* BTIH initialization is complex, save pointer for later */
if ((id & RHASH_BTIH) != 0) rctx->bt_ctx = phash_ctx;
+#endif
phash_ctx += (info->context_size + 7) & ~7;
/* initialize the i-th hash context */
@@ -508,6 +508,7 @@ const rhash_info* rhash_info_by_id(unsigned hash_id)
return rhash_info_table[rhash_ctz(hash_id)].info;
}
+#if 0
/**
* Detect default digest output format for given hash algorithm.
*
@@ -519,6 +520,7 @@ RHASH_API int rhash_is_base32(unsigned hash_id)
/* fast method is just to test a bit-mask */
return ((hash_id & (RHASH_TTH | RHASH_AICH)) != 0);
}
+#endif
/**
* Returns size of binary digest for given hash algorithm.
@@ -572,6 +574,7 @@ RHASH_API const char* rhash_get_magnet_name(unsigned hash_id)
return (info ? info->magnet_name : 0);
}
+#if 0
static size_t rhash_get_magnet_url_size(const char* filepath,
rhash context, unsigned hash_mask, int flags)
{
@@ -809,47 +812,6 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID reserved)
}
#endif
-/**
- * Process a BitTorrent-related rhash message.
- *
- * @param msg_id message identifier
- * @param bt BitTorrent context
- * @param ldata data depending on message
- * @param rdata data depending on message
- * @return message-specific data
- */
-static rhash_uptr_t process_bt_msg(unsigned msg_id, torrent_ctx* bt, rhash_uptr_t ldata, rhash_uptr_t rdata)
-{
- if (bt == NULL) return RHASH_ERROR;
-
- switch (msg_id) {
- case RMSG_BT_ADD_FILE:
- bt_add_file(bt, (const char*)ldata, *(unsigned long long*)rdata);
- break;
- case RMSG_BT_SET_OPTIONS:
- bt_set_options(bt, (unsigned)ldata);
- break;
- case RMSG_BT_SET_ANNOUNCE:
- bt_add_announce(bt, (const char*)ldata);
- break;
- case RMSG_BT_SET_PIECE_LENGTH:
- bt_set_piece_length(bt, (size_t)ldata);
- break;
- case RMSG_BT_SET_BATCH_SIZE:
- bt_set_piece_length(bt,
- bt_default_piece_length(*(unsigned long long*)ldata));
- break;
- case RMSG_BT_SET_PROGRAM_NAME:
- bt_set_program_name(bt, (const char*)ldata);
- break;
- case RMSG_BT_GET_TEXT:
- return (rhash_uptr_t)bt_get_text(bt, (char**)ldata);
- default:
- return RHASH_ERROR; /* unknown message */
- }
- return 0;
-}
-
#define PVOID2UPTR(p) ((rhash_uptr_t)((char*)p - 0))
/**
@@ -902,18 +864,9 @@ RHASH_API rhash_uptr_t rhash_transmit(unsigned msg_id, void* dst, rhash_uptr_t l
return rhash_openssl_hash_mask;
#endif
- /* BitTorrent related messages */
- case RMSG_BT_ADD_FILE:
- case RMSG_BT_SET_OPTIONS:
- case RMSG_BT_SET_ANNOUNCE:
- case RMSG_BT_SET_PIECE_LENGTH:
- case RMSG_BT_SET_PROGRAM_NAME:
- case RMSG_BT_GET_TEXT:
- case RMSG_BT_SET_BATCH_SIZE:
- return process_bt_msg(msg_id, (torrent_ctx*)(((rhash_context_ext*)dst)->bt_ctx), ldata, rdata);
-
default:
return RHASH_ERROR; /* unknown message */
}
return 0;
}
+#endif
diff --git a/Utilities/cmlibrhash/librhash/rhash.h b/Utilities/cmlibrhash/librhash/rhash.h
index 73ee537e18..6d18c18e7e 100644
--- a/Utilities/cmlibrhash/librhash/rhash.h
+++ b/Utilities/cmlibrhash/librhash/rhash.h
@@ -20,6 +20,7 @@ extern "C" {
*/
enum rhash_ids
{
+#if 0
RHASH_CRC32 = 0x01,
RHASH_MD4 = 0x02,
RHASH_MD5 = 0x04,
@@ -58,6 +59,22 @@ enum rhash_ids
/** The number of supported hash functions */
RHASH_HASH_COUNT = 26
+#else
+ RHASH_MD5 = 0x01,
+ RHASH_SHA1 = 0x02,
+ RHASH_SHA224 = 0x04,
+ RHASH_SHA256 = 0x08,
+ RHASH_SHA384 = 0x10,
+ RHASH_SHA512 = 0x20,
+ RHASH_ALL_HASHES =
+ RHASH_MD5 |
+ RHASH_SHA1 |
+ RHASH_SHA224 |
+ RHASH_SHA256 |
+ RHASH_SHA384 |
+ RHASH_SHA512,
+ RHASH_HASH_COUNT = 6
+#endif
};
/**
@@ -136,6 +153,7 @@ RHASH_API const char* rhash_get_magnet_name(unsigned hash_id); /* get name part
/* note, that rhash_info_by_id() is not exported to a shared library or DLL */
const rhash_info* rhash_info_by_id(unsigned hash_id); /* get hash sum info by hash id */
+#if 0
/**
* Flags for printing a hash sum
*/
@@ -168,6 +186,7 @@ enum rhash_print_sum_flags
/** print file size in rhash_print_magnet */
RHPR_FILESIZE = 0x40,
};
+#endif
/* output hash into the given buffer */
RHASH_API size_t rhash_print_bytes(char* output,
@@ -213,18 +232,6 @@ RHASH_API rhash_uptr_t rhash_transmit(
#define RMSG_SET_OPENSSL_MASK 10
#define RMSG_GET_OPENSSL_MASK 11
-#define RMSG_BT_ADD_FILE 32
-#define RMSG_BT_SET_OPTIONS 33
-#define RMSG_BT_SET_ANNOUNCE 34
-#define RMSG_BT_SET_PIECE_LENGTH 35
-#define RMSG_BT_SET_PROGRAM_NAME 36
-#define RMSG_BT_GET_TEXT 37
-#define RMSG_BT_SET_BATCH_SIZE 38
-
-/* possible BitTorrent options for the RMSG_BT_SET_OPTIONS message */
-#define RHASH_BT_OPT_PRIVATE 1
-#define RHASH_BT_OPT_INFOHASH_ONLY 2
-
/* helper macros */
/** Get a pointer to context of the specified hash function */