Skip to content

Commit

Permalink
Use small Curve25519 for wasm32 & other non-{aarch64,x86_64}.
Browse files Browse the repository at this point in the history
Enable `ring::agreement` for wasm32 targets using the small
implementation of Curve25519.

Use the small Curve25519 implementation of Curve25519 (and
P-256) for all targets except for Aarch64 and x86-64.

Besides being smaller, the small implementations are likely
more resistant to compiler-introduced side-channels, which
is especially important for the wasm32 virtual machine and
other targets that we don't QA as thoroughly as AAarch64
and x86-64.

Bring in the previously-removed definition of `fe_mul_llt`
from BoringSSL as of commit
8d71d24.
  • Loading branch information
briansmith committed Oct 14, 2023
1 parent 0f8386d commit da23dc0
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
8 changes: 5 additions & 3 deletions crypto/curve25519/curve25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,11 @@ static void fe_mul_ltt(fe_loose *h, const fe *f, const fe *g) {
fe_mul_impl(h->v, f->v, g->v);
}

// static void fe_mul_llt(fe_loose *h, const fe_loose *f, const fe *g) was
// removed. This comment is here to make diffs vs. BoringSSL easier to read.

#if defined(OPENSSL_SMALL)
static void fe_mul_llt(fe_loose *h, const fe_loose *f, const fe *g) {
fe_mul_impl(h->v, f->v, g->v);
}
#endif

static void fe_mul_ttt(fe *h, const fe *f, const fe *g) {
fe_mul_impl(h->v, f->v, g->v);
Expand Down
4 changes: 4 additions & 0 deletions include/ring-core/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,8 @@
#endif
#endif // OPENSSL_ASM_INCOMPATIBLE

#if !defined(OPENSSL_X86_64) && !defined(OPENSSL_AARCH64)
#define OPENSSL_SMALL
#endif

#endif // OPENSSL_HEADER_TARGET_H
1 change: 0 additions & 1 deletion src/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ derive_debug_via_id!(Curve);

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum CurveID {
#[cfg(not(target_arch = "wasm32"))]
Curve25519,
P256,
P384,
Expand Down
1 change: 0 additions & 1 deletion src/ec/curve25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
pub mod ed25519;

#[cfg(not(target_arch = "wasm32"))]
pub mod x25519;

mod ops;
Expand Down
1 change: 0 additions & 1 deletion src/ec/suite_b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ pub(crate) fn key_pair_from_bytes(

pub mod curve;

#[cfg(not(target_arch = "wasm32"))]
pub mod ecdh;

pub mod ecdsa;
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ mod polyfill;

pub mod aead;

#[cfg(not(target_arch = "wasm32"))]
pub mod agreement;

mod bits;
Expand Down
6 changes: 5 additions & 1 deletion tests/agreement_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#![cfg(not(target_arch = "wasm32"))]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test_configure!(run_in_browser);

extern crate alloc;

Expand Down

0 comments on commit da23dc0

Please sign in to comment.