pub struct NistP256;
Expand description
NIST P-256 elliptic curve.
This curve is also known as prime256v1 (ANSI X9.62) and secp256r1 (SECG) and is specified in FIPS 186-4: Digital Signature Standard (DSS):
https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
It’s included in the US National Security Agency’s “Suite B” and is widely used in protocols like TLS and the associated X.509 PKI.
Its equation is y² = x³ - 3x + b
over a ~256-bit prime field where b
is
the “verifiably random”† constant:
b = 41058363725152142129326129780047268409114441015993725554835256314039467401291
† NOTE: the specific origins of this constant have never been fully disclosed (it is the SHA-1 digest of an inexplicable NSA-selected constant)
Trait Implementations
sourceimpl AffineArithmetic for NistP256
impl AffineArithmetic for NistP256
type AffinePoint = AffinePoint
type AffinePoint = AffinePoint
Elliptic curve point in affine coordinates.
sourceimpl AffineXCoordinate<NistP256> for AffinePoint
impl AffineXCoordinate<NistP256> for AffinePoint
sourcefn x(&self) -> FieldBytes
fn x(&self) -> FieldBytes
Get the affine x-coordinate as a serialized field element.
sourceimpl AssociatedOid for NistP256
impl AssociatedOid for NistP256
sourceconst OID: ObjectIdentifier = pkcs8::ObjectIdentifier::new_unwrap("1.2.840.10045.3.1.7")
const OID: ObjectIdentifier = pkcs8::ObjectIdentifier::new_unwrap("1.2.840.10045.3.1.7")
The OID associated with this type.
sourceimpl Curve for NistP256
impl Curve for NistP256
type UInt = UInt<{_: usize}>
type UInt = UInt<{_: usize}>
256-bit integer type used for internally representing field elements.
sourceconst ORDER: U256 = U256::from_be_hex("ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551")
const ORDER: U256 = U256::from_be_hex("ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551")
Order of NIST P-256’s elliptic curve group (i.e. scalar modulus).
n = FFFFFFFF 00000000 FFFFFFFF FFFFFFFF BCE6FAAD A7179E84 F3B9CAC2 FC632551
Calculating the order
One way to calculate the order is with GP/PARI
:
p = (2^224) * (2^32 - 1) + 2^192 + 2^96 - 1
b = 41058363725152142129326129780047268409114441015993725554835256314039467401291
E = ellinit([Mod(-3, p), Mod(b, p)])
default(parisize, 120000000)
n = ellsea(E)
isprime(n)
sourceimpl DecompactPoint<NistP256> for AffinePoint
impl DecompactPoint<NistP256> for AffinePoint
sourcefn decompact(x_bytes: &FieldBytes) -> CtOption<Self>
fn decompact(x_bytes: &FieldBytes) -> CtOption<Self>
Attempt to decompact an elliptic curve point
sourceimpl DecompressPoint<NistP256> for AffinePoint
impl DecompressPoint<NistP256> for AffinePoint
sourcefn decompress(x_bytes: &FieldBytes, y_is_odd: Choice) -> CtOption<Self>
fn decompress(x_bytes: &FieldBytes, y_is_odd: Choice) -> CtOption<Self>
Attempt to decompress an elliptic curve point.
sourceimpl DigestPrimitive for NistP256
Available on crate features ecdsa-core
and sha256
only.
impl DigestPrimitive for NistP256
ecdsa-core
and sha256
only.sourceimpl FromEncodedPoint<NistP256> for AffinePoint
impl FromEncodedPoint<NistP256> for AffinePoint
sourcefn from_encoded_point(encoded_point: &EncodedPoint) -> CtOption<Self>
fn from_encoded_point(encoded_point: &EncodedPoint) -> CtOption<Self>
Attempts to parse the given EncodedPoint
as an SEC1-encoded AffinePoint
.
Returns
None
value if encoded_point
is not on the secp256r1 curve.
sourceimpl FromEncodedPoint<NistP256> for ProjectivePoint
impl FromEncodedPoint<NistP256> for ProjectivePoint
sourcefn from_encoded_point(p: &EncodedPoint) -> CtOption<Self>
fn from_encoded_point(p: &EncodedPoint) -> CtOption<Self>
Deserialize the type this trait is impl’d on from an EncodedPoint
.
sourceimpl GroupDigest for NistP256
impl GroupDigest for NistP256
type FieldElement = FieldElement
type FieldElement = FieldElement
The field element representation for a group value with multiple elements
sourcefn hash_from_bytes<'a, X>(
msgs: &[&[u8]],
dst: &'a [u8]
) -> Result<Self::ProjectivePoint, Error> where
X: ExpandMsg<'a>,
fn hash_from_bytes<'a, X>(
msgs: &[&[u8]],
dst: &'a [u8]
) -> Result<Self::ProjectivePoint, Error> where
X: ExpandMsg<'a>,
Computes the hash to curve routine. Read more
sourcefn encode_from_bytes<'a, X>(
msgs: &[&[u8]],
dst: &'a [u8]
) -> Result<Self::ProjectivePoint, Error> where
X: ExpandMsg<'a>,
fn encode_from_bytes<'a, X>(
msgs: &[&[u8]],
dst: &'a [u8]
) -> Result<Self::ProjectivePoint, Error> where
X: ExpandMsg<'a>,
Computes the encode to curve routine. Read more
sourcefn hash_to_scalar<'a, X>(
msgs: &[&[u8]],
dst: &'a [u8]
) -> Result<Self::Scalar, Error> where
X: ExpandMsg<'a>,
Self::Scalar: FromOkm,
fn hash_to_scalar<'a, X>(
msgs: &[&[u8]],
dst: &'a [u8]
) -> Result<Self::Scalar, Error> where
X: ExpandMsg<'a>,
Self::Scalar: FromOkm,
Computes the hash to field routine according to https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-13.html#section-5 and returns a scalar. Read more
sourceimpl JwkParameters for NistP256
Available on crate feature jwk
only.
impl JwkParameters for NistP256
jwk
only.sourceconst CRV: &'static str = "P-256"
const CRV: &'static str = "P-256"
The crv
parameter which identifies a particular elliptic curve
as defined in RFC 7518 Section 6.2.1.1:
https://tools.ietf.org/html/rfc7518#section-6.2.1.1 Read more
sourceimpl Ord for NistP256
impl Ord for NistP256
sourceimpl PartialOrd<NistP256> for NistP256
impl PartialOrd<NistP256> for NistP256
sourcefn partial_cmp(&self, other: &NistP256) -> Option<Ordering>
fn partial_cmp(&self, other: &NistP256) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PointCompaction for NistP256
impl PointCompaction for NistP256
sourceconst COMPACT_POINTS: bool = false
const COMPACT_POINTS: bool = false
NIST P-256 points are typically uncompressed.
sourceimpl PointCompression for NistP256
impl PointCompression for NistP256
sourceconst COMPRESS_POINTS: bool = false
const COMPRESS_POINTS: bool = false
NIST P-256 points are typically uncompressed.
sourceimpl PrimeCurveArithmetic for NistP256
impl PrimeCurveArithmetic for NistP256
type CurveGroup = ProjectivePoint
type CurveGroup = ProjectivePoint
Prime order elliptic curve group.
sourceimpl ProjectiveArithmetic for NistP256
impl ProjectiveArithmetic for NistP256
type ProjectivePoint = ProjectivePoint
type ProjectivePoint = ProjectivePoint
Elliptic curve point in projective coordinates. Read more
sourceimpl SignPrimitive<NistP256> for Scalar
Available on crate feature ecdsa-core
only.
impl SignPrimitive<NistP256> for Scalar
ecdsa-core
only.sourcefn try_sign_prehashed<K>(
&self,
k: K,
z: GenericArray<u8, <<C as Curve>::UInt as ArrayEncoding>::ByteSize>
) -> Result<(Signature<C>, Option<RecoveryId>), Error> where
K: Borrow<Self> + Invert<Output = CtOption<Self>>,
fn try_sign_prehashed<K>(
&self,
k: K,
z: GenericArray<u8, <<C as Curve>::UInt as ArrayEncoding>::ByteSize>
) -> Result<(Signature<C>, Option<RecoveryId>), Error> where
K: Borrow<Self> + Invert<Output = CtOption<Self>>,
Try to sign the prehashed message. Read more
sourcefn try_sign_prehashed_rfc6979<D>(
&self,
z: GenericArray<u8, <<C as Curve>::UInt as ArrayEncoding>::ByteSize>,
ad: &[u8]
) -> Result<(Signature<C>, Option<RecoveryId>), Error> where
Self: From<ScalarCore<C>>,
D: CoreProxy + FixedOutput<OutputSize = <<C as Curve>::UInt as ArrayEncoding>::ByteSize>,
<C as Curve>::UInt: for<'a> From<&'a Self>,
<D as CoreProxy>::Core: BlockSizeUser,
<D as CoreProxy>::Core: BufferKindUser,
<D as CoreProxy>::Core: Clone,
<D as CoreProxy>::Core: Default,
<D as CoreProxy>::Core: FixedOutputCore,
<D as CoreProxy>::Core: HashMarker,
<D as CoreProxy>::Core: OutputSizeUser,
<<D as CoreProxy>::Core as BlockSizeUser>::BlockSize: IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>,
<<<D as CoreProxy>::Core as BlockSizeUser>::BlockSize as IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>>::Output: NonZero,
<<D as CoreProxy>::Core as BufferKindUser>::BufferKind == Eager,
<<D as CoreProxy>::Core as OutputSizeUser>::OutputSize == <D as OutputSizeUser>::OutputSize,
fn try_sign_prehashed_rfc6979<D>(
&self,
z: GenericArray<u8, <<C as Curve>::UInt as ArrayEncoding>::ByteSize>,
ad: &[u8]
) -> Result<(Signature<C>, Option<RecoveryId>), Error> where
Self: From<ScalarCore<C>>,
D: CoreProxy + FixedOutput<OutputSize = <<C as Curve>::UInt as ArrayEncoding>::ByteSize>,
<C as Curve>::UInt: for<'a> From<&'a Self>,
<D as CoreProxy>::Core: BlockSizeUser,
<D as CoreProxy>::Core: BufferKindUser,
<D as CoreProxy>::Core: Clone,
<D as CoreProxy>::Core: Default,
<D as CoreProxy>::Core: FixedOutputCore,
<D as CoreProxy>::Core: HashMarker,
<D as CoreProxy>::Core: OutputSizeUser,
<<D as CoreProxy>::Core as BlockSizeUser>::BlockSize: IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>,
<<<D as CoreProxy>::Core as BlockSizeUser>::BlockSize as IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>>::Output: NonZero,
<<D as CoreProxy>::Core as BufferKindUser>::BufferKind == Eager,
<<D as CoreProxy>::Core as OutputSizeUser>::OutputSize == <D as OutputSizeUser>::OutputSize,
sourceimpl ToCompactEncodedPoint<NistP256> for AffinePoint
impl ToCompactEncodedPoint<NistP256> for AffinePoint
sourcefn to_compact_encoded_point(&self) -> CtOption<EncodedPoint>
fn to_compact_encoded_point(&self) -> CtOption<EncodedPoint>
Serialize this value as a SEC1 compact EncodedPoint
sourceimpl ToEncodedPoint<NistP256> for AffinePoint
impl ToEncodedPoint<NistP256> for AffinePoint
sourcefn to_encoded_point(&self, compress: bool) -> EncodedPoint
fn to_encoded_point(&self, compress: bool) -> EncodedPoint
Serialize this value as a SEC1 EncodedPoint
, optionally applying
point compression. Read more
sourceimpl ToEncodedPoint<NistP256> for ProjectivePoint
impl ToEncodedPoint<NistP256> for ProjectivePoint
sourcefn to_encoded_point(&self, compress: bool) -> EncodedPoint
fn to_encoded_point(&self, compress: bool) -> EncodedPoint
Serialize this value as a SEC1 EncodedPoint
, optionally applying
point compression. Read more
sourceimpl VerifyPrimitive<NistP256> for AffinePoint
Available on crate feature ecdsa-core
only.
impl VerifyPrimitive<NistP256> for AffinePoint
ecdsa-core
only.sourceimpl VoprfParameters for NistP256
Available on crate feature voprf
only.
impl VoprfParameters for NistP256
voprf
only.impl Copy for NistP256
impl Eq for NistP256
impl PrimeCurve for NistP256
impl StructuralEq for NistP256
impl StructuralPartialEq for NistP256
Auto Trait Implementations
impl RefUnwindSafe for NistP256
impl Send for NistP256
impl Sync for NistP256
impl Unpin for NistP256
impl UnwindSafe for NistP256
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> FmtForward for T
impl<T> FmtForward for T
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Causes self
to use its Binary
implementation when Debug
-formatted. Read more
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Causes self
to use its Display
implementation when
Debug
-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Causes self
to use its LowerExp
implementation when
Debug
-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self
to use its LowerHex
implementation when
Debug
-formatted. Read more
fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
Causes self
to use its Octal
implementation when Debug
-formatted. Read more
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Causes self
to use its Pointer
implementation when
Debug
-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Causes self
to use its UpperExp
implementation when
Debug
-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self
to use its UpperHex
implementation when
Debug
-formatted. Read more
fn fmt_list(self) -> FmtList<Self> where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self> where
&'a Self: for<'a> IntoIterator,
Formats each item in a sequence. Read more
impl<T> Pipe for T where
T: ?Sized,
impl<T> Pipe for T where
T: ?Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
Pipes by value. This is generally the method you want to use. Read more
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
Borrows self
and passes that borrow into the pipe function. Read more
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
Mutably borrows self
and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.borrow()
into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.borrow_mut()
into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.as_ref()
into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.as_mut()
into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.deref()
into the pipe function.
impl<T> Tap for T
impl<T> Tap for T
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B>
of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B>
of a value. Read more
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Immutable access to the AsRef<R>
view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Mutable access to the AsMut<R>
view of a value. Read more
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
Immutable access to the Deref::Target
of a value. Read more
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Mutable access to the Deref::Target
of a value. Read more
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls .tap()
only in debug builds, and is erased in release builds.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more