mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
Merge pull request #5484 from laytan/hash-bytes-to-buffer-up-to-digest-size
crypto/hash: hash_bytes_to_buffer slice result to digest size
This commit is contained in:
@@ -21,8 +21,7 @@ hash_string :: proc(algorithm: Algorithm, data: string, allocator := context.all
|
|||||||
// in a newly allocated slice.
|
// in a newly allocated slice.
|
||||||
hash_bytes :: proc(algorithm: Algorithm, data: []byte, allocator := context.allocator) -> []byte {
|
hash_bytes :: proc(algorithm: Algorithm, data: []byte, allocator := context.allocator) -> []byte {
|
||||||
dst := make([]byte, DIGEST_SIZES[algorithm], allocator)
|
dst := make([]byte, DIGEST_SIZES[algorithm], allocator)
|
||||||
hash_bytes_to_buffer(algorithm, data, dst)
|
return hash_bytes_to_buffer(algorithm, data, dst)
|
||||||
return dst
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// hash_string_to_buffer will hash the given input and assign the
|
// hash_string_to_buffer will hash the given input and assign the
|
||||||
@@ -46,7 +45,7 @@ hash_bytes_to_buffer :: proc(algorithm: Algorithm, data, hash: []byte) -> []byte
|
|||||||
update(&ctx, data)
|
update(&ctx, data)
|
||||||
final(&ctx, hash)
|
final(&ctx, hash)
|
||||||
|
|
||||||
return hash
|
return hash[:DIGEST_SIZES[algorithm]]
|
||||||
}
|
}
|
||||||
|
|
||||||
// hash_stream will incrementally fully consume a stream, and return the
|
// hash_stream will incrementally fully consume a stream, and return the
|
||||||
|
|||||||
Reference in New Issue
Block a user