Ensure divrem always returns remainder.

This commit is contained in:
Sean Bowe
2016-09-18 10:23:59 -06:00
parent 76344a7ae9
commit fbefb710cf
2 changed files with 50 additions and 23 deletions
+3 -3
View File
@@ -30,8 +30,8 @@ pub struct Fq2 {
impl Encodable for Fq2 {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
let c1: U256 = self.c1.into();
let c0: U256 = self.c0.into();
let c1: U256 = self.c1.into();
U512::from(&c1, &c0, &Fq::modulus()).encode(s)
}
@@ -42,10 +42,10 @@ impl Decodable for Fq2 {
let combined = try!(U512::decode(s));
match combined.divrem(&Fq::modulus()) {
Some((c1, c0)) => {
(Some(c1), c0) => {
Ok(Fq2::new(Fq::new(c0).unwrap(), Fq::new(c1).unwrap()))
},
None => {
_ => {
Err(s.error("integer not less than modulus squared"))
}
}