@@ -43,7 +43,7 @@ module BaseBeacon {
43
43
// = specification/searchable-encryption/beacons.md#basichash
44
44
// = type=implication
45
45
// # * basicHash MUST take an [hmac key](./search-config.md#hmac-key-generation), a [beacon length](#beacon-length) and a sequence of bytes as input.
46
- function method {:opaque} hash (val : Bytes , key : Bytes , length : BeaconLength , bucket : Bytes )
46
+ function method {:opaque} hash (val : Bytes , key : Bytes , length : BeaconLength , bucket : BucketBytes )
47
47
: (ret : Result< string , Error> )
48
48
ensures ret. Success? ==>
49
49
// = specification/searchable-encryption/beacons.md#basichash
@@ -70,7 +70,7 @@ module BaseBeacon {
70
70
}
71
71
72
72
// Get the standard hash for the UTF8 encoded representation of this string.
73
- function method {:opaque} hashStr (val : string , key : Bytes , length : BeaconLength , bucket : Bytes ) : (res : Result< string , Error> )
73
+ function method {:opaque} hashStr (val : string , key : Bytes , length : BeaconLength , bucket : BucketBytes ) : (res : Result< string , Error> )
74
74
ensures res. Success? ==> |res. value| > 0
75
75
{
76
76
var str := UTF8. Encode (val);
@@ -124,7 +124,7 @@ module BaseBeacon {
124
124
var beaconName := BeaconPrefix + name;
125
125
:- Need (DDB.IsValid_AttributeName(beaconName), E (beaconName + " is not a valid attribute name."));
126
126
var numBuckets : nat := if numberOfBuckets. Some? then numberOfBuckets. value as nat else 0;
127
- :- Need (numBuckets < 256, E(beaconName + " has numberOfBuckets greater than 255"));
127
+ // :- Need(numBuckets < 256, E(beaconName + " has numberOfBuckets greater than 255"));
128
128
Success (StandardBeacon.StandardBeacon(
129
129
BeaconBase (
130
130
client := client,
@@ -136,7 +136,7 @@ module BaseBeacon {
136
136
partOnly,
137
137
asSet,
138
138
share,
139
- numBuckets as uint8
139
+ numBuckets as OptBucketCount
140
140
))
141
141
}
142
142
datatype StandardBeacon = StandardBeacon (
@@ -146,21 +146,19 @@ module BaseBeacon {
146
146
partOnly : bool ,
147
147
asSet : bool ,
148
148
share : Option <string >,
149
- numberOfBuckets : uint8
149
+ numberOfBuckets : OptBucketCount
150
150
) {
151
- function method constrained_bucket (bucket : Bytes ) : Bytes
151
+
152
+ function method constrained_bucket (bucket : BucketNumber ) : BucketBytes
152
153
{
153
- SequenceIsSafeBecauseItIsInMemory (bucket);
154
- if numberOfBuckets == 0 || |bucket| as uint64 == 0 then
155
- bucket
154
+ if numberOfBuckets == 0 || bucket == 0 then
155
+ BucketNumberToBytes (bucket)
156
156
else
157
- var newBucket : uint8 := bucket[0] % numberOfBuckets;
158
- if newBucket == 0 then
159
- []
160
- else
161
- [newBucket]
157
+ var newBucket : BucketNumber := (bucket as OptBucketCount % numberOfBuckets) as BucketNumber;
158
+ BucketNumberToBytes (newBucket)
162
159
}
163
- function method {:opaque} hash (val : Bytes , key : Bytes , bucket : Bytes )
160
+
161
+ function method {:opaque} hash (val : Bytes , key : Bytes , bucket : BucketNumber )
164
162
: (ret : Result< string , Error> )
165
163
ensures ret. Success? ==>
166
164
&& |ret. value| > 0
@@ -188,7 +186,7 @@ module BaseBeacon {
188
186
// = type=implication
189
187
// # * string hash MUST take a string and some [key materials](./search-config.md#get-beacon-key-materials)
190
188
// # as input, and produce a string as output.
191
- function method {:opaque} hashStr (val : string , keys : HmacKeyMap , bucket : Bytes ) : (res : Result< string , Error> )
189
+ function method {:opaque} hashStr (val : string , keys : HmacKeyMap , bucket : BucketNumber ) : (res : Result< string , Error> )
192
190
ensures res. Success? ==> |res. value| > 0
193
191
194
192
// = specification/searchable-encryption/beacons.md#string-hash
@@ -211,7 +209,7 @@ module BaseBeacon {
211
209
hash (str.value, keys[keyName()], bucket)
212
210
}
213
211
214
- function method {:opaque} ValueToSet (value : DDB .AttributeValue, key : Bytes , bucket : Bytes ) : (ret : Result< DDB. AttributeValue, Error> )
212
+ function method {:opaque} ValueToSet (value : DDB .AttributeValue, key : Bytes , bucket : BucketNumber ) : (ret : Result< DDB. AttributeValue, Error> )
215
213
ensures ret. Success? ==> ret. value. SS?
216
214
ensures ! value. SS? && ! value. NS? && ! value. BS? ==> ret. Failure?
217
215
ensures ret. Success? ==> HasNoDuplicates (ret.value.SS)
@@ -230,7 +228,7 @@ module BaseBeacon {
230
228
// = specification/searchable-encryption/beacons.md#value-for-a-standard-beacon
231
229
// = type=implication
232
230
// # * This operation MUST take an [hmac key](./search-config.md#hmac-key-generation), a record as input, and produce an optional [AttributeValue](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValue.html).
233
- function method {:opaque} getHash (item : DDB .AttributeMap, vf : VirtualFieldMap , key : Bytes , bucket : Bytes ) : (ret : Result< Option< DDB. AttributeValue> , Error> )
231
+ function method {:opaque} getHash (item : DDB .AttributeMap, vf : VirtualFieldMap , key : Bytes , bucket : BucketNumber ) : (ret : Result< Option< DDB. AttributeValue> , Error> )
234
232
// = specification/searchable-encryption/beacons.md#value-for-a-standard-beacon
235
233
// = type=implication
236
234
// # * If this beacon is marked AsSet then this operation MUST return the
@@ -245,7 +243,7 @@ module BaseBeacon {
245
243
getHashNonSet (item, vf, key, bucket)
246
244
}
247
245
248
- function method {:opaque} getHashSet (item : DDB .AttributeMap, key : Bytes , bucket : Bytes ) : (ret : Result< Option< DDB. AttributeValue> , Error> )
246
+ function method {:opaque} getHashSet (item : DDB .AttributeMap, key : Bytes , bucket : BucketNumber ) : (ret : Result< Option< DDB. AttributeValue> , Error> )
249
247
requires asSet
250
248
ensures ret. Success? ==>
251
249
// = specification/searchable-encryption/beacons.md#value-for-a-set-standard-beacon
@@ -275,7 +273,7 @@ module BaseBeacon {
275
273
var setValue :- ValueToSet (value.value, key, bucket);
276
274
Success (Some(setValue))
277
275
}
278
- function method {:opaque} getHashNonSet (item : DDB .AttributeMap, vf : VirtualFieldMap , key : Bytes , bucket : Bytes ) : (ret : Result< Option< DDB. AttributeValue> , Error> )
276
+ function method {:opaque} getHashNonSet (item : DDB .AttributeMap, vf : VirtualFieldMap , key : Bytes , bucket : BucketNumber ) : (ret : Result< Option< DDB. AttributeValue> , Error> )
279
277
requires ! asSet
280
278
ensures ret. Success? ==>
281
279
// = specification/searchable-encryption/beacons.md#value-for-a-non-set-standard-beacon
@@ -321,7 +319,7 @@ module BaseBeacon {
321
319
[loc[0]. key]
322
320
}
323
321
324
- function method {:tailrecursion} BeaconizeStringSet (value : DDB .StringSetAttributeValue, key : Bytes , bucket : Bytes , converted : seq <string > := [])
322
+ function method {:tailrecursion} BeaconizeStringSet (value : DDB .StringSetAttributeValue, key : Bytes , bucket : BucketNumber , converted : seq <string > := [])
325
323
: (ret : Result< seq < string > , Error> )
326
324
requires HasNoDuplicates (converted)
327
325
ensures ret. Success? ==> HasNoDuplicates (ret.value)
@@ -338,7 +336,7 @@ module BaseBeacon {
338
336
BeaconizeStringSet (value[1..], key, bucket, converted + [h])
339
337
}
340
338
341
- function method {:tailrecursion} BeaconizeNumberSet (value : DDB .NumberSetAttributeValue, key : Bytes , bucket : Bytes , converted : seq <string > := [])
339
+ function method {:tailrecursion} BeaconizeNumberSet (value : DDB .NumberSetAttributeValue, key : Bytes , bucket : BucketNumber , converted : seq <string > := [])
342
340
: (ret : Result< seq < string > , Error> )
343
341
requires HasNoDuplicates (converted)
344
342
ensures ret. Success? ==> HasNoDuplicates (ret.value)
@@ -355,7 +353,7 @@ module BaseBeacon {
355
353
BeaconizeNumberSet (value[1..], key, bucket, converted + [h])
356
354
}
357
355
358
- function method {:tailrecursion} BeaconizeBinarySet (value : DDB .BinarySetAttributeValue, key : Bytes , bucket : Bytes , converted : seq <string > := [])
356
+ function method {:tailrecursion} BeaconizeBinarySet (value : DDB .BinarySetAttributeValue, key : Bytes , bucket : BucketNumber , converted : seq <string > := [])
359
357
: (ret : Result< seq < string > , Error> )
360
358
requires HasNoDuplicates (converted)
361
359
ensures ret. Success? ==> HasNoDuplicates (ret.value)
@@ -372,7 +370,7 @@ module BaseBeacon {
372
370
BeaconizeBinarySet (value[1..], key, bucket, converted + [h])
373
371
}
374
372
375
- function method GetBeaconValue (value : DDB .AttributeValue, key : Bytes , forContains : bool , bucket : Bytes )
373
+ function method GetBeaconValue (value : DDB .AttributeValue, key : Bytes , forContains : bool , bucket : BucketNumber )
376
374
: (ret : Result< DDB. AttributeValue, Error> )
377
375
{
378
376
// in query, allow beaconization of terminals
@@ -389,7 +387,7 @@ module BaseBeacon {
389
387
// = specification/searchable-encryption/beacons.md#getpart-for-a-standard-beacon
390
388
// = type=implication
391
389
// # * getPart MUST take an [hmac key](./search-config.md#hmac-key-generation), a sequence of bytes as input, and produce a string.
392
- function method {:opaque} getPart (val : Bytes , key : Bytes , bucket : Bytes )
390
+ function method {:opaque} getPart (val : Bytes , key : Bytes , bucket : BucketBytes )
393
391
: (ret : Result< string , Error> )
394
392
requires 0 < |val|
395
393
0 commit comments