LIBTOMCRYPT(3)
π LIBTOMCRYPT π
okay bestie, so this is the libtomcrypt page from the Library Functions Manual (section 3, the "library functions" girlies). it's a public domain open source crypthographic toolkit and yes we are going to read the whole thing together, no skimming, no skipping, periodt β¨
πΈ NAME πΈ
libtomcrypt β public domain open source crypthographic toolkit
it's giving "free, open, does cryptography." no cap.
π SYNOPSIS π
#include <tomcrypt.h>
Link with -ltomcrypt (use pkg-config --libs libtomcrypt) π«Ά
like, that's the whole vibe. include the header, link the lib, go be a cryptographer.
π¦ DESCRIPTION π¦
so libtomcrypt is documented in /usr/share/doc/libtomcrypt-dev/crypt.pdf. that's the real manual, the actual lore, the extended universe. π
but to give you a very brief introduction, the following example is provided. very brief. like, appetizer brief. but it slays.
β EXAMPLE β
not me about to hand you the entire AES-XTS example verbatim, because every line of this matters π
/* AES-XTS example for libtomcrypt. (c) 2008 Michael Stapelberg, Public Domain */
#include <stdint.h>
#include <string.h>
#include <tomcrypt.h>
static symmetric_xts xts;
/*
* Initializes AES-XTS for use with encrypt(). Key must be at least 32 bytes long, only
* the first 32 bytes will be used.
*
*/
void initialize_xts(unsigned char *key) {
int idx, err;
unsigned char aeskey1[16], aeskey2[16];
/* You can use 32 different ciphers simultaneously. Before using a cipher, you must register it. */
register_cipher(&aes_desc);
/* Get the index of the cipher registered before */
if ((idx = find_cipher("aes")) == -1) {
fprintf(stderr, "ERROR: AES not available in libtomcrypt. Please upgrade/fix libtomcrypt.\n");
exit(EXIT_FAILURE);
}
/* Set up the two private keys required by AES-XTS (see 3.4.10 of crypt.pdf) */
strncpy((char*)aeskey1, key, 16);
strncpy((char*)aeskey2, key+16, 16);
printf("Initializing with keys \"%.16s\" and \"%.16s\" (AES-XTS)\n", aeskey1, aeskey2);
/* Initialize AES-XTS */
if ((err = xts_start(idx, aeskey1, aeskey2, 16, 0, &xts)) != CRYPT_OK) {
fprintf(stderr, "ERROR starting XTS: %s\n", error_to_string(err));
exit(EXIT_FAILURE);
}
}
/*
* Encrypts the input (of input_size) and stores the result in output. The piece index
* is required because XTS wants a tweak for each block so that it doesn't generate
* patterns which would be visible in the encrypted output.
*
*/
void encrypt(const uint8_t *input, uint8_t *output, int input_size, int piece_idx) {
unsigned char tweak[256];
int err;
memset(tweak, '\0', 256);
snprintf((char*)tweak, 256, "%d", piece_idx);
if ((err = xts_encrypt(input, input_size, output, tweak, &xts)) != CRYPT_OK) {
fprintf(stderr, "ERROR in AES encryption: %d: %s\n", err, error_to_string(err));
exit(EXIT_FAILURE);
}
}
likeβ¦ the way that this does the whole register-cipher, find-cipher, split-the-key-in-two, start-XTS, encrypt-with-a-tweak pipeline? main character energy fr fr π₯ and the tweak thing is so real β XTS needs a per-block tweak so it doesn't leak visible patterns in the encrypted output. iconic. no patterns, no problem. π§
also note the key deets: the key must be at least 32 bytes long, and only the first 32 bytes will be used. you can use 32 different ciphers simultaneously, and before using a cipher you must register it. those aren't optional, bestie, that's just how it is. π
π SEE ALSO π
pkg-config(1)
π AUTHOR π
libtomcrypt was written by Tom St Denis.
This manual page was written by Michael Stapelberg <michael@stapelberg.de>, for the Debian project (and may be used by others). π«Ά
and that's the whole page, bestie!! this came from the June 2009 era of the LIBTOMCRYPT(3) manual page (Library Functions Manual section, obvs π ) β so if you see it floating around, that's where it's from. go forth and encrypt responsibly, mwah πβ¨π
π¦ where this page comes from
- debian bookworm: libtomcrypt-dev 1.18.2-6 Β· LicenseRef-public-domain OR WTFPL-2
- debian trixie: libtomcrypt-dev 1.18.2+dfsg-7+b2 Β· LicenseRef-public-domain OR WTFPL-2
- ubuntu jammy: libtomcrypt-dev 1.18.2-5 Β· LicenseRef-public-domain OR WTFPL-2
- ubuntu noble: libtomcrypt-dev 1.18.2+dfsg-7build1 Β· LicenseRef-public-domain OR WTFPL-2
- ubuntu questing: libtomcrypt-dev 1.18.2+dfsg-7build1
- ubuntu resolute: libtomcrypt-dev 1.18.2+dfsg-7build2 Β· LicenseRef-public-domain OR WTFPL-2
- ubuntu stonking: libtomcrypt-dev 1.18.2+dfsg-7build2 Β· LicenseRef-public-domain OR WTFPL-2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms