@@ -234,20 +234,46 @@ module StructuredEncryptionFooter {
234
234
GetCanonicalPlaintextField (data.key, data.data)
235
235
}
236
236
237
- function method CanonContent (
238
- data : CanonCryptoList , // remaining fields to be canonized
239
- canonized : Bytes := [] // output
240
- ) : Result< Bytes, Error>
237
+ function CanonContent (data : CanonCryptoList )
238
+ : Result< Bytes, Error>
241
239
{
242
240
if |data| == 0 then
243
- Success (canonized )
241
+ Success ([] )
244
242
else if data[0]. action == DO_NOTHING then
245
- CanonContent (data[1..], canonized )
243
+ CanonContent (data[1..])
246
244
else
245
+ var tail :- CanonContent (data[1..]);
247
246
var newPart :- GetCanonicalItem (data[0]);
248
- CanonContent (data[1..], canonized + newPart)
247
+ Success (newPart + tail)
248
+ } by method {
249
+ var i: nat := |data|;
250
+ var vectors : Bytes := [];
251
+
252
+ while i != 0
253
+ decreases i
254
+ invariant Success (vectors) == CanonContent (data[i..])
255
+ {
256
+ i := i - 1;
257
+ if data[i]. action != DO_NOTHING {
258
+ var test := GetCanonicalItem (data[i]);
259
+ if test. Failure? {
260
+ ghost var j := i;
261
+ while j != 0
262
+ decreases j
263
+ invariant Failure (test.error) == CanonContent (data[j..])
264
+ {
265
+ j := j - 1;
266
+ }
267
+ return Failure (test.error);
268
+ }
269
+ vectors := test. value + vectors;
270
+ }
271
+ }
272
+
273
+ return Success (vectors);
249
274
}
250
275
276
+
251
277
function method CanonRecord (
252
278
data : CanonCryptoList ,
253
279
header : Bytes ,
@@ -377,13 +403,21 @@ module StructuredEncryptionFooter {
377
403
}
378
404
}
379
405
380
- function method SerializeTags (tags : seq <RecipientTag >)
406
+ function SerializeTags (tags : seq <RecipientTag >)
381
407
: Bytes
382
408
{
383
409
if |tags| == 0 then
384
410
[]
385
411
else
386
412
tags[0] + SerializeTags (tags[1..])
413
+ } by method {
414
+ var result : Bytes := [];
415
+ for i := |tags| downto 0
416
+ invariant result == SerializeTags (tags[i..])
417
+ {
418
+ result := tags[i] + result;
419
+ }
420
+ return result;
387
421
}
388
422
389
423
function method SerializeSig (sig : Option <Signature >)
0 commit comments