diff --git a/sha1_stubs.c b/sha1_stubs.c index e393186..4d48ef9 100644 --- a/sha1_stubs.c +++ b/sha1_stubs.c @@ -24,6 +24,7 @@ typedef SSIZE_T ssize_t; #else #include #endif +#include #include #include #include "sha1.h" @@ -87,12 +88,15 @@ CAMLprim value stub_sha1_update(value ctx, value data, value ofs, value len) CAMLprim value stub_sha1_update_bigarray(value ctx, value buf) { CAMLparam2(ctx, buf); + struct sha1_ctx ctx_dup; unsigned char *data = Data_bigarray_val(buf); size_t len = Bigarray_val(buf)->dim[0]; + ctx_dup = *GET_CTX_STRUCT(ctx); caml_release_runtime_system(); - sha1_update(GET_CTX_STRUCT(ctx), data, len); + sha1_update(&ctx_dup, data, len); caml_acquire_runtime_system(); + *GET_CTX_STRUCT(ctx) = ctx_dup; CAMLreturn(Val_unit); } diff --git a/sha256_stubs.c b/sha256_stubs.c index d1d6c1c..f0b6411 100644 --- a/sha256_stubs.c +++ b/sha256_stubs.c @@ -24,6 +24,7 @@ typedef SSIZE_T ssize_t; #else #include #endif +#include #include #include #include "sha256.h" @@ -86,12 +87,15 @@ CAMLprim value stub_sha256_update(value ctx, value data, value ofs, value len) CAMLprim value stub_sha256_update_bigarray(value ctx, value buf) { CAMLparam2(ctx, buf); + struct sha256_ctx ctx_dup; unsigned char *data = Data_bigarray_val(buf); size_t len = Bigarray_val(buf)->dim[0]; + ctx_dup = *GET_CTX_STRUCT(ctx); caml_release_runtime_system(); - sha256_update(GET_CTX_STRUCT(ctx), data, len); + sha256_update(&ctx_dup, data, len); caml_acquire_runtime_system(); + *GET_CTX_STRUCT(ctx) = ctx_dup; CAMLreturn(Val_unit); } diff --git a/sha512_stubs.c b/sha512_stubs.c index b468be9..2652e19 100644 --- a/sha512_stubs.c +++ b/sha512_stubs.c @@ -24,6 +24,7 @@ typedef SSIZE_T ssize_t; #else #include #endif +#include #include #include #include "sha512.h" @@ -86,12 +87,15 @@ CAMLprim value stub_sha512_update(value ctx, value data, value ofs, value len) CAMLprim value stub_sha512_update_bigarray(value ctx, value buf) { CAMLparam2(ctx, buf); + struct sha512_ctx ctx_dup; unsigned char *data = Data_bigarray_val(buf); size_t len = Bigarray_val(buf)->dim[0]; + ctx_dup = *GET_CTX_STRUCT(ctx); caml_release_runtime_system(); - sha512_update(GET_CTX_STRUCT(ctx), data, len); + sha512_update(&ctx_dup, data, len); caml_acquire_runtime_system(); + *GET_CTX_STRUCT(ctx) = ctx_dup; CAMLreturn(Val_unit); }