mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
core/crypto/whirlpool: Remove, historical/exotic
This commit is contained in:
Vendored
-1
@@ -16,7 +16,6 @@ Wrappers for hashing algorithms have been added to match the API within the Odin
|
||||
| [SHA-3](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf) | ✔️ |
|
||||
| [SHAKE](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf) | ✔️ |
|
||||
| [SM3](https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-02) | ✔️ |
|
||||
| [Whirlpool](https://web.archive.org/web/20171129084214/http://www.larc.usp.br/~pbarreto/WhirlpoolPage.html) | ✔️ |
|
||||
|
||||
#### High level API
|
||||
Each hash algorithm contains a procedure group named `hash`, or if the algorithm provides more than one digest size `hash_<size>`.
|
||||
|
||||
Vendored
-1
@@ -74,7 +74,6 @@ HASH_SHA3_512 :: "SHA-3(512)"
|
||||
HASH_SHAKE_128 :: "SHAKE-128"
|
||||
HASH_SHAKE_256 :: "SHAKE-256"
|
||||
HASH_KECCAK_512 :: "Keccak-1600"
|
||||
HASH_WHIRLPOOL :: "Whirlpool"
|
||||
HASH_BLAKE2B :: "BLAKE2b"
|
||||
HASH_MD5 :: "MD5"
|
||||
HASH_SM3 :: "SM3"
|
||||
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
package vendor_whirlpool
|
||||
|
||||
/*
|
||||
Copyright 2021 zhibog
|
||||
Made available under the BSD-3 license.
|
||||
|
||||
List of contributors:
|
||||
zhibog: Initial implementation.
|
||||
|
||||
Interface for the WHIRLPOOL hashing algorithm.
|
||||
The hash will be computed via bindings to the Botan crypto library
|
||||
*/
|
||||
|
||||
import "core:os"
|
||||
import "core:io"
|
||||
|
||||
import botan "../bindings"
|
||||
|
||||
/*
|
||||
High level API
|
||||
*/
|
||||
|
||||
DIGEST_SIZE :: 64
|
||||
|
||||
// hash_string will hash the given input and return the
|
||||
// computed hash
|
||||
hash_string :: proc "contextless" (data: string) -> [DIGEST_SIZE]byte {
|
||||
return hash_bytes(transmute([]byte)(data))
|
||||
}
|
||||
|
||||
// hash_bytes will hash the given input and return the
|
||||
// computed hash
|
||||
hash_bytes :: proc "contextless" (data: []byte) -> [DIGEST_SIZE]byte {
|
||||
hash: [DIGEST_SIZE]byte
|
||||
ctx: botan.hash_t
|
||||
botan.hash_init(&ctx, botan.HASH_WHIRLPOOL, 0)
|
||||
botan.hash_update(ctx, len(data) == 0 ? nil : &data[0], uint(len(data)))
|
||||
botan.hash_final(ctx, &hash[0])
|
||||
botan.hash_destroy(ctx)
|
||||
return hash
|
||||
}
|
||||
|
||||
// hash_string_to_buffer will hash the given input and assign the
|
||||
// computed hash to the second parameter.
|
||||
// It requires that the destination buffer is at least as big as the digest size
|
||||
hash_string_to_buffer :: proc(data: string, hash: []byte) {
|
||||
hash_bytes_to_buffer(transmute([]byte)(data), hash)
|
||||
}
|
||||
|
||||
// hash_bytes_to_buffer will hash the given input and write the
|
||||
// computed hash into the second parameter.
|
||||
// It requires that the destination buffer is at least as big as the digest size
|
||||
hash_bytes_to_buffer :: proc(data, hash: []byte) {
|
||||
assert(len(hash) >= DIGEST_SIZE, "Size of destination buffer is smaller than the digest size")
|
||||
ctx: botan.hash_t
|
||||
botan.hash_init(&ctx, botan.HASH_WHIRLPOOL, 0)
|
||||
botan.hash_update(ctx, len(data) == 0 ? nil : &data[0], uint(len(data)))
|
||||
botan.hash_final(ctx, &hash[0])
|
||||
botan.hash_destroy(ctx)
|
||||
}
|
||||
|
||||
// hash_stream will read the stream in chunks and compute a
|
||||
// hash from its contents
|
||||
hash_stream :: proc(s: io.Stream) -> ([DIGEST_SIZE]byte, bool) {
|
||||
hash: [DIGEST_SIZE]byte
|
||||
ctx: botan.hash_t
|
||||
botan.hash_init(&ctx, botan.HASH_WHIRLPOOL, 0)
|
||||
buf := make([]byte, 512)
|
||||
defer delete(buf)
|
||||
i := 1
|
||||
for i > 0 {
|
||||
i, _ = io.read(s, buf)
|
||||
if i > 0 {
|
||||
botan.hash_update(ctx, len(buf) == 0 ? nil : &buf[0], uint(i))
|
||||
}
|
||||
}
|
||||
botan.hash_final(ctx, &hash[0])
|
||||
botan.hash_destroy(ctx)
|
||||
return hash, true
|
||||
}
|
||||
|
||||
// hash_file will read the file provided by the given handle
|
||||
// and compute a hash
|
||||
hash_file :: proc(hd: os.Handle, load_at_once := false) -> ([DIGEST_SIZE]byte, bool) {
|
||||
if !load_at_once {
|
||||
return hash_stream(os.stream_from_handle(hd))
|
||||
} else {
|
||||
if buf, ok := os.read_entire_file(hd); ok {
|
||||
return hash_bytes(buf[:]), ok
|
||||
}
|
||||
}
|
||||
return [DIGEST_SIZE]byte{}, false
|
||||
}
|
||||
|
||||
hash :: proc {
|
||||
hash_stream,
|
||||
hash_file,
|
||||
hash_bytes,
|
||||
hash_string,
|
||||
hash_bytes_to_buffer,
|
||||
hash_string_to_buffer,
|
||||
}
|
||||
|
||||
/*
|
||||
Low level API
|
||||
*/
|
||||
|
||||
Whirlpool_Context :: botan.hash_t
|
||||
|
||||
init :: proc "contextless" (ctx: ^botan.hash_t) {
|
||||
botan.hash_init(ctx, botan.HASH_WHIRLPOOL, 0)
|
||||
}
|
||||
|
||||
update :: proc "contextless" (ctx: ^botan.hash_t, data: []byte) {
|
||||
botan.hash_update(ctx^, len(data) == 0 ? nil : &data[0], uint(len(data)))
|
||||
}
|
||||
|
||||
final :: proc "contextless" (ctx: ^botan.hash_t, hash: []byte) {
|
||||
botan.hash_final(ctx^, &hash[0])
|
||||
botan.hash_destroy(ctx^)
|
||||
}
|
||||
Reference in New Issue
Block a user