Skip to content

Commit

Permalink
Try fix xtensa on 0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
reinismu committed Feb 3, 2023
1 parent c58b615 commit d82e61d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ untrusted = { version = "0.7.1" }
[target.'cfg(any(target_arch = "x86",target_arch = "x86_64", all(any(target_arch = "aarch64", target_arch = "arm"), any(target_os = "android", target_os = "fuchsia", target_os = "linux"))))'.dependencies]
spin = { version = "0.5.2", default-features = false }

[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
[target.'cfg(any(target_os = "android", target_os = "linux", target_os = "espidf"))'.dependencies]
libc = { version = "0.2.69", default-features = false }
once_cell = { version = "1.5.2", default-features = false, features=["std"], optional = true }

Expand Down Expand Up @@ -339,6 +339,7 @@ slow_tests = []
std = ["alloc"]
test_logging = []
wasm32_c = []
size_optimized = []

# XXX: debug = false because of https://github.com/rust-lang/rust/issues/34122

Expand Down
18 changes: 10 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,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/ecp_nistz256.c"),
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/gfp_p256.c"),
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/gfp_p384.c"),
(&[], "crypto/crypto.c"),
(&[], "crypto/curve25519/curve25519.c"),
(&[], "crypto/fipsmodule/ec/ecp_nistz.c"),
(&[], "crypto/fipsmodule/ec/ecp_nistz256.c"),
(&[], "crypto/fipsmodule/ec/gfp_p256.c"),
(&[], "crypto/fipsmodule/ec/gfp_p384.c"),

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

Expand Down Expand Up @@ -168,7 +168,8 @@ fn cpp_flags(target: &Target) -> &'static [&'static str] {
"-Wenum-compare",
"-Wfloat-equal",
"-Wformat=2",
"-Winline",
// #[cfg(not(feature = "size_optimized"))]
// "-Winline",
"-Winvalid-pch",
"-Wmissing-field-initializers",
"-Wmissing-include-dirs",
Expand Down Expand Up @@ -227,6 +228,7 @@ const ASM_TARGETS: &[(&str, Option<&str>, Option<&str>)] = &[
("arm", Some("ios"), Some("ios32")),
("arm", None, Some("linux32")),
("wasm32", None, None),
("xtensa", None, None),
];

const WINDOWS: &str = "windows";
Expand Down Expand Up @@ -355,7 +357,7 @@ fn build_c_code(target: &Target, pregenerated: PathBuf, out_dir: &Path) {
let &(entry_arch, entry_os, _) = *entry;
entry_arch == target.arch && is_none_or_equals(entry_os, &target.os)
})
.unwrap();
.unwrap_or_else(|| panic!("Invalid target {}", target.arch));

let use_pregenerated = !target.is_git;
let warnings_are_errors = target.is_git;
Expand Down
14 changes: 14 additions & 0 deletions crypto/fipsmodule/bn/montgomery.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,17 @@ int GFp_bn_from_montgomery_in_place(BN_ULONG r[], size_t num_r, BN_ULONG a[],
}
return 1;
}

#if !defined(OPENSSL_X86) && !defined(OPENSSL_X86_64) && \
!defined(OPENSSL_ARM) && !defined(OPENSSL_AARCH64)
void bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
const BN_ULONG *np, const BN_ULONG *n0, size_t num) {
Limb tmp[2 * num];
for (size_t i = 0; i < num; i++)
tmp[i] = 0;
for (size_t i = 0; i < num; i++)
tmp[num + i] = limbs_mul_add_limb(tmp + i, ap, bp[i], num);

bn_from_montgomery_in_place(rp, num, tmp, 2 * num, np, num, n0);
}
#endif
6 changes: 6 additions & 0 deletions include/GFp/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
#define OPENSSL_MIPS64
#elif defined(__wasm__)
#define OPENSSL_32_BIT
#elif defined(__xtensa__)
#define OPENSSL_32_BIT
#elif defined(__riscv) && __riscv_xlen == 64
#define OPENSSL_64_BIT
#elif defined(__riscv) && __riscv_xlen == 32
#define OPENSSL_32_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
Expand Down
17 changes: 17 additions & 0 deletions src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl crate::sealed::Sealed for SystemRandom {}
not(feature = "dev_urandom_fallback")
),
target_arch = "wasm32",
target_os = "espidf",
windows
))]
use self::sysrand::fill as fill_impl;
Expand Down Expand Up @@ -244,6 +245,21 @@ mod sysrand_chunk {
}
}

#[cfg(target_os = "espidf")]
mod sysrand_chunk {
use crate::{c, error};

#[inline]
pub fn chunk(dest: &mut [u8]) -> Result<usize, error::Unspecified> {
let chunk_len: c::size_t = dest.len();
let r = unsafe { libc::getrandom(dest.as_mut_ptr() as *mut libc::c_void, chunk_len, 0) };
if r < 0 {
return Err(error::Unspecified);
}
Ok(r as usize)
}
}

#[cfg(all(
target_arch = "wasm32",
target_vendor = "unknown",
Expand Down Expand Up @@ -300,6 +316,7 @@ mod sysrand_chunk {
target_os = "android",
target_os = "linux",
target_arch = "wasm32",
target_os = "espidf",
windows
))]
mod sysrand {
Expand Down

0 comments on commit d82e61d

Please sign in to comment.