aes(n)
β¨ aes β the Advanced Encryption Standard, but make it Tcl π
okay bestie, welcome to aes(n), the Tcllib manual page for AES, the Advanced Encryption Standard. it's a block cipher, it's iconic, it's literally the government-approved way to keep your secrets secret π
πΈ NAME πΈ
aes β Implementation of the AES block cipher
π 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]. no cap, it's the real one.
AES is a 128-bit block cipher with a variable key size of 128, 192 or 256 bits. this implementation supports ECB and CBC modes. that's the whole vibe β¨
π COMMANDS π
::aes::aes ?-mode [ecb|cbc]? ?-dir [encrypt|decrypt]? -key keydata ?-iv vector? ?-hex? ?-out channel? ?-chunksize size? [ -in channel | ?--? data ]β run the aes algorithm on either the data you hand it as an argument, or on the data it reads from the-inchannel. if you give it an-outchannel, the result gets written there instead. π«Ά
the -key option is not optional, bestie β you must give it. this parameter takes a binary string of either 16, 24 or 32 bytes in length, and it's what generates the key schedule.
the -mode and -dir options are optional and default to cbc mode and encrypt respectively. the initialization vector -iv takes a 16 byte binary argument, and it defaults to all zeros. head to MODES OF OPERATION for more about the available modes and what they're for.
AES is a 128-bit block cipher, which means the data has to come in units that are a multiple of 16 bytes. no partial blocks, we don't do that here π
π§ PROGRAMMING INTERFACE π§
internal state lives in an opaque structure that the Init function hands back to you. in ECB mode that state isn't affected by the input at all, 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.
::aes::Init mode keydata ivβ construct a brand new AES key schedule using the key data you specify and the initialization vector you give it. the iv isn't used with ECB mode but it's important for CBC mode. see MODES OF OPERATION for the deets on cipher modes.::aes::Encrypt Key dataβ use a prepared key you got from callingInitto encrypt the data you pass in. 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. slay π₯::aes::Decrypt Key dataβ decipher data using the key. note that the same key may be used to encrypt and decrypt data, as long as the initialization vector is reset appropriately for CBC mode. (iykyk β that reset is the whole game.)::aes::Reset Key ivβ reset the initialization vector. this lets the programmer re-use a key and skip the cost of regenerating the key schedule when the same key data is being used multiple times. efficiency, we love her π::aes::Final Keyβ call this to clean up the resources associated with Key. once this function has been called, the key may not be used again. like, ever. it's gone, she's retired π«‘
π MODES OF OPERATION π
π Electronic Code Book (ECB)
ECB is the basic mode of all block ciphers. each block gets encrypted independently, which means identical plain text produces identical output when encrypted with the same key. any encryption errors will only affect a single block β but bestie, this one is vulnerable to known plaintext attacks. π
π©΅ 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 corrects itself. CBC is the most commonly used mode in software encryption, and it's the default mode of operation for this module. main character energy, fr fr π
β 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
look at that hex output, absolutely ate π
π¦ 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
π BUGS, IDEAS, FEEDBACK π
this document, and the package it describes, will undoubtedly contain bugs and other problems. (not me being self-aware π) 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 the documentation.
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. π
π SEE ALSO π
blowfish(n), des(n), md5(n), sha1(n)
π·οΈ 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>
and that's the page, bestie π«Ά this was tcllib version 1.2.2, page aes(n). go forth and encrypt responsibly, and remember: never reuse your IV. periodt πβ¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- 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