Skip to content

ARM64-optimized implementation of the Rabbit stream cipher in C++ and assembly, with cross-verification between high-level and low-level code.

License

Notifications You must be signed in to change notification settings

zarkhodamoradi/rabbit-cipher-optimized

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‡ Rabbit Stream Cipher (C++ & ARM64 Assembly)

This project is a Rabbit stream cipher implementation in both C++ and ARM64 Assembly, designed for performance benchmarking and educational understanding of low-level cryptographic operations.


πŸš€ Features

  • Full implementation of Rabbit cipher key setup and encryption
  • Parallel C++ and ARM64 Assembly versions for comparison
  • Easy-to-read structure for learning or extending the cipher
  • Tested with sample plaintext and 128-bit key

🧠 What Is Rabbit Cipher?

Rabbit is a high-speed stream cipher designed for software applications. It was one of the finalists in the eSTREAM project and is known for its balance between performance and security.


πŸ—‚οΈ Project Structure

.
β”œβ”€β”€ main.cpp     # C++ implementation and test harness
β”œβ”€β”€ asm.s        # ARM64 Assembly implementation of key setup and encryption
β”œβ”€β”€ README.md    # You are here πŸš€

πŸ”§ Build Instructions

You'll need an ARM64 environment (e.g., Apple Silicon Mac or QEMU/VM with ARM64 Linux). Then:

# Assemble and link
as -o asm.o asm.s
g++ -o rabbit main.cpp asm.o
./rabbit

πŸ“Œ Usage

The main.cpp file contains two demos:

  • main1() uses the C++ implementation
  • main2() uses the Assembly implementation

Both perform the following:

  1. Encrypt the string "Hello, Rabbit Cipher!" using a 128-bit key.
  2. Print the encrypted hex bytes.
  3. Decrypt the ciphertext to recover the original plaintext.

πŸ“· Example Output

****************CPP****************
Original: Hello, Rabbit Cipher!
Encrypted: 3F 1A 9C ...
Decrypted: Hello, Rabbit Cipher!
****************ASM****************
Original: Hello, Rabbit Cipher!
Encrypted: 3F 1A 9C ...
Decrypted: Hello, Rabbit Cipher!

πŸ› οΈ Functions

In C++:

  • rabbit_key_setup – Initializes internal state with the key
  • rabbit_crypt – Encrypts or decrypts data using keystream XOR

In Assembly:

  • rabbit_key_setup_ – Optimized key setup (.global)
  • rabbit_crypt_ – Optimized stream encryption

🎯 Goals

  • Verify correctness and consistency between C++ and Assembly
  • Learn inner workings of Rabbit cipher and ARM64 calling conventions
  • Explore cryptographic implementation at the hardware level

πŸ“– References

About

ARM64-optimized implementation of the Rabbit stream cipher in C++ and assembly, with cross-verification between high-level and low-level code.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published