blowfish(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– blowfish β€” like, the Blowfish block cipher, bestie πŸ’–

okay so this is the blowfish page from the Tcl manual, section 3tcl, and it's genuinely one of my faves. Sit down, grab a strawberry πŸ“, and let's get into it.


✨ NAME ✨

blowfish β€” an implementation of the Blowfish block cipher. that's it, that's the vibe. πŸ‘‘


✨ SYNOPSIS ✨

package require Tcl 8.5 9

package require blowfish ?1.0.6?

::blowfish::blowfish ?-mode [ecb|cbc]? ?-dir [encrypt|decrypt]? -key keydata ?-iv vector? ?-out channel? ?-chunksize size? ?-pad padchar? [ -in channel | ?--? data ]

::blowfish::Init mode keydata iv

::blowfish::Encrypt Key data

::blowfish::Decrypt Key data

::blowfish::Reset Key iv

::blowfish::Final Key

not me putting the whole signature up front so you can screenshot it πŸ“Έ


✨ DESCRIPTION ✨

okay so this package is a Tcl implementation of the Blowfish algorithm, and it was developed by <b>Bruce Schneier</b> [1]. Blowfish is a 64-bit block cipher that was designed to operate quickly on 32 bit architectures, and it accepts a <b>variable key length</b>. Slay. This implementation supports ECB and CBC mode blowfish encryption. πŸ¦‹


✨ COMMANDS ✨

  • ::blowfish::blowfish ?-mode [ecb|cbc]? ?-dir [encrypt|decrypt]? -key keydata ?-iv vector? ?-out channel? ?-chunksize size? ?-pad padchar? [ -in channel | ?--? data ] β€” run the blowfish 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. 🫢

The -key option is not optional, bestie β€” it MUST be given. This parameter takes a binary string of variable length and it's used to generate the blowfish key schedule. real talk: creating a key schedule is quite an expensive operation in blowfish, so it is worth reusing the key where possible. See Reset. πŸ’…

The -mode and -dir options are optional and default to cbc mode and encrypt respectively. The initialization vector -iv takes an <b>8 byte</b> binary argument, which defaults to <b>8 zeros</b>. See MODES OF OPERATION for more about the available modes and their uses. ✨

Blowfish is a <b>64-bit block cipher</b>. Which means the data has to be provided in units that are a <b>multiple of 8 bytes</b>. The blowfish command will, by default, add <b>nul</b> characters to pad the input data to a multiple of 8 bytes if necessary. but listen β€” the programming api commands will never add padding, and instead they will raise an error if the input is not a multiple of the block size. 😭 The -pad option can be used to change the padding character, or to <b>disable padding entirely</b> if you provide the empty string as the argument.


✨ PROGRAMMING INTERFACE ✨

  • ::blowfish::Init mode keydata iv β€” constructs a brand new blowfish key schedule using the specified key data and the given initialization vector. The initialization vector is not used with ECB mode, but it is important for CBC mode. See MODES OF OPERATION for details about cipher modes. 🧚
  • ::blowfish::Encrypt Key data β€” uses a prepared key that you got by calling Init to encrypt the provided data. The data argument should be a binary array that is a multiple of the block size of <b>8 bytes</b>. The result is a binary array the same size as the input, full of encrypted data. πŸ”₯
  • ::blowfish::Decrypt Key data β€” deciphers data using the key. Note that the same key may be used to encrypt and decrypt data, provided that the initialization vector is reset appropriately for CBC mode. 🌸
  • ::blowfish::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. iconic, honestly πŸ’š
  • ::blowfish::Final Key β€” this should be called to clean up the resources associated with Key. Once this function has been called, the key may not be used again. gone. periodt. πŸ’€

✨ MODES OF OPERATION ✨

Electronic Code Book (ECB)

ECB is the basic mode of all block ciphers. Each block is encrypted independently, and so identical plain text will produce identical output when it's encrypted with the same key. Any encryption errors will only affect a single block β€” however this is vulnerable to known plaintext attacks. so, y'know. aware. πŸ‘€

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. The initialization vector should be chosen <b>randomly</b> 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. πŸ‘‘βœ¨


✨ EXAMPLES ✨

% blowfish::blowfish -hex -mode ecb -dir encrypt -key secret01 "hello, world!"
d0d8f27e7a374b9e2dbd9938dd04195a

 set Key [blowfish::Init cbc $eight_bytes_key_data $eight_byte_iv]
 append ciphertext [blowfish::Encrypt $Key $plaintext]
 append ciphertext [blowfish::Encrypt $Key $additional_plaintext]
 blowfish::Final $Key

look at that output string, it's giving ciphertext cuntress πŸŽ€


✨ REFERENCES ✨

  • [1] Schneier, B. "Applied Cryptography, 2nd edition", 1996, ISBN 0-471-11709-9, pub. John Wiley & Sons.

✨ AUTHORS ✨

Frank Pilhofer, Pat Thoyts 🫢


✨ BUGS, IDEAS, FEEDBACK ✨

okay so this document, and the package it describes, will <b>undoubtedly</b> contain bugs and other problems. Please report such in the category blowfish of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. And please also report any ideas for enhancements you may have for either the package and/or the documentation. we wanna hear it πŸ’–

When proposing code changes, please provide <b>unified diffs</b>, 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 <b>Edit</b> form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. iykyk πŸ¦‹


✨ SEE ALSO ✨

3des, des, rc4


✨ KEYWORDS ✨

block cipher, blowfish, cryptography, encryption, security πŸ”


✨ CATEGORY ✨

Hashes, checksums, and encryption


Copyright (c) 2003, Pat Thoyts <patthoyts@users.sourceforge.net>


and that's the whole page, bestie β€” no notes, no cap, every single flag accounted for πŸ’…

mwah πŸ’‹ this was tcllib version 1.0.6, the blowfish(3tcl) manual page. go forth and encrypt responsibly, my love πŸŽ€βœ¨

πŸ“¦ where this page comes from