openwall / passwdqc

Password/passphrase strength checking and policy enforcement
https://www.openwall.com/passwdqc/
Other
40 stars 17 forks source link

endian.h not found on macOS #15

Closed EricFromCanada closed 3 years ago

EricFromCanada commented 3 years ago

The reference to in passwdqc_filter.h needs to be <machine/endian.h> for it to compile on macOS.

solardiz commented 3 years ago

Thank you, @EricFromCanada! Does <machine/endian.h> define __BYTE_ORDER, __BIG_ENDIAN, and __LITTLE_ENDIAN? If not, then including it is of no use.

Since this is just an optimization anyhow, I'm tempted to treat macOS the same as MSVC there, like this:

-#ifndef _MSC_VER
+#if !defined(_MSC_VER) && !defined(__APPLE__)
 #include <endian.h>
 #endif

Does this work?

EricFromCanada commented 3 years ago

machine/endian.h includes i386/endian.h which defines BYTE_ORDER, BIG_ENDIAN and LITTLE_ENDIAN via sys/_endian.h, but it also looks like those aren't necessarily needed since you can assume little endian on macOS for Intel and ARM.

solardiz commented 3 years ago

defines BYTE_ORDER, BIG_ENDIAN and LITTLE_ENDIAN

However, these are not the "underscored" versions that passwdqc_filter.h currently uses.

via sys/_endian.h

Not, it defines those directly. That other file only defines the conversions.

you can assume little endian on macOS for Intel and ARM.

But not on PowerPC.

Overall, I'm tempted not to over-complicate this, and use the simpler patch I suggested above. The optimization would then continue to work for Linux and *BSDs. I guess large files would most commonly be processed with pwqfilter on Linux.

solardiz commented 3 years ago

I'm tempted to treat macOS the same as MSVC there, like this:

-#ifndef _MSC_VER
+#if !defined(_MSC_VER) && !defined(__APPLE__)
 #include <endian.h>
 #endif

Does this work?

@EricFromCanada Can you please test this specific change? Thanks!

EricFromCanada commented 3 years ago

Yes, that seems to work.