Skip to main content

ECIES

Struct ECIES 

Source
pub struct ECIES;
Expand description

ECIES encryption with Electrum and Bitcore variants.

Electrum uses BIE1 magic bytes, derives IV from ECDH shared secret, and uses AES-128-CBC.

Bitcore uses a random IV prepended to ciphertext, derives a 32-byte key from ECDH shared secret, and uses AES-256-CBC.

Implementations§

Source§

impl ECIES

Source

pub fn electrum_encrypt( plaintext: &[u8], recipient_pub_key: &PublicKey, sender_priv_key: Option<&PrivateKey>, ) -> Result<Vec<u8>, CompatError>

Encrypt plaintext using the Electrum ECIES variant (BIE1 format).

Format: “BIE1” (4 bytes) || ephemeral_pubkey (33 bytes) || ciphertext || HMAC (32 bytes)

If sender_priv_key is provided, it is used instead of an ephemeral key.

Source

pub fn electrum_decrypt( ciphertext: &[u8], recipient_priv_key: &PrivateKey, ) -> Result<Vec<u8>, CompatError>

Decrypt ciphertext using the Electrum ECIES variant (BIE1 format).

Expects format: “BIE1” (4) || pubkey (33) || ciphertext || HMAC (32) Minimum length: 4 + 33 + 16 + 32 = 85 (at least one AES block)

Source

pub fn bitcore_encrypt( plaintext: &[u8], recipient_pub_key: &PublicKey, sender_priv_key: Option<&PrivateKey>, ) -> Result<Vec<u8>, CompatError>

Encrypt plaintext using the Bitcore ECIES variant.

Format: ephemeral_pubkey (33) || iv (16) || aes_ciphertext || HMAC (32) HMAC is over iv + aes_ciphertext only (not including pubkey).

Uses AES-256-CBC with a 32-byte key derived from ECDH.

Source

pub fn bitcore_decrypt( ciphertext: &[u8], recipient_priv_key: &PrivateKey, ) -> Result<Vec<u8>, CompatError>

Decrypt ciphertext using the Bitcore ECIES variant.

Expects format: pubkey (33) || iv (16) || aes_ciphertext || HMAC (32) HMAC is verified over iv + aes_ciphertext only.

Auto Trait Implementations§

§

impl Freeze for ECIES

§

impl RefUnwindSafe for ECIES

§

impl Send for ECIES

§

impl Sync for ECIES

§

impl Unpin for ECIES

§

impl UnsafeUnpin for ECIES

§

impl UnwindSafe for ECIES

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> 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, 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.