Skip to content

Commit

Permalink
elliptic-curve: fix remaining FieldBytesSize handling (#1296)
Browse files Browse the repository at this point in the history
Fixes the two remaining usages of `C::Uint::BYTES` to use
`C::FieldBytesSize::USIZE` instead.

These usages were:

- `NonZeroScalar::from_slice`
- `ScalarPrimitive::from_slice`
  • Loading branch information
tarcieri authored Apr 9, 2023
1 parent 09dacdf commit 383438d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions elliptic-curve/src/scalar/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use core::{
};
use crypto_bigint::{ArrayEncoding, Integer};
use ff::{Field, PrimeField};
use generic_array::GenericArray;
use generic_array::{typenum::Unsigned, GenericArray};
use rand_core::CryptoRngCore;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
use zeroize::Zeroize;
Expand Down Expand Up @@ -285,7 +285,7 @@ where
type Error = Error;

fn try_from(bytes: &[u8]) -> Result<Self, Error> {
if bytes.len() == C::Uint::BYTES {
if bytes.len() == C::FieldBytesSize::USIZE {
Option::from(NonZeroScalar::from_repr(GenericArray::clone_from_slice(
bytes,
)))
Expand Down
4 changes: 2 additions & 2 deletions elliptic-curve/src/scalar/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use core::{
ops::{Add, AddAssign, Neg, ShrAssign, Sub, SubAssign},
str,
};
use generic_array::GenericArray;
use generic_array::{typenum::Unsigned, GenericArray};
use rand_core::CryptoRngCore;
use subtle::{
Choice, ConditionallySelectable, ConstantTimeEq, ConstantTimeGreater, ConstantTimeLess,
Expand Down Expand Up @@ -83,7 +83,7 @@ where

/// Decode [`ScalarPrimitive`] from a big endian byte slice.
pub fn from_slice(slice: &[u8]) -> Result<Self> {
if slice.len() == C::Uint::BYTES {
if slice.len() == C::FieldBytesSize::USIZE {
Option::from(Self::from_bytes(GenericArray::from_slice(slice))).ok_or(Error)
} else {
Err(Error)
Expand Down

0 comments on commit 383438d

Please sign in to comment.