Skip to content

Commit

Permalink
Rename ScalarBytes to ElementBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Aug 4, 2020
1 parent 9c4a886 commit 5b37cc0
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion k256/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,6 @@ mod tests {
let key = SecretKey::generate(&mut OsRng);

// Sanity check
assert!(!key.secret_scalar().iter().all(|b| *b == 0))
assert!(!key.as_bytes().iter().all(|b| *b == 0))
}
}
6 changes: 3 additions & 3 deletions k256/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cfg_if! {
}
}

use crate::{ScalarBytes, Secp256k1, SecretKey};
use crate::{ElementBytes, Secp256k1, SecretKey};
use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Shr, Sub, SubAssign};
use elliptic_curve::{
ops::Invert,
Expand Down Expand Up @@ -55,7 +55,7 @@ impl From<u32> for Scalar {

impl FromSecretKey<Secp256k1> for Scalar {
fn from_secret_key(secret_key: &SecretKey) -> CtOption<Self> {
Self::from_bytes(secret_key.secret_scalar().as_ref())
Self::from_bytes(secret_key.as_bytes().as_ref())
}
}

Expand Down Expand Up @@ -393,7 +393,7 @@ impl Invert for Scalar {
}
}

impl From<Scalar> for ScalarBytes {
impl From<Scalar> for ElementBytes {
fn from(scalar: Scalar) -> Self {
scalar.to_bytes().into()
}
Expand Down
4 changes: 2 additions & 2 deletions k256/src/ecdsa/signer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! ECDSA signer

use super::{recoverable, Error, Signature};
use crate::{ProjectivePoint, PublicKey, Scalar, ScalarBytes, Secp256k1, SecretKey};
use crate::{ElementBytes, ProjectivePoint, PublicKey, Scalar, Secp256k1, SecretKey};
use core::borrow::Borrow;
use ecdsa_core::{hazmat::RecoverableSignPrimitive, signature::RandomizedSigner};
use elliptic_curve::{
Expand Down Expand Up @@ -102,7 +102,7 @@ impl RecoverableSignPrimitive<Secp256k1> for Scalar {
fn try_sign_recoverable_prehashed<K>(
&self,
ephemeral_scalar: &K,
hashed_msg: &ScalarBytes,
hashed_msg: &ElementBytes,
) -> Result<(Signature, bool), Error>
where
K: Borrow<Scalar> + Invert<Output = Scalar>,
Expand Down
4 changes: 2 additions & 2 deletions k256/src/ecdsa/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! ECDSA verifier

use super::{recoverable, Error, Signature};
use crate::{AffinePoint, ProjectivePoint, PublicKey, Scalar, ScalarBytes, Secp256k1};
use crate::{AffinePoint, ElementBytes, ProjectivePoint, PublicKey, Scalar, Secp256k1};
use ecdsa_core::{hazmat::VerifyPrimitive, signature};
use elliptic_curve::subtle::CtOption;

Expand Down Expand Up @@ -36,7 +36,7 @@ impl signature::Verifier<recoverable::Signature> for Verifier {
impl VerifyPrimitive<Secp256k1> for AffinePoint {
fn verify_prehashed(
&self,
hashed_msg: &ScalarBytes,
hashed_msg: &ElementBytes,
signature: &Signature,
) -> Result<(), Error> {
let maybe_r =
Expand Down
2 changes: 1 addition & 1 deletion k256/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub type PublicKey = elliptic_curve::weierstrass::PublicKey<Secp256k1>;
/// K-256 Scalar Bytes.
///
/// Byte array containing a serialized scalar value (i.e. an integer)
pub type ScalarBytes = elliptic_curve::ScalarBytes<Secp256k1>;
pub type ElementBytes = elliptic_curve::ElementBytes<Secp256k1>;

/// K-256 Compressed Curve Point.
pub type CompressedPoint = elliptic_curve::weierstrass::CompressedPoint<Secp256k1>;
Expand Down
2 changes: 1 addition & 1 deletion p256/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,6 @@ mod tests {
let key = SecretKey::generate(&mut OsRng);

// Sanity check
assert!(!key.secret_scalar().iter().all(|b| *b == 0))
assert!(!key.as_bytes().iter().all(|b| *b == 0))
}
}
8 changes: 4 additions & 4 deletions p256/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(feature = "rand")]
pub mod blinding;

use crate::{NistP256, ScalarBytes, SecretKey};
use crate::{ElementBytes, NistP256, SecretKey};
use core::{
convert::TryInto,
ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign},
Expand Down Expand Up @@ -84,7 +84,7 @@ impl From<u64> for Scalar {

impl FromSecretKey<NistP256> for Scalar {
fn from_secret_key(secret_key: &SecretKey) -> CtOption<Self> {
Self::from_bytes(secret_key.secret_scalar().as_ref())
Self::from_bytes(secret_key.as_bytes().as_ref())
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ impl Scalar {
/// Returns None if the secret's underlying value does not represent a field element.
pub fn from_secret(s: SecretKey) -> CtOption<Scalar> {
// We can't unwrap() this, since it's not guaranteed that s represents a valid field elem
Self::from_bytes(s.secret_scalar().as_ref())
Self::from_bytes(s.as_bytes().as_ref())
}

/// Attempts to parse the given byte array as an SEC-1-encoded scalar.
Expand Down Expand Up @@ -680,7 +680,7 @@ impl Invert for Scalar {
}
}

impl From<Scalar> for ScalarBytes {
impl From<Scalar> for ElementBytes {
fn from(scalar: Scalar) -> Self {
scalar.to_bytes().into()
}
Expand Down
6 changes: 3 additions & 3 deletions p256/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::borrow::Borrow;

#[cfg(feature = "ecdsa")]
use {
crate::{AffinePoint, ProjectivePoint, Scalar, ScalarBytes},
crate::{AffinePoint, ElementBytes, ProjectivePoint, Scalar},
ecdsa_core::{
hazmat::{SignPrimitive, VerifyPrimitive},
Error,
Expand Down Expand Up @@ -38,7 +38,7 @@ impl SignPrimitive<NistP256> for Scalar {
fn try_sign_prehashed<K>(
&self,
ephemeral_scalar: &K,
hashed_msg: &ScalarBytes,
hashed_msg: &ElementBytes,
) -> Result<Signature, Error>
where
K: Borrow<Scalar> + Invert<Output = Scalar>,
Expand Down Expand Up @@ -77,7 +77,7 @@ impl SignPrimitive<NistP256> for Scalar {
impl VerifyPrimitive<NistP256> for AffinePoint {
fn verify_prehashed(
&self,
hashed_msg: &ScalarBytes,
hashed_msg: &ElementBytes,
signature: &Signature,
) -> Result<(), Error> {
let maybe_r =
Expand Down
2 changes: 1 addition & 1 deletion p256/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub type PublicKey = elliptic_curve::weierstrass::PublicKey<NistP256>;
/// NIST P-256 Scalar Bytes.
///
/// Byte array containing a serialized scalar value (i.e. an integer)
pub type ScalarBytes = elliptic_curve::ScalarBytes<NistP256>;
pub type ElementBytes = elliptic_curve::ElementBytes<NistP256>;

/// NIST P-256 Compressed Curve Point
pub type CompressedPoint = elliptic_curve::weierstrass::CompressedPoint<NistP256>;
Expand Down
2 changes: 1 addition & 1 deletion p384/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub type PublicKey = elliptic_curve::weierstrass::PublicKey<NistP384>;
/// NIST P-384 Scalar Bytes.
///
/// Byte array containing a serialized scalar value (i.e. an integer)
pub type ScalarBytes = elliptic_curve::ScalarBytes<NistP384>;
pub type ElementBytes = elliptic_curve::ElementBytes<NistP384>;

/// NIST P-384 Compressed Curve Point
pub type CompressedPoint = elliptic_curve::weierstrass::CompressedPoint<NistP384>;
Expand Down

0 comments on commit 5b37cc0

Please sign in to comment.