AtlatestRepositorysigil-crypto
sigil-crypto / tree / vendor / monocypherREADME.md
1
Monocypher2
----------4
Monocypher is an easy to use, easy to deploy, auditable crypto library5
written in portable C. It approaches the size of [TweetNaCl][] and the6
speed of [libsodium][].8
[Official site.](https://monocypher.org/) 9
[Official releases.](https://monocypher.org/download/)11
[libsodium]: https://libsodium.org12
[TweetNaCl]: https://tweetnacl.cr.yp.to/15
Features16
--------18
- [Authenticated Encryption][AEAD] with XChaCha20 and Poly130519
(RFC 8439).20
- [Hashing and key derivation][HASH] with BLAKE2b (and [SHA-512][]).21
- [Password Hashing][PWH] with Argon2.22
- [Public Key Cryptography][PKC] with X25519 key exchanges.23
- [Public Key Signatures][EDDSA] with EdDSA and [Ed25519][].24
- [Steganography and PAKE][STEG] with [Elligator 2][ELLI].26
[AEAD]: https://monocypher.org/manual/aead27
[HASH]: https://monocypher.org/manual/blake2b28
[SHA-512]: https://monocypher.org/manual/sha51229
[PWH]: https://monocypher.org/manual/argon230
[PKC]: https://monocypher.org/manual/x2551931
[EDDSA]: https://monocypher.org/manual/eddsa32
[Ed25519]: https://monocypher.org/manual/ed2551933
[STEG]: https://monocypher.org/manual/elligator34
[ELLI]: https://elligator.org37
Manual38
------40
The manual can be found at https://monocypher.org/manual/, and in the41
`doc/` folder.44
Installation45
------------47
### Option 1: grab the sources49
The easiest way to use Monocypher is to include `src/monocypher.h` and50
`src/monocypher.c` directly into your project. They compile as C (since51
C99) and C++ (since C++98).53
If you need the optional SHA-512 or Ed25519, grab54
`src/optional/monocypher-ed25519.h` and55
`src/optional/monocypher-ed25519.c` as well.57
### Option 2: grab the library59
Run `make`, then grab the `src/monocypher.h` header and either the60
`lib/libmonocypher.a` or `lib/libmonocypher.so` library. The default61
compiler is `gcc -std=c99`, and the default flags are `-pedantic -Wall62
-Wextra -O3 -march=native`. If they don't work on your platform, you63
can change them like this:65
$ make CC="clang -std=c11" CFLAGS="-O2"67
### Option 3: install it on your system69
Run `make`, then `make install` as root. This will install Monocypher in70
`/usr/local` by default. This can be changed with `PREFIX` and71
`DESTDIR`:73
$ make install PREFIX="/opt"75
Once installed, you may use `pkg-config` to compile and link your76
program. For instance:78
$ gcc program.c $(pkg-config monocypher --cflags) -c79
$ gcc program.o $(pkg-config monocypher --libs) -o program81
If for any reason you wish to avoid installing the man pages or the82
`pkg-config` file, you can use the following installation sub targets83
instead: `install-lib`, `install-doc`, and `install-pc`.86
Test suite87
----------89
$ make test91
It should display a nice printout of all the tests, ending with "All92
tests OK!". If you see "failure" or "Error" anywhere, something has gone93
wrong.95
*Do not* use Monocypher without running those tests at least once.97
The same test suite can be run under Clang sanitisers and Valgrind, and98
be checked for code coverage:100
$ tests/test.sh101
$ tests/coverage.sh104
### Serious auditing106
The code may be analysed more formally with [Frama-c][] and the107
[TIS interpreter][TIS]. To analyse the code with Frama-c, run:109
$ tests/formal-analysis.sh110
$ tests/frama-c.sh112
This will have Frama-c parse, and analyse the code, then launch a GUI.113
You must have Frama-c installed. See `frama-c.sh` for the recommended114
settings. To run the code under the TIS interpreter, run116
$ tests/formal-analysis.sh117
$ tis-interpreter.sh --cc -Dvolatile= tests/formal-analysis/*.c119
Notes:121
- `tis-interpreter.sh` is part of TIS. If it is not in your path,122
adjust the command accordingly.124
- The TIS interpreter sometimes fails to evaluate correct programs when125
they use the `volatile` keyword (which is only used as an attempt to126
prevent dead store elimination for memory wipes). The `-cc127
-Dvolatile=` option works around that bug by ignoring `volatile`128
altogether.130
[Frama-c]:https://frama-c.com/131
[TIS]: https://trust-in-soft.com/tis-interpreter/134
Customisation135
-------------137
Monocypher has optional compatibility with Ed25519. To have that, add138
`monocypher-ed25519.h` and `monocypher-ed25519.c` provided in139
`src/optional` to your project. If you compile or install Monocypher140
with the makefile, they will be automatically included.142
Monocypher also has the `BLAKE2_NO_UNROLLING` preprocessor flag, which143
is activated by compiling monocypher.c with the `-DBLAKE2_NO_UNROLLING`144
option.146
The `-DBLAKE2_NO_UNROLLING` option is a performance tweak. By default,147
Monocypher unrolls the BLAKE2b inner loop, because doing so is over 25%148
faster on modern processors. Some embedded processors however, run the149
unrolled loop _slower_ (possibly because of the cost of fetching 5KB of150
additional code). If you're using an embedded platform, try this151
option. The binary will be about 5KB smaller, and in some cases faster.153
The `MONOCYPHER_CPP_NAMESPACE` preprocessor definition allows C++ users154
who compile Monocypher as C++ to wrap it in a namespace. When it is not155
defined (the default), we assume Monocypher is compiled as C, and an156
`extern "C"` declaration is added when we detect that the header is157
included in C++ code.159
The `change-prefix.sh` script can rename all functions by replacing160
`crypto_` by a chosen prefix, so you can avoid name clashes. For161
instance, the following command changes all instances of `crypto_` by162
`foobar_` (note the absence of the underscore):164
./change-prefix.sh foobar