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 support for watchOS. #1914

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ const LINUX_ABI: &[&str] = &[

/// Operating systems that have the same ABI as macOS on every architecture
/// mentioned in `ASM_TARGETS`.
const MACOS_ABI: &[&str] = &["ios", "macos", "tvos"];
const MACOS_ABI: &[&str] = &["ios", "macos", "tvos", "watchos"];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this is precise enough. More discussion about this in #1832.


const WINDOWS: &str = "windows";

Expand Down
18 changes: 15 additions & 3 deletions src/ec/curve25519/x25519.rs
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, this file would require the additional OS checks that weren't necessary for tvOS as watchOS does support 32-bit ARM.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like BoringSSL is disabling all assembly support for 32-bit Apple targets, so I think we should do the same, and add a target_vendor="apple" case for this check? WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the PR author but that seems reasonable. There's no NEON available so the optimizations available on ARMv7k are more limited.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a reasonable suggestion to me 👍

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See PR #1919.

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ fn x25519_public_from_private(
let private_key: &[u8; SCALAR_LEN] = private_key.bytes_less_safe().try_into()?;
let private_key = ops::MaskedScalar::from_bytes_masked(*private_key);

#[cfg(all(not(target_os = "ios"), target_arch = "arm"))]
#[cfg(all(
target_arch = "arm",
not(target_os = "ios"),
not(target_os = "watchos")
))]
{
if cpu::arm::NEON.available(cpu_features) {
static MONTGOMERY_BASE_POINT: [u8; 32] = [
Expand Down Expand Up @@ -109,7 +113,11 @@ fn x25519_ecdh(
point: &ops::EncodedPoint,
#[allow(unused_variables)] cpu_features: cpu::Features,
) {
#[cfg(all(not(target_os = "ios"), target_arch = "arm"))]
#[cfg(all(
target_arch = "arm",
not(target_os = "ios"),
not(target_os = "watchos")
Copy link
Contributor

@BlackHoleFox BlackHoleFox Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs more info in #1919 first, and to avoid derailing, but then this gate isn't fully correct. The two 64-bit ARM Apple Watch targets have NEON.

))]
{
if cpu::arm::NEON.available(cpu_features) {
return x25519_neon(out, scalar, point);
Expand Down Expand Up @@ -158,7 +166,11 @@ fn x25519_ecdh(
Ok(())
}

#[cfg(all(not(target_os = "ios"), target_arch = "arm"))]
#[cfg(all(
target_arch = "arm",
not(target_os = "ios"),
not(target_os = "watchos")
))]
fn x25519_neon(out: &mut ops::EncodedPoint, scalar: &ops::MaskedScalar, point: &ops::EncodedPoint) {
prefixed_extern! {
fn x25519_NEON(
Expand Down
1 change: 1 addition & 0 deletions src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl crate::sealed::Sealed for SystemRandom {}
target_os = "solaris",
target_os = "tvos",
target_os = "vita",
target_os = "watchos",
target_os = "windows",
all(
target_arch = "wasm32",
Expand Down