mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-07-30 20:11:23 +00:00
ff: Remove PrimeFieldRepr trait
The ff::PrimeField::Repr associated type now has the minimal necessary bounds, which can be satisfied by a newtype around a byte array.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// Catch documentation errors caused by code changes.
|
||||
#![deny(intra_doc_link_resolution_failure)]
|
||||
|
||||
use ff::{PrimeField, PrimeFieldDecodingError, ScalarEngine, SqrtField};
|
||||
use ff::{PrimeField, ScalarEngine, SqrtField};
|
||||
use rand::RngCore;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
@@ -82,7 +82,7 @@ pub trait CurveProjective:
|
||||
|
||||
/// Recommends a wNAF window table size given a scalar. Always returns a number
|
||||
/// between 2 and 22, inclusive.
|
||||
fn recommended_wnaf_for_scalar(scalar: &<Self::Scalar as PrimeField>::Repr) -> usize;
|
||||
fn recommended_wnaf_for_scalar(scalar: &Self::Scalar) -> usize;
|
||||
|
||||
/// Recommends a wNAF window size given the number of scalars you intend to multiply
|
||||
/// a base by. Always returns a number between 2 and 22, inclusive.
|
||||
@@ -178,7 +178,7 @@ pub enum GroupDecodingError {
|
||||
/// The element is not part of the r-order subgroup.
|
||||
NotInSubgroup,
|
||||
/// One of the coordinates could not be decoded
|
||||
CoordinateDecodingError(&'static str, PrimeFieldDecodingError),
|
||||
CoordinateDecodingError(&'static str),
|
||||
/// The compression mode of the encoded element was not as expected
|
||||
UnexpectedCompressionMode,
|
||||
/// The encoding contained bits that should not have been set
|
||||
@@ -202,8 +202,8 @@ impl Error for GroupDecodingError {
|
||||
impl fmt::Display for GroupDecodingError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
GroupDecodingError::CoordinateDecodingError(description, ref err) => {
|
||||
write!(f, "{} decoding error: {}", description, err)
|
||||
GroupDecodingError::CoordinateDecodingError(description) => {
|
||||
write!(f, "{} decoding error", description)
|
||||
}
|
||||
_ => write!(f, "{}", self.description()),
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use ff::PrimeField;
|
||||
use std::iter;
|
||||
|
||||
@@ -19,7 +20,7 @@ pub(crate) fn wnaf_table<G: CurveProjective>(table: &mut Vec<G>, mut base: G, wi
|
||||
|
||||
/// Replaces the contents of `wnaf` with the w-NAF representation of a little-endian
|
||||
/// scalar.
|
||||
pub(crate) fn wnaf_form<S: AsRef<[u64]>>(wnaf: &mut Vec<i64>, c: S, window: usize) {
|
||||
pub(crate) fn wnaf_form<S: AsRef<[u8]>>(wnaf: &mut Vec<i64>, c: S, window: usize) {
|
||||
// Required by the NAF definition
|
||||
debug_assert!(window >= 2);
|
||||
// Required so that the NAF digits fit in i64
|
||||
@@ -27,11 +28,11 @@ pub(crate) fn wnaf_form<S: AsRef<[u64]>>(wnaf: &mut Vec<i64>, c: S, window: usiz
|
||||
|
||||
wnaf.truncate(0);
|
||||
|
||||
let u64_len = c.as_ref().len();
|
||||
let bit_len = u64_len * 64;
|
||||
let bit_len = c.as_ref().len() * 8;
|
||||
let u64_len = (bit_len + 1) / 64;
|
||||
|
||||
let mut c_u64 = vec![0u64; u64_len + 1];
|
||||
c_u64[0..u64_len].copy_from_slice(c.as_ref());
|
||||
LittleEndian::read_u64_into(c.as_ref(), &mut c_u64[0..u64_len]);
|
||||
|
||||
let width = 1u64 << window;
|
||||
let window_mask = width - 1;
|
||||
@@ -144,13 +145,11 @@ impl<G: CurveProjective> Wnaf<(), Vec<G>, Vec<i64>> {
|
||||
&mut self,
|
||||
scalar: &<G as CurveProjective>::Scalar,
|
||||
) -> Wnaf<usize, &mut Vec<G>, &[i64]> {
|
||||
let scalar = scalar.into_repr();
|
||||
|
||||
// Compute the appropriate window size for the scalar.
|
||||
let window_size = G::recommended_wnaf_for_scalar(&scalar);
|
||||
|
||||
// Compute the wNAF form of the scalar.
|
||||
wnaf_form(&mut self.scalar, scalar, window_size);
|
||||
wnaf_form(&mut self.scalar, scalar.into_repr(), window_size);
|
||||
|
||||
// Return a Wnaf object that mutably borrows the base storage location, but
|
||||
// immutably borrows the computed wNAF form scalar location.
|
||||
|
Reference in New Issue
Block a user