Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file mec_digestif.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410typebigstring=(char,Bigarray_compat.int8_unsigned_elt,Bigarray_compat.c_layout)Bigarray_compat.Array1.ttype'aiter=('a->unit)->unittype'acompare='a->'a->inttype'aequal='a->'a->booltype'app=Format.formatter->'a->unitmoduleBy=Digestif_bymoduleBi=Digestif_bimoduleEq=Digestif_eqmoduleConv=Digestif_convletfailwithfmt=Format.ksprintffailwithfmtmoduletypeS=sigvaldigest_size:inttypectxtypetvalempty:ctxvalinit:?personalisation:Bytes.t->unit->ctxvalfeed_bytes:ctx->?off:int->?len:int->Bytes.t->ctxvalfeed_string:ctx->?off:int->?len:int->String.t->ctxvalfeed_bigstring:ctx->?off:int->?len:int->bigstring->ctxvalfeedi_bytes:ctx->Bytes.titer->ctxvalfeedi_string:ctx->String.titer->ctxvalfeedi_bigstring:ctx->bigstringiter->ctxvalget:ctx->tvaldigest_bytes:?off:int->?len:int->Bytes.t->tvaldigest_string:?off:int->?len:int->String.t->tvaldigest_bigstring:?off:int->?len:int->bigstring->tvaldigesti_bytes:Bytes.titer->tvaldigesti_string:String.titer->tvaldigesti_bigstring:bigstringiter->tvaldigestv_bytes:Bytes.tlist->tvaldigestv_string:String.tlist->tvaldigestv_bigstring:bigstringlist->tvalunsafe_compare:tcomparevalequal:tequalvalpp:tppvalof_hex:string->tvalof_hex_opt:string->toptionvalconsistent_of_hex:string->tvalconsistent_of_hex_opt:string->toptionvalto_hex:t->stringvalof_raw_string:string->tvalof_raw_string_opt:string->toptionvalto_raw_string:t->stringendmoduletypeDesc=sigvaldigest_size:intvalblock_size:intendmoduletypeHash=sigtypectxvalinit:?personalisation:Bytes.t->unit->ctxvalunsafe_feed_bytes:ctx->By.t->int->int->unitvalunsafe_feed_bigstring:ctx->Bi.t->int->int->unitvalunsafe_get:ctx->By.tvaldup:ctx->ctxendmoduleUnsafe(Hash:Hash)(D:Desc)=structopenHashletdigest_size=D.digest_sizeletempty=init()letinit=initletunsafe_feed_bytesctx?off?lenbuf=letoff,len=match(off,len)with|Someoff,Somelen->(off,len)|Someoff,None->(off,By.lengthbuf-off)|None,Somelen->(0,len)|None,None->(0,By.lengthbuf)inifoff<0||len<0||off>By.lengthbuf-lentheninvalid_arg"offset out of bounds"elseunsafe_feed_bytesctxbufofflenletunsafe_feed_stringctx?off?lenbuf=unsafe_feed_bytesctx?off?len(By.unsafe_of_stringbuf)letunsafe_feed_bigstringctx?off?lenbuf=letoff,len=match(off,len)with|Someoff,Somelen->(off,len)|Someoff,None->(off,Bi.lengthbuf-off)|None,Somelen->(0,len)|None,None->(0,Bi.lengthbuf)inifoff<0||len<0||off>Bi.lengthbuf-lentheninvalid_arg"offset out of bounds"elseunsafe_feed_bigstringctxbufofflenletunsafe_get=unsafe_getendmoduleCore(Hash:Hash)(D:Desc)=structtypet=stringtypectx=Hash.ctxincludeUnsafe(Hash)(D)includeConv.Make(D)includeEq.Make(D)letgett=lett=Hash.duptinunsafe_gett|>By.unsafe_to_stringletfeed_bytest?off?lenbuf=lett=Hash.duptinunsafe_feed_bytest?off?lenbuf;tletfeed_stringt?off?lenbuf=lett=Hash.duptinunsafe_feed_stringt?off?lenbuf;tletfeed_bigstringt?off?lenbuf=lett=Hash.duptinunsafe_feed_bigstringt?off?lenbuf;tletfeedi_bytestiter=lett=Hash.duptinletfeedbuf=unsafe_feed_bytestbufiniterfeed;tletfeedi_stringtiter=lett=Hash.duptinletfeedbuf=unsafe_feed_stringtbufiniterfeed;tletfeedi_bigstringtiter=lett=Hash.duptinletfeedbuf=unsafe_feed_bigstringtbufiniterfeed;tletdigest_bytes?off?lenbuf=feed_bytesempty?off?lenbuf|>getletdigest_string?off?lenbuf=feed_stringempty?off?lenbuf|>getletdigest_bigstring?off?lenbuf=feed_bigstringempty?off?lenbuf|>getletdigesti_bytesiter=feedi_bytesemptyiter|>getletdigesti_stringiter=feedi_stringemptyiter|>getletdigesti_bigstringiter=feedi_bigstringemptyiter|>getletdigestv_byteslst=digesti_bytes(funf->List.iterflst)letdigestv_stringlst=digesti_string(funf->List.iterflst)letdigestv_bigstringlst=digesti_bigstring(funf->List.iterflst)endmoduleMake(H:Hash)(D:Desc)=structincludeCore(H)(D)endmoduletypeHash_BLAKE2=sigtypectxvalwith_outlen_and_bytes_key:?personalisation:Bytes.t->int->By.t->int->int->ctxvalunsafe_feed_bytes:ctx->By.t->int->int->unitvalunsafe_feed_bigstring:ctx->Bi.t->int->int->unitvalunsafe_get:ctx->By.tvaldup:ctx->ctxvalmax_outlen:intendmoduleMake_BLAKE2(H:Hash_BLAKE2)(D:Desc)=structlet()=ifD.digest_size>H.max_outlenthenfailwith"Invalid digest_size:%d to make a BLAKE2{S,B} implementation"D.digest_sizeincludeMake(structtypectx=H.ctxletinit?personalisation()=H.with_outlen_and_bytes_key(* XXX(dannywillems): adding personalisation *)?personalisationD.digest_sizeBy.empty00letunsafe_feed_bytes=H.unsafe_feed_bytesletunsafe_feed_bigstring=H.unsafe_feed_bigstringletunsafe_get=H.unsafe_getletdup=H.dupend)(D)endmoduleBLAKE2B:sigincludeSend=Make_BLAKE2(Baijiu_blake2b.Unsafe)(structletdigest_size,block_size=(64,128)end)moduleBLAKE2S:sigincludeSend=Make_BLAKE2(Baijiu_blake2s.Unsafe)(structletdigest_size,block_size=(32,64)end)moduleMake_BLAKE2B(D:sigvaldigest_size:intend):S=structincludeMake_BLAKE2(Baijiu_blake2b.Unsafe)(structletdigest_size,block_size=(D.digest_size,128)end)endmoduleMake_BLAKE2S(D:sigvaldigest_size:intend):S=structincludeMake_BLAKE2(Baijiu_blake2s.Unsafe)(structletdigest_size,block_size=(D.digest_size,64)end)endtype'khash=BLAKE2B:BLAKE2B.thash|BLAKE2S:BLAKE2S.thashletblake2b=BLAKE2Bletblake2s=BLAKE2Sletmodule_of:typek.khash->(moduleSwithtypet=k)=function|BLAKE2B->(moduleBLAKE2B)|BLAKE2S->(moduleBLAKE2S)type'hasht='hashletdigest_bytes:typek.khash->Bytes.t->kt=funhashbuf->letmoduleH=(valmodule_ofhash)inH.digest_bytesbufletdigest_string:typek.khash->String.t->kt=funhashbuf->letmoduleH=(valmodule_ofhash)inH.digest_stringbufletdigest_bigstring:typek.khash->bigstring->kt=funhashbuf->letmoduleH=(valmodule_ofhash)inH.digest_bigstringbufletdigesti_bytes:typek.khash->Bytes.titer->kt=funhashiter->letmoduleH=(valmodule_ofhash)inH.digesti_bytesiterletdigesti_string:typek.khash->String.titer->kt=funhashiter->letmoduleH=(valmodule_ofhash)inH.digesti_stringiterletdigesti_bigstring:typek.khash->bigstringiter->kt=funhashiter->letmoduleH=(valmodule_ofhash)inH.digesti_bigstringiter(* XXX(dinosaure): unsafe part to avoid overhead. *)letunsafe_compare:typek.khash->kt->kt->int=funhashab->letmoduleH=(valmodule_ofhash)inH.unsafe_compareabletequal:typek.khash->ktequal=funhashab->letmoduleH=(valmodule_ofhash)inH.equalabletpp:typek.khash->ktpp=funhashppft->letmoduleH=(valmodule_ofhash)inH.ppppftletof_hex:typek.khash->string->kt=funhashhex->letmoduleH=(valmodule_ofhash)inH.of_hexhexletof_hex_opt:typek.khash->string->ktoption=funhashhex->letmoduleH=(valmodule_ofhash)inH.of_hex_opthexletconsistent_of_hex:typek.khash->string->kt=funhashhex->letmoduleH=(valmodule_ofhash)inH.consistent_of_hexhexletconsistent_of_hex_opt:typek.khash->string->ktoption=funhashhex->letmoduleH=(valmodule_ofhash)inH.consistent_of_hex_opthexletto_hex:typek.khash->kt->string=funhasht->letmoduleH=(valmodule_ofhash)inH.to_hextletof_raw_string:typek.khash->string->kt=funhashs->letmoduleH=(valmodule_ofhash)inH.of_raw_stringsletof_raw_string_opt:typek.khash->string->ktoption=funhashs->letmoduleH=(valmodule_ofhash)inH.of_raw_string_optsletto_raw_string:typek.khash->kt->string=funhasht->letmoduleH=(valmodule_ofhash)inH.to_raw_stringtletof_digest(typehash)(moduleH:Swithtypet=hash)(hash:H.t):hasht=hashletof_blake2bhash=hashletof_blake2shash=hash