chickadee » sodium



Bindings to the libsodium crypto library, a "portable, cross-compilable, installable, packageable fork of NaCl, with a compatible API, and an extended API to improve usability even further".



(sodium-version-string) procedure

Returns a string representing the current libsodium version.

(sodium-init) procedure

Initializes the library and should be called before any other function provided by Sodium. The function can be called more than once, and can be called simultaneously from multiple threads since libsodium version 1.0.11.


(constant-time-blob=? a b len) procedure

Compares two blobs in constant time. Important when a comparison involves secret data (e.g. key, authentication tag), in order to mitigate side-channel attacks.

(bin->hex bin) procedure

Returns a string containing a hex representation of the binary data in the blob 'bin'.

(hex->bin hex #!optional ignore) procedure

Returns a blob of the binary data represented by the hex string 'hex'. Ignore is a string of characters to skip. For example, the string ": " allows columns and spaces to be present at any locations in the hexadecimal string. These characters will just be ignored. As a result, "69:FC", "69 FC", "69 : FC" and "69FC" will be valid inputs, and will produce the same output.


generic-hash-bytes constant

The minimum *recommended* output size of a generic-hash.

generic-hash-bytes-min constant

The actual minimum size of a generic-hash.

generic-hash-bytes-max constant

The maximum size of a generic-hash.

generic-hash-key-bytes constant

The recommended size of a generic-hash key.

generic-hash-key-bytes-min constant

The minimum size of a generic-hash key.

generic-hash-key-bytes-max constant

The maximum size of a generic-hash key.

(generic-hash data #!key (size generic-hash-bytes) key) procedure

Returns a fingerprint of 'data' using the BLAKE2b hashing algorithm. Returns a blob of size 'size', which should be between generich-hash-bytes-min and generic-hash-bytes-max. A key can also be specified. A message will always have the same fingerprint for a given key, but different keys used to hash the same message are very likely to produce distinct fingerprints.

(generic-hash-init #!key (size generic-hash-bytes) key) procedure

The streaming API alternative to generic-hash. This function returns a hash state object, which can be updated using generic-hash-update, then the final hash can be obtained using generic-hash-final.

(generic-hash-update state data) procedure

Updates the hash state (returned from a generic-hash-init call) with new data.

(generic-hash-final state) procedure

Returns the current hash value for 'state' (as returned from generic-hash-init) as a blob.

Public-key signatures

sign-public-key-bytes constant

Size of a ed25519 signing public key in bytes.

sign-secret-key-bytes constant

Size of a ed25519 signing secret key in bytes.

(sign-keypair) procedure

Generates a new ed25519 signing key pair and returns two values the public-key and the secret-key.

(sign-ed25519-secret-key->public-key secret-key) procedure

Extracts the public ed25519 signing key from the secret key.

sign-bytes constant

Size of an ed25519 signature in bytes.

(sign-detached data secret-key) procedure

Returns a separate ed25519 signature of 'data' as a blob.

(sign-verify-detached signature data public-key) procedure

Verifies a detached signature against 'data' and 'public-key'. Returns #t if verified, #f otherwise.

scalarmult-curve25519-bytes constant

Size of curve25519 key in bytes.

(sign-ed25519-public-key->curve25519) procedure

Converts an ed25519 public key to a curve25519 public key.

Note: if you can afford it, using distinct keys for signing and for encryption is still highly recommended.

(sign-ed25519-secret-key->curve2551) procedure

Converts an ed25519 secret key to a curve25519 secret key.

Note: if you can afford it, using distinct keys for signing and for encryption is still highly recommended.

Generating random data

(random-byte) procedure

Returns an unpredictable value between 0 and 0xffffffff (included) as an integer.

(random-uniform upper-bound) procedure

Returns an unpredictable value between 0 and upper-bound (excluded). Unlike (modulo random-byte upper-bound), it does its best to guarantee a uniform distribution of the possible output values even when upper-bound is not a power of 2.

(random-blob n) procedure

Returns a new blob of size 'n', filled with random bytes.

Contents »