Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elliptic-curve: replace hex module with base16ct #888

Merged
merged 1 commit into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions elliptic-curve/src/hex.rs

This file was deleted.

1 change: 0 additions & 1 deletion elliptic-curve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ pub mod ops;
pub mod sec1;

mod error;
mod hex;
mod point;
mod scalar;
mod secret_key;
Expand Down
3 changes: 1 addition & 2 deletions elliptic-curve/src/scalar/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use crate::{
bigint::{prelude::*, Limb, NonZero},
hex,
rand_core::{CryptoRng, RngCore},
subtle::{
Choice, ConditionallySelectable, ConstantTimeEq, ConstantTimeGreater, ConstantTimeLess,
Expand Down Expand Up @@ -398,7 +397,7 @@ where

fn from_str(hex: &str) -> Result<Self> {
let mut bytes = FieldBytes::<C>::default();
hex::decode(hex, &mut bytes)?;
base16ct::lower::decode(hex, &mut bytes)?;
Option::from(Self::from_be_bytes(bytes)).ok_or(Error)
}
}
Expand Down
9 changes: 6 additions & 3 deletions elliptic-curve/src/scalar/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use crate::{
bigint::Encoding as _,
hex,
ops::{Invert, Reduce, ReduceNonZero},
rand_core::{CryptoRng, RngCore},
Curve, Error, FieldBytes, IsHigh, PrimeCurve, Result, Scalar, ScalarArithmetic, ScalarCore,
Expand Down Expand Up @@ -320,8 +319,12 @@ where

fn from_str(hex: &str) -> Result<Self> {
let mut bytes = FieldBytes::<C>::default();
hex::decode(hex, &mut bytes)?;
Option::from(Self::from_repr(bytes)).ok_or(Error)

if base16ct::mixed::decode(hex, &mut bytes)?.len() == bytes.len() {
Option::from(Self::from_repr(bytes)).ok_or(Error)
} else {
Err(Error)
}
}
}

Expand Down