@@ -14,6 +14,7 @@ module CompoundBeacon {
14
14
import opened AwsCryptographyDbEncryptionSdkDynamoDbTypes
15
15
import opened DynamoDbEncryptionUtil
16
16
import opened DdbVirtualFields
17
+ import opened MemoryMath
17
18
18
19
import Prim = AwsCryptographyPrimitivesTypes
19
20
import Primitives = AtomicPrimitives
@@ -90,11 +91,11 @@ module CompoundBeacon {
90
91
base : BeaconBase ,
91
92
split : char ,
92
93
parts : seq <BeaconPart >, // Signed followed by Encrypted
93
- numSigned : nat ,
94
+ numSigned : uint64 ,
94
95
construct : ConstructorList
95
96
)
96
97
: (ret : Result< ValidCompoundBeacon, Error> )
97
- requires numSigned <= |parts|
98
+ requires numSigned as nat <= |parts|
98
99
requires OrderedParts (parts, numSigned)
99
100
100
101
// = specification/searchable-encryption/beacons.md#initialization-failure
@@ -110,34 +111,36 @@ module CompoundBeacon {
110
111
111
112
// are the parts properly ordered?
112
113
// that is, with the signed parts followed the encrypted parts
113
- predicate OrderedParts (p : seq <BeaconPart >, n : nat )
114
- requires n <= |p|
114
+ predicate OrderedParts (p : seq <BeaconPart >, n : uint64 )
115
+ requires n as nat <= |p|
115
116
{
116
- && (forall x | 0 <= x < n :: p[x]. Signed?)
117
- && (forall x | n <= x < |p| :: p[x]. Encrypted?)
117
+ SequenceIsSafeBecauseItIsInMemory (p);
118
+ && (forall x : uint64 | 0 <= x < n :: p[x]. Signed?)
119
+ && (forall x : uint64 | n <= x < |p| as uint64 :: p[x]. Encrypted?)
118
120
}
119
121
120
122
datatype CompoundBeacon = CompoundBeacon (
121
123
base : BeaconBase ,
122
124
split : char ,
123
125
parts : seq <BeaconPart >,
124
- numSigned : nat ,
126
+ numSigned : uint64 ,
125
127
construct : ConstructorList
126
128
) {
127
129
128
130
predicate ValidState ()
129
131
{
130
132
&& ValidPrefixSet ()
131
- && numSigned <= |parts|
133
+ && numSigned as nat <= |parts|
132
134
&& OrderedParts (parts, numSigned)
133
135
}
134
136
135
137
// no prefix is a prefix of another prefix
136
138
// that is, no ambiguity when determining which prefix is used in a value
137
139
predicate ValidPrefixSet ()
138
140
{
139
- forall x : nat , y : nat
140
- | 0 <= x < |parts| && x < y < |parts|
141
+ SequenceIsSafeBecauseItIsInMemory (parts);
142
+ forall x : uint64, y : uint64
143
+ | 0 <= x < |parts| as uint64 && x < y < |parts| as uint64
141
144
:: OkPrefixPair (x, y)
142
145
}
143
146
@@ -160,7 +163,8 @@ module CompoundBeacon {
160
163
161
164
// Does this beacon have any encrypted parts
162
165
predicate method isEncrypted () {
163
- numSigned < |parts|
166
+ SequenceIsSafeBecauseItIsInMemory (parts);
167
+ numSigned < |parts| as uint64
164
168
}
165
169
166
170
// find the part whose prefix matches this value
@@ -509,18 +513,18 @@ module CompoundBeacon {
509
513
}
510
514
511
515
// true is neither part's prefix is a prefix of the other
512
- predicate method OkPrefixPair (pos1 : nat , pos2 : nat )
513
- requires pos1 < |parts|
514
- requires pos2 < |parts|
516
+ predicate method OkPrefixPair (pos1 : uint64 , pos2 : uint64 )
517
+ requires pos1 as nat < |parts|
518
+ requires pos2 as nat < |parts|
515
519
{
516
520
|| pos1 == pos2
517
521
|| OkPrefixStringPair (parts[pos1].prefix, parts[pos2].prefix)
518
522
}
519
523
520
524
// OkPrefixPair, but return Result with error message
521
- function method CheckOnePrefixPart (pos1 : nat , pos2 : nat ) : (ret : Result< bool , Error> )
522
- requires pos1 < |parts|
523
- requires pos2 < |parts|
525
+ function method CheckOnePrefixPart (pos1 : uint64 , pos2 : uint64 ) : (ret : Result< bool , Error> )
526
+ requires pos1 as nat < |parts|
527
+ requires pos2 as nat < |parts|
524
528
ensures ret. Success? ==> OkPrefixPair (pos1, pos2)
525
529
{
526
530
if ! OkPrefixPair (pos1, pos2) then
@@ -534,29 +538,32 @@ module CompoundBeacon {
534
538
function method CheckOnePrefix (pos : nat ) : (ret : Result< bool , Error> )
535
539
requires pos < |parts|
536
540
{
541
+ SequenceIsSafeBecauseItIsInMemory (parts);
537
542
var partNumbers : seq < nat > := seq (|parts|, (i : nat ) => i as nat );
538
- var _ :- Sequence. MapWithResult ((p : int ) requires 0 <= p < |parts| => CheckOnePrefixPart (pos, p), seq (|parts|, i => i));
543
+ var _ :- Sequence. MapWithResult ((p : int ) requires 0 <= p < |parts| => CheckOnePrefixPart (pos as uint64 , p as uint64 ), seq (|parts|, i => i));
539
544
Success (true)
540
545
}
541
546
542
547
// error if any part's prefix is a prefix of another part's prefix
543
- function method {:tailrecursion} ValidPrefixSetResultPos (index : nat ) : (ret : Result< bool , Error> )
544
- decreases |parts| - index
548
+ function method {:tailrecursion} ValidPrefixSetResultPos (index : uint64 ) : (ret : Result< bool , Error> )
549
+ decreases |parts| - index as nat
545
550
{
546
- if |parts| <= index then
551
+ SequenceIsSafeBecauseItIsInMemory (parts);
552
+ if |parts| as uint64 <= index then
547
553
Success (true)
548
554
else
549
- var _ :- CheckOnePrefix (index);
555
+ var _ :- CheckOnePrefix (index as nat );
550
556
ValidPrefixSetResultPos (index+1)
551
557
}
552
558
553
559
// error if any part's prefix is a prefix of another part's prefix
554
560
function method ValidPrefixSetResult () : (ret : Result< bool , Error> )
555
561
ensures ret. Success? ==> ValidPrefixSet () && ret. value
556
562
{
563
+ SequenceIsSafeBecauseItIsInMemory (parts);
557
564
var _ :- ValidPrefixSetResultPos (0);
558
- if forall x : nat , y : nat
559
- | 0 <= x < |parts| && x < y < |parts|
565
+ if forall x : uint64 , y : uint64
566
+ | 0 <= x < |parts| as uint64 && x < y < |parts| as uint64
560
567
:: OkPrefixPair (x, y) then
561
568
Success (true)
562
569
else
0 commit comments