Getting started with Rust

November 21, 2018

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:

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.

  1. Install Visual C++ 2017 Build Tools from MS
  2. Instal Rust from rustup.rs
  3. ext install rust in vscode, to get the Rust extension
  4. cargo new --bin project to initialise a new Rust project
  5. code project to open the project in code
  6. 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. :-)