Running Nettle 3.0 tests on a powerpc64le RHEL 7.1 box shows the two failures below. The cause is in the second definition of the HAVE_NATIVE_64_BIT configuration macro:
$ grep HAVE_NATIVE_64_BIT config.* config.h:# define HAVE_NATIVE_64_BIT 1 config.h:# define HAVE_NATIVE_64_BIT (SIZEOF_LONG * CHAR_BIT >= 64)
The macro relies on the CHAR_BIT macro being defined at the point of its expansion. Uses of HAVE_NATIVE_64_BIT of the form
#if !HAVE_NATIVE_64_BIT
in files that don't include <limits.h> (and thus don't have the CHAR_BIT macro defined) end up compiling the conditional blocks that are intended to be included only when the target has no native support for 64 bit arithmetic. One such file that comes into play in the failing tests is camellia-absorb.c. Since powerpc64le obviously does have such support, the code is unnecessary and, as it turns out, introduces errors.
Once <limits.h> is included all of Nettle's tests pass even on powerpc64le-redhat-linux.
Martin
... Encrypt failed: Input: 0123456789abcdef fedcba9876543210
Output: df51fc645013f77c 25c472e2871f742a
Expected: 6767313854966973 0857065648eabe43
/src/nettle-3.0/run-tests: line 57: 46381 Aborted "$1" $testflags FAIL: camellia ... Assert failed: /src/nettle-3.0/testsuite/testutils.c:513: MEMEQ(digest->length, buffer, digest->data) /src/nettle-3.0/run-tests: line 57: 49811 Aborted "$1" $testflags FAIL: gcm ... ==================== 2 of 55 tests failed ====================
Martin Sebor msebor@redhat.com writes:
One such file that comes into play in the failing tests is camellia-absorb.c. Since powerpc64le obviously does have such support, the code is unnecessary and, as it turns out, introduces errors.
I added an #include <limits.h> to camellia-absorb.c last June, after the same problem had been tracked down by Magnus Holmgren, starting from failing tests on the debian s390x build machines.
I should mention this bugfix in the NEWS file for 3.1.
If you have found any additional other file(s) which are missing a required limits.h include, I'd like to know.
And the primary problem is not a bad value of HAVE_NATIVE_64_BIT in itself (that should only affect performance). What really breaks camellia is that HAVE_NATIVE_64_BIT is evaluated differently in cammellia-absorb.c and camellia-crypt-internal.c, since the subkeys are processed slightly differently in the two cases.
The special case for x86_64 in config.h is intended only for 64-bit MS windows builds. At least, that's the only 64-bit system I'm aware of where unsigned long is not a 64-bit type.
Regards, /Niels
nettle-bugs@lists.lysator.liu.se