From 78864a47aea345cdf731316df89feba06cb1a283 Mon Sep 17 00:00:00 2001 From: Samuel Lucas <63159663+samuel-lucas6@users.noreply.github.com> Date: Thu, 3 Jun 2021 15:50:09 +0100 Subject: [PATCH] Internals.md: Fix typos and reword a few bits. --- Internals.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Internals.md b/Internals.md index 74eda76..5b5df0e 100644 --- a/Internals.md +++ b/Internals.md @@ -1,20 +1,19 @@ # Internals -If you're wondering about how Picocrypt handles cryptography, you've come to the right place! This page will contain the technical details about the cryptographic schemes and formats used. +If you're wondering about how Picocrypt handles cryptography, you've come to the right place! This page contains the technical details about the cryptographic algorithms and file format. # Core Cryptography ## Encryption -Picocrypt uses these algorithms list of algorithms for encryption: -- XChaCha20 (IETF variant) -- Poly1305 +Picocrypt uses the following algorithms for encryption: +- XChaCha20-Poly1305 (IETF variant) - SHA3 - Argon2id -The first two of them are provided by Monocypher. Since Monocypher has been audited by Cure53, it's an extremely secure library. To bind Picocrypt (Go) to Monocypher (C), I created a binding called Monocypher-Go, which binds Go to C. For SHA3, Picocrypt uses Go's standard `golang.org/x/crypto/sha3`. For Argon2id, Picocrypt also uses Go's standard `golang.org/x/crypto/argon2`. +The first is provided by Monocypher, a library that has been audited by Cure53. To bind Picocrypt (written in Go) to Monocypher (written in C), I created a binding called Monocypher-Go. For SHA3, Picocrypt uses Go's built-in `golang.org/x/crypto/sha3`. For Argon2id, Picocrypt also uses Go's built-in `golang.org/x/crypto/argon2`. ### Here's how encryption works: -- An master key is generated by passing the user's password through Argon2id. If fast mode is enabled, Picocrypt uses Argon2id with 4 passes, 128 MiB of memory, and 4 threads. If fast mode is not enabled, Picocrypt uses much more resrouces, with 8 passes, 1 GiB of memory, and 8 threads. -- A SHA3-256 hash of the master key is generated and stored. This is used to let a user know if their password is correct. Note that this is a hash of the derived key, so it doesn't provide any vector for bruteforce. -- Encryption starts in 1 MiB chunks (1048576 bytes). For each chunk, a 24-byte nonce is generated through Go's `crypto/rand`. The nonce is appended into a list. The chunk is encrypted with the master key and unique nonce. The Poly1305 obtained after encrypting is appended to the chunk, which is then written to file. -- When all chunks are encrypted, the list of nonces are encrypted using the master key, and the resulting ciphertext and Poly1305 is written to the output. This is done not to protected the nonces themselves, but to add a layer of Poly1305 on top of the nonces to ensure that they can't be reordered. +- A master key is generated by hashing the user's password using Argon2id. If fast mode is enabled, Picocrypt uses Argon2id with 4 passes, 128 MiB of memory, and 4 threads. If fast mode is not enabled, Picocrypt uses 8 passes, 1 GiB of memory, and 8 threads. +- A SHA3-256 hash of the master key is generated and stored. This is used to let the user know if their password is correct. Note that this is a hash of the derived key, so it cannot be bruteforced. +- Encryption occurs in 1 MiB chunks (1048576 bytes). For each chunk, a 24-byte nonce is generated using Go's `crypto/rand`. The nonce is then appended to a list. The chunk is encrypted with the master key and the unique nonce. The Poly1305 tag is obtained after encryption and is appended to the chunk before the chunk is written to file. +- When all the chunks have been encrypted, the list of nonces is encrypted using the master key and written to the file. This is done to prevent the nonces from being reordered. # This is a work in progress...