Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit 9445ac8

Browse files
authored
Merge pull request #228 from project-everest/adl_memory_model
Update memory model (see #227)
2 parents 5d0b35f + bfef255 commit 9445ac8

29 files changed

+1922
-1278
lines changed

src/parsers/Parsers.rfc

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,7 @@ struct {
12241224
opaque SessionID<0..32>;
12251225

12261226
enum /*@open*/ { nullCompression(0), (255) } CompressionMethod;
1227+
enum { nullCompression(0), (255) } LegacyCompression;
12271228

12281229
/** Shared Handshake Message Types **/
12291230

@@ -1232,18 +1233,62 @@ struct {
12321233
Random random;
12331234
SessionID session_id;
12341235
CipherSuite cipher_suites<2..2^16-2>;
1235-
CompressionMethod compression_method<1..2^8-1>;
1236+
CompressionMethod compression_methods<1..2^8-1>;
12361237
ClientHelloExtensions extensions;
12371238
} ClientHello;
12381239

1240+
struct {
1241+
SessionID session_id;
1242+
CipherSuite cipher_suite;
1243+
CompressionMethod compression_method;
1244+
ServerHelloExtensions extensions;
1245+
} SHKind;
1246+
1247+
struct {
1248+
SessionID session_id;
1249+
CipherSuite cipher_suite;
1250+
LegacyCompression legacy_compression;
1251+
HRRExtensions extensions;
1252+
} HRRKind;
1253+
1254+
/*
1255+
We need to change the definition of the ServerHello
1256+
type to account for the syntactic differences between
1257+
ServerHello and HelloRetryRequest.
1258+
1259+
In a HRR, the compression_method must be null and the
1260+
format of some extensions is different (e.g. key_share
1261+
is a KeyShareEntry in SH and a GroupName in HRR)
1262+
*/
1263+
struct {
1264+
ProtocolVersion version;
1265+
opaque random[32];
1266+
(if random = "CF21AD74E59A6111BE1D8C021E65B891C2A211167ABB8C5E079E09E2C8A8339C"
1267+
HRRKind
1268+
else
1269+
SHKind) is_hrr;
1270+
} ServerHello;
1271+
1272+
/*
1273+
Using an if-then-else type is annoying, in the specification
1274+
of the handshake we want to convert it to either SH or HRR.
1275+
*/
12391276
struct {
12401277
ProtocolVersion version;
12411278
Random random;
12421279
SessionID session_id;
12431280
CipherSuite cipher_suite;
12441281
CompressionMethod compression_method;
12451282
ServerHelloExtensions extensions;
1246-
} ServerHello;
1283+
} RealServerHello;
1284+
1285+
struct {
1286+
ProtocolVersion version;
1287+
SessionID session_id;
1288+
CipherSuite cipher_suite;
1289+
LegacyCompression legacy_compression;
1290+
HRRExtensions extensions;
1291+
} HelloRetryRequest;
12471292

12481293
/** TLS 1.3 Handshake Messages */
12491294

src/tls/Crypto.CRF.fst

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Crypto.CRF
22

33
module Concrete = EverCrypt.Hash.Incremental
44
module Hash = EverCrypt.Hash
5+
module HD = Spec.Hash.Definitions
56

67
module B = LowStar.Buffer
78
module ST = FStar.HyperStack.ST
@@ -53,69 +54,59 @@ assume val of_seq
5354
/// ---------------------------
5455

5556
/// This is very finely tuned to avoid inference issues.
56-
type mstate a = a': Concrete.alg { a' == a } & p:B.pointer bytes {
57+
type mstate a = a': alg { a' == a } & p:B.pointer bytes {
5758
B.(loc_disjoint (loc_addr_of_buffer p) (loc_region_only true Mem.tls_tables_region))
5859
}
5960

6061
inline_for_extraction
61-
let state (a: Concrete.alg) =
62+
let state (a: alg) =
6263
if model then
6364
mstate a
6465
else
6566
Concrete.state a
6667

67-
// UGH!!!
68-
noextract inline_for_extraction
69-
let fst (#a: e_alg) (s: state (G.reveal a){model}):
70-
Tot (a': Concrete.alg { G.reveal a == a' })
71-
=
72-
if model then
73-
let (| a, s |) = (s <: mstate (G.reveal a)) in
74-
a
75-
else
76-
false_elim ()
77-
78-
noextract inline_for_extraction
79-
let snd (#a: e_alg) (s: state (G.reveal a){model}):
80-
Tot (p:B.pointer bytes {
81-
B.(loc_disjoint (loc_addr_of_buffer p) (loc_region_only true Mem.tls_tables_region))
82-
})
83-
=
84-
if model then
85-
let (| a, s |) = (s <: mstate (G.reveal a)) in
86-
s
87-
else
88-
false_elim ()
68+
noextract let ideal (#a:alg) (s:state a)
69+
: Pure (mstate a) (requires model) (ensures fun _ -> True)
70+
= s
71+
noextract let gideal (#a:e_alg) (s:state (G.reveal a))
72+
: Pure (mstate (G.reveal a)) (requires model) (ensures fun _ -> True)
73+
= s
74+
75+
inline_for_extraction noextract let real (#a:alg) (s:state a)
76+
: Pure (Concrete.state a) (requires not model) (ensures fun _ -> True)
77+
= s
78+
inline_for_extraction noextract let greal (#a:e_alg) (s:state (G.reveal a))
79+
: Pure (Concrete.state (G.reveal a)) (requires not model) (ensures fun _ -> True)
80+
= s
8981

9082
let freeable #a h (s:state a) =
9183
if model then
92-
let s: B.pointer bytes = snd #(G.hide a) s in
84+
let (| a, s |) = ideal s in
9385
B.freeable s
9486
else
95-
Concrete.freeable #a h s
87+
Concrete.freeable h (real s)
9688

9789
let footprint #a h (s: state a) =
9890
if model then
99-
B.loc_addr_of_buffer (snd #(G.hide a) s)
91+
B.loc_addr_of_buffer (dsnd (ideal s))
10092
else
101-
Concrete.footprint #a h s
93+
Concrete.footprint h (real s)
10294

10395
let invariant #a h (s: state a) =
10496
if model then
105-
let s: B.pointer bytes = snd #(G.hide a) s in
97+
let (| _, s |) = ideal s in
10698
B.live h s /\ S.length (B.deref h s) < pow2 61
10799
else
108-
Concrete.invariant #a h s
100+
Concrete.invariant h (real s)
109101

110102
let invariant_loc_in_footprint #_ _ _ = ()
111103

112104
let hashed #a h (s: state a) =
113105
if model then
114-
let s: B.pointer bytes = snd #(G.hide a) s in
106+
let (| _, s |) = ideal s in
115107
B.deref h s
116108
else
117-
let s: Concrete.state a = s in
118-
Concrete.hashed h s
109+
Concrete.hashed h (real s)
119110

120111
#push-options "--max_ifuel 1"
121112
let hash_fits #_ _ _ =
@@ -141,25 +132,23 @@ let create_in a r =
141132
let init a s =
142133
let open LowStar.BufferOps in
143134
if model then
144-
let s: B.pointer bytes = snd s in
145-
s *= S.empty
135+
dsnd (gideal s) *= S.empty
146136
else
147-
Concrete.init a s
137+
Concrete.init a (greal s)
148138

149139
let update a s data len =
150140
let open LowStar.BufferOps in
151141
if model then
152-
let s: B.pointer bytes = snd s in
142+
let (| _, s |) = gideal s in
153143
s *= (S.append !*s (to_seq data len))
154144
else
155-
Concrete.update a s data len
145+
Concrete.update a (greal s) data len
156146

157147
#push-options "--z3rlimit 50"
158148
let finish a st dst =
159149
let open LowStar.BufferOps in
160150
if model then
161-
let a = fst #a st in
162-
let s: B.pointer bytes = snd st in
151+
let (| a, s |) = gideal st in
163152
(**) assert B.(loc_disjoint (B.loc_addr_of_buffer s)
164153
(B.loc_region_only true Mem.tls_tables_region));
165154
(**) let h0 = ST.get () in
@@ -175,7 +164,6 @@ let finish a st dst =
175164

176165
let free a s =
177166
if model then
178-
B.free (snd s)
167+
B.free (dsnd (gideal s))
179168
else
180169
Concrete.free a s
181-

src/tls/Crypto.CRF.fsti

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Crypto.CRF
1212

1313
module Concrete = EverCrypt.Hash.Incremental
1414
module Hash = EverCrypt.Hash
15+
module HD = Spec.Hash.Definitions
1516

1617
module B = LowStar.Buffer
1718
module ST = FStar.HyperStack.ST
@@ -20,6 +21,7 @@ module S = FStar.Seq
2021
module U32 = FStar.UInt32
2122
module G = FStar.Ghost
2223

24+
open Mem
2325
open FStar.HyperStack.ST
2426

2527
inline_for_extraction
@@ -51,45 +53,45 @@ unfold noextract
5153
let bytes = Model.CRF.bytes
5254

5355
unfold noextract
54-
let e_alg = Concrete.e_alg
56+
let alg = Concrete.alg
5557

5658
unfold noextract
57-
let fresh_loc = Concrete.fresh_loc
59+
let e_alg = Concrete.e_alg
5860

5961
/// Overriding things
6062
/// -----------------
6163

6264
inline_for_extraction
63-
val state: Concrete.alg -> Type0
65+
val state: alg -> Type0
6466

65-
val freeable: #a:Concrete.alg -> HS.mem -> state a -> Type0
67+
val freeable: #a:alg -> HS.mem -> state a -> Type0
6668

6769
let preserves_freeable #a (s: state a) (h0 h1: HS.mem) =
6870
freeable h0 s ==> freeable h1 s
6971

70-
val footprint: #a:Concrete.alg -> HS.mem -> state a -> GTot B.loc
72+
val footprint: #a:alg -> HS.mem -> state a -> GTot B.loc
7173

72-
val invariant: #a:Concrete.alg -> HS.mem -> state a -> Type0
74+
val invariant: #a:alg -> HS.mem -> state a -> Type0
7375

7476
val invariant_loc_in_footprint
75-
(#a: Concrete.alg)
77+
(#a: alg)
7678
(s: state a)
7779
(m: HS.mem)
7880
: Lemma
7981
(requires (invariant m s))
80-
(ensures (Concrete.loc_in (footprint m s) m))
82+
(ensures (loc_in (footprint m s) m))
8183
[SMTPat (invariant m s)]
8284

83-
val hashed: #a:Concrete.alg -> HS.mem -> state a -> GTot bytes
85+
val hashed: #a:alg -> HS.mem -> state a -> GTot bytes
8486

85-
val hash_fits (#a:Hash.alg) (h:HS.mem) (s:state a): Lemma
87+
val hash_fits (#a:alg) (h:HS.mem) (s:state a): Lemma
8688
(requires (
8789
invariant h s))
8890
(ensures (
89-
S.length (hashed h s) < Spec.Hash.Definitions.max_input_length a))
91+
S.length (hashed h s) < HD.max_input_length a))
9092
[ SMTPat (hashed h s) ]
9193

92-
val frame_invariant (#a: Concrete.alg) (l: B.loc) (s: state a) (h0 h1: HS.mem): Lemma
94+
val frame_invariant (#a: alg) (l: B.loc) (s: state a) (h0 h1: HS.mem): Lemma
9395
(requires (
9496
invariant h0 s /\
9597
B.loc_disjoint l (footprint h0 s) /\
@@ -99,15 +101,15 @@ val frame_invariant (#a: Concrete.alg) (l: B.loc) (s: state a) (h0 h1: HS.mem):
99101
footprint h0 s == footprint h1 s))
100102
[ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ]
101103

102-
val frame_hashed (#a: Concrete.alg) (l: B.loc) (s: state a) (h0 h1: HS.mem): Lemma
104+
val frame_hashed (#a: alg) (l: B.loc) (s: state a) (h0 h1: HS.mem): Lemma
103105
(requires (
104106
invariant h0 s /\
105107
B.loc_disjoint l (footprint h0 s) /\
106108
B.modifies l h0 h1))
107109
(ensures (hashed h0 s == hashed h1 s))
108110
[ SMTPat (hashed h1 s); SMTPat (B.modifies l h0 h1) ]
109111

110-
val frame_freeable (#a: Concrete.alg) (l: B.loc) (s: state a) (h0 h1: HS.mem): Lemma
112+
val frame_freeable (#a: alg) (l: B.loc) (s: state a) (h0 h1: HS.mem): Lemma
111113
(requires (
112114
invariant h0 s /\
113115
freeable h0 s /\
@@ -121,7 +123,7 @@ val frame_freeable (#a: Concrete.alg) (l: B.loc) (s: state a) (h0 h1: HS.mem): L
121123

122124
(** @type: true
123125
*)
124-
val create_in (a: Hash.alg) (r: HS.rid): ST (state a)
126+
val create_in (a: alg) (r: HS.rid): ST (state a)
125127
(requires (fun _ ->
126128
// NEW! ↓
127129
B.(loc_disjoint (loc_region_only true r) (loc_region_only true Mem.tls_tables_region)) /\

0 commit comments

Comments
 (0)