Struct ecdsa::RecoveryId
source · pub struct RecoveryId(_);
Expand description
Recovery IDs, a.k.a. “recid”.
This is an integer value 0
, 1
, 2
, or 3
included along with a
signature which is used during the recovery process to select the correct
public key from the signature.
It consists of two bits of information:
- low bit (0/1): was the y-coordinate of the affine point resulting from the fixed-base multiplication 𝑘×𝑮 odd? This part of the algorithm functions similar to point decompression.
- hi bit (3/4): did the affine x-coordinate of 𝑘×𝑮 overflow the order of
the scalar field, requiring a reduction when computing
r
?
Implementations§
source§impl RecoveryId
impl RecoveryId
sourcepub const fn new(is_y_odd: bool, is_x_reduced: bool) -> Self
pub const fn new(is_y_odd: bool, is_x_reduced: bool) -> Self
Create a new RecoveryId
from the following 1-bit arguments:
is_y_odd
: is the affine y-coordinate of 𝑘×𝑮 odd?is_x_reduced
: did the affine x-coordinate of 𝑘×𝑮 overflow the curve order?
sourcepub const fn is_x_reduced(self) -> bool
pub const fn is_x_reduced(self) -> bool
Did the affine x-coordinate of 𝑘×𝑮 overflow the curve order?
sourcepub const fn from_byte(byte: u8) -> Option<Self>
pub const fn from_byte(byte: u8) -> Option<Self>
Convert a u8
into a RecoveryId
.
sourcepub const fn to_byte(self) -> u8
pub const fn to_byte(self) -> u8
Convert this RecoveryId
into a u8
.
source§impl RecoveryId
impl RecoveryId
sourcepub fn trial_recovery_from_msg<C>(
verifying_key: &VerifyingKey<C>,
msg: &[u8],
signature: &Signature<C>
) -> Result<Self>where
C: DigestPrimitive + PrimeCurve + ProjectiveArithmetic,
AffinePoint<C>: DecompressPoint<C> + FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
FieldSize<C>: ModulusSize,
Scalar<C>: Reduce<C::UInt>,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature verify
only.
pub fn trial_recovery_from_msg<C>(
verifying_key: &VerifyingKey<C>,
msg: &[u8],
signature: &Signature<C>
) -> Result<Self>where
C: DigestPrimitive + PrimeCurve + ProjectiveArithmetic,
AffinePoint<C>: DecompressPoint<C> + FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
FieldSize<C>: ModulusSize,
Scalar<C>: Reduce<C::UInt>,
SignatureSize<C>: ArrayLength<u8>,
verify
only.Given a public key, message, and signature, use trial recovery to determine if a suitable recovery ID exists, or return an error otherwise.
sourcepub fn trial_recovery_from_digest<C, D>(
verifying_key: &VerifyingKey<C>,
digest: D,
signature: &Signature<C>
) -> Result<Self>where
C: PrimeCurve + ProjectiveArithmetic,
D: Digest,
AffinePoint<C>: DecompressPoint<C> + FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
FieldSize<C>: ModulusSize,
Scalar<C>: Reduce<C::UInt>,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature verify
only.
pub fn trial_recovery_from_digest<C, D>(
verifying_key: &VerifyingKey<C>,
digest: D,
signature: &Signature<C>
) -> Result<Self>where
C: PrimeCurve + ProjectiveArithmetic,
D: Digest,
AffinePoint<C>: DecompressPoint<C> + FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
FieldSize<C>: ModulusSize,
Scalar<C>: Reduce<C::UInt>,
SignatureSize<C>: ArrayLength<u8>,
verify
only.Given a public key, message digest, and signature, use trial recovery to determine if a suitable recovery ID exists, or return an error otherwise.
sourcepub fn trial_recovery_from_prehash<C>(
verifying_key: &VerifyingKey<C>,
prehash: &[u8],
signature: &Signature<C>
) -> Result<Self>where
C: PrimeCurve + ProjectiveArithmetic,
AffinePoint<C>: DecompressPoint<C> + FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
FieldSize<C>: ModulusSize,
Scalar<C>: Reduce<C::UInt>,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature verify
only.
pub fn trial_recovery_from_prehash<C>(
verifying_key: &VerifyingKey<C>,
prehash: &[u8],
signature: &Signature<C>
) -> Result<Self>where
C: PrimeCurve + ProjectiveArithmetic,
AffinePoint<C>: DecompressPoint<C> + FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
FieldSize<C>: ModulusSize,
Scalar<C>: Reduce<C::UInt>,
SignatureSize<C>: ArrayLength<u8>,
verify
only.Given a public key, message digest, and signature, use trial recovery to determine if a suitable recovery ID exists, or return an error otherwise.
Trait Implementations§
source§impl Clone for RecoveryId
impl Clone for RecoveryId
source§fn clone(&self) -> RecoveryId
fn clone(&self) -> RecoveryId
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RecoveryId
impl Debug for RecoveryId
source§impl From<RecoveryId> for u8
impl From<RecoveryId> for u8
source§fn from(id: RecoveryId) -> u8
fn from(id: RecoveryId) -> u8
source§impl Ord for RecoveryId
impl Ord for RecoveryId
source§fn cmp(&self, other: &RecoveryId) -> Ordering
fn cmp(&self, other: &RecoveryId) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq<RecoveryId> for RecoveryId
impl PartialEq<RecoveryId> for RecoveryId
source§fn eq(&self, other: &RecoveryId) -> bool
fn eq(&self, other: &RecoveryId) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<RecoveryId> for RecoveryId
impl PartialOrd<RecoveryId> for RecoveryId
source§fn partial_cmp(&self, other: &RecoveryId) -> Option<Ordering>
fn partial_cmp(&self, other: &RecoveryId) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more