aes(3tcl)
β¨ aes(3tcl) β¨
okay bestie, you're looking at the man page for aes(3tcl) β aka Advanced Encryption Standard (AES), living in the tcllib collection. pull up a chair, we're gonna learn about block ciphers together π
πΈ NAME πΈ
aes β the implementation of the AES block cipher. that's it, that's the name, short and iconic π
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require aes ?1.2.2?
::aes::aes ?-mode [ecb|cbc]? ?-dir [encrypt|decrypt]? -key keydata ?-iv
vector? ?-hex? ?-out channel? ?-chunksize size? [ -in channel | ?--?
data ]
::aes::Init mode keydata iv
::aes::Encrypt Key data
::aes::Decrypt Key data
::aes::Reset Key iv
::aes::Final Key
π DESCRIPTION π
so this is a Tcl implementation of the Advanced Encryption Standard (AES) as published by the U.S. National Institute of Standards and Technology [1]. it's giving official. it's giving certified. π
here's the tea: AES is a 128-bit block cipher with a variable key size of 128, 192 or 256 bits. and this particular implementation supports ECB and CBC modes. no cap. π
π COMMANDS π
::aes::aes ?-mode [ecb|cbc]? ?-dir [encrypt|decrypt]? -key keydata ?-iv vector? ?-hex? ?-out channel? ?-chunksize size? [ -in channel | ?--? data ]
this one runs the aes algorithm on either the data you handed it as an argument, or on the data it reads from the -in channel. and if you give it an -out channel, the result gets written straight to that channel. main character energy fr. π
- the
-keyoption is mandatory, no skipping it bestie. it takes a binary string of either 16, 24 or 32 bytes in length, and that's what gets used to generate the key schedule. -modeand-dirare optional and they default tocbcmode andencryptrespectively. the initialization vector-ivtakes a 16 byte binary argument and defaults to all zeros. go read MODES OF OPERATION if you wanna know more about the modes and what they're for π
heads up: AES is a 128-bit block cipher, which literally means the data has to be provided in units that are a multiple of 16 bytes. don't come at it with 15 bytes and expect slay, it will not slay. π
π¦ PROGRAMMING INTERFACE π¦
internal state is kept in an opaque structure that gets returned from the Init function. in ECB mode the state isn't affected by the input, but for CBC mode some input-dependent state is maintained, and you can reset it by calling the Reset function with a new initialization vector value. cute, right? π«Ά
::aes::Init mode keydata iv
constructs a brand new AES key schedule using the specified key data and the given initialization vector. the initialization vector isn't used with ECB mode, but it is important for CBC mode. check MODES OF OPERATION for the details about cipher modes. β¨
::aes::Encrypt Key data
uses a prepared key you got by calling Init to encrypt the provided data. the data argument should be a binary array that's a multiple of the AES block size of 16 bytes. the result is a binary array the same size as the input, full of encrypted data. glow up complete. π₯
::aes::Decrypt Key data
deciphers data using the key. ngl the cute part is that the same key can be used to encrypt and decrypt data β provided the initialization vector is reset appropriately for CBC mode. π
::aes::Reset Key iv
resets the initialization vector. this lets the programmer re-use a key and dodge the cost of re-generating the key schedule when the same key data is being used multiple times. efficiency icon. β
::aes::Final Key
this is the one you call to clean up resources associated with Key. and bestie, listen β once this function has been called the key may not be used again. it's over, it's done, do not text it back. π
π MODES OF OPERATION π
Electronic Code Book (ECB)
ECB is the basic mode of all block ciphers. each block is encrypted independently, which means identical plain text will produce identical output when encrypted with the same key. π¬ any encryption errors will only affect a single block β but this is vulnerable to known plaintext attacks. so like, it's simple but it's not the moment.
Cipher Block Chaining (CBC)
CBC mode uses the output of the last block encryption to affect the current block. an initialization vector of the same size as the cipher block size is used to handle the first block. that initialization vector should be chosen randomly and transmitted as the first block of the output. errors in encryption affect the current block and the next block, after which the cipher will correct itself. CBC is the most commonly used mode in software encryption, and it's the default mode of operation for this module. periodt. π
π EXAMPLES π
% set nil_block [string repeat \\0 16]
% aes::aes -hex -mode cbc -dir encrypt -key $nil_block $nil_block
66e94bd4ef8a2c3b884cfa59ca342b2e
set Key [aes::Init cbc $sixteen_bytes_key_data $sixteen_byte_iv]
append ciphertext [aes::Encrypt $Key $plaintext]
append ciphertext [aes::Encrypt $Key $additional_plaintext]
aes::Final $Key
π REFERENCES π
- [1] "Advanced Encryption Standard", Federal Information Processing Standards Publication 197, 2001 (http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf)
π§ AUTHORS π§
Thorsten Schloermann, Pat Thoyts β legends, honestly. π
π BUGS, IDEAS, FEEDBACK π
this document, and the package it describes, will undoubtedly contain bugs and other problems. (their words, not mine, but ok go off.) please report such in the category aes of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. please also report any ideas for enhancements you may have for either the package and/or documentation. we want the feedback, we love the feedback. π«Ά
when proposing code changes, please provide unified diffs, i.e the output of diff -u.
note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. iykyk. β¨
π SEE ALSO π
blowfish(3tcl), des(3tcl), md5(3tcl), sha1(3tcl)
π KEYWORDS π
aes, block cipher, data integrity, encryption, security
π CATEGORY π
Hashes, checksums, and encryption
π COPYRIGHT π
Copyright (c) 2005, Pat Thoyts <patthoyts@users.sourceforge.net>
Copyright (c) 2012-2014, Andreas Kupries <andreas_kupries@users.sourceforge.net>
okay that's the whole page bestie, you're officially AES-literate π this was tcllib version 1.2.2, page aes(3tcl) β go encrypt something responsibly, stay safe, and remember: random IVs only. mwah πβ¨
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2005, Pat Thoyts <patthoyts@users\&.sourceforge\&.net>
- Copyright (c) 2012-2014, Andreas Kupries <andreas_kupries@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms