fix for ecmul scalar factors

This commit is contained in:
cdetrio
2017-09-07 10:58:43 +02:00
parent 3734552cf3
commit 7002225d76
2 changed files with 11 additions and 1 deletions
+10
View File
@@ -69,6 +69,16 @@ macro_rules! field_impl {
}
}
/// Converts a U256 to an Fr regardless of modulus.
pub fn new_mul_factor(mut a: U256) -> Option<Self> {
if true {
a.mul(&U256($rsquared), &U256($modulus), $inv);
Some($name(a))
} else {
None
}
}
pub fn interpret(buf: &[u8; 64]) -> Self {
$name::new(U512::interpret(buf).divrem(&U256($modulus)).1).unwrap()
}
+1 -1
View File
@@ -30,7 +30,7 @@ impl Fr {
pub fn from_slice(slice: &[u8]) -> Result<Self, FieldError> {
arith::U256::from_slice(slice)
.map_err(|_| FieldError::InvalidSliceLength) // todo: maybe more sensful error handling
.and_then(|x| fields::Fr::new(x).ok_or(FieldError::NotMember))
.and_then(|x| fields::Fr::new_mul_factor(x).ok_or(FieldError::NotMember))
.map(|x| Fr(x))
}
pub fn to_big_endian(&self, slice: &mut [u8]) -> Result<(), FieldError> {