ver.inc turns overflow and range checking off for the whole library, and this unit repeats that AFTER the include so that the setting cannot be inherited by accident: the wrap-around of a UInt32 IS the arithmetic here, and a build with overflow checking on would raise on correct input. The Boolean evaluation setting matches the kernel's for the same reason it is set there: and/or over Booleans is evaluated with branches, so the one comparison that must not branch - PirGaussGE, against a threshold derived from the client's secret - is written in integer arithmetic and never as a Boolean expression.
Feature notes: Private information retrieval notes (SimplePIR / DoublePIR)
inherits from ePirError
A parameter set that no table row supports, a dimension outside the scheme's range, or a chosen (p, L, M) that fails the correctness inequality.
(no public members)
inherits from ePirError
An array whose length contradicts the parameter set it is used with.
(no public members)
inherits from ePirError
A hint version other than the one the exchange's other side holds. It is a statement about that COUNTER alone: what binds an answer to the hint it was computed against is the digest below, and the two are separate classes because the remedies differ.
RAISED FROM BOTH SIDES, over the same two counters. tSimplePirClient.Recover and tDoublePirClient.Recover raise it when the version an answer is stamped with is not the client's; tSimplePirServer.Answer and tDoublePirServer.Answer raise it when the version a QUERY names is not the server's, which is the same disagreement caught one round trip earlier and before the table is read. Either way the remedy is the same - fetch the answering server's current hint - which is why it is one class and not two.
(no public members)
inherits from ePirError
A hint digest other than the one the exchange's other side computed from the hint it holds. Raised by tSimplePirClient.Recover and by tDoublePirClient.Recover over the stamp beside an ANSWER, and by tSimplePirServer.Answer and tDoublePirServer.Answer over the stamp a QUERY carries - the same comparison, made at whichever end has both values first.
WHY THIS AND NOT ePirHintVersionMismatch, which is the neighbour a reader reaches for. The version says one side is BEHIND the other and fetching the answering server's current hint fixes it. This one says the two are looking at a different hint altogether - another shard's table, or a hint one side patched and the other did not - and fetching a hint from whoever answered would not repair the exchange, it would hide it. A handler that retries on a version mismatch must not retry on this one, so it is a sibling of that class and not a descendant of it.
WHY NOT ePirDimensionMismatch: nothing here has the wrong length. The answer, the hint and the parameter set all agree on every dimension, and that is what makes the case worth a class of its own.
(no public members)
inherits from ePirError
An Answer asked of a server whose table has been written since its hint was last computed. Raised by tSimplePirServer.Answer and tDoublePirServer.Answer - by the SERVER, on its own state, before any answer exists.
IT NAMES THE HINT AND NOT THE TABLE because the hint is the thing that has gone wrong: the table is exactly what the caller meant to write, and the remedy is BuildHint - or, in this unit, UpdateHintRow over every row the write moved. It is not ePirHintVersionMismatch, although Answer now makes that comparison too: a write to the table moves no counter and releases no hint, so the version a query names is still the server's own and the digest a query carries still matches - this case is exactly the one where both of those agree and the answer would STILL be wrong, which is why the mark exists at all. It is not ePirDimensionMismatch either, because no array here is the wrong length.
(no public members)
One row of the plaintext-modulus table. LogSampleCount is the row's index: the row that applies is the first whose 2^LogSampleCount is at least the sample count of the shape. Delta, HalfDelta and Slack are 2^32 div p, its half, and 2^32 - Delta*p; they are shipped rather than computed so that a transcription error shows up as a failed assertion at unit start rather than as a scheme that decodes wrongly.
LogSampleCount: Integer;
SimpleModulus : Integer;
DoubleModulus : Integer;
Delta : tPirWord;
HalfDelta : tPirWord;
Slack : tPirWord;
LimbBitLen : Integer;
A resolved parameter set: the plaintext modulus, the matrix shape it implies, and the record layout that fills it. Every array in the system is shaped by RowCount and ColCount, so these are resolved once and carried.
SecretDim : Integer;
Modulus : Integer;
LimbBitLen : Integer;
LimbCount : Integer;
RowCount : Integer;
ColCount : Integer;
RecordCount: Integer;
RecordLen : Integer;
Delta : tPirWord;
class function Resolve(aRecordCount, aRecordLen: Integer): tPirParams; static;
class function ForModulus(aModulus, aRecordCount, aRecordLen, aSecretDim: Integer): tPirParams; static;
function CellCount: Int64;
function SampleCount: Int64;
function HintLen: Int64;
function QueryLen: Int64;
function AnswerLen: Int64;
function CorrectnessHolds: Boolean;
procedure CheckCorrectness;
An octet stream. The matrix expander and the library's random generator both present one, so the error sampler does not know which it is drawing from.
procedure NextOctets(var aBuf; aByteLen: Integer);
inherits from iPirOctetSource
The public matrix, as a stream rather than a matrix. The client must use it this way: materialising A costs M*n*4 octets.
procedure Reset;
procedure NextWords(var aBuf: tPirWordArray; aOffset, aWordCount: Integer);
The discrete Gaussian of the scheme, sigma = 6.4, as two's-complement UInt32 residues. Constant time: every sample scans all cPirGaussTau thresholds and applies its sign unconditionally.
constructor Create(const aSource: iPirOctetSource);
function Sample: tPirWord;
procedure Fill(var aVector: tPirWordArray; aOffset, aCount: Integer);
The server. It holds the table uncentred, answers queries with it, and computes the hint on the centred form of the same words.
constructor Create(const aParams: tPirParams; const aSeed: tBytes);
destructor Destroy; override;
procedure PutRecord(aRecordIndex: Integer; const aRecord: tBytes);
procedure BuildHint;
procedure UpdateHintRow(aRowIndex: Integer);
procedure GetHintRow(aRowIndex: Integer; var aRow: tPirWordArray);
procedure Answer(const aQuery: tPirWordArray; aHintVersion: UInt32; const aHintDigest: tBytes; var aAnswer: tPirWordArray);
property Params: tPirParams read fParams;
property Seed: tBytes read fSeed;
property Table: tPirWordArray read fDb;
property Hint: tPirWordArray read fHint;
property HintVersion: UInt32 read GetHintVersion;
property HintDigest: tBytes read GetHintDigest;
The client. It holds the hint and, between Query and Recover, the secret that decodes the answer.
constructor Create(const aParams: tPirParams; const aSeed: tBytes);
destructor Destroy; override;
procedure SetHint(const aHint: tPirWordArray; aHintVersion: UInt32);
procedure ReplaceHintRow(aRowIndex: Integer; const aRow: tPirWordArray; aHintVersion: UInt32);
procedure Query(aRecordIndex: Integer; var aQuery: tPirWordArray);
procedure QueryFrom(aRecordIndex: Integer; const aSecretSource, aErrorSource: iPirOctetSource; var aQuery: tPirWordArray);
function Recover(const aAnswer: tPirWordArray; aHintVersion: UInt32; const aHintDigest: tBytes): tBytes;
property Params: tPirParams read fParams;
property HintVersion: UInt32 read fHintVersion;
property HintDigest: tBytes read GetHintDigest;
property PRNG: iRawRandom read GetPRNG write SetPRNG;
A cumulative-distribution threshold, little-endian limbs: index 0 is least significant. UInt32 rather than UInt64 because the comparison against it must be branch-free on Win32 too, and Win32 has no 64-bit compare instruction.