Skip to content

Commit c587bbc

Browse files
committed
Clean up the algorithm and match it to the ref impl
1 parent 88859e7 commit c587bbc

File tree

1 file changed

+47
-32
lines changed

1 file changed

+47
-32
lines changed

draft-ietf-httpbis-cache-digest.md

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,22 @@ the ETag is available; otherwise, null);
215215
4. Let `key` be the return value of {{key}} with `URL` and `ETag` as inputs.
216216
5. Let `h1` be the return value of {{hash}} with `key` and `N` as inputs.
217217
6. Let `fingerprint` be the return value of {{fingerprint}} with `key` and `f` as inputs.
218-
7. Let `fingerprint-string` be the value of `fingerprint` in base 10, expressed as a string.
219-
8. Let `h2` be the return value of {{hash}} with `fingerprint-string` and `N` as inputs, XORed with
220-
`h1`.
221-
9. Let `h` be either `h1` or `h2`, picked in random.
222-
10. Let `position_start` be 40 + `h` * `f` \* `b`.
223-
11. Let `position_end` be `position_start` + `f` \* `b`.
224-
12. While `position_start` < `position_end`:
225-
1. Let `bits` be `f` bits from `digest_value` starting at `position_start`.
226-
2. If `bits` is all zeros, set `bits` to `fingerprint` and terminate these steps.
227-
3. Add `f` to `position_start`.
218+
7. Let `h2` be the return value of {{hash2}} with `h1`, `fingerprint` and `N` as inputs.
219+
8. Let `h` be either `h1` or `h2`, picked in random.
220+
9. While `maxcount` is larger than zero:
221+
1. Let `position_start` be 40 + `h` * `f` \* `b`.
222+
2. Let `position_end` be `position_start` + `f` \* `b`.
223+
3. While `position_start` < `position_end`:
224+
1. Let `bits` be `f` bits from `digest_value` starting at `position_start`.
225+
2. If `bits` is all zeros, set `bits` to `fingerprint` and terminate these steps.
226+
3. Add `f` to `position_start`.
227+
4. Let `e` be a random number from 0 to `b`.
228+
5. Substract `f` * (`b` - `e`) from `position_start`.
229+
6. Let `bits` be `f` bits from `digest_value` starting at `position_start`.
230+
7. Let `dest_fingerprint` be the value of bits, read as big endian.
231+
8. Set `bits` to `fingerprint`.
232+
9. Let `h` be {{hash2}} with `h`, `dest_fingerprint` and `N` as inputs.
233+
10. Substract 1 from `maxcount`.
228234
13. Substract `f` from `position_start`.
229235
14. Let `fingerprint` be the `f` bits starting at `position_start`.
230236
15. Let `h1` be `h`
@@ -249,17 +255,15 @@ the ETag is available; otherwise, null);
249255
4. Let `key` be the return value of {{key}} with `URL` and `ETag` as inputs.
250256
5. Let `h1` be the return value of {{hash}} with `key` and `N` as inputs.
251257
6. Let `fingerprint` be the return value of {{fingerprint}} with `key` and `f` as inputs.
252-
7. Let `fingerprint-string` be the value of `fingerprint` in base 10, expressed as a string.
253-
8. Let `h2` be the return value of {{hash}} with `fingerprint-string` and `N` as inputs, XORed with
254-
`h1`.
255-
9. Let `h` be `h1`.
256-
10. Let `position_start` be 40 + `h` \* `f` \* `b`.
257-
11. Let `position_end` be `position_start` + `f` \* `b`.
258-
12. While `position_start` < `position_end`:
259-
1. Let `bits` be `f` bits from `digest_value` starting at `position_start`.
260-
2. If `bits` is `fingerprint`, set `bits` to all zeros and terminate these steps.
261-
3. Add `f` to `position_start`.
262-
13. If `h` is not `h2`, set `h` to `h2` and return to step 10.
258+
7. Let `h2` be the return value of {{hash2}} with `h1`, `fingerprint` and `N` as inputs.
259+
8. Let `hashes` be an array containing `h1` and `h2`.
260+
9. For each `h` in `hashes`:
261+
1. Let `position_start` be 40 + `h` \* `f` \* `b`.
262+
2. Let `position_end` be `position_start` + `f` \* `b`.
263+
3. While `position_start` < `position_end`:
264+
1. Let `bits` be `f` bits from `digest_value` starting at `position_start`.
265+
2. If `bits` is `fingerprint`, set `bits` to all zeros and terminate these steps.
266+
3. Add `f` to `position_start`.
263267

264268
### Computing a fingerprint value {#fingerprint}
265269

@@ -298,6 +302,8 @@ Given the following inputs:
298302
and double quotes, as per {{RFC7232}}, Section 2.3.
299303
3. Return `key`
300304

305+
TODO: Add an example of the ETag and the key calcuations.
306+
301307
### Computing a Hash Value {#hash}
302308

303309
Given the following inputs:
@@ -311,6 +317,16 @@ Given the following inputs:
311317
expressed as an integer.
312318
2. Return `hash-value` modulo N.
313319

320+
### Computing an Alternative Hash Value {#hash2}
321+
Given the following inputs:
322+
323+
* `hash1`, an integer indicating the previous hash.
324+
* `fingerprint`, an integer indicating the fingerprint value.
325+
* `N`, an integer indicating the number of entries in the digest.
326+
327+
1. Let `fingerprint-string` be the value of `fingerprint` in base 10, expressed as a string.
328+
2. Let `hash2` be the return value of {{hash}} with `fingerprint-string` and `N` as inputs, XORed with `hash1`.
329+
3. Return `hash2`.
314330

315331
## Server Behavior
316332

@@ -351,17 +367,16 @@ the ETag is available; otherwise, null).
351367
4. Let `key` be the return value of {{key}} with `URL` and `ETag` as inputs.
352368
5. Let `h1` be the return value of {{hash}} with `key` and `N` as inputs.
353369
6. Let `fingerprint` be the return value of {{fingerprint}} with `key` and `f` as inputs.
354-
7. Let `fingerprint-string` be the value of `fingerprint` in base 10, expressed as a string.
355-
8. Let `h2` be the return value of {{hash}} with `fingerprint` and `N` as inputs, XORed with `h1`.
356-
9. Let `h` be `h1`.
357-
10. Let `position_start` be 40 + `h` \* `f` \* `b`.
358-
11. Let `position_end` be `position_start` + `f` \* `b`.
359-
12. While `position_start` < `position_end`:
360-
1. Let `bits` be `f` bits from `digest_value` starting at `position_start`.
361-
2. If `bits` is `fingerprint`, return true
362-
3. Add `f` to `position_start`.
363-
13. If `h` is not `h2`, set `h` to `h2` and return to step 10.
364-
13. Return false.
370+
7. Let `h2` be the return value of {{hash2}} with `h1`, `fingerprint` and `N` as inputs.
371+
8. Let `hashes` be an array containing `h1` and `h2`.
372+
9. For each `h` in `hashes`:
373+
1. Let `position_start` be 40 + `h` \* `f` \* `b`.
374+
2. Let `position_end` be `position_start` + `f` \* `b`.
375+
3. While `position_start` < `position_end`:
376+
1. Let `bits` be `f` bits from `digest_value` starting at `position_start`.
377+
2. If `bits` is `fingerprint`, return true
378+
3. Add `f` to `position_start`.
379+
10. Return false.
365380

366381
# The SENDING_CACHE_DIGEST SETTINGS Parameter
367382

0 commit comments

Comments
 (0)