Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

methodtDoublePirClient.Recover

function Recover(const aAnswer: tPirWordArray; aHintVersion: UInt32; const aHintDigest: tBytes): tBytes;
The record, from the answer to the query this client last made.

aHintDigest is what the answering server's HintDigest read, shipped beside aHintVersion. It is compared against the digest this client derived from its own hint at SetHint.

WHAT IT REFUSES, AND EVERY CLASS IS PINNED TO ITSELF. Raises ePirError when there is no outstanding query, which is 'a client cannot recover without having made a query'; ePirDimensionMismatch when there is no hint or the answer is not the length AnswerLen states, which are 'a client cannot recover without a hint' and 'an answer of the wrong length is refused'; ePirHintVersionMismatch when aHintVersion is not the version this client was given with its hint, which is 'an answer computed at another hint version is refused'; and ePirHintMismatch when aHintDigest is not the digest over the hint this client holds, which is 'a client holding another table's hint is refused the answer, at a hint version that matches'. THAT IS ALL, and each is pinned to the class ITSELF and not to a base it descends from, because the first of them IS the base: ePirDimensionMismatch descends from ePirError, so a handler written for the leaves lets the no-query case past it.

AND THE NO-QUERY CASE IS THE ONE A CALLER REACHES BY ACCIDENT, because the decode block below clears the state that decodes an answer. Once a Recover has got that far, a second on the same answer raises it - 'and a second recovery is refused, because the state that decoded the first one was wiped' - and so does a recovery after a query that raised, 'and it has no outstanding query either, so a recovery after a failed one is refused rather than run on released secrets'.

A REFUSAL TAKEN ABOVE THE BLOCK NEVER REACHES IT. All five checks are made before it, so the query stands, and a call that carries the remedy
- the version the answer was computed at, the stamp that goes with it, a hint, an answer of the right length - decodes it on that same query. That is what lets a version mismatch be remedied without a new query. A call that repeats the arguments that were refused is refused again, with the same class: what stands is the query, not the exchange. A raise from INSIDE the block is not one of these - the finally clause wipes, and that client has no outstanding query either.

WHAT BINDS AN ANSWER TO A HINT IS THE DIGEST, AND THE VERSION NEVER DID. The version is a number one server hands out, and two servers holding different tables are both at version 1 until one of them rebuilds; a client handed the wrong server's answer at a matching version used to decode it and return wrong octets. Every index is refused now rather than one of them - 'and not one of eight lookups returns a record to a client holding another table's hint: every one of the eight is refused'.

WHAT THE DIGEST CANNOT DO. It travels beside the answer, not inside it, and nothing here authenticates either, so whoever can hand this client an answer can hand it a stamp to go with it. It tells one hint from another; it does not tell an honest server from a dishonest one. And it cannot see a table written since the hint was built, because the hint that leaves standing is byte for byte the one the client holds - that case is refused by the SERVER, at Answer, as ePirHintStale.

AN HONEST SERVER NOW REFUSES TWO OF THESE FIRST, and NOTHING HERE WAS REMOVED FOR IT. Answer takes the client's hint version and stamp, so against a server that runs this library the version and digest cases are raised there, before the tables are read, and reach this client as the same two classes out of Answer rather than out of Recover. That is an optimisation on the server's work and not a check moved: a server that does not make it, or lies about the result of making it, is exactly the server this comparison exists for.

A recovery that is merely wrong yields wrong octets, never an exception.