module Hacl.Impl.MultiExponentiation open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module S = Lib.Exponentiation module BD = Hacl.Bignum.Definitions open Hacl.Impl.Exponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let lexp_double_fw_st (a_t:inttype_a) (len:size_t{v len > 0}) (ctx_len:size_t) (k:concrete_ops a_t len ctx_len) = ctx:lbuffer (uint_t a_t SEC) ctx_len -> a1:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b1:lbuffer (uint_t a_t SEC) bLen -> a2:lbuffer (uint_t a_t SEC) len -> b2:lbuffer (uint_t a_t SEC) bLen -> acc:lbuffer (uint_t a_t SEC) len -> l:size_t{0 < v l /\ v l < bits a_t /\ pow2 (v l) * v len <= max_size_t /\ v l < 32} -> Stack unit (requires fun h -> live h a1 /\ live h b1 /\ live h a2 /\ live h b2 /\ live h acc /\ live h ctx /\ eq_or_disjoint a1 a2 /\ disjoint a1 acc /\ disjoint a1 ctx /\ disjoint a2 acc /\ disjoint a2 ctx /\ disjoint acc b1 /\ disjoint acc b2 /\ disjoint acc ctx /\ BD.bn_v h b1 < pow2 (v bBits) /\ BD.bn_v h b2 < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a1) /\ k.to.linv (as_seq h a2) /\ k.to.linv (as_seq h acc) /\ k.to.refl (as_seq h acc) == k.to.comm_monoid.S.one) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\ k.to.refl (as_seq h1 acc) == S.exp_double_fw #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a1)) (v bBits) (BD.bn_v h0 b1) (k.to.refl (as_seq h0 a2)) (BD.bn_v h0 b2) (v l)) inline_for_extraction noextract val lexp_double_fw_vartime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> lexp_double_fw_st a_t len ctx_len k inline_for_extraction noextract val lexp_double_fw_consttime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> lexp_double_fw_st a_t len ctx_len k