Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic support for s390x #1297

Merged
merged 2 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ jobs:
- i686-unknown-linux-musl
- powerpc64le-unknown-linux-gnu
- riscv64gc-unknown-linux-gnu
- s390x-unknown-linux-gnu
- x86_64-pc-windows-gnu
- x86_64-pc-windows-msvc
- x86_64-apple-darwin
Expand Down Expand Up @@ -255,6 +256,9 @@ jobs:
- target: riscv64gc-unknown-linux-gnu
host_os: ubuntu-22.04

- target: s390x-unknown-linux-gnu
host_os: ubuntu-22.04

- target: x86_64-pc-windows-gnu
host_os: windows-latest

Expand Down Expand Up @@ -342,6 +346,7 @@ jobs:
- aarch64-unknown-linux-musl
- i686-pc-windows-msvc
- powerpc64le-unknown-linux-gnu
- s390x-unknown-linux-gnu
- x86_64-unknown-linux-gnu

mode:
Expand All @@ -363,6 +368,9 @@ jobs:
- target: powerpc64le-unknown-linux-gnu
host_os: ubuntu-22.04

- target: s390x-unknown-linux-gnu
host_os: ubuntu-22.04

- target: x86_64-unknown-linux-gnu
host_os: ubuntu-22.04

Expand Down Expand Up @@ -498,6 +506,7 @@ jobs:
- i686-unknown-linux-gnu
- powerpc64le-unknown-linux-gnu
- riscv64gc-unknown-linux-gnu
- s390x-unknown-linux-gnu
- x86_64-unknown-linux-musl

mode:
Expand Down Expand Up @@ -527,6 +536,9 @@ jobs:
- target: riscv64gc-unknown-linux-gnu
host_os: ubuntu-22.04

- target: s390x-unknown-linux-gnu
host_os: ubuntu-22.04

- target: x86_64-unknown-linux-musl
host_os: ubuntu-22.04

Expand Down
12 changes: 12 additions & 0 deletions crypto/fipsmodule/aes/aes_nohw.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ static inline aes_word_t aes_nohw_delta_swap(aes_word_t a, aes_word_t mask,
// http://programming.sirrida.de/calcperm.php on smaller inputs.
#if defined(OPENSSL_64_BIT)
static inline uint64_t aes_nohw_compact_word(uint64_t a) {
#if defined(RING_BIG_ENDIAN)
a = CRYPTO_bswap8(a);
#endif
// Numbering the 64/2 = 16 4-bit chunks, least to most significant, we swap
// quartets of those chunks:
// 0 1 2 3 | 4 5 6 7 | 8 9 10 11 | 12 13 14 15 =>
Expand All @@ -294,10 +297,16 @@ static inline uint64_t aes_nohw_uncompact_word(uint64_t a) {
a = aes_nohw_delta_swap(a, UINT64_C(0x00000000ffff0000), 16);
a = aes_nohw_delta_swap(a, UINT64_C(0x0000ff000000ff00), 8);
a = aes_nohw_delta_swap(a, UINT64_C(0x00f000f000f000f0), 4);
#if defined(RING_BIG_ENDIAN)
a = CRYPTO_bswap8(a);
#endif
return a;
}
#else // !OPENSSL_64_BIT
static inline uint32_t aes_nohw_compact_word(uint32_t a) {
#if defined(RING_BIG_ENDIAN)
a = CRYPTO_bswap4(a);
#endif
// Numbering the 32/2 = 16 pairs of bits, least to most significant, we swap:
// 0 1 2 3 | 4 5 6 7 | 8 9 10 11 | 12 13 14 15 =>
// 0 4 2 6 | 1 5 3 7 | 8 12 10 14 | 9 13 11 15
Expand All @@ -316,6 +325,9 @@ static inline uint32_t aes_nohw_uncompact_word(uint32_t a) {
// Reverse the steps of |aes_nohw_uncompact_word|.
a = aes_nohw_delta_swap(a, 0x0000f0f0, 12);
a = aes_nohw_delta_swap(a, 0x00cc00cc, 6);
#if defined(RING_BIG_ENDIAN)
a = CRYPTO_bswap4(a);
#endif
return a;
}

Expand Down
42 changes: 32 additions & 10 deletions crypto/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,55 +401,77 @@
// endianness. They use |memcpy|, and so avoid alignment or strict aliasing
// requirements on the input and output pointers.

#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define RING_BIG_ENDIAN
#endif
#endif

static inline uint32_t CRYPTO_load_u32_le(const void *in) {
uint32_t v;
OPENSSL_memcpy(&v, in, sizeof(v));
#if defined(RING_BIG_ENDIAN)
return CRYPTO_bswap4(v);
#else

Check warning on line 415 in crypto/internal.h

View check run for this annotation

Codecov / codecov/patch

crypto/internal.h#L415

Added line #L415 was not covered by tests
return v;
#endif
}

static inline void CRYPTO_store_u32_le(void *out, uint32_t v) {
#if defined(RING_BIG_ENDIAN)
v = CRYPTO_bswap4(v);
#endif
OPENSSL_memcpy(out, &v, sizeof(v));
}

static inline uint32_t CRYPTO_load_u32_be(const void *in) {
uint32_t v;
OPENSSL_memcpy(&v, in, sizeof(v));
#if !defined(RING_BIG_ENDIAN)
return CRYPTO_bswap4(v);
#else

Check warning on line 432 in crypto/internal.h

View check run for this annotation

Codecov / codecov/patch

crypto/internal.h#L432

Added line #L432 was not covered by tests
return v;
#endif
}

static inline void CRYPTO_store_u32_be(void *out, uint32_t v) {
#if !defined(RING_BIG_ENDIAN)
v = CRYPTO_bswap4(v);
#endif
OPENSSL_memcpy(out, &v, sizeof(v));
}

static inline uint64_t CRYPTO_load_u64_le(const void *in) {
uint64_t v;
OPENSSL_memcpy(&v, in, sizeof(v));
#if defined(RING_BIG_ENDIAN)
return CRYPTO_bswap8(v);
#else

Check warning on line 449 in crypto/internal.h

View check run for this annotation

Codecov / codecov/patch

crypto/internal.h#L447-L449

Added lines #L447 - L449 were not covered by tests
return v;
#endif
}

static inline void CRYPTO_store_u64_le(void *out, uint64_t v) {
#if defined(RING_BIG_ENDIAN)
v = CRYPTO_bswap8(v);
#endif

Check warning on line 457 in crypto/internal.h

View check run for this annotation

Codecov / codecov/patch

crypto/internal.h#L455-L457

Added lines #L455 - L457 were not covered by tests
OPENSSL_memcpy(out, &v, sizeof(v));
}

static inline uint64_t CRYPTO_load_u64_be(const void *ptr) {
uint64_t ret;
OPENSSL_memcpy(&ret, ptr, sizeof(ret));
#if !defined(RING_BIG_ENDIAN)

Check warning on line 464 in crypto/internal.h

View check run for this annotation

Codecov / codecov/patch

crypto/internal.h#L464

Added line #L464 was not covered by tests
return CRYPTO_bswap8(ret);
#else
return ret;
#endif

Check warning on line 468 in crypto/internal.h

View check run for this annotation

Codecov / codecov/patch

crypto/internal.h#L466-L468

Added lines #L466 - L468 were not covered by tests
}

static inline void CRYPTO_store_u64_be(void *out, uint64_t v) {
#if !defined(RING_BIG_ENDIAN)

Check warning on line 472 in crypto/internal.h

View check run for this annotation

Codecov / codecov/patch

crypto/internal.h#L472

Added line #L472 was not covered by tests
v = CRYPTO_bswap8(v);
OPENSSL_memcpy(out, &v, sizeof(v));
}

static inline crypto_word_t CRYPTO_load_word_le(const void *in) {
crypto_word_t v;
OPENSSL_memcpy(&v, in, sizeof(v));
return v;
}

static inline void CRYPTO_store_word_le(void *out, crypto_word_t v) {
#endif

Check warning on line 474 in crypto/internal.h

View check run for this annotation

Codecov / codecov/patch

crypto/internal.h#L474

Added line #L474 was not covered by tests
OPENSSL_memcpy(out, &v, sizeof(v));
}

Expand Down
3 changes: 3 additions & 0 deletions include/ring-core/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
#elif defined(__riscv) && __SIZEOF_POINTER__ == 8
#define OPENSSL_64_BIT
#define OPENSSL_RISCV64
#elif defined(__s390x__)
#define OPENSSL_64_BIT
#define OPENSSL_S390X
#elif defined(__wasm__)
#define OPENSSL_32_BIT
#else
Expand Down
11 changes: 11 additions & 0 deletions mk/cargo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ qemu_arm="qemu-arm -L /usr/arm-linux-gnueabihf"
qemu_mipsel="qemu-mipsel -L /usr/mipsel-linux-gnu"
qemu_powerpc64le="qemu-ppc64le -L /usr/powerpc64le-linux-gnu"
qemu_riscv64="qemu-riscv64 -L /usr/riscv64-linux-gnu"
qemu_s390x="qemu-s390x -L /usr/s390x-linux-gnu"

# Avoid putting the Android tools in `$PATH` because there are tools in this
# directory like `clang` that would conflict with the same-named tools that may
Expand Down Expand Up @@ -114,6 +115,16 @@ case $target in
export CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-linux-gnu-gcc
export CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUNNER="$qemu_riscv64"
;;
s390x-unknown-linux-gnu)
export CC_s390x_unknown_linux_gnu=clang-$llvm_version
export AR_s390x_unknown_linux_gnu=llvm-ar-$llvm_version
# XXX: Using -march=zEC12 to work around a z13 instruction bug in
# QEMU 8.0.2 and earlier that causes `test_constant_time` to fail
# (https://lists.gnu.org/archive/html/qemu-devel/2023-05/msg06965.html).
export CFLAGS_s390x_unknown_linux_gnu="--sysroot=/usr/s390x-linux-gnu -march=zEC12"
export CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_LINKER=s390x-linux-gnu-gcc
export CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_RUNNER="$qemu_s390x"
;;
x86_64-unknown-linux-musl)
export CC_x86_64_unknown_linux_musl=clang-$llvm_version
export AR_x86_64_unknown_linux_musl=llvm-ar-$llvm_version
Expand Down
8 changes: 8 additions & 0 deletions mk/install-build-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ case $target in
libc6-dev-riscv64-cross \
qemu-user
;;
--target=s390x-unknown-linux-gnu)
# Clang is needed for code coverage.
use_clang=1
install_packages \
qemu-user \
gcc-s390x-linux-gnu \
libc6-dev-s390x-cross
;;
--target=wasm32-unknown-unknown)
cargo install wasm-bindgen-cli --bin wasm-bindgen-test-runner
use_clang=1
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,9 @@
pub trait Sealed {}
}

// TODO: https://github.com/briansmith/ring/issues/1555.
const _LITTLE_ENDIAN_ONLY: () = assert!(cfg!(target_endian = "little"));
briansmith marked this conversation as resolved.
Show resolved Hide resolved
// XXX: 64-bit big endian is tested; 32-bit is not.
// TODO: Add 32-bit big endian test coverage to CI.

Check warning on line 119 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L119

Added line #L119 was not covered by tests
const _ENDIAN_TESTING: () = assert!(cfg!(any(
target_endian = "little",

Check warning on line 121 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L121

Added line #L121 was not covered by tests
target_pointer_width = "64"
)));
Loading