CAMLprim value stub_sha1_update_fd(value ctx, value fd, value len) { CAMLparam3(ctx, fd, len); unsigned char buf[BLKSIZE]; struct sha1_ctx ctx_dup = *GET_CTX_STRUCT(ctx); intnat ret, rest = Long_val(len); caml_release_runtime_system(); do { ret = rest < sizeof(buf) ? rest : sizeof(buf); ret = read(Long_val(fd), buf, ret); if (ret <= 0) break; rest -= ret; sha1_update(&ctx_dup, buf, ret); } while (ret > 0 && rest > 0); caml_acquire_runtime_system(); if (ret < 0) caml_failwith("read error"); *GET_CTX_STRUCT(ctx) = ctx_dup; CAMLreturn(Val_long(Long_val(len) - rest)); }
CAMLprim value stub_sha1_update_bigarray(value ctx, value buf, value pos, value len) { CAMLparam4(ctx, buf, pos, len); struct sha1_ctx ctx_dup; unsigned char *data = Data_bigarray_val(buf); ctx_dup = *GET_CTX_STRUCT(ctx); caml_release_runtime_system(); sha1_update(&ctx_dup, data + Long_val(pos), Long_val(len)); caml_acquire_runtime_system(); *GET_CTX_STRUCT(ctx) = ctx_dup; CAMLreturn(Val_unit); }
CAMLprim value stub_sha1_update(value ctx, value data, value ofs, value len) { CAMLparam4(ctx, data, ofs, len); sha1_update(GET_CTX_STRUCT(ctx), String_val(data) + Int_val(ofs), Int_val(len)); CAMLreturn(Val_unit); }
CAMLprim value stub_sha1_update(value ctx, value data, value ofs, value len) { CAMLparam4(ctx, data, ofs, len); sha1_update(GET_CTX_STRUCT(ctx), (unsigned char *) data + Long_val(ofs), Long_val(len)); CAMLreturn(Val_unit); }
CAMLexport value stub_sha1_init(value unit) { CAMLparam1(unit); CAMLlocal1(result); result = caml_alloc(sizeof(struct sha1_ctx), Abstract_tag); sha1_init(GET_CTX_STRUCT(result)); CAMLreturn(result); }
CAMLprim value stub_sha1_finalize(value ctx) { CAMLparam1(ctx); CAMLlocal1(result); result = caml_alloc_string(20); sha1_finalize(GET_CTX_STRUCT(ctx), (sha1_digest *) result); CAMLreturn(result); }
CAMLprim value stub_sha256_finalize(value ctx) { CAMLparam1(ctx); CAMLlocal1(result); result = caml_alloc_string(32); sha256_finalize(GET_CTX_STRUCT(ctx), String_val(result)); CAMLreturn(result); }