Monocypher is an easy-to-use crypto library. It is:
- Small. Sloccount counts under 2000 lines of code, small enough to allow audits. The binaries can be under 50KB, small enough for many embedded targets.
- Easy to deploy. Just add
monocypher.c
andmonocypher.h
to your project. They compile as C99 or C++ and are dedicated to the public domain (CC0-1.0, alternatively 2-clause BSD). - Portable. There are no dependencies, not even on libc.
- Honest. The API is small, consistent, and cannot fail on correct input.
- Direct. The abstractions are minimal. A developer with experience in applied cryptography can be productive in minutes.
- Fast. The primitives are fast to begin with and performance wasn’t needlessly sacrificed. Monocypher holds up pretty well against libsodium, despite being closer in size to TweetNaCl (see the more detailed benchmark)
Features
- Authenticated Encryption with XChaCha20 and Poly1305 (RFC 8439), with nonces big enough to be random. Regular ChaCha20 is also implemented.
- Hashing with BLAKE2b, which is as secure as SHA-3 and as fast as MD5.
- Password Hashing with Argon2i, which won the Password Hashing competition.
- Public Key Cryptography with X25519 (Diffie-Hellman key exchange). X25519 uses public keys to compute a symmetric key that can be used for authenticated encryption.
- Public Key Signatures with EdDSA (RFC 8032). By default, EdDSA uses BLAKE2b and Edwards25519. Ed25519 (SHA-512 and Edwards25519) is available as an option.
- Steganography support with Elligator 2. Elligator can hide ephemeral public keys as random noise, which is easier to hide from censors and other such adversaries.
- Password Authenticated Key Exchange (PAKE) support with Elligator 2 (map to point) and scalar inversion (Oblivious Pseudo-Random Function).
Getting started
Download the latest Monocypher and run the test suite:
$ tar -xzf monocypher-4.0.2.tar.gz
$ cd monocypher-4.0.2
$ make test
Optionally, you can generate and install binaries on your system:
$ make
$ sudo make install
Or you can just integrate Monocypher source files into your project:
$ cp src/monocypher.c path/to/your/source/folder
$ cp src/monocypher.h path/to/your/include/folder
Monocypher’s API is documented in the user manual. If you are not yet familiar with cryptography, please follow an introductory course. We currently recommend Crypto101.
Testimonials
Monocypher enabled me to develop Joulescope’s small microcontroller bootloader with secure firmware updates using modern cryptography. Monocypher is small, fast, easy to use, has no dependencies, and is excellent on microcontrollers.
Matt Liberty, Principal Engineer and creator of Joulescope
Jetperch LLC
We found monocypher very easy to integrate with the ArduPilot code. The resulting code size savings allowed us to fit support for secure boot into the existing bootloader sectors on many of the boards we support. The python bindings made writing the associated user tools very easy. Highly recommended!
Andrew Tridgell, ArduPilot Systems Lead
(If you would like to add your testimonial to the list, don’t hesitate to send us an email.)