Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Keys

Key is opaque, algorithm-tagged material. Capabilities depend on the bound algorithm.

Constantgenerate^ leavesNotes
Key.aes256gcmone Key (32 bytes)feeds Cipher.aes256gcm
Key.chacha20poly1305one Key (32 bytes)feeds Cipher.chacha20poly1305
Key.ed25519priv then pub.sign^ / .verify^
Key.x25519priv then pub.agree^ → shared ByteList
KindNameEffect
classgenerate( algo -- key ) or ( algo -- priv pub )
classfromBytes( algo bytes -- key )
classfromPublic( algo bytes -- key ) public half (Ed25519 / X25519)
methodtoBytes( -- bytes:ByteList )
methodsign( msg -- sig:ByteList ) Ed25519 private
methodverify( msg sig -- bool ) Ed25519 public
methodagree( peerPub:Key -- shared:ByteList ) X25519 private

fromBytes: symmetric 32 bytes; Ed25519 64 = private, 32 = public; X25519 32 = private (use fromPublic for public).

Ed25519

Key.ed25519 Key.generate^ >ys >xs   // y:pub x:priv
msg x:.sign^ >ts
msg t:peek y:.verify^               // bool

X25519

Key.x25519 Key.generate^ >ys >xs    // y:pubA x:privA
Key.x25519 Key.generate^
>ts                                 // t:pubB
drop                                // drop privB if unused
t:peek x:.agree^                    // shared:ByteList — feed Kdf, then Cipher

See examples/crypto/1a-seal-and-sign.fnl and 1c-derive-key.fnl.