Crypt:...Family(3pm)

πŸ’– NAME πŸ’–

Crypt::Eksblowfish::Family β€” the Eksblowfish cipher family, bestie. yes that's really the whole name. slay.


✨ SYNOPSIS ✨

okay so here's the whole vibe in one go, no cap:

use Crypt::Eksblowfish::Family;

$family = Crypt::Eksblowfish::Family->new_family(8, $salt);

$cost = $family->cost;
$salt = $family->salt;
$block_size = $family->blocksize;
$key_size = $family->keysize;
$cipher = $family->new($key);

πŸ¦‹ DESCRIPTION πŸ¦‹

An object of this class is literally an Eksblowfish cipher family. It's holding the family parameters β€” that's cost and salt β€” and the moment you combine it with a key, boom, you get an encryption function. If you want the whole tea on the Eksblowfish algorithm itself, go read Crypt::Eksblowfish. 🫢

The dream here is that an object of this class can slot into places like the -cipher parameter of Crypt::CBC. Normally that parameter is just the name of a class, like Crypt::Rijndael, and that class implements a block cipher algorithm, and it provides a new constructor that takes a key. Cute, right? πŸ™ˆ

But Eksblowfish said "not today", because the key alone is not sufficient. So the Eksblowfish family steps in and fills the role of the block cipher algorithm. That means you hand over a family object instead of a class name, and it's the family object that provides the new constructor. main character energy honestly πŸ‘‘

😭 Crypt::CBC 😭

Plot twist, and it's giving tragedy: Crypt::CBC itself has a problem, and the upshot is that this class can no longer be used with it the way it was originally intended. πŸ’€

Back when this class was designed, it worked with Crypt::CBC exactly as described above: an object of this class would be accepted by Crypt::CBC as a cipher algorithm, and Crypt::CBC would happily give it a key and encrypt using the resulting cipher object. Gorgeous. Flawless. But Crypt::CBC didn't realise it was dealing with a family object, so there was a risk that some future version might accidentally squash the object into a string, which would be, and I quote, of no use. 😭

Then in the course of discussion about regularising the use of cipher family objects, the author of Crypt::CBC got hold of the wrong end of the stick, and instead of putting this usage on a secure footing, they changed Crypt::CBC in a way that totally breaks it. not the glow up anyone asked for πŸ’€

So here's what Crypt::CBC does now: if you supply an object (rather than a class name) as the -cipher parameter, it means something completely different from usual. In that case the supplied object is used as the keyed cipher, instead of as a cipher algorithm that must be given a key. That completely bypasses all of Crypt::CBC's usual keying logic β€” the logic that can hash and salt a passphrase to generate the key. You could argue it's a useful feature, and sure, but it's a gross abuse of the -cipher parameter and a severe impediment to using family-keyed cipher algorithms. 🚩

Good news though: this class now provides a workaround. For the benefit of Crypt::CBC, and any other crypto plumbing that needs a keyable cipher algorithm to look like a Perl class (rather than an object), a family object of this class can in fact be reified as a class of its own. See the as_class method down below. πŸ‘‡


πŸŽ€ CONSTRUCTOR πŸŽ€

  • Crypt::Eksblowfish::Family->new_family(COST, SALT) β€” makes and returns an object representing the Eksblowfish cipher family you specified with those parameters. SALT is a family key and it must be exactly 16 octets, no more no less bestie. COST is an integer parameter controlling the expense of keying: the number of operations in key setup is proportional to 2^COST. so yeah, crank the cost and you're paying for it πŸ’…

🌸 METHODS 🌸

  • $family->cost β€” pulls out and returns the cost parameter.
  • $family->salt β€” pulls out and returns the salt parameter.
  • $family->blocksize β€” returns 8, because the Eksblowfish block size is 8 octets. iconic, consistent, we love her ✨
  • $family->keysize β€” returns 0, which means the key size is variable. This situation is handled specially by Crypt::CBC. iykyk 😌
  • $family->new(KEY) β€” does key setup on a fresh instance of the Eksblowfish algorithm and returns the keyed state. KEY can be any length from 1 octet to 72 octets inclusive. The object you get back is of class Crypt::Eksblowfish β€” for the encryption and decryption methods, go see Crypt::Eksblowfish. 🫢
⚠️ Important bestie: this method is called on a family object, not on the class Crypt::Eksblowfish::Family. don't @ me, that's just how it is πŸ™ˆ
  • $family->encrypt β€” this method nominally exists, purely to satisfy Crypt::CBC. It genuinely can't be used: it doesn't make any sense. she's there for appearances only πŸ’…
  • $family->as_class β€” generates and returns (the name of) a Perl class that behaves as a keyable cipher algorithm identical to this Eksblowfish cipher family. The same methods you can call as instance methods on $family can be called as class methods on that generated class. πŸͺ„

You should prefer to use the family object directly whenever you can. Aside from being a silly indirection, the classes generated by this method cannot be garbage-collected. 😭 This method exists only to cater to Crypt::CBC, which requires a keyable cipher algorithm to look like a Perl class, and won't operate correctly on one that looks like an object. it's giving hostage situation honestly, but here we are 🫠


πŸ‘€ SEE ALSO πŸ‘€

Crypt::CBC, Crypt::Eksblowfish


πŸ‘‘ AUTHOR πŸ‘‘

Andrew Main (Zefram) <zefram@fysh.org>


Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Andrew Main (Zefram) <zefram@fysh.org>


πŸ’– LICENSE πŸ’–

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole page bestie, ty for coming to my ted talk πŸŽ€βœ¨

signed off from perl v5.42.3, dated 2026-08-19, and lovingly filed under User Contributed Perl Documentation. mwah πŸ’‹

πŸ“¦ where this page comes from