I plan to finally do all of the Matasano cryptopals challenges, to improve my practical knowledge of cryptography and how to attack cryptographic implementations, building on the limited of theory I already know. Cryptopals suggests the challenges are a good opportunity to learn a new language and I have been meaning to learn Rust for some time. I’m sure someone has already done cryptopals in Rust, and probably posted solutions to Github, so it would be cool to compare my eventual solutions to whatever is out there and improve my Rust.
What is Rust?
“Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.”
It has a few really cool features of a modern programming language such as:
- zero-cost abstractions
- move semantics
- guaranteed memory safety
- threads without data races
- trait-based generics
- pattern matching
- type inference
- minimal runtime
- efficient C bindings
The guaranteed memory safety (“guaranteed” only when writing “safe rust”, more on that in a later post) are interesting to me as someone who likes to learn about security. Some entire bug classes are (supposedly) rendered impossible through safe rust, which in my opinion is a positive step towards improving systematically improving security in programming. Rust also borrows some great features from functional languages like Haskell, including pattern matching, higher-order functions, type classes and algebraic types. I like Haskell from an academic perspective, and I hope Rust can satisfy that aspect while also being extremely performant.
Getting started
I’m using vscode on Windows 10 at the moment, so instructions below are for this setup.
- Install Visual C++ 2017 Build Tools from MS
- Instal Rust from rustup.rs
ext install rust
in vscode, to get the Rust extensioncargo new --bin project
to initialise a new Rust projectcode project
to open the project in code- Install RLS when prompted by vscode, and reload
Building code
In vscode, you can build with ctrl + shift + b
alternatively, ctrl + '
to open a terminal, then cargo build
Running code
ctrl + '
to open a terminal, then cargo run
to run the project
What is Cargo?
Cargo is Rust’s build system and package manager. It mainly handles, building projects, downloading dependencies, and building dependencies. Cargo files live in the project root, and are named Cargo.toml
Hello World!
I guess no post about learning a new language is complete without the obligatory hello world function. So in Rust:
fn main() {
println!("Hello, world!");
}
Save and use the instructions for building and running above. :-)
>> Home