mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-22 19:49:22 +00:00
Slightly clean FROST's dalek support
This commit is contained in:
parent
32473d9976
commit
06e37623d0
1 changed files with 14 additions and 18 deletions
|
@ -81,7 +81,7 @@ macro_rules! dalek_curve {
|
||||||
let scalar = Self::F::from_repr(
|
let scalar = Self::F::from_repr(
|
||||||
slice.try_into().map_err(|_| CurveError::InvalidLength(32, slice.len()))?
|
slice.try_into().map_err(|_| CurveError::InvalidLength(32, slice.len()))?
|
||||||
);
|
);
|
||||||
if scalar.is_some().unwrap_u8() == 0 {
|
if !bool::from(scalar.is_some()) {
|
||||||
Err(CurveError::InvalidScalar)?;
|
Err(CurveError::InvalidScalar)?;
|
||||||
}
|
}
|
||||||
Ok(scalar.unwrap())
|
Ok(scalar.unwrap())
|
||||||
|
@ -89,25 +89,21 @@ macro_rules! dalek_curve {
|
||||||
|
|
||||||
fn G_from_slice(slice: &[u8]) -> Result<Self::G, CurveError> {
|
fn G_from_slice(slice: &[u8]) -> Result<Self::G, CurveError> {
|
||||||
let bytes = slice.try_into().map_err(|_| CurveError::InvalidLength(32, slice.len()))?;
|
let bytes = slice.try_into().map_err(|_| CurveError::InvalidLength(32, slice.len()))?;
|
||||||
let point = $Compressed::new(bytes).decompress();
|
let point = $Compressed::new(bytes).decompress().ok_or(CurveError::InvalidPoint)?;
|
||||||
|
|
||||||
if let Some(point) = point {
|
// Ban identity
|
||||||
// Ban identity
|
if point.is_identity().into() {
|
||||||
if point.is_identity().into() {
|
Err(CurveError::InvalidPoint)?;
|
||||||
Err(CurveError::InvalidPoint)?;
|
|
||||||
}
|
|
||||||
// Ban torsioned points to meet the prime order group requirement
|
|
||||||
if $torsioned(point) {
|
|
||||||
Err(CurveError::InvalidPoint)?;
|
|
||||||
}
|
|
||||||
// Ban points which weren't canonically encoded
|
|
||||||
if point.compress().to_bytes() != bytes {
|
|
||||||
Err(CurveError::InvalidPoint)?;
|
|
||||||
}
|
|
||||||
Ok(point)
|
|
||||||
} else {
|
|
||||||
Err(CurveError::InvalidPoint)
|
|
||||||
}
|
}
|
||||||
|
// Ban torsioned points to meet the prime order group requirement
|
||||||
|
if $torsioned(point) {
|
||||||
|
Err(CurveError::InvalidPoint)?;
|
||||||
|
}
|
||||||
|
// Ban points which weren't canonically encoded
|
||||||
|
if point.compress().to_bytes() != bytes {
|
||||||
|
Err(CurveError::InvalidPoint)?;
|
||||||
|
}
|
||||||
|
Ok(point)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn F_to_bytes(f: &Self::F) -> Vec<u8> {
|
fn F_to_bytes(f: &Self::F) -> Vec<u8> {
|
||||||
|
|
Loading…
Reference in a new issue