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 MIPS little-endian support #1181

Closed
wants to merge 41 commits into from
Closed

Conversation

bltavares
Copy link

@bltavares bltavares commented Jan 26, 2021

This is an attempt to add #562 MIPS support, starting with Little Endian platforms.

This includes the merge of several different PRs and fixes to match the latest code in the main branch, such as:

Tests on other platforms (Windows, Linux) still works. There are errors when running on mips, to be fixed yet. So far, Big Endian support is not present, as many of the BoringSSL files don't support it.

Failed tests with `cross test --target mipsel-unknown-linux-musl`
test ec::suite_b::ecdsa::digest_scalar::tests::test ... ok
test ec::suite_b::ecdsa::signing::tests::signature_ecdsa_sign_asn1_test ... FAILED
test ec::suite_b::ecdsa::signing::tests::signature_ecdsa_sign_fixed_test ... FAILED
test ec::suite_b::ecdsa::verification::tests::test_digest_based_test_vectors ... FAILED
test ec::suite_b::ops::tests::p256_elem_add_test ... ok
test ec::suite_b::ops::tests::p256_elem_mul_test ... ok
test ec::suite_b::ops::tests::p256_point_double_test ... ok
test ec::suite_b::ops::tests::p256_point_mul_base_test ... ok
test ec::suite_b::ops::tests::p256_point_mul_serialized_test ... ok
test ec::suite_b::ops::tests::p256_point_mul_test ... ok
test ec::suite_b::ops::tests::p256_point_sum_test ... ok
test ec::suite_b::ops::tests::p256_q_minus_n_plus_n_equals_0_test ... ok
test ec::suite_b::ops::tests::p256_scalar_inv_to_mont_zero_panic_test ... ok
test ec::suite_b::ops::tests::p256_scalar_mul_test ... FAILED
test ec::suite_b::ops::tests::p256_scalar_square_test ... FAILED
test ec::suite_b::ops::tests::p384_elem_add_test ... ok
test ec::suite_b::ops::tests::p384_elem_div_by_2_test ... ok
test ec::suite_b::ops::tests::p384_elem_mul_test ... qemu: uncaught target signal 11 (Segmentation fault) - core dumped

xen0n and others added 30 commits January 31, 2020 14:22
And disable point_mixed_test on mips64 where the codepath is unused.
Conditionally exclude the corresponding C code as well.
nistz256: N0 for p256 is TOBN(0x0, 0x1)
Don't require a specialized implementation of field element addition for
each curve; instead share an implementation between RSA and ECC.

Refactor the code to avoid needing `elem_sum`.
Use Fiat Crypto for non-x86_64 platforms, like BoringSSL. Continue
using the nistz256 code on Windows, differently from BoringSSL.

Make *ring* more consistent with BoringSSL.
briansmith and others added 11 commits January 21, 2021 16:15
Assume by default that an operating system does not have an ABI compatible
with the PerlAsm sources. Add all the operating systems that we've
explicitly added support for to the allowlist. Avoid trying to build or
use the PerlAsm code for those targets.

On top of this, we can build fallback logic for using Rust (or C)
implementations for those targets that aren't compatible with the
assembly.
@briansmith
Copy link
Owner

I think we're getting very close to being able to merge this, as I've merged some of the prerequisite work recently. I'm hoping to sort out #1174 and get it merged this weekend.

@briansmith
Copy link
Owner

PR #1174 is merged, which I think is the last prerequisite to this.

@briansmith
Copy link
Owner

@bltavares @LinusU I think we should rebase this PR (#1181) on top of PR #1120, and then close out #1120, concentrating our work on this PR (#1181). I think we should be very close to getting this mergable. Either of you interested in doing that?

Copy link
Owner

@briansmith briansmith left a comment

Choose a reason for hiding this comment

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

Reading this PR, it seems like a lot can be simplified.

Regarding the ECC stuff, if MIPS won't work without changes to the ECC code, then I guess we should do those changes to the ECC code in a separate PR from this MIPS-specific PR.

@@ -0,0 +1,119 @@
/*
Copy link
Owner

Choose a reason for hiding this comment

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

We now have src/aead/chacha/fallback.rs so we don't need this file any more.

@@ -1 +1,2 @@
ecp_nistz256_table.inl linguist-generated=true
p256-x86_64-table.h linguist-generated=true
p256_table.h linguist-generated=true
Copy link
Owner

Choose a reason for hiding this comment

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

It seems like all this ECC stuff can be deleted now. I think you can revert all crypto/fipsmodule/ec stuff.

target_arch = "arm",
target_arch = "x86_64",
target_arch = "x86"
))]
Copy link
Owner

Choose a reason for hiding this comment

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

This whole function is already guarded by #[cfg(target_arch = "x86_64")] so this isn't needed.

#[inline]
fn detect_implementation(_cpu: cpu::Features) -> Implementation {
Implementation::Fallback
}
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of doing this, change cpu.rs so that you can construct a no-op cpu::Features on MIPS. In fact, I think I already did that for wasm32, so I think you can just delete all of these changes.

m.limbs.len(),
)
}
limb::limbs_add_assign_mod(&mut a.limbs, &b.limbs, &m.limbs);
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this change is needed for this PR? Otherwise, PLMK why it is.

#[cfg_attr(
not(any(target_arch = "aarch64", target_arch = "arm")),
allow(dead_code)
)]
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure why this would be needed in this PR, but not needed already. Maybe this can be removed now?

.private_key_ops
.common
.elem_add(&mut r, &public_key_ops.common.n);
if sig_r_equals_x(self.ops, &r, &x, &z2) {
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure why this needs to change now. Could you explain?

@bltavares
Copy link
Author

bltavares commented May 3, 2021

I could try rebasing the PR on top of PR #1120 on the weekend.

A lot of those changes came from #943, so I don't have much context either. I just tried to make it compile and fixed the conflicts from the original PR hehe

@briansmith
Copy link
Owner

A lot of those changes came from #943, so I don't have much context either. I just tried to make it compile and fixed the conflicts from the original PR hehe

OK, then let's close this PR and try to build the final PR in #1120 on top of the code that's already there, trying to minimize the changes. Trying to port the code from PR #943 seems kind of unworkable since we don't understand that PR and also for IPR reasons.

@briansmith briansmith closed this May 3, 2021
bltavares added a commit to bltavares/ring that referenced this pull request May 4, 2021
This commit ports the changes from briansmith#1181 into the updated codebase

The following command is working:
> cross build --target mipsel-unknown-linux-musl

But tests are still not working:
> cross test --target mipsel-unknown-linux-musl
@bltavares bltavares mentioned this pull request May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants