DEV Community

skaunov
skaunov

Posted on

Cryptopals-25: use `edit` as keystream

Do you want a slightly simpler solution to #25 "Break "random access read/write" AES CTR"? Did you ever wanted to add a crate release (from git) that isn't at ?

As I mentioned on the previous page I was detailing challenge point and over-viewed few solutions. Usually I return back to existing solutions to see the alternatives and check my own solution sanity and correctness. This time was a bit different.

Surprisingly I didn't found my solution among those I viewed, so let me share it with you. Not to repeat common part in all of them, I just link a fresh write-up I liked, and quickly note that instead of getting the key and then deciphering with it, we can just feed our ciphertext to the edit function twice: as the one we want to edit (basically it will get us right length in most implementations) and the second time as "plaintext" we want to re-encrypt. (Offset should be 0, of course. So the key-stream would be aligned.) This simple trick/tweak will just apply the key-stream against ciphertext and as the result of "edit" we get plaintext.

Rust code of the solution: https://github.com/skaunov/challenge-25.

Bonus

I wondered of a clean way to import a particular version of crate from git, as the one I used isn't available from . And it turned out to be just a few lines to do it neatly.

[dependencies.ctr]
git = "https://github.com/RustCrypto/block-modes.git"
tag = "ctr-v0.9.1"
Enter fullscreen mode Exit fullscreen mode

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

đź‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay