Documentation.

This commit is contained in:
Didactic Drunk 2019-07-09 00:42:56 -07:00
parent 96b215cf54
commit fc60839d5b
6 changed files with 12 additions and 15 deletions

View File

@ -68,15 +68,15 @@ Several features in libsodium are already provided by Crystal:
| --- | --- | | --- | --- |
| Only use `CryptoBox::SecretKey` `Sign::SecretKey` `SecretBox` | I don't know much about crypto. | | Only use `CryptoBox::SecretKey` `Sign::SecretKey` `SecretBox` | I don't know much about crypto. |
| [`Sodium::CryptoBox::SecretKey`](https://didactic-drunk.github.io/sodium.cr/Sodium/CryptoBox/SecretKey.html) .box | I want to encrypt + authenticate data using public key encryption. | | [`Sodium::CryptoBox::SecretKey`](https://didactic-drunk.github.io/sodium.cr/Sodium/CryptoBox/SecretKey.html) .box | I want to encrypt + authenticate data using public key encryption. |
| [`Sodium::Sign::SecretKey`](https://didactic-drunk.github.io/sodium.cr/Sodium/CryptoBox/PublicKey.html) .encrypt | I want anonymously send encrypted data. (No authentication) | | [`Sodium::CryptoBox::SecretKey`](https://didactic-drunk.github.io/sodium.cr/Sodium/CryptoBox/PublicKey.html) .encrypt | I want anonymously send encrypted data. (No signatures) |
| [`Sodium::Sign::SecretKey`](https://didactic-drunk.github.io/sodium.cr/Sodium/Sign/SecretKey.html) | I want to sign or verify messages without encryption. | | [`Sodium::Sign::SecretKey`](https://didactic-drunk.github.io/sodium.cr/Sodium/Sign/SecretKey.html) | I want to sign or verify messages. (No encryption) |
| [`Sodium::SecretBox`](https://didactic-drunk.github.io/sodium.cr/Sodium/SecretBox.html) | I have a shared key and want to encrypt + authenticate data. | | [`Sodium::SecretBox`](https://didactic-drunk.github.io/sodium.cr/Sodium/SecretBox.html) | I have a shared key and want to encrypt + authenticate data. |
| AEAD | I have a shared key and want encrypt + authenticate streamed data. (Not implemented yet) | | [`Sodium::Cipher::SecretStream`](https://didactic-drunk.github.io/sodium.cr/Sodium/Cipher/SecretStream/XChaCha20Poly1305.html), AEAD | I have a shared key and want encrypt + authenticate streamed data. |
| [`Sodium::Digest::Blake2b`](https://didactic-drunk.github.io/sodium.cr/Sodium/Digest::Blake2b.html) | I want to hash data fast and securely. | | [`Sodium::Digest::Blake2b`](https://didactic-drunk.github.io/sodium.cr/Sodium/Digest::Blake2b.html) | I want to hash data fast and securely. |
| `Sodium::Digest::SipHash` | I want to hash data really fast and less securely. (Not implemented yet) | | `Sodium::Digest::SipHash` | I want to hash data really fast and less securely. (Not implemented yet) |
| `Sodium::Pwhash` | I want to hash a password and store it. | | [`Sodium::Pwhash`](https://didactic-drunk.github.io/sodium.cr/Sodium/Pwhash.html) | I want to hash a password and store it. |
| `Sodium::Pwhash` | I want to derive a key from a password. | | [`Sodium::Pwhash`](https://didactic-drunk.github.io/sodium.cr/Sodium/Pwhash.html) | I want to derive a key from a password. |
| `Sodium::Kdf` | I have a high quality master key and want to make subkeys. | | [`Sodium::Kdf`](https://didactic-drunk.github.io/sodium.cr/Sodium/Kdf.html) | I have a high quality master key and want to make subkeys. |
| [`Sodium::Cipher::Chalsa`](https://didactic-drunk.github.io/sodium.cr/Sodium/Cipher/Chalsa.html) | What goes with guacamole? | | [`Sodium::Cipher::Chalsa`](https://didactic-drunk.github.io/sodium.cr/Sodium/Cipher/Chalsa.html) | What goes with guacamole? |
| Everything else | I want to design my own crypto protocol and probably do it wrong. | | Everything else | I want to design my own crypto protocol and probably do it wrong. |

View File

@ -0,0 +1,3 @@
# Use Sodium::Cipher::SecretStream::XChaCha20Poly1305 or SecretBox
module Sodium::Cipher
end

View File

@ -79,9 +79,9 @@ module Sodium::Cipher
# [Libsodium Secret Stream API](https://libsodium.gitbook.io/doc/secret-key_cryptography/secretstream) # [Libsodium Secret Stream API](https://libsodium.gitbook.io/doc/secret-key_cryptography/secretstream)
# #
# This class mimicks the OpenSSL::Cipher interface with minor differences. # This class mimicks the OpenSSL::Cipher interface with minor differences.
# * every .update is it's own authenticated message. Unlike OpenSSL this class doesn't buffer data. You must handle the framing yourself.
# * .header must be called for encryption before calling .update # * .header must be called for encryption before calling .update
# * .header= must be called for decryption with the data returned from .header before calling .update # * .header= must be called for decryption with the data returned from .header before calling .update
# * every .update is it's own authenticated message. Unlike OpenSSL this class doesn't buffer data. You must handle the framing yourself.
# * A tag may be set before encrypting and is set after calling .update when decrypting. # * A tag may be set before encrypting and is set after calling .update when decrypting.
# * .additional may be set before encrypting and must be set before decrypting. # * .additional may be set before encrypting and must be set before decrypting.
# #

View File

@ -5,7 +5,6 @@ require "./wipe"
module Sodium module Sodium
# Key derivation function # Key derivation function
# #
# WARNING: This class takes ownership of any key material passed to it.
# Read **each** constructor WARNING for differences in usage. # Read **each** constructor WARNING for differences in usage.
# #
# Usage: # Usage:
@ -25,7 +24,8 @@ module Sodium
# Use an existing KDF key. # Use an existing KDF key.
# #
# Optionally erases bytes after copying if erase is set # * Copies key to a new SecureBuffer
# * Optionally erases bytes after copying if erase is set
def initialize(bytes : Bytes, erase = false) def initialize(bytes : Bytes, erase = false)
if bytes.bytesize != KEY_SIZE if bytes.bytesize != KEY_SIZE
raise ArgumentError.new("bytes must be #{KEY_SIZE}, got #{bytes.bytesize}") raise ArgumentError.new("bytes must be #{KEY_SIZE}, got #{bytes.bytesize}")
@ -35,9 +35,6 @@ module Sodium
end end
# Use an existing KDF SecureBuffer key. # Use an existing KDF SecureBuffer key.
#
# WARNING: This class takes ownership of any key material passed to it.
# If you don't want this behavior pass a duplicate of the key to initialize().
def initialize(@sbuf : SecureBuffer) def initialize(@sbuf : SecureBuffer)
if @sbuf.bytesize != KEY_SIZE if @sbuf.bytesize != KEY_SIZE
raise ArgumentError.new("bytes must be #{KEY_SIZE}, got #{sbuf.bytesize}") raise ArgumentError.new("bytes must be #{KEY_SIZE}, got #{sbuf.bytesize}")

View File

@ -5,8 +5,6 @@ require "./nonce"
module Sodium module Sodium
# [https://libsodium.gitbook.io/doc/secret-key_cryptography](https://libsodium.gitbook.io/doc/secret-key_cryptography) # [https://libsodium.gitbook.io/doc/secret-key_cryptography](https://libsodium.gitbook.io/doc/secret-key_cryptography)
# #
# WARNING: This class takes ownership of any key material passed to it.
# If you don't want this behavior pass a duplicate of the key/seed to initialize().
# #
# ```crystal # ```crystal
# key = Sodium::SecretBox.new # key = Sodium::SecretBox.new

View File

@ -5,7 +5,6 @@ require "./public_key"
module Sodium module Sodium
# Key used for signing/verification only. # Key used for signing/verification only.
# #
# WARNING: This class takes ownership of any key material passed to it.
# If you don't want this behavior pass a duplicate of the key/seed to initialize(). # If you don't want this behavior pass a duplicate of the key/seed to initialize().
# #
# Usage: # Usage: