Skip to content

Commit 046489a

Browse files
committed
m
1 parent 9b0df5c commit 046489a

File tree

10 files changed

+281
-179
lines changed

10 files changed

+281
-179
lines changed

DynamoDbEncryption/dafny/DynamoDbEncryption/src/CompoundBeacon.dfy

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,16 @@ module CompoundBeacon {
132132
&& OrderedParts(parts, numSigned)
133133
}
134134

135-
function method getNumQueries(globalMax : BucketCount) : BucketCount
136-
{
137-
var counts := GetBucketCountsFromValue(DDB.AttributeValue.S(""));
138-
if counts.Failure? then
139-
1
140-
else
141-
lcmSeq(counts.value, globalMax)
135+
method getNumQueries(globalMax : BucketCount, value : string) returns (output : BucketCount)
136+
ensures output <= globalMax
137+
{
138+
var counts := GetBucketCountsFromValue(DDB.AttributeValue.S(value));
139+
if counts.Failure? {
140+
return 1;
141+
} else {
142+
output := lcmSeq(counts.value, globalMax);
143+
return;
144+
}
142145
}
143146

144147
// no prefix is a prefix of another prefix

DynamoDbEncryption/dafny/DynamoDbEncryption/src/DDBSupport.dfy

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ module DynamoDBSupport {
3232
import SET = AwsCryptographyDbEncryptionSdkStructuredEncryptionTypes
3333
import NN = DynamoDbNormalizeNumber
3434

35-
method GetNumberOfQueries(search : SearchableEncryptionInfo.BeaconVersion, actions : AttributeActions, query : DDB.QueryInput)
35+
method GetNumberOfQueries(search : SearchableEncryptionInfo.BeaconVersion, query : DDB.QueryInput)
3636
returns (output : Result<BucketCount, Error>)
3737
{
38-
// var numberOfQueries :- Filter.GetNumQueries(
39-
// actions,
40-
// query.FilterExpression,
41-
// query.ExpressionAttributeNames,
42-
// search
43-
// );
44-
return Success(1);
38+
var numberOfQueries :- Filter.GetNumQueries(
39+
search,
40+
query.KeyConditionExpression,
41+
query.ExpressionAttributeValues,
42+
query.ExpressionAttributeNames
43+
);
44+
return Success(numberOfQueries);
4545
}
4646

4747
// IsWritable examines an AttributeMap and fails if it is unsuitable for writing.

DynamoDbEncryption/dafny/DynamoDbEncryption/src/FilterExpr.dfy

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,17 +1716,18 @@ module DynamoDBFilterExpr {
17161716
}
17171717
var parsed := ParseExpr(keyExpr.value);
17181718
var values :- GetValues(bv, parsed, values.value, names);
1719-
1720-
if |values| == 0 {
1721-
return Success(1);
1722-
} else if |values| == 1 {
1723-
return Success(values[0].0.getNumQueries(bv.numBuckets));
1724-
} else if |values| == 2 {
1725-
return Success(lcmBucket(values[0].0.getNumQueries(bv.numBuckets), values[1].0.getNumQueries(bv.numBuckets), bv.numBuckets));
1726-
} else {
1727-
print "\nThat's Odd : \n", keyExpr, "\n\n";
1728-
return Success(1); // FIXME
1719+
var result : BucketCount := 1;
1720+
SequenceIsSafeBecauseItIsInMemory(values);
1721+
for i : uint64 := 0 to |values| as uint64
1722+
invariant result <= bv.numBuckets
1723+
{
1724+
var buckets := values[i].0.getNumQueries(bv.numBuckets, values[0].1);
1725+
if buckets == 1 || buckets == result {
1726+
continue;
1727+
}
1728+
result := lcmBucket(result, buckets, bv.numBuckets);
17291729
}
1730+
return Success(result);
17301731
}
17311732

17321733
// Search through the query expressions to find the Multi-Tenant KeyId
@@ -2026,52 +2027,4 @@ module DynamoDBFilterExpr {
20262027
}
20272028
return Success(true);
20282029
}
2029-
2030-
// return an list of encrypted attributes used in expression
2031-
method GetEncryptedAttrs (
2032-
actions : AttributeActions,
2033-
expr : string,
2034-
names : Option<DDB.ExpressionAttributeNameMap>
2035-
)
2036-
returns (output : seq<string>)
2037-
{
2038-
var pExpr := ParseExpr(expr);
2039-
var result : seq<string> := [];
2040-
for i := 0 to |pExpr| {
2041-
if pExpr[i].Attr? {
2042-
var name := GetAttrName(pExpr[i], names);
2043-
if name in actions && actions[name] == SE.ENCRYPT_AND_SIGN {
2044-
result := result + [GetAttrName(pExpr[i], names)];
2045-
}
2046-
}
2047-
}
2048-
return result;
2049-
}
2050-
2051-
// return the number of queries necessary for these encrypted attributes
2052-
method GetNumQueriesForAttrs(attrs : seq<string>, b : SI.BeaconVersion) returns (output : Result<BucketCount, Error>)
2053-
ensures output.Success? ==> output.value <= b.numBuckets
2054-
{
2055-
if |attrs| == 0 {
2056-
return Success(1);
2057-
} else if |attrs| == 1 {
2058-
var attr := attrs[0];
2059-
if attr !in b.beacons {
2060-
return Failure(E("No beacon for " + attr));
2061-
}
2062-
return Success(b.beacons[attr].getNumQueries(b.numBuckets));
2063-
} else if |attrs| == 2 {
2064-
var attr1 := attrs[0];
2065-
if attr1 !in b.beacons {
2066-
return Failure(E("No beacon for " + attr1));
2067-
}
2068-
var attr2 := attrs[1];
2069-
if attr2 !in b.beacons {
2070-
return Failure(E("No beacon for " + attr2));
2071-
}
2072-
return Success(lcmBucket(b.beacons[attr1].getNumQueries(b.numBuckets), b.beacons[attr2].getNumQueries(b.numBuckets), b.numBuckets));
2073-
} else {
2074-
return Failure(E("More than two attributes not implemented yet"));
2075-
}
2076-
}
20772030
}

DynamoDbEncryption/dafny/DynamoDbEncryption/src/SearchInfo.dfy

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -544,16 +544,15 @@ module SearchableEncryptionInfo {
544544
| Standard(std : BaseBeacon.ValidStandardBeacon)
545545
| Compound(cmp : CompoundBeacon.ValidCompoundBeacon)
546546
{
547-
function method getNumQueries(globalMax : BucketCount) : BucketCount
548-
ensures 0 <= getNumQueries(globalMax) <= globalMax
547+
method getNumQueries(globalMax : BucketCount, value : string) returns (output : BucketCount)
548+
ensures 0 <= output <= globalMax
549549
{
550-
if Standard? then
551-
if std.numberOfBuckets <= globalMax then
552-
std.numberOfBuckets
553-
else
554-
globalMax
555-
else
556-
cmp.getNumQueries(globalMax)
550+
if Standard? {
551+
return bmin(std.numberOfBuckets, globalMax);
552+
} else {
553+
output := cmp.getNumQueries(globalMax, value);
554+
return;
555+
}
557556
}
558557
predicate method isEncrypted()
559558
{

DynamoDbEncryption/dafny/DynamoDbEncryption/src/Util.dfy

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module DynamoDbEncryptionUtil {
88
import opened Wrappers
99
import opened StandardLibrary
1010
import opened StandardLibrary.UInt
11+
import opened StandardLibrary.MemoryMath
1112
import DDB = ComAmazonawsDynamodbTypes
1213

1314
const ReservedPrefix := "aws_dbe_"
@@ -151,14 +152,24 @@ module DynamoDbEncryptionUtil {
151152
(a / gcd(a, b)) * b
152153
}
153154

155+
function method bmin(a : BucketCount, b : BucketCount) : (output : BucketCount)
156+
ensures output <= a
157+
ensures output <= b
158+
{
159+
if a <= b then
160+
a
161+
else
162+
b
163+
}
164+
154165
function method lcmBucket(a : BucketCount, b : BucketCount, max : BucketCount) : BucketCount
155166
requires 0 < a && 0 < b
156-
ensures 0 < lcmBucket(a, b, max)
167+
ensures 0 < lcmBucket(a, b, max) <= max
157168
{
158-
if a == 1 || b == max then
159-
b
169+
if a == 1 || b == max || a == b then
170+
bmin(b, max)
160171
else if b == 1 || a == max then
161-
a
172+
bmin(a, max)
162173
else
163174
var result := lcm(a as nat, b as nat);
164175
if result < max as nat then
@@ -167,20 +178,21 @@ module DynamoDbEncryptionUtil {
167178
max
168179
}
169180

170-
function method lcmSeq(values : seq<BucketCount>, max : BucketCount) : BucketCount
181+
method lcmSeq(values : seq<BucketCount>, max : BucketCount) returns (output : BucketCount)
171182
// requires forall i <- values :: i <= max
172-
decreases |values|
183+
ensures output <= max
173184
{
174-
if |values| == 0 then
175-
1
176-
else if |values| == 1 then
177-
values[0]
178-
else
179-
var res := lcmBucket(values[0], values[1], max);
180-
if |values| == 2 then
181-
res as BucketCount
182-
else
183-
lcmSeq([res as BucketCount] + values[2..], max)
185+
var result : BucketCount := 1;
186+
SequenceIsSafeBecauseItIsInMemory(values);
187+
for i : uint64 := 0 to |values| as uint64
188+
invariant result <= max
189+
{
190+
var buckets := values[i];
191+
if buckets == 1 || buckets == result {
192+
continue;
193+
}
194+
result := lcmBucket(result, buckets, max);
195+
}
196+
return result;
184197
}
185-
186198
}

DynamoDbEncryption/dafny/DynamoDbEncryptionTransforms/src/DynamoDbMiddlewareSupport.dfy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module DynamoDbMiddlewareSupport {
2828
method GetNumberOfQueries(config : ValidTableConfig, query : DDB.QueryInput) returns (output : Result<ET.BucketCount, Error>)
2929
requires config.search.Some?
3030
{
31-
var numQueries := BS.GetNumberOfQueries(config.search.value.versions[0], /*config.attributeActionsOnEncrypt*/map[], query);
31+
var numQueries := BS.GetNumberOfQueries(config.search.value.versions[0], query);
3232
return numQueries.MapFailure(e => AwsCryptographyDbEncryptionSdkDynamoDb(e));
3333
}
3434

DynamoDbEncryption/runtimes/go/ImplementationFromDafny-go/WrappedAwsCryptographyDbEncryptionSdkDynamoDbTransformsService/shim.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DynamoDbEncryption/runtimes/go/TestsFromDafny-go/WrappedAwsCryptographyDbEncryptionSdkDynamoDbTransformsService/shim.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)