|
|
2 лет назад | |
|---|---|---|
| .. | ||
| _blake2 | 2 лет назад | |
| _fiat | 2 лет назад | |
| _sha3 | 2 лет назад | |
| blake2b | 2 лет назад | |
| blake2s | 2 лет назад | |
| chacha20 | 2 лет назад | |
| chacha20poly1305 | 2 лет назад | |
| legacy | 2 лет назад | |
| poly1305 | 2 лет назад | |
| sha2 | 2 лет назад | |
| sha3 | 2 лет назад | |
| shake | 2 лет назад | |
| siphash | 2 лет назад | |
| sm3 | 2 лет назад | |
| x25519 | 2 лет назад | |
| README.md | 2 лет назад | |
| crypto.odin | 2 лет назад | |
| rand_generic.odin | 2 лет назад | |
| rand_js.odin | 2 лет назад | |
| rand_linux.odin | 2 лет назад | |
| rand_openbsd.odin | 3 лет назад | |
| rand_windows.odin | 3 лет назад | |
A cryptography library for the Odin language
This library offers various algorithms implemented in Odin. Please see the chart below for some of the options.
| Algorithm | |
|---|---|
| BLAKE2B | ✔️ |
| BLAKE2S | ✔️ |
| SHA-2 | ✔️ |
| SHA-3 | ✔️ |
| SHAKE | ✔️ |
| SM3 | ✔️ |
| legacy/Keccak | ✔️ |
| legacy/MD5 | ✔️ |
| legacy/SHA-1 | ✔️ |
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 internallyhash_bytes - Hash a given byte slice and return the computed hashhash_string_to_buffer - Hash a given string and put the computed hash in the second proc parameter. Just calls hash_bytes_to_buffer internallyhash_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 hashhash_stream - Takes a stream from io.Stream and returns the computed hash from ithash_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(...).
The above mentioned procedures internally call three procedures: init, update and final.
You may also directly call them, if you wish.
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 library is made available under the BSD-3 license.