Skip to main content

SharedKey

Struct SharedKey 

Source
pub struct SharedKey(/* private fields */);
Expand description

2つの鍵から導出した、AES-256-GCM の鍵。使い終わるとメモリを0で上書きする。

Implementations§

Source§

impl SharedKey

Source

pub fn derive( private_key: &PrivateKey, other_public_key: &PublicKey, ) -> Result<Self, InvalidPublicKey>

自分の秘密鍵と相手の公開鍵から導出する。catapult の DeriveSharedKey。

秘密鍵の SHA-512 の前半をクランプしたスカラーを相手の点に掛け、 圧縮した点を HKDF-HMAC-SHA256 にかける。相手の公開鍵は、署名の検証と同じく y が正規で、曲線上にあり、位数 L の部分群に入っているものだけを受け付ける。

Source

pub fn as_bytes(&self) -> &[u8; 32]

Source§

impl SharedKey

Source

pub fn candidates_from_x25519(shared: &[u8; 32]) -> Option<[Self; 2]>

X25519 の結果(共有した点の u)から、SharedKey::derive と同じ鍵の候補を2つ作る。

catapult は共有した点を Edwards の形(y と x の符号)で圧縮して使うが、X25519 の結果には x の符号がない。 符号の両方を候補にし、どちらが合うかは AES-GCM の認証タグで決める(open_x25519)

Trait Implementations§

Source§

impl Debug for SharedKey

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

Source§

type Output = T

Should always be Self
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.