Skip to content

Commit 3f704a1

Browse files
committed
m
1 parent 87b4a34 commit 3f704a1

File tree

6 files changed

+56
-4
lines changed

6 files changed

+56
-4
lines changed

DynamoDbEncryption/dafny/DynamoDbEncryption/Model/DynamoDbEncryption.smithy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ operation GetBucketNumber {
6161
output: GetBucketNumberOutput,
6262
}
6363

64+
//= specification/searchable-encryption/search-config.md#bucket-selector
65+
//= type=implication
66+
//# GetBucketNumber MUST take as input
67+
//#
68+
//# - A DynamoDB Item (i.e an AttributeMap)
69+
//# - The [number of buckets](#max-buckets) defined in the associated [beacon version](#beacon-version-initialization).
70+
//# - The logical table name for this defined in the associated [table config](../dynamodb-encryption-client/ddb-table-encryption-config.md#structure).
71+
6472
structure GetBucketNumberInput {
6573
@required
6674
item: AttributeMap,
@@ -70,6 +78,12 @@ structure GetBucketNumberInput {
7078
logicalTableName: String,
7179
}
7280

81+
//= specification/searchable-encryption/search-config.md#bucket-selector
82+
//= type=implication
83+
//# GetBucketNumber MUST return
84+
//#
85+
//# - The number of the bucket to use for this item
86+
7387
structure GetBucketNumberOutput {
7488
@required
7589
bucketNumber: BucketNumber

DynamoDbEncryption/dafny/DynamoDbEncryption/src/Beacon.dfy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ module BaseBeacon {
147147
numberOfBuckets : BucketCount
148148
) {
149149

150+
//= specification/searchable-encryption/beacons.md#beacon-constraint
151+
//# If an item is being written or queried as bucket `X`, but the [standard beacon](#standard-beacon-initialization) is constrained to only `N` buckets,
152+
//# then the bucket used to [encode](#bucket-beacon-encoding) the beacon MUST be `X % N`, where `%` is the modulo or remainder operation.
150153
function method constrained_bucket(bucket : BucketNumber) : BucketBytes
151154
{
152155
if numberOfBuckets == 0 || bucket == 0 then
@@ -165,6 +168,8 @@ module BaseBeacon {
165168

166169
&& |ret.value| == (((length as uint8) + 3) / 4) as nat
167170
{
171+
//= specification/searchable-encryption/beacons.md#value-for-a-non-set-standard-beacon
172+
//# - The serialized form MUST be augmented as per [bucket beacon encoding](#bucket-beacon-encoding).
168173
base.hash(val, key, length, constrained_bucket(bucket))
169174
}
170175

DynamoDbEncryption/dafny/DynamoDbEncryption/src/ConfigToInfo.dfy

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ module SearchConfigToInfo {
294294
true
295295
}
296296

297+
//= specification/searchable-encryption/search-config.md#bucket-selector
298+
//# The default implementation of the Bucket Selector MUST return a random number within the acceptable range, i.e.
297299
method GetBucketNumber'(input: GetBucketNumberInput)
298300
returns (output: Result<GetBucketNumberOutput, Error> )
299301
requires ValidState()
@@ -331,14 +333,30 @@ module SearchConfigToInfo {
331333
&& fresh(output.value.bucketSelector.Modifies)
332334
{
333335
var maxBuckets : BucketCount := config.maximumNumberOfBuckets.UnwrapOr(1);
334-
var defaultBuckets : BucketCount := config.defaultNumberOfBuckets.UnwrapOr(maxBuckets);
335-
:- Need(0 <= maxBuckets as nat < MAX_BUCKET_COUNT, E("Invalid number of buckets specified, " + Base10Int2String(maxBuckets as int) + ", must be 0 < maximumNumberOfBuckets <= 255."));
336+
:- Need(0 <= maxBuckets as nat < MAX_BUCKET_COUNT, E("Invalid maximumNumberOfBuckets specified, " + Base10Int2String(maxBuckets as int) + ", must be 0 < maximumNumberOfBuckets <= 255."));
336337
// Zero is invalid, but in Java we can't distinguish None from Some(0)
337338
if maxBuckets == 0 {
338339
maxBuckets := 1;
339340
}
340-
if defaultBuckets == 0 {
341+
342+
var defaultBucketsOpt : Option<BucketCount> := config.defaultNumberOfBuckets;
343+
var defaultBuckets;
344+
345+
//= specification/searchable-encryption/search-config.md#default-buckets
346+
//# If not set, Default Buckets MUST default to [Max Buckets](#max-buckets).
347+
if defaultBucketsOpt.None? || defaultBucketsOpt.value == 0 {
341348
defaultBuckets := maxBuckets;
349+
350+
//= specification/searchable-encryption/search-config.md#beacon-version-initialization
351+
//# Initialization MUST fail if [default number of buckets](#default-buckets) is greater than or equal to [maximum number of buckets](#max-buckets).
352+
353+
// if maximumNumberOfBuckets is not set, then maxBuckets == 1, and so this is also covered
354+
//= specification/searchable-encryption/search-config.md#beacon-version-initialization
355+
//# Initialization MUST fail if [default number of buckets](#default-buckets) is supplied but [maximum number of buckets](#max-buckets) is not.
356+
} else if maxBuckets <= defaultBucketsOpt.value {
357+
return(E("Invalid defaultNumberOfBuckets specified, " + Base10Int2String(defaultBucketsOpt.value as int) + ", must be 0 < defaultNumberOfBuckets < maximumNumberOfBuckets."));
358+
} else {
359+
defaultBuckets := defaultBucketsOpt.value;
342360
}
343361

344362
var virtualFields :- ConvertVirtualFields(outer, config.virtualFields);
@@ -602,6 +620,9 @@ module SearchConfigToInfo {
602620
else if inner.value < maxBuckets then
603621
Success(inner.value)
604622
else
623+
//= specification/searchable-encryption/beacons.md#standard-beacon-initialization
624+
//# Initialization MUST fail if [number of buckets](#beacon-constraint) is specified, and is greater than or equal to
625+
//# the maximum number of buckets specified in the [beacon version](search-config.md#beacon-version-initialization).
605626
Failure(E("Constrained numberOfBuckets for " + name + " is " + Base10Int2String(inner.value as int) + " but it must be less than the maximumNumberOfBuckets " + Base10Int2String(maxBuckets as int)))
606627
}
607628

DynamoDbEncryption/dafny/DynamoDbEncryption/src/Util.dfy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,12 @@ module DynamoDbEncryptionUtil {
9696

9797
function method BucketNumberToBytes(x : BucketNumber) : BucketBytes
9898
{
99+
//= specification/searchable-encryption/beacons.md#bucket-beacon-encoding
100+
//# If this number is zero, then the input sequence of bytes MUST be returned unchanged.
99101
if x == 0 then
100102
[]
103+
//= specification/searchable-encryption/beacons.md#bucket-beacon-encoding
104+
//# Otherwise, a single byte with a value equal to this calculated bucket number, MUST be appended to the input sequence of bytes.
101105
else
102106
[x as uint8]
103107
}

DynamoDbEncryption/dafny/DynamoDbEncryptionTransforms/Model/DynamoDbEncryptionTransforms.smithy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,18 @@ operation GetNumberOfQueries {
8181
input: GetNumberOfQueriesInput,
8282
output: GetNumberOfQueriesOutput,
8383
}
84+
85+
//= specification/dynamodb-encryption-client/ddb-get-number-of-queries.md#input
86+
//= type=implication
87+
//# This operation MUST take as input the QueryInput structure under consideration.
8488
structure GetNumberOfQueriesInput {
8589
@required
8690
input: QueryInput
8791
}
92+
93+
//= specification/dynamodb-encryption-client/ddb-get-number-of-queries.md#input
94+
//= type=implication
95+
//# This operation MUST return the number of queries necessary.
8896
structure GetNumberOfQueriesOutput {
8997
@required
9098
numberOfQueries: BucketCount

specification/searchable-encryption/search-config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ If not set, Max Buckets MUST default to `1`, which is synonymous with "no bucket
558558
The Default Buckets setting a [beacon version](#beacon-version-initialization) configures the number of buckets used by all
559559
[standard beacons](beacons.md#standard-beacon-initialization) that do not directly specify a number of buckets.
560560

561-
If not set, Max Buckets MUST default to [Max Buckets](#max-buckets).
561+
If not set, Default Buckets MUST default to [Max Buckets](#max-buckets).
562562

563563
### Bucket Selector
564564

0 commit comments

Comments
 (0)