mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-07 20:50:39 +00:00
Revert "Merge pull request #296 from isislovecruft/feature/compressed-try-from"
This reverts commit46f56f91ee, reversing changes made toa9b1d50c5a. These changes are not semver-compatible with the 2.0.0 release.
This commit is contained in:
parent
46f56f91ee
commit
6a44f31702
3 changed files with 8 additions and 60 deletions
|
|
@ -338,20 +338,15 @@ impl Default for CompressedEdwardsY {
|
||||||
impl CompressedEdwardsY {
|
impl CompressedEdwardsY {
|
||||||
/// Construct a `CompressedEdwardsY` from a slice of bytes.
|
/// Construct a `CompressedEdwardsY` from a slice of bytes.
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// An `Option<CompressedEdwardsY>` which is `None` if the input `bytes`
|
/// If the input `bytes` slice does not have a length of 32.
|
||||||
/// slice does not have a length of 32.
|
pub fn from_slice(bytes: &[u8]) -> CompressedEdwardsY {
|
||||||
pub fn from_slice(bytes: &[u8]) -> Option<CompressedEdwardsY> {
|
|
||||||
if bytes.len() != 32 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut tmp = [0u8; 32];
|
let mut tmp = [0u8; 32];
|
||||||
|
|
||||||
tmp.copy_from_slice(bytes);
|
tmp.copy_from_slice(bytes);
|
||||||
|
|
||||||
Some(CompressedEdwardsY(tmp))
|
CompressedEdwardsY(tmp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,6 @@ use field::FieldElement;
|
||||||
use scalar::Scalar;
|
use scalar::Scalar;
|
||||||
|
|
||||||
use traits::Identity;
|
use traits::Identity;
|
||||||
use traits::ValidityCheck;
|
|
||||||
|
|
||||||
use subtle::Choice;
|
use subtle::Choice;
|
||||||
use subtle::ConditionallySelectable;
|
use subtle::ConditionallySelectable;
|
||||||
|
|
@ -94,24 +93,6 @@ impl PartialEq for MontgomeryPoint {
|
||||||
|
|
||||||
impl Eq for MontgomeryPoint {}
|
impl Eq for MontgomeryPoint {}
|
||||||
|
|
||||||
impl ValidityCheck for MontgomeryPoint {
|
|
||||||
/// Decode the \\(u\\)-coordinate field element and re-encode it
|
|
||||||
/// to its canonical form to check whether the original was valid.
|
|
||||||
///
|
|
||||||
/// There are no other required checks for the Mongomery form of the curve,
|
|
||||||
/// as every element in \\( \mathbb{F}\_{q} \\) lies either on the curve or
|
|
||||||
/// its quadratic twist. (cf. §5.2 of "Montgomery Curves and Their
|
|
||||||
/// Arithmetic" by [Costello and Smith][costello-smith].)
|
|
||||||
///
|
|
||||||
/// [costello-smith]: https://eprint.iacr.org/2017/212.pdf
|
|
||||||
fn is_valid(&self) -> bool {
|
|
||||||
let maybe_u: FieldElement = FieldElement::from_bytes(&self.0);
|
|
||||||
let u: [u8; 32] = maybe_u.to_bytes();
|
|
||||||
|
|
||||||
u.ct_eq(&self.0).into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Zeroize for MontgomeryPoint {
|
impl Zeroize for MontgomeryPoint {
|
||||||
fn zeroize(&mut self) {
|
fn zeroize(&mut self) {
|
||||||
self.0.zeroize();
|
self.0.zeroize();
|
||||||
|
|
@ -129,29 +110,6 @@ impl MontgomeryPoint {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempt to create a `MontgomeryPoint` from a slice of bytes.
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// An `Option<MontgomeryPoint>` which is `None` if the length of the slice
|
|
||||||
/// of bytes is not 32, or if the bytes did not represent a canonical
|
|
||||||
/// `FieldElement`.
|
|
||||||
pub fn from_slice(bytes: &[u8]) -> Option<MontgomeryPoint> {
|
|
||||||
if bytes.len() != 32 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut array = [0u8; 32];
|
|
||||||
array.copy_from_slice(&bytes[..32]);
|
|
||||||
|
|
||||||
let P = MontgomeryPoint(array);
|
|
||||||
|
|
||||||
if P.is_valid() {
|
|
||||||
return Some(P);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Attempt to convert to an `EdwardsPoint`, using the supplied
|
/// Attempt to convert to an `EdwardsPoint`, using the supplied
|
||||||
/// choice of sign for the `EdwardsPoint`.
|
/// choice of sign for the `EdwardsPoint`.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -230,20 +230,15 @@ impl CompressedRistretto {
|
||||||
|
|
||||||
/// Construct a `CompressedRistretto` from a slice of bytes.
|
/// Construct a `CompressedRistretto` from a slice of bytes.
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// An `Option<CompressedRistretto>` which is `None` if the input `bytes`
|
/// If the input `bytes` slice does not have a length of 32.
|
||||||
/// slice does not have a length of 32.
|
pub fn from_slice(bytes: &[u8]) -> CompressedRistretto {
|
||||||
pub fn from_slice(bytes: &[u8]) -> Option<CompressedRistretto> {
|
|
||||||
if bytes.len() != 32 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut tmp = [0u8; 32];
|
let mut tmp = [0u8; 32];
|
||||||
|
|
||||||
tmp.copy_from_slice(bytes);
|
tmp.copy_from_slice(bytes);
|
||||||
|
|
||||||
Some(CompressedRistretto(tmp))
|
CompressedRistretto(tmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempt to decompress to an `RistrettoPoint`.
|
/// Attempt to decompress to an `RistrettoPoint`.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue