aboutsummaryrefslogtreecommitdiff
path: root/core/crypto/README.md
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2024-01-25 08:13:46 +0900
committerYawning Angel <yawning@schwanenlied.me>2024-02-07 00:37:18 +0900
commit00ab3beed9d403d15f4c9d365a7b00c0ce715717 (patch)
treed36504abc4a5a68ad191b4095ec60812f651bb69 /core/crypto/README.md
parentca10fc2d47990d3401b1fac8afeddc2c67df727b (diff)
core:crypto/hash: Add a generic higher level hash interface
There is a lot of code duplicated in convenience methods in each hash implementation, and having a generic hash type makes implementing higher-level constructs such as HMAC significantly easier down the road.
Diffstat (limited to 'core/crypto/README.md')
-rw-r--r--core/crypto/README.md78
1 files changed, 8 insertions, 70 deletions
diff --git a/core/crypto/README.md b/core/crypto/README.md
index adb815df4..1e4e41fb8 100644
--- a/core/crypto/README.md
+++ b/core/crypto/README.md
@@ -1,84 +1,22 @@
# crypto
-A cryptography library for the Odin language
+A cryptography library for the Odin language.
## Supported
-This library offers various algorithms implemented in Odin.
-Please see the chart below for some of the options.
-
-## Hashing algorithms
-
-| Algorithm | |
-|:-------------------------------------------------------------------------------------------------------------|:-----------------|
-| [BLAKE2B](https://datatracker.ietf.org/doc/html/rfc7693) | &#10004;&#65039; |
-| [BLAKE2S](https://datatracker.ietf.org/doc/html/rfc7693) | &#10004;&#65039; |
-| [SHA-2](https://csrc.nist.gov/csrc/media/publications/fips/180/2/archive/2002-08-01/documents/fips180-2.pdf) | &#10004;&#65039; |
-| [SHA-3](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf) | &#10004;&#65039; |
-| [SHAKE](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf) | &#10004;&#65039; |
-| [SM3](https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-02) | &#10004;&#65039; |
-| legacy/[Keccak](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf) | &#10004;&#65039; |
-| legacy/[MD5](https://datatracker.ietf.org/doc/html/rfc1321) | &#10004;&#65039; |
-| legacy/[SHA-1](https://datatracker.ietf.org/doc/html/rfc3174) | &#10004;&#65039; |
-
-#### High level API
-
-Each hash algorithm contains a procedure group named `hash`, or if the algorithm provides more than one digest size `hash_<size>`\*.
-Included in these groups are six procedures.
-- `hash_string` - Hash a given string and return the computed hash. Just calls `hash_bytes` internally
-- `hash_bytes` - Hash a given byte slice and return the computed hash
-- `hash_string_to_buffer` - Hash a given string and put the computed hash in the second proc parameter. Just calls `hash_bytes_to_buffer` internally
-- `hash_bytes_to_buffer` - Hash a given string and put the computed hash in the second proc parameter. The destination buffer has to be at least as big as the digest size of the hash
-- `hash_stream` - Takes a stream from io.Stream and returns the computed hash from it
-- `hash_file` - Takes a file handle and returns the computed hash from it. A second optional boolean parameter controls if the file is streamed (this is the default) or read at once (set to true)
-
-\* On some algorithms there is another part to the name, since they might offer control about additional parameters.
-For instance, `SHA-2` offers different sizes.
-Computing a 512-bit hash is therefore achieved by calling `sha2.hash_512(...)`.
-
-#### Low level API
-
-The above mentioned procedures internally call three procedures: `init`, `update` and `final`.
-You may also directly call them, if you wish.
-
-#### Example
-
-```odin
-package crypto_example
-
-// Import the desired package
-import "core:crypto/blake2b"
-
-main :: proc() {
- input := "foo"
-
- // Compute the hash, using the high level API
- computed_hash := blake2b.hash(input)
-
- // Variant that takes a destination buffer, instead of returning the computed hash
- hash := make([]byte, sha2.DIGEST_SIZE) // @note: Destination buffer has to be at least as big as the digest size of the hash
- blake2b.hash(input, hash[:])
-
- // Compute the hash, using the low level API
- ctx: blake2b.Context
- computed_hash_low: [blake2b.DIGEST_SIZE]byte
- blake2b.init(&ctx)
- blake2b.update(&ctx, transmute([]byte)input)
- blake2b.final(&ctx, computed_hash_low[:])
-}
-```
-For example uses of all available algorithms, please see the tests within `tests/core/crypto`.
+This package offers various algorithms implemented in Odin, along with
+useful helpers such as access to the system entropy source, and a
+constant-time byte comparison.
## Implementation considerations
- The crypto packages are not thread-safe.
- Best-effort is make to mitigate timing side-channels on reasonable
- architectures. Architectures that are known to be unreasonable include
+ architectures. Architectures that are known to be unreasonable include
but are not limited to i386, i486, and WebAssembly.
-- Some but not all of the packages attempt to santize sensitive data,
- however this is not done consistently through the library at the moment.
- As Thomas Pornin puts it "In general, such memory cleansing is a fool's
- quest."
+- The packages attempt to santize sensitive data, however this is, and
+ will remain a "best-effort" implementation decision. As Thomas Pornin
+ puts it "In general, such memory cleansing is a fool's quest."
- All of these packages have not received independent third party review.
## License