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 support #1277

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ jobs:
- i686-pc-windows-msvc
- i686-unknown-linux-gnu
- i686-unknown-linux-musl
- mipsel-unknown-linux-gnu
- x86_64-pc-windows-gnu
- x86_64-pc-windows-msvc
- x86_64-apple-darwin
Expand Down Expand Up @@ -259,6 +260,9 @@ jobs:
- target: i686-unknown-linux-musl
host_os: ubuntu-18.04

- target: mipsel-unknown-linux-gnu
host_os: ubuntu-18.04

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

Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ include = [
"crypto/fipsmodule/bn/asm/x86-mont.pl",
"crypto/fipsmodule/bn/asm/x86_64-mont.pl",
"crypto/fipsmodule/bn/asm/x86_64-mont5.pl",
"crypto/fipsmodule/bn/asm/mips-mont.pl",
Copy link
Owner

Choose a reason for hiding this comment

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

I understand why you're trying to do it this way, but this is exactly what I'm hoping to avoid. Let's find a way to do it without bringing in any MIPS assembly code. It's just not realistic to maintain the MIPS assembly code given current constraints. I'd rather concentrate on improving the C (in the near future, Rust) code instead.

Copy link
Author

Choose a reason for hiding this comment

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

I'm mostly reverse-engineering the error messages which complained about bn_mul_mont not existing, and I found this file defines it. I'm ok with removing it if I can figure out another way to overcome the error message.

"crypto/fipsmodule/bn/internal.h",
"crypto/fipsmodule/bn/montgomery.c",
"crypto/fipsmodule/bn/montgomery_inv.c",
Expand Down Expand Up @@ -105,6 +106,7 @@ include = [
"examples/checkdigest.rs",
"include/ring-core/aes.h",
"include/ring-core/arm_arch.h",
"include/ring-core/mips_arch.h",
"include/ring-core/base.h",
"include/ring-core/check.h",
"include/ring-core/cpu.h",
Expand Down
37 changes: 31 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const X86: &str = "x86";
const X86_64: &str = "x86_64";
const AARCH64: &str = "aarch64";
const ARM: &str = "arm";
const MIPS: &str = "mips";
const MIPS64: &str = "mips64";

#[rustfmt::skip]
const RING_SRCS: &[(&[&str], &str)] = &[
Expand All @@ -40,12 +42,12 @@ const RING_SRCS: &[(&[&str], &str)] = &[
(&[], "crypto/mem.c"),
(&[], "crypto/poly1305/poly1305.c"),

(&[AARCH64, ARM, X86_64, X86], "crypto/crypto.c"),
(&[AARCH64, ARM, X86_64, X86], "crypto/curve25519/curve25519.c"),
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/ecp_nistz.c"),
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/gfp_p256.c"),
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/gfp_p384.c"),
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/p256.c"),
(&[AARCH64, ARM, MIPS, MIPS64, X86_64, X86], "crypto/crypto.c"),
Copy link
Owner

Choose a reason for hiding this comment

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

crypto.c isn't relevant to MIPS so this should be reverted.

(&[AARCH64, ARM, MIPS, MIPS64, X86_64, X86], "crypto/curve25519/curve25519.c"),
(&[AARCH64, ARM, MIPS, MIPS64, X86_64, X86], "crypto/fipsmodule/ec/ecp_nistz.c"),
(&[AARCH64, ARM, MIPS, MIPS64, X86_64, X86], "crypto/fipsmodule/ec/gfp_p256.c"),
(&[AARCH64, ARM, MIPS, MIPS64, X86_64, X86], "crypto/fipsmodule/ec/gfp_p384.c"),
(&[AARCH64, ARM, MIPS, MIPS64, X86_64, X86], "crypto/fipsmodule/ec/p256.c"),
Copy link
Owner

Choose a reason for hiding this comment

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

Just use &[] for all of these. An empty list means "every platform."


(&[X86_64, X86], "crypto/cpu-intel.c"),

Expand Down Expand Up @@ -87,6 +89,8 @@ const RING_SRCS: &[(&[&str], &str)] = &[
(&[AARCH64], "crypto/chacha/asm/chacha-armv8.pl"),
(&[AARCH64], "crypto/fipsmodule/modes/asm/ghash-neon-armv8.pl"),
(&[AARCH64], SHA512_ARMV8),

(&[MIPS, MIPS64], "crypto/fipsmodule/bn/asm/mips-mont.pl"),
];

const SHA256_X86_64: &str = "crypto/fipsmodule/sha/asm/sha256-x86_64.pl";
Expand Down Expand Up @@ -200,6 +204,20 @@ const ASM_TARGETS: &[AsmTarget] = &[
asm_extension: "S",
preassemble: false,
},
AsmTarget {
Copy link
Owner

Choose a reason for hiding this comment

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

Let's remove the AsmTarget stuff for MIPS since my goal is to not have any assembly code for MIPS.

oss: LINUX_ABI,
arch: "mips",
perlasm_format: "elf",
asm_extension: "S",
preassemble: false,
},
AsmTarget {
oss: LINUX_ABI,
arch: "mips64",
perlasm_format: "elf",
asm_extension: "S",
preassemble: false,
},
AsmTarget {
oss: MACOS_ABI,
arch: "aarch64",
Expand Down Expand Up @@ -309,6 +327,7 @@ fn ring_build_rs_main() {
let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
let endian = env::var("CARGO_CFG_TARGET_ENDIAN").unwrap();
let (obj_ext, obj_opt) = if env == MSVC {
(MSVC_OBJ_EXT, MSVC_OBJ_OPT)
} else {
Expand All @@ -322,6 +341,7 @@ fn ring_build_rs_main() {

let target = Target {
arch,
endian,
Copy link
Owner

Choose a reason for hiding this comment

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

No need to store endian in the target since no big-endian targets are supported.

os,
env,
obj_ext,
Expand Down Expand Up @@ -373,6 +393,7 @@ fn pregenerate_asm_main() {

struct Target {
arch: String,
endian: String,
os: String,
env: String,
obj_ext: &'static str,
Expand All @@ -391,6 +412,10 @@ fn build_c_code(target: &Target, pregenerated: PathBuf, out_dir: &Path, ring_cor
}
}

if target.arch == "mips" && target.endian == "big" {
Copy link
Owner

Choose a reason for hiding this comment

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

No need for target.arch == "mips" because no big-endian targets are supported yet.

panic!("MIPS Big-Endian detected. Stoping compilation as BoringSSL code are not available for this platform");
Copy link
Owner

Choose a reason for hiding this comment

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

I would just write "Big-endian targets are not supported yet."

}

let asm_target = ASM_TARGETS.iter().find(|asm_target| {
asm_target.arch == target.arch && asm_target.oss.contains(&target.os.as_ref())
});
Expand Down
Loading