Math::...:ChaCha(3pm)

πŸ’– Math::...:ChaCha(3pm) πŸ’–

okay so bestie, you found the User Contributed Perl Documentation for this one β€” it's the Math::Prime::Util::ChaCha page, aka a Pure Perl ChaCha20 CSPRNG ✨ like, a whole cryptographically-secure random number generator, written in Perl, no cap 🫢


✨ VERSION ✨

Version 0.74 🌸 (yes she has a version number, she's a real one)


πŸŽ€ SYNOPSIS πŸŽ€

ngl, the original page leaves this section completely blank 🫠 no synopsis, no example, nothing. Just vibes. So we're honoring that β€” no invented code here, bestie, i'm not about to make stuff up 😌


πŸ¦‹ DESCRIPTION πŸ¦‹

It's a pure Perl implementation of ChaCha20 that comes with a CSPRNG interface. That's it. That's the whole description. Short, iconic, to the point πŸ’…


πŸ‘‘ FUNCTIONS πŸ‘‘

πŸ’œ csrand

She takes a binary string as her input and uses it to seed the internal CSPRNG. Give her your bytes, she gets the whole thing going 🌈

πŸ’œ srand

This one is a method for sieving the CSPRNG with a small value.

⚠️ heads up bestie: this is NOT secure. like, do not use it for anything that matters, okay? πŸ™ˆ it's for simulations and for emulating the system srand β€” that's the whole point of her.

How she behaves:

  • No argument? She chooses a random number, seeds with it, and hands the number back to you 🎁
  • One integer argument? She seeds with it and returns that number back to you πŸŽ€

πŸ’œ irand

Returns a random 32-bit integer πŸ”₯

πŸ’œ irand64

Returns a random 64-bit integer πŸ”₯πŸ”₯ (she's the tall one)

πŸ’œ random_bytes

Takes an unsigned number n as input and returns that many random bytes, all bundled up as a single binary string. So like random_bytes(16) β†’ 16 bytes of chaos in one string, slay πŸ’…


🌸 AUTHORS 🌸

Dana Jacobsen <dana@acm.org> β€” the icon, the moment, the whole reason this page exists πŸ‘‘


🌟 ACKNOWLEDGEMENTS 🌟

Daniel J. Bernstein wrote the ChaCha family of stream ciphers back in 2008, as an update to the popular Salsa20 cipher from 2005. the way he just kept iterating, king behavior fr fr πŸ‘‘

RFC7539: "ChaCha20 and Poly1305 for IETF Protocols" was used to create both the C and the Perl implementations. and the test vectors from that document are used here as well πŸ§ͺ✨ (test vectors, the unsung heroes)

For the final optimizations, ideas were borrowed from Christopher Madsen's Crypt::Salsa20 β€” specifically for how to best work around some of Perl's aggressive dynamic typing 😭 (perl, please). and fun fact: our core is still about 20% slower than Salsa20. not her being just a little bit behind, but she's still out here doing the thing πŸ’ͺ


Copyright 2017 by Dana Jacobsen <dana@acm.org> 🫢

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. periodt πŸ’…


and that's the whole page bestie!! this one's running on perl v5.42.3, dated 2026-08-20 β€” so if you're reading this from the future, hi, hope the randomness is random πŸŒˆβ­πŸ’œ

πŸ“¦ where this page comes from