Skip to content

Commit

Permalink
Add inline annotations on conditional_select in p256, k256, and prime…
Browse files Browse the repository at this point in the history
…order

This seems to help situations where the Rust compiler otherwise will not
completely inline conditional_select, causing algoritms which depend on this to
become significantly slower than they would otherwise.

See #940 for discussion.
  • Loading branch information
randombit committed Oct 18, 2023
1 parent 75d2ee4 commit c818f89
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions k256/src/arithmetic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ impl PrimeField for FieldElement {
}

impl ConditionallySelectable for FieldElement {
#[inline(always)]
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
Self(FieldElementImpl::conditional_select(&(a.0), &(b.0), choice))
}
Expand Down
1 change: 1 addition & 0 deletions k256/src/arithmetic/field/field_10x26.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ impl Default for FieldElement10x26 {
}

impl ConditionallySelectable for FieldElement10x26 {
#[inline(always)]
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
Self([
u32::conditional_select(&a.0[0], &b.0[0], choice),
Expand Down
1 change: 1 addition & 0 deletions k256/src/arithmetic/field/field_5x52.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ impl Default for FieldElement5x52 {
}

impl ConditionallySelectable for FieldElement5x52 {
#[inline(always)]
fn conditional_select(
a: &FieldElement5x52,
b: &FieldElement5x52,
Expand Down
1 change: 1 addition & 0 deletions k256/src/arithmetic/field/field_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl Default for FieldElementImpl {
}

impl ConditionallySelectable for FieldElementImpl {
#[inline(always)]
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
// 1. It's debug only, so it shouldn't present a security risk
// 2. Being normalized does is independent from the field element value;
Expand Down
1 change: 1 addition & 0 deletions p256/src/arithmetic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ impl PrimeField for FieldElement {
}

impl ConditionallySelectable for FieldElement {
#[inline(always)]
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
Self(U256::conditional_select(&a.0, &b.0, choice))
}
Expand Down
1 change: 1 addition & 0 deletions primeorder/src/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl<C> ConditionallySelectable for AffinePoint<C>
where
C: PrimeCurveParams,
{
#[inline(always)]
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
Self {
x: C::FieldElement::conditional_select(&a.x, &b.x, choice),
Expand Down
1 change: 1 addition & 0 deletions primeorder/src/projective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl<C> ConditionallySelectable for ProjectivePoint<C>
where
C: PrimeCurveParams,
{
#[inline(always)]
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
Self {
x: C::FieldElement::conditional_select(&a.x, &b.x, choice),
Expand Down

0 comments on commit c818f89

Please sign in to comment.