core/crypto/sha3: API cleanup

- sha3.Sha3_Context -> sha3.Context
This commit is contained in:
Yawning Angel
2023-11-17 19:31:51 +09:00
parent 92aad90c6b
commit b8f9deb3d8
2 changed files with 120 additions and 124 deletions
+60 -52
View File
@@ -35,11 +35,11 @@ hash_string_224 :: proc(data: string) -> [DIGEST_SIZE_224]byte {
// computed hash // computed hash
hash_bytes_224 :: proc(data: []byte) -> [DIGEST_SIZE_224]byte { hash_bytes_224 :: proc(data: []byte) -> [DIGEST_SIZE_224]byte {
hash: [DIGEST_SIZE_224]byte hash: [DIGEST_SIZE_224]byte
ctx: _sha3.Sha3_Context ctx: Context
ctx.mdlen = DIGEST_SIZE_224 ctx.mdlen = DIGEST_SIZE_224
_sha3.init(&ctx) init(&ctx)
_sha3.update(&ctx, data) update(&ctx, data)
_sha3.final(&ctx, hash[:]) final(&ctx, hash[:])
return hash return hash
} }
@@ -54,30 +54,32 @@ hash_string_to_buffer_224 :: proc(data: string, hash: []byte) {
// computed hash into the second parameter. // computed hash into the second parameter.
// It requires that the destination buffer is at least as big as the digest size // It requires that the destination buffer is at least as big as the digest size
hash_bytes_to_buffer_224 :: proc(data, hash: []byte) { hash_bytes_to_buffer_224 :: proc(data, hash: []byte) {
ctx: _sha3.Sha3_Context ctx: Context
ctx.mdlen = DIGEST_SIZE_224 ctx.mdlen = DIGEST_SIZE_224
_sha3.init(&ctx) init(&ctx)
_sha3.update(&ctx, data) update(&ctx, data)
_sha3.final(&ctx, hash) final(&ctx, hash)
} }
// hash_stream_224 will read the stream in chunks and compute a // hash_stream_224 will read the stream in chunks and compute a
// hash from its contents // hash from its contents
hash_stream_224 :: proc(s: io.Stream) -> ([DIGEST_SIZE_224]byte, bool) { hash_stream_224 :: proc(s: io.Stream) -> ([DIGEST_SIZE_224]byte, bool) {
hash: [DIGEST_SIZE_224]byte hash: [DIGEST_SIZE_224]byte
ctx: _sha3.Sha3_Context ctx: Context
ctx.mdlen = DIGEST_SIZE_224 ctx.mdlen = DIGEST_SIZE_224
_sha3.init(&ctx) init(&ctx)
buf := make([]byte, 512) buf := make([]byte, 512)
defer delete(buf) defer delete(buf)
read := 1 read := 1
for read > 0 { for read > 0 {
read, _ = io.read(s, buf) read, _ = io.read(s, buf)
if read > 0 { if read > 0 {
_sha3.update(&ctx, buf[:read]) update(&ctx, buf[:read])
} }
} }
_sha3.final(&ctx, hash[:]) final(&ctx, hash[:])
return hash, true return hash, true
} }
@@ -113,11 +115,11 @@ hash_string_256 :: proc(data: string) -> [DIGEST_SIZE_256]byte {
// computed hash // computed hash
hash_bytes_256 :: proc(data: []byte) -> [DIGEST_SIZE_256]byte { hash_bytes_256 :: proc(data: []byte) -> [DIGEST_SIZE_256]byte {
hash: [DIGEST_SIZE_256]byte hash: [DIGEST_SIZE_256]byte
ctx: _sha3.Sha3_Context ctx: Context
ctx.mdlen = DIGEST_SIZE_256 ctx.mdlen = DIGEST_SIZE_256
_sha3.init(&ctx) init(&ctx)
_sha3.update(&ctx, data) update(&ctx, data)
_sha3.final(&ctx, hash[:]) final(&ctx, hash[:])
return hash return hash
} }
@@ -132,30 +134,32 @@ hash_string_to_buffer_256 :: proc(data: string, hash: []byte) {
// computed hash into the second parameter. // computed hash into the second parameter.
// It requires that the destination buffer is at least as big as the digest size // It requires that the destination buffer is at least as big as the digest size
hash_bytes_to_buffer_256 :: proc(data, hash: []byte) { hash_bytes_to_buffer_256 :: proc(data, hash: []byte) {
ctx: _sha3.Sha3_Context ctx: Context
ctx.mdlen = DIGEST_SIZE_256 ctx.mdlen = DIGEST_SIZE_256
_sha3.init(&ctx) init(&ctx)
_sha3.update(&ctx, data) update(&ctx, data)
_sha3.final(&ctx, hash) final(&ctx, hash)
} }
// hash_stream_256 will read the stream in chunks and compute a // hash_stream_256 will read the stream in chunks and compute a
// hash from its contents // hash from its contents
hash_stream_256 :: proc(s: io.Stream) -> ([DIGEST_SIZE_256]byte, bool) { hash_stream_256 :: proc(s: io.Stream) -> ([DIGEST_SIZE_256]byte, bool) {
hash: [DIGEST_SIZE_256]byte hash: [DIGEST_SIZE_256]byte
ctx: _sha3.Sha3_Context ctx: Context
ctx.mdlen = DIGEST_SIZE_256 ctx.mdlen = DIGEST_SIZE_256
_sha3.init(&ctx) init(&ctx)
buf := make([]byte, 512) buf := make([]byte, 512)
defer delete(buf) defer delete(buf)
read := 1 read := 1
for read > 0 { for read > 0 {
read, _ = io.read(s, buf) read, _ = io.read(s, buf)
if read > 0 { if read > 0 {
_sha3.update(&ctx, buf[:read]) update(&ctx, buf[:read])
} }
} }
_sha3.final(&ctx, hash[:]) final(&ctx, hash[:])
return hash, true return hash, true
} }
@@ -191,11 +195,11 @@ hash_string_384 :: proc(data: string) -> [DIGEST_SIZE_384]byte {
// computed hash // computed hash
hash_bytes_384 :: proc(data: []byte) -> [DIGEST_SIZE_384]byte { hash_bytes_384 :: proc(data: []byte) -> [DIGEST_SIZE_384]byte {
hash: [DIGEST_SIZE_384]byte hash: [DIGEST_SIZE_384]byte
ctx: _sha3.Sha3_Context ctx: Context
ctx.mdlen = DIGEST_SIZE_384 ctx.mdlen = DIGEST_SIZE_384
_sha3.init(&ctx) init(&ctx)
_sha3.update(&ctx, data) update(&ctx, data)
_sha3.final(&ctx, hash[:]) final(&ctx, hash[:])
return hash return hash
} }
@@ -210,30 +214,32 @@ hash_string_to_buffer_384 :: proc(data: string, hash: []byte) {
// computed hash into the second parameter. // computed hash into the second parameter.
// It requires that the destination buffer is at least as big as the digest size // It requires that the destination buffer is at least as big as the digest size
hash_bytes_to_buffer_384 :: proc(data, hash: []byte) { hash_bytes_to_buffer_384 :: proc(data, hash: []byte) {
ctx: _sha3.Sha3_Context ctx: Context
ctx.mdlen = DIGEST_SIZE_384 ctx.mdlen = DIGEST_SIZE_384
_sha3.init(&ctx) init(&ctx)
_sha3.update(&ctx, data) update(&ctx, data)
_sha3.final(&ctx, hash) final(&ctx, hash)
} }
// hash_stream_384 will read the stream in chunks and compute a // hash_stream_384 will read the stream in chunks and compute a
// hash from its contents // hash from its contents
hash_stream_384 :: proc(s: io.Stream) -> ([DIGEST_SIZE_384]byte, bool) { hash_stream_384 :: proc(s: io.Stream) -> ([DIGEST_SIZE_384]byte, bool) {
hash: [DIGEST_SIZE_384]byte hash: [DIGEST_SIZE_384]byte
ctx: _sha3.Sha3_Context ctx: Context
ctx.mdlen = DIGEST_SIZE_384 ctx.mdlen = DIGEST_SIZE_384
_sha3.init(&ctx) init(&ctx)
buf := make([]byte, 512) buf := make([]byte, 512)
defer delete(buf) defer delete(buf)
read := 1 read := 1
for read > 0 { for read > 0 {
read, _ = io.read(s, buf) read, _ = io.read(s, buf)
if read > 0 { if read > 0 {
_sha3.update(&ctx, buf[:read]) update(&ctx, buf[:read])
} }
} }
_sha3.final(&ctx, hash[:]) final(&ctx, hash[:])
return hash, true return hash, true
} }
@@ -269,11 +275,11 @@ hash_string_512 :: proc(data: string) -> [DIGEST_SIZE_512]byte {
// computed hash // computed hash
hash_bytes_512 :: proc(data: []byte) -> [DIGEST_SIZE_512]byte { hash_bytes_512 :: proc(data: []byte) -> [DIGEST_SIZE_512]byte {
hash: [DIGEST_SIZE_512]byte hash: [DIGEST_SIZE_512]byte
ctx: _sha3.Sha3_Context ctx: Context
ctx.mdlen = DIGEST_SIZE_512 ctx.mdlen = DIGEST_SIZE_512
_sha3.init(&ctx) init(&ctx)
_sha3.update(&ctx, data) update(&ctx, data)
_sha3.final(&ctx, hash[:]) final(&ctx, hash[:])
return hash return hash
} }
@@ -288,30 +294,32 @@ hash_string_to_buffer_512 :: proc(data: string, hash: []byte) {
// computed hash into the second parameter. // computed hash into the second parameter.
// It requires that the destination buffer is at least as big as the digest size // It requires that the destination buffer is at least as big as the digest size
hash_bytes_to_buffer_512 :: proc(data, hash: []byte) { hash_bytes_to_buffer_512 :: proc(data, hash: []byte) {
ctx: _sha3.Sha3_Context ctx: Context
ctx.mdlen = DIGEST_SIZE_512 ctx.mdlen = DIGEST_SIZE_512
_sha3.init(&ctx) init(&ctx)
_sha3.update(&ctx, data) update(&ctx, data)
_sha3.final(&ctx, hash) final(&ctx, hash)
} }
// hash_stream_512 will read the stream in chunks and compute a // hash_stream_512 will read the stream in chunks and compute a
// hash from its contents // hash from its contents
hash_stream_512 :: proc(s: io.Stream) -> ([DIGEST_SIZE_512]byte, bool) { hash_stream_512 :: proc(s: io.Stream) -> ([DIGEST_SIZE_512]byte, bool) {
hash: [DIGEST_SIZE_512]byte hash: [DIGEST_SIZE_512]byte
ctx: _sha3.Sha3_Context ctx: Context
ctx.mdlen = DIGEST_SIZE_512 ctx.mdlen = DIGEST_SIZE_512
_sha3.init(&ctx) init(&ctx)
buf := make([]byte, 512) buf := make([]byte, 512)
defer delete(buf) defer delete(buf)
read := 1 read := 1
for read > 0 { for read > 0 {
read, _ = io.read(s, buf) read, _ = io.read(s, buf)
if read > 0 { if read > 0 {
_sha3.update(&ctx, buf[:read]) update(&ctx, buf[:read])
} }
} }
_sha3.final(&ctx, hash[:]) final(&ctx, hash[:])
return hash, true return hash, true
} }
@@ -341,16 +349,16 @@ hash_512 :: proc {
Low level API Low level API
*/ */
Sha3_Context :: _sha3.Sha3_Context Context :: _sha3.Sha3_Context
init :: proc(ctx: ^_sha3.Sha3_Context) { init :: proc(ctx: ^Context) {
_sha3.init(ctx) _sha3.init(ctx)
} }
update :: proc(ctx: ^_sha3.Sha3_Context, data: []byte) { update :: proc(ctx: ^Context, data: []byte) {
_sha3.update(ctx, data) _sha3.update(ctx, data)
} }
final :: proc(ctx: ^_sha3.Sha3_Context, hash: []byte) { final :: proc(ctx: ^Context, hash: []byte) {
_sha3.final(ctx, hash) _sha3.final(ctx, hash)
} }
+52 -64
View File
@@ -35,11 +35,10 @@ hash_string_224 :: proc(data: string) -> [DIGEST_SIZE_224]byte {
// computed hash // computed hash
hash_bytes_224 :: proc(data: []byte) -> [DIGEST_SIZE_224]byte { hash_bytes_224 :: proc(data: []byte) -> [DIGEST_SIZE_224]byte {
hash: [DIGEST_SIZE_224]byte hash: [DIGEST_SIZE_224]byte
ctx: botan.hash_t ctx: Context
botan.hash_init(&ctx, botan.HASH_SHA3_224, 0) init(&ctx, hash_size = 224)
botan.hash_update(ctx, len(data) == 0 ? nil : &data[0], uint(len(data))) update(&ctx, data)
botan.hash_final(ctx, &hash[0]) final(&ctx, hash[:])
botan.hash_destroy(ctx)
return hash return hash
} }
@@ -55,30 +54,28 @@ hash_string_to_buffer_224 :: proc(data: string, hash: []byte) {
// It requires that the destination buffer is at least as big as the digest size // It requires that the destination buffer is at least as big as the digest size
hash_bytes_to_buffer_224 :: proc(data, hash: []byte) { hash_bytes_to_buffer_224 :: proc(data, hash: []byte) {
assert(len(hash) >= DIGEST_SIZE_224, "Size of destination buffer is smaller than the digest size") assert(len(hash) >= DIGEST_SIZE_224, "Size of destination buffer is smaller than the digest size")
ctx: botan.hash_t ctx: Context
botan.hash_init(&ctx, botan.HASH_SHA3_224, 0) init(&ctx, hash_size = 224)
botan.hash_update(ctx, len(data) == 0 ? nil : &data[0], uint(len(data))) update(&ctx, data)
botan.hash_final(ctx, &hash[0]) final(&ctx, hash[:])
botan.hash_destroy(ctx)
} }
// hash_stream_224 will read the stream in chunks and compute a // hash_stream_224 will read the stream in chunks and compute a
// hash from its contents // hash from its contents
hash_stream_224 :: proc(s: io.Stream) -> ([DIGEST_SIZE_224]byte, bool) { hash_stream_224 :: proc(s: io.Stream) -> ([DIGEST_SIZE_224]byte, bool) {
hash: [DIGEST_SIZE_224]byte hash: [DIGEST_SIZE_224]byte
ctx: botan.hash_t ctx: Context
botan.hash_init(&ctx, botan.HASH_SHA3_224, 0) init(&ctx, hash_size = 224)
buf := make([]byte, 512) buf := make([]byte, 512)
defer delete(buf) defer delete(buf)
i := 1 i := 1
for i > 0 { for i > 0 {
i, _ = io.read(s, buf) i, _ = io.read(s, buf)
if i > 0 { if i > 0 {
botan.hash_update(ctx, len(buf) == 0 ? nil : &buf[0], uint(i)) update(&ctx, buf[:i])
} }
} }
botan.hash_final(ctx, &hash[0]) final(&ctx, hash[:])
botan.hash_destroy(ctx)
return hash, true return hash, true
} }
@@ -114,11 +111,10 @@ hash_string_256 :: proc(data: string) -> [DIGEST_SIZE_256]byte {
// computed hash // computed hash
hash_bytes_256 :: proc(data: []byte) -> [DIGEST_SIZE_256]byte { hash_bytes_256 :: proc(data: []byte) -> [DIGEST_SIZE_256]byte {
hash: [DIGEST_SIZE_256]byte hash: [DIGEST_SIZE_256]byte
ctx: botan.hash_t ctx: Context
botan.hash_init(&ctx, botan.HASH_SHA3_256, 0) init(&ctx, hash_size = 256)
botan.hash_update(ctx, len(data) == 0 ? nil : &data[0], uint(len(data))) update(&ctx, data)
botan.hash_final(ctx, &hash[0]) final(&ctx, hash[:])
botan.hash_destroy(ctx)
return hash return hash
} }
@@ -134,30 +130,28 @@ hash_string_to_buffer_256 :: proc(data: string, hash: []byte) {
// It requires that the destination buffer is at least as big as the digest size // It requires that the destination buffer is at least as big as the digest size
hash_bytes_to_buffer_256 :: proc(data, hash: []byte) { hash_bytes_to_buffer_256 :: proc(data, hash: []byte) {
assert(len(hash) >= DIGEST_SIZE_256, "Size of destination buffer is smaller than the digest size") assert(len(hash) >= DIGEST_SIZE_256, "Size of destination buffer is smaller than the digest size")
ctx: botan.hash_t ctx: Context
botan.hash_init(&ctx, botan.HASH_SHA3_256, 0) init(&ctx, hash_size = 256)
botan.hash_update(ctx, len(data) == 0 ? nil : &data[0], uint(len(data))) update(&ctx, data)
botan.hash_final(ctx, &hash[0]) final(&ctx, hash[:])
botan.hash_destroy(ctx)
} }
// hash_stream_256 will read the stream in chunks and compute a // hash_stream_256 will read the stream in chunks and compute a
// hash from its contents // hash from its contents
hash_stream_256 :: proc(s: io.Stream) -> ([DIGEST_SIZE_256]byte, bool) { hash_stream_256 :: proc(s: io.Stream) -> ([DIGEST_SIZE_256]byte, bool) {
hash: [DIGEST_SIZE_256]byte hash: [DIGEST_SIZE_256]byte
ctx: botan.hash_t ctx: Context
botan.hash_init(&ctx, botan.HASH_SHA3_256, 0) init(&ctx, hash_size = 256)
buf := make([]byte, 512) buf := make([]byte, 512)
defer delete(buf) defer delete(buf)
i := 1 i := 1
for i > 0 { for i > 0 {
i, _ = io.read(s, buf) i, _ = io.read(s, buf)
if i > 0 { if i > 0 {
botan.hash_update(ctx, len(buf) == 0 ? nil : &buf[0], uint(i)) update(&ctx, buf[:i])
} }
} }
botan.hash_final(ctx, &hash[0]) final(&ctx, hash[:])
botan.hash_destroy(ctx)
return hash, true return hash, true
} }
@@ -193,11 +187,10 @@ hash_string_384 :: proc(data: string) -> [DIGEST_SIZE_384]byte {
// computed hash // computed hash
hash_bytes_384 :: proc(data: []byte) -> [DIGEST_SIZE_384]byte { hash_bytes_384 :: proc(data: []byte) -> [DIGEST_SIZE_384]byte {
hash: [DIGEST_SIZE_384]byte hash: [DIGEST_SIZE_384]byte
ctx: botan.hash_t ctx: Context
botan.hash_init(&ctx, botan.HASH_SHA3_384, 0) init(&ctx, hash_size = 384)
botan.hash_update(ctx, len(data) == 0 ? nil : &data[0], uint(len(data))) update(&ctx, data)
botan.hash_final(ctx, &hash[0]) final(&ctx, hash[:])
botan.hash_destroy(ctx)
return hash return hash
} }
@@ -213,30 +206,28 @@ hash_string_to_buffer_384 :: proc(data: string, hash: []byte) {
// It requires that the destination buffer is at least as big as the digest size // It requires that the destination buffer is at least as big as the digest size
hash_bytes_to_buffer_384 :: proc(data, hash: []byte) { hash_bytes_to_buffer_384 :: proc(data, hash: []byte) {
assert(len(hash) >= DIGEST_SIZE_384, "Size of destination buffer is smaller than the digest size") assert(len(hash) >= DIGEST_SIZE_384, "Size of destination buffer is smaller than the digest size")
ctx: botan.hash_t ctx: Context
botan.hash_init(&ctx, botan.HASH_SHA3_384, 0) init(&ctx, hash_size = 384)
botan.hash_update(ctx, len(data) == 0 ? nil : &data[0], uint(len(data))) update(&ctx, data)
botan.hash_final(ctx, &hash[0]) final(&ctx, hash[:])
botan.hash_destroy(ctx)
} }
// hash_stream_384 will read the stream in chunks and compute a // hash_stream_384 will read the stream in chunks and compute a
// hash from its contents // hash from its contents
hash_stream_384 :: proc(s: io.Stream) -> ([DIGEST_SIZE_384]byte, bool) { hash_stream_384 :: proc(s: io.Stream) -> ([DIGEST_SIZE_384]byte, bool) {
hash: [DIGEST_SIZE_384]byte hash: [DIGEST_SIZE_384]byte
ctx: botan.hash_t ctx: Context
botan.hash_init(&ctx, botan.HASH_SHA3_384, 0) init(&ctx, hash_size = 384)
buf := make([]byte, 512) buf := make([]byte, 512)
defer delete(buf) defer delete(buf)
i := 1 i := 1
for i > 0 { for i > 0 {
i, _ = io.read(s, buf) i, _ = io.read(s, buf)
if i > 0 { if i > 0 {
botan.hash_update(ctx, len(buf) == 0 ? nil : &buf[0], uint(i)) update(&ctx, buf[:i])
} }
} }
botan.hash_final(ctx, &hash[0]) final(&ctx, hash[:])
botan.hash_destroy(ctx)
return hash, true return hash, true
} }
@@ -272,11 +263,10 @@ hash_string_512 :: proc(data: string) -> [DIGEST_SIZE_512]byte {
// computed hash // computed hash
hash_bytes_512 :: proc(data: []byte) -> [DIGEST_SIZE_512]byte { hash_bytes_512 :: proc(data: []byte) -> [DIGEST_SIZE_512]byte {
hash: [DIGEST_SIZE_512]byte hash: [DIGEST_SIZE_512]byte
ctx: botan.hash_t ctx: Context
botan.hash_init(&ctx, botan.HASH_SHA3_512, 0) init(&ctx, hash_size = 512)
botan.hash_update(ctx, len(data) == 0 ? nil : &data[0], uint(len(data))) update(&ctx, data)
botan.hash_final(ctx, &hash[0]) final(&ctx, hash[:])
botan.hash_destroy(ctx)
return hash return hash
} }
@@ -292,30 +282,28 @@ hash_string_to_buffer_512 :: proc(data: string, hash: []byte) {
// It requires that the destination buffer is at least as big as the digest size // It requires that the destination buffer is at least as big as the digest size
hash_bytes_to_buffer_512 :: proc(data, hash: []byte) { hash_bytes_to_buffer_512 :: proc(data, hash: []byte) {
assert(len(hash) >= DIGEST_SIZE_512, "Size of destination buffer is smaller than the digest size") assert(len(hash) >= DIGEST_SIZE_512, "Size of destination buffer is smaller than the digest size")
ctx: botan.hash_t ctx: Context
botan.hash_init(&ctx, botan.HASH_SHA3_512, 0) init(&ctx, hash_size = 512)
botan.hash_update(ctx, len(data) == 0 ? nil : &data[0], uint(len(data))) update(&ctx, data)
botan.hash_final(ctx, &hash[0]) final(&ctx, hash[:])
botan.hash_destroy(ctx)
} }
// hash_stream_512 will read the stream in chunks and compute a // hash_stream_512 will read the stream in chunks and compute a
// hash from its contents // hash from its contents
hash_stream_512 :: proc(s: io.Stream) -> ([DIGEST_SIZE_512]byte, bool) { hash_stream_512 :: proc(s: io.Stream) -> ([DIGEST_SIZE_512]byte, bool) {
hash: [DIGEST_SIZE_512]byte hash: [DIGEST_SIZE_512]byte
ctx: botan.hash_t ctx: Context
botan.hash_init(&ctx, botan.HASH_SHA3_512, 0) init(&ctx, hash_size = 512)
buf := make([]byte, 512) buf := make([]byte, 512)
defer delete(buf) defer delete(buf)
i := 1 i := 1
for i > 0 { for i > 0 {
i, _ = io.read(s, buf) i, _ = io.read(s, buf)
if i > 0 { if i > 0 {
botan.hash_update(ctx, len(buf) == 0 ? nil : &buf[0], uint(i)) update(&ctx, buf[:i])
} }
} }
botan.hash_final(ctx, &hash[0]) final(&ctx, hash[:])
botan.hash_destroy(ctx)
return hash, true return hash, true
} }
@@ -345,9 +333,9 @@ hash_512 :: proc {
Low level API Low level API
*/ */
Sha3_Context :: botan.hash_t Context :: botan.hash_t
init :: proc "contextless" (ctx: ^botan.hash_t, hash_size := 512) { init :: proc "contextless" (ctx: ^Context, hash_size := 512) {
switch hash_size { switch hash_size {
case 224: botan.hash_init(ctx, botan.HASH_SHA3_224, 0) case 224: botan.hash_init(ctx, botan.HASH_SHA3_224, 0)
case 256: botan.hash_init(ctx, botan.HASH_SHA3_256, 0) case 256: botan.hash_init(ctx, botan.HASH_SHA3_256, 0)
@@ -356,11 +344,11 @@ init :: proc "contextless" (ctx: ^botan.hash_t, hash_size := 512) {
} }
} }
update :: proc "contextless" (ctx: ^botan.hash_t, data: []byte) { update :: proc "contextless" (ctx: ^Context, data: []byte) {
botan.hash_update(ctx^, len(data) == 0 ? nil : &data[0], uint(len(data))) botan.hash_update(ctx^, len(data) == 0 ? nil : &data[0], uint(len(data)))
} }
final :: proc "contextless" (ctx: ^botan.hash_t, hash: []byte) { final :: proc "contextless" (ctx: ^Context, hash: []byte) {
botan.hash_final(ctx^, &hash[0]) botan.hash_final(ctx^, &hash[0])
botan.hash_destroy(ctx^) botan.hash_destroy(ctx^)
} }