123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408(* Copyright (c) 2014-2016 David Kaloper Meršinjak
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)moduleBy=Digestif_bymoduleBi=Digestif_bitypeoff=inttypesize=inttypeba=Bi.ttypest=By.ttypectx=By.tletdup:ctx->ctx=By.copymoduleMD5=structtypekind=[`MD5]moduleBigstring=structexternalinit:ctx->unit="caml_digestif_md5_ba_init"[@@noalloc]externalupdate:ctx->ba->off->size->unit="caml_digestif_md5_ba_update"[@@noalloc]externalfinalize:ctx->ba->off->unit="caml_digestif_md5_ba_finalize"[@@noalloc]endmoduleBytes=structexternalinit:ctx->unit="caml_digestif_md5_st_init"[@@noalloc]externalupdate:ctx->st->off->size->unit="caml_digestif_md5_st_update"[@@noalloc]externalfinalize:ctx->st->off->unit="caml_digestif_md5_st_finalize"[@@noalloc]endexternalctx_size:unit->int="caml_digestif_md5_ctx_size"[@@noalloc]endmoduleSHA1=structtypekind=[`SHA1]moduleBigstring=structexternalinit:ctx->unit="caml_digestif_sha1_ba_init"[@@noalloc]externalupdate:ctx->ba->off->size->unit="caml_digestif_sha1_ba_update"[@@noalloc]externalfinalize:ctx->ba->off->unit="caml_digestif_sha1_ba_finalize"[@@noalloc]endmoduleBytes=structexternalinit:ctx->unit="caml_digestif_sha1_st_init"[@@noalloc]externalupdate:ctx->st->off->size->unit="caml_digestif_sha1_st_update"[@@noalloc]externalfinalize:ctx->st->off->unit="caml_digestif_sha1_st_finalize"[@@noalloc]endexternalctx_size:unit->int="caml_digestif_sha1_ctx_size"[@@noalloc]endmoduleSHA224=structtypekind=[`SHA224]moduleBigstring=structexternalinit:ctx->unit="caml_digestif_sha224_ba_init"[@@noalloc]externalupdate:ctx->ba->off->size->unit="caml_digestif_sha224_ba_update"[@@noalloc]externalfinalize:ctx->ba->off->unit="caml_digestif_sha224_ba_finalize"[@@noalloc]endmoduleBytes=structexternalinit:ctx->unit="caml_digestif_sha224_st_init"[@@noalloc]externalupdate:ctx->st->off->size->unit="caml_digestif_sha224_st_update"[@@noalloc]externalfinalize:ctx->st->off->unit="caml_digestif_sha224_st_finalize"[@@noalloc]endexternalctx_size:unit->int="caml_digestif_sha224_ctx_size"[@@noalloc]endmoduleSHA256=structtypekind=[`SHA256]moduleBigstring=structexternalinit:ctx->unit="caml_digestif_sha256_ba_init"[@@noalloc]externalupdate:ctx->ba->off->size->unit="caml_digestif_sha256_ba_update"[@@noalloc]externalfinalize:ctx->ba->off->unit="caml_digestif_sha256_ba_finalize"[@@noalloc]endmoduleBytes=structexternalinit:ctx->unit="caml_digestif_sha256_st_init"[@@noalloc]externalupdate:ctx->st->off->size->unit="caml_digestif_sha256_st_update"[@@noalloc]externalfinalize:ctx->st->off->unit="caml_digestif_sha256_st_finalize"[@@noalloc]endexternalctx_size:unit->int="caml_digestif_sha256_ctx_size"[@@noalloc]endmoduleSHA384=structtypekind=[`SHA384]moduleBigstring=structexternalinit:ctx->unit="caml_digestif_sha384_ba_init"[@@noalloc]externalupdate:ctx->ba->off->size->unit="caml_digestif_sha384_ba_update"[@@noalloc]externalfinalize:ctx->ba->off->unit="caml_digestif_sha384_ba_finalize"[@@noalloc]endmoduleBytes=structexternalinit:ctx->unit="caml_digestif_sha384_st_init"[@@noalloc]externalupdate:ctx->st->off->size->unit="caml_digestif_sha384_st_update"[@@noalloc]externalfinalize:ctx->st->off->unit="caml_digestif_sha384_st_finalize"[@@noalloc]endexternalctx_size:unit->int="caml_digestif_sha384_ctx_size"[@@noalloc]endmoduleSHA512=structtypekind=[`SHA512]moduleBigstring=structexternalinit:ctx->unit="caml_digestif_sha512_ba_init"[@@noalloc]externalupdate:ctx->ba->off->size->unit="caml_digestif_sha512_ba_update"[@@noalloc]externalfinalize:ctx->ba->off->unit="caml_digestif_sha512_ba_finalize"[@@noalloc]endmoduleBytes=structexternalinit:ctx->unit="caml_digestif_sha512_st_init"[@@noalloc]externalupdate:ctx->st->off->size->unit="caml_digestif_sha512_st_update"[@@noalloc]externalfinalize:ctx->st->off->unit="caml_digestif_sha512_st_finalize"[@@noalloc]endexternalctx_size:unit->int="caml_digestif_sha512_ctx_size"[@@noalloc]endmoduleBLAKE2B=structtypekind=[`BLAKE2B]moduleBigstring=structexternalinit:ctx->unit="caml_digestif_blake2b_ba_init"[@@noalloc]externalupdate:ctx->ba->off->size->unit="caml_digestif_blake2b_ba_update"[@@noalloc]externalfinalize:ctx->ba->off->unit="caml_digestif_blake2b_ba_finalize"[@@noalloc]externalwith_outlen_and_key:ctx->size->ba->off->size->unit="caml_digestif_blake2b_ba_init_with_outlen_and_key"[@@noalloc]endmoduleBytes=structexternalinit:ctx->unit="caml_digestif_blake2b_st_init"[@@noalloc]externalupdate:ctx->st->off->size->unit="caml_digestif_blake2b_st_update"[@@noalloc]externalfinalize:ctx->st->off->unit="caml_digestif_blake2b_st_finalize"[@@noalloc]externalwith_outlen_and_key:ctx->size->st->off->size->unit="caml_digestif_blake2b_st_init_with_outlen_and_key"[@@noalloc]endexternalctx_size:unit->int="caml_digestif_blake2b_ctx_size"[@@noalloc]externalkey_size:unit->int="caml_digestif_blake2b_key_size"[@@noalloc]externaldigest_size:ctx->int="caml_digestif_blake2b_digest_size"[@@noalloc]endmoduleBLAKE2S=structtypekind=[`BLAKE2S]moduleBigstring=structexternalinit:ctx->unit="caml_digestif_blake2s_ba_init"[@@noalloc]externalupdate:ctx->ba->off->size->unit="caml_digestif_blake2s_ba_update"[@@noalloc]externalfinalize:ctx->ba->off->unit="caml_digestif_blake2s_ba_finalize"[@@noalloc]externalwith_outlen_and_key:ctx->size->ba->off->size->unit="caml_digestif_blake2s_ba_init_with_outlen_and_key"[@@noalloc]endmoduleBytes=structexternalinit:ctx->unit="caml_digestif_blake2s_st_init"[@@noalloc]externalupdate:ctx->st->off->size->unit="caml_digestif_blake2s_st_update"[@@noalloc]externalfinalize:ctx->st->off->unit="caml_digestif_blake2s_st_finalize"[@@noalloc]externalwith_outlen_and_key:ctx->size->st->off->size->unit="caml_digestif_blake2s_st_init_with_outlen_and_key"[@@noalloc]endexternalctx_size:unit->int="caml_digestif_blake2s_ctx_size"[@@noalloc]externalkey_size:unit->int="caml_digestif_blake2s_key_size"[@@noalloc]externaldigest_size:ctx->int="caml_digestif_blake2s_digest_size"[@@noalloc]endmoduleRMD160=structtypekind=[`RMD160]moduleBigstring=structexternalinit:ctx->unit="caml_digestif_rmd160_ba_init"[@@noalloc]externalupdate:ctx->ba->off->size->unit="caml_digestif_rmd160_ba_update"[@@noalloc]externalfinalize:ctx->ba->off->unit="caml_digestif_rmd160_ba_finalize"[@@noalloc]endmoduleBytes=structexternalinit:ctx->unit="caml_digestif_rmd160_st_init"[@@noalloc]externalupdate:ctx->st->off->size->unit="caml_digestif_rmd160_st_update"[@@noalloc]externalfinalize:ctx->st->off->unit="caml_digestif_rmd160_st_finalize"[@@noalloc]endexternalctx_size:unit->int="caml_digestif_rmd160_ctx_size"[@@noalloc]endletimin(a:int)(b:int)=ifa<bthenaelsebmoduleXOR=structmoduleBigstring=structexternalxor_into:ba->off->ba->off->size->unit="caml_digestif_ba_xor_into"[@@noalloc]letxor_intoabn=ifn>imin(Bi.lengtha)(Bi.lengthb)thenraise(Invalid_argument"Native.Bigstring.xor_into: buffers to small")elsexor_intoa0b0nletxorab=letl=imin(Bi.lengtha)(Bi.lengthb)inletr=Bi.copy(Bi.subb0l)in(xor_intoarl;r)endmoduleBytes=structexternalxor_into:st->off->st->off->size->unit="caml_digestif_st_xor_into"[@@noalloc]letxor_intoabn=ifn>imin(By.lengtha)(By.lengthb)thenraise(Invalid_argument"Native.Bigstring.xor_into: buffers to small")elsexor_intoa0b0nletxorab=letl=imin(By.lengtha)(By.lengthb)inletr=By.copy(By.subb0l)in(xor_intoarl;r)endend