effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Tot | val size32_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292})
: Tot (size32 (serialize_bounded_vlbytes min max)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLGen",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let size32_bounded_vlbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
: Tot (size32 (serialize_bounded_vlbytes min max))
= size32_bounded_vlbytes' min max (log256' max) | val size32_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292})
: Tot (size32 (serialize_bounded_vlbytes min max))
let size32_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292})
: Tot (size32 (serialize_bounded_vlbytes min max)) = | false | null | false | size32_bounded_vlbytes' min max (log256' max) | {
"checked_file": "LowParse.SLow.Bytes.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.SLow.VLGen.fst.checked",
"LowParse.SLow.VLData.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Bytes.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.SLow.Bytes.size32_bounded_vlbytes'",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.SLow.Base.size32",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.Bytes.parse_all_bytes_kind",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_t",
"LowParse.Spec.Bytes.parse_bounded_vlbytes",
"LowParse.Spec.Bytes.serialize_bounded_vlbytes"
] | [] | module LowParse.SLow.Bytes
include LowParse.Spec.Bytes
include LowParse.SLow.VLData
include LowParse.SLow.VLGen
module B32 = FStar.Bytes
module Seq = FStar.Seq
module U32 = FStar.UInt32
inline_for_extraction
let parse32_flbytes_gen
(sz: nat { sz < 4294967296 } )
(x: B32.lbytes sz)
: Tot (y: B32.lbytes sz { y == parse_flbytes_gen sz (B32.reveal x) } )
= B32.hide_reveal x;
x
#set-options "--z3rlimit 32"
inline_for_extraction
let parse32_flbytes
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
: Tot (
lt_pow2_32 sz;
parser32 (parse_flbytes sz)
)
= lt_pow2_32 sz;
make_total_constant_size_parser32
sz
sz'
#(B32.lbytes sz)
(parse_flbytes_gen sz)
()
(parse32_flbytes_gen sz)
inline_for_extraction
let serialize32_flbytes
(sz: nat { sz < 4294967296 } )
: Tot (serializer32 (serialize_flbytes sz))
= fun (input: B32.lbytes sz) ->
B32.hide_reveal input;
(input <: (res: bytes32 { serializer32_correct (serialize_flbytes sz) input res } ))
inline_for_extraction
let parse32_all_bytes
: parser32 parse_all_bytes
= fun (input: B32.bytes) ->
let res = Some (input, B32.len input) in
(res <: (res: option (bytes32 * U32.t) { parser32_correct parse_all_bytes input res } ))
inline_for_extraction
let serialize32_all_bytes
: serializer32 serialize_all_bytes
= fun (input: B32.bytes) ->
(input <: (res: bytes32 { serializer32_correct serialize_all_bytes input res } ))
inline_for_extraction
let parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (parser32 (parse_bounded_vlbytes' min max l))
= parse32_synth
_
(synth_bounded_vlbytes min max)
(fun (x: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes) -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vldata_strong' min min32 max max32 l serialize_all_bytes parse32_all_bytes)
()
inline_for_extraction
let parse32_bounded_vlbytes
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
: Tot (parser32 (parse_bounded_vlbytes min max))
= parse32_bounded_vlbytes' min min32 max max32 (log256' max)
inline_for_extraction
let serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l))
=
serialize32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
serialize32_all_bytes
inline_for_extraction
let serialize32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes' min max l))
= serialize32_synth
(parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(serialize32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes)
)
(fun x -> x)
()
inline_for_extraction
let serialize32_bounded_vlbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
: Tot (serializer32 (serialize_bounded_vlbytes min max))
= serialize32_bounded_vlbytes' min max (log256' max)
inline_for_extraction
let size32_all_bytes
: size32 serialize_all_bytes
= fun (input: B32.bytes) ->
let res = B32.len input in
(res <: (res: U32.t { size32_postcond serialize_all_bytes input res } ))
inline_for_extraction
let size32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes_aux min max l))
=
size32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
size32_all_bytes
(U32.uint_to_t l)
inline_for_extraction
let size32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes' min max l))
=
size32_synth
(parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(size32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes)
)
(fun x -> x)
()
inline_for_extraction
let size32_bounded_vlbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4 | false | false | LowParse.SLow.Bytes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val size32_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292})
: Tot (size32 (serialize_bounded_vlbytes min max)) | [] | LowParse.SLow.Bytes.size32_bounded_vlbytes | {
"file_name": "src/lowparse/LowParse.SLow.Bytes.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292}
-> LowParse.SLow.Base.size32 (LowParse.Spec.Bytes.serialize_bounded_vlbytes min max) | {
"end_col": 47,
"end_line": 171,
"start_col": 2,
"start_line": 171
} |
Prims.Tot | val parse32_bounded_vlbytes
(min: nat)
(min32: U32.t{U32.v min32 == min})
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(max32: U32.t{U32.v max32 == max})
: Tot (parser32 (parse_bounded_vlbytes min max)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLGen",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse32_bounded_vlbytes
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
: Tot (parser32 (parse_bounded_vlbytes min max))
= parse32_bounded_vlbytes' min min32 max max32 (log256' max) | val parse32_bounded_vlbytes
(min: nat)
(min32: U32.t{U32.v min32 == min})
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(max32: U32.t{U32.v max32 == max})
: Tot (parser32 (parse_bounded_vlbytes min max))
let parse32_bounded_vlbytes
(min: nat)
(min32: U32.t{U32.v min32 == min})
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(max32: U32.t{U32.v max32 == max})
: Tot (parser32 (parse_bounded_vlbytes min max)) = | false | null | false | parse32_bounded_vlbytes' min min32 max max32 (log256' max) | {
"checked_file": "LowParse.SLow.Bytes.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.SLow.VLGen.fst.checked",
"LowParse.SLow.VLData.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Bytes.fst"
} | [
"total"
] | [
"Prims.nat",
"FStar.UInt32.t",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.SLow.Bytes.parse32_bounded_vlbytes'",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.SLow.Base.parser32",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.Bytes.parse_all_bytes_kind",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_t",
"LowParse.Spec.Bytes.parse_bounded_vlbytes"
] | [] | module LowParse.SLow.Bytes
include LowParse.Spec.Bytes
include LowParse.SLow.VLData
include LowParse.SLow.VLGen
module B32 = FStar.Bytes
module Seq = FStar.Seq
module U32 = FStar.UInt32
inline_for_extraction
let parse32_flbytes_gen
(sz: nat { sz < 4294967296 } )
(x: B32.lbytes sz)
: Tot (y: B32.lbytes sz { y == parse_flbytes_gen sz (B32.reveal x) } )
= B32.hide_reveal x;
x
#set-options "--z3rlimit 32"
inline_for_extraction
let parse32_flbytes
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
: Tot (
lt_pow2_32 sz;
parser32 (parse_flbytes sz)
)
= lt_pow2_32 sz;
make_total_constant_size_parser32
sz
sz'
#(B32.lbytes sz)
(parse_flbytes_gen sz)
()
(parse32_flbytes_gen sz)
inline_for_extraction
let serialize32_flbytes
(sz: nat { sz < 4294967296 } )
: Tot (serializer32 (serialize_flbytes sz))
= fun (input: B32.lbytes sz) ->
B32.hide_reveal input;
(input <: (res: bytes32 { serializer32_correct (serialize_flbytes sz) input res } ))
inline_for_extraction
let parse32_all_bytes
: parser32 parse_all_bytes
= fun (input: B32.bytes) ->
let res = Some (input, B32.len input) in
(res <: (res: option (bytes32 * U32.t) { parser32_correct parse_all_bytes input res } ))
inline_for_extraction
let serialize32_all_bytes
: serializer32 serialize_all_bytes
= fun (input: B32.bytes) ->
(input <: (res: bytes32 { serializer32_correct serialize_all_bytes input res } ))
inline_for_extraction
let parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (parser32 (parse_bounded_vlbytes' min max l))
= parse32_synth
_
(synth_bounded_vlbytes min max)
(fun (x: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes) -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vldata_strong' min min32 max max32 l serialize_all_bytes parse32_all_bytes)
()
inline_for_extraction
let parse32_bounded_vlbytes
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } ) | false | false | LowParse.SLow.Bytes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse32_bounded_vlbytes
(min: nat)
(min32: U32.t{U32.v min32 == min})
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(max32: U32.t{U32.v max32 == max})
: Tot (parser32 (parse_bounded_vlbytes min max)) | [] | LowParse.SLow.Bytes.parse32_bounded_vlbytes | {
"file_name": "src/lowparse/LowParse.SLow.Bytes.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
min32: FStar.UInt32.t{FStar.UInt32.v min32 == min} ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
max32: FStar.UInt32.t{FStar.UInt32.v max32 == max}
-> LowParse.SLow.Base.parser32 (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) | {
"end_col": 60,
"end_line": 80,
"start_col": 2,
"start_line": 80
} |
Prims.Tot | val serialize32_bounded_vlgenbytes
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32:
serializer32 sk
{ kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\
Some?.v kk.parser_kind_high + max < 4294967296 })
: Tot (serializer32 (serialize_bounded_vlgenbytes min max sk)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLGen",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize32_bounded_vlgenbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32: serializer32 sk {kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\ Some?.v kk.parser_kind_high + max < 4294967296 })
: Tot (serializer32 (serialize_bounded_vlgenbytes min max sk))
= serialize32_synth
(parse_bounded_vlgen min max pk serialize_all_bytes)
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(serialize_bounded_vlgen min max sk serialize_all_bytes)
(serialize32_bounded_vlgen min max sk32 serialize32_all_bytes)
(fun x -> x)
(fun x -> x)
() | val serialize32_bounded_vlgenbytes
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32:
serializer32 sk
{ kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\
Some?.v kk.parser_kind_high + max < 4294967296 })
: Tot (serializer32 (serialize_bounded_vlgenbytes min max sk))
let serialize32_bounded_vlgenbytes
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32:
serializer32 sk
{ kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\
Some?.v kk.parser_kind_high + max < 4294967296 })
: Tot (serializer32 (serialize_bounded_vlgenbytes min max sk)) = | false | null | false | serialize32_synth (parse_bounded_vlgen min max pk serialize_all_bytes)
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(serialize_bounded_vlgen min max sk serialize_all_bytes)
(serialize32_bounded_vlgen min max sk32 serialize32_all_bytes)
(fun x -> x)
(fun x -> x)
() | {
"checked_file": "LowParse.SLow.Bytes.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.SLow.VLGen.fst.checked",
"LowParse.SLow.VLData.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Bytes.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.SLow.Base.serializer32",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"FStar.Pervasives.Native.uu___is_Some",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"Prims.op_Addition",
"FStar.Pervasives.Native.__proj__Some__item__v",
"LowParse.SLow.Combinators.serialize32_synth",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.Bytes.parse_all_bytes_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"FStar.Bytes.bytes",
"LowParse.Spec.Bytes.parse_all_bytes",
"LowParse.Spec.Bytes.serialize_all_bytes",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Spec.VLGen.serialize_bounded_vlgen",
"LowParse.SLow.VLGen.serialize32_bounded_vlgen",
"LowParse.SLow.Bytes.serialize32_all_bytes",
"LowParse.Spec.Bytes.parse_bounded_vlgenbytes",
"LowParse.Spec.Bytes.serialize_bounded_vlgenbytes"
] | [] | module LowParse.SLow.Bytes
include LowParse.Spec.Bytes
include LowParse.SLow.VLData
include LowParse.SLow.VLGen
module B32 = FStar.Bytes
module Seq = FStar.Seq
module U32 = FStar.UInt32
inline_for_extraction
let parse32_flbytes_gen
(sz: nat { sz < 4294967296 } )
(x: B32.lbytes sz)
: Tot (y: B32.lbytes sz { y == parse_flbytes_gen sz (B32.reveal x) } )
= B32.hide_reveal x;
x
#set-options "--z3rlimit 32"
inline_for_extraction
let parse32_flbytes
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
: Tot (
lt_pow2_32 sz;
parser32 (parse_flbytes sz)
)
= lt_pow2_32 sz;
make_total_constant_size_parser32
sz
sz'
#(B32.lbytes sz)
(parse_flbytes_gen sz)
()
(parse32_flbytes_gen sz)
inline_for_extraction
let serialize32_flbytes
(sz: nat { sz < 4294967296 } )
: Tot (serializer32 (serialize_flbytes sz))
= fun (input: B32.lbytes sz) ->
B32.hide_reveal input;
(input <: (res: bytes32 { serializer32_correct (serialize_flbytes sz) input res } ))
inline_for_extraction
let parse32_all_bytes
: parser32 parse_all_bytes
= fun (input: B32.bytes) ->
let res = Some (input, B32.len input) in
(res <: (res: option (bytes32 * U32.t) { parser32_correct parse_all_bytes input res } ))
inline_for_extraction
let serialize32_all_bytes
: serializer32 serialize_all_bytes
= fun (input: B32.bytes) ->
(input <: (res: bytes32 { serializer32_correct serialize_all_bytes input res } ))
inline_for_extraction
let parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (parser32 (parse_bounded_vlbytes' min max l))
= parse32_synth
_
(synth_bounded_vlbytes min max)
(fun (x: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes) -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vldata_strong' min min32 max max32 l serialize_all_bytes parse32_all_bytes)
()
inline_for_extraction
let parse32_bounded_vlbytes
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
: Tot (parser32 (parse_bounded_vlbytes min max))
= parse32_bounded_vlbytes' min min32 max max32 (log256' max)
inline_for_extraction
let serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l))
=
serialize32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
serialize32_all_bytes
inline_for_extraction
let serialize32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes' min max l))
= serialize32_synth
(parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(serialize32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes)
)
(fun x -> x)
()
inline_for_extraction
let serialize32_bounded_vlbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
: Tot (serializer32 (serialize_bounded_vlbytes min max))
= serialize32_bounded_vlbytes' min max (log256' max)
inline_for_extraction
let size32_all_bytes
: size32 serialize_all_bytes
= fun (input: B32.bytes) ->
let res = B32.len input in
(res <: (res: U32.t { size32_postcond serialize_all_bytes input res } ))
inline_for_extraction
let size32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes_aux min max l))
=
size32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
size32_all_bytes
(U32.uint_to_t l)
inline_for_extraction
let size32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes' min max l))
=
size32_synth
(parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(size32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes)
)
(fun x -> x)
()
inline_for_extraction
let size32_bounded_vlbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
: Tot (size32 (serialize_bounded_vlbytes min max))
= size32_bounded_vlbytes' min max (log256' max)
inline_for_extraction
let parse32_bounded_vlgenbytes
(min: nat)
(min32: U32.t { U32.v min32 == min })
(max: nat{ min <= max /\ max > 0 })
(max32: U32.t { U32.v max32 == max })
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(pk32: parser32 pk)
: Tot (parser32 (parse_bounded_vlgenbytes min max pk))
= parse32_synth
(parse_bounded_vlgen min max pk serialize_all_bytes)
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vlgen min min32 max max32 pk32 serialize_all_bytes parse32_all_bytes)
()
inline_for_extraction
let serialize32_bounded_vlgenbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32: serializer32 sk {kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\ Some?.v kk.parser_kind_high + max < 4294967296 }) | false | false | LowParse.SLow.Bytes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize32_bounded_vlgenbytes
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32:
serializer32 sk
{ kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\
Some?.v kk.parser_kind_high + max < 4294967296 })
: Tot (serializer32 (serialize_bounded_vlgenbytes min max sk)) | [] | LowParse.SLow.Bytes.serialize32_bounded_vlgenbytes | {
"file_name": "src/lowparse/LowParse.SLow.Bytes.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
sk32:
LowParse.SLow.Base.serializer32 sk
{ Mkparser_kind'?.parser_kind_subkind kk ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
Some? (Mkparser_kind'?.parser_kind_high kk) /\
Some?.v (Mkparser_kind'?.parser_kind_high kk) + max < 4294967296 }
-> LowParse.SLow.Base.serializer32 (LowParse.Spec.Bytes.serialize_bounded_vlgenbytes min max sk) | {
"end_col": 6,
"end_line": 206,
"start_col": 2,
"start_line": 199
} |
Prims.Tot | val parse32_all_bytes:parser32 parse_all_bytes | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLGen",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse32_all_bytes
: parser32 parse_all_bytes
= fun (input: B32.bytes) ->
let res = Some (input, B32.len input) in
(res <: (res: option (bytes32 * U32.t) { parser32_correct parse_all_bytes input res } )) | val parse32_all_bytes:parser32 parse_all_bytes
let parse32_all_bytes:parser32 parse_all_bytes = | false | null | false | fun (input: B32.bytes) ->
let res = Some (input, B32.len input) in
(res <: (res: option (bytes32 * U32.t) {parser32_correct parse_all_bytes input res})) | {
"checked_file": "LowParse.SLow.Bytes.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.SLow.VLGen.fst.checked",
"LowParse.SLow.VLData.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Bytes.fst"
} | [
"total"
] | [
"FStar.Bytes.bytes",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.SLow.Base.bytes32",
"FStar.UInt32.t",
"LowParse.SLow.Base.parser32_correct",
"LowParse.Spec.Bytes.parse_all_bytes_kind",
"LowParse.Spec.Bytes.parse_all_bytes",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Bytes.len"
] | [] | module LowParse.SLow.Bytes
include LowParse.Spec.Bytes
include LowParse.SLow.VLData
include LowParse.SLow.VLGen
module B32 = FStar.Bytes
module Seq = FStar.Seq
module U32 = FStar.UInt32
inline_for_extraction
let parse32_flbytes_gen
(sz: nat { sz < 4294967296 } )
(x: B32.lbytes sz)
: Tot (y: B32.lbytes sz { y == parse_flbytes_gen sz (B32.reveal x) } )
= B32.hide_reveal x;
x
#set-options "--z3rlimit 32"
inline_for_extraction
let parse32_flbytes
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
: Tot (
lt_pow2_32 sz;
parser32 (parse_flbytes sz)
)
= lt_pow2_32 sz;
make_total_constant_size_parser32
sz
sz'
#(B32.lbytes sz)
(parse_flbytes_gen sz)
()
(parse32_flbytes_gen sz)
inline_for_extraction
let serialize32_flbytes
(sz: nat { sz < 4294967296 } )
: Tot (serializer32 (serialize_flbytes sz))
= fun (input: B32.lbytes sz) ->
B32.hide_reveal input;
(input <: (res: bytes32 { serializer32_correct (serialize_flbytes sz) input res } ))
inline_for_extraction
let parse32_all_bytes | false | true | LowParse.SLow.Bytes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse32_all_bytes:parser32 parse_all_bytes | [] | LowParse.SLow.Bytes.parse32_all_bytes | {
"file_name": "src/lowparse/LowParse.SLow.Bytes.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | LowParse.SLow.Base.parser32 LowParse.Spec.Bytes.parse_all_bytes | {
"end_col": 92,
"end_line": 50,
"start_col": 2,
"start_line": 48
} |
Prims.Tot | val serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLGen",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l))
=
serialize32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
serialize32_all_bytes | val serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l))
let serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l)) = | false | null | false | serialize32_bounded_vldata_strong' min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
serialize32_all_bytes | {
"checked_file": "LowParse.SLow.Bytes.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.SLow.VLGen.fst.checked",
"LowParse.SLow.VLData.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Bytes.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.SLow.VLData.serialize32_bounded_vldata_strong'",
"LowParse.Spec.Bytes.parse_all_bytes_kind",
"FStar.Bytes.bytes",
"LowParse.Spec.Bytes.parse_all_bytes",
"LowParse.Spec.Bytes.serialize_all_bytes",
"LowParse.SLow.Bytes.serialize32_all_bytes",
"LowParse.SLow.Base.serializer32",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_aux",
"LowParse.Spec.Bytes.serialize_bounded_vlbytes_aux"
] | [] | module LowParse.SLow.Bytes
include LowParse.Spec.Bytes
include LowParse.SLow.VLData
include LowParse.SLow.VLGen
module B32 = FStar.Bytes
module Seq = FStar.Seq
module U32 = FStar.UInt32
inline_for_extraction
let parse32_flbytes_gen
(sz: nat { sz < 4294967296 } )
(x: B32.lbytes sz)
: Tot (y: B32.lbytes sz { y == parse_flbytes_gen sz (B32.reveal x) } )
= B32.hide_reveal x;
x
#set-options "--z3rlimit 32"
inline_for_extraction
let parse32_flbytes
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
: Tot (
lt_pow2_32 sz;
parser32 (parse_flbytes sz)
)
= lt_pow2_32 sz;
make_total_constant_size_parser32
sz
sz'
#(B32.lbytes sz)
(parse_flbytes_gen sz)
()
(parse32_flbytes_gen sz)
inline_for_extraction
let serialize32_flbytes
(sz: nat { sz < 4294967296 } )
: Tot (serializer32 (serialize_flbytes sz))
= fun (input: B32.lbytes sz) ->
B32.hide_reveal input;
(input <: (res: bytes32 { serializer32_correct (serialize_flbytes sz) input res } ))
inline_for_extraction
let parse32_all_bytes
: parser32 parse_all_bytes
= fun (input: B32.bytes) ->
let res = Some (input, B32.len input) in
(res <: (res: option (bytes32 * U32.t) { parser32_correct parse_all_bytes input res } ))
inline_for_extraction
let serialize32_all_bytes
: serializer32 serialize_all_bytes
= fun (input: B32.bytes) ->
(input <: (res: bytes32 { serializer32_correct serialize_all_bytes input res } ))
inline_for_extraction
let parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (parser32 (parse_bounded_vlbytes' min max l))
= parse32_synth
_
(synth_bounded_vlbytes min max)
(fun (x: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes) -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vldata_strong' min min32 max max32 l serialize_all_bytes parse32_all_bytes)
()
inline_for_extraction
let parse32_bounded_vlbytes
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
: Tot (parser32 (parse_bounded_vlbytes min max))
= parse32_bounded_vlbytes' min min32 max max32 (log256' max)
inline_for_extraction
let serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l)) | false | false | LowParse.SLow.Bytes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l)) | [] | LowParse.SLow.Bytes.serialize32_bounded_vlbytes_aux | {
"file_name": "src/lowparse/LowParse.SLow.Bytes.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292} ->
l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4}
-> LowParse.SLow.Base.serializer32 (LowParse.Spec.Bytes.serialize_bounded_vlbytes_aux min max l) | {
"end_col": 25,
"end_line": 97,
"start_col": 2,
"start_line": 89
} |
Prims.Tot | val size32_bounded_vlgenbytes
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32:
size32 sk
{ kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\
Some?.v kk.parser_kind_high + max < 4294967296 })
: Tot (size32 (serialize_bounded_vlgenbytes min max sk)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLGen",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let size32_bounded_vlgenbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32: size32 sk {kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\ Some?.v kk.parser_kind_high + max < 4294967296 })
: Tot (size32 (serialize_bounded_vlgenbytes min max sk))
= size32_synth
(parse_bounded_vlgen min max pk serialize_all_bytes)
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(serialize_bounded_vlgen min max sk serialize_all_bytes)
(size32_bounded_vlgen min max sk32 size32_all_bytes)
(fun x -> x)
(fun x -> x)
() | val size32_bounded_vlgenbytes
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32:
size32 sk
{ kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\
Some?.v kk.parser_kind_high + max < 4294967296 })
: Tot (size32 (serialize_bounded_vlgenbytes min max sk))
let size32_bounded_vlgenbytes
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32:
size32 sk
{ kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\
Some?.v kk.parser_kind_high + max < 4294967296 })
: Tot (size32 (serialize_bounded_vlgenbytes min max sk)) = | false | null | false | size32_synth (parse_bounded_vlgen min max pk serialize_all_bytes)
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(serialize_bounded_vlgen min max sk serialize_all_bytes)
(size32_bounded_vlgen min max sk32 size32_all_bytes)
(fun x -> x)
(fun x -> x)
() | {
"checked_file": "LowParse.SLow.Bytes.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.SLow.VLGen.fst.checked",
"LowParse.SLow.VLData.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Bytes.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.serializer",
"LowParse.SLow.Base.size32",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"FStar.Pervasives.Native.uu___is_Some",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"Prims.op_Addition",
"FStar.Pervasives.Native.__proj__Some__item__v",
"LowParse.SLow.Combinators.size32_synth",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.Bytes.parse_all_bytes_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"FStar.Bytes.bytes",
"LowParse.Spec.Bytes.parse_all_bytes",
"LowParse.Spec.Bytes.serialize_all_bytes",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.Spec.VLGen.serialize_bounded_vlgen",
"LowParse.SLow.VLGen.size32_bounded_vlgen",
"LowParse.SLow.Bytes.size32_all_bytes",
"LowParse.Spec.Bytes.parse_bounded_vlgenbytes",
"LowParse.Spec.Bytes.serialize_bounded_vlgenbytes"
] | [] | module LowParse.SLow.Bytes
include LowParse.Spec.Bytes
include LowParse.SLow.VLData
include LowParse.SLow.VLGen
module B32 = FStar.Bytes
module Seq = FStar.Seq
module U32 = FStar.UInt32
inline_for_extraction
let parse32_flbytes_gen
(sz: nat { sz < 4294967296 } )
(x: B32.lbytes sz)
: Tot (y: B32.lbytes sz { y == parse_flbytes_gen sz (B32.reveal x) } )
= B32.hide_reveal x;
x
#set-options "--z3rlimit 32"
inline_for_extraction
let parse32_flbytes
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
: Tot (
lt_pow2_32 sz;
parser32 (parse_flbytes sz)
)
= lt_pow2_32 sz;
make_total_constant_size_parser32
sz
sz'
#(B32.lbytes sz)
(parse_flbytes_gen sz)
()
(parse32_flbytes_gen sz)
inline_for_extraction
let serialize32_flbytes
(sz: nat { sz < 4294967296 } )
: Tot (serializer32 (serialize_flbytes sz))
= fun (input: B32.lbytes sz) ->
B32.hide_reveal input;
(input <: (res: bytes32 { serializer32_correct (serialize_flbytes sz) input res } ))
inline_for_extraction
let parse32_all_bytes
: parser32 parse_all_bytes
= fun (input: B32.bytes) ->
let res = Some (input, B32.len input) in
(res <: (res: option (bytes32 * U32.t) { parser32_correct parse_all_bytes input res } ))
inline_for_extraction
let serialize32_all_bytes
: serializer32 serialize_all_bytes
= fun (input: B32.bytes) ->
(input <: (res: bytes32 { serializer32_correct serialize_all_bytes input res } ))
inline_for_extraction
let parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (parser32 (parse_bounded_vlbytes' min max l))
= parse32_synth
_
(synth_bounded_vlbytes min max)
(fun (x: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes) -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vldata_strong' min min32 max max32 l serialize_all_bytes parse32_all_bytes)
()
inline_for_extraction
let parse32_bounded_vlbytes
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
: Tot (parser32 (parse_bounded_vlbytes min max))
= parse32_bounded_vlbytes' min min32 max max32 (log256' max)
inline_for_extraction
let serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l))
=
serialize32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
serialize32_all_bytes
inline_for_extraction
let serialize32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes' min max l))
= serialize32_synth
(parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(serialize32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes)
)
(fun x -> x)
()
inline_for_extraction
let serialize32_bounded_vlbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
: Tot (serializer32 (serialize_bounded_vlbytes min max))
= serialize32_bounded_vlbytes' min max (log256' max)
inline_for_extraction
let size32_all_bytes
: size32 serialize_all_bytes
= fun (input: B32.bytes) ->
let res = B32.len input in
(res <: (res: U32.t { size32_postcond serialize_all_bytes input res } ))
inline_for_extraction
let size32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes_aux min max l))
=
size32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
size32_all_bytes
(U32.uint_to_t l)
inline_for_extraction
let size32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes' min max l))
=
size32_synth
(parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(size32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes)
)
(fun x -> x)
()
inline_for_extraction
let size32_bounded_vlbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
: Tot (size32 (serialize_bounded_vlbytes min max))
= size32_bounded_vlbytes' min max (log256' max)
inline_for_extraction
let parse32_bounded_vlgenbytes
(min: nat)
(min32: U32.t { U32.v min32 == min })
(max: nat{ min <= max /\ max > 0 })
(max32: U32.t { U32.v max32 == max })
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(pk32: parser32 pk)
: Tot (parser32 (parse_bounded_vlgenbytes min max pk))
= parse32_synth
(parse_bounded_vlgen min max pk serialize_all_bytes)
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vlgen min min32 max max32 pk32 serialize_all_bytes parse32_all_bytes)
()
inline_for_extraction
let serialize32_bounded_vlgenbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32: serializer32 sk {kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\ Some?.v kk.parser_kind_high + max < 4294967296 })
: Tot (serializer32 (serialize_bounded_vlgenbytes min max sk))
= serialize32_synth
(parse_bounded_vlgen min max pk serialize_all_bytes)
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(serialize_bounded_vlgen min max sk serialize_all_bytes)
(serialize32_bounded_vlgen min max sk32 serialize32_all_bytes)
(fun x -> x)
(fun x -> x)
()
inline_for_extraction
let size32_bounded_vlgenbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32: size32 sk {kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\ Some?.v kk.parser_kind_high + max < 4294967296 }) | false | false | LowParse.SLow.Bytes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val size32_bounded_vlgenbytes
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk)
(sk32:
size32 sk
{ kk.parser_kind_subkind == Some ParserStrong /\ Some? kk.parser_kind_high /\
Some?.v kk.parser_kind_high + max < 4294967296 })
: Tot (size32 (serialize_bounded_vlgenbytes min max sk)) | [] | LowParse.SLow.Bytes.size32_bounded_vlgenbytes | {
"file_name": "src/lowparse/LowParse.SLow.Bytes.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
sk32:
LowParse.SLow.Base.size32 sk
{ Mkparser_kind'?.parser_kind_subkind kk ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
Some? (Mkparser_kind'?.parser_kind_high kk) /\
Some?.v (Mkparser_kind'?.parser_kind_high kk) + max < 4294967296 }
-> LowParse.SLow.Base.size32 (LowParse.Spec.Bytes.serialize_bounded_vlgenbytes min max sk) | {
"end_col": 6,
"end_line": 224,
"start_col": 2,
"start_line": 217
} |
Prims.Tot | val serialize32_bounded_vlbytes'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (serializer32 (serialize_bounded_vlbytes' min max l)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLGen",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes' min max l))
= serialize32_synth
(parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(serialize32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes)
)
(fun x -> x)
() | val serialize32_bounded_vlbytes'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (serializer32 (serialize_bounded_vlbytes' min max l))
let serialize32_bounded_vlbytes'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (serializer32 (serialize_bounded_vlbytes' min max l)) = | false | null | false | serialize32_synth (parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(serialize32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes))
(fun x -> x)
() | {
"checked_file": "LowParse.SLow.Bytes.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.SLow.VLGen.fst.checked",
"LowParse.SLow.VLData.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Bytes.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.SLow.Combinators.serialize32_synth",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.Bytes.parse_all_bytes_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"FStar.Bytes.bytes",
"LowParse.Spec.Bytes.parse_all_bytes",
"LowParse.Spec.Bytes.serialize_all_bytes",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_t",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_aux",
"LowParse.Spec.Bytes.synth_bounded_vlbytes",
"LowParse.Spec.Bytes.serialize_bounded_vlbytes_aux",
"LowParse.SLow.Bytes.serialize32_bounded_vlbytes_aux",
"Prims.eq2",
"LowParse.SLow.Base.serializer32",
"LowParse.Spec.Bytes.parse_bounded_vlbytes'",
"LowParse.Spec.Bytes.serialize_bounded_vlbytes'"
] | [] | module LowParse.SLow.Bytes
include LowParse.Spec.Bytes
include LowParse.SLow.VLData
include LowParse.SLow.VLGen
module B32 = FStar.Bytes
module Seq = FStar.Seq
module U32 = FStar.UInt32
inline_for_extraction
let parse32_flbytes_gen
(sz: nat { sz < 4294967296 } )
(x: B32.lbytes sz)
: Tot (y: B32.lbytes sz { y == parse_flbytes_gen sz (B32.reveal x) } )
= B32.hide_reveal x;
x
#set-options "--z3rlimit 32"
inline_for_extraction
let parse32_flbytes
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
: Tot (
lt_pow2_32 sz;
parser32 (parse_flbytes sz)
)
= lt_pow2_32 sz;
make_total_constant_size_parser32
sz
sz'
#(B32.lbytes sz)
(parse_flbytes_gen sz)
()
(parse32_flbytes_gen sz)
inline_for_extraction
let serialize32_flbytes
(sz: nat { sz < 4294967296 } )
: Tot (serializer32 (serialize_flbytes sz))
= fun (input: B32.lbytes sz) ->
B32.hide_reveal input;
(input <: (res: bytes32 { serializer32_correct (serialize_flbytes sz) input res } ))
inline_for_extraction
let parse32_all_bytes
: parser32 parse_all_bytes
= fun (input: B32.bytes) ->
let res = Some (input, B32.len input) in
(res <: (res: option (bytes32 * U32.t) { parser32_correct parse_all_bytes input res } ))
inline_for_extraction
let serialize32_all_bytes
: serializer32 serialize_all_bytes
= fun (input: B32.bytes) ->
(input <: (res: bytes32 { serializer32_correct serialize_all_bytes input res } ))
inline_for_extraction
let parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (parser32 (parse_bounded_vlbytes' min max l))
= parse32_synth
_
(synth_bounded_vlbytes min max)
(fun (x: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes) -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vldata_strong' min min32 max max32 l serialize_all_bytes parse32_all_bytes)
()
inline_for_extraction
let parse32_bounded_vlbytes
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
: Tot (parser32 (parse_bounded_vlbytes min max))
= parse32_bounded_vlbytes' min min32 max max32 (log256' max)
inline_for_extraction
let serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l))
=
serialize32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
serialize32_all_bytes
inline_for_extraction
let serialize32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } ) | false | false | LowParse.SLow.Bytes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize32_bounded_vlbytes'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (serializer32 (serialize_bounded_vlbytes' min max l)) | [] | LowParse.SLow.Bytes.serialize32_bounded_vlbytes' | {
"file_name": "src/lowparse/LowParse.SLow.Bytes.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292} ->
l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4}
-> LowParse.SLow.Base.serializer32 (LowParse.Spec.Bytes.serialize_bounded_vlbytes' min max l) | {
"end_col": 6,
"end_line": 114,
"start_col": 2,
"start_line": 105
} |
Prims.Tot | val size32_bounded_vlbytes'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (size32 (serialize_bounded_vlbytes' min max l)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLGen",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let size32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes' min max l))
=
size32_synth
(parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(size32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes)
)
(fun x -> x)
() | val size32_bounded_vlbytes'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (size32 (serialize_bounded_vlbytes' min max l))
let size32_bounded_vlbytes'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (size32 (serialize_bounded_vlbytes' min max l)) = | false | null | false | size32_synth (parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(size32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes))
(fun x -> x)
() | {
"checked_file": "LowParse.SLow.Bytes.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.SLow.VLGen.fst.checked",
"LowParse.SLow.VLData.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Bytes.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.SLow.Combinators.size32_synth",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.Bytes.parse_all_bytes_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"FStar.Bytes.bytes",
"LowParse.Spec.Bytes.parse_all_bytes",
"LowParse.Spec.Bytes.serialize_all_bytes",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_t",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_aux",
"LowParse.Spec.Bytes.synth_bounded_vlbytes",
"LowParse.Spec.Bytes.serialize_bounded_vlbytes_aux",
"LowParse.SLow.Bytes.size32_bounded_vlbytes_aux",
"Prims.eq2",
"LowParse.SLow.Base.size32",
"LowParse.Spec.Bytes.parse_bounded_vlbytes'",
"LowParse.Spec.Bytes.serialize_bounded_vlbytes'"
] | [] | module LowParse.SLow.Bytes
include LowParse.Spec.Bytes
include LowParse.SLow.VLData
include LowParse.SLow.VLGen
module B32 = FStar.Bytes
module Seq = FStar.Seq
module U32 = FStar.UInt32
inline_for_extraction
let parse32_flbytes_gen
(sz: nat { sz < 4294967296 } )
(x: B32.lbytes sz)
: Tot (y: B32.lbytes sz { y == parse_flbytes_gen sz (B32.reveal x) } )
= B32.hide_reveal x;
x
#set-options "--z3rlimit 32"
inline_for_extraction
let parse32_flbytes
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
: Tot (
lt_pow2_32 sz;
parser32 (parse_flbytes sz)
)
= lt_pow2_32 sz;
make_total_constant_size_parser32
sz
sz'
#(B32.lbytes sz)
(parse_flbytes_gen sz)
()
(parse32_flbytes_gen sz)
inline_for_extraction
let serialize32_flbytes
(sz: nat { sz < 4294967296 } )
: Tot (serializer32 (serialize_flbytes sz))
= fun (input: B32.lbytes sz) ->
B32.hide_reveal input;
(input <: (res: bytes32 { serializer32_correct (serialize_flbytes sz) input res } ))
inline_for_extraction
let parse32_all_bytes
: parser32 parse_all_bytes
= fun (input: B32.bytes) ->
let res = Some (input, B32.len input) in
(res <: (res: option (bytes32 * U32.t) { parser32_correct parse_all_bytes input res } ))
inline_for_extraction
let serialize32_all_bytes
: serializer32 serialize_all_bytes
= fun (input: B32.bytes) ->
(input <: (res: bytes32 { serializer32_correct serialize_all_bytes input res } ))
inline_for_extraction
let parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (parser32 (parse_bounded_vlbytes' min max l))
= parse32_synth
_
(synth_bounded_vlbytes min max)
(fun (x: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes) -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vldata_strong' min min32 max max32 l serialize_all_bytes parse32_all_bytes)
()
inline_for_extraction
let parse32_bounded_vlbytes
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
: Tot (parser32 (parse_bounded_vlbytes min max))
= parse32_bounded_vlbytes' min min32 max max32 (log256' max)
inline_for_extraction
let serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l))
=
serialize32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
serialize32_all_bytes
inline_for_extraction
let serialize32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes' min max l))
= serialize32_synth
(parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(serialize32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes)
)
(fun x -> x)
()
inline_for_extraction
let serialize32_bounded_vlbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
: Tot (serializer32 (serialize_bounded_vlbytes min max))
= serialize32_bounded_vlbytes' min max (log256' max)
inline_for_extraction
let size32_all_bytes
: size32 serialize_all_bytes
= fun (input: B32.bytes) ->
let res = B32.len input in
(res <: (res: U32.t { size32_postcond serialize_all_bytes input res } ))
inline_for_extraction
let size32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes_aux min max l))
=
size32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
size32_all_bytes
(U32.uint_to_t l)
inline_for_extraction
let size32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes' min max l)) | false | false | LowParse.SLow.Bytes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val size32_bounded_vlbytes'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (size32 (serialize_bounded_vlbytes' min max l)) | [] | LowParse.SLow.Bytes.size32_bounded_vlbytes' | {
"file_name": "src/lowparse/LowParse.SLow.Bytes.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292} ->
l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4}
-> LowParse.SLow.Base.size32 (LowParse.Spec.Bytes.serialize_bounded_vlbytes' min max l) | {
"end_col": 6,
"end_line": 164,
"start_col": 2,
"start_line": 155
} |
Prims.Tot | val parse32_bounded_vlgenbytes
(min: nat)
(min32: U32.t{U32.v min32 == min})
(max: nat{min <= max /\ max > 0})
(max32: U32.t{U32.v max32 == max})
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(pk32: parser32 pk)
: Tot (parser32 (parse_bounded_vlgenbytes min max pk)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLGen",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse32_bounded_vlgenbytes
(min: nat)
(min32: U32.t { U32.v min32 == min })
(max: nat{ min <= max /\ max > 0 })
(max32: U32.t { U32.v max32 == max })
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(pk32: parser32 pk)
: Tot (parser32 (parse_bounded_vlgenbytes min max pk))
= parse32_synth
(parse_bounded_vlgen min max pk serialize_all_bytes)
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vlgen min min32 max max32 pk32 serialize_all_bytes parse32_all_bytes)
() | val parse32_bounded_vlgenbytes
(min: nat)
(min32: U32.t{U32.v min32 == min})
(max: nat{min <= max /\ max > 0})
(max32: U32.t{U32.v max32 == max})
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(pk32: parser32 pk)
: Tot (parser32 (parse_bounded_vlgenbytes min max pk))
let parse32_bounded_vlgenbytes
(min: nat)
(min32: U32.t{U32.v min32 == min})
(max: nat{min <= max /\ max > 0})
(max32: U32.t{U32.v max32 == max})
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(pk32: parser32 pk)
: Tot (parser32 (parse_bounded_vlgenbytes min max pk)) = | false | null | false | parse32_synth (parse_bounded_vlgen min max pk serialize_all_bytes)
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(fun x -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vlgen min min32 max max32 pk32 serialize_all_bytes parse32_all_bytes)
() | {
"checked_file": "LowParse.SLow.Bytes.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.SLow.VLGen.fst.checked",
"LowParse.SLow.VLData.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Bytes.fst"
} | [
"total"
] | [
"Prims.nat",
"FStar.UInt32.t",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.SLow.Base.parser32",
"LowParse.SLow.Combinators.parse32_synth",
"LowParse.Spec.VLGen.parse_bounded_vlgen_kind",
"LowParse.Spec.Bytes.parse_all_bytes_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"FStar.Bytes.bytes",
"LowParse.Spec.Bytes.parse_all_bytes",
"LowParse.Spec.Bytes.serialize_all_bytes",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_t",
"LowParse.Spec.VLGen.parse_bounded_vlgen",
"LowParse.SLow.VLGen.parse32_bounded_vlgen",
"LowParse.SLow.Bytes.parse32_all_bytes",
"LowParse.Spec.Bytes.parse_bounded_vlgenbytes"
] | [] | module LowParse.SLow.Bytes
include LowParse.Spec.Bytes
include LowParse.SLow.VLData
include LowParse.SLow.VLGen
module B32 = FStar.Bytes
module Seq = FStar.Seq
module U32 = FStar.UInt32
inline_for_extraction
let parse32_flbytes_gen
(sz: nat { sz < 4294967296 } )
(x: B32.lbytes sz)
: Tot (y: B32.lbytes sz { y == parse_flbytes_gen sz (B32.reveal x) } )
= B32.hide_reveal x;
x
#set-options "--z3rlimit 32"
inline_for_extraction
let parse32_flbytes
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
: Tot (
lt_pow2_32 sz;
parser32 (parse_flbytes sz)
)
= lt_pow2_32 sz;
make_total_constant_size_parser32
sz
sz'
#(B32.lbytes sz)
(parse_flbytes_gen sz)
()
(parse32_flbytes_gen sz)
inline_for_extraction
let serialize32_flbytes
(sz: nat { sz < 4294967296 } )
: Tot (serializer32 (serialize_flbytes sz))
= fun (input: B32.lbytes sz) ->
B32.hide_reveal input;
(input <: (res: bytes32 { serializer32_correct (serialize_flbytes sz) input res } ))
inline_for_extraction
let parse32_all_bytes
: parser32 parse_all_bytes
= fun (input: B32.bytes) ->
let res = Some (input, B32.len input) in
(res <: (res: option (bytes32 * U32.t) { parser32_correct parse_all_bytes input res } ))
inline_for_extraction
let serialize32_all_bytes
: serializer32 serialize_all_bytes
= fun (input: B32.bytes) ->
(input <: (res: bytes32 { serializer32_correct serialize_all_bytes input res } ))
inline_for_extraction
let parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (parser32 (parse_bounded_vlbytes' min max l))
= parse32_synth
_
(synth_bounded_vlbytes min max)
(fun (x: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes) -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vldata_strong' min min32 max max32 l serialize_all_bytes parse32_all_bytes)
()
inline_for_extraction
let parse32_bounded_vlbytes
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
: Tot (parser32 (parse_bounded_vlbytes min max))
= parse32_bounded_vlbytes' min min32 max max32 (log256' max)
inline_for_extraction
let serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l))
=
serialize32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
serialize32_all_bytes
inline_for_extraction
let serialize32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes' min max l))
= serialize32_synth
(parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(serialize32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes)
)
(fun x -> x)
()
inline_for_extraction
let serialize32_bounded_vlbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
: Tot (serializer32 (serialize_bounded_vlbytes min max))
= serialize32_bounded_vlbytes' min max (log256' max)
inline_for_extraction
let size32_all_bytes
: size32 serialize_all_bytes
= fun (input: B32.bytes) ->
let res = B32.len input in
(res <: (res: U32.t { size32_postcond serialize_all_bytes input res } ))
inline_for_extraction
let size32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes_aux min max l))
=
size32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
size32_all_bytes
(U32.uint_to_t l)
inline_for_extraction
let size32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes' min max l))
=
size32_synth
(parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(size32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes)
)
(fun x -> x)
()
inline_for_extraction
let size32_bounded_vlbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
: Tot (size32 (serialize_bounded_vlbytes min max))
= size32_bounded_vlbytes' min max (log256' max)
inline_for_extraction
let parse32_bounded_vlgenbytes
(min: nat)
(min32: U32.t { U32.v min32 == min })
(max: nat{ min <= max /\ max > 0 })
(max32: U32.t { U32.v max32 == max })
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(pk32: parser32 pk) | false | false | LowParse.SLow.Bytes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse32_bounded_vlgenbytes
(min: nat)
(min32: U32.t{U32.v min32 == min})
(max: nat{min <= max /\ max > 0})
(max32: U32.t{U32.v max32 == max})
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(pk32: parser32 pk)
: Tot (parser32 (parse_bounded_vlgenbytes min max pk)) | [] | LowParse.SLow.Bytes.parse32_bounded_vlgenbytes | {
"file_name": "src/lowparse/LowParse.SLow.Bytes.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
min32: FStar.UInt32.t{FStar.UInt32.v min32 == min} ->
max: Prims.nat{min <= max /\ max > 0} ->
max32: FStar.UInt32.t{FStar.UInt32.v max32 == max} ->
pk32: LowParse.SLow.Base.parser32 pk
-> LowParse.SLow.Base.parser32 (LowParse.Spec.Bytes.parse_bounded_vlgenbytes min max pk) | {
"end_col": 6,
"end_line": 188,
"start_col": 2,
"start_line": 183
} |
Prims.Tot | val parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t{U32.v min32 == min})
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(max32: U32.t{U32.v max32 == max})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (parser32 (parse_bounded_vlbytes' min max l)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLGen",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (parser32 (parse_bounded_vlbytes' min max l))
= parse32_synth
_
(synth_bounded_vlbytes min max)
(fun (x: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes) -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vldata_strong' min min32 max max32 l serialize_all_bytes parse32_all_bytes)
() | val parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t{U32.v min32 == min})
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(max32: U32.t{U32.v max32 == max})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (parser32 (parse_bounded_vlbytes' min max l))
let parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t{U32.v min32 == min})
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(max32: U32.t{U32.v max32 == max})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (parser32 (parse_bounded_vlbytes' min max l)) = | false | null | false | parse32_synth _
(synth_bounded_vlbytes min max)
(fun (x: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes) ->
(x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vldata_strong' min min32 max max32 l serialize_all_bytes parse32_all_bytes)
() | {
"checked_file": "LowParse.SLow.Bytes.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.SLow.VLGen.fst.checked",
"LowParse.SLow.VLData.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Bytes.fst"
} | [
"total"
] | [
"Prims.nat",
"FStar.UInt32.t",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.SLow.Combinators.parse32_synth",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.Bytes.parse_all_bytes_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"FStar.Bytes.bytes",
"LowParse.Spec.Bytes.parse_all_bytes",
"LowParse.Spec.Bytes.serialize_all_bytes",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong'",
"LowParse.Spec.Bytes.synth_bounded_vlbytes",
"LowParse.SLow.VLData.parse32_bounded_vldata_strong'",
"LowParse.SLow.Bytes.parse32_all_bytes",
"LowParse.SLow.Base.parser32",
"LowParse.Spec.Bytes.parse_bounded_vlbytes'"
] | [] | module LowParse.SLow.Bytes
include LowParse.Spec.Bytes
include LowParse.SLow.VLData
include LowParse.SLow.VLGen
module B32 = FStar.Bytes
module Seq = FStar.Seq
module U32 = FStar.UInt32
inline_for_extraction
let parse32_flbytes_gen
(sz: nat { sz < 4294967296 } )
(x: B32.lbytes sz)
: Tot (y: B32.lbytes sz { y == parse_flbytes_gen sz (B32.reveal x) } )
= B32.hide_reveal x;
x
#set-options "--z3rlimit 32"
inline_for_extraction
let parse32_flbytes
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
: Tot (
lt_pow2_32 sz;
parser32 (parse_flbytes sz)
)
= lt_pow2_32 sz;
make_total_constant_size_parser32
sz
sz'
#(B32.lbytes sz)
(parse_flbytes_gen sz)
()
(parse32_flbytes_gen sz)
inline_for_extraction
let serialize32_flbytes
(sz: nat { sz < 4294967296 } )
: Tot (serializer32 (serialize_flbytes sz))
= fun (input: B32.lbytes sz) ->
B32.hide_reveal input;
(input <: (res: bytes32 { serializer32_correct (serialize_flbytes sz) input res } ))
inline_for_extraction
let parse32_all_bytes
: parser32 parse_all_bytes
= fun (input: B32.bytes) ->
let res = Some (input, B32.len input) in
(res <: (res: option (bytes32 * U32.t) { parser32_correct parse_all_bytes input res } ))
inline_for_extraction
let serialize32_all_bytes
: serializer32 serialize_all_bytes
= fun (input: B32.bytes) ->
(input <: (res: bytes32 { serializer32_correct serialize_all_bytes input res } ))
inline_for_extraction
let parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
(l: nat { l >= log256' max /\ l <= 4 } ) | false | false | LowParse.SLow.Bytes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t{U32.v min32 == min})
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(max32: U32.t{U32.v max32 == max})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (parser32 (parse_bounded_vlbytes' min max l)) | [] | LowParse.SLow.Bytes.parse32_bounded_vlbytes' | {
"file_name": "src/lowparse/LowParse.SLow.Bytes.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
min32: FStar.UInt32.t{FStar.UInt32.v min32 == min} ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
max32: FStar.UInt32.t{FStar.UInt32.v max32 == max} ->
l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4}
-> LowParse.SLow.Base.parser32 (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l) | {
"end_col": 6,
"end_line": 71,
"start_col": 2,
"start_line": 66
} |
Prims.Tot | val size32_bounded_vlbytes_aux
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (size32 (serialize_bounded_vlbytes_aux min max l)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "B32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLGen",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let size32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes_aux min max l))
=
size32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
size32_all_bytes
(U32.uint_to_t l) | val size32_bounded_vlbytes_aux
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (size32 (serialize_bounded_vlbytes_aux min max l))
let size32_bounded_vlbytes_aux
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (size32 (serialize_bounded_vlbytes_aux min max l)) = | false | null | false | size32_bounded_vldata_strong' min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
size32_all_bytes
(U32.uint_to_t l) | {
"checked_file": "LowParse.SLow.Bytes.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.SLow.VLGen.fst.checked",
"LowParse.SLow.VLData.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Bytes.fst"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.SLow.VLData.size32_bounded_vldata_strong'",
"LowParse.Spec.Bytes.parse_all_bytes_kind",
"FStar.Bytes.bytes",
"LowParse.Spec.Bytes.parse_all_bytes",
"LowParse.Spec.Bytes.serialize_all_bytes",
"LowParse.SLow.Bytes.size32_all_bytes",
"FStar.UInt32.uint_to_t",
"LowParse.SLow.Base.size32",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_aux",
"LowParse.Spec.Bytes.serialize_bounded_vlbytes_aux"
] | [] | module LowParse.SLow.Bytes
include LowParse.Spec.Bytes
include LowParse.SLow.VLData
include LowParse.SLow.VLGen
module B32 = FStar.Bytes
module Seq = FStar.Seq
module U32 = FStar.UInt32
inline_for_extraction
let parse32_flbytes_gen
(sz: nat { sz < 4294967296 } )
(x: B32.lbytes sz)
: Tot (y: B32.lbytes sz { y == parse_flbytes_gen sz (B32.reveal x) } )
= B32.hide_reveal x;
x
#set-options "--z3rlimit 32"
inline_for_extraction
let parse32_flbytes
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
: Tot (
lt_pow2_32 sz;
parser32 (parse_flbytes sz)
)
= lt_pow2_32 sz;
make_total_constant_size_parser32
sz
sz'
#(B32.lbytes sz)
(parse_flbytes_gen sz)
()
(parse32_flbytes_gen sz)
inline_for_extraction
let serialize32_flbytes
(sz: nat { sz < 4294967296 } )
: Tot (serializer32 (serialize_flbytes sz))
= fun (input: B32.lbytes sz) ->
B32.hide_reveal input;
(input <: (res: bytes32 { serializer32_correct (serialize_flbytes sz) input res } ))
inline_for_extraction
let parse32_all_bytes
: parser32 parse_all_bytes
= fun (input: B32.bytes) ->
let res = Some (input, B32.len input) in
(res <: (res: option (bytes32 * U32.t) { parser32_correct parse_all_bytes input res } ))
inline_for_extraction
let serialize32_all_bytes
: serializer32 serialize_all_bytes
= fun (input: B32.bytes) ->
(input <: (res: bytes32 { serializer32_correct serialize_all_bytes input res } ))
inline_for_extraction
let parse32_bounded_vlbytes'
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (parser32 (parse_bounded_vlbytes' min max l))
= parse32_synth
_
(synth_bounded_vlbytes min max)
(fun (x: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes) -> (x <: parse_bounded_vlbytes_t min max))
(parse32_bounded_vldata_strong' min min32 max max32 l serialize_all_bytes parse32_all_bytes)
()
inline_for_extraction
let parse32_bounded_vlbytes
(min: nat)
(min32: U32.t { U32.v min32 == min } )
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(max32: U32.t { U32.v max32 == max } )
: Tot (parser32 (parse_bounded_vlbytes min max))
= parse32_bounded_vlbytes' min min32 max max32 (log256' max)
inline_for_extraction
let serialize32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes_aux min max l))
=
serialize32_bounded_vldata_strong'
min
max
l
#_
#_
#parse_all_bytes
#serialize_all_bytes
serialize32_all_bytes
inline_for_extraction
let serialize32_bounded_vlbytes'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (serializer32 (serialize_bounded_vlbytes' min max l))
= serialize32_synth
(parse_bounded_vlbytes_aux min max l)
(synth_bounded_vlbytes min max)
(serialize_bounded_vlbytes_aux min max l)
(serialize32_bounded_vlbytes_aux min max l)
(fun (x: parse_bounded_vlbytes_t min max) ->
(x <: parse_bounded_vldata_strong_t min max #_ #_ #parse_all_bytes serialize_all_bytes)
)
(fun x -> x)
()
inline_for_extraction
let serialize32_bounded_vlbytes
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
: Tot (serializer32 (serialize_bounded_vlbytes min max))
= serialize32_bounded_vlbytes' min max (log256' max)
inline_for_extraction
let size32_all_bytes
: size32 serialize_all_bytes
= fun (input: B32.bytes) ->
let res = B32.len input in
(res <: (res: U32.t { size32_postcond serialize_all_bytes input res } ))
inline_for_extraction
let size32_bounded_vlbytes_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // max MUST BE less than 2^32 - 4
(l: nat { l >= log256' max /\ l <= 4 } )
: Tot (size32 (serialize_bounded_vlbytes_aux min max l)) | false | false | LowParse.SLow.Bytes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val size32_bounded_vlbytes_aux
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967292})
(l: nat{l >= log256' max /\ l <= 4})
: Tot (size32 (serialize_bounded_vlbytes_aux min max l)) | [] | LowParse.SLow.Bytes.size32_bounded_vlbytes_aux | {
"file_name": "src/lowparse/LowParse.SLow.Bytes.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292} ->
l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4}
-> LowParse.SLow.Base.size32 (LowParse.Spec.Bytes.serialize_bounded_vlbytes_aux min max l) | {
"end_col": 21,
"end_line": 146,
"start_col": 2,
"start_line": 137
} |
Prims.Tot | val ec1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> x:uint64
-> k:size_t{v k < 8}
-> res:uint16{res == S.ec1 (v logq) (v b) x (v k)} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Encode",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ec1 logq b x k =
Spec.Frodo.Lemmas.modulo_pow2_u64 (x >>. (b *! k)) (v b);
let rk = (x >>. (b *! k)) &. ((u64 1 <<. b) -. u64 1) in
ec logq b (to_u16 rk) | val ec1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> x:uint64
-> k:size_t{v k < 8}
-> res:uint16{res == S.ec1 (v logq) (v b) x (v k)}
let ec1 logq b x k = | false | null | false | Spec.Frodo.Lemmas.modulo_pow2_u64 (x >>. (b *! k)) (v b);
let rk = (x >>. (b *! k)) &. ((u64 1 <<. b) -. u64 1) in
ec logq b (to_u16 rk) | {
"checked_file": "Hacl.Impl.Frodo.Encode.fst.checked",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"Spec.Frodo.Encode.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Encode.fst"
} | [
"total"
] | [
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.uint64",
"Hacl.Impl.Frodo.Encode.ec",
"Lib.IntTypes.to_u16",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Amp_Dot",
"Lib.IntTypes.op_Greater_Greater_Dot",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.u64",
"Prims.unit",
"Spec.Frodo.Lemmas.modulo_pow2_u64",
"Lib.IntTypes.uint16",
"Prims.eq2",
"Spec.Frodo.Encode.ec1"
] | [] | module Hacl.Impl.Frodo.Encode
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
module S = Spec.Frodo.Encode
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract private
val ec:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= v logq}
-> k:uint16{v k < pow2 (v b)}
-> r:uint16{r == S.ec (v logq) (v b) k}
let ec logq b a =
a <<. (logq -. b)
inline_for_extraction noextract private
val dc:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b < v logq}
-> c:uint16
-> r:uint16{r == S.dc (v logq) (v b) c}
let dc logq b c =
let res1 = (c +. (u16 1 <<. (logq -. b -. size 1))) >>. (logq -. b) in
res1 &. ((u16 1 <<. b) -. u16 1)
inline_for_extraction noextract private
val ec1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> x:uint64
-> k:size_t{v k < 8}
-> res:uint16{res == S.ec1 (v logq) (v b) x (v k)} | false | false | Hacl.Impl.Frodo.Encode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ec1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> x:uint64
-> k:size_t{v k < 8}
-> res:uint16{res == S.ec1 (v logq) (v b) x (v k)} | [] | Hacl.Impl.Frodo.Encode.ec1 | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Encode.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
logq: Lib.IntTypes.size_t{0 < Lib.IntTypes.v logq /\ Lib.IntTypes.v logq <= 16} ->
b:
Lib.IntTypes.size_t
{0 < Lib.IntTypes.v b /\ Lib.IntTypes.v b <= 8 /\ Lib.IntTypes.v b <= Lib.IntTypes.v logq} ->
x: Lib.IntTypes.uint64 ->
k: Lib.IntTypes.size_t{Lib.IntTypes.v k < 8}
-> res:
Lib.IntTypes.uint16
{res == Spec.Frodo.Encode.ec1 (Lib.IntTypes.v logq) (Lib.IntTypes.v b) x (Lib.IntTypes.v k)} | {
"end_col": 23,
"end_line": 56,
"start_col": 2,
"start_line": 54
} |
Prims.Tot | val ec:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= v logq}
-> k:uint16{v k < pow2 (v b)}
-> r:uint16{r == S.ec (v logq) (v b) k} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Encode",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ec logq b a =
a <<. (logq -. b) | val ec:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= v logq}
-> k:uint16{v k < pow2 (v b)}
-> r:uint16{r == S.ec (v logq) (v b) k}
let ec logq b a = | false | null | false | a <<. (logq -. b) | {
"checked_file": "Hacl.Impl.Frodo.Encode.fst.checked",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"Spec.Frodo.Encode.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Encode.fst"
} | [
"total"
] | [
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.uint16",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.op_Subtraction_Dot",
"Prims.eq2",
"Spec.Frodo.Encode.ec"
] | [] | module Hacl.Impl.Frodo.Encode
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
module S = Spec.Frodo.Encode
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract private
val ec:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= v logq}
-> k:uint16{v k < pow2 (v b)}
-> r:uint16{r == S.ec (v logq) (v b) k} | false | false | Hacl.Impl.Frodo.Encode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ec:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= v logq}
-> k:uint16{v k < pow2 (v b)}
-> r:uint16{r == S.ec (v logq) (v b) k} | [] | Hacl.Impl.Frodo.Encode.ec | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Encode.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
logq: Lib.IntTypes.size_t{0 < Lib.IntTypes.v logq /\ Lib.IntTypes.v logq <= 16} ->
b: Lib.IntTypes.size_t{0 < Lib.IntTypes.v b /\ Lib.IntTypes.v b <= Lib.IntTypes.v logq} ->
k: Lib.IntTypes.uint16{Lib.IntTypes.v k < Prims.pow2 (Lib.IntTypes.v b)}
-> r: Lib.IntTypes.uint16{r == Spec.Frodo.Encode.ec (Lib.IntTypes.v logq) (Lib.IntTypes.v b) k} | {
"end_col": 19,
"end_line": 30,
"start_col": 2,
"start_line": 30
} |
Prims.Tot | val dc:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b < v logq}
-> c:uint16
-> r:uint16{r == S.dc (v logq) (v b) c} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Encode",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let dc logq b c =
let res1 = (c +. (u16 1 <<. (logq -. b -. size 1))) >>. (logq -. b) in
res1 &. ((u16 1 <<. b) -. u16 1) | val dc:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b < v logq}
-> c:uint16
-> r:uint16{r == S.dc (v logq) (v b) c}
let dc logq b c = | false | null | false | let res1 = (c +. (u16 1 <<. (logq -. b -. size 1))) >>. (logq -. b) in
res1 &. ((u16 1 <<. b) -. u16 1) | {
"checked_file": "Hacl.Impl.Frodo.Encode.fst.checked",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"Spec.Frodo.Encode.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Encode.fst"
} | [
"total"
] | [
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.uint16",
"Lib.IntTypes.op_Amp_Dot",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.u16",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Greater_Greater_Dot",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.size",
"Prims.eq2",
"Spec.Frodo.Encode.dc"
] | [] | module Hacl.Impl.Frodo.Encode
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
module S = Spec.Frodo.Encode
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract private
val ec:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= v logq}
-> k:uint16{v k < pow2 (v b)}
-> r:uint16{r == S.ec (v logq) (v b) k}
let ec logq b a =
a <<. (logq -. b)
inline_for_extraction noextract private
val dc:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b < v logq}
-> c:uint16
-> r:uint16{r == S.dc (v logq) (v b) c} | false | false | Hacl.Impl.Frodo.Encode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val dc:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b < v logq}
-> c:uint16
-> r:uint16{r == S.dc (v logq) (v b) c} | [] | Hacl.Impl.Frodo.Encode.dc | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Encode.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
logq: Lib.IntTypes.size_t{0 < Lib.IntTypes.v logq /\ Lib.IntTypes.v logq <= 16} ->
b: Lib.IntTypes.size_t{0 < Lib.IntTypes.v b /\ Lib.IntTypes.v b < Lib.IntTypes.v logq} ->
c: Lib.IntTypes.uint16
-> r: Lib.IntTypes.uint16{r == Spec.Frodo.Encode.dc (Lib.IntTypes.v logq) (Lib.IntTypes.v b) c} | {
"end_col": 34,
"end_line": 42,
"start_col": 17,
"start_line": 40
} |
FStar.HyperStack.ST.Stack | val frodo_key_encode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> x:uint64
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
Loops.repeati 8 (S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i)) (as_matrix h0 res)) | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Encode",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let frodo_key_encode2 logq b n a i x res =
[@ inline_let]
let spec h0 = S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i) in
let h0 = ST.get () in
loop1 h0 (size 8) res spec
(fun k ->
Loops.unfold_repeati 8 (spec h0) (as_seq h0 res) (v k);
mset res i k (ec1 logq b x k)
) | val frodo_key_encode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> x:uint64
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
Loops.repeati 8 (S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i)) (as_matrix h0 res))
let frodo_key_encode2 logq b n a i x res = | true | null | false | [@@ inline_let ]let spec h0 = S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i) in
let h0 = ST.get () in
loop1 h0
(size 8)
res
spec
(fun k ->
Loops.unfold_repeati 8 (spec h0) (as_seq h0 res) (v k);
mset res i k (ec1 logq b x k)) | {
"checked_file": "Hacl.Impl.Frodo.Encode.fst.checked",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"Spec.Frodo.Encode.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Encode.fst"
} | [] | [
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Prims.int",
"Hacl.Impl.Matrix.lbytes",
"Lib.IntTypes.op_Slash_Dot",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.size",
"Lib.IntTypes.uint64",
"Hacl.Impl.Matrix.matrix_t",
"Lib.Buffer.loop1",
"Hacl.Impl.Matrix.elem",
"Hacl.Impl.Matrix.mset",
"Hacl.Impl.Frodo.Encode.ec1",
"Prims.unit",
"Lib.LoopCombinators.unfold_repeati",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Prims.op_Multiply",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.nat",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Frodo.Encode.frodo_key_encode0",
"Lib.IntTypes.uint8"
] | [] | module Hacl.Impl.Frodo.Encode
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
module S = Spec.Frodo.Encode
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract private
val ec:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= v logq}
-> k:uint16{v k < pow2 (v b)}
-> r:uint16{r == S.ec (v logq) (v b) k}
let ec logq b a =
a <<. (logq -. b)
inline_for_extraction noextract private
val dc:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b < v logq}
-> c:uint16
-> r:uint16{r == S.dc (v logq) (v b) c}
let dc logq b c =
let res1 = (c +. (u16 1 <<. (logq -. b -. size 1))) >>. (logq -. b) in
res1 &. ((u16 1 <<. b) -. u16 1)
inline_for_extraction noextract private
val ec1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> x:uint64
-> k:size_t{v k < 8}
-> res:uint16{res == S.ec1 (v logq) (v b) x (v k)}
let ec1 logq b x k =
Spec.Frodo.Lemmas.modulo_pow2_u64 (x >>. (b *! k)) (v b);
let rk = (x >>. (b *! k)) &. ((u64 1 <<. b) -. u64 1) in
ec logq b (to_u16 rk)
inline_for_extraction noextract private
val frodo_key_encode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.frodo_key_encode1 (v logq) (v b) (v n) (as_seq h0 a) (v i))
let frodo_key_encode1 logq b n a i =
let h0 = ST.get() in
push_frame();
let v8 = create (size 8) (u8 0) in
let chunk = sub a (i *! b) b in
let h1 = ST.get() in
assert (as_seq h1 chunk == LSeq.sub (as_seq h0 a) (v (i *! b)) (v b));
update_sub v8 (size 0) b chunk;
let x = uint_from_bytes_le #U64 v8 in
pop_frame();
x
inline_for_extraction noextract private
val frodo_key_encode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> x:uint64
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
Loops.repeati 8 (S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i)) (as_matrix h0 res)) | false | false | Hacl.Impl.Frodo.Encode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val frodo_key_encode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> x:uint64
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
Loops.repeati 8 (S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i)) (as_matrix h0 res)) | [] | Hacl.Impl.Frodo.Encode.frodo_key_encode2 | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Encode.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
logq: Lib.IntTypes.size_t{0 < Lib.IntTypes.v logq /\ Lib.IntTypes.v logq <= 16} ->
b:
Lib.IntTypes.size_t
{0 < Lib.IntTypes.v b /\ Lib.IntTypes.v b <= 8 /\ Lib.IntTypes.v b <= Lib.IntTypes.v logq} ->
n: Lib.IntTypes.size_t{Lib.IntTypes.v n == 8} ->
a: Hacl.Impl.Matrix.lbytes (n *! n *! b /. Lib.IntTypes.size 8) ->
i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n} ->
x: Lib.IntTypes.uint64 ->
res: Hacl.Impl.Matrix.matrix_t n n
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 3,
"end_line": 108,
"start_col": 2,
"start_line": 101
} |
FStar.HyperStack.ST.Stack | val frodo_key_encode:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res /\
as_seq h res == Spec.Matrix.create (v n) (v n))
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_key_encode (v logq) (v b) (v n) (as_seq h0 a)) | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Encode",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let frodo_key_encode logq b n a res =
let h0 = ST.get () in
[@ inline_let]
let spec h0 = S.frodo_key_encode2 (v logq) (v b) (v n) (as_seq h0 a) in
loop1 h0 n res spec
(fun i ->
Loops.unfold_repeati (v n) (spec h0) (as_seq h0 res) (v i);
let x = frodo_key_encode1 logq b n a i in
frodo_key_encode2 logq b n a i x res
) | val frodo_key_encode:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res /\
as_seq h res == Spec.Matrix.create (v n) (v n))
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_key_encode (v logq) (v b) (v n) (as_seq h0 a))
let frodo_key_encode logq b n a res = | true | null | false | let h0 = ST.get () in
[@@ inline_let ]let spec h0 = S.frodo_key_encode2 (v logq) (v b) (v n) (as_seq h0 a) in
loop1 h0
n
res
spec
(fun i ->
Loops.unfold_repeati (v n) (spec h0) (as_seq h0 res) (v i);
let x = frodo_key_encode1 logq b n a i in
frodo_key_encode2 logq b n a i x res) | {
"checked_file": "Hacl.Impl.Frodo.Encode.fst.checked",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"Spec.Frodo.Encode.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Encode.fst"
} | [] | [
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Prims.int",
"Hacl.Impl.Matrix.lbytes",
"Lib.IntTypes.op_Slash_Dot",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.size",
"Hacl.Impl.Matrix.matrix_t",
"Lib.Buffer.loop1",
"Hacl.Impl.Matrix.elem",
"Hacl.Impl.Frodo.Encode.frodo_key_encode2",
"Prims.unit",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Hacl.Impl.Frodo.Encode.frodo_key_encode1",
"Lib.IntTypes.uint64",
"Lib.LoopCombinators.unfold_repeati",
"Lib.Sequence.lseq",
"Lib.IntTypes.U16",
"Prims.op_Multiply",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Frodo.Encode.frodo_key_encode2",
"Lib.IntTypes.uint8",
"FStar.HyperStack.ST.get"
] | [] | module Hacl.Impl.Frodo.Encode
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
module S = Spec.Frodo.Encode
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract private
val ec:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= v logq}
-> k:uint16{v k < pow2 (v b)}
-> r:uint16{r == S.ec (v logq) (v b) k}
let ec logq b a =
a <<. (logq -. b)
inline_for_extraction noextract private
val dc:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b < v logq}
-> c:uint16
-> r:uint16{r == S.dc (v logq) (v b) c}
let dc logq b c =
let res1 = (c +. (u16 1 <<. (logq -. b -. size 1))) >>. (logq -. b) in
res1 &. ((u16 1 <<. b) -. u16 1)
inline_for_extraction noextract private
val ec1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> x:uint64
-> k:size_t{v k < 8}
-> res:uint16{res == S.ec1 (v logq) (v b) x (v k)}
let ec1 logq b x k =
Spec.Frodo.Lemmas.modulo_pow2_u64 (x >>. (b *! k)) (v b);
let rk = (x >>. (b *! k)) &. ((u64 1 <<. b) -. u64 1) in
ec logq b (to_u16 rk)
inline_for_extraction noextract private
val frodo_key_encode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.frodo_key_encode1 (v logq) (v b) (v n) (as_seq h0 a) (v i))
let frodo_key_encode1 logq b n a i =
let h0 = ST.get() in
push_frame();
let v8 = create (size 8) (u8 0) in
let chunk = sub a (i *! b) b in
let h1 = ST.get() in
assert (as_seq h1 chunk == LSeq.sub (as_seq h0 a) (v (i *! b)) (v b));
update_sub v8 (size 0) b chunk;
let x = uint_from_bytes_le #U64 v8 in
pop_frame();
x
inline_for_extraction noextract private
val frodo_key_encode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> x:uint64
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
Loops.repeati 8 (S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i)) (as_matrix h0 res))
let frodo_key_encode2 logq b n a i x res =
[@ inline_let]
let spec h0 = S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i) in
let h0 = ST.get () in
loop1 h0 (size 8) res spec
(fun k ->
Loops.unfold_repeati 8 (spec h0) (as_seq h0 res) (v k);
mset res i k (ec1 logq b x k)
)
val frodo_key_encode:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res /\
as_seq h res == Spec.Matrix.create (v n) (v n))
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_key_encode (v logq) (v b) (v n) (as_seq h0 a)) | false | false | Hacl.Impl.Frodo.Encode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val frodo_key_encode:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res /\
as_seq h res == Spec.Matrix.create (v n) (v n))
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_key_encode (v logq) (v b) (v n) (as_seq h0 a)) | [] | Hacl.Impl.Frodo.Encode.frodo_key_encode | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Encode.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
logq: Lib.IntTypes.size_t{0 < Lib.IntTypes.v logq /\ Lib.IntTypes.v logq <= 16} ->
b:
Lib.IntTypes.size_t
{0 < Lib.IntTypes.v b /\ Lib.IntTypes.v b <= 8 /\ Lib.IntTypes.v b <= Lib.IntTypes.v logq} ->
n: Lib.IntTypes.size_t{Lib.IntTypes.v n == 8} ->
a: Hacl.Impl.Matrix.lbytes (n *! n *! b /. Lib.IntTypes.size 8) ->
res: Hacl.Impl.Matrix.matrix_t n n
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 3,
"end_line": 134,
"start_col": 37,
"start_line": 125
} |
FStar.HyperStack.ST.Stack | val frodo_key_encode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.frodo_key_encode1 (v logq) (v b) (v n) (as_seq h0 a) (v i)) | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Encode",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let frodo_key_encode1 logq b n a i =
let h0 = ST.get() in
push_frame();
let v8 = create (size 8) (u8 0) in
let chunk = sub a (i *! b) b in
let h1 = ST.get() in
assert (as_seq h1 chunk == LSeq.sub (as_seq h0 a) (v (i *! b)) (v b));
update_sub v8 (size 0) b chunk;
let x = uint_from_bytes_le #U64 v8 in
pop_frame();
x | val frodo_key_encode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.frodo_key_encode1 (v logq) (v b) (v n) (as_seq h0 a) (v i))
let frodo_key_encode1 logq b n a i = | true | null | false | let h0 = ST.get () in
push_frame ();
let v8 = create (size 8) (u8 0) in
let chunk = sub a (i *! b) b in
let h1 = ST.get () in
assert (as_seq h1 chunk == LSeq.sub (as_seq h0 a) (v (i *! b)) (v b));
update_sub v8 (size 0) b chunk;
let x = uint_from_bytes_le #U64 v8 in
pop_frame ();
x | {
"checked_file": "Hacl.Impl.Frodo.Encode.fst.checked",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"Spec.Frodo.Encode.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Encode.fst"
} | [] | [
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Prims.int",
"Hacl.Impl.Matrix.lbytes",
"Lib.IntTypes.op_Slash_Dot",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.size",
"Lib.IntTypes.uint64",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.ByteBuffer.uint_from_bytes_le",
"Lib.IntTypes.uint_t",
"Lib.Buffer.update_sub",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint8",
"Prims._assert",
"Lib.Sequence.lseq",
"Lib.Buffer.as_seq",
"Lib.Sequence.sub",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.U8",
"Lib.Buffer.sub",
"Lib.IntTypes.mk_int",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.Frodo.Encode
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
module S = Spec.Frodo.Encode
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract private
val ec:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= v logq}
-> k:uint16{v k < pow2 (v b)}
-> r:uint16{r == S.ec (v logq) (v b) k}
let ec logq b a =
a <<. (logq -. b)
inline_for_extraction noextract private
val dc:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b < v logq}
-> c:uint16
-> r:uint16{r == S.dc (v logq) (v b) c}
let dc logq b c =
let res1 = (c +. (u16 1 <<. (logq -. b -. size 1))) >>. (logq -. b) in
res1 &. ((u16 1 <<. b) -. u16 1)
inline_for_extraction noextract private
val ec1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> x:uint64
-> k:size_t{v k < 8}
-> res:uint16{res == S.ec1 (v logq) (v b) x (v k)}
let ec1 logq b x k =
Spec.Frodo.Lemmas.modulo_pow2_u64 (x >>. (b *! k)) (v b);
let rk = (x >>. (b *! k)) &. ((u64 1 <<. b) -. u64 1) in
ec logq b (to_u16 rk)
inline_for_extraction noextract private
val frodo_key_encode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.frodo_key_encode1 (v logq) (v b) (v n) (as_seq h0 a) (v i)) | false | false | Hacl.Impl.Frodo.Encode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val frodo_key_encode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.frodo_key_encode1 (v logq) (v b) (v n) (as_seq h0 a) (v i)) | [] | Hacl.Impl.Frodo.Encode.frodo_key_encode1 | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Encode.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
logq: Lib.IntTypes.size_t{0 < Lib.IntTypes.v logq /\ Lib.IntTypes.v logq <= 16} ->
b:
Lib.IntTypes.size_t
{0 < Lib.IntTypes.v b /\ Lib.IntTypes.v b <= 8 /\ Lib.IntTypes.v b <= Lib.IntTypes.v logq} ->
n: Lib.IntTypes.size_t{Lib.IntTypes.v n == 8} ->
a: Hacl.Impl.Matrix.lbytes (n *! n *! b /. Lib.IntTypes.size 8) ->
i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n}
-> FStar.HyperStack.ST.Stack Lib.IntTypes.uint64 | {
"end_col": 3,
"end_line": 81,
"start_col": 36,
"start_line": 71
} |
FStar.HyperStack.ST.Stack | val frodo_key_decode:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> a:matrix_t n n
-> res:lbytes (n *! n *! b /. size 8)
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res /\
as_seq h res == LSeq.create (v n * v n * v b / 8) (u8 0))
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_seq h1 res == S.frodo_key_decode (v logq) (v b) (v n) (as_matrix h0 a)) | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Encode",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let frodo_key_decode logq b n a res =
[@ inline_let]
let spec h0 = S.frodo_key_decode2 (v logq) (v b) (v n) (as_seq h0 a) in
let h0 = ST.get() in
loop1 h0 n res spec
(fun i ->
Loops.unfold_repeati (v n) (spec h0) (as_seq h0 res) (v i);
let templong = frodo_key_decode2 logq b n a i in
frodo_key_decode1 logq b n i templong res
) | val frodo_key_decode:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> a:matrix_t n n
-> res:lbytes (n *! n *! b /. size 8)
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res /\
as_seq h res == LSeq.create (v n * v n * v b / 8) (u8 0))
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_seq h1 res == S.frodo_key_decode (v logq) (v b) (v n) (as_matrix h0 a))
let frodo_key_decode logq b n a res = | true | null | false | [@@ inline_let ]let spec h0 = S.frodo_key_decode2 (v logq) (v b) (v n) (as_seq h0 a) in
let h0 = ST.get () in
loop1 h0
n
res
spec
(fun i ->
Loops.unfold_repeati (v n) (spec h0) (as_seq h0 res) (v i);
let templong = frodo_key_decode2 logq b n a i in
frodo_key_decode1 logq b n i templong res) | {
"checked_file": "Hacl.Impl.Frodo.Encode.fst.checked",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"Spec.Frodo.Encode.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Encode.fst"
} | [] | [
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Prims.int",
"Hacl.Impl.Matrix.matrix_t",
"Hacl.Impl.Matrix.lbytes",
"Lib.IntTypes.op_Slash_Dot",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.size",
"Lib.Buffer.loop1",
"Lib.IntTypes.uint8",
"Hacl.Impl.Frodo.Encode.frodo_key_decode1",
"Prims.unit",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Hacl.Impl.Frodo.Encode.frodo_key_decode2",
"Lib.IntTypes.uint64",
"Lib.LoopCombinators.unfold_repeati",
"Lib.Sequence.lseq",
"Lib.IntTypes.U8",
"Prims.op_Division",
"Prims.op_Multiply",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.nat",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Frodo.Encode.frodo_key_decode2",
"Hacl.Impl.Matrix.elem"
] | [] | module Hacl.Impl.Frodo.Encode
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
module S = Spec.Frodo.Encode
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract private
val ec:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= v logq}
-> k:uint16{v k < pow2 (v b)}
-> r:uint16{r == S.ec (v logq) (v b) k}
let ec logq b a =
a <<. (logq -. b)
inline_for_extraction noextract private
val dc:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b < v logq}
-> c:uint16
-> r:uint16{r == S.dc (v logq) (v b) c}
let dc logq b c =
let res1 = (c +. (u16 1 <<. (logq -. b -. size 1))) >>. (logq -. b) in
res1 &. ((u16 1 <<. b) -. u16 1)
inline_for_extraction noextract private
val ec1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> x:uint64
-> k:size_t{v k < 8}
-> res:uint16{res == S.ec1 (v logq) (v b) x (v k)}
let ec1 logq b x k =
Spec.Frodo.Lemmas.modulo_pow2_u64 (x >>. (b *! k)) (v b);
let rk = (x >>. (b *! k)) &. ((u64 1 <<. b) -. u64 1) in
ec logq b (to_u16 rk)
inline_for_extraction noextract private
val frodo_key_encode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.frodo_key_encode1 (v logq) (v b) (v n) (as_seq h0 a) (v i))
let frodo_key_encode1 logq b n a i =
let h0 = ST.get() in
push_frame();
let v8 = create (size 8) (u8 0) in
let chunk = sub a (i *! b) b in
let h1 = ST.get() in
assert (as_seq h1 chunk == LSeq.sub (as_seq h0 a) (v (i *! b)) (v b));
update_sub v8 (size 0) b chunk;
let x = uint_from_bytes_le #U64 v8 in
pop_frame();
x
inline_for_extraction noextract private
val frodo_key_encode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> x:uint64
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
Loops.repeati 8 (S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i)) (as_matrix h0 res))
let frodo_key_encode2 logq b n a i x res =
[@ inline_let]
let spec h0 = S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i) in
let h0 = ST.get () in
loop1 h0 (size 8) res spec
(fun k ->
Loops.unfold_repeati 8 (spec h0) (as_seq h0 res) (v k);
mset res i k (ec1 logq b x k)
)
val frodo_key_encode:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res /\
as_seq h res == Spec.Matrix.create (v n) (v n))
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_key_encode (v logq) (v b) (v n) (as_seq h0 a))
[@"c_inline"]
let frodo_key_encode logq b n a res =
let h0 = ST.get () in
[@ inline_let]
let spec h0 = S.frodo_key_encode2 (v logq) (v b) (v n) (as_seq h0 a) in
loop1 h0 n res spec
(fun i ->
Loops.unfold_repeati (v n) (spec h0) (as_seq h0 res) (v i);
let x = frodo_key_encode1 logq b n a i in
frodo_key_encode2 logq b n a i x res
)
inline_for_extraction noextract private
val frodo_key_decode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> i:size_t{v i < v n}
-> templong:uint64
-> res:lbytes (n *! n *! b /. size 8)
-> Stack unit
(requires fun h -> live h res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_seq h1 res == S.frodo_key_decode1 (v logq) (v b) (v n) (v i) templong (as_seq h0 res))
let frodo_key_decode1 logq b n i templong res =
push_frame();
let v8 = create (size 8) (u8 0) in
uint_to_bytes_le v8 templong;
let tmp = sub v8 (size 0) b in
update_sub res (i *! b) b tmp;
pop_frame()
inline_for_extraction noextract private
val frodo_key_decode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> a:matrix_t n n
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == Loops.repeat_gen 8 S.decode_templong_t
(S.frodo_key_decode0 (v logq) (v b) (v n) (as_matrix h0 a) (v i)) (u64 0))
let frodo_key_decode2 logq b n a i =
push_frame();
let templong = create (size 1) (u64 0) in
[@ inline_let]
let refl h i : GTot uint64 = bget h templong 0 in
[@ inline_let]
let footprint i = loc templong in
[@ inline_let]
let spec h0 = S.frodo_key_decode0 (v logq) (v b) (v n) (as_matrix h0 a) (v i) in
let h0 = ST.get () in
assert (bget h0 templong 0 == u64 0);
loop h0 (size 8) S.decode_templong_t refl footprint spec
(fun k ->
Loops.unfold_repeat_gen 8 S.decode_templong_t (spec h0) (refl h0 0) (v k);
let aik = mget a i k in
templong.(size 0) <- templong.(size 0) |. (to_u64 (dc logq b aik) <<. (b *! k))
);
let templong = templong.(size 0) in
pop_frame();
templong
val frodo_key_decode:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> a:matrix_t n n
-> res:lbytes (n *! n *! b /. size 8)
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res /\
as_seq h res == LSeq.create (v n * v n * v b / 8) (u8 0))
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_seq h1 res == S.frodo_key_decode (v logq) (v b) (v n) (as_matrix h0 a))
[@"c_inline"] | false | false | Hacl.Impl.Frodo.Encode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val frodo_key_decode:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> a:matrix_t n n
-> res:lbytes (n *! n *! b /. size 8)
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res /\
as_seq h res == LSeq.create (v n * v n * v b / 8) (u8 0))
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_seq h1 res == S.frodo_key_decode (v logq) (v b) (v n) (as_matrix h0 a)) | [] | Hacl.Impl.Frodo.Encode.frodo_key_decode | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Encode.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
logq: Lib.IntTypes.size_t{0 < Lib.IntTypes.v logq /\ Lib.IntTypes.v logq <= 16} ->
b:
Lib.IntTypes.size_t
{0 < Lib.IntTypes.v b /\ Lib.IntTypes.v b <= 8 /\ Lib.IntTypes.v b < Lib.IntTypes.v logq} ->
n: Lib.IntTypes.size_t{Lib.IntTypes.v n == 8} ->
a: Hacl.Impl.Matrix.matrix_t n n ->
res: Hacl.Impl.Matrix.lbytes (n *! n *! b /. Lib.IntTypes.size 8)
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 3,
"end_line": 217,
"start_col": 2,
"start_line": 209
} |
FStar.HyperStack.ST.Stack | val frodo_key_decode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> i:size_t{v i < v n}
-> templong:uint64
-> res:lbytes (n *! n *! b /. size 8)
-> Stack unit
(requires fun h -> live h res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_seq h1 res == S.frodo_key_decode1 (v logq) (v b) (v n) (v i) templong (as_seq h0 res)) | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Encode",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let frodo_key_decode1 logq b n i templong res =
push_frame();
let v8 = create (size 8) (u8 0) in
uint_to_bytes_le v8 templong;
let tmp = sub v8 (size 0) b in
update_sub res (i *! b) b tmp;
pop_frame() | val frodo_key_decode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> i:size_t{v i < v n}
-> templong:uint64
-> res:lbytes (n *! n *! b /. size 8)
-> Stack unit
(requires fun h -> live h res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_seq h1 res == S.frodo_key_decode1 (v logq) (v b) (v n) (v i) templong (as_seq h0 res))
let frodo_key_decode1 logq b n i templong res = | true | null | false | push_frame ();
let v8 = create (size 8) (u8 0) in
uint_to_bytes_le v8 templong;
let tmp = sub v8 (size 0) b in
update_sub res (i *! b) b tmp;
pop_frame () | {
"checked_file": "Hacl.Impl.Frodo.Encode.fst.checked",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"Spec.Frodo.Encode.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Encode.fst"
} | [] | [
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.uint64",
"Hacl.Impl.Matrix.lbytes",
"Lib.IntTypes.op_Slash_Dot",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.size",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.Buffer.update_sub",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint8",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Buffer.sub",
"Lib.IntTypes.uint_t",
"Lib.ByteBuffer.uint_to_bytes_le",
"Lib.IntTypes.U64",
"Lib.IntTypes.mk_int",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.Frodo.Encode
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
module S = Spec.Frodo.Encode
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract private
val ec:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= v logq}
-> k:uint16{v k < pow2 (v b)}
-> r:uint16{r == S.ec (v logq) (v b) k}
let ec logq b a =
a <<. (logq -. b)
inline_for_extraction noextract private
val dc:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b < v logq}
-> c:uint16
-> r:uint16{r == S.dc (v logq) (v b) c}
let dc logq b c =
let res1 = (c +. (u16 1 <<. (logq -. b -. size 1))) >>. (logq -. b) in
res1 &. ((u16 1 <<. b) -. u16 1)
inline_for_extraction noextract private
val ec1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> x:uint64
-> k:size_t{v k < 8}
-> res:uint16{res == S.ec1 (v logq) (v b) x (v k)}
let ec1 logq b x k =
Spec.Frodo.Lemmas.modulo_pow2_u64 (x >>. (b *! k)) (v b);
let rk = (x >>. (b *! k)) &. ((u64 1 <<. b) -. u64 1) in
ec logq b (to_u16 rk)
inline_for_extraction noextract private
val frodo_key_encode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.frodo_key_encode1 (v logq) (v b) (v n) (as_seq h0 a) (v i))
let frodo_key_encode1 logq b n a i =
let h0 = ST.get() in
push_frame();
let v8 = create (size 8) (u8 0) in
let chunk = sub a (i *! b) b in
let h1 = ST.get() in
assert (as_seq h1 chunk == LSeq.sub (as_seq h0 a) (v (i *! b)) (v b));
update_sub v8 (size 0) b chunk;
let x = uint_from_bytes_le #U64 v8 in
pop_frame();
x
inline_for_extraction noextract private
val frodo_key_encode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> x:uint64
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
Loops.repeati 8 (S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i)) (as_matrix h0 res))
let frodo_key_encode2 logq b n a i x res =
[@ inline_let]
let spec h0 = S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i) in
let h0 = ST.get () in
loop1 h0 (size 8) res spec
(fun k ->
Loops.unfold_repeati 8 (spec h0) (as_seq h0 res) (v k);
mset res i k (ec1 logq b x k)
)
val frodo_key_encode:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res /\
as_seq h res == Spec.Matrix.create (v n) (v n))
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_key_encode (v logq) (v b) (v n) (as_seq h0 a))
[@"c_inline"]
let frodo_key_encode logq b n a res =
let h0 = ST.get () in
[@ inline_let]
let spec h0 = S.frodo_key_encode2 (v logq) (v b) (v n) (as_seq h0 a) in
loop1 h0 n res spec
(fun i ->
Loops.unfold_repeati (v n) (spec h0) (as_seq h0 res) (v i);
let x = frodo_key_encode1 logq b n a i in
frodo_key_encode2 logq b n a i x res
)
inline_for_extraction noextract private
val frodo_key_decode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> i:size_t{v i < v n}
-> templong:uint64
-> res:lbytes (n *! n *! b /. size 8)
-> Stack unit
(requires fun h -> live h res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_seq h1 res == S.frodo_key_decode1 (v logq) (v b) (v n) (v i) templong (as_seq h0 res)) | false | false | Hacl.Impl.Frodo.Encode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val frodo_key_decode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> i:size_t{v i < v n}
-> templong:uint64
-> res:lbytes (n *! n *! b /. size 8)
-> Stack unit
(requires fun h -> live h res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_seq h1 res == S.frodo_key_decode1 (v logq) (v b) (v n) (v i) templong (as_seq h0 res)) | [] | Hacl.Impl.Frodo.Encode.frodo_key_decode1 | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Encode.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
logq: Lib.IntTypes.size_t{0 < Lib.IntTypes.v logq /\ Lib.IntTypes.v logq <= 16} ->
b:
Lib.IntTypes.size_t
{0 < Lib.IntTypes.v b /\ Lib.IntTypes.v b <= 8 /\ Lib.IntTypes.v b < Lib.IntTypes.v logq} ->
n: Lib.IntTypes.size_t{Lib.IntTypes.v n == 8} ->
i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n} ->
templong: Lib.IntTypes.uint64 ->
res: Hacl.Impl.Matrix.lbytes (n *! n *! b /. Lib.IntTypes.size 8)
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 13,
"end_line": 156,
"start_col": 2,
"start_line": 151
} |
FStar.HyperStack.ST.Stack | val frodo_key_decode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> a:matrix_t n n
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == Loops.repeat_gen 8 S.decode_templong_t
(S.frodo_key_decode0 (v logq) (v b) (v n) (as_matrix h0 a) (v i)) (u64 0)) | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Encode",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let frodo_key_decode2 logq b n a i =
push_frame();
let templong = create (size 1) (u64 0) in
[@ inline_let]
let refl h i : GTot uint64 = bget h templong 0 in
[@ inline_let]
let footprint i = loc templong in
[@ inline_let]
let spec h0 = S.frodo_key_decode0 (v logq) (v b) (v n) (as_matrix h0 a) (v i) in
let h0 = ST.get () in
assert (bget h0 templong 0 == u64 0);
loop h0 (size 8) S.decode_templong_t refl footprint spec
(fun k ->
Loops.unfold_repeat_gen 8 S.decode_templong_t (spec h0) (refl h0 0) (v k);
let aik = mget a i k in
templong.(size 0) <- templong.(size 0) |. (to_u64 (dc logq b aik) <<. (b *! k))
);
let templong = templong.(size 0) in
pop_frame();
templong | val frodo_key_decode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> a:matrix_t n n
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == Loops.repeat_gen 8 S.decode_templong_t
(S.frodo_key_decode0 (v logq) (v b) (v n) (as_matrix h0 a) (v i)) (u64 0))
let frodo_key_decode2 logq b n a i = | true | null | false | push_frame ();
let templong = create (size 1) (u64 0) in
[@@ inline_let ]let refl h i : GTot uint64 = bget h templong 0 in
[@@ inline_let ]let footprint i = loc templong in
[@@ inline_let ]let spec h0 = S.frodo_key_decode0 (v logq) (v b) (v n) (as_matrix h0 a) (v i) in
let h0 = ST.get () in
assert (bget h0 templong 0 == u64 0);
loop h0
(size 8)
S.decode_templong_t
refl
footprint
spec
(fun k ->
Loops.unfold_repeat_gen 8 S.decode_templong_t (spec h0) (refl h0 0) (v k);
let aik = mget a i k in
templong.(size 0) <- templong.(size 0) |. (to_u64 (dc logq b aik) <<. (b *! k)));
let templong = templong.(size 0) in
pop_frame ();
templong | {
"checked_file": "Hacl.Impl.Frodo.Encode.fst.checked",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"Spec.Frodo.Encode.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Encode.fst"
} | [] | [
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Prims.int",
"Hacl.Impl.Matrix.matrix_t",
"Lib.IntTypes.uint64",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"Lib.IntTypes.size",
"Lib.Buffer.loop",
"Spec.Frodo.Encode.decode_templong_t",
"Lib.Buffer.op_Array_Assignment",
"Lib.IntTypes.op_Bar_Dot",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.to_u64",
"Lib.IntTypes.U16",
"Hacl.Impl.Frodo.Encode.dc",
"Lib.IntTypes.op_Star_Bang",
"Hacl.Impl.Matrix.mget",
"Hacl.Impl.Matrix.elem",
"Lib.LoopCombinators.unfold_repeat_gen",
"Prims._assert",
"Lib.Buffer.bget",
"Lib.IntTypes.u64",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.nat",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Frodo.Encode.frodo_key_decode0",
"Hacl.Impl.Matrix.as_matrix",
"Lib.IntTypes.mk_int",
"LowStar.Monotonic.Buffer.loc",
"Lib.IntTypes.size_nat",
"Lib.Buffer.loc",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.create",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.Frodo.Encode
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
module S = Spec.Frodo.Encode
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract private
val ec:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= v logq}
-> k:uint16{v k < pow2 (v b)}
-> r:uint16{r == S.ec (v logq) (v b) k}
let ec logq b a =
a <<. (logq -. b)
inline_for_extraction noextract private
val dc:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b < v logq}
-> c:uint16
-> r:uint16{r == S.dc (v logq) (v b) c}
let dc logq b c =
let res1 = (c +. (u16 1 <<. (logq -. b -. size 1))) >>. (logq -. b) in
res1 &. ((u16 1 <<. b) -. u16 1)
inline_for_extraction noextract private
val ec1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> x:uint64
-> k:size_t{v k < 8}
-> res:uint16{res == S.ec1 (v logq) (v b) x (v k)}
let ec1 logq b x k =
Spec.Frodo.Lemmas.modulo_pow2_u64 (x >>. (b *! k)) (v b);
let rk = (x >>. (b *! k)) &. ((u64 1 <<. b) -. u64 1) in
ec logq b (to_u16 rk)
inline_for_extraction noextract private
val frodo_key_encode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.frodo_key_encode1 (v logq) (v b) (v n) (as_seq h0 a) (v i))
let frodo_key_encode1 logq b n a i =
let h0 = ST.get() in
push_frame();
let v8 = create (size 8) (u8 0) in
let chunk = sub a (i *! b) b in
let h1 = ST.get() in
assert (as_seq h1 chunk == LSeq.sub (as_seq h0 a) (v (i *! b)) (v b));
update_sub v8 (size 0) b chunk;
let x = uint_from_bytes_le #U64 v8 in
pop_frame();
x
inline_for_extraction noextract private
val frodo_key_encode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> i:size_t{v i < v n}
-> x:uint64
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
Loops.repeati 8 (S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i)) (as_matrix h0 res))
let frodo_key_encode2 logq b n a i x res =
[@ inline_let]
let spec h0 = S.frodo_key_encode0 (v logq) (v b) (v n) (as_seq h0 a) x (v i) in
let h0 = ST.get () in
loop1 h0 (size 8) res spec
(fun k ->
Loops.unfold_repeati 8 (spec h0) (as_seq h0 res) (v k);
mset res i k (ec1 logq b x k)
)
val frodo_key_encode:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b <= v logq}
-> n:size_t{v n == 8}
-> a:lbytes (n *! n *! b /. size 8)
-> res:matrix_t n n
-> Stack unit
(requires fun h ->
live h a /\ live h res /\ disjoint a res /\
as_seq h res == Spec.Matrix.create (v n) (v n))
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_key_encode (v logq) (v b) (v n) (as_seq h0 a))
[@"c_inline"]
let frodo_key_encode logq b n a res =
let h0 = ST.get () in
[@ inline_let]
let spec h0 = S.frodo_key_encode2 (v logq) (v b) (v n) (as_seq h0 a) in
loop1 h0 n res spec
(fun i ->
Loops.unfold_repeati (v n) (spec h0) (as_seq h0 res) (v i);
let x = frodo_key_encode1 logq b n a i in
frodo_key_encode2 logq b n a i x res
)
inline_for_extraction noextract private
val frodo_key_decode1:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> i:size_t{v i < v n}
-> templong:uint64
-> res:lbytes (n *! n *! b /. size 8)
-> Stack unit
(requires fun h -> live h res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_seq h1 res == S.frodo_key_decode1 (v logq) (v b) (v n) (v i) templong (as_seq h0 res))
let frodo_key_decode1 logq b n i templong res =
push_frame();
let v8 = create (size 8) (u8 0) in
uint_to_bytes_le v8 templong;
let tmp = sub v8 (size 0) b in
update_sub res (i *! b) b tmp;
pop_frame()
inline_for_extraction noextract private
val frodo_key_decode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> a:matrix_t n n
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == Loops.repeat_gen 8 S.decode_templong_t
(S.frodo_key_decode0 (v logq) (v b) (v n) (as_matrix h0 a) (v i)) (u64 0)) | false | false | Hacl.Impl.Frodo.Encode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val frodo_key_decode2:
logq:size_t{0 < v logq /\ v logq <= 16}
-> b:size_t{0 < v b /\ v b <= 8 /\ v b < v logq}
-> n:size_t{v n == 8}
-> a:matrix_t n n
-> i:size_t{v i < v n}
-> Stack uint64
(requires fun h -> live h a)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == Loops.repeat_gen 8 S.decode_templong_t
(S.frodo_key_decode0 (v logq) (v b) (v n) (as_matrix h0 a) (v i)) (u64 0)) | [] | Hacl.Impl.Frodo.Encode.frodo_key_decode2 | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Encode.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
logq: Lib.IntTypes.size_t{0 < Lib.IntTypes.v logq /\ Lib.IntTypes.v logq <= 16} ->
b:
Lib.IntTypes.size_t
{0 < Lib.IntTypes.v b /\ Lib.IntTypes.v b <= 8 /\ Lib.IntTypes.v b < Lib.IntTypes.v logq} ->
n: Lib.IntTypes.size_t{Lib.IntTypes.v n == 8} ->
a: Hacl.Impl.Matrix.matrix_t n n ->
i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n}
-> FStar.HyperStack.ST.Stack Lib.IntTypes.uint64 | {
"end_col": 10,
"end_line": 191,
"start_col": 2,
"start_line": 173
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t) | let bn_mont_ctx (t: limb_t) = | false | null | false | bn_mont_ctx' t (lb t) (ll t) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx'",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
} | false | true | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_mont_ctx : t: Hacl.Bignum.Definitions.limb_t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_mont_ctx | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> Type0 | {
"end_col": 57,
"end_line": 48,
"start_col": 29,
"start_line": 48
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k) | let freeable (#t: limb_t) (h: mem) (k: pbn_mont_ctx t) = | false | null | false | B.freeable k /\ freeable_s h (B.deref h k) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Prims.l_and",
"LowStar.Monotonic.Buffer.freeable",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.freeable_s",
"LowStar.Monotonic.Buffer.deref",
"Prims.logical"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val freeable : h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.pbn_mont_ctx t -> Prims.logical | [] | Hacl.Bignum.MontArithmetic.freeable | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.pbn_mont_ctx t -> Prims.logical | {
"end_col": 44,
"end_line": 91,
"start_col": 2,
"start_line": 91
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32) | let bn_mont_ctx_u32 = | false | null | false | bn_mont_ctx' U32 (lb U32) (ll U32) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.MontArithmetic.bn_mont_ctx'",
"Lib.IntTypes.U32",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t) | false | true | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_mont_ctx_u32 : Type0 | [] | Hacl.Bignum.MontArithmetic.bn_mont_ctx_u32 | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 56,
"end_line": 50,
"start_col": 22,
"start_line": 50
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64 | let pbn_mont_ctx_u64 = | false | null | false | B.pointer bn_mont_ctx_u64 | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"LowStar.Buffer.pointer",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx_u64"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32 | false | true | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pbn_mont_ctx_u64 : Type0 | [] | Hacl.Bignum.MontArithmetic.pbn_mont_ctx_u64 | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 48,
"end_line": 59,
"start_col": 23,
"start_line": 59
} |
|
Prims.GTot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) | let footprint (#t: limb_t) (h: mem) (k: pbn_mont_ctx t) = | false | null | false | let open B in loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"sometrivial"
] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.Monotonic.Buffer.loc_addr_of_buffer",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.footprint_s",
"LowStar.Monotonic.Buffer.deref",
"LowStar.Monotonic.Buffer.loc"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val footprint : h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.pbn_mont_ctx t
-> Prims.GTot LowStar.Monotonic.Buffer.loc | [] | Hacl.Bignum.MontArithmetic.footprint | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.pbn_mont_ctx t
-> Prims.GTot LowStar.Monotonic.Buffer.loc | {
"end_col": 68,
"end_line": 101,
"start_col": 2,
"start_line": 101
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t) | let pbn_mont_ctx (t: limb_t) = | false | null | false | B.pointer (bn_mont_ctx t) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"LowStar.Buffer.pointer",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64) | false | true | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pbn_mont_ctx : t: Hacl.Bignum.Definitions.limb_t -> Type0 | [] | Hacl.Bignum.MontArithmetic.pbn_mont_ctx | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> Type0 | {
"end_col": 55,
"end_line": 54,
"start_col": 30,
"start_line": 54
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64) | let bn_mont_ctx_u64 = | false | null | false | bn_mont_ctx' U64 (lb U64) (ll U64) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.MontArithmetic.bn_mont_ctx'",
"Lib.IntTypes.U64",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t) | false | true | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_mont_ctx_u64 : Type0 | [] | Hacl.Bignum.MontArithmetic.bn_mont_ctx_u64 | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 56,
"end_line": 51,
"start_col": 22,
"start_line": 51
} |
|
Prims.GTot | val as_pctx (#t: limb_t) (h: mem) (k: pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k) | val as_pctx (#t: limb_t) (h: mem) (k: pbn_mont_ctx t) : GTot (S.bn_mont_ctx t)
let as_pctx (#t: limb_t) (h: mem) (k: pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) = | false | null | false | as_ctx h (B.deref h k) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"sometrivial"
] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.MontArithmetic.as_ctx",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val as_pctx (#t: limb_t) (h: mem) (k: pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) | [] | Hacl.Bignum.MontArithmetic.as_pctx | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.pbn_mont_ctx t
-> Prims.GTot (Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t) | {
"end_col": 24,
"end_line": 105,
"start_col": 2,
"start_line": 105
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k) | let pbn_mont_ctx_inv (#t: limb_t) (h: mem) (k: pbn_mont_ctx t) = | false | null | false | B.live h k /\ B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowStar.Monotonic.Buffer.loc_addr_of_buffer",
"Hacl.Bignum.MontArithmetic.footprint_s",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx_inv",
"Prims.logical"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pbn_mont_ctx_inv : h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.pbn_mont_ctx t -> Prims.logical | [] | Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.pbn_mont_ctx t -> Prims.logical | {
"end_col": 33,
"end_line": 111,
"start_col": 2,
"start_line": 109
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32 | let pbn_mont_ctx_u32 = | false | null | false | B.pointer bn_mont_ctx_u32 | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"LowStar.Buffer.pointer",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx_u32"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t) | false | true | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pbn_mont_ctx_u32 : Type0 | [] | Hacl.Bignum.MontArithmetic.pbn_mont_ctx_u32 | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 48,
"end_line": 57,
"start_col": 23,
"start_line": 57
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_field_free_st (t:limb_t) = k:pbn_mont_ctx t ->
ST unit
(requires fun h ->
freeable h k /\
pbn_mont_ctx_inv h k)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 k) h0 h1)) | let bn_field_free_st (t: limb_t) = | false | null | false | k: pbn_mont_ctx t
-> ST unit
(requires fun h -> freeable h k /\ pbn_mont_ctx_inv h k)
(ensures fun h0 _ h1 -> let open B in modifies (footprint h0 k) h0 h1) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Hacl.Bignum.MontArithmetic.freeable",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"LowStar.Monotonic.Buffer.modifies",
"Hacl.Bignum.MontArithmetic.footprint"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t
inline_for_extraction noextract
let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n))
inline_for_extraction noextract
val bn_field_check_modulus: #t:limb_t -> km:BM.mont t -> bn_field_check_modulus_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_init_st (t:limb_t) (len:BN.meta_len t) =
r:HS.rid
-> n:lbignum t len ->
ST (pbn_mont_ctx t)
(requires fun h ->
S.bn_mont_ctx_pre (as_seq h n) /\
live h n /\ ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\
freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\
as_pctx h1 res == S.bn_field_init (as_seq h0 n))
inline_for_extraction noextract
val bn_field_init:
#t:limb_t
-> len:BN.meta_len t
-> precomp_r2:BM.bn_precomp_r2_mod_n_st t len ->
bn_field_init_st t len | false | true | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_field_free_st : t: Hacl.Bignum.Definitions.limb_t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_field_free_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> Type0 | {
"end_col": 40,
"end_line": 173,
"start_col": 34,
"start_line": 167
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64 | let ll (t: limb_t) = | false | null | false | match t with
| U32 -> uint32
| U64 -> uint64 | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.uint32",
"Lib.IntTypes.uint64"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract | false | true | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ll : t: Hacl.Bignum.Definitions.limb_t -> Type0 | [] | Hacl.Bignum.MontArithmetic.ll | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> Type0 | {
"end_col": 17,
"end_line": 36,
"start_col": 2,
"start_line": 34
} |
|
Prims.GTot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n | let bn_v_n (#t: limb_t) (h: mem) (k: pbn_mont_ctx t) = | false | null | false | let k1 = B.deref h k in
let n:lbignum t k1.len = k1.n in
bn_v h n | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"sometrivial"
] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Monotonic.Buffer.deref",
"LowStar.Buffer.trivial_preorder",
"Prims.nat"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k) | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_v_n : h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.pbn_mont_ctx t
-> Prims.GTot Prims.nat | [] | Hacl.Bignum.MontArithmetic.bn_v_n | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.pbn_mont_ctx t
-> Prims.GTot Prims.nat | {
"end_col": 10,
"end_line": 81,
"start_col": 51,
"start_line": 78
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k) | let bn_mont_ctx_inv (#t: limb_t) (h: mem) (k: bn_mont_ctx t) = | false | null | false | let n:buffer (limb t) = k.n in
let r2:buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\ S.bn_mont_ctx_inv (as_ctx h k) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv",
"Hacl.Bignum.MontArithmetic.as_ctx",
"Lib.Buffer.buffer_t",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__r2",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n",
"Prims.logical"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
} | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_mont_ctx_inv : h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.bn_mont_ctx t -> Prims.logical | [] | Hacl.Bignum.MontArithmetic.bn_mont_ctx_inv | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.bn_mont_ctx t -> Prims.logical | {
"end_col": 32,
"end_line": 74,
"start_col": 59,
"start_line": 70
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2 | let freeable_s (#t: limb_t) (h: mem) (k: bn_mont_ctx t) = | false | null | false | let n:buffer (limb t) = k.n in
let r2:buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2 | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"Prims.l_and",
"LowStar.Monotonic.Buffer.freeable",
"Hacl.Bignum.Definitions.limb",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__r2",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n",
"Prims.logical"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val freeable_s : h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.bn_mont_ctx t -> Prims.logical | [] | Hacl.Bignum.MontArithmetic.freeable_s | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.bn_mont_ctx t -> Prims.logical | {
"end_col": 31,
"end_line": 87,
"start_col": 54,
"start_line": 84
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64 | let lb (t: limb_t) = | false | null | false | match t with
| U32 -> buffer uint32
| U64 -> buffer uint64 | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.Buffer.buffer",
"Lib.IntTypes.uint32",
"Lib.IntTypes.uint64"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract | false | true | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lb : t: Hacl.Bignum.Definitions.limb_t -> Type0 | [] | Hacl.Bignum.MontArithmetic.lb | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> Type0 | {
"end_col": 24,
"end_line": 30,
"start_col": 2,
"start_line": 28
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k)) | let bn_field_get_len_st (t: limb_t) = | false | null | false | k: pbn_mont_ctx t
-> Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures
fun h0 r h1 ->
h0 == h1 /\ r == (B.deref h0 k).len /\ v r == S.bn_field_get_len (as_pctx h0 k)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.meta_len",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.max_size_t",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Hacl.Spec.Bignum.MontArithmetic.bn_field_get_len",
"Hacl.Bignum.MontArithmetic.as_pctx"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k) | false | true | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_field_get_len_st : t: Hacl.Bignum.Definitions.limb_t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_field_get_len_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> Type0 | {
"end_col": 45,
"end_line": 120,
"start_col": 37,
"start_line": 115
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n)) | let bn_field_check_modulus_st (t: limb_t) (len: BN.meta_len t) = | false | null | false | n: lbignum t len
-> Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_field_check_modulus (as_seq h0 n)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.Definitions.lbignum",
"Prims.bool",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Prims.l_and",
"Lib.Buffer.modifies0",
"Prims.eq2",
"Hacl.Spec.Bignum.MontArithmetic.bn_field_check_modulus",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.as_seq"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_field_check_modulus_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_field_check_modulus_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 48,
"end_line": 132,
"start_col": 63,
"start_line": 128
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_field_init_st (t:limb_t) (len:BN.meta_len t) =
r:HS.rid
-> n:lbignum t len ->
ST (pbn_mont_ctx t)
(requires fun h ->
S.bn_mont_ctx_pre (as_seq h n) /\
live h n /\ ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\
freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\
as_pctx h1 res == S.bn_field_init (as_seq h0 n)) | let bn_field_init_st (t: limb_t) (len: BN.meta_len t) = | false | null | false | r: HS.rid -> n: lbignum t len
-> ST (pbn_mont_ctx t)
(requires fun h -> S.bn_mont_ctx_pre (as_seq h n) /\ live h n /\ ST.is_eternal_region r)
(ensures
fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\ B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\ freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\ as_pctx h1 res == S.bn_field_init (as_seq h0 n)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"FStar.Monotonic.HyperHeap.rid",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_pre",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.live",
"FStar.HyperStack.ST.is_eternal_region",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"LowStar.Monotonic.Buffer.fresh_loc",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.loc_region_only",
"Hacl.Bignum.MontArithmetic.freeable",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Prims.nat",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv",
"Hacl.Bignum.MontArithmetic.as_pctx",
"Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx",
"Hacl.Spec.Bignum.MontArithmetic.bn_field_init"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t
inline_for_extraction noextract
let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n))
inline_for_extraction noextract
val bn_field_check_modulus: #t:limb_t -> km:BM.mont t -> bn_field_check_modulus_st t km.BM.bn.BN.len
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_field_init_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_field_init_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 52,
"end_line": 155,
"start_col": 4,
"start_line": 141
} |
|
Prims.GTot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2)) | let footprint_s (#t: limb_t) (h: mem) (k: bn_mont_ctx t) = | false | null | false | let n:buffer (limb t) = k.n in
let r2:buffer (limb t) = k.r2 in
let open B in loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"sometrivial"
] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.Monotonic.Buffer.loc_addr_of_buffer",
"Hacl.Bignum.Definitions.limb",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__r2",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n",
"LowStar.Monotonic.Buffer.loc"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k) | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val footprint_s : h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.bn_mont_ctx t
-> Prims.GTot LowStar.Monotonic.Buffer.loc | [] | Hacl.Bignum.MontArithmetic.footprint_s | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.bn_mont_ctx t
-> Prims.GTot LowStar.Monotonic.Buffer.loc | {
"end_col": 62,
"end_line": 97,
"start_col": 55,
"start_line": 94
} |
|
Prims.GTot | val as_ctx (#t: limb_t) (h: mem) (k: bn_mont_ctx t) : GTot (S.bn_mont_ctx t) | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
} | val as_ctx (#t: limb_t) (h: mem) (k: bn_mont_ctx t) : GTot (S.bn_mont_ctx t)
let as_ctx (#t: limb_t) (h: mem) (k: bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = | false | null | false | {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len)
} | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"sometrivial"
] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"Hacl.Spec.Bignum.MontArithmetic.Mkbn_mont_ctx",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__mu",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__r2",
"Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val as_ctx (#t: limb_t) (h: mem) (k: bn_mont_ctx t) : GTot (S.bn_mont_ctx t) | [] | Hacl.Bignum.MontArithmetic.as_ctx | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> k: Hacl.Bignum.MontArithmetic.bn_mont_ctx t
-> Prims.GTot (Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t) | {
"end_col": 44,
"end_line": 66,
"start_col": 2,
"start_line": 63
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_field_one_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> oneM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h oneM /\
B.(loc_disjoint (footprint h k) (loc_buffer (oneM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc oneM) h0 h1 /\
bn_v h1 oneM < bn_v_n h0 k /\
as_seq h1 oneM == S.bn_field_one (as_pctx h0 k)) | let bn_field_one_st (t: limb_t) (len: BN.meta_len t) = | false | null | false | k: pbn_mont_ctx t -> oneM: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).len == len /\ pbn_mont_ctx_inv h k /\ live h oneM /\
B.(loc_disjoint (footprint h k) (loc_buffer (oneM <: buffer (limb t)))))
(ensures
fun h0 _ h1 ->
modifies (loc oneM) h0 h1 /\ bn_v h1 oneM < bn_v_n h0 k /\
as_seq h1 oneM == S.bn_field_one (as_pctx h0 k)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len",
"Hacl.Bignum.MontArithmetic.as_pctx",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.MontArithmetic.bn_field_one"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t
inline_for_extraction noextract
let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n))
inline_for_extraction noextract
val bn_field_check_modulus: #t:limb_t -> km:BM.mont t -> bn_field_check_modulus_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_init_st (t:limb_t) (len:BN.meta_len t) =
r:HS.rid
-> n:lbignum t len ->
ST (pbn_mont_ctx t)
(requires fun h ->
S.bn_mont_ctx_pre (as_seq h n) /\
live h n /\ ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\
freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\
as_pctx h1 res == S.bn_field_init (as_seq h0 n))
inline_for_extraction noextract
val bn_field_init:
#t:limb_t
-> len:BN.meta_len t
-> precomp_r2:BM.bn_precomp_r2_mod_n_st t len ->
bn_field_init_st t len
inline_for_extraction noextract
let bn_field_free_st (t:limb_t) = k:pbn_mont_ctx t ->
ST unit
(requires fun h ->
freeable h k /\
pbn_mont_ctx_inv h k)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 k) h0 h1))
inline_for_extraction noextract
val bn_field_free: #t:limb_t -> bn_field_free_st t
inline_for_extraction noextract
let bn_to_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> a:lbignum t len
-> aM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\
bn_v h1 aM < bn_v_n h0 k /\
as_seq h1 aM == S.bn_to_field (as_pctx h0 k) (as_seq h0 a))
inline_for_extraction noextract
val bn_to_field: #t:limb_t -> km:BM.mont t -> bn_to_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_from_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> a:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\
bn_v h1 a < bn_v_n h0 k /\
as_seq h1 a == S.bn_from_field (as_pctx h0 k) (as_seq h0 aM))
inline_for_extraction noextract
val bn_from_field: #t:limb_t -> km:BM.mont t -> bn_from_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_add_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_add (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_add: #t:limb_t -> km:BM.mont t -> bn_field_add_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_sub_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sub (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_sub: #t:limb_t -> km:BM.mont t -> bn_field_sub_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_mul_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_mul (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_mul: #t:limb_t -> km:BM.mont t -> bn_field_mul_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_sqr_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
live h aM /\ live h cM /\ eq_or_disjoint aM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sqr (as_pctx h0 k) (as_seq h0 aM))
inline_for_extraction noextract
val bn_field_sqr: #t:limb_t -> km:BM.mont t -> bn_field_sqr_st t km.BM.bn.BN.len
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_field_one_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_field_one_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 52,
"end_line": 341,
"start_col": 4,
"start_line": 330
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_field_add_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_add (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM)) | let bn_field_add_st (t: limb_t) (len: BN.meta_len t) = | false | null | false | k: pbn_mont_ctx t -> aM: lbignum t len -> bM: lbignum t len -> cM: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).len == len /\ pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\ live h aM /\ live h bM /\ live h cM /\ eq_or_disjoint aM bM /\
eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures
fun h0 _ h1 ->
modifies (loc cM) h0 h1 /\ bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_add (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.eq_or_disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len",
"Hacl.Bignum.MontArithmetic.as_pctx",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.MontArithmetic.bn_field_add"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t
inline_for_extraction noextract
let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n))
inline_for_extraction noextract
val bn_field_check_modulus: #t:limb_t -> km:BM.mont t -> bn_field_check_modulus_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_init_st (t:limb_t) (len:BN.meta_len t) =
r:HS.rid
-> n:lbignum t len ->
ST (pbn_mont_ctx t)
(requires fun h ->
S.bn_mont_ctx_pre (as_seq h n) /\
live h n /\ ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\
freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\
as_pctx h1 res == S.bn_field_init (as_seq h0 n))
inline_for_extraction noextract
val bn_field_init:
#t:limb_t
-> len:BN.meta_len t
-> precomp_r2:BM.bn_precomp_r2_mod_n_st t len ->
bn_field_init_st t len
inline_for_extraction noextract
let bn_field_free_st (t:limb_t) = k:pbn_mont_ctx t ->
ST unit
(requires fun h ->
freeable h k /\
pbn_mont_ctx_inv h k)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 k) h0 h1))
inline_for_extraction noextract
val bn_field_free: #t:limb_t -> bn_field_free_st t
inline_for_extraction noextract
let bn_to_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> a:lbignum t len
-> aM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\
bn_v h1 aM < bn_v_n h0 k /\
as_seq h1 aM == S.bn_to_field (as_pctx h0 k) (as_seq h0 a))
inline_for_extraction noextract
val bn_to_field: #t:limb_t -> km:BM.mont t -> bn_to_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_from_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> a:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\
bn_v h1 a < bn_v_n h0 k /\
as_seq h1 a == S.bn_from_field (as_pctx h0 k) (as_seq h0 aM))
inline_for_extraction noextract
val bn_from_field: #t:limb_t -> km:BM.mont t -> bn_from_field_st t km.BM.bn.BN.len
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_field_add_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_field_add_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 80,
"end_line": 244,
"start_col": 4,
"start_line": 226
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_from_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> a:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\
bn_v h1 a < bn_v_n h0 k /\
as_seq h1 a == S.bn_from_field (as_pctx h0 k) (as_seq h0 aM)) | let bn_from_field_st (t: limb_t) (len: BN.meta_len t) = | false | null | false | k: pbn_mont_ctx t -> aM: lbignum t len -> a: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).len == len /\ pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\ live h a /\
live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures
fun h0 _ h1 ->
modifies (loc a) h0 h1 /\ bn_v h1 a < bn_v_n h0 k /\
as_seq h1 a == S.bn_from_field (as_pctx h0 k) (as_seq h0 aM)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len",
"Hacl.Bignum.MontArithmetic.as_pctx",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.MontArithmetic.bn_from_field"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t
inline_for_extraction noextract
let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n))
inline_for_extraction noextract
val bn_field_check_modulus: #t:limb_t -> km:BM.mont t -> bn_field_check_modulus_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_init_st (t:limb_t) (len:BN.meta_len t) =
r:HS.rid
-> n:lbignum t len ->
ST (pbn_mont_ctx t)
(requires fun h ->
S.bn_mont_ctx_pre (as_seq h n) /\
live h n /\ ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\
freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\
as_pctx h1 res == S.bn_field_init (as_seq h0 n))
inline_for_extraction noextract
val bn_field_init:
#t:limb_t
-> len:BN.meta_len t
-> precomp_r2:BM.bn_precomp_r2_mod_n_st t len ->
bn_field_init_st t len
inline_for_extraction noextract
let bn_field_free_st (t:limb_t) = k:pbn_mont_ctx t ->
ST unit
(requires fun h ->
freeable h k /\
pbn_mont_ctx_inv h k)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 k) h0 h1))
inline_for_extraction noextract
val bn_field_free: #t:limb_t -> bn_field_free_st t
inline_for_extraction noextract
let bn_to_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> a:lbignum t len
-> aM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\
bn_v h1 aM < bn_v_n h0 k /\
as_seq h1 aM == S.bn_to_field (as_pctx h0 k) (as_seq h0 a))
inline_for_extraction noextract
val bn_to_field: #t:limb_t -> km:BM.mont t -> bn_to_field_st t km.BM.bn.BN.len
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_from_field_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_from_field_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 65,
"end_line": 217,
"start_col": 4,
"start_line": 204
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_to_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> a:lbignum t len
-> aM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\
bn_v h1 aM < bn_v_n h0 k /\
as_seq h1 aM == S.bn_to_field (as_pctx h0 k) (as_seq h0 a)) | let bn_to_field_st (t: limb_t) (len: BN.meta_len t) = | false | null | false | k: pbn_mont_ctx t -> a: lbignum t len -> aM: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).len == len /\ pbn_mont_ctx_inv h k /\ live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures
fun h0 _ h1 ->
modifies (loc aM) h0 h1 /\ bn_v h1 aM < bn_v_n h0 k /\
as_seq h1 aM == S.bn_to_field (as_pctx h0 k) (as_seq h0 a)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len",
"Hacl.Bignum.MontArithmetic.as_pctx",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.MontArithmetic.bn_to_field"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t
inline_for_extraction noextract
let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n))
inline_for_extraction noextract
val bn_field_check_modulus: #t:limb_t -> km:BM.mont t -> bn_field_check_modulus_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_init_st (t:limb_t) (len:BN.meta_len t) =
r:HS.rid
-> n:lbignum t len ->
ST (pbn_mont_ctx t)
(requires fun h ->
S.bn_mont_ctx_pre (as_seq h n) /\
live h n /\ ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\
freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\
as_pctx h1 res == S.bn_field_init (as_seq h0 n))
inline_for_extraction noextract
val bn_field_init:
#t:limb_t
-> len:BN.meta_len t
-> precomp_r2:BM.bn_precomp_r2_mod_n_st t len ->
bn_field_init_st t len
inline_for_extraction noextract
let bn_field_free_st (t:limb_t) = k:pbn_mont_ctx t ->
ST unit
(requires fun h ->
freeable h k /\
pbn_mont_ctx_inv h k)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 k) h0 h1))
inline_for_extraction noextract
val bn_field_free: #t:limb_t -> bn_field_free_st t
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_to_field_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_to_field_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 63,
"end_line": 195,
"start_col": 4,
"start_line": 182
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_field_sqr_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
live h aM /\ live h cM /\ eq_or_disjoint aM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sqr (as_pctx h0 k) (as_seq h0 aM)) | let bn_field_sqr_st (t: limb_t) (len: BN.meta_len t) = | false | null | false | k: pbn_mont_ctx t -> aM: lbignum t len -> cM: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).len == len /\ pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\ live h aM /\
live h cM /\ eq_or_disjoint aM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures
fun h0 _ h1 ->
modifies (loc cM) h0 h1 /\ bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sqr (as_pctx h0 k) (as_seq h0 aM)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.eq_or_disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len",
"Hacl.Bignum.MontArithmetic.as_pctx",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.MontArithmetic.bn_field_sqr"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t
inline_for_extraction noextract
let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n))
inline_for_extraction noextract
val bn_field_check_modulus: #t:limb_t -> km:BM.mont t -> bn_field_check_modulus_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_init_st (t:limb_t) (len:BN.meta_len t) =
r:HS.rid
-> n:lbignum t len ->
ST (pbn_mont_ctx t)
(requires fun h ->
S.bn_mont_ctx_pre (as_seq h n) /\
live h n /\ ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\
freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\
as_pctx h1 res == S.bn_field_init (as_seq h0 n))
inline_for_extraction noextract
val bn_field_init:
#t:limb_t
-> len:BN.meta_len t
-> precomp_r2:BM.bn_precomp_r2_mod_n_st t len ->
bn_field_init_st t len
inline_for_extraction noextract
let bn_field_free_st (t:limb_t) = k:pbn_mont_ctx t ->
ST unit
(requires fun h ->
freeable h k /\
pbn_mont_ctx_inv h k)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 k) h0 h1))
inline_for_extraction noextract
val bn_field_free: #t:limb_t -> bn_field_free_st t
inline_for_extraction noextract
let bn_to_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> a:lbignum t len
-> aM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\
bn_v h1 aM < bn_v_n h0 k /\
as_seq h1 aM == S.bn_to_field (as_pctx h0 k) (as_seq h0 a))
inline_for_extraction noextract
val bn_to_field: #t:limb_t -> km:BM.mont t -> bn_to_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_from_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> a:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\
bn_v h1 a < bn_v_n h0 k /\
as_seq h1 a == S.bn_from_field (as_pctx h0 k) (as_seq h0 aM))
inline_for_extraction noextract
val bn_from_field: #t:limb_t -> km:BM.mont t -> bn_from_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_add_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_add (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_add: #t:limb_t -> km:BM.mont t -> bn_field_add_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_sub_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sub (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_sub: #t:limb_t -> km:BM.mont t -> bn_field_sub_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_mul_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_mul (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_mul: #t:limb_t -> km:BM.mont t -> bn_field_mul_st t km.BM.bn.BN.len
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_field_sqr_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_field_sqr_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 65,
"end_line": 321,
"start_col": 4,
"start_line": 307
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_field_sub_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sub (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM)) | let bn_field_sub_st (t: limb_t) (len: BN.meta_len t) = | false | null | false | k: pbn_mont_ctx t -> aM: lbignum t len -> bM: lbignum t len -> cM: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).len == len /\ pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\ live h aM /\ live h bM /\ live h cM /\ eq_or_disjoint aM bM /\
eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures
fun h0 _ h1 ->
modifies (loc cM) h0 h1 /\ bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sub (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.eq_or_disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len",
"Hacl.Bignum.MontArithmetic.as_pctx",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.MontArithmetic.bn_field_sub"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t
inline_for_extraction noextract
let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n))
inline_for_extraction noextract
val bn_field_check_modulus: #t:limb_t -> km:BM.mont t -> bn_field_check_modulus_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_init_st (t:limb_t) (len:BN.meta_len t) =
r:HS.rid
-> n:lbignum t len ->
ST (pbn_mont_ctx t)
(requires fun h ->
S.bn_mont_ctx_pre (as_seq h n) /\
live h n /\ ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\
freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\
as_pctx h1 res == S.bn_field_init (as_seq h0 n))
inline_for_extraction noextract
val bn_field_init:
#t:limb_t
-> len:BN.meta_len t
-> precomp_r2:BM.bn_precomp_r2_mod_n_st t len ->
bn_field_init_st t len
inline_for_extraction noextract
let bn_field_free_st (t:limb_t) = k:pbn_mont_ctx t ->
ST unit
(requires fun h ->
freeable h k /\
pbn_mont_ctx_inv h k)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 k) h0 h1))
inline_for_extraction noextract
val bn_field_free: #t:limb_t -> bn_field_free_st t
inline_for_extraction noextract
let bn_to_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> a:lbignum t len
-> aM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\
bn_v h1 aM < bn_v_n h0 k /\
as_seq h1 aM == S.bn_to_field (as_pctx h0 k) (as_seq h0 a))
inline_for_extraction noextract
val bn_to_field: #t:limb_t -> km:BM.mont t -> bn_to_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_from_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> a:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\
bn_v h1 a < bn_v_n h0 k /\
as_seq h1 a == S.bn_from_field (as_pctx h0 k) (as_seq h0 aM))
inline_for_extraction noextract
val bn_from_field: #t:limb_t -> km:BM.mont t -> bn_from_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_add_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_add (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_add: #t:limb_t -> km:BM.mont t -> bn_field_add_st t km.BM.bn.BN.len
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_field_sub_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_field_sub_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 80,
"end_line": 271,
"start_col": 4,
"start_line": 253
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_field_mul_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_mul (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM)) | let bn_field_mul_st (t: limb_t) (len: BN.meta_len t) = | false | null | false | k: pbn_mont_ctx t -> aM: lbignum t len -> bM: lbignum t len -> cM: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).len == len /\ pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\ live h aM /\ live h bM /\ live h cM /\ eq_or_disjoint aM bM /\
eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures
fun h0 _ h1 ->
modifies (loc cM) h0 h1 /\ bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_mul (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.eq_or_disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len",
"Hacl.Bignum.MontArithmetic.as_pctx",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.MontArithmetic.bn_field_mul"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t
inline_for_extraction noextract
let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n))
inline_for_extraction noextract
val bn_field_check_modulus: #t:limb_t -> km:BM.mont t -> bn_field_check_modulus_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_init_st (t:limb_t) (len:BN.meta_len t) =
r:HS.rid
-> n:lbignum t len ->
ST (pbn_mont_ctx t)
(requires fun h ->
S.bn_mont_ctx_pre (as_seq h n) /\
live h n /\ ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\
freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\
as_pctx h1 res == S.bn_field_init (as_seq h0 n))
inline_for_extraction noextract
val bn_field_init:
#t:limb_t
-> len:BN.meta_len t
-> precomp_r2:BM.bn_precomp_r2_mod_n_st t len ->
bn_field_init_st t len
inline_for_extraction noextract
let bn_field_free_st (t:limb_t) = k:pbn_mont_ctx t ->
ST unit
(requires fun h ->
freeable h k /\
pbn_mont_ctx_inv h k)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 k) h0 h1))
inline_for_extraction noextract
val bn_field_free: #t:limb_t -> bn_field_free_st t
inline_for_extraction noextract
let bn_to_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> a:lbignum t len
-> aM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\
bn_v h1 aM < bn_v_n h0 k /\
as_seq h1 aM == S.bn_to_field (as_pctx h0 k) (as_seq h0 a))
inline_for_extraction noextract
val bn_to_field: #t:limb_t -> km:BM.mont t -> bn_to_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_from_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> a:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\
bn_v h1 a < bn_v_n h0 k /\
as_seq h1 a == S.bn_from_field (as_pctx h0 k) (as_seq h0 aM))
inline_for_extraction noextract
val bn_from_field: #t:limb_t -> km:BM.mont t -> bn_from_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_add_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_add (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_add: #t:limb_t -> km:BM.mont t -> bn_field_add_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_sub_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sub (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_sub: #t:limb_t -> km:BM.mont t -> bn_field_sub_st t km.BM.bn.BN.len
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_field_mul_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_field_mul_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 80,
"end_line": 298,
"start_col": 4,
"start_line": 280
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_field_inv_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> aInvM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
Euclid.is_prime (bn_v_n h k) /\
0 < bn_v h aM /\ bn_v h aM < bn_v_n h k /\
live h aM /\ live h aInvM /\ disjoint aM aInvM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aInvM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc aInvM) h0 h1 /\
bn_v h1 aInvM < bn_v_n h0 k /\
as_seq h1 aInvM == S.bn_field_inv (as_pctx h0 k) (as_seq h0 aM)) | let bn_field_inv_st (t: limb_t) (len: BN.meta_len t) = | false | null | false | k: pbn_mont_ctx t -> aM: lbignum t len -> aInvM: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).len == len /\ pbn_mont_ctx_inv h k /\ Euclid.is_prime (bn_v_n h k) /\
0 < bn_v h aM /\ bn_v h aM < bn_v_n h k /\ live h aM /\ live h aInvM /\ disjoint aM aInvM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aInvM <: buffer (limb t)))))
(ensures
fun h0 _ h1 ->
modifies (loc aInvM) h0 h1 /\ bn_v h1 aInvM < bn_v_n h0 k /\
as_seq h1 aInvM == S.bn_field_inv (as_pctx h0 k) (as_seq h0 aM)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"FStar.Math.Euclid.is_prime",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.bn_v",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len",
"Hacl.Bignum.MontArithmetic.as_pctx",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.MontArithmetic.bn_field_inv"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t
inline_for_extraction noextract
let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n))
inline_for_extraction noextract
val bn_field_check_modulus: #t:limb_t -> km:BM.mont t -> bn_field_check_modulus_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_init_st (t:limb_t) (len:BN.meta_len t) =
r:HS.rid
-> n:lbignum t len ->
ST (pbn_mont_ctx t)
(requires fun h ->
S.bn_mont_ctx_pre (as_seq h n) /\
live h n /\ ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\
freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\
as_pctx h1 res == S.bn_field_init (as_seq h0 n))
inline_for_extraction noextract
val bn_field_init:
#t:limb_t
-> len:BN.meta_len t
-> precomp_r2:BM.bn_precomp_r2_mod_n_st t len ->
bn_field_init_st t len
inline_for_extraction noextract
let bn_field_free_st (t:limb_t) = k:pbn_mont_ctx t ->
ST unit
(requires fun h ->
freeable h k /\
pbn_mont_ctx_inv h k)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 k) h0 h1))
inline_for_extraction noextract
val bn_field_free: #t:limb_t -> bn_field_free_st t
inline_for_extraction noextract
let bn_to_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> a:lbignum t len
-> aM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\
bn_v h1 aM < bn_v_n h0 k /\
as_seq h1 aM == S.bn_to_field (as_pctx h0 k) (as_seq h0 a))
inline_for_extraction noextract
val bn_to_field: #t:limb_t -> km:BM.mont t -> bn_to_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_from_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> a:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\
bn_v h1 a < bn_v_n h0 k /\
as_seq h1 a == S.bn_from_field (as_pctx h0 k) (as_seq h0 aM))
inline_for_extraction noextract
val bn_from_field: #t:limb_t -> km:BM.mont t -> bn_from_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_add_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_add (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_add: #t:limb_t -> km:BM.mont t -> bn_field_add_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_sub_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sub (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_sub: #t:limb_t -> km:BM.mont t -> bn_field_sub_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_mul_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_mul (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_mul: #t:limb_t -> km:BM.mont t -> bn_field_mul_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_sqr_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
live h aM /\ live h cM /\ eq_or_disjoint aM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sqr (as_pctx h0 k) (as_seq h0 aM))
inline_for_extraction noextract
val bn_field_sqr: #t:limb_t -> km:BM.mont t -> bn_field_sqr_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_one_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> oneM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h oneM /\
B.(loc_disjoint (footprint h k) (loc_buffer (oneM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc oneM) h0 h1 /\
bn_v h1 oneM < bn_v_n h0 k /\
as_seq h1 oneM == S.bn_field_one (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_one: #t:limb_t -> km:BM.mont t -> bn_field_one_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_exp_consttime_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> resM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h b < pow2 (v bBits) /\
live h aM /\ live h b /\ live h resM /\
disjoint resM aM /\ disjoint resM b /\ disjoint aM b /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (resM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\
bn_v h1 resM < bn_v_n h0 k /\
as_seq h1 resM == S.bn_field_exp_consttime (as_pctx h0 k) (as_seq h0 aM) (v bBits) (as_seq h0 b))
inline_for_extraction noextract
val bn_field_exp_consttime: #t:limb_t -> km:BM.mont t -> bn_field_exp_consttime_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_exp_vartime_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> resM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h b < pow2 (v bBits) /\
live h aM /\ live h b /\ live h resM /\
disjoint resM aM /\ disjoint resM b /\ disjoint aM b /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (resM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\
bn_v h1 resM < bn_v_n h0 k /\
as_seq h1 resM == S.bn_field_exp_vartime (as_pctx h0 k) (as_seq h0 aM) (v bBits) (as_seq h0 b))
inline_for_extraction noextract
val bn_field_exp_vartime: #t:limb_t -> km:BM.mont t -> bn_field_exp_vartime_st t km.BM.bn.BN.len
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_field_inv_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_field_inv_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 68,
"end_line": 419,
"start_col": 4,
"start_line": 404
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_field_exp_consttime_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> resM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h b < pow2 (v bBits) /\
live h aM /\ live h b /\ live h resM /\
disjoint resM aM /\ disjoint resM b /\ disjoint aM b /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (resM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\
bn_v h1 resM < bn_v_n h0 k /\
as_seq h1 resM == S.bn_field_exp_consttime (as_pctx h0 k) (as_seq h0 aM) (v bBits) (as_seq h0 b)) | let bn_field_exp_consttime_st (t: limb_t) (len: BN.meta_len t) = | false | null | false |
k: pbn_mont_ctx t ->
aM: lbignum t len ->
bBits: size_t ->
b: lbignum t (blocks0 bBits (size (bits t))) ->
resM: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).len == len /\ pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
bn_v h b < pow2 (v bBits) /\ live h aM /\ live h b /\ live h resM /\ disjoint resM aM /\
disjoint resM b /\ disjoint aM b /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (resM <: buffer (limb t)))))
(ensures
fun h0 _ h1 ->
modifies (loc resM) h0 h1 /\ bn_v h1 resM < bn_v_n h0 k /\
as_seq h1 resM ==
S.bn_field_exp_consttime (as_pctx h0 k) (as_seq h0 aM) (v bBits) (as_seq h0 b)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"Prims.pow2",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len",
"Hacl.Bignum.MontArithmetic.as_pctx",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.MontArithmetic.bn_field_exp_consttime"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t
inline_for_extraction noextract
let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n))
inline_for_extraction noextract
val bn_field_check_modulus: #t:limb_t -> km:BM.mont t -> bn_field_check_modulus_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_init_st (t:limb_t) (len:BN.meta_len t) =
r:HS.rid
-> n:lbignum t len ->
ST (pbn_mont_ctx t)
(requires fun h ->
S.bn_mont_ctx_pre (as_seq h n) /\
live h n /\ ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\
freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\
as_pctx h1 res == S.bn_field_init (as_seq h0 n))
inline_for_extraction noextract
val bn_field_init:
#t:limb_t
-> len:BN.meta_len t
-> precomp_r2:BM.bn_precomp_r2_mod_n_st t len ->
bn_field_init_st t len
inline_for_extraction noextract
let bn_field_free_st (t:limb_t) = k:pbn_mont_ctx t ->
ST unit
(requires fun h ->
freeable h k /\
pbn_mont_ctx_inv h k)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 k) h0 h1))
inline_for_extraction noextract
val bn_field_free: #t:limb_t -> bn_field_free_st t
inline_for_extraction noextract
let bn_to_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> a:lbignum t len
-> aM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\
bn_v h1 aM < bn_v_n h0 k /\
as_seq h1 aM == S.bn_to_field (as_pctx h0 k) (as_seq h0 a))
inline_for_extraction noextract
val bn_to_field: #t:limb_t -> km:BM.mont t -> bn_to_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_from_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> a:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\
bn_v h1 a < bn_v_n h0 k /\
as_seq h1 a == S.bn_from_field (as_pctx h0 k) (as_seq h0 aM))
inline_for_extraction noextract
val bn_from_field: #t:limb_t -> km:BM.mont t -> bn_from_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_add_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_add (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_add: #t:limb_t -> km:BM.mont t -> bn_field_add_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_sub_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sub (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_sub: #t:limb_t -> km:BM.mont t -> bn_field_sub_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_mul_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_mul (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_mul: #t:limb_t -> km:BM.mont t -> bn_field_mul_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_sqr_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
live h aM /\ live h cM /\ eq_or_disjoint aM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sqr (as_pctx h0 k) (as_seq h0 aM))
inline_for_extraction noextract
val bn_field_sqr: #t:limb_t -> km:BM.mont t -> bn_field_sqr_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_one_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> oneM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h oneM /\
B.(loc_disjoint (footprint h k) (loc_buffer (oneM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc oneM) h0 h1 /\
bn_v h1 oneM < bn_v_n h0 k /\
as_seq h1 oneM == S.bn_field_one (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_one: #t:limb_t -> km:BM.mont t -> bn_field_one_st t km.BM.bn.BN.len
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_field_exp_consttime_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_field_exp_consttime_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 101,
"end_line": 368,
"start_col": 4,
"start_line": 350
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontArithmetic",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_field_exp_vartime_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> resM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h b < pow2 (v bBits) /\
live h aM /\ live h b /\ live h resM /\
disjoint resM aM /\ disjoint resM b /\ disjoint aM b /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (resM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\
bn_v h1 resM < bn_v_n h0 k /\
as_seq h1 resM == S.bn_field_exp_vartime (as_pctx h0 k) (as_seq h0 aM) (v bBits) (as_seq h0 b)) | let bn_field_exp_vartime_st (t: limb_t) (len: BN.meta_len t) = | false | null | false |
k: pbn_mont_ctx t ->
aM: lbignum t len ->
bBits: size_t ->
b: lbignum t (blocks0 bBits (size (bits t))) ->
resM: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).len == len /\ pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
bn_v h b < pow2 (v bBits) /\ live h aM /\ live h b /\ live h resM /\ disjoint resM aM /\
disjoint resM b /\ disjoint aM b /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (resM <: buffer (limb t)))))
(ensures
fun h0 _ h1 ->
modifies (loc resM) h0 h1 /\ bn_v h1 resM < bn_v_n h0 k /\
as_seq h1 resM ==
S.bn_field_exp_vartime (as_pctx h0 k) (as_seq h0 aM) (v bBits) (as_seq h0 b)) | {
"checked_file": "Hacl.Bignum.MontArithmetic.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.MontArithmetic.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"Prims.pow2",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len",
"Hacl.Bignum.MontArithmetic.as_pctx",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__n",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.MontArithmetic.bn_field_exp_vartime"
] | [] | module Hacl.Bignum.MontArithmetic
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module B = LowStar.Buffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module Euclid = FStar.Math.Euclid
module S = Hacl.Spec.Bignum.MontArithmetic
module BE = Hacl.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val _align_fsti : unit
inline_for_extraction noextract
let lb (t:limb_t) =
match t with
| U32 -> buffer uint32
| U64 -> buffer uint64
inline_for_extraction noextract
let ll (t:limb_t) =
match t with
| U32 -> uint32
| U64 -> uint64
inline_for_extraction
noeq
type bn_mont_ctx' (t:limb_t) (a:Type0{a == lb t}) (b:Type0{b == ll t}) = {
len: BN.meta_len t;
n: x:a{length #MUT #(limb t) x == v len};
mu: b;
r2: x:a{length #MUT #(limb t) x == v len};
}
inline_for_extraction noextract
let bn_mont_ctx (t:limb_t) = bn_mont_ctx' t (lb t) (ll t)
let bn_mont_ctx_u32 = bn_mont_ctx' U32 (lb U32) (ll U32)
let bn_mont_ctx_u64 = bn_mont_ctx' U64 (lb U64) (ll U64)
inline_for_extraction noextract
let pbn_mont_ctx (t:limb_t) = B.pointer (bn_mont_ctx t)
inline_for_extraction noextract
let pbn_mont_ctx_u32 = B.pointer bn_mont_ctx_u32
inline_for_extraction noextract
let pbn_mont_ctx_u64 = B.pointer bn_mont_ctx_u64
inline_for_extraction noextract
let as_ctx (#t:limb_t) (h:mem) (k:bn_mont_ctx t) : GTot (S.bn_mont_ctx t) = {
S.len = v k.len;
S.n = as_seq h (k.n <: lbignum t k.len);
S.mu = k.mu;
S.r2 = as_seq h (k.r2 <: lbignum t k.len);
}
inline_for_extraction noextract
let bn_mont_ctx_inv (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
live h n /\ live h r2 /\ disjoint n r2 /\
S.bn_mont_ctx_inv (as_ctx h k)
inline_for_extraction noextract
let bn_v_n (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
let k1 = B.deref h k in
let n : lbignum t k1.len = k1.n in
bn_v h n
inline_for_extraction noextract
let freeable_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.freeable n /\ B.freeable r2
inline_for_extraction noextract
let freeable (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.freeable k /\ freeable_s h (B.deref h k)
inline_for_extraction noextract
let footprint_s (#t:limb_t) (h:mem) (k:bn_mont_ctx t) =
let n : buffer (limb t) = k.n in
let r2 : buffer (limb t) = k.r2 in
B.(loc_union (loc_addr_of_buffer n) (loc_addr_of_buffer r2))
inline_for_extraction noextract
let footprint (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.(loc_union (loc_addr_of_buffer k) (footprint_s h (B.deref h k)))
inline_for_extraction noextract
let as_pctx (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) : GTot (S.bn_mont_ctx t) =
as_ctx h (B.deref h k)
inline_for_extraction noextract
let pbn_mont_ctx_inv (#t:limb_t) (h:mem) (k:pbn_mont_ctx t) =
B.live h k /\
B.(loc_disjoint (loc_addr_of_buffer k) (footprint_s h (B.deref h k))) /\
bn_mont_ctx_inv h (B.deref h k)
inline_for_extraction noextract
let bn_field_get_len_st (t:limb_t) = k:pbn_mont_ctx t ->
Stack (BN.meta_len t)
(requires fun h -> pbn_mont_ctx_inv h k)
(ensures fun h0 r h1 -> h0 == h1 /\
r == (B.deref h0 k).len /\
v r == S.bn_field_get_len (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_get_len: #t:limb_t -> bn_field_get_len_st t
inline_for_extraction noextract
let bn_field_check_modulus_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len ->
Stack bool
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_field_check_modulus (as_seq h0 n))
inline_for_extraction noextract
val bn_field_check_modulus: #t:limb_t -> km:BM.mont t -> bn_field_check_modulus_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_init_st (t:limb_t) (len:BN.meta_len t) =
r:HS.rid
-> n:lbignum t len ->
ST (pbn_mont_ctx t)
(requires fun h ->
S.bn_mont_ctx_pre (as_seq h n) /\
live h n /\ ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
B.(fresh_loc (footprint h1 res) h0 h1) /\
B.(loc_includes (loc_region_only true r) (footprint h1 res)) /\
freeable h1 res /\
(B.deref h1 res).len == len /\ bn_v_n h1 res == bn_v h0 n /\
S.bn_mont_ctx_inv (as_pctx h1 res) /\
as_pctx h1 res == S.bn_field_init (as_seq h0 n))
inline_for_extraction noextract
val bn_field_init:
#t:limb_t
-> len:BN.meta_len t
-> precomp_r2:BM.bn_precomp_r2_mod_n_st t len ->
bn_field_init_st t len
inline_for_extraction noextract
let bn_field_free_st (t:limb_t) = k:pbn_mont_ctx t ->
ST unit
(requires fun h ->
freeable h k /\
pbn_mont_ctx_inv h k)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 k) h0 h1))
inline_for_extraction noextract
val bn_field_free: #t:limb_t -> bn_field_free_st t
inline_for_extraction noextract
let bn_to_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> a:lbignum t len
-> aM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc aM) h0 h1 /\
bn_v h1 aM < bn_v_n h0 k /\
as_seq h1 aM == S.bn_to_field (as_pctx h0 k) (as_seq h0 a))
inline_for_extraction noextract
val bn_to_field: #t:limb_t -> km:BM.mont t -> bn_to_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_from_field_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> a:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\ bn_v h aM < bn_v_n h k /\
live h a /\ live h aM /\ disjoint a aM /\
B.(loc_disjoint (footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\
bn_v h1 a < bn_v_n h0 k /\
as_seq h1 a == S.bn_from_field (as_pctx h0 k) (as_seq h0 aM))
inline_for_extraction noextract
val bn_from_field: #t:limb_t -> km:BM.mont t -> bn_from_field_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_add_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_add (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_add: #t:limb_t -> km:BM.mont t -> bn_field_add_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_sub_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sub (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_sub: #t:limb_t -> km:BM.mont t -> bn_field_sub_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_mul_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h bM < bn_v_n h k /\
live h aM /\ live h bM /\ live h cM /\
eq_or_disjoint aM bM /\ eq_or_disjoint aM cM /\ eq_or_disjoint bM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (bM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_mul (as_pctx h0 k) (as_seq h0 aM) (as_seq h0 bM))
inline_for_extraction noextract
val bn_field_mul: #t:limb_t -> km:BM.mont t -> bn_field_mul_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_sqr_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> cM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
live h aM /\ live h cM /\ eq_or_disjoint aM cM /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (cM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc cM) h0 h1 /\
bn_v h1 cM < bn_v_n h0 k /\
as_seq h1 cM == S.bn_field_sqr (as_pctx h0 k) (as_seq h0 aM))
inline_for_extraction noextract
val bn_field_sqr: #t:limb_t -> km:BM.mont t -> bn_field_sqr_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_one_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> oneM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
live h oneM /\
B.(loc_disjoint (footprint h k) (loc_buffer (oneM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc oneM) h0 h1 /\
bn_v h1 oneM < bn_v_n h0 k /\
as_seq h1 oneM == S.bn_field_one (as_pctx h0 k))
inline_for_extraction noextract
val bn_field_one: #t:limb_t -> km:BM.mont t -> bn_field_one_st t km.BM.bn.BN.len
inline_for_extraction noextract
let bn_field_exp_consttime_st (t:limb_t) (len:BN.meta_len t) =
k:pbn_mont_ctx t
-> aM:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> resM:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).len == len /\
pbn_mont_ctx_inv h k /\
bn_v h aM < bn_v_n h k /\
bn_v h b < pow2 (v bBits) /\
live h aM /\ live h b /\ live h resM /\
disjoint resM aM /\ disjoint resM b /\ disjoint aM b /\
B.(loc_disjoint (footprint h k) (loc_buffer (aM <: buffer (limb t)))) /\
B.(loc_disjoint (footprint h k) (loc_buffer (resM <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc resM) h0 h1 /\
bn_v h1 resM < bn_v_n h0 k /\
as_seq h1 resM == S.bn_field_exp_consttime (as_pctx h0 k) (as_seq h0 aM) (v bBits) (as_seq h0 b))
inline_for_extraction noextract
val bn_field_exp_consttime: #t:limb_t -> km:BM.mont t -> bn_field_exp_consttime_st t km.BM.bn.BN.len
inline_for_extraction noextract | false | false | Hacl.Bignum.MontArithmetic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_field_exp_vartime_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.MontArithmetic.bn_field_exp_vartime_st | {
"file_name": "code/bignum/Hacl.Bignum.MontArithmetic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 99,
"end_line": 395,
"start_col": 4,
"start_line": 377
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Impl.P256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lbytes len = lbuffer uint8 len | let lbytes len = | false | null | false | lbuffer uint8 len | {
"checked_file": "Hacl.Impl.P256.Verify.fst.checked",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.P256.Montgomery.fsti.checked",
"Hacl.Impl.P256.Scalar.fsti.checked",
"Hacl.Impl.P256.Qinv.fsti.checked",
"Hacl.Impl.P256.PointMul.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Bignum.fsti.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.P256.Verify.fst"
} | [
"total"
] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8"
] | [] | module Hacl.Impl.P256.Verify
open FStar.Mul
open FStar.HyperStack.All
open FStar.HyperStack
module ST = FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.P256.Bignum
open Hacl.Impl.P256.Point
open Hacl.Impl.P256.Scalar
open Hacl.Impl.P256.PointMul
module BSeq = Lib.ByteSequence
module S = Spec.P256
module SL = Spec.P256.Lemmas
module SM = Hacl.Spec.P256.Montgomery
module QI = Hacl.Impl.P256.Qinv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | false | true | Hacl.Impl.P256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lbytes : len: Lib.IntTypes.size_t -> Type0 | [] | Hacl.Impl.P256.Verify.lbytes | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Lib.IntTypes.size_t -> Type0 | {
"end_col": 34,
"end_line": 26,
"start_col": 17,
"start_line": 26
} |
|
FStar.HyperStack.ST.Stack | val load_signature (r_q s_q:felem) (sign_r sign_s:lbytes 32ul) : Stack bool
(requires fun h ->
live h sign_r /\ live h sign_s /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q sign_r /\ disjoint r_q sign_s /\
disjoint s_q sign_r /\ disjoint s_q sign_s)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
as_nat h1 r_q = r_q_nat /\ as_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.order && 0 < s_q_nat && s_q_nat < S.order))) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.P256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let load_signature r_q s_q sign_r sign_s =
bn_from_bytes_be4 r_q sign_r;
bn_from_bytes_be4 s_q sign_s;
let is_r_valid = bn_is_lt_order_and_gt_zero_mask4 r_q in
let is_s_valid = bn_is_lt_order_and_gt_zero_mask4 s_q in
Hacl.Bignum.Base.unsafe_bool_of_limb is_r_valid &&
Hacl.Bignum.Base.unsafe_bool_of_limb is_s_valid | val load_signature (r_q s_q:felem) (sign_r sign_s:lbytes 32ul) : Stack bool
(requires fun h ->
live h sign_r /\ live h sign_s /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q sign_r /\ disjoint r_q sign_s /\
disjoint s_q sign_r /\ disjoint s_q sign_s)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
as_nat h1 r_q = r_q_nat /\ as_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.order && 0 < s_q_nat && s_q_nat < S.order)))
let load_signature r_q s_q sign_r sign_s = | true | null | false | bn_from_bytes_be4 r_q sign_r;
bn_from_bytes_be4 s_q sign_s;
let is_r_valid = bn_is_lt_order_and_gt_zero_mask4 r_q in
let is_s_valid = bn_is_lt_order_and_gt_zero_mask4 s_q in
Hacl.Bignum.Base.unsafe_bool_of_limb is_r_valid && Hacl.Bignum.Base.unsafe_bool_of_limb is_s_valid | {
"checked_file": "Hacl.Impl.P256.Verify.fst.checked",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.P256.Montgomery.fsti.checked",
"Hacl.Impl.P256.Scalar.fsti.checked",
"Hacl.Impl.P256.Qinv.fsti.checked",
"Hacl.Impl.P256.PointMul.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Bignum.fsti.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.P256.Verify.fst"
} | [] | [
"Hacl.Impl.P256.Bignum.felem",
"Hacl.Impl.P256.Verify.lbytes",
"FStar.UInt32.__uint_to_t",
"Prims.op_AmpAmp",
"Hacl.Spec.Bignum.Base.unsafe_bool_of_limb",
"Lib.IntTypes.U64",
"Prims.bool",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Hacl.Impl.P256.Scalar.bn_is_lt_order_and_gt_zero_mask4",
"Lib.IntTypes.uint64",
"Prims.unit",
"Hacl.Impl.P256.Bignum.bn_from_bytes_be4"
] | [] | module Hacl.Impl.P256.Verify
open FStar.Mul
open FStar.HyperStack.All
open FStar.HyperStack
module ST = FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.P256.Bignum
open Hacl.Impl.P256.Point
open Hacl.Impl.P256.Scalar
open Hacl.Impl.P256.PointMul
module BSeq = Lib.ByteSequence
module S = Spec.P256
module SL = Spec.P256.Lemmas
module SM = Hacl.Spec.P256.Montgomery
module QI = Hacl.Impl.P256.Qinv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
val qmul_mont: sinv:felem -> b:felem -> res:felem -> Stack unit
(requires fun h ->
live h sinv /\ live h b /\ live h res /\
disjoint sinv res /\ disjoint b res /\
as_nat h sinv < S.order /\ as_nat h b < S.order)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_nat h1 res < S.order /\
as_nat h1 res = (as_nat h0 sinv * SM.from_qmont (as_nat h0 b) * SM.qmont_R_inv) % S.order)
[@CInline]
let qmul_mont sinv b res =
let h0 = ST.get () in
push_frame ();
let tmp = create_felem () in
from_qmont tmp b;
let h1 = ST.get () in
assert (as_nat h1 tmp == SM.from_qmont (as_nat h0 b));
qmul res sinv tmp;
let h2 = ST.get () in
assert (as_nat h2 res = (as_nat h1 sinv * as_nat h1 tmp * SM.qmont_R_inv) % S.order);
pop_frame ()
inline_for_extraction noextract
val ecdsa_verification_get_u12: u1:felem -> u2:felem -> r:felem -> s:felem -> z:felem -> Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
as_nat h s < S.order /\ as_nat h z < S.order /\ as_nat h r < S.order)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (as_nat h0 s) in
as_nat h1 u1 == sinv * as_nat h0 z % S.order /\
as_nat h1 u2 == sinv * as_nat h0 r % S.order))
let ecdsa_verification_get_u12 u1 u2 r s z =
push_frame ();
let h0 = ST.get () in
let sinv = create_felem () in
QI.qinv sinv s;
let h1 = ST.get () in
assert (qmont_as_nat h1 sinv == S.qinv (qmont_as_nat h0 s));
//assert (as_nat h2 sinv * SM.qmont_R_inv % S.order ==
//S.qinv (as_nat h1 sinv * SM.qmont_R_inv % S.order));
SM.qmont_inv_mul_lemma (as_nat h0 s) (as_nat h1 sinv) (as_nat h0 z);
SM.qmont_inv_mul_lemma (as_nat h0 s) (as_nat h1 sinv) (as_nat h0 r);
qmul_mont sinv z u1;
qmul_mont sinv r u2;
pop_frame ()
inline_for_extraction noextract
val ecdsa_verify_finv: p:point -> r:felem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ 0 < as_nat h r /\ as_nat h r < S.order)
//not (S.is_point_at_inf (from_mont_point (as_point_nat h p))))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = from_mont_point (as_point_nat h0 p) in
b <==> (S.fmul _X (S.finv _Z) % S.order = as_nat h0 r)))
let ecdsa_verify_finv p r_q =
push_frame ();
let x = create_felem () in
to_aff_point_x x p;
qmod_short x x;
let res = bn_is_eq_vartime4 x r_q in
pop_frame ();
res
inline_for_extraction noextract
val ecdsa_verification_cmpr: r:felem -> pk:point -> u1:felem -> u2:felem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ as_nat h u1 < S.order /\ as_nat h u2 < S.order /\
0 < as_nat h r /\ as_nat h r < S.order)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (as_nat h0 u1) (as_nat h0 u2)
(from_mont_point (as_point_nat h0 pk)) in
b <==> (if S.is_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.order = as_nat h0 r)))
let ecdsa_verification_cmpr r pk u1 u2 =
push_frame ();
let res = create_point () in
let h0 = ST.get () in
point_mul_double_g res u1 u2 pk;
let h1 = ST.get () in
assert (S.to_aff_point (from_mont_point (as_point_nat h1 res)) ==
S.to_aff_point (S.point_mul_double_g (as_nat h0 u1) (as_nat h0 u2)
(from_mont_point (as_point_nat h0 pk))));
SL.lemma_aff_is_point_at_inf (from_mont_point (as_point_nat h1 res));
SL.lemma_aff_is_point_at_inf
(S.point_mul_double_g (as_nat h0 u1) (as_nat h0 u2) (from_mont_point (as_point_nat h0 pk)));
let b =
if is_point_at_inf_vartime res then false
else ecdsa_verify_finv res r in
pop_frame ();
b
inline_for_extraction noextract
val load_signature (r_q s_q:felem) (sign_r sign_s:lbytes 32ul) : Stack bool
(requires fun h ->
live h sign_r /\ live h sign_s /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q sign_r /\ disjoint r_q sign_s /\
disjoint s_q sign_r /\ disjoint s_q sign_s)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
as_nat h1 r_q = r_q_nat /\ as_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.order && 0 < s_q_nat && s_q_nat < S.order))) | false | false | Hacl.Impl.P256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val load_signature (r_q s_q:felem) (sign_r sign_s:lbytes 32ul) : Stack bool
(requires fun h ->
live h sign_r /\ live h sign_s /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q sign_r /\ disjoint r_q sign_s /\
disjoint s_q sign_r /\ disjoint s_q sign_s)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
as_nat h1 r_q = r_q_nat /\ as_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.order && 0 < s_q_nat && s_q_nat < S.order))) | [] | Hacl.Impl.P256.Verify.load_signature | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
r_q: Hacl.Impl.P256.Bignum.felem ->
s_q: Hacl.Impl.P256.Bignum.felem ->
sign_r: Hacl.Impl.P256.Verify.lbytes 32ul ->
sign_s: Hacl.Impl.P256.Verify.lbytes 32ul
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 49,
"end_line": 153,
"start_col": 2,
"start_line": 148
} |
FStar.HyperStack.ST.Stack | val qmul_mont: sinv:felem -> b:felem -> res:felem -> Stack unit
(requires fun h ->
live h sinv /\ live h b /\ live h res /\
disjoint sinv res /\ disjoint b res /\
as_nat h sinv < S.order /\ as_nat h b < S.order)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_nat h1 res < S.order /\
as_nat h1 res = (as_nat h0 sinv * SM.from_qmont (as_nat h0 b) * SM.qmont_R_inv) % S.order) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.P256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let qmul_mont sinv b res =
let h0 = ST.get () in
push_frame ();
let tmp = create_felem () in
from_qmont tmp b;
let h1 = ST.get () in
assert (as_nat h1 tmp == SM.from_qmont (as_nat h0 b));
qmul res sinv tmp;
let h2 = ST.get () in
assert (as_nat h2 res = (as_nat h1 sinv * as_nat h1 tmp * SM.qmont_R_inv) % S.order);
pop_frame () | val qmul_mont: sinv:felem -> b:felem -> res:felem -> Stack unit
(requires fun h ->
live h sinv /\ live h b /\ live h res /\
disjoint sinv res /\ disjoint b res /\
as_nat h sinv < S.order /\ as_nat h b < S.order)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_nat h1 res < S.order /\
as_nat h1 res = (as_nat h0 sinv * SM.from_qmont (as_nat h0 b) * SM.qmont_R_inv) % S.order)
let qmul_mont sinv b res = | true | null | false | let h0 = ST.get () in
push_frame ();
let tmp = create_felem () in
from_qmont tmp b;
let h1 = ST.get () in
assert (as_nat h1 tmp == SM.from_qmont (as_nat h0 b));
qmul res sinv tmp;
let h2 = ST.get () in
assert (as_nat h2 res = ((as_nat h1 sinv * as_nat h1 tmp) * SM.qmont_R_inv) % S.order);
pop_frame () | {
"checked_file": "Hacl.Impl.P256.Verify.fst.checked",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.P256.Montgomery.fsti.checked",
"Hacl.Impl.P256.Scalar.fsti.checked",
"Hacl.Impl.P256.Qinv.fsti.checked",
"Hacl.Impl.P256.PointMul.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Bignum.fsti.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.P256.Verify.fst"
} | [] | [
"Hacl.Impl.P256.Bignum.felem",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Hacl.Impl.P256.Bignum.as_nat",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Hacl.Spec.P256.Montgomery.qmont_R_inv",
"Spec.P256.PointOps.order",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.P256.Scalar.qmul",
"Prims.eq2",
"Prims.nat",
"Hacl.Spec.P256.Montgomery.from_qmont",
"Hacl.Impl.P256.Scalar.from_qmont",
"Hacl.Impl.P256.Bignum.create_felem",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.P256.Verify
open FStar.Mul
open FStar.HyperStack.All
open FStar.HyperStack
module ST = FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.P256.Bignum
open Hacl.Impl.P256.Point
open Hacl.Impl.P256.Scalar
open Hacl.Impl.P256.PointMul
module BSeq = Lib.ByteSequence
module S = Spec.P256
module SL = Spec.P256.Lemmas
module SM = Hacl.Spec.P256.Montgomery
module QI = Hacl.Impl.P256.Qinv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
val qmul_mont: sinv:felem -> b:felem -> res:felem -> Stack unit
(requires fun h ->
live h sinv /\ live h b /\ live h res /\
disjoint sinv res /\ disjoint b res /\
as_nat h sinv < S.order /\ as_nat h b < S.order)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_nat h1 res < S.order /\
as_nat h1 res = (as_nat h0 sinv * SM.from_qmont (as_nat h0 b) * SM.qmont_R_inv) % S.order) | false | false | Hacl.Impl.P256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val qmul_mont: sinv:felem -> b:felem -> res:felem -> Stack unit
(requires fun h ->
live h sinv /\ live h b /\ live h res /\
disjoint sinv res /\ disjoint b res /\
as_nat h sinv < S.order /\ as_nat h b < S.order)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_nat h1 res < S.order /\
as_nat h1 res = (as_nat h0 sinv * SM.from_qmont (as_nat h0 b) * SM.qmont_R_inv) % S.order) | [] | Hacl.Impl.P256.Verify.qmul_mont | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
sinv: Hacl.Impl.P256.Bignum.felem ->
b: Hacl.Impl.P256.Bignum.felem ->
res: Hacl.Impl.P256.Bignum.felem
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 14,
"end_line": 48,
"start_col": 26,
"start_line": 38
} |
FStar.HyperStack.ST.Stack | val ecdsa_verify_finv: p:point -> r:felem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ 0 < as_nat h r /\ as_nat h r < S.order)
//not (S.is_point_at_inf (from_mont_point (as_point_nat h p))))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = from_mont_point (as_point_nat h0 p) in
b <==> (S.fmul _X (S.finv _Z) % S.order = as_nat h0 r))) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.P256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ecdsa_verify_finv p r_q =
push_frame ();
let x = create_felem () in
to_aff_point_x x p;
qmod_short x x;
let res = bn_is_eq_vartime4 x r_q in
pop_frame ();
res | val ecdsa_verify_finv: p:point -> r:felem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ 0 < as_nat h r /\ as_nat h r < S.order)
//not (S.is_point_at_inf (from_mont_point (as_point_nat h p))))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = from_mont_point (as_point_nat h0 p) in
b <==> (S.fmul _X (S.finv _Z) % S.order = as_nat h0 r)))
let ecdsa_verify_finv p r_q = | true | null | false | push_frame ();
let x = create_felem () in
to_aff_point_x x p;
qmod_short x x;
let res = bn_is_eq_vartime4 x r_q in
pop_frame ();
res | {
"checked_file": "Hacl.Impl.P256.Verify.fst.checked",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.P256.Montgomery.fsti.checked",
"Hacl.Impl.P256.Scalar.fsti.checked",
"Hacl.Impl.P256.Qinv.fsti.checked",
"Hacl.Impl.P256.PointMul.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Bignum.fsti.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.P256.Verify.fst"
} | [] | [
"Hacl.Impl.P256.Point.point",
"Hacl.Impl.P256.Bignum.felem",
"Prims.bool",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Hacl.Impl.P256.Bignum.bn_is_eq_vartime4",
"Hacl.Impl.P256.Scalar.qmod_short",
"Hacl.Impl.P256.Point.to_aff_point_x",
"Hacl.Impl.P256.Bignum.create_felem",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.P256.Verify
open FStar.Mul
open FStar.HyperStack.All
open FStar.HyperStack
module ST = FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.P256.Bignum
open Hacl.Impl.P256.Point
open Hacl.Impl.P256.Scalar
open Hacl.Impl.P256.PointMul
module BSeq = Lib.ByteSequence
module S = Spec.P256
module SL = Spec.P256.Lemmas
module SM = Hacl.Spec.P256.Montgomery
module QI = Hacl.Impl.P256.Qinv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
val qmul_mont: sinv:felem -> b:felem -> res:felem -> Stack unit
(requires fun h ->
live h sinv /\ live h b /\ live h res /\
disjoint sinv res /\ disjoint b res /\
as_nat h sinv < S.order /\ as_nat h b < S.order)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_nat h1 res < S.order /\
as_nat h1 res = (as_nat h0 sinv * SM.from_qmont (as_nat h0 b) * SM.qmont_R_inv) % S.order)
[@CInline]
let qmul_mont sinv b res =
let h0 = ST.get () in
push_frame ();
let tmp = create_felem () in
from_qmont tmp b;
let h1 = ST.get () in
assert (as_nat h1 tmp == SM.from_qmont (as_nat h0 b));
qmul res sinv tmp;
let h2 = ST.get () in
assert (as_nat h2 res = (as_nat h1 sinv * as_nat h1 tmp * SM.qmont_R_inv) % S.order);
pop_frame ()
inline_for_extraction noextract
val ecdsa_verification_get_u12: u1:felem -> u2:felem -> r:felem -> s:felem -> z:felem -> Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
as_nat h s < S.order /\ as_nat h z < S.order /\ as_nat h r < S.order)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (as_nat h0 s) in
as_nat h1 u1 == sinv * as_nat h0 z % S.order /\
as_nat h1 u2 == sinv * as_nat h0 r % S.order))
let ecdsa_verification_get_u12 u1 u2 r s z =
push_frame ();
let h0 = ST.get () in
let sinv = create_felem () in
QI.qinv sinv s;
let h1 = ST.get () in
assert (qmont_as_nat h1 sinv == S.qinv (qmont_as_nat h0 s));
//assert (as_nat h2 sinv * SM.qmont_R_inv % S.order ==
//S.qinv (as_nat h1 sinv * SM.qmont_R_inv % S.order));
SM.qmont_inv_mul_lemma (as_nat h0 s) (as_nat h1 sinv) (as_nat h0 z);
SM.qmont_inv_mul_lemma (as_nat h0 s) (as_nat h1 sinv) (as_nat h0 r);
qmul_mont sinv z u1;
qmul_mont sinv r u2;
pop_frame ()
inline_for_extraction noextract
val ecdsa_verify_finv: p:point -> r:felem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ 0 < as_nat h r /\ as_nat h r < S.order)
//not (S.is_point_at_inf (from_mont_point (as_point_nat h p))))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = from_mont_point (as_point_nat h0 p) in
b <==> (S.fmul _X (S.finv _Z) % S.order = as_nat h0 r))) | false | false | Hacl.Impl.P256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ecdsa_verify_finv: p:point -> r:felem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ 0 < as_nat h r /\ as_nat h r < S.order)
//not (S.is_point_at_inf (from_mont_point (as_point_nat h p))))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = from_mont_point (as_point_nat h0 p) in
b <==> (S.fmul _X (S.finv _Z) % S.order = as_nat h0 r))) | [] | Hacl.Impl.P256.Verify.ecdsa_verify_finv | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | p: Hacl.Impl.P256.Point.point -> r: Hacl.Impl.P256.Bignum.felem
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 5,
"end_line": 97,
"start_col": 2,
"start_line": 91
} |
FStar.HyperStack.ST.Stack | val ecdsa_verification_get_u12: u1:felem -> u2:felem -> r:felem -> s:felem -> z:felem -> Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
as_nat h s < S.order /\ as_nat h z < S.order /\ as_nat h r < S.order)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (as_nat h0 s) in
as_nat h1 u1 == sinv * as_nat h0 z % S.order /\
as_nat h1 u2 == sinv * as_nat h0 r % S.order)) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.P256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ecdsa_verification_get_u12 u1 u2 r s z =
push_frame ();
let h0 = ST.get () in
let sinv = create_felem () in
QI.qinv sinv s;
let h1 = ST.get () in
assert (qmont_as_nat h1 sinv == S.qinv (qmont_as_nat h0 s));
//assert (as_nat h2 sinv * SM.qmont_R_inv % S.order ==
//S.qinv (as_nat h1 sinv * SM.qmont_R_inv % S.order));
SM.qmont_inv_mul_lemma (as_nat h0 s) (as_nat h1 sinv) (as_nat h0 z);
SM.qmont_inv_mul_lemma (as_nat h0 s) (as_nat h1 sinv) (as_nat h0 r);
qmul_mont sinv z u1;
qmul_mont sinv r u2;
pop_frame () | val ecdsa_verification_get_u12: u1:felem -> u2:felem -> r:felem -> s:felem -> z:felem -> Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
as_nat h s < S.order /\ as_nat h z < S.order /\ as_nat h r < S.order)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (as_nat h0 s) in
as_nat h1 u1 == sinv * as_nat h0 z % S.order /\
as_nat h1 u2 == sinv * as_nat h0 r % S.order))
let ecdsa_verification_get_u12 u1 u2 r s z = | true | null | false | push_frame ();
let h0 = ST.get () in
let sinv = create_felem () in
QI.qinv sinv s;
let h1 = ST.get () in
assert (qmont_as_nat h1 sinv == S.qinv (qmont_as_nat h0 s));
SM.qmont_inv_mul_lemma (as_nat h0 s) (as_nat h1 sinv) (as_nat h0 z);
SM.qmont_inv_mul_lemma (as_nat h0 s) (as_nat h1 sinv) (as_nat h0 r);
qmul_mont sinv z u1;
qmul_mont sinv r u2;
pop_frame () | {
"checked_file": "Hacl.Impl.P256.Verify.fst.checked",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.P256.Montgomery.fsti.checked",
"Hacl.Impl.P256.Scalar.fsti.checked",
"Hacl.Impl.P256.Qinv.fsti.checked",
"Hacl.Impl.P256.PointMul.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Bignum.fsti.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.P256.Verify.fst"
} | [] | [
"Hacl.Impl.P256.Bignum.felem",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.P256.Verify.qmul_mont",
"Hacl.Spec.P256.Montgomery.qmont_inv_mul_lemma",
"Hacl.Impl.P256.Bignum.as_nat",
"Prims._assert",
"Prims.eq2",
"Spec.P256.PointOps.qelem",
"Hacl.Impl.P256.Scalar.qmont_as_nat",
"Spec.P256.PointOps.qinv",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.P256.Qinv.qinv",
"Hacl.Impl.P256.Bignum.create_felem",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.P256.Verify
open FStar.Mul
open FStar.HyperStack.All
open FStar.HyperStack
module ST = FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.P256.Bignum
open Hacl.Impl.P256.Point
open Hacl.Impl.P256.Scalar
open Hacl.Impl.P256.PointMul
module BSeq = Lib.ByteSequence
module S = Spec.P256
module SL = Spec.P256.Lemmas
module SM = Hacl.Spec.P256.Montgomery
module QI = Hacl.Impl.P256.Qinv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
val qmul_mont: sinv:felem -> b:felem -> res:felem -> Stack unit
(requires fun h ->
live h sinv /\ live h b /\ live h res /\
disjoint sinv res /\ disjoint b res /\
as_nat h sinv < S.order /\ as_nat h b < S.order)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_nat h1 res < S.order /\
as_nat h1 res = (as_nat h0 sinv * SM.from_qmont (as_nat h0 b) * SM.qmont_R_inv) % S.order)
[@CInline]
let qmul_mont sinv b res =
let h0 = ST.get () in
push_frame ();
let tmp = create_felem () in
from_qmont tmp b;
let h1 = ST.get () in
assert (as_nat h1 tmp == SM.from_qmont (as_nat h0 b));
qmul res sinv tmp;
let h2 = ST.get () in
assert (as_nat h2 res = (as_nat h1 sinv * as_nat h1 tmp * SM.qmont_R_inv) % S.order);
pop_frame ()
inline_for_extraction noextract
val ecdsa_verification_get_u12: u1:felem -> u2:felem -> r:felem -> s:felem -> z:felem -> Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
as_nat h s < S.order /\ as_nat h z < S.order /\ as_nat h r < S.order)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (as_nat h0 s) in
as_nat h1 u1 == sinv * as_nat h0 z % S.order /\
as_nat h1 u2 == sinv * as_nat h0 r % S.order)) | false | false | Hacl.Impl.P256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ecdsa_verification_get_u12: u1:felem -> u2:felem -> r:felem -> s:felem -> z:felem -> Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
as_nat h s < S.order /\ as_nat h z < S.order /\ as_nat h r < S.order)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (as_nat h0 s) in
as_nat h1 u1 == sinv * as_nat h0 z % S.order /\
as_nat h1 u2 == sinv * as_nat h0 r % S.order)) | [] | Hacl.Impl.P256.Verify.ecdsa_verification_get_u12 | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
u1: Hacl.Impl.P256.Bignum.felem ->
u2: Hacl.Impl.P256.Bignum.felem ->
r: Hacl.Impl.P256.Bignum.felem ->
s: Hacl.Impl.P256.Bignum.felem ->
z: Hacl.Impl.P256.Bignum.felem
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 14,
"end_line": 77,
"start_col": 2,
"start_line": 64
} |
FStar.HyperStack.ST.Stack | val ecdsa_verify_msg_as_qelem:
m_q:felem
-> public_key:lbuffer uint8 64ul
-> signature_r:lbuffer uint8 32ul
-> signature_s:lbuffer uint8 32ul ->
Stack bool
(requires fun h ->
live h public_key /\ live h signature_r /\ live h signature_s /\ live h m_q /\
as_nat h m_q < S.order)
(ensures fun h0 result h1 -> modifies0 h0 h1 /\
result == S.ecdsa_verify_msg_as_qelem (as_nat h0 m_q)
(as_seq h0 public_key) (as_seq h0 signature_r) (as_seq h0 signature_s)) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.P256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s =
push_frame ();
let tmp = create 28ul (u64 0) in
let pk = sub tmp 0ul 12ul in
let r_q = sub tmp 12ul 4ul in
let s_q = sub tmp 16ul 4ul in
let u1 = sub tmp 20ul 4ul in
let u2 = sub tmp 24ul 4ul in
let is_pk_valid = load_point_vartime pk public_key in
let is_rs_valid = load_signature r_q s_q signature_r signature_s in
let res =
if not (is_pk_valid && is_rs_valid) then false
else begin
ecdsa_verification_get_u12 u1 u2 r_q s_q m_q;
ecdsa_verification_cmpr r_q pk u1 u2 end in
pop_frame ();
res | val ecdsa_verify_msg_as_qelem:
m_q:felem
-> public_key:lbuffer uint8 64ul
-> signature_r:lbuffer uint8 32ul
-> signature_s:lbuffer uint8 32ul ->
Stack bool
(requires fun h ->
live h public_key /\ live h signature_r /\ live h signature_s /\ live h m_q /\
as_nat h m_q < S.order)
(ensures fun h0 result h1 -> modifies0 h0 h1 /\
result == S.ecdsa_verify_msg_as_qelem (as_nat h0 m_q)
(as_seq h0 public_key) (as_seq h0 signature_r) (as_seq h0 signature_s))
let ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s = | true | null | false | push_frame ();
let tmp = create 28ul (u64 0) in
let pk = sub tmp 0ul 12ul in
let r_q = sub tmp 12ul 4ul in
let s_q = sub tmp 16ul 4ul in
let u1 = sub tmp 20ul 4ul in
let u2 = sub tmp 24ul 4ul in
let is_pk_valid = load_point_vartime pk public_key in
let is_rs_valid = load_signature r_q s_q signature_r signature_s in
let res =
if not (is_pk_valid && is_rs_valid)
then false
else
(ecdsa_verification_get_u12 u1 u2 r_q s_q m_q;
ecdsa_verification_cmpr r_q pk u1 u2)
in
pop_frame ();
res | {
"checked_file": "Hacl.Impl.P256.Verify.fst.checked",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.P256.Montgomery.fsti.checked",
"Hacl.Impl.P256.Scalar.fsti.checked",
"Hacl.Impl.P256.Qinv.fsti.checked",
"Hacl.Impl.P256.PointMul.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Bignum.fsti.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.P256.Verify.fst"
} | [] | [
"Hacl.Impl.P256.Bignum.felem",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Prims.op_Negation",
"Prims.op_AmpAmp",
"Hacl.Impl.P256.Verify.ecdsa_verification_cmpr",
"Hacl.Impl.P256.Verify.ecdsa_verification_get_u12",
"Hacl.Impl.P256.Verify.load_signature",
"Hacl.Impl.P256.Point.load_point_vartime",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"Lib.IntTypes.uint64",
"Lib.Buffer.create",
"Lib.IntTypes.u64",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.P256.Verify
open FStar.Mul
open FStar.HyperStack.All
open FStar.HyperStack
module ST = FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.P256.Bignum
open Hacl.Impl.P256.Point
open Hacl.Impl.P256.Scalar
open Hacl.Impl.P256.PointMul
module BSeq = Lib.ByteSequence
module S = Spec.P256
module SL = Spec.P256.Lemmas
module SM = Hacl.Spec.P256.Montgomery
module QI = Hacl.Impl.P256.Qinv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
val qmul_mont: sinv:felem -> b:felem -> res:felem -> Stack unit
(requires fun h ->
live h sinv /\ live h b /\ live h res /\
disjoint sinv res /\ disjoint b res /\
as_nat h sinv < S.order /\ as_nat h b < S.order)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_nat h1 res < S.order /\
as_nat h1 res = (as_nat h0 sinv * SM.from_qmont (as_nat h0 b) * SM.qmont_R_inv) % S.order)
[@CInline]
let qmul_mont sinv b res =
let h0 = ST.get () in
push_frame ();
let tmp = create_felem () in
from_qmont tmp b;
let h1 = ST.get () in
assert (as_nat h1 tmp == SM.from_qmont (as_nat h0 b));
qmul res sinv tmp;
let h2 = ST.get () in
assert (as_nat h2 res = (as_nat h1 sinv * as_nat h1 tmp * SM.qmont_R_inv) % S.order);
pop_frame ()
inline_for_extraction noextract
val ecdsa_verification_get_u12: u1:felem -> u2:felem -> r:felem -> s:felem -> z:felem -> Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
as_nat h s < S.order /\ as_nat h z < S.order /\ as_nat h r < S.order)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (as_nat h0 s) in
as_nat h1 u1 == sinv * as_nat h0 z % S.order /\
as_nat h1 u2 == sinv * as_nat h0 r % S.order))
let ecdsa_verification_get_u12 u1 u2 r s z =
push_frame ();
let h0 = ST.get () in
let sinv = create_felem () in
QI.qinv sinv s;
let h1 = ST.get () in
assert (qmont_as_nat h1 sinv == S.qinv (qmont_as_nat h0 s));
//assert (as_nat h2 sinv * SM.qmont_R_inv % S.order ==
//S.qinv (as_nat h1 sinv * SM.qmont_R_inv % S.order));
SM.qmont_inv_mul_lemma (as_nat h0 s) (as_nat h1 sinv) (as_nat h0 z);
SM.qmont_inv_mul_lemma (as_nat h0 s) (as_nat h1 sinv) (as_nat h0 r);
qmul_mont sinv z u1;
qmul_mont sinv r u2;
pop_frame ()
inline_for_extraction noextract
val ecdsa_verify_finv: p:point -> r:felem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ 0 < as_nat h r /\ as_nat h r < S.order)
//not (S.is_point_at_inf (from_mont_point (as_point_nat h p))))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = from_mont_point (as_point_nat h0 p) in
b <==> (S.fmul _X (S.finv _Z) % S.order = as_nat h0 r)))
let ecdsa_verify_finv p r_q =
push_frame ();
let x = create_felem () in
to_aff_point_x x p;
qmod_short x x;
let res = bn_is_eq_vartime4 x r_q in
pop_frame ();
res
inline_for_extraction noextract
val ecdsa_verification_cmpr: r:felem -> pk:point -> u1:felem -> u2:felem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ as_nat h u1 < S.order /\ as_nat h u2 < S.order /\
0 < as_nat h r /\ as_nat h r < S.order)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (as_nat h0 u1) (as_nat h0 u2)
(from_mont_point (as_point_nat h0 pk)) in
b <==> (if S.is_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.order = as_nat h0 r)))
let ecdsa_verification_cmpr r pk u1 u2 =
push_frame ();
let res = create_point () in
let h0 = ST.get () in
point_mul_double_g res u1 u2 pk;
let h1 = ST.get () in
assert (S.to_aff_point (from_mont_point (as_point_nat h1 res)) ==
S.to_aff_point (S.point_mul_double_g (as_nat h0 u1) (as_nat h0 u2)
(from_mont_point (as_point_nat h0 pk))));
SL.lemma_aff_is_point_at_inf (from_mont_point (as_point_nat h1 res));
SL.lemma_aff_is_point_at_inf
(S.point_mul_double_g (as_nat h0 u1) (as_nat h0 u2) (from_mont_point (as_point_nat h0 pk)));
let b =
if is_point_at_inf_vartime res then false
else ecdsa_verify_finv res r in
pop_frame ();
b
inline_for_extraction noextract
val load_signature (r_q s_q:felem) (sign_r sign_s:lbytes 32ul) : Stack bool
(requires fun h ->
live h sign_r /\ live h sign_s /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q sign_r /\ disjoint r_q sign_s /\
disjoint s_q sign_r /\ disjoint s_q sign_s)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
as_nat h1 r_q = r_q_nat /\ as_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.order && 0 < s_q_nat && s_q_nat < S.order)))
let load_signature r_q s_q sign_r sign_s =
bn_from_bytes_be4 r_q sign_r;
bn_from_bytes_be4 s_q sign_s;
let is_r_valid = bn_is_lt_order_and_gt_zero_mask4 r_q in
let is_s_valid = bn_is_lt_order_and_gt_zero_mask4 s_q in
Hacl.Bignum.Base.unsafe_bool_of_limb is_r_valid &&
Hacl.Bignum.Base.unsafe_bool_of_limb is_s_valid
val ecdsa_verify_msg_as_qelem:
m_q:felem
-> public_key:lbuffer uint8 64ul
-> signature_r:lbuffer uint8 32ul
-> signature_s:lbuffer uint8 32ul ->
Stack bool
(requires fun h ->
live h public_key /\ live h signature_r /\ live h signature_s /\ live h m_q /\
as_nat h m_q < S.order)
(ensures fun h0 result h1 -> modifies0 h0 h1 /\
result == S.ecdsa_verify_msg_as_qelem (as_nat h0 m_q)
(as_seq h0 public_key) (as_seq h0 signature_r) (as_seq h0 signature_s))
[@CInline] | false | false | Hacl.Impl.P256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ecdsa_verify_msg_as_qelem:
m_q:felem
-> public_key:lbuffer uint8 64ul
-> signature_r:lbuffer uint8 32ul
-> signature_s:lbuffer uint8 32ul ->
Stack bool
(requires fun h ->
live h public_key /\ live h signature_r /\ live h signature_s /\ live h m_q /\
as_nat h m_q < S.order)
(ensures fun h0 result h1 -> modifies0 h0 h1 /\
result == S.ecdsa_verify_msg_as_qelem (as_nat h0 m_q)
(as_seq h0 public_key) (as_seq h0 signature_r) (as_seq h0 signature_s)) | [] | Hacl.Impl.P256.Verify.ecdsa_verify_msg_as_qelem | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
m_q: Hacl.Impl.P256.Bignum.felem ->
public_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul ->
signature_r: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
signature_s: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 5,
"end_line": 188,
"start_col": 2,
"start_line": 171
} |
FStar.HyperStack.ST.Stack | val ecdsa_verification_cmpr: r:felem -> pk:point -> u1:felem -> u2:felem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ as_nat h u1 < S.order /\ as_nat h u2 < S.order /\
0 < as_nat h r /\ as_nat h r < S.order)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (as_nat h0 u1) (as_nat h0 u2)
(from_mont_point (as_point_nat h0 pk)) in
b <==> (if S.is_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.order = as_nat h0 r))) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.P256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ecdsa_verification_cmpr r pk u1 u2 =
push_frame ();
let res = create_point () in
let h0 = ST.get () in
point_mul_double_g res u1 u2 pk;
let h1 = ST.get () in
assert (S.to_aff_point (from_mont_point (as_point_nat h1 res)) ==
S.to_aff_point (S.point_mul_double_g (as_nat h0 u1) (as_nat h0 u2)
(from_mont_point (as_point_nat h0 pk))));
SL.lemma_aff_is_point_at_inf (from_mont_point (as_point_nat h1 res));
SL.lemma_aff_is_point_at_inf
(S.point_mul_double_g (as_nat h0 u1) (as_nat h0 u2) (from_mont_point (as_point_nat h0 pk)));
let b =
if is_point_at_inf_vartime res then false
else ecdsa_verify_finv res r in
pop_frame ();
b | val ecdsa_verification_cmpr: r:felem -> pk:point -> u1:felem -> u2:felem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ as_nat h u1 < S.order /\ as_nat h u2 < S.order /\
0 < as_nat h r /\ as_nat h r < S.order)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (as_nat h0 u1) (as_nat h0 u2)
(from_mont_point (as_point_nat h0 pk)) in
b <==> (if S.is_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.order = as_nat h0 r)))
let ecdsa_verification_cmpr r pk u1 u2 = | true | null | false | push_frame ();
let res = create_point () in
let h0 = ST.get () in
point_mul_double_g res u1 u2 pk;
let h1 = ST.get () in
assert (S.to_aff_point (from_mont_point (as_point_nat h1 res)) ==
S.to_aff_point (S.point_mul_double_g (as_nat h0 u1)
(as_nat h0 u2)
(from_mont_point (as_point_nat h0 pk))));
SL.lemma_aff_is_point_at_inf (from_mont_point (as_point_nat h1 res));
SL.lemma_aff_is_point_at_inf (S.point_mul_double_g (as_nat h0 u1)
(as_nat h0 u2)
(from_mont_point (as_point_nat h0 pk)));
let b = if is_point_at_inf_vartime res then false else ecdsa_verify_finv res r in
pop_frame ();
b | {
"checked_file": "Hacl.Impl.P256.Verify.fst.checked",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.P256.Montgomery.fsti.checked",
"Hacl.Impl.P256.Scalar.fsti.checked",
"Hacl.Impl.P256.Qinv.fsti.checked",
"Hacl.Impl.P256.PointMul.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Bignum.fsti.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.P256.Verify.fst"
} | [] | [
"Hacl.Impl.P256.Bignum.felem",
"Hacl.Impl.P256.Point.point",
"Prims.bool",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Hacl.Impl.P256.Verify.ecdsa_verify_finv",
"Hacl.Impl.P256.Point.is_point_at_inf_vartime",
"Spec.P256.Lemmas.lemma_aff_is_point_at_inf",
"Spec.P256.point_mul_double_g",
"Hacl.Impl.P256.Bignum.as_nat",
"Hacl.Impl.P256.Point.from_mont_point",
"Hacl.Impl.P256.Point.as_point_nat",
"Prims._assert",
"Prims.eq2",
"Spec.P256.PointOps.aff_point",
"Spec.P256.PointOps.to_aff_point",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.P256.PointMul.point_mul_double_g",
"Hacl.Impl.P256.Point.create_point",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.P256.Verify
open FStar.Mul
open FStar.HyperStack.All
open FStar.HyperStack
module ST = FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.P256.Bignum
open Hacl.Impl.P256.Point
open Hacl.Impl.P256.Scalar
open Hacl.Impl.P256.PointMul
module BSeq = Lib.ByteSequence
module S = Spec.P256
module SL = Spec.P256.Lemmas
module SM = Hacl.Spec.P256.Montgomery
module QI = Hacl.Impl.P256.Qinv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
val qmul_mont: sinv:felem -> b:felem -> res:felem -> Stack unit
(requires fun h ->
live h sinv /\ live h b /\ live h res /\
disjoint sinv res /\ disjoint b res /\
as_nat h sinv < S.order /\ as_nat h b < S.order)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_nat h1 res < S.order /\
as_nat h1 res = (as_nat h0 sinv * SM.from_qmont (as_nat h0 b) * SM.qmont_R_inv) % S.order)
[@CInline]
let qmul_mont sinv b res =
let h0 = ST.get () in
push_frame ();
let tmp = create_felem () in
from_qmont tmp b;
let h1 = ST.get () in
assert (as_nat h1 tmp == SM.from_qmont (as_nat h0 b));
qmul res sinv tmp;
let h2 = ST.get () in
assert (as_nat h2 res = (as_nat h1 sinv * as_nat h1 tmp * SM.qmont_R_inv) % S.order);
pop_frame ()
inline_for_extraction noextract
val ecdsa_verification_get_u12: u1:felem -> u2:felem -> r:felem -> s:felem -> z:felem -> Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
as_nat h s < S.order /\ as_nat h z < S.order /\ as_nat h r < S.order)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (as_nat h0 s) in
as_nat h1 u1 == sinv * as_nat h0 z % S.order /\
as_nat h1 u2 == sinv * as_nat h0 r % S.order))
let ecdsa_verification_get_u12 u1 u2 r s z =
push_frame ();
let h0 = ST.get () in
let sinv = create_felem () in
QI.qinv sinv s;
let h1 = ST.get () in
assert (qmont_as_nat h1 sinv == S.qinv (qmont_as_nat h0 s));
//assert (as_nat h2 sinv * SM.qmont_R_inv % S.order ==
//S.qinv (as_nat h1 sinv * SM.qmont_R_inv % S.order));
SM.qmont_inv_mul_lemma (as_nat h0 s) (as_nat h1 sinv) (as_nat h0 z);
SM.qmont_inv_mul_lemma (as_nat h0 s) (as_nat h1 sinv) (as_nat h0 r);
qmul_mont sinv z u1;
qmul_mont sinv r u2;
pop_frame ()
inline_for_extraction noextract
val ecdsa_verify_finv: p:point -> r:felem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ 0 < as_nat h r /\ as_nat h r < S.order)
//not (S.is_point_at_inf (from_mont_point (as_point_nat h p))))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = from_mont_point (as_point_nat h0 p) in
b <==> (S.fmul _X (S.finv _Z) % S.order = as_nat h0 r)))
let ecdsa_verify_finv p r_q =
push_frame ();
let x = create_felem () in
to_aff_point_x x p;
qmod_short x x;
let res = bn_is_eq_vartime4 x r_q in
pop_frame ();
res
inline_for_extraction noextract
val ecdsa_verification_cmpr: r:felem -> pk:point -> u1:felem -> u2:felem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ as_nat h u1 < S.order /\ as_nat h u2 < S.order /\
0 < as_nat h r /\ as_nat h r < S.order)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (as_nat h0 u1) (as_nat h0 u2)
(from_mont_point (as_point_nat h0 pk)) in
b <==> (if S.is_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.order = as_nat h0 r))) | false | false | Hacl.Impl.P256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ecdsa_verification_cmpr: r:felem -> pk:point -> u1:felem -> u2:felem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ as_nat h u1 < S.order /\ as_nat h u2 < S.order /\
0 < as_nat h r /\ as_nat h r < S.order)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (as_nat h0 u1) (as_nat h0 u2)
(from_mont_point (as_point_nat h0 pk)) in
b <==> (if S.is_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.order = as_nat h0 r))) | [] | Hacl.Impl.P256.Verify.ecdsa_verification_cmpr | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
r: Hacl.Impl.P256.Bignum.felem ->
pk: Hacl.Impl.P256.Point.point ->
u1: Hacl.Impl.P256.Bignum.felem ->
u2: Hacl.Impl.P256.Bignum.felem
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 3,
"end_line": 132,
"start_col": 2,
"start_line": 115
} |
Prims.Tot | val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM | val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM = | false | null | false | mont_reduction pbits rLen n mu aM | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.nat",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat | false | true | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat | [] | Hacl.Spec.Montgomery.Lemmas.from_mont | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.nat -> n: Prims.pos -> mu: Prims.nat -> aM: Prims.nat -> Prims.nat | {
"end_col": 35,
"end_line": 225,
"start_col": 2,
"start_line": 225
} |
Prims.Tot | val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a | val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a = | false | null | false | mont_mul pbits rLen n mu a a | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.nat",
"Hacl.Spec.Montgomery.Lemmas.mont_mul"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat | false | true | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat | [] | Hacl.Spec.Montgomery.Lemmas.mont_sqr | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.nat -> n: Prims.pos -> mu: Prims.nat -> a: Prims.nat -> Prims.nat | {
"end_col": 30,
"end_line": 234,
"start_col": 2,
"start_line": 234
} |
Prims.Tot | val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c | val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b = | false | null | false | let c = a * b in
mont_reduction pbits rLen n mu c | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.nat",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction",
"Prims.int",
"FStar.Mul.op_Star"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM | false | true | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat | [] | Hacl.Spec.Montgomery.Lemmas.mont_mul | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.nat -> n: Prims.pos -> mu: Prims.nat -> a: Prims.nat -> b: Prims.nat
-> Prims.nat | {
"end_col": 34,
"end_line": 230,
"start_col": 34,
"start_line": 228
} |
Prims.Tot | val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n | val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c = | false | null | false | let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.nat",
"Prims.op_LessThan",
"Prims.bool",
"Prims.op_Subtraction",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_div_r"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res | false | true | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.nat -> n: Prims.pos -> mu: Prims.nat -> c: Prims.nat -> Prims.nat | {
"end_col": 34,
"end_line": 215,
"start_col": 38,
"start_line": 213
} |
Prims.Tot | val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2 | val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu = | false | null | false | let r2 = pow2 ((2 * pbits) * rLen) % n in
mont_reduction pbits rLen n mu r2 | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.nat",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction",
"Prims.int",
"Prims.op_Modulus",
"Prims.pow2",
"FStar.Mul.op_Star"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a | false | true | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat | [] | Hacl.Spec.Montgomery.Lemmas.mont_one | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.nat -> n: Prims.pos -> mu: Prims.nat -> Prims.nat | {
"end_col": 35,
"end_line": 239,
"start_col": 30,
"start_line": 237
} |
Prims.Tot | val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c | val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a = | false | null | false | let r2 = pow2 ((2 * pbits) * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.nat",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.op_Modulus",
"Prims.pow2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n | false | true | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat | [] | Hacl.Spec.Montgomery.Lemmas.to_mont | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.nat -> n: Prims.pos -> mu: Prims.nat -> a: Prims.nat -> Prims.nat | {
"end_col": 34,
"end_line": 221,
"start_col": 31,
"start_line": 218
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1 | let mont_pre (pbits rLen n: pos) (mu: nat) = | false | null | false | (1 + n * mu) % pow2 pbits == 0 /\ 1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1 | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.nat",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.logical"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n) | false | true | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_pre : pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos -> mu: Prims.nat -> Prims.logical | [] | Hacl.Spec.Montgomery.Lemmas.mont_pre | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos -> mu: Prims.nat -> Prims.logical | {
"end_col": 47,
"end_line": 456,
"start_col": 2,
"start_line": 455
} |
|
Prims.Tot | val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res | val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c = | false | null | false | let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + (n * q_i) * pow2 (pbits * i) in
res | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.int",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Modulus",
"Prims.op_Division"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_f | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
pbits: Prims.pos ->
rLen: Prims.nat ->
n: Prims.pos ->
mu: Prims.nat ->
i: Prims.nat{i < rLen} ->
c: Prims.nat
-> Prims.nat | {
"end_col": 5,
"end_line": 204,
"start_col": 42,
"start_line": 200
} |
Prims.Tot | val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res | val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c = | false | null | false | let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.nat",
"Prims.int",
"Prims.op_Division",
"Prims.pow2",
"FStar.Mul.op_Star",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.LoopCombinators.repeati",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_f"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res | false | true | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_div_r | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.nat -> n: Prims.pos -> mu: Prims.nat -> c: Prims.nat -> Prims.nat | {
"end_col": 5,
"end_line": 210,
"start_col": 49,
"start_line": 207
} |
FStar.Pervasives.Lemma | val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n) | val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 = | false | null | true | let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + (n * q_i) * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims._assert",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.unit",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step_bound_aux",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_Division",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_f"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n) | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step_bound | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
pbits: Prims.pos ->
rLen: Prims.nat ->
n: Prims.pos ->
mu: Prims.nat ->
i: Prims.pos{i <= rLen} ->
c: Prims.nat ->
res0: Prims.nat
-> FStar.Pervasives.Lemma (requires res0 <= c + (Prims.pow2 (pbits * (i - 1)) - 1) * n)
(ensures
Hacl.Spec.Montgomery.Lemmas.mont_reduction_f pbits rLen n mu (i - 1) res0 <=
c + (Prims.pow2 (pbits * i) - 1) * n) | {
"end_col": 48,
"end_line": 287,
"start_col": 62,
"start_line": 281
} |
Prims.Pure | val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k) | val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n = | false | null | false | let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == (n * k / pow2 a) * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [] | [
"Prims.pos",
"FStar.Pervasives.Native.Mktuple2",
"Prims.int",
"Prims.op_Minus",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Prims.pow2",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Math.Lemmas.cancel_mul_div",
"FStar.Math.Lemmas.lemma_mult_lt_left",
"Prims.op_Division",
"Prims.op_Modulus",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd_k",
"FStar.Pervasives.Native.tuple2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n) | [] | Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Prims.pos -> n: Prims.pos -> Prims.Pure (Prims.int * Prims.int) | {
"end_col": 12,
"end_line": 144,
"start_col": 22,
"start_line": 134
} |
FStar.Pervasives.Lemma | val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1))) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end | val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 = | false | null | true | let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0
then
(Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
()) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Subtraction",
"FStar.Math.Lemmas.small_division_lemma_2",
"Prims.bool",
"Prims.eq2",
"Prims.op_Division",
"FStar.Math.Lemmas.pow2_modulo_division_lemma_1"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1))) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1))) | [] | Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd_k_lemma_d | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Prims.pos -> n: Prims.pos -> k1: Prims.pos
-> FStar.Pervasives.Lemma (requires n * k1 % Prims.pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures
(let d = n * k1 / Prims.pow2 (a - 1) in
d % 2 ==
(match n * k1 % Prims.pow2 a < Prims.pow2 (a - 1) with
| true -> 0
| _ -> 1))) | {
"end_col": 10,
"end_line": 28,
"start_col": 35,
"start_line": 21
} |
FStar.Pervasives.Lemma | val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1))) | val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 = | false | null | true | let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + (n * q_i) * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1))) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Math.Lemmas.modulo_addition_lemma",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Math.Lemmas.paren_mul_right",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Prims.op_Modulus",
"Prims.op_Division",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_f"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n) | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step_modn | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
pbits: Prims.pos ->
rLen: Prims.nat ->
n: Prims.pos ->
mu: Prims.nat ->
i: Prims.pos{i <= rLen} ->
c: Prims.nat ->
res0: Prims.nat
-> FStar.Pervasives.Lemma (requires res0 % n == c % n)
(ensures
Hacl.Spec.Montgomery.Lemmas.mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n) | {
"end_col": 73,
"end_line": 365,
"start_col": 61,
"start_line": 359
} |
FStar.Pervasives.Lemma | val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu | val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu = | false | null | true | mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.nat",
"Hacl.Spec.Montgomery.Lemmas.mont_preconditions_n0",
"Prims.unit",
"Hacl.Spec.Montgomery.Lemmas.mont_preconditions_d"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0)) | [] | Hacl.Spec.Montgomery.Lemmas.mont_preconditions | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos{1 < n} -> mu: Prims.nat
-> FStar.Pervasives.Lemma
(requires n % 2 = 1 /\ (1 + (n % Prims.pow2 pbits) * mu) % Prims.pow2 pbits == 0)
(ensures
(let r = Prims.pow2 (pbits * rLen) in
let _ = Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd (pbits * rLen) n in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ d _ = _ in
r * d % n == 1 /\ (1 + n * mu) % Prims.pow2 pbits == 0)
<:
Type0)) | {
"end_col": 34,
"end_line": 194,
"start_col": 2,
"start_line": 193
} |
FStar.Pervasives.Lemma | val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r | val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n = | false | null | true | assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.nat",
"Prims.pos",
"FStar.Math.Lemmas.lemma_div_le",
"Prims.op_Subtraction",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"FStar.Math.Lemmas.cancel_mul_div",
"FStar.Mul.op_Star"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n) | [] | Hacl.Spec.Montgomery.Lemmas.lemma_fits_c_lt_rn | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | c: Prims.nat -> r: Prims.pos -> n: Prims.pos
-> FStar.Pervasives.Lemma (requires c < r * n) (ensures (c - n) / r < n) | {
"end_col": 38,
"end_line": 482,
"start_col": 2,
"start_line": 479
} |
FStar.Pervasives.Lemma | val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1) | val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 = | false | null | true | if n * k1 % pow2 a < pow2 (a - 1)
then Math.Lemmas.pow2_lt_compat a (a - 1)
else Math.Lemmas.pow2_double_sum (a - 1) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.op_LessThan",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Subtraction",
"FStar.Math.Lemmas.pow2_lt_compat",
"Prims.bool",
"FStar.Math.Lemmas.pow2_double_sum",
"Prims.unit"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a)) | [] | Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd_k_lemma_bound | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Prims.pos -> n: Prims.pos -> k1: Prims.pos
-> FStar.Pervasives.Lemma
(requires n * k1 % Prims.pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < Prims.pow2 (a - 1))
(ensures
(let k =
(match n * k1 % Prims.pow2 a < Prims.pow2 (a - 1) with
| true -> k1
| _ -> k1 + Prims.pow2 (a - 1))
<:
Prims.int
in
k < Prims.pow2 a)) | {
"end_col": 39,
"end_line": 107,
"start_col": 2,
"start_line": 104
} |
Prims.Pure | val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end | val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n = | false | null | false | if a = 1
then 1
else
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [] | [
"Prims.pos",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.pow2",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd_k_lemma_bound",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd_k_lemma",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"Prims.op_Addition",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd_k"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a) | [
"recursion"
] | Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd_k | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Prims.pos -> n: Prims.pos -> Prims.Pure Prims.pos | {
"end_col": 9,
"end_line": 125,
"start_col": 2,
"start_line": 117
} |
FStar.Pervasives.Lemma | val mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures mont_one pbits rLen n mu == 1 * pow2 (pbits * rLen) % n) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_one_lemma pbits rLen n mu =
to_mont_lemma pbits rLen n mu 1 | val mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures mont_one pbits rLen n mu == 1 * pow2 (pbits * rLen) % n)
let mont_one_lemma pbits rLen n mu = | false | null | true | to_mont_lemma pbits rLen n mu 1 | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Hacl.Spec.Montgomery.Lemmas.to_mont_lemma",
"Prims.unit"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b)
/// Lemma (to_mont rLen n mu a == a * r % n)
val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n)
let lemma_mod_mul_distr3 a b c n =
calc (==) {
a * (b % n) * c % n;
(==) { }
(b % n) * a * c % n;
(==) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
(==) { Math.Lemmas.paren_mul_right b a c }
a * b * c % n;
}
val mult_lt_lemma: a:nat -> b:nat -> c:nat -> d:nat -> Lemma
(requires a < c /\ b < d)
(ensures a * b < c * d)
let mult_lt_lemma a b c d = ()
val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n))
let to_mont_eval_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let c = a * r2 in
calc (==) {
c * d % n;
(==) { }
a * r2 * d % n;
(==) { Math.Lemmas.paren_mul_right 2 pbits rLen;
Math.Lemmas.pow2_plus (pbits * rLen) (pbits * rLen) }
a * (r * r % n) * d % n;
(==) { lemma_mod_mul_distr3 a (r * r) d n }
a * (r * r) * d % n;
(==) { Math.Lemmas.paren_mul_right a r r }
a * r * r * d % n;
(==) { Math.Lemmas.paren_mul_right (a * r) r d }
a * r * (r * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (a * r) (r * d) n }
a * r * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a * r % n;
};
assert (c * d % n == a * r % n)
val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n)
let to_mont_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let c = a * r2 in
let aM = to_mont pbits rLen n mu a in
assert (aM == mont_reduction pbits rLen n mu c);
mult_lt_lemma a r2 r n;
assert (a * r2 < r * n);
mont_reduction_lemma pbits rLen n mu c;
assert (aM == c * d % n);
to_mont_eval_lemma pbits rLen n mu a;
assert (aM == a * r % n)
/// Lemma (from_mont rLen n mu aM == aM * d % n)
val from_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ aM < pow2 (pbits * rLen))
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
from_mont pbits rLen n mu aM == aM * d % n))
let from_mont_lemma pbits rLen n mu aM =
mont_reduction_lemma pbits rLen n mu aM
/// Lemma (mont_one pbits rLen n mu == 1 * r % n)
val mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures mont_one pbits rLen n mu == 1 * pow2 (pbits * rLen) % n) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures mont_one pbits rLen n mu == 1 * pow2 (pbits * rLen) % n) | [] | Hacl.Spec.Montgomery.Lemmas.mont_one_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos -> mu: Prims.nat
-> FStar.Pervasives.Lemma (requires Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu)
(ensures
Hacl.Spec.Montgomery.Lemmas.mont_one pbits rLen n mu == 1 * Prims.pow2 (pbits * rLen) % n) | {
"end_col": 33,
"end_line": 618,
"start_col": 2,
"start_line": 618
} |
FStar.Pervasives.Lemma | val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n | val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c = | false | null | true | let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n
then ()
else
(assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n);
Math.Lemmas.small_mod res1 n | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.int",
"FStar.Math.Lemmas.small_mod",
"Prims.unit",
"Prims.op_LessThan",
"Prims.bool",
"Hacl.Spec.Montgomery.Lemmas.lemma_fits_c_lt_rn",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Division",
"Prims.op_Subtraction",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Math.Lemmas.lemma_mod_sub",
"Prims.op_GreaterThanOrEqual",
"Prims.l_and",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_div_r_lemma",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_div_r",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd",
"Prims.pow2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n)) | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos -> mu: Prims.nat -> c: Prims.nat
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu /\ c < Prims.pow2 (pbits * rLen) * n)
(ensures
(let _ = Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd (pbits * rLen) n in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ d _ = _ in
Hacl.Spec.Montgomery.Lemmas.mont_reduction pbits rLen n mu c == c * d % n)
<:
Type0)) | {
"end_col": 30,
"end_line": 506,
"start_col": 44,
"start_line": 491
} |
FStar.Pervasives.Lemma | val from_mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires
mont_pre pbits rLen n mu)
(ensures
(let oneM = mont_one pbits rLen n mu in
let one = from_mont pbits rLen n mu oneM in
one == 1)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let from_mont_one_lemma pbits rLen n mu =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let oneM = mont_one pbits rLen n mu in
mont_one_lemma pbits rLen n mu;
assert (oneM == r % n);
let one = from_mont pbits rLen n mu oneM in
from_mont_lemma pbits rLen n mu oneM;
assert (one == oneM * d % n);
assert (one == (r % n) * d % n);
lemma_mont_id n r d 1;
assert (one == 1 % n);
Math.Lemmas.small_mod 1 n | val from_mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires
mont_pre pbits rLen n mu)
(ensures
(let oneM = mont_one pbits rLen n mu in
let one = from_mont pbits rLen n mu oneM in
one == 1))
let from_mont_one_lemma pbits rLen n mu = | false | null | true | let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let oneM = mont_one pbits rLen n mu in
mont_one_lemma pbits rLen n mu;
assert (oneM == r % n);
let one = from_mont pbits rLen n mu oneM in
from_mont_lemma pbits rLen n mu oneM;
assert (one == oneM * d % n);
assert (one == (r % n) * d % n);
lemma_mont_id n r d 1;
assert (one == 1 % n);
Math.Lemmas.small_mod 1 n | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.int",
"FStar.Math.Lemmas.small_mod",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.op_Modulus",
"Hacl.Spec.Montgomery.Lemmas.lemma_mont_id",
"FStar.Mul.op_Star",
"Hacl.Spec.Montgomery.Lemmas.from_mont_lemma",
"Hacl.Spec.Montgomery.Lemmas.from_mont",
"Hacl.Spec.Montgomery.Lemmas.mont_one_lemma",
"Hacl.Spec.Montgomery.Lemmas.mont_one",
"Hacl.Spec.Montgomery.Lemmas.mont_preconditions_d",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd",
"Prims.pow2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b)
/// Lemma (to_mont rLen n mu a == a * r % n)
val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n)
let lemma_mod_mul_distr3 a b c n =
calc (==) {
a * (b % n) * c % n;
(==) { }
(b % n) * a * c % n;
(==) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
(==) { Math.Lemmas.paren_mul_right b a c }
a * b * c % n;
}
val mult_lt_lemma: a:nat -> b:nat -> c:nat -> d:nat -> Lemma
(requires a < c /\ b < d)
(ensures a * b < c * d)
let mult_lt_lemma a b c d = ()
val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n))
let to_mont_eval_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let c = a * r2 in
calc (==) {
c * d % n;
(==) { }
a * r2 * d % n;
(==) { Math.Lemmas.paren_mul_right 2 pbits rLen;
Math.Lemmas.pow2_plus (pbits * rLen) (pbits * rLen) }
a * (r * r % n) * d % n;
(==) { lemma_mod_mul_distr3 a (r * r) d n }
a * (r * r) * d % n;
(==) { Math.Lemmas.paren_mul_right a r r }
a * r * r * d % n;
(==) { Math.Lemmas.paren_mul_right (a * r) r d }
a * r * (r * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (a * r) (r * d) n }
a * r * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a * r % n;
};
assert (c * d % n == a * r % n)
val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n)
let to_mont_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let c = a * r2 in
let aM = to_mont pbits rLen n mu a in
assert (aM == mont_reduction pbits rLen n mu c);
mult_lt_lemma a r2 r n;
assert (a * r2 < r * n);
mont_reduction_lemma pbits rLen n mu c;
assert (aM == c * d % n);
to_mont_eval_lemma pbits rLen n mu a;
assert (aM == a * r % n)
/// Lemma (from_mont rLen n mu aM == aM * d % n)
val from_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ aM < pow2 (pbits * rLen))
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
from_mont pbits rLen n mu aM == aM * d % n))
let from_mont_lemma pbits rLen n mu aM =
mont_reduction_lemma pbits rLen n mu aM
/// Lemma (mont_one pbits rLen n mu == 1 * r % n)
val mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures mont_one pbits rLen n mu == 1 * pow2 (pbits * rLen) % n)
let mont_one_lemma pbits rLen n mu =
to_mont_lemma pbits rLen n mu 1
/// Properties of Montgomery arithmetic
// from_mont (to_mont a) = a % n
val lemma_mont_id: n:pos -> r:pos -> d:int{r * d % n == 1} -> a:nat ->
Lemma (a * r % n * d % n == a % n)
let lemma_mont_id n r d a =
calc (==) {
a * r % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * r) d n }
a * r * d % n;
(==) { Math.Lemmas.paren_mul_right a r d; Math.Lemmas.lemma_mod_mul_distr_r a (r * d) n }
a * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a % n;
}
// to_mont (mont_reduction a) = a % n
val lemma_mont_id1: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (a * d % n * r % n == a % n)
let lemma_mont_id1 n r d a =
calc (==) {
((a * d % n) * r) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * d) r n }
((a * d) * r) % n;
(==) { Math.Lemmas.paren_mul_right a d r }
(a * (d * r)) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (d * r) n }
(a * (d * r % n)) % n;
(==) { assert (r * d % n = 1) }
a % n;
};
assert (a * d % n * r % n == a % n)
// one_M * a = a
val lemma_mont_mul_one: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (let r0 = 1 * r % n in let r1 = a * r % n in r0 * r1 * d % n == r1 % n)
let lemma_mont_mul_one n r d a =
let r0 = 1 * r % n in
let r1 = a * r % n in
calc (==) {
r1 * r0 * d % n;
(==) { Math.Lemmas.paren_mul_right r1 r0 d; Math.Lemmas.lemma_mod_mul_distr_r r1 (r0 * d) n }
r1 * (r0 * d % n) % n;
(==) { lemma_mont_id n r d 1 }
r1 * (1 % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r r1 1 n }
r1 % n;
}
val from_mont_add_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a + b) % n))
let from_mont_add_lemma pbits rLen n mu aM bM =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
from_mont_lemma pbits rLen n mu cM;
assert (c == cM * d % n);
calc (==) { //c
cM * d % n;
(==) { }
(aM + bM) % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM + bM) d n }
(aM + bM) * d % n;
(==) { Math.Lemmas.distributivity_add_left aM bM d }
(aM * d + bM * d) % n;
(==) { Math.Lemmas.modulo_distributivity (aM * d) (bM * d) n }
(aM * d % n + bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM
val from_mont_sub_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM - bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a - b) % n))
let from_mont_sub_lemma pbits rLen n mu aM bM =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = (aM - bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
from_mont_lemma pbits rLen n mu cM;
assert (c == cM * d % n);
calc (==) { //c
cM * d % n;
(==) { }
(aM - bM) % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM - bM) d n }
(aM - bM) * d % n;
(==) { Math.Lemmas.distributivity_sub_left aM bM d }
(aM * d - bM * d) % n;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (aM * d) (- bM * d) n }
(aM * d % n - bM * d) % n;
(==) { Math.Lemmas.lemma_mod_sub_distr (aM * d % n) (bM * d) n }
(aM * d % n - bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM
val from_mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = mont_mul pbits rLen n mu aM bM in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == a * b % n))
let from_mont_mul_lemma pbits rLen n mu aM bM =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = mont_mul pbits rLen n mu aM bM in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
mont_mul_lemma pbits rLen n mu aM bM;
assert (cM == aM * bM * d % n);
from_mont_lemma pbits rLen n mu cM;
calc (==) { //c
cM * d % n;
(==) { }
(aM * bM * d % n) * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM * bM * d) d n }
aM * bM * d * d % n;
(==) { Math.Lemmas.paren_mul_right aM bM d }
aM * (bM * d) * d % n;
(==) {
Math.Lemmas.paren_mul_right aM (bM * d) d;
Math.Lemmas.swap_mul (bM * d) d;
Math.Lemmas.paren_mul_right aM d (bM * d) }
aM * d * (bM * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM * d) (bM * d) n }
(aM * d % n) * (bM * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (aM * d % n) (bM * d) n }
(aM * d % n) * (bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM
val from_mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires
mont_pre pbits rLen n mu)
(ensures
(let oneM = mont_one pbits rLen n mu in
let one = from_mont pbits rLen n mu oneM in
one == 1)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val from_mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires
mont_pre pbits rLen n mu)
(ensures
(let oneM = mont_one pbits rLen n mu in
let one = from_mont pbits rLen n mu oneM in
one == 1)) | [] | Hacl.Spec.Montgomery.Lemmas.from_mont_one_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos -> mu: Prims.nat
-> FStar.Pervasives.Lemma (requires Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu)
(ensures
(let oneM = Hacl.Spec.Montgomery.Lemmas.mont_one pbits rLen n mu in
let one = Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu oneM in
one == 1)) | {
"end_col": 27,
"end_line": 824,
"start_col": 41,
"start_line": 810
} |
FStar.Pervasives.Lemma | val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c | val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c = | false | null | true | let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.int",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_div_r_eval_lemma",
"Prims.unit",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_div_r_fits_lemma",
"Hacl.Spec.Montgomery.Lemmas.mont_preconditions_d",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd",
"FStar.Mul.op_Star"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n)) | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_div_r_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos -> mu: Prims.nat -> c: Prims.nat
-> FStar.Pervasives.Lemma (requires Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu)
(ensures
(let res = Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_div_r pbits rLen n mu c in
let r = Prims.pow2 (pbits * rLen) in
let _ = Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd (pbits * rLen) n in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ d _ = _ in
res % n == c * d % n /\ res <= (c - n) / r + n)
<:
Type0)) | {
"end_col": 58,
"end_line": 469,
"start_col": 55,
"start_line": 465
} |
FStar.Pervasives.Lemma | val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0 | val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 = | false | null | true | mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0 | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step_modn",
"Prims.unit",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step_modr",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step_bound"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n)) | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
pbits: Prims.pos ->
rLen: Prims.nat ->
n: Prims.pos ->
mu: Prims.nat ->
i: Prims.pos{i <= rLen} ->
c: Prims.nat ->
res0: Prims.nat
-> FStar.Pervasives.Lemma
(requires
res0 % n == c % n /\ res0 % Prims.pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (Prims.pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % Prims.pow2 pbits == 0)
(ensures
(let res = Hacl.Spec.Montgomery.Lemmas.mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % Prims.pow2 (pbits * i) == 0 /\
res <= c + (Prims.pow2 (pbits * i) - 1) * n)) | {
"end_col": 57,
"end_line": 379,
"start_col": 2,
"start_line": 377
} |
FStar.Pervasives.Lemma | val from_to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
mont_pre pbits rLen n mu /\ a < r))
(ensures
(let aM = to_mont pbits rLen n mu a in
let a' = from_mont pbits rLen n mu aM in
a' == a % n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let from_to_mont_lemma pbits rLen n mu a =
let aM = to_mont pbits rLen n mu a in
let a' = from_mont pbits rLen n mu aM in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
assert (r * d % n == 1);
to_mont_lemma pbits rLen n mu a;
assert (aM == a * r % n);
from_mont_lemma pbits rLen n mu aM;
assert (a' == aM * d % n);
lemma_mont_id n r d a;
assert (a' == a % n) | val from_to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
mont_pre pbits rLen n mu /\ a < r))
(ensures
(let aM = to_mont pbits rLen n mu a in
let a' = from_mont pbits rLen n mu aM in
a' == a % n))
let from_to_mont_lemma pbits rLen n mu a = | false | null | true | let aM = to_mont pbits rLen n mu a in
let a' = from_mont pbits rLen n mu aM in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
assert (r * d % n == 1);
to_mont_lemma pbits rLen n mu a;
assert (aM == a * r % n);
from_mont_lemma pbits rLen n mu aM;
assert (a' == aM * d % n);
lemma_mont_id n r d a;
assert (a' == a % n) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.int",
"Prims._assert",
"Prims.eq2",
"Prims.op_Modulus",
"Prims.unit",
"Hacl.Spec.Montgomery.Lemmas.lemma_mont_id",
"FStar.Mul.op_Star",
"Hacl.Spec.Montgomery.Lemmas.from_mont_lemma",
"Hacl.Spec.Montgomery.Lemmas.to_mont_lemma",
"Hacl.Spec.Montgomery.Lemmas.mont_preconditions_d",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd",
"Prims.pow2",
"Hacl.Spec.Montgomery.Lemmas.from_mont",
"Hacl.Spec.Montgomery.Lemmas.to_mont"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b)
/// Lemma (to_mont rLen n mu a == a * r % n)
val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n)
let lemma_mod_mul_distr3 a b c n =
calc (==) {
a * (b % n) * c % n;
(==) { }
(b % n) * a * c % n;
(==) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
(==) { Math.Lemmas.paren_mul_right b a c }
a * b * c % n;
}
val mult_lt_lemma: a:nat -> b:nat -> c:nat -> d:nat -> Lemma
(requires a < c /\ b < d)
(ensures a * b < c * d)
let mult_lt_lemma a b c d = ()
val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n))
let to_mont_eval_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let c = a * r2 in
calc (==) {
c * d % n;
(==) { }
a * r2 * d % n;
(==) { Math.Lemmas.paren_mul_right 2 pbits rLen;
Math.Lemmas.pow2_plus (pbits * rLen) (pbits * rLen) }
a * (r * r % n) * d % n;
(==) { lemma_mod_mul_distr3 a (r * r) d n }
a * (r * r) * d % n;
(==) { Math.Lemmas.paren_mul_right a r r }
a * r * r * d % n;
(==) { Math.Lemmas.paren_mul_right (a * r) r d }
a * r * (r * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (a * r) (r * d) n }
a * r * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a * r % n;
};
assert (c * d % n == a * r % n)
val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n)
let to_mont_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let c = a * r2 in
let aM = to_mont pbits rLen n mu a in
assert (aM == mont_reduction pbits rLen n mu c);
mult_lt_lemma a r2 r n;
assert (a * r2 < r * n);
mont_reduction_lemma pbits rLen n mu c;
assert (aM == c * d % n);
to_mont_eval_lemma pbits rLen n mu a;
assert (aM == a * r % n)
/// Lemma (from_mont rLen n mu aM == aM * d % n)
val from_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ aM < pow2 (pbits * rLen))
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
from_mont pbits rLen n mu aM == aM * d % n))
let from_mont_lemma pbits rLen n mu aM =
mont_reduction_lemma pbits rLen n mu aM
/// Lemma (mont_one pbits rLen n mu == 1 * r % n)
val mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures mont_one pbits rLen n mu == 1 * pow2 (pbits * rLen) % n)
let mont_one_lemma pbits rLen n mu =
to_mont_lemma pbits rLen n mu 1
/// Properties of Montgomery arithmetic
// from_mont (to_mont a) = a % n
val lemma_mont_id: n:pos -> r:pos -> d:int{r * d % n == 1} -> a:nat ->
Lemma (a * r % n * d % n == a % n)
let lemma_mont_id n r d a =
calc (==) {
a * r % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * r) d n }
a * r * d % n;
(==) { Math.Lemmas.paren_mul_right a r d; Math.Lemmas.lemma_mod_mul_distr_r a (r * d) n }
a * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a % n;
}
// to_mont (mont_reduction a) = a % n
val lemma_mont_id1: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (a * d % n * r % n == a % n)
let lemma_mont_id1 n r d a =
calc (==) {
((a * d % n) * r) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * d) r n }
((a * d) * r) % n;
(==) { Math.Lemmas.paren_mul_right a d r }
(a * (d * r)) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (d * r) n }
(a * (d * r % n)) % n;
(==) { assert (r * d % n = 1) }
a % n;
};
assert (a * d % n * r % n == a % n)
// one_M * a = a
val lemma_mont_mul_one: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (let r0 = 1 * r % n in let r1 = a * r % n in r0 * r1 * d % n == r1 % n)
let lemma_mont_mul_one n r d a =
let r0 = 1 * r % n in
let r1 = a * r % n in
calc (==) {
r1 * r0 * d % n;
(==) { Math.Lemmas.paren_mul_right r1 r0 d; Math.Lemmas.lemma_mod_mul_distr_r r1 (r0 * d) n }
r1 * (r0 * d % n) % n;
(==) { lemma_mont_id n r d 1 }
r1 * (1 % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r r1 1 n }
r1 % n;
}
val from_mont_add_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a + b) % n))
let from_mont_add_lemma pbits rLen n mu aM bM =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
from_mont_lemma pbits rLen n mu cM;
assert (c == cM * d % n);
calc (==) { //c
cM * d % n;
(==) { }
(aM + bM) % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM + bM) d n }
(aM + bM) * d % n;
(==) { Math.Lemmas.distributivity_add_left aM bM d }
(aM * d + bM * d) % n;
(==) { Math.Lemmas.modulo_distributivity (aM * d) (bM * d) n }
(aM * d % n + bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM
val from_mont_sub_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM - bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a - b) % n))
let from_mont_sub_lemma pbits rLen n mu aM bM =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = (aM - bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
from_mont_lemma pbits rLen n mu cM;
assert (c == cM * d % n);
calc (==) { //c
cM * d % n;
(==) { }
(aM - bM) % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM - bM) d n }
(aM - bM) * d % n;
(==) { Math.Lemmas.distributivity_sub_left aM bM d }
(aM * d - bM * d) % n;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (aM * d) (- bM * d) n }
(aM * d % n - bM * d) % n;
(==) { Math.Lemmas.lemma_mod_sub_distr (aM * d % n) (bM * d) n }
(aM * d % n - bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM
val from_mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = mont_mul pbits rLen n mu aM bM in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == a * b % n))
let from_mont_mul_lemma pbits rLen n mu aM bM =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = mont_mul pbits rLen n mu aM bM in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
mont_mul_lemma pbits rLen n mu aM bM;
assert (cM == aM * bM * d % n);
from_mont_lemma pbits rLen n mu cM;
calc (==) { //c
cM * d % n;
(==) { }
(aM * bM * d % n) * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM * bM * d) d n }
aM * bM * d * d % n;
(==) { Math.Lemmas.paren_mul_right aM bM d }
aM * (bM * d) * d % n;
(==) {
Math.Lemmas.paren_mul_right aM (bM * d) d;
Math.Lemmas.swap_mul (bM * d) d;
Math.Lemmas.paren_mul_right aM d (bM * d) }
aM * d * (bM * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM * d) (bM * d) n }
(aM * d % n) * (bM * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (aM * d % n) (bM * d) n }
(aM * d % n) * (bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM
val from_mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires
mont_pre pbits rLen n mu)
(ensures
(let oneM = mont_one pbits rLen n mu in
let one = from_mont pbits rLen n mu oneM in
one == 1))
let from_mont_one_lemma pbits rLen n mu =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let oneM = mont_one pbits rLen n mu in
mont_one_lemma pbits rLen n mu;
assert (oneM == r % n);
let one = from_mont pbits rLen n mu oneM in
from_mont_lemma pbits rLen n mu oneM;
assert (one == oneM * d % n);
assert (one == (r % n) * d % n);
lemma_mont_id n r d 1;
assert (one == 1 % n);
Math.Lemmas.small_mod 1 n
val from_to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
mont_pre pbits rLen n mu /\ a < r))
(ensures
(let aM = to_mont pbits rLen n mu a in
let a' = from_mont pbits rLen n mu aM in
a' == a % n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val from_to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
mont_pre pbits rLen n mu /\ a < r))
(ensures
(let aM = to_mont pbits rLen n mu a in
let a' = from_mont pbits rLen n mu aM in
a' == a % n)) | [] | Hacl.Spec.Montgomery.Lemmas.from_to_mont_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos -> mu: Prims.nat -> a: Prims.nat
-> FStar.Pervasives.Lemma
(requires
(let r = Prims.pow2 (pbits * rLen) in
Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu /\ a < r))
(ensures
(let aM = Hacl.Spec.Montgomery.Lemmas.to_mont pbits rLen n mu a in
let a' = Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu aM in
a' == a % n)) | {
"end_col": 22,
"end_line": 850,
"start_col": 42,
"start_line": 835
} |
FStar.Pervasives.Lemma | val lemma_mont_id: n:pos -> r:pos -> d:int{r * d % n == 1} -> a:nat ->
Lemma (a * r % n * d % n == a % n) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_mont_id n r d a =
calc (==) {
a * r % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * r) d n }
a * r * d % n;
(==) { Math.Lemmas.paren_mul_right a r d; Math.Lemmas.lemma_mod_mul_distr_r a (r * d) n }
a * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a % n;
} | val lemma_mont_id: n:pos -> r:pos -> d:int{r * d % n == 1} -> a:nat ->
Lemma (a * r % n * d % n == a % n)
let lemma_mont_id n r d a = | false | null | true | calc ( == ) {
(a * r % n) * d % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l (a * r) d n }
(a * r) * d % n;
( == ) { (Math.Lemmas.paren_mul_right a r d;
Math.Lemmas.lemma_mod_mul_distr_r a (r * d) n) }
a * (r * d % n) % n;
( == ) { assert (r * d % n == 1) }
a % n;
} | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.nat",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"FStar.Math.Lemmas.paren_mul_right",
"Prims._assert"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b)
/// Lemma (to_mont rLen n mu a == a * r % n)
val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n)
let lemma_mod_mul_distr3 a b c n =
calc (==) {
a * (b % n) * c % n;
(==) { }
(b % n) * a * c % n;
(==) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
(==) { Math.Lemmas.paren_mul_right b a c }
a * b * c % n;
}
val mult_lt_lemma: a:nat -> b:nat -> c:nat -> d:nat -> Lemma
(requires a < c /\ b < d)
(ensures a * b < c * d)
let mult_lt_lemma a b c d = ()
val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n))
let to_mont_eval_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let c = a * r2 in
calc (==) {
c * d % n;
(==) { }
a * r2 * d % n;
(==) { Math.Lemmas.paren_mul_right 2 pbits rLen;
Math.Lemmas.pow2_plus (pbits * rLen) (pbits * rLen) }
a * (r * r % n) * d % n;
(==) { lemma_mod_mul_distr3 a (r * r) d n }
a * (r * r) * d % n;
(==) { Math.Lemmas.paren_mul_right a r r }
a * r * r * d % n;
(==) { Math.Lemmas.paren_mul_right (a * r) r d }
a * r * (r * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (a * r) (r * d) n }
a * r * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a * r % n;
};
assert (c * d % n == a * r % n)
val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n)
let to_mont_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let c = a * r2 in
let aM = to_mont pbits rLen n mu a in
assert (aM == mont_reduction pbits rLen n mu c);
mult_lt_lemma a r2 r n;
assert (a * r2 < r * n);
mont_reduction_lemma pbits rLen n mu c;
assert (aM == c * d % n);
to_mont_eval_lemma pbits rLen n mu a;
assert (aM == a * r % n)
/// Lemma (from_mont rLen n mu aM == aM * d % n)
val from_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ aM < pow2 (pbits * rLen))
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
from_mont pbits rLen n mu aM == aM * d % n))
let from_mont_lemma pbits rLen n mu aM =
mont_reduction_lemma pbits rLen n mu aM
/// Lemma (mont_one pbits rLen n mu == 1 * r % n)
val mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures mont_one pbits rLen n mu == 1 * pow2 (pbits * rLen) % n)
let mont_one_lemma pbits rLen n mu =
to_mont_lemma pbits rLen n mu 1
/// Properties of Montgomery arithmetic
// from_mont (to_mont a) = a % n
val lemma_mont_id: n:pos -> r:pos -> d:int{r * d % n == 1} -> a:nat ->
Lemma (a * r % n * d % n == a % n) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mont_id: n:pos -> r:pos -> d:int{r * d % n == 1} -> a:nat ->
Lemma (a * r % n * d % n == a % n) | [] | Hacl.Spec.Montgomery.Lemmas.lemma_mont_id | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | n: Prims.pos -> r: Prims.pos -> d: Prims.int{r * d % n == 1} -> a: Prims.nat
-> FStar.Pervasives.Lemma (ensures (a * r % n) * d % n == a % n) | {
"end_col": 3,
"end_line": 635,
"start_col": 2,
"start_line": 627
} |
FStar.Pervasives.Lemma | val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1) | val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n = | false | null | true | let d, k = eea_pow2_odd (pbits * rLen) n in
calc ( == ) {
pow2 (pbits * rLen) * d % n;
( == ) { () }
(1 + k * n) % n;
( == ) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
( == ) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.int",
"Prims._assert",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Prims.op_Addition",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.modulo_addition_lemma",
"FStar.Math.Lemmas.small_mod",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1)) | [] | Hacl.Spec.Montgomery.Lemmas.mont_preconditions_d | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos{1 < n}
-> FStar.Pervasives.Lemma (requires n % 2 = 1)
(ensures
(let _ = Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd (pbits * rLen) n in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ d _ = _ in
Prims.pow2 (pbits * rLen) * d % n == 1)
<:
Type0)) | {
"end_col": 43,
"end_line": 162,
"start_col": 39,
"start_line": 151
} |
FStar.Pervasives.Lemma | val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_mod_mul_distr3 a b c n =
calc (==) {
a * (b % n) * c % n;
(==) { }
(b % n) * a * c % n;
(==) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
(==) { Math.Lemmas.paren_mul_right b a c }
a * b * c % n;
} | val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n)
let lemma_mod_mul_distr3 a b c n = | false | null | true | calc ( == ) {
(a * (b % n)) * c % n;
( == ) { () }
((b % n) * a) * c % n;
( == ) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
( == ) { Math.Lemmas.paren_mul_right b a c }
(a * b) * c % n;
} | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.int",
"Prims.pos",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.paren_mul_right",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b)
/// Lemma (to_mont rLen n mu a == a * r % n)
val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n) | [] | Hacl.Spec.Montgomery.Lemmas.lemma_mod_mul_distr3 | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Prims.int -> b: Prims.int -> c: Prims.int -> n: Prims.pos
-> FStar.Pervasives.Lemma (ensures (a * (b % n)) * c % n == (a * b) * c % n) | {
"end_col": 3,
"end_line": 539,
"start_col": 2,
"start_line": 529
} |
FStar.Pervasives.Lemma | val from_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ aM < pow2 (pbits * rLen))
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
from_mont pbits rLen n mu aM == aM * d % n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let from_mont_lemma pbits rLen n mu aM =
mont_reduction_lemma pbits rLen n mu aM | val from_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ aM < pow2 (pbits * rLen))
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
from_mont pbits rLen n mu aM == aM * d % n))
let from_mont_lemma pbits rLen n mu aM = | false | null | true | mont_reduction_lemma pbits rLen n mu aM | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma",
"Prims.unit"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b)
/// Lemma (to_mont rLen n mu a == a * r % n)
val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n)
let lemma_mod_mul_distr3 a b c n =
calc (==) {
a * (b % n) * c % n;
(==) { }
(b % n) * a * c % n;
(==) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
(==) { Math.Lemmas.paren_mul_right b a c }
a * b * c % n;
}
val mult_lt_lemma: a:nat -> b:nat -> c:nat -> d:nat -> Lemma
(requires a < c /\ b < d)
(ensures a * b < c * d)
let mult_lt_lemma a b c d = ()
val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n))
let to_mont_eval_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let c = a * r2 in
calc (==) {
c * d % n;
(==) { }
a * r2 * d % n;
(==) { Math.Lemmas.paren_mul_right 2 pbits rLen;
Math.Lemmas.pow2_plus (pbits * rLen) (pbits * rLen) }
a * (r * r % n) * d % n;
(==) { lemma_mod_mul_distr3 a (r * r) d n }
a * (r * r) * d % n;
(==) { Math.Lemmas.paren_mul_right a r r }
a * r * r * d % n;
(==) { Math.Lemmas.paren_mul_right (a * r) r d }
a * r * (r * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (a * r) (r * d) n }
a * r * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a * r % n;
};
assert (c * d % n == a * r % n)
val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n)
let to_mont_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let c = a * r2 in
let aM = to_mont pbits rLen n mu a in
assert (aM == mont_reduction pbits rLen n mu c);
mult_lt_lemma a r2 r n;
assert (a * r2 < r * n);
mont_reduction_lemma pbits rLen n mu c;
assert (aM == c * d % n);
to_mont_eval_lemma pbits rLen n mu a;
assert (aM == a * r % n)
/// Lemma (from_mont rLen n mu aM == aM * d % n)
val from_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ aM < pow2 (pbits * rLen))
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
from_mont pbits rLen n mu aM == aM * d % n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val from_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ aM < pow2 (pbits * rLen))
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
from_mont pbits rLen n mu aM == aM * d % n)) | [] | Hacl.Spec.Montgomery.Lemmas.from_mont_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos -> mu: Prims.nat -> aM: Prims.nat
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu /\ aM < Prims.pow2 (pbits * rLen))
(ensures
(let _ = Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd (pbits * rLen) n in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ d _ = _ in
Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu aM == aM * d % n)
<:
Type0)) | {
"end_col": 41,
"end_line": 608,
"start_col": 2,
"start_line": 608
} |
FStar.Pervasives.Lemma | val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i | val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 = | false | null | true | let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step_mod_pbits",
"Prims.unit",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step_modr_aux",
"FStar.Math.Lemmas.lemma_div_exact",
"Prims.int",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Division",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_f",
"Prims.op_Subtraction"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0) | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step_modr | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
pbits: Prims.pos ->
rLen: Prims.nat ->
n: Prims.pos ->
mu: Prims.nat ->
i: Prims.pos{i <= rLen} ->
res0: Prims.nat
-> FStar.Pervasives.Lemma
(requires res0 % Prims.pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % Prims.pow2 pbits == 0)
(ensures
Hacl.Spec.Montgomery.Lemmas.mont_reduction_f pbits rLen n mu (i - 1) res0 %
Prims.pow2 (pbits * i) ==
0) | {
"end_col": 52,
"end_line": 351,
"start_col": 59,
"start_line": 343
} |
FStar.Pervasives.Lemma | val lemma_mont_mul_one: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (let r0 = 1 * r % n in let r1 = a * r % n in r0 * r1 * d % n == r1 % n) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_mont_mul_one n r d a =
let r0 = 1 * r % n in
let r1 = a * r % n in
calc (==) {
r1 * r0 * d % n;
(==) { Math.Lemmas.paren_mul_right r1 r0 d; Math.Lemmas.lemma_mod_mul_distr_r r1 (r0 * d) n }
r1 * (r0 * d % n) % n;
(==) { lemma_mont_id n r d 1 }
r1 * (1 % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r r1 1 n }
r1 % n;
} | val lemma_mont_mul_one: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (let r0 = 1 * r % n in let r1 = a * r % n in r0 * r1 * d % n == r1 % n)
let lemma_mont_mul_one n r d a = | false | null | true | let r0 = 1 * r % n in
let r1 = a * r % n in
calc ( == ) {
(r1 * r0) * d % n;
( == ) { (Math.Lemmas.paren_mul_right r1 r0 d;
Math.Lemmas.lemma_mod_mul_distr_r r1 (r0 * d) n) }
r1 * (r0 * d % n) % n;
( == ) { lemma_mont_id n r d 1 }
r1 * (1 % n) % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_r r1 1 n }
r1 % n;
} | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.int",
"Prims.b2t",
"Prims.op_Equality",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.nat",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"FStar.Math.Lemmas.paren_mul_right",
"Prims.squash",
"Hacl.Spec.Montgomery.Lemmas.lemma_mont_id"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b)
/// Lemma (to_mont rLen n mu a == a * r % n)
val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n)
let lemma_mod_mul_distr3 a b c n =
calc (==) {
a * (b % n) * c % n;
(==) { }
(b % n) * a * c % n;
(==) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
(==) { Math.Lemmas.paren_mul_right b a c }
a * b * c % n;
}
val mult_lt_lemma: a:nat -> b:nat -> c:nat -> d:nat -> Lemma
(requires a < c /\ b < d)
(ensures a * b < c * d)
let mult_lt_lemma a b c d = ()
val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n))
let to_mont_eval_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let c = a * r2 in
calc (==) {
c * d % n;
(==) { }
a * r2 * d % n;
(==) { Math.Lemmas.paren_mul_right 2 pbits rLen;
Math.Lemmas.pow2_plus (pbits * rLen) (pbits * rLen) }
a * (r * r % n) * d % n;
(==) { lemma_mod_mul_distr3 a (r * r) d n }
a * (r * r) * d % n;
(==) { Math.Lemmas.paren_mul_right a r r }
a * r * r * d % n;
(==) { Math.Lemmas.paren_mul_right (a * r) r d }
a * r * (r * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (a * r) (r * d) n }
a * r * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a * r % n;
};
assert (c * d % n == a * r % n)
val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n)
let to_mont_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let c = a * r2 in
let aM = to_mont pbits rLen n mu a in
assert (aM == mont_reduction pbits rLen n mu c);
mult_lt_lemma a r2 r n;
assert (a * r2 < r * n);
mont_reduction_lemma pbits rLen n mu c;
assert (aM == c * d % n);
to_mont_eval_lemma pbits rLen n mu a;
assert (aM == a * r % n)
/// Lemma (from_mont rLen n mu aM == aM * d % n)
val from_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ aM < pow2 (pbits * rLen))
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
from_mont pbits rLen n mu aM == aM * d % n))
let from_mont_lemma pbits rLen n mu aM =
mont_reduction_lemma pbits rLen n mu aM
/// Lemma (mont_one pbits rLen n mu == 1 * r % n)
val mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures mont_one pbits rLen n mu == 1 * pow2 (pbits * rLen) % n)
let mont_one_lemma pbits rLen n mu =
to_mont_lemma pbits rLen n mu 1
/// Properties of Montgomery arithmetic
// from_mont (to_mont a) = a % n
val lemma_mont_id: n:pos -> r:pos -> d:int{r * d % n == 1} -> a:nat ->
Lemma (a * r % n * d % n == a % n)
let lemma_mont_id n r d a =
calc (==) {
a * r % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * r) d n }
a * r * d % n;
(==) { Math.Lemmas.paren_mul_right a r d; Math.Lemmas.lemma_mod_mul_distr_r a (r * d) n }
a * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a % n;
}
// to_mont (mont_reduction a) = a % n
val lemma_mont_id1: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (a * d % n * r % n == a % n)
let lemma_mont_id1 n r d a =
calc (==) {
((a * d % n) * r) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * d) r n }
((a * d) * r) % n;
(==) { Math.Lemmas.paren_mul_right a d r }
(a * (d * r)) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (d * r) n }
(a * (d * r % n)) % n;
(==) { assert (r * d % n = 1) }
a % n;
};
assert (a * d % n * r % n == a % n)
// one_M * a = a
val lemma_mont_mul_one: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat -> | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mont_mul_one: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (let r0 = 1 * r % n in let r1 = a * r % n in r0 * r1 * d % n == r1 % n) | [] | Hacl.Spec.Montgomery.Lemmas.lemma_mont_mul_one | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | n: Prims.pos -> r: Prims.pos -> d: Prims.int{r * d % n = 1} -> a: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
(let r0 = 1 * r % n in
let r1 = a * r % n in
(r0 * r1) * d % n == r1 % n)) | {
"end_col": 5,
"end_line": 671,
"start_col": 32,
"start_line": 659
} |
FStar.Pervasives.Lemma | val from_mont_add_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a + b) % n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let from_mont_add_lemma pbits rLen n mu aM bM =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
from_mont_lemma pbits rLen n mu cM;
assert (c == cM * d % n);
calc (==) { //c
cM * d % n;
(==) { }
(aM + bM) % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM + bM) d n }
(aM + bM) * d % n;
(==) { Math.Lemmas.distributivity_add_left aM bM d }
(aM * d + bM * d) % n;
(==) { Math.Lemmas.modulo_distributivity (aM * d) (bM * d) n }
(aM * d % n + bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM | val from_mont_add_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a + b) % n))
let from_mont_add_lemma pbits rLen n mu aM bM = | false | null | true | let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
from_mont_lemma pbits rLen n mu cM;
assert (c == cM * d % n);
calc ( == ) {
cM * d % n;
( == ) { () }
((aM + bM) % n) * d % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l (aM + bM) d n }
(aM + bM) * d % n;
( == ) { Math.Lemmas.distributivity_add_left aM bM d }
(aM * d + bM * d) % n;
( == ) { Math.Lemmas.modulo_distributivity (aM * d) (bM * d) n }
(aM * d % n + bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.int",
"Hacl.Spec.Montgomery.Lemmas.from_mont_lemma",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"FStar.Math.Lemmas.distributivity_add_left",
"FStar.Math.Lemmas.modulo_distributivity",
"Prims._assert",
"Hacl.Spec.Montgomery.Lemmas.from_mont",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd",
"Prims.pow2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b)
/// Lemma (to_mont rLen n mu a == a * r % n)
val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n)
let lemma_mod_mul_distr3 a b c n =
calc (==) {
a * (b % n) * c % n;
(==) { }
(b % n) * a * c % n;
(==) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
(==) { Math.Lemmas.paren_mul_right b a c }
a * b * c % n;
}
val mult_lt_lemma: a:nat -> b:nat -> c:nat -> d:nat -> Lemma
(requires a < c /\ b < d)
(ensures a * b < c * d)
let mult_lt_lemma a b c d = ()
val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n))
let to_mont_eval_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let c = a * r2 in
calc (==) {
c * d % n;
(==) { }
a * r2 * d % n;
(==) { Math.Lemmas.paren_mul_right 2 pbits rLen;
Math.Lemmas.pow2_plus (pbits * rLen) (pbits * rLen) }
a * (r * r % n) * d % n;
(==) { lemma_mod_mul_distr3 a (r * r) d n }
a * (r * r) * d % n;
(==) { Math.Lemmas.paren_mul_right a r r }
a * r * r * d % n;
(==) { Math.Lemmas.paren_mul_right (a * r) r d }
a * r * (r * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (a * r) (r * d) n }
a * r * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a * r % n;
};
assert (c * d % n == a * r % n)
val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n)
let to_mont_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let c = a * r2 in
let aM = to_mont pbits rLen n mu a in
assert (aM == mont_reduction pbits rLen n mu c);
mult_lt_lemma a r2 r n;
assert (a * r2 < r * n);
mont_reduction_lemma pbits rLen n mu c;
assert (aM == c * d % n);
to_mont_eval_lemma pbits rLen n mu a;
assert (aM == a * r % n)
/// Lemma (from_mont rLen n mu aM == aM * d % n)
val from_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ aM < pow2 (pbits * rLen))
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
from_mont pbits rLen n mu aM == aM * d % n))
let from_mont_lemma pbits rLen n mu aM =
mont_reduction_lemma pbits rLen n mu aM
/// Lemma (mont_one pbits rLen n mu == 1 * r % n)
val mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures mont_one pbits rLen n mu == 1 * pow2 (pbits * rLen) % n)
let mont_one_lemma pbits rLen n mu =
to_mont_lemma pbits rLen n mu 1
/// Properties of Montgomery arithmetic
// from_mont (to_mont a) = a % n
val lemma_mont_id: n:pos -> r:pos -> d:int{r * d % n == 1} -> a:nat ->
Lemma (a * r % n * d % n == a % n)
let lemma_mont_id n r d a =
calc (==) {
a * r % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * r) d n }
a * r * d % n;
(==) { Math.Lemmas.paren_mul_right a r d; Math.Lemmas.lemma_mod_mul_distr_r a (r * d) n }
a * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a % n;
}
// to_mont (mont_reduction a) = a % n
val lemma_mont_id1: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (a * d % n * r % n == a % n)
let lemma_mont_id1 n r d a =
calc (==) {
((a * d % n) * r) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * d) r n }
((a * d) * r) % n;
(==) { Math.Lemmas.paren_mul_right a d r }
(a * (d * r)) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (d * r) n }
(a * (d * r % n)) % n;
(==) { assert (r * d % n = 1) }
a % n;
};
assert (a * d % n * r % n == a % n)
// one_M * a = a
val lemma_mont_mul_one: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (let r0 = 1 * r % n in let r1 = a * r % n in r0 * r1 * d % n == r1 % n)
let lemma_mont_mul_one n r d a =
let r0 = 1 * r % n in
let r1 = a * r % n in
calc (==) {
r1 * r0 * d % n;
(==) { Math.Lemmas.paren_mul_right r1 r0 d; Math.Lemmas.lemma_mod_mul_distr_r r1 (r0 * d) n }
r1 * (r0 * d % n) % n;
(==) { lemma_mont_id n r d 1 }
r1 * (1 % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r r1 1 n }
r1 % n;
}
val from_mont_add_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a + b) % n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val from_mont_add_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a + b) % n)) | [] | Hacl.Spec.Montgomery.Lemmas.from_mont_add_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
pbits: Prims.pos ->
rLen: Prims.pos ->
n: Prims.pos ->
mu: Prims.nat ->
aM: Prims.nat ->
bM: Prims.nat
-> FStar.Pervasives.Lemma
(requires Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu /\ aM < n /\ bM < n)
(ensures
(let cM = (aM + bM) % n in
let c = Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu cM in
let a = Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu aM in
let b = Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu bM in
c == (a + b) % n)) | {
"end_col": 36,
"end_line": 710,
"start_col": 47,
"start_line": 685
} |
FStar.Pervasives.Lemma | val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n) | val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c = | false | null | true | let r = pow2 (pbits * rLen) in
let res:nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc ( == ) {
(c + (r - 1) * n) / r;
( == ) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
( == ) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Division",
"Prims.op_Addition",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"FStar.Mul.op_Star",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.distributivity_sub_left",
"Prims.squash",
"FStar.Math.Lemmas.division_addition_lemma",
"FStar.Math.Lemmas.lemma_div_le",
"Prims.l_and",
"Prims.op_Modulus",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_lemma",
"Lib.LoopCombinators.repeati",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_f",
"Prims.pow2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n)) | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_div_r_fits_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.nat -> n: Prims.pos -> mu: Prims.nat -> c: Prims.nat
-> FStar.Pervasives.Lemma
(requires
(let r = Prims.pow2 (pbits * rLen) in
(1 + n * mu) % Prims.pow2 pbits == 0))
(ensures
(let res = Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_div_r pbits rLen n mu c in
let r = Prims.pow2 (pbits * rLen) in
res <= (c - n) / r + n)) | {
"end_col": 37,
"end_line": 420,
"start_col": 60,
"start_line": 405
} |
FStar.Pervasives.Lemma | val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let to_mont_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let c = a * r2 in
let aM = to_mont pbits rLen n mu a in
assert (aM == mont_reduction pbits rLen n mu c);
mult_lt_lemma a r2 r n;
assert (a * r2 < r * n);
mont_reduction_lemma pbits rLen n mu c;
assert (aM == c * d % n);
to_mont_eval_lemma pbits rLen n mu a;
assert (aM == a * r % n) | val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n)
let to_mont_lemma pbits rLen n mu a = | false | null | true | let r = pow2 (pbits * rLen) in
let r2 = pow2 ((2 * pbits) * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let c = a * r2 in
let aM = to_mont pbits rLen n mu a in
assert (aM == mont_reduction pbits rLen n mu c);
mult_lt_lemma a r2 r n;
assert (a * r2 < r * n);
mont_reduction_lemma pbits rLen n mu c;
assert (aM == c * d % n);
to_mont_eval_lemma pbits rLen n mu a;
assert (aM == a * r % n) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.int",
"Prims._assert",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.unit",
"Hacl.Spec.Montgomery.Lemmas.to_mont_eval_lemma",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Montgomery.Lemmas.mult_lt_lemma",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction",
"Hacl.Spec.Montgomery.Lemmas.to_mont",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd",
"Prims.pow2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b)
/// Lemma (to_mont rLen n mu a == a * r % n)
val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n)
let lemma_mod_mul_distr3 a b c n =
calc (==) {
a * (b % n) * c % n;
(==) { }
(b % n) * a * c % n;
(==) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
(==) { Math.Lemmas.paren_mul_right b a c }
a * b * c % n;
}
val mult_lt_lemma: a:nat -> b:nat -> c:nat -> d:nat -> Lemma
(requires a < c /\ b < d)
(ensures a * b < c * d)
let mult_lt_lemma a b c d = ()
val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n))
let to_mont_eval_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let c = a * r2 in
calc (==) {
c * d % n;
(==) { }
a * r2 * d % n;
(==) { Math.Lemmas.paren_mul_right 2 pbits rLen;
Math.Lemmas.pow2_plus (pbits * rLen) (pbits * rLen) }
a * (r * r % n) * d % n;
(==) { lemma_mod_mul_distr3 a (r * r) d n }
a * (r * r) * d % n;
(==) { Math.Lemmas.paren_mul_right a r r }
a * r * r * d % n;
(==) { Math.Lemmas.paren_mul_right (a * r) r d }
a * r * (r * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (a * r) (r * d) n }
a * r * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a * r % n;
};
assert (c * d % n == a * r % n)
val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n) | [] | Hacl.Spec.Montgomery.Lemmas.to_mont_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos -> mu: Prims.nat -> a: Prims.nat
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu /\ a < Prims.pow2 (pbits * rLen))
(ensures
Hacl.Spec.Montgomery.Lemmas.to_mont pbits rLen n mu a == a * Prims.pow2 (pbits * rLen) % n) | {
"end_col": 26,
"end_line": 598,
"start_col": 37,
"start_line": 586
} |
FStar.Pervasives.Lemma | val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0) | val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu = | false | null | true | calc ( == ) {
(1 + n * mu) % pow2 pbits;
( == ) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + (n % pow2 pbits) * mu % pow2 pbits) % pow2 pbits;
( == ) { Math.Lemmas.lemma_mod_plus_distr_r 1 ((n % pow2 pbits) * mu) (pow2 pbits) }
(1 + (n % pow2 pbits) * mu) % pow2 pbits;
( == ) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.nat",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.lemma_mod_plus_distr_r",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0) | [] | Hacl.Spec.Montgomery.Lemmas.mont_preconditions_n0 | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> n: Prims.pos{n > 1} -> mu: Prims.nat
-> FStar.Pervasives.Lemma (requires (1 + (n % Prims.pow2 pbits) * mu) % Prims.pow2 pbits == 0)
(ensures (1 + n * mu) % Prims.pow2 pbits == 0) | {
"end_col": 41,
"end_line": 181,
"start_col": 2,
"start_line": 170
} |
FStar.Pervasives.Lemma | val from_mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = mont_mul pbits rLen n mu aM bM in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == a * b % n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let from_mont_mul_lemma pbits rLen n mu aM bM =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = mont_mul pbits rLen n mu aM bM in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
mont_mul_lemma pbits rLen n mu aM bM;
assert (cM == aM * bM * d % n);
from_mont_lemma pbits rLen n mu cM;
calc (==) { //c
cM * d % n;
(==) { }
(aM * bM * d % n) * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM * bM * d) d n }
aM * bM * d * d % n;
(==) { Math.Lemmas.paren_mul_right aM bM d }
aM * (bM * d) * d % n;
(==) {
Math.Lemmas.paren_mul_right aM (bM * d) d;
Math.Lemmas.swap_mul (bM * d) d;
Math.Lemmas.paren_mul_right aM d (bM * d) }
aM * d * (bM * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM * d) (bM * d) n }
(aM * d % n) * (bM * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (aM * d % n) (bM * d) n }
(aM * d % n) * (bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM | val from_mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = mont_mul pbits rLen n mu aM bM in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == a * b % n))
let from_mont_mul_lemma pbits rLen n mu aM bM = | false | null | true | let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = mont_mul pbits rLen n mu aM bM in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
mont_mul_lemma pbits rLen n mu aM bM;
assert (cM == (aM * bM) * d % n);
from_mont_lemma pbits rLen n mu cM;
calc ( == ) {
cM * d % n;
( == ) { () }
((aM * bM) * d % n) * d % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l ((aM * bM) * d) d n }
((aM * bM) * d) * d % n;
( == ) { Math.Lemmas.paren_mul_right aM bM d }
(aM * (bM * d)) * d % n;
( == ) { (Math.Lemmas.paren_mul_right aM (bM * d) d;
Math.Lemmas.swap_mul (bM * d) d;
Math.Lemmas.paren_mul_right aM d (bM * d)) }
(aM * d) * (bM * d) % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l (aM * d) (bM * d) n }
(aM * d % n) * (bM * d) % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_r (aM * d % n) (bM * d) n }
(aM * d % n) * (bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.int",
"Hacl.Spec.Montgomery.Lemmas.from_mont_lemma",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"FStar.Math.Lemmas.paren_mul_right",
"FStar.Math.Lemmas.swap_mul",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Prims._assert",
"Hacl.Spec.Montgomery.Lemmas.mont_mul_lemma",
"Hacl.Spec.Montgomery.Lemmas.from_mont",
"Hacl.Spec.Montgomery.Lemmas.mont_mul",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd",
"Prims.pow2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b)
/// Lemma (to_mont rLen n mu a == a * r % n)
val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n)
let lemma_mod_mul_distr3 a b c n =
calc (==) {
a * (b % n) * c % n;
(==) { }
(b % n) * a * c % n;
(==) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
(==) { Math.Lemmas.paren_mul_right b a c }
a * b * c % n;
}
val mult_lt_lemma: a:nat -> b:nat -> c:nat -> d:nat -> Lemma
(requires a < c /\ b < d)
(ensures a * b < c * d)
let mult_lt_lemma a b c d = ()
val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n))
let to_mont_eval_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let c = a * r2 in
calc (==) {
c * d % n;
(==) { }
a * r2 * d % n;
(==) { Math.Lemmas.paren_mul_right 2 pbits rLen;
Math.Lemmas.pow2_plus (pbits * rLen) (pbits * rLen) }
a * (r * r % n) * d % n;
(==) { lemma_mod_mul_distr3 a (r * r) d n }
a * (r * r) * d % n;
(==) { Math.Lemmas.paren_mul_right a r r }
a * r * r * d % n;
(==) { Math.Lemmas.paren_mul_right (a * r) r d }
a * r * (r * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (a * r) (r * d) n }
a * r * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a * r % n;
};
assert (c * d % n == a * r % n)
val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n)
let to_mont_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let c = a * r2 in
let aM = to_mont pbits rLen n mu a in
assert (aM == mont_reduction pbits rLen n mu c);
mult_lt_lemma a r2 r n;
assert (a * r2 < r * n);
mont_reduction_lemma pbits rLen n mu c;
assert (aM == c * d % n);
to_mont_eval_lemma pbits rLen n mu a;
assert (aM == a * r % n)
/// Lemma (from_mont rLen n mu aM == aM * d % n)
val from_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ aM < pow2 (pbits * rLen))
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
from_mont pbits rLen n mu aM == aM * d % n))
let from_mont_lemma pbits rLen n mu aM =
mont_reduction_lemma pbits rLen n mu aM
/// Lemma (mont_one pbits rLen n mu == 1 * r % n)
val mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures mont_one pbits rLen n mu == 1 * pow2 (pbits * rLen) % n)
let mont_one_lemma pbits rLen n mu =
to_mont_lemma pbits rLen n mu 1
/// Properties of Montgomery arithmetic
// from_mont (to_mont a) = a % n
val lemma_mont_id: n:pos -> r:pos -> d:int{r * d % n == 1} -> a:nat ->
Lemma (a * r % n * d % n == a % n)
let lemma_mont_id n r d a =
calc (==) {
a * r % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * r) d n }
a * r * d % n;
(==) { Math.Lemmas.paren_mul_right a r d; Math.Lemmas.lemma_mod_mul_distr_r a (r * d) n }
a * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a % n;
}
// to_mont (mont_reduction a) = a % n
val lemma_mont_id1: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (a * d % n * r % n == a % n)
let lemma_mont_id1 n r d a =
calc (==) {
((a * d % n) * r) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * d) r n }
((a * d) * r) % n;
(==) { Math.Lemmas.paren_mul_right a d r }
(a * (d * r)) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (d * r) n }
(a * (d * r % n)) % n;
(==) { assert (r * d % n = 1) }
a % n;
};
assert (a * d % n * r % n == a % n)
// one_M * a = a
val lemma_mont_mul_one: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (let r0 = 1 * r % n in let r1 = a * r % n in r0 * r1 * d % n == r1 % n)
let lemma_mont_mul_one n r d a =
let r0 = 1 * r % n in
let r1 = a * r % n in
calc (==) {
r1 * r0 * d % n;
(==) { Math.Lemmas.paren_mul_right r1 r0 d; Math.Lemmas.lemma_mod_mul_distr_r r1 (r0 * d) n }
r1 * (r0 * d % n) % n;
(==) { lemma_mont_id n r d 1 }
r1 * (1 % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r r1 1 n }
r1 % n;
}
val from_mont_add_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a + b) % n))
let from_mont_add_lemma pbits rLen n mu aM bM =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
from_mont_lemma pbits rLen n mu cM;
assert (c == cM * d % n);
calc (==) { //c
cM * d % n;
(==) { }
(aM + bM) % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM + bM) d n }
(aM + bM) * d % n;
(==) { Math.Lemmas.distributivity_add_left aM bM d }
(aM * d + bM * d) % n;
(==) { Math.Lemmas.modulo_distributivity (aM * d) (bM * d) n }
(aM * d % n + bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM
val from_mont_sub_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM - bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a - b) % n))
let from_mont_sub_lemma pbits rLen n mu aM bM =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = (aM - bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
from_mont_lemma pbits rLen n mu cM;
assert (c == cM * d % n);
calc (==) { //c
cM * d % n;
(==) { }
(aM - bM) % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM - bM) d n }
(aM - bM) * d % n;
(==) { Math.Lemmas.distributivity_sub_left aM bM d }
(aM * d - bM * d) % n;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (aM * d) (- bM * d) n }
(aM * d % n - bM * d) % n;
(==) { Math.Lemmas.lemma_mod_sub_distr (aM * d % n) (bM * d) n }
(aM * d % n - bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM
val from_mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = mont_mul pbits rLen n mu aM bM in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == a * b % n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val from_mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = mont_mul pbits rLen n mu aM bM in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == a * b % n)) | [] | Hacl.Spec.Montgomery.Lemmas.from_mont_mul_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
pbits: Prims.pos ->
rLen: Prims.pos ->
n: Prims.pos ->
mu: Prims.nat ->
aM: Prims.nat ->
bM: Prims.nat
-> FStar.Pervasives.Lemma
(requires Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu /\ aM < n /\ bM < n)
(ensures
(let cM = Hacl.Spec.Montgomery.Lemmas.mont_mul pbits rLen n mu aM bM in
let c = Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu cM in
let a = Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu aM in
let b = Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu bM in
c == a * b % n)) | {
"end_col": 36,
"end_line": 799,
"start_col": 47,
"start_line": 765
} |
FStar.Pervasives.Lemma | val from_mont_sub_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM - bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a - b) % n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let from_mont_sub_lemma pbits rLen n mu aM bM =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = (aM - bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
from_mont_lemma pbits rLen n mu cM;
assert (c == cM * d % n);
calc (==) { //c
cM * d % n;
(==) { }
(aM - bM) % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM - bM) d n }
(aM - bM) * d % n;
(==) { Math.Lemmas.distributivity_sub_left aM bM d }
(aM * d - bM * d) % n;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (aM * d) (- bM * d) n }
(aM * d % n - bM * d) % n;
(==) { Math.Lemmas.lemma_mod_sub_distr (aM * d % n) (bM * d) n }
(aM * d % n - bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM | val from_mont_sub_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM - bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a - b) % n))
let from_mont_sub_lemma pbits rLen n mu aM bM = | false | null | true | let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = (aM - bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
from_mont_lemma pbits rLen n mu cM;
assert (c == cM * d % n);
calc ( == ) {
cM * d % n;
( == ) { () }
((aM - bM) % n) * d % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l (aM - bM) d n }
(aM - bM) * d % n;
( == ) { Math.Lemmas.distributivity_sub_left aM bM d }
(aM * d - bM * d) % n;
( == ) { Math.Lemmas.lemma_mod_plus_distr_l (aM * d) (- bM * d) n }
(aM * d % n - bM * d) % n;
( == ) { Math.Lemmas.lemma_mod_sub_distr (aM * d % n) (bM * d) n }
(aM * d % n - bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.int",
"Hacl.Spec.Montgomery.Lemmas.from_mont_lemma",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.op_Subtraction",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"FStar.Math.Lemmas.distributivity_sub_left",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"Prims.op_Minus",
"FStar.Math.Lemmas.lemma_mod_sub_distr",
"Prims._assert",
"Hacl.Spec.Montgomery.Lemmas.from_mont",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd",
"Prims.pow2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b)
/// Lemma (to_mont rLen n mu a == a * r % n)
val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n)
let lemma_mod_mul_distr3 a b c n =
calc (==) {
a * (b % n) * c % n;
(==) { }
(b % n) * a * c % n;
(==) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
(==) { Math.Lemmas.paren_mul_right b a c }
a * b * c % n;
}
val mult_lt_lemma: a:nat -> b:nat -> c:nat -> d:nat -> Lemma
(requires a < c /\ b < d)
(ensures a * b < c * d)
let mult_lt_lemma a b c d = ()
val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n))
let to_mont_eval_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let c = a * r2 in
calc (==) {
c * d % n;
(==) { }
a * r2 * d % n;
(==) { Math.Lemmas.paren_mul_right 2 pbits rLen;
Math.Lemmas.pow2_plus (pbits * rLen) (pbits * rLen) }
a * (r * r % n) * d % n;
(==) { lemma_mod_mul_distr3 a (r * r) d n }
a * (r * r) * d % n;
(==) { Math.Lemmas.paren_mul_right a r r }
a * r * r * d % n;
(==) { Math.Lemmas.paren_mul_right (a * r) r d }
a * r * (r * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (a * r) (r * d) n }
a * r * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a * r % n;
};
assert (c * d % n == a * r % n)
val to_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < pow2 (pbits * rLen))
(ensures to_mont pbits rLen n mu a == a * pow2 (pbits * rLen) % n)
let to_mont_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let c = a * r2 in
let aM = to_mont pbits rLen n mu a in
assert (aM == mont_reduction pbits rLen n mu c);
mult_lt_lemma a r2 r n;
assert (a * r2 < r * n);
mont_reduction_lemma pbits rLen n mu c;
assert (aM == c * d % n);
to_mont_eval_lemma pbits rLen n mu a;
assert (aM == a * r % n)
/// Lemma (from_mont rLen n mu aM == aM * d % n)
val from_mont_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ aM < pow2 (pbits * rLen))
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
from_mont pbits rLen n mu aM == aM * d % n))
let from_mont_lemma pbits rLen n mu aM =
mont_reduction_lemma pbits rLen n mu aM
/// Lemma (mont_one pbits rLen n mu == 1 * r % n)
val mont_one_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures mont_one pbits rLen n mu == 1 * pow2 (pbits * rLen) % n)
let mont_one_lemma pbits rLen n mu =
to_mont_lemma pbits rLen n mu 1
/// Properties of Montgomery arithmetic
// from_mont (to_mont a) = a % n
val lemma_mont_id: n:pos -> r:pos -> d:int{r * d % n == 1} -> a:nat ->
Lemma (a * r % n * d % n == a % n)
let lemma_mont_id n r d a =
calc (==) {
a * r % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * r) d n }
a * r * d % n;
(==) { Math.Lemmas.paren_mul_right a r d; Math.Lemmas.lemma_mod_mul_distr_r a (r * d) n }
a * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a % n;
}
// to_mont (mont_reduction a) = a % n
val lemma_mont_id1: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (a * d % n * r % n == a % n)
let lemma_mont_id1 n r d a =
calc (==) {
((a * d % n) * r) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * d) r n }
((a * d) * r) % n;
(==) { Math.Lemmas.paren_mul_right a d r }
(a * (d * r)) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (d * r) n }
(a * (d * r % n)) % n;
(==) { assert (r * d % n = 1) }
a % n;
};
assert (a * d % n * r % n == a % n)
// one_M * a = a
val lemma_mont_mul_one: n:pos -> r:pos -> d:int{r * d % n = 1} -> a:nat ->
Lemma (let r0 = 1 * r % n in let r1 = a * r % n in r0 * r1 * d % n == r1 % n)
let lemma_mont_mul_one n r d a =
let r0 = 1 * r % n in
let r1 = a * r % n in
calc (==) {
r1 * r0 * d % n;
(==) { Math.Lemmas.paren_mul_right r1 r0 d; Math.Lemmas.lemma_mod_mul_distr_r r1 (r0 * d) n }
r1 * (r0 * d % n) % n;
(==) { lemma_mont_id n r d 1 }
r1 * (1 % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r r1 1 n }
r1 % n;
}
val from_mont_add_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a + b) % n))
let from_mont_add_lemma pbits rLen n mu aM bM =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let cM = (aM + bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
from_mont_lemma pbits rLen n mu cM;
assert (c == cM * d % n);
calc (==) { //c
cM * d % n;
(==) { }
(aM + bM) % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (aM + bM) d n }
(aM + bM) * d % n;
(==) { Math.Lemmas.distributivity_add_left aM bM d }
(aM * d + bM * d) % n;
(==) { Math.Lemmas.modulo_distributivity (aM * d) (bM * d) n }
(aM * d % n + bM * d % n) % n;
};
from_mont_lemma pbits rLen n mu aM;
from_mont_lemma pbits rLen n mu bM
val from_mont_sub_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM - bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a - b) % n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val from_mont_sub_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> bM:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\
aM < n /\ bM < n)
(ensures
(let cM = (aM - bM) % n in
let c = from_mont pbits rLen n mu cM in
let a = from_mont pbits rLen n mu aM in
let b = from_mont pbits rLen n mu bM in
c == (a - b) % n)) | [] | Hacl.Spec.Montgomery.Lemmas.from_mont_sub_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
pbits: Prims.pos ->
rLen: Prims.pos ->
n: Prims.pos ->
mu: Prims.nat ->
aM: Prims.nat ->
bM: Prims.nat
-> FStar.Pervasives.Lemma
(requires Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu /\ aM < n /\ bM < n)
(ensures
(let cM = (aM - bM) % n in
let c = Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu cM in
let a = Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu aM in
let b = Hacl.Spec.Montgomery.Lemmas.from_mont pbits rLen n mu bM in
c == (a - b) % n)) | {
"end_col": 36,
"end_line": 751,
"start_col": 47,
"start_line": 724
} |
FStar.Pervasives.Lemma | val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let to_mont_eval_lemma pbits rLen n mu a =
let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let c = a * r2 in
calc (==) {
c * d % n;
(==) { }
a * r2 * d % n;
(==) { Math.Lemmas.paren_mul_right 2 pbits rLen;
Math.Lemmas.pow2_plus (pbits * rLen) (pbits * rLen) }
a * (r * r % n) * d % n;
(==) { lemma_mod_mul_distr3 a (r * r) d n }
a * (r * r) * d % n;
(==) { Math.Lemmas.paren_mul_right a r r }
a * r * r * d % n;
(==) { Math.Lemmas.paren_mul_right (a * r) r d }
a * r * (r * d) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (a * r) (r * d) n }
a * r * (r * d % n) % n;
(==) { assert (r * d % n == 1) }
a * r % n;
};
assert (c * d % n == a * r % n) | val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n))
let to_mont_eval_lemma pbits rLen n mu a = | false | null | true | let r = pow2 (pbits * rLen) in
let r2 = pow2 ((2 * pbits) * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
let c = a * r2 in
calc ( == ) {
c * d % n;
( == ) { () }
(a * r2) * d % n;
( == ) { (Math.Lemmas.paren_mul_right 2 pbits rLen;
Math.Lemmas.pow2_plus (pbits * rLen) (pbits * rLen)) }
(a * (r * r % n)) * d % n;
( == ) { lemma_mod_mul_distr3 a (r * r) d n }
(a * (r * r)) * d % n;
( == ) { Math.Lemmas.paren_mul_right a r r }
((a * r) * r) * d % n;
( == ) { Math.Lemmas.paren_mul_right (a * r) r d }
(a * r) * (r * d) % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_r (a * r) (r * d) n }
(a * r) * (r * d % n) % n;
( == ) { assert (r * d % n == 1) }
a * r % n;
};
assert (c * d % n == a * r % n) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.int",
"Prims._assert",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.pow2_plus",
"FStar.Math.Lemmas.paren_mul_right",
"Hacl.Spec.Montgomery.Lemmas.lemma_mod_mul_distr3",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Hacl.Spec.Montgomery.Lemmas.mont_preconditions_d",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd",
"Prims.pow2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b)
/// Lemma (to_mont rLen n mu a == a * r % n)
val lemma_mod_mul_distr3: a:int -> b:int -> c:int -> n:pos -> Lemma
(a * (b % n) * c % n == a * b * c % n)
let lemma_mod_mul_distr3 a b c n =
calc (==) {
a * (b % n) * c % n;
(==) { }
(b % n) * a * c % n;
(==) { Math.Lemmas.paren_mul_right (b % n) a c }
(b % n) * (a * c) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l b (a * c) n }
b * (a * c) % n;
(==) { Math.Lemmas.paren_mul_right b a c }
a * b * c % n;
}
val mult_lt_lemma: a:nat -> b:nat -> c:nat -> d:nat -> Lemma
(requires a < c /\ b < d)
(ensures a * b < c * d)
let mult_lt_lemma a b c d = ()
val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val to_mont_eval_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let r = pow2 (pbits * rLen) in
let r2 = pow2 (2 * pbits * rLen) % n in
let d, _ = eea_pow2_odd (pbits * rLen) n in
a * r2 * d % n == a * r % n)) | [] | Hacl.Spec.Montgomery.Lemmas.to_mont_eval_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos -> mu: Prims.nat -> a: Prims.nat
-> FStar.Pervasives.Lemma (requires Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu)
(ensures
(let r = Prims.pow2 (pbits * rLen) in
let r2 = Prims.pow2 ((2 * pbits) * rLen) % n in
let _ = Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd (pbits * rLen) n in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ d _ = _ in
(a * r2) * d % n == a * r % n)
<:
Type0)) | {
"end_col": 33,
"end_line": 579,
"start_col": 42,
"start_line": 555
} |
FStar.Pervasives.Lemma | val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
} | val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 = | false | null | true | let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc ( == ) {
((res0 / b1) * b1 + (n * q_i) * b1) % pow2 (pbits * i);
( == ) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
( == ) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i)
(pbits * i)
(pbits * (i - 1)) }
((res0 / b1 + n * q_i) % pow2 pbits) * b1;
( == ) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
((res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits) * b1;
} | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.op_Division",
"Prims.pow2",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.distributivity_add_left",
"Prims.squash",
"FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2",
"Prims.op_Subtraction",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"Prims._assert",
"FStar.Math.Lemmas.distributivity_sub_right"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1) | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step_modr_aux | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> n: Prims.pos -> q_i: Prims.nat -> i: Prims.pos -> res0: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
(let b1 = Prims.pow2 (pbits * (i - 1)) in
((res0 / b1) * b1 + (n * q_i) * b1) % Prims.pow2 (pbits * i) ==
((res0 / b1 % Prims.pow2 pbits + n * q_i) % Prims.pow2 pbits) * b1)) | {
"end_col": 5,
"end_line": 335,
"start_col": 59,
"start_line": 322
} |
FStar.Pervasives.Lemma | val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end | val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c = | false | null | true | let res:nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0
then eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else
(unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0:nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.int",
"Lib.LoopCombinators.eq_repeati0",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_f",
"Prims.bool",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step",
"Prims.unit",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_lemma",
"Prims.op_Subtraction",
"Lib.LoopCombinators.repeati",
"Lib.LoopCombinators.unfold_repeati"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n)) | [
"recursion"
] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
pbits: Prims.pos ->
rLen: Prims.nat ->
n: Prims.pos ->
mu: Prims.nat ->
i: Prims.nat{i <= rLen} ->
c: Prims.nat
-> FStar.Pervasives.Lemma (requires (1 + n * mu) % Prims.pow2 pbits == 0)
(ensures
(let res =
Lib.LoopCombinators.repeati i
(Hacl.Spec.Montgomery.Lemmas.mont_reduction_f pbits rLen n mu)
c
in
res % n == c % n /\ res % Prims.pow2 (pbits * i) == 0 /\
res <= c + (Prims.pow2 (pbits * i) - 1) * n)) | {
"end_col": 58,
"end_line": 395,
"start_col": 55,
"start_line": 387
} |
FStar.Pervasives.Lemma | val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
} | val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 = | false | null | true | let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc ( <= ) {
res0 + (n * q_i) * b1;
( <= ) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + (n * (pow2 pbits - 1)) * b1;
( == ) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
( == ) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
( == ) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
( == ) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
( <= ) { () }
c + (b1 - 1) * n + n * b - n * b1;
( == ) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
( == ) { () }
c - n + b * n;
( == ) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
} | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.op_Subtraction",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.eq2",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.lemma_mult_le_right",
"Prims.squash",
"FStar.Math.Lemmas.paren_mul_right",
"FStar.Math.Lemmas.distributivity_sub_left",
"FStar.Math.Lemmas.pow2_plus",
"FStar.Math.Lemmas.distributivity_sub_right"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n) | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step_bound_aux | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
pbits: Prims.pos ->
n: Prims.pos ->
q_i: Prims.nat{q_i < Prims.pow2 pbits} ->
i: Prims.pos ->
c: Prims.nat ->
res0: Prims.nat
-> FStar.Pervasives.Lemma (requires res0 <= c + (Prims.pow2 (pbits * (i - 1)) - 1) * n)
(ensures
res0 + (n * q_i) * Prims.pow2 (pbits * (i - 1)) <= c + (Prims.pow2 (pbits * i) - 1) * n) | {
"end_col": 3,
"end_line": 273,
"start_col": 62,
"start_line": 249
} |
FStar.Pervasives.Lemma | val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
} | val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i = | false | null | true | let r = pow2 pbits in
let q_i = mu * c_i % r in
calc ( == ) {
(c_i + n * q_i) % r;
( == ) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
( == ) { () }
(c_i + n * (mu * c_i % r) % r) % r;
( == ) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
( == ) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
( == ) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + (n * mu) * c_i) % r;
( == ) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
(((1 + n * mu) % r) * c_i) % r;
( == ) { assert ((1 + n * mu) % r = 0) }
0;
} | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.lemma_mod_plus_distr_r",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"FStar.Math.Lemmas.paren_mul_right",
"FStar.Math.Lemmas.distributivity_add_left",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.pow2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0) | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma_step_mod_pbits | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> n: Prims.pos -> mu: Prims.nat -> c_i: Prims.nat
-> FStar.Pervasives.Lemma (requires (1 + n * mu) % Prims.pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % Prims.pow2 pbits)) % Prims.pow2 pbits == 0) | {
"end_col": 3,
"end_line": 315,
"start_col": 56,
"start_line": 294
} |
FStar.Pervasives.Lemma | val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n) | val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c = | false | null | true | let r = pow2 (pbits * rLen) in
let res:nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc ( == ) {
res / r % n;
( == ) { assert (r * d % n == 1) }
(res / r) * (r * d % n) % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
(res / r) * (r * d) % n;
( == ) { Math.Lemmas.paren_mul_right (res / r) r d }
((res / r) * r) * d % n;
( == ) { Math.Lemmas.div_exact_r res r }
res * d % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
(res % n) * d % n;
( == ) { assert (res % n == c % n) }
(c % n) * d % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.int",
"Prims._assert",
"Prims.eq2",
"Prims.op_Modulus",
"Prims.op_Division",
"FStar.Mul.op_Star",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"FStar.Math.Lemmas.paren_mul_right",
"FStar.Math.Lemmas.div_exact_r",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Prims.op_Subtraction",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_lemma",
"Lib.LoopCombinators.repeati",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_f",
"Prims.pow2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n)) | [] | Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_div_r_eval_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.nat -> n: Prims.pos -> d: Prims.int -> mu: Prims.nat -> c: Prims.nat
-> FStar.Pervasives.Lemma
(requires
(let r = Prims.pow2 (pbits * rLen) in
(1 + n * mu) % Prims.pow2 pbits == 0 /\ r * d % n == 1))
(ensures
(let res = Hacl.Spec.Montgomery.Lemmas.mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n)) | {
"end_col": 35,
"end_line": 451,
"start_col": 62,
"start_line": 429
} |
FStar.Pervasives.Lemma | val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n)) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Montgomery",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mont_mul_lemma pbits rLen n mu a b =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b) | val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n))
let mont_mul_lemma pbits rLen n mu a b = | false | null | true | let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_mul pbits rLen n mu a b in
Math.Lemmas.lemma_mult_lt_sqr a b n;
assert (a * b < n * n);
Math.Lemmas.lemma_mult_lt_right n n r;
assert (a * b < r * n);
mont_reduction_lemma pbits rLen n mu (a * b) | {
"checked_file": "Hacl.Spec.Montgomery.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Montgomery.Lemmas.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.int",
"Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma",
"FStar.Mul.op_Star",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Math.Lemmas.lemma_mult_lt_right",
"FStar.Math.Lemmas.lemma_mult_lt_sqr",
"Hacl.Spec.Montgomery.Lemmas.mont_mul",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd",
"Prims.pow2"
] | [] | module Hacl.Spec.Montgomery.Lemmas
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
(**
https://members.loria.fr/PZimmermann/mca/mca-cup-0.5.9.pdf
https://eprint.iacr.org/2011/239.pdf
https://eprint.iacr.org/2017/1057.pdf *)
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val eea_pow2_odd_k_lemma_d: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let d = n * k1 / pow2 (a - 1) in
d % 2 == (if n * k1 % pow2 a < pow2 (a - 1) then 0 else 1)))
let eea_pow2_odd_k_lemma_d a n k1 =
let d = n * k1 / pow2 (a - 1) in
Math.Lemmas.pow2_modulo_division_lemma_1 (n * k1) (a - 1) a;
assert (d % 2 == n * k1 % pow2 a / pow2 (a - 1));
if d % 2 = 0 then begin
Math.Lemmas.small_division_lemma_2 (n * k1 % pow2 a) (pow2 (a - 1));
assert (n * k1 % pow2 a < pow2 (a - 1));
() end
#push-options "--z3rlimit 100"
val eea_pow2_odd_k_lemma: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1)
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
n * k % pow2 a == 1))
let eea_pow2_odd_k_lemma a n k1 =
let d = n * k1 / pow2 (a - 1) in
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
calc (==) {
n * k1;
(==) { Math.Lemmas.euclidean_division_definition (n * k1) (pow2 (a - 1)) }
1 + d * pow2 (a - 1);
(==) { Math.Lemmas.euclidean_division_definition d 2 }
1 + (d / 2 * 2 + d % 2) * pow2 (a - 1);
(==) { Math.Lemmas.distributivity_add_left (d / 2 * 2) (d % 2) (pow2 (a - 1)) }
1 + d / 2 * 2 * pow2 (a - 1) + d % 2 * pow2 (a - 1);
(==) { Math.Lemmas.pow2_plus 1 (a - 1) }
1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1);
};
assert (n * k1 == 1 + d / 2 * pow2 a + d % 2 * pow2 (a - 1));
if n * k1 % pow2 a < pow2 (a - 1) then begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 0);
calc (==) {
n * k % pow2 a;
(==) { }
(1 + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) (d / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a = 1);
() end
else begin
eea_pow2_odd_k_lemma_d a n k1;
assert (d % 2 = 1);
assert (n * k1 == 1 + d / 2 * pow2 a + pow2 (a - 1));
//assert (n * k == 1 + d / 2 * pow2 a + pow2 (a - 1) + n * pow2 (a - 1));
calc (==) {
n * k % pow2 a;
(==) { Math.Lemmas.distributivity_add_right n k1 (pow2 (a - 1)) }
(n * k1 + n * pow2 (a - 1)) % pow2 a;
(==) { }
(1 + pow2 (a - 1) + n * pow2 (a - 1) + d / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma (1 + pow2 (a - 1) + n * pow2 (a - 1)) (pow2 a) (d / 2) }
(1 + pow2 (a - 1) + n * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.distributivity_add_left 1 n (pow2 (a - 1)) }
(1 + (1 + n) * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.lemma_div_exact (1 + n) 2 }
(1 + (1 + n) / 2 * 2 * pow2 (a - 1)) % pow2 a;
(==) { Math.Lemmas.paren_mul_right ((1 + n) / 2) 2 (pow2 (a - 1)) }
(1 + (1 + n) / 2 * (2 * pow2 (a - 1))) % pow2 a;
(==) { Math.Lemmas.pow2_plus 1 (a - 1)}
(1 + (1 + n) / 2 * pow2 a) % pow2 a;
(==) { Math.Lemmas.modulo_addition_lemma 1 (pow2 a) ((1 + n) / 2) }
1 % pow2 a;
(==) { Math.Lemmas.pow2_le_compat a 1; Math.Lemmas.small_mod 1 (pow2 a) }
1;
};
assert (n * k % pow2 a == 1);
() end
#pop-options
val eea_pow2_odd_k_lemma_bound: a:pos -> n:pos -> k1:pos -> Lemma
(requires n * k1 % pow2 (a - 1) == 1 /\ n % 2 = 1 /\ k1 < pow2 (a - 1))
(ensures (let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
k < pow2 a))
let eea_pow2_odd_k_lemma_bound a n k1 =
if n * k1 % pow2 a < pow2 (a - 1) then
Math.Lemmas.pow2_lt_compat a (a - 1)
else
Math.Lemmas.pow2_double_sum (a - 1)
val eea_pow2_odd_k: a:pos -> n:pos ->
Pure pos
(requires n % 2 = 1)
(ensures fun k ->
n * k % pow2 a == 1 /\ k < pow2 a)
let rec eea_pow2_odd_k a n =
if a = 1 then 1
else begin
let k1 = eea_pow2_odd_k (a - 1) n in
assert (n * k1 % pow2 (a - 1) == 1);
let k = if n * k1 % pow2 a < pow2 (a - 1) then k1 else k1 + pow2 (a - 1) in
eea_pow2_odd_k_lemma a n k1;
eea_pow2_odd_k_lemma_bound a n k1;
assert (n * k % pow2 a == 1);
k end
val eea_pow2_odd: a:pos -> n:pos ->
Pure (tuple2 int int)
(requires n % 2 = 1)
(ensures fun (d, k) ->
pow2 a * d == 1 + k * n /\ - d < n)
let eea_pow2_odd a n =
let k = eea_pow2_odd_k a n in
assert (n * k % pow2 a == 1);
assert (n * k == n * k / pow2 a * pow2 a + 1);
let d = n * k / pow2 a in
Math.Lemmas.lemma_mult_lt_left n k (pow2 a);
assert (n * k < n * pow2 a);
Math.Lemmas.cancel_mul_div n (pow2 a);
assert (d < n);
assert (n * k == d * pow2 a + 1);
(- d, - k)
val mont_preconditions_d: pbits:pos -> rLen:pos -> n:pos{1 < n} -> Lemma
(requires n % 2 = 1)
(ensures (let d, k = eea_pow2_odd (pbits * rLen) n in pow2 (pbits * rLen) * d % n == 1))
let mont_preconditions_d pbits rLen n =
let d, k = eea_pow2_odd (pbits * rLen) n in
calc (==) {
pow2 (pbits * rLen) * d % n;
(==) { }
(1 + k * n) % n;
(==) { Math.Lemmas.modulo_addition_lemma 1 n k }
1 % n;
(==) { Math.Lemmas.small_mod 1 n }
1;
};
assert (pow2 (pbits * rLen) * d % n == 1)
val mont_preconditions_n0: pbits:pos -> n:pos{n > 1} -> mu:nat -> Lemma
(requires (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures (1 + n * mu) % pow2 pbits == 0)
let mont_preconditions_n0 pbits n mu =
calc (==) {
(1 + n * mu) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n * mu) (pow2 pbits) }
(1 + n * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_mul_distr_l n mu (pow2 pbits) }
(1 + n % pow2 pbits * mu % pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.lemma_mod_plus_distr_r 1 (n % pow2 pbits * mu) (pow2 pbits) }
(1 + n % pow2 pbits * mu) % pow2 pbits;
(==) { assert ((1 + (n % pow2 pbits) * mu) % pow2 pbits == 0) }
0;
};
assert ((1 + n * mu) % pow2 pbits == 0)
val mont_preconditions: pbits:pos -> rLen:pos -> n:pos{1 < n} -> mu:nat -> Lemma
(requires
n % 2 = 1 /\ (1 + (n % pow2 pbits) * mu) % pow2 pbits == 0)
(ensures
(let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
r * d % n == 1 /\ (1 + n * mu) % pow2 pbits == 0))
let mont_preconditions pbits rLen n mu =
mont_preconditions_d pbits rLen n;
mont_preconditions_n0 pbits n mu
/// High-level specification of Montgomery arithmetic
val mont_reduction_f: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i < rLen} -> c:nat -> nat
let mont_reduction_f pbits rLen n mu i c =
let c_i = c / pow2 (pbits * i) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
let res = c + n * q_i * pow2 (pbits * i) in
res
val mont_reduction_loop_div_r: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction_loop_div_r pbits rLen n mu c =
let res = repeati rLen (mont_reduction_f pbits rLen n mu) c in
let res = res / pow2 (pbits * rLen) in
res
val mont_reduction: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> nat
let mont_reduction pbits rLen n mu c =
let res = mont_reduction_loop_div_r pbits rLen n mu c in
if res < n then res else res - n
val to_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let to_mont pbits rLen n mu a =
let r2 = pow2 (2 * pbits * rLen) % n in
let c = a * r2 in
mont_reduction pbits rLen n mu c
val from_mont: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> aM:nat -> nat
let from_mont pbits rLen n mu aM =
mont_reduction pbits rLen n mu aM
val mont_mul: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> b:nat -> nat
let mont_mul pbits rLen n mu a b =
let c = a * b in
mont_reduction pbits rLen n mu c
val mont_sqr: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> a:nat -> nat
let mont_sqr pbits rLen n mu a =
mont_mul pbits rLen n mu a a
val mont_one: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> nat
let mont_one pbits rLen n mu =
let r2 = pow2 (2 * pbits * rLen) % n in
mont_reduction pbits rLen n mu r2
/// Lemma (let res = mont_reduction_loop_div_r pbits rLen n mu c in
/// res % n == c * d % n /\ res <= (c - n) / r + n)
val mont_reduction_lemma_step_bound_aux:
pbits:pos -> n:pos -> q_i:nat{q_i < pow2 pbits} -> i:pos -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures res0 + n * q_i * pow2 (pbits * (i - 1)) <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound_aux pbits n q_i i c res0 =
let b = pow2 (pbits * i) in
let b1 = pow2 (pbits * (i - 1)) in
calc (<=) {
res0 + n * q_i * b1;
(<=) { Math.Lemmas.lemma_mult_le_right b1 q_i (pow2 pbits - 1) }
res0 + n * (pow2 pbits - 1) * b1;
(==) { Math.Lemmas.paren_mul_right n (pow2 pbits - 1) b1 }
res0 + n * ((pow2 pbits - 1) * b1);
(==) { Math.Lemmas.distributivity_sub_left (pow2 pbits) 1 b1 }
res0 + n * (pow2 pbits * b1 - b1);
(==) { Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
res0 + n * (b - b1);
(==) { Math.Lemmas.distributivity_sub_right n b b1 }
res0 + n * b - n * b1;
(<=) { }
c + (b1 - 1) * n + n * b - n * b1;
(==) { Math.Lemmas.distributivity_sub_left b1 1 n }
c + b1 * n - n + n * b - n * b1;
(==) { }
c - n + b * n;
(==) { Math.Lemmas.distributivity_sub_left b 1 n }
c + (b - 1) * n;
}
val mont_reduction_lemma_step_bound:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 <= c + (pow2 (pbits * i) - 1) * n)
let mont_reduction_lemma_step_bound pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
mont_reduction_lemma_step_bound_aux pbits n q_i i c res0;
assert (res <= c + (pow2 (pbits * i) - 1) * n)
val mont_reduction_lemma_step_mod_pbits: pbits:pos -> n:pos -> mu:nat -> c_i:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (c_i + n * (mu * c_i % pow2 pbits)) % pow2 pbits == 0)
let mont_reduction_lemma_step_mod_pbits pbits n mu c_i =
let r = pow2 pbits in
let q_i = mu * c_i % r in
calc (==) {
(c_i + n * q_i) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * q_i) r }
(c_i + n * q_i % r) % r;
(==) { }
(c_i + n * (mu * c_i % r) % r) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_r n (mu * c_i) r }
(c_i + n * (mu * c_i) % r) % r;
(==) { Math.Lemmas.lemma_mod_plus_distr_r c_i (n * (mu * c_i)) r }
(c_i + n * (mu * c_i)) % r;
(==) { Math.Lemmas.paren_mul_right n mu c_i }
(c_i + n * mu * c_i) % r;
(==) { Math.Lemmas.distributivity_add_left 1 (n * mu) c_i }
((1 + n * mu) * c_i) % r;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (1 + n * mu) c_i r }
((1 + n * mu) % r * c_i) % r;
(==) { assert ((1 + n * mu) % r = 0) }
0;
}
val mont_reduction_lemma_step_modr_aux: pbits:pos -> n:pos -> q_i:nat -> i:pos -> res0:nat ->
Lemma (let b1 = pow2 (pbits * (i - 1)) in
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i) == (res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1)
let mont_reduction_lemma_step_modr_aux pbits n q_i i res0 =
let b1 = pow2 (pbits * (i - 1)) in
Math.Lemmas.distributivity_sub_right pbits i 1;
assert (pbits * i - pbits * (i - 1) == pbits);
calc (==) {
(res0 / b1 * b1 + n * q_i * b1) % pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (res0 / b1) (n * q_i) b1 }
(res0 / b1 + n * q_i) * b1 % pow2 (pbits * i);
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (res0 / b1 + n * q_i) (pbits * i) (pbits * (i - 1)) }
(res0 / b1 + n * q_i) % pow2 pbits * b1;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (res0 / b1) (n * q_i) (pow2 pbits) }
(res0 / b1 % pow2 pbits + n * q_i) % pow2 pbits * b1;
}
val mont_reduction_lemma_step_modr:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> res0:nat -> Lemma
(requires res0 % pow2 (pbits * (i - 1)) == 0 /\ (1 + n * mu) % pow2 pbits == 0)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % pow2 (pbits * i) == 0)
let mont_reduction_lemma_step_modr pbits rLen n mu i res0 =
let b1 = pow2 (pbits * (i - 1)) in
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / b1 % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
Math.Lemmas.lemma_div_exact res0 b1;
mont_reduction_lemma_step_modr_aux pbits n q_i i res0;
mont_reduction_lemma_step_mod_pbits pbits n mu c_i
val mont_reduction_lemma_step_modn:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires res0 % n == c % n)
(ensures mont_reduction_f pbits rLen n mu (i - 1) res0 % n == c % n)
let mont_reduction_lemma_step_modn pbits rLen n mu i c res0 =
let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
let c_i = res0 / pow2 (pbits * (i - 1)) % pow2 pbits in
let q_i = mu * c_i % pow2 pbits in
assert (res == res0 + n * q_i * pow2 (pbits * (i - 1)));
Math.Lemmas.paren_mul_right n q_i (pow2 (pbits * (i - 1)));
Math.Lemmas.modulo_addition_lemma res0 n (q_i * pow2 (pbits * (i - 1)))
val mont_reduction_lemma_step:
pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:pos{i <= rLen} -> c:nat -> res0:nat -> Lemma
(requires
res0 % n == c % n /\ res0 % pow2 (pbits * (i - 1)) == 0 /\
res0 <= c + (pow2 (pbits * (i - 1)) - 1) * n /\ (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = mont_reduction_f pbits rLen n mu (i - 1) res0 in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let mont_reduction_lemma_step pbits rLen n mu i c res0 =
mont_reduction_lemma_step_bound pbits rLen n mu i c res0;
mont_reduction_lemma_step_modr pbits rLen n mu i res0;
mont_reduction_lemma_step_modn pbits rLen n mu i c res0
val mont_reduction_loop_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> i:nat{i <= rLen} -> c:nat -> Lemma
(requires (1 + n * mu) % pow2 pbits == 0)
(ensures (let res = repeati i (mont_reduction_f pbits rLen n mu) c in
res % n == c % n /\ res % pow2 (pbits * i) == 0 /\ res <= c + (pow2 (pbits * i) - 1) * n))
let rec mont_reduction_loop_lemma pbits rLen n mu i c =
let res : nat = repeati i (mont_reduction_f pbits rLen n mu) c in
if i = 0 then
eq_repeati0 i (mont_reduction_f pbits rLen n mu) c
else begin
unfold_repeati i (mont_reduction_f pbits rLen n mu) c (i - 1);
let res0 : nat = repeati (i - 1) (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu (i - 1) c;
mont_reduction_lemma_step pbits rLen n mu i c res0 end
val mont_reduction_loop_div_r_fits_lemma: pbits:pos -> rLen:nat -> n:pos -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
res <= (c - n) / r + n))
let mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
Math.Lemmas.lemma_div_le res (c + (r - 1) * n) r;
assert (res / r <= (c + (r - 1) * n) / r);
calc (==) {
(c + (r - 1) * n) / r;
(==) { Math.Lemmas.distributivity_sub_left r 1 n }
(c - n + r * n) / r;
(==) { Math.Lemmas.division_addition_lemma (c - n) r n }
(c - n) / r + n;
};
assert (res / r <= (c - n) / r + n)
val mont_reduction_loop_div_r_eval_lemma: pbits:pos -> rLen:nat -> n:pos -> d:int -> mu:nat -> c:nat -> Lemma
(requires (let r = pow2 (pbits * rLen) in
(1 + n * mu) % pow2 pbits == 0 /\ r * d % n == 1))
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
res % n == c * d % n))
let mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c =
let r = pow2 (pbits * rLen) in
let res : nat = repeati rLen (mont_reduction_f pbits rLen n mu) c in
mont_reduction_loop_lemma pbits rLen n mu rLen c;
assert (res % n == c % n /\ res % r == 0 /\ res <= c + (r - 1) * n);
calc (==) {
res / r % n;
(==) { assert (r * d % n == 1) }
res / r * (r * d % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (res / r) (r * d) n }
res / r * (r * d) % n;
(==) { Math.Lemmas.paren_mul_right (res / r) r d }
res / r * r * d % n;
(==) { Math.Lemmas.div_exact_r res r }
res * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l res d n }
res % n * d % n;
(==) { assert (res % n == c % n) }
c % n * d % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l c d n }
c * d % n;
};
assert (res / r % n == c * d % n)
let mont_pre (pbits:pos) (rLen:pos) (n:pos) (mu:nat) =
(1 + n * mu) % pow2 pbits == 0 /\
1 < n /\ n < pow2 (pbits * rLen) /\ n % 2 = 1
val mont_reduction_loop_div_r_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires mont_pre pbits rLen n mu)
(ensures (let res = mont_reduction_loop_div_r pbits rLen n mu c in
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
res % n == c * d % n /\ res <= (c - n) / r + n))
let mont_reduction_loop_div_r_lemma pbits rLen n mu c =
let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_preconditions_d pbits rLen n;
mont_reduction_loop_div_r_fits_lemma pbits rLen n mu c;
mont_reduction_loop_div_r_eval_lemma pbits rLen n d mu c
/// Montgomery multiplication
val lemma_fits_c_lt_rn: c:nat -> r:pos -> n:pos -> Lemma
(requires c < r * n)
(ensures (c - n) / r < n)
let lemma_fits_c_lt_rn c r n =
assert (c < r * n);
Math.Lemmas.cancel_mul_div n r;
assert (c / r < n);
Math.Lemmas.lemma_div_le (c - n) c r
val mont_reduction_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> c:nat -> Lemma
(requires
mont_pre pbits rLen n mu /\ c < pow2 (pbits * rLen) * n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_reduction pbits rLen n mu c == c * d % n))
let mont_reduction_lemma pbits rLen n mu c =
let r = pow2 (pbits * rLen) in
let d, _ = eea_pow2_odd (pbits * rLen) n in
let res = mont_reduction_loop_div_r pbits rLen n mu c in
mont_reduction_loop_div_r_lemma pbits rLen n mu c;
assert (res % n == c * d % n /\ res <= (c - n) / r + n);
let res1 = if res < n then res else res - n in
if res < n then ()
else begin
assert (res1 % n == (res - n) % n);
Math.Lemmas.lemma_mod_sub res n 1;
assert (res1 % n == res % n);
assert (res1 <= (c - n) / r);
lemma_fits_c_lt_rn c r n end;
Math.Lemmas.small_mod res1 n
val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n)) | false | false | Hacl.Spec.Montgomery.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mont_mul_lemma: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> a:nat -> b:nat -> Lemma
(requires mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures (let d, _ = eea_pow2_odd (pbits * rLen) n in
mont_mul pbits rLen n mu a b == a * b * d % n)) | [] | Hacl.Spec.Montgomery.Lemmas.mont_mul_lemma | {
"file_name": "code/bignum/Hacl.Spec.Montgomery.Lemmas.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | pbits: Prims.pos -> rLen: Prims.pos -> n: Prims.pos -> mu: Prims.nat -> a: Prims.nat -> b: Prims.nat
-> FStar.Pervasives.Lemma
(requires Hacl.Spec.Montgomery.Lemmas.mont_pre pbits rLen n mu /\ a < n /\ b < n)
(ensures
(let _ = Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd (pbits * rLen) n in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ d _ = _ in
Hacl.Spec.Montgomery.Lemmas.mont_mul pbits rLen n mu a b == (a * b) * d % n)
<:
Type0)) | {
"end_col": 46,
"end_line": 522,
"start_col": 40,
"start_line": 514
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.