123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161(*****************************************************************************)(* *)(* Copyright (c) 2020-2021 Danny Willems <be.danny.willems@gmail.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)moduleStubs=structtypefp12externalallocate_fq12:unit->fp12="allocate_fp12_stubs"externalmul:fp12->fp12->fp12->int="caml_blst_fp12_mul_stubs"externalone:fp12->int="caml_blst_fp12_one_stubs"externalequal:fp12->fp12->bool="caml_blst_fp12_is_equal_stubs"externalis_zero:fp12->bool="caml_blst_fp12_is_zero_stubs"externalinverse:fp12->fp12->int="caml_blst_fp12_inverse_stubs"externalsqr:fp12->fp12->int="caml_blst_fp12_sqr_stubs"externalpow:fp12->fp12->Bytes.t->int->int="caml_blst_fp12_pow_stubs"externalto_bytes:Bytes.t->fp12->int="caml_blst_fp12_to_bytes_stubs"externalof_bytes:fp12->Bytes.t->int="caml_blst_fp12_of_bytes_stubs"endmoduleFq12=structexceptionNot_in_fieldofBytes.ttypet=Stubs.fp12letorder=letfq_order=Z.of_string"4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787"inZ.powfq_order12letsize_in_bytes=48*12letto_bytesp=letbuffer=Bytes.makesize_in_bytes'\000'inignore@@Stubs.to_bytesbufferp;bufferletof_bytes_optbs=ifBytes.lengthbs<>size_in_bytesthenNoneelseletbuffer=Stubs.allocate_fq12()inignore@@Stubs.of_bytesbufferbs;Somebufferletrandom?state()=letbuffer=Stubs.allocate_fq12()inletbs=Bytes.concatBytes.empty(List.init12(fun_->Fq.(to_bytes(random?state()))))inignore@@Stubs.of_bytesbufferbs;bufferletof_bytes_exnbs=matchof_bytes_optbswithNone->raise(Not_in_fieldbs)|Somep->pletone=letbuffer=Stubs.allocate_fq12()inignore@@Stubs.onebuffer;bufferletzero=Stubs.allocate_fq12()letsize_in_memory=Obj.reachable_words(Obj.reprone)*8leteqxy=letres=Stubs.equalxyinresletis_zerop=letres=eqpzeroinresletis_onep=eqponeletmulxy=letbuffer=Stubs.allocate_fq12()inignore@@Stubs.mulbufferxy;bufferletinverse_optx=ifis_zeroxthenNoneelseletbuffer=Stubs.allocate_fq12()inignore@@Stubs.inversebufferx;Somebufferletinverse_exnx=ifis_zeroxthenraiseDivision_by_zeroelseletbuffer=Stubs.allocate_fq12()inignore@@Stubs.inversebufferx;bufferletof_zx0x1x2x3x4x5x6x7x8x9x10x11=letcoordinates=[x0;x1;x2;x3;x4;x5;x6;x7;x8;x9;x10;x11]inletcoordinates=List.map(funx->Bytes.of_string(Z.to_bitsx))coordinatesinletbs=Bytes.concatBytes.emptycoordinatesinletbuffer=Stubs.allocate_fq12()inignore@@Stubs.of_bytesbufferbs;bufferletof_stringx0x1x2x3x4x5x6x7x8x9x10x11=letx0=Z.of_stringx0inletx1=Z.of_stringx1inletx2=Z.of_stringx2inletx3=Z.of_stringx3inletx4=Z.of_stringx4inletx5=Z.of_stringx5inletx6=Z.of_stringx6inletx7=Z.of_stringx7inletx8=Z.of_stringx8inletx9=Z.of_stringx9inletx10=Z.of_stringx10inletx11=Z.of_stringx11inof_zx0x1x2x3x4x5x6x7x8x9x10x11letpowxn=letn=Z.eremn(Z.predorder)inletbuffer=Stubs.allocate_fq12()inletexp=Z.to_bitsn|>Bytes.unsafe_of_stringinletexp_len=Z.numbitsninignore@@Stubs.powbufferxexpexp_len;bufferendincludeFq12