Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

Private information retrieval notes (SimplePIR / DoublePIR)

================================================================================
 PRIVATE INFORMATION RETRIEVAL
 The SimplePIR and DoublePIR schemes and their scan kernel
 (StreamSec.PIR.Scan / StreamSec.PIR.Simple / StreamSec.PIR.Double)
 (StreamSec Security Library for Embarcadero Delphi)
================================================================================

Generated: 2026-09-26  (First edition.)

A private-information-retrieval scheme answers a lookup without learning what
was looked up. The server holds a table; the client fetches record r; the
server ends the exchange knowing no more about r than it did before. Nothing
is hidden by obscurity: the server's whole per-lookup computation is one
matrix-vector product over every cell of the table, so a query for record 7
and a query for record 70000 are the same instructions over the same octets,
and take the same time. The query itself is a vector of learning-with-errors
samples and carries no recoverable index.

Companion to TLS.txt and PKIX.txt only in the sense that all three describe
library subsystems; nothing here depends on either, and nothing in the library
depends on this. The subsystem is self-contained and is called from your own
code.

--------------------------------------------------------------------------------
0. SUMMARY
--------------------------------------------------------------------------------

Three units in the StrSecIV runtime packages (170 through 370, i.e. XE3 through
Delphi 13). No design-time registration: nothing here is a component, and there
is no palette icon to look for. It is a class and record API, called from code.

  client                                   server
  ------                                   ------
  holds the hint, one download per epoch   holds the table
  Query(r)          -- query + stamp -->   Answer(query,stamp)
  Recover(answer)   <--- answer -------

THE HINT IS THE PRICE, AND IT IS THE FIRST THING TO BUDGET FOR. Once per epoch
the client downloads a matrix that depends on the table but not on any query.
It is megabytes where a query and an answer are kilobytes. The scheme earns its
cost where a client makes many lookups against a table that changes rarely; it
does not earn it for a single lookup.

WHAT THIS IS NOT. It is not an encrypted database, and it hides the QUERY, not
the TABLE. The server's table is not secret from the client: the client already
knows the public matrix seed and could download the table outright. What the
scheme buys is that it does not have to, and that the server cannot tell which
record it wanted. It is also not an access-control mechanism - every client
that can query can query anything.

================================================================================
1. UNIT INVENTORY
================================================================================

  StreamSec.PIR.Scan     The matrix-vector products both schemes rest on, over
                         UInt32 with arithmetic modulo 2^32. Portable Pascal
                         and an AVX2 arm. Depends on nothing but SysUtils.

  StreamSec.PIR.Simple   SimplePIR: parameter resolution, the table, the hint,
                         the query, the answer, recovery, and per-row hint
                         update. Depends on PIR.Scan and on the library's
                         random generator.

  StreamSec.PIR.Double   DoublePIR: the same exchange with the hint reduced by
                         applying the scheme a second time to the first hint.
                         Depends on PIR.Scan and PIR.Simple.

Three more files ship beside them and are not units you name in a uses clause:

  PirAvx2RowDot.inc      The two AVX2 bodies, written once against a neutral
  PirAvx2RowAxpy.inc     register assignment and included by three hosts.

  stPirAvx2Func.o        Those same two bodies assembled by Free Pascal, for
                         Delphi Linux64, which has no built-in assembler. See
                         section 5. stPirAvx2Func.pas is its source and is in
                         no Delphi package, exactly as stAESNIFunc.pas and
                         stGHashFunc.pas are not.

Dependency direction is one way throughout: Scan knows nothing of Simple, and
Simple knows nothing of Double.

================================================================================
2. SPECIFICATION STATUS - THERE IS NO RFC FOR THIS
================================================================================

There is no RFC and no FIPS publication for private information retrieval. The
schemes here are from the academic literature, and the implementation follows
one paper:

  Henzinger, Hong, Corrigan-Gibbs, Meiklejohn and Vaikuntanathan,
  "One Server for the Price of Two", IACR ePrint 2022/949.

READ THE FULL EPRINT VERSION, NOT THE USENIX SECURITY 2023 PROCEEDINGS PAPER.
DoublePIR is specified in Appendix E of the ePrint; the proceedings paper does
not carry that appendix, and its section 5 describes the scheme without the
detail an implementation needs.

TWO DELIBERATE DEVIATIONS FROM THE PAPER, both in the record layout, both
documented at length in the header of StreamSec.PIR.Simple:

  Records are sliced into b-bit limbs rather than decomposed in base p. It
  costs about ten per cent more cells at a twelve-kilooctet record and it buys
  a shift and a mask in place of a bignum division per record.

  The server stores the table uncentred in [0, p) and answers with it, while
  the hint is computed on the centred form. Recovery repairs the difference.
  This changes the answer on the wire relative to the fully centred form, so
  it is a wire convention rather than an internal one.

Anything that cites the paper's record handling is describing a different
database. Two implementations of this subsystem will interoperate with each
other and will not interoperate with an implementation written from the paper.

================================================================================
3. THE SCAN KERNEL  (StreamSec.PIR.Scan)
================================================================================

  ePirError                 The subsystem's exception root. Every exception
                            raised by any of the three units descends from it.
  tPirWord                  UInt32. The arithmetic is modulo 2^32, which is
                            what the type already does, so nothing kept at
                            that width reduces. The scan kernel has no
                            reduction in it at all; each Recover has one,
                            where a centring offset is formed as a UInt64
                            product and masked back.
  pPirWord                  ^tPirWord.
  tPirWordArray             array of tPirWord.

  tPirScan.MatVec           result := matrix * vector, row by row.
  tPirScan.MatVecT          result := matrix-transpose * vector.
  tPirScan.Avx2Available    True when this build has the AVX2 arm AND the
                            processor and operating system support it.
  tPirScan.GetUseAvx2       Which arm the next call will take.
  tPirScan.SetUseAvx2       Force the portable arm, for comparison. Asking for
                            AVX2 where it is not available leaves the portable
                            arm selected.

Each product has a pointer form and an array form; the array form checks the
lengths against the shape you pass and raises ePirDimensionMismatch rather
than reading past an end.

BOTH PRODUCTS WALK THEIR MATRIX IN STORAGE ORDER. The transposed product
streams as well as the forward one, which is why the layout is what it is.

THE PRODUCT IS BOUND BY MEMORY BANDWIDTH, NOT BY ARITHMETIC. It touches every
cell once and does two operations per cell. A faster core does not help a
kernel that is already waiting on RAM, and that is worth knowing before sizing
hardware for it. Addition modulo 2^32 is associative and commutative, so the
order in which a row is summed does not affect the result; that is what
licenses both the vectorisation and partitioning the work across threads.

================================================================================
4. THE AVX2 ARM AND WHERE IT EXISTS
================================================================================

THE ARM IS NOT ON EVERY BUILD THAT HAS THE HARDWARE, and the condition is a
compiler condition as well as a platform one:

  64-bit Windows      Delphi 11 Alexandria and later. Earlier dcc64 releases
                      do not know the AVX instructions.
  Delphi Linux64      All supported versions. The library supports Linux64
                      from 10.3 Rio.
  Free Pascal         x86-64 away from Windows.
  Everything else     Portable kernel only. That includes Win32 always, and
                      Win64 on the eleven compilers before Delphi 11.

So a Win64 build on XE3 through 10.4 Sydney reports Avx2Available as False on
a machine that plainly has AVX2. That is the compiler, not the processor.

Define ST4_NO_AVX2 - or the library-wide ST4_NO_ASM, which removes all of the
library's assembler - to compile the arm out on any platform.

WHAT THE ARM IS WORTH DEPENDS ENTIRELY ON THE MACHINE, and no single figure
generalises. Where something else binds first - memory bandwidth, or a virtual
CPU shared with another tenant - the two arms measure the same to within the
noise. On a core with the memory system to itself the AVX2 arm is worth about
a fifth. On Delphi Linux64 the comparison is not the one you would expect,
because the compiler's own back end already vectorises the portable loop.
Measure on the machine you will deploy on; the PIR demo does exactly that and
reports both arms.

================================================================================
5. WHAT A DELPHI LINUX64 BUILD NEEDS
================================================================================

dcclinux64 has no built-in assembler, so on that target the AVX2 bodies arrive
as a linked object rather than inline. stPirAvx2Func.o MUST BE ON THE OBJECT
PATH - -O on the command line, or DCC_ObjPath in a .dproj - exactly as
stAESNIFunc.o and stGHashFunc.o already must be. The object ships in the
Source folder.

Without it the link fails. It does not fall back to the portable arm:

  E2597 dcc-ld.lld: error: cannot open stPirAvx2Func.o: no such file or
  directory

Define ST4_NO_AVX2 or ST4_NO_ASM instead and that build needs no object at
all, on any platform, and keeps the portable kernel.

================================================================================
6. SIMPLEPIR  (StreamSec.PIR.Simple)
================================================================================

  ePirParamsOutOfRange      A parameter set no table row supports, or a chosen
                            shape that fails the correctness inequality.
  ePirDimensionMismatch     An array whose length contradicts the parameter
                            set it is used with.
  ePirHintVersionMismatch   An answer computed at a hint version other than
                            the one the client was given with its hint. It is
                            a statement about that counter alone. Raised by
                            Recover on the answer it is handed, and by Answer
                            on the stamp the query carries, in both schemes.
  ePirHintMismatch          An answer computed against a hint other than the
                            one the client holds, whatever the version says.
                            Raised at both ends, like the one above.
  ePirHintStale             An Answer asked of a server whose table has been
                            written since its hint was computed, or that has
                            no stamp to publish. Raised by the SERVER, on its
                            own state, in both schemes.

  tPirParams                The resolved parameter set: the plaintext modulus,
                            the matrix shape it implies, and the record layout
                            that fills it. Resolve, ForModulus, CellCount,
                            SampleCount, HintLen, QueryLen, AnswerLen,
                            CorrectnessHolds, CheckCorrectness.
  tSimplePirServer          Create, PutRecord, BuildHint, UpdateHintRow,
                            GetHintRow, Answer; Params, Seed, Table, Hint,
                            HintVersion, HintDigest.
  tSimplePirClient          Create, SetHint, ReplaceHintRow, Query, QueryFrom,
                            Recover; Params, HintVersion, HintDigest, PRNG.
  PirHintDigest             The SHA-256 of a hint, which is what both
                            HintDigest properties return. Both schemes use
                            this one routine.
  tPirGauss                 The error sampler. Create, Sample, Fill.
  iPirOctetSource           An octet stream, so the sampler does not know
                            whether it is drawing from the generator or from
                            the matrix expander.
  iPirMatrixExpander        The public matrix as a stream rather than a matrix.

RESOLVE REFUSES A SHAPE IT CANNOT DECODE rather than returning one that decodes
most of the time. Ask it for a record count and a record length and it either
gives you a working parameter set or raises.

PutRecord refuses a record whose length is not EXACTLY RecordLen. It does not
pad a short one and does not truncate a long one, because a caller that pads by
accident gets back a record it did not store.

THE ERROR SAMPLER IS CONSTANT TIME. It is a cumulative-distribution-table
sampler and not rejection sampling, because a rejection sampler's loop count
and its comparison both depend on the sample - and the sample is the client's
secret. One sample consumes exactly sixteen octets and scans every threshold
with no early exit.

A STALE HINT IS REFUSED, NOT DECODED. Every hint carries a version that the
server moves whenever it recomputes one, and Recover raises
ePirHintVersionMismatch on an answer computed at a version other than the one
the client holds. Without that check the answer would decode to
plausible-looking wrong octets, which is the worse failure. A recovery that is
merely wrong yields wrong octets and never an exception.

AND AN ANSWER IS BOUND TO THE HINT IT WAS COMPUTED AGAINST, which the version
alone never did. The server publishes HintDigest, the SHA-256 of its hint, and
you ship it beside HintVersion; Recover compares it with the digest the client
derived from its own hint at SetHint and raises ePirHintMismatch when they
differ. That closes the case of two shards at the same version over different
tables, and the case of a hint the client patched or spoilt. It is 32 octets a
hint and 32 an answer.

THE CASE NO DIGEST COULD CLOSE IS CLOSED BY THE SERVER. A PutRecord that
nothing follows leaves the hint byte-for-byte what the client holds, so its
digest is unchanged and there is nothing for a client to see. PutRecord marks
the LimbCount rows it wrote, Answer raises ePirHintStale while any mark
stands, and BuildHint clears them all; UpdateHintRow clears the one row it
recomputed, so a push that stopped part way is still refused. Code that
writes records between queries therefore gets an exception where it would
otherwise get an answer decoded against a hint that predates the write:
rebuild before answering, with BuildHint, or with UpdateHintRow over every
one of the LimbCount rows the record occupies.

THE MARK SEES WHAT PutRecord WROTE AND NOTHING ELSE, and that is the bound on
the paragraph above, in both schemes. The Table property hands back the
server's own array: a write through it reaches the field without passing
PutRecord, nothing marks it, and Answer cannot refuse it. Writing there is
the caller's to keep consistent - rebuild the hint afterwards, or write with
PutRecord, which marks what it wrote.

THE QUERY CARRIES THE STAMP, SO THE SERVER REFUSES BEFORE IT READS THE
TABLE. Answer takes the client's own version and digest beside the query:

    fServer.Answer(lQuery,fClient.HintVersion,fClient.HintDigest,lAnswer);

and makes the same two comparisons Recover makes, ahead of the scan that is
the whole cost of a lookup. ePirHintStale is tried first, because a table
written since the hint was built leaves the version and the digest agreeing,
and a client sent to refresh its hint by a version refusal would fetch one
its next query was refused against anyway.

A CLIENT THAT DECLINES TO NAME ITS HINT IS STILL SERVED. Pass an empty
digest and the server answers as though the arguments were not there, at the
cost of the scan. The rule is that the server refuses what it KNOWS will
fail, and about an unidentified query it knows nothing; a deployment that
wants identification to be mandatory refuses the empty stamp itself, before
the call. None of this removes the client's own check: a dishonest server
can answer anything and stamp it anything, so Recover derives its own digest
and makes both comparisons on every call. What is refused at the server is
work, not trust.

WHAT THE SERVER LEARNS FROM THE STAMP IS NOTHING ABOUT A RECORD. The hint is
public and byte-for-byte the same for every client of a server at a version,
so the pair is a function of the hint alone - not of the client, not of its
secret, not of the record it wants. Two clients on one hint asking for
different records put the same version and the same 32 octets on the wire,
so among queries the server ACCEPTS the identity is constant and carries no
information at all. On a refused one the server learns that the request came
from a client on an older epoch or another shard, which is a fact about a
public hint and not about a record.

WHAT NONE OF IT IS, is authentication. The values are computed from public
material and travel beside the query and the answer, not inside them, and
the mark is the server's statement about its own state. A deployment that
needs to know it read the record it asked for still authenticates the
RECORD, above these units. What none of it leaves is the silent wrong
answer.

A SERVER WITH NO STAMP TO PUBLISH REFUSES RATHER THAN TAKING ONE, in both
schemes, and that is the third thing Answer refuses for. With no hint built at
all it raises ePirDimensionMismatch: an answer computed then is one Recover
refuses for want of a hint, so the scan would be spent on an exchange that
cannot end. The digest itself is taken where the hint stops moving - by
BuildHint over the hint it built, and in SimplePIR by the UpdateHintRow that
leaves nothing outstanding, which is once per push and not once per row - so
reading HintDigest computes nothing at any time. It reads EMPTY while a row
push is part way through, because a hint mid-push describes no table the
server ever held and there is no stamp to publish for it; Answer refuses there
on the marks.

SO ANY NUMBER OF THREADS MAY ANSWER FROM ONE SERVER AT ONCE, in both schemes,
unconditionally and with no call to make first: Answer assigns to no field of
the server. That is the whole of what these classes promise about threads.
PutRecord, BuildHint and UpdateHintRow write the table, the hint, the marks
and the stamp, take no lock, and are safe against neither each other nor a
concurrent Answer - a deployment that builds while it answers serialises that
itself, or builds a second server and swaps it in. A client is not shared
either: Query and Recover are one state machine over one secret.

RECOVER'S OTHER REFUSALS, AND ONE OF THEM IS NOT A LEAF. ePirDimensionMismatch
when the client has no hint or the answer is the wrong length, and ePirError -
the base class the others descend from - when there is no outstanding query.
A Recover that DECODED clears the state that decoded it, so a second call on
the same answer raises that base class, and a handler written for the leaves
alone lets the commonest mistake there is go past it. A Recover that REFUSED
clears nothing: the query stands and the next call on it decodes, which is
what lets a version or a digest mismatch be remedied without querying again.

ONE CHANGED RECORD IS NOT A NEW HINT. A record occupies LimbCount consecutive
rows of one row block. UpdateHintRow recomputes one of them and GetHintRow
ships it; the client takes it with ReplaceHintRow. The client REPLACES that
row - it is not a delta. Push EVERY row of a record before answering: the
marks are counted per row, so a server that pushed some of them is still
refused. The push that leaves nothing outstanding takes the new stamp, so the
whole push pays one pass over the hint and the first answer after it pays
none.

THE CLIENT DOES NOT MATERIALISE THE PUBLIC MATRIX. At the sizes this is used
at it would be tens of megabytes. It is consumed a block of rows at a time
straight from the expander.

================================================================================
7. DOUBLEPIR  (StreamSec.PIR.Double)
================================================================================

DoublePIR exists for one reason: in SimplePIR the hint grows with the table,
and past a certain size that is what stops being affordable. DoublePIR applies
the scheme a second time, to the first level's hint, so what the client
downloads stops growing with the number of records.

  tPirDoubleParams          Resolve, ForModulus, CellCount, TotalCellCount,
                            SampleCount, SecondRowCount, RecoveryCount,
                            HintLen, QueryLen, AnswerLen, CorrectnessHolds,
                            CheckCorrectness.
  tDoublePirServer          Create, PutRecord, BuildHint, Answer; Params,
                            Seed1, Seed2, Table, Hint, HintDigits,
                            HintVersion, HintDigest.
  tDoublePirClient          Create, SetHint, Query, QueryFrom, Recover;
                            Params, HintVersion, HintDigest, PRNG.

  PirDoubleDigitCount       How many digits the second level decomposes into.
  PirDoubleLookupModulus    The modulus for a sample count.
  PirDoubleBoundHolds       Whether a modulus satisfies the second level's
  PirDoubleBoundNeeds       correctness bound, and what it would need.
  PirDecompose              A word to its digits, and back.
  PirRecompose

WHAT IT COSTS, AND THE VERDICT THAT FOLLOWS FROM THAT. What drops out of the
sizes is the record COUNT and nothing else. Both of the things a DoublePIR
client downloads carry d, the number of Z_p elements one record maps to: the
hint is d*kappa*n*n words and the answer is d*(2*kappa*n + kappa), so BOTH
grow linearly with the record LENGTH. At the shipped secret dimension a
one-octet record costs 26 214 400 octets of hint and 40 976 octets of answer;
a 12 288-octet record at the same shape costs 286 339 891 200 and
447 580 848.

SO DoublePIR IS A SCHEME FOR SHORT RECORDS. The answer is a second reason for
that and not a footnote to the hint, because the two are paid at different
times: the hint is downloaded once per EPOCH, the answer once per QUERY. A
one-octet record is 26 MB to start and 41 kB on every lookup. Read
tPirDoubleParams.HintLen AND tPirDoubleParams.AnswerLen before you build
anything.

The query is the one object that does not move with the record length at all:
m + l words, about twice the square root of the record count, and the only
place the record count appears on the wire.

CHOOSING BETWEEN THE TWO. Use SimplePIR when the hint at your table size is a
download you are willing to make; it is the simpler exchange, it has one
public matrix rather than two, and its per-lookup work is lower. Use DoublePIR
when the SimplePIR hint has grown past what you will ship AND your records are
short. Compare tPirParams.HintLen against tPirDoubleParams.HintLen at your own
record count and length - both are cheap to call and neither builds anything -
and compare tPirDoubleParams.AnswerLen against SimplePIR's beside them,
because that one is paid again on every lookup.

TWO SEEDS, NOT ONE. The server carries Seed1 and Seed2, one public matrix per
level, and they must differ. The client needs both to form its query.

THE TWO CLIENT SECRETS ARE DRAWN INDEPENDENTLY. What that buys is stated
precisely in the unit header, and the short version of it is wrong, so read it
there rather than reasoning from the shape.

RECOVER REFUSES WHAT SIMPLEPIR'S DOES, WITH THE SAME CLASSES. Section 6's
notes apply here word for word: ePirError when there is no outstanding query,
ePirDimensionMismatch when there is no hint or the answer is the wrong length,
ePirHintVersionMismatch when the version is not the one this client was given,
and ePirHintMismatch when the digest the answer was stamped with is not the
digest over the hint this client holds. Answer raises ePirHintStale after a
PutRecord that no BuildHint followed, and ePirDimensionMismatch before any
BuildHint at all, and refuses the stamp the query carries exactly as
section 6 describes.

ONE DIFFERENCE, AND IT IS IN THE SERVER. DoublePIR has no UpdateHintRow, so
there is nothing between 'written' and 'rebuilt' for it to represent: it
carries one flag where SimplePIR carries one mark a row. The digest is over
Hint - hint_c, the array the client downloads - while an answer is computed
from the tables and from HintDigits. What makes that a binding rather than a
coincidence is the pair: one BuildHint computes both levels from one table,
and the flag refuses an answer once the table has moved away from them.

================================================================================
8. PARAMETERS AND WHAT THE SECURITY FIGURE RESTS ON
================================================================================

The secret dimension, the ciphertext modulus and the error width are one
parameter choice and not three: the modulus tables in both units were produced
for exactly that triple. Do not change one of them in a local build and expect
the tables to still apply.

tPirParams.CorrectnessHolds states whether the chosen shape satisfies the
inequality that carries the correctness claim, and CheckCorrectness raises if
it does not. Resolve asserts it for whatever it chose, so a parameter set that
came from Resolve has already passed.

The correctness bound is an inequality you can check. The SECURITY figure is
not: it comes from a lattice estimator run against the chosen dimension,
modulus and error width. It is not derived in this document and it is not
derived in the units.

================================================================================
9. KNOWN LIMITS
================================================================================

  The hint grows with the table in           Use DoublePIR, section 7.
  SimplePIR.

  DoublePIR's hint AND its answer both       Only the record COUNT drops out.
  grow linearly with the record LENGTH.      Compare both schemes at your own
                                             record length, and weigh the
                                             answer separately: it is paid on
                                             every lookup, the hint once per
                                             epoch.

  There is no keyword lookup. A record is    Map your key to an index
  fetched by INDEX, not by a key.            yourself, in a structure the
                                             server does not see you consult.

  A client that fetches by index still       If the mapping from key to index
  leaks whatever the index itself means      is public, the index is as
  to an observer who knows the mapping.      revealing as the key.

  Every client that can query can query      There is no per-record access
  anything.                                  control in the scheme.

  One lookup costs one full pass over the    That is inherent, not an
  table.                                     implementation limit. It is what
                                             makes a hit and a miss alike.

  The table is not secret from the client.   See section 0.

  The hint store is held by whatever your    The units keep the hint in
  code does with it.                         memory; persisting it is yours.

  The hint digest is a mix-up detector,      It tells one hint from another.
  not a MAC. It is computed from public      It does not tell an honest server
  material and travels beside the answer     from a dishonest one.
  rather than inside it.                     Authenticate the RECORD if you
                                             need that.

Stated plainly, because an accurate limit is worth more than an absolute
claim.

================================================================================
10. THE DEMO
================================================================================

Demos\Delphi <version>\PIR\PIRDemo.dproj builds a table, fetches a record out
of it without disclosing which, and shows the two things a description cannot:
two queries for the same record side by side, sharing no word; and what
happens when the table changes under a client that still holds the old hint.
Its last panel measures the scan kernel on both arms, so the figure comes from
your machine rather than from a table in a document. readme.txt in that folder
says what each panel is for.


================================================================================
 END OF FILE
================================================================================