Block Cipher Magma in Rust

I had some fun experimenting with symmetric cryptography using Rust.


In a recent project, I implemented the 28147-89 / RFC5830 cipher, a well-known encryption method in my home country, Uzbekistan, as well as in other nations across the Commonwealth of Independent States (CIS).


I implemented the cipher entirely from scratch using pure and safe Rust by following publicly available official references and test vectors.


During my exploration, I also experimented with parallel processing, leveraging the power of the 'rayon' crate to execute tasks concurrently.


  • On MacBook M1 Pro with 8+2 cores, the encryption speed was about 8.3 times faster.
  • On Intel i7-3770 with 4 cores, running Linux, the speed increased by about 4.5 times, all thanks to the power of parallel processing.


To visualize the output patterns of various cipher modes, I had a delightful companion - Ferris the crab.


Ferris the crab.
The original bitmap image
Encrypted in Electronic Codebook (ECB) Mode Encrypted in Cipher Block Chaining (CBC) Mode

As you see here, after ciphering in the ECB mode, Ferris remained as cute as ever, as anticipated.


Please note that ECB has weaknesses. It does not hide data patterns well and leaks information about the plaintext. ECB mode is not recommended for use in cryptographic protocols.


The source code is available on GitHub: https://github.com/sheroz/magma














IT / Coding / How-To


Other Topics