Skip to content

Commit

Permalink
Enable ed25519 to be built in wasm target with wasm32_c gate
Browse files Browse the repository at this point in the history
  • Loading branch information
acmiyaguchi committed Jan 22, 2021
1 parent 628acbe commit 0b65853
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const RING_SRCS: &[(&[&str], &str)] = &[
(&[], "crypto/poly1305/poly1305.c"),

(&[AARCH64, ARM, X86_64, X86], "crypto/crypto.c"),
(&[AARCH64, ARM, X86_64, X86], "crypto/curve25519/curve25519.c"),
(&[], "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"),
Expand Down
18 changes: 18 additions & 0 deletions tests/ed25519_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ use ring::{
test, test_file,
};

#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::{wasm_bindgen_test, wasm_bindgen_test_configure};

#[cfg(target_arch = "wasm32")]
wasm_bindgen_test_configure!(run_in_browser);

/// Test vectors from BoringSSL.
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg(any(not(target_arch = "wasm32"), feature = "wasm32_c"))]
fn test_signature_ed25519() {
test::run(test_file!("ed25519_tests.txt"), |section, test_case| {
assert_eq!(section, "");
Expand Down Expand Up @@ -63,6 +71,8 @@ fn test_signature_ed25519() {

/// Test vectors from BoringSSL.
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg(any(not(target_arch = "wasm32"), feature = "wasm32_c"))]
fn test_signature_ed25519_verify() {
test::run(
test_file!("ed25519_verify_tests.txt"),
Expand Down Expand Up @@ -96,6 +106,8 @@ fn test_signature_verification(
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg(any(not(target_arch = "wasm32"), feature = "wasm32_c"))]
fn test_ed25519_from_seed_and_public_key_misuse() {
const PRIVATE_KEY: &[u8] = include_bytes!("ed25519_test_private_key.bin");
const PUBLIC_KEY: &[u8] = include_bytes!("ed25519_test_public_key.bin");
Expand All @@ -113,6 +125,8 @@ fn test_ed25519_from_seed_and_public_key_misuse() {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg(any(not(target_arch = "wasm32"), feature = "wasm32_c"))]
fn test_ed25519_from_pkcs8_unchecked() {
// Just test that we can parse the input.
test::run(
Expand All @@ -135,6 +149,8 @@ fn test_ed25519_from_pkcs8_unchecked() {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg(any(not(target_arch = "wasm32"), feature = "wasm32_c"))]
fn test_ed25519_from_pkcs8() {
// Just test that we can parse the input.
test::run(
Expand All @@ -157,6 +173,8 @@ fn test_ed25519_from_pkcs8() {
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg(any(not(target_arch = "wasm32"), feature = "wasm32_c"))]
fn ed25519_test_public_key_coverage() {
const PRIVATE_KEY: &[u8] = include_bytes!("ed25519_test_private_key.p8");
const PUBLIC_KEY: &[u8] = include_bytes!("ed25519_test_public_key.der");
Expand Down

0 comments on commit 0b65853

Please sign in to comment.