docs

您正在閱讀 v0.1.0 的文件。Nabi 0.1.0 已停止支援。 最新版本:v0.1.3 →

本頁尚未翻譯,以下為英文原文。

#Sealed messages

本頁內容

Encrypt a message so only its recipient can read it, and sign it so the recipient knows who sent it, with nothing but core::crypto and the OS random source.

Warning

Nabi's cryptography is new and unaudited. This program shows how the pieces fit; do not protect real secrets with it yet.

#Code

#Walkthrough

  • Each message gets a fresh X25519 key pair. Its secret half and Bob's public key give the same shared secret that Bob computes from his secret and the one-time public key sent along. Keys are typed values: x25519::PrivateKey keeps its bytes in secret storage, and its PublicKey half is a plain value that goes in the message (x25519, 2.21.3 key exchange).
  • A raw shared secret is not used as a key directly: hkdf::extract / expand turn it into a 32-byte AEAD key, with a label (b"sealed-box v1") that ties the key to this protocol (2.21.1).
  • ChaCha20-Poly1305 encrypts and authenticates. The 24-byte text becomes 40 bytes, the extra 16 being the tag. open returns none for a wrong key or a changed byte, so Eve and the tampered copy are both rejected before any plaintext appears (Aead, 2.21.2).
  • Alice signs the one-time key, nonce and ciphertext together with Ed25519, so nobody can swap any of them. open checks the signature first, with Alice's VerifyingKey (ed25519).
  • Private keys are made from random::secret, which puts the bytes straight into secret storage, and the shared secret and derived key are Secrets too, so no key byte lands in an ordinary List. Nonces are public and come from random::bytes. The algorithms never fetch randomness themselves (Key material). Optional results are unwrapped with postfix ? and ?? (Sum types).
  • More in Cryptography and TLS.

Found a mistake? Edit this page on GitHub. Last updated