#ifndef SHA1DC_NO_STANDARD_INCLUDES
#include <string.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __unix__
#include <sys/types.h>
#endif
#endif
#ifdef SHA1DC_CUSTOM_INCLUDE_SHA1_C
#include SHA1DC_CUSTOM_INCLUDE_SHA1_C
#endif
#ifndef SHA1DC_INIT_SAFE_HASH_DEFAULT
#define SHA1DC_INIT_SAFE_HASH_DEFAULT …
#endif
#include "sha1.h"
#include "ubc_check.h"
#if (defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || \
defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || \
defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || \
defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__) || defined(__INTEL__) || \
defined(__386) || defined(_M_X64) || defined(_M_AMD64))
#define SHA1DC_ON_INTEL_LIKE_PROCESSOR
#endif
#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define SHA1DC_BIGENDIAN
#endif
#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN)
#if __BYTE_ORDER == __BIG_ENDIAN
#define SHA1DC_BIGENDIAN
#endif
#elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN)
#if _BYTE_ORDER == _BIG_ENDIAN
#define SHA1DC_BIGENDIAN
#endif
#elif (defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || \
defined(__sparc))
#define SHA1DC_BIGENDIAN
#elif (defined(_AIX) || defined(__hpux))
#define SHA1DC_BIGENDIAN
#elif defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR)
#else
#endif
#if (defined(SHA1DC_FORCE_LITTLEENDIAN) && defined(SHA1DC_BIGENDIAN))
#undef SHA1DC_BIGENDIAN
#endif
#if (defined(SHA1DC_FORCE_BIGENDIAN) && !defined(SHA1DC_BIGENDIAN))
#define SHA1DC_BIGENDIAN
#endif
#ifndef SHA1DC_FORCE_ALIGNED_ACCESS
#if defined(SHA1DC_FORCE_UNALIGNED_ACCESS) || defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR)
#define SHA1DC_ALLOW_UNALIGNED_ACCESS
#endif
#endif
#define rotate_right(x,n) …
#define rotate_left(x,n) …
#define sha1_bswap32(x) …
#define sha1_mix(W, t) …
#ifdef SHA1DC_BIGENDIAN
#define sha1_load …
#else
#define sha1_load(m, t, temp) …
#endif
#define sha1_store(W, t, x) …
#define sha1_f1(b,c,d) …
#define sha1_f2(b,c,d) …
#define sha1_f3(b,c,d) …
#define sha1_f4(b,c,d) …
#define HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, m, t) …
#define HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, m, t) …
#define HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, m, t) …
#define HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, m, t) …
#define HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, m, t) …
#define HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, m, t) …
#define HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, m, t) …
#define HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, m, t) …
#define SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, t, temp) …
#define SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(a, b, c, d, e, W, t, temp) …
#define SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, t, temp) …
#define SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, t, temp) …
#define SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, t, temp) …
#define SHA1_STORE_STATE(i) …
#ifdef BUILDNOCOLLDETECTSHA1COMPRESSION
void sha1_compression(uint32_t ihv[5], const uint32_t m[16])
{
uint32_t W[80];
uint32_t a,b,c,d,e;
unsigned i;
memcpy(W, m, 16 * 4);
for (i = 16; i < 80; ++i)
W[i] = sha1_mix(W, i);
a = ihv[0]; b = ihv[1]; c = ihv[2]; d = ihv[3]; e = ihv[4];
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18);
HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38);
HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58);
HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78);
HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79);
ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e;
}
#endif
static void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80])
{ … }
void sha1_compression_states(uint32_t ihv[5], const uint32_t m[16], uint32_t W[80], uint32_t states[80][5])
{ … }
#define SHA1_RECOMPRESS(t) …
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4127)
#endif
#ifdef DOSTORESTATE0
SHA1_RECOMPRESS(0)
#endif
#ifdef DOSTORESTATE1
SHA1_RECOMPRESS(1)
#endif
#ifdef DOSTORESTATE2
SHA1_RECOMPRESS(2)
#endif
#ifdef DOSTORESTATE3
SHA1_RECOMPRESS(3)
#endif
#ifdef DOSTORESTATE4
SHA1_RECOMPRESS(4)
#endif
#ifdef DOSTORESTATE5
SHA1_RECOMPRESS(5)
#endif
#ifdef DOSTORESTATE6
SHA1_RECOMPRESS(6)
#endif
#ifdef DOSTORESTATE7
SHA1_RECOMPRESS(7)
#endif
#ifdef DOSTORESTATE8
SHA1_RECOMPRESS(8)
#endif
#ifdef DOSTORESTATE9
SHA1_RECOMPRESS(9)
#endif
#ifdef DOSTORESTATE10
SHA1_RECOMPRESS(10)
#endif
#ifdef DOSTORESTATE11
SHA1_RECOMPRESS(11)
#endif
#ifdef DOSTORESTATE12
SHA1_RECOMPRESS(12)
#endif
#ifdef DOSTORESTATE13
SHA1_RECOMPRESS(13)
#endif
#ifdef DOSTORESTATE14
SHA1_RECOMPRESS(14)
#endif
#ifdef DOSTORESTATE15
SHA1_RECOMPRESS(15)
#endif
#ifdef DOSTORESTATE16
SHA1_RECOMPRESS(16)
#endif
#ifdef DOSTORESTATE17
SHA1_RECOMPRESS(17)
#endif
#ifdef DOSTORESTATE18
SHA1_RECOMPRESS(18)
#endif
#ifdef DOSTORESTATE19
SHA1_RECOMPRESS(19)
#endif
#ifdef DOSTORESTATE20
SHA1_RECOMPRESS(20)
#endif
#ifdef DOSTORESTATE21
SHA1_RECOMPRESS(21)
#endif
#ifdef DOSTORESTATE22
SHA1_RECOMPRESS(22)
#endif
#ifdef DOSTORESTATE23
SHA1_RECOMPRESS(23)
#endif
#ifdef DOSTORESTATE24
SHA1_RECOMPRESS(24)
#endif
#ifdef DOSTORESTATE25
SHA1_RECOMPRESS(25)
#endif
#ifdef DOSTORESTATE26
SHA1_RECOMPRESS(26)
#endif
#ifdef DOSTORESTATE27
SHA1_RECOMPRESS(27)
#endif
#ifdef DOSTORESTATE28
SHA1_RECOMPRESS(28)
#endif
#ifdef DOSTORESTATE29
SHA1_RECOMPRESS(29)
#endif
#ifdef DOSTORESTATE30
SHA1_RECOMPRESS(30)
#endif
#ifdef DOSTORESTATE31
SHA1_RECOMPRESS(31)
#endif
#ifdef DOSTORESTATE32
SHA1_RECOMPRESS(32)
#endif
#ifdef DOSTORESTATE33
SHA1_RECOMPRESS(33)
#endif
#ifdef DOSTORESTATE34
SHA1_RECOMPRESS(34)
#endif
#ifdef DOSTORESTATE35
SHA1_RECOMPRESS(35)
#endif
#ifdef DOSTORESTATE36
SHA1_RECOMPRESS(36)
#endif
#ifdef DOSTORESTATE37
SHA1_RECOMPRESS(37)
#endif
#ifdef DOSTORESTATE38
SHA1_RECOMPRESS(38)
#endif
#ifdef DOSTORESTATE39
SHA1_RECOMPRESS(39)
#endif
#ifdef DOSTORESTATE40
SHA1_RECOMPRESS(40)
#endif
#ifdef DOSTORESTATE41
SHA1_RECOMPRESS(41)
#endif
#ifdef DOSTORESTATE42
SHA1_RECOMPRESS(42)
#endif
#ifdef DOSTORESTATE43
SHA1_RECOMPRESS(43)
#endif
#ifdef DOSTORESTATE44
SHA1_RECOMPRESS(44)
#endif
#ifdef DOSTORESTATE45
SHA1_RECOMPRESS(45)
#endif
#ifdef DOSTORESTATE46
SHA1_RECOMPRESS(46)
#endif
#ifdef DOSTORESTATE47
SHA1_RECOMPRESS(47)
#endif
#ifdef DOSTORESTATE48
SHA1_RECOMPRESS(48)
#endif
#ifdef DOSTORESTATE49
SHA1_RECOMPRESS(49)
#endif
#ifdef DOSTORESTATE50
SHA1_RECOMPRESS(50)
#endif
#ifdef DOSTORESTATE51
SHA1_RECOMPRESS(51)
#endif
#ifdef DOSTORESTATE52
SHA1_RECOMPRESS(52)
#endif
#ifdef DOSTORESTATE53
SHA1_RECOMPRESS(53)
#endif
#ifdef DOSTORESTATE54
SHA1_RECOMPRESS(54)
#endif
#ifdef DOSTORESTATE55
SHA1_RECOMPRESS(55)
#endif
#ifdef DOSTORESTATE56
SHA1_RECOMPRESS(56)
#endif
#ifdef DOSTORESTATE57
SHA1_RECOMPRESS(57)
#endif
#ifdef DOSTORESTATE58
SHA1_RECOMPRESS(…)
#endif
#ifdef DOSTORESTATE59
SHA1_RECOMPRESS(59)
#endif
#ifdef DOSTORESTATE60
SHA1_RECOMPRESS(60)
#endif
#ifdef DOSTORESTATE61
SHA1_RECOMPRESS(61)
#endif
#ifdef DOSTORESTATE62
SHA1_RECOMPRESS(62)
#endif
#ifdef DOSTORESTATE63
SHA1_RECOMPRESS(63)
#endif
#ifdef DOSTORESTATE64
SHA1_RECOMPRESS(64)
#endif
#ifdef DOSTORESTATE65
SHA1_RECOMPRESS(…)
#endif
#ifdef DOSTORESTATE66
SHA1_RECOMPRESS(66)
#endif
#ifdef DOSTORESTATE67
SHA1_RECOMPRESS(67)
#endif
#ifdef DOSTORESTATE68
SHA1_RECOMPRESS(68)
#endif
#ifdef DOSTORESTATE69
SHA1_RECOMPRESS(69)
#endif
#ifdef DOSTORESTATE70
SHA1_RECOMPRESS(70)
#endif
#ifdef DOSTORESTATE71
SHA1_RECOMPRESS(71)
#endif
#ifdef DOSTORESTATE72
SHA1_RECOMPRESS(72)
#endif
#ifdef DOSTORESTATE73
SHA1_RECOMPRESS(73)
#endif
#ifdef DOSTORESTATE74
SHA1_RECOMPRESS(74)
#endif
#ifdef DOSTORESTATE75
SHA1_RECOMPRESS(75)
#endif
#ifdef DOSTORESTATE76
SHA1_RECOMPRESS(76)
#endif
#ifdef DOSTORESTATE77
SHA1_RECOMPRESS(77)
#endif
#ifdef DOSTORESTATE78
SHA1_RECOMPRESS(78)
#endif
#ifdef DOSTORESTATE79
SHA1_RECOMPRESS(79)
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif
static void sha1_recompression_step(uint32_t step, uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5])
{ … }
static void sha1_process(SHA1_CTX* ctx, const uint32_t block[16])
{ … }
void SHA1DCInit(SHA1_CTX* ctx)
{ … }
void SHA1DCSetSafeHash(SHA1_CTX* ctx, int safehash)
{ … }
void SHA1DCSetUseUBC(SHA1_CTX* ctx, int ubc_check)
{ … }
void SHA1DCSetUseDetectColl(SHA1_CTX* ctx, int detect_coll)
{ … }
void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX* ctx, int reduced_round_coll)
{ … }
void SHA1DCSetCallback(SHA1_CTX* ctx, collision_block_callback callback)
{ … }
void SHA1DCUpdate(SHA1_CTX* ctx, const char* buf, size_t len)
{ … }
static const unsigned char sha1_padding[64] = …;
int SHA1DCFinal(unsigned char output[20], SHA1_CTX *ctx)
{ … }
#ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C
#include SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C
#endif