mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-06 20:41:14 +00:00
Expand const fn support (#494)
Does a pass on adding `const` to methods where it's possible.
This commit is contained in:
parent
6a51f4fa40
commit
8c2f545d91
4 changed files with 12 additions and 11 deletions
|
|
@ -176,12 +176,12 @@ impl Debug for CompressedEdwardsY {
|
||||||
|
|
||||||
impl CompressedEdwardsY {
|
impl CompressedEdwardsY {
|
||||||
/// View this `CompressedEdwardsY` as an array of bytes.
|
/// View this `CompressedEdwardsY` as an array of bytes.
|
||||||
pub fn as_bytes(&self) -> &[u8; 32] {
|
pub const fn as_bytes(&self) -> &[u8; 32] {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copy this `CompressedEdwardsY` to an array of bytes.
|
/// Copy this `CompressedEdwardsY` to an array of bytes.
|
||||||
pub fn to_bytes(&self) -> [u8; 32] {
|
pub const fn to_bytes(&self) -> [u8; 32] {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -481,7 +481,7 @@ impl EdwardsPoint {
|
||||||
/// coordinates to projective coordinates.
|
/// coordinates to projective coordinates.
|
||||||
///
|
///
|
||||||
/// Free.
|
/// Free.
|
||||||
pub(crate) fn as_projective(&self) -> ProjectivePoint {
|
pub(crate) const fn as_projective(&self) -> ProjectivePoint {
|
||||||
ProjectivePoint {
|
ProjectivePoint {
|
||||||
X: self.X,
|
X: self.X,
|
||||||
Y: self.Y,
|
Y: self.Y,
|
||||||
|
|
|
||||||
|
|
@ -119,12 +119,12 @@ impl Zeroize for MontgomeryPoint {
|
||||||
|
|
||||||
impl MontgomeryPoint {
|
impl MontgomeryPoint {
|
||||||
/// View this `MontgomeryPoint` as an array of bytes.
|
/// View this `MontgomeryPoint` as an array of bytes.
|
||||||
pub fn as_bytes(&self) -> &[u8; 32] {
|
pub const fn as_bytes(&self) -> &[u8; 32] {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert this `MontgomeryPoint` to an array of bytes.
|
/// Convert this `MontgomeryPoint` to an array of bytes.
|
||||||
pub fn to_bytes(&self) -> [u8; 32] {
|
pub const fn to_bytes(&self) -> [u8; 32] {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -231,12 +231,12 @@ impl ConstantTimeEq for CompressedRistretto {
|
||||||
|
|
||||||
impl CompressedRistretto {
|
impl CompressedRistretto {
|
||||||
/// Copy the bytes of this `CompressedRistretto`.
|
/// Copy the bytes of this `CompressedRistretto`.
|
||||||
pub fn to_bytes(&self) -> [u8; 32] {
|
pub const fn to_bytes(&self) -> [u8; 32] {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// View this `CompressedRistretto` as an array of bytes.
|
/// View this `CompressedRistretto` as an array of bytes.
|
||||||
pub fn as_bytes(&self) -> &[u8; 32] {
|
pub const fn as_bytes(&self) -> &[u8; 32] {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -226,8 +226,9 @@ pub struct Scalar {
|
||||||
///
|
///
|
||||||
/// This ensures that there is room for a carry bit when computing a NAF representation.
|
/// This ensures that there is room for a carry bit when computing a NAF representation.
|
||||||
//
|
//
|
||||||
// XXX This is pub(crate) so we can write literal constants. If const fns were stable, we could
|
// XXX This is pub(crate) so we can write literal constants.
|
||||||
// make the Scalar constructors const fns and use those instead.
|
// Alternatively we could make the Scalar constructors `const fn`s and use those instead.
|
||||||
|
// See dalek-cryptography/curve25519-dalek#493
|
||||||
pub(crate) bytes: [u8; 32],
|
pub(crate) bytes: [u8; 32],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -688,7 +689,7 @@ impl Scalar {
|
||||||
///
|
///
|
||||||
/// assert!(s.to_bytes() == [0u8; 32]);
|
/// assert!(s.to_bytes() == [0u8; 32]);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn to_bytes(&self) -> [u8; 32] {
|
pub const fn to_bytes(&self) -> [u8; 32] {
|
||||||
self.bytes
|
self.bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -703,7 +704,7 @@ impl Scalar {
|
||||||
///
|
///
|
||||||
/// assert!(s.as_bytes() == &[0u8; 32]);
|
/// assert!(s.as_bytes() == &[0u8; 32]);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn as_bytes(&self) -> &[u8; 32] {
|
pub const fn as_bytes(&self) -> &[u8; 32] {
|
||||||
&self.bytes
|
&self.bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue