Documentation ¶
Overview ¶
Package box authenticates and encrypts messages using public-key cryptography.
Box uses Curve25519, XSalsa20 and Poly1305 to encrypt and authenticate messages. The length of messages is not hidden.
It is the caller's responsibility to ensure the uniqueness of nonces—for example, by using nonce 1 for the first message, nonce 2 for the second message, etc. Nonces are long enough that randomly generated nonces have negligible risk of collision.
This package is interoperable with NaCl: https://nacl.cr.yp.to/box.html.
Index ¶
- Constants
- func GenerateKey(rand io.Reader) (publicKey, privateKey *[32]byte, err error)
- func Open(out, box []byte, nonce *[24]byte, peersPublicKey, privateKey *[32]byte) ([]byte, bool)
- func OpenAfterPrecomputation(out, box []byte, nonce *[24]byte, sharedKey *[32]byte) ([]byte, bool)
- func Precompute(sharedKey, peersPublicKey, privateKey *[32]byte)
- func Seal(out, message []byte, nonce *[24]byte, peersPublicKey, privateKey *[32]byte) []byte
- func SealAfterPrecomputation(out, message []byte, nonce *[24]byte, sharedKey *[32]byte) []byte
Constants ¶
const Overhead = secretbox.Overhead
Overhead is the number of bytes of overhead when boxing a message.
Variables ¶
This section is empty.
Functions ¶
func GenerateKey ¶
GenerateKey generates a new public/private key pair suitable for use with Seal and Open.
func Open ¶
Open authenticates and decrypts a box produced by Seal and appends the message to out, which must not overlap box. The output will be Overhead bytes smaller than box.
func OpenAfterPrecomputation ¶
OpenAfterPrecomputation performs the same actions as Open, but takes a shared key as generated by Precompute.
func Precompute ¶
func Precompute(sharedKey, peersPublicKey, privateKey *[32]byte)
Precompute calculates the shared key between peersPublicKey and privateKey and writes it to sharedKey. The shared key can be used with OpenAfterPrecomputation and SealAfterPrecomputation to speed up processing when using the same pair of keys repeatedly.
Types ¶
This section is empty.