mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
The prior workflow (now deleted) required manually specifying the packages to check and only checked the package could compile under the stated MSRV. It didn't verify it was actually the _minimum_ supported Rust version. The new version finds the MSRV from scratch to check if the stated MSRV aligns. Updates stated MSRVs accordingly. Also removes many explicit dependencies from secq256k1 for their re-exports via k256. Not directly relevant, just part of tidying up all the `toml`s.
54 lines
1.4 KiB
Rust
54 lines
1.4 KiB
Rust
use k256::elliptic_curve::{
|
|
zeroize::{DefaultIsZeroes, Zeroize},
|
|
bigint::{
|
|
U256, U512,
|
|
modular::constant_mod::{ResidueParams, Residue},
|
|
},
|
|
};
|
|
|
|
const MODULUS_STR: &str = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F";
|
|
|
|
impl_modulus!(SecQ, U256, MODULUS_STR);
|
|
type ResidueType = Residue<SecQ, { SecQ::LIMBS }>;
|
|
|
|
/// The Scalar field of secq256k1.
|
|
///
|
|
/// This is equivalent to the field secp256k1 is defined over.
|
|
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
|
|
#[repr(C)]
|
|
pub struct Scalar(pub(crate) ResidueType);
|
|
|
|
impl DefaultIsZeroes for Scalar {}
|
|
|
|
pub(crate) const MODULUS: U256 = U256::from_be_hex(MODULUS_STR);
|
|
|
|
const WIDE_MODULUS: U512 = U512::from_be_hex(concat!(
|
|
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F",
|
|
));
|
|
|
|
field!(
|
|
Scalar,
|
|
ResidueType,
|
|
MODULUS_STR,
|
|
MODULUS,
|
|
WIDE_MODULUS,
|
|
256,
|
|
3,
|
|
1,
|
|
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e",
|
|
"0000000000000000000000000000000000000000000000000000000000000009",
|
|
);
|
|
|
|
impl Scalar {
|
|
/// Perform a wide reduction, presumably to obtain a non-biased Scalar field element.
|
|
pub fn wide_reduce(bytes: [u8; 64]) -> Scalar {
|
|
Scalar(Residue::new(&reduce(U512::from_le_slice(bytes.as_ref()))))
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_scalar_field() {
|
|
ff_group_tests::prime_field::test_prime_field_bits::<_, Scalar>(&mut rand_core::OsRng);
|
|
}
|