Skip to content

Commit

Permalink
Hook-up endianness & sizeof(long) detection code in SHA-1 implementat…
Browse files Browse the repository at this point in the history
…ion (roehling#90)

This makes the SHA-1 implementation valid for big endian architectures
as well.
  • Loading branch information
oxan authored and jeredfloyd committed May 4, 2022
1 parent 3242f2d commit a13db64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.4)
project(postsrsd C)
include(CheckIncludeFile)
include(CheckTypeSize)
include(TestBigEndian)

option(GENERATE_SRS_SECRET "Generate a random SRS secret if none exists during install" ON)
option(USE_APPARMOR "Enable AppArmor profile" OFF)
Expand Down Expand Up @@ -56,6 +58,13 @@ if(HAVE_SYS_TYPES_H)
add_definitions(-DHAVE_SYS_TYPES_H)
endif()

test_big_endian(WORDS_BIGENDIAN)
if(WORDS_BIGENDIAN)
add_definitions(-DWORDS_BIGENDIAN)
endif()
check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
add_definitions(-DSIZEOF_UNSIGNED_LONG=${SIZEOF_UNSIGNED_LONG})

if(NOT DEFINED INIT_FLAVOR)
if(SYSTEMD)
message(STATUS "Detected init flavor: systemd")
Expand Down
17 changes: 13 additions & 4 deletions sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@
#endif
#endif

#ifdef WORDS_BIGENDIAN
#define BYTEORDER 0x4321
#if SIZEOF_UNSIGNED_LONG == 4
# ifdef WORDS_BIGENDIAN
# define BYTEORDER 0x4321
# else
# define BYTEORDER 0x1234
# endif
#elif SIZEOF_UNSIGNED_LONG == 8
# ifdef WORDS_BIGENDIAN
# define BYTEORDER 0x87654321
# else
# define BYTEORDER 0x12345678
# endif
#else
#define BYTEORDER 0x1234
# error "SHA1 requires an unsigned long of either 4 or 8 bytes"
#endif


/* UNRAVEL should be fastest & biggest */
/* UNROLL_LOOPS should be just as big, but slightly slower */
/* both undefined should be smallest and slowest */
Expand Down

0 comments on commit a13db64

Please sign in to comment.