1 /* algorithms.h - rhash library algorithms */ 2 #ifndef RHASH_ALGORITHMS_H 3 #define RHASH_ALGORITHMS_H 4 5 #include "rhash.h" 6 #include "byte_order.h" 7 #include <stddef.h> 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #ifndef RHASH_API 14 /* modifier for RHash library functions */ 15 # define RHASH_API 16 #endif 17 18 /** 19 * Bit flag: default hash output format is base32. 20 */ 21 #define RHASH_INFO_BASE32 1 22 23 /** 24 * Information about a hash function. 25 */ 26 typedef struct rhash_info 27 { 28 /** 29 * Hash function indentifier. 30 */ 31 unsigned hash_id; 32 /** 33 * Flags bit-mask, including RHASH_INFO_BASE32 bit. 34 */ 35 unsigned flags; 36 /** 37 The size of of the raw message digest in bytes. 38 */ 39 size_t digest_size; 40 /** 41 * The hash function name. 42 */ 43 const char* name; 44 /** 45 * The corresponding paramenter name in a magnet link. 46 */ 47 const char* magnet_name; 48 } rhash_info; 49 50 typedef void (*pinit_t)(void*); 51 typedef void (*pupdate_t)(void* ctx, const void* msg, size_t size); 52 typedef void (*pfinal_t)(void*, unsigned char*); 53 typedef void (*pcleanup_t)(void*); 54 55 /** 56 * Information about a hash function 57 */ 58 typedef struct rhash_hash_info 59 { 60 rhash_info* info; 61 size_t context_size; 62 ptrdiff_t digest_diff; 63 pinit_t init; 64 pupdate_t update; 65 pfinal_t final; 66 pcleanup_t cleanup; 67 } rhash_hash_info; 68 69 /** 70 * Information on a hash function and its context 71 */ 72 typedef struct rhash_vector_item 73 { 74 struct rhash_hash_info* hash_info; 75 void* context; 76 } rhash_vector_item; 77 78 /** 79 * The rhash context containing contexts for several hash functions 80 */ 81 typedef struct rhash_context_ext 82 { 83 struct rhash_context rc; 84 unsigned hash_vector_size; /* number of contained hash sums */ 85 unsigned flags; 86 unsigned state; 87 void* callback; 88 void* callback_data; 89 void* bt_ctx; 90 rhash_vector_item vector[1]; /* contexts of contained hash sums */ 91 } rhash_context_ext; 92 93 extern rhash_hash_info rhash_hash_info_default[RHASH_HASH_COUNT]; 94 extern rhash_hash_info* rhash_info_table; 95 extern int rhash_info_size; 96 extern unsigned rhash_uninitialized_algorithms; 97 98 extern rhash_info info_crc32; 99 extern rhash_info info_crc32c; 100 extern rhash_info info_md4; 101 extern rhash_info info_md5; 102 extern rhash_info info_sha1; 103 extern rhash_info info_tiger; 104 extern rhash_info info_tth ; 105 extern rhash_info info_btih; 106 extern rhash_info info_ed2k; 107 extern rhash_info info_aich; 108 extern rhash_info info_whirlpool; 109 extern rhash_info info_rmd160; 110 extern rhash_info info_gost; 111 extern rhash_info info_gostpro; 112 extern rhash_info info_has160; 113 extern rhash_info info_snf128; 114 extern rhash_info info_snf256; 115 extern rhash_info info_sha224; 116 extern rhash_info info_sha256; 117 extern rhash_info info_sha384; 118 extern rhash_info info_sha512; 119 extern rhash_info info_sha3_224; 120 extern rhash_info info_sha3_256; 121 extern rhash_info info_sha3_384; 122 extern rhash_info info_sha3_512; 123 extern rhash_info info_edr256; 124 extern rhash_info info_edr512; 125 126 /* rhash_info flags */ 127 #define F_BS32 1 /* default output in base32 */ 128 #define F_SWAP32 2 /* Big endian flag */ 129 #define F_SWAP64 4 130 131 /* define endianness flags */ 132 #if IS_LITTLE_ENDIAN 133 #define F_LE32 0 134 #define F_LE64 0 135 #define F_BE32 F_SWAP32 136 #define F_BE64 F_SWAP64 137 #else 138 #define F_LE32 F_SWAP32 139 #define F_LE64 F_SWAP64 140 #define F_BE32 0 141 #define F_BE64 0 142 #endif 143 144 void rhash_init_algorithms(unsigned mask); 145 const rhash_info* rhash_info_by_id(unsigned hash_id); /* get hash sum info by hash id */ 146 147 #if defined(OPENSSL_RUNTIME) && !defined(USE_OPENSSL) 148 # define USE_OPENSSL 149 #endif 150 151 #ifdef __cplusplus 152 } /* extern "C" */ 153 #endif /* __cplusplus */ 154 155 #endif /* RHASH_ALGORITHMS_H */ 156