Skip to content

Commit

Permalink
Make from_bytes_unchecked() for Scalar and Field pribate to the crate
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Jul 21, 2020
1 parent 2d18ea1 commit 3d19153
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion k256/src/arithmetic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl FieldElement {

/// Attempts to parse the given byte array as an SEC-1-encoded field element.
/// Does not check the result for being in the correct range.
pub const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
pub(crate) const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
Self(FieldElementImpl::from_bytes_unchecked(bytes))
}

Expand Down
2 changes: 1 addition & 1 deletion k256/src/arithmetic/field/field_10x26.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl FieldElement10x26 {

/// Attempts to parse the given byte array as an SEC-1-encoded field element.
/// Does not check the result for being in the correct range.
pub const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
pub(crate) const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
let w0 = (bytes[31] as u32)
| ((bytes[30] as u32) << 8)
| ((bytes[29] as u32) << 16)
Expand Down
2 changes: 1 addition & 1 deletion k256/src/arithmetic/field/field_5x52.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl FieldElement5x52 {

/// Attempts to parse the given byte array as an SEC-1-encoded field element.
/// Does not check the result for being in the correct range.
pub const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
pub(crate) const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
let w0 = (bytes[31] as u64)
| ((bytes[30] as u64) << 8)
| ((bytes[29] as u64) << 16)
Expand Down
2 changes: 1 addition & 1 deletion k256/src/arithmetic/field/field_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl FieldElementImpl {
Self::new_normalized(&FieldElementUnsafeImpl::one())
}

pub const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
pub(crate) const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
let value = FieldElementUnsafeImpl::from_bytes_unchecked(bytes);
Self::new_normalized(&value)
}
Expand Down
2 changes: 1 addition & 1 deletion k256/src/arithmetic/field/field_montgomery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl FieldElementMontgomery {
R
}

pub const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
pub(crate) const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
Self(bytes_to_words(bytes)).mul(&R2)
}

Expand Down
4 changes: 3 additions & 1 deletion k256/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ impl Scalar {

/// Attempts to parse the given byte array as a scalar.
/// Does not check the result for being in the correct range.
pub const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
#[cfg(feature = "endomorphism-mul")]
pub(crate) const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
Self(ScalarImpl::from_bytes_unchecked(bytes))
}

Expand Down Expand Up @@ -510,6 +511,7 @@ mod tests {
}

#[test]
#[cfg(feature = "endomorphism-mul")]
fn fuzzy_roundtrip_to_bytes_unchecked(a in scalar()) {
let bytes = a.to_bytes();
let a_back = Scalar::from_bytes_unchecked(&bytes);
Expand Down
3 changes: 2 additions & 1 deletion k256/src/arithmetic/scalar/scalar_4x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ impl Scalar4x64 {
self.0[0] as u32
}

pub const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
#[cfg(feature = "endomorphism-mul")]
pub(crate) const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
// Interpret the bytes as a big-endian integer w.
let w3 =
((bytes[0] as u64) << 56) | ((bytes[1] as u64) << 48) | ((bytes[2] as u64) << 40) | ((bytes[3] as u64) << 32) |
Expand Down
3 changes: 2 additions & 1 deletion k256/src/arithmetic/scalar/scalar_8x32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ impl Scalar8x32 {
self.0[0]
}

pub const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
#[cfg(feature = "endomorphism-mul")]
pub(crate) const fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self {
// Interpret the bytes as a big-endian integer w.
let w7 =
((bytes[0] as u32) << 24) | ((bytes[1] as u32) << 16) | ((bytes[2] as u32) << 8) | (bytes[3] as u32);
Expand Down

0 comments on commit 3d19153

Please sign in to comment.