Skip to content

Commit be9545f

Browse files
committed
m
1 parent 3d077b8 commit be9545f

File tree

2 files changed

+28
-35
lines changed

2 files changed

+28
-35
lines changed

DynamoDbEncryption/dafny/DynamoDbEncryption/src/CompoundBeacon.dfy

+22-29
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module CompoundBeacon {
1414
import opened AwsCryptographyDbEncryptionSdkDynamoDbTypes
1515
import opened DynamoDbEncryptionUtil
1616
import opened DdbVirtualFields
17-
import opened MemoryMath
1817

1918
import Prim = AwsCryptographyPrimitivesTypes
2019
import Primitives = AtomicPrimitives
@@ -91,11 +90,11 @@ module CompoundBeacon {
9190
base : BeaconBase,
9291
split : char,
9392
parts : seq<BeaconPart>, // Signed followed by Encrypted
94-
numSigned : uint64,
93+
numSigned : nat,
9594
construct : ConstructorList
9695
)
9796
: (ret : Result<ValidCompoundBeacon, Error>)
98-
requires numSigned as nat <= |parts|
97+
requires numSigned <= |parts|
9998
requires OrderedParts(parts, numSigned)
10099

101100
//= specification/searchable-encryption/beacons.md#initialization-failure
@@ -111,36 +110,34 @@ module CompoundBeacon {
111110

112111
// are the parts properly ordered?
113112
// that is, with the signed parts followed the encrypted parts
114-
predicate OrderedParts(p : seq<BeaconPart>, n : uint64)
115-
requires n as nat <= |p|
113+
predicate OrderedParts(p : seq<BeaconPart>, n : nat)
114+
requires n <= |p|
116115
{
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?)
116+
&& (forall x | 0 <= x < n :: p[x].Signed?)
117+
&& (forall x | n <= x < |p| :: p[x].Encrypted?)
120118
}
121119

122120
datatype CompoundBeacon = CompoundBeacon(
123121
base : BeaconBase,
124122
split : char,
125123
parts : seq<BeaconPart>,
126-
numSigned : uint64,
124+
numSigned : nat,
127125
construct : ConstructorList
128126
) {
129127

130128
predicate ValidState()
131129
{
132130
&& ValidPrefixSet()
133-
&& numSigned as nat <= |parts|
131+
&& numSigned <= |parts|
134132
&& OrderedParts(parts, numSigned)
135133
}
136134

137135
// no prefix is a prefix of another prefix
138136
// that is, no ambiguity when determining which prefix is used in a value
139137
predicate ValidPrefixSet()
140138
{
141-
SequenceIsSafeBecauseItIsInMemory(parts);
142-
forall x : uint64, y : uint64
143-
| 0 <= x < |parts| as uint64 && x < y < |parts| as uint64
139+
forall x : nat, y : nat
140+
| 0 <= x < |parts| && x < y < |parts|
144141
:: OkPrefixPair(x, y)
145142
}
146143

@@ -163,8 +160,7 @@ module CompoundBeacon {
163160

164161
// Does this beacon have any encrypted parts
165162
predicate method isEncrypted() {
166-
SequenceIsSafeBecauseItIsInMemory(parts);
167-
numSigned < |parts| as uint64
163+
numSigned < |parts|
168164
}
169165

170166
// find the part whose prefix matches this value
@@ -513,9 +509,9 @@ module CompoundBeacon {
513509
}
514510

515511
// true is neither part's prefix is a prefix of the other
516-
predicate method OkPrefixPair(pos1 : uint64, pos2 : uint64)
517-
requires pos1 as nat < |parts|
518-
requires pos2 as nat< |parts|
512+
predicate method OkPrefixPair(pos1 : nat, pos2 : nat)
513+
requires pos1 < |parts|
514+
requires pos2 < |parts|
519515
{
520516
|| pos1 == pos2
521517
|| OkPrefixStringPair(parts[pos1].prefix, parts[pos2].prefix)
@@ -525,10 +521,9 @@ module CompoundBeacon {
525521
function method CheckOnePrefixPart(pos1 : nat, pos2 : nat) : (ret : Result<bool, Error>)
526522
requires pos1 < |parts|
527523
requires pos2 < |parts|
528-
ensures ret.Success? ==> HasUint64Len(parts) && OkPrefixPair(pos1 as uint64, pos2 as uint64)
524+
ensures ret.Success? ==> OkPrefixPair(pos1, pos2)
529525
{
530-
SequenceIsSafeBecauseItIsInMemory(parts);
531-
if !OkPrefixPair(pos1 as uint64, pos2 as uint64) then
526+
if !OkPrefixPair(pos1, pos2) then
532527
Failure(E("Compound beacon " + base.name + " defines part " + parts[pos1].getName() + " with prefix " + parts[pos1].prefix
533528
+ " which is incompatible with part " + parts[pos2].getName() + " which has a prefix of " + parts[pos2].prefix + "."))
534529
else
@@ -545,25 +540,23 @@ module CompoundBeacon {
545540
}
546541

547542
// error if any part's prefix is a prefix of another part's prefix
548-
function method {:tailrecursion} ValidPrefixSetResultPos(index : uint64) : (ret : Result<bool, Error>)
549-
decreases |parts| - index as nat
543+
function method {:tailrecursion} ValidPrefixSetResultPos(index : nat) : (ret : Result<bool, Error>)
544+
decreases |parts| - index
550545
{
551-
SequenceIsSafeBecauseItIsInMemory(parts);
552-
if |parts| as uint64 <= index then
546+
if |parts| <= index then
553547
Success(true)
554548
else
555-
var _ :- CheckOnePrefix(index as nat);
549+
var _ :- CheckOnePrefix(index);
556550
ValidPrefixSetResultPos(index+1)
557551
}
558552

559553
// error if any part's prefix is a prefix of another part's prefix
560554
function method ValidPrefixSetResult() : (ret : Result<bool, Error>)
561555
ensures ret.Success? ==> ValidPrefixSet() && ret.value
562556
{
563-
SequenceIsSafeBecauseItIsInMemory(parts);
564557
var _ :- ValidPrefixSetResultPos(0);
565-
if forall x : uint64, y : uint64
566-
| 0 <= x < |parts| as uint64 && x < y < |parts| as uint64
558+
if forall x : nat, y : nat
559+
| 0 <= x < |parts| && x < y < |parts|
567560
:: OkPrefixPair(x, y) then
568561
Success(true)
569562
else

DynamoDbEncryption/dafny/DynamoDbEncryption/src/ConfigToInfo.dfy

+6-6
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ module SearchConfigToInfo {
766766
requires |allParts| == |parts| + |converted|
767767
requires parts == allParts[|converted|..]
768768
requires numNon as nat <= |allParts|
769-
requires CB.OrderedParts(allParts, numNon)
769+
requires CB.OrderedParts(allParts, numNon as nat)
770770
requires forall i | 0 <= i < |converted| ::
771771
&& converted[i].part == allParts[i]
772772
&& converted[i].required
@@ -777,7 +777,7 @@ module SearchConfigToInfo {
777777
//= type=implication
778778
//# * This default constructor MUST be all of the signed parts,
779779
//# followed by all the encrypted parts, all parts being required.
780-
&& CB.OrderedParts(allParts, numNon)
780+
&& CB.OrderedParts(allParts, numNon as nat)
781781
&& (forall i | 0 <= i < |ret.value[0].parts| ::
782782
&& ret.value[0].parts[i].part == allParts[i]
783783
&& ret.value[0].parts[i].required)
@@ -894,7 +894,7 @@ module SearchConfigToInfo {
894894
requires 0 < |parts|
895895
requires constructors.Some? ==> 0 < |constructors.value|
896896
requires numSigned as nat <= |parts|
897-
requires CB.OrderedParts(parts, numSigned)
897+
requires CB.OrderedParts(parts, numSigned as nat)
898898
ensures ret.Success? ==>
899899
&& (constructors.None? ==> |ret.value| == 1)
900900
&& (constructors.Some? ==> |ret.value| == |constructors.value|)
@@ -1068,9 +1068,9 @@ module SearchConfigToInfo {
10681068

10691069
SequenceIsSafeBecauseItIsInMemory(signed);
10701070
var numNon := |signed| as uint64;
1071-
assert CB.OrderedParts(signed, numNon);
1071+
assert CB.OrderedParts(signed, numNon as nat);
10721072
var allParts := signed + encrypted;
1073-
assert CB.OrderedParts(allParts, numNon);
1073+
assert CB.OrderedParts(allParts, numNon as nat);
10741074

10751075
var isSignedBeacon := |encrypted| == 0;
10761076
var _ :- BeaconNameAllowed(outer, virtualFields, beacon.name, "CompoundBeacon", isSignedBeacon);
@@ -1089,7 +1089,7 @@ module SearchConfigToInfo {
10891089
),
10901090
beacon.split[0],
10911091
allParts,
1092-
numNon,
1092+
numNon as nat,
10931093
constructors
10941094
)
10951095
}

0 commit comments

Comments
 (0)