Struct nettle::rsa::PrivateKey

source ·
pub struct PrivateKey { /* private fields */ }
Expand description

A private RSA key.

Implementations§

source§

impl PrivateKey

source

pub fn new<'a, O: Into<Option<&'a [u8]>>>( d: &[u8], p: &[u8], q: &[u8], inv: O ) -> Result<Self>

Creates a new private key with the private exponent d and the two primes p/q.

If the inverse inv for q in Z_p is None the function computes it.

Notes

This function does time-variable computation on the private key that may leak it. See new_crt for a time-constant way to create a PrivateKey.

source

pub fn new_crt<'a, O: Into<Option<&'a [u8]>>>( dp: &[u8], dq: &[u8], p: &[u8], q: &[u8], inv: O ) -> Result<Self>

Creates a new private key with the two primes p/q.

The private exponent d is given as dp = d mod p - 1 and dq = d mod q - 1. If the inverse inv of q in Z_p is None the function computes it.

Notes

If inv is None the function does time-variable computation on the private key that may leak it.

source

pub fn public_key(&self) -> Result<PublicKey>

Computes the public key to this private key.

This only works if the private key was created with new instead of new_crt.

Notes

This function does time-variable computation on the private key that may leak it.

source

pub fn as_rfc4880(&self) -> (Box<[u8]>, Box<[u8]>, Box<[u8]>)

Returns the tuple a, b, c.

a and b are the two RSA primes p/q with a < b and c = a^-1 mod b.

source

pub fn primes(&self) -> (Box<[u8]>, Box<[u8]>)

Returns the primes p/q as big endian integers.

source

pub fn d_crt(&self) -> (Box<[u8]>, Box<[u8]>, Box<[u8]>)

Returns the private exponent d as pair of big endian integers dp = d mod p - 1 and dq = d mod q - 1 and the inverse of q in Z_p as third value.

source

pub fn d(&self) -> Box<[u8]>

Returns the private exponent d as big endian integer.

Trait Implementations§

source§

impl Clone for PrivateKey

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Drop for PrivateKey

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.