From b8037999c03a8ebc768f1f5d0a8651615e9a2a82 Mon Sep 17 00:00:00 2001 From: Greg Rubin Date: Thu, 23 Apr 2020 21:30:22 +0000 Subject: [PATCH 1/3] Backport code needed for old x86_64 buildchains --- csrc/util.h | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/csrc/util.h b/csrc/util.h index 7779bbd9..53b064d7 100644 --- a/csrc/util.h +++ b/csrc/util.h @@ -122,12 +122,33 @@ class pthread_lock_auto { }; #if __BYTE_ORDER == __LITTLE_ENDIAN +#if defined(__x86_64__) +// We need to continue supporting some old x86_64 build-chains, so we use a hand-rolled version of bswap64 +static inline uint64_t swapEndian(uint64_t val) { + uint64_t result = val; + __asm__( + "bswap %0" + : "+r"(result) + ); + return result; +} +#define hostToBigEndian64(x) swapEndian(x) +#define bigEndianToHost64(x) swapEndian(x) + +#else +// For all other platforms (currently just aarch64), we know we are on a modern build-chain +// and can use the build-in function. (Also, the x86_64 assembly above won't work.) #define hostToBigEndian64(x) __builtin_bswap64(x) #define bigEndianToHost64(x) __builtin_bswap64(x) -#else + +#endif // Platform logic in __BYTE_ORDER == __LITTLE_ENDIAN + +#else // __BYTE_ORDER == __BIG_ENDIAN +// No conversions are needed, so these methods become NOPs #define hostToBigEndian64(x) (x) #define bigEndianToHost64(x) (x) -#endif +#endif // BYTE_ORDER logic + static inline void* fast_xor(void* dest, const void* src, int len) { int idx = 0; From 3443fd9cec128d015b1fab9f09693802434196c0 Mon Sep 17 00:00:00 2001 From: Greg Rubin Date: Thu, 23 Apr 2020 21:30:40 +0000 Subject: [PATCH 2/3] Version gate P1363Format tests --- .../crypto/provider/test/EvpSignatureTest.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tst/com/amazon/corretto/crypto/provider/test/EvpSignatureTest.java b/tst/com/amazon/corretto/crypto/provider/test/EvpSignatureTest.java index 237d6906..e3f7816b 100644 --- a/tst/com/amazon/corretto/crypto/provider/test/EvpSignatureTest.java +++ b/tst/com/amazon/corretto/crypto/provider/test/EvpSignatureTest.java @@ -4,6 +4,7 @@ package com.amazon.corretto.crypto.provider.test; import static com.amazon.corretto.crypto.provider.test.TestUtil.assertThrows; +import static com.amazon.corretto.crypto.provider.test.TestUtil.versionCompare; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -200,12 +201,15 @@ public static void setupParams() throws GeneralSecurityException { MASTER_PARAMS_LIST.add(new TestParams(base, algorithm, length, true, false, currentPair)); MASTER_PARAMS_LIST.add(new TestParams(base, algorithm, length, false, true, currentPair)); MASTER_PARAMS_LIST.add(new TestParams(base, algorithm, length, true, true, currentPair)); - if (base.equals("ECDSA") && !hash.equals("NONE")) { - algorithm = algorithm + "inP1363Format"; - MASTER_PARAMS_LIST.add(new TestParams(base, algorithm, length, false, false, currentPair)); - MASTER_PARAMS_LIST.add(new TestParams(base, algorithm, length, true, false, currentPair)); - MASTER_PARAMS_LIST.add(new TestParams(base, algorithm, length, false, true, currentPair)); - MASTER_PARAMS_LIST.add(new TestParams(base, algorithm, length, true, true, currentPair)); + // These new algorithms were only added in 1.3.0 + if (versionCompare("1.3.0", NATIVE_PROVIDER) <= 0) { + if (base.equals("ECDSA") && !hash.equals("NONE")) { + algorithm = algorithm + "inP1363Format"; + MASTER_PARAMS_LIST.add(new TestParams(base, algorithm, length, false, false, currentPair)); + MASTER_PARAMS_LIST.add(new TestParams(base, algorithm, length, true, false, currentPair)); + MASTER_PARAMS_LIST.add(new TestParams(base, algorithm, length, false, true, currentPair)); + MASTER_PARAMS_LIST.add(new TestParams(base, algorithm, length, true, true, currentPair)); + } } } } From ae0a5185656a19359711f18f213a4c79f75559c7 Mon Sep 17 00:00:00 2001 From: Greg Rubin Date: Thu, 23 Apr 2020 21:42:13 +0000 Subject: [PATCH 3/3] CHANGELOG for P1363 version gating and x86_64 build logic --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2fa6664..dd470906 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ ### Maintenance * Upgrade tests to JUnit5. [PR #111](https://github.com/corretto/amazon-corretto-crypto-provider/pull/111) * Upgrade BouncyCastle test dependency 1.65. [PR #110](https://github.com/corretto/amazon-corretto-crypto-provider/pull/110) +* Add version gating to P1363 Format tests. [PR #112](https://github.com/corretto/amazon-corretto-crypto-provider/pull/112) +* Re-add support for very old x86_64 build-chains. [PR #112](https://github.com/corretto/amazon-corretto-crypto-provider/pull/112) ## 1.4.0 ### Improvements