Skip to content

Commit 38096fc

Browse files
Merge pull request #23 from cr-marcstevens/bigendian
* Protect against outside definitions of SHA1DC_BIGENDIAN, one can fo…
2 parents 007905a + 15c90b2 commit 38096fc

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

‎lib/sha1.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@
1616

1717
/*
1818
Because Little-Endian architectures are most common,
19-
we only set BIGENDIAN if one of these conditions is met.
19+
we only set SHA1DC_BIGENDIAN if one of these conditions is met.
2020
Note that all MSFT platforms are little endian,
2121
so none of these will be defined under the MSC compiler.
2222
If you are compiling on a big endian platform and your compiler does not define one of these,
2323
you will have to add whatever macros your tool chain defines to indicate Big-Endianness.
2424
*/
25-
#if (defined(__BYTE_ORDER) && (__BYTE_ORDER==__BIG_ENDIAN)) || \
25+
#ifdefSHA1DC_BIGENDIAN
26+
#undef SHA1DC_BIGENDIAN
27+
#endif
28+
#if (!defined SHA1DC_FORCE_LITTLEENDIAN) && \
29+
((defined(__BYTE_ORDER) && (__BYTE_ORDER==__BIG_ENDIAN)) || \
2630
(defined(__BYTE_ORDER__) && (__BYTE_ORDER__==__BIG_ENDIAN__)) || \
2731
defined(__BIG_ENDIAN__) || defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
28-
defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
32+
defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)|| defined(SHA1DC_FORCE_BIGENDIAN))
2933

30-
#defineBIGENDIAN (1)
34+
#defineSHA1DC_BIGENDIAN
3135

3236
#endif/*ENDIANNESS SELECTION*/
3337

@@ -39,11 +43,11 @@
3943

4044
#definesha1_mix(W, t) (rotate_left(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1))
4145

42-
#if defined(BIGENDIAN)
46+
#ifdefSHA1DC_BIGENDIAN
4347
#definesha1_load(m, t, temp){temp = m[t]}
4448
#else
4549
#definesha1_load(m, t, temp){temp = m[t]; sha1_bswap32(temp)}
46-
#endif/*define(BIGENDIAN)*/
50+
#endif
4751

4852
#definesha1_store(W, t, x) *(volatile uint32_t *)&W[t] = x
4953

‎lib/sha1.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* https://opensource.org/licenses/MIT
66
***/
77

8+
#ifndefSHA1DC_SHA1_H
9+
#defineSHA1DC_SHA1_H
10+
811
#if defined(__cplusplus)
912
extern"C"{
1013
#endif
@@ -103,3 +106,5 @@ int SHA1DCFinal(unsigned char[20], SHA1_CTX*);
103106
#if defined(__cplusplus)
104107
}
105108
#endif
109+
110+
#endif

‎lib/ubc_check.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
// thus one needs to do the recompression check for each DV that has its bit set
2121
*/
2222

23-
#ifndefUBC_CHECK_H
24-
#defineUBC_CHECK_H
23+
#ifndefSHA1DC_UBC_CHECK_H
24+
#defineSHA1DC_UBC_CHECK_H
2525

2626
#if defined(__cplusplus)
2727
extern"C"{
@@ -43,4 +43,4 @@ void ubc_check(const uint32_t W[80], uint32_t dvmask[DVMASKSIZE]);
4343
}
4444
#endif
4545

46-
#endif/* UBC_CHECK_H */
46+
#endif

0 commit comments

Comments
(0)