mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-04 20:17:48 +00:00
botan
A wrapper for the Botan crypto library
Supported
This library offers full bindings for everything exposed by Botan's FFI.
Wrappers for hashing algorithms have been added to match the API within the Odin core:crypto library.
Hashing algorithms
| Algorithm | |
|---|---|
| BLAKE2B | ✔️ |
| GOST | ✔️ |
| Keccak | ✔️ |
| MD4 | ✔️ |
| MD5 | ✔️ |
| RIPEMD-160 | ✔️ |
| SHA-1 | ✔️ |
| SHA-2 | ✔️ |
| SHA-3 | ✔️ |
| SHAKE | ✔️ |
| Skein-512 | ✔️ |
| SM3 | ✔️ |
| Streebog | ✔️ |
| Tiger | ✔️ |
| Whirlpool | ✔️ |
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 four procedures.
hash_string- Hash a given string and return the computed hash. Just callshash_bytesinternallyhash_bytes- Hash a given byte slice and return the computed 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)
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
package crypto_example
// Import the desired package
import "vendor:botan/md4"
main :: proc() {
input := "foo"
// Compute the hash, using the high level API
computed_hash := md4.hash(input)
// Compute the hash, using the low level API
// @note: Botan's structs are opaque by design, they don't expose any fields
ctx: md4.Md4_Context
computed_hash_low: [16]byte
md4.init(&ctx)
md4.update(&ctx, transmute([]byte)input)
md4.final(&ctx, computed_hash_low[:])
}
For example uses of all available algorithms, please see the tests within tests/vendor/botan.
License
This library is made available under the BSD-3 license.