Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sec1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rust-version = "1.85"

[dependencies]
base16ct = { version = "1", optional = true, default-features = false }
ctutils = { version = "0.3", optional = true }
der = { version = "0.8.0-rc.10", optional = true, features = ["oid"] }
hybrid-array = { version = "0.4", optional = true, default-features = false }
serdect = { version = "0.4", optional = true, default-features = false, features = ["alloc"] }
Expand Down
79 changes: 48 additions & 31 deletions sec1/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use hybrid_array::{Array, ArraySize, typenum::U1};
#[cfg(feature = "alloc")]
use alloc::boxed::Box;

#[cfg(feature = "ctutils")]
use ctutils::{Choice, CtSelect};

#[cfg(feature = "serde")]
use serdect::serde::{Deserialize, Serialize, de, ser};

#[cfg(feature = "subtle")]
use subtle::{Choice, ConditionallySelectable};

#[cfg(feature = "zeroize")]
use zeroize::Zeroize;

Expand Down Expand Up @@ -254,23 +254,6 @@ where
}
}

#[cfg(feature = "subtle")]
impl<Size> ConditionallySelectable for EncodedPoint<Size>
where
Size: ModulusSize,
<Size::UncompressedPointSize as ArraySize>::ArrayType<u8>: Copy,
{
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
let mut bytes = Array::default();

for (i, byte) in bytes.iter_mut().enumerate() {
*byte = u8::conditional_select(&a.bytes[i], &b.bytes[i], choice);
}

Self { bytes }
}
}

impl<Size> Copy for EncodedPoint<Size>
where
Size: ModulusSize,
Expand Down Expand Up @@ -336,17 +319,6 @@ where
}
}

#[cfg(feature = "zeroize")]
impl<Size> Zeroize for EncodedPoint<Size>
where
Size: ModulusSize,
{
fn zeroize(&mut self) {
self.bytes.zeroize();
*self = Self::identity();
}
}

impl<Size> fmt::Display for EncodedPoint<Size>
where
Size: ModulusSize,
Expand Down Expand Up @@ -392,6 +364,40 @@ where
}
}

// TODO(tarcieri): add `ctutils` support to `hybrid-array`
#[cfg(feature = "ctutils")]
impl<Size> CtSelect for EncodedPoint<Size>
where
Size: ModulusSize,
{
fn ct_select(&self, other: &Self, choice: Choice) -> Self {
let mut bytes = Array::default();

for (i, byte) in bytes.iter_mut().enumerate() {
*byte = self.bytes[i].ct_select(&other.bytes[i], choice);
}

Self { bytes }
}
}

#[cfg(feature = "subtle")]
impl<Size> subtle::ConditionallySelectable for EncodedPoint<Size>
where
Size: ModulusSize,
<Size::UncompressedPointSize as ArraySize>::ArrayType<u8>: Copy,
{
fn conditional_select(a: &Self, b: &Self, choice: subtle::Choice) -> Self {
let mut bytes = Array::default();

for (i, byte) in bytes.iter_mut().enumerate() {
*byte = u8::conditional_select(&a.bytes[i], &b.bytes[i], choice);
}

Self { bytes }
}
}

#[cfg(feature = "serde")]
impl<Size> Serialize for EncodedPoint<Size>
where
Expand Down Expand Up @@ -419,6 +425,17 @@ where
}
}

#[cfg(feature = "zeroize")]
impl<Size> Zeroize for EncodedPoint<Size>
where
Size: ModulusSize,
{
fn zeroize(&mut self) {
self.bytes.zeroize();
*self = Self::identity();
}
}

/// Enum representing the coordinates of either compressed or uncompressed
/// SEC1-encoded elliptic curve points.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Expand Down