From 8b8ba22c1f1f7c69763b048874c9e1f559571b2e Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Fri, 16 Apr 2021 20:05:41 +0100 Subject: [PATCH] Add support for 448-bit integers and fields. (#261) These are needed for the Pluto and Eris curves (https://github.com/daira/pluto-eris). Signed-off-by: Daira Hopwood Co-authored-by: Weikeng Chen --- ff/src/biginteger/mod.rs | 1 + ff/src/biginteger/tests.rs | 6 ++++++ ff/src/fields/mod.rs | 4 +++- ff/src/fields/models/mod.rs | 3 ++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ff/src/biginteger/mod.rs b/ff/src/biginteger/mod.rs index 0ce935da3..e88baf355 100644 --- a/ff/src/biginteger/mod.rs +++ b/ff/src/biginteger/mod.rs @@ -34,6 +34,7 @@ bigint_impl!(BigInteger128, 2); bigint_impl!(BigInteger256, 4); bigint_impl!(BigInteger320, 5); bigint_impl!(BigInteger384, 6); +bigint_impl!(BigInteger448, 7); bigint_impl!(BigInteger768, 12); bigint_impl!(BigInteger832, 13); diff --git a/ff/src/biginteger/tests.rs b/ff/src/biginteger/tests.rs index ad46fe5ad..0602b4e86 100644 --- a/ff/src/biginteger/tests.rs +++ b/ff/src/biginteger/tests.rs @@ -89,6 +89,12 @@ fn test_biginteger384() { test_biginteger(B::new([0u64; 6])); } +#[test] +fn test_biginteger448() { + use crate::biginteger::BigInteger448 as B; + test_biginteger(B::new([0u64; 7])); +} + #[test] fn test_biginteger768() { use crate::biginteger::BigInteger768 as B; diff --git a/ff/src/fields/mod.rs b/ff/src/fields/mod.rs index 678962868..e5c27a2c9 100644 --- a/ff/src/fields/mod.rs +++ b/ff/src/fields/mod.rs @@ -545,13 +545,15 @@ impl> Iterator for BitIteratorLE { } use crate::biginteger::{ - BigInteger256, BigInteger320, BigInteger384, BigInteger64, BigInteger768, BigInteger832, + BigInteger256, BigInteger320, BigInteger384, BigInteger448, BigInteger64, BigInteger768, + BigInteger832, }; impl_field_bigint_conv!(Fp64, BigInteger64, Fp64Parameters); impl_field_bigint_conv!(Fp256, BigInteger256, Fp256Parameters); impl_field_bigint_conv!(Fp320, BigInteger320, Fp320Parameters); impl_field_bigint_conv!(Fp384, BigInteger384, Fp384Parameters); +impl_field_bigint_conv!(Fp448, BigInteger448, Fp448Parameters); impl_field_bigint_conv!(Fp768, BigInteger768, Fp768Parameters); impl_field_bigint_conv!(Fp832, BigInteger832, Fp832Parameters); diff --git a/ff/src/fields/models/mod.rs b/ff/src/fields/models/mod.rs index 21314c597..17f5c858f 100644 --- a/ff/src/fields/models/mod.rs +++ b/ff/src/fields/models/mod.rs @@ -11,7 +11,7 @@ use num_traits::{One, Zero}; use crate::{ biginteger::{ arithmetic as fa, BigInteger as _BigInteger, BigInteger256, BigInteger320, BigInteger384, - BigInteger64, BigInteger768, BigInteger832, + BigInteger448, BigInteger64, BigInteger768, BigInteger832, }, bytes::{FromBytes, ToBytes}, fields::{FftField, Field, FpParameters, LegendreSymbol, PrimeField, SquareRootField}, @@ -22,6 +22,7 @@ impl_Fp!(Fp64, Fp64Parameters, BigInteger64, BigInteger64, 1); impl_Fp!(Fp256, Fp256Parameters, BigInteger256, BigInteger256, 4); impl_Fp!(Fp320, Fp320Parameters, BigInteger320, BigInteger320, 5); impl_Fp!(Fp384, Fp384Parameters, BigInteger384, BigInteger384, 6); +impl_Fp!(Fp448, Fp448Parameters, BigInteger448, BigInteger448, 7); impl_Fp!(Fp768, Fp768Parameters, BigInteger768, BigInteger768, 12); impl_Fp!(Fp832, Fp832Parameters, BigInteger832, BigInteger832, 13);