Wiki page
[(crypto tweetnacl)] by
murphy
2018-01-31 20:26:38.
D 2018-01-31T20:26:38.794
L (crypto\stweetnacl)
P b8cee67961895ae5ac9891000b6f7092caf20e37
U murphy
W 5638
<h1>TweetNaCl Bindings</h1>
<h2>Synopsis</h2>
<code>(import (crypto tweetnacl))</code>
Bindings to the [https://tweetnacl.cr.yp.to/|TweetNaCl] library of cryptographic operations.
<h2>Keys</h2>
<h3>record: <code>key</code></h3>
<h3>procedure: <code>(key? <i>any</i>)</code></h3>
<h3>procedure: <code>(make-key <i>algorithm</i> <i>public</i> <i>secret</i>)</code></h3>
<h3>procedure: <code>(key-algorithm <i>key</i>)</code></h3>
<h3>procedure: <code>(public-key <i>key</i>)</code></h3>
<h3>procedure: <code>(secret-key <i>key</i>)</code></h3>
Keys are represented by record instances that hold an algorithm name, a public key bytevector and a secret key bytevector. Depending on the algorithm and intended use of the key, either the public or secret component may be <tt>#f</tt>.
<h3>procedure: <code>(check-key <i>who</i> <i>algorithm</i> <i>any</i>)</code></h3>
Ensures that the given value is a key with the given algorithm name and returns the key. If the value does not pass the check, an error condition is raised that contains a <tt>&who</tt> condition indicating the given location.
<h2>Asymmetric Boxes</h2>
<h3>constant: <code>asymmetric-box-algorithm</code></h3>
The name of the asymmetric box algorithm.
<h3>constant: <code>asymmetric-box-publickeybytes</code></h3>
<h3>constant: <code>asymmetric-box-secretkeybytes</code></h3>
<h3>constant: <code>asymmetric-box-noncebytes</code></h3>
Byte lengths of algorithm parameters.
<h3>procedure: <code>(make-asymmetric-box-key)</code></h3>
<h3>procedure: <code>(make-asymmetric-box-key <i>port</i>)</code></h3>
Generate a new keypair using entropy from the given port or from <tt>(current-entropy-port)</tt>.
<h3>procedure: <code>((asymmetric-box <i>pk</i> <i>sk</i>) <i>data</i> <i>nonce</i>)</code></h3>
<h3>procedure: <code>((asymmetric-unbox <i>pk</i> <i>sk</i>) <i>data</i> <i>nonce</i>)</code></h3>
Perform key agreement and return boxing and unboxing procedures.
<h2>Asymmetric Signatures</h2>
<h3>constant: <code>asymmetric-sign-algorithm</code></h3>
The name of the asymmetric signature algorithm.
<h3>constant: <code>asymmetric-sign-publickeybytes</code></h3>
<h3>constant: <code>asymmetric-sign-secretkeybytes</code></h3>
Byte lengths of algorithm parameters.
<h3>procedure: <code>(make-asymmetric-sign-key)</code></h3>
<h3>procedure: <code>(make-asymmetric-sign-key <i>port</i>)</code></h3>
Generate a new keypair using entropy from the given port or from <tt>(current-entropy-port)</tt>.
<h3>procedure: <code>((asymmetric-sign <i>sk</i>) <i>data</i>)</code></h3>
<h3>procedure: <code>((asymmetric-verify <i>pk</i>) <i>data</i>)</code></h3>
Create signature and verification procedures.
<h2>Symmetric Boxes</h2>
<h3>constant: <code>symmetric-box-algorithm</code></h3>
The name of the symmetric box algorithm.
<h3>constant: <code>symmetric-box-keybytes</code></h3>
<h3>constant: <code>symmetric-box-noncebytes</code></h3>
Byte lengths of algorithm parameters.
<h3>procedure: <code>(make-symmetric-box-key)</code></h3>
<h3>procedure: <code>(make-symmetric-box-key <i>port</i>)</code></h3>
Generate a new key using entropy from the given port or from <tt>(current-entropy-port)</tt>.
<h3>procedure: <code>(derive-symmetric-box-key <i>pk</i> <i>sk</i>)</code></h3>
Derive a symmetric box key through an asymmetric box key agreement.
<h3>procedure: <code>((symmetric-box <i>k</i>) <i>data</i> <i>nonce</i>)</code></h3>
<h3>procedure: <code>((symmetric-unbox <i>k</i>) <i>data</i> <i>nonce</i>)</code></h3>
Create boxing and unboxing procedures.
<h2>Symmetric Signatures</h2>
<h3>constant: <code>symmetric-sign-algorithm</code></h3>
The name of the symmetric signature algorithm.
<h3>constant: <code>symmetric-sign-keybytes</code></h3>
Byte lengths of algorithm parameters.
<h3>procedure: <code>(make-symmetric-sign-key)</code></h3>
<h3>procedure: <code>(make-symmetric-sign-key <i>port</i>)</code></h3>
Generate a new key using entropy from the given port or from <tt>(current-entropy-port)</tt>.
<h3>procedure: <code>((symmetric-sign <i>k</i>) <i>data</i>)</code></h3>
<h3>procedure: <code>((symmetric-verify <i>k</i>) <i>data</i>)</code></h3>
Create signature and verification procedures.
<h2>Pseudo-Random Streams</h2>
<h3>constant: <code>random-stream-algorithm</code></h3>
The name of the pseudo-random number generator algorithm.
<h3>constant: <code>random-stream-keybytes</code></h3>
<h3>constant: <code>random-stream-noncebytes</code></h3>
Byte lengths of algorithm parameters.
<h3>procedure: <code>(make-random-stream-key)</code></h3>
<h3>procedure: <code>(make-random-stream-key <i>port</i>)</code></h3>
Generate a new key using entropy from the given port or from <tt>(current-entropy-port)</tt>.
<h3>procedure: <code>(derive-random-stream-key <i>pk</i> <i>sk</i>)</code></h3>
Derive a pseudo-random stream key through an asymmetric box key agreement.
<h3>procedure: <code>(open-random-stream <i>k</i> <i>nonce</i>)</code></h3>
<h3>procedure: <code>(open-random-stream <i>k</i> <i>nonce</i> <i>limit</i>)</code></h3>
Open a binary input port backed by a pseudo-random number generator. The default limit, after which the port will signal end of file, is 1 GiB of random data, but <tt>#f</tt> or <tt>+inf.0</tt> may be passed to deactivate the limit.
<h2>Message Digests</h2>
<h3>constant: <code>hash-algorithm</code></h3>
The name of the message digest algorithm.
<h3>procedure: <code>(hash <i>data</i>)</code></h3>
Compute the message digest of binary data.
Z 8ebdd9dc5530f81f032d9310b102f370