Struct PublicKey

Source
pub struct PublicKey<S: Suite> {
    pub point: NonZero<Point<S::E>>,
}
Expand description

Public key is a point on the elliptic curve of the chosen suite.

You can obtain a public key from a newly generated private key by PrivateKey::public_key, or by reading it from bytes with PublicKey::from_bytes

Fields§

§point: NonZero<Point<S::E>>

Q in the standard

Implementations§

Source§

impl PublicKey<Curve25519Aes128cbcHmacsha256>

Source

pub fn encrypt_in_place<'m>( &self, message: &'m mut [u8], data_len: usize, rng: &mut (impl RngCore + CryptoRng), ) -> Result<EncryptedMessage<'m>, EncError>

Encrypt the message bytes in place; specialization for curve25519aes128_cbchmac. Uses PKCS7 padding.

  • message - the buffer containing the message to encrypt, plus enough space for padding
  • data_len - length of the message in the buffer

Given a message m, the size of the buffer should be at least m.len() + pad_size(m.len()). If the buffer size is too small, the function will return crate::EncError::PadError

You can interact with the encrypted bytes through the returned EncryptedMessage, but be careful that changing them will invalidate the mac.

Convenient alias for PublicKey::block_encrypt_in_place

Source

pub fn encrypt( &self, message: &[u8], rng: &mut (impl RngCore + CryptoRng), ) -> Result<Vec<u8>, EncError>

Encrypt the message bytes into a new buffer. Uses PKCS7 padding. Returnes the encoded bytes of EncryptedMessage. Specialization for curve25519aes128_cbchmac

Convenient alias for PublicKey::block_encrypt

Source§

impl PublicKey<Curve25519Xsalsa20Hmacsha256>

Source

pub fn encrypt_in_place<'m>( &self, message: &'m mut [u8], rng: &mut (impl RngCore + CryptoRng), ) -> Result<EncryptedMessage<'m>, EncError>

Encrypt the message bytes in place; specialization for curve25519xsalsa20hmac

You can interact with the encrypted bytes through the returned EncryptedMessage, but be careful that changing them will invalidate the mac.

Convenient alias for PublicKey::stream_encrypt_in_place

Source

pub fn encrypt( &self, message: &[u8], rng: &mut (impl RngCore + CryptoRng), ) -> Result<Vec<u8>, EncError>

Encrypt the message bytes into a new buffer. Returnes the encoded bytes of EncryptedMessage. Specialization for curve25519xsalsa20hmac

Convenient alias for PublicKey::stream_encrypt

Source§

impl<S: Suite> PublicKey<S>

Source

pub fn from_bytes(bytes: impl AsRef<[u8]>) -> Option<Self>

Read the encoded scalar. Should be compatible with most other software for working with elliptic curves.

Source

pub fn to_bytes(&self) -> Vec<u8>

Write the encoded scalar. Should be compatible with most other software for working with elliptic curves.

Source

pub fn stream_encrypt_in_place<'m>( &self, message: &'m mut [u8], rng: &mut (impl RngCore + CryptoRng), ) -> Result<EncryptedMessage<'m, S>, EncError>
where S::Mac: Mac + KeyInit, S::Enc: KeyIvInit + StreamCipher,

Encrypt the message bytes in place. Variant for suites with stream ciphers.

You can interact with the encrypted bytes through the returned EncryptedMessage, but be careful that changing them will invalidate the mac.

Source

pub fn block_encrypt_in_place<'m>( &self, message: &'m mut [u8], data_len: usize, rng: &mut (impl RngCore + CryptoRng), ) -> Result<EncryptedMessage<'m, S>, EncError>

Encrypt the message bytes in place. Variant for suites with block ciphers. Uses PKCS7 padding.

  • message - the buffer containing the message to encrypt, plus enough space for padding
  • data_len - length of the message in the buffer

Given a message m, the size of the buffer should be at least m.len() + pad_size(m.len()). If the buffer size is too small, the function will return EncError::PadError

You can interact with the encrypted bytes through the returned EncryptedMessage, but be careful that changing them will invalidate the mac.

Source

pub fn stream_encrypt( &self, message: &[u8], rng: &mut (impl RngCore + CryptoRng), ) -> Result<Vec<u8>, EncError>
where S::Mac: Mac + KeyInit, S::Enc: KeyIvInit + StreamCipher,

Encrypt the message bytes into a new buffer. Variant for suites with stream ciphers.

Returnes the encoded bytes of EncryptedMessage

Source

pub fn block_encrypt( &self, message: &[u8], rng: &mut (impl RngCore + CryptoRng), ) -> Result<Vec<u8>, EncError>

Encrypt the message bytes into a new buffer. Variant for suites with block ciphers. Uses PKCS7 padding.

Returnes the encoded bytes of EncryptedMessage

Trait Implementations§

Source§

impl<S: Clone + Suite> Clone for PublicKey<S>
where S::E: Clone,

Source§

fn clone(&self) -> PublicKey<S>

Returns a duplicate 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<S: Debug + Suite> Debug for PublicKey<S>
where S::E: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: PartialEq + Suite> PartialEq for PublicKey<S>
where S::E: PartialEq,

Source§

fn eq(&self, other: &PublicKey<S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S: Eq + Suite> Eq for PublicKey<S>
where S::E: Eq,

Source§

impl<S: Suite> StructuralPartialEq for PublicKey<S>

Auto Trait Implementations§

§

impl<S> Freeze for PublicKey<S>
where <<S as Suite>::E as Curve>::Point: Freeze,

§

impl<S> RefUnwindSafe for PublicKey<S>
where <<S as Suite>::E as Curve>::Point: RefUnwindSafe,

§

impl<S> Send for PublicKey<S>

§

impl<S> Sync for PublicKey<S>

§

impl<S> Unpin for PublicKey<S>

§

impl<S> UnwindSafe for PublicKey<S>
where <<S as Suite>::E as Curve>::Point: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.