-
Notifications
You must be signed in to change notification settings - Fork 708
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
C (or Rust) fallback for all functions that work for all little-endian targets #1455
Comments
Also related to #1297 it seems! |
I am generalizing this issue to be about automatically supporting every little-endian architecture with a generic fallback. Big-endian architectures are tracked separately in #1555; the work in supporting them is a superset of the work in supporting the little-endian architectures. Here's what we need to do, AFAICT:
Regarding the allowlist in
The base.h file is inherited from BoringSSL. The allowlist approach may work well for BoringSSL but it won't work well for ring because the allowlist means that we necessarily must receive at least one PR per target architecture before that architecutre starts working. We should remove things like the logic that defines Ahead of the - #else
- #endif
+ #elif defined(RING_ASSUME_OPENSSL_32_BIT)
+ #define OPENSSL_32_BIT
+ #elif defined(RING_ASSUME_OPENSSL_64_BIT)
+ #define OPENSSL_64_BIT
#else
// Note BoringSSL only supports standard 32-bit and 64-bit two's-complement,
// little-endian architectures. Functions will not produce the correct answer
// on other systems. Run the crypto_test binary, notably
// crypto/compiler_test.cc, before adding a new architecture.
#error "Unknown target CPU"
#endif
+ #if (defined(RING_ASSUME_OPENSSL_32_BIT) && defined(OPENSSL_64_BIT)) || (defined(RING_ASSUME_OPENSSL_64_BIT) && !defined(OPENSSL_64_BIT))
+ #error "RING_ASSUME_OPENSSL_{32,64}_BIT does not match OPENSSL_{32,64}_BIT`
+ #endif Then build.rs can set One complication is that currently we have:
My understanding is that WebAssembly should be able to properly support 64-bit integers and, if that is correct, we should ensure Also in build.rs we currently have:
I suggest we try to generalize that to every target_arch and every OS (besides macOS and Windows?), so that cross-compiling with clang won't require a sysroot. |
Unfortunately wasm32-wasi doesn't look like a great choice because it doesn't support profiler builtins, which means it doesn't support code coverage measurement. Anybody have a suggestion for a single 32-bit target and a single 32-bit target that each meets these conditions?:
For my part in this, I am expanding the test suite to include more tests for the arithmetic for which we'll need to add fallbacks for ( |
I'm curious if |
Here are some rust-lang/rust issues related to missing profiler built-in support:
|
Besides the code coverage measurement issue, here are some additional things to consider:
We should go add that boilerplate to all the tests as part of doing this work, or at least all the integration tests. We should add a static assertion that the target is either 32-bit or 64-bit. We should add a static assertion that the target is little-endian. Again, changes to support big endian targets are expected to be done on top of this work, and those changes are tracked in issue #1555. |
PR #1558 implements the fallback for |
It seems like PR #1558 was the only thing needed here that isn't big-endian specific. Given rust-lang/rust#104304, it looks like the fallback logic will most likely end up being tested in QEMU using s390x once the big-endian support is added (see #1555), at least initially. |
rust-lang/rust#105389 has added profiler support on So platform-independent code can also be tested on little-endian systems now. |
When building for
It looks like there hasn't been a release in 2 years, have fixes for this been merged? |
Thank you very much Brian, and happy new year! |
Related: #1419
Just want to start a conversation around portability to embedded architectures.
Despite having a lot of assembly, ring actually pretty close to being portable. All that's preventing it from building on architectures like RISC-V and xtensa is a Rust or pure-C implementation of what appears to be a montgomery multiplier. There's an open PR (#1436) to add one (written in C) but I can't figure out where the code actually came from, and there are no tests so I don't really trust it.
I'm pretty motivated to get crypto stuff working for an ESP32 project of mine, so let me know if I can help make this happen. I'd be up for trying to write a C or Rust fallback for this function, or writing tests for the existing one, trying to analyze it with KLEE to prove its memory safety and constant-time properties, etc, whatever's needed to meet code standards.
It would be amazing to have the entire rust ecosystem of crypto libraries working on the ESP32 especially if I don't have to maintain a patch like I am right now. :)
The text was updated successfully, but these errors were encountered: