1 ![SlunkCrypt](etc/img/SlunkCrypt-Logo.png)
6 SlunkCrypt is an experimental cryptography library and command-line tool.
12 Use of SlunkCrypt may be illegal in countries where encryption is outlawed. We believe it is legal to use SlunkCrypt in many countries all around the world, but we are not lawyers, and so if in doubt you should seek legal advice before downloading it. You may find useful information at [cryptolaw.org](http://www.cryptolaw.org/), which collects information on cryptography laws in many countries, but we can't vouch for its correctness.
18 This section describes the SlunkCypt command-line front-end.
23 The SlunkCypt command-line program is invoked as follows:
25 slunkcrypt --encrypt [[@][:]<passphrase>] <input.txt> <output.enc>
26 slunkcrypt --decrypt [[@][:]<passphrase>] <input.enc> <output.txt>
31 One of the following commands must be chosen:
33 - **`--encrypt` (`-e`):**
34 Encrypt the plaintext in the given input file. The ciphertext is written to the specified output file.
35 - **`--decrypt` (`-d`):**
36 Decrypt the ciphertext in the given input file. The plaintext is written to the specified output file.
37 - **`--self-test` (`-t`):**
38 Run self-test and exit application.
43 The following options are available:
45 - If `<passphrase>` is prefixed with a **`@`** character, then it specifies the file to read the passphrase from.
46 *Note:* Only the first non-empty line in the specified file is used!
47 - If `<passphrase>` is prefixed with a **`:`** character, then the leading character is ignored.
48 - If `<passphrase>` is omitted, then the passphrase is read from the `SLUNK_PASSPHRASE` environment variable.
49 - If `<passphrase>` is set to **`@-`**, then the passphrase is read from the standard input stream.
52 Programming Interface (API)
53 ===========================
58 This section describes the "low-level" C99 API of the SlunkCypt library.
60 ### slunkcrypt_alloc()
62 Allocate and initialize a new SlunkCrypt encryption/decryption context.
64 slunkcrypt_t slunkcrypt_alloc(
66 const uint8_t *const passwd,
67 const size_t passwd_len
72 The *nonce* (number used once) to be used for the encryption/decryption process. The purpose of the nonce is to ensure that each message will be encrypted differently, even when the same password is used to encrypt *multiple* (possibly identical) messages. Therefore, a new *random* nonce **must** be chosen for each message to be encrypted! It is *not* necessary to keep the nonce confidential, but the same nonce **must** be used for both, encryption *and* decryption. Typically, the nonce is stored/transmitted alongside the ciphertext.
74 *Note:* It is recommended to generate a random nonce via the `slunkcrypt_generate_nonce()` function for each message!
77 The password to "protect" the message. The password is given as an array of bytes (`uint8_t`), e.g. UTF-8 encoded characters; a terminating NULL character is *not* required, as the length of the password is specified explicitly. The same password **may** be used to encrypt *multiple* messages. Also, the same password **must** be used for both, encryption *and* decryption; it will *only* be possible decrypt the ciphertext, if the "correct" password is known. The password must be kept confidential under all circumstances!
79 *Note:* In order to thwart *brute force* attacks, it is recommended to choose a "random" password that is at least 12 characters in length and that consists of upper-case characters, lower-case characters, digits as well as other "special" characters.
82 The length of password given by the `passwd` parameter, in bytes, **not** counting a terminating NULL character. The minimum/maximum length of the password are given by the `SLUNKCRYPT_PWDLEN_MIN` and `SLUNKCRYPT_PWDLEN_MAX` constants, respectively.
85 * If successful, a handle to the new SlunkCrypt context is return; otherwise `SLUNKCRYPT_NULL` is returned.
87 *Note:* Applications **should** treat `slunkcrypt_t` as an *opaque* handle type. Also, as soon as the SlunkCrypt context is *not* needed anymore, the application **shall** call `slunkcrypt_free()` in order to "clear" and de-allocate that context.
89 ### slunkcrypt_reset()
91 Re-initialize an existing SlunkCrypt encryption/decryption context.
94 const slunkcrypt_t context,
96 const uint8_t *const passwd,
97 const size_t passwd_len
102 The existing SlunkCrypt context to be re-initialized. This must be a valid handle that was returned by a previous invocation of the `slunkcrypt_alloc()` function and that has **not** been `free`'d since then.
105 Please refer to the `slunkcrypt_alloc()` function for details!
108 Please refer to the `slunkcrypt_alloc()` function for details!
111 Please refer to the `slunkcrypt_alloc()` function for details!
114 * If successful, `SLUNKCRYPT_SUCCESS` is returned; otherwise `SLUNKCRYPT_FAILURE` or `SLUNKCRYPT_ABORTED` is returned.
116 ### slunkcrypt_free()
118 De-allocate an existing SlunkCrypt encryption/decryption context. This will "clear" and release any memory occupied by the context.
120 void slunkcrypt_free(
121 const slunkcrypt_t context
126 The existing SlunkCrypt context to be de-allocated. This must be a valid handle that was returned by a previous invocation of the `slunkcrypt_alloc()` function and that has **not** been `free`'d since then.
128 *Note:* Once a handle has been passed to this function, that handle is *invalidated* and **must not** be used again!
130 ### slunkcrypt_generate_nonce()
132 Generate a new random *nonce* (number used once), using the system's "cryptographically secure" entropy source.
134 int slunkcrypt_generate_nonce(
140 A pointer to a variable of type `int64_t` that receives the new random nonce.
143 * If successful, `SLUNKCRYPT_SUCCESS` is returned; otherwise `SLUNKCRYPT_FAILURE` or `SLUNKCRYPT_ABORTED` is returned.
145 ### slunkcrypt_encrypt()
147 Encrypt the next message chunk, using separate input/output buffers.
149 int slunkcrypt_encrypt(
150 const slunkcrypt_t context,
151 const uint8_t *const input,
152 uint8_t* const output,
158 The existing SlunkCrypt context to be used for encrypting the message chunk. This context will be updated.
161 A pointer to the *input* buffer containing the next chunk of the plaintext to be encrypted. The plaintext is given as an array of bytes (`uint8_t`). This can be arbitrary binary data, e.g. UTF-8 encoded text. NULL bytes are **not** treated specially.
163 The *input* buffer must contain *at least* `length` bytes of data. If the buffer is longer than `length` bytes, then only the first `length` bytes will be processed and the remainder is ignored!
166 A pointer to the *output* buffer where the ciphertext chunk that corresponds to the given plaintext chunk will be stored. The ciphertext is stored as an array of bytes (`uint8_t`); it has the same length as the plaintext data.
168 The *output* buffer must provide sufficient space for storing *at least* `length` bytes of encrypted data. If the buffer is longer than `length` bytes, then only the first `length` bytes of the buffer will be filled with encrypted data!
171 The length of the plaintext chunk contained in the *input* buffer given by the `input` parameter, in bytes. At the same time, this determines the minimum required size of the *output* buffer given by the `output` parameters, in bytes.
174 * If successful, `SLUNKCRYPT_SUCCESS` is returned; otherwise `SLUNKCRYPT_FAILURE` or `SLUNKCRYPT_ABORTED` is returned.
176 ### slunkcrypt_encrypt_inplace()
178 Encrypt the next message chunk, using a single buffer.
180 int slunkcrypt_encrypt(
181 const slunkcrypt_t context,
182 uint8_t* const buffer,
188 The existing SlunkCrypt context to be used for encrypting the message chunk. This context will be updated.
191 A pointer to the buffer initially containing the next chunk of the plaintext to be encrypted. The plaintext is given as an array of bytes (`uint8_t`). This can be arbitrary binary data, e.g. UTF-8 encoded text. NULL bytes are **not** treated specially. The ciphertext chunk that corresponds to the given plaintext chunk will be stored to the *same* buffer, thus replacing the plaintext data.
193 The buffer must initially contain *at least* `length` bytes of input data; the first `length` bytes of the buffer will be overwritten with the encrypted data. If the buffer is longer than `length` bytes, then only the first `length` bytes will be processed and overwritten.
196 The length of the plaintext chunk initially contained in the input/output buffer given by the `buffer` parameter, in bytes. At the same time, this determines the portion of the input/output buffer that will be overwritten with encrypted data, in bytes.
199 * If successful, `SLUNKCRYPT_SUCCESS` is returned; otherwise `SLUNKCRYPT_FAILURE` or `SLUNKCRYPT_ABORTED` is returned.
205 This work has been released under the **CC0 1.0 Universal** license.
207 For details, please refer to:
208 <https://creativecommons.org/publicdomain/zero/1.0/legalcode>