@@ -14,6 +14,7 @@ module CompoundBeacon {
1414 import opened AwsCryptographyDbEncryptionSdkDynamoDbTypes
1515 import opened DynamoDbEncryptionUtil
1616 import opened DdbVirtualFields
17+ import opened MemoryMath
1718
1819 import Prim = AwsCryptographyPrimitivesTypes
1920 import Primitives = AtomicPrimitives
@@ -90,11 +91,11 @@ module CompoundBeacon {
9091 base : BeaconBase ,
9192 split : char ,
9293 parts : seq <BeaconPart >, // Signed followed by Encrypted
93- numSigned : nat ,
94+ numSigned : uint64 ,
9495 construct : ConstructorList
9596 )
9697 : (ret : Result< ValidCompoundBeacon, Error> )
97- requires numSigned <= |parts|
98+ requires numSigned as nat <= |parts|
9899 requires OrderedParts (parts, numSigned)
99100
100101 // = specification/searchable-encryption/beacons.md#initialization-failure
@@ -110,34 +111,36 @@ module CompoundBeacon {
110111
111112 // are the parts properly ordered?
112113 // 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|
115116 {
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?)
118120 }
119121
120122 datatype CompoundBeacon = CompoundBeacon (
121123 base : BeaconBase ,
122124 split : char ,
123125 parts : seq <BeaconPart >,
124- numSigned : nat ,
126+ numSigned : uint64 ,
125127 construct : ConstructorList
126128 ) {
127129
128130 predicate ValidState ()
129131 {
130132 && ValidPrefixSet ()
131- && numSigned <= |parts|
133+ && numSigned as nat <= |parts|
132134 && OrderedParts (parts, numSigned)
133135 }
134136
135137 // no prefix is a prefix of another prefix
136138 // that is, no ambiguity when determining which prefix is used in a value
137139 predicate ValidPrefixSet ()
138140 {
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
141144 :: OkPrefixPair (x, y)
142145 }
143146
@@ -160,7 +163,8 @@ module CompoundBeacon {
160163
161164 // Does this beacon have any encrypted parts
162165 predicate method isEncrypted () {
163- numSigned < |parts|
166+ SequenceIsSafeBecauseItIsInMemory (parts);
167+ numSigned < |parts| as uint64
164168 }
165169
166170 // find the part whose prefix matches this value
@@ -509,18 +513,18 @@ module CompoundBeacon {
509513 }
510514
511515 // 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|
515519 {
516520 || pos1 == pos2
517521 || OkPrefixStringPair (parts[pos1].prefix, parts[pos2].prefix)
518522 }
519523
520524 // 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|
524528 ensures ret. Success? ==> OkPrefixPair (pos1, pos2)
525529 {
526530 if ! OkPrefixPair (pos1, pos2) then
@@ -534,29 +538,32 @@ module CompoundBeacon {
534538 function method CheckOnePrefix (pos : nat ) : (ret : Result< bool , Error> )
535539 requires pos < |parts|
536540 {
541+ SequenceIsSafeBecauseItIsInMemory (parts);
537542 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));
539544 Success (true)
540545 }
541546
542547 // 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
545550 {
546- if |parts| <= index then
551+ SequenceIsSafeBecauseItIsInMemory (parts);
552+ if |parts| as uint64 <= index then
547553 Success (true)
548554 else
549- var _ :- CheckOnePrefix (index);
555+ var _ :- CheckOnePrefix (index as nat );
550556 ValidPrefixSetResultPos (index+1)
551557 }
552558
553559 // error if any part's prefix is a prefix of another part's prefix
554560 function method ValidPrefixSetResult () : (ret : Result< bool , Error> )
555561 ensures ret. Success? ==> ValidPrefixSet () && ret. value
556562 {
563+ SequenceIsSafeBecauseItIsInMemory (parts);
557564 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
560567 :: OkPrefixPair (x, y) then
561568 Success (true)
562569 else
0 commit comments