Skip to content

Commit

Permalink
Merge pull request #23 from cr-marcstevens/bigendian
Browse files Browse the repository at this point in the history
* Protect against outside definitions of SHA1DC_BIGENDIAN, one can fo…
  • Loading branch information
cr-marcstevens committed Mar 27, 2017
2 parents 007905a + 15c90b2 commit 38096fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
16 changes: 10 additions & 6 deletions lib/sha1.c
Expand Up @@ -16,18 +16,22 @@

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

#define BIGENDIAN (1)
#define SHA1DC_BIGENDIAN

#endif /*ENDIANNESS SELECTION*/

Expand All @@ -39,11 +43,11 @@

#define sha1_mix(W, t) (rotate_left(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1))

#if defined(BIGENDIAN)
#ifdef SHA1DC_BIGENDIAN
#define sha1_load(m, t, temp) { temp = m[t]; }
#else
#define sha1_load(m, t, temp) { temp = m[t]; sha1_bswap32(temp); }
#endif /*define(BIGENDIAN)*/
#endif

#define sha1_store(W, t, x) *(volatile uint32_t *)&W[t] = x

Expand Down
5 changes: 5 additions & 0 deletions lib/sha1.h
Expand Up @@ -5,6 +5,9 @@
* https://opensource.org/licenses/MIT
***/

#ifndef SHA1DC_SHA1_H
#define SHA1DC_SHA1_H

#if defined(__cplusplus)
extern "C" {
#endif
Expand Down Expand Up @@ -103,3 +106,5 @@ int SHA1DCFinal(unsigned char[20], SHA1_CTX*);
#if defined(__cplusplus)
}
#endif

#endif
6 changes: 3 additions & 3 deletions lib/ubc_check.h
Expand Up @@ -20,8 +20,8 @@
// thus one needs to do the recompression check for each DV that has its bit set
*/

#ifndef UBC_CHECK_H
#define UBC_CHECK_H
#ifndef SHA1DC_UBC_CHECK_H
#define SHA1DC_UBC_CHECK_H

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

#endif /* UBC_CHECK_H */
#endif

0 comments on commit 38096fc

Please sign in to comment.